From 0383bb473ddd394495c17f1ce7f5e555e311986d Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 20 Nov 2015 10:16:34 -0800 Subject: [PATCH] cmd/compile: simplify tracing code (cleanup) Change-Id: I7c084542996226f3ed464314a5622fcfaac02d61 Reviewed-on: https://go-review.googlesource.com/17103 Reviewed-by: Chris Manghane --- src/cmd/compile/internal/gc/parser.go | 29 +++++++-------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/src/cmd/compile/internal/gc/parser.go b/src/cmd/compile/internal/gc/parser.go index b73af6d900..7244e44654 100644 --- a/src/cmd/compile/internal/gc/parser.go +++ b/src/cmd/compile/internal/gc/parser.go @@ -10,7 +10,7 @@ import ( "strings" ) -const trace = true // if set, parse tracing can be enabled with -x +const trace = false // if set, parse tracing can be enabled with -x // TODO(gri) Once we handle imports w/o redirecting the underlying // source of the lexer we can get rid of these. They are here for @@ -80,7 +80,7 @@ type parser struct { fnest int // function nesting level (for error handling) xnest int // expression nesting level (for complit ambiguity resolution) yy yySymType // for temporary use by next - indent int // tracing support + indent []byte // tracing support } func (p *parser) next() { @@ -282,32 +282,17 @@ var tokstrings = map[int32]string{ PreferToRightParen: "PreferToRightParen", // we should never see this one } -func (p *parser) print_trace(msg ...interface{}) { - const dots = ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " - const n = len(dots) - fmt.Printf("%5d: ", lineno) - - i := 2 * p.indent - for i > n { - fmt.Print(dots) - i -= n - } - // i <= n - - fmt.Print(dots[0:i]) - fmt.Println(msg...) -} - // usage: defer p.trace(msg)() func (p *parser) trace(msg string) func() { - p.print_trace(msg, "(") - p.indent++ + fmt.Printf("%5d: %s%s (\n", lineno, p.indent, msg) + const tab = ". " + p.indent = append(p.indent, tab...) return func() { - p.indent-- + p.indent = p.indent[:len(p.indent)-len(tab)] if x := recover(); x != nil { panic(x) // skip print_trace } - p.print_trace(")") + fmt.Printf("%5d: %s)\n", lineno, p.indent) } } -- 2.48.1