* tracepoint.c (scope_info): Update.

* symtab.c (lookup_block_symbol, iterate_over_symbols)
	(find_pc_sect_symtab, search_symbols)
	(default_make_symbol_completion_list_break_on)
	(make_file_symbol_completion_list): Update.
	* symmisc.c (dump_symtab_1): Update.
	* stack.c (print_frame_args, iterate_over_block_locals)
	(print_frame_labels, iterate_over_block_arg_vars): Update.
	* python/py-block.c (block_object) <dict>: Remove.
	<block>: New field.
	<iter>: Change type.
	(blpy_iter): Update.
	(blpy_block_syms_iternext): Update.
	* psymtab.c (map_block): Use block iterators.
	* objfiles.c (objfile_relocate1): Use ALL_DICT_SYMBOLS.
	* mi/mi-cmd-stack.c (list_args_or_locals): Update.
	* mdebugread.c (parse_symbol, mylookup_symbol): Update.
	* infrun.c (check_exception_resume): Update.
	* cp-support.c (make_symbol_overload_list_block): Update.
	* coffread.c (patch_opaque_types): Update.
	* buildsym.c (finish_block, end_symtab): Use ALL_DICT_SYMBOLS.
	* block.h (struct block_iterator): New.
	(block_iterator_first, block_iterator_next, block_iter_name_first)
	(block_iter_name_next, block_iter_match_first)
	(block_iter_match_next): Declare.
	(ALL_BLOCK_SYMBOLS): Redefine.
	* block.c (block_iterator_first, block_iterator_next)
	(block_iter_name_first, block_iter_name_next)
	(block_iter_match_first, block_iter_match_next): New functions.
	* ada-lang.c (ada_add_block_symbols)
	(ada_make_symbol_completion_list): Use block iterator.
This commit is contained in:
Tom Tromey 2012-05-10 19:50:09 +00:00
parent a2ca7a527e
commit 8157b174fd
17 changed files with 228 additions and 61 deletions

View File

@ -1,3 +1,37 @@
2012-05-10 Tom Tromey <tromey@redhat.com>
* tracepoint.c (scope_info): Update.
* symtab.c (lookup_block_symbol, iterate_over_symbols)
(find_pc_sect_symtab, search_symbols)
(default_make_symbol_completion_list_break_on)
(make_file_symbol_completion_list): Update.
* symmisc.c (dump_symtab_1): Update.
* stack.c (print_frame_args, iterate_over_block_locals)
(print_frame_labels, iterate_over_block_arg_vars): Update.
* python/py-block.c (block_object) <dict>: Remove.
<block>: New field.
<iter>: Change type.
(blpy_iter): Update.
(blpy_block_syms_iternext): Update.
* psymtab.c (map_block): Use block iterators.
* objfiles.c (objfile_relocate1): Use ALL_DICT_SYMBOLS.
* mi/mi-cmd-stack.c (list_args_or_locals): Update.
* mdebugread.c (parse_symbol, mylookup_symbol): Update.
* infrun.c (check_exception_resume): Update.
* cp-support.c (make_symbol_overload_list_block): Update.
* coffread.c (patch_opaque_types): Update.
* buildsym.c (finish_block, end_symtab): Use ALL_DICT_SYMBOLS.
* block.h (struct block_iterator): New.
(block_iterator_first, block_iterator_next, block_iter_name_first)
(block_iter_name_next, block_iter_match_first)
(block_iter_match_next): Declare.
(ALL_BLOCK_SYMBOLS): Redefine.
* block.c (block_iterator_first, block_iterator_next)
(block_iter_name_first, block_iter_name_next)
(block_iter_match_first, block_iter_match_next): New functions.
* ada-lang.c (ada_add_block_symbols)
(ada_make_symbol_completion_list): Use block iterator.
2012-05-10 Tom Tromey <tromey@redhat.com>
* psymtab.c (PSYMTAB_TO_SYMTAB): Remove.

View File

