]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: eliminate global fileparser
authorMatthew Dempsky <mdempsky@google.com>
Sat, 20 Feb 2016 02:51:24 +0000 (18:51 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Sat, 20 Feb 2016 05:41:53 +0000 (05:41 +0000)
Change-Id: I9b8b13731ccc2ba33d21642b12cc614dde0804b1
Reviewed-on: https://go-review.googlesource.com/19752
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>

src/cmd/compile/internal/gc/lex.go
src/cmd/compile/internal/gc/parser.go

index 91b521e95bab685bfe1b7176faef5f17809ea625..66cc01862d403a10dde85dfb0138d673304fc539 100644 (file)
@@ -661,16 +661,16 @@ func loadsys() {
        incannedimport = 1
 
        importpkg = Runtimepkg
-       parse_import(obj.Binitr(strings.NewReader(runtimeimport)))
+       parse_import(obj.Binitr(strings.NewReader(runtimeimport)), nil)
 
        importpkg = unsafepkg
-       parse_import(obj.Binitr(strings.NewReader(unsafeimport)))
+       parse_import(obj.Binitr(strings.NewReader(unsafeimport)), nil)
 
        importpkg = nil
        incannedimport = 0
 }
 
-func importfile(f *Val) {
+func importfile(f *Val, indent []byte) {
        if importpkg != nil {
                Fatalf("importpkg not nil")
        }
@@ -815,7 +815,7 @@ func importfile(f *Val) {
        switch c {
        case '\n':
                // old export format
-               parse_import(imp)
+               parse_import(imp, indent)
 
        case 'B':
                // new export format
index e41f3b9e86fdea7aba80b04c70fdf9fd4c4bfbd7..048b81e01bc3bb4bd009fb7c1eefb4f887c487c4 100644 (file)
@@ -21,22 +21,11 @@ import (
 
 const trace = false // if set, parse tracing can be enabled with -x
 
-// TODO(gri) Once we stop supporting the legacy export data format
-// we can get rid of this (issue 13242).
-var fileparser parser // the Go source file parser in use
-
-func parse_import(bin *obj.Biobuf) {
+func parse_import(bin *obj.Biobuf, indent []byte) {
        pushedio := curio
        curio = Io{bin: bin}
 
-       // 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.)
-       importparser := parser{indent: fileparser.indent} // preserve indentation
+       importparser := parser{indent: indent} // preserve indentation
        importparser.next()
        importparser.import_package()
 
@@ -47,7 +36,7 @@ func parse_import(bin *obj.Biobuf) {
 func parse_file(bin *obj.Biobuf) {
        curio = Io{bin: bin}
 
-       fileparser = parser{}
+       fileparser := parser{}
        fileparser.next()
        fileparser.file()
 }
@@ -360,7 +349,7 @@ func (p *parser) importdcl() {
        path := p.val
        p.next()
 
-       importfile(&path)
+       importfile(&path, p.indent)
        if importpkg == nil {
                if nerrors == 0 {
                        Fatalf("phase error in import")