Граф коммитов

5845 Коммитов

Автор SHA1 Сообщение Дата
Robert Griesemer 5efab5e9c0 go.tools/go/types: Use []*Field instead of *Scope for struct fields
This partially reverts a previous change, using a []*Field is a better
representation for struct fields than a *Scope, after all; however
*Fields remain Objects.

Fixes golang/go#5670.

R=adonovan, axwalk
CC=golang-dev
https://golang.org/cl/10207043
2013-06-11 19:54:47 -07:00
Rob Pike 0ca15cc618 go.tools/cmd/cover: add -o outputfile option
Makes it easier to get error output when run from the go tool.

R=adonovan
CC=golang-dev
https://golang.org/cl/10190043
2013-06-11 10:18:55 -07:00
Robert Griesemer 0d2f7d411b go.tools/go/types: fix isAssignable and IsIdentical
- Imported objects that are explicitly exported may have a nil package;
  don't use it for qualified name computation (it's not needed).
- isAssignable must check all possibilities before declaring failure.

Fixes golang/go#5675.

R=adonovan
CC=golang-dev
https://golang.org/cl/10141044
2013-06-11 10:00:00 -07:00
Robert Griesemer 63f3103b6f go.tools/go/types: call Context.Ident for selectors
Fixes golang/go#5669.

R=adonovan
CC=golang-dev
https://golang.org/cl/9714045
2013-06-10 16:42:22 -07:00
Rob Pike 73612ddbfd go.tools/cmd/cover: handle empty select
Putting a coverage counter inside select{} is invalid Go.

R=adonovan
CC=golang-dev
https://golang.org/cl/10175043
2013-06-10 15:58:32 -07:00
Rob Pike ba51e7a586 go.tools/cmd/cover: make -mode=atomic work again
It was broken by a previous simplification. The import was missing.

R=adonovan
CC=golang-dev
https://golang.org/cl/10117045
2013-06-10 10:58:08 -07:00
Rob Pike ab78c3fa10 go.tools/cmd/cover: new tool
This is just the tool proper; stitching into "go test" will be a separate CL.
Tests are missing - they'll come once it's integrated - but it can handle,
perhaps correctly, all of src/pkg/...

The basic approach is to rewrite the source to add annotations that will
track coverage; the rewritten source must of course be compiled and
run after this tool has done its job.

R=adonovan
CC=golang-dev
https://golang.org/cl/10102043
2013-06-06 23:51:51 -07:00
Rob Pike 3402cf10ab go.tools/cmd/vet: verify printf for String and Error implementers
Fixes golang/go#5624.

R=adonovan
CC=gobot, golang-dev, gri
https://golang.org/cl/9657048
2013-06-06 16:05:14 -07:00
Robert Griesemer 221795b447 go.tools/go/types: Factories for all objects
R=adonovan
CC=golang-dev
https://golang.org/cl/9794044
2013-06-04 15:15:41 -04:00
Alan Donovan fc4c97d1f1 go.tools/ssa: refactoring: eliminate Builder from API.
Details:
- builder is now un-exported and is now a per-package entity.
- Package.nTo1Vars is now part of builder, where it belongs.
- CREATE phase code split out into its own file, create.go
- Context type is gone; it had become trivial after the
  Importer refactoring.
- importer.PackageInfo.Imports() now encapsulates iteration
  over imports.

Typical usage is now:
  prog := ssa.NewProgram(imp.Fset, mode)
  prog.CreatePackages(imp)
  prog.BuildAll()

Builder.BuildPackage(Package) is now Package.Build()
Builder.BuildAllPackages() is now Program.BuildAll()

R=iant, gri
CC=golang-dev
https://golang.org/cl/9970044
2013-06-03 16:46:57 -04:00
Alan Donovan 4d628a0312 go.tools/ssa: refactoring to make Builder stateless.
A Builder is now just a Program and a Context.

Details of this CL:
- Builder.imp field removed.
- Builder.globals split up into Package.values and Prog.Builtins.
- Builder.packages  moved to Prog.packages.
- Builder.PackageFor moved to Program.Package(types.Object)
- Program.Lookup() func replaces Builder.globals map.
- also: keep Package.info field around until end of BuildPackage.

Planned follow-ups to eliminate Builder from API:
- split NewBuilder up into NewProgram and Program.CreatePackages(...)
- move Builder.BuildAllPackages -> Program.BuildAll(Context)
- move Builder.BuildPackage -> Package.Build(Context)

