store symbol children for faster lookup

This commit is contained in:
Alex Martin 2017-10-15 12:55:51 +02:00
parent 2d8791a0f2
commit 73d4934d61
3 changed files with 11 additions and 6 deletions

View File

@ -131,6 +131,7 @@ typedef struct s_constvalue {
typedef struct s_symbol {
struct s_symbol *next;
struct s_symbol *parent; /* hierarchical types (multi-dimensional arrays) */
struct s_symbol *child;
char name[sNAMEMAX+1];
cell addr; /* address or offset (or value for constant, index for native function) */
cell codeaddr; /* address (in the code segment) where the symbol declaration starts */

View File

@ -2929,6 +2929,8 @@ static void decl_enum(int vclass,int fstatic)
sym->dim.array.length=size;
sym->dim.array.level=0;
sym->parent=enumsym;
if (enumsym)
enumsym->child=sym;
if (fstatic)
sym->fnumber=filenum;
@ -3522,6 +3524,8 @@ static void funcstub(int fnative)
assert(sym!=NULL);
sub=addvariable(symbolname,0,iARRAY,sGLOBAL,tag,dim,numdim,idxtag,0);
sub->parent=sym;
if (sym)
sym->child=sub;
} /* if */
litidx=0; /* clear the literal pool */
@ -6513,6 +6517,8 @@ static void doreturn(void)
sub=addvariable(curfunc->name,(argcount+3)*sizeof(cell),iREFARRAY,sGLOBAL,
curfunc->tag,dim,numdim,idxtag,0);
sub->parent=curfunc;
if (curfunc)
curfunc->child=sub;
} /* if */
/* get the hidden parameter, copy the array (the array is on the heap;
* it stays on the heap for the moment, and it is removed -usually- at

View File

@ -2855,12 +2855,8 @@ static symbol *find_symbol(const symbol *root,const char *name,int fnumber,int a
static symbol *find_symbol_child(const symbol *root,const symbol *sym)
{
symbol *ptr=root->next;
while (ptr!=NULL) {
if (ptr->parent==sym)
return ptr;
ptr=ptr->next;
} /* while */
if (sym->child && sym->child->parent == sym)
return sym->child;
return NULL;
}
@ -3062,6 +3058,8 @@ SC_FUNC symbol *addvariable(const char *name,cell addr,int ident,int vclass,int
top->dim.array.level=(short)(numdim-level-1);
top->x.tags.index=idxtag[level];
top->parent=parent;
if (parent)
parent->child=top;
if (vclass==sLOCAL || vclass==sSTATIC) {
top->compound=compound; /* for multiple declaration/shadowing check */
} /* if */