]> Cypherpunks repositories - gostls13.git/commitdiff
more line numbers
authorKen Thompson <ken@golang.org>
Sun, 29 Jun 2008 00:27:39 +0000 (17:27 -0700)
committerKen Thompson <ken@golang.org>
Sun, 29 Jun 2008 00:27:39 +0000 (17:27 -0700)
SVN=125265

src/cmd/6g/cgen.c
src/cmd/6g/gen.c
src/cmd/6g/gsubr.c
src/cmd/gc/lex.c
src/cmd/gc/subr.c
src/cmd/gc/walk.c

index b8c49b4f928ff421a4eaa165966211bddf0e151d..1565d3259bd4c77ac56218a34aed2851eaab95bf 100644 (file)
@@ -7,7 +7,6 @@
 void
 cgen(Node *n, Node *res)
 {
-       long lno;
        Node *nl, *nr, *r;
        Node n1, n2;
        int a;
@@ -20,8 +19,6 @@ cgen(Node *n, Node *res)
        if(n == N || n->type == T)
                return;
 
-       lno = setlineno(n);
-
        if(res == N || res->type == T)
                fatal("cgen: res nil");
 
@@ -239,7 +236,7 @@ uop:        // unary
        goto ret;
 
 ret:
-       lineno = lno;
+       ;
 }
 
 void
@@ -249,7 +246,6 @@ agen(Node *n, Node *res)
        Node n1, n2, n3, tmp;
        ulong w;
        Type *t;
-       long lno;
 
        if(debug['g']) {
                dump("\nagen-res", res);
@@ -258,8 +254,6 @@ agen(Node *n, Node *res)
        if(n == N || n->type == T)
                return;
 
-       lno = setlineno(n);
-
        if(!isptr[res->type->etype])
                fatal("agen: not tptr: %T", res->type);
 
@@ -391,7 +385,7 @@ agen(Node *n, Node *res)
        }
 
 ret:
-       lineno = lno;
+       ;
 }
 
 vlong
@@ -416,7 +410,6 @@ igen(Node *n, Node *a, Node *res)
 void
 bgen(Node *n, int true, Prog *to)
 {
-       long lno;
        int et, a;
        Node *nl, *nr, *r;
        Node n1, n2, tmp;
@@ -425,11 +418,10 @@ bgen(Node *n, int true, Prog *to)
        if(debug['g']) {
                dump("\nbgen", n);
        }
+
        if(n == N)
                n = booltrue;
 
-       lno = setlineno(n);
-
        nl = n->left;
        nr = n->right;
 
@@ -580,16 +572,14 @@ bgen(Node *n, int true, Prog *to)
        goto ret;
 
 ret:
-       lineno = lno;
+       ;
 }
 
 void
 sgen(Node *n, Node *ns, ulong w)
 {
        Node nodl, nodr;
-       long c, lno;
-
-       lno = setlineno(n);
+       long c;
 
        if(debug['g']) {
                dump("\nsgen-res", ns);
@@ -627,5 +617,4 @@ sgen(Node *n, Node *ns, ulong w)
                gins(AMOVSB, N, N);     // MOVB *(SI)+,*(DI)+
        }
 
-       lineno = lno;
 }
index 9c1d3df9b9de3ba88311bc87ebc2984535684cb7..6b4dfde80ce240c2d1571f84247d61b3bd453874 100644 (file)
@@ -23,13 +23,11 @@ compile(Node *fn)
        Prog *ptxt;
        long lno;
 
-
        if(fn->nbody == N)
                return;
        lno = setlineno(fn);
 
        curfn = fn;
-       lineno = curfn->lineno; // for diagnostics
        dowidth(curfn->type);
 
        walk(curfn);
@@ -58,6 +56,7 @@ compile(Node *fn)
 //             gins(AGOK, N, N);
 
        pc->as = ARET;  // overwrite AEND
+       pc->lineno = lineno;
 
        // fill in final stack size
        ptxt->to.offset = rnd(stksize+maxarg, maxround);
