e_ptr + 1);
}
-{NUM10}"#"{HEXDIG}({HEXDIG}|_)*"#" {
+ /* The "llf" is a gdb extension to allow a floating-point
+ constant to be written in some other base. The
+ floating-point number is formed by reinterpreting the
+ bytes, allowing direct control over the bits. */
+{NUM10}(l{0,2}f)?"#"{HEXDIG}({HEXDIG}|_)*"#" {
canonicalizeNumeral (numbuf, yytext);
return processInt (pstate, numbuf, strchr (numbuf, '#') + 1,
NULL);
processInt (struct parser_state *par_state, const char *base0,
const char *num0, const char *exp0)
{
- ULONGEST result;
long exp;
int base;
- const char *trailer;
+ /* For the based literal with an "f" prefix, we'll return a
+ floating-point number. This counts the the number of "l"s seen,
+ to decide the width of the floating-point number to return. -1
+ means no "f". */
+ int floating_point_l_count = -1;
if (base0 == NULL)
base = 10;
else
{
- base = strtol (base0, (char **) NULL, 10);
+ char *end_of_base;
+ base = strtol (base0, &end_of_base, 10);
if (base < 2 || base > 16)
error (_("Invalid base: %d."), base);
+ while (*end_of_base == 'l')
+ {
+ ++floating_point_l_count;
+ ++end_of_base;
+ }
+ /* This assertion is ensured by the pattern. */
+ gdb_assert (floating_point_l_count == -1 || *end_of_base == 'f');
+ if (*end_of_base == 'f')
+ {
+ ++end_of_base;
+ ++floating_point_l_count;
+ }
+ /* This assertion is ensured by the pattern. */
+ gdb_assert (*end_of_base == '#');
}
if (exp0 == NULL)
else
exp = strtol(exp0, (char **) NULL, 10);
- errno = 0;
- result = strtoulst (num0, &trailer, base);
- if (errno == ERANGE)
- error (_("Integer literal out of range"));
- if (isxdigit(*trailer))
- error (_("Invalid digit `%c' in based literal"), *trailer);
+ gdb_mpz result;
+ while (isxdigit (*num0))
+ {
+ int dig = fromhex (*num0);
+ if (dig >= base)
+ error (_("Invalid digit `%c' in based literal"), *num0);
+ mpz_mul_ui (result.val, result.val, base);
+ mpz_add_ui (result.val, result.val, dig);
+ ++num0;
+ }
while (exp > 0)
{
- if (result > (ULONG_MAX / base))
- error (_("Integer literal out of range"));
- result *= base;
+ mpz_mul_ui (result.val, result.val, base);
exp -= 1;
}
- if ((result >> (gdbarch_int_bit (par_state->gdbarch ())-1)) == 0)
+ if (floating_point_l_count > -1)
+ {
+ struct type *fp_type;
+ if (floating_point_l_count == 0)
+ fp_type = language_lookup_primitive_type (par_state->language (),
+ par_state->gdbarch (),
+ "float");
+ else if (floating_point_l_count == 1)
+ fp_type = language_lookup_primitive_type (par_state->language (),
+ par_state->gdbarch (),
+ "long_float");
+ else
+ {
+ /* This assertion is ensured by the pattern. */
+ gdb_assert (floating_point_l_count == 2);
+ fp_type = language_lookup_primitive_type (par_state->language (),
+ par_state->gdbarch (),
+ "long_long_float");
+ }
+
+ yylval.typed_val_float.type = fp_type;
+ result.write (gdb::make_array_view (yylval.typed_val_float.val,
+ TYPE_LENGTH (fp_type)),
+ type_byte_order (fp_type),
+ true);
+
+ return FLOAT;
+ }
+
+ gdb_mpz maxval (ULONGEST_MAX / base);
+ if (mpz_cmp (result.val, maxval.val) > 0)
+ error (_("Integer literal out of range"));
+
+ LONGEST value = result.as_integer<LONGEST> ();
+ if ((value >> (gdbarch_int_bit (par_state->gdbarch ())-1)) == 0)
yylval.typed_val.type = type_int (par_state);
- else if ((result >> (gdbarch_long_bit (par_state->gdbarch ())-1)) == 0)
+ else if ((value >> (gdbarch_long_bit (par_state->gdbarch ())-1)) == 0)
yylval.typed_val.type = type_long (par_state);
- else if (((result >> (gdbarch_long_bit (par_state->gdbarch ())-1)) >> 1) == 0)
+ else if (((value >> (gdbarch_long_bit (par_state->gdbarch ())-1)) >> 1) == 0)
{
/* We have a number representable as an unsigned integer quantity.
For consistency with the C treatment, we will treat it as an
*/
yylval.typed_val.type
= builtin_type (par_state->gdbarch ())->builtin_unsigned_long;
- if (result & LONGEST_SIGN)
+ if (value & LONGEST_SIGN)
yylval.typed_val.val =
- (LONGEST) (result & ~LONGEST_SIGN)
+ (LONGEST) (value & ~LONGEST_SIGN)
- (LONGEST_SIGN>>1) - (LONGEST_SIGN>>1);
else
- yylval.typed_val.val = (LONGEST) result;
+ yylval.typed_val.val = (LONGEST) value;
return INT;
}
else
yylval.typed_val.type = type_long_long (par_state);
- yylval.typed_val.val = (LONGEST) result;
+ yylval.typed_val.val = value;
return INT;
}
--- /dev/null
+# Copyright 2022 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test floating-point literal extension.
+
+load_lib "ada.exp"
+
+if { [skip_ada_tests] } { return -1 }
+
+standard_ada_testfile prog
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} {
+ return -1
+}
+
+clean_restart ${testfile}
+
+set bp_location [gdb_get_line_number "BREAK" ${testdir}/prog.adb]
+runto "prog.adb:$bp_location"
+
+gdb_test "print 16f#41b80000#" " = 23.0"
+gdb_test "print val_float" " = 23.0"
+gdb_test "print val_float := 16f#41b80000#" " = 23.0"
+gdb_test "print val_float" " = 23.0" \
+ "print val_float after assignment"
+
+gdb_test "print 16lf#bc0d83c94fb6d2ac#" " = -2.0e-19"
+gdb_test "print val_double" " = -2.0e-19"
+gdb_test "print val_double := 16lf#bc0d83c94fb6d2ac#" " = -2.0e-19"
+gdb_test "print val_double" " = -2.0e-19" \
+ "print val_double after assignment"
+
+gdb_test "print 16llf#7FFFF7FF4054A56FA5B99019A5C8#" " = 5.0e\\+25"
+gdb_test "print val_long_double" " = 5.0e\\+25"
+gdb_test "print val_long_double := 16llf#7FFFF7FF4054A56FA5B99019A5C8#" \
+ " = 5.0e\\+25"
+gdb_test "print val_long_double" " = 5.0e\\+25" \
+ "print val_long_double after assignment"