mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
4e6e8e8c58
commit
338a891e79
3 changed files with 22 additions and 45 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 .
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue