From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTP id 4CFE9398B14D for ; Thu, 18 Feb 2021 18:04:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4CFE9398B14D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 24721116ED7; Thu, 18 Feb 2021 13:04:33 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id pHGtLtJbaNCD; Thu, 18 Feb 2021 13:04:33 -0500 (EST) Received: from murgatroyd.Home (97-122-70-152.hlrn.qwest.net [97.122.70.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id C729511671A; Thu, 18 Feb 2021 13:04:32 -0500 (EST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/4] Simplify resolve_subexp by using C++ algorithms Date: Thu, 18 Feb 2021 11:04:28 -0700 Message-Id: <20210218180430.326137-3-tromey@adacore.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210218180430.326137-1-tromey@adacore.com> References: <20210218180430.326137-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_STOCKGEN, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Feb 2021 18:04:42 -0000 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-02-18 Tom Tromey * ada-lang.c (resolve_subexp): Use any_of and erase-remove idiom. --- gdb/ChangeLog | 4 ++++ gdb/ada-lang.c | 57 +++++++++++++++++++++++++------------------------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index e2b2e6105b0..db4f3591131 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) -- 2.26.2