From 2faf5bca2e23be26fd0fc3a373bee7a354813861 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 2 Mar 2016 11:30:29 -0800 Subject: [PATCH] cmd/compile: introduce linestr helper to simplify line reporting Change-Id: Ic9ca792b55cc4ebd0ac6cfa2fbdb58030893bacd Reviewed-on: https://go-review.googlesource.com/20132 Run-TryBot: Robert Griesemer Reviewed-by: Matthew Dempsky TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/gc/dcl.go | 10 +++++----- src/cmd/compile/internal/gc/esc.go | 24 ++++++++++++------------ src/cmd/compile/internal/gc/gen.go | 4 ++-- src/cmd/compile/internal/gc/lex.go | 4 ++-- src/cmd/compile/internal/gc/ssa.go | 8 ++++---- src/cmd/compile/internal/gc/subr.go | 20 ++++++++++++-------- 6 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/cmd/compile/internal/gc/dcl.go b/src/cmd/compile/internal/gc/dcl.go index eb0ccf087f..da0c4575bf 100644 --- a/src/cmd/compile/internal/gc/dcl.go +++ b/src/cmd/compile/internal/gc/dcl.go @@ -44,7 +44,7 @@ func pushdcl(s *Sym) *Sym { d := push() dcopy(d, s) 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 } @@ -57,7 +57,7 @@ func popdcl() { dcopy(s, d) d.Lastlineno = lno 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) { 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) { if ctxt == PEXTERN { externdcl = append(externdcl, n) 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 { if Curfn == nil && ctxt == PAUTO { @@ -1527,7 +1527,7 @@ func checknowritebarrierrec() { // Build the error message in reverse. err := "" 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 call = c.best[n] } diff --git a/src/cmd/compile/internal/gc/esc.go b/src/cmd/compile/internal/gc/esc.go index 08cdc88496..30eacc6670 100644 --- a/src/cmd/compile/internal/gc/esc.go +++ b/src/cmd/compile/internal/gc/esc.go @@ -650,7 +650,7 @@ func esc(e *EscState, n *Node, up *Node) { } 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 { @@ -663,11 +663,11 @@ func esc(e *EscState, n *Node, up *Node) { case OLABEL: if n.Left.Sym.Label == &nonlooping { 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 { 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++ } @@ -958,7 +958,7 @@ func escassign(e *EscState, dst *Node, src *Node) { if Debug['m'] > 1 { 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(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 if Debug['m'] > 2 { 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 { @@ -1396,7 +1396,7 @@ func esccall(e *EscState, n *Node, up *Node) { for ; ll != nil; ll = ll.Next { escassign(e, &e.theSink, ll.N) 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 @@ -1416,7 +1416,7 @@ func esccall(e *EscState, n *Node, up *Node) { 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 { 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. @@ -1461,7 +1461,7 @@ func esccall(e *EscState, n *Node, up *Node) { // "..." arguments are untracked for ; ll != nil; ll = ll.Next { 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) } @@ -1475,7 +1475,7 @@ func esccall(e *EscState, n *Node, up *Node) { } 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. @@ -1543,7 +1543,7 @@ func esccall(e *EscState, n *Node, up *Node) { for ; ll != nil; ll = ll.Next { 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 } @@ -1562,7 +1562,7 @@ func escflows(e *EscState, dst *Node, src *Node) { } 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) @@ -1823,7 +1823,7 @@ func escwalkBody(e *EscState, level Level, dst *Node, src *Node, extraloopdepth if srcE.Escretval != nil { if Debug['m'] > 1 { 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)) } src = srcE.Escretval.N diff --git a/src/cmd/compile/internal/gc/gen.go b/src/cmd/compile/internal/gc/gen.go index 38dc27da31..13fac83875 100644 --- a/src/cmd/compile/internal/gc/gen.go +++ b/src/cmd/compile/internal/gc/gen.go @@ -192,9 +192,9 @@ func checkgoto(from *Node, to *Node) { } 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 { - 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) } diff --git a/src/cmd/compile/internal/gc/lex.go b/src/cmd/compile/internal/gc/lex.go index 9cf5ae74d0..6405dff681 100644 --- a/src/cmd/compile/internal/gc/lex.go +++ b/src/cmd/compile/internal/gc/lex.go @@ -1239,9 +1239,9 @@ l0: lx: if Debug['x'] != 0 { 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 { - fmt.Printf("%v lex: TOKEN '%c'\n", Ctxt.Line(int(lineno)), c) + fmt.Printf("%v lex: TOKEN '%c'\n", linestr(lineno), c) } } diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index e5c65c7002..e5d72ced4f 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -596,7 +596,7 @@ func (s *state) stmt(n *Node) { if !lab.defined() { lab.defNode = n } 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 } // The label might already have a target block via a goto. @@ -3446,9 +3446,9 @@ func (s *state) checkgoto(from *Node, to *Node) { lno := from.Left.Lineno 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 { - 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 { } func (e *ssaExport) Line(line int32) string { - return Ctxt.Line(int(line)) + return linestr(line) } // Log logs a message from the compiler. diff --git a/src/cmd/compile/internal/gc/subr.go b/src/cmd/compile/internal/gc/subr.go index 386955c2da..72bdfb24f9 100644 --- a/src/cmd/compile/internal/gc/subr.go +++ b/src/cmd/compile/internal/gc/subr.go @@ -45,7 +45,7 @@ func adderrorname(n *Node) { func adderr(line int32, format string, args ...interface{}) { errors = append(errors, Error{ 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() { } } +func linestr(line int32) string { + return Ctxt.Line(int(line)) +} + func yyerrorl(line int32, format string, args ...interface{}) { adderr(line, format, args...) @@ -88,7 +92,7 @@ func yyerrorl(line int32, format string, args ...interface{}) { nerrors++ if nsavederrors+nerrors >= 10 && Debug['e'] == 0 { Flusherrors() - fmt.Printf("%v: too many errors\n", Ctxt.Line(int(line))) + fmt.Printf("%v: too many errors\n", linestr(line)) errorexit() } } @@ -116,7 +120,7 @@ func Yyerror(format string, args ...interface{}) { nerrors++ if nsavederrors+nerrors >= 10 && Debug['e'] == 0 { Flusherrors() - fmt.Printf("%v: too many errors\n", Ctxt.Line(int(lineno))) + fmt.Printf("%v: too many errors\n", linestr(lineno)) errorexit() } } @@ -137,7 +141,7 @@ func Warnl(line int32, fmt_ string, args ...interface{}) { func Fatalf(fmt_ string, args ...interface{}) { 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("\n") @@ -154,28 +158,28 @@ func Fatalf(fmt_ string, args ...interface{}) { func linehistpragma(file string) { 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) } func linehistpush(file string) { 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) } func linehistpop() { 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)) } func linehistupdate(file string, off int) { 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) } -- 2.48.1