aboutsummaryrefslogtreecommitdiff
path: root/gdb/ada-exp.y
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2021-07-01 11:36:58 -0600
committerTom Tromey <tromey@adacore.com>2021-08-02 10:11:22 -0600
commit03adb248d621063cbbb0ce583cbd2e016ada7a6f (patch)
tree5d600cd66576f9e36bfae3573d4d593c1288d7c1 /gdb/ada-exp.y
parent8b12db26d161d526953ab04ad92d598fd148d0bf (diff)
downloadgdb-03adb248d621063cbbb0ce583cbd2e016ada7a6f.zip
gdb-03adb248d621063cbbb0ce583cbd2e016ada7a6f.tar.gz
gdb-03adb248d621063cbbb0ce583cbd2e016ada7a6f.tar.bz2
Defer Ada character literal resolution
In Ada, an enumeration type can use a character literal as one of the enumerators. The Ada expression parser handles the appropriate conversion. It turns out, though, that this conversion was handled incorrectly. For an expression like TYPE'(EXP), the conversion would be done for any such literal appearing in EXP -- but only the outermost such expression should really be affected. This patch defers the conversion until the resolution phase, fixing the bug.
Diffstat (limited to 'gdb/ada-exp.y')
-rw-r--r--gdb/ada-exp.y47
1 files changed, 3 insertions, 44 deletions
diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index afa085e..a0b8b7d 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -91,8 +91,6 @@ static void write_name_assoc (struct parser_state *, struct stoken);
static const struct block *block_lookup (const struct block *, const char *);
-static LONGEST convert_char_literal (struct type *, LONGEST);
-
static void write_ambiguous_var (struct parser_state *,
const struct block *, const char *, int);
@@ -869,11 +867,9 @@ primary : INT
;
primary : CHARLIT
- { write_int (pstate,
- convert_char_literal (type_qualifier, $1.val),
- (type_qualifier == NULL)
- ? $1.type : type_qualifier);
- }
+ {
+ pstate->push_new<ada_char_operation> ($1.type, $1.val);
+ }
;
primary : FLOAT
@@ -1718,43 +1714,6 @@ write_name_assoc (struct parser_state *par_state, struct stoken name)
push_association<ada_name_association> (ada_pop ());
}
-/* Convert the character literal whose ASCII value would be VAL to the
- appropriate value of type TYPE, if there is a translation.
- Otherwise return VAL. Hence, in an enumeration type ('A', 'B'),
- the literal 'A' (VAL == 65), returns 0. */
-
-static LONGEST
-convert_char_literal (struct type *type, LONGEST val)
-{
- char name[7];
- int f;
-
- if (type == NULL)
- return val;
- type = check_typedef (type);
- if (type->code () != TYPE_CODE_ENUM)
- return val;
-
- if ((val >= 'a' && val <= 'z') || (val >= '0' && val <= '9'))
- xsnprintf (name, sizeof (name), "Q%c", (int) val);
- else
- xsnprintf (name, sizeof (name), "QU%02x", (int) val);
- size_t len = strlen (name);
- for (f = 0; f < type->num_fields (); f += 1)
- {
- /* Check the suffix because an enum constant in a package will
- have a name like "pkg__QUxx". This is safe enough because we
- already have the correct type, and because mangling means
- there can't be clashes. */
- const char *ename = TYPE_FIELD_NAME (type, f);
- size_t elen = strlen (ename);
-
- if (elen >= len && strcmp (name, ename + elen - len) == 0)
- return TYPE_FIELD_ENUMVAL (type, f);
- }
- return val;
-}
-
static struct type *
type_int (struct parser_state *par_state)
{