]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: insert \n at end of every input file
authorRuss Cox <rsc@golang.org>
Tue, 30 Jul 2013 14:27:08 +0000 (10:27 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 30 Jul 2013 14:27:08 +0000 (10:27 -0400)
Not just the first one.

Fixes #5433.
Fixes #5913.

R=ken2
CC=golang-dev
https://golang.org/cl/12028049

src/cmd/gc/go.h
src/cmd/gc/lex.c
test/fixedbugs/bug435.go

index db25013cca19e4edaac885df1b23d425d7d49c3f..e530e79dd0c2a6093f2a586d8a098e41cdc2635c 100644 (file)
@@ -751,6 +751,7 @@ struct      Io
        int32   ilineno;
        int     nlsemi;
        int     eofnl;
+       int     last;
        int     peekc;
        int     peekc1; // second peekc for ...
        char*   cp;     // used for content when bin==nil
index b7f71d553ea34852a74a5b16aaf75bb17c83f914..750b6aad6a93672689665c249a314c59d58f10a7 100644 (file)
@@ -329,6 +329,8 @@ main(int argc, char *argv[])
                curio.peekc = 0;
                curio.peekc1 = 0;
                curio.nlsemi = 0;
+               curio.eofnl = 0;
+               curio.last = 0;
 
                // Skip initial BOM if present.
                if(Bgetrune(curio.bin) != BOM)
@@ -1602,7 +1604,7 @@ check:
                }
        case EOF:
                // insert \n at EOF
-               if(curio.eofnl)
+               if(curio.eofnl || curio.last == '\n')
                        return EOF;
                curio.eofnl = 1;
                c = '\n';
@@ -1611,6 +1613,7 @@ check:
                        lexlineno++;
                break;
        }
+       curio.last = c;
        return c;
 }
 
index 9c30b143bcf245ad725d80de30c8e655dda17c5b..45323d8eed6be2c97cd2ff4e8fc37a57840a69d3 100644 (file)
@@ -12,4 +12,4 @@
 package main
 
 func foo() {
-       bar(1, // ERROR "unexpected|missing|undefined"
+       bar(1, // ERROR "unexpected|missing|undefined"
\ No newline at end of file