From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ELg2Lt+Y71/aTQAAWB0awg (envelope-from ) for ; Fri, 01 Jan 2021 16:49:19 -0500 Received: by simark.ca (Postfix, from userid 112) id BB23E1F0B8; Fri, 1 Jan 2021 16:49:19 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED, MAILING_LIST_MULTI,T_DKIM_INVALID,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 39F3D1F0AA for ; Fri, 1 Jan 2021 16:49:13 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1AE1E389852A; Fri, 1 Jan 2021 21:48:45 +0000 (GMT) Received: from gateway33.websitewelcome.com (gateway33.websitewelcome.com [192.185.146.130]) by sourceware.org (Postfix) with ESMTPS id 0C4A53896C2A for ; Fri, 1 Jan 2021 21:48:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0C4A53896C2A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway33.websitewelcome.com (Postfix) with ESMTP id A034D10EB936 for ; Fri, 1 Jan 2021 15:48:38 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id vSHmka1kcnPrxvSHmkleBw; Fri, 01 Jan 2021 15:48:38 -0600 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=FoDJMc4jMt6sSfie8oYAqBtZaXfoA9Y8S7R/QV9p+XI=; b=lRlSEhFI5Q7TE9Am1CItavWvEc nlGZWbGjED5LcWpLjz8BMh68kNn63Nz0O6ZV7oBKyr5hDe2YglfCW6hWkIKO3pMZZAyhmd8EsXXLA IB8zOuj1+p5WqJHPqwfqAE+Vj; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:60416 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kvSHm-0029oI-EY for gdb-patches@sourceware.org; Fri, 01 Jan 2021 14:48:38 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 151/203] Split out some Ada type resolution code Date: Fri, 1 Jan 2021 14:46:31 -0700 Message-Id: <20210101214723.1784144-152-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210101214723.1784144-1-tom@tromey.com> References: <20210101214723.1784144-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.81.39 X-Source-L: No X-Exim-ID: 1kvSHm-0029oI-EY X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:60416 X-Source-Auth: tom+tromey.com X-Email-Count: 152 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes 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: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" This splits some Ada type resolution code out of resolve_subexp into new functions that can be reused. gdb/ChangeLog 2021-01-01 Tom Tromey * ada-lang.h (ada_find_operator_symbol, ada_resolve_funcall) (ada_resolve_variable): Declare. * ada-lang.c (ada_find_operator_symbol, ada_resolve_funcall) (ada_resolve_variable): New functions. (resolve_subexp): Update. --- gdb/ChangeLog | 8 ++ gdb/ada-lang.c | 266 ++++++++++++++++++++++++++++--------------------- gdb/ada-lang.h | 18 ++++ 3 files changed, 176 insertions(+), 116 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index e2c9de69b65..50b82e6bcf9 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -3452,6 +3452,132 @@ See set/show multiple-symbol.")); return n_chosen; } +/* See ada-lang.h. */ + +block_symbol +ada_find_operator_symbol (enum exp_opcode op, int parse_completion, + int nargs, value *argvec[]) +{ + if (possible_user_operator_p (op, argvec)) + { + std::vector candidates; + int n_candidates = ada_lookup_symbol_list (ada_decoded_op_name (op), + NULL, VAR_DOMAIN, + &candidates); + int i = ada_resolve_function (candidates.data (), n_candidates, argvec, + nargs, ada_decoded_op_name (op), NULL, + parse_completion); + if (i >= 0) + return candidates[i]; + } + return {}; +} + +/* See ada-lang.h. */ + +block_symbol +ada_resolve_funcall (struct symbol *sym, const struct block *block, + struct type *context_type, + int parse_completion, + int nargs, value *argvec[], + innermost_block_tracker *tracker) +{ + std::vector candidates; + int n_candidates = ada_lookup_symbol_list (sym->linkage_name (), block, + VAR_DOMAIN, &candidates); + + int i; + if (n_candidates == 1) + i = 0; + else + { + i = ada_resolve_function (candidates.data (), n_candidates, + argvec, nargs, + sym->linkage_name (), + context_type, parse_completion); + if (i < 0) + error (_("Could not find a match for %s"), sym->print_name ()); + } + + tracker->update (candidates[i]); + return candidates[i]; +} + +/* See ada-lang.h. */ + +block_symbol +ada_resolve_variable (struct symbol *sym, const struct block *block, + struct type *context_type, + int parse_completion, + int deprocedure_p, + innermost_block_tracker *tracker) +{ + std::vector candidates; + int n_candidates = ada_lookup_symbol_list (sym->linkage_name (), + block, VAR_DOMAIN, + &candidates); + + if (n_candidates > 1) + { + /* 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)) + { + 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; + } + } + } + + int i; + if (n_candidates == 0) + error (_("No definition found for %s"), sym->print_name ()); + else if (n_candidates == 1) + i = 0; + else if (deprocedure_p + && !is_nonfunction (candidates.data (), n_candidates)) + { + i = ada_resolve_function (candidates.data (), n_candidates, NULL, 0, + sym->linkage_name (), + context_type, parse_completion); + if (i < 0) + error (_("Could not find a match for %s"), sym->print_name ()); + } + else + { + printf_filtered (_("Multiple matches for %s\n"), sym->print_name ()); + user_select_syms (candidates.data (), n_candidates, 1); + i = 0; + } + + tracker->update (candidates[i]); + return candidates[i]; +} + /* Resolve the operator of the subexpression beginning at position *POS of *EXPP. "Resolving" consists of replacing the symbols that have undefined namespaces in OP_VAR_VALUE nodes @@ -3640,77 +3766,13 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p, case OP_VAR_VALUE: if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN) { - std::vector candidates; - int n_candidates; - - n_candidates = - ada_lookup_symbol_list (exp->elts[pc + 2].symbol->linkage_name (), - exp->elts[pc + 1].block, VAR_DOMAIN, - &candidates); - - if (n_candidates > 1) - { - /* 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)) - { - 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; - } - } - } - - if (n_candidates == 0) - error (_("No definition found for %s"), - exp->elts[pc + 2].symbol->print_name ()); - else if (n_candidates == 1) - i = 0; - else if (deprocedure_p - && !is_nonfunction (candidates.data (), n_candidates)) - { - i = ada_resolve_function - (candidates.data (), n_candidates, NULL, 0, - exp->elts[pc + 2].symbol->linkage_name (), - context_type, parse_completion); - if (i < 0) - error (_("Could not find a match for %s"), - exp->elts[pc + 2].symbol->print_name ()); - } - else - { - printf_filtered (_("Multiple matches for %s\n"), - exp->elts[pc + 2].symbol->print_name ()); - user_select_syms (candidates.data (), n_candidates, 1); - i = 0; - } - - exp->elts[pc + 1].block = candidates[i].block; - exp->elts[pc + 2].symbol = candidates[i].symbol; - tracker->update (candidates[i]); + block_symbol resolved + = ada_resolve_variable (exp->elts[pc + 2].symbol, + exp->elts[pc + 1].block, + context_type, parse_completion, + deprocedure_p, tracker); + exp->elts[pc + 1].block = resolved.block; + exp->elts[pc + 2].symbol = resolved.symbol; } if (deprocedure_p @@ -3729,31 +3791,14 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p, if (exp->elts[pc + 3].opcode == OP_VAR_VALUE && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN) { - std::vector candidates; - int n_candidates; - - n_candidates = - ada_lookup_symbol_list (exp->elts[pc + 5].symbol->linkage_name (), - exp->elts[pc + 4].block, VAR_DOMAIN, - &candidates); - - if (n_candidates == 1) - i = 0; - else - { - i = ada_resolve_function - (candidates.data (), n_candidates, - argvec, nargs, - exp->elts[pc + 5].symbol->linkage_name (), - context_type, parse_completion); - if (i < 0) - error (_("Could not find a match for %s"), - exp->elts[pc + 5].symbol->print_name ()); - } - - exp->elts[pc + 4].block = candidates[i].block; - exp->elts[pc + 5].symbol = candidates[i].symbol; - tracker->update (candidates[i]); + block_symbol resolved + = ada_resolve_funcall (exp->elts[pc + 5].symbol, + exp->elts[pc + 4].block, + context_type, parse_completion, + nargs, argvec, + tracker); + exp->elts[pc + 4].block = resolved.block; + exp->elts[pc + 5].symbol = resolved.symbol; } } break; @@ -3778,27 +3823,16 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p, case UNOP_PLUS: case UNOP_LOGICAL_NOT: case UNOP_ABS: - if (possible_user_operator_p (op, argvec)) - { - std::vector candidates; - int n_candidates; - - n_candidates = - ada_lookup_symbol_list (ada_decoded_op_name (op), - NULL, VAR_DOMAIN, - &candidates); - - i = ada_resolve_function (candidates.data (), n_candidates, argvec, - nargs, ada_decoded_op_name (op), NULL, - parse_completion); - if (i < 0) - break; + { + block_symbol found = ada_find_operator_symbol (op, parse_completion, + nargs, argvec); + if (found.symbol == nullptr) + break; - replace_operator_with_call (expp, pc, nargs, 1, - candidates[i].symbol, - candidates[i].block); - exp = expp->get (); - } + replace_operator_with_call (expp, pc, nargs, 1, + found.symbol, found.block); + exp = expp->get (); + } break; case OP_TYPE: diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h index dbf45a84928..8333def6280 100644 --- a/gdb/ada-lang.h +++ b/gdb/ada-lang.h @@ -386,4 +386,22 @@ extern void print_ada_task_info (struct ui_out *uiout, const char *taskno_str, struct inferior *inf); +extern block_symbol ada_find_operator_symbol (enum exp_opcode op, + int parse_completion, + int nargs, value *argvec[]); + +extern block_symbol ada_resolve_funcall (struct symbol *sym, + const struct block *block, + struct type *context_type, + int parse_completion, + int nargs, value *argvec[], + innermost_block_tracker *tracker); + +extern block_symbol ada_resolve_variable (struct symbol *sym, + const struct block *block, + struct type *context_type, + int parse_completion, + int deprocedure_p, + innermost_block_tracker *tracker); + #endif -- 2.26.2