From: Matthew Dempsky Date: Sat, 20 Feb 2016 02:47:01 +0000 (-0800) Subject: cmd/compile: eliminate pushedio and savedstate X-Git-Tag: go1.7beta1~1816 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=338a891e79444de97d6f485b1632d42899c47c6d;p=gostls13.git cmd/compile: eliminate pushedio and savedstate 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 Run-TryBot: Matthew Dempsky --- diff --git a/src/cmd/compile/internal/gc/go.go b/src/cmd/compile/internal/gc/go.go index 71a5d88ccb..7cfc2c9057 100644 --- a/src/cmd/compile/internal/gc/go.go +++ b/src/cmd/compile/internal/gc/go.go @@ -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 diff --git a/src/cmd/compile/internal/gc/lex.go b/src/cmd/compile/internal/gc/lex.go index ae201a7d97..91b521e95b 100644 --- a/src/cmd/compile/internal/gc/lex.go +++ b/src/cmd/compile/internal/gc/lex.go @@ -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' } diff --git a/src/cmd/compile/internal/gc/parser.go b/src/cmd/compile/internal/gc/parser.go index 4a49836e8d..e41f3b9e86 100644 --- a/src/cmd/compile/internal/gc/parser.go +++ b/src/cmd/compile/internal/gc/parser.go @@ -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 .