Allow symbols to be referenced from outside functions

This commit is contained in:
Daniel_Cortez 2019-09-13 19:33:07 +07:00
parent ef49529b50
commit 65070b6563
3 changed files with 10 additions and 12 deletions

View File

@ -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.

View File

@ -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 */

View File

@ -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 */
}