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 <gri@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Matthew Dempsky 2016-02-19 18:47:01 -08:00
parent 4e6e8e8c58
commit 338a891e79
3 changed files with 22 additions and 45 deletions

View file

@ -451,8 +451,6 @@ var dotlist [10]Dlist // size is max depth of embeddeds
var curio Io var curio Io
var pushedio Io
var lexlineno int32 var lexlineno int32
var lineno int32 var lineno int32

View file

@ -320,22 +320,15 @@ func Main() {
linehistpush(infile) linehistpush(infile)
var err error bin, err := obj.Bopenr(infile)
curio.bin, err = obj.Bopenr(infile)
if err != nil { if err != nil {
fmt.Printf("open %s: %v\n", infile, err) fmt.Printf("open %s: %v\n", infile, err)
errorexit() errorexit()
} }
curio.peekc = 0
curio.peekc1 = 0
curio.nlsemi = false
curio.eofnl = false
curio.last = 0
// Skip initial BOM if present. // Skip initial BOM if present.
if obj.Bgetrune(curio.bin) != BOM { if obj.Bgetrune(bin) != BOM {
obj.Bungetrune(curio.bin) obj.Bungetrune(bin)
} }
block = 1 block = 1
@ -343,15 +336,13 @@ func Main() {
imported_unsafe = false imported_unsafe = false
parse_file() parse_file(bin)
if nsyntaxerrors != 0 { if nsyntaxerrors != 0 {
errorexit() errorexit()
} }
linehistpop() linehistpop()
if curio.bin != nil { obj.Bterm(bin)
obj.Bterm(curio.bin)
}
} }
testdclstack() testdclstack()
@ -667,14 +658,16 @@ func loadsys() {
block = 1 block = 1
iota_ = -1000000 iota_ = -1000000
incannedimport = 1
importpkg = Runtimepkg importpkg = Runtimepkg
cannedimports("runtime.Builtin", runtimeimport) parse_import(obj.Binitr(strings.NewReader(runtimeimport)))
importpkg = unsafepkg importpkg = unsafepkg
cannedimports("unsafe.o", unsafeimport) parse_import(obj.Binitr(strings.NewReader(unsafeimport)))
importpkg = nil importpkg = nil
incannedimport = 0
} }
func importfile(f *Val) { func importfile(f *Val) {
@ -822,15 +815,7 @@ func importfile(f *Val) {
switch c { switch c {
case '\n': case '\n':
// old export format // old export format
pushedio = curio parse_import(imp)
curio = Io{bin: imp}
typecheckok = true
parse_import()
typecheckok = false
curio = pushedio
pushedio.bin = nil
case 'B': case 'B':
// new export format // 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 { func isSpace(c int) bool {
return c == ' ' || c == '\t' || c == '\n' || c == '\r' return c == ' ' || c == '\t' || c == '\n' || c == '\r'
} }

View file

@ -13,6 +13,7 @@ package gc
// to handle optional commas and semicolons before a closing ) or } . // to handle optional commas and semicolons before a closing ) or } .
import ( import (
"cmd/internal/obj"
"fmt" "fmt"
"strconv" "strconv"
"strings" "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). // we can get rid of this (issue 13242).
var fileparser parser // the Go source file parser in use 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 // Indentation (for tracing) must be preserved across parsers
// since we are changing the lexer source (and parser state) // since we are changing the lexer source (and parser state)
// under foot, in the middle of productions. This won't be // 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 := parser{indent: fileparser.indent} // preserve indentation
importparser.next() importparser.next()
importparser.import_package() importparser.import_package()
curio = pushedio
} }
// parse_file sets up a new parser and parses a single Go source file. // 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 = parser{}
fileparser.next() fileparser.next()
fileparser.file() fileparser.file()
@ -428,6 +436,7 @@ func (p *parser) import_package() {
} }
importpkg.Safe = importsafe importpkg.Safe = importsafe
typecheckok = true
defercheckwidth() defercheckwidth()
p.hidden_import_list() p.hidden_import_list()
@ -438,6 +447,7 @@ func (p *parser) import_package() {
} }
resumecheckwidth() resumecheckwidth()
typecheckok = false
} }
// Declaration = ConstDecl | TypeDecl | VarDecl . // Declaration = ConstDecl | TypeDecl | VarDecl .