R=gri, iant
CC=golang-dev
https://golang.org/cl/9966044
2013-06-03 14:15:19 -04:00
Alan Donovan 1f2812fe9b go.tools/ssa: fix bug in makeBridgeMethod for promoted interfaces.
The method index was hard-coded to zero, which works some of
the time.  Apparently I just forgot to implement the
method-table lookup...

Added regression test.

R=gri
CC=golang-dev
https://golang.org/cl/9916043
2013-05-31 16:36:03 -04:00
Rob Pike 838e9a8987 go.tools/cmd/vet: check indexed arguments in printf
Refactor the printf parser to be easier to understand.

R=gri
CC=golang-dev
https://golang.org/cl/9909043
2013-05-31 16:31:01 -04:00
Alan Donovan be28dbb86f go.types/ssa: split the load/parse/typecheck logic off into a separate package.
PLEASE NOTE: the APIs for both "importer" and "ssa" packages
will continue to evolve and both need some polishing; the key
thing is that this CL splits them.

The go.types/importer package contains contains the Importer,
which takes care of the mechanics of loading a set of packages
and type-checking them.  It exposes for each package a
PackageInfo containing:
- the package's ASTs (i.e. the input to the typechecker)
- the types.Package object
- the memoization of the typechecker callbacks for identifier
  resolution, constant folding and expression type inference.

Method-set computation (and hence bridge-method creation) is
now moved to after creation of all packages: since they are no
longer created in topological order, we can't guarantee the
needed delegate methods exist yet.

ssa.Package no longer has public TypeOf, ObjectOf, ValueOf methods.
The private counterparts are valid only during the build phase.

Also:
- added to go/types an informative error (not crash) for an
  importer() returning nil without error.
- removed Package.Name(), barely needed.
- changed Package.String() slightly.
- flag what looks like a bug in makeBridgeMethod. Will follow up.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/9898043
2013-05-31 16:14:13 -04:00
Robert Griesemer 710a117e33 go.tools/go/types: don't use nil fields and methods
The change for fields is in anticipation of fields
becoming a *Scope.

Pointed out by adonovan.

R=adonovan
CC=golang-dev
https://golang.org/cl/9874049
2013-05-31 12:02:33 -07:00
Robert Griesemer e5f49b1c9f go.tools/go/types: typecheck call arguments even if the call doesn't typecheck
This provides better partial type information in case of type errors.

R=r
CC=golang-dev
https://golang.org/cl/9835049
2013-05-31 11:22:00 -07:00
Robert Griesemer 3cad037e2f go.tools/go/types: replace ObjSet with improved Scope
- First step towards unified use of scopes. Will enable
  further simplifications.

- Removed various ForEach iterators in favor of the existing
  accessor methods, for a thinner API.

- Renamed outer/Outer to parent/Parent for scopes.

- Removed check.lookup in favor of Scope.LookupParent.

R=adonovan
CC=golang-dev
https://golang.org/cl/9862044
2013-05-30 21:58:14 -07:00
Rob Pike 291b2c84b6 go.tools/cmd/vet: prepare print format checker for indexed arguments
Rewrite the checker to be more flexible and better documented, being
more explicit about parsed format vs. checked arguments.
No attempt yet to do check indexed formats; this just paves the way.
All tests still pass.

R=gri
CC=golang-dev
https://golang.org/cl/9881044
2013-05-30 14:26:22 -04:00
Alan Donovan 18f85da60d go.tools/ssa: fix breakage caused by CL 9839045 to go/types.
This removes the ast.CaseClase hack for implicit variables.

R=gri
CC=golang-dev
https://golang.org/cl/9863045
2013-05-30 13:18:07 -04:00
Robert Griesemer faef64e271 go.tools/go/types: support for Context.ImplicitObj callbacks
Also:
- more cleanup of new identifier resolution code
- removed residue Object.Pos() code
- two separate, equally formatted error messages for redeclaration
  errors for easier tool support
- initial support for labels
- enabled several disabled tests

Thic CL will break go.tools/ssa/interp, but the pending
CL 9863045 fixes that.

Fixes golang/go#5504.

