Get rid of function finddepend()

This commit is contained in:
Stanislav Gromov 2020-11-10 19:54:56 +07:00
parent dfaff28897
commit 4b4319aa74
5 changed files with 27 additions and 48 deletions

View File

@ -740,7 +740,6 @@ SC_FUNC void rename_symbol(symbol *sym,const char *newname);
SC_FUNC symbol *findglb(const char *name,int filter);
SC_FUNC symbol *findloc(const char *name);
SC_FUNC symbol *findconst(const char *name,int *cmptag);
SC_FUNC symbol *finddepend(const symbol *parent);
SC_FUNC symbol *addsym(const char *name,cell addr,int ident,int vclass,int tag,
int usage);
SC_FUNC symbol *addvariable(const char *name,cell addr,int ident,int vclass,int tag,

View File

@ -4058,14 +4058,12 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc
&& (lvar=findloc(sym->dim.arglist[i].name))!=NULL) {
if ((sym->dim.arglist[i].usage & uWRITTEN)==0) {
/* check if the argument was written in this definition */
depend=lvar;
while (depend!=NULL) {
for (depend=lvar; depend!=NULL; depend=depend->child) {
if ((depend->usage & uWRITTEN)!=0) {
sym->dim.arglist[i].usage|=depend->usage & uWRITTEN;
break;
}
depend=finddepend(depend);
} /* while */
} /* if */
} /* for */
} /* if */
/* mark argument as written if it was written in another definition */
lvar->usage|=sym->dim.arglist[i].usage & uWRITTEN;
@ -5149,14 +5147,13 @@ static int testsymbols(symbol *root,int level,int testlabs,int testconst)
errorset(sSETPOS,-1);
} else if ((sym->usage & (uWRITTEN | uPUBLIC | uCONST))==0 && sym->ident==iREFARRAY) {
int warn = TRUE;
symbol* depend = finddepend(sym);
while (depend != NULL) {
if ((depend->usage & (uWRITTEN | uPUBLIC | uCONST)) != 0) {
warn = FALSE;
symbol *depend;
for (depend=sym->child; depend!=NULL; depend=depend->child) {
if ((depend->usage & (uWRITTEN | uPUBLIC | uCONST))!=0) {
warn=FALSE;
break;
}
depend = finddepend(depend);
} /* while */
} /* if */
} /* for */
if (warn) {
errorset(sSETPOS, sym->lnumber);
error(214, sym->name); /* make array argument "const" */
@ -5181,7 +5178,7 @@ static cell calc_array_datasize(symbol *sym, cell *offset)
assert(sym->ident==iARRAY || sym->ident==iREFARRAY);
length=sym->dim.array.length;
if (sym->dim.array.level > 0) {
cell sublength=calc_array_datasize(finddepend(sym),offset);
cell sublength=calc_array_datasize(sym->child,offset);
if (offset!=NULL)
*offset=length*(*offset+sizeof(cell));
if (sublength>0)
@ -7942,7 +7939,7 @@ static void doreturn(void)
error(225); /* unreachable code */
/* see if this function already has a sub type (an array attached) */
assert(curfunc!=NULL);
sub=finddepend(curfunc);
sub=curfunc->child;
assert(sub==NULL || sub->ident==iREFARRAY);
if ((rettype & uRETVALUE)!=0) {
int retarray=(ident==iARRAY || ident==iREFARRAY);
@ -7974,8 +7971,8 @@ static void doreturn(void)
if (sym->dim.array.length!=dim[numdim])
error(47); /* array sizes must match */
if (numdim<level) {
sym=finddepend(sym);
sub=finddepend(sub);
sym=sym->child;
sub=sub->child;
assert(sym!=NULL && sub!=NULL);
/* ^^^ both arrays have the same dimensions (this was checked
* earlier) so the dependend should always be found
@ -7996,7 +7993,7 @@ static void doreturn(void)
dim[numdim]=(int)sub->dim.array.length;
idxtag[numdim]=sub->x.tags.index;
if (numdim<level) {
sub=finddepend(sub);
sub=sub->child;
assert(sub!=NULL);
} /* if */
/* check that all dimensions are known */

View File

@ -3222,13 +3222,6 @@ static symbol *find_symbol(const symbol *root,const char *name,int fnumber,int a
return firstmatch;
}
static symbol *find_symbol_child(const symbol *root,const symbol *sym)
{
if (sym->child && sym->child->parent==sym)
return sym->child;
return NULL;
}
/* Adds "bywhom" to the list of referrers of "entry". Typically,
* bywhom will be the function that uses a variable or that calls
* the function.
@ -3445,16 +3438,6 @@ SC_FUNC symbol *findconst(const char *name,int *cmptag)
return sym;
}
SC_FUNC symbol *finddepend(const symbol *parent)
{
symbol *sym;
sym=find_symbol_child(&loctab,parent); /* try local symbols first */
if (sym==NULL) /* not found */
sym=find_symbol_child(&glbtab,parent);
return sym;
}
/* addsym
*
* Adds a symbol to the symbol table (either global or local variables,

View File

@ -817,7 +817,7 @@ SC_FUNC cell array_totalsize(symbol *sym)
assert(sym->ident==iARRAY || sym->ident==iREFARRAY);
length=sym->dim.array.length;
if (sym->dim.array.level > 0) {
cell sublength=array_totalsize(finddepend(sym));
cell sublength=array_totalsize(sym->child);
if (sublength>0)
length=length+length*sublength;
else
@ -832,7 +832,7 @@ static cell array_levelsize(symbol *sym,int level)
assert(sym->ident==iARRAY || sym->ident==iREFARRAY);
assert(level <= sym->dim.array.level);
while (level-- > 0) {
sym=finddepend(sym);
sym=sym->child;
assert(sym!=NULL);
} /* if */
return sym->dim.array.length;
@ -1062,8 +1062,8 @@ static int hier14(value *lval1)
*/
assert(exactmatch);
for (i=0; i<level; i++) {
sym1=finddepend(sym1);
sym2=finddepend(sym2);
sym1=sym1->child;
sym2=sym2->child;
assert(sym1!=NULL && sym2!=NULL);
/* ^^^ both arrays have the same dimensions (this was checked
* earlier) so the dependend should always be found
@ -1428,7 +1428,7 @@ static int hier2(value *lval)
numoffsets+=offsmul;
offsmul*=subsym->dim.array.length;
arrayidx=(arrayidx*subsym->dim.array.length)+val;
subsym=finddepend(subsym);
subsym=subsym->child;
}
needtoken(']');
} /* for */
@ -1438,7 +1438,7 @@ static int hier2(value *lval)
numoffsets+=offsmul;
offsmul*=subsym->dim.array.length;
arrayidx*=arrayidx*subsym->dim.array.length;
subsym=finddepend(subsym);
subsym=subsym->child;
} /* if */
lval->constval+=(numoffsets-1+arrayidx)*(cell)sizeof(cell);
ldconst(lval->constval,sPRI);
@ -1541,7 +1541,7 @@ static int hier2(value *lval)
} /* if */
needtoken(']');
if (subsym!=NULL)
subsym=finddepend(subsym);
subsym=subsym->child;
} /* for */
if (level>sym->dim.array.level+1)
error(28,sym->name); /* invalid subscript */
@ -1593,7 +1593,7 @@ static int hier2(value *lval)
} /* if */
needtoken(']');
if (subsym!=NULL)
subsym=finddepend(subsym);
subsym=subsym->child;
} /* for */
if (level>sym->dim.array.level+1)
error(28,sym->name); /* invalid subscript */
@ -1788,7 +1788,7 @@ restart:
/* parse the next index if this is not the lowest array dimension */
if (sym!=NULL && (sym->ident==iARRAY || sym->ident==iREFARRAY) && sym->dim.array.level>0) {
lval1->ident=iREFARRAY;
lval1->sym=finddepend(sym);
lval1->sym=sym->child;
assert(lval1->sym!=NULL);
assert(lval1->sym->dim.array.level==sym->dim.array.level-1);
cursym=lval1->sym;
@ -1875,7 +1875,7 @@ restart:
ob_add();
/* adjust the "value" structure and find the referenced array */
lval1->ident=iREFARRAY;
lval1->sym=finddepend(sym);
lval1->sym=sym->child;
assert(lval1->sym!=NULL);
assert(lval1->sym->dim.array.level==sym->dim.array.level-1);
cursym=lval1->sym;
@ -2195,7 +2195,7 @@ static int nesting=0;
return;
}
/* check whether this is a function that returns an array */
symret=finddepend(sym);
symret=sym->child;
assert(symret==NULL || symret->ident==iREFARRAY);
if (symret!=NULL) {
int retsize;
@ -2451,7 +2451,7 @@ static int nesting=0;
else
check_index_tagmismatch(sym->name,arg[argidx].idxtag[level],sym->x.tags.index,TRUE,0);
append_constval(&arrayszlst,arg[argidx].name,sym->dim.array.length,level);
sym=finddepend(sym);
sym=sym->child;
assert(sym!=NULL);
level++;
} /* if */

View File

@ -482,7 +482,7 @@ SC_FUNC stringlist *insert_dbgsymbol(symbol *sym)
#endif
symbol *sub;
strcat(string," [ ");
for (sub=sym; sub!=NULL; sub=finddepend(sub)) {
for (sub=sym; sub!=NULL; sub=sub->child) {
assert(sub->dim.array.level==count--);
sprintf(string+strlen(string),"%x:%x ",sub->x.tags.index,sub->dim.array.length);
} /* for */