Fix symbol nesting level not remembered for 2d+ arrays
This fixes a bug where defining a 2d+ array variable in different blocks at the same nesting level would trigger a symbol redefinition error. For example: main() { new x; if (x) { new a[10][11]; } else { new a[10][12]; // error 021: symbol already defined: "a" } } It turned out that the compiler defines a separate symbol for each of the array dimensions but it only was setting sym->compound for the first of them, causing delete_symbols() to not delete the remaining dimension symbols. Now it sets the compound field for all dimensions. Fixes #60
This commit is contained in:
parent
6e8bdc7438
commit
85f849ba08
@ -564,7 +564,7 @@ SC_FUNC symbol *finddepend(const symbol *parent);
|
|||||||
SC_FUNC symbol *addsym(const char *name,cell addr,int ident,int vclass,int tag,
|
SC_FUNC symbol *addsym(const char *name,cell addr,int ident,int vclass,int tag,
|
||||||
int usage);
|
int usage);
|
||||||
SC_FUNC symbol *addvariable(const char *name,cell addr,int ident,int vclass,int tag,
|
SC_FUNC symbol *addvariable(const char *name,cell addr,int ident,int vclass,int tag,
|
||||||
int dim[],int numdim,int idxtag[]);
|
int dim[],int numdim,int idxtag[],int nestlevel);
|
||||||
SC_FUNC int getlabel(void);
|
SC_FUNC int getlabel(void);
|
||||||
SC_FUNC char *itoh(ucell val);
|
SC_FUNC char *itoh(ucell val);
|
||||||
|
|
||||||
|
@ -2092,7 +2092,7 @@ static void declglb(char *firstname,int firsttag,int fpublic,int fstatic,int fst
|
|||||||
} /* if */
|
} /* if */
|
||||||
litidx=0;
|
litidx=0;
|
||||||
if (sym==NULL) { /* define only if not yet defined */
|
if (sym==NULL) { /* define only if not yet defined */
|
||||||
sym=addvariable(name,address,ident,sGLOBAL,tag,dim,numdim,idxtag);
|
sym=addvariable(name,address,ident,sGLOBAL,tag,dim,numdim,idxtag,nestlevel);
|
||||||
if (sc_curstates>0)
|
if (sc_curstates>0)
|
||||||
attachstatelist(sym,sc_curstates);
|
attachstatelist(sym,sc_curstates);
|
||||||
} else { /* if declared but not yet defined, adjust the variable's address */
|
} else { /* if declared but not yet defined, adjust the variable's address */
|
||||||
@ -2210,11 +2210,11 @@ static int declloc(int fstatic)
|
|||||||
while (litidx<cur_lit+size)
|
while (litidx<cur_lit+size)
|
||||||
litadd(0);
|
litadd(0);
|
||||||
sym=addvariable(name,(cur_lit+glb_declared)*sizeof(cell),ident,sSTATIC,
|
sym=addvariable(name,(cur_lit+glb_declared)*sizeof(cell),ident,sSTATIC,
|
||||||
tag,dim,numdim,idxtag);
|
tag,dim,numdim,idxtag,nestlevel);
|
||||||
} else {
|
} else {
|
||||||
declared+=(int)size; /* variables are put on stack, adjust "declared" */
|
declared+=(int)size; /* variables are put on stack, adjust "declared" */
|
||||||
sym=addvariable(name,-declared*sizeof(cell),ident,sLOCAL,tag,
|
sym=addvariable(name,-declared*sizeof(cell),ident,sLOCAL,
|
||||||
dim,numdim,idxtag);
|
tag,dim,numdim,idxtag,nestlevel);
|
||||||
if (ident==iVARIABLE) {
|
if (ident==iVARIABLE) {
|
||||||
assert(!staging);
|
assert(!staging);
|
||||||
stgset(TRUE); /* start stage-buffering */
|
stgset(TRUE); /* start stage-buffering */
|
||||||
@ -2231,7 +2231,6 @@ static int declloc(int fstatic)
|
|||||||
/* now that we have reserved memory for the variable, we can proceed
|
/* now that we have reserved memory for the variable, we can proceed
|
||||||
* to initialize it */
|
* to initialize it */
|
||||||
assert(sym!=NULL); /* we declared it, it must be there */
|
assert(sym!=NULL); /* we declared it, it must be there */
|
||||||
sym->compound=nestlevel; /* for multiple declaration/shadowing check */
|
|
||||||
if (fconst)
|
if (fconst)
|
||||||
sym->usage|=uCONST;
|
sym->usage|=uCONST;
|
||||||
if (!fstatic) { /* static variables already initialized */
|
if (!fstatic) { /* static variables already initialized */
|
||||||
@ -3455,7 +3454,7 @@ static void funcstub(int fnative)
|
|||||||
/* attach the array to the function symbol */
|
/* attach the array to the function symbol */
|
||||||
if (numdim>0) {
|
if (numdim>0) {
|
||||||
assert(sym!=NULL);
|
assert(sym!=NULL);
|
||||||
sub=addvariable(symbolname,0,iARRAY,sGLOBAL,tag,dim,numdim,idxtag);
|
sub=addvariable(symbolname,0,iARRAY,sGLOBAL,tag,dim,numdim,idxtag,nestlevel);
|
||||||
sub->parent=sym;
|
sub->parent=sym;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
@ -4017,7 +4016,7 @@ static void doarg(char *name,int ident,int offset,int tags[],int numtags,
|
|||||||
/* add details of type and address */
|
/* add details of type and address */
|
||||||
assert(numtags>0);
|
assert(numtags>0);
|
||||||
argsym=addvariable(name,offset,ident,sLOCAL,tags[0],
|
argsym=addvariable(name,offset,ident,sLOCAL,tags[0],
|
||||||
arg->dim,arg->numdim,arg->idxtag);
|
arg->dim,arg->numdim,arg->idxtag,nestlevel);
|
||||||
argsym->compound=0;
|
argsym->compound=0;
|
||||||
if (ident==iREFERENCE)
|
if (ident==iREFERENCE)
|
||||||
argsym->usage|=uREAD; /* because references are passed back */
|
argsym->usage|=uREAD; /* because references are passed back */
|
||||||
@ -5786,7 +5785,8 @@ static void doreturn(void)
|
|||||||
assert(curfunc->dim.arglist!=NULL);
|
assert(curfunc->dim.arglist!=NULL);
|
||||||
for (argcount=0; curfunc->dim.arglist[argcount].ident!=0; argcount++)
|
for (argcount=0; curfunc->dim.arglist[argcount].ident!=0; argcount++)
|
||||||
/* nothing */;
|
/* nothing */;
|
||||||
sub=addvariable(curfunc->name,(argcount+3)*sizeof(cell),iREFARRAY,sGLOBAL,curfunc->tag,dim,numdim,idxtag);
|
sub=addvariable(curfunc->name,(argcount+3)*sizeof(cell),iREFARRAY,sGLOBAL,
|
||||||
|
curfunc->tag,dim,numdim,idxtag,nestlevel);
|
||||||
sub->parent=curfunc;
|
sub->parent=curfunc;
|
||||||
} /* if */
|
} /* if */
|
||||||
/* get the hidden parameter, copy the array (the array is on the heap;
|
/* get the hidden parameter, copy the array (the array is on the heap;
|
||||||
|
@ -2991,7 +2991,7 @@ SC_FUNC symbol *addsym(const char *name,cell addr,int ident,int vclass,int tag,i
|
|||||||
}
|
}
|
||||||
|
|
||||||
SC_FUNC symbol *addvariable(const char *name,cell addr,int ident,int vclass,int tag,
|
SC_FUNC symbol *addvariable(const char *name,cell addr,int ident,int vclass,int tag,
|
||||||
int dim[],int numdim,int idxtag[])
|
int dim[],int numdim,int idxtag[],int nestlevel)
|
||||||
{
|
{
|
||||||
symbol *sym;
|
symbol *sym;
|
||||||
|
|
||||||
@ -3016,6 +3016,7 @@ SC_FUNC symbol *addvariable(const char *name,cell addr,int ident,int vclass,int
|
|||||||
top->dim.array.level=(short)(numdim-level-1);
|
top->dim.array.level=(short)(numdim-level-1);
|
||||||
top->x.tags.index=idxtag[level];
|
top->x.tags.index=idxtag[level];
|
||||||
top->parent=parent;
|
top->parent=parent;
|
||||||
|
top->compound=nestlevel; /* for multiple declaration/shadowing check */
|
||||||
parent=top;
|
parent=top;
|
||||||
if (level==0)
|
if (level==0)
|
||||||
sym=top;
|
sym=top;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user