]> Cypherpunks repositories - gostls13.git/commitdiff
use correct lineno in nod even if yacc has looked ahead.
authorRuss Cox <rsc@golang.org>
Tue, 18 Nov 2008 17:32:05 +0000 (09:32 -0800)
committerRuss Cox <rsc@golang.org>
Tue, 18 Nov 2008 17:32:05 +0000 (09:32 -0800)
makes lineno correct for statements without semicolons.

R=ken
OCL=19454
CL=19454

src/cmd/gc/go.h
src/cmd/gc/lex.c
src/cmd/gc/subr.c

index 54c47d0c51f952255950bc31d7dd2d59498d3d97..c5e35a1e481ba4447e9b572e50e338ada4420ef8 100644 (file)
@@ -419,6 +419,7 @@ EXTERN      Dlist   dotlist[10];    // size is max depth of embeddeds
 EXTERN Io      curio;
 EXTERN Io      pushedio;
 EXTERN int32   lineno;
+EXTERN int32   prevlineno;
 EXTERN char*   pathname;
 EXTERN Hist*   hist;
 EXTERN Hist*   ehist;
index 99a8d7914fe91624d1549de0fe4844ff867f0a25..d305fb65ae946a575f7f244158cc196ee6df9d36 100644 (file)
@@ -300,6 +300,8 @@ yylex(void)
        int escflag;
        Sym *s;
 
+       prevlineno = lineno;
+
 l0:
        c = getc();
        if(isspace(c))
index e1bdde5f588e42c09a000379a175755dec587178..851f17404f6128eb54c5ec9a35663e36dffe6f9d 100644 (file)
@@ -269,6 +269,7 @@ dcl(void)
        return d;
 }
 
+extern int yychar;
 Node*
 nod(int op, Node *nleft, Node *nright)
 {
@@ -278,7 +279,10 @@ nod(int op, Node *nleft, Node *nright)
        n->op = op;
        n->left = nleft;
        n->right = nright;
-       n->lineno = lineno;
+       if(yychar <= 0) // no lookahead
+               n->lineno = lineno;
+       else
+               n->lineno = prevlineno;
        return n;
 }