Allow symbols to be referenced from outside functions
This commit is contained in:
parent
ef49529b50
commit
65070b6563
@ -237,6 +237,8 @@ typedef struct s_symbol {
|
||||
#define uMISSING 0x080
|
||||
#define uFORWARD 0x100
|
||||
#define uNODESTRUCT 0x200 /* "no destruct(or)", not "node struct" */
|
||||
/* symbol is referenced "globally", e.g. via "__emit" or "#emit" used outside functions */
|
||||
#define uGLOBALREF 0x400
|
||||
/* uRETNONE is not stored in the "usage" field of a symbol. It is
|
||||
* used during parsing a function, to detect a mix of "return;" and
|
||||
* "return value;" in a few special cases.
|
||||
|
@ -4248,15 +4248,13 @@ static void doarg(char *name,int ident,int offset,int tags[],int numtags,
|
||||
} /* if */
|
||||
}
|
||||
|
||||
static int count_referrers(symbol *entry)
|
||||
static int has_referrers(symbol *entry)
|
||||
{
|
||||
int i,count;
|
||||
|
||||
count=0;
|
||||
int i;
|
||||
for (i=0; i<entry->numrefers; i++)
|
||||
if (entry->refer[i]!=NULL)
|
||||
count++;
|
||||
return count;
|
||||
return TRUE;
|
||||
return ((entry->usage & uGLOBALREF)!=0);
|
||||
}
|
||||
|
||||
#if !defined SC_LIGHT
|
||||
@ -4696,7 +4694,7 @@ static void reduce_referrers(symbol *root)
|
||||
if (sym->ident==iFUNCTN
|
||||
&& (sym->usage & uNATIVE)==0
|
||||
&& (sym->usage & uPUBLIC)==0 && strcmp(sym->name,uMAINFUNC)!=0 && strcmp(sym->name,uENTRYFUNC)!=0
|
||||
&& count_referrers(sym)==0)
|
||||
&& !has_referrers(sym))
|
||||
{
|
||||
sym->usage&=~(uREAD | uWRITTEN); /* erase usage bits if there is no referrer */
|
||||
/* find all symbols that are referred by this symbol */
|
||||
@ -4715,7 +4713,7 @@ static void reduce_referrers(symbol *root)
|
||||
} else if ((sym->ident==iVARIABLE || sym->ident==iARRAY)
|
||||
&& (sym->usage & uPUBLIC)==0
|
||||
&& sym->parent==NULL
|
||||
&& count_referrers(sym)==0)
|
||||
&& !has_referrers(sym))
|
||||
{
|
||||
sym->usage&=~(uREAD | uWRITTEN); /* erase usage bits if there is no referrer */
|
||||
} /* if */
|
||||
|
@ -3164,12 +3164,10 @@ SC_FUNC void markusage(symbol *sym,int usage)
|
||||
if ((usage & (uREAD | uWRITTEN))!=0) {
|
||||
/* only do this for global symbols */
|
||||
if (sym->vclass==sGLOBAL) {
|
||||
/* "curfunc" should always be valid, since statements may not occurs
|
||||
* outside functions; in the case of syntax errors, however, the
|
||||
* compiler may arrive through this function
|
||||
*/
|
||||
if (curfunc!=NULL)
|
||||
refer_symbol(sym,curfunc);
|
||||
else
|
||||
sym->usage |= uGLOBALREF;
|
||||
} /* if */
|
||||
} /* if */
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user