Skip to content

Commit

Permalink
cmd/compile: introduce linestr helper to simplify line reporting
Browse files Browse the repository at this point in the history
Change-Id: Ic9ca792b55cc4ebd0ac6cfa2fbdb58030893bacd
Reviewed-on: https://go-review.googlesource.com/20132
Run-TryBot: Robert Griesemer <[email protected]>
Reviewed-by: Matthew Dempsky <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
  • Loading branch information
griesemer committed Mar 2, 2016
1 parent 6969d9b commit 2faf5bc
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 33 deletions.
10 changes: 5 additions & 5 deletions src/cmd/compile/internal/gc/dcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
}
Expand Down
24 changes: 12 additions & 12 deletions src/cmd/compile/internal/gc/esc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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++
}
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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)
}
Expand All @@ -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.
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/gc/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/gc/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/cmd/compile/internal/gc/ssa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
}
}
}
Expand Down Expand Up @@ -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.
Expand Down
20 changes: 12 additions & 8 deletions src/cmd/compile/internal/gc/subr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)),
})
}

Expand Down Expand Up @@ -81,14 +81,18 @@ func hcrash() {
}
}

func linestr(line int32) string {
return Ctxt.Line(int(line))
}

func yyerrorl(line int32, format string, args ...interface{}) {
adderr(line, format, args...)

hcrash()
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()
}
}
Expand Down Expand Up @@ -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()
}
}
Expand All @@ -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")

Expand All @@ -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)
}
Expand Down

0 comments on commit 2faf5bc

Please sign in to comment.