示例#1
0
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
0
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)
				}
			}
		}
	})
}