Remove ALL_BLOCK_SYMBOLS

This removes ALL_BLOCK_SYMBOLS in favor of foreach.
This commit is contained in:
Tom Tromey
2023-01-19 20:25:55 -07:00
parent a1b294260f
commit 548a89df23
12 changed files with 35 additions and 84 deletions

View File

@ -6111,10 +6111,8 @@ ada_add_block_symbols (std::vector<struct block_symbol> &result,
const std::string &ada_lookup_name = lookup_name.ada ().lookup_name (); const std::string &ada_lookup_name = lookup_name.ada ().lookup_name ();
const char *name = ada_lookup_name.c_str (); const char *name = ada_lookup_name.c_str ();
size_t name_len = ada_lookup_name.size (); size_t name_len = ada_lookup_name.size ();
struct symbol *sym;
struct block_iterator iter;
ALL_BLOCK_SYMBOLS (block, iter, sym) for (struct symbol *sym : block_iterator_range (block))
{ {
if (symbol_matches_domain (sym->language (), if (symbol_matches_domain (sym->language (),
sym->domain (), domain)) sym->domain (), domain))
@ -13049,10 +13047,7 @@ ada_add_exceptions_from_frame (compiled_regex *preg,
while (block != 0) while (block != 0)
{ {
struct block_iterator iter; for (struct symbol *sym : block_iterator_range (block))
struct symbol *sym;
ALL_BLOCK_SYMBOLS (block, iter, sym)
{ {
switch (sym->aclass ()) switch (sym->aclass ())
{ {
@ -13134,10 +13129,8 @@ ada_add_global_exceptions (compiled_regex *preg,
for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++) for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
{ {
const struct block *b = bv->block (i); const struct block *b = bv->block (i);
struct block_iterator iter;
struct symbol *sym;
ALL_BLOCK_SYMBOLS (b, iter, sym) for (struct symbol *sym : block_iterator_range (b))
if (ada_is_non_standard_exception_sym (sym) if (ada_is_non_standard_exception_sym (sym)
&& name_matches_regex (sym->natural_name (), preg)) && name_matches_regex (sym->natural_name (), preg))
{ {
@ -13639,9 +13632,7 @@ public:
const char *text, const char *word, const char *text, const char *word,
enum type_code code) const override enum type_code code) const override
{ {
struct symbol *sym;
const struct block *b, *surrounding_static_block = 0; const struct block *b, *surrounding_static_block = 0;
struct block_iterator iter;
gdb_assert (code == TYPE_CODE_UNDEF); gdb_assert (code == TYPE_CODE_UNDEF);
@ -13701,7 +13692,7 @@ public:
if (!b->superblock ()) if (!b->superblock ())
surrounding_static_block = b; /* For elmin of dups */ surrounding_static_block = b; /* For elmin of dups */
ALL_BLOCK_SYMBOLS (b, iter, sym) for (struct symbol *sym : block_iterator_range (b))
{ {
if (completion_skip_symbol (mode, sym)) if (completion_skip_symbol (mode, sym))
continue; continue;
@ -13722,7 +13713,7 @@ public:
{ {
QUIT; QUIT;
b = s->blockvector ()->global_block (); b = s->blockvector ()->global_block ();
ALL_BLOCK_SYMBOLS (b, iter, sym) for (struct symbol *sym : block_iterator_range (b))
{ {
if (completion_skip_symbol (mode, sym)) if (completion_skip_symbol (mode, sym))
continue; continue;
@ -13744,7 +13735,7 @@ public:
/* Don't do this block twice. */ /* Don't do this block twice. */
if (b == surrounding_static_block) if (b == surrounding_static_block)
continue; continue;
ALL_BLOCK_SYMBOLS (b, iter, sym) for (struct symbol *sym : block_iterator_range (b))
{ {
if (completion_skip_symbol (mode, sym)) if (completion_skip_symbol (mode, sym))
continue; continue;

View File

@ -595,15 +595,6 @@ extern int block_find_non_opaque_type (struct symbol *sym, void *data);
extern int block_find_non_opaque_type_preferred (struct symbol *sym, extern int block_find_non_opaque_type_preferred (struct symbol *sym,
void *data); void *data);
/* Macro to loop through all symbols in BLOCK, in no particular
order. ITER helps keep track of the iteration, and must 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)))
/* Given a vector of pairs, allocate and build an obstack allocated /* Given a vector of pairs, allocate and build an obstack allocated
blockranges struct for a block. */ blockranges struct for a block. */
struct blockranges *make_blockranges (struct objfile *objfile, struct blockranges *make_blockranges (struct objfile *objfile,

View File

@ -997,7 +997,7 @@ buildsym_compunit::end_compunit_symtab_with_blockvector
/* Note that we only want to fix up symbols from the local /* Note that we only want to fix up symbols from the local
blocks, not blocks coming from included symtabs. That is why blocks, not blocks coming from included symtabs. That is why
we use ALL_DICT_SYMBOLS here and not ALL_BLOCK_SYMBOLS. */ we use ALL_DICT_SYMBOLS here and not a block iterator. */
ALL_DICT_SYMBOLS (block->multidict (), miter, sym) ALL_DICT_SYMBOLS (block->multidict (), miter, sym)
if (sym->symtab () == NULL) if (sym->symtab () == NULL)
sym->set_symtab (symtab); sym->set_symtab (symtab);

View File

@ -1503,12 +1503,9 @@ patch_type (struct type *type, struct type *real_type)
static void static void
patch_opaque_types (struct symtab *s) patch_opaque_types (struct symtab *s)
{ {
struct block_iterator iter;
struct symbol *real_sym;
/* Go through the per-file symbols only. */ /* Go through the per-file symbols only. */
const struct block *b = s->compunit ()->blockvector ()->static_block (); const struct block *b = s->compunit ()->blockvector ()->static_block ();
ALL_BLOCK_SYMBOLS (b, iter, real_sym) for (struct symbol *real_sym : block_iterator_range (b))
{ {
/* Find completed typedefs to use to fix opaque ones. /* Find completed typedefs to use to fix opaque ones.
Remove syms from the chain when their types are stored, Remove syms from the chain when their types are stored,

View File

@ -618,13 +618,11 @@ static void
info_common_command_for_block (const struct block *block, const char *comname, info_common_command_for_block (const struct block *block, const char *comname,
int *any_printed) int *any_printed)
{ {
struct block_iterator iter;
struct symbol *sym;
struct value_print_options opts; struct value_print_options opts;
get_user_print_options (&opts); get_user_print_options (&opts);
ALL_BLOCK_SYMBOLS (block, iter, sym) for (struct symbol *sym : block_iterator_range (block))
if (sym->domain () == COMMON_BLOCK_DOMAIN) if (sym->domain () == COMMON_BLOCK_DOMAIN)
{ {
const struct common_block *common = sym->value_common_block (); const struct common_block *common = sym->value_common_block ();

View File

@ -8123,8 +8123,6 @@ check_exception_resume (struct execution_control_state *ecs,
try try
{ {
const struct block *b; const struct block *b;
struct block_iterator iter;
struct symbol *sym;
int argno = 0; int argno = 0;
/* The exception breakpoint is a thread-specific breakpoint on /* The exception breakpoint is a thread-specific breakpoint on
@ -8142,7 +8140,7 @@ check_exception_resume (struct execution_control_state *ecs,
handler. */ handler. */
b = func->value_block (); b = func->value_block ();
ALL_BLOCK_SYMBOLS (b, iter, sym) for (struct symbol *sym : block_iterator_range (b))
{ {
if (!sym->is_argument ()) if (!sym->is_argument ())
continue; continue;

View File

@ -3900,14 +3900,12 @@ find_label_symbols_in_block (const struct block *block,
{ {
if (completion_mode) if (completion_mode)
{ {
struct block_iterator iter;
struct symbol *sym;
size_t name_len = strlen (name); size_t name_len = strlen (name);
int (*cmp) (const char *, const char *, size_t); int (*cmp) (const char *, const char *, size_t);
cmp = case_sensitivity == case_sensitive_on ? strncmp : strncasecmp; cmp = case_sensitivity == case_sensitive_on ? strncmp : strncasecmp;
ALL_BLOCK_SYMBOLS (block, iter, sym) for (struct symbol *sym : block_iterator_range (block))
{ {
if (symbol_matches_domain (sym->language (), if (symbol_matches_domain (sym->language (),
sym->domain (), LABEL_DOMAIN) sym->domain (), LABEL_DOMAIN)

View File

@ -1193,19 +1193,16 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
type. Set that from the type of the parameter symbols. */ type. Set that from the type of the parameter symbols. */
int nparams = top_stack->numargs; int nparams = top_stack->numargs;
int iparams; int iparams;
struct symbol *sym;
if (nparams > 0) if (nparams > 0)
{ {
struct block_iterator iter;
ftype->set_num_fields (nparams); ftype->set_num_fields (nparams);
ftype->set_fields ftype->set_fields
((struct field *) ((struct field *)
TYPE_ALLOC (ftype, nparams * sizeof (struct field))); TYPE_ALLOC (ftype, nparams * sizeof (struct field)));
iparams = 0; iparams = 0;
ALL_BLOCK_SYMBOLS (cblock, iter, sym) for (struct symbol *sym : block_iterator_range (cblock))
{ {
if (iparams == nparams) if (iparams == nparams)
break; break;
@ -4464,12 +4461,10 @@ static struct symbol *
mylookup_symbol (const char *name, const struct block *block, mylookup_symbol (const char *name, const struct block *block,
domain_enum domain, enum address_class theclass) domain_enum domain, enum address_class theclass)
{ {
struct block_iterator iter;
int inc; int inc;
struct symbol *sym;
inc = name[0]; inc = name[0];
ALL_BLOCK_SYMBOLS (block, iter, sym) for (struct symbol *sym : block_iterator_range (block))
{ {
if (sym->linkage_name ()[0] == inc if (sym->linkage_name ()[0] == inc
&& sym->domain () == domain && sym->domain () == domain

View File

@ -568,8 +568,6 @@ list_args_or_locals (const frame_print_options &fp_opts,
frame_info_ptr fi, int skip_unavailable) frame_info_ptr fi, int skip_unavailable)
{ {
const struct block *block; const struct block *block;
struct symbol *sym;
struct block_iterator iter;
const char *name_of_result; const char *name_of_result;
struct ui_out *uiout = current_uiout; struct ui_out *uiout = current_uiout;
@ -594,7 +592,7 @@ list_args_or_locals (const frame_print_options &fp_opts,
while (block != 0) while (block != 0)
{ {
ALL_BLOCK_SYMBOLS (block, iter, sym) for (struct symbol *sym : block_iterator_range (block))
{ {
int print_me = 0; int print_me = 0;

View File

@ -751,10 +751,8 @@ print_frame_args (const frame_print_options &fp_opts,
if (func) if (func)
{ {
const struct block *b = func->value_block (); const struct block *b = func->value_block ();
struct block_iterator iter;
struct symbol *sym;
ALL_BLOCK_SYMBOLS (b, iter, sym) for (struct symbol *sym : block_iterator_range (b))
{ {
struct frame_arg arg, entryarg; struct frame_arg arg, entryarg;
@ -2221,10 +2219,7 @@ static void
iterate_over_block_locals (const struct block *b, iterate_over_block_locals (const struct block *b,
iterate_over_block_arg_local_vars_cb cb) iterate_over_block_arg_local_vars_cb cb)
{ {
struct block_iterator iter; for (struct symbol *sym : block_iterator_range (b))
struct symbol *sym;
ALL_BLOCK_SYMBOLS (b, iter, sym)
{ {
switch (sym->aclass ()) switch (sym->aclass ())
{ {
@ -2470,10 +2465,7 @@ void
iterate_over_block_arg_vars (const struct block *b, iterate_over_block_arg_vars (const struct block *b,
iterate_over_block_arg_local_vars_cb cb) iterate_over_block_arg_local_vars_cb cb)
{ {
struct block_iterator iter; for (struct symbol *sym : block_iterator_range (b))
struct symbol *sym, *sym2;
ALL_BLOCK_SYMBOLS (b, iter, sym)
{ {
/* Don't worry about things which aren't arguments. */ /* Don't worry about things which aren't arguments. */
if (sym->is_argument ()) if (sym->is_argument ())
@ -2489,8 +2481,9 @@ iterate_over_block_arg_vars (const struct block *b,
float). There are also LOC_ARG/LOC_REGISTER pairs which float). There are also LOC_ARG/LOC_REGISTER pairs which
are not combined in symbol-reading. */ are not combined in symbol-reading. */
sym2 = lookup_symbol_search_name (sym->search_name (), struct symbol *sym2
b, VAR_DOMAIN).symbol; = lookup_symbol_search_name (sym->search_name (),
b, VAR_DOMAIN).symbol;
cb (sym->print_name (), sym2); cb (sym->print_name (), sym2);
} }
} }

View File

@ -2880,22 +2880,24 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
if (section != 0) if (section != 0)
{ {
struct symbol *sym = NULL; struct symbol *found_sym = nullptr;
struct block_iterator iter;
for (int b_index = GLOBAL_BLOCK; for (int b_index = GLOBAL_BLOCK;
b_index <= STATIC_BLOCK && sym == NULL; b_index <= STATIC_BLOCK && found_sym == nullptr;
++b_index) ++b_index)
{ {
const struct block *b = bv->block (b_index); const struct block *b = bv->block (b_index);
ALL_BLOCK_SYMBOLS (b, iter, sym) for (struct symbol *sym : block_iterator_range (b))
{ {
if (matching_obj_sections (sym->obj_section (obj_file), if (matching_obj_sections (sym->obj_section (obj_file),
section)) section))
break; {
found_sym = sym;
break;
}
} }
} }
if (sym == NULL) if (found_sym == nullptr)
continue; /* No symbol in this symtab matches continue; /* No symbol in this symtab matches
section. */ section. */
} }
@ -2946,10 +2948,8 @@ find_symbol_at_address (CORE_ADDR address)
for (int i = GLOBAL_BLOCK; i <= STATIC_BLOCK; ++i) for (int i = GLOBAL_BLOCK; i <= STATIC_BLOCK; ++i)
{ {
const struct block *b = bv->block (i); const struct block *b = bv->block (i);
struct block_iterator iter;
struct symbol *sym;
ALL_BLOCK_SYMBOLS (b, iter, sym) for (struct symbol *sym : block_iterator_range (b))
{ {
if (sym->aclass () == LOC_STATIC if (sym->aclass () == LOC_STATIC
&& sym->value_address () == addr) && sym->value_address () == addr)
@ -4709,11 +4709,9 @@ global_symbol_searcher::add_matching_symbols
for (block_enum block : { GLOBAL_BLOCK, STATIC_BLOCK }) for (block_enum block : { GLOBAL_BLOCK, STATIC_BLOCK })
{ {
struct block_iterator iter;
struct symbol *sym;
const struct block *b = bv->block (block); const struct block *b = bv->block (block);
ALL_BLOCK_SYMBOLS (b, iter, sym) for (struct symbol *sym : block_iterator_range (b))
{ {
struct symtab *real_symtab = sym->symtab (); struct symtab *real_symtab = sym->symtab ();
@ -5673,8 +5671,6 @@ add_symtab_completions (struct compunit_symtab *cust,
const char *text, const char *word, const char *text, const char *word,
enum type_code code) enum type_code code)
{ {
struct symbol *sym;
struct block_iterator iter;
int i; int i;
if (cust == NULL) if (cust == NULL)
@ -5685,7 +5681,7 @@ add_symtab_completions (struct compunit_symtab *cust,
QUIT; QUIT;
const struct block *b = cust->blockvector ()->block (i); const struct block *b = cust->blockvector ()->block (i);
ALL_BLOCK_SYMBOLS (b, iter, sym) for (struct symbol *sym : block_iterator_range (b))
{ {
if (completion_skip_symbol (mode, sym)) if (completion_skip_symbol (mode, sym))
continue; continue;
@ -5711,10 +5707,8 @@ default_collect_symbol_completion_matches_break_on
frees them. I'm not going to worry about this; hopefully there frees them. I'm not going to worry about this; hopefully there
won't be that many. */ won't be that many. */
struct symbol *sym;
const struct block *b; const struct block *b;
const struct block *surrounding_static_block, *surrounding_global_block; const struct block *surrounding_static_block, *surrounding_global_block;
struct block_iterator iter;
/* The symbol we are completing on. Points in same buffer as text. */ /* The symbol we are completing on. Points in same buffer as text. */
const char *sym_text; const char *sym_text;
@ -5835,7 +5829,7 @@ default_collect_symbol_completion_matches_break_on
{ {
QUIT; QUIT;
ALL_BLOCK_SYMBOLS (b, iter, sym) for (struct symbol *sym : block_iterator_range (b))
{ {
if (code == TYPE_CODE_UNDEF) if (code == TYPE_CODE_UNDEF)
{ {
@ -5863,12 +5857,12 @@ default_collect_symbol_completion_matches_break_on
if (code == TYPE_CODE_UNDEF) if (code == TYPE_CODE_UNDEF)
{ {
if (surrounding_static_block != NULL) if (surrounding_static_block != NULL)
ALL_BLOCK_SYMBOLS (surrounding_static_block, iter, sym) for (struct symbol *sym : block_iterator_range (surrounding_static_block))
completion_list_add_fields (tracker, sym, lookup_name, completion_list_add_fields (tracker, sym, lookup_name,
sym_text, word); sym_text, word);
if (surrounding_global_block != NULL) if (surrounding_global_block != NULL)
ALL_BLOCK_SYMBOLS (surrounding_global_block, iter, sym) for (struct symbol *sym : block_iterator_range (surrounding_global_block))
completion_list_add_fields (tracker, sym, lookup_name, completion_list_add_fields (tracker, sym, lookup_name,
sym_text, word); sym_text, word);
} }

View File

@ -2459,12 +2459,10 @@ tfind_outside_command (const char *args, int from_tty)
static void static void
info_scope_command (const char *args_in, int from_tty) info_scope_command (const char *args_in, int from_tty)
{ {
struct symbol *sym;
struct bound_minimal_symbol msym; struct bound_minimal_symbol msym;
const struct block *block; const struct block *block;
const char *symname; const char *symname;
const char *save_args = args_in; const char *save_args = args_in;
struct block_iterator iter;
int j, count = 0; int j, count = 0;
struct gdbarch *gdbarch; struct gdbarch *gdbarch;
int regno; int regno;
@ -2492,7 +2490,7 @@ info_scope_command (const char *args_in, int from_tty)
while (block != 0) while (block != 0)
{ {
QUIT; /* Allow user to bail out with ^C. */ QUIT; /* Allow user to bail out with ^C. */
ALL_BLOCK_SYMBOLS (block, iter, sym) for (struct symbol *sym : block_iterator_range (block))
{ {
QUIT; /* Allow user to bail out with ^C. */ QUIT; /* Allow user to bail out with ^C. */
if (count == 0) if (count == 0)