diff options
author | Ulrich Weigand <ulrich.weigand@de.ibm.com> | 2017-10-25 15:32:23 +0200 |
---|---|---|
committer | Ulrich Weigand <ulrich.weigand@de.ibm.com> | 2017-10-25 15:32:23 +0200 |
commit | edd079d9f6ca2f9ad21322b742269aec5de61190 (patch) | |
tree | ce27c78e6d4f1b598e0e351ba69ba55e1281d649 /gdb/d-exp.y | |
parent | e5d70d6b5a5c2832ad199ac1b91f68324b4a12c9 (diff) | |
download | binutils-edd079d9f6ca2f9ad21322b742269aec5de61190.zip binutils-edd079d9f6ca2f9ad21322b742269aec5de61190.tar.gz binutils-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/d-exp.y')
-rw-r--r-- | gdb/d-exp.y | 73 |
1 files changed, 34 insertions, 39 deletions
diff --git a/gdb/d-exp.y b/gdb/d-exp.y index 00c9676..0a43bc4 100644 --- a/gdb/d-exp.y +++ b/gdb/d-exp.y @@ -86,7 +86,7 @@ static int type_aggregate_p (struct type *); struct type *type; } typed_val_int; struct { - DOUBLEST dval; + gdb_byte val[16]; struct type *type; } typed_val_float; struct symbol *sym; @@ -540,10 +540,10 @@ PrimaryExpression: write_exp_elt_longcst (pstate, (LONGEST)($1.val)); write_exp_elt_opcode (pstate, OP_LONG); } | FLOAT_LITERAL - { write_exp_elt_opcode (pstate, OP_DOUBLE); + { write_exp_elt_opcode (pstate, OP_FLOAT); write_exp_elt_type (pstate, $1.type); - write_exp_elt_dblcst (pstate, $1.dval); - write_exp_elt_opcode (pstate, OP_DOUBLE); } + write_exp_elt_floatcst (pstate, $1.val); + write_exp_elt_opcode (pstate, OP_FLOAT); } | CHARACTER_LITERAL { struct stoken_vector vec; vec.len = 1; @@ -682,8 +682,6 @@ parse_number (struct parser_state *ps, const char *p, if (parsed_float) { - const char *suffix; - int suffix_len; char *s, *sp; /* Strip out all embedded '_' before passing to parse_float. */ @@ -698,54 +696,51 @@ parse_number (struct parser_state *ps, const char *p, *sp = '\0'; len = strlen (s); - if (! parse_float (s, len, &putithere->typed_val_float.dval, &suffix)) - return ERROR; - - suffix_len = s + len - suffix; - - if (suffix_len == 0) - { - putithere->typed_val_float.type - = parse_d_type (ps)->builtin_double; - } - else if (suffix_len == 1) + /* Check suffix for `i' , `fi' or `li' (idouble, ifloat or ireal). */ + if (len >= 1 && tolower (s[len - 1]) == 'i') { - /* Check suffix for `f', `l', or `i' (float, real, or idouble). */ - if (tolower (*suffix) == 'f') + if (len >= 2 && tolower (s[len - 2]) == 'f') { putithere->typed_val_float.type - = parse_d_type (ps)->builtin_float; + = parse_d_type (ps)->builtin_ifloat; + len -= 2; } - else if (tolower (*suffix) == 'l') + else if (len >= 2 && tolower (s[len - 2]) == 'l') { putithere->typed_val_float.type - = parse_d_type (ps)->builtin_real; + = parse_d_type (ps)->builtin_ireal; + len -= 2; } - else if (tolower (*suffix) == 'i') + else { putithere->typed_val_float.type = parse_d_type (ps)->builtin_idouble; + len -= 1; } - else - return ERROR; } - else if (suffix_len == 2) + /* Check suffix for `f' or `l'' (float or real). */ + else if (len >= 1 && tolower (s[len - 1]) == 'f') { - /* Check suffix for `fi' or `li' (ifloat or ireal). */ - if (tolower (suffix[0]) == 'f' && tolower (suffix[1] == 'i')) - { - putithere->typed_val_float.type - = parse_d_type (ps)->builtin_ifloat; - } - else if (tolower (suffix[0]) == 'l' && tolower (suffix[1] == 'i')) - { - putithere->typed_val_float.type - = parse_d_type (ps)->builtin_ireal; - } - else - return ERROR; + putithere->typed_val_float.type + = parse_d_type (ps)->builtin_float; + len -= 1; } + else if (len >= 1 && tolower (s[len - 1]) == 'l') + { + putithere->typed_val_float.type + = parse_d_type (ps)->builtin_real; + len -= 1; + } + /* Default type if no suffix. */ else + { + putithere->typed_val_float.type + = parse_d_type (ps)->builtin_double; + } + + if (!parse_float (s, len, + putithere->typed_val_float.type, + putithere->typed_val_float.val)) return ERROR; return FLOAT_LITERAL; |