From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/2] Remove ada_attribute_name
Date: Thu, 29 Jun 2023 13:44:30 -0600 [thread overview]
Message-ID: <20230629-enum-attrs-v1-1-ee36873534e2@adacore.com> (raw)
In-Reply-To: <20230629-enum-attrs-v1-0-ee36873534e2@adacore.com>
ada_attribute_name uses an array that must be kept in sync with an
enum -- but the comment here refers to an enum that no longer exists.
Looking at the sole caller, I see this can only be called for two
opcodes. So, remove this entirely and inline it.
---
gdb/ada-lang.c | 41 +++++++++--------------------------------
1 file changed, 9 insertions(+), 32 deletions(-)
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 8e506bd4f2b..3d629cc110f 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -8767,35 +8767,6 @@ ada_to_fixed_value (struct value *val)
/* Attributes */
-/* Table mapping attribute numbers to names.
- NOTE: Keep up to date with enum ada_attribute definition in ada-lang.h. */
-
-static const char * const attribute_names[] = {
- "<?>",
-
- "first",
- "last",
- "length",
- "image",
- "max",
- "min",
- "modulus",
- "pos",
- "size",
- "tag",
- "val",
- 0
-};
-
-static const char *
-ada_attribute_name (enum exp_opcode n)
-{
- if (n >= OP_ATR_FIRST && n <= (int) OP_ATR_VAL)
- return attribute_names[n - OP_ATR_FIRST + 1];
- else
- return attribute_names[0];
-}
-
/* Evaluate the 'POS attribute applied to ARG. */
static LONGEST
@@ -10271,6 +10242,12 @@ static value *
ada_unop_atr (struct expression *exp, enum noside noside, enum exp_opcode op,
struct value *arg1, struct type *type_arg, int tem)
{
+ const char *attr_name = nullptr;
+ if (op == OP_ATR_FIRST)
+ attr_name = "first";
+ else if (op == OP_ATR_LAST)
+ attr_name = "last";
+
if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
if (type_arg == NULL)
@@ -10288,7 +10265,7 @@ ada_unop_atr (struct expression *exp, enum noside noside, enum exp_opcode op,
case OP_ATR_FIRST:
case OP_ATR_LAST:
type_arg = ada_index_type (type_arg, tem,
- ada_attribute_name (op));
+ attr_name);
break;
case OP_ATR_LENGTH:
type_arg = builtin_type (exp->gdbarch)->builtin_int;
@@ -10311,7 +10288,7 @@ ada_unop_atr (struct expression *exp, enum noside noside, enum exp_opcode op,
else
{
type = ada_index_type (arg1->type (), tem,
- ada_attribute_name (op));
+ attr_name);
if (type == NULL)
type = builtin_type (exp->gdbarch)->builtin_int;
}
@@ -10369,7 +10346,7 @@ ada_unop_atr (struct expression *exp, enum noside noside, enum exp_opcode op,
type = builtin_type (exp->gdbarch)->builtin_int;
else
{
- type = ada_index_type (type_arg, tem, ada_attribute_name (op));
+ type = ada_index_type (type_arg, tem, attr_name);
if (type == NULL)
type = builtin_type (exp->gdbarch)->builtin_int;
}
--
2.40.1
next prev parent reply other threads:[~2023-06-29 19:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-29 19:44 [PATCH 0/2] Implement two new Ada attributes Tom Tromey
2023-06-29 19:44 ` Tom Tromey [this message]
2023-06-29 19:44 ` [PATCH 2/2] Implement 'Enum_Val and 'Enum_Rep Tom Tromey
2023-06-30 5:43 ` Eli Zaretskii
2023-06-30 17:39 ` Tom Tromey
2023-06-30 19:04 ` Eli Zaretskii
2023-06-30 19:59 ` Tom Tromey
2023-07-01 5:39 ` Eli Zaretskii
2023-07-13 17:44 ` [PATCH 0/2] Implement two new Ada attributes Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230629-enum-attrs-v1-1-ee36873534e2@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).