From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GD+iM+mY718XTQAAWB0awg (envelope-from ) for ; Fri, 01 Jan 2021 16:49:29 -0500 Received: by simark.ca (Postfix, from userid 112) id 87D9E1F0BC; Fri, 1 Jan 2021 16:49:28 -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.4 required=5.0 tests=DKIM_SIGNED,MAILING_LIST_MULTI, RDNS_NONE,T_DKIM_INVALID,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [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 BD34C1F0B8 for ; Fri, 1 Jan 2021 16:49:26 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A53B03938C1A; Fri, 1 Jan 2021 21:48:53 +0000 (GMT) Received: from gateway30.websitewelcome.com (gateway30.websitewelcome.com [192.185.152.11]) by sourceware.org (Postfix) with ESMTPS id 4F4023938395 for ; Fri, 1 Jan 2021 21:48:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4F4023938395 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 cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway30.websitewelcome.com (Postfix) with ESMTP id EF29126BF for ; Fri, 1 Jan 2021 15:48:48 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id vSHwkJAqduDoAvSHwkcclq; Fri, 01 Jan 2021 15:48:48 -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=bQOsv1Uz48tzHBOaL1gNRBE5VhxzbPCAm9XHr3vhXHA=; b=vsG0pZMtEM50DjciWiJCC9nGEH 3qTk9YG2tiUrN5aN40D5agN+YeXcDbpx03TAviuSHPnCZ6QKHqt+EhOYhzV/MyrFoZXj5W/W4nqLm yaDGUCIF+g4pTxcWSX0HLddxC; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:60422 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 1kvSHw-0029t6-NQ for gdb-patches@sourceware.org; Fri, 01 Jan 2021 14:48:48 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 169/203] Implement Ada resolution Date: Fri, 1 Jan 2021 14:46:49 -0700 Message-Id: <20210101214723.1784144-170-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: 1kvSHw-0029t6-NQ X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:60422 X-Source-Auth: tom+tromey.com X-Email-Count: 170 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" Ada has a parser post-pass that implements "resolution". This process replaces some opcodes with function calls. For example, a "+" operation might be replaced with a call to the appropriate overloaded function. This differs from the approach taken for the same problem in C++. However, in this series I chose not to try to make changes outside of rewrite the expression data structure. So, resolution remains. The new approach to resolution is to introduce an interface class, that some concrete operations implement. Then, the Ada code will use this to resolve the expression tree. Because new-style expressions are built as ordinary objects, and don't require rewriting the data structure in place, in the new code this processing will be done in the parser. By the end of the series, some special cases in this area that exist only for Ada will be removed. gdb/ChangeLog 2021-01-01 Tom Tromey * ada-lang.c (ada_var_value_operation::resolve) (ada_funcall_operation::resolve): New methods. * ada-exp.h (struct ada_resolvable): New. (class ada_var_value_operation): Derive from ada_resolvable. : New methods. (class ada_funcall_operation): Derive from ada_resolvable. : New method. --- gdb/ChangeLog | 10 ++++++++ gdb/ada-exp.h | 38 ++++++++++++++++++++++++++++-- gdb/ada-lang.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 2 deletions(-) diff --git a/gdb/ada-exp.h b/gdb/ada-exp.h index 287ed5cc62c..2c5696cab76 100644 --- a/gdb/ada-exp.h +++ b/gdb/ada-exp.h @@ -304,9 +304,27 @@ class ada_unop_atr_operation { return std::get<1> (m_storage); } }; +/* The base class for Ada type resolution. Ada operations that want + to participate in resolution implement this interface. */ +struct ada_resolvable +{ + /* Resolve this object. EXP is the expression being resolved. + DEPROCEDURE_P is true if de-proceduring is desired. + PARSE_COMPLETION and TRACKER are passed in from the parser + context. CONTEXT_TYPE is the expected type of the expression, or + nullptr if none is known. This method should return true if the + operation should be replaced by a function call with this object + as the callee. */ + virtual bool resolve (struct expression *exp, + bool deprocedure_p, + bool parse_completion, + innermost_block_tracker *tracker, + struct type *context_type) = 0; +}; + /* Variant of var_value_operation for Ada. */ class ada_var_value_operation - : public var_value_operation + : public var_value_operation, public ada_resolvable { public: @@ -323,6 +341,15 @@ class ada_var_value_operation symbol *get_symbol () const { return std::get<0> (m_storage); } + const block *get_block () const + { return std::get<1> (m_storage); } + + bool resolve (struct expression *exp, + bool deprocedure_p, + bool parse_completion, + innermost_block_tracker *tracker, + struct type *context_type) override; + protected: using operation::do_generate_ax; @@ -392,7 +419,8 @@ class ada_structop_operation /* Function calls for Ada. */ class ada_funcall_operation - : public tuple_holding_operation> + : public tuple_holding_operation>, + public ada_resolvable { public: @@ -402,6 +430,12 @@ class ada_funcall_operation struct expression *exp, enum noside noside) override; + bool resolve (struct expression *exp, + bool deprocedure_p, + bool parse_completion, + innermost_block_tracker *tracker, + struct type *context_type) override; + enum exp_opcode opcode () const override { return OP_FUNCALL; } }; diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 18f250b5a34..fa323331047 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -10836,6 +10836,31 @@ ada_var_value_operation::evaluate (struct type *expect_type, return ada_to_fixed_value (arg1); } +bool +ada_var_value_operation::resolve (struct expression *exp, + bool deprocedure_p, + bool parse_completion, + innermost_block_tracker *tracker, + struct type *context_type) +{ + symbol *sym = std::get<0> (m_storage); + if (SYMBOL_DOMAIN (sym) == UNDEF_DOMAIN) + { + block_symbol resolved + = ada_resolve_variable (sym, std::get<1> (m_storage), + context_type, parse_completion, + deprocedure_p, tracker); + std::get<0> (m_storage) = resolved.symbol; + std::get<1> (m_storage) = resolved.block; + } + + if (deprocedure_p + && SYMBOL_TYPE (std::get<0> (m_storage))->code () == TYPE_CODE_FUNC) + return true; + + return false; +} + value * ada_atr_val_operation::evaluate (struct type *expect_type, struct expression *exp, @@ -11114,6 +11139,44 @@ ada_funcall_operation::evaluate (struct type *expect_type, } } +bool +ada_funcall_operation::resolve (struct expression *exp, + bool deprocedure_p, + bool parse_completion, + innermost_block_tracker *tracker, + struct type *context_type) +{ + operation_up &callee_op = std::get<0> (m_storage); + + ada_var_value_operation *avv + = dynamic_cast (callee_op.get ()); + if (avv == nullptr) + return false; + + symbol *sym = avv->get_symbol (); + if (SYMBOL_DOMAIN (sym) != UNDEF_DOMAIN) + return false; + + const std::vector &args_up = std::get<1> (m_storage); + int nargs = args_up.size (); + std::vector argvec (nargs); + + for (int i = 0; i < args_up.size (); ++i) + argvec[i] = args_up[i]->evaluate (nullptr, exp, EVAL_AVOID_SIDE_EFFECTS); + + const block *block = avv->get_block (); + block_symbol resolved + = ada_resolve_funcall (sym, block, + context_type, parse_completion, + nargs, argvec.data (), + tracker); + + std::get<0> (m_storage) + = make_operation (resolved.symbol, + resolved.block); + return false; +} + } /* Implement the evaluate_exp routine in the exp_descriptor structure -- 2.26.2