aboutsummaryrefslogtreecommitdiff
path: root/oracle
diff options
context:
space:
mode:
authorAlan Donovan <adonovan@google.com>2014-07-11 10:50:09 +0100
committerAlan Donovan <adonovan@google.com>2014-07-11 10:50:09 +0100
commitf2db24a319eae4c252712e9616927ece673bdbb6 (patch)
treeacd52b2576187412be7d523c3ccc3243dff7bfb8 /oracle
parent961ab3ca8da85b939bda5b0ae5f8d0bb442a038a (diff)
downloadtools-f2db24a319eae4c252712e9616927ece673bdbb6.tar.gz
go.tools/go/loader: use new types.TypeAndValue mode predicates.
PackageInfo: - deleted IsType - inlined + deleted: ValueOf, TypeCaseVar, ImportSpecPkg - on failure, TypeOf accessor now returns nil (was: panic) go/ssa: avoid extra map lookups by using Uses or Defs directly when safe to do so, and keeping the TypeAndValue around in expr0(). LGTM=gri R=gri, pcc CC=golang-codereviews https://golang.org/cl/107650043
Diffstat (limited to 'oracle')
-rw-r--r--oracle/callees.go4
-rw-r--r--oracle/describe.go25
-rw-r--r--oracle/freevars.go8
3 files changed, 20 insertions, 17 deletions
diff --git a/oracle/callees.go b/oracle/callees.go
index a900b7b..8584403 100644
--- a/oracle/callees.go
+++ b/oracle/callees.go
@@ -38,13 +38,13 @@ func callees(o *Oracle, qpos *QueryPos) (queryResult, error) {
// not what the user intended.
// Reject type conversions.
- if qpos.info.IsType(e.Fun) {
+ if qpos.info.Types[e.Fun].IsType() {
return nil, fmt.Errorf("this is a type conversion, not a function call")
}
// Reject calls to built-ins.
if id, ok := unparen(e.Fun).(*ast.Ident); ok {
- if b, ok := qpos.info.ObjectOf(id).(*types.Builtin); ok {
+ if b, ok := qpos.info.Uses[id].(*types.Builtin); ok {
return nil, fmt.Errorf("this is a call to the built-in '%s' operator", b.Name())
}
}
diff --git a/oracle/describe.go b/oracle/describe.go
index 149172c..26a81b9 100644
--- a/oracle/describe.go
+++ b/oracle/describe.go
@@ -9,6 +9,7 @@ import (
"fmt"
"go/ast"
"go/token"
+ "log"
"os"
"strings"
@@ -180,7 +181,8 @@ func findInterestingNode(pkginfo *loader.PackageInfo, path []ast.Node) ([]ast.No
return path, actionExpr
case *ast.SelectorExpr:
- if pkginfo.ObjectOf(n.Sel) == nil {
+ // TODO(adonovan): use Selections info directly.
+ if pkginfo.Uses[n.Sel] == nil {
// TODO(adonovan): is this reachable?
return path, actionUnknown
}
@@ -267,15 +269,15 @@ func findInterestingNode(pkginfo *loader.PackageInfo, path []ast.Node) ([]ast.No
return path[1:], actionPackage
default:
- // e.g. blank identifier (go/types bug?)
- // or y in "switch y := x.(type)" (go/types bug?)
+ // e.g. blank identifier
+ // or y in "switch y := x.(type)"
// or code in a _test.go file that's not part of the package.
- fmt.Printf("unknown reference %s in %T\n", n, path[1])
+ log.Printf("unknown reference %s in %T\n", n, path[1])
return path, actionUnknown
}
case *ast.StarExpr:
- if pkginfo.IsType(n) {
+ if pkginfo.Types[n].IsType() {
return path, actionType
}
return path, actionExpr
@@ -311,7 +313,7 @@ func describeValue(o *Oracle, qpos *QueryPos, path []ast.Node) (*describeValueRe
}
typ := qpos.info.TypeOf(expr)
- constVal := qpos.info.ValueOf(expr)
+ constVal := qpos.info.Types[expr].Value
return &describeValueResult{
qpos: qpos,
@@ -497,7 +499,12 @@ func describePackage(o *Oracle, qpos *QueryPos, path []ast.Node) (*describePacka
var pkg *types.Package
switch n := path[0].(type) {
case *ast.ImportSpec:
- pkgname := qpos.info.ImportSpecPkg(n)
+ var pkgname *types.PkgName
+ if n.Name != nil {
+ pkgname = qpos.info.Defs[n.Name].(*types.PkgName)
+ } else if p := qpos.info.Implicits[n]; p != nil {
+ pkgname = p.(*types.PkgName)
+ }
description = fmt.Sprintf("import of package %q", pkgname.Pkg().Path())
pkg = pkgname.Pkg()
@@ -507,7 +514,7 @@ func describePackage(o *Oracle, qpos *QueryPos, path []ast.Node) (*describePacka
pkg = qpos.info.Pkg
description = fmt.Sprintf("definition of package %q", pkg.Path())
} else {
- // e.g. import id
+ // e.g. import id "..."
// or id.F()
pkg = qpos.info.ObjectOf(n).Pkg()
description = fmt.Sprintf("reference to package %q", pkg.Path())
@@ -662,7 +669,7 @@ func describeStmt(o *Oracle, qpos *QueryPos, path []ast.Node) (*describeStmtResu
var description string
switch n := path[0].(type) {
case *ast.Ident:
- if qpos.info.ObjectOf(n).Pos() == n.Pos() {
+ if qpos.info.Defs[n] != nil {
description = "labelled statement"
} else {
description = "reference to labelled statement"
diff --git a/oracle/freevars.go b/oracle/freevars.go
index a142d15..5582318 100644
--- a/oracle/freevars.go
+++ b/oracle/freevars.go
@@ -51,17 +51,13 @@ func freevars(o *Oracle, qpos *QueryPos) (queryResult, error) {
}
id = func(n *ast.Ident) types.Object {
- obj := qpos.info.ObjectOf(n)
+ obj := qpos.info.Uses[n]
if obj == nil {
- return nil // TODO(adonovan): fix: this fails for *types.Label.
- panic("no types.Object for ast.Ident")
+ return nil // not a reference
}
if _, ok := obj.(*types.PkgName); ok {
return nil // imported package
}
- if n.Pos() == obj.Pos() {
- return nil // this ident is the definition, not a reference
- }
if !(file.Pos() <= obj.Pos() && obj.Pos() <= file.End()) {
return nil // not defined in this file
}