Reformat struct "assigninfo" into "symstate", so it could be used to store multiple symbol usage flags
This commit is contained in:
parent
355b324df4
commit
0b721bfa1c
@ -302,15 +302,15 @@ typedef struct s_valuepair {
|
|||||||
long second;
|
long second;
|
||||||
} valuepair;
|
} valuepair;
|
||||||
|
|
||||||
/* struct "assigninfo" is used to synchronize the status of assignments that
|
/* struct "symstate" is used to:
|
||||||
* were made in multiple "if" and "switch" branches, so the compiler could
|
* * synchronize the status of assignments between all "if" branches or "switch"
|
||||||
* detect unused assignments in all of those branches, not only the last one */
|
* cases, so the compiler could detect unused assignments in all of those
|
||||||
|
* branches/cases, not only in the last one */
|
||||||
typedef struct s_assigninfo {
|
typedef struct s_assigninfo {
|
||||||
int unused; /* true if the variable has an unused value assigned to it
|
|
||||||
* in one of the branches" */
|
|
||||||
int lnumber; /* line number of the first unused assignment made in one of
|
int lnumber; /* line number of the first unused assignment made in one of
|
||||||
* the branches (used for error messages) */
|
* the branches (used for error messages) */
|
||||||
} assigninfo;
|
short usage; /* usage flags to memoize (currently only uASSIGNED) */
|
||||||
|
} symstate;
|
||||||
|
|
||||||
/* macros for code generation */
|
/* macros for code generation */
|
||||||
#define opcodes(n) ((n)*sizeof(cell)) /* opcode size */
|
#define opcodes(n) ((n)*sizeof(cell)) /* opcode size */
|
||||||
@ -735,8 +735,8 @@ SC_FUNC int refer_symbol(symbol *entry,symbol *bywhom);
|
|||||||
SC_FUNC void markusage(symbol *sym,int usage);
|
SC_FUNC void markusage(symbol *sym,int usage);
|
||||||
SC_FUNC void markinitialized(symbol *sym,int assignment);
|
SC_FUNC void markinitialized(symbol *sym,int assignment);
|
||||||
SC_FUNC void clearassignments(int fromlevel);
|
SC_FUNC void clearassignments(int fromlevel);
|
||||||
SC_FUNC void memoizeassignments(int fromlevel,assigninfo **assignments);
|
SC_FUNC void memoizeassignments(int fromlevel,symstate **assignments);
|
||||||
SC_FUNC void restoreassignments(int fromlevel,assigninfo *assignments);
|
SC_FUNC void restoreassignments(int fromlevel,symstate *assignments);
|
||||||
SC_FUNC void rename_symbol(symbol *sym,const char *newname);
|
SC_FUNC void rename_symbol(symbol *sym,const char *newname);
|
||||||
SC_FUNC symbol *findglb(const char *name,int filter);
|
SC_FUNC symbol *findglb(const char *name,int filter);
|
||||||
SC_FUNC symbol *findloc(const char *name);
|
SC_FUNC symbol *findloc(const char *name);
|
||||||
|
@ -5884,7 +5884,7 @@ static int doif(void)
|
|||||||
int ifindent;
|
int ifindent;
|
||||||
int lastst_true;
|
int lastst_true;
|
||||||
int returnst=tIF;
|
int returnst=tIF;
|
||||||
assigninfo *assignments=NULL;
|
symstate *assignments=NULL;
|
||||||
|
|
||||||
lastst=0; /* reset the last statement */
|
lastst=0; /* reset the last statement */
|
||||||
ifindent=stmtindent; /* save the indent of the "if" instruction */
|
ifindent=stmtindent; /* save the indent of the "if" instruction */
|
||||||
@ -6104,7 +6104,7 @@ static int doswitch(void)
|
|||||||
constvalue_root caselist = { NULL, NULL}; /* case list starts empty */
|
constvalue_root caselist = { NULL, NULL}; /* case list starts empty */
|
||||||
constvalue *cse,*csp,*newval;
|
constvalue *cse,*csp,*newval;
|
||||||
char labelname[sNAMEMAX+1];
|
char labelname[sNAMEMAX+1];
|
||||||
assigninfo *assignments=NULL;
|
symstate *assignments=NULL;
|
||||||
|
|
||||||
endtok= matchtoken('(') ? ')' : tDO;
|
endtok= matchtoken('(') ? ')' : tDO;
|
||||||
ident=doexpr(TRUE,FALSE,FALSE,FALSE,&swtag,NULL,TRUE,NULL); /* evaluate switch expression */
|
ident=doexpr(TRUE,FALSE,FALSE,FALSE,&swtag,NULL,TRUE,NULL); /* evaluate switch expression */
|
||||||
|
@ -3350,7 +3350,7 @@ SC_FUNC void clearassignments(int fromlevel)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* memoizes all assignments done on the specified compound level and higher */
|
/* memoizes all assignments done on the specified compound level and higher */
|
||||||
SC_FUNC void memoizeassignments(int fromlevel,assigninfo **assignments)
|
SC_FUNC void memoizeassignments(int fromlevel,symstate **assignments)
|
||||||
{
|
{
|
||||||
symbol *sym;
|
symbol *sym;
|
||||||
int num;
|
int num;
|
||||||
@ -3370,7 +3370,7 @@ SC_FUNC void memoizeassignments(int fromlevel,assigninfo **assignments)
|
|||||||
/* if there are no variables, then we have an early exit */
|
/* if there are no variables, then we have an early exit */
|
||||||
if (num==0)
|
if (num==0)
|
||||||
return;
|
return;
|
||||||
*assignments=(assigninfo *)calloc((size_t)num,sizeof(assigninfo));
|
*assignments=(symstate *)calloc((size_t)num,sizeof(symstate));
|
||||||
if (*assignments==NULL)
|
if (*assignments==NULL)
|
||||||
error(103); /* insufficient memory */
|
error(103); /* insufficient memory */
|
||||||
} /* if */
|
} /* if */
|
||||||
@ -3385,16 +3385,17 @@ SC_FUNC void memoizeassignments(int fromlevel,assigninfo **assignments)
|
|||||||
sym->usage &= ~uASSIGNED;
|
sym->usage &= ~uASSIGNED;
|
||||||
/* memoize the assignment only if there was no other unused assignment
|
/* memoize the assignment only if there was no other unused assignment
|
||||||
* in any other "if" or "switch" branch */
|
* in any other "if" or "switch" branch */
|
||||||
if ((*assignments)[num].unused==FALSE) {
|
assert_static(sizeof(sym->usage)==sizeof((*assignments)->usage));
|
||||||
(*assignments)[num].unused=TRUE;
|
if (((*assignments)[num].usage & uASSIGNED)==0) {
|
||||||
(*assignments)[num].lnumber=sym->lnumber;
|
(*assignments)[num].lnumber=sym->lnumber;
|
||||||
|
(*assignments)[num].usage |= uASSIGNED;
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* for */
|
} /* for */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* restores all memoized assignments */
|
/* restores all memoized assignments */
|
||||||
SC_FUNC void restoreassignments(int fromlevel,assigninfo *assignments)
|
SC_FUNC void restoreassignments(int fromlevel,symstate *assignments)
|
||||||
{
|
{
|
||||||
symbol *sym;
|
symbol *sym;
|
||||||
int num;
|
int num;
|
||||||
@ -3402,7 +3403,7 @@ SC_FUNC void restoreassignments(int fromlevel,assigninfo *assignments)
|
|||||||
sym=&loctab;
|
sym=&loctab;
|
||||||
while ((sym=sym->next)!=NULL && sym->ident==iLABEL) {} /* skip labels */
|
while ((sym=sym->next)!=NULL && sym->ident==iLABEL) {} /* skip labels */
|
||||||
for (num=0; sym!=NULL; num++,sym=sym->next) {
|
for (num=0; sym!=NULL; num++,sym=sym->next) {
|
||||||
if (assignments!=NULL && assignments[num].unused) {
|
if (assignments!=NULL && (assignments[num].usage & uASSIGNED)!=0) {
|
||||||
sym->usage |= uASSIGNED;
|
sym->usage |= uASSIGNED;
|
||||||
sym->lnumber=assignments[num].lnumber;
|
sym->lnumber=assignments[num].lnumber;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user