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

273 Commits

Author SHA1 Message Date
Alan Donovan
713699d8ad go.tools: add copyright messages to source files.
R=r
CC=golang-dev
https://golang.org/cl/13305043
2013-08-27 18:49:13 -04:00
Brad Fitzpatrick
6f6897428a cmd/godoc: fix indexing
Use the flag.

Thanks to Travis Cline.

Fixes golang/go#6233

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/13284044
2013-08-27 15:16:31 -07:00
Alan Donovan
e08d89f3ed go.tools/oracle: an oracle that answers questions about Go source code.
+ Tests.
+ Emacs integration.
+ Emacs integration test.
+ very rudimentary Vim integration.  Needs some love from a Vim user.

TODO (in follow-ups):
- More tests would be good.
  We'll need to make the output order deterministic in more places.
- Documentation.

R=gri, crawshaw, dominik.honnef
CC=golang-dev
https://golang.org/cl/9502043
2013-08-27 17:58:26 -04:00
Alan Donovan
be2647ec01 go.tools/ssa: fix bug in Program.VarValue.
Before, VarValue looked for the ssa.Value for the 'var' object
in the same package as the object was defined, but this is
(obviously) wrong for a cross-package FieldVal selection,
expr.f.  The caller must provide the package containing the
reference.

+ test.

Also:
- add 2 TODOs.
- split builder.expr into two functions so we don't need
  defer, which makes panic dumps harder to read.

R=golang-dev, crawshaw
CC=golang-dev
https://golang.org/cl/13257045
2013-08-27 17:57:55 -04:00
Alan Donovan
de47ebac4b go.tools/ssa: fix bad type info in 'for _ = range channel'.
Previously, if the result was not wanted, the received
(value, ok) tuple had no type for 'value'.
Now it is always set to the channel's element type.

Also: set the position on such receive instructions to that of
the = or := token, and document it.

+ (indirect) test via pointer analysis.

R=crawshaw, gri
CC=golang-dev
https://golang.org/cl/12956052
2013-08-27 11:18:31 -04:00
Alan Donovan
7ce958b4a5 go.tools/pointer: fix build breakage.
(caused by overlapping pending CLs at commit time).

