go.types/ssa: inline all calls to objKind().

R=gri
CC=golang-dev
https://golang.org/cl/9740052
This commit is contained in:
Alan Donovan 2013-05-30 12:13:42 -04:00
parent 6c7ce1c2d3
commit 4e0d6858c8
3 changed files with 10 additions and 28 deletions

View File

@ -826,10 +826,10 @@ func (b *Builder) expr(fn *Function, e ast.Expr) Value {
obj := fn.Pkg.ObjectOf(e)
// Global or universal?
if v, ok := b.lookup(fn.Pkg, obj); ok {
if objKind(obj) == ast.Var {
v = emitLoad(fn, v) // var (address)
if _, ok := obj.(*types.Var); ok {
return emitLoad(fn, v) // var (address)
}
return v
return v // (func)
}
// Local?
return emitLoad(fn, fn.lookup(obj, false)) // var (address)
@ -2560,8 +2560,6 @@ func (b *Builder) createPackageImpl(typkg *types.Package, importPath string, fil
if len(files) > 0 {
// Go source package.
// TODO(gri): make it a typechecker error for there to
// be duplicate (e.g.) main functions in the same package.
for _, file := range p.Files {
for _, decl := range file.Decls {
b.membersFromDecl(p, decl)
@ -2619,8 +2617,7 @@ func (b *Builder) buildDecl(pkg *Package, decl ast.Decl) {
if isBlankIdent(id) {
continue
}
obj := pkg.ObjectOf(id).(*types.TypeName)
nt := obj.Type().(*types.Named)
nt := pkg.ObjectOf(id).Type().(*types.Named)
nt.ForEachMethod(func(m *types.Func) {
b.buildFunction(b.Prog.concreteMethods[m])
})

View File

@ -65,12 +65,14 @@ func (info *TypeInfo) IsType(e ast.Expr) bool {
switch e := e.(type) {
case *ast.SelectorExpr: // pkg.Type
if obj := info.isPackageRef(e); obj != nil {
return objKind(obj) == ast.Typ
_, isType := obj.(*types.TypeName)
return isType
}
case *ast.StarExpr: // *T
return info.IsType(e.X)
case *ast.Ident:
return objKind(info.ObjectOf(e)) == ast.Typ
_, isType := info.ObjectOf(e).(*types.TypeName)
return isType
case *ast.ArrayType, *ast.StructType, *ast.FuncType, *ast.InterfaceType, *ast.MapType, *ast.ChanType:
return true
case *ast.ParenExpr:
@ -86,8 +88,8 @@ func (info *TypeInfo) IsType(e ast.Expr) bool {
//
func (info *TypeInfo) isPackageRef(sel *ast.SelectorExpr) types.Object {
if id, ok := sel.X.(*ast.Ident); ok {
if obj := info.ObjectOf(id); objKind(obj) == ast.Pkg {
return obj.(*types.Package).Scope().Lookup(sel.Sel.Name)
if pkg, ok := info.ObjectOf(id).(*types.Package); ok {
return pkg.Scope().Lookup(sel.Sel.Name)
}
}
return nil

View File

@ -101,23 +101,6 @@ outer:
return true
}
// objKind returns the syntactic category of the named entity denoted by obj.
func objKind(obj types.Object) ast.ObjKind {
switch obj.(type) {
case *types.Package:
return ast.Pkg
case *types.TypeName:
return ast.Typ
case *types.Const:
return ast.Con
case *types.Var:
return ast.Var
case *types.Func:
return ast.Fun
}
panic(fmt.Sprintf("unexpected Object type: %T", obj))
}
// canHaveConcreteMethods returns true iff typ may have concrete
// methods associated with it. Callers must supply allowPtr=true.
//