R=adonovan
CC=golang-dev
https://golang.org/cl/9839045
2013-05-30 09:50:44 -07:00
Alan Donovan 4e0d6858c8 go.types/ssa: inline all calls to objKind().
R=gri
CC=golang-dev
https://golang.org/cl/9740052
2013-05-30 12:13:42 -04:00
Alan Donovan 6c7ce1c2d3 go.tools/ssa: Value.Pos() method + remaining source position plumbing.
Implement Pos() method for
  Values:       Parameter, Capture, Phi.  (Not Literal, Builtin.)
  Instructions: UnOp, BinOp, Store.

'address' (an lvalue) now needs position of '*' in "*addr".

Also:
- Un-export fields Pos_ Type_ Name_ Block_ from various values/instructions.
  Define NewFunction() as a temporary measure.
  Will try to eliminate calls from clients...
- Remove Implements{Value,Member,Interface} marker methods.
  I've decided I don't like them.
- Func.addParamObj helper.
- Various comment fixes.

R=gri
CC=golang-dev
https://golang.org/cl/9740046
2013-05-30 09:59:17 -04:00
Rob Pike d6c1c75eab go.tools/cmd/vet: say ./testvet instead of testvet
I bet "." is not in the default PATH.

R=golang-dev, minux.ma
CC=golang-dev
https://golang.org/cl/9867043
2013-05-29 15:00:51 -04:00
Rob Pike f91ca66179 go.tools/cmd/vet: attempt to fix build
Can't reproduce the failure outside the builder, but attempt a fix
by changing the criterion for failure: FAIL iff the output contains "BUG".

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/9798050
2013-05-29 11:28:19 -04:00
Rob Pike 2b48cfca08 cmd/vet: use length of output from errchk to check PASS/FAIL
errchk is itself a FAIL: it doesn't exit non-zero on error!

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/9842044
2013-05-28 16:51:47 -04:00
Rob Pike c7f7fa1381 cmd/vet: simplify format checker
Simplify the code a bit, get it working after recent go/types changes,
and handle "%*%" just in case. Preparation for handling argument indexing.

R=gri
CC=golang-dev
https://golang.org/cl/9747045
2013-05-28 15:37:34 -04:00
Alan Donovan 20029fe5f7 go.tools/ssa: utility functions mapping source intervals to ast.Nodes.
PathEnclosingInterval: 	maps a source position to an ast.Node.
EnclosingFunction:   	finds ssa.Function enclosing an ast.Node.
HasEnclosingFunction:   cheaper impl of EnclosingFunction()!=nil
NodeDescription:        user friendly node type descriptions.

+ tests.

Also: make ssa.Package.TypeInfo field a pointer.

R=gri, r
CC=golang-dev
https://golang.org/cl/9639045
2013-05-28 15:28:46 -04:00
Robert Griesemer b52cce75f3 adonovan: first round of cleanups: remove 'resolve' internal flag and respective dead code
No other changes besides documentation updates for now.

R=golang-dev, adonovan
CC=golang-dev
https://golang.org/cl/9780045
2013-05-28 11:39:15 -07:00
Robert Griesemer 5c2bbcb0fd go.tools/go/types: enable resolution of objects in type checker
R=adonovan
CC=golang-dev
https://golang.org/cl/9838043
2013-05-28 10:25:11 -07:00
Robert Griesemer 3df6f127f0 go.tools/go/types: resolve objects in type checker
By setting resolve = true in check.go, the type checker
will do all identifier resolution during type checking
time and ignore (and not depend on) parser objects. This
permits the type checker to run easily on ASTs that are
not generated with invariants guaranteed by the parser.

There is a lot of new code; much of it slightly modified
copies of old code. There is also a lot of duplication.
After removing the dead code resulting from resolve = true
permanently (and removing the flag as well), it will be
easier to perform a thorough cleanup. As is, there are
too many intertwined code paths.

For now resolve = false. To be enabled in a successor CL.

R=adonovan
CC=golang-dev
https://golang.org/cl/9606045
2013-05-28 10:06:37 -07:00
Robert Griesemer 98bcbfbab7 go.tools/ssa: print identifer location if not found in TypeInfo
R=adonovan, r
CC=golang-dev
https://golang.org/cl/9703044
2013-05-25 10:04:20 -07:00
Robert Griesemer 7a48931508 go.tools/ssa: fix debug printing
R=adonovan, r
CC=golang-dev
https://golang.org/cl/9774043
2013-05-25 09:51:29 -07:00
Alan Donovan 8cdf1f1cb1 go.tools/ssa: add support for bound-method closures.
Extracted Builder.findMethod function to handle
methodset/receiver logic common to
function calls (Builder.setCall) and
bound method closure creation (Builder.selector).

Capture: added explicit Name, Type fields to Capture instead
of relying on Outer field, which is now un-exported since its
only purpose is to let Builder.expr(case *ast.FuncLit) know
which values to put in the closure; it is nilled immediately
after.

Simplified Function.lookup() logic: there's no need to walk
the Outer chain each time to set Alloc.Heap=true, as it's
already set during creation of the outermost
Capture{outer:*Alloc}.

Added interp/testdata/boundmeth.go test.

Cosmetic changes:
- add support for bound method thunks to Function.FullName().
- Simplified {Literal,Global,Builtin,Function}.String()
- doc: Captures are no longer necessarily addresses.
- added yet another missing pair of "()" (go/types accessors).
- print "Synthetic" not "Declared at -" for synthetic functions.
- use '$' not center-dot in synthetic identifiers (easier to type).

R=gri
CC=golang-dev
https://golang.org/cl/9654043
2013-05-22 17:56:18 -04:00
Rob Pike bf87b9f0f5 go.tools/cmd/vet: use "go test" to test
- remove Makefile
- move test data into a subdirectory
- encapsulate the invocation of errchk into a standard Test using os.exec

R=golang-dev, minux.ma, rsc
CC=golang-dev
https://golang.org/cl/9509045
2013-05-22 10:20:50 -07:00
Robert Griesemer 08ee2985d7 go.tools/go.types: check for redeclarations across package files
Fixes golang/go#5506.

R=adonovan
CC=golang-dev
https://golang.org/cl/9600044
2013-05-20 14:29:57 -07:00
Robert Griesemer ad2dafcf8f go.tools/gotype: fix build
Move from go.exp brought over an old version.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/9594043
2013-05-20 12:56:17 -07:00
Rob Pike 08cc526448 go.tools/cmd/vet: update to new go/types package
Now that it's in the same repository as the go/types package we can delete
the mechanism to build it without type checking.

Add a make rule to install it where the go tool can find it.
Why doesn't "go install" take a -o flag?

R=gri
CC=gobot, golang-dev
https://golang.org/cl/9526043
2013-05-20 12:20:05 -07:00
Alan Donovan 113d6d30b1 code.google.com/p/go.tools/ssa: include ssa.Package and init() function in example output.
Also:
- remove redundant text in doc.go.
- fix (yet more) cases of missing parens in Printf, fallout from
  go/types accessors refactoring.
- don't mix spaces and tabs within lines printed by ssa.Function.DumpTo:
  it makes it too hard to constructed expected outputs for tests.
  (Tabs may appear at line start though.)

Sadly godoc -play won't run this program; it complains it
can't import "code.google.com/p/go.exp/ssa".  Any idea why?

R=gri
CC=golang-dev
https://golang.org/cl/9481044
2013-05-17 17:33:09 -04:00
Rob Pike 87334f402b go.tools: bring up to date
Repo was copied from old point.  Bad r.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/9504043
2013-05-17 14:02:47 -07:00
Rob Pike 83f21b9226 go.tools: add missing files ssa/*.go
R=golang-dev, adonovan
CC=golang-dev
https://golang.org/cl/9500043
2013-05-17 13:25:48 -07:00
Rob Pike 01f8cd246d go.tools: add go/types, ssa, and cmd/vet
They will be deleted from their current homes once this has landed.
Changes made to import paths to make the code compile, and to find
errchk in the right place in cmd/vet's Makefile.
TODO in a later CL: tidy up vet.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/9495043
2013-05-17 13:20:39 -07:00
Rob Pike 9f31513c92 go.tools: provide the right README
R=golang-dev, minux.ma
CC=golang-dev
https://golang.org/cl/9479044
2013-05-17 12:55:10 -07:00
Nigel Tao ca8b903872 go.empty: add PATENTS file to the subrepo.
R=r
CC=golang-dev
https://golang.org/cl/6026043
2012-04-16 11:24:04 +10:00
Rob Pike b38d45f7ff LICENSE: add
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5845057
2012-03-17 15:20:58 +11:00
Russ Cox f61fbb80d2 go.empty: prototype for new subrepository
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5572056
2012-01-25 14:45:13 -05:00