From: Matthew Dempsky Date: Wed, 2 Dec 2015 19:30:34 +0000 (-0800) Subject: cmd/compile: eliminate Io.infile and Io.cp X-Git-Tag: go1.7beta1~1818 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f8e41f6f5907ce832cc263bdce749117d4d0b342;p=gostls13.git 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/19651 Reviewed-by: Brad Fitzpatrick Reviewed-by: Dave Cheney Reviewed-by: Robert Griesemer --- diff --git a/src/cmd/compile/internal/gc/go.go b/src/cmd/compile/internal/gc/go.go index ebc6a5171b..71a5d88ccb 100644 --- a/src/cmd/compile/internal/gc/go.go +++ b/src/cmd/compile/internal/gc/go.go @@ -386,9 +386,7 @@ type Sig struct { } type Io struct { - infile string bin *obj.Biobuf - cp string // used for content when bin==nil last int peekc int peekc1 int // second peekc for ... diff --git a/src/cmd/compile/internal/gc/lex.go b/src/cmd/compile/internal/gc/lex.go index e506f7a117..57b2959de6 100644 --- a/src/cmd/compile/internal/gc/lex.go +++ b/src/cmd/compile/internal/gc/lex.go @@ -320,7 +320,6 @@ func Main() { linehistpush(infile) - curio.infile = infile var err error curio.bin, err = obj.Bopenr(infile) if err != nil { @@ -824,7 +823,7 @@ func importfile(f *Val) { case '\n': // old export format pushedio = curio - curio = Io{bin: imp, infile: file} + curio = Io{bin: imp} typecheckok = true parse_import() @@ -851,7 +850,7 @@ func importfile(f *Val) { func cannedimports(file string, cp string) { lexlineno++ // if sys.6 is included on line 1, pushedio = curio - curio = Io{infile: file, bin: obj.Binitr(strings.NewReader(cp))} + curio = Io{bin: obj.Binitr(strings.NewReader(cp))} typecheckok = true incannedimport = 1 @@ -1903,42 +1902,29 @@ func getc() int { goto check } - if curio.bin == nil { - if len(curio.cp) == 0 { - c = 0 - } else { - c = int(curio.cp[0]) - curio.cp = curio.cp[1:] +loop: + 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() } - } else { - loop: - 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") + if buf[0] == 0xbb && buf[1] == 0xbf { + yyerrorl(int(lexlineno), "Unicode (UTF-8) BOM in middle of file") - // consume BOM bytes - obj.Bgetc(curio.bin) - obj.Bgetc(curio.bin) - goto loop - } + // consume BOM bytes + obj.Bgetc(curio.bin) + obj.Bgetc(curio.bin) + goto loop } } check: switch c { case 0: - if curio.bin != nil { - Yyerror("illegal NUL byte") - break - } - fallthrough + Yyerror("illegal NUL byte") // insert \n at EOF case EOF: