本文整理汇总了Golang中golang.org/x/tools/go/types.Builtin.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang Builtin.Name方法的具体用法?Golang Builtin.Name怎么用?Golang Builtin.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/tools/go/types.Builtin
的用法示例。
在下文中一共展示了Builtin.Name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: builtin
func (f *Finder) builtin(obj *types.Builtin, sig *types.Signature, args []ast.Expr, T types.Type) types.Type {
switch obj.Name() {
case "make", "new":
// skip the type operand
for _, arg := range args[1:] {
f.expr(arg)
}
case "append":
s := f.expr(args[0])
if _, ok := args[len(args)-1].(*ast.Ellipsis); ok && len(args) == 2 {
// append(x, y...) including append([]byte, "foo"...)
f.expr(args[1])
} else {
// append(x, y, z)
tElem := s.Underlying().(*types.Slice).Elem()
for _, arg := range args[1:] {
f.assign(tElem, f.expr(arg))
}
}
case "delete":
m := f.expr(args[0])
k := f.expr(args[1])
f.assign(m.Underlying().(*types.Map).Key(), k)
default:
// ordinary call
f.call(sig, args)
}
return T
}
示例2: translateStmt
func (c *funcContext) translateStmt(stmt ast.Stmt, label *types.Label) {
c.SetPos(stmt.Pos())
stmt = filter.IncDecStmt(stmt, c.p.Info)
stmt = filter.Assign(stmt, c.p.Info)
switch s := stmt.(type) {
case *ast.BlockStmt:
c.translateStmtList(s.List)
case *ast.IfStmt:
if s.Init != nil {
c.translateStmt(s.Init, nil)
}
var caseClauses []ast.Stmt
ifStmt := s
for {
caseClauses = append(caseClauses, &ast.CaseClause{List: []ast.Expr{ifStmt.Cond}, Body: ifStmt.Body.List})
switch elseStmt := ifStmt.Else.(type) {
case *ast.IfStmt:
if elseStmt.Init != nil {
caseClauses = append(caseClauses, &ast.CaseClause{List: nil, Body: []ast.Stmt{elseStmt}})
break
}
ifStmt = elseStmt
continue
case *ast.BlockStmt:
caseClauses = append(caseClauses, &ast.CaseClause{List: nil, Body: elseStmt.List})
case *ast.EmptyStmt, nil:
// no else clause
default:
panic(fmt.Sprintf("Unhandled else: %T\n", elseStmt))
}
break
}
c.translateBranchingStmt(caseClauses, false, nil, nil, nil, c.Flattened[s])
case *ast.SwitchStmt:
if s.Init != nil {
c.translateStmt(s.Init, nil)
}
tag := s.Tag
if tag == nil {
tag = ast.NewIdent("true")
c.p.Types[tag] = types.TypeAndValue{Type: types.Typ[types.Bool], Value: exact.MakeBool(true)}
}
if c.p.Types[tag].Value == nil {
refVar := c.newVariable("_ref")
c.Printf("%s = %s;", refVar, c.translateExpr(tag))
tag = c.newIdent(refVar, c.p.Types[tag].Type)
}
translateCond := func(cond ast.Expr) *expression {
return c.translateExpr(&ast.BinaryExpr{
X: tag,
Op: token.EQL,
Y: cond,
})
}
c.translateBranchingStmt(s.Body.List, true, translateCond, nil, label, c.Flattened[s])
case *ast.TypeSwitchStmt:
if s.Init != nil {
c.translateStmt(s.Init, nil)
}
refVar := c.newVariable("_ref")
var expr ast.Expr
var printCaseBodyPrefix func(index int)
switch a := s.Assign.(type) {
case *ast.AssignStmt:
expr = a.Rhs[0].(*ast.TypeAssertExpr).X
printCaseBodyPrefix = func(index int) {
value := refVar
caseClause := s.Body.List[index].(*ast.CaseClause)
if len(caseClause.List) == 1 {
t := c.p.Types[caseClause.List[0]].Type
if _, isInterface := t.Underlying().(*types.Interface); !isInterface && !types.Identical(t, types.Typ[types.UntypedNil]) {
value += ".$val"
}
}
c.Printf("%s = %s;", c.objectName(c.p.Implicits[caseClause]), value)
}
case *ast.ExprStmt:
expr = a.X.(*ast.TypeAssertExpr).X
}
c.Printf("%s = %s;", refVar, c.translateExpr(expr))
translateCond := func(cond ast.Expr) *expression {
if types.Identical(c.p.Types[cond].Type, types.Typ[types.UntypedNil]) {
return c.formatExpr("%s === $ifaceNil", refVar)
}
return c.formatExpr("$assertType(%s, %s, true)[1]", refVar, c.typeName(c.p.Types[cond].Type))
}
c.translateBranchingStmt(s.Body.List, true, translateCond, printCaseBodyPrefix, label, c.Flattened[s])
case *ast.ForStmt:
if s.Init != nil {
c.translateStmt(s.Init, nil)
}
//.........这里部分代码省略.........