forked from Imagelibrary/binutils-gdb
Simplify resolve_subexp by using C++ algorithms
This changes resolve_subexp to use any_of and the erase-remove idiom to simplify the code somewhat. This simplifies the next patch a bit. gdb/ChangeLog 2021-03-02 Tom Tromey <tromey@adacore.com> * ada-lang.c (resolve_subexp): Use any_of and erase-remove idiom.
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
2021-03-02 Tom Tromey <tromey@adacore.com>
|
||||||
|
|
||||||
|
* ada-lang.c (resolve_subexp): Use any_of and erase-remove idiom.
|
||||||
|
|
||||||
2021-03-02 Tom Tromey <tromey@adacore.com>
|
2021-03-02 Tom Tromey <tromey@adacore.com>
|
||||||
|
|
||||||
* ada-lang.c (struct ada_symbol_cache) <cache_space>: Now an
|
* ada-lang.c (struct ada_symbol_cache) <cache_space>: Now an
|
||||||
|
|||||||
@@ -3660,15 +3660,14 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
|
|||||||
ada_lookup_symbol_list (exp->elts[pc + 2].symbol->linkage_name (),
|
ada_lookup_symbol_list (exp->elts[pc + 2].symbol->linkage_name (),
|
||||||
exp->elts[pc + 1].block, VAR_DOMAIN,
|
exp->elts[pc + 1].block, VAR_DOMAIN,
|
||||||
&candidates);
|
&candidates);
|
||||||
|
/* Paranoia. */
|
||||||
|
candidates.resize (n_candidates);
|
||||||
|
|
||||||
if (n_candidates > 1)
|
if (std::any_of (candidates.begin (),
|
||||||
|
candidates.end (),
|
||||||
|
[] (block_symbol &sym)
|
||||||
{
|
{
|
||||||
/* Types tend to get re-introduced locally, so if there
|
switch (SYMBOL_CLASS (sym.symbol))
|
||||||
are any local symbols that are not types, first filter
|
|
||||||
out all types. */
|
|
||||||
int j;
|
|
||||||
for (j = 0; j < n_candidates; j += 1)
|
|
||||||
switch (SYMBOL_CLASS (candidates[j].symbol))
|
|
||||||
{
|
{
|
||||||
case LOC_REGISTER:
|
case LOC_REGISTER:
|
||||||
case LOC_ARG:
|
case LOC_ARG:
|
||||||
@@ -3676,25 +3675,25 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
|
|||||||
case LOC_REGPARM_ADDR:
|
case LOC_REGPARM_ADDR:
|
||||||
case LOC_LOCAL:
|
case LOC_LOCAL:
|
||||||
case LOC_COMPUTED:
|
case LOC_COMPUTED:
|
||||||
goto FoundNonType;
|
return true;
|
||||||
default:
|
default:
|
||||||
break;
|
return false;
|
||||||
}
|
}
|
||||||
FoundNonType:
|
}))
|
||||||
if (j < n_candidates)
|
|
||||||
{
|
{
|
||||||
j = 0;
|
/* Types tend to get re-introduced locally, so if there
|
||||||
while (j < n_candidates)
|
are any local symbols that are not types, first filter
|
||||||
|
out all types. */
|
||||||
|
candidates.erase
|
||||||
|
(std::remove_if
|
||||||
|
(candidates.begin (),
|
||||||
|
candidates.end (),
|
||||||
|
[] (block_symbol &sym)
|
||||||
{
|
{
|
||||||
if (SYMBOL_CLASS (candidates[j].symbol) == LOC_TYPEDEF)
|
return SYMBOL_CLASS (sym.symbol) == LOC_TYPEDEF;
|
||||||
{
|
}),
|
||||||
candidates[j] = candidates[n_candidates - 1];
|
candidates.end ());
|
||||||
n_candidates -= 1;
|
n_candidates = candidates.size ();
|
||||||
}
|
|
||||||
else
|
|
||||||
j += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n_candidates == 0)
|
if (n_candidates == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user