本文整理汇总了Golang中go/types.NewVar函数的典型用法代码示例。如果您正苦于以下问题:Golang NewVar函数的具体用法?Golang NewVar怎么用?Golang NewVar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewVar函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: newIdent
func (c *simplifyContext) newIdent(t types.Type) *ast.Ident {
c.varCounter++
id := ast.NewIdent(fmt.Sprintf("_%d", c.varCounter))
c.info.Types[id] = types.TypeAndValue{Type: t} // TODO remove?
c.info.Uses[id] = types.NewVar(token.NoPos, nil, id.Name, t)
return id
}
开发者ID:neelance,项目名称:astrewrite,代码行数:7,代码来源:simplify.go
示例2: NewIdent
func NewIdent(name string, t types.Type, info *types.Info, pkg *types.Package) *ast.Ident {
ident := ast.NewIdent(name)
info.Types[ident] = types.TypeAndValue{Type: t}
obj := types.NewVar(0, pkg, name, t)
info.Uses[ident] = obj
return ident
}
开发者ID:julesGoullee,项目名称:gopherjs,代码行数:7,代码来源:astutil.go
示例3: obj
func (p *importer) obj(tag int) {
switch tag {
case constTag:
pos := p.pos()
pkg, name := p.qualifiedName()
typ := p.typ(nil)
val := p.value()
p.declare(types.NewConst(pos, pkg, name, typ, val))
case typeTag:
_ = p.typ(nil)
case varTag:
pos := p.pos()
pkg, name := p.qualifiedName()
typ := p.typ(nil)
p.declare(types.NewVar(pos, pkg, name, typ))
case funcTag:
pos := p.pos()
pkg, name := p.qualifiedName()
params, isddd := p.paramList()
result, _ := p.paramList()
sig := types.NewSignature(nil, params, result, isddd)
p.declare(types.NewFunc(pos, pkg, name, sig))
default:
panic(fmt.Sprintf("unexpected object tag %d", tag))
}
}
开发者ID:mysll,项目名称:flynet,代码行数:30,代码来源:bimport.go
示例4: param
func (p *importer) param(named bool) (*types.Var, bool) {
t := p.typ(nil)
td, isddd := t.(*dddSlice)
if isddd {
t = types.NewSlice(td.elem)
}
var pkg *types.Package
var name string
if named {
name = p.string()
if name == "" {
panic("expected named parameter")
}
if name != "_" {
pkg = p.pkg()
}
if i := strings.Index(name, "·"); i > 0 {
name = name[:i] // cut off gc-specific parameter numbering
}
}
// read and discard compiler-specific info
p.string()
return types.NewVar(token.NoPos, pkg, name, t), isddd
}
开发者ID:mysll,项目名称:flynet,代码行数:27,代码来源:bimport.go
示例5: loadStruct
func (c *funcContext) loadStruct(array, target string, s *types.Struct) string {
view := c.newVariable("_view")
code := fmt.Sprintf("%s = new DataView(%s.buffer, %s.byteOffset)", view, array, array)
var fields []*types.Var
var collectFields func(s *types.Struct, path string)
collectFields = func(s *types.Struct, path string) {
for i := 0; i < s.NumFields(); i++ {
field := s.Field(i)
if fs, isStruct := field.Type().Underlying().(*types.Struct); isStruct {
collectFields(fs, path+"."+fieldName(s, i))
continue
}
fields = append(fields, types.NewVar(0, nil, path+"."+fieldName(s, i), field.Type()))
}
}
collectFields(s, target)
offsets := sizes32.Offsetsof(fields)
for i, field := range fields {
switch t := field.Type().Underlying().(type) {
case *types.Basic:
if isNumeric(t) {
if is64Bit(t) {
code += fmt.Sprintf(", %s = new %s(%s.getUint32(%d, true), %s.getUint32(%d, true))", field.Name(), c.typeName(field.Type()), view, offsets[i]+4, view, offsets[i])
break
}
code += fmt.Sprintf(", %s = %s.get%s(%d, true)", field.Name(), view, toJavaScriptType(t), offsets[i])
}
case *types.Array:
code += fmt.Sprintf(`, %s = new ($nativeArray(%s))(%s.buffer, $min(%s.byteOffset + %d, %s.buffer.byteLength))`, field.Name(), typeKind(t.Elem()), array, array, offsets[i], array)
}
}
return code
}
开发者ID:camlistore,项目名称:camlistore,代码行数:33,代码来源:expressions.go
示例6: newIdent
func (c *funcContext) newIdent(name string, t types.Type) *ast.Ident {
ident := ast.NewIdent(name)
c.setType(ident, t)
obj := types.NewVar(0, c.p.Pkg, name, t)
c.p.Uses[ident] = obj
c.p.objectNames[obj] = name
return ident
}
开发者ID:snyderep,项目名称:pongish,代码行数:8,代码来源:utils.go
示例7: newMethod
// newMethod creates a new method of the specified name, package and receiver type.
func newMethod(pkg *ssa.Package, recvType types.Type, name string) *ssa.Function {
// TODO(adonovan): fix: hack: currently the only part of Signature
// that is needed is the "pointerness" of Recv.Type, and for
// now, we'll set it to always be false since we're only
// concerned with rtype. Encapsulate this better.
sig := types.NewSignature(types.NewVar(token.NoPos, nil, "recv", recvType), nil, nil, false)
fn := pkg.Prog.NewFunction(name, sig, "fake reflect method")
fn.Pkg = pkg
return fn
}
开发者ID:tsandall,项目名称:opa,代码行数:11,代码来源:reflect.go
示例8: obj
func (p *importer) obj(tag int) {
switch tag {
case constTag:
pos := p.pos()
pkg, name := p.qualifiedName()
typ := p.typ(nil)
val := p.value()
p.declare(types.NewConst(pos, pkg, name, typ, val))
case typeTag:
p.typ(nil)
case varTag:
pos := p.pos()
pkg, name := p.qualifiedName()
typ := p.typ(nil)
p.declare(types.NewVar(pos, pkg, name, typ))
case funcTag:
pos := p.pos()
pkg, name := p.qualifiedName()
params, isddd := p.paramList()
result, _ := p.paramList()
sig := types.NewSignature(nil, params, result, isddd)
p.declare(types.NewFunc(pos, pkg, name, sig))
case aliasTag:
pos := p.pos()
name := p.string()
var orig types.Object
if pkg, name := p.qualifiedName(); pkg != nil {
orig = pkg.Scope().Lookup(name)
}
// Alias-related code. Keep for now.
_ = pos
_ = name
_ = orig
// p.declare(types.NewAlias(pos, p.pkgList[0], name, orig))
default:
errorf("unexpected object tag %d", tag)
}
}
开发者ID:golang,项目名称:gddo,代码行数:43,代码来源:bimport.go
示例9: param
func (p *importer) param(named bool) (*types.Var, bool) {
t := p.typ(nil)
td, isddd := t.(*dddSlice)
if isddd {
t = types.NewSlice(td.elem)
}
var name string
if named {
name = p.string()
if name == "" {
panic("expected named parameter")
}
}
// read and discard compiler-specific info
p.string()
return types.NewVar(token.NoPos, nil, name, t), isddd
}
开发者ID:CyCoreSystems,项目名称:coreos-kubernetes,代码行数:20,代码来源:bimport.go
示例10: obj
func (p *importer) obj(pkg *types.Package) {
var obj types.Object
switch tag := p.int(); tag {
case constTag:
obj = types.NewConst(token.NoPos, pkg, p.string(), p.typ(), p.value())
case typeTag:
// type object is added to scope via respective named type
_ = p.typ().(*types.Named)
return
case varTag:
obj = types.NewVar(token.NoPos, pkg, p.string(), p.typ())
case funcTag:
obj = types.NewFunc(token.NoPos, pkg, p.string(), p.typ().(*types.Signature))
default:
panic(fmt.Sprintf("unexpected object tag %d", tag))
}
if alt := pkg.Scope().Insert(obj); alt != nil {
panic(fmt.Sprintf("%s already declared", alt.Name()))
}
}
开发者ID:julesGoullee,项目名称:gopherjs,代码行数:21,代码来源:import.go
示例11: parseParameter
// Parameter = ( identifier | "?" ) [ "..." ] Type [ string_lit ] .
//
func (p *parser) parseParameter() (par *types.Var, isVariadic bool) {
_, name := p.parseName(nil, false)
// remove gc-specific parameter numbering
if i := strings.Index(name, "·"); i >= 0 {
name = name[:i]
}
if p.tok == '.' {
p.expectSpecial("...")
isVariadic = true
}
typ := p.parseType(nil)
if isVariadic {
typ = types.NewSlice(typ)
}
// ignore argument tag (e.g. "noescape")
if p.tok == scanner.String {
p.next()
}
// TODO(gri) should we provide a package?
par = types.NewVar(token.NoPos, nil, name, typ)
return
}
开发者ID:vmware,项目名称:vic,代码行数:24,代码来源:gcimporter.go
示例12: appendComponentsRecursive
// appendComponentsRecursive implements componentsOfType.
// Recursion is required to correct handle structs and arrays,
// which can contain arbitrary other types.
func appendComponentsRecursive(arch *asmArch, t types.Type, cc []component, suffix string, off int) []component {
s := t.String()
size := int(arch.sizes.Sizeof(t))
kind := asmKindForType(t, size)
cc = append(cc, newComponent(suffix, kind, s, off, size, suffix))
switch kind {
case 8:
if arch.ptrSize() == 4 {
w1, w2 := "lo", "hi"
if arch.bigEndian {
w1, w2 = w2, w1
}
cc = append(cc, newComponent(suffix+"_"+w1, 4, "half "+s, off, 4, suffix))
cc = append(cc, newComponent(suffix+"_"+w2, 4, "half "+s, off+4, 4, suffix))
}
case asmEmptyInterface:
cc = append(cc, newComponent(suffix+"_type", asmKind(arch.ptrSize()), "interface type", off, arch.ptrSize(), suffix))
cc = append(cc, newComponent(suffix+"_data", asmKind(arch.ptrSize()), "interface data", off+arch.ptrSize(), arch.ptrSize(), suffix))
case asmInterface:
cc = append(cc, newComponent(suffix+"_itable", asmKind(arch.ptrSize()), "interface itable", off, arch.ptrSize(), suffix))
cc = append(cc, newComponent(suffix+"_data", asmKind(arch.ptrSize()), "interface data", off+arch.ptrSize(), arch.ptrSize(), suffix))
case asmSlice:
cc = append(cc, newComponent(suffix+"_base", asmKind(arch.ptrSize()), "slice base", off, arch.ptrSize(), suffix))
cc = append(cc, newComponent(suffix+"_len", asmKind(arch.intSize()), "slice len", off+arch.ptrSize(), arch.intSize(), suffix))
cc = append(cc, newComponent(suffix+"_cap", asmKind(arch.intSize()), "slice cap", off+arch.ptrSize()+arch.intSize(), arch.intSize(), suffix))
case asmString:
cc = append(cc, newComponent(suffix+"_base", asmKind(arch.ptrSize()), "string base", off, arch.ptrSize(), suffix))
cc = append(cc, newComponent(suffix+"_len", asmKind(arch.intSize()), "string len", off+arch.ptrSize(), arch.intSize(), suffix))
case asmComplex:
fsize := size / 2
cc = append(cc, newComponent(suffix+"_real", asmKind(fsize), fmt.Sprintf("real(complex%d)", size*8), off, fsize, suffix))
cc = append(cc, newComponent(suffix+"_imag", asmKind(fsize), fmt.Sprintf("imag(complex%d)", size*8), off+fsize, fsize, suffix))
case asmStruct:
tu := t.Underlying().(*types.Struct)
fields := make([]*types.Var, tu.NumFields())
for i := 0; i < tu.NumFields(); i++ {
fields[i] = tu.Field(i)
}
offsets := arch.sizes.Offsetsof(fields)
for i, f := range fields {
cc = appendComponentsRecursive(arch, f.Type(), cc, suffix+"_"+f.Name(), off+int(offsets[i]))
}
case asmArray:
tu := t.Underlying().(*types.Array)
elem := tu.Elem()
// Calculate offset of each element array.
fields := []*types.Var{
types.NewVar(token.NoPos, nil, "fake0", elem),
types.NewVar(token.NoPos, nil, "fake1", elem),
}
offsets := arch.sizes.Offsetsof(fields)
elemoff := int(offsets[1])
for i := 0; i < int(tu.Len()); i++ {
cc = appendComponentsRecursive(arch, elem, cc, suffix+"_"+strconv.Itoa(i), i*elemoff)
}
}
return cc
}
开发者ID:Harvey-OS,项目名称:go,代码行数:70,代码来源:asmdecl.go
示例13: BImportData
// BImportData imports a package from the serialized package data
// and returns the number of bytes consumed and a reference to the package.
// If data is obviously malformed, an error is returned but in
// general it is not recommended to call BImportData on untrusted data.
func BImportData(imports map[string]*types.Package, data []byte, path string) (int, *types.Package, error) {
p := importer{
imports: imports,
data: data,
}
p.buf = p.bufarray[:]
// read low-level encoding format
switch format := p.byte(); format {
case 'c':
// compact format - nothing to do
case 'd':
p.debugFormat = true
default:
return p.read, nil, fmt.Errorf("invalid encoding format in export data: got %q; want 'c' or 'd'", format)
}
// --- generic export data ---
if v := p.string(); v != "v0" {
return p.read, nil, fmt.Errorf("unknown version: %s", v)
}
// populate typList with predeclared "known" types
p.typList = append(p.typList, predeclared...)
// read package data
// TODO(gri) clean this up
i := p.tagOrIndex()
if i != packageTag {
panic(fmt.Sprintf("package tag expected, got %d", i))
}
name := p.string()
if s := p.string(); s != "" {
panic(fmt.Sprintf("empty path expected, got %s", s))
}
pkg := p.imports[path]
if pkg == nil {
pkg = types.NewPackage(path, name)
p.imports[path] = pkg
}
p.pkgList = append(p.pkgList, pkg)
if debug && p.pkgList[0] != pkg {
panic("imported packaged not found in pkgList[0]")
}
// read compiler-specific flags
p.string() // discard
// read consts
for i := p.int(); i > 0; i-- {
name := p.string()
typ := p.typ(nil)
val := p.value()
p.declare(types.NewConst(token.NoPos, pkg, name, typ, val))
}
// read vars
for i := p.int(); i > 0; i-- {
name := p.string()
typ := p.typ(nil)
p.declare(types.NewVar(token.NoPos, pkg, name, typ))
}
// read funcs
for i := p.int(); i > 0; i-- {
name := p.string()
sig := p.typ(nil).(*types.Signature)
p.int() // read and discard index of inlined function body
p.declare(types.NewFunc(token.NoPos, pkg, name, sig))
}
// read types
for i := p.int(); i > 0; i-- {
// name is parsed as part of named type and the
// type object is added to scope via respective
// named type
_ = p.typ(nil).(*types.Named)
}
// ignore compiler-specific import data
// complete interfaces
for _, typ := range p.typList {
if it, ok := typ.(*types.Interface); ok {
it.Complete()
}
}
// record all referenced packages as imports
list := append(([]*types.Package)(nil), p.pkgList[1:]...)
sort.Sort(byPath(list))
pkg.SetImports(list)
// package was imported completely and without errors
//.........这里部分代码省略.........
开发者ID:CyCoreSystems,项目名称:coreos-kubernetes,代码行数:101,代码来源:bimport.go
示例14: parseVarDecl
// VarDecl = "var" ExportedName Type .
//
func (p *parser) parseVarDecl() {
p.expectKeyword("var")
pkg, name := p.parseExportedName()
typ := p.parseType(pkg)
pkg.Scope().Insert(types.NewVar(token.NoPos, pkg, name, typ))
}
开发者ID:vmware,项目名称:vic,代码行数:8,代码来源:gcimporter.go
示例15: translateExpr
//.........这里部分代码省略.........
switch x := astutil.RemoveParens(e.X).(type) {
case *ast.CompositeLit:
return c.formatExpr("$newDataPointer(%e, %s)", x, c.typeName(c.p.TypeOf(e)))
case *ast.Ident:
obj := c.p.Uses[x].(*types.Var)
if c.p.escapingVars[obj] {
return c.formatExpr("(%1s.$ptr || (%1s.$ptr = new %2s(function() { return this.$target[0]; }, function($v) { this.$target[0] = $v; }, %1s)))", c.p.objectNames[obj], c.typeName(exprType))
}
return c.formatExpr(`(%1s || (%1s = new %2s(function() { return %3s; }, function($v) { %4s })))`, c.varPtrName(obj), c.typeName(exprType), c.objectName(obj), c.translateAssign(x, c.newIdent("$v", exprType), false))
case *ast.SelectorExpr:
sel, ok := c.p.SelectionOf(x)
if !ok {
// qualified identifier
obj := c.p.Uses[x.Sel].(*types.Var)
return c.formatExpr(`(%1s || (%1s = new %2s(function() { return %3s; }, function($v) { %4s })))`, c.varPtrName(obj), c.typeName(exprType), c.objectName(obj), c.translateAssign(x, c.newIdent("$v", exprType), false))
}
newSel := &ast.SelectorExpr{X: c.newIdent("this.$target", c.p.TypeOf(x.X)), Sel: x.Sel}
c.setType(newSel, exprType)
c.p.additionalSelections[newSel] = sel
return c.formatExpr("(%1e.$ptr_%2s || (%1e.$ptr_%2s = new %3s(function() { return %4e; }, function($v) { %5s }, %1e)))", x.X, x.Sel.Name, c.typeName(exprType), newSel, c.translateAssign(newSel, c.newIdent("$v", exprType), false))
case *ast.IndexExpr:
if _, ok := c.p.TypeOf(x.X).Underlying().(*types.Slice); ok {
return c.formatExpr("$indexPtr(%1e.$array, %1e.$offset + %2e, %3s)", x.X, x.Index, c.typeName(exprType))
}
return c.formatExpr("$indexPtr(%e, %e, %s)", x.X, x.Index, c.typeName(exprType))
case *ast.StarExpr:
return c.translateExpr(x.X)
default:
panic(fmt.Sprintf("Unhandled: %T\n", x))
}
case token.ARROW:
call := &ast.CallExpr{
Fun: c.newIdent("$recv", types.NewSignature(nil, types.NewTuple(types.NewVar(0, nil, "", t)), types.NewTuple(types.NewVar(0, nil, "", exprType), types.NewVar(0, nil, "", types.Typ[types.Bool])), false)),
Args: []ast.Expr{e.X},
}
c.Blocking[call] = true
if _, isTuple := exprType.(*types.Tuple); isTuple {
return c.formatExpr("%e", call)
}
return c.formatExpr("%e[0]", call)
}
basic := t.Underlying().(*types.Basic)
switch e.Op {
case token.ADD:
return c.translateExpr(e.X)
case token.SUB:
switch {
case is64Bit(basic):
return c.formatExpr("new %1s(-%2h, -%2l)", c.typeName(t), e.X)
case isComplex(basic):
return c.formatExpr("new %1s(-%2r, -%2i)", c.typeName(t), e.X)
case isUnsigned(basic):
return c.fixNumber(c.formatExpr("-%e", e.X), basic)
default:
return c.formatExpr("-%e", e.X)
}
case token.XOR:
if is64Bit(basic) {
return c.formatExpr("new %1s(~%2h, ~%2l >>> 0)", c.typeName(t), e.X)
}
return c.fixNumber(c.formatExpr("~%e", e.X), basic)
case token.NOT:
return c.formatExpr("!%e", e.X)
default:
开发者ID:camlistore,项目名称:camlistore,代码行数:67,代码来源:expressions.go
示例16: param
func (p *importer) param() *types.Var {
return types.NewVar(token.NoPos, nil, p.string(), p.typ())
}
开发者ID:julesGoullee,项目名称:gopherjs,代码行数:3,代码来源:import.go
示例17: buildSSA
func buildSSA(fn *gst.FuncDecl, fnType *types.Func, log bool) (ssafn *ssa.Func, ok bool) {
// HACK, hardcoded
arch := "amd64"
signature, ok := fnType.Type().(*types.Signature)
if signature == nil || !ok {
fmt.Println("Error: function type isn't signature")
return nil, false
}
if signature.Results().Len() > 1 {
fmt.Println("Multiple return values unsupported")
return nil, false
}
var e ssaExport
var s state
e.log = log
link := obj.Link{}
s.ctx = Ctx{nil} //Ctx{fnInfo}
s.fnDecl = nil
s.fnType = nil
s.fnInfo = nil
s.config = ssa.NewConfig(arch, &e, &link, false)
s.f = s.config.NewFunc()
s.f.Name = fnType.Name()
s.f.Entry = s.f.NewBlock(ssa.BlockPlain)
s.scanBlocksGst(fn.Body)
if len(s.blocks) < 1 {
panic("no blocks found, need at least one block per function")
}
s.f.Entry = s.blocks[0].b
s.startBlock(s.f.Entry)
// Allocate starting values
s.labels = map[string]*ssaLabel{}
s.labeledNodes = map[ast.Node]*ssaLabel{}
s.startmem = s.entryNewValue0(ssa.OpInitMem, ssa.TypeMem)
s.sp = s.entryNewValue0(ssa.OpSP, Typ[types.Uintptr]) // TODO: use generic pointer type (unsafe.Pointer?) instead
s.sb = s.entryNewValue0(ssa.OpSB, Typ[types.Uintptr])
s.vars = map[ssaVar]*ssa.Value{}
s.vars[&memVar] = s.startmem
//s.varsyms = map[*Node]interface{}{}
// Generate addresses of local declarations
s.decladdrs = map[ssaVar]*ssa.Value{}
vars := []ssaVar{} //getVars(s.ctx, fn, fnType)
for _, v := range vars {
switch v.Class() {
case PPARAM:
// aux := s.lookupSymbol(n, &ssa.ArgSymbol{Typ: n.Type, Node: n})
// s.decladdrs[n] = s.entryNewValue1A(ssa.OpAddr, Ptrto(n.Type), aux, s.sp)
case PAUTO | PHEAP:
// TODO this looks wrong for PAUTO|PHEAP, no vardef, but also no definition
// aux := s.lookupSymbol(n, &ssa.AutoSymbol{Typ: n.Type, Node: n})
// s.decladdrs[n] = s.entryNewValue1A(ssa.OpAddr, Ptrto(n.Type), aux, s.sp)
case PPARAM | PHEAP, PPARAMOUT | PHEAP:
// This ends up wrong, have to do it at the PARAM node instead.
case PAUTO, PPARAMOUT:
// processed at each use, to prevent Addr coming
// before the decl.
case PFUNC:
// local function - already handled by frontend
default:
str := ""
if v.Class()&PHEAP != 0 {
str = ",heap"
}
s.Unimplementedf("local variable with class %s%s unimplemented", v.Class(), str)
}
}
//fpVar := types.NewVar(0, fnType.Pkg(), ".fp", Typ[types.Int32].Type)
fpVar := types.NewVar(0, nil, ".fp", Typ[types.Int32].Type)
nodfp := &ssaParam{v: fpVar, ctx: s.ctx}
// nodfp is a special argument which is the function's FP.
aux := &ssa.ArgSymbol{Typ: Typ[types.Uintptr], Node: nodfp}
s.decladdrs[nodfp] = s.entryNewValue1A(ssa.OpAddr, Typ[types.Uintptr], aux, s.sp)
s.processBlocks()
// Link up variable uses to variable definitions
s.linkForwardReferences()
//fmt.Println("f:", f)
ssa.Compile(s.f)
return s.f, true
}
开发者ID:bjwbell,项目名称:gir,代码行数:97,代码来源:builder.go
示例18: simplifyStmt
//.........这里部分代码省略.........
switch t := c.info.TypeOf(s.X).Underlying().(type) {
case *types.Chan:
key := s.Key
tok := s.Tok
if key == nil {
key = ast.NewIdent("_")
tok = token.DEFINE
}
okVar := c.newIdent(types.Typ[types.Bool])
if s.Tok == token.ASSIGN {
*stmts = append(*stmts, &ast.DeclStmt{
Decl: &ast.GenDecl{
Tok: token.VAR,
Specs: []ast.Spec{&ast.ValueSpec{
Names: []*ast.Ident{okVar},
Type: ast.NewIdent("bool"),
}},
},
})
}
newS = &ast.ForStmt{
For: s.For,
Body: &ast.BlockStmt{
Lbrace: s.Body.Lbrace,
List: append([]ast.Stmt{
&ast.AssignStmt{
Lhs: []ast.Expr{key, okVar},
TokPos: s.TokPos,
Tok: tok,
Rhs: []ast.Expr{c.setType(&ast.UnaryExpr{
Op: token.ARROW,
X: c.newVar(stmts, s.X),
}, types.NewTuple(
types.NewVar(token.NoPos, nil, "", t.Elem()),
types.NewVar(token.NoPos, nil, "", types.Typ[types.Bool]),
))},
},
&ast.IfStmt{
Cond: c.setType(&ast.UnaryExpr{
Op: token.NOT,
X: okVar,
}, types.Typ[types.Bool]),
Body: &ast.BlockStmt{
List: []ast.Stmt{
&ast.BranchStmt{Tok: token.BREAK},
},
},
},
}, c.simplifyStmtList(s.Body.List)...),
Rbrace: s.Body.Rbrace,
},
}
default:
newS = &ast.RangeStmt{
For: s.For,
Key: s.Key,
Value: s.Value,
TokPos: s.TokPos,
Tok: s.Tok,
X: s.X,
Body: c.simplifyBlock(s.Body),
}
}
c.info.Scopes[newS] = c.info.Scopes[s]
*stmts = append(*stmts, newS)
开发者ID:neelance,项目名称:astrewrite,代码行数:67,代码来源:simplify.go
示例19: init
"comma-separated list of functions whose results must be used")
var unusedStringMethodsFlag = flag.String("unusedstringmethods",
"Error,String",
"comma-separated list of names of methods of type func() string whose results must be used")
func init() {
register("unusedresult",
"check for unused result of calls to functions in -unusedfuncs list and methods in -unusedstringmethods list",
checkUnusedResult,
exprStmt)
}
// func() string
var sigNoArgsStringResult = types.NewSignature(nil, nil, nil,
types.NewTuple(types.NewVar(token.NoPos, nil, "", types.Typ[types.String])),
false)
var unusedFuncs = make(map[string]bool)
var unusedStringMethods = make(map[string]bool)
func initUnusedFlags() {
commaSplit := func(s string, m map[string]bool) {
if s != "" {
for _, name := range strings.Split(s, ",") {
if len(name) == 0 {
flag.Usage()
}
m[name] = true
}
}
开发者ID:josharian,项目名称:go.ssa,代码行数:31,代码来源:unused.go
示例20: parseVar
// Var = Name Type .
func (p *parser) parseVar(pkg *types.Package) *types.Var {
name := p.parseName()
return types.NewVar(token.NoPos, pkg, name, p.parseType(pkg))
}
开发者ID:syreclabs,项目名称:go-tools,代码行数:5,代码来源:parser.go
注:本文中的go/types.NewVar函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论