From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway21.websitewelcome.com (gateway21.websitewelcome.com [192.185.45.163]) by sourceware.org (Postfix) with ESMTPS id 3AC5D394443A for ; Sat, 20 Feb 2021 20:16:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3AC5D394443A 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 gateway21.websitewelcome.com (Postfix) with ESMTP id BA535400C6A72 for ; Sat, 20 Feb 2021 14:16:27 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id DYfzlIhRuuDoADYfzlBfjP; Sat, 20 Feb 2021 14:16:27 -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=yMxIzYproivuOJV3p0k7VFQLi2lx6+aiKg/xY/brZrI=; b=PWUf/HTyVw7hyGC/Mkg+98S0Q1 buhF1KrXypupGu7yPHE5Vmlu6YAmpTrfK0Bzf+qs508dZNufFaxJypCmc5mn9m1Ei5FdKOr97GbI6 GkvdsJNh3bAPTEwRVxx+kzdyb; Received: from 97-122-70-152.hlrn.qwest.net ([97.122.70.152]:52684 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 1lDYfz-000GOP-Gz for gdb-patches@sourceware.org; Sat, 20 Feb 2021 13:16:27 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH v3 068/206] Split out ada_unop_atr Date: Sat, 20 Feb 2021 13:13:51 -0700 Message-Id: <20210220201609.838264-69-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210220201609.838264-1-tom@tromey.com> References: <20210220201609.838264-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.70.152 X-Source-L: No X-Exim-ID: 1lDYfz-000GOP-Gz X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-70-152.hlrn.qwest.net (localhost.localdomain) [97.122.70.152]:52684 X-Source-Auth: tom+tromey.com X-Email-Count: 69 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3032.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_BL, RCVD_IN_MSPIKE_L3, SPF_HELO_PASS, SPF_NEUTRAL, 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: Sat, 20 Feb 2021 20:16:33 -0000 This splits some Ada attribute operations into a new function for future use. gdb/ChangeLog 2021-02-20 Tom Tromey * ada-lang.c (ada_unop_atr): New function. (ada_evaluate_subexp): Use it. --- gdb/ChangeLog | 5 + gdb/ada-lang.c | 244 ++++++++++++++++++++++++++----------------------- 2 files changed, 133 insertions(+), 116 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index ab4b0022c49..4ad63da2ed7 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -10393,6 +10393,133 @@ ada_binop_in_bounds (struct expression *exp, enum noside noside, || value_equal (arg2, arg1))); } +/* A helper function for some attribute operations. */ + +static value * +ada_unop_atr (struct expression *exp, enum noside noside, enum exp_opcode op, + struct value *arg1, struct type *type_arg, int tem) +{ + if (noside == EVAL_AVOID_SIDE_EFFECTS) + { + if (type_arg == NULL) + type_arg = value_type (arg1); + + if (ada_is_constrained_packed_array_type (type_arg)) + type_arg = decode_constrained_packed_array_type (type_arg); + + if (!discrete_type_p (type_arg)) + { + switch (op) + { + default: /* Should never happen. */ + error (_("unexpected attribute encountered")); + case OP_ATR_FIRST: + case OP_ATR_LAST: + type_arg = ada_index_type (type_arg, tem, + ada_attribute_name (op)); + break; + case OP_ATR_LENGTH: + type_arg = builtin_type (exp->gdbarch)->builtin_int; + break; + } + } + + return value_zero (type_arg, not_lval); + } + else if (type_arg == NULL) + { + arg1 = ada_coerce_ref (arg1); + + if (ada_is_constrained_packed_array_type (value_type (arg1))) + arg1 = ada_coerce_to_simple_array (arg1); + + struct type *type; + if (op == OP_ATR_LENGTH) + type = builtin_type (exp->gdbarch)->builtin_int; + else + { + type = ada_index_type (value_type (arg1), tem, + ada_attribute_name (op)); + if (type == NULL) + type = builtin_type (exp->gdbarch)->builtin_int; + } + + switch (op) + { + default: /* Should never happen. */ + error (_("unexpected attribute encountered")); + case OP_ATR_FIRST: + return value_from_longest + (type, ada_array_bound (arg1, tem, 0)); + case OP_ATR_LAST: + return value_from_longest + (type, ada_array_bound (arg1, tem, 1)); + case OP_ATR_LENGTH: + return value_from_longest + (type, ada_array_length (arg1, tem)); + } + } + else if (discrete_type_p (type_arg)) + { + struct type *range_type; + const char *name = ada_type_name (type_arg); + + range_type = NULL; + if (name != NULL && type_arg->code () != TYPE_CODE_ENUM) + range_type = to_fixed_range_type (type_arg, NULL); + if (range_type == NULL) + range_type = type_arg; + switch (op) + { + default: + error (_("unexpected attribute encountered")); + case OP_ATR_FIRST: + return value_from_longest + (range_type, ada_discrete_type_low_bound (range_type)); + case OP_ATR_LAST: + return value_from_longest + (range_type, ada_discrete_type_high_bound (range_type)); + case OP_ATR_LENGTH: + error (_("the 'length attribute applies only to array types")); + } + } + else if (type_arg->code () == TYPE_CODE_FLT) + error (_("unimplemented type attribute")); + else + { + LONGEST low, high; + + if (ada_is_constrained_packed_array_type (type_arg)) + type_arg = decode_constrained_packed_array_type (type_arg); + + struct type *type; + if (op == OP_ATR_LENGTH) + type = builtin_type (exp->gdbarch)->builtin_int; + else + { + type = ada_index_type (type_arg, tem, ada_attribute_name (op)); + if (type == NULL) + type = builtin_type (exp->gdbarch)->builtin_int; + } + + switch (op) + { + default: + error (_("unexpected attribute encountered")); + case OP_ATR_FIRST: + low = ada_array_bound_from_type (type_arg, tem, 0); + return value_from_longest (type, low); + case OP_ATR_LAST: + high = ada_array_bound_from_type (type_arg, tem, 1); + return value_from_longest (type, high); + case OP_ATR_LENGTH: + low = ada_array_bound_from_type (type_arg, tem, 0); + high = ada_array_bound_from_type (type_arg, tem, 1); + return value_from_longest (type, high - low + 1); + } + } +} + /* Implement the evaluate_exp routine in the exp_descriptor structure for the Ada language. */ @@ -10912,123 +11039,8 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, if (noside == EVAL_SKIP) goto nosideret; - else if (noside == EVAL_AVOID_SIDE_EFFECTS) - { - if (type_arg == NULL) - type_arg = value_type (arg1); - - if (ada_is_constrained_packed_array_type (type_arg)) - type_arg = decode_constrained_packed_array_type (type_arg); - if (!discrete_type_p (type_arg)) - { - switch (op) - { - default: /* Should never happen. */ - error (_("unexpected attribute encountered")); - case OP_ATR_FIRST: - case OP_ATR_LAST: - type_arg = ada_index_type (type_arg, tem, - ada_attribute_name (op)); - break; - case OP_ATR_LENGTH: - type_arg = builtin_type (exp->gdbarch)->builtin_int; - break; - } - } - - return value_zero (type_arg, not_lval); - } - else if (type_arg == NULL) - { - arg1 = ada_coerce_ref (arg1); - - if (ada_is_constrained_packed_array_type (value_type (arg1))) - arg1 = ada_coerce_to_simple_array (arg1); - - if (op == OP_ATR_LENGTH) - type = builtin_type (exp->gdbarch)->builtin_int; - else - { - type = ada_index_type (value_type (arg1), tem, - ada_attribute_name (op)); - if (type == NULL) - type = builtin_type (exp->gdbarch)->builtin_int; - } - - switch (op) - { - default: /* Should never happen. */ - error (_("unexpected attribute encountered")); - case OP_ATR_FIRST: - return value_from_longest - (type, ada_array_bound (arg1, tem, 0)); - case OP_ATR_LAST: - return value_from_longest - (type, ada_array_bound (arg1, tem, 1)); - case OP_ATR_LENGTH: - return value_from_longest - (type, ada_array_length (arg1, tem)); - } - } - else if (discrete_type_p (type_arg)) - { - struct type *range_type; - const char *name = ada_type_name (type_arg); - - range_type = NULL; - if (name != NULL && type_arg->code () != TYPE_CODE_ENUM) - range_type = to_fixed_range_type (type_arg, NULL); - if (range_type == NULL) - range_type = type_arg; - switch (op) - { - default: - error (_("unexpected attribute encountered")); - case OP_ATR_FIRST: - return value_from_longest - (range_type, ada_discrete_type_low_bound (range_type)); - case OP_ATR_LAST: - return value_from_longest - (range_type, ada_discrete_type_high_bound (range_type)); - case OP_ATR_LENGTH: - error (_("the 'length attribute applies only to array types")); - } - } - else if (type_arg->code () == TYPE_CODE_FLT) - error (_("unimplemented type attribute")); - else - { - LONGEST low, high; - - if (ada_is_constrained_packed_array_type (type_arg)) - type_arg = decode_constrained_packed_array_type (type_arg); - - if (op == OP_ATR_LENGTH) - type = builtin_type (exp->gdbarch)->builtin_int; - else - { - type = ada_index_type (type_arg, tem, ada_attribute_name (op)); - if (type == NULL) - type = builtin_type (exp->gdbarch)->builtin_int; - } - - switch (op) - { - default: - error (_("unexpected attribute encountered")); - case OP_ATR_FIRST: - low = ada_array_bound_from_type (type_arg, tem, 0); - return value_from_longest (type, low); - case OP_ATR_LAST: - high = ada_array_bound_from_type (type_arg, tem, 1); - return value_from_longest (type, high); - case OP_ATR_LENGTH: - low = ada_array_bound_from_type (type_arg, tem, 0); - high = ada_array_bound_from_type (type_arg, tem, 1); - return value_from_longest (type, high - low + 1); - } - } + return ada_unop_atr (exp, noside, op, arg1, type_arg, tem); } case OP_ATR_TAG: -- 2.26.2