本文整理汇总了Golang中go/ast.Decl.AddChild方法的典型用法代码示例。如果您正苦于以下问题:Golang Decl.AddChild方法的具体用法?Golang Decl.AddChild怎么用?Golang Decl.AddChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/ast.Decl
的用法示例。
在下文中一共展示了Decl.AddChild方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: appendToTopDecls
func appendToTopDecls(decls map[string]*Decl, decl ast.Decl, scope *Scope) {
foreachDecl(decl, func(data *foreachDeclStruct) {
class := astDeclClass(data.decl)
for i, name := range data.names {
typ, v, vi := data.typeValueIndex(i, 0)
d := NewDecl2(name.Name, class, 0, typ, v, vi, scope)
if d == nil {
return
}
methodof := MethodOf(decl)
if methodof != "" {
decl, ok := decls[methodof]
if ok {
decl.AddChild(d)
} else {
decl = NewDecl(methodof, DECL_METHODS_STUB, scope)
decls[methodof] = decl
decl.AddChild(d)
}
} else {
decl, ok := decls[d.Name]
if ok {
decl.ExpandOrReplace(d)
} else {
decls[d.Name] = d
}
}
}
})
}
示例2: processDecl
func (self *PackageFile) processDecl(decl ast.Decl) {
if self.scope != self.filescope {
if t, ok := decl.(*ast.GenDecl); ok && t.Offset > self.cursor {
return
}
}
decls := splitDecls(decl)
for _, decl := range decls {
names := declNames(decl)
values := declValues(decl)
for i, name := range names {
var value ast.Expr = nil
valueindex := -1
if values != nil {
if len(values) > 1 {
value = values[i]
} else {
value = values[0]
valueindex = i
}
}
d := NewDeclFromAstDecl(name, 0, decl, value, valueindex, self.scope)
if d == nil {
continue
}
methodof := MethodOf(decl)
if methodof != "" {
decl, ok := self.decls[methodof]
if ok {
decl.AddChild(d)
} else {
decl = NewDecl(methodof, DECL_METHODS_STUB, self.scope)
self.decls[methodof] = decl
decl.AddChild(d)
}
} else {
if self.scope != self.filescope {
// the declaration itself has a scope which follows it's definition
// and it's false for type declarations
if d.Class != DECL_TYPE {
self.scope = NewScope(self.scope)
self.topscope = self.scope
}
self.scope.addNamedDecl(d)
} else {
self.addVarDecl(d)
}
}
}
}
}
示例3: addAstDeclToPackage
func addAstDeclToPackage(pkg *Decl, decl ast.Decl, scope *Scope) {
foreachDecl(decl, func(data *foreachDeclStruct) {
class := astDeclClass(data.decl)
for i, name := range data.names {
typ, v, vi := data.typeValueIndex(i, DECL_FOREIGN)
d := NewDecl2(name.Name, class, DECL_FOREIGN, typ, v, vi, scope)
if d == nil {
return
}
if !name.IsExported() && d.Class != DECL_TYPE {
return
}
methodof := MethodOf(data.decl)
if methodof != "" {
decl := pkg.FindChild(methodof)
if decl != nil {
decl.AddChild(d)
} else {
decl = NewDecl(methodof, DECL_METHODS_STUB, scope)
decl.AddChild(d)
pkg.AddChild(decl)
}
} else {
decl := pkg.FindChild(d.Name)
if decl != nil {
decl.ExpandOrReplace(d)
} else {
pkg.AddChild(d)
}
}
}
})
}