mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
go.types/ssa: inline all calls to objKind().
R=gri CC=golang-dev https://golang.org/cl/9740052
This commit is contained in:
parent
6c7ce1c2d3
commit
4e0d6858c8
@ -826,10 +826,10 @@ func (b *Builder) expr(fn *Function, e ast.Expr) Value {
|
|||||||
obj := fn.Pkg.ObjectOf(e)
|
obj := fn.Pkg.ObjectOf(e)
|
||||||
// Global or universal?
|
// Global or universal?
|
||||||
if v, ok := b.lookup(fn.Pkg, obj); ok {
|
if v, ok := b.lookup(fn.Pkg, obj); ok {
|
||||||
if objKind(obj) == ast.Var {
|
if _, ok := obj.(*types.Var); ok {
|
||||||
v = emitLoad(fn, v) // var (address)
|
return emitLoad(fn, v) // var (address)
|
||||||
}
|
}
|
||||||
return v
|
return v // (func)
|
||||||
}
|
}
|
||||||
// Local?
|
// Local?
|
||||||
return emitLoad(fn, fn.lookup(obj, false)) // var (address)
|
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 {
|
if len(files) > 0 {
|
||||||
// Go source package.
|
// 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 _, file := range p.Files {
|
||||||
for _, decl := range file.Decls {
|
for _, decl := range file.Decls {
|
||||||
b.membersFromDecl(p, decl)
|
b.membersFromDecl(p, decl)
|
||||||
@ -2619,8 +2617,7 @@ func (b *Builder) buildDecl(pkg *Package, decl ast.Decl) {
|
|||||||
if isBlankIdent(id) {
|
if isBlankIdent(id) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
obj := pkg.ObjectOf(id).(*types.TypeName)
|
nt := pkg.ObjectOf(id).Type().(*types.Named)
|
||||||
nt := obj.Type().(*types.Named)
|
|
||||||
nt.ForEachMethod(func(m *types.Func) {
|
nt.ForEachMethod(func(m *types.Func) {
|
||||||
b.buildFunction(b.Prog.concreteMethods[m])
|
b.buildFunction(b.Prog.concreteMethods[m])
|
||||||
})
|
})
|
||||||
|
@ -65,12 +65,14 @@ func (info *TypeInfo) IsType(e ast.Expr) bool {
|
|||||||
switch e := e.(type) {
|
switch e := e.(type) {
|
||||||
case *ast.SelectorExpr: // pkg.Type
|
case *ast.SelectorExpr: // pkg.Type
|
||||||
if obj := info.isPackageRef(e); obj != nil {
|
if obj := info.isPackageRef(e); obj != nil {
|
||||||
return objKind(obj) == ast.Typ
|
_, isType := obj.(*types.TypeName)
|
||||||
|
return isType
|
||||||
}
|
}
|
||||||
case *ast.StarExpr: // *T
|
case *ast.StarExpr: // *T
|
||||||
return info.IsType(e.X)
|
return info.IsType(e.X)
|
||||||
case *ast.Ident:
|
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:
|
case *ast.ArrayType, *ast.StructType, *ast.FuncType, *ast.InterfaceType, *ast.MapType, *ast.ChanType:
|
||||||
return true
|
return true
|
||||||
case *ast.ParenExpr:
|
case *ast.ParenExpr:
|
||||||
@ -86,8 +88,8 @@ func (info *TypeInfo) IsType(e ast.Expr) bool {
|
|||||||
//
|
//
|
||||||
func (info *TypeInfo) isPackageRef(sel *ast.SelectorExpr) types.Object {
|
func (info *TypeInfo) isPackageRef(sel *ast.SelectorExpr) types.Object {
|
||||||
if id, ok := sel.X.(*ast.Ident); ok {
|
if id, ok := sel.X.(*ast.Ident); ok {
|
||||||
if obj := info.ObjectOf(id); objKind(obj) == ast.Pkg {
|
if pkg, ok := info.ObjectOf(id).(*types.Package); ok {
|
||||||
return obj.(*types.Package).Scope().Lookup(sel.Sel.Name)
|
return pkg.Scope().Lookup(sel.Sel.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
17
ssa/util.go
17
ssa/util.go
@ -101,23 +101,6 @@ outer:
|
|||||||
return true
|
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
|
// canHaveConcreteMethods returns true iff typ may have concrete
|
||||||
// methods associated with it. Callers must supply allowPtr=true.
|
// methods associated with it. Callers must supply allowPtr=true.
|
||||||
//
|
//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user