diff options
Diffstat (limited to 'src/cmd/internal')
| -rw-r--r-- | src/cmd/internal/obj/line_test.go | 2 | ||||
| -rw-r--r-- | src/cmd/internal/obj/util.go | 2 | ||||
| -rw-r--r-- | src/cmd/internal/src/pos.go | 23 | ||||
| -rw-r--r-- | src/cmd/internal/src/pos_test.go | 14 | ||||
| -rw-r--r-- | src/cmd/internal/src/xpos_test.go | 2 |
5 files changed, 23 insertions, 20 deletions
diff --git a/src/cmd/internal/obj/line_test.go b/src/cmd/internal/obj/line_test.go index 6b21abecd2..f159a65e2b 100644 --- a/src/cmd/internal/obj/line_test.go +++ b/src/cmd/internal/obj/line_test.go @@ -17,7 +17,7 @@ func TestLinkgetlineFromPos(t *testing.T) { afile := src.NewFileBase("a.go", "a.go") bfile := src.NewFileBase("b.go", "/foo/bar/b.go") - lfile := src.NewLinePragmaBase(src.MakePos(afile, 7, 0), "linedir", 100) + lfile := src.NewLinePragmaBase(src.MakePos(afile, 7, 0), "linedir", "linedir", 100) var tests = []struct { pos src.Pos diff --git a/src/cmd/internal/obj/util.go b/src/cmd/internal/obj/util.go index f1ac1a8808..867c69f3ef 100644 --- a/src/cmd/internal/obj/util.go +++ b/src/cmd/internal/obj/util.go @@ -15,7 +15,7 @@ const REG_NONE = 0 // Line returns a string containing the filename and line number for p func (p *Prog) Line() string { - return p.Ctxt.OutermostPos(p.Pos).Format(false) + return p.Ctxt.OutermostPos(p.Pos).Format(false, true) } // LineNumber returns a string containing the line number for p's position diff --git a/src/cmd/internal/src/pos.go b/src/cmd/internal/src/pos.go index a1ea3fcdac..10fa924c0b 100644 --- a/src/cmd/internal/src/pos.go +++ b/src/cmd/internal/src/pos.go @@ -79,15 +79,15 @@ func (p Pos) AbsFilename() string { return p.base.AbsFilename() } func (p Pos) SymFilename() string { return p.base.SymFilename() } func (p Pos) String() string { - return p.Format(true) + return p.Format(true, true) } // Format formats a position as "filename:line" or "filename:line:column", -// controlled by the showCol flag. -// If the position is relative to a line directive, the original position -// is appended in square brackets without column (since the column doesn't -// change). -func (p Pos) Format(showCol bool) string { +// controlled by the showCol flag. A position relative to a line directive +// is always formatted without column information. In that case, if showOrig +// is set, the original position (again controlled by showCol) is appended +// in square brackets: "filename:line[origfile:origline:origcolumn]". +func (p Pos) Format(showCol, showOrig bool) string { if !p.IsKnown() { return "<unknown line number>" } @@ -105,8 +105,11 @@ func (p Pos) Format(showCol bool) string { // that's provided via a line directive). // TODO(gri) This may not be true if we have an inlining base. // We may want to differentiate at some point. - return format(p.RelFilename(), p.RelLine(), 0, false) + - "[" + format(p.Filename(), p.Line(), p.Col(), showCol) + "]" + s := format(p.RelFilename(), p.RelLine(), 0, false) + if showOrig { + s += "[" + format(p.Filename(), p.Line(), p.Col(), showCol) + "]" + } + return s } // format formats a (filename, line, col) tuple as "filename:line" (showCol @@ -155,8 +158,8 @@ func NewFileBase(filename, absFilename string) *PosBase { // NewLinePragmaBase returns a new *PosBase for a line pragma of the form // //line filename:line // at position pos. -func NewLinePragmaBase(pos Pos, filename string, line uint) *PosBase { - return &PosBase{pos, filename, filename, FileSymPrefix + filename, line - 1, -1} +func NewLinePragmaBase(pos Pos, filename, absFilename string, line uint) *PosBase { + return &PosBase{pos, filename, absFilename, FileSymPrefix + absFilename, line - 1, -1} } // NewInliningBase returns a copy of the old PosBase with the given inlining diff --git a/src/cmd/internal/src/pos_test.go b/src/cmd/internal/src/pos_test.go index a101bc10b1..b06d382536 100644 --- a/src/cmd/internal/src/pos_test.go +++ b/src/cmd/internal/src/pos_test.go @@ -12,16 +12,16 @@ import ( func TestPos(t *testing.T) { f0 := NewFileBase("", "") f1 := NewFileBase("f1", "f1") - f2 := NewLinePragmaBase(Pos{}, "f2", 10) - f3 := NewLinePragmaBase(MakePos(f1, 10, 1), "f3", 100) - f4 := NewLinePragmaBase(MakePos(f3, 10, 1), "f4", 100) + f2 := NewLinePragmaBase(Pos{}, "f2", "f2", 10) + f3 := NewLinePragmaBase(MakePos(f1, 10, 1), "f3", "f3", 100) + f4 := NewLinePragmaBase(MakePos(f3, 10, 1), "f4", "f4", 100) // line directives from issue #19392 fp := NewFileBase("p.go", "p.go") - fc := NewLinePragmaBase(MakePos(fp, 3, 0), "c.go", 10) - ft := NewLinePragmaBase(MakePos(fp, 6, 0), "t.go", 20) - fv := NewLinePragmaBase(MakePos(fp, 9, 0), "v.go", 30) - ff := NewLinePragmaBase(MakePos(fp, 12, 0), "f.go", 40) + fc := NewLinePragmaBase(MakePos(fp, 3, 0), "c.go", "c.go", 10) + ft := NewLinePragmaBase(MakePos(fp, 6, 0), "t.go", "t.go", 20) + fv := NewLinePragmaBase(MakePos(fp, 9, 0), "v.go", "v.go", 30) + ff := NewLinePragmaBase(MakePos(fp, 12, 0), "f.go", "f.go", 40) for _, test := range []struct { pos Pos diff --git a/src/cmd/internal/src/xpos_test.go b/src/cmd/internal/src/xpos_test.go index 4cfeedcd05..8ac9c9dc4e 100644 --- a/src/cmd/internal/src/xpos_test.go +++ b/src/cmd/internal/src/xpos_test.go @@ -19,7 +19,7 @@ func TestNoXPos(t *testing.T) { func TestConversion(t *testing.T) { b1 := NewFileBase("b1", "b1") b2 := NewFileBase("b2", "b2") - b3 := NewLinePragmaBase(MakePos(b1, 10, 0), "b3", 123) + b3 := NewLinePragmaBase(MakePos(b1, 10, 0), "b3", "b3", 123) var tab PosTable for _, want := range []Pos{ |
