本文整理汇总了Golang中go/ast.Expr.Value方法的典型用法代码示例。如果您正苦于以下问题:Golang Expr.Value方法的具体用法?Golang Expr.Value怎么用?Golang Expr.Value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/ast.Expr
的用法示例。
在下文中一共展示了Expr.Value方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: MangleExpr
func (sc *PackageScoping) MangleExpr(e ast.Expr) ast.Expr {
switch e := e.(type) {
case *ast.CallExpr:
for i := range e.Args {
e.Args[i] = sc.MangleExpr(e.Args[i])
}
sc.MangleExpr(e.Fun)
if fn, ok := e.Fun.(*ast.Ident); ok {
switch fn.Name {
case "print", "println":
sc.Do("runtime.print")
sc.Do("runtime.print_int")
case "new":
sc.Do("runtime.malloc")
}
}
case *ast.Ident:
if pkg, ok := sc.Globals[e.Name]; ok {
// It's a global identifier, so we need to mangle it...
sc.Do(pkg + "." + e.Name)
oldname := e.Name
e.Name = ManglePackageAndName(pkg, e.Name)
fmt.Println("Name is", e.Name, "from", pkg, oldname)
} else {
// Nothing to do here, it is a local identifier or builtin.
}
case *ast.BasicLit:
// Nothing to do here, a literal is never imported.
case *ast.BinaryExpr:
e.X = sc.MangleExpr(e.X)
e.Y = sc.MangleExpr(e.Y)
// FIXME: We could do better here if we had type information...
switch e.Op {
case token.EQL:
sc.Do("runtime.strings_equal")
case token.NEQ:
sc.Do("runtime.strings_unequal")
}
case *ast.UnaryExpr:
sc.MangleExpr(e.X)
case *ast.ParenExpr:
sc.MangleExpr(e.X)
case *ast.IndexExpr:
e.X = sc.MangleExpr(e.X)
e.Index = sc.MangleExpr(e.Index)
case *ast.SliceExpr:
e.X = sc.MangleExpr(e.X)
e.Low = sc.MangleExpr(e.Low)
e.High = sc.MangleExpr(e.High)
sc.Do("runtime.slice_string")
case *ast.StarExpr:
sc.MangleExpr(e.X)
case *ast.SelectorExpr:
if b, ok := e.X.(*ast.Ident); ok {
if theimp, ok := sc.Imports[b.Name]; ok {
sc.Do(theimp + "." + e.Sel.Name)
e.Sel.Name = ManglePackageAndName(theimp, e.Sel.Name)
return e.Sel
} else {
fmt.Println("not a package: ", b.Name)
fmt.Println("Imports are", sc.Imports)
sc.MangleExpr(e.X)
}
} else {
sc.MangleExpr(e.X)
}
case *ast.StructType:
for _, f := range e.Fields.List {
sc.MangleExpr(f.Type)
}
case *ast.CompositeLit:
e.Type = sc.MangleExpr(e.Type)
for i := range e.Elts {
e.Elts[i] = sc.MangleExpr(e.Elts[i])
}
case *ast.MapType:
e.Key = sc.MangleExpr(e.Key)
e.Value = sc.MangleExpr(e.Value)
case *ast.Ellipsis:
e.Elt = sc.MangleExpr(e.Elt)
case *ast.InterfaceType:
for _, field := range e.Methods.List {
field.Type = sc.MangleExpr(field.Type)
}
case *ast.ArrayType:
e.Len = sc.MangleExpr(e.Len)
e.Elt = sc.MangleExpr(e.Elt)
case *ast.TypeAssertExpr:
e.X = sc.MangleExpr(e.X)
e.Type = sc.MangleExpr(e.Type)
case *ast.FuncType:
for _, field := range e.Params.List {
field.Type = sc.MangleExpr(field.Type)
}
for _, field := range e.Results.List {
field.Type = sc.MangleExpr(field.Type)
}
case *ast.FuncLit:
for _, field := range e.Type.Params.List {
field.Type = sc.MangleExpr(field.Type)
//.........这里部分代码省略.........