]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: eliminate Io.infile and Io.cp
authorMatthew Dempsky <mdempsky@google.com>
Wed, 2 Dec 2015 19:30:34 +0000 (11:30 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Sat, 20 Feb 2016 04:39:09 +0000 (04:39 +0000)
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 <bradfitz@golang.org>
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/go.go
src/cmd/compile/internal/gc/lex.go

index ebc6a5171ba4e535bcc8ccbbab1df8168c0351c7..71a5d88ccbef5271c7ca9a6f8d1137adb228c8a6 100644 (file)
@@ -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 ...
index e506f7a117fd92df8ad87fe616a6f1fdb0946af5..57b2959de671d99ac1e86ac1bca6fbe50dcf35d2 100644 (file)
@@ -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: