Commit 2faf5bca authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile: introduce linestr helper to simplify line reporting

Change-Id: Ic9ca792b55cc4ebd0ac6cfa2fbdb58030893bacd
Reviewed-on: https://go-review.googlesource.com/20132
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 6969d9bf
...@@ -44,7 +44,7 @@ func pushdcl(s *Sym) *Sym { ...@@ -44,7 +44,7 @@ func pushdcl(s *Sym) *Sym {
d := push() d := push()
dcopy(d, s) dcopy(d, s)
if dflag() { if dflag() {
fmt.Printf("\t%v push %v %p\n", Ctxt.Line(int(lineno)), s, s.Def) fmt.Printf("\t%v push %v %p\n", linestr(lineno), s, s.Def)
} }
return d return d
} }
...@@ -57,7 +57,7 @@ func popdcl() { ...@@ -57,7 +57,7 @@ func popdcl() {
dcopy(s, d) dcopy(s, d)
d.Lastlineno = lno d.Lastlineno = lno
if dflag() { if dflag() {
fmt.Printf("\t%v pop %v %p\n", Ctxt.Line(int(lineno)), s, s.Def) fmt.Printf("\t%v pop %v %p\n", linestr(lineno), s, s.Def)
} }
} }
...@@ -127,7 +127,7 @@ func redeclare(s *Sym, where string) { ...@@ -127,7 +127,7 @@ func redeclare(s *Sym, where string) {
line1 = s.Lastlineno line1 = s.Lastlineno
} }
yyerrorl(line1, "%v redeclared %s\n"+"\tprevious declaration at %v", s, where, Ctxt.Line(int(line2))) yyerrorl(line1, "%v redeclared %s\n"+"\tprevious declaration at %v", s, where, linestr(line2))
} }
} }
...@@ -166,7 +166,7 @@ func declare(n *Node, ctxt Class) { ...@@ -166,7 +166,7 @@ func declare(n *Node, ctxt Class) {
if ctxt == PEXTERN { if ctxt == PEXTERN {
externdcl = append(externdcl, n) externdcl = append(externdcl, n)
if dflag() { if dflag() {
fmt.Printf("\t%v global decl %v %p\n", Ctxt.Line(int(lineno)), s, n) fmt.Printf("\t%v global decl %v %p\n", linestr(lineno), s, n)
} }
} else { } else {
if Curfn == nil && ctxt == PAUTO { if Curfn == nil && ctxt == PAUTO {
...@@ -1527,7 +1527,7 @@ func checknowritebarrierrec() { ...@@ -1527,7 +1527,7 @@ func checknowritebarrierrec() {
// Build the error message in reverse. // Build the error message in reverse.
err := "" err := ""
for call.target != nil { for call.target != nil {
err = fmt.Sprintf("\n\t%v: called by %v%s", Ctxt.Line(int(call.lineno)), n.Func.Nname, err) err = fmt.Sprintf("\n\t%v: called by %v%s", linestr(call.lineno), n.Func.Nname, err)
n = call.target n = call.target
call = c.best[n] call = c.best[n]
} }
......
...@@ -650,7 +650,7 @@ func esc(e *EscState, n *Node, up *Node) { ...@@ -650,7 +650,7 @@ func esc(e *EscState, n *Node, up *Node) {
} }
if Debug['m'] > 1 { if Debug['m'] > 1 {
fmt.Printf("%v:[%d] %v esc: %v\n", Ctxt.Line(int(lineno)), e.loopdepth, funcSym(Curfn), n) fmt.Printf("%v:[%d] %v esc: %v\n", linestr(lineno), e.loopdepth, funcSym(Curfn), n)
} }
switch n.Op { switch n.Op {
...@@ -663,11 +663,11 @@ func esc(e *EscState, n *Node, up *Node) { ...@@ -663,11 +663,11 @@ func esc(e *EscState, n *Node, up *Node) {
case OLABEL: case OLABEL:
if n.Left.Sym.Label == &nonlooping { if n.Left.Sym.Label == &nonlooping {
if Debug['m'] > 1 { if Debug['m'] > 1 {
fmt.Printf("%v:%v non-looping label\n", Ctxt.Line(int(lineno)), n) fmt.Printf("%v:%v non-looping label\n", linestr(lineno), n)
} }
} else if n.Left.Sym.Label == &looping { } else if n.Left.Sym.Label == &looping {
if Debug['m'] > 1 { if Debug['m'] > 1 {
fmt.Printf("%v: %v looping label\n", Ctxt.Line(int(lineno)), n) fmt.Printf("%v: %v looping label\n", linestr(lineno), n)
} }
e.loopdepth++ e.loopdepth++
} }
...@@ -958,7 +958,7 @@ func escassign(e *EscState, dst *Node, src *Node) { ...@@ -958,7 +958,7 @@ func escassign(e *EscState, dst *Node, src *Node) {
if Debug['m'] > 1 { if Debug['m'] > 1 {
fmt.Printf("%v:[%d] %v escassign: %v(%v)[%v] = %v(%v)[%v]\n", fmt.Printf("%v:[%d] %v escassign: %v(%v)[%v] = %v(%v)[%v]\n",
Ctxt.Line(int(lineno)), e.loopdepth, funcSym(Curfn), linestr(lineno), e.loopdepth, funcSym(Curfn),
Nconv(dst, obj.FmtShort), Jconv(dst, obj.FmtShort), Oconv(int(dst.Op), 0), Nconv(dst, obj.FmtShort), Jconv(dst, obj.FmtShort), Oconv(int(dst.Op), 0),
Nconv(src, obj.FmtShort), Jconv(src, obj.FmtShort), Oconv(int(src.Op), 0)) Nconv(src, obj.FmtShort), Jconv(src, obj.FmtShort), Oconv(int(src.Op), 0))
} }
...@@ -1228,7 +1228,7 @@ func escassignfromtag(e *EscState, note *string, dsts *NodeList, src *Node) uint ...@@ -1228,7 +1228,7 @@ func escassignfromtag(e *EscState, note *string, dsts *NodeList, src *Node) uint
if Debug['m'] > 2 { if Debug['m'] > 2 {
fmt.Printf("%v::assignfromtag:: src=%v, em=%s\n", fmt.Printf("%v::assignfromtag:: src=%v, em=%s\n",
Ctxt.Line(int(lineno)), Nconv(src, obj.FmtShort), describeEscape(em)) linestr(lineno), Nconv(src, obj.FmtShort), describeEscape(em))
} }
if em == EscUnknown { if em == EscUnknown {
...@@ -1396,7 +1396,7 @@ func esccall(e *EscState, n *Node, up *Node) { ...@@ -1396,7 +1396,7 @@ func esccall(e *EscState, n *Node, up *Node) {
for ; ll != nil; ll = ll.Next { for ; ll != nil; ll = ll.Next {
escassign(e, &e.theSink, ll.N) escassign(e, &e.theSink, ll.N)
if Debug['m'] > 2 { if Debug['m'] > 2 {
fmt.Printf("%v::esccall:: indirect call <- %v, untracked\n", Ctxt.Line(int(lineno)), Nconv(ll.N, obj.FmtShort)) fmt.Printf("%v::esccall:: indirect call <- %v, untracked\n", linestr(lineno), Nconv(ll.N, obj.FmtShort))
} }
} }
// Set up bogus outputs // Set up bogus outputs
...@@ -1416,7 +1416,7 @@ func esccall(e *EscState, n *Node, up *Node) { ...@@ -1416,7 +1416,7 @@ func esccall(e *EscState, n *Node, up *Node) {
if fn != nil && fn.Op == ONAME && fn.Class == PFUNC && if fn != nil && fn.Op == ONAME && fn.Class == PFUNC &&
fn.Name.Defn != nil && len(fn.Name.Defn.Nbody.Slice()) != 0 && fn.Name.Param.Ntype != nil && fn.Name.Defn.Esc < EscFuncTagged { fn.Name.Defn != nil && len(fn.Name.Defn.Nbody.Slice()) != 0 && fn.Name.Param.Ntype != nil && fn.Name.Defn.Esc < EscFuncTagged {
if Debug['m'] > 2 { if Debug['m'] > 2 {
fmt.Printf("%v::esccall:: %v in recursive group\n", Ctxt.Line(int(lineno)), Nconv(n, obj.FmtShort)) fmt.Printf("%v::esccall:: %v in recursive group\n", linestr(lineno), Nconv(n, obj.FmtShort))
} }
// function in same mutually recursive group. Incorporate into flow graph. // function in same mutually recursive group. Incorporate into flow graph.
...@@ -1461,7 +1461,7 @@ func esccall(e *EscState, n *Node, up *Node) { ...@@ -1461,7 +1461,7 @@ func esccall(e *EscState, n *Node, up *Node) {
// "..." arguments are untracked // "..." arguments are untracked
for ; ll != nil; ll = ll.Next { for ; ll != nil; ll = ll.Next {
if Debug['m'] > 2 { if Debug['m'] > 2 {
fmt.Printf("%v::esccall:: ... <- %v, untracked\n", Ctxt.Line(int(lineno)), Nconv(ll.N, obj.FmtShort)) fmt.Printf("%v::esccall:: ... <- %v, untracked\n", linestr(lineno), Nconv(ll.N, obj.FmtShort))
} }
escassign(e, &e.theSink, ll.N) escassign(e, &e.theSink, ll.N)
} }
...@@ -1475,7 +1475,7 @@ func esccall(e *EscState, n *Node, up *Node) { ...@@ -1475,7 +1475,7 @@ func esccall(e *EscState, n *Node, up *Node) {
} }
if Debug['m'] > 2 { if Debug['m'] > 2 {
fmt.Printf("%v::esccall:: %v not recursive\n", Ctxt.Line(int(lineno)), Nconv(n, obj.FmtShort)) fmt.Printf("%v::esccall:: %v not recursive\n", linestr(lineno), Nconv(n, obj.FmtShort))
} }
// set up out list on this call node with dummy auto ONAMES in the current (calling) function. // set up out list on this call node with dummy auto ONAMES in the current (calling) function.
...@@ -1543,7 +1543,7 @@ func esccall(e *EscState, n *Node, up *Node) { ...@@ -1543,7 +1543,7 @@ func esccall(e *EscState, n *Node, up *Node) {
for ; ll != nil; ll = ll.Next { for ; ll != nil; ll = ll.Next {
if Debug['m'] > 2 { if Debug['m'] > 2 {
fmt.Printf("%v::esccall:: ... <- %v\n", Ctxt.Line(int(lineno)), Nconv(ll.N, obj.FmtShort)) fmt.Printf("%v::esccall:: ... <- %v\n", linestr(lineno), Nconv(ll.N, obj.FmtShort))
} }
escassign(e, src, ll.N) // args to slice escassign(e, src, ll.N) // args to slice
} }
...@@ -1562,7 +1562,7 @@ func escflows(e *EscState, dst *Node, src *Node) { ...@@ -1562,7 +1562,7 @@ func escflows(e *EscState, dst *Node, src *Node) {
} }
if Debug['m'] > 2 { if Debug['m'] > 2 {
fmt.Printf("%v::flows:: %v <- %v\n", Ctxt.Line(int(lineno)), Nconv(dst, obj.FmtShort), Nconv(src, obj.FmtShort)) fmt.Printf("%v::flows:: %v <- %v\n", linestr(lineno), Nconv(dst, obj.FmtShort), Nconv(src, obj.FmtShort))
} }
dstE := e.nodeEscState(dst) dstE := e.nodeEscState(dst)
...@@ -1823,7 +1823,7 @@ func escwalkBody(e *EscState, level Level, dst *Node, src *Node, extraloopdepth ...@@ -1823,7 +1823,7 @@ func escwalkBody(e *EscState, level Level, dst *Node, src *Node, extraloopdepth
if srcE.Escretval != nil { if srcE.Escretval != nil {
if Debug['m'] > 1 { if Debug['m'] > 1 {
fmt.Printf("%v:[%d] dst %v escwalk replace src: %v with %v\n", fmt.Printf("%v:[%d] dst %v escwalk replace src: %v with %v\n",
Ctxt.Line(int(lineno)), e.loopdepth, linestr(lineno), e.loopdepth,
Nconv(dst, obj.FmtShort), Nconv(src, obj.FmtShort), Nconv(srcE.Escretval.N, obj.FmtShort)) Nconv(dst, obj.FmtShort), Nconv(src, obj.FmtShort), Nconv(srcE.Escretval.N, obj.FmtShort))
} }
src = srcE.Escretval.N src = srcE.Escretval.N
......
...@@ -192,9 +192,9 @@ func checkgoto(from *Node, to *Node) { ...@@ -192,9 +192,9 @@ func checkgoto(from *Node, to *Node) {
} }
if block != nil { if block != nil {
Yyerror("goto %v jumps into block starting at %v", from.Left.Sym, Ctxt.Line(int(block.Lastlineno))) Yyerror("goto %v jumps into block starting at %v", from.Left.Sym, linestr(block.Lastlineno))
} else { } else {
Yyerror("goto %v jumps over declaration of %v at %v", from.Left.Sym, dcl, Ctxt.Line(int(dcl.Lastlineno))) Yyerror("goto %v jumps over declaration of %v at %v", from.Left.Sym, dcl, linestr(dcl.Lastlineno))
} }
lineno = int32(lno) lineno = int32(lno)
} }
......
...@@ -1239,9 +1239,9 @@ l0: ...@@ -1239,9 +1239,9 @@ l0:
lx: lx:
if Debug['x'] != 0 { if Debug['x'] != 0 {
if c >= utf8.RuneSelf { if c >= utf8.RuneSelf {
fmt.Printf("%v lex: TOKEN %s\n", Ctxt.Line(int(lineno)), lexname(c)) fmt.Printf("%v lex: TOKEN %s\n", linestr(lineno), lexname(c))
} else { } else {
fmt.Printf("%v lex: TOKEN '%c'\n", Ctxt.Line(int(lineno)), c) fmt.Printf("%v lex: TOKEN '%c'\n", linestr(lineno), c)
} }
} }
......
...@@ -596,7 +596,7 @@ func (s *state) stmt(n *Node) { ...@@ -596,7 +596,7 @@ func (s *state) stmt(n *Node) {
if !lab.defined() { if !lab.defined() {
lab.defNode = n lab.defNode = n
} else { } else {
s.Error("label %v already defined at %v", sym, Ctxt.Line(int(lab.defNode.Lineno))) s.Error("label %v already defined at %v", sym, linestr(lab.defNode.Lineno))
lab.reported = true lab.reported = true
} }
// The label might already have a target block via a goto. // The label might already have a target block via a goto.
...@@ -3446,9 +3446,9 @@ func (s *state) checkgoto(from *Node, to *Node) { ...@@ -3446,9 +3446,9 @@ func (s *state) checkgoto(from *Node, to *Node) {
lno := from.Left.Lineno lno := from.Left.Lineno
if block != nil { if block != nil {
yyerrorl(lno, "goto %v jumps into block starting at %v", from.Left.Sym, Ctxt.Line(int(block.Lastlineno))) yyerrorl(lno, "goto %v jumps into block starting at %v", from.Left.Sym, linestr(block.Lastlineno))
} else { } else {
yyerrorl(lno, "goto %v jumps over declaration of %v at %v", from.Left.Sym, dcl, Ctxt.Line(int(dcl.Lastlineno))) yyerrorl(lno, "goto %v jumps over declaration of %v at %v", from.Left.Sym, dcl, linestr(dcl.Lastlineno))
} }
} }
} }
...@@ -5181,7 +5181,7 @@ func (e *ssaExport) CanSSA(t ssa.Type) bool { ...@@ -5181,7 +5181,7 @@ func (e *ssaExport) CanSSA(t ssa.Type) bool {
} }
func (e *ssaExport) Line(line int32) string { func (e *ssaExport) Line(line int32) string {
return Ctxt.Line(int(line)) return linestr(line)
} }
// Log logs a message from the compiler. // Log logs a message from the compiler.
......
...@@ -45,7 +45,7 @@ func adderrorname(n *Node) { ...@@ -45,7 +45,7 @@ func adderrorname(n *Node) {
func adderr(line int32, format string, args ...interface{}) { func adderr(line int32, format string, args ...interface{}) {
errors = append(errors, Error{ errors = append(errors, Error{
lineno: line, lineno: line,
msg: fmt.Sprintf("%v: %s\n", Ctxt.Line(int(line)), fmt.Sprintf(format, args...)), msg: fmt.Sprintf("%v: %s\n", linestr(line), fmt.Sprintf(format, args...)),
}) })
} }
...@@ -81,6 +81,10 @@ func hcrash() { ...@@ -81,6 +81,10 @@ func hcrash() {
} }
} }
func linestr(line int32) string {
return Ctxt.Line(int(line))
}
func yyerrorl(line int32, format string, args ...interface{}) { func yyerrorl(line int32, format string, args ...interface{}) {
adderr(line, format, args...) adderr(line, format, args...)
...@@ -88,7 +92,7 @@ func yyerrorl(line int32, format string, args ...interface{}) { ...@@ -88,7 +92,7 @@ func yyerrorl(line int32, format string, args ...interface{}) {
nerrors++ nerrors++
if nsavederrors+nerrors >= 10 && Debug['e'] == 0 { if nsavederrors+nerrors >= 10 && Debug['e'] == 0 {
Flusherrors() Flusherrors()
fmt.Printf("%v: too many errors\n", Ctxt.Line(int(line))) fmt.Printf("%v: too many errors\n", linestr(line))
errorexit() errorexit()
} }
} }
...@@ -116,7 +120,7 @@ func Yyerror(format string, args ...interface{}) { ...@@ -116,7 +120,7 @@ func Yyerror(format string, args ...interface{}) {
nerrors++ nerrors++
if nsavederrors+nerrors >= 10 && Debug['e'] == 0 { if nsavederrors+nerrors >= 10 && Debug['e'] == 0 {
Flusherrors() Flusherrors()
fmt.Printf("%v: too many errors\n", Ctxt.Line(int(lineno))) fmt.Printf("%v: too many errors\n", linestr(lineno))
errorexit() errorexit()
} }
} }
...@@ -137,7 +141,7 @@ func Warnl(line int32, fmt_ string, args ...interface{}) { ...@@ -137,7 +141,7 @@ func Warnl(line int32, fmt_ string, args ...interface{}) {
func Fatalf(fmt_ string, args ...interface{}) { func Fatalf(fmt_ string, args ...interface{}) {
Flusherrors() Flusherrors()
fmt.Printf("%v: internal compiler error: ", Ctxt.Line(int(lineno))) fmt.Printf("%v: internal compiler error: ", linestr(lineno))
fmt.Printf(fmt_, args...) fmt.Printf(fmt_, args...)
fmt.Printf("\n") fmt.Printf("\n")
...@@ -154,28 +158,28 @@ func Fatalf(fmt_ string, args ...interface{}) { ...@@ -154,28 +158,28 @@ func Fatalf(fmt_ string, args ...interface{}) {
func linehistpragma(file string) { func linehistpragma(file string) {
if Debug['i'] != 0 { if Debug['i'] != 0 {
fmt.Printf("pragma %s at line %v\n", file, Ctxt.Line(int(lexlineno))) fmt.Printf("pragma %s at line %v\n", file, linestr(lexlineno))
} }
Ctxt.AddImport(file) Ctxt.AddImport(file)
} }
func linehistpush(file string) { func linehistpush(file string) {
if Debug['i'] != 0 { if Debug['i'] != 0 {
fmt.Printf("import %s at line %v\n", file, Ctxt.Line(int(lexlineno))) fmt.Printf("import %s at line %v\n", file, linestr(lexlineno))
} }
Ctxt.LineHist.Push(int(lexlineno), file) Ctxt.LineHist.Push(int(lexlineno), file)
} }
func linehistpop() { func linehistpop() {
if Debug['i'] != 0 { if Debug['i'] != 0 {
fmt.Printf("end of import at line %v\n", Ctxt.Line(int(lexlineno))) fmt.Printf("end of import at line %v\n", linestr(lexlineno))
} }
Ctxt.LineHist.Pop(int(lexlineno)) Ctxt.LineHist.Pop(int(lexlineno))
} }
func linehistupdate(file string, off int) { func linehistupdate(file string, off int) {
if Debug['i'] != 0 { if Debug['i'] != 0 {
fmt.Printf("line %s at line %v\n", file, Ctxt.Line(int(lexlineno))) fmt.Printf("line %s at line %v\n", file, linestr(lexlineno))
} }
Ctxt.LineHist.Update(int(lexlineno), file, off) Ctxt.LineHist.Update(int(lexlineno), file, off)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment