]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: eliminate pushedio and savedstate
authorMatthew Dempsky <mdempsky@google.com>
Sat, 20 Feb 2016 02:47:01 +0000 (18:47 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Sat, 20 Feb 2016 05:14:32 +0000 (05:14 +0000)
While here, get drop the lexlineno{++,--} hacks for canned imports.
They were added in commit d3237f9, but don't seem to serve any
purpose.

Change-Id: I00f9e6be0ae9f217f2fa113b85e041dfd0303757
Reviewed-on: https://go-review.googlesource.com/19652
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>

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

index 71a5d88ccbef5271c7ca9a6f8d1137adb228c8a6..7cfc2c9057eef360a0c00528f88aab2aa07b3ace 100644 (file)
@@ -451,8 +451,6 @@ var dotlist [10]Dlist // size is max depth of embeddeds
 
 var curio Io
 
-var pushedio Io
-
 var lexlineno int32
 
 var lineno int32
index ae201a7d97e1bae9e5159ca16fb6aaf852a451a9..91b521e95bab685bfe1b7176faef5f17809ea625 100644 (file)
@@ -320,22 +320,15 @@ func Main() {
 
                linehistpush(infile)
 
-               var err error
-               curio.bin, err = obj.Bopenr(infile)
+               bin, err := obj.Bopenr(infile)
                if err != nil {
                        fmt.Printf("open %s: %v\n", infile, err)
                        errorexit()
                }
 
-               curio.peekc = 0
-               curio.peekc1 = 0
-               curio.nlsemi = false
-               curio.eofnl = false
-               curio.last = 0
-
                // Skip initial BOM if present.
-               if obj.Bgetrune(curio.bin) != BOM {
-                       obj.Bungetrune(curio.bin)
+               if obj.Bgetrune(bin) != BOM {
+                       obj.Bungetrune(bin)
                }
 
                block = 1
@@ -343,15 +336,13 @@ func Main() {
 
                imported_unsafe = false
 
-               parse_file()
+               parse_file(bin)
                if nsyntaxerrors != 0 {
                        errorexit()
                }
 
                linehistpop()
-               if curio.bin != nil {
-                       obj.Bterm(curio.bin)
-               }
+               obj.Bterm(bin)
        }
 
        testdclstack()
@@ -667,14 +658,16 @@ func loadsys() {
 
        block = 1
        iota_ = -1000000
+       incannedimport = 1
 
        importpkg = Runtimepkg
-       cannedimports("runtime.Builtin", runtimeimport)
+       parse_import(obj.Binitr(strings.NewReader(runtimeimport)))
 
        importpkg = unsafepkg
-       cannedimports("unsafe.o", unsafeimport)
+       parse_import(obj.Binitr(strings.NewReader(unsafeimport)))
 
        importpkg = nil
+       incannedimport = 0
 }
 
 func importfile(f *Val) {
@@ -822,15 +815,7 @@ func importfile(f *Val) {
        switch c {
        case '\n':
                // old export format
-               pushedio = curio
-               curio = Io{bin: imp}
-               typecheckok = true
-
-               parse_import()
-
-               typecheckok = false
-               curio = pushedio
-               pushedio.bin = nil
+               parse_import(imp)
 
        case 'B':
                // new export format
@@ -847,22 +832,6 @@ func importfile(f *Val) {
        }
 }
 
-func cannedimports(file string, cp string) {
-       lexlineno++ // if sys.6 is included on line 1,
-       pushedio = curio
-       curio = Io{bin: obj.Binitr(strings.NewReader(cp))}
-       typecheckok = true
-       incannedimport = 1
-
-       parse_import()
-
-       typecheckok = false
-       incannedimport = 0
-       curio = pushedio
-       pushedio.bin = nil
-       lexlineno-- // re correct sys.6 line number
-}
-
 func isSpace(c int) bool {
        return c == ' ' || c == '\t' || c == '\n' || c == '\r'
 }
index 4a49836e8d6cb5629b56a8dd4e1a3f5b1fc6d471..e41f3b9e86fdea7aba80b04c70fdf9fd4c4bfbd7 100644 (file)
@@ -13,6 +13,7 @@ package gc
 // to handle optional commas and semicolons before a closing ) or } .
 
 import (
+       "cmd/internal/obj"
        "fmt"
        "strconv"
        "strings"
@@ -24,7 +25,10 @@ const trace = false // if set, parse tracing can be enabled with -x
 // we can get rid of this (issue 13242).
 var fileparser parser // the Go source file parser in use
 
-func parse_import() {
+func parse_import(bin *obj.Biobuf) {
+       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
@@ -35,10 +39,14 @@ func parse_import() {
        importparser := parser{indent: fileparser.indent} // preserve indentation
        importparser.next()
        importparser.import_package()
+
+       curio = pushedio
 }
 
 // parse_file sets up a new parser and parses a single Go source file.
-func parse_file() {
+func parse_file(bin *obj.Biobuf) {
+       curio = Io{bin: bin}
+
        fileparser = parser{}
        fileparser.next()
        fileparser.file()
@@ -428,6 +436,7 @@ func (p *parser) import_package() {
        }
        importpkg.Safe = importsafe
 
+       typecheckok = true
        defercheckwidth()
 
        p.hidden_import_list()
@@ -438,6 +447,7 @@ func (p *parser) import_package() {
        }
 
        resumecheckwidth()
+       typecheckok = false
 }
 
 // Declaration = ConstDecl | TypeDecl | VarDecl .