@@ -442,7 +441,7 @@ swgen(Node *n)
        dflt = P;
        c1 = listfirst(&save1, &n->nbody);
        while(c1 != N) {
-               lineno = c1->lineno;    // for diagnostics
+               setlineno(c1);
                if(c1->op != OCASE) {
                        if(s0 == C && dflt == P)
                                yyerror("unreachable statements in a switch");
@@ -483,6 +482,8 @@ swgen(Node *n)
                c1 = listnext(&save1);
        }
 
+       lineno = lno;
+
        if(any)
                patch(gbranch(AJMP, T), breakpc);
 
@@ -492,6 +493,7 @@ swgen(Node *n)
        cgen(n->ntest, &tmp);
 
        for(s=s0; s!=C; s=s->slink) {
+               setlineno(s->scase);
                memset(&n1, 0, sizeof(n1));
                n1.op = OEQ;
                n1.left = &tmp;
@@ -534,9 +536,6 @@ cgen_callinter(Node *n, Node *res)
 {
        Node *i, *f;
        Node tmpi, nodo, nodr, nodsp;
-       long lno;
-
-       lno = setlineno(n);
 
        i = n->left;
        if(i->op != ODOTINTER)
@@ -580,20 +579,16 @@ cgen_callinter(Node *n, Node *res)
        regfree(&nodr);
 
        setmaxarg(n->left->type);
-       lineno = lno;
 }
 
 void
 cgen_callmeth(Node *n)
 {
        Node *l;
-       long lno;
 
        // generate a rewrite for method call
        // (p.f)(...) goes to (f)(p,...)
 
-       lno = setlineno(n);
-
        l = n->left;
        if(l->op != ODOTMETH)
                fatal("cgen_callmeth: not dotmethod: %N");
@@ -605,7 +600,6 @@ cgen_callmeth(Node *n)
        if(n->left->op == ONAME)
                n->left->class = PEXTERN;
        cgen_call(n);
-       lineno = lno;
 }
 
 void
@@ -613,13 +607,10 @@ cgen_call(Node *n)
 {
        Type *t;
        Node nod, afun;
-       long lno;
 
        if(n == N)
                return;
 
-       lno = setlineno(n);
-
        if(n->left->ullman >= UINF) {
                // if name involves a fn call
                // precompute the address of the fn
@@ -660,7 +651,7 @@ cgen_call(Node *n)
        gins(ACALL, N, n->left);
 
 ret:
-       lineno = lno;
+       ;
 }
 
 void
@@ -669,9 +660,6 @@ cgen_callret(Node *n, Node *res)
        Node nod;
        Type *fp, *t;
        Iter flist;
-       long lno;
-
-       lno = setlineno(n);
 
        t = n->left->type;
        if(t->etype == TPTR32 || t->etype == TPTR64)
@@ -685,12 +673,10 @@ cgen_callret(Node *n, Node *res)
        nod.op = OINDREG;
        nod.val.vval = D_SP;
        nod.addable = 1;
-       nod.lineno = lineno;
 
        nod.xoffset = fp->width;
        nod.type = fp->type;
        cgen_as(res, &nod, 0);
-       lineno = lno;
 }
 
 void
@@ -699,9 +685,6 @@ cgen_aret(Node *n, Node *res)
        Node nod1, nod2;
        Type *fp, *t;
        Iter flist;
-       long lno;
-
-       lno = setlineno(n);
 
        t = n->left->type;
        if(isptr[t->etype])
@@ -715,24 +698,18 @@ cgen_aret(Node *n, Node *res)
        nod1.op = OINDREG;
        nod1.val.vval = D_SP;
        nod1.addable = 1;
-       nod1.lineno = lineno;
 
        nod1.xoffset = fp->width;
        nod1.type = fp->type;
 
        gins(ALEAQ, &nod1, res);
-       lineno = lno;
 }
 
 void
 cgen_ret(Node *n)
 {
-       long lno;
-
-       lno = setlineno(n);
        gen(n->left);   // copy out args
        gins(ARET, N, N);
-       lineno = lno;
 }
 
 void
@@ -742,8 +719,6 @@ cgen_asop(Node *n)
        Node *nl, *nr;
        long lno;
 
-       lno = setlineno(n);
-
        nl = n->left;
        nr = n->right;
 
@@ -753,7 +728,7 @@ cgen_asop(Node *n)
                n2 = *n;
                n2.right = &n1;
                cgen_asop(&n2);
-               return;
+               goto ret;
        }
 
        if(nr->ullman > nl->ullman) {
@@ -778,7 +753,9 @@ cgen_asop(Node *n)
        regfree(&n1);
        regfree(&n2);
        regfree(&n4);
-       lineno = lno;
+
+ret:
+       ;
 }
 
 void
