From: Ian Romanick Date: Fri, 19 Mar 2010 22:32:57 +0000 (-0700) Subject: Add function to determine the scope where a variable is declared X-Git-Tag: 062012170305~10660^2~625^2~628 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=95517faf6931765408c697e3d60e4469616ad1d3;p=profile%2Fivi%2Fmesa.git Add function to determine the scope where a variable is declared --- diff --git a/symbol_table.c b/symbol_table.c index 4e043d1..5d748f4 100644 --- a/symbol_table.c +++ b/symbol_table.c @@ -269,6 +269,36 @@ _mesa_symbol_table_iterator_next(struct _mesa_symbol_table_iterator *iter) } +/** + * Determine the scope "distance" of a symbol from the current scope + * + * \return + * A non-negative number for the number of scopes between the current scope + * and the scope where a symbol was defined. A value of zero means the current + * scope. A negative number if the symbol does not exist. + */ +int +_mesa_symbol_table_symbol_scope(struct _mesa_symbol_table *table, + int name_space, const char *name) +{ + struct symbol_header *const hdr = find_symbol(table, name); + struct symbol *sym; + + if (hdr != NULL) { + for (sym = hdr->symbols; sym != NULL; sym = sym->next_with_same_name) { + assert(sym->hdr == hdr); + + if ((name_space == -1) || (sym->name_space == name_space)) { + assert(sym->depth <= table->depth); + return sym->depth - table->depth; + } + } + } + + return -1; +} + + void * _mesa_symbol_table_find_symbol(struct _mesa_symbol_table *table, int name_space, const char *name) diff --git a/symbol_table.h b/symbol_table.h index d3f65e3..3a9994c 100644 --- a/symbol_table.h +++ b/symbol_table.h @@ -37,6 +37,9 @@ extern void _mesa_symbol_table_pop_scope(struct _mesa_symbol_table *table); extern int _mesa_symbol_table_add_symbol(struct _mesa_symbol_table *symtab, int name_space, const char *name, void *declaration); +extern int _mesa_symbol_table_symbol_scope(struct _mesa_symbol_table *table, + int name_space, const char *name); + extern void *_mesa_symbol_table_find_symbol( struct _mesa_symbol_table *symtab, int name_space, const char *name);