aboutsummaryrefslogtreecommitdiff
path: root/gdb/rust-exp.y
diff options
context:
space:
mode:
authorUlrich Weigand <ulrich.weigand@de.ibm.com>2017-10-25 15:32:23 +0200
committerUlrich Weigand <ulrich.weigand@de.ibm.com>2017-10-25 15:32:23 +0200
commitedd079d9f6ca2f9ad21322b742269aec5de61190 (patch)
treece27c78e6d4f1b598e0e351ba69ba55e1281d649 /gdb/rust-exp.y
parente5d70d6b5a5c2832ad199ac1b91f68324b4a12c9 (diff)
downloadgdb-edd079d9f6ca2f9ad21322b742269aec5de61190.zip
gdb-edd079d9f6ca2f9ad21322b742269aec5de61190.tar.gz
gdb-edd079d9f6ca2f9ad21322b742269aec5de61190.tar.bz2
Target FP: Use target format throughout expression parsing
When parsing floating-point literals, the language parsers currently use parse_float or some equivalent routine to parse the input string into a DOUBLEST, which is then stored within a OP_DOUBLE expression node. When evaluating the expression, the OP_DOUBLE is finally converted into a value in target format. On the other hand, *decimal* floating-point literals are parsed directly into target format and stored that way in a OP_DECFLOAT expression node. In order to eliminate the DOUBLEST, this patch therefore unifies the handling of binary and decimal floating- point literals and stores them both in target format within a new OP_FLOAT expression node, replacing both OP_DOUBLE and OP_DECFLOAT. In order to store literals in target format, the parse_float routine needs to know the type of the literal. All parsers therefore need to be changed to determine the appropriate type (e.g. by detecting suffixes) *before* calling parse_float, instead of after it as today. However, this change is mostly straightforward -- again, this is already done for decimal FP today. The core of the literal parsing is moved into a new routine floatformat_from_string, mirroring floatformat_to_string. The parse_float routine now calls either floatformat_from_string or decimal_from_sting, allowing it to handle any type of FP literal. All language parsers need to be updated. Some notes on specific changes to the various languages: - C: Decimal FP is now handled in parse_float, and no longer needs to be handled specially. - D: Straightforward. - Fortran: Still used a hard-coded "atof", also replaced by parse_float now. Continues to always use builtin_real_s8 as the type of literal, even though this is probably wrong. - Go: This used to handle "f" and "l" suffixes, even though the Go language actually doesn't support those. I kept this support for now -- maybe revisit later. Note the the GDB test suite for some reason actually *verifies* that GDB supports those unsupported suffixes ... - Pascal: Likewise -- this handles suffixes that are not supported in the language standard. - Modula-2: Like Fortran, used to use "atof". - Rust: Mostly straightforward, except for a unit-testing hitch. The code use to set a special "unit_testing" flag which would cause "rust_type" to always return NULL. This makes it not possible to encode a literal into target format (which type?). The reason for this flag appears to have been that during unit testing, there is no "rust_parser" context set up, which means no "gdbarch" is available to use its types. To fix this, I removed the unit_testing flag, and instead simply just set up a dummy rust_parser context during unit testing. - Ada: This used to check sizeof (DOUBLEST) to determine which type to use for floating-point literal. This seems questionable to begin with (since DOUBLEST is quite unrelated to target formats), and in any case we need to get rid of DOUBLEST. I'm now simply always using the largest type (builtin_long_double). gdb/ChangeLog: 2017-10-25 Ulrich Weigand <uweigand@de.ibm.com> * doublest.c (floatformat_from_string): New function. * doublest.h (floatformat_from_string): Add prototype. * std-operator.def (OP_DOUBLE, OP_DECFLOAT): Remove, replace by ... (OP_FLOAT): ... this. * expression.h: Do not include "doublest.h". (union exp_element): Replace doubleconst and decfloatconst by new element floatconst. * ada-lang.c (resolve_subexp): Handle OP_FLOAT instead of OP_DOUBLE. (ada_evaluate_subexp): Likewise. * eval.c (evaluate_subexp_standard): Handle OP_FLOAT instead of OP_DOUBLE and OP_DECFLOAT. * expprint.c (print_subexp_standard): Likewise. (dump_subexp_body_standard): Likewise. * breakpoint.c (watchpoint_exp_is_const): Likewise. * parse.c: Include "dfp.h". (write_exp_elt_dblcst, write_exp_elt_decfloatcst): Remove. (write_exp_elt_floatcst): New function. (operator_length_standard): Handle OP_FLOAT instead of OP_DOUBLE and OP_DECFLOAT. (operator_check_standard): Likewise. (parse_float): Do not accept suffix. Take type as input. Return bool. Return target format buffer instead of host DOUBLEST. Use floatformat_from_string and decimal_from_string to parse either binary or decimal floating-point types. (parse_c_float): Remove. * parser-defs.h: Do not include "doublest.h". (write_exp_elt_dblcst, write_exp_elt_decfloatcst): Remove. (write_exp_elt_floatcst): Add prototype. (parse_float): Update prototype. (parse_c_float): Remove. * c-exp.y: Do not include "dfp.h". (typed_val_float): Use byte buffer instead of DOUBLEST. (typed_val_decfloat): Remove. (DECFLOAT): Remove. (FLOAT): Use OP_FLOAT and write_exp_elt_floatcst. (parse_number): Update to new parse_float interface. Parse suffixes and determine type before calling parse_float. Handle decimal and binary FP types the same way. * d-exp.y (typed_val_float): Use byte buffer instead of DOUBLEST. (FLOAT_LITERAL): Use OP_FLOAT and write_exp_elt_floatcst. (parse_number): Update to new parse_float interface. Parse suffixes and determine type before calling parse_float. * f-exp.y: Replace dval by typed_val_float. (FLOAT): Use OP_FLOAT and write_exp_elt_floatcst. (parse_number): Use parse_float instead of atof. * go-exp.y (typed_val_float): Use byte buffer instead of DOUBLEST. (parse_go_float): Remove. (FLOAT): Use OP_FLOAT and write_exp_elt_floatcst. (parse_number): Call parse_float instead of parse_go_float. Parse suffixes and determine type before calling parse_float. * p-exp.y (typed_val_float): Use byte buffer instead of DOUBLEST. (FLOAT): Use OP_FLOAT and write_exp_elt_floatcst. (parse_number): Update to new parse_float interface. Parse suffixes and determine type before calling parse_float. * m2-exp.y: Replace dval by byte buffer val. (FLOAT): Use OP_FLOAT and write_exp_elt_floatcst. (parse_number): Call parse_float instead of atof. * rust-exp.y (typed_val_float): Use byte buffer instead of DOUBLEST. (lex_number): Call parse_float instead of strtod. (ast_dliteral): Use OP_FLOAT instead of OP_DOUBLE. (convert_ast_to_expression): Handle OP_FLOAT instead of OP_DOUBLE. Use write_exp_elt_floatcst. (unit_testing): Remove static variable. (rust_type): Do not check unit_testing. (rust_lex_tests): Do not set uint_testing. Set up dummy rust_parser. * ada-exp.y (type_float, type_double): Remove. (typed_val_float): Use byte buffer instead of DOUBLEST. (FLOAT): Use OP_FLOAT and write_exp_elt_floatcst. * ada-lex.l (processReal): Use parse_float instead of sscanf.
Diffstat (limited to 'gdb/rust-exp.y')
-rw-r--r--gdb/rust-exp.y33
1 files changed, 14 insertions, 19 deletions
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
index 0cb185c..e372a6e 100644
--- a/gdb/rust-exp.y
+++ b/gdb/rust-exp.y
@@ -54,7 +54,7 @@ struct typed_val_int
struct typed_val_float
{
- DOUBLEST dval;
+ gdb_byte val[16];
struct type *type;
};
@@ -173,10 +173,6 @@ static const char *number_regex_text =
static regex_t number_regex;
-/* True if we're running unit tests. */
-
-static int unit_testing;
-
/* Obstack for data temporarily allocated during parsing. Points to
the obstack in the rust_parser, or to a temporary obstack during
unit testing. */
@@ -1068,11 +1064,6 @@ rust_type (const char *name)
{
struct type *type;
- /* When unit testing, we don't bother checking the types, so avoid a
- possibly-failing lookup here. */
- if (unit_testing)
- return NULL;
-
type = language_lookup_primitive_type (current_parser->language (),
current_parser->arch (),
name);
@@ -1586,8 +1577,11 @@ lex_number (void)
}
else
{
- rustyylval.typed_val_float.dval = strtod (number.c_str (), NULL);
rustyylval.typed_val_float.type = type;
+ bool parsed = parse_float (number.c_str (), number.length (),
+ rustyylval.typed_val_float.type,
+ rustyylval.typed_val_float.val);
+ gdb_assert (parsed);
}
return is_integer ? (could_be_decimal ? DECIMAL_INTEGER : INTEGER) : FLOAT;
@@ -1716,7 +1710,7 @@ ast_dliteral (struct typed_val_float val)
{
struct rust_op *result = OBSTACK_ZALLOC (work_obstack, struct rust_op);
- result->opcode = OP_DOUBLE;
+ result->opcode = OP_FLOAT;
result->left.typed_val_float = val;
return result;
@@ -2181,11 +2175,11 @@ convert_ast_to_expression (struct parser_state *state,
write_exp_elt_opcode (state, OP_LONG);
break;
- case OP_DOUBLE:
- write_exp_elt_opcode (state, OP_DOUBLE);
+ case OP_FLOAT:
+ write_exp_elt_opcode (state, OP_FLOAT);
write_exp_elt_type (state, operation->left.typed_val_float.type);
- write_exp_elt_dblcst (state, operation->left.typed_val_float.dval);
- write_exp_elt_opcode (state, OP_DOUBLE);
+ write_exp_elt_floatcst (state, operation->left.typed_val_float.val);
+ write_exp_elt_opcode (state, OP_FLOAT);
break;
case STRUCTOP_STRUCT:
@@ -2675,7 +2669,10 @@ rust_lex_tests (void)
scoped_restore obstack_holder = make_scoped_restore (&work_obstack,
&test_obstack);
- unit_testing = 1;
+ // Set up dummy "parser", so that rust_type works.
+ struct parser_state ps;
+ initialize_expout (&ps, 0, &rust_language_defn, target_gdbarch ());
+ rust_parser parser (&ps);
rust_lex_test_one ("", 0);
rust_lex_test_one (" \t \n \r ", 0);
@@ -2764,8 +2761,6 @@ rust_lex_tests (void)
rust_lex_test_completion ();
rust_lex_test_push_back ();
-
- unit_testing = 0;
}
#endif /* GDB_SELF_TEST */