(see also issue 3961).
hexdump -c testdata/crlf.input
0000000 / * \r \n \t S o u r c e c o n t
0000010 a i n i n g C R / L F l i n
0000020 e e n d i n g s . \r \n \t T h e
0000030 g o f m t ' e d o u t p u t
0000040 m u s t o n l y h a v e
0000050 L F \r \n \t l i n e e n d i n g
0000060 s . \r \n * / \r \n p a c k a g e
0000070 m a i n \r \n \r \n f u n c m a i
0000080 n ( ) { \r \n \t / / l i n e
0000090 c o m m e n t \r \n \t p r i n t l
00000a0 n ( " h e l l o , w o r l d !
00000b0 " ) / / a n o t h e r l i
00000c0 n e c o m m e n t \r \n \t p r i
00000d0 n t l n ( ) \r \n } \r \n
00000db
hexdump -c testdata/crlf.golden
0000000 / * \n \t S o u r c e c o n t a
0000010 i n i n g C R / L F l i n e
0000020 e n d i n g s . \n \t T h e g
0000030 o f m t ' e d o u t p u t m
0000040 u s t o n l y h a v e L F
0000050 \n \t l i n e e n d i n g s . \n
0000060 * / \n p a c k a g e m a i n \n
0000070 \n f u n c m a i n ( ) { \n \t
0000080 / / l i n e c o m m e n t \n
0000090 \t p r i n t l n ( " h e l l o ,
00000a0 w o r l d ! " ) / / a n o
00000b0 t h e r l i n e c o m m e n
00000c0 t \n \t p r i n t l n ( ) \n } \n
00000cf
R=rsc
CC=golang-dev
https://golang.org/cl/6526052
windows cmd.exe can't show utf-8 correctly basically.
chcp 65001 may make it show, but most people don't have fonts which can
show it.
R=golang-dev, rsc, adg, gri, r
CC=golang-dev
https://golang.org/cl/5820060
Also: Simplified handling of selector expressions. As a result, complicated
multi-line expressions containing selectors and calls/indices with arguments
broken accross lines don't get indented the same way as before, but the change
is minimal (see tests) and there's no such code in the std library. It seems
a worthwhile compromise given the much simpler code.
Applied gofmt -w $GOROOT/src $GOROOT/misc .
Fixes#1847.
R=rsc
CC=golang-dev
https://golang.org/cl/5675062
If a printer is configured with the SourcePos mode
set, it will emit //-line comments as necessary to
ensure that the result - if reparsed - reflects the
original source position information.
This change required a bit of reworking of the
output section in printer.go. Specifically:
- Introduced new Config mode 'SourcePos'.
- Introduced new position 'out' which tracks the
position of the generated output if it were read
in again. If there is a discrepancy between out
and the current AST/source position, a //line
comment is emitted to correct for it.
- Lazy emission of indentation so that //line
comments can be placed correctly. As a result,
the trimmer will have to do less work.
- Merged writeItem into writeString.
- Merged writeByteN into writeByte.
- Use a []byte instead of a byte.Buffer both in the
printer and in the trimmer (eliminates dependency).
Also: introduced explicit printer.Mode type (in
sync w/ parser.Mode, scanner.Mode, etc.)
Runs all tests. Applied gofmt to src, misc w/o changes.
Fixes#1047.
Fixes#2697.
R=rsc, rsc
CC=golang-dev
https://golang.org/cl/5643066
Consequently, remove many package Makefiles,
and shorten the few that remain.
gomake becomes 'go tool make'.
Turn off test phases of run.bash that do not work,
flagged with $BROKEN. Future CLs will restore these,
but this seemed like a big enough CL already.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5601057
Only ParseFile, ParseDir, and ParseExpr are used in the tree.
If partial parsing of code is required, it is fairly simple
to wrap the relevant piece of code into a dummy package for
parsing (see parser.ParseExpr).
Also: minor cleanups.
R=rsc
CC=golang-dev
https://golang.org/cl/5535055
Without this check, gofmt panics when trying to apply
the identity transformation on "item.field" expressions.
Fixes#2410.
R=rsc, gri
CC=golang-dev, remy
https://golang.org/cl/5376061
The current implementation of formatting for incomplete programs
cannot tolerate program rewrites; ignore -rewrite in that case
with a warning message (temporary solution).
Fix a couple of crashes that were introduced recently.
Fixes#2348.
R=rsc
CC=golang-dev
https://golang.org/cl/5233054
This one uses a closure than an interface, and is much simpler to use.
It also enables a called function to return an error and (possibly)
halt processing.
Fixes#2237.
R=golang-dev, gri, rsc, r, cw, n13m3y3r
CC=golang-dev
https://golang.org/cl/5014043
This makes it possible to grab a block of code
in an editor and pipe it through gofmt, instead of
having to pipe in the entire file.
R=gri
CC=golang-dev
https://golang.org/cl/4973074
API change. Needs further reflection.
««« original CL description
path/filepath: Simplify Walk interface
The last argument of filepath.Walk was removed, and the Visitor
interface now contains an Error method that is called on errors.
Fixes#2237.
R=golang-dev, gri, r
CC=golang-dev
https://golang.org/cl/4964067
»»»
R=r
CC=golang-dev
https://golang.org/cl/4974065
The last argument of filepath.Walk was removed, and the Visitor
interface now contains an Error method that is called on errors.
Fixes#2237.
R=golang-dev, gri, r
CC=golang-dev
https://golang.org/cl/4964067
Also:
- Add parser.SpuriousError flag. If set, the parser reports all (including
spurious) errors rather then at most one error per line.
- Add -e flag to gofmt and gotype: If set, gofmt and gotype report all
(including spurious) errors rather than at most one error per line.
- Updated the respective documentation.
Fixes#2088.
R=rsc
CC=golang-dev
https://golang.org/cl/4803047
Change the signature of Split to have no count,
assuming a full split, and rename the existing
Split with a count to SplitN.
Do the same to package bytes.
Add a gofix module.
R=adg, dsymonds, alex.brainman, rsc
CC=golang-dev
https://golang.org/cl/4661051
This removes exec.Run and replaces exec.Cmd with a
new implementation. The new exec.Cmd represents
both a currently-running command and also a command
being prepared. It has a good zero value.
You can Start + Wait on a Cmd, or simply Run it.
Start (and Run) deal with copying stdout, stdin,
and stderr between the Cmd's io.Readers and
io.Writers.
There are convenience methods to capture a command's
stdout and/or stderr.
R=r, n13m3y3r, rsc, gustavo, alex.brainman, dsymonds, r, adg, duzy.chan, mike.rosset, kevlar
CC=golang-dev
https://golang.org/cl/4552052
Don't use the rewrite rule from a previous test
for the next test if there is no rewrite rule
provided.
R=r, r2
CC=golang-dev
https://golang.org/cl/4419045
The new reflection API makes it an error to call value.Set(x)
if x is invalid. Guard for it.
Added corresponding test case.
Fixes#1696.
R=rsc, r
CC=golang-dev
https://golang.org/cl/4398047
- replaced existing testdata/test.sh with new gofmt_test
- added initial test case for rewrite tests
TODO: Need to add more tests.
R=rsc
CC=golang-dev
https://golang.org/cl/4368063
With the (partial) resolution of identifiers done
by the go/parser, ast.Objects point may introduce
cycles in the AST. Don't follow *ast.Objects, and
replace them with nil instead (they are likely
incorrect after a rewrite anyway).
- minor manual cleanups after reflect change automatic rewrite
- includes fix by rsc related to reflect change
Fixes#1667.
R=rsc
CC=golang-dev
https://golang.org/cl/4387044
We replace the current Open with:
OpenFile(name, flag, perm) // same as old Open
Open(name) // same as old Open(name, O_RDONLY, 0)
Create(name) // same as old Open(name, O_RDWR|O_TRUNC|O_CREAT, 0666)
This CL includes a gofix module and full code updates: all.bash passes.
(There may be a few comments I missed.)
The interesting packages are:
gofix
os
Everything else is automatically generated except for hand tweaks to:
src/pkg/io/ioutil/ioutil.go
src/pkg/io/ioutil/tempfile.go
src/pkg/crypto/tls/generate_cert.go
src/cmd/goyacc/goyacc.go
src/cmd/goyacc/units.y
R=golang-dev, bradfitzwork, rsc, r2
CC=golang-dev
https://golang.org/cl/4357052
Revert changes to printer.Config. Pass in the
nodeSizes map trough an internal helper function.
R=golang-dev, rsc1
CC=golang-dev
https://golang.org/cl/4309042
Use memoization to avoid repeated recomputation of nested
node sizes. Speeds up testdata/slow.input by several orders
of magnitude.
- added respective test case
- added timeout to test code
- deleted some unrelated unused code
Fixes#1628.
R=rsc, r
CC=golang-dev
https://golang.org/cl/4274075
Swapping the goroutines lets them reuse the
communication completion on v instead of
needing a second channel (done).
R=gri
CC=golang-dev
https://golang.org/cl/4287045
Functionality was only present for
debuggging and now is available in
gocheck where is makes more sense.
R=rsc
CC=golang-dev
https://golang.org/cl/4239078
The path package now contains only functions which
deal with slashed paths, sensible for any OS when dealing
with network paths or URLs. OS-specific functionality
has been moved into the new path/filepath package.
This also includes fixes for godoc, goinstall and other
packages which were mixing slashed and OS-specific paths.
R=rsc, gri, mattn, brainman
CC=golang-dev
https://golang.org/cl/4252044
Neither gofmt nor godoc are making use of a Styler (for
token-specific formatting) anymore. Stylers interacted in complicated
ways with HTML-escaping which was why the printer needed an HTML mode
in the first place.
godoc now uses a more powerful and general text formatting
function that does HTML escaping, text selection, and can
handle token-specific formatting if so desired (currently
used only for comments).
As a consequence, cleaned up uses of go/printer in godoc;
simplified the various write utility functions, and also
removed the need for the "html" template format (in favor of
html-esc which now does the same and is used more pervasively).
Applied gofmt -w src misc to verify no changes occured,
and tested godoc manually.
There should be no visible changes except that (type) code
snippets presented for godoc package documentation now
uses the same formatting as for general source code and
thus comments get the comment-specific color here as well
(not the case at the moment).
(TODO: godoc needs a good automatic test suite).
R=rsc
CC=golang-dev
https://golang.org/cl/4152042
- change Walk signature to use an ast.Node instead of interface{}
- add Pos functions to a couple of ast types to make them proper nodes
- explicit nil checks where a node can be nil; incorrect ASTs cause Walk to crash
For now ast.Walk is exercised extensively as part of godoc's indexer;
so we have some confidence in its correctness. But this needs a test,
eventually.
Fixes#1326.
R=rsc, r
CC=golang-dev
https://golang.org/cl/3481043
Specifically:
* lib/godoc:
- provide file set (FSet) argument to formatters where needed
* src/cmd:
- cgo, ebnflint, godoc, gofmt, goinstall: provide file set (fset) where needed
- godoc: remove local binary search with sort.Search (change by rsc),
extract file set for formatters
* src/pkg:
- exp/eval: remove embedded token.Position fields from nodes and replace
with named token.Pos fields; add corresponding Pos() accessor methods
- go/token: added file.Line(), changed signature of File.Position()
* test/fixedbugs/:
- bug206.go: change test to not rely on token.Pos details
* added various extra comments
* Runs all.bash
* gofmt formats all of src, misc w/o changes
* godoc runs
* performance:
- The new version of godoc consumes about the same space after indexing
has completed, but indexing is half the speed. Significant space savings
are expected from smaller ASTs, but since they are thrown away after a
file has been indexed, this is not visible anymore. The slower indexing
time is due to the much more expensive computation of line information.
However, with the new compressed position information, indexing can be
rewritten and simplified. Furthermore, computing the line info can be
done more efficiently.
New godoc, immediately after indexing completed (best of three runs):
PID COMMAND %CPU TIME #TH #PRTS #MREGS RPRVT RSHRD RSIZE VSIZE
44381 godoc 0.0% 0:38.00 4 19 149 145M 184K 148M 176M
2010/12/03 17:58:35 index updated (39.231s, 18505 unique words, 386387 spots)
2010/12/03 17:58:35 bytes=90858456 footprint=199182584
2010/12/03 17:58:36 bytes=47858568 footprint=167295224
Old godoc, immediately after indexing completed (best of three runs):
PID COMMAND %CPU TIME #TH #PRTS #MREGS RPRVT RSHRD RSIZE VSIZE
23167 godoc 0.0% 0:22.02 4 17 132 129M 184K 132M 173M
2010/12/03 14:51:32 index updated (24.892s, 18765 unique words, 393830 spots)
2010/12/03 14:51:32 bytes=66404528 footprint=163907832
2010/12/03 14:51:32 bytes=46282224 footprint=163907832
The different numbers for unique words/spots stem from the fact the the
two workspaces are not exactly identical. The new godoc maintains a large
file set data structure during indexing which (probably) is the reason
for the larger heap (90858456 vs 66404528) before garbage collection.
R=rsc, r
CC=golang-dev
https://golang.org/cl/3050041
go/ast: implement Fprint and print functions to
print AST nodes
gofmt: print AST nodes by setting -ast flag
R=rsc, r
CC=golang-dev
https://golang.org/cl/1981044
- change ast.Ident back to contain the name and adjust all dependent code
- identifier object information will be added again through an optional
typechecker phase (in the works).
- remove tracking of scopes in parser - it's easier to do this in a separate
phase (in the works)
- in godoc, generate popup info table directly instead of through a formatter
for simpler data flow (at the expense of a little bit more code)
Runs all tests.
As a result of this change, the currently shown popup information
(const, var, type, func, followed by identifier name) will not be
shown anymore temporarily.
R=rsc
CC=golang-dev
https://golang.org/cl/1994041
go/scanner: return information on semicolon (real or inserted) when
found in source
go/parser: better error message when a semicolon is found unexpectedly
For instance, if an unexpected semicolon is found that was automatically
inserted, the parser error message is now:
"expected '}', found newline"
Fixes#1006.
R=rsc
CC=golang-dev
https://golang.org/cl/1936044
- don't allow parenthesized receiver base types or anonymous fields
- fixed a couple of other omissions
- adjusted gofmt test script
- removed several TODOs
R=rsc
CC=golang-dev
https://golang.org/cl/1897043
- go/ast: removed StringList (not needed anymore)
- go/ast: changed import path and field list tag to a single string
- updated all dependencies
R=rsc
CC=golang-dev
https://golang.org/cl/217056
- provide scope to parse functions; if non-nil, parser uses the scope
to declare and lookup identifiers
- resolve forward references where possible
R=rsc
CC=golang-dev
https://golang.org/cl/194098
- Identifiers refer now to the language entity (Object)
that they denote. At the moment this is at best an
approximation.
- Initial data structures for language entities (Objects)
and expression types (Type) independent of the actual
type notations.
- Initial support for declaring and looking up identifiers.
- Updated various dependent files and added support functions.
- Extensively tested to avoid breakage. This is an AST change.
R=rsc
CC=golang-dev, rog
https://golang.org/cl/189080
now printed using the semicolon-free style.
Removed NoSemis flag and mechanism dealing with
optional semicolons from go/printer.
Updated all go/printer output files using the
semi-colon free style.
Changes have no formatting impact on checked in
go code under src and misc.
R=rsc, r
CC=golang-dev
https://golang.org/cl/184068