From: Robert Griesemer Date: Fri, 20 Nov 2015 17:58:22 +0000 (-0800) Subject: cmd/compile: fix TODO in tracing code X-Git-Tag: go1.6beta1~345 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=af8cd3f6bdca237b3a843d66031c568f4679de73;p=gostls13.git cmd/compile: fix TODO in tracing code For #13243. Change-Id: I214945278255a49f93120f9407f536a6c01a29fb Reviewed-on: https://go-review.googlesource.com/17101 Reviewed-by: Chris Manghane --- diff --git a/src/cmd/compile/internal/gc/parser.go b/src/cmd/compile/internal/gc/parser.go index f440ef7d3f..b73af6d900 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 = false // if set, parse tracing can be enabled with -x +const trace = true // 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 @@ -19,14 +19,24 @@ var thenewparser parser // the parser in use var savedstate []parser // saved parser state, used during import func push_parser() { + // Indentation (for tracing) must be preserved across parsers + // since we are changing the lexer source (and parser state) + // under foot, in the middle of productions. This won't be + // needed anymore once we fix issue 13242, but neither will + // be the push/pop_parser functionality. + // (Instead we could just use a global variable indent, but + // but eventually indent should be parser-specific anyway.) + indent := thenewparser.indent savedstate = append(savedstate, thenewparser) - thenewparser = parser{} + thenewparser = parser{indent: indent} // preserve indentation thenewparser.next() } func pop_parser() { + indent := thenewparser.indent n := len(savedstate) - 1 thenewparser = savedstate[n] + thenewparser.indent = indent // preserve indentation savedstate = savedstate[:n] } @@ -277,18 +287,13 @@ func (p *parser) print_trace(msg ...interface{}) { const n = len(dots) fmt.Printf("%5d: ", lineno) - // TODO(gri) imports screw up p.indent - fix this - // (issue 13243) - if p.indent < 0 { - p.indent = 0 - } - i := 2 * p.indent for i > n { fmt.Print(dots) i -= n } // i <= n + fmt.Print(dots[0:i]) fmt.Println(msg...) }