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 uMISSING 0x080
|
||||||
#define uFORWARD 0x100
|
#define uFORWARD 0x100
|
||||||
#define uNODESTRUCT 0x200 /* "no destruct(or)", not "node struct" */
|
#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
|
/* 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
|
* used during parsing a function, to detect a mix of "return;" and
|
||||||
* "return value;" in a few special cases.
|
* "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 */
|
} /* if */
|
||||||
}
|
}
|
||||||
|
|
||||||
static int count_referrers(symbol *entry)
|
static int has_referrers(symbol *entry)
|
||||||
{
|
{
|
||||||
int i,count;
|
int i;
|
||||||
|
|
||||||
count=0;
|
|
||||||
for (i=0; i<entry->numrefers; i++)
|
for (i=0; i<entry->numrefers; i++)
|
||||||
if (entry->refer[i]!=NULL)
|
if (entry->refer[i]!=NULL)
|
||||||
count++;
|
return TRUE;
|
||||||
return count;
|
return ((entry->usage & uGLOBALREF)!=0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined SC_LIGHT
|
#if !defined SC_LIGHT
|
||||||
@ -4696,7 +4694,7 @@ static void reduce_referrers(symbol *root)
|
|||||||
if (sym->ident==iFUNCTN
|
if (sym->ident==iFUNCTN
|
||||||
&& (sym->usage & uNATIVE)==0
|
&& (sym->usage & uNATIVE)==0
|
||||||
&& (sym->usage & uPUBLIC)==0 && strcmp(sym->name,uMAINFUNC)!=0 && strcmp(sym->name,uENTRYFUNC)!=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 */
|
sym->usage&=~(uREAD | uWRITTEN); /* erase usage bits if there is no referrer */
|
||||||
/* find all symbols that are referred by this symbol */
|
/* 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)
|
} else if ((sym->ident==iVARIABLE || sym->ident==iARRAY)
|
||||||
&& (sym->usage & uPUBLIC)==0
|
&& (sym->usage & uPUBLIC)==0
|
||||||
&& sym->parent==NULL
|
&& sym->parent==NULL
|
||||||
&& count_referrers(sym)==0)
|
&& !has_referrers(sym))
|
||||||
{
|
{
|
||||||
sym->usage&=~(uREAD | uWRITTEN); /* erase usage bits if there is no referrer */
|
sym->usage&=~(uREAD | uWRITTEN); /* erase usage bits if there is no referrer */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
@ -3164,12 +3164,10 @@ SC_FUNC void markusage(symbol *sym,int usage)
|
|||||||
if ((usage & (uREAD | uWRITTEN))!=0) {
|
if ((usage & (uREAD | uWRITTEN))!=0) {
|
||||||
/* only do this for global symbols */
|
/* only do this for global symbols */
|
||||||
if (sym->vclass==sGLOBAL) {
|
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)
|
if (curfunc!=NULL)
|
||||||
refer_symbol(sym,curfunc);
|
refer_symbol(sym,curfunc);
|
||||||
|
else
|
||||||
|
sym->usage |= uGLOBALREF;
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user