]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix TODO in tracing code
authorRobert Griesemer <gri@golang.org>
Fri, 20 Nov 2015 17:58:22 +0000 (09:58 -0800)
committerRobert Griesemer <gri@golang.org>
Fri, 20 Nov 2015 19:56:51 +0000 (19:56 +0000)
For #13243.

Change-Id: I214945278255a49f93120f9407f536a6c01a29fb
Reviewed-on: https://go-review.googlesource.com/17101
Reviewed-by: Chris Manghane <cmang@golang.org>
src/cmd/compile/internal/gc/parser.go

index f440ef7d3f268516117a33d9cb40aacae91a88d3..b73af6d900f23c58a4ee5aa855bbaf8f4595962f 100644 (file)
@@ -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...)
 }