]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: simplify tracing code (cleanup)
authorRobert Griesemer <gri@golang.org>
Fri, 20 Nov 2015 18:16:34 +0000 (10:16 -0800)
committerRobert Griesemer <gri@golang.org>
Sat, 21 Nov 2015 07:20:39 +0000 (07:20 +0000)
Change-Id: I7c084542996226f3ed464314a5622fcfaac02d61
Reviewed-on: https://go-review.googlesource.com/17103
Reviewed-by: Chris Manghane <cmang@golang.org>
src/cmd/compile/internal/gc/parser.go

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