diff options
author | Tom Tromey <tromey@adacore.com> | 2021-03-02 13:00:45 -0700 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2021-03-02 13:00:45 -0700 |
commit | 886d459fbea73da4b07bae37f4526b766cbd90e8 (patch) | |
tree | a72eacd92ad227823cade0255da0fbc1eda22a9c /gdb | |
parent | bdcccc56393c26b86265f94d4fcf55c20c938ab7 (diff) | |
download | binutils-886d459fbea73da4b07bae37f4526b766cbd90e8.zip binutils-886d459fbea73da4b07bae37f4526b766cbd90e8.tar.gz binutils-886d459fbea73da4b07bae37f4526b766cbd90e8.tar.bz2 |
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.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 4 | ||||
-rw-r--r-- | gdb/ada-lang.c | 57 |
2 files changed, 32 insertions, 29 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8f5bc1d..282df4c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,9 @@ 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> + * ada-lang.c (struct ada_symbol_cache) <cache_space>: Now an auto_obstack. <root>: Initialize. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 7ab423b..c3e562c 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -3660,41 +3660,40 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p, ada_lookup_symbol_list (exp->elts[pc + 2].symbol->linkage_name (), exp->elts[pc + 1].block, VAR_DOMAIN, &candidates); + /* Paranoia. */ + candidates.resize (n_candidates); - if (n_candidates > 1) + if (std::any_of (candidates.begin (), + candidates.end (), + [] (block_symbol &sym) + { + switch (SYMBOL_CLASS (sym.symbol)) + { + case LOC_REGISTER: + case LOC_ARG: + case LOC_REF_ARG: + case LOC_REGPARM_ADDR: + case LOC_LOCAL: + case LOC_COMPUTED: + return true; + default: + return false; + } + })) { /* Types tend to get re-introduced locally, so if there 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)) + candidates.erase + (std::remove_if + (candidates.begin (), + candidates.end (), + [] (block_symbol &sym) { - case LOC_REGISTER: - case LOC_ARG: - case LOC_REF_ARG: - case LOC_REGPARM_ADDR: - case LOC_LOCAL: - case LOC_COMPUTED: - goto FoundNonType; - default: - break; - } - FoundNonType: - if (j < n_candidates) - { - j = 0; - while (j < n_candidates) - { - if (SYMBOL_CLASS (candidates[j].symbol) == LOC_TYPEDEF) - { - candidates[j] = candidates[n_candidates - 1]; - n_candidates -= 1; - } - else - j += 1; - } - } + return SYMBOL_CLASS (sym.symbol) == LOC_TYPEDEF; + }), + candidates.end ()); + n_candidates = candidates.size (); } if (n_candidates == 0) |