From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id oObLL5SY71/2TAAAWB0awg (envelope-from ) for ; Fri, 01 Jan 2021 16:48:04 -0500 Received: by simark.ca (Postfix, from userid 112) id 6709F1F0C4; Fri, 1 Jan 2021 16:48:03 -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 5DE9C1F071 for ; Fri, 1 Jan 2021 16:48:01 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5A4693890411; Fri, 1 Jan 2021 21:47:53 +0000 (GMT) Received: from gateway33.websitewelcome.com (gateway33.websitewelcome.com [192.185.146.130]) by sourceware.org (Postfix) with ESMTPS id 892CE388E833 for ; Fri, 1 Jan 2021 21:47:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 892CE388E833 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 cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 2A084B98ACD for ; Fri, 1 Jan 2021 15:47:49 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id vSGzkzasbDT64vSGzk78wW; Fri, 01 Jan 2021 15:47:49 -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=vdTfdv7o6QoZkk2ZVj4AKZGixsifzbKsWNF4Ls5cQ+s=; b=fFZsDWc2CL4DZLWEO/XR9hq/bF DM9wbuKUBbt/vMf3sk4MxbinDQZ/15KwoMM5+A4te3MB14epdVrbe9acjL9FN0if3K8MW1+aMja0v evvOXKwv/5wid1cqXcjK2MQI+; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:60384 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 1kvSGy-0029E8-VE for gdb-patches@sourceware.org; Fri, 01 Jan 2021 14:47:49 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 051/203] Split helper functions Date: Fri, 1 Jan 2021 14:44:51 -0700 Message-Id: <20210101214723.1784144-52-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: 1kvSGy-0029E8-VE X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:60384 X-Source-Auth: tom+tromey.com X-Email-Count: 52 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 a couple of address-of and sizeof functions, so that the body can be reused by the (coming) new expression code. gdb/ChangeLog 2021-01-01 Tom Tromey * eval.c (evaluate_subexp_for_address_base): New function. (evaluate_subexp_for_address): Use it. (evaluate_subexp_for_sizeof_base): New function. (evaluate_subexp_for_sizeof): Use it. --- gdb/ChangeLog | 7 ++++++ gdb/eval.c | 65 +++++++++++++++++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/gdb/eval.c b/gdb/eval.c index 2907362f709..c27d80ba823 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -3056,6 +3056,29 @@ evaluate_subexp_standard (struct type *expect_type, gdb_assert_not_reached ("missed return?"); } +/* Helper for evaluate_subexp_for_address. */ + +static value * +evaluate_subexp_for_address_base (struct expression *exp, enum noside noside, + value *x) +{ + if (noside == EVAL_AVOID_SIDE_EFFECTS) + { + struct type *type = check_typedef (value_type (x)); + + if (TYPE_IS_REFERENCE (type)) + return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type)), + not_lval); + else if (VALUE_LVAL (x) == lval_memory || value_must_coerce_to_target (x)) + return value_zero (lookup_pointer_type (value_type (x)), + not_lval); + else + error (_("Attempt to take address of " + "value not located in memory.")); + } + return value_addr (x); +} + /* Evaluate a subexpression of EXP, at index *POS, and return the address of that subexpression. Advance *POS over the subexpression. @@ -3163,21 +3186,7 @@ evaluate_subexp_for_address (struct expression *exp, int *pos, default_case: x = evaluate_subexp (nullptr, exp, pos, noside); default_case_after_eval: - if (noside == EVAL_AVOID_SIDE_EFFECTS) - { - struct type *type = check_typedef (value_type (x)); - - if (TYPE_IS_REFERENCE (type)) - return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type)), - not_lval); - else if (VALUE_LVAL (x) == lval_memory || value_must_coerce_to_target (x)) - return value_zero (lookup_pointer_type (value_type (x)), - not_lval); - else - error (_("Attempt to take address of " - "value not located in memory.")); - } - return value_addr (x); + return evaluate_subexp_for_address_base (exp, noside, x); } } @@ -3226,6 +3235,23 @@ evaluate_subexp_with_coercion (struct expression *exp, } } +/* Helper function for evaluating the size of a type. */ + +static value * +evaluate_subexp_for_sizeof_base (struct expression *exp, struct type *type) +{ + /* FIXME: This should be size_t. */ + struct type *size_type = builtin_type (exp->gdbarch)->builtin_int; + /* $5.3.3/2 of the C++ Standard (n3290 draft) says of sizeof: + "When applied to a reference or a reference type, the result is + the size of the referenced type." */ + type = check_typedef (type); + if (exp->language_defn->la_language == language_cplus + && (TYPE_IS_REFERENCE (type))) + type = check_typedef (TYPE_TARGET_TYPE (type)); + return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type)); +} + /* Evaluate a subexpression of EXP, at index *POS, and return a value for the size of that subexpression. Advance *POS over the subexpression. If NOSIDE is EVAL_NORMAL @@ -3349,14 +3375,7 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos, break; } - /* $5.3.3/2 of the C++ Standard (n3290 draft) says of sizeof: - "When applied to a reference or a reference type, the result is - the size of the referenced type." */ - type = check_typedef (type); - if (exp->language_defn->la_language == language_cplus - && (TYPE_IS_REFERENCE (type))) - type = check_typedef (TYPE_TARGET_TYPE (type)); - return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type)); + return evaluate_subexp_for_sizeof_base (exp, type); } /* Evaluate a subexpression of EXP, at index *POS, and return a value -- 2.26.2