[qfcc] Allow symbol tables to have procedural symbols

If a symbol is not found in the table and a callback is provided, the
callback will be used to check for a valid procedural symbol before
moving on to the next table in the chain. This allows for both tight
scoping of the procedural symbols and caching.
This commit is contained in:
Bill Currie 2023-08-21 17:29:48 +09:00
parent dfb7862419
commit cb9a82e74c
2 changed files with 8 additions and 1 deletions

View file

@ -104,6 +104,8 @@ typedef struct symtab_s {
symbol_t **symtail; ///< keep chain in declaration order
struct defspace_s *space; ///< storage for vars in scope symtabs
struct class_s *class; ///< owning class if ivar scope
symbol_t *(*procsymbol) (const char *name, struct symtab_s *symtab);
void *procsymbol_data;
} symtab_t;
const char *symtype_str (sy_type_e type) __attribute__((const));

View file

@ -119,8 +119,13 @@ symtab_lookup (symtab_t *symtab, const char *name)
{
symbol_t *symbol;
do {
if ((symbol = Hash_Find (symtab->tab, name)))
if ((symbol = Hash_Find (symtab->tab, name))) {
return symbol;
}
if (symtab->procsymbol
&& (symbol = symtab->procsymbol (name, symtab))) {
return symbol;
}
symtab = symtab->parent;
} while (symtab);
return 0;