Commit 19d7fc40 authored by Ken Thompson's avatar Ken Thompson

change line pragma from

	//line number file
to
	//line file:number

R=rsc
CC=golang-dev
https://golang.org/cl/1868041
parent d1e2f73b
...@@ -1110,7 +1110,7 @@ caseout: ...@@ -1110,7 +1110,7 @@ caseout:
/* /*
* read and interpret syntax that looks like * read and interpret syntax that looks like
* //line 15 parse.y * //line parse.y:15
* as a discontenuity in sequential line numbers. * as a discontenuity in sequential line numbers.
* the next line of input comes from parse.y:15 * the next line of input comes from parse.y:15
*/ */
...@@ -1124,44 +1124,45 @@ getlinepragma(void) ...@@ -1124,44 +1124,45 @@ getlinepragma(void)
for(i=0; i<5; i++) { for(i=0; i<5; i++) {
c = getr(); c = getr();
if(c != "line "[i]) if(c != "line "[i])
return c; goto out;
} }
n = 0;
for(;;) {
c = getr();
if(!isdigit(c))
break;
n = n*10 + (c-'0');
}
if(c != ' ' || n == 0)
return c;
cp = lexbuf; cp = lexbuf;
ep = lexbuf+sizeof(lexbuf)-5; ep = lexbuf+sizeof(lexbuf)-5;
for(;;) { for(;;) {
c = getr(); c = getr();
if(c == '\n' || c == EOF)
goto out;
if(c == ' ') if(c == ' ')
continue; continue;
if(c == '\n') if(c == ':')
break; break;
if(cp < ep)
*cp++ = c; *cp++ = c;
if(cp >= ep)
break;
} }
*cp = 0; *cp = 0;
// n--; // weve already seen the newline
if(n > 0) { n = 0;
for(;;) {
c = getr();
if(!isdigit(c))
break;
n = n*10 + (c-'0');
}
if(c != '\n' || n <= 0)
goto out;
// try to avoid allocating file name over and over // try to avoid allocating file name over and over
for(h=hist; h!=H; h=h->link) { for(h=hist; h!=H; h=h->link) {
if(h->name != nil && strcmp(h->name, lexbuf) == 0) { if(h->name != nil && strcmp(h->name, lexbuf) == 0) {
linehist(h->name, n, 0); linehist(h->name, n, 0);
return c; goto out;
} }
} }
linehist(strdup(lexbuf), n, 0); linehist(strdup(lexbuf), n, 0);
}
out:
return c; return c;
} }
......
...@@ -675,7 +675,7 @@ outer: ...@@ -675,7 +675,7 @@ outer:
// //
if t == MARK { if t == MARK {
if !lflag { if !lflag {
fmt.Fprintf(ftable, "\n//line %v %v\n", lineno, infile) fmt.Fprintf(ftable, "\n//line %v:%v\n", infile, lineno)
} }
for { for {
c := getrune(finput) c := getrune(finput)
...@@ -1032,7 +1032,7 @@ func chfind(t int, s string) int { ...@@ -1032,7 +1032,7 @@ func chfind(t int, s string) int {
func cpyunion() { func cpyunion() {
if !lflag { if !lflag {
fmt.Fprintf(ftable, "\n//line %v %v\n", lineno, infile) fmt.Fprintf(ftable, "\n//line %v:%v\n", infile, lineno)
} }
fmt.Fprintf(ftable, "type\tyySymType\tstruct") fmt.Fprintf(ftable, "type\tyySymType\tstruct")
...@@ -1075,7 +1075,7 @@ func cpycode() { ...@@ -1075,7 +1075,7 @@ func cpycode() {
lineno++ lineno++
} }
if !lflag { if !lflag {
fmt.Fprintf(ftable, "\n//line %v %v\n", lineno, infile) fmt.Fprintf(ftable, "\n//line %v:%v\n", infile, lineno)
} }
for c != EOF { for c != EOF {
if c == '%' { if c == '%' {
...@@ -1158,7 +1158,7 @@ func dumpprod(curprod []int, max int) { ...@@ -1158,7 +1158,7 @@ func dumpprod(curprod []int, max int) {
func cpyact(curprod []int, max int) { func cpyact(curprod []int, max int) {
if !lflag { if !lflag {
fmt.Fprintf(fcode, "\n//line %v %v\n", lineno, infile) fmt.Fprintf(fcode, "\n//line %v:%v\n", infile, lineno)
} }
lno := lineno lno := lineno
...@@ -2066,7 +2066,7 @@ nextk: ...@@ -2066,7 +2066,7 @@ nextk:
func output() { func output() {
var c, u, v int var c, u, v int
fmt.Fprintf(ftable, "\n//line 1 yacctab\n") fmt.Fprintf(ftable, "\n//line yacctab:1\n")
fmt.Fprintf(ftable, "var\tyyExca = []int {\n") fmt.Fprintf(ftable, "var\tyyExca = []int {\n")
noset := mkset() noset := mkset()
...@@ -2827,7 +2827,7 @@ func others() { ...@@ -2827,7 +2827,7 @@ func others() {
} }
// copy yaccpar // copy yaccpar
fmt.Fprintf(ftable, "\n//line 1 yaccpar\n") fmt.Fprintf(ftable, "\n//line yaccpar:1\n")
parts := strings.Split(yaccpar, "yyrun()", 2) parts := strings.Split(yaccpar, "yyrun()", 2)
fmt.Fprintf(ftable, "%v", parts[0]) fmt.Fprintf(ftable, "%v", parts[0])
......
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