Commit 59914723 authored by Russ Cox's avatar Russ Cox

declared and not used error, but disabled.

fix some bugs involving _.

R=ken
OCL=34621
CL=34621
parent f3a33bca
...@@ -26,6 +26,7 @@ allocparams(void) ...@@ -26,6 +26,7 @@ allocparams(void)
Node *n; Node *n;
uint32 w; uint32 w;
Sym *s; Sym *s;
int lno;
if(stksize < 0) if(stksize < 0)
fatal("allocparams not during code generation"); fatal("allocparams not during code generation");
...@@ -35,6 +36,7 @@ allocparams(void) ...@@ -35,6 +36,7 @@ allocparams(void)
* slots for all automatics. * slots for all automatics.
* allocated starting at -w down. * allocated starting at -w down.
*/ */
lno = lineno;
for(l=curfn->dcl; l; l=l->next) { for(l=curfn->dcl; l; l=l->next) {
n = l->n; n = l->n;
if(n->op == ONAME && n->class == PHEAP-1) { if(n->op == ONAME && n->class == PHEAP-1) {
...@@ -46,19 +48,21 @@ allocparams(void) ...@@ -46,19 +48,21 @@ allocparams(void)
} }
if(n->op != ONAME || n->class != PAUTO) if(n->op != ONAME || n->class != PAUTO)
continue; continue;
typecheck(&n, Erv); // only needed for unused variables lineno = n->lineno;
typecheck(&n, Erv | Easgn); // only needed for unused variables
if(n->type == T) if(n->type == T)
continue; continue;
// if(!n->used && n->sym->name[0] != '&')
// yyerror("%S declared and not used", n->sym);
dowidth(n->type); dowidth(n->type);
w = n->type->width; w = n->type->width;
if(n->class & PHEAP)
w = widthptr;
if(w >= 100000000) if(w >= 100000000)
fatal("bad width"); fatal("bad width");
stksize += w; stksize += w;
stksize = rnd(stksize, w); stksize = rnd(stksize, w);
n->xoffset = -stksize; n->xoffset = -stksize;
} }
lineno = lno;
} }
void void
......
...@@ -201,6 +201,7 @@ struct Node ...@@ -201,6 +201,7 @@ struct Node
uchar local; uchar local;
uchar initorder; uchar initorder;
uchar dodata; // compile literal assignment as data statement uchar dodata; // compile literal assignment as data statement
uchar used;
// most nodes // most nodes
Node* left; Node* left;
......
...@@ -456,6 +456,7 @@ case: ...@@ -456,6 +456,7 @@ case:
if(typesw != N && typesw->right != N && (n=typesw->right->left) != N) { if(typesw != N && typesw->right != N && (n=typesw->right->left) != N) {
// type switch - declare variable // type switch - declare variable
n = newname(n->sym); n = newname(n->sym);
n->used = 1; // TODO(rsc): better job here
declare(n, dclcontext); declare(n, dclcontext);
$$->nname = n; $$->nname = n;
} }
...@@ -488,6 +489,7 @@ case: ...@@ -488,6 +489,7 @@ case:
if(typesw != N && typesw->right != N && (n=typesw->right->left) != N) { if(typesw != N && typesw->right != N && (n=typesw->right->left) != N) {
// type switch - declare variable // type switch - declare variable
n = newname(n->sym); n = newname(n->sym);
n->used = 1; // TODO(rsc): better job here
declare(n, dclcontext); declare(n, dclcontext);
$$->nname = n; $$->nname = n;
} }
......
...@@ -112,9 +112,13 @@ reswitch: ...@@ -112,9 +112,13 @@ reswitch:
ok |= Ecall; ok |= Ecall;
goto ret; goto ret;
} }
if(isblank(n) && !(top & Easgn)) { if(!(top & Easgn)) {
yyerror("cannot use _ as value"); // not a write to the variable
goto error; if(isblank(n)) {
yyerror("cannot use _ as value");
goto error;
}
n->used = 1;
} }
ok |= Erv; ok |= Erv;
goto ret; goto ret;
......
...@@ -1771,6 +1771,9 @@ convas(Node *n, NodeList **init) ...@@ -1771,6 +1771,9 @@ convas(Node *n, NodeList **init)
if(lt == T || rt == T) if(lt == T || rt == T)
goto out; goto out;
if(isblank(n->left))
goto out;
if(n->left->op == OINDEXMAP) { if(n->left->op == OINDEXMAP) {
n = mkcall1(mapfn("mapassign1", n->left->left->type), T, init, n = mkcall1(mapfn("mapassign1", n->left->left->type), T, init,
n->left->left, n->left->right, n->right); n->left->left, n->left->right, n->right);
......
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