1
0
mirror of https://github.com/golang/go synced 2024-10-01 10:28:31 -06:00
Commit Graph

8 Commits

Author SHA1 Message Date
Robert Griesemer
30b1abe2f7 go.tools: fix various typos
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/97920045
2014-05-02 14:38:08 -07:00
Alan Donovan
ced954c167 go.tools/go/types: split Info.Objects map into Defs and Uses.
An identifier X in anonymous struct field struct{X} is both a
definition of a field (*Var) and reference to a type
(*TypeName).  Now that we have split the map, we can capture
both of these aspects.

Interestingly, every client but one was going to extra effort
to iterate over just the uses or just the defs; this
simplifies them.

Also, fix two bug related to tagless switches:
- An entry was being recorded in the Object map for a piece of
  synthetic syntax.
- The "true" identifier was being looked up in the current scope,
  which allowed perverse users to locally redefine it.  Now
  we use the bool (not untyped boolean) constant true, per the
  consequent clarification of the spec (issue 7404).

+ tests.

Fixes golang/go#7276

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/68270044
2014-02-27 13:21:59 -05:00
Alan Donovan
f119874203 go.tools/oracle: improvements to command set and performance.
Command set:
- what: an extremely fast query that parses a single
  file and returns the AST stack, package name and the
  set of query modes that apply to the current selection.
  Intended for GUI tools that need to grey out UI elements.
- definition: shows the definition of an identifier.
- pointsto: the PTA features of 'describe' have been split
  out into their own command.
- describe: with PTA stripped out, the cost is now bounded by
  type checking.

Performance:
- The importer.Config.TypeCheckFuncBodies predicate supports
  setting the 'IgnoreFuncBodies' typechecker flag on a
  per-package basis.  This means we can load dependencies from
  source more quickly if we only need exported types.
  (We avoid gcimport data because it may be absent or stale.)
  This also means we can run type-based queries on packages
  that aren't part of the pointer analysis scope. (Yay.)
- Modes that require only type analysis of the query package
  run a "what" query first, and restrict their analysis scope
  to just that package and its dependencies (sans func
  bodies), making them much faster.
- We call newOracle not oracle.New in Query, so that the
  'needs' bitset isn't ignored (oops!).  This makes the
  non-PTA queries faster.

Also:
- removed vestigial timers junk.
- pos.go: existing position utilties split out into own file.
  Added parsePosFlag utility.
- numerous cosmetic tweaks.

+ very basic tests.

To do in follow-ups:
- sophisticated editor integration of "what".
- better tests.
- refactoring of control flow as described in comment.
- changes to "implements", "describe" commands.
- update design doc + user manual.

R=crawshaw, dominik.honnef
CC=golang-dev, gri
https://golang.org/cl/40630043
2013-12-13 10:04:55 -05:00
Alan Donovan
3a4c0462d8 go.tools/oracle: change -mode argument into subcommand.
e.g. "oracle callgraph <package>"

Also: simplified error handling.
Eliminated oracle.errorf because it prepends "file:line:col: "
to the error message so the main function can't safely prepend "Error: ".
The position wasn't interesting though: it was just -pos, more or less.

R=crawshaw, dominik.honnef, r
CC=golang-dev
https://golang.org/cl/13864044
2013-09-25 14:34:39 -04:00
Alan Donovan
37f76edde8 go.tools/oracle: support -format=xml (for Eclipse)
This CL is mostly a renaming s/json/serial/, abstracting the
oracle package away from any particular data syntax.  (The
encoding/* machinery is very clean; clearly I should have
structured it this way from the outset.)

Supporting XML then becomes a one-liner in cmd/oracle/main.go.

Also: call MarshalIndent(), not Marshall() then Indent().

R=crawshaw
CC=golang-dev
https://golang.org/cl/13858046
2013-09-24 15:08:14 -04:00
Alan Donovan
25a0cc4bfd go.tools/oracle: refactor Oracle API to allow repeated queries on same scope.
The existing standalone Query function builds an importer, ssa.Program, oracle,
and query position, executes the query and returns the result.
For clients (such as Frederik Zipp's web-based github.com/fzipp/pythia tool)
that wish to load the program once and make several queries, we now expose
these as separate operations too.  Here's a client, in pseudocode:

        o := oracle.New(...)
        for ... {
                qpos := o.ParseQueryPos(...)
                res := o.Query(mode, qpos)
                print result
        }

NB: this is a slight deoptimisation in the one-shot case since we have to
build the entire SSA program with debug info, not just the query package,
since we now don't know the query package at that time.

The 'exact' param to ParseQueryPos needs more thought since its
ideal value is a function of the query mode.  This will do for now.

Details:
- expose Oracle type, New() func and Query() method.
- expose QueryPos type and ParseQueryPos func.
- improved package doc comment.
- un-exposed the "needs" bits.
- added test.

R=crawshaw
CC=frederik.zipp, golang-dev
https://golang.org/cl/13810043
2013-09-23 15:02:18 -04:00
Robert Griesemer
1928c01286 go.tools/go/types: separate package descriptor from package object
Includes changes by adonovan to make oracle work again
(former CL 13395050).

R=adonovan
CC=golang-dev
https://golang.org/cl/13672044
2013-09-13 09:52:57 -07:00
Alan Donovan
0725e5a5b3 go.tools/oracle: new query 'referrers' returns all references to an identifier.
+ test.

Also:
- provide non-nil map to Importer.doImport0() to avoid a crash.
- reorganize oracle "needs" bits.
- reduce "needs" of 'freevars' and 'implements' queries by avoiding
  ssa.Packages when types.Package suffices.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13421046
2013-09-10 14:11:42 -04:00