示例#1
0
文件: gortfm.go 项目: nsf/gortfm
func main() {
	flag.Parse()

	if !*optNoShared {
		writeSharedDir()
	}

	fset := token.NewFileSet()
	pkgs, err := parser.ParseFiles(fset, flag.Args(), parser.ParseComments)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	pkg := getOnlyPkg(pkgs)
	if pkg != nil {
		if *optNiceName == "" {
			*optNiceName = pkg.Name
		}

		ast.PackageExports(pkg)

		docs := doce.NewPackage(pkg, fset)
		writePackage(docs, *optNiceName)
	}
}
示例#2
0
文件: go.go 项目: droundy/go-compiler
func main() {
	goopt.Parse(func() []string { return nil })
	if len(goopt.Args) > 0 {
		x, err := parser.ParseFiles(myfiles, goopt.Args, 0)
		die(err)
		fmt.Fprintln(os.Stderr, "Parsed: ", *x["main"])
		die(typechecker.CheckPackage(myfiles, x["main"], nil))
		fmt.Fprintln(os.Stderr, "Checked: ", *x["main"])
		//for _,a := range x["main"].Files {
		//	die(printer.Fprint(os.Stdout, a))
		//}

		aaa := x86.StartData
		var bbb *Stack
		var cv = CompileVisitor{&aaa, make(map[string]string), bbb.New("global")}
		ast.Walk(StringVisitor(cv), x["main"])

		cv.Append(x86.StartText...)
		ast.Walk(&cv, x["main"])

		// Here we just add a crude debug library
		cv.Append(x86.Debugging...)
		ass := x86.Assembly(*cv.assembly)
		//fmt.Println(ass)
		die(elf.AssembleAndLink(goopt.Args[0][:len(goopt.Args[0])-3], []byte(ass)))
	}
}
示例#3
0
func getAstTree(srcDir string, specialFiles []string) (*token.FileSet, map[string]*ast.Package, os.Error) {
	fileSet := token.NewFileSet()
	if specialFiles != nil {
		pckgs, err := parser.ParseFiles(fileSet, getFullNameFiles(specialFiles, srcDir), parser.ParseComments)
		return fileSet, pckgs, err
	}
	pckgs, err := parser.ParseDir(fileSet, srcDir, utils.GoFilter, parser.ParseComments)
	return fileSet, pckgs, err

}
示例#4
0
func main() {
	flag.Parse()
	filenames := flag.Args()
	fset := token.NewFileSet()
	pkgMap, firstErr := parser.ParseFiles(fset, filenames, 0)
	if firstErr != nil {
		fmt.Fprintf(os.Stderr, "Error while parsing: %v\n", firstErr)
	}

	v := NewNodeChecker(fset)
	v.InterfaceName = regexp.MustCompile("[Ii][A-Z][A-Za-z]+")
	v.InvalidMethodName = regexp.MustCompile("^Get(.+)") // can't do negative match in Go's regexp?

	for _, pkg := range pkgMap {
		ast.Walk(v, pkg)
	}
}