本文整理汇总了Golang中go/types.Builtin类的典型用法代码示例。如果您正苦于以下问题:Golang Builtin类的具体用法?Golang Builtin怎么用?Golang Builtin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Builtin类的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
}
开发者ID:syreclabs,项目名称:go-tools,代码行数:33,代码来源:find.go
示例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)
}
}
开发者ID:tcard,项目名称:sgo,代码行数:8,代码来源:importer.go
示例3: translateStmt
//.........这里部分代码省略.........
c.PrintCond(data.endCase == 0, fmt.Sprintf("break%s;", normalLabel), fmt.Sprintf("$s = %d; continue%s;", data.endCase, blockingLabel))
case token.CONTINUE:
data.postStmt()
c.PrintCond(data.beginCase == 0, fmt.Sprintf("continue%s;", normalLabel), fmt.Sprintf("$s = %d; continue%s;", data.beginCase, blockingLabel))
case token.GOTO:
c.PrintCond(false, "goto "+s.Label.Name, fmt.Sprintf("$s = %d; continue;", c.labelCase(c.p.Uses[s.Label].(*types.Label))))
case token.FALLTHROUGH:
// handled in CaseClause
default:
panic("Unhandled branch statment: " + s.Tok.String())
}
case *ast.ReturnStmt:
results := s.Results
if c.resultNames != nil {
if len(s.Results) != 0 {
c.translateStmt(&ast.AssignStmt{
Lhs: c.resultNames,
Tok: token.ASSIGN,
Rhs: s.Results,
}, nil)
}
results = c.resultNames
}
rVal := c.translateResults(results)
if c.Flattened[s] {
resumeCase := c.caseCounter
c.caseCounter++
c.Printf("/* */ $s = %[1]d; case %[1]d:", resumeCase)
}
c.Printf("return%s;", rVal)
case *ast.DeferStmt:
isBuiltin := false
isJs := false
switch fun := s.Call.Fun.(type) {
case *ast.Ident:
var builtin *types.Builtin
builtin, isBuiltin = c.p.Uses[fun].(*types.Builtin)
if isBuiltin && builtin.Name() == "recover" {
c.Printf("$deferred.push([$recover, []]);")
return
}
case *ast.SelectorExpr:
isJs = typesutil.IsJsPackage(c.p.Uses[fun.Sel].Pkg())
}
sig := c.p.TypeOf(s.Call.Fun).Underlying().(*types.Signature)
args := c.translateArgs(sig, s.Call.Args, s.Call.Ellipsis.IsValid(), true)
if isBuiltin || isJs {
vars := make([]string, len(s.Call.Args))
callArgs := make([]ast.Expr, len(s.Call.Args))
for i, arg := range s.Call.Args {
v := c.newVariable("_arg")
vars[i] = v
callArgs[i] = c.newIdent(v, c.p.TypeOf(arg))
}
call := c.translateExpr(&ast.CallExpr{
Fun: s.Call.Fun,
Args: callArgs,
Ellipsis: s.Call.Ellipsis,
})
c.Printf("$deferred.push([function(%s) { %s; }, [%s]]);", strings.Join(vars, ", "), call, strings.Join(args, ", "))
return
}
c.Printf("$deferred.push([%s, [%s]]);", c.translateExpr(s.Call.Fun), strings.Join(args, ", "))
开发者ID:pombredanne,项目名称:camlistore,代码行数:66,代码来源:statements.go
注:本文中的go/types.Builtin类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论