int nesting_level = 1;
- /* What level do we consider to be file scope? This is normally 1,
- but can get pushed up by DW_TAG_namespace entries. */
+ /* We only want to read in symbols corresponding to variables or
+ other similar objects that are global or static. Normally, these
+ are all children of the DW_TAG_compile_unit die, so are all at
+ level 1. But C++ namespaces give ries to DW_TAG_namespace dies
+ whose children are global objects. So we keep track of what
+ level we currently think of as referring to file scope; this
+ should always equal 1 plus the number of namespaces that we are
+ currently nested within. */
int file_scope_level = 1;
}
break;
case DW_TAG_enumerator:
- /* File scope enumerators are added to the partial symbol
- table. */
+ /* File scope enumerators are added to the partial
+ symbol table. They're children of the enumeration
+ type die, so they occur at a level one higher than we
+ normally look for. */
if (nesting_level == file_scope_level + 1)
add_partial_symbol (&pdi, objfile, cu_header);
break;
int *is_a_field_of_this,
struct symtab **symtab);
-static struct symbol *lookup_symbol_aux_local (const char *name,
- const char *mangled_name,
- const struct block *block,
- const namespace_enum namespace,
- struct symtab **symtab);
+static
+struct symbol *lookup_symbol_aux_local (const char *name,
+ const char *mangled_name,
+ const struct block *block,
+ const namespace_enum namespace,
+ struct symtab **symtab,
+ const struct block **static_block);
static
struct symbol *lookup_symbol_aux_nonlocal (int block_index,
int *is_a_field_of_this, struct symtab **symtab)
{
struct symbol *sym;
+ const struct block *static_block;
- /* Search specified block and its superiors. */
+ /* Search specified block and its superiors. Don't search
+ STATIC_BLOCK or GLOBAL_BLOCK. */
sym = lookup_symbol_aux_local (name, mangled_name, block, namespace,
- symtab);
+ symtab, &static_block);
if (sym != NULL)
return sym;
}
}
+ /* If there's a static block to search, search it next. */
+
+ if (static_block != NULL)
+ {
+ sym = lookup_block_symbol (static_block, name, mangled_name, namespace);
+ if (sym != NULL)
+ return sym;
+ }
+
/* Now search all global blocks. Do the symtab's first, then
check the psymtab's. If a psymtab indicates the existence
of the desired name as a global, then do psymtab-to-symtab
- conversion on the fly and return the found symbol. */
-
- sym = lookup_symbol_aux_nonlocal (GLOBAL_BLOCK, name, mangled_name,
- namespace, symtab);
- if (sym != NULL)
- return sym;
+ conversion on the fly and return the found symbol.
- /* If we're in the C++ case, check to see if the symbol is defined
- in a namespace accessible via a "using" declaration. */
+ We do this from within lookup_symbol_aux_using: that will apply
+ appropriate using directives in the C++ case. But it works fine
+ in the non-C++ case, too. */
- /* FIXME: carlton/2002-10-10: is "is_a_field_of_this" always
- non-NULL if we're in the C++ case? Maybe we should always do
- this, and delete the two previous searches: this will always
- search the global namespace, after all. */
+ /* NOTE: carlton/2002-10-22: Is it worthwhile to try to figure out
+ whether or not we're in the C++ case? Doing
+ lookup_symbol_aux_using won't slow things down much at all in the
+ general case, though: other parts of this function are much, much
+ more expensive. */
- if (is_a_field_of_this)
- {
- sym = lookup_symbol_aux_using (name, mangled_name, block, namespace,
- symtab);
- if (sym != NULL)
- return sym;
- }
+ sym = lookup_symbol_aux_using (name, mangled_name, block, namespace,
+ symtab);
+ if (sym != NULL)
+ return sym;
#ifndef HPUXHPPA
return NULL;
}
-/* Check to see if the symbol is defined in BLOCK or its
- superiors. */
+/* Check to see if the symbol is defined in BLOCK or its superiors.
+ Don't search STATIC_BLOCK or GLOBAL_BLOCK. If we don't find a
+ match, store the address of STATIC_BLOCK in static_block. */
static struct symbol *
lookup_symbol_aux_local (const char *name, const char *mangled_name,
const struct block *block,
const namespace_enum namespace,
- struct symtab **symtab)
+ struct symtab **symtab,
+ const struct block **static_block)
{
struct symbol *sym;
struct objfile *objfile = NULL;
struct blockvector *bv;
struct block *b;
struct symtab *s = NULL;
-
- while (block != 0)
+
+ /* Either no block is specified or it's a global block. */
+
+ if (block == NULL || BLOCK_SUPERBLOCK (block) == NULL)
+ {
+ *static_block = NULL;
+ return NULL;
+ }
+
+ while (BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) != NULL)
{
sym = lookup_block_symbol (block, name, mangled_name, namespace);
if (sym)
block = BLOCK_SUPERBLOCK (block);
}
+ /* We've reached the static block. */
+
+ *static_block = block;
return NULL;
}