@@ -787,7 +764,6 @@ cgen_as(Node *nl, Node *nr, int op)
        Node nc, n1;
        Type *tl;
        ulong w, c;
-       long lno;
 
        if(nl == N)
                return;
@@ -796,8 +772,6 @@ cgen_as(Node *nl, Node *nr, int op)
        if(tl == T)
                return;
 
-       lno = setlineno(nl);
-
        if(nr == N || isnil(nr)) {
                if(isfat(tl)) {
                        /* clear a fat object */
@@ -891,7 +865,7 @@ cgen_as(Node *nl, Node *nr, int op)
        cgen(nr, nl);
 
 ret:
-       lineno = lno;
+       ;
 }
 
 int
@@ -916,9 +890,6 @@ cgen_div(int op, Node *nl, Node *nr, Node *res)
 {
        Node n1, n2, n3;
        int a, rax, rdx;
-       long lno;
-
-       lno = setlineno(nl);
 
        rax = reg[D_AX];
        rdx = reg[D_DX];
@@ -992,7 +963,7 @@ cgen_div(int op, Node *nl, Node *nr, Node *res)
        regfree(&n2);
 
 ret:
-       lineno = lno;
+       ;
 }
 
 /*
@@ -1005,9 +976,6 @@ cgen_shift(int op, Node *nl, Node *nr, Node *res)
 {
        Node n1, n2;
        int a, rcl;
-       long lno;
-
-       lno = setlineno(nl);
 
        a = optoas(op, nl->type);
 
@@ -1055,5 +1023,5 @@ cgen_shift(int op, Node *nl, Node *nr, Node *res)
        regfree(&n2);
 
 ret:
-       lineno = lno;
+       ;
 }
index 62774461554921cf37388e7b1c8bf1e97484e310..7b534467cf1cea6b5385591c5f0ff7203a3d5832 100644 (file)
@@ -52,11 +52,14 @@ prog(int as)
 
        clearp(pc);
 
+       if(lineno == 0) {
+               if(debug['K'])
+                       warn("prog: line 0");
+       }
+
        p->as = as;
        p->lineno = lineno;
        p->link = pc;
-if(lineno == 0)
-warn("line 0 %P\n", p);
        return p;
 }
 
@@ -216,7 +219,6 @@ nodreg(Node *n, Type *t, int r)
        memset(n, 0, sizeof(*n));
        n->op = OREGISTER;
        n->addable = 1;
-       n->lineno = lineno;
        ullmancalc(n);
        n->val.vval = r;
        n->type = t;
@@ -242,7 +244,6 @@ nodarg(Type *t, int fp)
        n->sym = t->sym;
        n->xoffset = t->width;
        n->addable = 1;
-       n->lineno = lineno;
 
        switch(fp) {
        case 0:         // output arg
@@ -270,7 +271,6 @@ nodconst(Node *n, Type *t, vlong v)
        memset(n, 0, sizeof(*n));
        n->op = OLITERAL;
        n->addable = 1;
-       n->lineno = lineno;
        ullmancalc(n);
        n->val.vval = v;
        n->val.ctype = CTINT;
@@ -1677,7 +1677,6 @@ tempname(Node *n, Type *t)
        n->etype = t->etype;
        n->class = PAUTO;
        n->addable = 1;
-       n->lineno = lineno;
        n->ullman = 0;
 
        dowidth(t);
index 74dbb1deb79b93bed6316e4dd32d7a0bbf159b4a..5aa12c328e9ace7df2037c839cf20f4a3eba1a27 100644 (file)
@@ -162,7 +162,8 @@ unimportfile(void)
        if(curio.bin != nil) {
                Bterm(curio.bin);
                curio.bin = nil;
-       }
+       } else
+               lineno--;       // re correct sys.6 line number
        curio = pushedio;
        pushedio.bin = nil;
        inimportsys = 0;
@@ -174,7 +175,8 @@ cannedimports(void)
        char *file;
 
        file = "sys.6";
-       linehist(file, 0);
+       lineno++;               // if sys.6 is included on line 1,
+       linehist(file, 0);      // the debugger gets confused
 
        pushedio = curio;
        curio.bin = nil;
index 6bae9833ac4355c126e6c6b3410140e7bd8101d1..2a2da5b7c34ffc49b70abc151b264c50685c6427 100644 (file)
@@ -102,8 +102,14 @@ setlineno(Node *n)
        long lno;
 
        lno = lineno;
-       if(n != N && n->op != ONAME)
+       if(n != N && n->op != ONAME) {
                lineno = n->lineno;
+               if(lineno == 0) {
+                       if(debug['K'])
+                               warn("setlineno: line 0");
+                       lineno = lno;
+               }
+       }
        return lno;
 }
 
index fc0ced4f540077599e449ed953d7488f32b6d377..258a087f73be5569d45a1d7afc6efde90c1a18b6 100644 (file)
@@ -26,8 +26,10 @@ walktype(Node *n, int top)
        Node *r, *l;
        Type *t;
        Sym *s;
-       long lno;
        int et, cl, cr;
+       long lno;
+
+       lno = setlineno(n);
 
        /*
         * walk the whole tree of the body of a function.
@@ -35,7 +37,6 @@ walktype(Node *n, int top)
         * compile-time constants are evaluated.
         */
 
-       lno = setlineno(n);
        if(top == Exxx || top == Eyyy) {
                dump("", n);
                fatal("walktype: bad top=%d", top);
@@ -44,6 +45,7 @@ walktype(Node *n, int top)
 loop:
        if(n == N)
                goto ret;
+
        setlineno(n);
 
        if(debug['w'] > 1 && top == Etop && n->op != OLIST)
@@ -765,6 +767,8 @@ walkswitch(Node *sw, Type*(*call)(Node*, Type*))
        Type *place;
        place = call(sw->ntest, T);
 
+       setlineno(sw);
+
        n = sw->nbody;
        if(n->op == OLIST)
                n = n->left;
@@ -776,9 +780,11 @@ walkswitch(Node *sw, Type*(*call)(Node*, Type*))
                        fatal("walkswitch: not case %O\n", n->op);
                for(c=n->left; c!=N; c=c->right) {
                        if(c->op != OLIST) {
+                               setlineno(c);
                                place = call(c, place);
                                break;
                        }
+                       setlineno(c);
                        place = call(c->left, place);
                }
        }
@@ -1216,9 +1222,7 @@ Node*
 stringop(Node *n, int top)
 {
        Node *r, *c, *on;
-       long lno, l;
-
-       lno = setlineno(n);
+       long l;
 
        switch(n->op) {
        default:
@@ -1310,7 +1314,6 @@ stringop(Node *n, int top)
        }
 
        walktype(r, top);
-       lineno = lno;
        return r;
 }
 
@@ -1366,14 +1369,11 @@ algtype(Type *t)
 Node*
 mapop(Node *n, int top)
 {
-       long lno;
        Node *r, *a;
        Type *t;
        Node *on;
        int alg1, alg2, cl, cr;
 
-       lno = setlineno(n);
-
 //dump("mapop", n);
 
        r = n;
@@ -1553,19 +1553,16 @@ mapop(Node *n, int top)
                break;
 
        }
-       lineno = lno;
        return r;
 
 shape:
        dump("shape", n);
        fatal("mapop: cl=%d cr=%d, %O", top, n->op);
-       lineno = lno;
        return N;
 
 nottop:
        dump("bad top", n);
        fatal("mapop: top=%d %O", top, n->op);
-       lineno = lno;
        return N;
 }