R=crawshaw
TBR=crawshaw
CC=golang-dev
https://golang.org/cl/12820048
2013-08-22 17:10:06 -04:00
Alan Donovan
6643abb26c go.tools/pointer: inclusion-based pointer analysis for Go.
Suggested reading order:
- doc.go
- api.go, analysis.go, callgraph.go, labels.go
- print.go, util.go
- gen.go
- solve.go
- pointer_test.go, testdata/*
- intrinsics.go (none are implemented yet)

R=dannyb, gri, crawshaw, 0xjnml
CC=golang-dev
https://golang.org/cl/10618043
2013-08-22 12:27:55 -04:00
Alan Donovan
c8a6890a12 go.tools/ssa: fix a bug building SSA code for ast.CompositeLit.
Map literals should use the same recursion logic as
struct/array/slice literals to apply an implicit &-operator to
the nested literals when a pointer is wanted.

+ test.

Also:
- ensure we set the source location for all Lookup and
  MapUpdate instructions.
- remove obsolete address.object field.

R=gri, crawshaw
CC=golang-dev
https://golang.org/cl/12787048
2013-08-22 10:13:51 -04:00
Andrew Gerrand
890e4c0731 go.tools/cmd/vet: exclude "%#v" from recursive stringer check
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/13163043
2013-08-22 11:44:39 +10:00
Andrew Gerrand
f6a22edf66 go.tools/cmd/vet: relax recursive stringer check
For the pointer receiver x, fmt.Sprintf(*x) does not invoke x's String
method.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/12971045
2013-08-22 11:29:44 +10:00
David Symonds
cec37cabd4 go/vcs: add proper error handling to test.
Fix a couple of error messages to report better messages.

R=adg
CC=golang-dev
https://golang.org/cl/13146043
2013-08-21 13:55:33 +10:00
Andrew Gerrand
373fd88c80 go.tools/cmd: move static files into new package 'static'
Fixes golang/go#6200.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/12805046
2013-08-21 13:49:05 +10:00
Chris Manghane
d64ad45594 go.tools/go/vcs: add logging functionality and create/log at revision
Add support for logging commands for Mercurial and Subversion as well as the ability to create/log a repo at a certain revision.

- Exported Cmd.LogCmd
- Exported Cmd.CreateAtRev
- Exported Cmd.Log
- Exported Cmd.LogAtRev

R=adg
CC=golang-dev
https://golang.org/cl/13060044
2013-08-20 20:10:15 -07:00
Andrew Gerrand
de72360261 go.tools/cmd/vet: fix build of testdata package
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/13144043
2013-08-21 11:08:25 +10:00
Andrew Gerrand
61d86e98d5 go.tools/cmd/vet: check for recursive stringers
Fixes golang/go#6129.

R=r
CC=golang-dev
https://golang.org/cl/12936046
2013-08-21 11:07:53 +10:00
Brad Fitzpatrick
3e29592dba cmd/vet: move whitelist to its own package
App Engine needs the whitelist file and it's cleaner if it's
in its own package where it can be imported directly, without
pushing composite.go through a pile of sed.

R=dsymonds, r
CC=golang-dev
https://golang.org/cl/12746045
2013-08-20 15:39:49 -07:00
Alan Donovan
99ac9493e1 go.types/ssa: add back Signature.Recv to interface method wrappers.
It is needed after all, as I discovered in the pointer analysis.
(ssa needs more API test coverage.)

Also:
- sanity: remove debugging cruft
- promote: don't redundantly include the function's
  own name in its Synthetic string.
- print: IntuitiveMethodSet utility fixes a bug in the
  printing logic (for interface types, mset(*T) is empty).
  The function is also used by the Oracle.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13116043
2013-08-20 14:50:13 -04:00
Andrew Gerrand
74ecc2c09b go.tools/cmd/vet: detect useless function comparisons
Also fix bug in types.go discovered by this check.

Fixes golang/go#5347.

R=golang-dev, dsymonds, r
CC=golang-dev
https://golang.org/cl/13102043
2013-08-20 16:11:01 +10:00
Brad Fitzpatrick
7c5549876e cmd/godoc: don't parse HTML templates in command-line mode
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/12956044
2013-08-19 22:29:56 -07:00
Andrew Gerrand
4e1a4d9fde go.tools/go/types: fix bad function comparison
Issue found by vet -nilfunc.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12816044
2013-08-20 15:26:04 +10:00
Alan Donovan
5cbf2abd36 go.tools/ssa: ensure address-deriving operations panic on nil inputs.
&x.f, &x[0], x[i:j], &*x all must panic if x==nil.

The first three are already addressed by the semantics of
FieldAddr, IndexAddr, Slice; updated docs to reflect this.
The final case requires generation of an additional dynamic check.

See golang.org/s/go12nil for details.

Tested on $GOROOT/test/nilptr2.go (with patch from CL 13108043)

Also: remove a TODO where a no-op will do.

R=gri, crawshaw
CC=golang-dev, rsc
https://golang.org/cl/13064044
2013-08-19 17:51:33 -04:00
Alan Donovan
7072253af5 go.tools/ssa: fixes, cleanups, cosmetic tweaks.
Fix bug: the Signature for an interface method wrapper
erroneously had a non-nil receiver.

Function:
- Set Pkg field non-nil even for wrappers.
  It is equal to that of the wrapped function.
  Only wrappers of error.Error
  (and its embeddings in other interfaces) may have nil.
  Sanity checker now asserts this.
- FullName() now uses .Synthetic field to discriminate
  synthetic methods, not Pkg==nil.
- Fullname() uses new relType() utility to print receiver type
  name unqualified if it belongs to the same package.
  (Alloc.String also uses relType utility.)

CallCommon:
- Description(): fix switch logic broken when we
  eliminated the Recv field.
- better docs.

R=david.crawshaw, crawshaw, gri
CC=golang-dev
https://golang.org/cl/13057043
2013-08-19 15:38:30 -04:00
Alan Donovan
df0c50c614 go.tools/importer: retain scope information.
(It's needed by the oracle.)

R=crawshaw, gri
CC=golang-dev
https://golang.org/cl/13071043
2013-08-19 15:14:13 -04:00
Alan Donovan
50bd0e3288 go.tools/ssa: synthesize main functions for test packages.
Package.CreateTestMainFunction() creates a function called
main and adds it to the package.  This function calls
testing.Main in the Go library with the appropriate arguments:
slices of test, benchmark and example functions from the
package.

Tested by running the interpreter on the following tests:
- unicode/script_test.go
- unicode/digit_test.go
- hash/crc32/crc32_test.go
- path/path_test.go

It's also covered indirectly via the pointer analysis.

R=crawshaw, gri
CC=golang-dev
https://golang.org/cl/12814046
2013-08-19 15:00:25 -04:00
Alan Donovan
3b53279d8f go.tools/ssa: preserve type of &&/|| operands in result.
+ test.

With this change, the Go Oracle is now self-aware. :)

R=gri, rsc
CC=golang-dev
https://golang.org/cl/12381043
2013-08-19 12:50:40 -04:00
Dave Cheney
41a15a3013 go.tools/go/vcs: do not delete $TMPDIR during test runs
The test would nuke the entire contents of os.TempDir on completion.

This change corrects the code to use ioutil.TempDir.

R=r, adg
CC=golang-dev
https://golang.org/cl/12796045
2013-08-19 16:22:31 +10:00
David Symonds
a7c698b070 undo CL 12811043 / 44387735a77d
Not the right thing to do.
Fixes golang/go#6148.

««« original CL description
cmd/vet: flag redundant invocations of String and Error methods in printf calls.

R=r
CC=golang-dev
https://golang.org/cl/12811043
»»»

R=r
CC=golang-dev
https://golang.org/cl/13034043
2013-08-19 11:12:44 +10:00
Brad Fitzpatrick
1633383a2b cmd/godoc: don't start up indexer in command-line mode
Fixes golang/go#6075

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/12995044
2013-08-16 19:49:24 -07:00
Andrew Gerrand
32acd2b372 go.tools/cmd/godoc: redirect old pkg/cmd paths
fixes golang/go#5317.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/12869046
2013-08-16 13:44:52 +10:00
Andrew Gerrand
562e4faeca cmd/godoc: bake templates and scripts into godoc binary
Add godoc/vfs/mapfs package for serving baked files.

Fixes golang/go#6010.

R=golang-dev, bradfitz, r, arnehormann, rsc
CC=golang-dev
https://golang.org/cl/12978043
2013-08-16 11:44:27 +10:00
Chris Manghane
dfa65ded17 go.tools: add go/vcs
go/vcs exposes cmd/go/vcs.go from the `go get` command.

- Exported global variables `Verbose` and `ShowCmd` to replace `buildV` and `buildX` from cmd/go/main.go.
- Moved environment building code (envForDir, mergeEnvLists)from cmd/go/main.go to env.go
- Exported Cmd and its methods: Create, Download, Ping, TagSync, and Tags
- Exported ByCmd and FromDir functions for constructing Cmd
- Exported TagCmd
- Exported RepoRoot
- Exported RepoRootForImport* functions for constructing RepoRoot

R=golang-dev, adg, cmang, bradfitz
CC=golang-dev
https://golang.org/cl/12058054
2013-08-15 09:00:02 -07:00
Robert Griesemer
ae874abc7a go.tools/go/types: *interface types have no methods
Fixes golang/go#5918.

R=adonovan
CC=golang-dev
https://golang.org/cl/12909043
2013-08-14 11:02:10 -07:00
Robert Griesemer
0b3996b1d3 go.tools/ssa/interp: add missing "external" (fix build)
R=adonovan, bradfitz
CC=golang-dev
https://golang.org/cl/12898043
2013-08-13 15:00:07 -07:00
David Symonds
c0b6badc83 cmd/vet: flag redundant invocations of String and Error methods in printf calls.
R=r
CC=golang-dev
https://golang.org/cl/12811043
2013-08-13 13:47:58 +10:00
Robert Griesemer
d13d94afe7 go.tools/go/types: do rounding in constant numeric conversions
- cleaned up surrounding code
- adjusted error message positions for too few/many argument errors
- added more conversion tests
- added all tests under test/ken to std tests

R=adonovan, r
TBR=adonovan
CC=golang-dev
https://golang.org/cl/12711043
2013-08-12 14:57:08 -07:00
Robert Griesemer
508ae115ae go.tools/go/types: added missing test for file scopes
R=adonovan, r
CC=golang-dev
https://golang.org/cl/12671044
2013-08-08 20:54:28 -07:00
Rob Pike
28fe5aa8d3 go.tools/cmd/cover: s/ParseInt/Atoi/
So people stop asking me to do this.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/12691044
2013-08-09 13:48:46 +10:00
Robert Griesemer
2449594308 go.tools/go.types: retain ast.Node links on demand only
- support Info.Scopes mapping that maps ast.Nodes
  to the respective *Scope
- remove old node link from *Scope
- added corresponding API test

Also: re-enable debug mode (the faster version was
only important for the go api tool, which  has its
own version now).

R=adonovan, r
CC=golang-dev
https://golang.org/cl/12552047
2013-08-08 20:27:15 -07:00
Rob Pike
4622486b62 go.tools/cmd/cover: add -func mode to print per-function coverage
fmt/format.go:	init			100.0%
fmt/format.go:	clearflags		100.0%
fmt/format.go:	init			100.0%
fmt/format.go:	computePadding		84.6%
fmt/format.go:	writePadding		83.3%
...
total:		(statements)		91.3%

Fixes golang/go#5985.

R=golang-dev, dave, gri
CC=golang-dev
https://golang.org/cl/12454043
2013-08-09 12:55:21 +10:00
Robert Griesemer
875ff2496f go.tools/go/types: support for fake imports of package "C"
Also:
- cleaner method set printing
- disable debug mode internally (50% faster)

R=adonovan, bradfitz
CC=golang-dev
https://golang.org/cl/12578043
2013-08-07 14:09:50 -07:00
Robert Griesemer
56b9e46247 go.tools/go/types: fewer guarantees in case of type errors
Provide fewer guarantees regarding the collected result
type information in types.Info if there are type errors.

Specifically, don't record nil objects in the Objects map
in case of a declaration error; instead, simply omit them.

R=adonovan
TBR=adonovan
CC=golang-dev
https://golang.org/cl/12553043
2013-08-06 11:27:05 -07:00
Rob Pike
75920173e4 go.tools/go/types: don't put an interface nil into the Objects map
If a method cannot type check, we end up with the interface variable
m to hold <*Func, nil>. Don't put that in the map because it defeats
the usual != nil check.

R=gri, dsymonds
CC=golang-dev
https://golang.org/cl/12506043
2013-08-06 16:19:10 +10:00
Robert Griesemer
45e3d57f32 go.tools/cmd/vet: enable test (fix build)
R=r
TBR=r
CC=golang-dev
https://golang.org/cl/12482043
2013-08-05 14:02:52 -07:00
Robert Griesemer
b956928b06 go.tools/go/types: Fix for broken IsAssignableTo.
Was broken by CL 12378043.

- factored out some error checking code
- adjusted error positions

R=adonovan
TBR=adonovan
CC=golang-dev
https://golang.org/cl/12401043
2013-08-05 13:54:22 -07:00
David Symonds
1dce9cc7c7 go/types: exclude a couple of files from the stdlib test that don't parse on Windows.
They use stuff in syscall that doesn't exist on Windows, and this test does not
parse build tags (not that we make that easy) to automatically skip them.

R=golang-dev, r, gri
CC=golang-dev
https://golang.org/cl/12453043
2013-08-05 13:54:22 +10:00
Rob Pike
c333e7a7b6 go.tools/cmd/vet: fix go.tools build
TBR: gri

I cannot create an issue on the tracker for some reason, so here it is:
go vet contains this snippet:

        if types.IsAssignableTo(typ, errorType) || types.IsAssignableTo(typ, stringerType) {

It's getting the wrong answer: It claims

interface {
        f()
}

or even

interface {
        f() float64
}

matches the Error and Stringer interfaces. Both of them.  This causes a test failure:
$ go test code.google.com/p/go.tools/cmd/vet
BUG: errchk: testdata/print.go:124: missing expected error: '"for printf verb %s of wrong type"'
$
This worked until very recently.

R=gri
CC=golang-dev
https://golang.org/cl/12398043
2013-08-03 15:56:56 +10:00
Rob Pike
aecec2f502 go.tools/cmd/vet: the composite test is about keys, not tags
Fix the confusion.
No semantic change, just some renamings.

Fixes golang/go#6017.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12394043
2013-08-03 12:19:59 +10:00
Robert Griesemer
3209d6ad73 go.tools/go/types: fix interface vs interface type assertion
R=adonovan
CC=golang-dev
https://golang.org/cl/12378043
2013-08-02 14:37:19 -07:00
Robert Griesemer
e06b897351 go.tools/go/types: mark imported named types as 'complete'
Fixes "illegal cycle" error for: go tool vet -v pkg/unicode.

R=adonovan
CC=golang-dev
https://golang.org/cl/12355043
2013-08-02 09:33:37 -07:00
Rob Pike
797431e1a3 go.tools/cmd/vet: fix printf analysis for structs.
The old code only got it right for Stringers (etc.) and a few other simple cases.
But the rule used by fmt.Printf for non-Stringers is that pointers to structs
print as pointers, the rest must satisfy the format verb element-wise.
Thus for example
        struct {a int, b []byte}
prints with %d and %q (sic) but not %g.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12340043
2013-08-02 22:52:38 +10:00