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

View File

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

View File

@ -480,7 +480,7 @@ func (f *Function) fullName(from *Package) string {
// Package-level function. // Package-level function.
// Prefix with package name for cross-package references only. // Prefix with package name for cross-package references only.
if from != f.Pkg { 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 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) { func (f *Function) DumpTo(w io.Writer) {
fmt.Fprintf(w, "# Name: %s\n", f.String()) fmt.Fprintf(w, "# Name: %s\n", f.String())
if pos := f.Pos(); pos.IsValid() { 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 { } else {
fmt.Fprintln(w, "# Synthetic") 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 { func callSSA(i *interpreter, caller *frame, callpos token.Pos, fn *ssa.Function, args []value, env []value) value {
if i.mode&EnableTracing != 0 { if i.mode&EnableTracing != 0 {
fset := fn.Prog.Files fset := fn.Prog.Fset
// TODO(adonovan): fix: loc() lies for external functions. // TODO(adonovan): fix: loc() lies for external functions.
fmt.Fprintf(os.Stderr, "Entering %s%s.\n", fn, loc(fset, fn.Pos())) fmt.Fprintf(os.Stderr, "Entering %s%s.\n", fn, loc(fset, fn.Pos()))
suffix := "" suffix := ""
@ -526,7 +526,7 @@ func setGlobal(i *interpreter, pkg *ssa.Package, name string, v value) {
*g = v *g = v
return 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. // 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) initReflect(i)
for importPath, pkg := range i.prog.Packages { for importPath, pkg := range i.prog.PackagesByPath {
// Initialize global storage. // Initialize global storage.
for _, m := range pkg.Members { for _, m := range pkg.Members {
switch v := m.(type) { 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) { func initReflect(i *interpreter) {
i.reflectPackage = &ssa.Package{ i.reflectPackage = &ssa.Package{
Prog: i.prog, Prog: i.prog,
Types: reflectTypesPackage, Object: reflectTypesPackage,
Members: make(map[string]ssa.Member), Members: make(map[string]ssa.Member),
} }

View File

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

View File

@ -486,7 +486,7 @@ func indirectionWrapper(meth *Function) *Function {
} }
s := meth.Signature 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())) types.NewPointer(s.Recv().Type()))
fn = &Function{ fn = &Function{
name: meth.Name(), 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) { 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 importPath, info := range imp.Packages {
for _, f := range info.Files { for _, f := range info.Files {
if !tokenFileContainsPos(prog.Files.File(f.Package), start) { if !tokenFileContainsPos(prog.Fset.File(f.Package), start) {
continue continue
} }
if path, exact := PathEnclosingInterval(f, start, end); path != nil { 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. // A Program is a partial or complete Go program converted to SSA form.
// //
type Program struct { type Program struct {
Files *token.FileSet // position information for the files of this Program [TODO: rename Fset] Fset *token.FileSet // position information for the files of this Program
Packages map[string]*Package // all loaded Packages, keyed by import path [TODO rename packagesByPath] PackagesByPath map[string]*Package // all loaded Packages, keyed by import path
packages map[*types.Package]*Package // all loaded Packages, keyed by object [TODO rename Packages] packages map[*types.Package]*Package // all loaded Packages, keyed by object
Builtins map[types.Object]*Builtin // all built-in functions, keyed by typechecker objects. 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 concreteMethods map[*types.Func]*Function // maps named concrete methods to their code
mode BuilderMode // set of mode bits for SSA construction mode BuilderMode // set of mode bits for SSA construction
@ -38,7 +38,7 @@ type Program struct {
// //
type Package struct { type Package struct {
Prog *Program // the owning program 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 Members map[string]Member // all package members keyed by name
values map[types.Object]Value // package-level vars and funcs, keyed by object values map[types.Object]Value // package-level vars and funcs, keyed by object
Init *Function // the package's (concatenated) init function Init *Function // the package's (concatenated) init function
@ -1400,7 +1400,7 @@ func (prog *Program) Value(obj types.Object) Value {
} }
return nil return nil
} }
return prog.Builtins[obj] return prog.builtins[obj]
} }
// Package returns the SSA package corresponding to the specified // Package returns the SSA package corresponding to the specified