예제 #1
0
func main() {
	var err error
	var p *ast.Object
	var pp []*ast.Object = make([]*ast.Object, 0)

	for _, s := range packages {
		p, err = types.GcImport(imports, s)
		if err != nil {
			panic(err)
		}
		pp = append(pp, p)
	}

	fset := token.NewFileSet()
	for i, pkg := range pp {
		Printf("\n")
		Printf("%s: \n", packages[i])
		Printf("\n")
		Printf("pkg=%#v\n", pkg)
		Printf("\n")
		Printf("pkg.Data=%#v\n", pkg.Data)
		Printf("\n")
		ast.Print(fset, pkg)
		Printf("\n")
		Printf("\n")
	}

}
예제 #2
0
func main() {
	var err error
	var p *ast.Object
	var pp []*ast.Object = make([]*ast.Object, 0)

	Println("package generated")
	Println()

	if len(os.Args) > 1 {
		packages = os.Args[1:]
	} else {
		// Walk the packages directory to find our packages
		filepath.Walk(pkgbasepath, findPackages)
	}
	for _, pack := range packages {
		p, err = types.GcImport(imports, pack)
		if err != nil {
			panic(err)
		}
		pp = append(pp, p)
		snake := strings.Replace(pack, "/", "_", -1)
		snake = strings.Replace(snake, ".", "_", -1)
		snake = strings.Replace(snake, "-", "_", -1)
		Printf("import %s \"%s\"\n", snake, pack)
	}

	Println()
	Println("var Types map[string]interface{} = make(map[string]interface{}, 0)")
	Println("var Funcs map[string]interface{} = make(map[string]interface{}, 0)")
	Println("var Vars map[string]interface{} = make(map[string]interface{}, 0)")
	Println("var Consts map[string]interface{} = make(map[string]interface{}, 0)")

	//Println("type TypeConverter func (interface{}) interface{}")
	//Println("var Converters map[string]TypeConverter = make(map[string]TypeConverter, 0)")

	Println()
	Println("func init() {")

	for i, pkg := range pp {
		if packages[i] == "sort" {
			// ast.Print(nil, pkg)
		}
		Println()
		RemarkScope(packages[i], pkg.Data.(*ast.Scope))
		Println()
		DoScope(packages[i], pkg.Data.(*ast.Scope))
		Println()
	}

	Println("} // END")

	for uk, uv := range Uniq {
		if uv > 1 {
			Printf("//# ! Uniq <%s> %d\n", uk, uv)
		}
	}
}