@ -5515,7 +5515,7 @@ ada_add_block_symbols (struct obstack *obstackp,
domain_enum domain, struct objfile *objfile,
int wild)
{
struct dict_iterator iter;
struct block_iterator iter;
int name_len = strlen (name);
/* A matching argument symbol, if any. */
struct symbol *arg_sym;
@ -5527,9 +5527,8 @@ ada_add_block_symbols (struct obstack *obstackp,
found_sym = 0;
if (wild)
{
for (sym = dict_iter_match_first (BLOCK_DICT (block), name,
wild_match, &iter);
sym != NULL; sym = dict_iter_match_next (name, wild_match, &iter))
for (sym = block_iter_match_first (block, name, wild_match, &iter);
sym != NULL; sym = block_iter_match_next (name, wild_match, &iter))
{
if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
SYMBOL_DOMAIN (sym), domain)
@ -5551,9 +5550,8 @@ ada_add_block_symbols (struct obstack *obstackp,
}
else
{
for (sym = dict_iter_match_first (BLOCK_DICT (block), name,
full_match, &iter);
sym != NULL; sym = dict_iter_match_next (name, full_match, &iter))
for (sym = block_iter_match_first (block, name, full_match, &iter);
sym != NULL; sym = block_iter_match_next (name, full_match, &iter))
{
if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
SYMBOL_DOMAIN (sym), domain))
@ -5816,7 +5814,7 @@ ada_make_symbol_completion_list (char *text0, char *word)
struct objfile *objfile;
struct block *b, *surrounding_static_block = 0;
int i;
struct dict_iterator iter;
struct block_iterator iter;
if (text0[0] == '<')
{

View File

@ -369,3 +369,62 @@ allocate_block (struct obstack *obstack)
return bl;
}
/* See block.h. */
struct symbol *
block_iterator_first (const struct block *block,
struct block_iterator *iterator)
{
return dict_iterator_first (block->dict, &iterator->dict_iter);
}
/* See block.h. */
struct symbol *
block_iterator_next (struct block_iterator *iterator)
{
return dict_iterator_next (&iterator->dict_iter);
}
/* See block.h. */
struct symbol *
block_iter_name_first (const struct block *block,
const char *name,
struct block_iterator *iterator)
{
return dict_iter_name_first (block->dict, name, &iterator->dict_iter);
}
/* See block.h. */
struct symbol *
block_iter_name_next (const char *name, struct block_iterator *iterator)
{
return dict_iter_name_next (name, &iterator->dict_iter);
}
/* See block.h. */
struct symbol *
block_iter_match_first (const struct block *block,
const char *name,
symbol_compare_ftype *compare,
struct block_iterator *iterator)
{
return dict_iter_match_first (block->dict, name, compare,
&iterator->dict_iter);
}
/* See block.h. */
struct symbol *
block_iter_match_next (const char *name,
symbol_compare_ftype *compare,
struct block_iterator *iterator)
{
return dict_iter_match_next (name, compare, &iterator->dict_iter);
}

View File

@ -20,6 +20,8 @@
#ifndef BLOCK_H
#define BLOCK_H
#include "dictionary.h"
/* Opaque declarations. */
struct symbol;
@ -27,7 +29,6 @@ struct symtab;
struct block_namespace_info;
struct using_direct;
struct obstack;
struct dictionary;
struct addrmap;
/* All of the name-scope contours of the program
@ -105,13 +106,6 @@ struct block
#define BLOCK_DICT(bl) (bl)->dict
#define BLOCK_NAMESPACE(bl) (bl)->language_specific.cplus_specific.namespace
/* Macro to loop through all symbols in a block BL, in no particular
order. ITER helps keep track of the iteration, and should be a
struct dict_iterator. SYM points to the current symbol. */
#define ALL_BLOCK_SYMBOLS(block, iter, sym) \
ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
struct blockvector
{
/* Number of blocks in the list. */
@ -167,4 +161,80 @@ extern const struct block *block_global_block (const struct block *block);
extern struct block *allocate_block (struct obstack *obstack);
/* A block iterator. This structure should be treated as though it
were opaque; it is only defined here because we want to support
stack allocation of iterators. */
struct block_iterator
{
/* The underlying dictionary iterator. */
struct dict_iterator dict_iter;
};
/* Initialize ITERATOR to point at the first symbol in BLOCK, and
return that first symbol, or NULL if BLOCK is empty. */
extern struct symbol *block_iterator_first (const struct block *block,
struct block_iterator *iterator);
/* Advance ITERATOR, and return the next symbol, or NULL if there are
no more symbols. Don't call this if you've previously received
NULL from block_iterator_first or block_iterator_next on this
iteration. */
extern struct symbol *block_iterator_next (struct block_iterator *iterator);
/* Initialize ITERATOR to point at the first symbol in BLOCK whose
SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), and return
that first symbol, or NULL if there are no such symbols. */
extern struct symbol *block_iter_name_first (const struct block *block,
const char *name,
struct block_iterator *iterator);
/* Advance ITERATOR to point at the next symbol in BLOCK whose
SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), or NULL if
there are no more such symbols. Don't call this if you've
previously received NULL from block_iterator_first or
block_iterator_next on this iteration. And don't call it unless
ITERATOR was created by a previous call to block_iter_name_first
with the same NAME. */
extern struct symbol *block_iter_name_next (const char *name,
struct block_iterator *iterator);
/* Initialize ITERATOR to point at the first symbol in BLOCK whose
SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (which must use
the same conventions as strcmp_iw and be compatible with any
block hashing function), and return that first symbol, or NULL
if there are no such symbols. */
extern struct symbol *block_iter_match_first (const struct block *block,
const char *name,
symbol_compare_ftype *compare,
struct block_iterator *iterator);
/* Advance ITERATOR to point at the next symbol in BLOCK whose
SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (see
block_iter_match_first), or NULL if there are no more such symbols.
Don't call this if you've previously received NULL from
block_iterator_match_first or block_iterator_match_next on this
iteration. And don't call it unless ITERATOR was created by a
previous call to block_iter_match_first with the same NAME and COMPARE. */
extern struct symbol *block_iter_match_next (const char *name,
symbol_compare_ftype *compare,
struct block_iterator *iterator);
/* Macro to loop through all symbols in a block BL, in no particular
order. ITER helps keep track of the iteration, and should be a
struct block_iterator. SYM points to the current symbol. */
#define ALL_BLOCK_SYMBOLS(block, iter, sym) \
for ((sym) = block_iterator_first ((block), &(iter)); \
(sym); \
(sym) = block_iterator_next (&(iter)))
#endif /* BLOCK_H */

View File

@ -261,7 +261,10 @@ finish_block (struct symbol *symbol, struct pending **listhead,
parameter symbols. */
int nparams = 0, iparams;
struct symbol *sym;
ALL_BLOCK_SYMBOLS (block, iter, sym)
/* Here we want to directly access the dictionary, because
we haven't fully initialized the block yet. */
ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
{
if (SYMBOL_IS_ARGUMENT (sym))
nparams++;
@ -273,7 +276,9 @@ finish_block (struct symbol *symbol, struct pending **listhead,
TYPE_ALLOC (ftype, nparams * sizeof (struct field));
iparams = 0;
ALL_BLOCK_SYMBOLS (block, iter, sym)
/* Here we want to directly access the dictionary, because
we haven't fully initialized the block yet. */
ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
{
if (iparams == nparams)
break;
@ -1173,9 +1178,9 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
if (SYMBOL_SYMTAB (BLOCK_FUNCTION (block)) == NULL)
SYMBOL_SYMTAB (BLOCK_FUNCTION (block)) = symtab;
for (sym = dict_iterator_first (BLOCK_DICT (block), &iter);
sym != NULL;
sym = dict_iterator_next (&iter))
/* Note that we only want to fix up symbols from the local
blocks, not blocks coming from included symtabs. */
ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
if (SYMBOL_SYMTAB (sym) == NULL)
SYMBOL_SYMTAB (sym) = symtab;
}

View File

@ -1471,7 +1471,7 @@ static void
patch_opaque_types (struct symtab *s)
{
struct block *b;
struct dict_iterator iter;
struct block_iterator iter;
struct symbol *real_sym;
/* Go through the per-file symbols only. */

View File

@ -1140,14 +1140,12 @@ static void
make_symbol_overload_list_block (const char *name,
const struct block *block)
{
struct dict_iterator iter;
struct block_iterator iter;
struct symbol *sym;
const struct dictionary *dict = BLOCK_DICT (block);
for (sym = dict_iter_name_first (dict, name, &iter);
for (sym = block_iter_name_first (block, name, &iter);
sym != NULL;
sym = dict_iter_name_next (name, &iter))
sym = block_iter_name_next (name, &iter))
overload_list_add_symbol (sym, name);
}

View File

@ -5620,7 +5620,7 @@ check_exception_resume (struct execution_control_state *ecs,
TRY_CATCH (e, RETURN_MASK_ERROR)
{
struct block *b;
struct dict_iterator iter;
struct block_iterator iter;
struct symbol *sym;
int argno = 0;

View File

@ -1184,7 +1184,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
if (nparams > 0)
{
struct dict_iterator iter;
struct block_iterator iter;
TYPE_NFIELDS (ftype) = nparams;
TYPE_FIELDS (ftype) = (struct field *)
@ -4607,7 +4607,7 @@ static struct symbol *
mylookup_symbol (char *name, struct block *block,
domain_enum domain, enum address_class class)
{
struct dict_iterator iter;
struct block_iterator iter;
int inc;
struct symbol *sym;

View File

@ -328,7 +328,7 @@ list_args_or_locals (enum what_to_list what, enum print_values values,
{
struct block *block;
struct symbol *sym;
struct dict_iterator iter;
struct block_iterator iter;
struct cleanup *cleanup_list;
struct type *type;
char *name_of_result;

View File

@ -730,7 +730,9 @@ objfile_relocate1 (struct objfile *objfile,
BLOCK_START (b) += ANOFFSET (delta, s->block_line_section);
BLOCK_END (b) += ANOFFSET (delta, s->block_line_section);
ALL_BLOCK_SYMBOLS (b, iter, sym)
/* We only want to iterate over the local symbols, not any
symbols in included symtabs. */
ALL_DICT_SYMBOLS (BLOCK_DICT (b), iter, sym)
{
relocate_one_symbol (sym, objfile, delta);
}

View File

@ -1182,11 +1182,11 @@ map_block (const char *name, domain_enum namespace, struct objfile *objfile,
int (*callback) (struct block *, struct symbol *, void *),
void *data, symbol_compare_ftype *match)
{
struct dict_iterator iter;
struct block_iterator iter;
struct symbol *sym;
for (sym = dict_iter_match_first (BLOCK_DICT (block), name, match, &iter);
sym != NULL; sym = dict_iter_match_next (name, match, &iter))
for (sym = block_iter_match_first (block, name, match, &iter);
sym != NULL; sym = block_iter_match_next (name, match, &iter))
{
if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
SYMBOL_DOMAIN (sym), namespace))

View File

@ -41,10 +41,10 @@ typedef struct blpy_block_object {
typedef struct {
PyObject_HEAD
/* The block dictionary of symbols. */
struct dictionary *dict;
/* The iterator for that dictionary. */
struct dict_iterator iter;
/* The block. */
const struct block *block;
/* The iterator for that block. */
struct block_iterator iter;
/* Has the iterator been initialized flag. */
int initialized_p;
/* Pointer back to the original source block object. Needed to
@ -94,7 +94,7 @@ blpy_iter (PyObject *self)
if (block_iter_obj == NULL)
return NULL;
block_iter_obj->dict = BLOCK_DICT (block);
block_iter_obj->block = block;
block_iter_obj->initialized_p = 0;
Py_INCREF (self);
block_iter_obj->source = (block_object *) self;
@ -311,11 +311,11 @@ blpy_block_syms_iternext (PyObject *self)
if (!iter_obj->initialized_p)
{
sym = dict_iterator_first (iter_obj->dict, &(iter_obj->iter));
sym = block_iterator_first (iter_obj->block, &(iter_obj->iter));
iter_obj->initialized_p = 1;
}
else
sym = dict_iterator_next (&(iter_obj->iter));
sym = block_iterator_next (&(iter_obj->iter));
if (sym == NULL)
{

View File

@ -512,7 +512,7 @@ print_frame_args (struct symbol *func, struct frame_info *frame,
if (func)
{
struct block *b = SYMBOL_BLOCK_VALUE (func);
struct dict_iterator iter;
struct block_iterator iter;
struct symbol *sym;
ALL_BLOCK_SYMBOLS (b, iter, sym)
@ -1821,7 +1821,7 @@ iterate_over_block_locals (struct block *b,
iterate_over_block_arg_local_vars_cb cb,
void *cb_data)
{
struct dict_iterator iter;
struct block_iterator iter;
struct symbol *sym;
ALL_BLOCK_SYMBOLS (b, iter, sym)
@ -1858,7 +1858,7 @@ static int
print_block_frame_labels (struct gdbarch *gdbarch, struct block *b,
int *have_default, struct ui_file *stream)
{
struct dict_iterator iter;
struct block_iterator iter;
struct symbol *sym;
int values_printed = 0;
@ -1990,7 +1990,7 @@ iterate_over_block_arg_vars (struct block *b,
iterate_over_block_arg_local_vars_cb cb,
void *cb_data)
{
struct dict_iterator iter;
struct block_iterator iter;
struct symbol *sym, *sym2;
ALL_BLOCK_SYMBOLS (b, iter, sym)

View File

@ -353,8 +353,9 @@ dump_symtab_1 (struct objfile *objfile, struct symtab *symtab,
}
fprintf_filtered (outfile, "\n");
/* Now print each symbol in this block (in no particular order, if
we're using a hashtable). */
ALL_BLOCK_SYMBOLS (b, iter, sym)
we're using a hashtable). Note that we only want this
block, not any blocks from included symtabs. */
ALL_DICT_SYMBOLS (BLOCK_DICT (b), iter, sym)
{
struct print_symbol_args s;

View File

@ -1924,14 +1924,14 @@ struct symbol *
lookup_block_symbol (const struct block *block, const char *name,
const domain_enum domain)
{
struct dict_iterator iter;
struct block_iterator iter;
struct symbol *sym;
if (!BLOCK_FUNCTION (block))
{
for (sym = dict_iter_name_first (BLOCK_DICT (block), name, &iter);
for (sym = block_iter_name_first (block, name, &iter);
sym != NULL;
sym = dict_iter_name_next (name, &iter))
sym = block_iter_name_next (name, &iter))
{
if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
SYMBOL_DOMAIN (sym), domain))
@ -1949,9 +1949,9 @@ lookup_block_symbol (const struct block *block, const char *name,
struct symbol *sym_found = NULL;
for (sym = dict_iter_name_first (BLOCK_DICT (block), name, &iter);
for (sym = block_iter_name_first (block, name, &iter);
sym != NULL;
sym = dict_iter_name_next (name, &iter))
sym = block_iter_name_next (name, &iter))
{
if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
SYMBOL_DOMAIN (sym), domain))
@ -1986,12 +1986,12 @@ iterate_over_symbols (const struct block *block, const char *name,
{
while (block)
{
struct dict_iterator iter;
struct block_iterator iter;
struct symbol *sym;
for (sym = dict_iter_name_first (BLOCK_DICT (block), name, &iter);
for (sym = block_iter_name_first (block, name, &iter);
sym != NULL;
sym = dict_iter_name_next (name, &iter))
sym = block_iter_name_next (name, &iter))
{
if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
SYMBOL_DOMAIN (sym), domain))
@ -2081,7 +2081,7 @@ find_pc_sect_symtab (CORE_ADDR pc, struct obj_section *section)
}
if (section != 0)
{
struct dict_iterator iter;
struct block_iterator iter;
struct symbol *sym = NULL;
ALL_BLOCK_SYMBOLS (b, iter, sym)
@ -3329,7 +3329,7 @@ search_symbols (char *regexp, enum search_domain kind,
struct blockvector *bv;
struct block *b;
int i = 0;
struct dict_iterator iter;
struct block_iterator iter;
struct symbol *sym;
struct objfile *objfile;
struct minimal_symbol *msymbol;
@ -4131,7 +4131,7 @@ default_make_symbol_completion_list_break_on (char *text, char *word,
struct objfile *objfile;
struct block *b;
const struct block *surrounding_static_block, *surrounding_global_block;
struct dict_iterator iter;
struct block_iterator iter;
/* The symbol we are completing on. Points in same buffer as text. */
char *sym_text;
/* Length of sym_text. */
@ -4363,7 +4363,7 @@ make_file_symbol_completion_list (char *text, char *word, char *srcfile)
struct symbol *sym;
struct symtab *s;
struct block *b;
struct dict_iterator iter;
struct block_iterator iter;
/* The symbol we are completing on. Points in same buffer as text. */
char *sym_text;
/* Length of sym_text. */

View File

@ -2612,7 +2612,7 @@ scope_info (char *args, int from_tty)
struct block *block;
const char *symname;
char *save_args = args;
struct dict_iterator iter;
struct block_iterator iter;
int j, count = 0;
struct gdbarch *gdbarch;
int regno;