Alien-TinyCCx
view release on metacpan or search on metacpan
src/tccgen.c view on Meta::CPAN
/* find a symbol and return its associated structure. 's' is the top
of the symbol stack */
ST_FUNC Sym *sym_find2(Sym *s, int v)
{
/* #ifdef CONFIG_TCC_EXSYMTAB */
v &= ~SYM_EXTENDED;
/* #endif */
while (s) {
/* #ifdef CONFIG_TCC_EXSYMTAB */
if ((s->v & ~SYM_EXTENDED) == v)
/* #else
if (s->v == v)
#endif */
return s;
else if (s->v == -1)
return NULL;
s = s->prev;
}
return NULL;
}
/* structure lookup */
ST_INLN Sym *struct_find(int v)
{
/* #ifdef CONFIG_TCC_EXSYMTAB */
v &= ~SYM_EXTENDED;
/* #endif */
v -= TOK_IDENT;
if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT))
return NULL;
return table_ident[v]->sym_struct;
}
/* find an identifier */
ST_INLN Sym *sym_find(int v)
{
/* #ifdef CONFIG_TCC_EXSYMTAB */
int is_extended = v & SYM_EXTENDED;
v &= ~SYM_EXTENDED;
/* #endif */
v -= TOK_IDENT;
/* Does not exist in our table! The best we can do is return null. XXX Maybe
* should warn if this happens with an extended symbol, since that would be
* a sign of an inconsistent internal state. */
if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT))
return NULL;
/* #ifdef CONFIG_TCC_EXSYMTAB */
/* If this is an extended symbol table reference, then we need to make sure
* that the extended symbol reference callback gets fired, but only once.
* We'll modify the TokenSym's tok field and remove the flag if the callback
* has been fired, so check if the TokenSym's tok field has the flag.
*/
if (is_extended && (table_ident[v]->tok & SYM_EXTENDED)) {
TokenSym *ts = table_ident[v];
/* Clear the extended symbol flag in the TokenSym. */
ts->tok &= ~SYM_EXTENDED;
/* XXX If we don't have the callback function... throw error? */
if ((ts->sym_identifier != NULL)
&& (ts->sym_identifier->type.t & VT_EXTERN)
&& (tcc_state->symtab_sym_used_callback != NULL))
{
/* Call the function, passing the symbol name. */
tcc_state->symtab_sym_used_callback(ts->str, ts->len,
tcc_state->symtab_callback_data);
}
}
/* #endif */
return table_ident[v]->sym_identifier;
}
/* push a given symbol on the symbol stack */
ST_FUNC Sym *sym_push(int v, CType *type, int r, int c)
{
Sym *s, **ps;
TokenSym *ts;
if (local_stack)
ps = &local_stack;
else {
/* #ifdef CONFIG_TCC_EXSYMTAB */
/* Global symbol stack. This is OK for the local symbol stack, but don't allow
* this for symbols that are in the extended symbol stack. There seem to be
* some issues associated with copying *all* TokenSyms, so this needs to be
* ironed out. For now, I'm removing the check. */
//
// if (v & SYM_EXTENDED) {
// tcc_error("Cannot use name '%s' as a global variable, it is already in the "
// "extended symbol table.", get_tok_str(v, 0));
// }
/* #endif */
ps = &global_stack;
}
/* #ifdef CONFIG_TCC_EXSYMTAB */
v &= ~SYM_EXTENDED;
/* #endif */
s = sym_push2(ps, v, type->t, c);
s->type.ref = type->ref;
s->r = r;
/* don't record fields or anonymous symbols */
/* XXX: simplify */
if (!(v & SYM_FIELD) && (v & ~SYM_STRUCT) < SYM_FIRST_ANOM) {
/* record symbol in token array */
ts = table_ident[(v & ~SYM_STRUCT) - TOK_IDENT];
if (v & SYM_STRUCT)
ps = &ts->sym_struct;
else
ps = &ts->sym_identifier;
s->prev_tok = *ps;
*ps = s;
s->scope = local_scope;
if (s->prev_tok && s->prev_tok->scope == s->scope)
tcc_error("redeclaration of '%s'",
get_tok_str(v & ~SYM_STRUCT, NULL));
}
return s;
}
( run in 0.552 second using v1.01-cache-2.11-cpan-f6376fbd888 )