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
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()
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) {
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
}
}
-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'
}
// to handle optional commas and semicolons before a closing ) or } .
import (
+ "cmd/internal/obj"
"fmt"
"strconv"
"strings"
// 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
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()
}
importpkg.Safe = importsafe
+ typecheckok = true
defercheckwidth()
p.hidden_import_list()
}
resumecheckwidth()
+ typecheckok = false
}
// Declaration = ConstDecl | TypeDecl | VarDecl .