Exemplo n.º 1
0
Arquivo: code.go Projeto: romana/core
func (a *Analyzer) Analyze() error {
	f, err := os.Open(a.srcDir)
	if err != nil {
		return err
	}
	info, err := f.Stat()
	if err != nil {
		return err
	}
	err = f.Close()
	if !info.IsDir() {
		return errors.New(fmt.Sprintf("Expected %s to be a directory", a.srcDir))
	}
	err = filepath.Walk(a.srcDir, a.walker)
	if err != nil {
		return err
	}
	log.Printf("Visited:\n%s", a.analyzed)

	lprog, err := a.conf.Load()
	if lprog == nil {
		return err
	}
	log.Printf("Loaded program: %v, Error: %T %v", lprog, err, err)

	for _, pkg := range lprog.InitialPackages() {
		for k, v := range pkg.Types {
			log.Printf("%v ==> %+v", k, v)
		}

		scope := pkg.Pkg.Scope()
		for _, n := range scope.Names() {
			obj := scope.Lookup(n)
			log.Printf("Type: Type: %s: %s ", obj.Type().String(), obj.Id())
			a.objects = append(a.objects, obj)
		}
	}

	ssaProg := ssautil.CreateProgram(lprog, ssa.BuilderMode(ssa.GlobalDebug))
	ssaProg.Build()

	for _, p := range a.docPackages {
		for _, t := range p.Types {
			log.Printf("\n****\n%+v\n****\n", t)
		}
	}
	return nil
}
Exemplo n.º 2
0
	"go/build"
	"go/types"
	"os"
	"runtime"
	"runtime/pprof"

	"golang.org/x/tools/go/buildutil"
	"golang.org/x/tools/go/loader"
	"golang.org/x/tools/go/ssa"
	"golang.org/x/tools/go/ssa/interp"
	"golang.org/x/tools/go/ssa/ssautil"
)

// flags
var (
	mode = ssa.BuilderMode(0)

	testFlag = flag.Bool("test", false, "Loads test code (*_test.go) for imported packages.")

	runFlag = flag.Bool("run", false, "Invokes the SSA interpreter on the program.")

	interpFlag = flag.String("interp", "", `Options controlling the SSA test interpreter.
The value is a sequence of zero or more more of these letters:
R	disable [R]ecover() from panic; show interpreter crash instead.
T	[T]race execution of the program.  Best for single-threaded programs!
`)

	cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
)

func init() {