aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/gc/noder.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2018-02-26 17:35:29 -0800
committerRobert Griesemer <gri@golang.org>2018-02-28 03:51:23 +0000
commit0c884d0810285ffec6ed6290dc64f2fa34248a19 (patch)
treec716a862891d556041f481e7be6ed145f4bf72c9 /src/cmd/compile/internal/gc/noder.go
parentb5bd5bfbc731c033955a0d4777ca34a9ac71020c (diff)
downloadgo-0c884d0810285ffec6ed6290dc64f2fa34248a19.tar.xz
cmd/compile, cmd/compile/internal/syntax: print relative column info
This change enables printing of relative column information if a prior line directive specified a valid column. If there was no line directive, or the line directive didn't specify a column (or the -C flag is specified), no column information is shown in file positions. Implementation: Column values (and line values, for that matter) that are zero are interpreted as "unknown". A line directive that doesn't specify a column records that as a zero column in the respective PosBase data structure. When computing relative columns, a relative value is zero of the base's column value is zero. When formatting a position, a zero column value is not printed. To make this work without special cases, the PosBase for a file is given a concrete (non-0:0) position 1:1 with the PosBase's line and column also being 1:1. In other words, at the position 1:1 of a file, it's relative positions are starting with 1:1 as one would expect. In the package syntax, this requires self-recursive PosBases for file bases, matching what cmd/internal/src.PosBase was already doing. In src.PosBase, file and inlining bases also need to be based at 1:1 to indicate "known" positions. This change completes the cmd/compiler part of the issue below. Fixes #22662. Change-Id: I6c3d2dee26709581fba0d0261b1d12e93f1cba1a Reviewed-on: https://go-review.googlesource.com/97375 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/gc/noder.go')
-rw-r--r--src/cmd/compile/internal/gc/noder.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/cmd/compile/internal/gc/noder.go b/src/cmd/compile/internal/gc/noder.go
index 7865550293..e911ac6e42 100644
--- a/src/cmd/compile/internal/gc/noder.go
+++ b/src/cmd/compile/internal/gc/noder.go
@@ -78,13 +78,13 @@ func (p *noder) makeSrcPosBase(b0 *syntax.PosBase) *src.PosBase {
b1, ok := p.basemap[b0]
if !ok {
fn := b0.Filename()
- if p0 := b0.Pos(); p0.IsKnown() {
+ if b0.IsFileBase() {
+ b1 = src.NewFileBase(fn, absFilename(fn))
+ } else {
// line directive base
+ p0 := b0.Pos()
p1 := src.MakePos(p.makeSrcPosBase(p0.Base()), p0.Line(), p0.Col())
b1 = src.NewLinePragmaBase(p1, fn, fileh(fn), b0.Line(), b0.Col())
- } else {
- // file base
- b1 = src.NewFileBase(fn, absFilename(fn))
}
p.basemap[b0] = b1
}