X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Ff-exp.y;h=5ef16125f5dad844820d2c3280b1d57b6247879a;hb=e98ee8c458f3a8405eb93e71b00f801b4bbe3635;hp=56629dc40c0d25c84836e88c3ca114d499a293e6;hpb=63e43d3aedb8b1112899c2d0ad74cbbee687e5d6;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/f-exp.y b/gdb/f-exp.y index 56629dc40c..5ef16125f5 100644 --- a/gdb/f-exp.y +++ b/gdb/f-exp.y @@ -1,6 +1,6 @@ /* YACC parser for Fortran expressions, for GDB. - Copyright (C) 1986-2015 Free Software Foundation, Inc. + Copyright (C) 1986-2018 Free Software Foundation, Inc. Contributed by Motorola. Adapted from the C parser by Farooq Butt (fmbutt@engage.sps.mot.com). @@ -53,69 +53,15 @@ #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */ #include "block.h" #include +#include #define parse_type(ps) builtin_type (parse_gdbarch (ps)) #define parse_f_type(ps) builtin_f_type (parse_gdbarch (ps)) -/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc), - as well as gratuitiously global symbol names, so we can have multiple - yacc generated parsers in gdb. Note that these are only the variables - produced by yacc. If other parser generators (bison, byacc, etc) produce - additional global names that conflict at link time, then those parser - generators need to be fixed instead of adding those names to this list. */ - -#define yymaxdepth f_maxdepth -#define yyparse f_parse_internal -#define yylex f_lex -#define yyerror f_error -#define yylval f_lval -#define yychar f_char -#define yydebug f_debug -#define yypact f_pact -#define yyr1 f_r1 -#define yyr2 f_r2 -#define yydef f_def -#define yychk f_chk -#define yypgo f_pgo -#define yyact f_act -#define yyexca f_exca -#define yyerrflag f_errflag -#define yynerrs f_nerrs -#define yyps f_ps -#define yypv f_pv -#define yys f_s -#define yy_yys f_yys -#define yystate f_state -#define yytmp f_tmp -#define yyv f_v -#define yy_yyv f_yyv -#define yyval f_val -#define yylloc f_lloc -#define yyreds f_reds /* With YYDEBUG defined */ -#define yytoks f_toks /* With YYDEBUG defined */ -#define yyname f_name /* With YYDEBUG defined */ -#define yyrule f_rule /* With YYDEBUG defined */ -#define yylhs f_yylhs -#define yylen f_yylen -#define yydefred f_yydefred -#define yydgoto f_yydgoto -#define yysindex f_yysindex -#define yyrindex f_yyrindex -#define yygindex f_yygindex -#define yytable f_yytable -#define yycheck f_yycheck -#define yyss f_yyss -#define yysslim f_yysslim -#define yyssp f_yyssp -#define yystacksize f_yystacksize -#define yyvs f_yyvs -#define yyvsp f_yyvsp - -#ifndef YYDEBUG -#define YYDEBUG 1 /* Default to yydebug support */ -#endif - -#define YYFPRINTF parser_fprintf +/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, + etc). */ +#define GDB_YY_REMAP_PREFIX f_ +#include "yy-remap.h" /* The state of the parser, used internally when we are parsing the expression. */ @@ -126,7 +72,7 @@ int yyparse (void); static int yylex (void); -void yyerror (char *); +static void yyerror (const char *); static void growbuf_by_size (int); @@ -145,7 +91,10 @@ static int match_string_literal (void); LONGEST val; struct type *type; } typed_val; - DOUBLEST dval; + struct { + gdb_byte val[16]; + struct type *type; + } typed_val_float; struct symbol *sym; struct type *tval; struct stoken sval; @@ -176,7 +125,7 @@ static int parse_number (struct parser_state *, const char *, int, %type ptype %token INT -%token FLOAT +%token FLOAT /* Both NAME and TYPENAME tokens represent symbols in the input, and both convey their data as strings. @@ -313,27 +262,27 @@ arglist : arglist ',' exp %prec ABOVE_COMMA /* There are four sorts of subrange types in F90. */ subrange: exp ':' exp %prec ABOVE_COMMA - { write_exp_elt_opcode (pstate, OP_F90_RANGE); + { write_exp_elt_opcode (pstate, OP_RANGE); write_exp_elt_longcst (pstate, NONE_BOUND_DEFAULT); - write_exp_elt_opcode (pstate, OP_F90_RANGE); } + write_exp_elt_opcode (pstate, OP_RANGE); } ; subrange: exp ':' %prec ABOVE_COMMA - { write_exp_elt_opcode (pstate, OP_F90_RANGE); + { write_exp_elt_opcode (pstate, OP_RANGE); write_exp_elt_longcst (pstate, HIGH_BOUND_DEFAULT); - write_exp_elt_opcode (pstate, OP_F90_RANGE); } + write_exp_elt_opcode (pstate, OP_RANGE); } ; subrange: ':' exp %prec ABOVE_COMMA - { write_exp_elt_opcode (pstate, OP_F90_RANGE); + { write_exp_elt_opcode (pstate, OP_RANGE); write_exp_elt_longcst (pstate, LOW_BOUND_DEFAULT); - write_exp_elt_opcode (pstate, OP_F90_RANGE); } + write_exp_elt_opcode (pstate, OP_RANGE); } ; subrange: ':' %prec ABOVE_COMMA - { write_exp_elt_opcode (pstate, OP_F90_RANGE); + { write_exp_elt_opcode (pstate, OP_RANGE); write_exp_elt_longcst (pstate, BOTH_BOUND_DEFAULT); - write_exp_elt_opcode (pstate, OP_F90_RANGE); } + write_exp_elt_opcode (pstate, OP_RANGE); } ; complexnum: exp ',' exp @@ -468,12 +417,10 @@ exp : NAME_OR_INT ; exp : FLOAT - { write_exp_elt_opcode (pstate, OP_DOUBLE); - write_exp_elt_type (pstate, - parse_f_type (pstate) - ->builtin_real_s8); - write_exp_elt_dblcst (pstate, $1); - write_exp_elt_opcode (pstate, OP_DOUBLE); } + { write_exp_elt_opcode (pstate, OP_FLOAT); + write_exp_elt_type (pstate, $1.type); + write_exp_elt_floatcst (pstate, $1.val); + write_exp_elt_opcode (pstate, OP_FLOAT); } ; exp : variable @@ -514,12 +461,7 @@ variable: name_not_typename if (sym.symbol) { if (symbol_read_needs_frame (sym.symbol)) - { - if (innermost_block == 0 - || contained_in (sym.block, - innermost_block)) - innermost_block = sym.block; - } + innermost_block.update (sym); write_exp_elt_opcode (pstate, OP_VAR_VALUE); write_exp_elt_block (pstate, sym.block); write_exp_elt_sym (pstate, sym.symbol); @@ -567,7 +509,7 @@ ptype : typebase follow_type = lookup_pointer_type (follow_type); break; case tp_reference: - follow_type = lookup_reference_type (follow_type); + follow_type = lookup_lvalue_reference_type (follow_type); break; case tp_array: array_size = pop_type_int (); @@ -701,16 +643,22 @@ parse_number (struct parser_state *par_state, if (parsed_float) { /* It's a float since it contains a point or an exponent. */ - /* [dD] is not understood as an exponent by atof, change it to 'e'. */ + /* [dD] is not understood as an exponent by parse_float, + change it to 'e'. */ char *tmp, *tmp2; tmp = xstrdup (p); for (tmp2 = tmp; *tmp2; ++tmp2) if (*tmp2 == 'd' || *tmp2 == 'D') *tmp2 = 'e'; - putithere->dval = atof (tmp); + + /* FIXME: Should this use different types? */ + putithere->typed_val_float.type = parse_f_type (pstate)->builtin_real_s8; + bool parsed = parse_float (tmp, len, + putithere->typed_val_float.type, + putithere->typed_val_float.val); free (tmp); - return FLOAT; + return parsed? FLOAT : ERROR; } /* Handle base-switching prefixes 0x, 0t, 0d, 0 */ @@ -827,7 +775,7 @@ parse_number (struct parser_state *par_state, struct token { - char *oper; + const char *oper; int token; enum exp_opcode opcode; }; @@ -861,7 +809,7 @@ static const struct token dot_ops[] = struct f77_boolean_val { - char *name; + const char *name; int value; }; @@ -921,7 +869,7 @@ growbuf_by_size (int count) { int growby; - growby = max (count, GROWBY_MIN_SIZE); + growby = std::max (count, GROWBY_MIN_SIZE); tempbufsize += growby; if (tempbuf == NULL) tempbuf = (char *) malloc (tempbufsize); @@ -1060,7 +1008,7 @@ yylex (void) /* Might be a floating point number. */ if (lexptr[1] < '0' || lexptr[1] > '9') goto symbol; /* Nope, must be a symbol. */ - /* FALL THRU into number case. */ + /* FALL THRU. */ case '0': case '1': @@ -1260,23 +1208,19 @@ yylex (void) int f_parse (struct parser_state *par_state) { - int result; - struct cleanup *c = make_cleanup_clear_parser_state (&pstate); - /* Setting up the parser state. */ + scoped_restore pstate_restore = make_scoped_restore (&pstate); gdb_assert (par_state != NULL); pstate = par_state; - result = yyparse (); - do_cleanups (c); - return result; + return yyparse (); } -void -yyerror (char *msg) +static void +yyerror (const char *msg) { if (prev_lexptr) lexptr = prev_lexptr; - error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr); + error (_("A %s in expression, near `%s'."), msg, lexptr); }