go.tools/ssa: some renamings.

- Prog.Files -> Fset
- Prog.Packages -> PackagesByPath
- Prog.Builtins -> builtins
- Package.Types -> Object

R=gri
CC=golang-dev
https://golang.org/cl/10748043
This commit is contained in:
Alan Donovan 2013-07-01 15:24:50 -04:00
parent c24b2413c0
commit 6ae930a01c
9 changed files with 37 additions and 37 deletions

View File

@ -335,7 +335,7 @@ func (b *builder) builtin(fn *Function, name string, args []ast.Expr, typ types.
//
func (b *builder) selectField(fn *Function, e *ast.SelectorExpr, wantAddr, escaping bool) Value {
tx := fn.Pkg.typeOf(e.X)
obj, indices, isIndirect := types.LookupFieldOrMethod(tx, fn.Pkg.Types, e.Sel.Name)
obj, indices, isIndirect := types.LookupFieldOrMethod(tx, fn.Pkg.Object, e.Sel.Name)
if obj == nil {
panic("field not found: " + e.Sel.Name)
}
@ -552,7 +552,7 @@ func (b *builder) expr(fn *Function, e ast.Expr) Value {
panic("non-constant BasicLit") // unreachable
case *ast.FuncLit:
posn := fn.Prog.Files.Position(e.Type.Func)
posn := fn.Prog.Fset.Position(e.Type.Func)
fn2 := &Function{
name: fmt.Sprintf("func@%d.%d", posn.Line, posn.Column),
Signature: fn.Pkg.typeOf(e.Type).Underlying().(*types.Signature),
@ -606,7 +606,7 @@ func (b *builder) expr(fn *Function, e ast.Expr) Value {
// Call to "intrinsic" built-ins, e.g. new, make, panic.
if id, ok := e.Fun.(*ast.Ident); ok {
obj := fn.Pkg.objectOf(id)
if _, ok := fn.Prog.Builtins[obj]; ok {
if _, ok := fn.Prog.builtins[obj]; ok {
if v := b.builtin(fn, id.Name, e.Args, typ, e.Lparen); v != nil {
return v
}
@ -682,7 +682,7 @@ func (b *builder) expr(fn *Function, e ast.Expr) Value {
obj := fn.Pkg.objectOf(e)
// Universal built-in?
if obj.Pkg() == nil {
return fn.Prog.Builtins[obj]
return fn.Prog.builtins[obj]
}
// Package-level func or var?
if v := b.lookup(fn.Pkg, obj); v != nil {
@ -700,7 +700,7 @@ func (b *builder) expr(fn *Function, e ast.Expr) Value {
return b.expr(fn, e.Sel)
}
id := MakeId(e.Sel.Name, fn.Pkg.Types)
id := MakeId(e.Sel.Name, fn.Pkg.Object)
// (*T).f or T.f, the method f from the method-set of type T.
if fn.Pkg.info.IsType(e.X) {
@ -857,7 +857,7 @@ func (b *builder) setCallFunc(fn *Function, e *ast.CallExpr, c *CallCommon) {
return
}
id := MakeId(sel.Sel.Name, fn.Pkg.Types)
id := MakeId(sel.Sel.Name, fn.Pkg.Object)
// Let X be the type of x.
@ -1746,7 +1746,7 @@ func (b *builder) rangeIndexed(fn *Function, x Value, tv types.Type) (k, v Value
} else {
// length = len(x).
var c Call
c.Call.Func = fn.Prog.Builtins[types.Universe.Lookup(nil, "len")]
c.Call.Func = fn.Prog.builtins[types.Universe.Lookup(nil, "len")]
c.Call.Args = []Value{x}
c.setType(tInt)
length = fn.emit(&c)
@ -2222,7 +2222,7 @@ func (b *builder) buildFunction(fn *Function) {
return
}
if fn.Prog.mode&LogSource != 0 {
defer logStack("build function %s @ %s", fn, fn.Prog.Files.Position(fn.pos))()
defer logStack("build function %s @ %s", fn, fn.Prog.Fset.Position(fn.pos))()
}
fn.startBody()
fn.createSyntacticParams()
@ -2272,7 +2272,7 @@ func (b *builder) buildDecl(pkg *Package, decl ast.Decl) {
} else if id.Name == "init" {
// init() block
if pkg.Prog.mode&LogSource != 0 {
fmt.Fprintln(os.Stderr, "build init block @", pkg.Prog.Files.Position(decl.Pos()))
fmt.Fprintln(os.Stderr, "build init block @", pkg.Prog.Fset.Position(decl.Pos()))
}
init := pkg.Init
@ -2308,7 +2308,7 @@ func (b *builder) buildDecl(pkg *Package, decl ast.Decl) {
//
func (prog *Program) BuildAll() {
var wg sync.WaitGroup
for _, p := range prog.Packages {
for _, p := range prog.PackagesByPath {
if prog.mode&BuildSerially != 0 {
p.Build()
} else {
@ -2391,7 +2391,7 @@ func (p *Package) objectOf(id *ast.Ident) types.Object {
return o
}
panic(fmt.Sprintf("no types.Object for ast.Ident %s @ %s",
id.Name, p.Prog.Files.Position(id.Pos())))
id.Name, p.Prog.Fset.Position(id.Pos())))
}
// Only valid during p's create and build phases.

View File

@ -35,10 +35,10 @@ const (
//
func NewProgram(fset *token.FileSet, mode BuilderMode) *Program {
prog := &Program{
Files: fset,
Packages: make(map[string]*Package),
Fset: fset,
PackagesByPath: make(map[string]*Package),
packages: make(map[*types.Package]*Package),
Builtins: make(map[types.Object]*Builtin),
builtins: make(map[types.Object]*Builtin),
methodSets: make(map[types.Type]MethodSet),
concreteMethods: make(map[*types.Func]*Function),
indirectionWrappers: make(map[*Function]*Function),
@ -50,7 +50,7 @@ func NewProgram(fset *token.FileSet, mode BuilderMode) *Program {
// Create Values for built-in functions.
for i, n := 0, types.Universe.NumEntries(); i < n; i++ {
if obj, ok := types.Universe.At(i).(*types.Func); ok {
prog.Builtins[obj] = &Builtin{obj}
prog.builtins[obj] = &Builtin{obj}
}
}
@ -134,7 +134,7 @@ func memberFromObject(pkg *Package, obj types.Object, syntax ast.Node) {
// Method declaration.
_, method := namedTypeMethodIndex(
recv.Type().Deref().(*types.Named),
MakeId(name, pkg.Types))
MakeId(name, pkg.Object))
pkg.Prog.concreteMethods[method] = fn
}
@ -203,7 +203,7 @@ func createPackage(prog *Program, importPath string, info *importer.PackageInfo)
Prog: prog,
Members: make(map[string]Member),
values: make(map[types.Object]Value),
Types: info.Pkg,
Object: info.Pkg,
info: info, // transient (CREATE and BUILD phases)
}
@ -228,7 +228,7 @@ func createPackage(prog *Program, importPath string, info *importer.PackageInfo)
// GC-compiled binary package.
// No code.
// No position information.
scope := p.Types.Scope()
scope := p.Object.Scope()
for i, n := 0, scope.NumEntries(); i < n; i++ {
memberFromObject(p, scope.At(i), nil)
}
@ -246,6 +246,6 @@ func createPackage(prog *Program, importPath string, info *importer.PackageInfo)
p.DumpTo(os.Stderr)
}
prog.Packages[importPath] = p
prog.packages[p.Types] = p
prog.PackagesByPath[importPath] = p
prog.packages[p.Object] = p
}

View File

@ -480,7 +480,7 @@ func (f *Function) fullName(from *Package) string {
// Package-level function.
// Prefix with package name for cross-package references only.
if from != f.Pkg {
return fmt.Sprintf("%s.%s", f.Pkg.Types.Path(), f.name)
return fmt.Sprintf("%s.%s", f.Pkg.Object.Path(), f.name)
}
return f.name
}
@ -533,7 +533,7 @@ func writeSignature(w io.Writer, name string, sig *types.Signature, params []*Pa
func (f *Function) DumpTo(w io.Writer) {
fmt.Fprintf(w, "# Name: %s\n", f.String())
if pos := f.Pos(); pos.IsValid() {
fmt.Fprintf(w, "# Declared at %s\n", f.Prog.Files.Position(pos))
fmt.Fprintf(w, "# Declared at %s\n", f.Prog.Fset.Position(pos))
} else {
fmt.Fprintln(w, "# Synthetic")
}

View File

@ -434,7 +434,7 @@ func loc(fset *token.FileSet, pos token.Pos) string {
//
func callSSA(i *interpreter, caller *frame, callpos token.Pos, fn *ssa.Function, args []value, env []value) value {
if i.mode&EnableTracing != 0 {
fset := fn.Prog.Files
fset := fn.Prog.Fset
// TODO(adonovan): fix: loc() lies for external functions.
fmt.Fprintf(os.Stderr, "Entering %s%s.\n", fn, loc(fset, fn.Pos()))
suffix := ""
@ -526,7 +526,7 @@ func setGlobal(i *interpreter, pkg *ssa.Package, name string, v value) {
*g = v
return
}
panic("no global variable: " + pkg.Types.Path() + "." + name)
panic("no global variable: " + pkg.Object.Path() + "." + name)
}
// Interpret interprets the Go program whose main package is mainpkg.
@ -544,7 +544,7 @@ func Interpret(mainpkg *ssa.Package, mode Mode, filename string, args []string)
}
initReflect(i)
for importPath, pkg := range i.prog.Packages {
for importPath, pkg := range i.prog.PackagesByPath {
// Initialize global storage.
for _, m := range pkg.Members {
switch v := m.(type) {

View File

@ -404,7 +404,7 @@ func newMethod(pkg *ssa.Package, recvType types.Type, name string) *ssa.Function
func initReflect(i *interpreter) {
i.reflectPackage = &ssa.Package{
Prog: i.prog,
Types: reflectTypesPackage,
Object: reflectTypesPackage,
Members: make(map[string]ssa.Member),
}

View File

@ -73,7 +73,7 @@ func (v *Function) String() string {
// FullName returns g's package-qualified name.
func (g *Global) FullName() string {
return fmt.Sprintf("%s.%s", g.Pkg.Types.Path(), g.name)
return fmt.Sprintf("%s.%s", g.Pkg.Object.Path(), g.name)
}
// Instruction.String()
@ -356,7 +356,7 @@ func (s *MapUpdate) String() string {
}
func (p *Package) String() string {
return "package " + p.Types.Path()
return "package " + p.Object.Path()
}
func (p *Package) DumpTo(w io.Writer) {

View File

@ -486,7 +486,7 @@ func indirectionWrapper(meth *Function) *Function {
}
s := meth.Signature
recv := types.NewVar(token.NoPos, meth.Pkg.Types, "recv",
recv := types.NewVar(token.NoPos, meth.Pkg.Object, "recv",
types.NewPointer(s.Recv().Type()))
fn = &Function{
name: meth.Name(),

View File

@ -34,11 +34,11 @@ func tokenFileContainsPos(f *token.File, pos token.Pos) bool {
func (prog *Program) PathEnclosingInterval(imp *importer.Importer, start, end token.Pos) (pkg *Package, path []ast.Node, exact bool) {
for importPath, info := range imp.Packages {
for _, f := range info.Files {
if !tokenFileContainsPos(prog.Files.File(f.Package), start) {
if !tokenFileContainsPos(prog.Fset.File(f.Package), start) {
continue
}
if path, exact := PathEnclosingInterval(f, start, end); path != nil {
return prog.Packages[importPath], path, exact
return prog.PackagesByPath[importPath], path, exact
}
}
}

View File

@ -17,10 +17,10 @@ import (
// A Program is a partial or complete Go program converted to SSA form.
//
type Program struct {
Files *token.FileSet // position information for the files of this Program [TODO: rename Fset]
Packages map[string]*Package // all loaded Packages, keyed by import path [TODO rename packagesByPath]
packages map[*types.Package]*Package // all loaded Packages, keyed by object [TODO rename Packages]
Builtins map[types.Object]*Builtin // all built-in functions, keyed by typechecker objects.
Fset *token.FileSet // position information for the files of this Program
PackagesByPath map[string]*Package // all loaded Packages, keyed by import path
packages map[*types.Package]*Package // all loaded Packages, keyed by object
builtins map[types.Object]*Builtin // all built-in functions, keyed by typechecker objects.
concreteMethods map[*types.Func]*Function // maps named concrete methods to their code
mode BuilderMode // set of mode bits for SSA construction
@ -38,7 +38,7 @@ type Program struct {
//
type Package struct {
Prog *Program // the owning program
Types *types.Package // the type checker's package object for this package [TODO rename Object]
Object *types.Package // the type checker's package object for this package
Members map[string]Member // all package members keyed by name
values map[types.Object]Value // package-level vars and funcs, keyed by object
Init *Function // the package's (concatenated) init function
@ -1400,7 +1400,7 @@ func (prog *Program) Value(obj types.Object) Value {
}
return nil
}
return prog.Builtins[obj]
return prog.builtins[obj]
}
// Package returns the SSA package corresponding to the specified