1
0
mirror of https://github.com/golang/go synced 2024-09-30 20:38:32 -06:00
Commit Graph

585 Commits

Author SHA1 Message Date
Jongmin Kim
dc0000626d cmd/present: fix unclosed section element
Change-Id: I974ec7a2caccfca3aff18836d6495597e17664e7
Reviewed-on: https://go-review.googlesource.com/2533
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-01-08 23:27:10 +00:00
Péter Surányi
bd69d2dd34 cmd/godoc: mention examples feature in godoc
Godoc documentation did not mention the feature for showing example code
runnable by the testing package. Add a link to the testing package.

Update golang/go#9471

Change-Id: Ic15794c59732e9b0b42c5b16c60be0a47c41afa5
Reviewed-on: https://go-review.googlesource.com/2490
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-01-08 02:02:02 +00:00
Andrew Gerrand
af7d92a90f cmd/tipgodoc: record and report errors
Change-Id: I76c04c745367427cd3b474949d213e105f6b47c1
Reviewed-on: https://go-review.googlesource.com/2413
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-01-07 05:30:47 +00:00
Andrew Gerrand
c836fe615a cmd/godoc: add golang.org/x/playground custom import path
Change-Id: Ic399dbf8a77e7c61ba8be263515b13a6b488b4e9
Reviewed-on: https://go-review.googlesource.com/2309
Reviewed-by: Rob Pike <r@golang.org>
2015-01-06 02:12:10 +00:00
Dominik Honnef
0ff6678340 benchmark/parse, cmd/benchcmp: new package for parsing benchmarks
Move the parser for benchmark output from cmd/benchcmp into its own
package, benchmark/parse.

The majority of the change is just moving code around. Instead of
implementing the '-best' flag in ParseBenchSet, it is now implemented in
its own function 'selectBest' in cmd/benchcmp.

Bench.Ord (the ordinal position of a Bench within a BenchSet) has been
exported.

Change-Id: Id27032a220f9ff2596117b58b86243998695a804
Reviewed-on: https://go-review.googlesource.com/2102
Reviewed-by: Rob Pike <r@golang.org>
2015-01-06 01:34:08 +00:00
Alan Donovan
c1ef9c75bf cmd/gorename: make Usage documentation sensible in godoc
Fixes golang/go#9469

Change-Id: I74e19e3d095e4c2ab62f755a408f58fd5e7ac2f2
Reviewed-on: https://go-review.googlesource.com/2176
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2014-12-30 16:36:43 +00:00
Alan Donovan
4f13714aca astutil: add Unparen utility, eliminating 7 copies.
Change-Id: I824328c275bd6198a57edd64bf72cb2cf0490a68
Reviewed-on: https://go-review.googlesource.com/2172
Reviewed-by: Chris Manghane <cmang@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2014-12-29 22:24:57 +00:00
Emil Hessman
ca3901c3d8 all: address vet reports
Fixes various problems reported by go vet.

Change-Id: I12a6fdba8f911b21805d8e42903f8f6a5033790a
Reviewed-on: https://go-review.googlesource.com/2163
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-12-29 06:08:34 +00:00
Shenghou Ma
f72c7f7642 cmd/godoc: show the BUG section
This will match the default behavior when running locally.

In fact, our http://blog.golang.org/godoc-documenting-go-code explicitly
documents this feature (see also golang.org/cl/1953).

Change-Id: I581b17b60229ce70900cb51d548d1e2a34df41ba
Signed-off-by: Shenghou Ma <minux@golang.org>
Reviewed-on: https://go-review.googlesource.com/2116
Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-12-28 23:27:51 +00:00
Matt Bostock
79d60d6e2c cmd/present: Fix indentation in styles.css
No functional changes.

Also adds a newline to the end of the file, for compatibility with
`cat(1)` and `vim(1)`. See also:

https://gcc.gnu.org/ml/gcc/2003-11/msg01568.html

Change-Id: I4fc7ac64ad7c4b4d9c2be7296cb8b612e0becef2
Reviewed-on: https://go-review.googlesource.com/2106
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-12-26 16:52:14 +00:00
Matt Bostock
255341fbe0 cmd/present: Fix HTML to use matching header tag
Close the `<h3>` header tag with a closing `</h3>` tag to fix the HTML
syntax.

Change-Id: Ic86c5f31ec5550d6875aa085eed8da6a75881405
Reviewed-on: https://go-review.googlesource.com/2104
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2014-12-25 00:19:42 +00:00
Rob Pike
575b88be8f stringer: avoid if's in the generated code
Suggestion by dsymonds: Save code not data.
Add an extra element to the index array and an if can be eliminated.

Old generated code:
const _Day_name = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday"

var _Day_index = [...]uint8{6, 13, 22, 30, 36, 44, 50}

func (i Day) String() string {
	if i < 0 || i >= Day(len(_Day_index)) {
		return fmt.Sprintf("Day(%d)", i)
	}
	hi := _Day_index[i]
	lo := uint8(0)
	if i > 0 {
		lo = _Day_index[i-1]
	}
	return _Day_name[lo:hi]
}

New generated code:
const _Day_name = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday"

var _Day_index = [...]uint8{0, 6, 13, 22, 30, 36, 44, 50}

func (i Day) String() string {
	if i < 0 || i+1 >= Day(len(_Day_index)) {
		return fmt.Sprintf("Day(%d)", i)
	}
	return _Day_name[_Day_index[i]:_Day_index[i+1]]
}

Change-Id: I6f46a4892d5813a12ec1ad01738c6a21c7e45172
Reviewed-on: https://go-review.googlesource.com/1990
Reviewed-by: David Symonds <dsymonds@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2014-12-22 20:58:05 +00:00
Emil Hessman
864e280a1d cmd/godoc: add missing space to flag description
Change-Id: I8f4dada13353065475baf33c71e6e1a28f889e71
Reviewed-on: https://go-review.googlesource.com/1892
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2014-12-19 19:42:26 +00:00
Oling Cat
65b875be27 cmd/godoc: update GAE setup script
Change-Id: Ief2c49a03cbd3251d62d854be4f51dcb27a42458
Reviewed-on: https://go-review.googlesource.com/1522
Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-12-19 02:48:01 +00:00
Shenghou Ma
458cff5230 cmd/tipgodoc: add appenginevm build tag
Fixes golang/go#9381.

Change-Id: Ied5fd00475dde2b781cedff398dc9ee8d7f642a4
Signed-off-by: Shenghou Ma <minux@golang.org>
Reviewed-on: https://go-review.googlesource.com/1801
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-12-18 22:13:11 +00:00
Shenghou Ma
a47975eda8 cmd/eg, godoc/redirect: update remaining code.google.com links
Change-Id: I67da9e0c0c511c19e5b5296fbcf46f641273a7bb
Signed-off-by: Shenghou Ma <minux@golang.org>
Reviewed-on: https://go-review.googlesource.com/1515
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-12-18 07:48:40 +00:00
Brad Fitzpatrick
f56df04f2d cmd/tipgodoc: make tipgodoc run on App Engine Managed VMs
At least in theory. We don't totally have it working yet. It does
run locally in the dev environment, though, which should be the same
as production, since it builds the Docker container locally.
But we're getting problems when pushing it to production.

Also some minor tweaks to the code with Andrew.

Change-Id: Id192669dbc8d3f86d9c8dad79764abd66e983895
Reviewed-on: https://go-review.googlesource.com/1761
Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-12-18 06:10:19 +00:00
Andrew Gerrand
5bf57d6426 cmd/tipgodoc: new tip.golang.org server
Rough work in progress. Don't hate.

Change-Id: I9d8247005724a21bdb5d4760cc6135bceb49f2d4
Reviewed-on: https://go-review.googlesource.com/1704
Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-12-17 04:51:07 +00:00
Brad Fitzpatrick
88d370fb93 cmd/godoc: add debug subrepo meta to x handler
Change-Id: I0ba56b32dd9b53d06817f9f7e2dafff04e6a86d2
Reviewed-on: https://go-review.googlesource.com/1565
Reviewed-by: David Symonds <dsymonds@golang.org>
2014-12-15 04:44:49 +00:00
Shenghou Ma
14ecce811f cmd/present: skip the "golang.org" directory
Change-Id: I732194c22062c77c431dcec57f9ef832f1dc1afe
Signed-off-by: Shenghou Ma <minux@golang.org>
Reviewed-on: https://go-review.googlesource.com/1512
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-12-14 23:37:49 +00:00
Brad Fitzpatrick
802ec582a3 all: update links from code.google.com to new homes
Change-Id: Id3c5b2480c8499ab712265a421ffba125fb913db
Reviewed-on: https://go-review.googlesource.com/1401
Reviewed-by: David Symonds <dsymonds@golang.org>
2014-12-12 03:10:55 +00:00
David Symonds
24257c8cd2 tools: add import comments.
Change-Id: Idda6e64580432cb9a731e4ebf4005ee4ceb4202d
Reviewed-on: https://go-review.googlesource.com/1244
Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-12-09 22:42:16 +00:00
Andrew Gerrand
9e66c59fb1 x/tools/cmd/godoc: update golang.org/x/ redirects to point to git repos
LGTM=dsymonds
R=dsymonds
CC=golang-codereviews
https://golang.org/cl/182620043
2014-12-08 10:30:52 +11:00
Daniel Morsing
25f58f97ce x/tools/oracle: add whicherrs query mode
The whicherrs query mode takes the position of an error and returns the set of constants, globals and types visible from within the scope of the error being queried.
It is meant to be used as a shortcut to find out which errors should be handled for a given functions call.

LGTM=adonovan
R=golang-codereviews, dominik.honnef, adonovan
CC=golang-codereviews
https://golang.org/cl/167420043
2014-12-05 15:51:34 +00:00
Alan Donovan
c6ec5ea66d cmd/gorename: support renaming of methods with consequences for other types, iff initiated at an abstract method.
Previously, gorename rejected all method renamings if it would
change the assignability relation.

Now, so long as the renaming was initiated at an abstract
method, the renaming proceeds, changing concrete methods (and
possibly other abstract methods) as needed.  The user
intention is clear.

The intention of a renaming initiated at a concrete method is
less clear, so we still reject it if it would change the
assignability relation.  The diagnostic advises the user to
rename the abstract method if that was the intention.

Additional safety checks are required: for each
satisfy.Constraint that couples a concrete type C and an
interface type I, we must treat it just like a set of implicit
selections C.f, one per abstract method f of I, and ensure the
selections' meanings are unchanged.

The satisfy package no longer canonicalizes types, since this
substitutes one interface for another (equivalent) one, which
is sound, but makes the type names random and the error
messages confusing.

Also, fixed a bug in 'satisfy' relating to map keys.

+ Lots more tests.

LGTM=sameer
R=sameer
CC=golang-codereviews
https://golang.org/cl/173430043
2014-12-04 09:37:50 -05:00
Rob Pike
0e9050009a tools/cmd/vet: check that cgo is enabled before testing it
Should fix the tools builders.

LGTM=bradfitz
R=rsc, bradfitz
CC=golang-codereviews
https://golang.org/cl/176530043
2014-12-02 08:15:26 +09:00
Nathan John Youngman
806f1dbf43 tools/cmd/stringer: fake import C.
Avoid error "could not import C (can't find import: C)"
Fixes golang/go#9169.

LGTM=adonovan, r
R=golang-codereviews, adonovan, r
CC=golang-codereviews
https://golang.org/cl/184730043
2014-11-27 15:36:14 +11:00
Andrew Gerrand
354b6ccbcc x/tools/cmd/godoc: add golang.org/x/oauth2 import path
LGTM=r
R=jbd, r
CC=golang-codereviews
https://golang.org/cl/175700043
2014-11-26 15:31:30 +11:00
Alan Donovan
a9651d6ad7 cmd/callgraph: add -algo=static and -algo=cha options.
"static" ignores dynamic calls altogether.

"cha" uses Class Hierarchy Analysis, which assumes that a
dynamic call may dispatch to any func or method that satisfies
the type.

Both these algorithms can work on partial programs,
e.g. libraries without a main function or tests.

(This feature was requested after my talk last night.)

+ Tests.

LGTM=sameer
R=sameer, minux
CC=golang-codereviews, gri
https://golang.org/cl/176780043
2014-11-21 11:07:56 -05:00
Andrew Gerrand
4f9827a99d x/tools/cmd/godoc: fix bad repository path
Not caught by inattentive reviewer. Pick up your game, people.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/180880043
2014-11-19 15:51:44 +11:00
Andrew Gerrand
1536a92c03 x/tools/cmd/godoc: add golang.org/x/review custom import path
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/174410043
2014-11-19 14:03:19 +11:00
Alan Donovan
d75c6bdb8f cmd/oracle: minor fixes.
- print "oracle:" not "Error:" in error messages; remove period.
- allocate token.FileSet correctly.
- remove stale TODO (multiple test packages)
- fix typo and omission ('what') in usage message.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/178860043
2014-11-17 13:50:23 -05:00
Alan Donovan
4162082cba x/tools/*: print program name, not "Error", when reporting command error messages.
Such messages are more informative when the error occurs deep within a script.

Also: add tool name to digraph's usage messages.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/173380043
2014-11-17 12:58:28 -05:00
Alan Donovan
c13d674f5e go/callgraph/rta: rename from go/rta
LGTM=sameer
R=sameer
CC=golang-codereviews, gri
https://golang.org/cl/175770043
2014-11-14 11:02:44 -05:00
Alan Donovan
b8d26f5b94 tools: minor comment fixes.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/173170043
2014-11-13 12:34:25 -05:00
Robert Griesemer
c2b324b9b4 cmd/callgraph: fix build
TBR=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/171640043
2014-11-12 16:49:47 -08:00
Alan Donovan
b8a5fcfcec cmd/callgraph: a utility for dumping the callgraph of a Go program.
(This functionality is provided by the oracle, but its output
format is inflexible, and the functionality is better suited
to a shell utility.  I may remove the oracle 'callgraph' feature.)

See Usage for details.

+ Test.

LGTM=sameer
R=sameer
CC=golang-codereviews, gri
https://golang.org/cl/164460044
2014-11-12 17:36:22 -05:00
Alan Donovan
c097262a24 cmd/digraph: support Go-style double-quotes in input data.
+ test.

LGTM=sameer
R=sameer
CC=golang-codereviews, gri
https://golang.org/cl/170090043
2014-11-12 13:37:06 -05:00
Andrew Gerrand
5ebbcd132f go.tools: use golang.org/x/... import paths
Rewrite performed with this command:
  sed -i '' 's_code.google.com/p/go\._golang.org/x/_g' \
    $(grep -lr 'code.google.com/p/go.' *)

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/170920043
2014-11-10 08:50:40 +11:00
Austin Clements
348181cdd4 cmd/vet: tests for RET checking, SP checking, and leaf functions
Add tests for recently introduced asm error checks in vet.
This adds tests for the new warnings about functions that
don't store to their return slot before returning or that
store to SP-relative addresses in or beyond the argument
frame.  It also adds a test for leaf function handling on arm,
where the link register is not implicitly saved.

LGTM=rsc
R=rsc
CC=adg, golang-codereviews, r
https://golang.org/cl/166040044
2014-11-03 17:27:41 -05:00
Austin Clements
52f3c4bf8a cmd/vet: update test patterns to include asm function name
vet now includes function names in its error messages about
assembly code.  Update the error test patterns to account for
this and expand some patterns to check that go vet discovers
the function name correctly.

Fixes golang/go#9041

LGTM=r
R=adg, r, rsc
CC=golang-codereviews
https://golang.org/cl/170940044
2014-11-02 12:21:04 -05:00
Alan Donovan
d73c11bfcb refactor/rename: make -from syntax support string literals for complex import paths.
(They may contain any character, after all.)

Also, allow but don't require parens and stars.
e.g. (*"encoding/json".Decoder).Decode or "encoding/json".Decoder.Decode
     but not encoding/json.Decoder.Decode.

Since -from queries are now Go expressions, we use the Go parser.
(Thanks to Rog Peppe for the suggestion.)

LGTM=sameer
R=sameer
CC=golang-codereviews, gri, rogpeppe
https://golang.org/cl/154610043
2014-10-31 15:39:22 -04:00
Andrew Gerrand
5d1cfb1968 go.tools/cmd/godoc: add handlers for new sub-repo paths
Fixes golang/go#9009.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/162470043
2014-10-31 09:01:52 +11:00
Austin Clements
c7512a5f83 cmd/vet: check return moves, support power64x, various fixes
This adds support for checking moves to the return value stack
slot (from rsc), adds support for checking power64x assembly,
fixes argument offset checking and leaf function support on
platforms with a link register (arm and power64).

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/166920043
2014-10-30 11:53:56 -04:00
Alex Brainman
4bb917e48d go.tools/cmd/godoc: wait for godoc to exit before removing tmp directory
otherwise tmp directories do not get deleted on windows

LGTM=adg
R=golang-codereviews, adg
CC=golang-codereviews
https://golang.org/cl/166750043
2014-10-28 16:59:58 +11:00
Alex Brainman
d8b266df1c go.tools/cmd/godoc: wait for analysis to complete in TestTypeAnalysis
LGTM=adg
R=golang-codereviews, adg
CC=golang-codereviews
https://golang.org/cl/157590043
2014-10-28 12:25:46 +11:00
Robert Griesemer
bdfcf50b6f cmd/vet: fix internal comments
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/163070043
2014-10-23 10:59:27 -07:00
Robert Griesemer
ea1477608d cmd/vet: use changed types.LookupParent API (fix build)
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/162080043
2014-10-23 09:57:19 -07:00
Alan Donovan
5f5b110a59 cmd/digraph: digraph: a UNIX-style utility command for common operations on directed graphs in text format.
Example: show the transitive closure of imports of the digraph tool itself:

% go list -f '{{.ImportPath}}{{.Imports}}' ... | tr '[]' '  ' |
    digraph forward code.google.com/p/go.tools/cmd/digraph

+ basic test.

LGTM=gri
R=gri, sameer
CC=golang-codereviews
https://golang.org/cl/161760043
2014-10-23 09:13:39 -04:00
David Symonds
26439e8d81 cmd/vet: return nil from importType if it fails.
This permits vet to not panic during init if fmt.a is unavailable.

LGTM=r
R=gri, r
CC=golang-codereviews
https://golang.org/cl/153590043
2014-10-15 16:56:09 +11:00
Rob Pike
9be0b38f5b cmd/vet: don't panic if import fails
Initializing the unused variable formatterType (it will be used soon) was
panicking if the import couldn't be done, but vet shouldn't be so fragile.

LGTM=gri
R=gri
CC=dsymonds, golang-codereviews
https://golang.org/cl/153480044
2014-10-14 12:55:46 -07:00
Hana Kim
13837d25ef godoc: exclude internal packages and cmd from packages page.
Internal packages are now only included with ?m=all

Fixes golang/go#8879

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/155910044
2014-10-13 18:47:02 +02:00
Dmitri Shuralyov
cccd43354a cmd/vet: fix bug where incorrect exit code was returned
Fixes golang/go#8792.

This is a simple change that fixes the issue. It may be desireable
to opt for a larger code change that makes this problem less likely
to be inadvertedly reintroduced in the future. For instance, a vetMain()
func can be used similar to gofmtMain(), or the os.Exit call can be
deferred.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/150850043
2014-10-02 10:33:35 -07:00
Josh Bleecher Snyder
e62e5f9885 go.tools/cmd/vet: remove duplicate test file
In CL 145360043, I hg cp'd copylock.go to copylock_func.go instead of hg mv. Oops.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/143660043
2014-09-26 15:09:18 -07:00
Robert Griesemer
315249fc55 cmd/vet: provide access to externally defined types
Preliminaries for fixing issue 6212.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/145370043
2014-09-24 13:54:50 -07:00
Josh Bleecher Snyder
2cd071c190 go.tools/cmd/vet: warn about copying locks in range statements
Fixes golang/go#8356.

LGTM=r
R=r, dsymonds
CC=golang-codereviews
https://golang.org/cl/145360043
2014-09-24 12:35:15 -07:00
Alan Donovan
e94ae77171 refactor: minor no-op fixes
- fix typos and mistakes in docstrings, usage message and comments.
- remove 'backup' parameter to rewriteFile

LGTM=sameer
R=sameer
CC=golang-codereviews
https://golang.org/cl/147980043
2014-09-23 15:17:49 -04:00
Alan Donovan
74021b4175 cmd/gorename: a precise, type-aware renaming tool for Go identifiers.
See the usage message in main.go for orientation.

To the best of my knowledge, the tool implements all required
soundness checks, except:
- the dynamic behaviour of reflection is obviously undecidable.
- it rejects method renamings that change the "implements" relation.
  It should probably be more aggressive.
- actually it only checks the part of the "implements" relation
  needed for compilation.  Understanding the dynamic behaviour
  of interfaces is obviously undecidable.
- a couple of minor gaps are indicated by TODO comments.

Also:
- Emacs integration.
- tests of all safety checks and (some) successful rewrites.

LGTM=dominik.honnef, sameer
R=gri, sameer, dominik.honnef
CC=golang-codereviews
https://golang.org/cl/139150044
2014-09-23 10:23:04 -04:00
Alan Donovan
6c93dbff3e go.tools/godoc: deal with fallout from $GOROOT/src/pkg -> $GOROOT/src renaming.
To avoid breaking URLs, we redirect /src/pkg/* to /src/*.

The URL /pkg is now the "directory" /src, which triggers the
"Packages" index.

All other references to "src/pkg" are now gone,
except a number in the namespace documentation which are
probably still illustrative.

Tested: go test cmd/godoc godoc
        Manual inspection of src and src/pkg pages.
        with GOROOT and GOPATH packages
        -analysis
        /AUTHORS file URL still works

LGTM=bradfitz, adg
R=bradfitz, adg
CC=golang-codereviews
https://golang.org/cl/141770044
2014-09-10 09:02:54 -04:00
Rob Pike
e548cb3dfe go.tools/cmd/stringer: fix docs: stringer is not a "go tool"
Documentation change only. The binary will not be installed
using the "go tool" mechanism.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/133710046
2014-09-09 13:29:38 -07:00
Alan Donovan
9872f0d268 go.tools/*: replace $GOROOT/src/pkg with $GOROOT/src where appropriate.
(godoc is excluded from this CL since it will continue to use
/src/pkg in its URL namespace, making the necessary cleanup
more subtle.)

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/141770043
2014-09-08 13:24:38 -04:00
Alex Brainman
d39af6c903 go.tools/cmd/stringer: add .exe suffix to executable name in TestEndToEnd
Fixes windows build

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/140360043
2014-09-08 13:55:05 +10:00
Rob Pike
d03e8a67df go.tools/cmd/stringer: delete needless subtraction of zero in generated code
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/136270043
2014-09-05 17:05:28 -07:00
Rob Pike
d0448f16e3 go.tools/cmd/stringer: add end-to-end test that compiles, runs, and verifies the generated method
In the process, fix a bug in one of the method generators.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/141130043
2014-09-05 15:42:23 -07:00
Rob Pike
75b67f833e go.tools/cmd/stringer: fix generated map code
Missed comment from previous code review.
Next up: execution tests so this won't happen again

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/134480043
2014-09-04 16:18:38 -07:00
Rob Pike
22ede605a7 go.tools/cmd/stringer: use const for names, slice for map strings
Improve the generated code by using a const instead of a var for the names string.
This requires some refactoring to get neat const() and var() blocks.
Also change the generate map code go use a single sliced string, to reduce the
size of the compiled representation (only one string value).

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/135450044
2014-09-04 16:06:51 -07:00
Rob Pike
9207f67279 go.tools/cmd/stringer: add tests
Refactor a little to make testing easier.
Add golden tests and a check fo splitIntoRuns, which is the subtlest piece.
Still to come: execution tests.

Also fix a few issues in the generated code.

LGTM=gri
R=gri
CC=golang-codereviews, josharian
https://golang.org/cl/134450044
2014-09-04 14:16:59 -07:00
Yasuhiro Matsumoto
0673c34537 go.tools/cmd/stringer: Fix build on 32bit OSs.
LGTM=r
R=golang-codereviews, gri, r
CC=golang-codereviews
https://golang.org/cl/138040043
2014-09-04 10:51:38 -07:00
Rob Pike
2c5c896732 go.tools/cmd/stringer: new tool
This tool creates String methods from constant definitions.
It's a time-saver designed to be used from go generate.
The methods generated are efficient, more so than one
is likely to create by hand.

Given

        package date

        type Day int

        const (
                Monday Day = iota
                Tuesday
                Wednesday
                Thursday
                Friday
                Saturday
                Sunday
        )

the command

        stringer -type Day

will create the file day_string.go containing

        package date

        import "fmt"

        var (
                _Day_indexes = []uint8{6, 13, 22, 30, 36, 44, 50}
                _Day_names   = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday"
        )

        func (i Day) String() string {
                if i < 0 || i >= Day(len(_Day_indexes)) {
                        return fmt.Sprintf("Day(%d)", i)
                }
                hi := _Day_indexes[i]
                lo := uint8(0)
                if i > 0 {
                        lo = _Day_indexes[i-1]
                }
                return _Day_names[lo:hi]
        }

There are several strategies for the created method chosen according to
the structure of the sequence of constants.

Handles integer types only, both signed and unsigned. That's probably
all that is needed.

Tests to follow, but the test structure will be large so sending this out
separately. The code has been heavily hand-tested but there are
some bugs. Don't depend on this until the tests are installed.

LGTM=gri
R=gri, josharian
CC=golang-codereviews
https://golang.org/cl/136180043
2014-09-03 17:27:48 -07:00
Rob Pike
1e11d05bd8 cmd/vet: simplify file-reading code per gri
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/140960043
2014-09-03 16:49:14 -07:00
Matt Jibson
59c8647562 go.tools/cmd/vet: detect suspicious shifts
LGTM=josharian, dsymonds, r
R=golang-codereviews, josharian, minux, dsymonds, dave, axwalk, adg, r
CC=golang-codereviews
https://golang.org/cl/134780043
2014-08-29 11:17:01 -07:00
David Symonds
2b15aa63b7 go.tools/cmd/vet: don't panic on zero arg Log method calls.
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/134000043
2014-08-29 08:56:35 +10:00
Robert Griesemer
5dca7d8bd1 go.tools/go/types: LookupFieldOrMethod checks method set
LookupFieldOrMethod now also decides whether a found
method is actually in the method set. Simplifies call
sites. Added corresponding API tests.

TODO (separate CL): Decide what the correct value for
the indirect result should be (as required for code
generation). For now, the result value for indirect
is unchanged from before if a field/method is found.

Fixes golang/go#8584.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/132260043
2014-08-28 13:03:13 -07:00
Alan Donovan
4abc8436bc cmd/eg: add -beforeedit flag, which specifies a command to run before editing a file.
e.g. chmod +w, checkout.

Also: add a TIPS section to the documentation.

LGTM=crawshaw
R=crawshaw, gri
CC=golang-codereviews
https://golang.org/cl/136780044
2014-08-26 15:52:40 -04:00
Rob Pike
cd9959d796 go.tools/cmd/vet: validate calls to t.Log and t.Logf
Be careful not to complain about math.Log and cmplx.Log.
Seems worthwhile since t.Log and t.Logf are often written but
rarely executed.

Nothing new turned up in the standard library.

Fixes golang/go#8504.

LGTM=josharian, dsymonds
R=golang-codereviews, josharian, dsymonds
CC=golang-codereviews
https://golang.org/cl/130490043
2014-08-25 12:31:49 -07:00
Rob Pike
671b9204b8 go.tools/cmd/vet: change message for range check
s/enclosed by function/captured by func literal/
Users complained. They often do.

LGTM=josharian, adg
R=golang-codereviews, josharian, nightlyone, minux, adg
CC=golang-codereviews
https://golang.org/cl/132080043
2014-08-24 17:26:18 -07:00
Fatih Arslan
ba91af23b8 cmd/cover: add start lines numbers to each function in -func mode
This CL aims to fix the problem described here:

https://groups.google.com/forum/#!topic/golang-nuts/R6ms1n9KjiY

This makes it easier to parse via external tools such as editors. Editors can
show each function in a list and jump directly to each function with this
additional information. This pattern can be seen in other Go tools such as "go
test" in the form of:

--- FAIL: TestCover (0.52 seconds)
        cover_test.go:43: example error

LGTM=adg
R=r, adg, josharian, dave
CC=golang-codereviews
https://golang.org/cl/131820043
2014-08-21 16:28:12 -07:00
Rob Pike
f11381f265 go.tools/cmd/cover: don't assume code is gofmt'd
We want to make an if look like two blocks and have the coverage
report for the else block decorate the "else" keyword with the right
color. To do this, we adjust the apparent starting point of the else
block to include the "else".

The previous code assumed the way to do this was to move the
width of "else " backwards from the else block's opening brace, but
that assumes there is a space there. Instead, we now just start the
else block exactly at the end of the if block. Simpler, cleaner, and
fixes a bug.

Fixes golang/go#8557.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/127620043
2014-08-20 11:14:50 -07:00
Francesc Campoy
e8a1924bfb html2article: Ignore empty anchor elements and obtain the original url from Google Docs
LGTM=adg
R=adg, campoy
CC=golang-codereviews
https://golang.org/cl/127560043
2014-08-19 17:55:46 -07:00
Andrew Gerrand
573fa9f0bd cmd/cover: show file coverage in HTML drop down
As requested on Stack Overflow: http://goo.gl/ams9fY
(Kudos to sberry for his JavaScript solution, provided there.
This change does the same thing on the server side.)

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/127030043
2014-08-12 09:22:11 +10:00
Francesc Campoy
11569f39ea go.tools/cmd/present: track page views for every slide.
LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/124720043
2014-08-05 16:02:39 -07:00
Alan Donovan
149e030318 go.tools/cmd/ssadump: print packages and functions to stdout, not stderr.
And serialize the printing of each item with a mutex.
It is the formatted output of this tool, after all.

Also: minor doc tweaks.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/114620044
2014-08-01 14:44:37 -04:00
David Symonds
105b764ad0 benchcmp: Fix invocation instructions.
`go test` takes -run and -bench; the -test.run and -test.bench flags
are only for the test binary itself.

LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/113390043
2014-07-22 17:50:39 +10:00
Keith Randall
562b65fda7 vet: LEA* opcodes don't need to have matching length source and destination.
LGTM=rsc
R=golang-codereviews, khr, rsc
CC=golang-codereviews
https://golang.org/cl/117950044
2014-07-21 21:15:39 -07:00
Robert Daniel Kortschak
09286920ba go.tools/cmd/present: move jquery ui code into static
LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/118760043
2014-07-16 16:33:46 +10:00
Francesc Campoy
bbb1c45ba5 go.tools/present: add support for figure captions
LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/110600043
2014-07-15 08:23:16 -07:00
Francesc Campoy
bb2f616e98 go.toosl/cmd/present: Remove border from iframes
If the author wants a border they can add it on their own.

LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/107590045
2014-07-09 13:14:06 +10:00
Robert Daniel Kortschak
f563a1f0f5 go.tools/cmd/present: move dirListTemplate into template file
This change allows the directory front page to be more easily configurable.

Templates are now read only at start-up and stored in a map rather than re-parsed for each page rendering.

LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/109080044
2014-07-08 15:27:33 +10:00
Josh Bleecher Snyder
3e7bc48329 go.tools/cmd/benchcmp: do not generate trailing whitespace
text/tabwriter cells are tab-terminated, not tab-separated. This creates trailing whitespace. However, with left-aligned columns, it is ok not to treat the final element as a cell. Demo: http://play.golang.org/p/m_ajG8SSZe

LGTM=gri
R=golang-codereviews, gobot, gri
CC=golang-codereviews, r
https://golang.org/cl/103650043
2014-07-07 11:55:26 -07:00
Josh Bleecher Snyder
7da5f193b7 go.tools/cmd/vet: detect stupid boolean conditions
This CL introduces two vet checks. Statistics and code below are from a recent 50mb corpus of public code.

1. Check for redundant conjunctions and disjunctions. This check caught 26 instances, of which 20 were clearly copy/paste bugs and 6 appeared to be mere duplication. A typical example:

if xResolution < 0 || xResolution < 0 {
        panic("SetSize(): width < 0 || height < 0")
}

2. Check for expressions of the form 'x != c1 || x != c2' or 'x == c1 && x == c2', with c1 and c2 constant expressions. This check caught 16 instances, of which all were bugs. A typical example:

if rf.uri.Scheme != "http" || rf.uri.Scheme != "ftp" {
        rf.uri.Scheme = "file"
}

Fixes golang/go#7622.

LGTM=rsc, r
R=golang-codereviews, jscrockett01, r, gri, rsc
CC=golang-codereviews
https://golang.org/cl/98120043
2014-07-02 10:39:57 -07:00
Rob Pike
ccb18ed35d go.tools/cmd/goimports: update doc.go to new emacs instructions
LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/103670045
2014-07-01 10:24:22 -07:00
Josh Bleecher Snyder
95a7aeb192 go.tools/cmd/vet: don't panic on commented-out asm
Really two fixes: Don't panic on bad instructions and don't complain about commented out instructions.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/110070044
2014-06-20 16:52:48 -07:00
Josh Bleecher Snyder
9d6cc5fd08 go.tools/cmd/vet: prevent panic on goto without label
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/107260043
2014-06-20 11:08:45 -07:00
Andrew Gerrand
4aa650cf80 go.tools/cmd/godoc: register redirect handler for /dl/
LGTM=minux
R=golang-codereviews, gobot, bradfitz, minux
CC=golang-codereviews
https://golang.org/cl/107050044
2014-06-18 15:44:09 +10:00
Mikio Hara
81fd812913 go.tools/cmd/present: update doc
LGTM=adg
R=golang-codereviews, dan.kortschak, gobot, adg
CC=golang-codereviews
https://golang.org/cl/106860043
2014-06-18 11:23:08 +10:00
Robert Griesemer
2bf6947d09 go.tools/cmd/gotype: fix call site (fix build)
TBR=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/101330046
2014-06-17 11:06:19 -07:00
Peter Collingbourne
02990bd494 go.tools/go/gccgoimporter: keep track of package and import priority
Clients such as compilers need this information in order
to correctly link against imported packages.

This also adds support for the condensed import data format
where the priority information is stored as a suffix of the
condensed import data, as well as support for archive files.

LGTM=gri
R=gri
CC=golang-codereviews, iant
https://golang.org/cl/78740043
2014-06-17 10:56:47 -07:00
Peter Collingbourne
4a6efa0a34 go.tools/go/ssa: add a flag for selecting bare init functions
Bare init functions omit calls to dependent init functions and the
use of an init guard. They are useful in cases where the client uses
a different calling convention for init functions, or cases where
it is easier for a client to analyze bare init functions.

LGTM=adonovan
R=adonovan
CC=golang-codereviews, iant
https://golang.org/cl/78780043
2014-06-16 21:34:51 -04:00
Josh Bleecher Snyder
d46b792624 cmd/vet: check for use of json/xml struct tags with unexported fields
This is a common source of bugs, particularly for those new to Go. Running this on a corpus of public code flagged 114 instances.

This check may need to be updated once issue 7363 is resolved.

LGTM=r
R=golang-codereviews, r
CC=bradfitz, golang-codereviews
https://golang.org/cl/91010047
2014-06-13 18:44:31 -07:00
Andrew Gerrand
5a5dc64a96 go.tools/godoc: fix index reading and writing
In command godoc, set IndexEnabled when the -write_index flag is set.
Previously you would need to (unintuitively) set the -http flag to
achieve this.

In package godoc, set up the FS tree before loading the index, and
then return before starting the index refresh loop. Previously the
index would be loaded and then immediately refreshed, negating the
benefits of the on-disk index.

TBR=bradfitz
R=golang-codereviews
CC=golang-codereviews
https://golang.org/cl/103370046
2014-06-13 16:49:32 +10:00
Andrew Gerrand
93b08999a7 go.tools/cmd/godoc: set corpus.MaxResults in appinit.go
LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/101220045
2014-06-13 15:20:15 +10:00
David Symonds
f895b43688 vet: Rearrange checkers to use a registration system.
This removes much of the AST logic out of main.go,
and makes it easier to build custom vet binaries

The trade-off in this change is for flexibility.
There's very little change in the per-check files,
a lot less code in main.go (specifically the AST walking
logic has shrunk), and it makes it much easier to build
custom vet binaries simply by dropping new source files
in the directory.

LGTM=josharian, r
R=r, josharian, kamil.kisiel
CC=golang-codereviews
https://golang.org/cl/83400043
2014-06-13 15:04:45 +10:00
Andrew Gerrand
83c1b4e7d4 go.tools/cmd/present: register SVG mime type
This will fix the images in Brad's GoCon presentation.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/100950043
2014-06-03 14:16:59 +10:00
Mikio Hara
96cece04e7 go.tools/{cmd/present,playground/socket}: add orighost flag to handle the web origin more flexible
Also fixes the following nits;
- literal IPv6 address handling
- URL host component handling in the case of a wildcard listen
- URL port component handling in the case of no port component in origin

Fixes golang/go#8096.

LGTM=dan.kortschak, adg
R=adg, golang-codereviews, dan.kortschak
CC=golang-codereviews
https://golang.org/cl/102770046
2014-06-02 21:39:33 +09:00
Russ Cox
222283a9c8 go.tools/cmd/benchcmp: add -best flag
If you have multiple runs in old.txt and new.txt
the default behavior is to match them up pairwise
and compare successive pairs (and if you have a
different number of runs in each file, benchcmp
refuses to do anything).

The new -best flag changes the behavior to instead
compare the fastest run of each benchmark from
the two files. This makes sense if you believe that
the fastest speed is the 'actual' speed and the slower
results are due to the computer spending time doing
non-benchmark work while the benchmark was
running.

LGTM=josharian
R=golang-codereviews, josharian
CC=golang-codereviews
https://golang.org/cl/102890047
2014-05-30 21:45:27 -04:00
Andrew Gerrand
d29843f35e go.tools/cmd/present: re-enable transitions
They were disabled by mistake during the move to go.tools.

LGTM=dan.kortschak
R=golang-codereviews, dan.kortschak
CC=golang-codereviews
https://golang.org/cl/98440048
2014-05-21 14:35:45 +10:00
Rob Pike
4374c8910f go.tools/cmd/vet: clean up formatting of the package document
It was very ugly; a little tweaking helps godoc parse it better.
Also make unsafeptr.go not own the package doc (add a blank line)
and put one more sentence about that check into doc.go.

Fixes golang/go#7925.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/98370044
2014-05-19 11:34:31 -07:00
Rob Pike
a8c8f48be3 go.tools/all: the the thes are too frequent, it's clear that that's not what we want
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/98380043
2014-05-19 09:48:30 -07:00
Russ Cox
322a5f1b4c cmd/vet: add amd64p32 (nacl) support to asmdecl check
Also add 'ErrorString', for checking Plan 9's package syscall.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/93410045
2014-05-19 12:31:38 -04:00
Russ Cox
d8a81d8377 cmd/vet: fix line number in asm errors
Before:
: asm_amd64.s:16: [amd64] invalid offset new+16(FP); expected new+8(FP)
: asm_amd64.s:26: [amd64] invalid offset new+16(FP); expected new+8(FP)

After:
asm_amd64.s:16: [amd64] invalid offset new+16(FP); expected new+8(FP)
asm_amd64.s:26: [amd64] invalid offset new+16(FP); expected new+8(FP)

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/91510043
2014-05-19 12:31:28 -04:00
Rob Pike
6f17d00f0d go.tools: fix various minor issues found by go vet
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/96360048
2014-05-19 08:47:28 -07:00
Russ Cox
b752e9ffdf cmd/vet: diagnose use of unsafe.Pointer to convert integer to pointer
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/100470044
2014-05-15 15:32:51 -04:00
Robert Obryk
91b1b28499 go.tools/cmd/vet: fix a panic on invalid AddInt
Ignore calls to various flavours of atomic.AddInt with a wrong
number of arguments.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/91370045
2014-05-14 12:16:58 -07:00
Alex Brainman
d52b449ed7 go.tools/cmd/godoc: prevent duplicate GOROOT/GOPATH in environment in TestTypeAnalysis
LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/94430044
2014-05-14 12:39:20 +10:00
Andrew Gerrand
a41b4fc37a go.tools/cmd/present: update docs after move
LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/99060043
2014-05-13 09:17:18 +10:00
Andrew Gerrand
ca18093fea go.tools/cmd/present: add present tool
LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/97030045
2014-05-05 14:55:27 -07:00
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
Robert Griesemer
f84e8b3f03 go.tools/cmd/godex: print correct type for const/var decls
The old code printed the underlying type; e.g., the type
of time.Millisecond was reported to be int64 rather than
time.Duration.

Testsuite (and corresponding tests) in progress (another CL).

LGTM=adonovan
R=adonovan, dsymonds
CC=golang-codereviews
https://golang.org/cl/94770045
2014-04-29 19:58:47 -07:00
Stephen Weinberg
55d5722095 imports, cmd/goimports: add missing package main if func main exists
Assuming:
        1) package declaration does not exist
        2) the Fragment option is set
        3) a main function exists

We will assume it is a main package and add the declaration.

This change also sets the Fragment option in goimports.

LGTM=crawshaw, bradfitz
R=bradfitz, crawshaw
CC=golang-codereviews
https://golang.org/cl/96850044
2014-04-28 17:15:33 -04:00
Alan Donovan
c288136f0c go.tools/cmd/eg: Use Print, not Printf, to print Help string.
Fixes golang/go#7861

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/95770043
2014-04-25 12:03:38 -04:00
Alan Donovan
4a9f74ad65 cmd/godoc: wait up to 500ms for results of -analysis=type.
(The test thread is racing with the analysis thread, which
takes around 4ms on this input.)

LGTM=gri
R=gri, bradfitz
CC=golang-codereviews
https://golang.org/cl/89780044
2014-04-21 17:56:06 -04:00
Robert Griesemer
de6fbfe0ea go.tools/cmd/godex: make relative package paths work
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/89160044
2014-04-18 12:44:23 -04:00
Alan Donovan
4843aaee02 godoc: add very basic integration test of godoc -analysis=type.
Also: fix careless regression introduced yesterday.

LGTM=bgarcia
R=bgarcia
CC=golang-codereviews
https://golang.org/cl/88880043
2014-04-17 15:51:27 -04:00
Robert Griesemer
a7ddb1e509 godex: improved printing of numeric constants
TODO: Add testing code (another CL).

LGTM=adonovan
R=golang-codereviews, adonovan
CC=golang-codereviews
https://golang.org/cl/88090044
2014-04-17 11:28:24 -07:00
Alan Donovan
503140c72e godoc: documentation of -analysis features.
The text and images are "baked in" to the godoc executable's
rodata section (~300KB) and are accessible from the godoc
server itself at /lib/godoc/analysis/help.html.

In due course, the page will become visible at
http://golang.org/lib/godoc/analysis/help.html, which will be
the canonical location for this doc (in announcements, etc).

The page is temporarily visible here, for those on the Google corp network:
http://172.26.104.127:7777/lib/godoc/analysis/help.html

Also:
- add link to new doc from source view pages.
- document -analysis flag in cmd/godoc/doc.go
- fix indentation of -analysis flag's help string

LGTM=gri
R=gri, bgarcia, r
CC=golang-codereviews
https://golang.org/cl/87110045
2014-04-16 16:35:08 -04:00
Josh Bleecher Snyder
6157b5a256 go.tools/cmd/benchcmp: expand documentation
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/85390044
2014-04-14 17:00:04 -07:00
Alan Donovan
7ef831a4e6 go.tools/go/ssa: perform nil check when taking value of interface method.
+ test.

Fixes golang/go#7269

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/84650046
2014-04-09 18:00:57 -04:00
Robert Griesemer
fa0f6bd591 go.tools/cmd/godex: update documentation
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/83580046
2014-04-07 13:49:05 -07:00
Alex Brainman
2961704231 go.tools/cmd/godoc: correct TestCLI match string on windows
Fixes golang/go#7707

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/84280045
2014-04-06 12:41:24 +10:00
Alan Donovan
bfcffc697d go.tools/refactor/eg: an example-based refactoring tool.
See refactor/eg/eg.go for details.

LGTM=crawshaw
R=crawshaw, gri, kamil.kisiel, josharian
CC=golang-codereviews
https://golang.org/cl/81010043
2014-04-02 12:24:55 -04:00
Robert Griesemer
fb8f3e8fbf go/tools/cmd/godex: print combined method sets
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/82890044
2014-04-02 08:49:21 -07:00
Robert Griesemer
4775a5ed46 go.tools/cmd/godex: remove spurious println
TBR=adonovan

TBR=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/82040043
2014-03-28 15:26:40 -07:00
Robert Griesemer
723686bb4b go.tools/cmd/godex: permit absolute paths for gccgo-generated package (export) files
TBR=adonovan

TBR=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/82030043
2014-03-28 15:17:20 -07:00
Robert Griesemer
7e60d06cfc go.tools/cmd/godex: don't generate prefixes for local and absolute path arguments
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/81340047
2014-03-28 14:59:25 -07:00
Robert Griesemer
1faba6e3b8 go.tools/cmd/godex: replicate path logic for gccgo-new importer
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/81990043
2014-03-28 14:50:14 -07:00
Robert Griesemer
700390eaed go.tools/cmd/godex: fix prefix generation, filtering, formatting
Details:
- auto-generate prefixes for std lib (e.g., "godex big" works now)
- apply filtering to package-level objects only
- nicer formatting of single-entry const, var, or type declaration

TBR=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/81360046
2014-03-28 12:21:51 -07:00
Robert Griesemer
f293460f67 go/tools/cmd/godex: don't print unexported methods
and print exported methods of unexported types

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/80920046
2014-03-27 10:49:59 -07:00
Robert Griesemer
8b161c33a9 go.tools/cmd/godex: support for common path prefixes
All of these work now as expected:

        godex code.google.com/p/go.tools/go/types
        godex go.tools/go/types
        godex go/types
        godex types

Also improved logging/verbose mode.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/80930043
2014-03-26 14:47:52 -07:00
Robert Griesemer
03478d3d3e go.tools/cmd/godex: better argument handling
1) Split a path.name argument at the last '.' that
   is not part of the path.

2) Try various importers always in the same order
   for consistent results (use lists instead of maps).

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/80790043
2014-03-26 09:54:20 -07:00
Robert Griesemer
8648e1a481 go.tools/cmd/godex: nicer formatting
- handle indentation
- write non-empty tuples and signatures in multiple lines
- don't crash for package unsafe

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/79920044
2014-03-26 08:38:40 -07:00
Robert Griesemer
4a27ee3a1b go.tools/cmd/godex: a tool to dump export information
Initial implementation. Lots of missing pieces.

Example use:
        godex math
        godex math.Sin
        godex math.Sin math.Cos

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/76890044
2014-03-25 15:26:38 -07:00
Alan Donovan
7877131709 cmd/godoc: fix careless crash introduced by recent analysis CL
+ basic integration test

LGTM=bgarcia
R=bgarcia, bradfitz
CC=golang-codereviews
https://golang.org/cl/76410045
2014-03-16 16:17:13 -04:00
Alan Donovan
80c4f06c0f go.tools/godoc: server mode: add support for type and pointer analysis.
See analysis.go for overview of new features.
See README for known bugs and issues.

Much UI polish, testing and optimization work remains, but
this is a starting point.

Flag: we add a new flag -analysis=type,pointer, default "",
for adventurous users only at this stage.
Type analysis takes ~10s for stdlib + go.tools;
Pointer analysis (currently) takes several minutes.

Dependencies: we now include jquery.treeview.js and its GIF
images among the resources.  (bake.go now handles binary.)

LGTM=crawshaw, bgarcia
R=crawshaw, bgarcia
CC=bradfitz, golang-codereviews
https://golang.org/cl/60540044
2014-03-14 18:58:22 -04:00
Brad Garcia
a81074af88 godoc: Output "No match found" only if there is no ast or docs included in info.
Fixes golang/go#7499.

R=minux.ma
CC=golang-codereviews
https://golang.org/cl/75400043
2014-03-14 10:00:10 -04:00
David Symonds
7c69950f7f vet: Don't consider %T for recursive stringers.
Unlike the other anyType verbs, %T never calls String.

Fixes golang/go#7540.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/75580045
2014-03-14 16:08:04 +11:00
David Symonds
d4c8d5dae3 vet: Broaden suppression of recursive stringer warning.
Updates golang/go#6212.

LGTM=r, gri
R=r, gri
CC=golang-codereviews
https://golang.org/cl/75130043
2014-03-13 11:19:34 +11:00
Rob Pike
e239f1b3f2 go.tools/cmd/vet: don't check for shadowing of blank identifier
It's pointless.
Also this fixes a crash, because the blank identifier no longer appears as a
defined object after CL 74190043 so we were getting nil pointer violations.
Even better, we get to re-enable a disabled test.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/75140043
2014-03-13 10:27:55 +11:00
Robert Griesemer
ea79d922e6 go.tools/go/vet: temporarily disable some tests to fix build
Revert this CL once a proper fix is in place.

LGTM=adonovan
R=r, adonovan
CC=golang-codereviews
https://golang.org/cl/74930043
2014-03-12 11:56:25 -07:00
Rob Pike
6bd3206b1f go.tools/cmd/vet: allow checks to be disabled explicitly as well as set explicitly
Now we can say
        vet -printf=false
to disable the printf test but run all others.
Implemented by creating a tri-state boolean flag that records whether it has been
set explicitly; before this, -printf=false was not distinguishable from not having
mentioned the printf flag at all.

Fixes golang/go#7422.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/72330043
2014-03-07 16:02:49 +11:00
Rob Pike
95c9b7bad1 go.tools/cmd/vet: replace warnings by errors
Over time, a number of modules were added that used Warn instead of Bad
to report problems with the code, but the documentation states that
if there is a problem, the exit code must be 1, not 0. Warn does not set the
exit code and should be used only for internal errors and messages
triggered by the -v flag.

There's nothing substantive here except calling the other function in a few
places.

Fixes golang/go#7017.

LGTM=crawshaw
R=golang-codereviews, crawshaw
CC=golang-codereviews
https://golang.org/cl/71860044
2014-03-07 15:31:28 +11:00
Rob Pike
31c219bef7 go.tools/cmd/vet: change reporting of incorrect error count in Printf
The old code was misleading in saying how many args were present.
Change the wording of the message to be unambiguous and change
the presentation of the format to include the full directive, making
it easier to correlate with the input (and fixing a silent bug).
Fixes golang/go#6248.

LGTM=dsymonds
R=golang-codereviews, dsymonds
CC=golang-codereviews
https://golang.org/cl/69120044
2014-03-04 15:41:49 +11:00
David du Colombier
ec0de5a8bc go.tools/cmd/godoc: fix test on Plan 9
LGTM=bradfitz
R=minux.ma, bradfitz
CC=golang-codereviews
https://golang.org/cl/70610044
2014-03-02 19:34:05 +01: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
Brad Garcia
aaca3a4f95 godoc: Remove bogus messages referring to "/target".
Fix package text display spacing.
Fixes golang/go#7395.

R=bradfitz, sameer
CC=golang-codereviews
https://golang.org/cl/68210043
2014-02-26 13:21:44 -05:00
Rob Pike
ee3eeefaa3 cmd/vet: check for nil result set in isStringer
Fixes golang/go#7149.

LGTM=gri
R=golang-codereviews, gri
CC=golang-codereviews
https://golang.org/cl/68260044
2014-02-24 11:39:42 -08:00
Rob Pike
cde4d316d2 go.tools/cmd/vet: docs: explain the command line interface better
How it handles packages vs. directories vs. files was not explained.

LGTM=rsc
R=golang-codereviews, gobot, rsc
CC=golang-codereviews
https://golang.org/cl/67150043
2014-02-24 10:44:02 -08:00
David du Colombier
374c600cae go.tools/cmd/vet: disable TestVet on Plan 9
LGTM=minux.ma
R=golang-codereviews, minux.ma
CC=golang-codereviews
https://golang.org/cl/64410043
2014-02-20 21:43:24 +01:00
Josh Bleecher Snyder
e8c291b808 go.tools/cmd/benchcmp: sort by original benchmark order by default
benchcmp now preserves benchmark order. This restores the original
misc/benchcmp behavior. This also makes the output of benchcmp stable,
and groups together multiple -cpu results.

Magnitude-based sorting is still available via the -mag flag.
It is useful for surfacing items of note (particularly changes
in allocs) when making compiler changes and running broad
benchmarks.

Fixes golang/go#7259.

LGTM=dave
R=dave, mtj
CC=bradfitz, dvyukov, golang-codereviews
https://golang.org/cl/60840045
2014-02-19 07:44:49 -08:00
Andrew Gerrand
47596b4b81 go.tools/cmd/vet: add stable checks to doc.go
These are the simplest possible descriptions of each command.
They may be fleshed out later.

Fixes golang/go#7298.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/61480044
2014-02-13 11:05:01 +11:00
Brad Fitzpatrick
05bc285da4 cmd/goimports: update doc, remove old gofmt flags
Don't say the word "fork" (not accurate), and remove the
tab/comment flags that were removed from gofmt.

LGTM=adg
R=golang-codereviews, adg
CC=golang-codereviews
https://golang.org/cl/61410052
2014-02-12 08:35:02 -08:00
Alan Donovan
08fadac071 go.tools/go/loader: simplify command-line syntax.
Previously, each word could be a package import path or a
comma-separated list of *.go file names.  Now, if the
first word ends with ".go", all words are assumed to be
Go source files.  This makes it impossible to specify
two ad-hoc packages from source files, but no-one needs that.

FromArgs also takes a boolean indicating whether tests
are wanted or not.

Also: ssadump: add -test flag to set that boolean.
For the oracle it's always true.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/61470047
2014-02-11 16:52:16 -05:00
Alan Donovan
1f29e74bfa go.tools/go/types: remove Type.MethodSet() method.
Method-set caching is now performed externally using a MethodSetCache (if desired), not by the Types themselves.

This a minor deoptimization due to the extra maps, but avoids a situation in which method-sets are computed and frozen prematurely. (See b/7114)

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/61430045
2014-02-11 16:49:27 -05:00
Robert Griesemer
20efc5ba73 go.tools/go/types: use init cycle tracking for all const and var cycles
Also rename types.Assertable -> types.AssertableTo per adonovan.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/59680044
2014-02-03 16:02:56 -08:00
Robert Griesemer
4dcaee97b2 go.tools/cmd/vet: use new Assertable predicate (fix build)
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/59210045
2014-02-03 11:39:10 -08:00
Josh Bleecher Snyder
285f6fe2f6 go.tools/cmd/benchcmp: add benchcmp
This is intended to replace the awk-based misc/benchcmp.
It mostly matches the existing misc/benchcmp.
Notable changes:

* Written in Go.
* Minor whitespace changes in the output; the tabular nature of the
  output is preserved, as is most number formatting and verbiage.
* Comparisons within each section are sorted from highest change to lowest.
* Proper handling of multiple benchmarks with the same name (issue 7016).
* Does not omit benchmark comparisons for which the new value is zero.
* Adds -changed flag to only show benchmarks whose value have changed.
  Useful for memory-oriented, large-scale benchmark comparisons.
* Has tests.
* Formats small ns measurements with extra precision.

Updates golang/go#7016.

LGTM=r
R=golang-codereviews, dave, dvyukov, oleku.konko, bradfitz, gobot, r
CC=golang-codereviews
https://golang.org/cl/47980043
2014-01-31 15:39:59 -08:00
Brad Garcia
d682175c6e godoc: test fixes for recent cmdline changes.
Tests broken by:
https://code.google.com/p/go/source/detail?r=1666da2583f4&repo=tools

R=gri, adonovan
CC=golang-codereviews
https://golang.org/cl/58780043
2014-01-30 15:32:23 -05:00
Brad Garcia
f97ec06d2c godoc: forward /pkg/C links to /cmd/cgo.
Fixes golang/go#5651.

R=bradfitz
CC=golang-codereviews
https://golang.org/cl/58660043
2014-01-30 07:07:12 -05:00
Alan Donovan
64ec206bfd go.tools/go/types: combine Info.{Types,Values} maps.
This results in significant improvement to type-checking time:
it reduces by 4% the entire running time of ssa/stdlib_test
(GOMAXPROCS=8, n=7).

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/57770043
2014-01-28 16:46:24 -05:00
Robert Griesemer
ebfa4efbc4 go.tools/go/types: cleanup: more consistent exported predicate names
Renamed predicates:
IsIdentical -> Identical
IsAssignableTo -> AssignableTo
Signature.IsVariadic -> Signature.Variadic
Object.IsExported -> Object.Exported

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/53370043
2014-01-28 10:57:56 -08:00
Alan Donovan
3fc0fc1310 go.tools: rename packages.
Was:		Now:
ssa		go/ssa
importer	go/loader
pointer		go/pointer

Next CL: call -> go/callgraph (requires more care)

R=gri, crawshaw
CC=golang-codereviews
https://golang.org/cl/52960043
2014-01-16 09:33:58 -05:00
Alan Donovan
e8afbfad8c go.tools/importer: API rethink.
The Importer type has been replaced with Config and Program.

Clients populate a Config, directly or more usually via
convenience functions.  They then call its Load() method to do
all of the typechecking and transitive-closure computation.

ssa.NewProgram and ssa.CreatePackages have been fused into
ssa.Create, which now cannot fail, since (*Config).Load()
reports all type errors.

Also:
- The addition of an ssa.GlobalDebug builder mode flag
  eliminates a loop-over-packages repeated in many clients.
- PackageInfo.Err flag unexported.  Clients never see bad infos now.
- cmd/ssadump: now only looks for func "main" in package "main".
- importsOf deleted, was dead code.

STILL TODO:
- ParseFile seems like API creep (though it's convenient)
  and CreateFromFiles is dangerous (w.r.t. FileSet identity).
  Need to think more...
- the need for clients to rely on elementwise correspondence
  of Config.CreatePkgs and Program.Created is a little sad.
- The command-line interface has not changed.
  That will happen in a follow-up.
  r recommends using a repeated flag: -package p -package q ...

R=gri
CC=axwalk, frederik.zipp, golang-codereviews
https://golang.org/cl/49530047
2014-01-15 21:37:55 -05:00
Alan Donovan
3d82e7e94a go.tools/ssa: fix crash in SSA builder when using GCImporter to satisfy imports (ssadump -build=G).
Packages were not being created for all types.Packages,
specifically, indirectly imported packages were missing.
(*Program).CreatePackages now iterates over the type-checker's
package map too.

Also: removed all concurrency from importer.  I think it was
incorrect (and hard to fix).

Also: change LoadInitialPackages so that all named packages
are loaded from source.  This happens regardless of whether
GCImporter is used to satisfy imports.

Details:
- importer.Config.SourceImports flag determines whether to
  load all packages from *.go source.
  (Before, this was indicated by Config.Build != nil.)
- importer.Config.Build field effectively defaults to
  &go/build.Default.  A zero importer.Config is now usable.
- importer.Importer.Config field is now exported.
- LoadPackage renamed to ImportPackage since the resulting
  packages may come from GCImporter (and be incomplete).
- doImport and ImportPackage fused.

Fixes golang/go#7028

R=gri, axwalk
CC=golang-codereviews
https://golang.org/cl/48770043
2014-01-09 14:11:54 -05:00
Peter Collingbourne
d0b88d2206 cmd/gotype: add -gccgo flag
R=gri
CC=golang-codereviews, golang-dev
https://golang.org/cl/39050043
2014-01-08 15:25:17 -08:00
Alan Donovan
5612f0615f go.tools/ssa: use correct word size for GOARCH during type checking, interpretation.
Also report an error for "cross-interpretation": not supported
due to the interpreter's assumption that host and target
{int,uint,uintptr} are the same.  (Too tedious and messy to fix.)

Tested manually:

% cat d.go
package main
const m = ^uintptr(0)
const w = m>>8&1 + m>>16&1 + m>>32&1
func main() { println(m, w) }

% ./ssadump -build=P -run d.go
package main:
  const m          m = 18446744073709551615:uintptr
  const w          w = 3:uintptr
18446744073709551615 3

% GOARCH=386 ./ssadump -build=P -run d.go
package main:
  const m          m = 4294967295:uintptr
  const w          w = 2:uintptr
Error: Cross-interpretation is not yet supported (target has GOARCH 386, interpreter has amd64).

Fixes golang/go#7080

R=gri
CC=golang-codereviews
https://golang.org/cl/49070043
2014-01-08 14:46:17 -05:00
Brad Garcia
a28efa5d8c godoc: add ability to change or disable the display of search results.
The display of search results can now be changed. A slice of functions for displaying the results can now be provided.  By default, three functions are provided to display documentation, source code, and textual results.
This makes it possible to replace them with equivalents that, say,
obtain search results from alternative source code search engines.

R=bradfitz, adg
CC=golang-codereviews
https://golang.org/cl/43470043
2014-01-06 09:51:01 -05:00
Pavel Zinovkin
3658622d3e go.tools/cmd/goimports: Fixed url
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/40610046
2014-01-02 11:02:13 -08:00
Andrew Gerrand
efcc5ffb58 go.tools/cmd/goimports: rename README to doc.go
README is a GitHub thing. Let's do the godoc thing.

R=golang-dev, crawshaw
CC=golang-dev
https://golang.org/cl/44030046
2013-12-20 09:26:26 +11:00
Rob Pike
bae6bf6180 go.tools/cmd/vet: improve error message for build tag problems
Fixes golang/go#6979.

R=golang-dev, dave, iant
CC=golang-dev
https://golang.org/cl/37720048
2013-12-18 16:06:56 -08:00
David Crawshaw
c87866116c go.tools/imports: move goimports from github to go.tools.
From revision d0880223588919729793727c9d65f202a73cda77.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/35850048
2013-12-17 21:21:03 -05:00
Brad Fitzpatrick
59db975409 godoc: limit concurrency to local disk filesystem
Not for Go 1.2.  Still needs a flag.

Linux at least (and likely other OSes) don't like you doing
a few hundred readdirs at once and spawing as many threads.

R=golang-dev, adg, jeremyjackins
CC=golang-dev
https://golang.org/cl/30620043
2013-12-16 11:25:50 -08:00
Alan Donovan
8b9d1fd507 go.tools/oracle: implements: now shows whole-program implements relation for selected type.
(Previously it showed the implements relation for all types within the query package.)

R=crawshaw
CC=golang-dev
https://golang.org/cl/42000043
2013-12-13 18:00:55 -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
Josh Bleecher Snyder
866b24e166 cmd/vet: check for sync types being copied during function calls
Using a type containing a sync type directly
in a function call (whether as a receiver,
a param, or a return value) is an easy way
to accidentally copy a lock or other sync primitive.
Check for it.

The test as implemented does not provide 100%
coverage; see the discussion near the bottom of
testdata/copylock.go for shortcomings.

Fixes golang/go#6729.

R=adg, r, dsymonds
CC=golang-dev
https://golang.org/cl/23420043
2013-12-09 20:14:28 -08:00
Andrew Wilkins
df34f98521 go.tools/cover: split parsing code out from cmd/cover
Split the profile parsing code out of cmd/cover into
a reusable package, to support third-party coverage
tools.

R=golang-dev, r, adg
CC=golang-dev
https://golang.org/cl/36050045
2013-12-03 20:55:21 -08:00
Shenghou Ma
5d386107a0 go.tools/cmd/oracle: output help messages to stderr for consistency
Fixes golang/go#6838.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/36820043
2013-12-03 17:37:59 -05:00
Brad Garcia
f3faf8b6e0 godoc: add search results that point to documentation instead of source.
Add explicit options to Corpus to control search indexing of documentation, Go source code, and full-text.

R=bradfitz, r
CC=golang-dev
https://golang.org/cl/24190043
2013-11-21 11:55:42 -05:00
Brad Garcia
b844907f9f godoc: refactor command-line mode handling.
R=bradfitz
CC=golang-dev
https://golang.org/cl/29230044
2013-11-20 09:56:10 -05:00
Robert Griesemer
27563ff576 go.tools/go/types: move gcimporter to its own package
- fixed a couple of TODOs
- various cleanups along the way
- adjusted clients

Once submitted, clients of go/types that don't explicitly
specify Config.Import will need to add the extra import:

import _ "code.google.com/p/go.tools/go/gcimporter"

to install the default (gc) importer in go/types.

R=adonovan, gri
CC=golang-dev
https://golang.org/cl/26390043
2013-11-14 14:11:43 -08:00
Brad Fitzpatrick
626e9341d5 godoc: add forgotten file from last CL to fix build
R=adg, franciscossouza, dave
CC=golang-dev
https://golang.org/cl/25650043
2013-11-12 15:46:25 -08:00
Robert Griesemer
7b183d1766 go.tools/go/types, cmd/gotype: fix early bailout
Clients must have chance to look at panics they
are raising.

R=adonovan
CC=golang-dev
https://golang.org/cl/23820043
2013-11-08 12:52:57 -08:00
Robert Griesemer
0c141425f6 go.tools/cmd/gotype: parse in parallel
Performance increase is much smaller than expected;
need to investigate. Possibly, repeatedly (for each
line) accessing file sets from multiple goroutines
(in the scanner) is a bottle neck; or perhaps i/o.

R=adonovan
CC=golang-dev
https://golang.org/cl/23090043
2013-11-07 13:32:02 -08:00
Rob Pike
2afbb1cd5f go.tools/cmd/vet: handle symbolic TEXT annotations
The symbolic names such as NOSPLIT for annotations on the TEXT
directive appeared after vet started checking .s files. This CL tweaks
the regular expression to allow CAPITALS and the symbols | and +
as well as digits in that field, and interprets NOSPLIT as equivalent
to 7 in that field. All magic.

Fixes golang/go#6695

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/18700044
2013-11-01 11:49:11 -07:00
Robert Griesemer
03e3f0cf81 go.tools/cmd/gotype: make gotype use go/build
This CL makes gotype usable again. Removed -r
(recursive) mode; use go/build to determine
the correct set of Go files when processing
a directory. The -v (verbose) mode now prints
some basic stats (duration, number of files,
lines, and lines/s).

Thoroughly restructured the code.

Applying gotype -v -a . to the go/types directory:
128.94141ms (40 files, 12008 lines, 93127 lines/s)

On a 2.8 GHz Quad-Core Intel Xeon, 800 MHz DDR2 FB-DIMM,
with go/types built with the (interal) debug flag set to
false. There's still quite a bit of room for performance
improvement in all parts of the code since no tuning has
been done.

R=golang-dev, adonovan
CC=golang-dev
https://golang.org/cl/19930043
2013-10-31 10:01:58 -07:00
Alan Donovan
8636f40baf go.tools/ssa: CreateTestMainPackage: synthesize test driver as a package ("testmain") not 'main' function.
This allows us to run/analyze multiple tests.
Also it causes the production code packages to be properly initialized.

Also:
- cmd/ssadump: improved usage message (add example;
  incorporate LoadInitialPackages usage; explain how -run
  finds main).
- pointer, oracle, ssa/interp: use CreateTestMainPackage.
- ssa/builder.go: remove 'rundefers' instruction from package init,
  which no longer uses 'defer'.

R=gri
CC=golang-dev
https://golang.org/cl/15920047
2013-10-23 18:07:53 -04:00
Andrew Gerrand
36c288d6d7 go.tools/cmd/godoc: search go.tools/cmd before $GOROOT/cmd
Fixes golang/go#6527.

R=rsc
CC=golang-dev
https://golang.org/cl/14725043
2013-10-18 10:42:41 +09:00
Alan Donovan
2accef29d7 go.tools/ssa: implement correct control flow for recovered panic.
A function such as this:
        func one() (x int) {
                defer func() { recover() }()
                x = 1
                panic("return")
        }
that combines named return parameters (NRPs) with deferred calls
that call recover, may return non-zero values despite the
fact it doesn't even contain a return statement. (!)

This requires a change to the SSA API: all functions'
control-flow graphs now have a second entry point, called
Recover, which is the block at which control flow resumes
after a recovered panic.  The Recover block simply loads the
NRPs and returns them.

As an optimization, most functions don't need a Recover block,
so it is omitted.  In fact it is only needed for functions that
have NRPs and defer a call to another function that _may_ call
recover.

Dataflow analysis of SSA now requires extra work, since every
may-panic instruction has an implicit control-flow edge to
the Recover block.  The only dataflow analysis so far implemented
is SSA renaming, for which we make the following simplifying
assumption: the Recover block only loads the NRPs and returns.
This means we don't really need to analyze it, we can just
skip the "lifting" of such NRPs.  We also special-case the Recover
block in the dominance computation.

Rejected alternative approaches:
- Specifying a Recover block for every defer instruction (like a
   traditional exception handler).
   This seemed like excessive generality, since Go programs
   only need the same degenerate form of Recover block.
- Adding an instruction to set the Recover block immediately
   after the named return values are set up, so that dominance
   can be computed without special-casing.
   This didn't seem worth the effort.

Interpreter:
- This CL completely reimplements the panic/recover/
  defer logic in the interpreter.  It's clearer and simpler
  and closer to the model in the spec.
- Some runtime panic messages have been changed to be closer
  to gc's, since tests depend on it.
- The interpreter now requires that the runtime.runtimeError
  type be part of the SSA program.  This requires that clients
  import this package prior to invoking the interpreter.
  This in turn requires (Importer).ImportPackage(path string),
  which this CL adds.
- All $GOROOT/test/recover{,1,2,3}.go tests are now passing.

NB, the bug described in coverage.go (defer/recover in a concatenated
init function) remains.  Will be fixed in a follow-up.

Fixes golang/go#6381

R=gri
CC=crawshaw, golang-dev
https://golang.org/cl/13844043
2013-10-14 15:38:56 -04:00
Rob Pike
e4256a40f4 go.tools/cmd/cover: for range loops might contain function literals
Break the basic block at the function literal. The code to do this analysis
was already there; this CL just factors it out more nicely and uses it in
one new place. Also adds a test.

Fixes golang/go#6555.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/14601043
2013-10-11 10:32:36 -07:00
Andrew Gerrand
7b481db506 go.tools/cmd/godoc: search go.tools/cmd for command docs
Update golang/go#6527

R=r, dsymonds
CC=golang-dev
https://golang.org/cl/14526053
2013-10-11 10:36:50 +09:00
Andrew Gerrand
ce4c627192 go.tools/cmd/cover: move docs to separate doc.go
The doc.go files will be copied into the binary distributions'
source tree that "godoc cover" works.

R=r
CC=golang-dev
https://golang.org/cl/14599045
2013-10-11 09:13:58 +09:00
Alan Donovan
f5b337da55 go.tools/cmd/cover: preserve comments, as other build tools may need "// +build" directives.
Also: fix a crash when a file already contains 'import "sync/atomic"'.

R=r, gri
CC=golang-dev
https://golang.org/cl/14441052
2013-10-10 15:29:24 -04:00
Robert Griesemer
f50f6c858a go.tools/go/types: nil is not a constant + misc. cleanups
- removed support for nil constants from go/exact
- instead define a singleton Nil Object (the nil _value_)
- in assignments, follow more closely spec wording
  (pending spec CL 14415043)
- removed use of goto in checker.unary
- cleanup around handling of isRepresentable for
  constants, with better error messages
- fix missing checks in checker.convertUntyped
- added isTyped (== !isUntyped) and isInterface predicates
- fixed hasNil predicate: unsafe.Pointer also has nil
- adjusted ssa per adonovan
- implememted types.Implements (wrapper arounfd types.MissingMethod)
- use types.Implements in vet (and fix a bug)

R=adonovan, r
CC=golang-dev
https://golang.org/cl/14438052
2013-10-09 14:17:25 -07:00
Dominik Honnef
d5044c7ed2 go.tools/cmd/vet: Update canonical method check for new xml.Marshaler/Unmarshaler interfaces
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/14484043
2013-10-07 11:10:36 -07:00
Rob Pike
51613a10d7 go.tools/cmd/cover: sort the file names in the output presentation
Present the files in lexical order so the output is reproducible
and easier to navigate. Do a little type rearrangement to simplify
things while we're there.

R=adg
CC=golang-dev
https://golang.org/cl/14357043
2013-10-03 16:37:34 -07:00
Andrew Gerrand
dcad628c68 go.tools/cmd/blog: handle "/blog/" redirect properly
The redirect.PrefixHandler redirects "/foo/" to "/foo", which is what
we want in most cases ("/cl/", "/change/", etc) but not here.
So wrap it with a handler that handles "/blog/" explictly.

R=dsymonds
CC=golang-dev
https://golang.org/cl/14326043
2013-10-03 18:10:57 +10:00
Andrew Gerrand
3a3a765782 go.tools/cmd/godoc: fix app engine version; update build script and readme
R=golang-dev, dsymonds, bradfitz
CC=golang-dev
https://golang.org/cl/12897045
2013-10-03 14:29:16 +10:00
Russ Cox
1d95d02fef go.tools/cmd/godoc: point at doc.ToHTML documentation for formatting rules
Fixes golang/go#5429.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/14292043
2013-10-02 22:08:24 -04:00
Andrew Gerrand
401293d22c go.tools/godoc: provide an explicit mux to register redirects
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/14199043
2013-10-02 13:13:34 +10:00
Andrew Gerrand
d20f86cc8e go.tools/godoc: move redirect helpers to new package
Update golang/go#6512

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/14193043
2013-10-01 16:32:13 +10:00
Robert Griesemer
49904d9a2c go.tools/cmd/gotype: use go/types identifier resolution
R=adonovan
CC=golang-dev
https://golang.org/cl/14146043
2013-09-30 12:59:02 -07:00
Andrew Gerrand
0ebdd2c316 go.tools/cmd/html2article: move command from go.blog repository
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/14009043
2013-09-27 10:40:53 +10:00
Nathan John Youngman
cb07517a77 go.tools/cover: validate flags with appropriate error messages
Fixes golang/go#6444.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/13956043
2013-09-26 18:11:03 +10: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
Nathan John Youngman
84cae5a52d go.tools/cover: clean up usage information
R=golang-dev, r, minux.ma
CC=golang-dev
https://golang.org/cl/13532052
2013-09-24 17:27:26 +10:00
Alan Donovan
3371b79a96 go.tools/pointer: reflect, part 2: channels.
(reflect.Value).Send
        (reflect.Value).TrySend
        (reflect.Value).Recv
        (reflect.Value).TryRecv
        (reflect.Type).ChanOf
        (reflect.Type).In
        (reflect.Type).Out
        reflect.Indirect
        reflect.MakeChan

Also:
- specialize genInvoke when the receiver is a reflect.Type under the
  assumption that there's only one possible concrete type.  This
  makes all reflect.Type operations context-sensitive since the calls
  are no longer dynamic.
- Rename all variables to match the actual parameter names used in
  the reflect API.
- Add pointer.Config.Reflection flag
  (exposed in oracle as --reflect, default false) to enable reflection.
  It currently adds about 20% running time.  I'll make it true after
  the presolver is implemented.
- Simplified worklist datatype and solver main loop slightly
  (~10% speed improvement).
- Use addLabel() utility to add a label to a PTS.

(Working on my 3 yr old 2x2GHz+4GB Mac vs 8x4GHz+24GB workstation,
one really notices the cost of pointer analysis.
Note to self: time to implement presolver.)

R=crawshaw
CC=golang-dev
https://golang.org/cl/13242062
2013-09-23 16:13:01 -04:00
Andrew Gerrand
eb130cb481 go.tools/cmd/cover: add content-type meta tag to HTML output
Fixes golang/go#6435.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/13822045
2013-09-23 13:57:03 +10:00
Alan Donovan
0c4a02a8c4 go.tools/oracle: improve usage messages.
Full help is only displayed when -help is requested;
CLI usage errors just remind the the user of this flag.

R=r, crawshaw
CC=golang-dev
https://golang.org/cl/13523048
2013-09-20 11:35:00 -04:00
Yasuhiro Matsumoto
7959c09b86 go.tools/cmd/oracle: Encoding issue, Possible to describe modified file
line2byte doesn't handle non utf-8 fileencoding. So added s:getpos().
        And also, changing errorformat is not right way on go filetype.
        Added range operations.

R=golang-dev, kamil.kisiel, dsymonds, dominik.honnef
CC=golang-dev
https://golang.org/cl/13656045
2013-09-20 11:09:27 +10:00
Rob Pike
34fbb29ae0 go.tools/gotype: move to go.tools/cmd/gotype
Commands in the go.tools repo should be under the cmd subdirectory.

R=gri, adg
CC=golang-dev
https://golang.org/cl/13768044
2013-09-19 11:38:07 +10:00
Andrew Gerrand
f54bd1aebf go.tools/cmd/godoc: update import paths
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/13770043
2013-09-19 10:59:21 +10:00
Andrew Gerrand
072133c61b go.tools/cmd/godoc: include the blog server
Defer parsing of blog content until accessed for faster startup.
Fall back on redirect if blog content unavailable locally.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/13335052
2013-09-18 15:20:41 +10:00
Rob Pike
6ad0d283e1 go.tools/cmd/vet: handle recursive structs and slices.
Fixes golang/go#6309

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/13386046
2013-09-18 12:57:59 +10:00
Andrew Gerrand
dceff279d0 go.tools/cmd/godoc: add redirects for godoc, vet, and gotest
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/13709046
2013-09-18 11:15:12 +10:00
Andrew Gerrand
b9b578154e go.tools/godoc: some content re-organization
Remove References section heading.
Add redirects from old paths to new content.
Add a link to the SubRepositories wiki page from package list.
Add styles for "pop-out" link.

R=r
CC=golang-dev
https://golang.org/cl/13356047
2013-09-16 15:46:38 +10:00
Andrew Gerrand
4709d08a36 go.toos/cmd/cover: "add" package comment
R=r
CC=golang-dev
https://golang.org/cl/13463046
2013-09-16 14:39:12 +10:00
Andrew Gerrand
334d56a124 go.tools/cmd/godoc: permit dash and capitals in redirect paths
This was causing some /blog/foo-bar-baz paths to 404.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/13640044
2013-09-16 13:02:15 +10:00
Andrew Gerrand
1564988897 go.tools/cmd/godoc: add redirect helpers
Previously these helpers were added by a private deployment script.
There's no reason why they shouldn't be part of godoc proper now
that it's in the go.tools repository.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/13722043
2013-09-16 11:41:03 +10:00
Rob Pike
ece05f910e go.tools/cmd/vet: update for fmt handling %b for complex numbers
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/13490048
2013-09-16 08:18:27 +10:00
Dominik Honnef
59968caad5 go.tools/oracle: turn emacs integration into minor-mode
Define a minor mode called go-oracle-mode. Right now its sole
purpose is to define a keymap but it might later be used to add
hooks or add other features to go-mode.

R=adonovan
CC=golang-dev
https://golang.org/cl/13412048
2013-09-12 22:34:38 -04: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
Alan Donovan
5eb0d4d152 go.tools/oracle: restore edits lost in rev aa9b649bccd9 (botched merge)
R=crawshaw
TBR=crawshaw
CC=golang-dev
https://golang.org/cl/13604044
2013-09-09 21:31:33 -04:00
Alan Donovan
c6e88b1b2a go.tools/cmd/oracle: use -pos=file:#start,#end syntax to indicate half-open [start,end) extent of byte offsets.
Also: improve help message.

R=r, crawshaw, rsc
CC=golang-dev
https://golang.org/cl/13593043
2013-09-08 22:10:11 -04:00
Alan Donovan
3f2f9a7e70 go.tools/importer: generalize command-line syntax.
Motivation: pointer analysis tools (like the oracle) want the
user to specify a set of initial packages, like 'go test'.
This change enables the user to specify a set of packages on
the command line using importer.LoadInitialPackages(args).

Each argument is interpreted as either:
- a comma-separated list of *.go source files together
  comprising one non-importable ad-hoc package.
  e.g. "src/pkg/net/http/triv.go" gives us [main].
- an import path, denoting both the imported package
  and its non-importable external test package, if any.
  e.g. "fmt" gives us [fmt, fmt_test].

Current type-checker limitations mean that only the first
import path may contribute tests: multiple packages augmented
by *_test.go files could create import cycles, which 'go test'
avoids by building a separate executable for each one.
That approach is less attractive for static analysis.

Details:  (many files touched, but importer.go is the crux)

importer:
- PackageInfo.Importable boolean indicates whether
  package is importable.
- un-expose Importer.Packages; expose AllPackages() instead.
- CreatePackageFromArgs has become LoadInitialPackages.
- imports() moved to util.go, renamed importsOf().
- InitialPackagesUsage usage message exported to clients.
- the package name for ad-hoc packages now comes from the
  'package' decl, not "main".

ssa.Program:
- added CreatePackages() method
- PackagesByPath un-exposed, renamed 'imported'.
- expose AllPackages and ImportedPackage accessors.

oracle:
- describe: explain and workaround a go/types bug.

Misc:
- Removed various unnecessary error.Error() calls in Printf args.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13579043
2013-09-06 18:13:57 -04:00
Alan Donovan
b21b4e8c88 go.tools/importer: negate "cgo" build tag to avoid native code in "net".
This removes the need for the caller to specify CGO_ENABLED=0
in the environment.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13464045
2013-09-04 15:20:38 -04:00
Alan Donovan
f9e325b575 go.tools/oracle: change notation for byte offsets to "-pos=file.go:#123-#456"
The previous notation (sans '#') now yields an error but is
"reserved for future use", e.g. to denote line/column offsets.
Will implement as needed.

R=r, crawshaw
CC=golang-dev
https://golang.org/cl/13526043
2013-09-04 14:35:24 -04:00
Alan Donovan
e2921e188a go.tools/importer: make loading/parsing concurrent.
1. ParseFiles (in util.go) parses each file in its own goroutine.

2. (*Importer).LoadPackage asynchronously prefetches the
   import graph by scanning the imports of each loaded package
   and calling LoadPackage on each one.

   LoadPackage is now thread-safe and idempotent: it uses a
   condition variable per package; the first goroutine to
   request a package becomes responsible for loading it and
   broadcasts to the others (waiting) when it becomes ready.

ssadump runs 34% faster when loading the oracle.

Also, refactorings:
- delete SourceLoader mechanism; just expose go/build.Context directly.
- CreateSourcePackage now also returns an error directly,
  rather than via PackageInfo.Err, since every client wants that.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13509045
2013-09-04 13:15:49 -04:00
Alan Donovan
48d14ded32 go.tools/cmd/oracle: cosmetic tweaks to Emacs.
1. call display-buffer after the postprocessing step to avoid display glitch.
2. suppress the postprocessing progress message---it's too verbose.
   (instead I should just make the postprocessing loop faster)

Also: rename channel-peers to just peers for consistency with other commands and documentation.

R=dominik.honnef
CC=golang-dev
https://golang.org/cl/13388044
2013-09-03 15:41:05 -04:00
Alan Donovan
d2cdbefbfc go.tools/oracle: add option to output results in JSON syntax.
See json.go for interface specification.

Example usage:
% oracle -format=json -mode=callgraph code.google.com/p/go.tools/cmd/oracle

+ Tests, based on (small) golden files.

Overview:
  Each <query>Result structure has been "lowered" so that all
  but the most trivial logic in each display() function has
  been moved to the main query.

  Each one now has a toJSON method that populates a json.Result
  struct.  Though the <query>Result structs are similar to the
  correponding JSON protocol, they're not close enough to be
  used directly; for example, the former contain richer
  semantic entities (token.Pos, ast.Expr, ssa.Value,
  pointer.Pointer, etc) whereas JSON contains only their
  printed forms using Go basic types.

  The choices of what levels of abstractions the two sets of
  structs should have is somewhat arbitrary.  We may want
  richer information in the JSON output in future.

Details:
- oracle.Main has been split into oracle.Query() and the
  printing of the oracle.Result.
- the display() method no longer needs an *oracle param, only
  a print function.
- callees: sort the result for determinism.
- callees: compute the union across all contexts.
- callers: sort the results for determinism.
- describe(package): fixed a bug in the predicate for method
  accessibility: an unexported method defined in pkg A may
  belong to a type defined in package B (via
  embedding/promotion) and may thus be accessible to A.  New
  accessibleMethods() utility fixes this.
- describe(type): filter methods by accessibility.
- added tests of 'callgraph'.
- pointer: eliminated the 'caller CallGraphNode' parameter from
  pointer.Context.Call callback since it was redundant w.r.t
  site.Caller().
- added warning if CGO_ENABLED is unset.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13270045
2013-09-03 15:29:02 -04:00
Alan Donovan
0126405cad go.tools/oracle: change -pos flag syntax from "file pos-pos" to file:pos-pos.
Pro: no shell quotation needed.
Con: can't be parsed by (the perpetually useless) Scanf.

R=crawshaw, dgryski
CC=golang-dev
https://golang.org/cl/13441043
2013-09-03 10:58:58 -04:00
Alan Donovan
b43fa6fbda go.tools/cmd/ssadump: move ssa/ssadump.go command to its own package.
(Its former location was based on a misunderstanding of 'go build'.)

Also: set GOMAXPROCS to NumCPU by default.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13354043
2013-08-29 21:34:36 -04:00
Alan Donovan
3184482148 go.tools/oracle: change -ptalog default to "".
Also: add a TODO.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13352043
2013-08-29 21:32:49 -04:00
Rob Pike
bc5f637240 go.tools/cmd/vet: assume implementations of fmt.Formatter print just fine
Update golang/go#6212
See issue 6259.
When that is resolved, we can do a better job. Until then, we just see if the
type has a method called Format and, if so, assume it's a Formatter and so
there's nothing to check.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/13267043
2013-08-28 11:24:43 +10:00
Andrew Gerrand
2e6fbd84f8 go.tools/cmd/godoc: don't list factory functions under types in builtin package
Fixes golang/go#6220.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/13094049
2013-08-28 09:39:02 +10:00
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
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
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
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
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
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
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
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
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
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
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
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
Andrew Gerrand
8d55039560 go.tools/cmd/godoc: fix typo
R=golang-dev
CC=golang-dev
https://golang.org/cl/12238043
2013-08-01 17:43:31 +10:00
Andrew Gerrand
37c18cdcf3 go.tools/cmd/godoc: start indexer in app engine mode
R=golang-dev
CC=golang-dev
https://golang.org/cl/12237044
2013-08-01 17:37:20 +10:00
Andrew Gerrand
0830cbddc9 go.talks/cmd/godoc: add jquery.js and style.css
Somehow missed these.

R=golang-dev
CC=golang-dev
https://golang.org/cl/12233043
2013-08-01 17:36:56 +10:00
Andrew Gerrand
0afeff2d4b go.tools/cmd/godoc: add godocs.js and playground.js from core repo
The originals will be removed.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/12219043
2013-08-01 15:08:46 +10:00
Andrew Gerrand
508186a765 go.tools/cmd/godoc: copy templates from $GOROOT/lib/godoc
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/12209043
2013-08-01 11:01:10 +10:00
Brad Fitzpatrick
143d18d6c5 cmd/godoc: fix build
R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/12127043
2013-07-30 13:42:50 -07:00
Rob Pike
2a8b9debdd go.tools/cmd/vet: don't complain about empty interface values in printf
R=dsymonds
CC=golang-dev
https://golang.org/cl/12005047
2013-07-30 15:51:35 +10:00
Andrew Gerrand
253974207b go.tools/cmd/godoc: update appinit.go to use new godoc packages
Also move some common code from main.go to handlers.go, and
exclude remotesearch.go from the appengine build (it is only
relevant to the command line interface).

R=bradfitz, dsymonds
CC=golang-dev
https://golang.org/cl/12001049
2013-07-30 14:23:23 +10:00
Rob Pike
5ba51116ee go.tools/cmd/vet: treat arrays like slices in the printf checks.
The analysis for types.Array was just missing. It's the same as a slice,
but we can't share code easily because the types differ, so we just dup it.

R=dsymonds
CC=golang-dev
https://golang.org/cl/12041045
2013-07-30 14:00:52 +10:00
David Symonds
40baf75587 cmd/vet: Avoid warning on pointer to invalid types.
TBR=r
CC=golang-dev
https://golang.org/cl/12038051
2013-07-30 13:41:07 +10:00
David Symonds
573374c476 cmd/vet: Fix handling of non-Stringer arguments.
First, %v and %T accept any arguments, so they should never warn.
Second, pointer types were not handled in matchArgType.
Third, the default response for matchArgType should be false.

R=r
CC=adonovan, golang-dev
https://golang.org/cl/12038050
2013-07-30 13:15:31 +10:00
Andrew Gerrand
7375911b0e go.tools/cmd/godoc: use playground package from go.tools
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/11507044
2013-07-24 17:25:24 +10:00
Rob Pike
9ac8940d29 all: be more idiomatic when documenting boolean return values.
Phrases like "returns whether or not the image is opaque" could be
describing what the function does (it always returns, regardless of
the opacity) or what it returns (a boolean indicating the opacity).
Even when the "or not" is missing, the phrasing is bizarre.

Go with "reports whether", which is still clunky but at least makes
it clear we're talking about the return value.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/11458046
2013-07-23 10:37:43 +10:00
David Symonds
75919c8eee cmd/vet: avoid panic if no valid inputs are found.
I'd like to make vet work as a filter, but passing /dev/stdin as a
command line argument doesn't work. This at least makes it not panic.

R=r
CC=golang-dev
https://golang.org/cl/11521045
2013-07-22 12:43:11 +10:00
Brad Fitzpatrick
80d38231f7 godoc: move search from cmd to the package
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/11540045
2013-07-19 14:02:03 +10:00
David Symonds
0160160d5e cmd/godoc: Fix reg test on Windows.
R=bradfitz, gri
CC=golang-dev
https://golang.org/cl/11551043
2013-07-19 10:31:12 +10:00
Brad Fitzpatrick
705bb7ffce godoc: remove the last of the global variables, unexport Server
The exported Server becomes handlerServer, and part of Presentation
now.  Presentation is also now an http.Handler with its own
internal mux (a detail, which might go away).

main.go becomes ever simpler.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/11505043
2013-07-19 10:27:53 +10:00
Robert Griesemer
40a278e5ee go.tools/go/types: rename Context -> Config (more apt name)
Also: Various minor cleanups.

R=adonovan, r
CC=golang-dev
https://golang.org/cl/11445044
2013-07-18 17:07:44 -07:00
Robert Griesemer
9460d02473 go.tools/cmd/vet: fix error message
R=r, dsymonds, bradfitz
CC=golang-dev
https://golang.org/cl/11552043
2013-07-18 16:56:01 -07:00
Robert Griesemer
6d85cc17dd go.tools/go/types: request type Info via maps instead of callbacks
Allmost all uses of go/types that wanted the type
information computed, installed callback functions
that stored the information in maps. Most of the
time this is the only thing that could be done because
there is no guarantee that types are completely set
up before the end of type-checking.

This CL removes the respective Context callbacks in favor
of corresponding maps that collect the desired information
on demand, grouped together in an optional Info struct.

R=adonovan
CC=golang-dev
https://golang.org/cl/11530044
2013-07-18 13:09:03 -07:00
Brad Fitzpatrick
66f0d6e92e godoc: more cleanup
cmd/godoc/godoc.go is now merged into main.go, which is now
only 530 lines.

App Engine mode is still broken, but should be easy to fix up.
(just needs a global *godoc.Presentation created in init)

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/11498044
2013-07-18 13:51:17 +10:00
Brad Fitzpatrick
5395cfe05a godoc: remove more global variables
More moves into Corpus and Presentation.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/11492043
2013-07-18 13:14:09 +10:00
Brad Fitzpatrick
4fc6323385 godoc: add a Corpus and Presentation type
Start of moving globals into those types.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/11484043
2013-07-18 09:52:45 +10:00
David Symonds
3af65e49c2 cmd/godoc: Add a basic regression test.
R=adg, bradfitz
CC=golang-dev
https://golang.org/cl/11419044
2013-07-17 17:32:45 +10:00
Brad Fitzpatrick
cd835f01af godoc: use httptest.ResponseRecorder instead of reimplementing it
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/11428043
2013-07-17 17:25:54 +10:00
Brad Fitzpatrick
e6ff53bcc8 godoc: move bulk of the code to the package
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/11424043
2013-07-17 17:09:54 +10:00
Andrew Gerrand
2392be72c2 go.tools/godoc: move Throttle to package godoc/util
R=bradfitz
CC=golang-dev
https://golang.org/cl/11417043
2013-07-17 15:23:31 +10:00
Andrew Gerrand
2822addeae go.tools/cmd/godoc: use go.talks playground package
R=bradfitz
CC=golang-dev
https://golang.org/cl/11416043
2013-07-17 15:17:04 +10:00
Andrew Gerrand
5ff0687cc9 go.tools/godoc: move vfs code to vfs package
R=bradfitz
CC=golang-dev
https://golang.org/cl/11414043
2013-07-17 15:02:27 +10:00
Brad Fitzpatrick
7526441b70 godoc: add util package, add start of vfs package
Move some code out of cmd/godoc.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/11413043
2013-07-17 14:44:18 +10:00
Andrew Gerrand
d79f4fe25b go.tools/cmd/godoc: copy godoc from core reposistory
The plan for godoc:
- Copy godoc source from the core repo to go.tools (this CL).
- Break godoc into several packages inside go.tools, leaving a package
  main that merely sets up a local file system, interprets the command
  line, and otherwise delegates the heavy-lifting to the new packages.
- Remove godoc from the core repo.
- Update cmd/go to install this godoc binary in $GOROOT/bin.
- Update misc/dist to include godoc when building binary distributions.

R=bradfitz
CC=golang-dev
https://golang.org/cl/11408043
2013-07-17 14:02:35 +10:00
Alan Donovan
25f3e0fbde go.tools/cmd/vet: improvements to static checking of printf calls.
Details:
- added support for complex numbers as distinct from floats:
  %[efg] allows complex; %b does not.
- %p: only Signature, Map, Chan, Slice, unsafe.Pointer allowed.
- %s: allow []byte.
- allow a verb to match map[K]V and []T if it matches K/V/T,
  e.g. %d now matches []int.  i.e. matching is recursive.
- use go/types' constant folding.  literal() is gone.
- group cases together.

Added tests.

R=gri, r
CC=golang-dev
https://golang.org/cl/10895043
2013-07-15 18:37:49 -04:00
Rob Pike
b042505490 go.tools/cmd/vet: use types.Eval to simplify some checking.
Depends on CL 10748044

R=gri
CC=golang-dev
https://golang.org/cl/11206043
2013-07-13 07:52:00 +10:00
Rob Pike
1c382c95b2 go.tools/cmd/cover: get cover counters on if conditions
This requires a little more tree rewriting to put a block around the if of an "else if".
More tests too.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/11042045
2013-07-10 15:20:52 +10:00
Andrew Gerrand
5b27bc1db9 go.talks/cmd/cover: show simpler legend for "set" mode
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/10738044
2013-07-10 14:03:35 +10:00