]> Cypherpunks repositories - gostls13.git/commit
go/printer: simplify handling of line directives
authorRobert Griesemer <gri@golang.org>
Fri, 9 Mar 2018 00:06:16 +0000 (16:06 -0800)
committerRobert Griesemer <gri@golang.org>
Fri, 9 Mar 2018 01:01:25 +0000 (01:01 +0000)
commit53c416396fafb9f73b24159134836bbbd2266d29
treeae48d4795dee55fea38cc984c9f9b47884c9f85d
parent2cc15b18dbab600939147dfe4c58aa6b8f04586e
go/printer: simplify handling of line directives

Strangely enough, the existing implementation used adjusted (by line
directives) source positions to determine layout and thus required
position corrections when printing a line directive.

Instead, just use the unadjusted, absolute source positions and then
printing a line directive doesn't require any adjustments, only some
care to make sure it remains in column 1 as before.

The new code doesn't need to parse line directives anymore and simply
ensures that comments with the //line prefix and starting in column 1
remain in that position. That is a slight change from the old behavior
(which ignored incorrect line directives, e.g. because they had an
invalid line number) but unlikely to show up in real code.

This is prep work for handling of line directives that also specify
columns (which now won't require much special handling anymore).

For #24143.

Change-Id: I07eb2e1b35b37337e632e3dbf5b70c783c615f8a
Reviewed-on: https://go-review.googlesource.com/99621
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/go/printer/printer.go
src/go/printer/printer_test.go
src/go/printer/testdata/comments.golden
src/go/printer/testdata/comments.input