X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fp-exp.y;h=31e8c4bea665acf3ce50f44e88ffcbf35267ee45;hb=be6d4f74c77c6f521afc873d226480e001cb99c2;hp=b4f08346aca5e09a3d25658f65475d4abce646f3;hpb=224c3ddb89a43bf8db06c373d4ff429477833c0f;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/p-exp.y b/gdb/p-exp.y index b4f08346ac..31e8c4bea6 100644 --- a/gdb/p-exp.y +++ b/gdb/p-exp.y @@ -1,5 +1,5 @@ /* YACC parser for Pascal expressions, for GDB. - Copyright (C) 2000-2015 Free Software Foundation, Inc. + Copyright (C) 2000-2019 Free Software Foundation, Inc. This file is part of GDB. @@ -58,65 +58,10 @@ #define parse_type(ps) builtin_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 pascal_maxdepth -#define yyparse pascal_parse_internal -#define yylex pascal_lex -#define yyerror pascal_error -#define yylval pascal_lval -#define yychar pascal_char -#define yydebug pascal_debug -#define yypact pascal_pact -#define yyr1 pascal_r1 -#define yyr2 pascal_r2 -#define yydef pascal_def -#define yychk pascal_chk -#define yypgo pascal_pgo -#define yyact pascal_act -#define yyexca pascal_exca -#define yyerrflag pascal_errflag -#define yynerrs pascal_nerrs -#define yyps pascal_ps -#define yypv pascal_pv -#define yys pascal_s -#define yy_yys pascal_yys -#define yystate pascal_state -#define yytmp pascal_tmp -#define yyv pascal_v -#define yy_yyv pascal_yyv -#define yyval pascal_val -#define yylloc pascal_lloc -#define yyreds pascal_reds /* With YYDEBUG defined */ -#define yytoks pascal_toks /* With YYDEBUG defined */ -#define yyname pascal_name /* With YYDEBUG defined */ -#define yyrule pascal_rule /* With YYDEBUG defined */ -#define yylhs pascal_yylhs -#define yylen pascal_yylen -#define yydefred pascal_yydefred -#define yydgoto pascal_yydgoto -#define yysindex pascal_yysindex -#define yyrindex pascal_yyrindex -#define yygindex pascal_yygindex -#define yytable pascal_yytable -#define yycheck pascal_yycheck -#define yyss pascal_yyss -#define yysslim pascal_yysslim -#define yyssp pascal_yyssp -#define yystacksize pascal_yystacksize -#define yyvs pascal_yyvs -#define yyvsp pascal_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 pascal_ +#include "yy-remap.h" /* The state of the parser, used internally when we are parsing the expression. */ @@ -127,7 +72,7 @@ int yyparse (void); static int yylex (void); -void yyerror (char *); +static void yyerror (const char *); static char *uptok (const char *, int); %} @@ -144,7 +89,7 @@ static char *uptok (const char *, int); struct type *type; } typed_val_int; struct { - DOUBLEST dval; + gdb_byte val[16]; struct type *type; } typed_val_float; struct symbol *sym; @@ -213,7 +158,7 @@ static int search_field; /* Special type cases, put in to allow the parser to distinguish different legal basetypes. */ -%token VARIABLE +%token DOLLAR_VARIABLE /* Object pascal */ @@ -566,17 +511,17 @@ exp : NAME_OR_INT exp : FLOAT - { write_exp_elt_opcode (pstate, OP_DOUBLE); + { write_exp_elt_opcode (pstate, OP_FLOAT); write_exp_elt_type (pstate, $1.type); current_type = $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); } ; exp : variable ; -exp : VARIABLE +exp : DOLLAR_VARIABLE /* Already written by write_dollar_variable. Handle current_type. */ { if (intvar) { @@ -764,12 +709,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); @@ -783,10 +723,7 @@ variable: name_not_typename /* Object pascal: it hangs off of `this'. Must not inadvertently convert from a method call to data ref. */ - if (innermost_block == 0 - || contained_in (sym.block, - innermost_block)) - innermost_block = sym.block; + innermost_block.update (sym); write_exp_elt_opcode (pstate, OP_THIS); write_exp_elt_opcode (pstate, OP_THIS); write_exp_elt_opcode (pstate, STRUCTOP_PTR); @@ -909,9 +846,30 @@ parse_number (struct parser_state *par_state, if (parsed_float) { - if (! parse_c_float (parse_gdbarch (par_state), p, len, - &putithere->typed_val_float.dval, - &putithere->typed_val_float.type)) + /* Handle suffixes: 'f' for float, 'l' for long double. + FIXME: This appears to be an extension -- do we want this? */ + if (len >= 1 && tolower (p[len - 1]) == 'f') + { + putithere->typed_val_float.type + = parse_type (par_state)->builtin_float; + len--; + } + else if (len >= 1 && tolower (p[len - 1]) == 'l') + { + putithere->typed_val_float.type + = parse_type (par_state)->builtin_long_double; + len--; + } + /* Default type for floating-point literals is double. */ + else + { + putithere->typed_val_float.type + = parse_type (par_state)->builtin_double; + } + + if (!parse_float (p, len, + putithere->typed_val_float.type, + putithere->typed_val_float.val)) return ERROR; return FLOAT; } @@ -1102,7 +1060,7 @@ pop_current_type (void) struct token { - char *oper; + const char *oper; int token; enum exp_opcode opcode; }; @@ -1154,7 +1112,6 @@ yylex (void) { int c; int namelen; - unsigned int i; const char *tokstart; char *uptokstart; const char *tokptr; @@ -1171,7 +1128,7 @@ yylex (void) /* See if it is a special token of length 3. */ if (explen > 2) - for (i = 0; i < sizeof (tokentab3) / sizeof (tokentab3[0]); i++) + for (int i = 0; i < sizeof (tokentab3) / sizeof (tokentab3[0]); i++) if (strncasecmp (tokstart, tokentab3[i].oper, 3) == 0 && (!isalpha (tokentab3[i].oper[0]) || explen == 3 || (!isalpha (tokstart[3]) @@ -1184,7 +1141,7 @@ yylex (void) /* See if it is a special token of length 2. */ if (explen > 1) - for (i = 0; i < sizeof (tokentab2) / sizeof (tokentab2[0]); i++) + for (int i = 0; i < sizeof (tokentab2) / sizeof (tokentab2[0]); i++) if (strncasecmp (tokstart, tokentab2[i].oper, 2) == 0 && (!isalpha (tokentab2[i].oper[0]) || explen == 2 || (!isalpha (tokstart[2]) @@ -1266,7 +1223,7 @@ yylex (void) goto symbol; /* Nope, must be a symbol. */ } - /* FALL THRU into number case. */ + /* FALL THRU. */ case '0': case '1': @@ -1535,7 +1492,7 @@ yylex (void) tmp[namelen] = '\0'; intvar = lookup_only_internalvar (tmp + 1); free (uptokstart); - return VARIABLE; + return DOLLAR_VARIABLE; } /* Use token-type BLOCKNAME for symbols that happen to be defined as @@ -1561,7 +1518,7 @@ yylex (void) /* second chance uppercased (as Free Pascal does). */ if (!sym && is_a_field_of_this.type == NULL && !is_a_field) { - for (i = 0; i <= namelen; i++) + for (int i = 0; i <= namelen; i++) { if ((tmp[i] >= 'a' && tmp[i] <= 'z')) tmp[i] -= ('a'-'A'); @@ -1577,7 +1534,7 @@ yylex (void) /* Third chance Capitalized (as GPC does). */ if (!sym && is_a_field_of_this.type == NULL && !is_a_field) { - for (i = 0; i <= namelen; i++) + for (int i = 0; i <= namelen; i++) { if (i == 0) { @@ -1756,23 +1713,19 @@ yylex (void) int pascal_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); }