Commit f8e41f6f authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: eliminate Io.infile and Io.cp

infile is never read and cp is never written.  Both are unneeded.

Change-Id: I0a90bb772a53a580ea4be8e5f0f770da7c1acf3a
Reviewed-on: https://go-review.googlesource.com/19651Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarDave Cheney <dave@cheney.net>
Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
parent 699a2ba1
...@@ -386,9 +386,7 @@ type Sig struct { ...@@ -386,9 +386,7 @@ type Sig struct {
} }
type Io struct { type Io struct {
infile string
bin *obj.Biobuf bin *obj.Biobuf
cp string // used for content when bin==nil
last int last int
peekc int peekc int
peekc1 int // second peekc for ... peekc1 int // second peekc for ...
......
...@@ -320,7 +320,6 @@ func Main() { ...@@ -320,7 +320,6 @@ func Main() {
linehistpush(infile) linehistpush(infile)
curio.infile = infile
var err error var err error
curio.bin, err = obj.Bopenr(infile) curio.bin, err = obj.Bopenr(infile)
if err != nil { if err != nil {
...@@ -824,7 +823,7 @@ func importfile(f *Val) { ...@@ -824,7 +823,7 @@ func importfile(f *Val) {
case '\n': case '\n':
// old export format // old export format
pushedio = curio pushedio = curio
curio = Io{bin: imp, infile: file} curio = Io{bin: imp}
typecheckok = true typecheckok = true
parse_import() parse_import()
...@@ -851,7 +850,7 @@ func importfile(f *Val) { ...@@ -851,7 +850,7 @@ func importfile(f *Val) {
func cannedimports(file string, cp string) { func cannedimports(file string, cp string) {
lexlineno++ // if sys.6 is included on line 1, lexlineno++ // if sys.6 is included on line 1,
pushedio = curio pushedio = curio
curio = Io{infile: file, bin: obj.Binitr(strings.NewReader(cp))} curio = Io{bin: obj.Binitr(strings.NewReader(cp))}
typecheckok = true typecheckok = true
incannedimport = 1 incannedimport = 1
...@@ -1903,42 +1902,29 @@ func getc() int { ...@@ -1903,42 +1902,29 @@ func getc() int {
goto check goto check
} }
if curio.bin == nil { loop:
if len(curio.cp) == 0 { c = obj.Bgetc(curio.bin)
c = 0 // recognize BOM (U+FEFF): UTF-8 encoding is 0xef 0xbb 0xbf
} else { if c == 0xef {
c = int(curio.cp[0]) buf, err := curio.bin.Peek(2)
curio.cp = curio.cp[1:] if err != nil {
yyerrorl(int(lexlineno), "illegal UTF-8 sequence ef % x followed by read error (%v)", string(buf), err)
errorexit()
} }
} else { if buf[0] == 0xbb && buf[1] == 0xbf {
loop: yyerrorl(int(lexlineno), "Unicode (UTF-8) BOM in middle of file")
c = obj.Bgetc(curio.bin)
// recognize BOM (U+FEFF): UTF-8 encoding is 0xef 0xbb 0xbf
if c == 0xef {
buf, err := curio.bin.Peek(2)
if err != nil {
yyerrorl(int(lexlineno), "illegal UTF-8 sequence ef % x followed by read error (%v)", string(buf), err)
errorexit()
}
if buf[0] == 0xbb && buf[1] == 0xbf {
yyerrorl(int(lexlineno), "Unicode (UTF-8) BOM in middle of file")
// consume BOM bytes // consume BOM bytes
obj.Bgetc(curio.bin) obj.Bgetc(curio.bin)
obj.Bgetc(curio.bin) obj.Bgetc(curio.bin)
goto loop goto loop
}
} }
} }
check: check:
switch c { switch c {
case 0: case 0:
if curio.bin != nil { Yyerror("illegal NUL byte")
Yyerror("illegal NUL byte")
break
}
fallthrough
// insert \n at EOF // insert \n at EOF
case EOF: case EOF:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment