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

23 Commits

Author SHA1 Message Date
Hironao OTSUBO
321c6fd171 cmd/stringer: fixed usage line typo
Change-Id: I5852d03c0326d82c13d9e1078f9648ecc695fbbf
Reviewed-on: https://go-review.googlesource.com/22150
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-04-17 02:19:27 +00:00
Robert Griesemer
adaaa07486 x/tools: delete x/tools/go/types and dependent packages/client files
Per https://groups.google.com/forum/#!topic/golang-announce/qu_rAphYdxY
this change deletes the packages

  go/exact
  go/gccgoimporter
  go/gcimporter
  go/importer
  go/types
  cmd/vet

from the x/tools repo and any files depending on those packages
building against Go 1.4.

x/tools packages depending on any of these libraries must use the
respective versions from the std lib or use vendored versions if
building against 1.4.

Remaining packages may or may not build against Go 1.4 anymore
and will not be supported against 1.4.

Change-Id: I1c655fc30aee49b6c7326ebd4eb1bb0836ac97e0
Reviewed-on: https://go-review.googlesource.com/20810
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-04-06 21:52:49 +00:00
Alan Donovan
f8ecfdb6b6 cmd/stringer: fork and tag for go1.4
The previous change updated the import of golang.org/x/tools/go/types
to the standard go/types package, causing 1.4 builds to fail.

Fixes #13874.

Change-Id: Idf0b4ac5e4e01dd5cd7cc9b89d017fbffb7a29df
Reviewed-on: https://go-review.googlesource.com/18430
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-01-11 14:24:22 +00:00
Alan Donovan
542ffc7e75 tools: switch to standard go/types at tip
A few files have been forked and tagged "go1.5,!go1.6" to work around
minor API changes between the two types packages:
- constant.Value.String() in oracle/describe.go and its tests;
- constant.ToInt must now be called before constant.Int64Val.
- types.Config{Importer: importer.Default()} in a number of places
- go/types/typeutil/import_test.go uses lowercase names to avoid 'import "C"'.

Files in go/types/typesutil, missing from my previous CL, have been
tagged !go1.5; these files will be deleted in February.

All affected packages were tested using 1.4.1, 1.5, and ~1.6 (tip).

Change-Id: Iec7fd370e1434508149b378438fb37f65b8d2ba8
Reviewed-on: https://go-review.googlesource.com/18207
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-01-06 22:15:26 +00:00
Tamir Duberstein
4b07c5ce8a cmd/stringer: prepend "Code" to codegen warning
This allows Github to hide diffs in generated files. See:
https://github.com/github/linguist/blob/473282d/lib/linguist/generated.rb#L241

Change-Id: Ic0a9ed80ecc6130d81fd0ba10e2df48217eb14cc
Reviewed-on: https://go-review.googlesource.com/15073
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-11-08 08:43:00 +00:00
Robert Griesemer
63f996ec75 cmd/stringer: exclude end-to-end test for Android
Change-Id: I37224abb3d9ca902ed23d520493f3b2794ef0471
Reviewed-on: https://go-review.googlesource.com/13261
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-08-05 22:44:14 +00:00
Nick Craig-Wood
578c521fc2 cmd/stringer: fix panic caused by integer overflow
When String() was called on the maximum value of an integer type (eg
255 for uint8) this would cause an integer overflow, which would cause
an index error later in the code.

Fixed by re-arranging the code slightly.

Fixes golang/go#10563

Change-Id: I9fd016afc5eea22adbc3843f6081091fd50deccf
Reviewed-on: https://go-review.googlesource.com/9255
Reviewed-by: Rob Pike <r@golang.org>
2015-06-02 19:44:20 +00:00
Paul Smith
92211c448d cmd/stringer: remove os.Exit call from Usage func
The caller of Usage should call os.Exit -- Usage shouldn't call it.

Change-Id: I3decf662883fb2a6b19b7035138ee8a06a02de08
Reviewed-on: https://go-review.googlesource.com/7110
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-03-09 01:18:24 +00:00
Nigel Tao
045f02ba9d cmd/stringer: fix ignored error in TestEndToEnd.
Change-Id: Ia139e9da37aecddebe8895c0d3427d7e97d408f8
Reviewed-on: https://go-review.googlesource.com/2931
Reviewed-by: David Symonds <dsymonds@golang.org>
2015-01-15 23:10:50 +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
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
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
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
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
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