X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Fd-exp.y;h=6b25ee298d4eaf2e56a7bfdbeb56af26c11e7995;hb=4bdb25fe6902963ca9cf91d6b2688cf888527bf8;hp=9addf6c04108f1b77d5ffd771c2bc6b4f6e2ffd6;hpb=5776fca307b8af3d852525b77e9b917a9aa97370;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/d-exp.y b/gdb/d-exp.y index 9addf6c041..6b25ee298d 100644 --- a/gdb/d-exp.y +++ b/gdb/d-exp.y @@ -51,6 +51,7 @@ #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */ #include "charset.h" #include "block.h" +#include "type-stack.h" #define parse_type(ps) builtin_type (ps->gdbarch ()) #define parse_d_type(ps) builtin_d_type (ps->gdbarch ()) @@ -65,6 +66,9 @@ static struct parser_state *pstate = NULL; +/* The current type stack. */ +static struct type_stack *type_stack; + int yyparse (void); static int yylex (void); @@ -338,7 +342,7 @@ PostfixExpression: PrimaryExpression | PostfixExpression '.' COMPLETE { struct stoken s; - mark_struct_expression (pstate); + pstate->mark_struct_expression (); write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); s.ptr = ""; s.length = 0; @@ -349,7 +353,7 @@ PostfixExpression: write_exp_string (pstate, $3); write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } | PostfixExpression '.' IDENTIFIER COMPLETE - { mark_struct_expression (pstate); + { pstate->mark_struct_expression (); write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); write_exp_string (pstate, $3); write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } @@ -366,32 +370,32 @@ PostfixExpression: ArgumentList: AssignExpression - { arglist_len = 1; } + { pstate->arglist_len = 1; } | ArgumentList ',' AssignExpression - { arglist_len++; } + { pstate->arglist_len++; } ; ArgumentList_opt: /* EMPTY */ - { arglist_len = 0; } + { pstate->arglist_len = 0; } | ArgumentList ; CallExpression: PostfixExpression '(' - { start_arglist (); } + { pstate->start_arglist (); } ArgumentList_opt ')' { write_exp_elt_opcode (pstate, OP_FUNCALL); - write_exp_elt_longcst (pstate, (LONGEST) end_arglist ()); + write_exp_elt_longcst (pstate, pstate->end_arglist ()); write_exp_elt_opcode (pstate, OP_FUNCALL); } ; IndexExpression: PostfixExpression '[' ArgumentList ']' - { if (arglist_len > 0) + { if (pstate->arglist_len > 0) { write_exp_elt_opcode (pstate, MULTI_SUBSCRIPT); - write_exp_elt_longcst (pstate, (LONGEST) arglist_len); + write_exp_elt_longcst (pstate, pstate->arglist_len); write_exp_elt_opcode (pstate, MULTI_SUBSCRIPT); } else @@ -411,17 +415,18 @@ PrimaryExpression: { /* Do nothing. */ } | IdentifierExp { struct bound_minimal_symbol msymbol; - char *copy = copy_name ($1); + std::string copy = copy_name ($1); struct field_of_this_result is_a_field_of_this; struct block_symbol sym; /* Handle VAR, which could be local or global. */ - sym = lookup_symbol (copy, pstate->expression_context_block, + sym = lookup_symbol (copy.c_str (), + pstate->expression_context_block, VAR_DOMAIN, &is_a_field_of_this); if (sym.symbol && SYMBOL_CLASS (sym.symbol) != LOC_TYPEDEF) { if (symbol_read_needs_frame (sym.symbol)) - innermost_block.update (sym); + pstate->block_tracker->update (sym); write_exp_elt_opcode (pstate, OP_VAR_VALUE); write_exp_elt_block (pstate, sym.block); write_exp_elt_sym (pstate, sym.symbol); @@ -431,7 +436,7 @@ PrimaryExpression: { /* It hangs off of `this'. Must not inadvertently convert from a method call to data ref. */ - innermost_block.update (sym); + 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); @@ -441,13 +446,14 @@ PrimaryExpression: else { /* Lookup foreign name in global static symbols. */ - msymbol = lookup_bound_minimal_symbol (copy); + msymbol = lookup_bound_minimal_symbol (copy.c_str ()); if (msymbol.minsym != NULL) write_exp_msymbol (pstate, msymbol); else if (!have_full_symbols () && !have_partial_symbols ()) error (_("No symbol table is loaded. Use the \"file\" command")); else - error (_("No symbol \"%s\" in current context."), copy); + error (_("No symbol \"%s\" in current context."), + copy.c_str ()); } } | TypeExp '.' IdentifierExp @@ -558,7 +564,7 @@ PrimaryExpression: ArrayLiteral: '[' ArgumentList_opt ']' - { $$ = arglist_len; } + { $$ = pstate->arglist_len; } ; IdentifierExp: @@ -606,7 +612,7 @@ TypeExp: write_exp_elt_type (pstate, $1); write_exp_elt_opcode (pstate, OP_TYPE); } | BasicType BasicType2 - { $$ = follow_types ($1); + { $$ = type_stack->follow_types ($1); write_exp_elt_opcode (pstate, OP_TYPE); write_exp_elt_type (pstate, $$); write_exp_elt_opcode (pstate, OP_TYPE); @@ -615,15 +621,15 @@ TypeExp: BasicType2: '*' - { push_type (tp_pointer); } + { type_stack->push (tp_pointer); } | '*' BasicType2 - { push_type (tp_pointer); } + { type_stack->push (tp_pointer); } | '[' INTEGER_LITERAL ']' - { push_type_int ($2.val); - push_type (tp_array); } + { type_stack->push ($2.val); + type_stack->push (tp_array); } | '[' INTEGER_LITERAL ']' BasicType2 - { push_type_int ($2.val); - push_type (tp_array); } + { type_stack->push ($2.val); + type_stack->push (tp_array); } ; BasicType: @@ -1033,7 +1039,6 @@ lex_one_token (struct parser_state *par_state) unsigned int i; const char *tokstart; int saw_structop = last_was_structop; - char *copy; last_was_structop = 0; @@ -1107,7 +1112,7 @@ lex_one_token (struct parser_state *par_state) /* Might be a floating point number. */ if (pstate->lexptr[1] < '0' || pstate->lexptr[1] > '9') { - if (parse_completion) + if (pstate->parse_completion) last_was_structop = 1; goto symbol; /* Nope, must be a symbol. */ } @@ -1277,9 +1282,9 @@ lex_one_token (struct parser_state *par_state) yylval.sval.length = namelen; /* Catch specific keywords. */ - copy = copy_name (yylval.sval); + std::string copy = copy_name (yylval.sval); for (i = 0; i < sizeof ident_tokens / sizeof ident_tokens[0]; i++) - if (strcmp (copy, ident_tokens[i].oper) == 0) + if (copy == ident_tokens[i].oper) { /* It is ok to always set this, even though we don't always strictly need to. */ @@ -1292,7 +1297,7 @@ lex_one_token (struct parser_state *par_state) yylval.tsym.type = language_lookup_primitive_type (par_state->language (), - par_state->gdbarch (), copy); + par_state->gdbarch (), copy.c_str ()); if (yylval.tsym.type != NULL) return TYPENAME; @@ -1308,7 +1313,7 @@ lex_one_token (struct parser_state *par_state) return NAME_OR_INT; } - if (parse_completion && *pstate->lexptr == '\0') + if (pstate->parse_completion && *pstate->lexptr == '\0') saw_name_at_eof = 1; return IDENTIFIER; @@ -1341,12 +1346,11 @@ static int classify_name (struct parser_state *par_state, const struct block *block) { struct block_symbol sym; - char *copy; struct field_of_this_result is_a_field_of_this; - copy = copy_name (yylval.sval); + std::string copy = copy_name (yylval.sval); - sym = lookup_symbol (copy, block, VAR_DOMAIN, &is_a_field_of_this); + sym = lookup_symbol (copy.c_str (), block, VAR_DOMAIN, &is_a_field_of_this); if (sym.symbol && SYMBOL_CLASS (sym.symbol) == LOC_TYPEDEF) { yylval.tsym.type = SYMBOL_TYPE (sym.symbol); @@ -1355,9 +1359,9 @@ classify_name (struct parser_state *par_state, const struct block *block) else if (sym.symbol == NULL) { /* Look-up first for a module name, then a type. */ - sym = lookup_symbol (copy, block, MODULE_DOMAIN, NULL); + sym = lookup_symbol (copy.c_str (), block, MODULE_DOMAIN, NULL); if (sym.symbol == NULL) - sym = lookup_symbol (copy, block, STRUCT_DOMAIN, NULL); + sym = lookup_symbol (copy.c_str (), block, STRUCT_DOMAIN, NULL); if (sym.symbol != NULL) { @@ -1380,7 +1384,6 @@ classify_inner_name (struct parser_state *par_state, const struct block *block, struct type *context) { struct type *type; - char *copy; if (context == NULL) return classify_name (par_state, block); @@ -1389,8 +1392,8 @@ classify_inner_name (struct parser_state *par_state, if (!type_aggregate_p (type)) return ERROR; - copy = copy_name (yylval.ssym.stoken); - yylval.ssym.sym = d_lookup_nested_symbol (type, copy, block); + std::string copy = copy_name (yylval.ssym.stoken); + yylval.ssym.sym = d_lookup_nested_symbol (type, copy.c_str (), block); if (yylval.ssym.sym.symbol == NULL) return ERROR; @@ -1619,6 +1622,10 @@ d_parse (struct parser_state *par_state) scoped_restore restore_yydebug = make_scoped_restore (&yydebug, parser_debug); + struct type_stack stack; + scoped_restore restore_type_stack = make_scoped_restore (&type_stack, + &stack); + /* Initialize some state used by the lexer. */ last_was_structop = 0; saw_name_at_eof = 0;