X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Fp-exp.y;h=213033d543883494fe7ba747958bd68b2fc240b4;hb=7c392d1de1400202eb86f7679628c4b7c14f8108;hp=5911d8de24d71a012b28ed95c95d86897e5ed8bc;hpb=61baf725eca99af2569262d10aca03dcde2698f6;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/p-exp.y b/gdb/p-exp.y index 5911d8de24..213033d543 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-2017 Free Software Foundation, Inc. + Copyright (C) 2000-2020 Free Software Foundation, Inc. This file is part of GDB. @@ -56,7 +56,7 @@ #include "block.h" #include "completer.h" -#define parse_type(ps) builtin_type (parse_gdbarch (ps)) +#define parse_type(ps) builtin_type (ps->gdbarch ()) /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc). */ @@ -68,11 +68,14 @@ static struct parser_state *pstate = NULL; +/* Depth of parentheses. */ +static int paren_depth; + int yyparse (void); static int yylex (void); -void yyerror (char *); +static void yyerror (const char *); static char *uptok (const char *, int); %} @@ -89,7 +92,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; @@ -158,7 +161,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 */ @@ -282,14 +285,14 @@ exp : field_exp name } ; exp : field_exp name COMPLETE - { mark_struct_expression (pstate); + { pstate->mark_struct_expression (); write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); write_exp_string (pstate, $2); write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } ; exp : field_exp COMPLETE { struct stoken s; - mark_struct_expression (pstate); + pstate->mark_struct_expression (); write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); s.ptr = ""; s.length = 0; @@ -331,11 +334,11 @@ exp : exp '(' /* This is to save the value of arglist_len being accumulated by an outer function call. */ { push_current_type (); - start_arglist (); } + pstate->start_arglist (); } arglist ')' %prec ARROW { write_exp_elt_opcode (pstate, OP_FUNCALL); write_exp_elt_longcst (pstate, - (LONGEST) end_arglist ()); + pstate->end_arglist ()); write_exp_elt_opcode (pstate, OP_FUNCALL); pop_current_type (); if (current_type) @@ -345,9 +348,9 @@ exp : exp '(' arglist : | exp - { arglist_len = 1; } + { pstate->arglist_len = 1; } | arglist ',' exp %prec ABOVE_COMMA - { arglist_len++; } + { pstate->arglist_len++; } ; exp : type '(' exp ')' %prec UNARY @@ -511,24 +514,24 @@ 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) { struct value * val, * mark; mark = value_mark (); - val = value_of_internalvar (parse_gdbarch (pstate), + val = value_of_internalvar (pstate->gdbarch (), intvar); current_type = value_type (val); value_release_to_mark (mark); @@ -591,7 +594,7 @@ exp : THIS write_exp_elt_opcode (pstate, OP_THIS); /* We need type of this. */ this_val - = value_of_this_silent (parse_language (pstate)); + = value_of_this_silent (pstate->language ()); if (this_val) this_type = value_type (this_val); else @@ -617,37 +620,41 @@ block : BLOCKNAME $$ = SYMBOL_BLOCK_VALUE ($1.sym.symbol); else { + std::string copy = copy_name ($1.stoken); struct symtab *tem = - lookup_symtab (copy_name ($1.stoken)); + lookup_symtab (copy.c_str ()); if (tem) $$ = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (tem), STATIC_BLOCK); else error (_("No file or function \"%s\"."), - copy_name ($1.stoken)); + copy.c_str ()); } } ; block : block COLONCOLON name - { struct symbol *tem - = lookup_symbol (copy_name ($3), $1, + { + std::string copy = copy_name ($3); + struct symbol *tem + = lookup_symbol (copy.c_str (), $1, VAR_DOMAIN, NULL).symbol; if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK) error (_("No function \"%s\" in specified context."), - copy_name ($3)); + copy.c_str ()); $$ = SYMBOL_BLOCK_VALUE (tem); } ; variable: block COLONCOLON name { struct block_symbol sym; - sym = lookup_symbol (copy_name ($3), $1, + std::string copy = copy_name ($3); + sym = lookup_symbol (copy.c_str (), $1, VAR_DOMAIN, NULL); if (sym.symbol == 0) error (_("No symbol \"%s\" in specified context."), - copy_name ($3)); + copy.c_str ()); write_exp_elt_opcode (pstate, OP_VAR_VALUE); write_exp_elt_block (pstate, sym.block); @@ -674,12 +681,13 @@ qualified_name: typebase COLONCOLON name variable: qualified_name | COLONCOLON name { - char *name = copy_name ($2); + std::string name = copy_name ($2); struct symbol *sym; struct bound_minimal_symbol msymbol; sym = - lookup_symbol (name, (const struct block *) NULL, + lookup_symbol (name.c_str (), + (const struct block *) NULL, VAR_DOMAIN, NULL).symbol; if (sym) { @@ -690,7 +698,8 @@ variable: qualified_name break; } - msymbol = lookup_bound_minimal_symbol (name); + msymbol + = lookup_bound_minimal_symbol (name.c_str ()); if (msymbol.minsym != NULL) write_exp_msymbol (pstate, msymbol); else if (!have_full_symbols () @@ -699,7 +708,7 @@ variable: qualified_name "Use the \"file\" command.")); else error (_("No symbol \"%s\" in current context."), - name); + name.c_str ()); } ; @@ -709,12 +718,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; - } + pstate->block_tracker->update (sym); write_exp_elt_opcode (pstate, OP_VAR_VALUE); write_exp_elt_block (pstate, sym.block); @@ -728,10 +732,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; + pstate->block_tracker->update (sym); write_exp_elt_opcode (pstate, OP_THIS); write_exp_elt_opcode (pstate, OP_THIS); write_exp_elt_opcode (pstate, STRUCTOP_PTR); @@ -739,7 +740,7 @@ variable: name_not_typename write_exp_elt_opcode (pstate, STRUCTOP_PTR); /* We need type of this. */ this_val - = value_of_this_silent (parse_language (pstate)); + = value_of_this_silent (pstate->language ()); if (this_val) this_type = value_type (this_val); else @@ -747,17 +748,17 @@ variable: name_not_typename if (this_type) current_type = lookup_struct_elt_type ( this_type, - copy_name ($1.stoken), 0); + copy_name ($1.stoken).c_str (), 0); else current_type = NULL; } else { struct bound_minimal_symbol msymbol; - char *arg = copy_name ($1.stoken); + std::string arg = copy_name ($1.stoken); msymbol = - lookup_bound_minimal_symbol (arg); + lookup_bound_minimal_symbol (arg.c_str ()); if (msymbol.minsym != NULL) write_exp_msymbol (pstate, msymbol); else if (!have_full_symbols () @@ -766,7 +767,7 @@ variable: name_not_typename "Use the \"file\" command.")); else error (_("No symbol \"%s\" in current context."), - copy_name ($1.stoken)); + arg.c_str ()); } } ; @@ -792,11 +793,15 @@ typebase /* Implements (approximately): (type-qualifier)* type-specifier */ | TYPENAME { $$ = $1.type; } | STRUCT name - { $$ = lookup_struct (copy_name ($2), - expression_context_block); } + { $$ + = lookup_struct (copy_name ($2).c_str (), + pstate->expression_context_block); + } | CLASS name - { $$ = lookup_struct (copy_name ($2), - expression_context_block); } + { $$ + = lookup_struct (copy_name ($2).c_str (), + pstate->expression_context_block); + } /* "const" and "volatile" are curently ignored. A type qualifier after the type is handled in the ptype rule. I think these could be too. */ @@ -854,9 +859,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; } @@ -960,10 +986,10 @@ parse_number (struct parser_state *par_state, un = (ULONGEST)n >> 2; if (long_p == 0 - && (un >> (gdbarch_int_bit (parse_gdbarch (par_state)) - 2)) == 0) + && (un >> (gdbarch_int_bit (par_state->gdbarch ()) - 2)) == 0) { high_bit - = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch (par_state)) - 1); + = ((ULONGEST)1) << (gdbarch_int_bit (par_state->gdbarch ()) - 1); /* A large decimal (not hex or octal) constant (between INT_MAX and UINT_MAX) is a long or unsigned long, according to ANSI, @@ -975,10 +1001,10 @@ parse_number (struct parser_state *par_state, signed_type = parse_type (par_state)->builtin_int; } else if (long_p <= 1 - && (un >> (gdbarch_long_bit (parse_gdbarch (par_state)) - 2)) == 0) + && (un >> (gdbarch_long_bit (par_state->gdbarch ()) - 2)) == 0) { high_bit - = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch (par_state)) - 1); + = ((ULONGEST)1) << (gdbarch_long_bit (par_state->gdbarch ()) - 1); unsigned_type = parse_type (par_state)->builtin_unsigned_long; signed_type = parse_type (par_state)->builtin_long; } @@ -986,11 +1012,11 @@ parse_number (struct parser_state *par_state, { int shift; if (sizeof (ULONGEST) * HOST_CHAR_BIT - < gdbarch_long_long_bit (parse_gdbarch (par_state))) + < gdbarch_long_long_bit (par_state->gdbarch ())) /* A long long does not fit in a LONGEST. */ shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1); else - shift = (gdbarch_long_long_bit (parse_gdbarch (par_state)) - 1); + shift = (gdbarch_long_long_bit (par_state->gdbarch ()) - 1); high_bit = (ULONGEST) 1 << shift; unsigned_type = parse_type (par_state)->builtin_unsigned_long_long; signed_type = parse_type (par_state)->builtin_long_long; @@ -1047,7 +1073,7 @@ pop_current_type (void) struct token { - char *oper; + const char *oper; int token; enum exp_opcode opcode; }; @@ -1099,7 +1125,6 @@ yylex (void) { int c; int namelen; - unsigned int i; const char *tokstart; char *uptokstart; const char *tokptr; @@ -1109,33 +1134,33 @@ yylex (void) retry: - prev_lexptr = lexptr; + pstate->prev_lexptr = pstate->lexptr; - tokstart = lexptr; - explen = strlen (lexptr); + tokstart = pstate->lexptr; + explen = strlen (pstate->lexptr); /* 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]) && !isdigit (tokstart[3]) && tokstart[3] != '_'))) { - lexptr += 3; + pstate->lexptr += 3; yylval.opcode = tokentab3[i].opcode; return tokentab3[i].token; } /* 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]) && !isdigit (tokstart[2]) && tokstart[2] != '_'))) { - lexptr += 2; + pstate->lexptr += 2; yylval.opcode = tokentab2[i].opcode; return tokentab2[i].token; } @@ -1143,7 +1168,7 @@ yylex (void) switch (c = *tokstart) { case 0: - if (search_field && parse_completion) + if (search_field && pstate->parse_completion) return COMPLETE; else return 0; @@ -1151,31 +1176,31 @@ yylex (void) case ' ': case '\t': case '\n': - lexptr++; + pstate->lexptr++; goto retry; case '\'': /* We either have a character constant ('0' or '\177' for example) or we have a quoted symbol reference ('foo(int,int)' in object pascal for example). */ - lexptr++; - c = *lexptr++; + pstate->lexptr++; + c = *pstate->lexptr++; if (c == '\\') - c = parse_escape (parse_gdbarch (pstate), &lexptr); + c = parse_escape (pstate->gdbarch (), &pstate->lexptr); else if (c == '\'') error (_("Empty character constant.")); yylval.typed_val_int.val = c; yylval.typed_val_int.type = parse_type (pstate)->builtin_char; - c = *lexptr++; + c = *pstate->lexptr++; if (c != '\'') { namelen = skip_quoted (tokstart) - tokstart; if (namelen > 2) { - lexptr = tokstart + namelen; - if (lexptr[-1] != '\'') + pstate->lexptr = tokstart + namelen; + if (pstate->lexptr[-1] != '\'') error (_("Unmatched single quote.")); namelen -= 2; tokstart++; @@ -1188,30 +1213,30 @@ yylex (void) case '(': paren_depth++; - lexptr++; + pstate->lexptr++; return c; case ')': if (paren_depth == 0) return 0; paren_depth--; - lexptr++; + pstate->lexptr++; return c; case ',': - if (comma_terminates && paren_depth == 0) + if (pstate->comma_terminates && paren_depth == 0) return 0; - lexptr++; + pstate->lexptr++; return c; case '.': /* Might be a floating point number. */ - if (lexptr[1] < '0' || lexptr[1] > '9') + if (pstate->lexptr[1] < '0' || pstate->lexptr[1] > '9') { goto symbol; /* Nope, must be a symbol. */ } - /* FALL THRU into number case. */ + /* FALL THRU. */ case '0': case '1': @@ -1274,7 +1299,7 @@ yylex (void) err_copy[p - tokstart] = 0; error (_("Invalid number \"%s\"."), err_copy); } - lexptr = p; + pstate->lexptr = p; return toktype; } @@ -1298,7 +1323,7 @@ yylex (void) case '{': case '}': symbol: - lexptr++; + pstate->lexptr++; return c; case '"': @@ -1331,7 +1356,7 @@ yylex (void) break; case '\\': ++tokptr; - c = parse_escape (parse_gdbarch (pstate), &tokptr); + c = parse_escape (pstate->gdbarch (), &tokptr); if (c == -1) { continue; @@ -1350,7 +1375,7 @@ yylex (void) tempbuf[tempbufindex] = '\0'; /* See note above. */ yylval.sval.ptr = tempbuf; yylval.sval.length = tempbufindex; - lexptr = tokptr; + pstate->lexptr = tokptr; return (STRING); } @@ -1401,7 +1426,7 @@ yylex (void) return 0; } - lexptr += namelen; + pstate->lexptr += namelen; tryname: @@ -1451,7 +1476,7 @@ yylex (void) inserted in FPC stabs debug info. */ static const char this_name[] = "this"; - if (lookup_symbol (this_name, expression_context_block, + if (lookup_symbol (this_name, pstate->expression_context_block, VAR_DOMAIN, NULL).symbol) { free (uptokstart); @@ -1480,7 +1505,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 @@ -1489,7 +1514,7 @@ yylex (void) currently as names of types; NAME for other symbols. The caller is not constrained to care about the distinction. */ { - char *tmp = copy_name (yylval.sval); + std::string tmp = copy_name (yylval.sval); struct symbol *sym; struct field_of_this_result is_a_field_of_this; int is_a_field = 0; @@ -1497,32 +1522,34 @@ yylex (void) is_a_field_of_this.type = NULL; if (search_field && current_type) - is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL); + is_a_field = (lookup_struct_elt_type (current_type, + tmp.c_str (), 1) != NULL); if (is_a_field) sym = NULL; else - sym = lookup_symbol (tmp, expression_context_block, + sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block, VAR_DOMAIN, &is_a_field_of_this).symbol; /* 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'); } if (search_field && current_type) - is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL); + is_a_field = (lookup_struct_elt_type (current_type, + tmp.c_str (), 1) != NULL); if (is_a_field) sym = NULL; else - sym = lookup_symbol (tmp, expression_context_block, + sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block, VAR_DOMAIN, &is_a_field_of_this).symbol; } /* 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) { @@ -1534,18 +1561,19 @@ yylex (void) tmp[i] -= ('A'-'a'); } if (search_field && current_type) - is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL); + is_a_field = (lookup_struct_elt_type (current_type, + tmp.c_str (), 1) != NULL); if (is_a_field) sym = NULL; else - sym = lookup_symbol (tmp, expression_context_block, + sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block, VAR_DOMAIN, &is_a_field_of_this).symbol; } if (is_a_field || (is_a_field_of_this.type != NULL)) { tempbuf = (char *) realloc (tempbuf, namelen + 1); - strncpy (tempbuf, tmp, namelen); + strncpy (tempbuf, tmp.c_str (), namelen); tempbuf [namelen] = 0; yylval.sval.ptr = tempbuf; yylval.sval.length = namelen; @@ -1562,7 +1590,7 @@ yylex (void) no psymtabs (coff, xcoff, or some future change to blow away the psymtabs once once symbols are read). */ if ((sym && SYMBOL_CLASS (sym) == LOC_BLOCK) - || lookup_symtab (tmp)) + || lookup_symtab (tmp.c_str ())) { yylval.ssym.sym.symbol = sym; yylval.ssym.sym.block = NULL; @@ -1597,7 +1625,7 @@ yylex (void) us whether a type is nested), we just ignore the containing type. */ - p = lexptr; + p = pstate->lexptr; best_sym = sym; while (1) { @@ -1622,25 +1650,27 @@ yylex (void) /* As big as the whole rest of the expression, which is at least big enough. */ char *ncopy - = (char *) alloca (strlen (tmp) + strlen (namestart) + = (char *) alloca (tmp.size () + strlen (namestart) + 3); char *tmp1; tmp1 = ncopy; - memcpy (tmp1, tmp, strlen (tmp)); - tmp1 += strlen (tmp); + memcpy (tmp1, tmp.c_str (), tmp.size ()); + tmp1 += tmp.size (); memcpy (tmp1, "::", 2); tmp1 += 2; memcpy (tmp1, namestart, p - namestart); tmp1[p - namestart] = '\0'; - cur_sym = lookup_symbol (ncopy, expression_context_block, - VAR_DOMAIN, NULL).symbol; + cur_sym + = lookup_symbol (ncopy, + pstate->expression_context_block, + VAR_DOMAIN, NULL).symbol; if (cur_sym) { if (SYMBOL_CLASS (cur_sym) == LOC_TYPEDEF) { best_sym = cur_sym; - lexptr = p; + pstate->lexptr = p; } else break; @@ -1663,8 +1693,8 @@ yylex (void) return TYPENAME; } yylval.tsym.type - = language_lookup_primitive_type (parse_language (pstate), - parse_gdbarch (pstate), tmp); + = language_lookup_primitive_type (pstate->language (), + pstate->gdbarch (), tmp.c_str ()); if (yylval.tsym.type != NULL) { free (uptokstart); @@ -1701,23 +1731,20 @@ 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; + paren_depth = 0; - 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; + if (pstate->prev_lexptr) + pstate->lexptr = pstate->prev_lexptr; - error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr); + error (_("A %s in expression, near `%s'."), msg, pstate->lexptr); }