本文整理汇总了Golang中go/types.Builtin.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang Builtin.Name方法的具体用法?Golang Builtin.Name怎么用?Golang Builtin.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/types.Builtin
的用法示例。
在下文中一共展示了Builtin.Name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: convertBuiltin
func (c *converter) convertBuiltin(v *gotypes.Builtin) *types.Builtin {
switch v.Name() {
case "Alignof", "Offsetof", "Sizeof":
return types.Unsafe.Scope().Lookup(v.Name()).(*types.Builtin)
default:
return types.Universe.Lookup(v.Name()).(*types.Builtin)
}
}
示例3: translateStmt
func (c *funcContext) translateStmt(stmt ast.Stmt, label *types.Label) {
c.SetPos(stmt.Pos())
stmt = filter.IncDecStmt(stmt, c.p.Info.Info)
stmt = filter.Assign(stmt, c.p.Info.Info, c.p.Info.Pkg)
switch s := stmt.(type) {
case *ast.BlockStmt:
c.translateStmtList(s.List)
case *ast.IfStmt:
var caseClauses []*ast.CaseClause
ifStmt := s
for {
if ifStmt.Init != nil {
panic("simplification error")
}
caseClauses = append(caseClauses, &ast.CaseClause{List: []ast.Expr{ifStmt.Cond}, Body: ifStmt.Body.List})
elseStmt, ok := ifStmt.Else.(*ast.IfStmt)
if !ok {
break
}
ifStmt = elseStmt
}
var defaultClause *ast.CaseClause
if block, ok := ifStmt.Else.(*ast.BlockStmt); ok {
defaultClause = &ast.CaseClause{Body: block.List}
}
c.translateBranchingStmt(caseClauses, defaultClause, false, c.translateExpr, nil, c.Flattened[s])
case *ast.SwitchStmt:
if s.Init != nil || s.Tag != nil || len(s.Body.List) != 1 {
panic("simplification error")
}
clause := s.Body.List[0].(*ast.CaseClause)
if len(clause.List) != 0 {
panic("simplification error")
}
prevFlowData := c.flowDatas[nil]
data := &flowData{
postStmt: prevFlowData.postStmt, // for "continue" of outer loop
beginCase: prevFlowData.beginCase, // same
}
c.flowDatas[nil] = data
c.flowDatas[label] = data
defer func() {
delete(c.flowDatas, label)
c.flowDatas[nil] = prevFlowData
}()
if c.Flattened[s] {
data.endCase = c.caseCounter
c.caseCounter++
c.Indent(func() {
c.translateStmtList(clause.Body)
})
c.Printf("case %d:", data.endCase)
return
}
if label != nil || analysis.HasBreak(clause) {
if label != nil {
c.Printf("%s:", label.Name())
}
c.Printf("switch (0) { default:")
c.Indent(func() {
c.translateStmtList(clause.Body)
})
c.Printf("}")
return
}
c.translateStmtList(clause.Body)
case *ast.TypeSwitchStmt:
if s.Init != nil {
c.translateStmt(s.Init, nil)
}
refVar := c.newVariable("_ref")
var expr ast.Expr
switch a := s.Assign.(type) {
case *ast.AssignStmt:
expr = a.Rhs[0].(*ast.TypeAssertExpr).X
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.TypeOf(cond), types.Typ[types.UntypedNil]) {
return c.formatExpr("%s === $ifaceNil", refVar)
}
return c.formatExpr("$assertType(%s, %s, true)[1]", refVar, c.typeName(c.p.TypeOf(cond)))
}
var caseClauses []*ast.CaseClause
var defaultClause *ast.CaseClause
for _, cc := range s.Body.List {
clause := cc.(*ast.CaseClause)
var bodyPrefix []ast.Stmt
//.........这里部分代码省略.........