diff options
author | Robert Griesemer <gri@golang.org> | 2012-02-10 13:27:32 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2012-02-10 13:27:32 -0800 |
commit | 7b8496e9b843b11c06a7548916896335530329cc (patch) | |
tree | 0038eb2ded75dfebd94302b1ce9a9b6dc78a4b02 /src/cmd/gofmt | |
parent | 254ef965be266b3cfdda29c124777f6224c5f512 (diff) | |
download | go-7b8496e9b843b11c06a7548916896335530329cc.tar.gz |
go/printer: implement SourcePos mode
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 issue 1047.
Fixes issue 2697.
R=rsc, rsc
CC=golang-dev
http://codereview.appspot.com/5643066
Diffstat (limited to 'src/cmd/gofmt')
-rw-r--r-- | src/cmd/gofmt/gofmt.go | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/cmd/gofmt/gofmt.go b/src/cmd/gofmt/gofmt.go index 6d610adc0..55c01beb5 100644 --- a/src/cmd/gofmt/gofmt.go +++ b/src/cmd/gofmt/gofmt.go @@ -45,7 +45,7 @@ var ( exitCode = 0 rewrite func(*ast.File) *ast.File parserMode parser.Mode - printerMode uint + printerMode printer.Mode ) func report(err error) { |