go.tools/oracle: set AllASTs=true always, and simplify.
Every one of the oracle's query modes needs to have typed ASTs available, at least transiently, so that the -pos flag can be interpreted. (The only mode that doesn't need the -pos flag is callgraph, but that needs PTA.) So we hard-code it to true. This change fixes a bug in the 'implements' query that causes -pos parsing to fail. (This wasn't exposed by the tests because they are degenerate in that the query always occurs in the main package, which is specified ad-hoc, i.e. as a source file not an import path. That's unfortunate, but this change renders the distinction uninteresting in future.) R=crawshaw, dominik.honnef CC=golang-dev https://golang.org/cl/13334050
This commit is contained in:
parent
c871e361fc
commit
d38c09ed22
|
|
@ -50,14 +50,16 @@ type oracle struct {
|
|||
}
|
||||
|
||||
// A set of bits indicating the analytical requirements of each mode.
|
||||
// Typed ASTs for the queried package are always available.
|
||||
//
|
||||
// Typed ASTs for the whole program are always constructed
|
||||
// transiently; they are retained only for the queried package unless
|
||||
// AllTypeInfo is set.
|
||||
const (
|
||||
Pos = 1 << iota // needs a position
|
||||
ExactPos // needs an exact AST selection; implies Pos
|
||||
AllASTs // needs ASTs (not just object types) for whole program
|
||||
AllTypeInfo // needs to retain type info for all ASTs in the program
|
||||
SSA // needs ssa.Packages for whole program
|
||||
PTA = AllASTs | SSA // needs pointer analysis
|
||||
Pos = 1 << iota // needs a position
|
||||
ExactPos // needs an exact AST selection; implies Pos
|
||||
AllTypeInfo // needs to retain type info for all ASTs in the program
|
||||
SSA // needs ssa.Packages for whole program
|
||||
PTA = SSA // needs pointer analysis
|
||||
)
|
||||
|
||||
type modeInfo struct {
|
||||
|
|
@ -71,10 +73,10 @@ var modes = map[string]modeInfo{
|
|||
"callgraph": modeInfo{PTA, callgraph},
|
||||
"callstack": modeInfo{PTA | Pos, callstack},
|
||||
"describe": modeInfo{PTA | ExactPos, describe},
|
||||
"freevars": modeInfo{AllASTs | Pos, freevars},
|
||||
"freevars": modeInfo{Pos, freevars},
|
||||
"implements": modeInfo{Pos, implements},
|
||||
"peers": modeInfo{PTA | Pos, peers},
|
||||
"referrers": modeInfo{AllTypeInfo | AllASTs | Pos, referrers},
|
||||
"referrers": modeInfo{AllTypeInfo | Pos, referrers},
|
||||
}
|
||||
|
||||
type printfFunc func(pos interface{}, format string, args ...interface{})
|
||||
|
|
@ -132,9 +134,6 @@ func Query(args []string, mode, pos string, ptalog io.Writer, buildContext *buil
|
|||
return nil, fmt.Errorf("invalid mode type: %q", mode)
|
||||
}
|
||||
|
||||
if minfo.needs&AllASTs == 0 {
|
||||
buildContext = nil
|
||||
}
|
||||
imp := importer.New(&importer.Config{Build: buildContext})
|
||||
o := &oracle{
|
||||
prog: ssa.NewProgram(imp.Fset, 0),
|
||||
|
|
|
|||
Loading…
Reference in New Issue