Commit 27d17255 authored by Russ Cox's avatar Russ Cox

cmd/gc: insert \n at end of every input file

Not just the first one.

Fixes #5433.
Fixes #5913.

R=ken2
CC=golang-dev
https://golang.org/cl/12028049
parent 28138f13
...@@ -751,6 +751,7 @@ struct Io ...@@ -751,6 +751,7 @@ struct Io
int32 ilineno; int32 ilineno;
int nlsemi; int nlsemi;
int eofnl; int eofnl;
int last;
int peekc; int peekc;
int peekc1; // second peekc for ... int peekc1; // second peekc for ...
char* cp; // used for content when bin==nil char* cp; // used for content when bin==nil
......
...@@ -329,6 +329,8 @@ main(int argc, char *argv[]) ...@@ -329,6 +329,8 @@ main(int argc, char *argv[])
curio.peekc = 0; curio.peekc = 0;
curio.peekc1 = 0; curio.peekc1 = 0;
curio.nlsemi = 0; curio.nlsemi = 0;
curio.eofnl = 0;
curio.last = 0;
// Skip initial BOM if present. // Skip initial BOM if present.
if(Bgetrune(curio.bin) != BOM) if(Bgetrune(curio.bin) != BOM)
...@@ -1602,7 +1604,7 @@ check: ...@@ -1602,7 +1604,7 @@ check:
} }
case EOF: case EOF:
// insert \n at EOF // insert \n at EOF
if(curio.eofnl) if(curio.eofnl || curio.last == '\n')
return EOF; return EOF;
curio.eofnl = 1; curio.eofnl = 1;
c = '\n'; c = '\n';
...@@ -1611,6 +1613,7 @@ check: ...@@ -1611,6 +1613,7 @@ check:
lexlineno++; lexlineno++;
break; break;
} }
curio.last = c;
return c; return c;
} }
......
...@@ -12,4 +12,4 @@ ...@@ -12,4 +12,4 @@
package main package main
func foo() { func foo() {
bar(1, // ERROR "unexpected|missing|undefined" bar(1, // ERROR "unexpected|missing|undefined"
\ No newline at end of file
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