Alien-TinyCCx
view release on metacpan or search on metacpan
src/tccexsymtab.c view on Meta::CPAN
* part here is finding the local tokensym associated with the type.ref field.
* In principle this is only an issue if the type is a pointer, struct, enum,
* or function, but at this point checking non-null is sufficient. */
#define copy_ctype(to_type, from, symtab) do { \
int btype = from->type.t & VT_BTYPE; \
to_type.t = from->type.t; \
if (from->type.ref != NULL) { \
/* Get the from->type.ref's token and look for it here */ \
if (from->type.ref->v & SYM_FIRST_ANOM) { \
/* Anonymous symbol; just copy it. */ \
to_type.ref = copy_extended_sym(symtab, from->type.ref, \
/* ??? */ anon_sym++ | (from->type.ref->v & (SYM_STRUCT | SYM_FIELD))); \
} \
else if (from->type.ref->v == SYM_FIELD) { \
/* Anonymous symbol; just copy it. */ \
to_type.ref = copy_extended_sym(symtab, from->type.ref, SYM_FIELD); \
} \
else { \
/* Not anonymous: get the tokensym */ \
TokenSym* local_ts = get_local_tokensym_for_extended_tok(from->type.ref->v, symtab); \
if (btype == VT_STRUCT) to_type.ref = local_ts->sym_struct; \
else to_type.ref = local_ts->sym_identifier; \
} \
} \
else to_type.ref = NULL; \
} while(0)
Sym * copy_extended_sym (extended_symtab * symtab, Sym * from, int to_tok)
{
CType to_type;
Sym * s;
Sym * from_next;
Sym **psnext;
if (from == NULL) return NULL;
/* Copy the flags and CType from the "from" sym and push on the symbol stack */
to_tok |= from->v & (SYM_STRUCT | SYM_FIELD | SYM_FIRST_ANOM);
copy_ctype(to_type, from, symtab);
s = sym_push(to_tok, &to_type, from->r, from->c);
/* Copy the assembler label, if present */
s->asm_label = get_local_tok_for_extended_tok(from->asm_label, symtab);
/* All done unless we have a next field to copy as well. */
if (from->next == NULL) return s;
/* Copy the linked list started in the next field. Much of this code
* resembles copy_ctype, unfortunately. */
from_next = from->next;
psnext = &s->next;
while (from_next)
{
CType new_next_type;
int new_tok;
if (from_next->v & SYM_FIRST_ANOM)
{
/* Anonymous symbol; not attached to a TokenSym, so just copy it. */
*psnext = copy_extended_sym(symtab, from_next,
anon_sym++ | (from_next->v & (SYM_STRUCT | SYM_FIELD)));
/* copy_extended_sym is a recursive function call which copied the
* remaining elements of the next chain. Thus, we're done. */
return s;
}
else if (from_next->v == SYM_FIELD)
{
/* This is an anonymous symbol associated with pointers, arrays, and
* function declarations (tccgen.c in post_type). As above, just
* copy it. */
*psnext = copy_extended_sym(symtab, from_next, SYM_FIELD);
/* copy_extended_sym is a recursive function call which copied the
* remaining elements of the next chain. Thus, we're done. */
return s;
}
/* Push a copy of the Sym to the local symbol stack. */
copy_ctype(new_next_type, from_next, symtab);
new_tok = get_local_tok_for_extended_tok(from_next->v, symtab);
*psnext = sym_push(new_tok, &new_next_type, from_next->r, from_next->c);
/* Cycle the pointers. */
from_next = from_next->next;
psnext = &((*psnext)->next);
}
return s;
}
/*****************************************************************************/
/* Extended Symbol Table Caching */
/*****************************************************************************/
LIBTCCAPI int tcc_set_extended_symbol(extended_symtab * symtab, const char * name, const void * pointer)
{
TokenSym * ts = tcc_get_extended_tokensym(symtab, name);
if (ts == NULL) return 0; /* failed */
ts->hash_next = (void*)pointer;
/* XXX working here - update sym's type.t as well??? */
return 1; /* succeeded */
}
/* Write the total number of tokens that live on the end of this exsymtab, as
* well as tok_start. */
int exsymtab_serialize_init(extended_symtab * symtab, FILE * out_fh)
{
int to_write[3];
to_write[0] = symtab->tokenSym_last - symtab->tokenSym_list; /* N_tokens */
to_write[1] = symtab->tok_start;
to_write[2] = symtab->tok_start_offset;
if (fwrite(to_write, sizeof(int), 3, out_fh) == 3) return 1;
( run in 0.573 second using v1.01-cache-2.11-cpan-e1769b4cff6 )