Remove ALL_DICT_SYMBOLS

This replaces ALL_DICT_SYMBOLS with an iterator so that for-each can
be used.
This commit is contained in:
Tom Tromey 2023-04-16 09:10:02 -06:00
parent 5250cbc85c
commit 8e8d48f91c
5 changed files with 55 additions and 28 deletions

View File

@ -143,6 +143,10 @@ struct block : public allocate_on_obstack
multidictionary *multidict () const
{ return m_multidict; }
/* Return an iterator range for this block's multidict. */
iterator_range<mdict_iterator_wrapper> multidict_symbols () const
{ return iterator_range<mdict_iterator_wrapper> (m_multidict); }
/* Set this block's multidict. */
void set_multidict (multidictionary *multidict)
{ m_multidict = multidict; }

View File

@ -244,7 +244,6 @@ buildsym_compunit::finish_block_internal
if (symbol)
{
struct type *ftype = symbol->type ();
struct mdict_iterator miter;
symbol->set_value_block (block);
symbol->set_section_index (SECT_OFF_TEXT (m_objfile));
block->set_function (symbol);
@ -255,11 +254,10 @@ buildsym_compunit::finish_block_internal
function's type. Set that from the type of the
parameter symbols. */
int nparams = 0, iparams;
struct symbol *sym;
/* Here we want to directly access the dictionary, because
we haven't fully initialized the block yet. */
ALL_DICT_SYMBOLS (block->multidict (), miter, sym)
for (struct symbol *sym : block->multidict_symbols ())
{
if (sym->is_argument ())
nparams++;
@ -274,7 +272,7 @@ buildsym_compunit::finish_block_internal
iparams = 0;
/* Here we want to directly access the dictionary, because
we haven't fully initialized the block yet. */
ALL_DICT_SYMBOLS (block->multidict (), miter, sym)
for (struct symbol *sym : block->multidict_symbols ())
{
if (iparams == nparams)
break;
@ -975,8 +973,6 @@ buildsym_compunit::end_compunit_symtab_with_blockvector
for (block_i = 0; block_i < blockvector->num_blocks (); block_i++)
{
struct block *block = blockvector->block (block_i);
struct symbol *sym;
struct mdict_iterator miter;
/* Inlined functions may have symbols not in the global or
static symbol lists. */
@ -985,9 +981,10 @@ buildsym_compunit::end_compunit_symtab_with_blockvector
block->function ()->set_symtab (symtab);
/* Note that we only want to fix up symbols from the local
blocks, not blocks coming from included symtabs. That is why
we use ALL_DICT_SYMBOLS here and not a block iterator. */
ALL_DICT_SYMBOLS (block->multidict (), miter, sym)
blocks, not blocks coming from included symtabs. That is
why we use an mdict iterator here and not a block
iterator. */
for (struct symbol *sym : block->multidict_symbols ())
if (sym->symtab () == NULL)
sym->set_symtab (symtab);
}

View File

@ -164,16 +164,49 @@ extern struct symbol *mdict_iter_match_next (const lookup_name_info &name,
extern int mdict_size (const struct multidictionary *mdict);
/* Macro to loop through all symbols in a dictionary DICT, in no
particular order. ITER is a struct dict_iterator (NOTE: __not__ a
struct dict_iterator *), and SYM points to the current symbol.
/* An iterator that wraps an mdict_iterator. The naming here is
unfortunate, but mdict_iterator was named before gdb switched to
C++. */
struct mdict_iterator_wrapper
{
typedef mdict_iterator_wrapper self_type;
typedef struct symbol *value_type;
It's implemented as a single loop, so you can terminate the loop
early by a break if you desire. */
explicit mdict_iterator_wrapper (const struct multidictionary *mdict)
: m_sym (mdict_iterator_first (mdict, &m_iter))
{
}
#define ALL_DICT_SYMBOLS(dict, iter, sym) \
for ((sym) = mdict_iterator_first ((dict), &(iter)); \
(sym); \
(sym) = mdict_iterator_next (&(iter)))
mdict_iterator_wrapper ()
: m_sym (nullptr)
{
}
value_type operator* () const
{
return m_sym;
}
bool operator== (const self_type &other) const
{
return m_sym == other.m_sym;
}
bool operator!= (const self_type &other) const
{
return m_sym != other.m_sym;
}
self_type &operator++ ()
{
m_sym = mdict_iterator_next (&m_iter);
return *this;
}
private:
struct symbol *m_sym;
struct mdict_iterator m_iter;
};
#endif /* DICTIONARY_H */

View File

@ -625,9 +625,6 @@ objfile_relocate1 (struct objfile *objfile,
for (block *b : bv->blocks ())
{
struct symbol *sym;
struct mdict_iterator miter;
b->set_start (b->start () + delta[block_line_section]);
b->set_end (b->end () + delta[block_line_section]);
@ -639,10 +636,8 @@ objfile_relocate1 (struct objfile *objfile,
/* We only want to iterate over the local symbols, not any
symbols in included symtabs. */
ALL_DICT_SYMBOLS (b->multidict (), miter, sym)
{
relocate_one_symbol (sym, objfile, delta);
}
for (struct symbol *sym : b->multidict_symbols ())
relocate_one_symbol (sym, objfile, delta);
}
}

View File

@ -236,9 +236,7 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
{
struct objfile *objfile = symtab->compunit ()->objfile ();
struct gdbarch *gdbarch = objfile->arch ();
struct mdict_iterator miter;
const struct linetable *l;
struct symbol *sym;
int depth;
gdb_printf (outfile, "\nSymtab for file %s at %s\n",
@ -307,7 +305,7 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
/* Now print each symbol in this block (in no particular order, if
we're using a hashtable). Note that we only want this
block, not any blocks from included symtabs. */
ALL_DICT_SYMBOLS (b->multidict (), miter, sym)
for (struct symbol *sym : b->multidict_symbols ())
{
try
{