Commit af8cd3f6 authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile: fix TODO in tracing code

For #13243.

Change-Id: I214945278255a49f93120f9407f536a6c01a29fb
Reviewed-on: https://go-review.googlesource.com/17101Reviewed-by: default avatarChris Manghane <cmang@golang.org>
parent 64cd8679
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
"strings" "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 // 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 // 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 ...@@ -19,14 +19,24 @@ var thenewparser parser // the parser in use
var savedstate []parser // saved parser state, used during import var savedstate []parser // saved parser state, used during import
func push_parser() { 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) savedstate = append(savedstate, thenewparser)
thenewparser = parser{} thenewparser = parser{indent: indent} // preserve indentation
thenewparser.next() thenewparser.next()
} }
func pop_parser() { func pop_parser() {
indent := thenewparser.indent
n := len(savedstate) - 1 n := len(savedstate) - 1
thenewparser = savedstate[n] thenewparser = savedstate[n]
thenewparser.indent = indent // preserve indentation
savedstate = savedstate[:n] savedstate = savedstate[:n]
} }
...@@ -277,18 +287,13 @@ func (p *parser) print_trace(msg ...interface{}) { ...@@ -277,18 +287,13 @@ func (p *parser) print_trace(msg ...interface{}) {
const n = len(dots) const n = len(dots)
fmt.Printf("%5d: ", lineno) 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 i := 2 * p.indent
for i > n { for i > n {
fmt.Print(dots) fmt.Print(dots)
i -= n i -= n
} }
// i <= n // i <= n
fmt.Print(dots[0:i]) fmt.Print(dots[0:i])
fmt.Println(msg...) fmt.Println(msg...)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment