From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id +LRUA6KY718DTQAAWB0awg (envelope-from ) for ; Fri, 01 Jan 2021 16:48:18 -0500 Received: by simark.ca (Postfix, from userid 112) id F3ED31F071; Fri, 1 Jan 2021 16:48:16 -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 5C8AE1F071 for ; Fri, 1 Jan 2021 16:48:11 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C886C389244D; Fri, 1 Jan 2021 21:48:02 +0000 (GMT) Received: from gateway31.websitewelcome.com (gateway31.websitewelcome.com [192.185.143.47]) by sourceware.org (Postfix) with ESMTPS id 436CB3890431 for ; Fri, 1 Jan 2021 21:47:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 436CB3890431 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 gateway31.websitewelcome.com (Postfix) with ESMTP id DB4C92C1FE for ; Fri, 1 Jan 2021 15:47:56 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id vSH6kJAM6uDoAvSH6kccHi; Fri, 01 Jan 2021 15:47:56 -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=3J0Ug3yFNMhxIRxP6YqkHMiH6MSDH/0GGhwH80EovuE=; b=pxUChzpBj29itfhX8rHizi/PSU XHU3VrrGo3Z0+PCbUAGdkZ949yWZpQDZRuDQeQzyaSilItABe/G6GnTgmZwIKbBNyXWH0GTrWrDVq WGcrzbg+cJgZ6ma1NYZrOqZzd; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:60388 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 1kvSH6-0029JW-Mn for gdb-patches@sourceware.org; Fri, 01 Jan 2021 14:47:56 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 067/203] Split out ada_unop_atr Date: Fri, 1 Jan 2021 14:45:07 -0700 Message-Id: <20210101214723.1784144-68-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: 1kvSH6-0029JW-Mn X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:60388 X-Source-Auth: tom+tromey.com X-Email-Count: 68 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 attribute operations into a new function for future use. gdb/ChangeLog 2021-01-01 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 bc5fc618161..06347b0a28c 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -10374,6 +10374,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. */ @@ -10873,123 +11000,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