Add symbol::matches method

This adds symbol::matches, a wrapper for symbol_matches_domain.  Most
places calling symbol_matches_domain can call this method instead,
which is a bit less wordy and also (IMO) clearer.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
This commit is contained in:
Tom Tromey
2023-03-14 16:56:38 -06:00
parent 8c329d5c65
commit 911e1e795e
5 changed files with 21 additions and 19 deletions

View File

@@ -6051,7 +6051,7 @@ ada_add_block_symbols (std::vector<struct block_symbol> &result,
found_sym = false; found_sym = false;
for (struct symbol *sym : block_iterator_range (block, &lookup_name)) for (struct symbol *sym : block_iterator_range (block, &lookup_name))
{ {
if (symbol_matches_domain (sym->language (), sym->domain (), domain)) if (sym->matches (domain))
{ {
if (sym->aclass () != LOC_UNRESOLVED) if (sym->aclass () != LOC_UNRESOLVED)
{ {
@@ -6086,8 +6086,7 @@ ada_add_block_symbols (std::vector<struct block_symbol> &result,
for (struct symbol *sym : block_iterator_range (block)) for (struct symbol *sym : block_iterator_range (block))
{ {
if (symbol_matches_domain (sym->language (), if (sym->matches (domain))
sym->domain (), domain))
{ {
int cmp; int cmp;

View File

@@ -680,8 +680,7 @@ block_lookup_symbol (const struct block *block, const char *name,
STRUCT vs VAR domain symbols. So if a matching symbol is found, STRUCT vs VAR domain symbols. So if a matching symbol is found,
make sure there is no "better" matching symbol, i.e., one with make sure there is no "better" matching symbol, i.e., one with
exactly the same domain. PR 16253. */ exactly the same domain. PR 16253. */
if (symbol_matches_domain (sym->language (), if (sym->matches (domain))
sym->domain (), domain))
other = better_symbol (other, sym, domain); other = better_symbol (other, sym, domain);
} }
return other; return other;
@@ -701,8 +700,7 @@ block_lookup_symbol (const struct block *block, const char *name,
for (struct symbol *sym : block_iterator_range (block, &lookup_name)) for (struct symbol *sym : block_iterator_range (block, &lookup_name))
{ {
if (symbol_matches_domain (sym->language (), if (sym->matches (domain))
sym->domain (), domain))
{ {
sym_found = sym; sym_found = sym;
if (!sym->is_argument ()) if (!sym->is_argument ())
@@ -766,11 +764,11 @@ block_lookup_symbol_primary (const struct block *block, const char *name,
if (best_symbol (sym, domain)) if (best_symbol (sym, domain))
return sym; return sym;
/* This is a bit of a hack, but symbol_matches_domain might ignore /* This is a bit of a hack, but 'matches' might ignore
STRUCT vs VAR domain symbols. So if a matching symbol is found, STRUCT vs VAR domain symbols. So if a matching symbol is found,
make sure there is no "better" matching symbol, i.e., one with make sure there is no "better" matching symbol, i.e., one with
exactly the same domain. PR 16253. */ exactly the same domain. PR 16253. */
if (symbol_matches_domain (sym->language (), sym->domain (), domain)) if (sym->matches (domain))
other = better_symbol (other, sym, domain); other = better_symbol (other, sym, domain);
} }
@@ -794,7 +792,7 @@ block_find_symbol (const struct block *block, const char *name,
{ {
/* MATCHER is deliberately called second here so that it never sees /* MATCHER is deliberately called second here so that it never sees
a non-domain-matching symbol. */ a non-domain-matching symbol. */
if (symbol_matches_domain (sym->language (), sym->domain (), domain) if (sym->matches (domain)
&& matcher (sym, data)) && matcher (sym, data))
return sym; return sym;
} }

View File

@@ -3908,8 +3908,7 @@ find_label_symbols_in_block (const struct block *block,
for (struct symbol *sym : block_iterator_range (block)) for (struct symbol *sym : block_iterator_range (block))
{ {
if (symbol_matches_domain (sym->language (), if (sym->matches (LABEL_DOMAIN)
sym->domain (), LABEL_DOMAIN)
&& cmp (sym->search_name (), name, name_len) == 0) && cmp (sym->search_name (), name, name_len) == 0)
{ {
result->push_back ({sym, block}); result->push_back ({sym, block});

View File

@@ -2288,8 +2288,7 @@ lookup_symbol_in_objfile_symtabs (struct objfile *objfile,
other = result; other = result;
break; break;
} }
if (symbol_matches_domain (result.symbol->language (), if (result.symbol->matches (domain))
result.symbol->domain (), domain))
{ {
struct symbol *better struct symbol *better
= better_symbol (other.symbol, result.symbol, domain); = better_symbol (other.symbol, result.symbol, domain);
@@ -2777,7 +2776,7 @@ iterate_over_symbols (const struct block *block,
{ {
for (struct symbol *sym : block_iterator_range (block, &name)) for (struct symbol *sym : block_iterator_range (block, &name))
{ {
if (symbol_matches_domain (sym->language (), sym->domain (), domain)) if (sym->matches (domain))
{ {
struct block_symbol block_sym = {sym, block}; struct block_symbol block_sym = {sym, block};

View File

@@ -1226,6 +1226,10 @@ enum symbol_subclass_kind
extern gdb::array_view<const struct symbol_impl> symbol_impls; extern gdb::array_view<const struct symbol_impl> symbol_impls;
bool symbol_matches_domain (enum language symbol_language,
domain_enum symbol_domain,
domain_enum domain);
/* This structure is space critical. See space comments at the top. */ /* This structure is space critical. See space comments at the top. */
struct symbol : public general_symbol_info, public allocate_on_obstack struct symbol : public general_symbol_info, public allocate_on_obstack
@@ -1272,6 +1276,13 @@ struct symbol : public general_symbol_info, public allocate_on_obstack
return this->impl ().aclass; return this->impl ().aclass;
} }
/* Call symbol_matches_domain on this symbol, using the symbol's
domain. */
bool matches (domain_enum d) const
{
return symbol_matches_domain (language (), domain (), d);
}
domain_enum domain () const domain_enum domain () const
{ {
return m_domain; return m_domain;
@@ -2021,10 +2032,6 @@ extern const char multiple_symbols_cancel[];
const char *multiple_symbols_select_mode (void); const char *multiple_symbols_select_mode (void);
bool symbol_matches_domain (enum language symbol_language,
domain_enum symbol_domain,
domain_enum domain);
/* lookup a symbol table by source file name. */ /* lookup a symbol table by source file name. */
extern struct symtab *lookup_symtab (const char *); extern struct symtab *lookup_symtab (const char *);