+2013-03-05 Doug Evans <dje@google.com>
+
+ * ada-lang.c (ada_lookup_symbol_list_worker): New function, contents
+ of old ada_lookup_symbol_list. In !full_search case, don't
+ search superblocks.
+ (ada_lookup_symbol_list): Delete arg full_search, all callers
+ updated. Call ada_lookup_symbol_list_worker.
+ (ada_iterate_over_symbols): Call ada_lookup_symbol_list_worker.
+ * ada-lang.h (ada_lookup_symbol_list): Update.
+ * language.h (language_defn): Update comment for
+ la_iterate_over_symbols.
+ * linespec.c (iterate_over_file_blocks): New function.
+ (iterate_over_all_matching_symtabs): Call it.
+ (lookup_prefix_sym): Ditto.
+ (get_current_search_block): New function.
+ (get_search_block): Delete.
+ (find_label_symbols): Call get_current_search_block.
+ (add_matching_symbols_to_info): Call iterate_over_file_blocks.
+ * symtab.c (iterate_over_symbols): Don't search superblocks.
+
2013-03-05 Yao Qi <yao@codesourcery.com>
* cli/cli-decode.c (add_setshow_zuinteger_unlimited_cmd): Change
else
name = ada_encode (raw_name);
- nsyms = ada_lookup_symbol_list (name, context, VAR_DOMAIN, &syms, 1);
+ nsyms = ada_lookup_symbol_list (name, context, VAR_DOMAIN, &syms);
if (context == NULL
&& (nsyms == 0 || SYMBOL_CLASS (syms[0].sym) != LOC_BLOCK))
symtab = lookup_symtab (name);
encoded_name[tail_index] = '\0';
nsyms = ada_lookup_symbol_list (encoded_name, block,
- VAR_DOMAIN, &syms, 1);
+ VAR_DOMAIN, &syms);
encoded_name[tail_index] = terminator;
/* A single symbol may rename a package or object. */
{
struct ada_symbol_info *syms;
int nsyms = ada_lookup_symbol_list (name.ptr, expression_context_block,
- VAR_DOMAIN, &syms, 1);
+ VAR_DOMAIN, &syms);
if (nsyms != 1 || SYMBOL_CLASS (syms[0].sym) == LOC_TYPEDEF)
write_exp_op_with_string (OP_NAME, name);
else
ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME
(exp->elts[pc + 2].symbol),
exp->elts[pc + 1].block, VAR_DOMAIN,
- &candidates, 1);
+ &candidates);
if (n_candidates > 1)
{
ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME
(exp->elts[pc + 5].symbol),
exp->elts[pc + 4].block, VAR_DOMAIN,
- &candidates, 1);
+ &candidates);
if (n_candidates == 1)
i = 0;
else
n_candidates =
ada_lookup_symbol_list (ada_encode (ada_decoded_op_name (op)),
(struct block *) NULL, VAR_DOMAIN,
- &candidates, 1);
+ &candidates);
i = ada_resolve_function (candidates, n_candidates, argvec, nargs,
ada_decoded_op_name (op), NULL);
if (i < 0)
}
}
-/* Find symbols in DOMAIN matching NAME0, in BLOCK0 and enclosing
- scope and in global scopes, returning the number of matches.
+/* Find symbols in DOMAIN matching NAME0, in BLOCK0 and, if full_search is
+ non-zero, enclosing scope and in global scopes, returning the number of
+ matches.
Sets *RESULTS to point to a vector of (SYM,BLOCK) tuples,
indicating the symbols found and the blocks and symbol tables (if
- any) in which they were found. This vector are transient---good only to
- the next call of ada_lookup_symbol_list. Any non-function/non-enumeral
+ any) in which they were found. This vector is transient---good only to
+ the next call of ada_lookup_symbol_list.
+
+ When full_search is non-zero, any non-function/non-enumeral
symbol match within the nest of blocks whose innermost member is BLOCK0,
is the one match returned (no other matches in that or
enclosing blocks is returned). If there are any matches in or
- surrounding BLOCK0, then these alone are returned. Otherwise, if
- FULL_SEARCH is non-zero, then the search extends to global and
- file-scope (static) symbol tables.
+ surrounding BLOCK0, then these alone are returned.
+
Names prefixed with "standard__" are handled specially: "standard__"
is first stripped off, and only static and global symbols are searched. */
-int
-ada_lookup_symbol_list (const char *name0, const struct block *block0,
- domain_enum namespace,
- struct ada_symbol_info **results,
- int full_search)
+static int
+ada_lookup_symbol_list_worker (const char *name0, const struct block *block0,
+ domain_enum namespace,
+ struct ada_symbol_info **results,
+ int full_search)
{
struct symbol *sym;
struct block *block;
/* Check the non-global symbols. If we have ANY match, then we're done. */
- ada_add_local_symbols (&symbol_list_obstack, name, block, namespace,
- wild_match_p);
- if (num_defns_collected (&symbol_list_obstack) > 0 || !full_search)
- goto done;
+ if (block != NULL)
+ {
+ if (full_search)
+ {
+ ada_add_local_symbols (&symbol_list_obstack, name, block,
+ namespace, wild_match_p);
+ }
+ else
+ {
+ /* In the !full_search case we're are being called by
+ ada_iterate_over_symbols, and we don't want to search
+ superblocks. */
+ ada_add_block_symbols (&symbol_list_obstack, block, name,
+ namespace, NULL, wild_match_p);
+ }
+ if (num_defns_collected (&symbol_list_obstack) > 0 || !full_search)
+ goto done;
+ }
/* No non-global symbols found. Check our cache to see if we have
already performed this search before. If we have, then return
return ndefns;
}
+/* Find symbols in DOMAIN matching NAME0, in BLOCK0 and enclosing scope and
+ in global scopes, returning the number of matches, and setting *RESULTS
+ to a vector of (SYM,BLOCK) tuples.
+ See ada_lookup_symbol_list_worker for further details. */
+
+int
+ada_lookup_symbol_list (const char *name0, const struct block *block0,
+ domain_enum domain, struct ada_symbol_info **results)
+{
+ return ada_lookup_symbol_list_worker (name0, block0, domain, results, 1);
+}
+
+/* Implementation of the la_iterate_over_symbols method. */
+
+static void
+ada_iterate_over_symbols (const struct block *block,
+ const char *name, domain_enum domain,
+ symbol_found_callback_ftype *callback,
+ void *data)
+{
+ int ndefs, i;
+ struct ada_symbol_info *results;
+
+ ndefs = ada_lookup_symbol_list_worker (name, block, domain, &results, 0);
+ for (i = 0; i < ndefs; ++i)
+ {
+ if (! (*callback) (results[i].sym, data))
+ break;
+ }
+}
+
/* If NAME is the name of an entity, return a string that should
be used to look that entity up in Ada units. This string should
be deallocated after use using xfree.
return canon;
}
-/* Implementation of the la_iterate_over_symbols method. */
-
-static void
-ada_iterate_over_symbols (const struct block *block,
- const char *name, domain_enum domain,
- symbol_found_callback_ftype *callback,
- void *data)
-{
- int ndefs, i;
- struct ada_symbol_info *results;
-
- ndefs = ada_lookup_symbol_list (name, block, domain, &results, 0);
- for (i = 0; i < ndefs; ++i)
- {
- if (! (*callback) (results[i].sym, data))
- break;
- }
-}
-
/* The result is as for ada_lookup_symbol_list with FULL_SEARCH set
to 1, but choosing the first symbol found if there are multiple
choices.
gdb_assert (info != NULL);
memset (info, 0, sizeof (struct ada_symbol_info));
- n_candidates = ada_lookup_symbol_list (name, block, namespace, &candidates,
- 1);
-
+ n_candidates = ada_lookup_symbol_list (name, block, namespace, &candidates);
if (n_candidates == 0)
return;
/* Add symbols from BLOCK matching identifier NAME in DOMAIN to
vector *defn_symbols, updating the list of symbols in OBSTACKP
(if necessary). If WILD, treat as NAME with a wildcard prefix.
- OBJFILE is the section containing BLOCK.
- SYMTAB is recorded with each symbol added. */
+ OBJFILE is the section containing BLOCK. */
static void
ada_add_block_symbols (struct obstack *obstackp,
int nsyms;
nsyms = ada_lookup_symbol_list (name, get_selected_block (0), VAR_DOMAIN,
- &syms, 1);
+ &syms);
if (nsyms != 1)
{
extern void clear_ada_sym_cache (void);
extern int ada_lookup_symbol_list (const char *, const struct block *,
- domain_enum, struct ada_symbol_info**,
- int);
+ domain_enum, struct ada_symbol_info**);
extern char *ada_fold_name (const char *);
/* Find all symbols in the current program space matching NAME in
DOMAIN, according to this language's rules.
- The search starts with BLOCK. This function iterates upward
- through blocks. When the outermost block has been finished,
- the function returns.
+ The search is done in BLOCK only.
+ The caller is responsible for iterating up through superblocks
+ if desired.
For each one, call CALLBACK with the symbol and the DATA
argument. If CALLBACK returns zero, the iteration ends at that
/* Prototypes for local functions. */
+static void iterate_over_file_blocks (struct symtab *symtab,
+ const char *name, domain_enum domain,
+ symbol_found_callback_ftype *callback,
+ void *data);
+
static void initialize_defaults (struct symtab **default_symtab,
int *default_line);
ALL_OBJFILE_PRIMARY_SYMTABS (objfile, symtab)
{
- struct block *block;
-
- block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
- state->language->la_iterate_over_symbols (block, name, domain,
- callback, data);
+ iterate_over_file_blocks (symtab, name, domain, callback, data);
if (include_inline)
{
struct symbol_and_data_callback cad = { callback, data };
+ struct block *block;
int i;
for (i = FIRST_LOCAL_BLOCK;
}
}
-/* Returns the block to be used for symbol searches for the given SYMTAB,
- which may be NULL. */
+/* Returns the block to be used for symbol searches from
+ the current location. */
static struct block *
-get_search_block (struct symtab *symtab)
+get_current_search_block ()
{
struct block *block;
+ enum language save_language;
- if (symtab != NULL)
- block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
- else
- {
- enum language save_language;
-
- /* get_selected_block can change the current language when there is
- no selected frame yet. */
- save_language = current_language->la_language;
- block = get_selected_block (0);
- set_language (save_language);
- }
+ /* get_selected_block can change the current language when there is
+ no selected frame yet. */
+ save_language = current_language->la_language;
+ block = get_selected_block (0);
+ set_language (save_language);
return block;
}
+/* Iterate over static and global blocks. */
+
+static void
+iterate_over_file_blocks (struct symtab *symtab,
+ const char *name, domain_enum domain,
+ symbol_found_callback_ftype *callback, void *data)
+{
+ struct block *block;
+
+ for (block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
+ block != NULL;
+ block = BLOCK_SUPERBLOCK (block))
+ LA_ITERATE_OVER_SYMBOLS (block, name, domain, callback, data);
+}
+
/* A helper for find_method. This finds all methods in type T which
match NAME. It adds matching symbol names to RESULT_NAMES, and
adds T's direct superclasses to SUPERCLASSES. */
}
else
{
- struct block *search_block;
-
/* Program spaces that are executing startup should have
been filtered out earlier. */
gdb_assert (!SYMTAB_PSPACE (elt)->executing_startup);
set_current_program_space (SYMTAB_PSPACE (elt));
- search_block = get_search_block (elt);
- LA_ITERATE_OVER_SYMBOLS (search_block, class_name, STRUCT_DOMAIN,
- collect_one_symbol, &collector);
- LA_ITERATE_OVER_SYMBOLS (search_block, class_name, VAR_DOMAIN,
- collect_one_symbol, &collector);
+ iterate_over_file_blocks (elt, class_name, STRUCT_DOMAIN,
+ collect_one_symbol, &collector);
+ iterate_over_file_blocks (elt, class_name, VAR_DOMAIN,
+ collect_one_symbol, &collector);
}
}
if (function_symbols == NULL)
{
set_current_program_space (self->program_space);
- block = get_search_block (NULL);
+ block = get_current_search_block ();
for (;
block && !BLOCK_FUNCTION (block);
been filtered out earlier. */
gdb_assert (!SYMTAB_PSPACE (elt)->executing_startup);
set_current_program_space (SYMTAB_PSPACE (elt));
- LA_ITERATE_OVER_SYMBOLS (get_search_block (elt), name,
- VAR_DOMAIN, collect_symbols,
- info);
+ iterate_over_file_blocks (elt, name, VAR_DOMAIN,
+ collect_symbols, info);
}
}
}
}
}
-/* Iterate over the symbols named NAME, matching DOMAIN, starting with
- BLOCK.
+/* Iterate over the symbols named NAME, matching DOMAIN, in BLOCK.
For each symbol that matches, CALLBACK is called. The symbol and
DATA are passed to the callback.
If CALLBACK returns zero, the iteration ends. Otherwise, the
- search continues. This function iterates upward through blocks.
- When the outermost block has been finished, the function
- returns. */
+ search continues. */
void
iterate_over_symbols (const struct block *block, const char *name,
symbol_found_callback_ftype *callback,
void *data)
{
- while (block)
- {
- struct block_iterator iter;
- struct symbol *sym;
+ struct block_iterator iter;
+ struct symbol *sym;
- for (sym = block_iter_name_first (block, name, &iter);
- sym != NULL;
- sym = block_iter_name_next (name, &iter))
+ for (sym = block_iter_name_first (block, name, &iter);
+ sym != NULL;
+ sym = block_iter_name_next (name, &iter))
+ {
+ if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
+ SYMBOL_DOMAIN (sym), domain))
{
- if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
- SYMBOL_DOMAIN (sym), domain))
- {
- if (!callback (sym, data))
- return;
- }
+ if (!callback (sym, data))
+ return;
}
-
- block = BLOCK_SUPERBLOCK (block);
}
}