diff options
author | Sergio Durigan Junior <sergiodj@redhat.com> | 2014-03-27 19:10:40 -0300 |
---|---|---|
committer | Sergio Durigan Junior <sergiodj@redhat.com> | 2014-03-27 19:10:40 -0300 |
commit | 410a0ff2df3fa8d260c1c6d76172c65285968cea (patch) | |
tree | 1da3b4674bc592c603a1b9e3f8e1761e807a81f8 | |
parent | 342587c49476ad7472419a3028267f2ddb03f4d8 (diff) | |
download | gdb-410a0ff2df3fa8d260c1c6d76172c65285968cea.zip gdb-410a0ff2df3fa8d260c1c6d76172c65285968cea.tar.gz gdb-410a0ff2df3fa8d260c1c6d76172c65285968cea.tar.bz2 |
Remove `expout*' globals from parser-defs.h
This commit removes the "expout*" globals from our parser code, turning
them into a structure that is passed when an expression needs to be
evaluated. This is the initial step to make our parser less
"globalized".
This is mostly a mechanical patch, which creates a structure containing
the "expout*" globals and then modify all the functions that handle them
in order to take the structure as argument. It is big, and has been
reviewed at least 4 times, so I think everything is covered.
Below you can see the message links from the discussions:
- First attempt:
<https://sourceware.org/ml/gdb-patches/2012-01/msg00522.html>
Message-ID: <m3k44s7qej.fsf@gmail.com>
- Second attempt:
<https://sourceware.org/ml/gdb-patches/2012-06/msg00054.html>
Message-Id: <1338665528-5932-1-git-send-email-sergiodj@redhat.com>
- Third attempt:
<https://sourceware.org/ml/gdb-patches/2014-01/msg00949.html>
Message-Id: <1390629467-27139-1-git-send-email-sergiodj@redhat.com>
- Fourth (last) attempt:
<https://sourceware.org/ml/gdb-patches/2014-03/msg00546.html>
Message-Id: <1395463432-29750-1-git-send-email-sergiodj@redhat.com>
gdb/
2014-03-27 Sergio Durigan Junior <sergiodj@redhat.com>
Remove some globals from our parser.
* language.c (unk_lang_parser): Add "struct parser_state"
argument.
* language.h (struct language_defn) <la_parser>: Likewise.
* parse.c (expout, expout_size, expout_ptr): Remove variables.
(initialize_expout): Add "struct parser_state" argument.
Rewrite function to use the parser state.
(reallocate_expout, write_exp_elt, write_exp_elt_opcode,
write_exp_elt_sym, write_exp_elt_block, write_exp_elt_objfile,
write_exp_elt_longcst, write_exp_elt_dblcst,
write_exp_elt_decfloatcst, write_exp_elt_type,
write_exp_elt_intern, write_exp_string, write_exp_string_vector,
write_exp_bitstring, write_exp_msymbol, mark_struct_expression,
write_dollar_variable): Likewise.
(parse_exp_in_context_1): Use parser state.
(insert_type_address_space): Add "struct parser_state" argument.
Use parser state.
(increase_expout_size): New function.
* parser-defs.h: Forward declare "struct language_defn" and
"struct parser_state".
(expout, expout_size, expout_ptr): Remove extern declarations.
(parse_gdbarch, parse_language): Rewrite macro declarations to
accept the parser state.
(struct parser_state): New struct.
(initialize_expout, reallocate_expout, write_exp_elt_opcode,
write_exp_elt_sym, write_exp_elt_longcst, write_exp_elt_dblcst,
write_exp_elt_decfloatcst, write_exp_elt_type,
write_exp_elt_intern, write_exp_string, write_exp_string_vector,
write_exp_bitstring, write_exp_elt_block, write_exp_elt_objfile,
write_exp_msymbol, write_dollar_variable,
mark_struct_expression, insert_type_address_space): Add "struct
parser_state" argument.
(increase_expout_size): New function.
* utils.c (do_clear_parser_state): New function.
(make_cleanup_clear_parser_state): Likewise.
* utils.h (make_cleanup_clear_parser_state): New function
prototype.
* aarch64-linux-tdep.c (aarch64_stap_parse_special_token):
Update calls to write_exp* in order to pass the parser state.
* arm-linux-tdep.c (arm_stap_parse_special_token): Likewise.
* i386-tdep.c (i386_stap_parse_special_token_triplet): Likewise.
(i386_stap_parse_special_token_three_arg_disp): Likewise.
* ppc-linux-tdep.c (ppc_stap_parse_special_token): Likewise.
* stap-probe.c (stap_parse_register_operand): Likewise.
(stap_parse_single_operand): Likewise.
(stap_parse_argument_1): Likewise.
(stap_parse_argument): Use parser state.
* stap-probe.h: Include "parser-defs.h".
(struct stap_parse_info) <pstate>: New field.
* c-exp.y (parse_type): Rewrite to use parser state.
(yyparse): Redefine to c_parse_internal.
(pstate): New global variable.
(parse_number): Add "struct parser_state" argument.
(write_destructor_name): Likewise.
(type_exp): Update calls to write_exp* and similars in order to
use parser state.
(exp1, exp, variable, qualified_name, space_identifier,
typename, typebase): Likewise.
(write_destructor_name, parse_number, lex_one_token,
classify_name, classify_inner_name, c_parse): Add "struct
parser_state" argument. Update function to use parser state.
* c-lang.h: Forward declare "struct parser_state".
(c_parse): Add "struct parser_state" argument.
* ada-exp.y (parse_type): Rewrite macro to use parser state.
(yyparse): Redefine macro to ada_parse_internal.
(pstate): New variable.
(write_int, write_object_renaming, write_var_or_type,
write_name_assoc, write_exp_op_with_string, write_ambiguous_var,
type_int, type_long, type_long_long, type_float, type_double,
type_long_double, type_char, type_boolean, type_system_address):
Add "struct parser_state" argument.
(exp1, primary, simple_exp, relation, and_exp, and_then_exp,
or_exp, or_else_exp, xor_exp, type_prefix, opt_type_prefix,
var_or_type, aggregate, aggregate_component_list,
positional_list, others, component_group,
component_associations): Update calls to write_exp* and similar
functions in order to use parser state.
(ada_parse, write_var_from_sym, write_int,
write_exp_op_with_string, write_object_renaming,
find_primitive_type, write_selectors, write_ambiguous_var,
write_var_or_type, write_name_assoc, type_int, type_long,
type_long_long, type_float, type_double, type_long_double,
type_char, type_boolean, type_system_address): Add "struct
parser_state" argument. Adjust function to use parser state.
* ada-lang.c (parse): Likewise.
* ada-lang.h: Forward declare "struct parser_state".
(ada_parse): Add "struct parser_state" argument.
* ada-lex.l (processInt, processReal): Likewise. Adjust all
calls to both functions.
* f-exp.y (parse_type, parse_f_type): Rewrite macros to use
parser state.
(yyparse): Redefine macro to f_parse_internal.
(pstate): New variable.
(parse_number): Add "struct parser_state" argument.
(type_exp, exp, subrange, typebase): Update calls to write_exp*
and similars in order to use parser state.
(parse_number): Adjust code to use parser state.
(yylex): Likewise.
(f_parse): New function.
* f-lang.h: Forward declare "struct parser_state".
(f_parse): Add "struct parser_state" argument.
* jv-exp.y (parse_type, parse_java_type): Rewrite macros to use
parser state.
(yyparse): Redefine macro for java_parse_internal.
(pstate): New variable.
(push_expression_name, push_expression_name, insert_exp): Add
"struct parser_state" argument.
(type_exp, StringLiteral, Literal, PrimitiveType, IntegralType,
FloatingPointType, exp1, PrimaryNoNewArray, FieldAccess,
FuncStart, MethodInvocation, ArrayAccess, PostfixExpression,
PostIncrementExpression, PostDecrementExpression,
UnaryExpression, PreIncrementExpression, PreDecrementExpression,
UnaryExpressionNotPlusMinus, CastExpression,
MultiplicativeExpression, AdditiveExpression, ShiftExpression,
RelationalExpression, EqualityExpression, AndExpression,
ExclusiveOrExpression, InclusiveOrExpression,
ConditionalAndExpression, ConditionalOrExpression,
ConditionalExpression, Assignment, LeftHandSide): Update
calls to write_exp* and similars in order to use parser state.
(parse_number): Ajust code to use parser state.
(yylex): Likewise.
(java_parse): New function.
(push_variable): Add "struct parser_state" argument. Adjust
code to user parser state.
(push_fieldnames, push_qualified_expression_name,
push_expression_name, insert_exp): Likewise.
* jv-lang.h: Forward declare "struct parser_state".
(java_parse): Add "struct parser_state" argument.
* m2-exp.y (parse_type, parse_m2_type): Rewrite macros to use
parser state.
(yyparse): Redefine macro to m2_parse_internal.
(pstate): New variable.
(type_exp, exp, fblock, variable, type): Update calls to
write_exp* and similars to use parser state.
(yylex): Likewise.
(m2_parse): New function.
* m2-lang.h: Forward declare "struct parser_state".
(m2_parse): Add "struct parser_state" argument.
* objc-lang.c (end_msglist): Add "struct parser_state" argument.
* objc-lang.h: Forward declare "struct parser_state".
(end_msglist): Add "struct parser_state" argument.
* p-exp.y (parse_type): Rewrite macro to use parser state.
(yyparse): Redefine macro to pascal_parse_internal.
(pstate): New variable.
(parse_number): Add "struct parser_state" argument.
(type_exp, exp1, exp, qualified_name, variable): Update calls to
write_exp* and similars in order to use parser state.
(parse_number, yylex): Adjust code to use parser state.
(pascal_parse): New function.
* p-lang.h: Forward declare "struct parser_state".
(pascal_parse): Add "struct parser_state" argument.
* go-exp.y (parse_type): Rewrite macro to use parser state.
(yyparse): Redefine macro to go_parse_internal.
(pstate): New variable.
(parse_number): Add "struct parser_state" argument.
(type_exp, exp1, exp, variable, type): Update calls to
write_exp* and similars in order to use parser state.
(parse_number, lex_one_token, classify_name, yylex): Adjust code
to use parser state.
(go_parse): Likewise.
* go-lang.h: Forward declare "struct parser_state".
(go_parse): Add "struct parser_state" argument.
-rw-r--r-- | gdb/ChangeLog | 165 | ||||
-rw-r--r-- | gdb/aarch64-linux-tdep.c | 26 | ||||
-rw-r--r-- | gdb/ada-exp.y | 488 | ||||
-rw-r--r-- | gdb/ada-lang.c | 4 | ||||
-rw-r--r-- | gdb/ada-lang.h | 3 | ||||
-rw-r--r-- | gdb/ada-lex.l | 54 | ||||
-rw-r--r-- | gdb/arm-linux-tdep.c | 26 | ||||
-rw-r--r-- | gdb/c-exp.y | 698 | ||||
-rw-r--r-- | gdb/c-lang.h | 3 | ||||
-rw-r--r-- | gdb/f-exp.y | 276 | ||||
-rw-r--r-- | gdb/f-lang.h | 3 | ||||
-rw-r--r-- | gdb/go-exp.y | 268 | ||||
-rw-r--r-- | gdb/go-lang.h | 4 | ||||
-rw-r--r-- | gdb/i386-tdep.c | 88 | ||||
-rw-r--r-- | gdb/jv-exp.y | 368 | ||||
-rw-r--r-- | gdb/jv-lang.h | 3 | ||||
-rw-r--r-- | gdb/language.c | 4 | ||||
-rw-r--r-- | gdb/language.h | 3 | ||||
-rw-r--r-- | gdb/m2-exp.y | 275 | ||||
-rw-r--r-- | gdb/m2-lang.h | 3 | ||||
-rw-r--r-- | gdb/objc-lang.c | 8 | ||||
-rw-r--r-- | gdb/objc-lang.h | 3 | ||||
-rw-r--r-- | gdb/p-exp.y | 352 | ||||
-rw-r--r-- | gdb/p-lang.h | 3 | ||||
-rw-r--r-- | gdb/parse.c | 277 | ||||
-rw-r--r-- | gdb/parser-defs.h | 83 | ||||
-rw-r--r-- | gdb/ppc-linux-tdep.c | 6 | ||||
-rw-r--r-- | gdb/stap-probe.c | 64 | ||||
-rw-r--r-- | gdb/stap-probe.h | 6 | ||||
-rw-r--r-- | gdb/utils.c | 18 | ||||
-rw-r--r-- | gdb/utils.h | 4 |
31 files changed, 2038 insertions, 1548 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index ade657e..46f6141 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,168 @@ +2014-03-27 Sergio Durigan Junior <sergiodj@redhat.com> + + Remove some globals from our parser. + * language.c (unk_lang_parser): Add "struct parser_state" + argument. + * language.h (struct language_defn) <la_parser>: Likewise. + * parse.c (expout, expout_size, expout_ptr): Remove variables. + (initialize_expout): Add "struct parser_state" argument. + Rewrite function to use the parser state. + (reallocate_expout, write_exp_elt, write_exp_elt_opcode, + write_exp_elt_sym, write_exp_elt_block, write_exp_elt_objfile, + write_exp_elt_longcst, write_exp_elt_dblcst, + write_exp_elt_decfloatcst, write_exp_elt_type, + write_exp_elt_intern, write_exp_string, write_exp_string_vector, + write_exp_bitstring, write_exp_msymbol, mark_struct_expression, + write_dollar_variable): Likewise. + (parse_exp_in_context_1): Use parser state. + (insert_type_address_space): Add "struct parser_state" argument. + Use parser state. + (increase_expout_size): New function. + * parser-defs.h: Forward declare "struct language_defn" and + "struct parser_state". + (expout, expout_size, expout_ptr): Remove extern declarations. + (parse_gdbarch, parse_language): Rewrite macro declarations to + accept the parser state. + (struct parser_state): New struct. + (initialize_expout, reallocate_expout, write_exp_elt_opcode, + write_exp_elt_sym, write_exp_elt_longcst, write_exp_elt_dblcst, + write_exp_elt_decfloatcst, write_exp_elt_type, + write_exp_elt_intern, write_exp_string, write_exp_string_vector, + write_exp_bitstring, write_exp_elt_block, write_exp_elt_objfile, + write_exp_msymbol, write_dollar_variable, + mark_struct_expression, insert_type_address_space): Add "struct + parser_state" argument. + (increase_expout_size): New function. + * utils.c (do_clear_parser_state): New function. + (make_cleanup_clear_parser_state): Likewise. + * utils.h (make_cleanup_clear_parser_state): New function + prototype. + * aarch64-linux-tdep.c (aarch64_stap_parse_special_token): + Update calls to write_exp* in order to pass the parser state. + * arm-linux-tdep.c (arm_stap_parse_special_token): Likewise. + * i386-tdep.c (i386_stap_parse_special_token_triplet): Likewise. + (i386_stap_parse_special_token_three_arg_disp): Likewise. + * ppc-linux-tdep.c (ppc_stap_parse_special_token): Likewise. + * stap-probe.c (stap_parse_register_operand): Likewise. + (stap_parse_single_operand): Likewise. + (stap_parse_argument_1): Likewise. + (stap_parse_argument): Use parser state. + * stap-probe.h: Include "parser-defs.h". + (struct stap_parse_info) <pstate>: New field. + * c-exp.y (parse_type): Rewrite to use parser state. + (yyparse): Redefine to c_parse_internal. + (pstate): New global variable. + (parse_number): Add "struct parser_state" argument. + (write_destructor_name): Likewise. + (type_exp): Update calls to write_exp* and similars in order to + use parser state. + (exp1, exp, variable, qualified_name, space_identifier, + typename, typebase): Likewise. + (write_destructor_name, parse_number, lex_one_token, + classify_name, classify_inner_name, c_parse): Add "struct + parser_state" argument. Update function to use parser state. + * c-lang.h: Forward declare "struct parser_state". + (c_parse): Add "struct parser_state" argument. + * ada-exp.y (parse_type): Rewrite macro to use parser state. + (yyparse): Redefine macro to ada_parse_internal. + (pstate): New variable. + (write_int, write_object_renaming, write_var_or_type, + write_name_assoc, write_exp_op_with_string, write_ambiguous_var, + type_int, type_long, type_long_long, type_float, type_double, + type_long_double, type_char, type_boolean, type_system_address): + Add "struct parser_state" argument. + (exp1, primary, simple_exp, relation, and_exp, and_then_exp, + or_exp, or_else_exp, xor_exp, type_prefix, opt_type_prefix, + var_or_type, aggregate, aggregate_component_list, + positional_list, others, component_group, + component_associations): Update calls to write_exp* and similar + functions in order to use parser state. + (ada_parse, write_var_from_sym, write_int, + write_exp_op_with_string, write_object_renaming, + find_primitive_type, write_selectors, write_ambiguous_var, + write_var_or_type, write_name_assoc, type_int, type_long, + type_long_long, type_float, type_double, type_long_double, + type_char, type_boolean, type_system_address): Add "struct + parser_state" argument. Adjust function to use parser state. + * ada-lang.c (parse): Likewise. + * ada-lang.h: Forward declare "struct parser_state". + (ada_parse): Add "struct parser_state" argument. + * ada-lex.l (processInt, processReal): Likewise. Adjust all + calls to both functions. + * f-exp.y (parse_type, parse_f_type): Rewrite macros to use + parser state. + (yyparse): Redefine macro to f_parse_internal. + (pstate): New variable. + (parse_number): Add "struct parser_state" argument. + (type_exp, exp, subrange, typebase): Update calls to write_exp* + and similars in order to use parser state. + (parse_number): Adjust code to use parser state. + (yylex): Likewise. + (f_parse): New function. + * f-lang.h: Forward declare "struct parser_state". + (f_parse): Add "struct parser_state" argument. + * jv-exp.y (parse_type, parse_java_type): Rewrite macros to use + parser state. + (yyparse): Redefine macro for java_parse_internal. + (pstate): New variable. + (push_expression_name, push_expression_name, insert_exp): Add + "struct parser_state" argument. + (type_exp, StringLiteral, Literal, PrimitiveType, IntegralType, + FloatingPointType, exp1, PrimaryNoNewArray, FieldAccess, + FuncStart, MethodInvocation, ArrayAccess, PostfixExpression, + PostIncrementExpression, PostDecrementExpression, + UnaryExpression, PreIncrementExpression, PreDecrementExpression, + UnaryExpressionNotPlusMinus, CastExpression, + MultiplicativeExpression, AdditiveExpression, ShiftExpression, + RelationalExpression, EqualityExpression, AndExpression, + ExclusiveOrExpression, InclusiveOrExpression, + ConditionalAndExpression, ConditionalOrExpression, + ConditionalExpression, Assignment, LeftHandSide): Update + calls to write_exp* and similars in order to use parser state. + (parse_number): Ajust code to use parser state. + (yylex): Likewise. + (java_parse): New function. + (push_variable): Add "struct parser_state" argument. Adjust + code to user parser state. + (push_fieldnames, push_qualified_expression_name, + push_expression_name, insert_exp): Likewise. + * jv-lang.h: Forward declare "struct parser_state". + (java_parse): Add "struct parser_state" argument. + * m2-exp.y (parse_type, parse_m2_type): Rewrite macros to use + parser state. + (yyparse): Redefine macro to m2_parse_internal. + (pstate): New variable. + (type_exp, exp, fblock, variable, type): Update calls to + write_exp* and similars to use parser state. + (yylex): Likewise. + (m2_parse): New function. + * m2-lang.h: Forward declare "struct parser_state". + (m2_parse): Add "struct parser_state" argument. + * objc-lang.c (end_msglist): Add "struct parser_state" argument. + * objc-lang.h: Forward declare "struct parser_state". + (end_msglist): Add "struct parser_state" argument. + * p-exp.y (parse_type): Rewrite macro to use parser state. + (yyparse): Redefine macro to pascal_parse_internal. + (pstate): New variable. + (parse_number): Add "struct parser_state" argument. + (type_exp, exp1, exp, qualified_name, variable): Update calls to + write_exp* and similars in order to use parser state. + (parse_number, yylex): Adjust code to use parser state. + (pascal_parse): New function. + * p-lang.h: Forward declare "struct parser_state". + (pascal_parse): Add "struct parser_state" argument. + * go-exp.y (parse_type): Rewrite macro to use parser state. + (yyparse): Redefine macro to go_parse_internal. + (pstate): New variable. + (parse_number): Add "struct parser_state" argument. + (type_exp, exp1, exp, variable, type): Update calls to + write_exp* and similars in order to use parser state. + (parse_number, lex_one_token, classify_name, yylex): Adjust code + to use parser state. + (go_parse): Likewise. + * go-lang.h: Forward declare "struct parser_state". + (go_parse): Add "struct parser_state" argument. + 2014-03-27 Doug Evans <dje@google.com> * dwarf2read.c (read_str_index): Delete arg cu. All callers updated. diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index 194e4cc..92d1248 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -352,28 +352,28 @@ aarch64_stap_parse_special_token (struct gdbarch *gdbarch, return 0; /* The displacement. */ - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type (gdbarch)->builtin_long); - write_exp_elt_longcst (displacement); - write_exp_elt_opcode (OP_LONG); + write_exp_elt_opcode (&p->pstate, OP_LONG); + write_exp_elt_type (&p->pstate, builtin_type (gdbarch)->builtin_long); + write_exp_elt_longcst (&p->pstate, displacement); + write_exp_elt_opcode (&p->pstate, OP_LONG); if (got_minus) - write_exp_elt_opcode (UNOP_NEG); + write_exp_elt_opcode (&p->pstate, UNOP_NEG); /* The register name. */ - write_exp_elt_opcode (OP_REGISTER); + write_exp_elt_opcode (&p->pstate, OP_REGISTER); str.ptr = regname; str.length = len; - write_exp_string (str); - write_exp_elt_opcode (OP_REGISTER); + write_exp_string (&p->pstate, str); + write_exp_elt_opcode (&p->pstate, OP_REGISTER); - write_exp_elt_opcode (BINOP_ADD); + write_exp_elt_opcode (&p->pstate, BINOP_ADD); /* Casting to the expected type. */ - write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type (lookup_pointer_type (p->arg_type)); - write_exp_elt_opcode (UNOP_CAST); + write_exp_elt_opcode (&p->pstate, UNOP_CAST); + write_exp_elt_type (&p->pstate, lookup_pointer_type (p->arg_type)); + write_exp_elt_opcode (&p->pstate, UNOP_CAST); - write_exp_elt_opcode (UNOP_IND); + write_exp_elt_opcode (&p->pstate, UNOP_IND); p->arg = tmp; } diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y index 4273f1d..9815f23 100644 --- a/gdb/ada-exp.y +++ b/gdb/ada-exp.y @@ -49,7 +49,7 @@ #include "frame.h" #include "block.h" -#define parse_type builtin_type (parse_gdbarch) +#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 @@ -63,7 +63,8 @@ without BISON? (PNH) */ #define yymaxdepth ada_maxdepth -#define yyparse _ada_parse /* ada_parse calls this after initialization */ +/* ada_parse calls this after initialization */ +#define yyparse ada_parse_internal #define yylex ada_lex #define yyerror ada_error #define yylval ada_lval @@ -113,6 +114,11 @@ struct name_info { struct stoken stoken; }; +/* The state of the parser, used internally when we are parsing the + expression. */ + +static struct parser_state *pstate = NULL; + static struct stoken empty_stoken = { "", 0 }; /* If expression is in the context of TYPE'(...), then TYPE, else @@ -125,40 +131,44 @@ static int yylex (void); void yyerror (char *); -static void write_int (LONGEST, struct type *); +static void write_int (struct parser_state *, LONGEST, struct type *); -static void write_object_renaming (const struct block *, const char *, int, +static void write_object_renaming (struct parser_state *, + const struct block *, const char *, int, const char *, int); -static struct type* write_var_or_type (const struct block *, struct stoken); +static struct type* write_var_or_type (struct parser_state *, + const struct block *, struct stoken); -static void write_name_assoc (struct stoken); +static void write_name_assoc (struct parser_state *, struct stoken); -static void write_exp_op_with_string (enum exp_opcode, struct stoken); +static void write_exp_op_with_string (struct parser_state *, enum exp_opcode, + struct stoken); static struct block *block_lookup (struct block *, const char *); static LONGEST convert_char_literal (struct type *, LONGEST); -static void write_ambiguous_var (const struct block *, char *, int); +static void write_ambiguous_var (struct parser_state *, + const struct block *, char *, int); -static struct type *type_int (void); +static struct type *type_int (struct parser_state *); -static struct type *type_long (void); +static struct type *type_long (struct parser_state *); -static struct type *type_long_long (void); +static struct type *type_long_long (struct parser_state *); -static struct type *type_float (void); +static struct type *type_float (struct parser_state *); -static struct type *type_double (void); +static struct type *type_double (struct parser_state *); -static struct type *type_long_double (void); +static struct type *type_long_double (struct parser_state *); -static struct type *type_char (void); +static struct type *type_char (struct parser_state *); -static struct type *type_boolean (void); +static struct type *type_boolean (struct parser_state *); -static struct type *type_system_address (void); +static struct type *type_system_address (struct parser_state *); %} @@ -234,25 +244,26 @@ start : exp1 /* Expressions, including the sequencing operator. */ exp1 : exp | exp1 ';' exp - { write_exp_elt_opcode (BINOP_COMMA); } + { write_exp_elt_opcode (pstate, BINOP_COMMA); } | primary ASSIGN exp /* Extension for convenience */ - { write_exp_elt_opcode (BINOP_ASSIGN); } + { write_exp_elt_opcode (pstate, BINOP_ASSIGN); } ; /* Expressions, not including the sequencing operator. */ primary : primary DOT_ALL - { write_exp_elt_opcode (UNOP_IND); } + { write_exp_elt_opcode (pstate, UNOP_IND); } ; primary : primary DOT_ID - { write_exp_op_with_string (STRUCTOP_STRUCT, $2); } + { write_exp_op_with_string (pstate, STRUCTOP_STRUCT, + $2); } ; primary : primary '(' arglist ')' { - write_exp_elt_opcode (OP_FUNCALL); - write_exp_elt_longcst ($3); - write_exp_elt_opcode (OP_FUNCALL); + write_exp_elt_opcode (pstate, OP_FUNCALL); + write_exp_elt_longcst (pstate, $3); + write_exp_elt_opcode (pstate, OP_FUNCALL); } | var_or_type '(' arglist ')' { @@ -260,15 +271,15 @@ primary : primary '(' arglist ')' { if ($3 != 1) error (_("Invalid conversion")); - write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type ($1); - write_exp_elt_opcode (UNOP_CAST); + write_exp_elt_opcode (pstate, UNOP_CAST); + write_exp_elt_type (pstate, $1); + write_exp_elt_opcode (pstate, UNOP_CAST); } else { - write_exp_elt_opcode (OP_FUNCALL); - write_exp_elt_longcst ($3); - write_exp_elt_opcode (OP_FUNCALL); + write_exp_elt_opcode (pstate, OP_FUNCALL); + write_exp_elt_longcst (pstate, $3); + write_exp_elt_opcode (pstate, OP_FUNCALL); } } ; @@ -278,9 +289,9 @@ primary : var_or_type '\'' save_qualifier { type_qualifier = $1; } { if ($1 == NULL) error (_("Type required for qualification")); - write_exp_elt_opcode (UNOP_QUAL); - write_exp_elt_type ($1); - write_exp_elt_opcode (UNOP_QUAL); + write_exp_elt_opcode (pstate, UNOP_QUAL); + write_exp_elt_type (pstate, $1); + write_exp_elt_opcode (pstate, UNOP_QUAL); type_qualifier = $3; } ; @@ -290,10 +301,10 @@ save_qualifier : { $$ = type_qualifier; } primary : primary '(' simple_exp DOTDOT simple_exp ')' - { write_exp_elt_opcode (TERNOP_SLICE); } + { write_exp_elt_opcode (pstate, TERNOP_SLICE); } | var_or_type '(' simple_exp DOTDOT simple_exp ')' { if ($1 == NULL) - write_exp_elt_opcode (TERNOP_SLICE); + write_exp_elt_opcode (pstate, TERNOP_SLICE); else error (_("Cannot slice a type")); } @@ -313,15 +324,15 @@ primary : '(' exp1 ')' { } primary : var_or_type %prec VAR { if ($1 != NULL) { - write_exp_elt_opcode (OP_TYPE); - write_exp_elt_type ($1); - write_exp_elt_opcode (OP_TYPE); + write_exp_elt_opcode (pstate, OP_TYPE); + write_exp_elt_type (pstate, $1); + write_exp_elt_opcode (pstate, OP_TYPE); } } ; primary : SPECIAL_VARIABLE /* Various GDB extensions */ - { write_dollar_variable ($1); } + { write_dollar_variable (pstate, $1); } ; primary : aggregate @@ -331,19 +342,19 @@ simple_exp : primary ; simple_exp : '-' simple_exp %prec UNARY - { write_exp_elt_opcode (UNOP_NEG); } + { write_exp_elt_opcode (pstate, UNOP_NEG); } ; simple_exp : '+' simple_exp %prec UNARY - { write_exp_elt_opcode (UNOP_PLUS); } + { write_exp_elt_opcode (pstate, UNOP_PLUS); } ; simple_exp : NOT simple_exp %prec UNARY - { write_exp_elt_opcode (UNOP_LOGICAL_NOT); } + { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); } ; simple_exp : ABS simple_exp %prec UNARY - { write_exp_elt_opcode (UNOP_ABS); } + { write_exp_elt_opcode (pstate, UNOP_ABS); } ; arglist : { $$ = 0; } @@ -364,111 +375,111 @@ primary : '{' var_or_type '}' primary %prec '.' { if ($2 == NULL) error (_("Type required within braces in coercion")); - write_exp_elt_opcode (UNOP_MEMVAL); - write_exp_elt_type ($2); - write_exp_elt_opcode (UNOP_MEMVAL); + write_exp_elt_opcode (pstate, UNOP_MEMVAL); + write_exp_elt_type (pstate, $2); + write_exp_elt_opcode (pstate, UNOP_MEMVAL); } ; /* Binary operators in order of decreasing precedence. */ simple_exp : simple_exp STARSTAR simple_exp - { write_exp_elt_opcode (BINOP_EXP); } + { write_exp_elt_opcode (pstate, BINOP_EXP); } ; simple_exp : simple_exp '*' simple_exp - { write_exp_elt_opcode (BINOP_MUL); } + { write_exp_elt_opcode (pstate, BINOP_MUL); } ; simple_exp : simple_exp '/' simple_exp - { write_exp_elt_opcode (BINOP_DIV); } + { write_exp_elt_opcode (pstate, BINOP_DIV); } ; simple_exp : simple_exp REM simple_exp /* May need to be fixed to give correct Ada REM */ - { write_exp_elt_opcode (BINOP_REM); } + { write_exp_elt_opcode (pstate, BINOP_REM); } ; simple_exp : simple_exp MOD simple_exp - { write_exp_elt_opcode (BINOP_MOD); } + { write_exp_elt_opcode (pstate, BINOP_MOD); } ; simple_exp : simple_exp '@' simple_exp /* GDB extension */ - { write_exp_elt_opcode (BINOP_REPEAT); } + { write_exp_elt_opcode (pstate, BINOP_REPEAT); } ; simple_exp : simple_exp '+' simple_exp - { write_exp_elt_opcode (BINOP_ADD); } + { write_exp_elt_opcode (pstate, BINOP_ADD); } ; simple_exp : simple_exp '&' simple_exp - { write_exp_elt_opcode (BINOP_CONCAT); } + { write_exp_elt_opcode (pstate, BINOP_CONCAT); } ; simple_exp : simple_exp '-' simple_exp - { write_exp_elt_opcode (BINOP_SUB); } + { write_exp_elt_opcode (pstate, BINOP_SUB); } ; relation : simple_exp ; relation : simple_exp '=' simple_exp - { write_exp_elt_opcode (BINOP_EQUAL); } + { write_exp_elt_opcode (pstate, BINOP_EQUAL); } ; relation : simple_exp NOTEQUAL simple_exp - { write_exp_elt_opcode (BINOP_NOTEQUAL); } + { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); } ; relation : simple_exp LEQ simple_exp - { write_exp_elt_opcode (BINOP_LEQ); } + { write_exp_elt_opcode (pstate, BINOP_LEQ); } ; relation : simple_exp IN simple_exp DOTDOT simple_exp - { write_exp_elt_opcode (TERNOP_IN_RANGE); } + { write_exp_elt_opcode (pstate, TERNOP_IN_RANGE); } | simple_exp IN primary TICK_RANGE tick_arglist - { write_exp_elt_opcode (BINOP_IN_BOUNDS); - write_exp_elt_longcst ((LONGEST) $5); - write_exp_elt_opcode (BINOP_IN_BOUNDS); + { write_exp_elt_opcode (pstate, BINOP_IN_BOUNDS); + write_exp_elt_longcst (pstate, (LONGEST) $5); + write_exp_elt_opcode (pstate, BINOP_IN_BOUNDS); } | simple_exp IN var_or_type %prec TICK_ACCESS { if ($3 == NULL) error (_("Right operand of 'in' must be type")); - write_exp_elt_opcode (UNOP_IN_RANGE); - write_exp_elt_type ($3); - write_exp_elt_opcode (UNOP_IN_RANGE); + write_exp_elt_opcode (pstate, UNOP_IN_RANGE); + write_exp_elt_type (pstate, $3); + write_exp_elt_opcode (pstate, UNOP_IN_RANGE); } | simple_exp NOT IN simple_exp DOTDOT simple_exp - { write_exp_elt_opcode (TERNOP_IN_RANGE); - write_exp_elt_opcode (UNOP_LOGICAL_NOT); + { write_exp_elt_opcode (pstate, TERNOP_IN_RANGE); + write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); } | simple_exp NOT IN primary TICK_RANGE tick_arglist - { write_exp_elt_opcode (BINOP_IN_BOUNDS); - write_exp_elt_longcst ((LONGEST) $6); - write_exp_elt_opcode (BINOP_IN_BOUNDS); - write_exp_elt_opcode (UNOP_LOGICAL_NOT); + { write_exp_elt_opcode (pstate, BINOP_IN_BOUNDS); + write_exp_elt_longcst (pstate, (LONGEST) $6); + write_exp_elt_opcode (pstate, BINOP_IN_BOUNDS); + write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); } | simple_exp NOT IN var_or_type %prec TICK_ACCESS { if ($4 == NULL) error (_("Right operand of 'in' must be type")); - write_exp_elt_opcode (UNOP_IN_RANGE); - write_exp_elt_type ($4); - write_exp_elt_opcode (UNOP_IN_RANGE); - write_exp_elt_opcode (UNOP_LOGICAL_NOT); + write_exp_elt_opcode (pstate, UNOP_IN_RANGE); + write_exp_elt_type (pstate, $4); + write_exp_elt_opcode (pstate, UNOP_IN_RANGE); + write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); } ; relation : simple_exp GEQ simple_exp - { write_exp_elt_opcode (BINOP_GEQ); } + { write_exp_elt_opcode (pstate, BINOP_GEQ); } ; relation : simple_exp '<' simple_exp - { write_exp_elt_opcode (BINOP_LESS); } + { write_exp_elt_opcode (pstate, BINOP_LESS); } ; relation : simple_exp '>' simple_exp - { write_exp_elt_opcode (BINOP_GTR); } + { write_exp_elt_opcode (pstate, BINOP_GTR); } ; exp : relation @@ -481,36 +492,36 @@ exp : relation and_exp : relation _AND_ relation - { write_exp_elt_opcode (BINOP_BITWISE_AND); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); } | and_exp _AND_ relation - { write_exp_elt_opcode (BINOP_BITWISE_AND); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); } ; and_then_exp : relation _AND_ THEN relation - { write_exp_elt_opcode (BINOP_LOGICAL_AND); } + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); } | and_then_exp _AND_ THEN relation - { write_exp_elt_opcode (BINOP_LOGICAL_AND); } + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); } ; or_exp : relation OR relation - { write_exp_elt_opcode (BINOP_BITWISE_IOR); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); } | or_exp OR relation - { write_exp_elt_opcode (BINOP_BITWISE_IOR); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); } ; or_else_exp : relation OR ELSE relation - { write_exp_elt_opcode (BINOP_LOGICAL_OR); } + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); } | or_else_exp OR ELSE relation - { write_exp_elt_opcode (BINOP_LOGICAL_OR); } + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); } ; xor_exp : relation XOR relation - { write_exp_elt_opcode (BINOP_BITWISE_XOR); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); } | xor_exp XOR relation - { write_exp_elt_opcode (BINOP_BITWISE_XOR); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); } ; /* Primaries can denote types (OP_TYPE). In cases such as @@ -522,36 +533,37 @@ xor_exp : relation XOR relation aType'access evaluates to a type that evaluate_subexp attempts to evaluate. */ primary : primary TICK_ACCESS - { write_exp_elt_opcode (UNOP_ADDR); } + { write_exp_elt_opcode (pstate, UNOP_ADDR); } | primary TICK_ADDRESS - { write_exp_elt_opcode (UNOP_ADDR); - write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type (type_system_address ()); - write_exp_elt_opcode (UNOP_CAST); + { write_exp_elt_opcode (pstate, UNOP_ADDR); + write_exp_elt_opcode (pstate, UNOP_CAST); + write_exp_elt_type (pstate, + type_system_address (pstate)); + write_exp_elt_opcode (pstate, UNOP_CAST); } | primary TICK_FIRST tick_arglist - { write_int ($3, type_int ()); - write_exp_elt_opcode (OP_ATR_FIRST); } + { write_int (pstate, $3, type_int (pstate)); + write_exp_elt_opcode (pstate, OP_ATR_FIRST); } | primary TICK_LAST tick_arglist - { write_int ($3, type_int ()); - write_exp_elt_opcode (OP_ATR_LAST); } + { write_int (pstate, $3, type_int (pstate)); + write_exp_elt_opcode (pstate, OP_ATR_LAST); } | primary TICK_LENGTH tick_arglist - { write_int ($3, type_int ()); - write_exp_elt_opcode (OP_ATR_LENGTH); } + { write_int (pstate, $3, type_int (pstate)); + write_exp_elt_opcode (pstate, OP_ATR_LENGTH); } | primary TICK_SIZE - { write_exp_elt_opcode (OP_ATR_SIZE); } + { write_exp_elt_opcode (pstate, OP_ATR_SIZE); } | primary TICK_TAG - { write_exp_elt_opcode (OP_ATR_TAG); } + { write_exp_elt_opcode (pstate, OP_ATR_TAG); } | opt_type_prefix TICK_MIN '(' exp ',' exp ')' - { write_exp_elt_opcode (OP_ATR_MIN); } + { write_exp_elt_opcode (pstate, OP_ATR_MIN); } | opt_type_prefix TICK_MAX '(' exp ',' exp ')' - { write_exp_elt_opcode (OP_ATR_MAX); } + { write_exp_elt_opcode (pstate, OP_ATR_MAX); } | opt_type_prefix TICK_POS '(' exp ')' - { write_exp_elt_opcode (OP_ATR_POS); } + { write_exp_elt_opcode (pstate, OP_ATR_POS); } | type_prefix TICK_VAL '(' exp ')' - { write_exp_elt_opcode (OP_ATR_VAL); } + { write_exp_elt_opcode (pstate, OP_ATR_VAL); } | type_prefix TICK_MODULUS - { write_exp_elt_opcode (OP_ATR_MODULUS); } + { write_exp_elt_opcode (pstate, OP_ATR_MODULUS); } ; tick_arglist : %prec '(' @@ -565,53 +577,55 @@ type_prefix : { if ($1 == NULL) error (_("Prefix must be type")); - write_exp_elt_opcode (OP_TYPE); - write_exp_elt_type ($1); - write_exp_elt_opcode (OP_TYPE); } + write_exp_elt_opcode (pstate, OP_TYPE); + write_exp_elt_type (pstate, $1); + write_exp_elt_opcode (pstate, OP_TYPE); } ; opt_type_prefix : type_prefix | /* EMPTY */ - { write_exp_elt_opcode (OP_TYPE); - write_exp_elt_type (parse_type->builtin_void); - write_exp_elt_opcode (OP_TYPE); } + { write_exp_elt_opcode (pstate, OP_TYPE); + write_exp_elt_type (pstate, + parse_type (pstate)->builtin_void); + write_exp_elt_opcode (pstate, OP_TYPE); } ; primary : INT - { write_int ((LONGEST) $1.val, $1.type); } + { write_int (pstate, (LONGEST) $1.val, $1.type); } ; primary : CHARLIT - { write_int (convert_char_literal (type_qualifier, $1.val), + { write_int (pstate, + convert_char_literal (type_qualifier, $1.val), (type_qualifier == NULL) ? $1.type : type_qualifier); } ; primary : FLOAT - { write_exp_elt_opcode (OP_DOUBLE); - write_exp_elt_type ($1.type); - write_exp_elt_dblcst ($1.dval); - write_exp_elt_opcode (OP_DOUBLE); + { write_exp_elt_opcode (pstate, OP_DOUBLE); + write_exp_elt_type (pstate, $1.type); + write_exp_elt_dblcst (pstate, $1.dval); + write_exp_elt_opcode (pstate, OP_DOUBLE); } ; primary : NULL_PTR - { write_int (0, type_int ()); } + { write_int (pstate, 0, type_int (pstate)); } ; primary : STRING { - write_exp_op_with_string (OP_STRING, $1); + write_exp_op_with_string (pstate, OP_STRING, $1); } ; primary : TRUEKEYWORD - { write_int (1, type_boolean ()); } + { write_int (pstate, 1, type_boolean (pstate)); } | FALSEKEYWORD - { write_int (0, type_boolean ()); } + { write_int (pstate, 0, type_boolean (pstate)); } ; primary : NEW NAME @@ -619,22 +633,22 @@ primary : NEW NAME ; var_or_type: NAME %prec VAR - { $$ = write_var_or_type (NULL, $1); } + { $$ = write_var_or_type (pstate, NULL, $1); } | block NAME %prec VAR - { $$ = write_var_or_type ($1, $2); } + { $$ = write_var_or_type (pstate, $1, $2); } | NAME TICK_ACCESS { - $$ = write_var_or_type (NULL, $1); + $$ = write_var_or_type (pstate, NULL, $1); if ($$ == NULL) - write_exp_elt_opcode (UNOP_ADDR); + write_exp_elt_opcode (pstate, UNOP_ADDR); else $$ = lookup_pointer_type ($$); } | block NAME TICK_ACCESS { - $$ = write_var_or_type ($1, $2); + $$ = write_var_or_type (pstate, $1, $2); if ($$ == NULL) - write_exp_elt_opcode (UNOP_ADDR); + write_exp_elt_opcode (pstate, UNOP_ADDR); else $$ = lookup_pointer_type ($$); } @@ -650,18 +664,18 @@ block : NAME COLONCOLON aggregate : '(' aggregate_component_list ')' { - write_exp_elt_opcode (OP_AGGREGATE); - write_exp_elt_longcst ($2); - write_exp_elt_opcode (OP_AGGREGATE); + write_exp_elt_opcode (pstate, OP_AGGREGATE); + write_exp_elt_longcst (pstate, $2); + write_exp_elt_opcode (pstate, OP_AGGREGATE); } ; aggregate_component_list : component_groups { $$ = $1; } | positional_list exp - { write_exp_elt_opcode (OP_POSITIONAL); - write_exp_elt_longcst ($1); - write_exp_elt_opcode (OP_POSITIONAL); + { write_exp_elt_opcode (pstate, OP_POSITIONAL); + write_exp_elt_longcst (pstate, $1); + write_exp_elt_opcode (pstate, OP_POSITIONAL); $$ = $1 + 1; } | positional_list component_groups @@ -670,15 +684,15 @@ aggregate_component_list : positional_list : exp ',' - { write_exp_elt_opcode (OP_POSITIONAL); - write_exp_elt_longcst (0); - write_exp_elt_opcode (OP_POSITIONAL); + { write_exp_elt_opcode (pstate, OP_POSITIONAL); + write_exp_elt_longcst (pstate, 0); + write_exp_elt_opcode (pstate, OP_POSITIONAL); $$ = 1; } | positional_list exp ',' - { write_exp_elt_opcode (OP_POSITIONAL); - write_exp_elt_longcst ($1); - write_exp_elt_opcode (OP_POSITIONAL); + { write_exp_elt_opcode (pstate, OP_POSITIONAL); + write_exp_elt_longcst (pstate, $1); + write_exp_elt_opcode (pstate, OP_POSITIONAL); $$ = $1 + 1; } ; @@ -691,15 +705,15 @@ component_groups: ; others : OTHERS ARROW exp - { write_exp_elt_opcode (OP_OTHERS); } + { write_exp_elt_opcode (pstate, OP_OTHERS); } ; component_group : component_associations { - write_exp_elt_opcode (OP_CHOICES); - write_exp_elt_longcst ($1); - write_exp_elt_opcode (OP_CHOICES); + write_exp_elt_opcode (pstate, OP_CHOICES); + write_exp_elt_longcst (pstate, $1); + write_exp_elt_opcode (pstate, OP_CHOICES); } ; @@ -710,22 +724,23 @@ component_group : resolved shift/reduce conflict. */ component_associations : NAME ARROW - { write_name_assoc ($1); } + { write_name_assoc (pstate, $1); } exp { $$ = 1; } | simple_exp ARROW exp { $$ = 1; } | simple_exp DOTDOT simple_exp ARROW - { write_exp_elt_opcode (OP_DISCRETE_RANGE); - write_exp_op_with_string (OP_NAME, empty_stoken); + { write_exp_elt_opcode (pstate, OP_DISCRETE_RANGE); + write_exp_op_with_string (pstate, OP_NAME, + empty_stoken); } exp { $$ = 1; } | NAME '|' - { write_name_assoc ($1); } + { write_name_assoc (pstate, $1); } component_associations { $$ = $4 + 1; } | simple_exp '|' component_associations { $$ = $3 + 1; } | simple_exp DOTDOT simple_exp '|' - { write_exp_elt_opcode (OP_DISCRETE_RANGE); } + { write_exp_elt_opcode (pstate, OP_DISCRETE_RANGE); } component_associations { $$ = $6 + 1; } ; @@ -733,11 +748,11 @@ component_associations : can't get used to Ada notation in GDB. */ primary : '*' primary %prec '.' - { write_exp_elt_opcode (UNOP_IND); } + { write_exp_elt_opcode (pstate, UNOP_IND); } | '&' primary %prec '.' - { write_exp_elt_opcode (UNOP_ADDR); } + { write_exp_elt_opcode (pstate, UNOP_ADDR); } | primary '[' exp ']' - { write_exp_elt_opcode (BINOP_SUBSCRIPT); } + { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); } ; %% @@ -768,14 +783,23 @@ static struct obstack temp_parse_space; #include "ada-lex.c" int -ada_parse (void) +ada_parse (struct parser_state *par_state) { + int result; + struct cleanup *c = make_cleanup_clear_parser_state (&pstate); + + /* Setting up the parser state. */ + gdb_assert (par_state != NULL); + pstate = par_state; + lexer_init (yyin); /* (Re-)initialize lexer. */ type_qualifier = NULL; obstack_free (&temp_parse_space, NULL); obstack_init (&temp_parse_space); - return _ada_parse (); + result = yyparse (); + do_cleanups (c); + return result; } void @@ -787,7 +811,8 @@ yyerror (char *msg) /* Emit expression to access an instance of SYM, in block BLOCK (if * non-NULL), and with :: qualification ORIG_LEFT_CONTEXT. */ static void -write_var_from_sym (const struct block *orig_left_context, +write_var_from_sym (struct parser_state *par_state, + const struct block *orig_left_context, const struct block *block, struct symbol *sym) { @@ -798,30 +823,31 @@ write_var_from_sym (const struct block *orig_left_context, innermost_block = block; } - write_exp_elt_opcode (OP_VAR_VALUE); - write_exp_elt_block (block); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_opcode (par_state, OP_VAR_VALUE); + write_exp_elt_block (par_state, block); + write_exp_elt_sym (par_state, sym); + write_exp_elt_opcode (par_state, OP_VAR_VALUE); } /* Write integer or boolean constant ARG of type TYPE. */ static void -write_int (LONGEST arg, struct type *type) +write_int (struct parser_state *par_state, LONGEST arg, struct type *type) { - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (type); - write_exp_elt_longcst (arg); - write_exp_elt_opcode (OP_LONG); + write_exp_elt_opcode (par_state, OP_LONG); + write_exp_elt_type (par_state, type); + write_exp_elt_longcst (par_state, arg); + write_exp_elt_opcode (par_state, OP_LONG); } /* Write an OPCODE, string, OPCODE sequence to the current expression. */ static void -write_exp_op_with_string (enum exp_opcode opcode, struct stoken token) +write_exp_op_with_string (struct parser_state *par_state, + enum exp_opcode opcode, struct stoken token) { - write_exp_elt_opcode (opcode); - write_exp_string (token); - write_exp_elt_opcode (opcode); + write_exp_elt_opcode (par_state, opcode); + write_exp_string (par_state, token); + write_exp_elt_opcode (par_state, opcode); } /* Emit expression corresponding to the renamed object named @@ -836,7 +862,8 @@ write_exp_op_with_string (enum exp_opcode opcode, struct stoken token) * new encoding entirely (FIXME pnh 7/20/2007). */ static void -write_object_renaming (const struct block *orig_left_context, +write_object_renaming (struct parser_state *par_state, + const struct block *orig_left_context, const char *renamed_entity, int renamed_entity_len, const char *renaming_expr, int max_depth) { @@ -869,10 +896,11 @@ write_object_renaming (const struct block *orig_left_context, &inner_renaming_expr)) { case ADA_NOT_RENAMING: - write_var_from_sym (orig_left_context, sym_info.block, sym_info.sym); + write_var_from_sym (par_state, orig_left_context, sym_info.block, + sym_info.sym); break; case ADA_OBJECT_RENAMING: - write_object_renaming (sym_info.block, + write_object_renaming (par_state, sym_info.block, inner_renamed_entity, inner_renamed_entity_len, inner_renaming_expr, max_depth - 1); break; @@ -889,7 +917,7 @@ write_object_renaming (const struct block *orig_left_context, switch (*renaming_expr) { case 'A': renaming_expr += 1; - write_exp_elt_opcode (UNOP_IND); + write_exp_elt_opcode (par_state, UNOP_IND); break; case 'L': slice_state = LOWER_BOUND; @@ -903,10 +931,10 @@ write_object_renaming (const struct block *orig_left_context, if (next == renaming_expr) goto BadEncoding; renaming_expr = next; - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (type_int ()); - write_exp_elt_longcst ((LONGEST) val); - write_exp_elt_opcode (OP_LONG); + write_exp_elt_opcode (par_state, OP_LONG); + write_exp_elt_type (par_state, type_int (par_state)); + write_exp_elt_longcst (par_state, (LONGEST) val); + write_exp_elt_opcode (par_state, OP_LONG); } else { @@ -930,20 +958,20 @@ write_object_renaming (const struct block *orig_left_context, else if (SYMBOL_CLASS (index_sym_info.sym) == LOC_TYPEDEF) /* Index is an old-style renaming symbol. */ index_sym_info.block = orig_left_context; - write_var_from_sym (NULL, index_sym_info.block, + write_var_from_sym (par_state, NULL, index_sym_info.block, index_sym_info.sym); } if (slice_state == SIMPLE_INDEX) { - write_exp_elt_opcode (OP_FUNCALL); - write_exp_elt_longcst ((LONGEST) 1); - write_exp_elt_opcode (OP_FUNCALL); + write_exp_elt_opcode (par_state, OP_FUNCALL); + write_exp_elt_longcst (par_state, (LONGEST) 1); + write_exp_elt_opcode (par_state, OP_FUNCALL); } else if (slice_state == LOWER_BOUND) slice_state = UPPER_BOUND; else if (slice_state == UPPER_BOUND) { - write_exp_elt_opcode (TERNOP_SLICE); + write_exp_elt_opcode (par_state, TERNOP_SLICE); slice_state = SIMPLE_INDEX; } break; @@ -967,7 +995,7 @@ write_object_renaming (const struct block *orig_left_context, strncpy (buf, renaming_expr, end - renaming_expr); buf[end - renaming_expr] = '\000'; renaming_expr = end; - write_exp_op_with_string (STRUCTOP_STRUCT, field_name); + write_exp_op_with_string (par_state, STRUCTOP_STRUCT, field_name); break; } @@ -1056,14 +1084,14 @@ select_possible_type_sym (struct ada_symbol_info *syms, int nsyms) } static struct type* -find_primitive_type (char *name) +find_primitive_type (struct parser_state *par_state, char *name) { struct type *type; - type = language_lookup_primitive_type_by_name (parse_language, - parse_gdbarch, + type = language_lookup_primitive_type_by_name (parse_language (par_state), + parse_gdbarch (par_state), name); if (type == NULL && strcmp ("system__address", name) == 0) - type = type_system_address (); + type = type_system_address (par_state); if (type != NULL) { @@ -1112,7 +1140,7 @@ chop_separator (char *name) <sep> is '__' or '.', write the indicated sequence of STRUCTOP_STRUCT expression operators. */ static void -write_selectors (char *sels) +write_selectors (struct parser_state *par_state, char *sels) { while (*sels != '\0') { @@ -1124,7 +1152,7 @@ write_selectors (char *sels) sels += 1; field_name.length = sels - p; field_name.ptr = p; - write_exp_op_with_string (STRUCTOP_STRUCT, field_name); + write_exp_op_with_string (par_state, STRUCTOP_STRUCT, field_name); } } @@ -1133,7 +1161,8 @@ write_selectors (char *sels) a temporary symbol that is valid until the next call to ada_parse. */ static void -write_ambiguous_var (const struct block *block, char *name, int len) +write_ambiguous_var (struct parser_state *par_state, + const struct block *block, char *name, int len) { struct symbol *sym = obstack_alloc (&temp_parse_space, sizeof (struct symbol)); @@ -1142,10 +1171,10 @@ write_ambiguous_var (const struct block *block, char *name, int len) SYMBOL_LINKAGE_NAME (sym) = obstack_copy0 (&temp_parse_space, name, len); SYMBOL_LANGUAGE (sym) = language_ada; - write_exp_elt_opcode (OP_VAR_VALUE); - write_exp_elt_block (block); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_opcode (par_state, OP_VAR_VALUE); + write_exp_elt_block (par_state, block); + write_exp_elt_sym (par_state, sym); + write_exp_elt_opcode (par_state, OP_VAR_VALUE); } /* A convenient wrapper around ada_get_field_index that takes @@ -1225,7 +1254,8 @@ get_symbol_field_type (struct symbol *sym, char *encoded_field_name) identifier). */ static struct type* -write_var_or_type (const struct block *block, struct stoken name0) +write_var_or_type (struct parser_state *par_state, + const struct block *block, struct stoken name0) { int depth; char *encoded_name; @@ -1299,9 +1329,9 @@ write_var_or_type (const struct block *block, struct stoken name0) goto TryAfterRenaming; } case ADA_OBJECT_RENAMING: - write_object_renaming (block, renaming, renaming_len, + write_object_renaming (par_state, block, renaming, renaming_len, renaming_expr, MAX_RENAMING_CHAIN_LENGTH); - write_selectors (encoded_name + tail_index); + write_selectors (par_state, encoded_name + tail_index); return NULL; default: internal_error (__FILE__, __LINE__, @@ -1328,7 +1358,8 @@ write_var_or_type (const struct block *block, struct stoken name0) } else if (tail_index == name_len && nsyms == 0) { - struct type *type = find_primitive_type (encoded_name); + struct type *type = find_primitive_type (par_state, + encoded_name); if (type != NULL) return type; @@ -1336,8 +1367,9 @@ write_var_or_type (const struct block *block, struct stoken name0) if (nsyms == 1) { - write_var_from_sym (block, syms[0].block, syms[0].sym); - write_selectors (encoded_name + tail_index); + write_var_from_sym (par_state, block, syms[0].block, + syms[0].sym); + write_selectors (par_state, encoded_name + tail_index); return NULL; } else if (nsyms == 0) @@ -1346,9 +1378,9 @@ write_var_or_type (const struct block *block, struct stoken name0) = ada_lookup_simple_minsym (encoded_name); if (msym.minsym != NULL) { - write_exp_msymbol (msym); + write_exp_msymbol (par_state, msym); /* Maybe cause error here rather than later? FIXME? */ - write_selectors (encoded_name + tail_index); + write_selectors (par_state, encoded_name + tail_index); return NULL; } @@ -1361,8 +1393,9 @@ write_var_or_type (const struct block *block, struct stoken name0) } else { - write_ambiguous_var (block, encoded_name, tail_index); - write_selectors (encoded_name + tail_index); + write_ambiguous_var (par_state, block, encoded_name, + tail_index); + write_selectors (par_state, encoded_name + tail_index); return NULL; } } @@ -1397,7 +1430,7 @@ write_var_or_type (const struct block *block, struct stoken name0) ambiguous name, one must write instead ((R) => 42). */ static void -write_name_assoc (struct stoken name) +write_name_assoc (struct parser_state *par_state, struct stoken name) { if (strchr (name.ptr, '.') == NULL) { @@ -1405,12 +1438,12 @@ write_name_assoc (struct stoken name) int nsyms = ada_lookup_symbol_list (name.ptr, expression_context_block, VAR_DOMAIN, &syms); if (nsyms != 1 || SYMBOL_CLASS (syms[0].sym) == LOC_TYPEDEF) - write_exp_op_with_string (OP_NAME, name); + write_exp_op_with_string (par_state, OP_NAME, name); else - write_var_from_sym (NULL, syms[0].block, syms[0].sym); + write_var_from_sym (par_state, NULL, syms[0].block, syms[0].sym); } else - if (write_var_or_type (NULL, name) != NULL) + if (write_var_or_type (par_state, NULL, name) != NULL) error (_("Invalid use of type.")); } @@ -1441,61 +1474,62 @@ convert_char_literal (struct type *type, LONGEST val) } static struct type * -type_int (void) +type_int (struct parser_state *par_state) { - return parse_type->builtin_int; + return parse_type (par_state)->builtin_int; } static struct type * -type_long (void) +type_long (struct parser_state *par_state) { - return parse_type->builtin_long; + return parse_type (par_state)->builtin_long; } static struct type * -type_long_long (void) +type_long_long (struct parser_state *par_state) { - return parse_type->builtin_long_long; + return parse_type (par_state)->builtin_long_long; } static struct type * -type_float (void) +type_float (struct parser_state *par_state) { - return parse_type->builtin_float; + return parse_type (par_state)->builtin_float; } static struct type * -type_double (void) +type_double (struct parser_state *par_state) { - return parse_type->builtin_double; + return parse_type (par_state)->builtin_double; } static struct type * -type_long_double (void) +type_long_double (struct parser_state *par_state) { - return parse_type->builtin_long_double; + return parse_type (par_state)->builtin_long_double; } static struct type * -type_char (void) +type_char (struct parser_state *par_state) { - return language_string_char_type (parse_language, parse_gdbarch); + return language_string_char_type (parse_language (par_state), + parse_gdbarch (par_state)); } static struct type * -type_boolean (void) +type_boolean (struct parser_state *par_state) { - return parse_type->builtin_bool; + return parse_type (par_state)->builtin_bool; } static struct type * -type_system_address (void) +type_system_address (struct parser_state *par_state) { struct type *type - = language_lookup_primitive_type_by_name (parse_language, - parse_gdbarch, + = language_lookup_primitive_type_by_name (parse_language (par_state), + parse_gdbarch (par_state), "system__address"); - return type != NULL ? type : parse_type->builtin_data_ptr; + return type != NULL ? type : parse_type (par_state)->builtin_data_ptr; } /* Provide a prototype to silence -Wmissing-prototypes. */ diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 38df182..71827ae 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -13376,10 +13376,10 @@ emit_char (int c, struct type *type, struct ui_file *stream, int quoter) } static int -parse (void) +parse (struct parser_state *ps) { warnings_issued = 0; - return ada_parse (); + return ada_parse (ps); } static const struct exp_descriptor ada_exp_descriptor = { diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h index c053278..6356cfa 100644 --- a/gdb/ada-lang.h +++ b/gdb/ada-lang.h @@ -23,6 +23,7 @@ struct frame_info; struct inferior; struct type_print_options; +struct parser_state; #include "value.h" #include "gdbtypes.h" @@ -169,7 +170,7 @@ extern int ada_get_field_index (const struct type *type, const char *field_name, int maybe_missing); -extern int ada_parse (void); /* Defined in ada-exp.y */ +extern int ada_parse (struct parser_state *); /* Defined in ada-exp.y */ extern void ada_error (char *); /* Defined in ada-exp.y */ diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l index 0787a0f..9632073 100644 --- a/gdb/ada-lex.l +++ b/gdb/ada-lex.l @@ -48,8 +48,9 @@ POSEXP (e"+"?{NUM10}) static char numbuf[NUMERAL_WIDTH]; static void canonicalizeNumeral (char *s1, const char *); static struct stoken processString (const char*, int); -static int processInt (const char *, const char *, const char *); -static int processReal (const char *); +static int processInt (struct parser_state *, const char *, const char *, + const char *); +static int processReal (struct parser_state *, const char *); static struct stoken processId (const char *, int); static int processAttribute (const char *); static int find_dot_all (const char *); @@ -89,40 +90,42 @@ static int find_dot_all (const char *); {NUM10}{POSEXP} { canonicalizeNumeral (numbuf, yytext); - return processInt (NULL, numbuf, strrchr(numbuf, 'e')+1); + return processInt (pstate, NULL, numbuf, + strrchr (numbuf, 'e') + 1); } {NUM10} { canonicalizeNumeral (numbuf, yytext); - return processInt (NULL, numbuf, NULL); + return processInt (pstate, NULL, numbuf, NULL); } {NUM10}"#"{HEXDIG}({HEXDIG}|_)*"#"{POSEXP} { canonicalizeNumeral (numbuf, yytext); - return processInt (numbuf, + return processInt (pstate, numbuf, strchr (numbuf, '#') + 1, strrchr(numbuf, '#') + 1); } {NUM10}"#"{HEXDIG}({HEXDIG}|_)*"#" { canonicalizeNumeral (numbuf, yytext); - return processInt (numbuf, strchr (numbuf, '#') + 1, NULL); + return processInt (pstate, numbuf, strchr (numbuf, '#') + 1, + NULL); } "0x"{HEXDIG}+ { canonicalizeNumeral (numbuf, yytext+2); - return processInt ("16#", numbuf, NULL); + return processInt (pstate, "16#", numbuf, NULL); } {NUM10}"."{NUM10}{EXP} { canonicalizeNumeral (numbuf, yytext); - return processReal (numbuf); + return processReal (pstate, numbuf); } {NUM10}"."{NUM10} { canonicalizeNumeral (numbuf, yytext); - return processReal (numbuf); + return processReal (pstate, numbuf); } {NUM10}"#"{NUM16}"."{NUM16}"#"{EXP} { @@ -134,14 +137,14 @@ static int find_dot_all (const char *); } <INITIAL>"'"({GRAPHIC}|\")"'" { - yylval.typed_val.type = type_char (); + yylval.typed_val.type = type_char (pstate); yylval.typed_val.val = yytext[1]; return CHARLIT; } <INITIAL>"'[\""{HEXDIG}{2}"\"]'" { int v; - yylval.typed_val.type = type_char (); + yylval.typed_val.type = type_char (pstate); sscanf (yytext+3, "%2x", &v); yylval.typed_val.val = v; return CHARLIT; @@ -324,7 +327,8 @@ canonicalizeNumeral (char *s1, const char *s2) */ static int -processInt (const char *base0, const char *num0, const char *exp0) +processInt (struct parser_state *par_state, const char *base0, + const char *num0, const char *exp0) { ULONGEST result; long exp; @@ -360,11 +364,11 @@ processInt (const char *base0, const char *num0, const char *exp0) exp -= 1; } - if ((result >> (gdbarch_int_bit (parse_gdbarch)-1)) == 0) - yylval.typed_val.type = type_int (); - else if ((result >> (gdbarch_long_bit (parse_gdbarch)-1)) == 0) - yylval.typed_val.type = type_long (); - else if (((result >> (gdbarch_long_bit (parse_gdbarch)-1)) >> 1) == 0) + if ((result >> (gdbarch_int_bit (parse_gdbarch (par_state))-1)) == 0) + yylval.typed_val.type = type_int (par_state); + else if ((result >> (gdbarch_long_bit (parse_gdbarch (par_state))-1)) == 0) + yylval.typed_val.type = type_long (par_state); + else if (((result >> (gdbarch_long_bit (parse_gdbarch (par_state))-1)) >> 1) == 0) { /* We have a number representable as an unsigned integer quantity. For consistency with the C treatment, we will treat it as an @@ -374,7 +378,7 @@ processInt (const char *base0, const char *num0, const char *exp0) assignment does the trick (no, it doesn't; read the reference manual). */ yylval.typed_val.type - = builtin_type (parse_gdbarch)->builtin_unsigned_long; + = builtin_type (parse_gdbarch (par_state))->builtin_unsigned_long; if (result & LONGEST_SIGN) yylval.typed_val.val = (LONGEST) (result & ~LONGEST_SIGN) @@ -384,24 +388,24 @@ processInt (const char *base0, const char *num0, const char *exp0) return INT; } else - yylval.typed_val.type = type_long_long (); + yylval.typed_val.type = type_long_long (par_state); yylval.typed_val.val = (LONGEST) result; return INT; } static int -processReal (const char *num0) +processReal (struct parser_state *par_state, const char *num0) { sscanf (num0, "%" DOUBLEST_SCAN_FORMAT, &yylval.typed_val_float.dval); - yylval.typed_val_float.type = type_float (); - if (sizeof(DOUBLEST) >= gdbarch_double_bit (parse_gdbarch) + yylval.typed_val_float.type = type_float (par_state); + if (sizeof(DOUBLEST) >= gdbarch_double_bit (parse_gdbarch (par_state)) / TARGET_CHAR_BIT) - yylval.typed_val_float.type = type_double (); - if (sizeof(DOUBLEST) >= gdbarch_long_double_bit (parse_gdbarch) + yylval.typed_val_float.type = type_double (par_state); + if (sizeof(DOUBLEST) >= gdbarch_long_double_bit (parse_gdbarch (par_state)) / TARGET_CHAR_BIT) - yylval.typed_val_float.type = type_long_double (); + yylval.typed_val_float.type = type_long_double (par_state); return FLOAT; } diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c index de0c211..98b912b 100644 --- a/gdb/arm-linux-tdep.c +++ b/gdb/arm-linux-tdep.c @@ -1206,28 +1206,28 @@ arm_stap_parse_special_token (struct gdbarch *gdbarch, return 0; /* The displacement. */ - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type (gdbarch)->builtin_long); - write_exp_elt_longcst (displacement); - write_exp_elt_opcode (OP_LONG); + write_exp_elt_opcode (&p->pstate, OP_LONG); + write_exp_elt_type (&p->pstate, builtin_type (gdbarch)->builtin_long); + write_exp_elt_longcst (&p->pstate, displacement); + write_exp_elt_opcode (&p->pstate, OP_LONG); if (got_minus) - write_exp_elt_opcode (UNOP_NEG); + write_exp_elt_opcode (&p->pstate, UNOP_NEG); /* The register name. */ - write_exp_elt_opcode (OP_REGISTER); + write_exp_elt_opcode (&p->pstate, OP_REGISTER); str.ptr = regname; str.length = len; - write_exp_string (str); - write_exp_elt_opcode (OP_REGISTER); + write_exp_string (&p->pstate, str); + write_exp_elt_opcode (&p->pstate, OP_REGISTER); - write_exp_elt_opcode (BINOP_ADD); + write_exp_elt_opcode (&p->pstate, BINOP_ADD); /* Casting to the expected type. */ - write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type (lookup_pointer_type (p->arg_type)); - write_exp_elt_opcode (UNOP_CAST); + write_exp_elt_opcode (&p->pstate, UNOP_CAST); + write_exp_elt_type (&p->pstate, lookup_pointer_type (p->arg_type)); + write_exp_elt_opcode (&p->pstate, UNOP_CAST); - write_exp_elt_opcode (UNOP_IND); + write_exp_elt_opcode (&p->pstate, UNOP_IND); p->arg = tmp; } diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 11631ba..fc79807 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -56,7 +56,7 @@ #include "typeprint.h" #include "cp-abi.h" -#define parse_type builtin_type (parse_gdbarch) +#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 @@ -118,6 +118,11 @@ #define YYFPRINTF parser_fprintf +/* The state of the parser, used internally when we are parsing the + expression. */ + +static struct parser_state *pstate = NULL; + int yyparse (void); static int yylex (void); @@ -164,10 +169,12 @@ void yyerror (char *); %{ /* YYSTYPE gets defined by %union */ -static int parse_number (const char *, int, int, YYSTYPE *); +static int parse_number (struct parser_state *par_state, + const char *, int, int, YYSTYPE *); static struct stoken operator_stoken (const char *); static void check_parameter_typelist (VEC (type_ptr) *); -static void write_destructor_name (struct stoken); +static void write_destructor_name (struct parser_state *par_state, + struct stoken); #ifdef YYBISON static void c_print_token (FILE *file, int type, YYSTYPE value); @@ -283,186 +290,186 @@ start : exp1 ; type_exp: type - { write_exp_elt_opcode(OP_TYPE); - write_exp_elt_type($1); - write_exp_elt_opcode(OP_TYPE);} + { write_exp_elt_opcode(pstate, OP_TYPE); + write_exp_elt_type(pstate, $1); + write_exp_elt_opcode(pstate, OP_TYPE);} | TYPEOF '(' exp ')' { - write_exp_elt_opcode (OP_TYPEOF); + write_exp_elt_opcode (pstate, OP_TYPEOF); } | TYPEOF '(' type ')' { - write_exp_elt_opcode (OP_TYPE); - write_exp_elt_type ($3); - write_exp_elt_opcode (OP_TYPE); + write_exp_elt_opcode (pstate, OP_TYPE); + write_exp_elt_type (pstate, $3); + write_exp_elt_opcode (pstate, OP_TYPE); } | DECLTYPE '(' exp ')' { - write_exp_elt_opcode (OP_DECLTYPE); + write_exp_elt_opcode (pstate, OP_DECLTYPE); } ; /* Expressions, including the comma operator. */ exp1 : exp | exp1 ',' exp - { write_exp_elt_opcode (BINOP_COMMA); } + { write_exp_elt_opcode (pstate, BINOP_COMMA); } ; /* Expressions, not including the comma operator. */ exp : '*' exp %prec UNARY - { write_exp_elt_opcode (UNOP_IND); } + { write_exp_elt_opcode (pstate, UNOP_IND); } ; exp : '&' exp %prec UNARY - { write_exp_elt_opcode (UNOP_ADDR); } + { write_exp_elt_opcode (pstate, UNOP_ADDR); } ; exp : '-' exp %prec UNARY - { write_exp_elt_opcode (UNOP_NEG); } + { write_exp_elt_opcode (pstate, UNOP_NEG); } ; exp : '+' exp %prec UNARY - { write_exp_elt_opcode (UNOP_PLUS); } + { write_exp_elt_opcode (pstate, UNOP_PLUS); } ; exp : '!' exp %prec UNARY - { write_exp_elt_opcode (UNOP_LOGICAL_NOT); } + { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); } ; exp : '~' exp %prec UNARY - { write_exp_elt_opcode (UNOP_COMPLEMENT); } + { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); } ; exp : INCREMENT exp %prec UNARY - { write_exp_elt_opcode (UNOP_PREINCREMENT); } + { write_exp_elt_opcode (pstate, UNOP_PREINCREMENT); } ; exp : DECREMENT exp %prec UNARY - { write_exp_elt_opcode (UNOP_PREDECREMENT); } + { write_exp_elt_opcode (pstate, UNOP_PREDECREMENT); } ; exp : exp INCREMENT %prec UNARY - { write_exp_elt_opcode (UNOP_POSTINCREMENT); } + { write_exp_elt_opcode (pstate, UNOP_POSTINCREMENT); } ; exp : exp DECREMENT %prec UNARY - { write_exp_elt_opcode (UNOP_POSTDECREMENT); } + { write_exp_elt_opcode (pstate, UNOP_POSTDECREMENT); } ; exp : TYPEID '(' exp ')' %prec UNARY - { write_exp_elt_opcode (OP_TYPEID); } + { write_exp_elt_opcode (pstate, OP_TYPEID); } ; exp : TYPEID '(' type_exp ')' %prec UNARY - { write_exp_elt_opcode (OP_TYPEID); } + { write_exp_elt_opcode (pstate, OP_TYPEID); } ; exp : SIZEOF exp %prec UNARY - { write_exp_elt_opcode (UNOP_SIZEOF); } + { write_exp_elt_opcode (pstate, UNOP_SIZEOF); } ; exp : exp ARROW name - { write_exp_elt_opcode (STRUCTOP_PTR); - write_exp_string ($3); - write_exp_elt_opcode (STRUCTOP_PTR); } + { write_exp_elt_opcode (pstate, STRUCTOP_PTR); + write_exp_string (pstate, $3); + write_exp_elt_opcode (pstate, STRUCTOP_PTR); } ; exp : exp ARROW name COMPLETE - { mark_struct_expression (); - write_exp_elt_opcode (STRUCTOP_PTR); - write_exp_string ($3); - write_exp_elt_opcode (STRUCTOP_PTR); } + { mark_struct_expression (pstate); + write_exp_elt_opcode (pstate, STRUCTOP_PTR); + write_exp_string (pstate, $3); + write_exp_elt_opcode (pstate, STRUCTOP_PTR); } ; exp : exp ARROW COMPLETE { struct stoken s; - mark_struct_expression (); - write_exp_elt_opcode (STRUCTOP_PTR); + mark_struct_expression (pstate); + write_exp_elt_opcode (pstate, STRUCTOP_PTR); s.ptr = ""; s.length = 0; - write_exp_string (s); - write_exp_elt_opcode (STRUCTOP_PTR); } + write_exp_string (pstate, s); + write_exp_elt_opcode (pstate, STRUCTOP_PTR); } ; exp : exp ARROW '~' name - { write_exp_elt_opcode (STRUCTOP_PTR); - write_destructor_name ($4); - write_exp_elt_opcode (STRUCTOP_PTR); } + { write_exp_elt_opcode (pstate, STRUCTOP_PTR); + write_destructor_name (pstate, $4); + write_exp_elt_opcode (pstate, STRUCTOP_PTR); } ; exp : exp ARROW '~' name COMPLETE - { mark_struct_expression (); - write_exp_elt_opcode (STRUCTOP_PTR); - write_destructor_name ($4); - write_exp_elt_opcode (STRUCTOP_PTR); } + { mark_struct_expression (pstate); + write_exp_elt_opcode (pstate, STRUCTOP_PTR); + write_destructor_name (pstate, $4); + write_exp_elt_opcode (pstate, STRUCTOP_PTR); } ; exp : exp ARROW qualified_name { /* exp->type::name becomes exp->*(&type::name) */ /* Note: this doesn't work if name is a static member! FIXME */ - write_exp_elt_opcode (UNOP_ADDR); - write_exp_elt_opcode (STRUCTOP_MPTR); } + write_exp_elt_opcode (pstate, UNOP_ADDR); + write_exp_elt_opcode (pstate, STRUCTOP_MPTR); } ; exp : exp ARROW_STAR exp - { write_exp_elt_opcode (STRUCTOP_MPTR); } + { write_exp_elt_opcode (pstate, STRUCTOP_MPTR); } ; exp : exp '.' name - { write_exp_elt_opcode (STRUCTOP_STRUCT); - write_exp_string ($3); - write_exp_elt_opcode (STRUCTOP_STRUCT); } + { write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); + write_exp_string (pstate, $3); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } ; exp : exp '.' name COMPLETE - { mark_struct_expression (); - write_exp_elt_opcode (STRUCTOP_STRUCT); - write_exp_string ($3); - write_exp_elt_opcode (STRUCTOP_STRUCT); } + { mark_struct_expression (pstate); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); + write_exp_string (pstate, $3); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } ; exp : exp '.' COMPLETE { struct stoken s; - mark_struct_expression (); - write_exp_elt_opcode (STRUCTOP_STRUCT); + mark_struct_expression (pstate); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); s.ptr = ""; s.length = 0; - write_exp_string (s); - write_exp_elt_opcode (STRUCTOP_STRUCT); } + write_exp_string (pstate, s); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } ; exp : exp '.' '~' name - { write_exp_elt_opcode (STRUCTOP_STRUCT); - write_destructor_name ($4); - write_exp_elt_opcode (STRUCTOP_STRUCT); } + { write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); + write_destructor_name (pstate, $4); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } ; exp : exp '.' '~' name COMPLETE - { mark_struct_expression (); - write_exp_elt_opcode (STRUCTOP_STRUCT); - write_destructor_name ($4); - write_exp_elt_opcode (STRUCTOP_STRUCT); } + { mark_struct_expression (pstate); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); + write_destructor_name (pstate, $4); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } ; exp : exp '.' qualified_name { /* exp.type::name becomes exp.*(&type::name) */ /* Note: this doesn't work if name is a static member! FIXME */ - write_exp_elt_opcode (UNOP_ADDR); - write_exp_elt_opcode (STRUCTOP_MEMBER); } + write_exp_elt_opcode (pstate, UNOP_ADDR); + write_exp_elt_opcode (pstate, STRUCTOP_MEMBER); } ; exp : exp DOT_STAR exp - { write_exp_elt_opcode (STRUCTOP_MEMBER); } + { write_exp_elt_opcode (pstate, STRUCTOP_MEMBER); } ; exp : exp '[' exp1 ']' - { write_exp_elt_opcode (BINOP_SUBSCRIPT); } + { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); } ; exp : exp OBJC_LBRAC exp1 ']' - { write_exp_elt_opcode (BINOP_SUBSCRIPT); } + { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); } ; /* @@ -474,45 +481,47 @@ exp : OBJC_LBRAC TYPENAME { CORE_ADDR class; - class = lookup_objc_class (parse_gdbarch, + class = lookup_objc_class (parse_gdbarch (pstate), copy_name ($2.stoken)); if (class == 0) error (_("%s is not an ObjC Class"), copy_name ($2.stoken)); - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (parse_type->builtin_int); - write_exp_elt_longcst ((LONGEST) class); - write_exp_elt_opcode (OP_LONG); + write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, + parse_type (pstate)->builtin_int); + write_exp_elt_longcst (pstate, (LONGEST) class); + write_exp_elt_opcode (pstate, OP_LONG); start_msglist(); } msglist ']' - { write_exp_elt_opcode (OP_OBJC_MSGCALL); - end_msglist(); - write_exp_elt_opcode (OP_OBJC_MSGCALL); + { write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL); + end_msglist (pstate); + write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL); } ; exp : OBJC_LBRAC CLASSNAME { - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (parse_type->builtin_int); - write_exp_elt_longcst ((LONGEST) $2.class); - write_exp_elt_opcode (OP_LONG); + write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, + parse_type (pstate)->builtin_int); + write_exp_elt_longcst (pstate, (LONGEST) $2.class); + write_exp_elt_opcode (pstate, OP_LONG); start_msglist(); } msglist ']' - { write_exp_elt_opcode (OP_OBJC_MSGCALL); - end_msglist(); - write_exp_elt_opcode (OP_OBJC_MSGCALL); + { write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL); + end_msglist (pstate); + write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL); } ; exp : OBJC_LBRAC exp { start_msglist(); } msglist ']' - { write_exp_elt_opcode (OP_OBJC_MSGCALL); - end_msglist(); - write_exp_elt_opcode (OP_OBJC_MSGCALL); + { write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL); + end_msglist (pstate); + write_exp_elt_opcode (pstate, OP_OBJC_MSGCALL); } ; @@ -538,20 +547,23 @@ exp : exp '(' being accumulated by an outer function call. */ { start_arglist (); } arglist ')' %prec ARROW - { write_exp_elt_opcode (OP_FUNCALL); - write_exp_elt_longcst ((LONGEST) end_arglist ()); - write_exp_elt_opcode (OP_FUNCALL); } + { write_exp_elt_opcode (pstate, OP_FUNCALL); + write_exp_elt_longcst (pstate, + (LONGEST) end_arglist ()); + write_exp_elt_opcode (pstate, OP_FUNCALL); } ; exp : UNKNOWN_CPP_NAME '(' { /* This could potentially be a an argument defined lookup function (Koenig). */ - write_exp_elt_opcode (OP_ADL_FUNC); - write_exp_elt_block (expression_context_block); - write_exp_elt_sym (NULL); /* Placeholder. */ - write_exp_string ($1.stoken); - write_exp_elt_opcode (OP_ADL_FUNC); + write_exp_elt_opcode (pstate, OP_ADL_FUNC); + write_exp_elt_block (pstate, + expression_context_block); + write_exp_elt_sym (pstate, + NULL); /* Placeholder. */ + write_exp_string (pstate, $1.stoken); + write_exp_elt_opcode (pstate, OP_ADL_FUNC); /* This is to save the value of arglist_len being accumulated by an outer function call. */ @@ -560,9 +572,10 @@ exp : UNKNOWN_CPP_NAME '(' } arglist ')' %prec ARROW { - write_exp_elt_opcode (OP_FUNCALL); - write_exp_elt_longcst ((LONGEST) end_arglist ()); - write_exp_elt_opcode (OP_FUNCALL); + write_exp_elt_opcode (pstate, OP_FUNCALL); + write_exp_elt_longcst (pstate, + (LONGEST) end_arglist ()); + write_exp_elt_opcode (pstate, OP_FUNCALL); } ; @@ -587,14 +600,14 @@ exp : exp '(' parameter_typelist ')' const_or_volatile struct type *type_elt; LONGEST len = VEC_length (type_ptr, type_list); - write_exp_elt_opcode (TYPE_INSTANCE); - write_exp_elt_longcst (len); + write_exp_elt_opcode (pstate, TYPE_INSTANCE); + write_exp_elt_longcst (pstate, len); for (i = 0; VEC_iterate (type_ptr, type_list, i, type_elt); ++i) - write_exp_elt_type (type_elt); - write_exp_elt_longcst(len); - write_exp_elt_opcode (TYPE_INSTANCE); + write_exp_elt_type (pstate, type_elt); + write_exp_elt_longcst(pstate, len); + write_exp_elt_opcode (pstate, TYPE_INSTANCE); VEC_free (type_ptr, type_list); } ; @@ -603,18 +616,18 @@ rcurly : '}' { $$ = end_arglist () - 1; } ; exp : lcurly arglist rcurly %prec ARROW - { write_exp_elt_opcode (OP_ARRAY); - write_exp_elt_longcst ((LONGEST) 0); - write_exp_elt_longcst ((LONGEST) $3); - write_exp_elt_opcode (OP_ARRAY); } + { write_exp_elt_opcode (pstate, OP_ARRAY); + write_exp_elt_longcst (pstate, (LONGEST) 0); + write_exp_elt_longcst (pstate, (LONGEST) $3); + write_exp_elt_opcode (pstate, OP_ARRAY); } ; exp : lcurly type_exp rcurly exp %prec UNARY - { write_exp_elt_opcode (UNOP_MEMVAL_TYPE); } + { write_exp_elt_opcode (pstate, UNOP_MEMVAL_TYPE); } ; exp : '(' type_exp ')' exp %prec UNARY - { write_exp_elt_opcode (UNOP_CAST_TYPE); } + { write_exp_elt_opcode (pstate, UNOP_CAST_TYPE); } ; exp : '(' exp1 ')' @@ -624,100 +637,101 @@ exp : '(' exp1 ')' /* Binary operators in order of decreasing precedence. */ exp : exp '@' exp - { write_exp_elt_opcode (BINOP_REPEAT); } + { write_exp_elt_opcode (pstate, BINOP_REPEAT); } ; exp : exp '*' exp - { write_exp_elt_opcode (BINOP_MUL); } + { write_exp_elt_opcode (pstate, BINOP_MUL); } ; exp : exp '/' exp - { write_exp_elt_opcode (BINOP_DIV); } + { write_exp_elt_opcode (pstate, BINOP_DIV); } ; exp : exp '%' exp - { write_exp_elt_opcode (BINOP_REM); } + { write_exp_elt_opcode (pstate, BINOP_REM); } ; exp : exp '+' exp - { write_exp_elt_opcode (BINOP_ADD); } + { write_exp_elt_opcode (pstate, BINOP_ADD); } ; exp : exp '-' exp - { write_exp_elt_opcode (BINOP_SUB); } + { write_exp_elt_opcode (pstate, BINOP_SUB); } ; exp : exp LSH exp - { write_exp_elt_opcode (BINOP_LSH); } + { write_exp_elt_opcode (pstate, BINOP_LSH); } ; exp : exp RSH exp - { write_exp_elt_opcode (BINOP_RSH); } + { write_exp_elt_opcode (pstate, BINOP_RSH); } ; exp : exp EQUAL exp - { write_exp_elt_opcode (BINOP_EQUAL); } + { write_exp_elt_opcode (pstate, BINOP_EQUAL); } ; exp : exp NOTEQUAL exp - { write_exp_elt_opcode (BINOP_NOTEQUAL); } + { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); } ; exp : exp LEQ exp - { write_exp_elt_opcode (BINOP_LEQ); } + { write_exp_elt_opcode (pstate, BINOP_LEQ); } ; exp : exp GEQ exp - { write_exp_elt_opcode (BINOP_GEQ); } + { write_exp_elt_opcode (pstate, BINOP_GEQ); } ; exp : exp '<' exp - { write_exp_elt_opcode (BINOP_LESS); } + { write_exp_elt_opcode (pstate, BINOP_LESS); } ; exp : exp '>' exp - { write_exp_elt_opcode (BINOP_GTR); } + { write_exp_elt_opcode (pstate, BINOP_GTR); } ; exp : exp '&' exp - { write_exp_elt_opcode (BINOP_BITWISE_AND); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); } ; exp : exp '^' exp - { write_exp_elt_opcode (BINOP_BITWISE_XOR); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); } ; exp : exp '|' exp - { write_exp_elt_opcode (BINOP_BITWISE_IOR); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); } ; exp : exp ANDAND exp - { write_exp_elt_opcode (BINOP_LOGICAL_AND); } + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); } ; exp : exp OROR exp - { write_exp_elt_opcode (BINOP_LOGICAL_OR); } + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); } ; exp : exp '?' exp ':' exp %prec '?' - { write_exp_elt_opcode (TERNOP_COND); } + { write_exp_elt_opcode (pstate, TERNOP_COND); } ; exp : exp '=' exp - { write_exp_elt_opcode (BINOP_ASSIGN); } + { write_exp_elt_opcode (pstate, BINOP_ASSIGN); } ; exp : exp ASSIGN_MODIFY exp - { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); - write_exp_elt_opcode ($2); - write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); } + { write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); + write_exp_elt_opcode (pstate, $2); + write_exp_elt_opcode (pstate, + BINOP_ASSIGN_MODIFY); } ; exp : INT - { write_exp_elt_opcode (OP_LONG); - write_exp_elt_type ($1.type); - write_exp_elt_longcst ((LONGEST)($1.val)); - write_exp_elt_opcode (OP_LONG); } + { write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, $1.type); + write_exp_elt_longcst (pstate, (LONGEST) ($1.val)); + write_exp_elt_opcode (pstate, OP_LONG); } ; exp : CHAR @@ -725,33 +739,35 @@ exp : CHAR struct stoken_vector vec; vec.len = 1; vec.tokens = &$1; - write_exp_string_vector ($1.type, &vec); + write_exp_string_vector (pstate, $1.type, &vec); } ; exp : NAME_OR_INT { YYSTYPE val; - parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val); - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (val.typed_val_int.type); - write_exp_elt_longcst ((LONGEST)val.typed_val_int.val); - write_exp_elt_opcode (OP_LONG); + parse_number (pstate, $1.stoken.ptr, + $1.stoken.length, 0, &val); + write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, val.typed_val_int.type); + write_exp_elt_longcst (pstate, + (LONGEST) val.typed_val_int.val); + write_exp_elt_opcode (pstate, OP_LONG); } ; exp : FLOAT - { write_exp_elt_opcode (OP_DOUBLE); - write_exp_elt_type ($1.type); - write_exp_elt_dblcst ($1.dval); - write_exp_elt_opcode (OP_DOUBLE); } + { write_exp_elt_opcode (pstate, OP_DOUBLE); + write_exp_elt_type (pstate, $1.type); + write_exp_elt_dblcst (pstate, $1.dval); + write_exp_elt_opcode (pstate, OP_DOUBLE); } ; exp : DECFLOAT - { write_exp_elt_opcode (OP_DECFLOAT); - write_exp_elt_type ($1.type); - write_exp_elt_decfloatcst ($1.val); - write_exp_elt_opcode (OP_DECFLOAT); } + { write_exp_elt_opcode (pstate, OP_DECFLOAT); + write_exp_elt_type (pstate, $1.type); + write_exp_elt_decfloatcst (pstate, $1.val); + write_exp_elt_opcode (pstate, OP_DECFLOAT); } ; exp : variable @@ -759,43 +775,46 @@ exp : variable exp : VARIABLE { - write_dollar_variable ($1); + write_dollar_variable (pstate, $1); } ; exp : SELECTOR '(' name ')' { - write_exp_elt_opcode (OP_OBJC_SELECTOR); - write_exp_string ($3); - write_exp_elt_opcode (OP_OBJC_SELECTOR); } + write_exp_elt_opcode (pstate, OP_OBJC_SELECTOR); + write_exp_string (pstate, $3); + write_exp_elt_opcode (pstate, OP_OBJC_SELECTOR); } ; exp : SIZEOF '(' type ')' %prec UNARY - { write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (lookup_signed_typename - (parse_language, parse_gdbarch, + { write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, lookup_signed_typename + (parse_language (pstate), + parse_gdbarch (pstate), "int")); CHECK_TYPEDEF ($3); - write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3)); - write_exp_elt_opcode (OP_LONG); } + write_exp_elt_longcst (pstate, + (LONGEST) TYPE_LENGTH ($3)); + write_exp_elt_opcode (pstate, OP_LONG); } ; exp : REINTERPRET_CAST '<' type_exp '>' '(' exp ')' %prec UNARY - { write_exp_elt_opcode (UNOP_REINTERPRET_CAST); } + { write_exp_elt_opcode (pstate, + UNOP_REINTERPRET_CAST); } ; exp : STATIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY - { write_exp_elt_opcode (UNOP_CAST_TYPE); } + { write_exp_elt_opcode (pstate, UNOP_CAST_TYPE); } ; exp : DYNAMIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY - { write_exp_elt_opcode (UNOP_DYNAMIC_CAST); } + { write_exp_elt_opcode (pstate, UNOP_DYNAMIC_CAST); } ; exp : CONST_CAST '<' type_exp '>' '(' exp ')' %prec UNARY { /* We could do more error checking here, but it doesn't seem worthwhile. */ - write_exp_elt_opcode (UNOP_CAST_TYPE); } + write_exp_elt_opcode (pstate, UNOP_CAST_TYPE); } ; string_exp: @@ -860,7 +879,7 @@ exp : string_exp } } - write_exp_string_vector (type, &$1); + write_exp_string_vector (pstate, type, &$1); for (i = 0; i < $1.len; ++i) free ($1.tokens[i].ptr); free ($1.tokens); @@ -870,24 +889,26 @@ exp : string_exp exp : NSSTRING /* ObjC NextStep NSString constant * of the form '@' '"' string '"'. */ - { write_exp_elt_opcode (OP_OBJC_NSSTRING); - write_exp_string ($1); - write_exp_elt_opcode (OP_OBJC_NSSTRING); } + { write_exp_elt_opcode (pstate, OP_OBJC_NSSTRING); + write_exp_string (pstate, $1); + write_exp_elt_opcode (pstate, OP_OBJC_NSSTRING); } ; /* C++. */ exp : TRUEKEYWORD - { write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (parse_type->builtin_bool); - write_exp_elt_longcst ((LONGEST) 1); - write_exp_elt_opcode (OP_LONG); } + { write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, + parse_type (pstate)->builtin_bool); + write_exp_elt_longcst (pstate, (LONGEST) 1); + write_exp_elt_opcode (pstate, OP_LONG); } ; exp : FALSEKEYWORD - { write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (parse_type->builtin_bool); - write_exp_elt_longcst ((LONGEST) 0); - write_exp_elt_opcode (OP_LONG); } + { write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, + parse_type (pstate)->builtin_bool); + write_exp_elt_longcst (pstate, (LONGEST) 0); + write_exp_elt_opcode (pstate, OP_LONG); } ; /* end of C++. */ @@ -925,9 +946,9 @@ variable: name_not_typename ENTRY "parameters, not for \"%s\""), copy_name ($1.stoken)); - write_exp_elt_opcode (OP_VAR_ENTRY_VALUE); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_ENTRY_VALUE); + write_exp_elt_opcode (pstate, OP_VAR_ENTRY_VALUE); + write_exp_elt_sym (pstate, sym); + write_exp_elt_opcode (pstate, OP_VAR_ENTRY_VALUE); } ; @@ -946,11 +967,11 @@ variable: block COLONCOLON name innermost_block = block_found; } - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); /* block_found is set by lookup_symbol. */ - write_exp_elt_block (block_found); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); } + write_exp_elt_block (pstate, block_found); + write_exp_elt_sym (pstate, sym); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); } ; qualified_name: TYPENAME COLONCOLON name @@ -963,10 +984,10 @@ qualified_name: TYPENAME COLONCOLON name error (_("`%s' is not defined as an aggregate type."), TYPE_SAFE_NAME (type)); - write_exp_elt_opcode (OP_SCOPE); - write_exp_elt_type (type); - write_exp_string ($3); - write_exp_elt_opcode (OP_SCOPE); + write_exp_elt_opcode (pstate, OP_SCOPE); + write_exp_elt_type (pstate, type); + write_exp_string (pstate, $3); + write_exp_elt_opcode (pstate, OP_SCOPE); } | TYPENAME COLONCOLON '~' name { @@ -989,10 +1010,10 @@ qualified_name: TYPENAME COLONCOLON name /* Check for valid destructor name. */ destructor_name_p (tmp_token.ptr, $1.type); - write_exp_elt_opcode (OP_SCOPE); - write_exp_elt_type (type); - write_exp_string (tmp_token); - write_exp_elt_opcode (OP_SCOPE); + write_exp_elt_opcode (pstate, OP_SCOPE); + write_exp_elt_type (pstate, type); + write_exp_string (pstate, tmp_token); + write_exp_elt_opcode (pstate, OP_SCOPE); } | TYPENAME COLONCOLON name COLONCOLON name { @@ -1015,16 +1036,16 @@ variable: qualified_name VAR_DOMAIN, NULL); if (sym) { - write_exp_elt_opcode (OP_VAR_VALUE); - write_exp_elt_block (NULL); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); + write_exp_elt_block (pstate, NULL); + write_exp_elt_sym (pstate, sym); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); break; } msymbol = lookup_bound_minimal_symbol (name); if (msymbol.minsym != NULL) - write_exp_msymbol (msymbol); + write_exp_msymbol (pstate, msymbol); else if (!have_full_symbols () && !have_partial_symbols ()) error (_("No symbol table is loaded. Use the \"file\" command.")); else @@ -1045,13 +1066,13 @@ variable: name_not_typename innermost_block = block_found; } - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); /* We want to use the selected frame, not another more inner frame which happens to be in the same block. */ - write_exp_elt_block (NULL); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_block (pstate, NULL); + write_exp_elt_sym (pstate, sym); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); } else if ($1.is_a_field_of_this) { @@ -1062,11 +1083,11 @@ variable: name_not_typename || contained_in (block_found, innermost_block)) innermost_block = block_found; - write_exp_elt_opcode (OP_THIS); - write_exp_elt_opcode (OP_THIS); - write_exp_elt_opcode (STRUCTOP_PTR); - write_exp_string ($1.stoken); - write_exp_elt_opcode (STRUCTOP_PTR); + write_exp_elt_opcode (pstate, OP_THIS); + write_exp_elt_opcode (pstate, OP_THIS); + write_exp_elt_opcode (pstate, STRUCTOP_PTR); + write_exp_string (pstate, $1.stoken); + write_exp_elt_opcode (pstate, STRUCTOP_PTR); } else { @@ -1076,7 +1097,7 @@ variable: name_not_typename msymbol = lookup_bound_minimal_symbol (arg); if (msymbol.minsym != NULL) - write_exp_msymbol (msymbol); + write_exp_msymbol (pstate, msymbol); else if (!have_full_symbols () && !have_partial_symbols ()) error (_("No symbol table is loaded. Use the \"file\" command.")); else @@ -1087,7 +1108,7 @@ variable: name_not_typename ; space_identifier : '@' NAME - { insert_type_address_space (copy_name ($2.stoken)); } + { insert_type_address_space (pstate, copy_name ($2.stoken)); } ; const_or_volatile: const_or_volatile_noopt @@ -1194,117 +1215,121 @@ typebase /* Implements (approximately): (type-qualifier)* type-specifier */ : TYPENAME { $$ = $1.type; } | INT_KEYWORD - { $$ = lookup_signed_typename (parse_language, - parse_gdbarch, + { $$ = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "int"); } | LONG - { $$ = lookup_signed_typename (parse_language, - parse_gdbarch, + { $$ = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "long"); } | SHORT - { $$ = lookup_signed_typename (parse_language, - parse_gdbarch, + { $$ = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "short"); } | LONG INT_KEYWORD - { $$ = lookup_signed_typename (parse_language, - parse_gdbarch, + { $$ = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "long"); } | LONG SIGNED_KEYWORD INT_KEYWORD - { $$ = lookup_signed_typename (parse_language, - parse_gdbarch, + { $$ = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "long"); } | LONG SIGNED_KEYWORD - { $$ = lookup_signed_typename (parse_language, - parse_gdbarch, + { $$ = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "long"); } | SIGNED_KEYWORD LONG INT_KEYWORD - { $$ = lookup_signed_typename (parse_language, - parse_gdbarch, + { $$ = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "long"); } | UNSIGNED LONG INT_KEYWORD - { $$ = lookup_unsigned_typename (parse_language, - parse_gdbarch, + { $$ = lookup_unsigned_typename (parse_language (pstate), + parse_gdbarch (pstate), "long"); } | LONG UNSIGNED INT_KEYWORD - { $$ = lookup_unsigned_typename (parse_language, - parse_gdbarch, + { $$ = lookup_unsigned_typename (parse_language (pstate), + parse_gdbarch (pstate), "long"); } | LONG UNSIGNED - { $$ = lookup_unsigned_typename (parse_language, - parse_gdbarch, + { $$ = lookup_unsigned_typename (parse_language (pstate), + parse_gdbarch (pstate), "long"); } | LONG LONG - { $$ = lookup_signed_typename (parse_language, - parse_gdbarch, + { $$ = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "long long"); } | LONG LONG INT_KEYWORD - { $$ = lookup_signed_typename (parse_language, - parse_gdbarch, + { $$ = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "long long"); } | LONG LONG SIGNED_KEYWORD INT_KEYWORD - { $$ = lookup_signed_typename (parse_language, - parse_gdbarch, + { $$ = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "long long"); } | LONG LONG SIGNED_KEYWORD - { $$ = lookup_signed_typename (parse_language, - parse_gdbarch, + { $$ = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "long long"); } | SIGNED_KEYWORD LONG LONG - { $$ = lookup_signed_typename (parse_language, - parse_gdbarch, + { $$ = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "long long"); } | SIGNED_KEYWORD LONG LONG INT_KEYWORD - { $$ = lookup_signed_typename (parse_language, - parse_gdbarch, + { $$ = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "long long"); } | UNSIGNED LONG LONG - { $$ = lookup_unsigned_typename (parse_language, - parse_gdbarch, + { $$ = lookup_unsigned_typename (parse_language (pstate), + parse_gdbarch (pstate), "long long"); } | UNSIGNED LONG LONG INT_KEYWORD - { $$ = lookup_unsigned_typename (parse_language, - parse_gdbarch, + { $$ = lookup_unsigned_typename (parse_language (pstate), + parse_gdbarch (pstate), "long long"); } | LONG LONG UNSIGNED - { $$ = lookup_unsigned_typename (parse_language, - parse_gdbarch, + { $$ = lookup_unsigned_typename (parse_language (pstate), + parse_gdbarch (pstate), "long long"); } | LONG LONG UNSIGNED INT_KEYWORD - { $$ = lookup_unsigned_typename (parse_language, - parse_gdbarch, + { $$ = lookup_unsigned_typename (parse_language (pstate), + parse_gdbarch (pstate), "long long"); } | SHORT INT_KEYWORD - { $$ = lookup_signed_typename (parse_language, - parse_gdbarch, + { $$ = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "short"); } | SHORT SIGNED_KEYWORD INT_KEYWORD - { $$ = lookup_signed_typename (parse_language, - parse_gdbarch, + { $$ = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "short"); } | SHORT SIGNED_KEYWORD - { $$ = lookup_signed_typename (parse_language, - parse_gdbarch, + { $$ = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "short"); } | UNSIGNED SHORT INT_KEYWORD - { $$ = lookup_unsigned_typename (parse_language, - parse_gdbarch, + { $$ = lookup_unsigned_typename (parse_language (pstate), + parse_gdbarch (pstate), "short"); } | SHORT UNSIGNED - { $$ = lookup_unsigned_typename (parse_language, - parse_gdbarch, + { $$ = lookup_unsigned_typename (parse_language (pstate), + parse_gdbarch (pstate), "short"); } | SHORT UNSIGNED INT_KEYWORD - { $$ = lookup_unsigned_typename (parse_language, - parse_gdbarch, + { $$ = lookup_unsigned_typename (parse_language (pstate), + parse_gdbarch (pstate), "short"); } | DOUBLE_KEYWORD - { $$ = lookup_typename (parse_language, parse_gdbarch, - "double", (struct block *) NULL, + { $$ = lookup_typename (parse_language (pstate), + parse_gdbarch (pstate), + "double", + (struct block *) NULL, 0); } | LONG DOUBLE_KEYWORD - { $$ = lookup_typename (parse_language, parse_gdbarch, + { $$ = lookup_typename (parse_language (pstate), + parse_gdbarch (pstate), "long double", - (struct block *) NULL, 0); } + (struct block *) NULL, + 0); } | STRUCT name { $$ = lookup_struct (copy_name ($2), expression_context_block); } @@ -1362,20 +1387,20 @@ typebase /* Implements (approximately): (type-qualifier)* type-specifier */ $$ = NULL; } | UNSIGNED typename - { $$ = lookup_unsigned_typename (parse_language, - parse_gdbarch, + { $$ = lookup_unsigned_typename (parse_language (pstate), + parse_gdbarch (pstate), TYPE_NAME($2.type)); } | UNSIGNED - { $$ = lookup_unsigned_typename (parse_language, - parse_gdbarch, + { $$ = lookup_unsigned_typename (parse_language (pstate), + parse_gdbarch (pstate), "int"); } | SIGNED_KEYWORD typename - { $$ = lookup_signed_typename (parse_language, - parse_gdbarch, + { $$ = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), TYPE_NAME($2.type)); } | SIGNED_KEYWORD - { $$ = lookup_signed_typename (parse_language, - parse_gdbarch, + { $$ = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "int"); } /* It appears that this rule for templates is never reduced; template recognition happens by lookahead @@ -1395,24 +1420,24 @@ typename: TYPENAME { $$.stoken.ptr = "int"; $$.stoken.length = 3; - $$.type = lookup_signed_typename (parse_language, - parse_gdbarch, + $$.type = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "int"); } | LONG { $$.stoken.ptr = "long"; $$.stoken.length = 4; - $$.type = lookup_signed_typename (parse_language, - parse_gdbarch, + $$.type = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "long"); } | SHORT { $$.stoken.ptr = "short"; $$.stoken.length = 5; - $$.type = lookup_signed_typename (parse_language, - parse_gdbarch, + $$.type = lookup_signed_typename (parse_language (pstate), + parse_gdbarch (pstate), "short"); } ; @@ -1635,7 +1660,7 @@ name_not_typename : NAME /* Like write_exp_string, but prepends a '~'. */ static void -write_destructor_name (struct stoken token) +write_destructor_name (struct parser_state *par_state, struct stoken token) { char *copy = alloca (token.length + 1); @@ -1645,7 +1670,7 @@ write_destructor_name (struct stoken token) token.ptr = copy; ++token.length; - write_exp_string (token); + write_exp_string (par_state, token); } /* Returns a stoken of the operator name given by OP (which does not @@ -1706,7 +1731,8 @@ check_parameter_typelist (VEC (type_ptr) *params) /*** Needs some error checking for the float case ***/ static int -parse_number (const char *buf, int len, int parsed_float, YYSTYPE *putithere) +parse_number (struct parser_state *par_state, + const char *buf, int len, int parsed_float, YYSTYPE *putithere) { /* FIXME: Shouldn't these be unsigned? We don't deal with negative values here, and we do kind of silly things like cast to unsigned. */ @@ -1742,9 +1768,10 @@ parse_number (const char *buf, int len, int parsed_float, YYSTYPE *putithere) { p[len - 2] = '\0'; putithere->typed_val_decfloat.type - = parse_type->builtin_decfloat; + = parse_type (par_state)->builtin_decfloat; decimal_from_string (putithere->typed_val_decfloat.val, 4, - gdbarch_byte_order (parse_gdbarch), p); + gdbarch_byte_order (parse_gdbarch (par_state)), + p); p[len - 2] = 'd'; return DECFLOAT; } @@ -1753,9 +1780,10 @@ parse_number (const char *buf, int len, int parsed_float, YYSTYPE *putithere) { p[len - 2] = '\0'; putithere->typed_val_decfloat.type - = parse_type->builtin_decdouble; + = parse_type (par_state)->builtin_decdouble; decimal_from_string (putithere->typed_val_decfloat.val, 8, - gdbarch_byte_order (parse_gdbarch), p); + gdbarch_byte_order (parse_gdbarch (par_state)), + p); p[len - 2] = 'd'; return DECFLOAT; } @@ -1764,14 +1792,15 @@ parse_number (const char *buf, int len, int parsed_float, YYSTYPE *putithere) { p[len - 2] = '\0'; putithere->typed_val_decfloat.type - = parse_type->builtin_declong; + = parse_type (par_state)->builtin_declong; decimal_from_string (putithere->typed_val_decfloat.val, 16, - gdbarch_byte_order (parse_gdbarch), p); + gdbarch_byte_order (parse_gdbarch (par_state)), + p); p[len - 2] = 'd'; return DECFLOAT; } - if (! parse_c_float (parse_gdbarch, p, len, + if (! parse_c_float (parse_gdbarch (par_state), p, len, &putithere->typed_val_float.dval, &putithere->typed_val_float.type)) return ERROR; @@ -1887,9 +1916,10 @@ parse_number (const char *buf, int len, int parsed_float, YYSTYPE *putithere) un = (ULONGEST)n >> 2; if (long_p == 0 - && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0) + && (un >> (gdbarch_int_bit (parse_gdbarch (par_state)) - 2)) == 0) { - high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1); + high_bit + = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch (par_state)) - 1); /* A large decimal (not hex or octal) constant (between INT_MAX and UINT_MAX) is a long or unsigned long, according to ANSI, @@ -1897,28 +1927,29 @@ parse_number (const char *buf, int len, int parsed_float, YYSTYPE *putithere) int. This probably should be fixed. GCC gives a warning on such constants. */ - unsigned_type = parse_type->builtin_unsigned_int; - signed_type = parse_type->builtin_int; + unsigned_type = parse_type (par_state)->builtin_unsigned_int; + signed_type = parse_type (par_state)->builtin_int; } else if (long_p <= 1 - && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0) + && (un >> (gdbarch_long_bit (parse_gdbarch (par_state)) - 2)) == 0) { - high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1); - unsigned_type = parse_type->builtin_unsigned_long; - signed_type = parse_type->builtin_long; + high_bit + = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch (par_state)) - 1); + unsigned_type = parse_type (par_state)->builtin_unsigned_long; + signed_type = parse_type (par_state)->builtin_long; } else { int shift; if (sizeof (ULONGEST) * HOST_CHAR_BIT - < gdbarch_long_long_bit (parse_gdbarch)) + < gdbarch_long_long_bit (parse_gdbarch (par_state))) /* A long long does not fit in a LONGEST. */ shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1); else - shift = (gdbarch_long_long_bit (parse_gdbarch) - 1); + shift = (gdbarch_long_long_bit (parse_gdbarch (par_state)) - 1); high_bit = (ULONGEST) 1 << shift; - unsigned_type = parse_type->builtin_unsigned_long_long; - signed_type = parse_type->builtin_long_long; + unsigned_type = parse_type (par_state)->builtin_unsigned_long_long; + signed_type = parse_type (par_state)->builtin_long_long; } putithere->typed_val_int.val = n; @@ -2417,7 +2448,7 @@ static int last_was_structop; /* Read one token, getting characters through lexptr. */ static int -lex_one_token (int *is_quoted_name) +lex_one_token (struct parser_state *par_state, int *is_quoted_name) { int c; int namelen; @@ -2450,7 +2481,7 @@ lex_one_token (int *is_quoted_name) if (strncmp (tokstart, tokentab3[i].operator, 3) == 0) { if ((tokentab3[i].flags & FLAG_CXX) != 0 - && parse_language->la_language != language_cplus) + && parse_language (par_state)->la_language != language_cplus) break; lexptr += 3; @@ -2463,7 +2494,7 @@ lex_one_token (int *is_quoted_name) if (strncmp (tokstart, tokentab2[i].operator, 2) == 0) { if ((tokentab2[i].flags & FLAG_CXX) != 0 - && parse_language->la_language != language_cplus) + && parse_language (par_state)->la_language != language_cplus) break; lexptr += 2; @@ -2507,7 +2538,8 @@ lex_one_token (int *is_quoted_name) case '(': paren_depth++; lexptr++; - if (parse_language->la_language == language_objc && c == '[') + if (parse_language (par_state)->la_language == language_objc + && c == '[') return OBJC_LBRAC; return c; @@ -2587,7 +2619,8 @@ lex_one_token (int *is_quoted_name) && (*p < 'A' || *p > 'Z'))) break; } - toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval); + toktype = parse_number (par_state, tokstart, p - tokstart, + got_dot|got_e, &yylval); if (toktype == ERROR) { char *err_copy = (char *) alloca (p - tokstart + 1); @@ -2605,7 +2638,7 @@ lex_one_token (int *is_quoted_name) const char *p = &tokstart[1]; size_t len = strlen ("entry"); - if (parse_language->la_language == language_objc) + if (parse_language (par_state)->la_language == language_objc) { size_t len = strlen ("selector"); @@ -2759,7 +2792,7 @@ lex_one_token (int *is_quoted_name) if (strcmp (copy, ident_tokens[i].operator) == 0) { if ((ident_tokens[i].flags & FLAG_CXX) != 0 - && parse_language->la_language != language_cplus) + && parse_language (par_state)->la_language != language_cplus) break; if ((ident_tokens[i].flags & FLAG_SHADOW) != 0) @@ -2768,8 +2801,8 @@ lex_one_token (int *is_quoted_name) if (lookup_symbol (copy, expression_context_block, VAR_DOMAIN, - (parse_language->la_language == language_cplus - ? &is_a_field_of_this + (parse_language (par_state)->la_language + == language_cplus ? &is_a_field_of_this : NULL)) != NULL) { @@ -2822,7 +2855,8 @@ static struct obstack name_obstack; IS_QUOTED_NAME is non-zero if the name token was originally quoted in single quotes. */ static int -classify_name (const struct block *block, int is_quoted_name) +classify_name (struct parser_state *par_state, const struct block *block, + int is_quoted_name) { struct symbol *sym; char *copy; @@ -2835,7 +2869,7 @@ classify_name (const struct block *block, int is_quoted_name) memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this)); sym = lookup_symbol (copy, block, VAR_DOMAIN, - parse_language->la_name_of_this + parse_language (par_state)->la_name_of_this ? &is_a_field_of_this : NULL); if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK) @@ -2892,15 +2926,16 @@ classify_name (const struct block *block, int is_quoted_name) } yylval.tsym.type - = language_lookup_primitive_type_by_name (parse_language, - parse_gdbarch, copy); + = language_lookup_primitive_type_by_name (parse_language (par_state), + parse_gdbarch (par_state), + copy); if (yylval.tsym.type != NULL) return TYPENAME; /* See if it's an ObjC classname. */ - if (parse_language->la_language == language_objc && !sym) + if (parse_language (par_state)->la_language == language_objc && !sym) { - CORE_ADDR Class = lookup_objc_class (parse_gdbarch, copy); + CORE_ADDR Class = lookup_objc_class (parse_gdbarch (par_state), copy); if (Class) { yylval.class.class = Class; @@ -2919,7 +2954,8 @@ classify_name (const struct block *block, int is_quoted_name) || (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10))) { YYSTYPE newlval; /* Its value is ignored. */ - int hextype = parse_number (copy, yylval.sval.length, 0, &newlval); + int hextype = parse_number (par_state, copy, yylval.sval.length, + 0, &newlval); if (hextype == INT) { yylval.ssym.sym = sym; @@ -2933,7 +2969,7 @@ classify_name (const struct block *block, int is_quoted_name) yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL; if (sym == NULL - && parse_language->la_language == language_cplus + && parse_language (par_state)->la_language == language_cplus && is_a_field_of_this.type == NULL && lookup_minimal_symbol (copy, NULL, NULL).minsym == NULL) return UNKNOWN_CPP_NAME; @@ -2946,13 +2982,14 @@ classify_name (const struct block *block, int is_quoted_name) NULL if this is the first component of a name. */ static int -classify_inner_name (const struct block *block, struct type *context) +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 (block, 0); + return classify_name (par_state, block, 0); type = check_typedef (context); if (TYPE_CODE (type) != TYPE_CODE_STRUCT @@ -3035,10 +3072,11 @@ yylex (void) /* Read the first token and decide what to do. Most of the subsequent code is C++-only; but also depends on seeing a "::" or name-like token. */ - current.token = lex_one_token (&is_quoted_name); + current.token = lex_one_token (pstate, &is_quoted_name); if (current.token == NAME) - current.token = classify_name (expression_context_block, is_quoted_name); - if (parse_language->la_language != language_cplus + current.token = classify_name (pstate, expression_context_block, + is_quoted_name); + if (parse_language (pstate)->la_language != language_cplus || (current.token != TYPENAME && current.token != COLONCOLON && current.token != FILENAME)) return current.token; @@ -3054,7 +3092,7 @@ yylex (void) /* We ignore quoted names other than the very first one. Subsequent ones do not have any special meaning. */ - current.token = lex_one_token (&ignore); + current.token = lex_one_token (pstate, &ignore); current.value = yylval; VEC_safe_push (token_and_value, token_fifo, ¤t); @@ -3104,7 +3142,8 @@ yylex (void) int classification; yylval = next->value; - classification = classify_inner_name (search_block, context_type); + classification = classify_inner_name (pstate, search_block, + context_type); /* We keep going until we either run out of names, or until we have a qualified name which is not a type. */ if (classification != TYPENAME && classification != NAME) @@ -3164,11 +3203,17 @@ yylex (void) } int -c_parse (void) +c_parse (struct parser_state *par_state) { int result; - struct cleanup *back_to = make_cleanup (free_current_contents, - &expression_macro_scope); + struct cleanup *back_to; + + /* Setting up the parser state. */ + gdb_assert (par_state != NULL); + pstate = par_state; + + back_to = make_cleanup (free_current_contents, &expression_macro_scope); + make_cleanup_clear_parser_state (&pstate); /* Set up the scope for macro expansion. */ expression_macro_scope = NULL; @@ -3200,6 +3245,7 @@ c_parse (void) result = yyparse (); do_cleanups (back_to); + return result; } diff --git a/gdb/c-lang.h b/gdb/c-lang.h index 9c7dcfb..76bd426 100644 --- a/gdb/c-lang.h +++ b/gdb/c-lang.h @@ -24,6 +24,7 @@ struct ui_file; struct language_arch_info; struct type_print_options; +struct parser_state; #include "value.h" #include "macroexp.h" @@ -57,7 +58,7 @@ enum c_string_type /* Defined in c-exp.y. */ -extern int c_parse (void); +extern int c_parse (struct parser_state *); extern void c_error (char *); diff --git a/gdb/f-exp.y b/gdb/f-exp.y index 7a94b15..3deaf30 100644 --- a/gdb/f-exp.y +++ b/gdb/f-exp.y @@ -54,8 +54,8 @@ #include "block.h" #include <ctype.h> -#define parse_type builtin_type (parse_gdbarch) -#define parse_f_type builtin_f_type (parse_gdbarch) +#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 @@ -65,7 +65,7 @@ generators need to be fixed instead of adding those names to this list. */ #define yymaxdepth f_maxdepth -#define yyparse f_parse +#define yyparse f_parse_internal #define yylex f_lex #define yyerror f_error #define yylval f_lval @@ -117,6 +117,11 @@ #define YYFPRINTF parser_fprintf +/* The state of the parser, used internally when we are parsing the + expression. */ + +static struct parser_state *pstate = NULL; + int yyparse (void); static int yylex (void); @@ -157,7 +162,8 @@ static int match_string_literal (void); %{ /* YYSTYPE gets defined by %union */ -static int parse_number (const char *, int, int, YYSTYPE *); +static int parse_number (struct parser_state *, const char *, int, + int, YYSTYPE *); %} %type <voidval> exp type_exp start variable @@ -239,9 +245,9 @@ start : exp ; type_exp: type - { write_exp_elt_opcode(OP_TYPE); - write_exp_elt_type($1); - write_exp_elt_opcode(OP_TYPE); } + { write_exp_elt_opcode (pstate, OP_TYPE); + write_exp_elt_type (pstate, $1); + write_exp_elt_opcode (pstate, OP_TYPE); } ; exp : '(' exp ')' @@ -250,27 +256,27 @@ exp : '(' exp ')' /* Expressions, not including the comma operator. */ exp : '*' exp %prec UNARY - { write_exp_elt_opcode (UNOP_IND); } + { write_exp_elt_opcode (pstate, UNOP_IND); } ; exp : '&' exp %prec UNARY - { write_exp_elt_opcode (UNOP_ADDR); } + { write_exp_elt_opcode (pstate, UNOP_ADDR); } ; exp : '-' exp %prec UNARY - { write_exp_elt_opcode (UNOP_NEG); } + { write_exp_elt_opcode (pstate, UNOP_NEG); } ; exp : BOOL_NOT exp %prec UNARY - { write_exp_elt_opcode (UNOP_LOGICAL_NOT); } + { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); } ; exp : '~' exp %prec UNARY - { write_exp_elt_opcode (UNOP_COMPLEMENT); } + { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); } ; exp : SIZEOF exp %prec UNARY - { write_exp_elt_opcode (UNOP_SIZEOF); } + { write_exp_elt_opcode (pstate, UNOP_SIZEOF); } ; /* No more explicit array operators, we treat everything in F77 as @@ -281,9 +287,12 @@ exp : SIZEOF exp %prec UNARY exp : exp '(' { start_arglist (); } arglist ')' - { write_exp_elt_opcode (OP_F77_UNDETERMINED_ARGLIST); - write_exp_elt_longcst ((LONGEST) end_arglist ()); - write_exp_elt_opcode (OP_F77_UNDETERMINED_ARGLIST); } + { write_exp_elt_opcode (pstate, + OP_F77_UNDETERMINED_ARGLIST); + write_exp_elt_longcst (pstate, + (LONGEST) end_arglist ()); + write_exp_elt_opcode (pstate, + OP_F77_UNDETERMINED_ARGLIST); } ; arglist : @@ -304,27 +313,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 (OP_F90_RANGE); - write_exp_elt_longcst (NONE_BOUND_DEFAULT); - write_exp_elt_opcode (OP_F90_RANGE); } + { write_exp_elt_opcode (pstate, OP_F90_RANGE); + write_exp_elt_longcst (pstate, NONE_BOUND_DEFAULT); + write_exp_elt_opcode (pstate, OP_F90_RANGE); } ; subrange: exp ':' %prec ABOVE_COMMA - { write_exp_elt_opcode (OP_F90_RANGE); - write_exp_elt_longcst (HIGH_BOUND_DEFAULT); - write_exp_elt_opcode (OP_F90_RANGE); } + { write_exp_elt_opcode (pstate, OP_F90_RANGE); + write_exp_elt_longcst (pstate, HIGH_BOUND_DEFAULT); + write_exp_elt_opcode (pstate, OP_F90_RANGE); } ; subrange: ':' exp %prec ABOVE_COMMA - { write_exp_elt_opcode (OP_F90_RANGE); - write_exp_elt_longcst (LOW_BOUND_DEFAULT); - write_exp_elt_opcode (OP_F90_RANGE); } + { write_exp_elt_opcode (pstate, OP_F90_RANGE); + write_exp_elt_longcst (pstate, LOW_BOUND_DEFAULT); + write_exp_elt_opcode (pstate, OP_F90_RANGE); } ; subrange: ':' %prec ABOVE_COMMA - { write_exp_elt_opcode (OP_F90_RANGE); - write_exp_elt_longcst (BOTH_BOUND_DEFAULT); - write_exp_elt_opcode (OP_F90_RANGE); } + { write_exp_elt_opcode (pstate, OP_F90_RANGE); + write_exp_elt_longcst (pstate, BOTH_BOUND_DEFAULT); + write_exp_elt_opcode (pstate, OP_F90_RANGE); } ; complexnum: exp ',' exp @@ -332,133 +341,139 @@ complexnum: exp ',' exp ; exp : '(' complexnum ')' - { write_exp_elt_opcode(OP_COMPLEX); - write_exp_elt_type (parse_f_type->builtin_complex_s16); - write_exp_elt_opcode(OP_COMPLEX); } + { write_exp_elt_opcode (pstate, OP_COMPLEX); + write_exp_elt_type (pstate, + parse_f_type (pstate) + ->builtin_complex_s16); + write_exp_elt_opcode (pstate, OP_COMPLEX); } ; exp : '(' type ')' exp %prec UNARY - { write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type ($2); - write_exp_elt_opcode (UNOP_CAST); } + { write_exp_elt_opcode (pstate, UNOP_CAST); + write_exp_elt_type (pstate, $2); + write_exp_elt_opcode (pstate, UNOP_CAST); } ; exp : exp '%' name - { write_exp_elt_opcode (STRUCTOP_STRUCT); - write_exp_string ($3); - write_exp_elt_opcode (STRUCTOP_STRUCT); } + { write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); + write_exp_string (pstate, $3); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } ; /* Binary operators in order of decreasing precedence. */ exp : exp '@' exp - { write_exp_elt_opcode (BINOP_REPEAT); } + { write_exp_elt_opcode (pstate, BINOP_REPEAT); } ; exp : exp STARSTAR exp - { write_exp_elt_opcode (BINOP_EXP); } + { write_exp_elt_opcode (pstate, BINOP_EXP); } ; exp : exp '*' exp - { write_exp_elt_opcode (BINOP_MUL); } + { write_exp_elt_opcode (pstate, BINOP_MUL); } ; exp : exp '/' exp - { write_exp_elt_opcode (BINOP_DIV); } + { write_exp_elt_opcode (pstate, BINOP_DIV); } ; exp : exp '+' exp - { write_exp_elt_opcode (BINOP_ADD); } + { write_exp_elt_opcode (pstate, BINOP_ADD); } ; exp : exp '-' exp - { write_exp_elt_opcode (BINOP_SUB); } + { write_exp_elt_opcode (pstate, BINOP_SUB); } ; exp : exp LSH exp - { write_exp_elt_opcode (BINOP_LSH); } + { write_exp_elt_opcode (pstate, BINOP_LSH); } ; exp : exp RSH exp - { write_exp_elt_opcode (BINOP_RSH); } + { write_exp_elt_opcode (pstate, BINOP_RSH); } ; exp : exp EQUAL exp - { write_exp_elt_opcode (BINOP_EQUAL); } + { write_exp_elt_opcode (pstate, BINOP_EQUAL); } ; exp : exp NOTEQUAL exp - { write_exp_elt_opcode (BINOP_NOTEQUAL); } + { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); } ; exp : exp LEQ exp - { write_exp_elt_opcode (BINOP_LEQ); } + { write_exp_elt_opcode (pstate, BINOP_LEQ); } ; exp : exp GEQ exp - { write_exp_elt_opcode (BINOP_GEQ); } + { write_exp_elt_opcode (pstate, BINOP_GEQ); } ; exp : exp LESSTHAN exp - { write_exp_elt_opcode (BINOP_LESS); } + { write_exp_elt_opcode (pstate, BINOP_LESS); } ; exp : exp GREATERTHAN exp - { write_exp_elt_opcode (BINOP_GTR); } + { write_exp_elt_opcode (pstate, BINOP_GTR); } ; exp : exp '&' exp - { write_exp_elt_opcode (BINOP_BITWISE_AND); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); } ; exp : exp '^' exp - { write_exp_elt_opcode (BINOP_BITWISE_XOR); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); } ; exp : exp '|' exp - { write_exp_elt_opcode (BINOP_BITWISE_IOR); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); } ; exp : exp BOOL_AND exp - { write_exp_elt_opcode (BINOP_LOGICAL_AND); } + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); } ; exp : exp BOOL_OR exp - { write_exp_elt_opcode (BINOP_LOGICAL_OR); } + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); } ; exp : exp '=' exp - { write_exp_elt_opcode (BINOP_ASSIGN); } + { write_exp_elt_opcode (pstate, BINOP_ASSIGN); } ; exp : exp ASSIGN_MODIFY exp - { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); - write_exp_elt_opcode ($2); - write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); } + { write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); + write_exp_elt_opcode (pstate, $2); + write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); } ; exp : INT - { write_exp_elt_opcode (OP_LONG); - write_exp_elt_type ($1.type); - write_exp_elt_longcst ((LONGEST)($1.val)); - write_exp_elt_opcode (OP_LONG); } + { write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, $1.type); + write_exp_elt_longcst (pstate, (LONGEST) ($1.val)); + write_exp_elt_opcode (pstate, OP_LONG); } ; exp : NAME_OR_INT { YYSTYPE val; - parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val); - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (val.typed_val.type); - write_exp_elt_longcst ((LONGEST)val.typed_val.val); - write_exp_elt_opcode (OP_LONG); } + parse_number (pstate, $1.stoken.ptr, + $1.stoken.length, 0, &val); + write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, val.typed_val.type); + write_exp_elt_longcst (pstate, + (LONGEST)val.typed_val.val); + write_exp_elt_opcode (pstate, OP_LONG); } ; exp : FLOAT - { write_exp_elt_opcode (OP_DOUBLE); - write_exp_elt_type (parse_f_type->builtin_real_s8); - write_exp_elt_dblcst ($1); - write_exp_elt_opcode (OP_DOUBLE); } + { 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); } ; exp : variable @@ -468,25 +483,28 @@ exp : VARIABLE ; exp : SIZEOF '(' type ')' %prec UNARY - { write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (parse_f_type->builtin_integer); + { write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, + parse_f_type (pstate) + ->builtin_integer); CHECK_TYPEDEF ($3); - write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3)); - write_exp_elt_opcode (OP_LONG); } + write_exp_elt_longcst (pstate, + (LONGEST) TYPE_LENGTH ($3)); + write_exp_elt_opcode (pstate, OP_LONG); } ; exp : BOOLEAN_LITERAL - { write_exp_elt_opcode (OP_BOOL); - write_exp_elt_longcst ((LONGEST) $1); - write_exp_elt_opcode (OP_BOOL); + { write_exp_elt_opcode (pstate, OP_BOOL); + write_exp_elt_longcst (pstate, (LONGEST) $1); + write_exp_elt_opcode (pstate, OP_BOOL); } ; exp : STRING_LITERAL { - write_exp_elt_opcode (OP_STRING); - write_exp_string ($1); - write_exp_elt_opcode (OP_STRING); + write_exp_elt_opcode (pstate, OP_STRING); + write_exp_string (pstate, $1); + write_exp_elt_opcode (pstate, OP_STRING); } ; @@ -502,13 +520,13 @@ variable: name_not_typename innermost_block)) innermost_block = block_found; } - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); /* We want to use the selected frame, not another more inner frame which happens to be in the same block. */ - write_exp_elt_block (NULL); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_block (pstate, NULL); + write_exp_elt_sym (pstate, sym); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); break; } else @@ -519,7 +537,7 @@ variable: name_not_typename msymbol = lookup_bound_minimal_symbol (arg); if (msymbol.minsym != NULL) - write_exp_msymbol (msymbol); + write_exp_msymbol (pstate, msymbol); else if (!have_full_symbols () && !have_partial_symbols ()) error (_("No symbol table is loaded. Use the \"file\" command.")); else @@ -560,7 +578,8 @@ ptype : typebase { range_type = create_range_type ((struct type *) NULL, - parse_f_type->builtin_integer, + parse_f_type (pstate) + ->builtin_integer, 0, array_size - 1); follow_type = create_array_type ((struct type *) NULL, @@ -606,31 +625,31 @@ typebase /* Implements (approximately): (type-qualifier)* type-specifier */ : TYPENAME { $$ = $1.type; } | INT_KEYWORD - { $$ = parse_f_type->builtin_integer; } + { $$ = parse_f_type (pstate)->builtin_integer; } | INT_S2_KEYWORD - { $$ = parse_f_type->builtin_integer_s2; } + { $$ = parse_f_type (pstate)->builtin_integer_s2; } | CHARACTER - { $$ = parse_f_type->builtin_character; } + { $$ = parse_f_type (pstate)->builtin_character; } | LOGICAL_S8_KEYWORD - { $$ = parse_f_type->builtin_logical_s8; } + { $$ = parse_f_type (pstate)->builtin_logical_s8; } | LOGICAL_KEYWORD - { $$ = parse_f_type->builtin_logical; } + { $$ = parse_f_type (pstate)->builtin_logical; } | LOGICAL_S2_KEYWORD - { $$ = parse_f_type->builtin_logical_s2; } + { $$ = parse_f_type (pstate)->builtin_logical_s2; } | LOGICAL_S1_KEYWORD - { $$ = parse_f_type->builtin_logical_s1; } + { $$ = parse_f_type (pstate)->builtin_logical_s1; } | REAL_KEYWORD - { $$ = parse_f_type->builtin_real; } + { $$ = parse_f_type (pstate)->builtin_real; } | REAL_S8_KEYWORD - { $$ = parse_f_type->builtin_real_s8; } + { $$ = parse_f_type (pstate)->builtin_real_s8; } | REAL_S16_KEYWORD - { $$ = parse_f_type->builtin_real_s16; } + { $$ = parse_f_type (pstate)->builtin_real_s16; } | COMPLEX_S8_KEYWORD - { $$ = parse_f_type->builtin_complex_s8; } + { $$ = parse_f_type (pstate)->builtin_complex_s8; } | COMPLEX_S16_KEYWORD - { $$ = parse_f_type->builtin_complex_s16; } + { $$ = parse_f_type (pstate)->builtin_complex_s16; } | COMPLEX_S32_KEYWORD - { $$ = parse_f_type->builtin_complex_s32; } + { $$ = parse_f_type (pstate)->builtin_complex_s32; } ; nonempty_typelist @@ -669,7 +688,8 @@ name_not_typename : NAME /*** Needs some error checking for the float case ***/ static int -parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere) +parse_number (struct parser_state *par_state, + const char *p, int len, int parsed_float, YYSTYPE *putithere) { LONGEST n = 0; LONGEST prevn = 0; @@ -775,20 +795,24 @@ parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere) are the same size. So we shift it twice, with fewer bits each time, for the same result. */ - if ((gdbarch_int_bit (parse_gdbarch) != gdbarch_long_bit (parse_gdbarch) + if ((gdbarch_int_bit (parse_gdbarch (par_state)) + != gdbarch_long_bit (parse_gdbarch (par_state)) && ((n >> 2) - >> (gdbarch_int_bit (parse_gdbarch)-2))) /* Avoid shift warning */ + >> (gdbarch_int_bit (parse_gdbarch (par_state))-2))) /* Avoid + shift warning */ || long_p) { - high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch)-1); - unsigned_type = parse_type->builtin_unsigned_long; - signed_type = parse_type->builtin_long; + high_bit = ((ULONGEST)1) + << (gdbarch_long_bit (parse_gdbarch (par_state))-1); + unsigned_type = parse_type (par_state)->builtin_unsigned_long; + signed_type = parse_type (par_state)->builtin_long; } else { - high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch)-1); - unsigned_type = parse_type->builtin_unsigned_int; - signed_type = parse_type->builtin_int; + high_bit = + ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch (par_state)) - 1); + unsigned_type = parse_type (par_state)->builtin_unsigned_int; + signed_type = parse_type (par_state)->builtin_int; } putithere->typed_val.val = n; @@ -1090,7 +1114,8 @@ yylex (void) && (*p < 'A' || *p > 'Z'))) break; } - toktype = parse_number (tokstart, p - tokstart, got_dot|got_e|got_d, + toktype = parse_number (pstate, tokstart, p - tokstart, + got_dot|got_e|got_d, &yylval); if (toktype == ERROR) { @@ -1164,7 +1189,7 @@ yylex (void) if (*tokstart == '$') { - write_dollar_variable (yylval.sval); + write_dollar_variable (pstate, yylval.sval); return VARIABLE; } @@ -1192,8 +1217,8 @@ yylex (void) sym = lookup_symbol (tmp, expression_context_block, lookup_domains[i], - parse_language->la_language == language_cplus - ? &is_a_field_of_this : NULL); + parse_language (pstate)->la_language + == language_cplus ? &is_a_field_of_this : NULL); if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF) { yylval.tsym.type = SYMBOL_TYPE (sym); @@ -1205,8 +1230,8 @@ yylex (void) } yylval.tsym.type - = language_lookup_primitive_type_by_name (parse_language, - parse_gdbarch, tmp); + = language_lookup_primitive_type_by_name (parse_language (pstate), + parse_gdbarch (pstate), tmp); if (yylval.tsym.type != NULL) return TYPENAME; @@ -1218,7 +1243,7 @@ yylex (void) || (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10))) { YYSTYPE newlval; /* Its value is ignored. */ - hextype = parse_number (tokstart, namelen, 0, &newlval); + hextype = parse_number (pstate, tokstart, namelen, 0, &newlval); if (hextype == INT) { yylval.ssym.sym = sym; @@ -1234,6 +1259,21 @@ 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. */ + gdb_assert (par_state != NULL); + pstate = par_state; + + result = yyparse (); + do_cleanups (c); + return result; +} + void yyerror (char *msg) { diff --git a/gdb/f-lang.h b/gdb/f-lang.h index 2d67a48..7f77603 100644 --- a/gdb/f-lang.h +++ b/gdb/f-lang.h @@ -21,8 +21,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ struct type_print_options; +struct parser_state; -extern int f_parse (void); +extern int f_parse (struct parser_state *); extern void f_error (char *); /* Defined in f-exp.y */ diff --git a/gdb/go-exp.y b/gdb/go-exp.y index 974bdb1..bab5dde 100644 --- a/gdb/go-exp.y +++ b/gdb/go-exp.y @@ -66,7 +66,7 @@ #include "charset.h" #include "block.h" -#define parse_type builtin_type (parse_gdbarch) +#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 @@ -122,6 +122,11 @@ #define YYFPRINTF parser_fprintf +/* The state of the parser, used internally when we are parsing the + expression. */ + +static struct parser_state *pstate = NULL; + int yyparse (void); static int yylex (void); @@ -158,7 +163,8 @@ void yyerror (char *); %{ /* YYSTYPE gets defined by %union. */ -static int parse_number (const char *, int, int, YYSTYPE *); +static int parse_number (struct parser_state *, + const char *, int, int, YYSTYPE *); static int parse_go_float (struct gdbarch *gdbarch, const char *p, int len, DOUBLEST *d, struct type **t); %} @@ -239,77 +245,77 @@ start : exp1 ; type_exp: type - { write_exp_elt_opcode(OP_TYPE); - write_exp_elt_type($1); - write_exp_elt_opcode(OP_TYPE); } + { write_exp_elt_opcode (pstate, OP_TYPE); + write_exp_elt_type (pstate, $1); + write_exp_elt_opcode (pstate, OP_TYPE); } ; /* Expressions, including the comma operator. */ exp1 : exp | exp1 ',' exp - { write_exp_elt_opcode (BINOP_COMMA); } + { write_exp_elt_opcode (pstate, BINOP_COMMA); } ; /* Expressions, not including the comma operator. */ exp : '*' exp %prec UNARY - { write_exp_elt_opcode (UNOP_IND); } + { write_exp_elt_opcode (pstate, UNOP_IND); } ; exp : '&' exp %prec UNARY - { write_exp_elt_opcode (UNOP_ADDR); } + { write_exp_elt_opcode (pstate, UNOP_ADDR); } ; exp : '-' exp %prec UNARY - { write_exp_elt_opcode (UNOP_NEG); } + { write_exp_elt_opcode (pstate, UNOP_NEG); } ; exp : '+' exp %prec UNARY - { write_exp_elt_opcode (UNOP_PLUS); } + { write_exp_elt_opcode (pstate, UNOP_PLUS); } ; exp : '!' exp %prec UNARY - { write_exp_elt_opcode (UNOP_LOGICAL_NOT); } + { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); } ; exp : '^' exp %prec UNARY - { write_exp_elt_opcode (UNOP_COMPLEMENT); } + { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); } ; exp : exp INCREMENT %prec UNARY - { write_exp_elt_opcode (UNOP_POSTINCREMENT); } + { write_exp_elt_opcode (pstate, UNOP_POSTINCREMENT); } ; exp : exp DECREMENT %prec UNARY - { write_exp_elt_opcode (UNOP_POSTDECREMENT); } + { write_exp_elt_opcode (pstate, UNOP_POSTDECREMENT); } ; /* foo->bar is not in Go. May want as a gdb extension. Later. */ exp : exp '.' name_not_typename - { write_exp_elt_opcode (STRUCTOP_STRUCT); - write_exp_string ($3.stoken); - write_exp_elt_opcode (STRUCTOP_STRUCT); } + { write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); + write_exp_string (pstate, $3.stoken); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } ; exp : exp '.' name_not_typename COMPLETE - { mark_struct_expression (); - write_exp_elt_opcode (STRUCTOP_STRUCT); - write_exp_string ($3.stoken); - write_exp_elt_opcode (STRUCTOP_STRUCT); } + { mark_struct_expression (pstate); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); + write_exp_string (pstate, $3.stoken); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } ; exp : exp '.' COMPLETE { struct stoken s; - mark_struct_expression (); - write_exp_elt_opcode (STRUCTOP_STRUCT); + mark_struct_expression (pstate); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); s.ptr = ""; s.length = 0; - write_exp_string (s); - write_exp_elt_opcode (STRUCTOP_STRUCT); } + write_exp_string (pstate, s); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } ; exp : exp '[' exp1 ']' - { write_exp_elt_opcode (BINOP_SUBSCRIPT); } + { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); } ; exp : exp '(' @@ -317,9 +323,10 @@ exp : exp '(' being accumulated by an outer function call. */ { start_arglist (); } arglist ')' %prec LEFT_ARROW - { write_exp_elt_opcode (OP_FUNCALL); - write_exp_elt_longcst ((LONGEST) end_arglist ()); - write_exp_elt_opcode (OP_FUNCALL); } + { write_exp_elt_opcode (pstate, OP_FUNCALL); + write_exp_elt_longcst (pstate, + (LONGEST) end_arglist ()); + write_exp_elt_opcode (pstate, OP_FUNCALL); } ; lcurly : '{' @@ -342,15 +349,15 @@ rcurly : '}' ; exp : lcurly type rcurly exp %prec UNARY - { write_exp_elt_opcode (UNOP_MEMVAL); - write_exp_elt_type ($2); - write_exp_elt_opcode (UNOP_MEMVAL); } + { write_exp_elt_opcode (pstate, UNOP_MEMVAL); + write_exp_elt_type (pstate, $2); + write_exp_elt_opcode (pstate, UNOP_MEMVAL); } ; exp : type '(' exp ')' %prec UNARY - { write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type ($1); - write_exp_elt_opcode (UNOP_CAST); } + { write_exp_elt_opcode (pstate, UNOP_CAST); + write_exp_elt_type (pstate, $1); + write_exp_elt_opcode (pstate, UNOP_CAST); } ; exp : '(' exp1 ')' @@ -360,100 +367,100 @@ exp : '(' exp1 ')' /* Binary operators in order of decreasing precedence. */ exp : exp '@' exp - { write_exp_elt_opcode (BINOP_REPEAT); } + { write_exp_elt_opcode (pstate, BINOP_REPEAT); } ; exp : exp '*' exp - { write_exp_elt_opcode (BINOP_MUL); } + { write_exp_elt_opcode (pstate, BINOP_MUL); } ; exp : exp '/' exp - { write_exp_elt_opcode (BINOP_DIV); } + { write_exp_elt_opcode (pstate, BINOP_DIV); } ; exp : exp '%' exp - { write_exp_elt_opcode (BINOP_REM); } + { write_exp_elt_opcode (pstate, BINOP_REM); } ; exp : exp '+' exp - { write_exp_elt_opcode (BINOP_ADD); } + { write_exp_elt_opcode (pstate, BINOP_ADD); } ; exp : exp '-' exp - { write_exp_elt_opcode (BINOP_SUB); } + { write_exp_elt_opcode (pstate, BINOP_SUB); } ; exp : exp LSH exp - { write_exp_elt_opcode (BINOP_LSH); } + { write_exp_elt_opcode (pstate, BINOP_LSH); } ; exp : exp RSH exp - { write_exp_elt_opcode (BINOP_RSH); } + { write_exp_elt_opcode (pstate, BINOP_RSH); } ; exp : exp EQUAL exp - { write_exp_elt_opcode (BINOP_EQUAL); } + { write_exp_elt_opcode (pstate, BINOP_EQUAL); } ; exp : exp NOTEQUAL exp - { write_exp_elt_opcode (BINOP_NOTEQUAL); } + { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); } ; exp : exp LEQ exp - { write_exp_elt_opcode (BINOP_LEQ); } + { write_exp_elt_opcode (pstate, BINOP_LEQ); } ; exp : exp GEQ exp - { write_exp_elt_opcode (BINOP_GEQ); } + { write_exp_elt_opcode (pstate, BINOP_GEQ); } ; exp : exp '<' exp - { write_exp_elt_opcode (BINOP_LESS); } + { write_exp_elt_opcode (pstate, BINOP_LESS); } ; exp : exp '>' exp - { write_exp_elt_opcode (BINOP_GTR); } + { write_exp_elt_opcode (pstate, BINOP_GTR); } ; exp : exp '&' exp - { write_exp_elt_opcode (BINOP_BITWISE_AND); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); } ; exp : exp '^' exp - { write_exp_elt_opcode (BINOP_BITWISE_XOR); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); } ; exp : exp '|' exp - { write_exp_elt_opcode (BINOP_BITWISE_IOR); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); } ; exp : exp ANDAND exp - { write_exp_elt_opcode (BINOP_LOGICAL_AND); } + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); } ; exp : exp OROR exp - { write_exp_elt_opcode (BINOP_LOGICAL_OR); } + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); } ; exp : exp '?' exp ':' exp %prec '?' - { write_exp_elt_opcode (TERNOP_COND); } + { write_exp_elt_opcode (pstate, TERNOP_COND); } ; exp : exp '=' exp - { write_exp_elt_opcode (BINOP_ASSIGN); } + { write_exp_elt_opcode (pstate, BINOP_ASSIGN); } ; exp : exp ASSIGN_MODIFY exp - { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); - write_exp_elt_opcode ($2); - write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); } + { write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); + write_exp_elt_opcode (pstate, $2); + write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); } ; exp : INT - { write_exp_elt_opcode (OP_LONG); - write_exp_elt_type ($1.type); - write_exp_elt_longcst ((LONGEST)($1.val)); - write_exp_elt_opcode (OP_LONG); } + { write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, $1.type); + write_exp_elt_longcst (pstate, (LONGEST)($1.val)); + write_exp_elt_opcode (pstate, OP_LONG); } ; exp : CHAR @@ -461,28 +468,28 @@ exp : CHAR struct stoken_vector vec; vec.len = 1; vec.tokens = &$1; - write_exp_string_vector ($1.type, &vec); + write_exp_string_vector (pstate, $1.type, &vec); } ; exp : NAME_OR_INT { YYSTYPE val; - parse_number ($1.stoken.ptr, $1.stoken.length, - 0, &val); - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (val.typed_val_int.type); - write_exp_elt_longcst ((LONGEST) + parse_number (pstate, $1.stoken.ptr, + $1.stoken.length, 0, &val); + write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, val.typed_val_int.type); + write_exp_elt_longcst (pstate, (LONGEST) val.typed_val_int.val); - write_exp_elt_opcode (OP_LONG); + write_exp_elt_opcode (pstate, OP_LONG); } ; exp : FLOAT - { write_exp_elt_opcode (OP_DOUBLE); - write_exp_elt_type ($1.type); - write_exp_elt_dblcst ($1.dval); - write_exp_elt_opcode (OP_DOUBLE); } + { write_exp_elt_opcode (pstate, OP_DOUBLE); + write_exp_elt_type (pstate, $1.type); + write_exp_elt_dblcst (pstate, $1.dval); + write_exp_elt_opcode (pstate, OP_DOUBLE); } ; exp : variable @@ -490,26 +497,29 @@ exp : variable exp : DOLLAR_VARIABLE { - write_dollar_variable ($1); + write_dollar_variable (pstate, $1); } ; exp : SIZEOF_KEYWORD '(' type ')' %prec UNARY { /* TODO(dje): Go objects in structs. */ - write_exp_elt_opcode (OP_LONG); + write_exp_elt_opcode (pstate, OP_LONG); /* TODO(dje): What's the right type here? */ - write_exp_elt_type (parse_type->builtin_unsigned_int); + write_exp_elt_type + (pstate, + parse_type (pstate)->builtin_unsigned_int); CHECK_TYPEDEF ($3); - write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3)); - write_exp_elt_opcode (OP_LONG); + write_exp_elt_longcst (pstate, + (LONGEST) TYPE_LENGTH ($3)); + write_exp_elt_opcode (pstate, OP_LONG); } ; exp : SIZEOF_KEYWORD '(' exp ')' %prec UNARY { /* TODO(dje): Go objects in structs. */ - write_exp_elt_opcode (UNOP_SIZEOF); + write_exp_elt_opcode (pstate, UNOP_SIZEOF); } string_exp: @@ -552,7 +562,8 @@ exp : string_exp %prec ABOVE_COMMA { int i; - write_exp_string_vector (0 /*always utf8*/, &$1); + write_exp_string_vector (pstate, 0 /*always utf8*/, + &$1); for (i = 0; i < $1.len; ++i) free ($1.tokens[i].ptr); free ($1.tokens); @@ -560,15 +571,15 @@ exp : string_exp %prec ABOVE_COMMA ; exp : TRUE_KEYWORD - { write_exp_elt_opcode (OP_BOOL); - write_exp_elt_longcst ((LONGEST) $1); - write_exp_elt_opcode (OP_BOOL); } + { write_exp_elt_opcode (pstate, OP_BOOL); + write_exp_elt_longcst (pstate, (LONGEST) $1); + write_exp_elt_opcode (pstate, OP_BOOL); } ; exp : FALSE_KEYWORD - { write_exp_elt_opcode (OP_BOOL); - write_exp_elt_longcst ((LONGEST) $1); - write_exp_elt_opcode (OP_BOOL); } + { write_exp_elt_opcode (pstate, OP_BOOL); + write_exp_elt_longcst (pstate, (LONGEST) $1); + write_exp_elt_opcode (pstate, OP_BOOL); } ; variable: name_not_typename ENTRY @@ -581,9 +592,9 @@ variable: name_not_typename ENTRY "parameters, not for \"%s\""), copy_name ($1.stoken)); - write_exp_elt_opcode (OP_VAR_ENTRY_VALUE); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_ENTRY_VALUE); + write_exp_elt_opcode (pstate, OP_VAR_ENTRY_VALUE); + write_exp_elt_sym (pstate, sym); + write_exp_elt_opcode (pstate, OP_VAR_ENTRY_VALUE); } ; @@ -600,13 +611,13 @@ variable: name_not_typename innermost_block = block_found; } - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); /* We want to use the selected frame, not another more inner frame which happens to be in the same block. */ - write_exp_elt_block (NULL); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_block (pstate, NULL); + write_exp_elt_sym (pstate, sym); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); } else if ($1.is_a_field_of_this) { @@ -622,7 +633,7 @@ variable: name_not_typename msymbol = lookup_bound_minimal_symbol (arg); if (msymbol.minsym != NULL) - write_exp_msymbol (msymbol); + write_exp_msymbol (pstate, msymbol); else if (!have_full_symbols () && !have_partial_symbols ()) error (_("No symbol table is loaded. " @@ -652,7 +663,7 @@ type /* Implements (approximately): [*] type-specifier */ expression_context_block); } */ | BYTE_KEYWORD - { $$ = builtin_go_type (parse_gdbarch) + { $$ = builtin_go_type (parse_gdbarch (pstate)) ->builtin_uint8; } ; @@ -704,7 +715,8 @@ parse_go_float (struct gdbarch *gdbarch, const char *p, int len, as our YYSTYPE is different than c-exp.y's */ static int -parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere) +parse_number (struct parser_state *par_state, + const char *p, int len, int parsed_float, YYSTYPE *putithere) { /* FIXME: Shouldn't these be unsigned? We don't deal with negative values here, and we do kind of silly things like cast to unsigned. */ @@ -729,7 +741,7 @@ parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere) if (parsed_float) { - if (! parse_go_float (parse_gdbarch, p, len, + if (! parse_go_float (parse_gdbarch (par_state), p, len, &putithere->typed_val_float.dval, &putithere->typed_val_float.type)) return ERROR; @@ -845,9 +857,10 @@ parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere) un = (ULONGEST)n >> 2; if (long_p == 0 - && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0) + && (un >> (gdbarch_int_bit (parse_gdbarch (par_state)) - 2)) == 0) { - high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1); + high_bit + = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch (par_state)) - 1); /* A large decimal (not hex or octal) constant (between INT_MAX and UINT_MAX) is a long or unsigned long, according to ANSI, @@ -855,28 +868,29 @@ parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere) int. This probably should be fixed. GCC gives a warning on such constants. */ - unsigned_type = parse_type->builtin_unsigned_int; - signed_type = parse_type->builtin_int; + unsigned_type = parse_type (par_state)->builtin_unsigned_int; + signed_type = parse_type (par_state)->builtin_int; } else if (long_p <= 1 - && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0) + && (un >> (gdbarch_long_bit (parse_gdbarch (par_state)) - 2)) == 0) { - high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1); - unsigned_type = parse_type->builtin_unsigned_long; - signed_type = parse_type->builtin_long; + high_bit + = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch (par_state)) - 1); + unsigned_type = parse_type (par_state)->builtin_unsigned_long; + signed_type = parse_type (par_state)->builtin_long; } else { int shift; if (sizeof (ULONGEST) * HOST_CHAR_BIT - < gdbarch_long_long_bit (parse_gdbarch)) + < gdbarch_long_long_bit (parse_gdbarch (par_state))) /* A long long does not fit in a LONGEST. */ shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1); else - shift = (gdbarch_long_long_bit (parse_gdbarch) - 1); + shift = (gdbarch_long_long_bit (parse_gdbarch (par_state)) - 1); high_bit = (ULONGEST) 1 << shift; - unsigned_type = parse_type->builtin_unsigned_long_long; - signed_type = parse_type->builtin_long_long; + unsigned_type = parse_type (par_state)->builtin_unsigned_long_long; + signed_type = parse_type (par_state)->builtin_long_long; } putithere->typed_val_int.val = n; @@ -1044,7 +1058,7 @@ static int last_was_structop; /* Read one token, getting characters through lexptr. */ static int -lex_one_token (void) +lex_one_token (struct parser_state *par_state) { int c; int namelen; @@ -1175,7 +1189,8 @@ lex_one_token (void) && (*p < 'A' || *p > 'Z'))) break; } - toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval); + toktype = parse_number (par_state, tokstart, p - tokstart, + got_dot|got_e, &yylval); if (toktype == ERROR) { char *err_copy = (char *) alloca (p - tokstart + 1); @@ -1431,7 +1446,7 @@ classify_packaged_name (const struct block *block) The result is one of NAME, NAME_OR_INT, or TYPENAME. */ static int -classify_name (const struct block *block) +classify_name (struct parser_state *par_state, const struct block *block) { struct type *type; struct symbol *sym; @@ -1441,8 +1456,9 @@ classify_name (const struct block *block) copy = copy_name (yylval.sval); /* Try primitive types first so they win over bad/weird debug info. */ - type = language_lookup_primitive_type_by_name (parse_language, - parse_gdbarch, copy); + type = language_lookup_primitive_type_by_name (parse_language (par_state), + parse_gdbarch (par_state), + copy); if (type != NULL) { /* NOTE: We take advantage of the fact that yylval coming in was a @@ -1498,7 +1514,8 @@ classify_name (const struct block *block) || (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10)) { YYSTYPE newlval; /* Its value is ignored. */ - int hextype = parse_number (copy, yylval.sval.length, 0, &newlval); + int hextype = parse_number (par_state, copy, yylval.sval.length, + 0, &newlval); if (hextype == INT) { yylval.ssym.sym = NULL; @@ -1531,7 +1548,7 @@ yylex (void) } popping = 0; - current.token = lex_one_token (); + current.token = lex_one_token (pstate); /* TODO: Need a way to force specifying name1 as a package. .name1.name2 ? */ @@ -1542,14 +1559,14 @@ yylex (void) /* See if we have "name1 . name2". */ current.value = yylval; - next.token = lex_one_token (); + next.token = lex_one_token (pstate); next.value = yylval; if (next.token == '.') { token_and_value name2; - name2.token = lex_one_token (); + name2.token = lex_one_token (pstate); name2.value = yylval; if (name2.token == NAME) @@ -1588,16 +1605,23 @@ yylex (void) popping = 1; yylval = current.value; - return classify_name (expression_context_block); + return classify_name (pstate, expression_context_block); } int -go_parse (void) +go_parse (struct parser_state *par_state) { int result; - struct cleanup *back_to = make_cleanup (null_cleanup, NULL); + struct cleanup *back_to; + + /* Setting up the parser state. */ + gdb_assert (par_state != NULL); + pstate = par_state; + + back_to = make_cleanup (null_cleanup, NULL); make_cleanup_restore_integer (&yydebug); + make_cleanup_clear_parser_state (&pstate); yydebug = parser_debug; /* Initialize some state used by the lexer. */ diff --git a/gdb/go-lang.h b/gdb/go-lang.h index 726b7ad..1fe12fa 100644 --- a/gdb/go-lang.h +++ b/gdb/go-lang.h @@ -26,6 +26,8 @@ struct type_print_options; #include "symtab.h" #include "value.h" +struct parser_state; + struct builtin_go_type { struct type *builtin_void; @@ -56,7 +58,7 @@ enum go_type /* Defined in go-exp.y. */ -extern int go_parse (void); +extern int go_parse (struct parser_state *); extern void go_error (char *); diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index be40b20..5515afb 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -3766,33 +3766,36 @@ i386_stap_parse_special_token_triplet (struct gdbarch *gdbarch, for (i = 0; i < 3; i++) { - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type (gdbarch)->builtin_long); - write_exp_elt_longcst (displacements[i]); - write_exp_elt_opcode (OP_LONG); + write_exp_elt_opcode (&p->pstate, OP_LONG); + write_exp_elt_type + (&p->pstate, builtin_type (gdbarch)->builtin_long); + write_exp_elt_longcst (&p->pstate, displacements[i]); + write_exp_elt_opcode (&p->pstate, OP_LONG); if (got_minus[i]) - write_exp_elt_opcode (UNOP_NEG); + write_exp_elt_opcode (&p->pstate, UNOP_NEG); } - write_exp_elt_opcode (OP_REGISTER); + write_exp_elt_opcode (&p->pstate, OP_REGISTER); str.ptr = regname; str.length = len; - write_exp_string (str); - write_exp_elt_opcode (OP_REGISTER); + write_exp_string (&p->pstate, str); + write_exp_elt_opcode (&p->pstate, OP_REGISTER); - write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type (builtin_type (gdbarch)->builtin_data_ptr); - write_exp_elt_opcode (UNOP_CAST); + write_exp_elt_opcode (&p->pstate, UNOP_CAST); + write_exp_elt_type (&p->pstate, + builtin_type (gdbarch)->builtin_data_ptr); + write_exp_elt_opcode (&p->pstate, UNOP_CAST); - write_exp_elt_opcode (BINOP_ADD); - write_exp_elt_opcode (BINOP_ADD); - write_exp_elt_opcode (BINOP_ADD); + write_exp_elt_opcode (&p->pstate, BINOP_ADD); + write_exp_elt_opcode (&p->pstate, BINOP_ADD); + write_exp_elt_opcode (&p->pstate, BINOP_ADD); - write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type (lookup_pointer_type (p->arg_type)); - write_exp_elt_opcode (UNOP_CAST); + write_exp_elt_opcode (&p->pstate, UNOP_CAST); + write_exp_elt_type (&p->pstate, + lookup_pointer_type (p->arg_type)); + write_exp_elt_opcode (&p->pstate, UNOP_CAST); - write_exp_elt_opcode (UNOP_IND); + write_exp_elt_opcode (&p->pstate, UNOP_IND); p->arg = s; @@ -3912,47 +3915,50 @@ i386_stap_parse_special_token_three_arg_disp (struct gdbarch *gdbarch, if (offset) { - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type (gdbarch)->builtin_long); - write_exp_elt_longcst (offset); - write_exp_elt_opcode (OP_LONG); + write_exp_elt_opcode (&p->pstate, OP_LONG); + write_exp_elt_type (&p->pstate, + builtin_type (gdbarch)->builtin_long); + write_exp_elt_longcst (&p->pstate, offset); + write_exp_elt_opcode (&p->pstate, OP_LONG); if (offset_minus) - write_exp_elt_opcode (UNOP_NEG); + write_exp_elt_opcode (&p->pstate, UNOP_NEG); } - write_exp_elt_opcode (OP_REGISTER); + write_exp_elt_opcode (&p->pstate, OP_REGISTER); base_token.ptr = base; base_token.length = len_base; - write_exp_string (base_token); - write_exp_elt_opcode (OP_REGISTER); + write_exp_string (&p->pstate, base_token); + write_exp_elt_opcode (&p->pstate, OP_REGISTER); if (offset) - write_exp_elt_opcode (BINOP_ADD); + write_exp_elt_opcode (&p->pstate, BINOP_ADD); - write_exp_elt_opcode (OP_REGISTER); + write_exp_elt_opcode (&p->pstate, OP_REGISTER); index_token.ptr = index; index_token.length = len_index; - write_exp_string (index_token); - write_exp_elt_opcode (OP_REGISTER); + write_exp_string (&p->pstate, index_token); + write_exp_elt_opcode (&p->pstate, OP_REGISTER); if (size) { - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type (gdbarch)->builtin_long); - write_exp_elt_longcst (size); - write_exp_elt_opcode (OP_LONG); + write_exp_elt_opcode (&p->pstate, OP_LONG); + write_exp_elt_type (&p->pstate, + builtin_type (gdbarch)->builtin_long); + write_exp_elt_longcst (&p->pstate, size); + write_exp_elt_opcode (&p->pstate, OP_LONG); if (size_minus) - write_exp_elt_opcode (UNOP_NEG); - write_exp_elt_opcode (BINOP_MUL); + write_exp_elt_opcode (&p->pstate, UNOP_NEG); + write_exp_elt_opcode (&p->pstate, BINOP_MUL); } - write_exp_elt_opcode (BINOP_ADD); + write_exp_elt_opcode (&p->pstate, BINOP_ADD); - write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type (lookup_pointer_type (p->arg_type)); - write_exp_elt_opcode (UNOP_CAST); + write_exp_elt_opcode (&p->pstate, UNOP_CAST); + write_exp_elt_type (&p->pstate, + lookup_pointer_type (p->arg_type)); + write_exp_elt_opcode (&p->pstate, UNOP_CAST); - write_exp_elt_opcode (UNOP_IND); + write_exp_elt_opcode (&p->pstate, UNOP_IND); p->arg = s; diff --git a/gdb/jv-exp.y b/gdb/jv-exp.y index ec23b34..0894fad 100644 --- a/gdb/jv-exp.y +++ b/gdb/jv-exp.y @@ -49,8 +49,8 @@ #include "block.h" #include "completer.h" -#define parse_type builtin_type (parse_gdbarch) -#define parse_java_type builtin_java_type (parse_gdbarch) +#define parse_type(ps) builtin_type (parse_gdbarch (ps)) +#define parse_java_type(ps) builtin_java_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 @@ -60,7 +60,7 @@ generators need to be fixed instead of adding those names to this list. */ #define yymaxdepth java_maxdepth -#define yyparse java_parse +#define yyparse java_parse_internal #define yylex java_lex #define yyerror java_error #define yylval java_lval @@ -112,6 +112,11 @@ #define YYFPRINTF parser_fprintf +/* The state of the parser, used internally when we are parsing the + expression. */ + +static struct parser_state *pstate = NULL; + int yyparse (void); static int yylex (void); @@ -119,11 +124,11 @@ static int yylex (void); void yyerror (char *); static struct type *java_type_from_name (struct stoken); -static void push_expression_name (struct stoken); -static void push_fieldnames (struct stoken); +static void push_expression_name (struct parser_state *, struct stoken); +static void push_fieldnames (struct parser_state *, struct stoken); static struct expression *copy_exp (struct expression *, int); -static void insert_exp (int, struct expression *); +static void insert_exp (struct parser_state *, int, struct expression *); %} @@ -155,7 +160,8 @@ static void insert_exp (int, struct expression *); %{ /* YYSTYPE gets defined by %union */ -static int parse_number (const char *, int, int, YYSTYPE *); +static int parse_number (struct parser_state *, const char *, int, + int, YYSTYPE *); %} %type <lval> rcurly Dims Dims_opt @@ -215,9 +221,9 @@ start : exp1 type_exp: PrimitiveOrArrayType { - write_exp_elt_opcode(OP_TYPE); - write_exp_elt_type($1); - write_exp_elt_opcode(OP_TYPE); + write_exp_elt_opcode (pstate, OP_TYPE); + write_exp_elt_type (pstate, $1); + write_exp_elt_opcode (pstate, OP_TYPE); } ; @@ -229,36 +235,38 @@ PrimitiveOrArrayType: StringLiteral: STRING_LITERAL { - write_exp_elt_opcode (OP_STRING); - write_exp_string ($1); - write_exp_elt_opcode (OP_STRING); + write_exp_elt_opcode (pstate, OP_STRING); + write_exp_string (pstate, $1); + write_exp_elt_opcode (pstate, OP_STRING); } ; Literal: INTEGER_LITERAL - { write_exp_elt_opcode (OP_LONG); - write_exp_elt_type ($1.type); - write_exp_elt_longcst ((LONGEST)($1.val)); - write_exp_elt_opcode (OP_LONG); } + { write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, $1.type); + write_exp_elt_longcst (pstate, (LONGEST)($1.val)); + write_exp_elt_opcode (pstate, OP_LONG); } | NAME_OR_INT { YYSTYPE val; - parse_number ($1.ptr, $1.length, 0, &val); - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (val.typed_val_int.type); - write_exp_elt_longcst ((LONGEST)val.typed_val_int.val); - write_exp_elt_opcode (OP_LONG); + parse_number (pstate, $1.ptr, $1.length, 0, &val); + write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, val.typed_val_int.type); + write_exp_elt_longcst (pstate, + (LONGEST) val.typed_val_int.val); + write_exp_elt_opcode (pstate, OP_LONG); } | FLOATING_POINT_LITERAL - { write_exp_elt_opcode (OP_DOUBLE); - write_exp_elt_type ($1.type); - write_exp_elt_dblcst ($1.dval); - write_exp_elt_opcode (OP_DOUBLE); } + { write_exp_elt_opcode (pstate, OP_DOUBLE); + write_exp_elt_type (pstate, $1.type); + write_exp_elt_dblcst (pstate, $1.dval); + write_exp_elt_opcode (pstate, OP_DOUBLE); } | BOOLEAN_LITERAL - { write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (parse_java_type->builtin_boolean); - write_exp_elt_longcst ((LONGEST)$1); - write_exp_elt_opcode (OP_LONG); } + { write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, + parse_java_type (pstate)->builtin_boolean); + write_exp_elt_longcst (pstate, (LONGEST)$1); + write_exp_elt_opcode (pstate, OP_LONG); } | StringLiteral ; @@ -272,7 +280,7 @@ Type: PrimitiveType: NumericType | BOOLEAN - { $$ = parse_java_type->builtin_boolean; } + { $$ = parse_java_type (pstate)->builtin_boolean; } ; NumericType: @@ -282,22 +290,22 @@ NumericType: IntegralType: BYTE - { $$ = parse_java_type->builtin_byte; } + { $$ = parse_java_type (pstate)->builtin_byte; } | SHORT - { $$ = parse_java_type->builtin_short; } + { $$ = parse_java_type (pstate)->builtin_short; } | INT - { $$ = parse_java_type->builtin_int; } + { $$ = parse_java_type (pstate)->builtin_int; } | LONG - { $$ = parse_java_type->builtin_long; } + { $$ = parse_java_type (pstate)->builtin_long; } | CHAR - { $$ = parse_java_type->builtin_char; } + { $$ = parse_java_type (pstate)->builtin_char; } ; FloatingPointType: FLOAT - { $$ = parse_java_type->builtin_float; } + { $$ = parse_java_type (pstate)->builtin_float; } | DOUBLE - { $$ = parse_java_type->builtin_double; } + { $$ = parse_java_type (pstate)->builtin_double; } ; /* UNUSED: @@ -367,7 +375,7 @@ type_exp: type /* Expressions, including the comma operator. */ exp1 : Expression | exp1 ',' Expression - { write_exp_elt_opcode (BINOP_COMMA); } + { write_exp_elt_opcode (pstate, BINOP_COMMA); } ; Primary: @@ -383,10 +391,10 @@ PrimaryNoNewArray: | MethodInvocation | ArrayAccess | lcurly ArgumentList rcurly - { write_exp_elt_opcode (OP_ARRAY); - write_exp_elt_longcst ((LONGEST) 0); - write_exp_elt_longcst ((LONGEST) $3); - write_exp_elt_opcode (OP_ARRAY); } + { write_exp_elt_opcode (pstate, OP_ARRAY); + write_exp_elt_longcst (pstate, (LONGEST) 0); + write_exp_elt_longcst (pstate, (LONGEST) $3); + write_exp_elt_opcode (pstate, OP_ARRAY); } ; lcurly: @@ -451,24 +459,24 @@ Dims_opt: FieldAccess: Primary '.' SimpleName - { push_fieldnames ($3); } + { push_fieldnames (pstate, $3); } | VARIABLE '.' SimpleName - { push_fieldnames ($3); } + { push_fieldnames (pstate, $3); } /*| SUPER '.' SimpleName { FIXME } */ ; FuncStart: Name '(' - { push_expression_name ($1); } + { push_expression_name (pstate, $1); } ; MethodInvocation: FuncStart { start_arglist(); } ArgumentList_opt ')' - { write_exp_elt_opcode (OP_FUNCALL); - write_exp_elt_longcst ((LONGEST) end_arglist ()); - write_exp_elt_opcode (OP_FUNCALL); } + { write_exp_elt_opcode (pstate, OP_FUNCALL); + write_exp_elt_longcst (pstate, (LONGEST) end_arglist ()); + write_exp_elt_opcode (pstate, OP_FUNCALL); } | Primary '.' SimpleName '(' ArgumentList_opt ')' { error (_("Form of method invocation not implemented")); } | SUPER '.' SimpleName '(' ArgumentList_opt ')' @@ -485,24 +493,27 @@ ArrayAccess: for our parsing kludges. */ struct expression *name_expr; - push_expression_name ($1); - name_expr = copy_exp (expout, expout_ptr); - expout_ptr -= name_expr->nelts; - insert_exp (expout_ptr-length_of_subexp (expout, expout_ptr), + push_expression_name (pstate, $1); + name_expr = copy_exp (pstate->expout, pstate->expout_ptr); + pstate->expout_ptr -= name_expr->nelts; + insert_exp (pstate, + pstate->expout_ptr + - length_of_subexp (pstate->expout, + pstate->expout_ptr), name_expr); free (name_expr); - write_exp_elt_opcode (BINOP_SUBSCRIPT); + write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); } | VARIABLE '[' Expression ']' - { write_exp_elt_opcode (BINOP_SUBSCRIPT); } + { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); } | PrimaryNoNewArray '[' Expression ']' - { write_exp_elt_opcode (BINOP_SUBSCRIPT); } + { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); } ; PostfixExpression: Primary | Name - { push_expression_name ($1); } + { push_expression_name (pstate, $1); } | VARIABLE /* Already written by write_dollar_variable. */ | PostIncrementExpression @@ -511,12 +522,12 @@ PostfixExpression: PostIncrementExpression: PostfixExpression INCREMENT - { write_exp_elt_opcode (UNOP_POSTINCREMENT); } + { write_exp_elt_opcode (pstate, UNOP_POSTINCREMENT); } ; PostDecrementExpression: PostfixExpression DECREMENT - { write_exp_elt_opcode (UNOP_POSTDECREMENT); } + { write_exp_elt_opcode (pstate, UNOP_POSTDECREMENT); } ; UnaryExpression: @@ -524,144 +535,151 @@ UnaryExpression: | PreDecrementExpression | '+' UnaryExpression | '-' UnaryExpression - { write_exp_elt_opcode (UNOP_NEG); } + { write_exp_elt_opcode (pstate, UNOP_NEG); } | '*' UnaryExpression - { write_exp_elt_opcode (UNOP_IND); } /*FIXME not in Java */ + { write_exp_elt_opcode (pstate, + UNOP_IND); } /*FIXME not in Java */ | UnaryExpressionNotPlusMinus ; PreIncrementExpression: INCREMENT UnaryExpression - { write_exp_elt_opcode (UNOP_PREINCREMENT); } + { write_exp_elt_opcode (pstate, UNOP_PREINCREMENT); } ; PreDecrementExpression: DECREMENT UnaryExpression - { write_exp_elt_opcode (UNOP_PREDECREMENT); } + { write_exp_elt_opcode (pstate, UNOP_PREDECREMENT); } ; UnaryExpressionNotPlusMinus: PostfixExpression | '~' UnaryExpression - { write_exp_elt_opcode (UNOP_COMPLEMENT); } + { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); } | '!' UnaryExpression - { write_exp_elt_opcode (UNOP_LOGICAL_NOT); } + { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); } | CastExpression ; CastExpression: '(' PrimitiveType Dims_opt ')' UnaryExpression - { write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type (java_array_type ($2, $3)); - write_exp_elt_opcode (UNOP_CAST); } + { write_exp_elt_opcode (pstate, UNOP_CAST); + write_exp_elt_type (pstate, java_array_type ($2, $3)); + write_exp_elt_opcode (pstate, UNOP_CAST); } | '(' Expression ')' UnaryExpressionNotPlusMinus { - int last_exp_size = length_of_subexp(expout, expout_ptr); + int last_exp_size = length_of_subexp (pstate->expout, + pstate->expout_ptr); struct type *type; int i; - int base = expout_ptr - last_exp_size - 3; - if (base < 0 || expout->elts[base+2].opcode != OP_TYPE) + int base = pstate->expout_ptr - last_exp_size - 3; + + if (base < 0 + || pstate->expout->elts[base+2].opcode != OP_TYPE) error (_("Invalid cast expression")); - type = expout->elts[base+1].type; + type = pstate->expout->elts[base+1].type; /* Remove the 'Expression' and slide the UnaryExpressionNotPlusMinus down to replace it. */ for (i = 0; i < last_exp_size; i++) - expout->elts[base + i] = expout->elts[base + i + 3]; - expout_ptr -= 3; + pstate->expout->elts[base + i] + = pstate->expout->elts[base + i + 3]; + pstate->expout_ptr -= 3; if (TYPE_CODE (type) == TYPE_CODE_STRUCT) type = lookup_pointer_type (type); - write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type (type); - write_exp_elt_opcode (UNOP_CAST); + write_exp_elt_opcode (pstate, UNOP_CAST); + write_exp_elt_type (pstate, type); + write_exp_elt_opcode (pstate, UNOP_CAST); } | '(' Name Dims ')' UnaryExpressionNotPlusMinus - { write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type (java_array_type (java_type_from_name ($2), $3)); - write_exp_elt_opcode (UNOP_CAST); } + { write_exp_elt_opcode (pstate, UNOP_CAST); + write_exp_elt_type (pstate, + java_array_type (java_type_from_name + ($2), $3)); + write_exp_elt_opcode (pstate, UNOP_CAST); } ; MultiplicativeExpression: UnaryExpression | MultiplicativeExpression '*' UnaryExpression - { write_exp_elt_opcode (BINOP_MUL); } + { write_exp_elt_opcode (pstate, BINOP_MUL); } | MultiplicativeExpression '/' UnaryExpression - { write_exp_elt_opcode (BINOP_DIV); } + { write_exp_elt_opcode (pstate, BINOP_DIV); } | MultiplicativeExpression '%' UnaryExpression - { write_exp_elt_opcode (BINOP_REM); } + { write_exp_elt_opcode (pstate, BINOP_REM); } ; AdditiveExpression: MultiplicativeExpression | AdditiveExpression '+' MultiplicativeExpression - { write_exp_elt_opcode (BINOP_ADD); } + { write_exp_elt_opcode (pstate, BINOP_ADD); } | AdditiveExpression '-' MultiplicativeExpression - { write_exp_elt_opcode (BINOP_SUB); } + { write_exp_elt_opcode (pstate, BINOP_SUB); } ; ShiftExpression: AdditiveExpression | ShiftExpression LSH AdditiveExpression - { write_exp_elt_opcode (BINOP_LSH); } + { write_exp_elt_opcode (pstate, BINOP_LSH); } | ShiftExpression RSH AdditiveExpression - { write_exp_elt_opcode (BINOP_RSH); } + { write_exp_elt_opcode (pstate, BINOP_RSH); } /* | ShiftExpression >>> AdditiveExpression { FIXME } */ ; RelationalExpression: ShiftExpression | RelationalExpression '<' ShiftExpression - { write_exp_elt_opcode (BINOP_LESS); } + { write_exp_elt_opcode (pstate, BINOP_LESS); } | RelationalExpression '>' ShiftExpression - { write_exp_elt_opcode (BINOP_GTR); } + { write_exp_elt_opcode (pstate, BINOP_GTR); } | RelationalExpression LEQ ShiftExpression - { write_exp_elt_opcode (BINOP_LEQ); } + { write_exp_elt_opcode (pstate, BINOP_LEQ); } | RelationalExpression GEQ ShiftExpression - { write_exp_elt_opcode (BINOP_GEQ); } + { write_exp_elt_opcode (pstate, BINOP_GEQ); } /* | RelationalExpresion INSTANCEOF ReferenceType { FIXME } */ ; EqualityExpression: RelationalExpression | EqualityExpression EQUAL RelationalExpression - { write_exp_elt_opcode (BINOP_EQUAL); } + { write_exp_elt_opcode (pstate, BINOP_EQUAL); } | EqualityExpression NOTEQUAL RelationalExpression - { write_exp_elt_opcode (BINOP_NOTEQUAL); } + { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); } ; AndExpression: EqualityExpression | AndExpression '&' EqualityExpression - { write_exp_elt_opcode (BINOP_BITWISE_AND); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); } ; ExclusiveOrExpression: AndExpression | ExclusiveOrExpression '^' AndExpression - { write_exp_elt_opcode (BINOP_BITWISE_XOR); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); } ; InclusiveOrExpression: ExclusiveOrExpression | InclusiveOrExpression '|' ExclusiveOrExpression - { write_exp_elt_opcode (BINOP_BITWISE_IOR); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); } ; ConditionalAndExpression: InclusiveOrExpression | ConditionalAndExpression ANDAND InclusiveOrExpression - { write_exp_elt_opcode (BINOP_LOGICAL_AND); } + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); } ; ConditionalOrExpression: ConditionalAndExpression | ConditionalOrExpression OROR ConditionalAndExpression - { write_exp_elt_opcode (BINOP_LOGICAL_OR); } + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); } ; ConditionalExpression: ConditionalOrExpression | ConditionalOrExpression '?' Expression ':' ConditionalExpression - { write_exp_elt_opcode (TERNOP_COND); } + { write_exp_elt_opcode (pstate, TERNOP_COND); } ; AssignmentExpression: @@ -671,16 +689,16 @@ AssignmentExpression: Assignment: LeftHandSide '=' ConditionalExpression - { write_exp_elt_opcode (BINOP_ASSIGN); } + { write_exp_elt_opcode (pstate, BINOP_ASSIGN); } | LeftHandSide ASSIGN_MODIFY ConditionalExpression - { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); - write_exp_elt_opcode ($2); - write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); } + { write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); + write_exp_elt_opcode (pstate, $2); + write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); } ; LeftHandSide: ForcedName - { push_expression_name ($1); } + { push_expression_name (pstate, $1); } | VARIABLE /* Already written by write_dollar_variable. */ | FieldAccess @@ -700,7 +718,8 @@ Expression: /*** Needs some error checking for the float case ***/ static int -parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere) +parse_number (struct parser_state *par_state, + const char *p, int len, int parsed_float, YYSTYPE *putithere) { ULONGEST n = 0; ULONGEST limit, limit_div_base; @@ -721,16 +740,17 @@ parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere) suffix_len = p + len - suffix; if (suffix_len == 0) - putithere->typed_val_float.type = parse_type->builtin_double; + putithere->typed_val_float.type + = parse_type (par_state)->builtin_double; else if (suffix_len == 1) { /* See if it has `f' or `d' suffix (float or double). */ if (tolower (*suffix) == 'f') putithere->typed_val_float.type = - parse_type->builtin_float; + parse_type (par_state)->builtin_float; else if (tolower (*suffix) == 'd') putithere->typed_val_float.type = - parse_type->builtin_double; + parse_type (par_state)->builtin_double; else return ERROR; } @@ -777,12 +797,12 @@ parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere) limit = ((limit << 16) << 16) | limit; if (c == 'l' || c == 'L') { - type = parse_java_type->builtin_long; + type = parse_java_type (par_state)->builtin_long; len--; } else { - type = parse_java_type->builtin_int; + type = parse_java_type (par_state)->builtin_int; } limit_div_base = limit / (ULONGEST) base; @@ -807,11 +827,13 @@ parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere) /* If the type is bigger than a 32-bit signed integer can be, implicitly promote to long. Java does not do this, so mark it as - parse_type->builtin_uint64 rather than parse_java_type->builtin_long. + parse_type (par_state)->builtin_uint64 rather than + parse_java_type (par_state)->builtin_long. 0x80000000 will become -0x80000000 instead of 0x80000000L, because we don't know the sign at this point. */ - if (type == parse_java_type->builtin_int && n > (ULONGEST)0x80000000) - type = parse_type->builtin_uint64; + if (type == parse_java_type (par_state)->builtin_int + && n > (ULONGEST)0x80000000) + type = parse_type (par_state)->builtin_uint64; putithere->typed_val_int.val = n; putithere->typed_val_int.type = type; @@ -909,12 +931,12 @@ yylex (void) lexptr++; c = *lexptr++; if (c == '\\') - c = parse_escape (parse_gdbarch, &lexptr); + c = parse_escape (parse_gdbarch (pstate), &lexptr); else if (c == '\'') error (_("Empty character constant")); yylval.typed_val_int.val = c; - yylval.typed_val_int.type = parse_java_type->builtin_char; + yylval.typed_val_int.type = parse_java_type (pstate)->builtin_char; c = *lexptr++; if (c != '\'') @@ -1007,7 +1029,8 @@ yylex (void) && (*p < 'A' || *p > 'Z'))) break; } - toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval); + toktype = parse_number (pstate, tokstart, p - tokstart, + got_dot|got_e, &yylval); if (toktype == ERROR) { char *err_copy = (char *) alloca (p - tokstart + 1); @@ -1072,7 +1095,7 @@ yylex (void) break; case '\\': tokptr++; - c = parse_escape (parse_gdbarch, &tokptr); + c = parse_escape (parse_gdbarch (pstate), &tokptr); if (c == -1) { continue; @@ -1184,7 +1207,7 @@ yylex (void) if (*tokstart == '$') { - write_dollar_variable (yylval.sval); + write_dollar_variable (pstate, yylval.sval); return VARIABLE; } @@ -1195,13 +1218,29 @@ yylex (void) (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10))) { YYSTYPE newlval; /* Its value is ignored. */ - int hextype = parse_number (tokstart, namelen, 0, &newlval); + int hextype = parse_number (pstate, tokstart, namelen, 0, &newlval); if (hextype == INTEGER_LITERAL) return NAME_OR_INT; } return IDENTIFIER; } +int +java_parse (struct parser_state *par_state) +{ + int result; + struct cleanup *c = make_cleanup_clear_parser_state (&pstate); + + /* Setting up the parser state. */ + gdb_assert (par_state != NULL); + pstate = par_state; + + result = yyparse (); + do_cleanups (c); + + return result; +} + void yyerror (char *msg) { @@ -1228,11 +1267,12 @@ java_type_from_name (struct stoken name) Otherwise, return 0. */ static int -push_variable (struct stoken name) +push_variable (struct parser_state *par_state, struct stoken name) { char *tmp = copy_name (name); struct field_of_this_result is_a_field_of_this; struct symbol *sym; + sym = lookup_symbol (tmp, expression_context_block, VAR_DOMAIN, &is_a_field_of_this); if (sym && SYMBOL_CLASS (sym) != LOC_TYPEDEF) @@ -1244,12 +1284,12 @@ push_variable (struct stoken name) innermost_block = block_found; } - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_opcode (par_state, OP_VAR_VALUE); /* We want to use the selected frame, not another more inner frame which happens to be in the same block. */ - write_exp_elt_block (NULL); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_block (par_state, NULL); + write_exp_elt_sym (par_state, sym); + write_exp_elt_opcode (par_state, OP_VAR_VALUE); return 1; } if (is_a_field_of_this.type != NULL) @@ -1259,11 +1299,11 @@ push_variable (struct stoken name) if (innermost_block == 0 || contained_in (block_found, innermost_block)) innermost_block = block_found; - write_exp_elt_opcode (OP_THIS); - write_exp_elt_opcode (OP_THIS); - write_exp_elt_opcode (STRUCTOP_PTR); - write_exp_string (name); - write_exp_elt_opcode (STRUCTOP_PTR); + write_exp_elt_opcode (par_state, OP_THIS); + write_exp_elt_opcode (par_state, OP_THIS); + write_exp_elt_opcode (par_state, STRUCTOP_PTR); + write_exp_string (par_state, name); + write_exp_elt_opcode (par_state, STRUCTOP_PTR); return 1; } return 0; @@ -1274,7 +1314,7 @@ push_variable (struct stoken name) qualified name (has '.'), generate a field access for each part. */ static void -push_fieldnames (struct stoken name) +push_fieldnames (struct parser_state *par_state, struct stoken name) { int i; struct stoken token; @@ -1285,9 +1325,9 @@ push_fieldnames (struct stoken name) { /* token.ptr is start of current field name. */ token.length = &name.ptr[i] - token.ptr; - write_exp_elt_opcode (STRUCTOP_PTR); - write_exp_string (token); - write_exp_elt_opcode (STRUCTOP_PTR); + write_exp_elt_opcode (par_state, STRUCTOP_PTR); + write_exp_string (par_state, token); + write_exp_elt_opcode (par_state, STRUCTOP_PTR); token.ptr += token.length + 1; } if (i >= name.length) @@ -1299,7 +1339,8 @@ push_fieldnames (struct stoken name) Handle a qualified name, where DOT_INDEX is the index of the first '.' */ static void -push_qualified_expression_name (struct stoken name, int dot_index) +push_qualified_expression_name (struct parser_state *par_state, + struct stoken name, int dot_index) { struct stoken token; char *tmp; @@ -1308,11 +1349,11 @@ push_qualified_expression_name (struct stoken name, int dot_index) token.ptr = name.ptr; token.length = dot_index; - if (push_variable (token)) + if (push_variable (par_state, token)) { token.ptr = name.ptr + dot_index + 1; token.length = name.length - dot_index - 1; - push_fieldnames (token); + push_fieldnames (par_state, token); return; } @@ -1326,9 +1367,9 @@ push_qualified_expression_name (struct stoken name, int dot_index) { if (dot_index == name.length) { - write_exp_elt_opcode(OP_TYPE); - write_exp_elt_type(typ); - write_exp_elt_opcode(OP_TYPE); + write_exp_elt_opcode (par_state, OP_TYPE); + write_exp_elt_type (par_state, typ); + write_exp_elt_opcode (par_state, OP_TYPE); return; } dot_index++; /* Skip '.' */ @@ -1339,16 +1380,16 @@ push_qualified_expression_name (struct stoken name, int dot_index) dot_index++; token.ptr = name.ptr; token.length = dot_index; - write_exp_elt_opcode (OP_SCOPE); - write_exp_elt_type (typ); - write_exp_string (token); - write_exp_elt_opcode (OP_SCOPE); + write_exp_elt_opcode (par_state, OP_SCOPE); + write_exp_elt_type (par_state, typ); + write_exp_string (par_state, token); + write_exp_elt_opcode (par_state, OP_SCOPE); if (dot_index < name.length) { dot_index++; name.ptr += dot_index; name.length -= dot_index; - push_fieldnames (name); + push_fieldnames (par_state, name); } return; } @@ -1365,7 +1406,7 @@ push_qualified_expression_name (struct stoken name, int dot_index) Handle VAR, TYPE, TYPE.FIELD1....FIELDN and VAR.FIELD1....FIELDN. */ static void -push_expression_name (struct stoken name) +push_expression_name (struct parser_state *par_state, struct stoken name) { char *tmp; struct type *typ; @@ -1376,22 +1417,22 @@ push_expression_name (struct stoken name) if (name.ptr[i] == '.') { /* It's a Qualified Expression Name. */ - push_qualified_expression_name (name, i); + push_qualified_expression_name (par_state, name, i); return; } } /* It's a Simple Expression Name. */ - if (push_variable (name)) + if (push_variable (par_state, name)) return; tmp = copy_name (name); typ = java_lookup_class (tmp); if (typ != NULL) { - write_exp_elt_opcode(OP_TYPE); - write_exp_elt_type(typ); - write_exp_elt_opcode(OP_TYPE); + write_exp_elt_opcode (par_state, OP_TYPE); + write_exp_elt_type (par_state, typ); + write_exp_elt_opcode (par_state, OP_TYPE); } else { @@ -1399,7 +1440,7 @@ push_expression_name (struct stoken name) msymbol = lookup_bound_minimal_symbol (tmp); if (msymbol.minsym != NULL) - write_exp_msymbol (msymbol); + write_exp_msymbol (par_state, msymbol); else if (!have_full_symbols () && !have_partial_symbols ()) error (_("No symbol table is loaded. Use the \"file\" command")); else @@ -1423,6 +1464,7 @@ copy_exp (struct expression *expr, int endpos) int len = length_of_subexp (expr, endpos); struct expression *new = (struct expression *) malloc (sizeof (*new) + EXP_ELEM_TO_BYTES (len)); + new->nelts = len; memcpy (new->elts, expr->elts + endpos - len, EXP_ELEM_TO_BYTES (len)); new->language_defn = 0; @@ -1432,27 +1474,19 @@ copy_exp (struct expression *expr, int endpos) /* Insert the expression NEW into the current expression (expout) at POS. */ static void -insert_exp (int pos, struct expression *new) +insert_exp (struct parser_state *par_state, int pos, struct expression *new) { int newlen = new->nelts; + int i; /* Grow expout if necessary. In this function's only use at present, this should never be necessary. */ - if (expout_ptr + newlen > expout_size) - { - expout_size = max (expout_size * 2, expout_ptr + newlen + 10); - expout = (struct expression *) - realloc ((char *) expout, (sizeof (struct expression) - + EXP_ELEM_TO_BYTES (expout_size))); - } - - { - int i; + increase_expout_size (par_state, newlen); - for (i = expout_ptr - 1; i >= pos; i--) - expout->elts[i + newlen] = expout->elts[i]; - } + for (i = par_state->expout_ptr - 1; i >= pos; i--) + par_state->expout->elts[i + newlen] = par_state->expout->elts[i]; - memcpy (expout->elts + pos, new->elts, EXP_ELEM_TO_BYTES (newlen)); - expout_ptr += newlen; + memcpy (par_state->expout->elts + pos, new->elts, + EXP_ELEM_TO_BYTES (newlen)); + par_state->expout_ptr += newlen; } diff --git a/gdb/jv-lang.h b/gdb/jv-lang.h index 43feec7..345cc91 100644 --- a/gdb/jv-lang.h +++ b/gdb/jv-lang.h @@ -22,8 +22,9 @@ struct value; struct type_print_options; +struct parser_state; -extern int java_parse (void); /* Defined in jv-exp.y */ +extern int java_parse (struct parser_state *); /* Defined in jv-exp.y */ extern void java_error (char *); /* Defined in jv-exp.y */ diff --git a/gdb/language.c b/gdb/language.c index ae0fa15..d5502f2 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -50,7 +50,7 @@ extern void _initialize_language (void); static void unk_lang_error (char *); -static int unk_lang_parser (void); +static int unk_lang_parser (struct parser_state *); static void show_check (char *, int); @@ -694,7 +694,7 @@ default_get_string (struct value *value, gdb_byte **buffer, int *length, /* Define the language that is no language. */ static int -unk_lang_parser (void) +unk_lang_parser (struct parser_state *ps) { return 1; } diff --git a/gdb/language.h b/gdb/language.h index ded595f..9e95bf2 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -34,6 +34,7 @@ struct ui_file; struct value_print_options; struct type_print_options; struct lang_varobj_ops; +struct parser_state; #define MAX_FORTRAN_DIMS 7 /* Maximum number of F77 array dims. */ @@ -164,7 +165,7 @@ struct language_defn /* Parser function. */ - int (*la_parser) (void); + int (*la_parser) (struct parser_state *); /* Parser error function. */ diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y index 07aa986..917a028 100644 --- a/gdb/m2-exp.y +++ b/gdb/m2-exp.y @@ -49,8 +49,8 @@ #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */ #include "block.h" -#define parse_type builtin_type (parse_gdbarch) -#define parse_m2_type builtin_m2_type (parse_gdbarch) +#define parse_type(ps) builtin_type (parse_gdbarch (ps)) +#define parse_m2_type(ps) builtin_m2_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 @@ -60,7 +60,7 @@ generators need to be fixed instead of adding those names to this list. */ #define yymaxdepth m2_maxdepth -#define yyparse m2_parse +#define yyparse m2_parse_internal #define yylex m2_lex #define yyerror m2_error #define yylval m2_lval @@ -112,6 +112,11 @@ #define YYFPRINTF parser_fprintf +/* The state of the parser, used internally when we are parsing the + expression. */ + +static struct parser_state *pstate = NULL; + int yyparse (void); static int yylex (void); @@ -204,31 +209,31 @@ start : exp ; type_exp: type - { write_exp_elt_opcode(OP_TYPE); - write_exp_elt_type($1); - write_exp_elt_opcode(OP_TYPE); + { write_exp_elt_opcode (pstate, OP_TYPE); + write_exp_elt_type (pstate, $1); + write_exp_elt_opcode (pstate, OP_TYPE); } ; /* Expressions */ exp : exp '^' %prec UNARY - { write_exp_elt_opcode (UNOP_IND); } + { write_exp_elt_opcode (pstate, UNOP_IND); } ; exp : '-' { number_sign = -1; } exp %prec UNARY { number_sign = 1; - write_exp_elt_opcode (UNOP_NEG); } + write_exp_elt_opcode (pstate, UNOP_NEG); } ; exp : '+' exp %prec UNARY - { write_exp_elt_opcode(UNOP_PLUS); } + { write_exp_elt_opcode (pstate, UNOP_PLUS); } ; exp : not_exp exp %prec UNARY - { write_exp_elt_opcode (UNOP_LOGICAL_NOT); } + { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); } ; not_exp : NOT @@ -236,88 +241,90 @@ not_exp : NOT ; exp : CAP '(' exp ')' - { write_exp_elt_opcode (UNOP_CAP); } + { write_exp_elt_opcode (pstate, UNOP_CAP); } ; exp : ORD '(' exp ')' - { write_exp_elt_opcode (UNOP_ORD); } + { write_exp_elt_opcode (pstate, UNOP_ORD); } ; exp : ABS '(' exp ')' - { write_exp_elt_opcode (UNOP_ABS); } + { write_exp_elt_opcode (pstate, UNOP_ABS); } ; exp : HIGH '(' exp ')' - { write_exp_elt_opcode (UNOP_HIGH); } + { write_exp_elt_opcode (pstate, UNOP_HIGH); } ; exp : MIN_FUNC '(' type ')' - { write_exp_elt_opcode (UNOP_MIN); - write_exp_elt_type ($3); - write_exp_elt_opcode (UNOP_MIN); } + { write_exp_elt_opcode (pstate, UNOP_MIN); + write_exp_elt_type (pstate, $3); + write_exp_elt_opcode (pstate, UNOP_MIN); } ; exp : MAX_FUNC '(' type ')' - { write_exp_elt_opcode (UNOP_MAX); - write_exp_elt_type ($3); - write_exp_elt_opcode (UNOP_MAX); } + { write_exp_elt_opcode (pstate, UNOP_MAX); + write_exp_elt_type (pstate, $3); + write_exp_elt_opcode (pstate, UNOP_MAX); } ; exp : FLOAT_FUNC '(' exp ')' - { write_exp_elt_opcode (UNOP_FLOAT); } + { write_exp_elt_opcode (pstate, UNOP_FLOAT); } ; exp : VAL '(' type ',' exp ')' - { write_exp_elt_opcode (BINOP_VAL); - write_exp_elt_type ($3); - write_exp_elt_opcode (BINOP_VAL); } + { write_exp_elt_opcode (pstate, BINOP_VAL); + write_exp_elt_type (pstate, $3); + write_exp_elt_opcode (pstate, BINOP_VAL); } ; exp : CHR '(' exp ')' - { write_exp_elt_opcode (UNOP_CHR); } + { write_exp_elt_opcode (pstate, UNOP_CHR); } ; exp : ODD '(' exp ')' - { write_exp_elt_opcode (UNOP_ODD); } + { write_exp_elt_opcode (pstate, UNOP_ODD); } ; exp : TRUNC '(' exp ')' - { write_exp_elt_opcode (UNOP_TRUNC); } + { write_exp_elt_opcode (pstate, UNOP_TRUNC); } ; exp : TSIZE '(' exp ')' - { write_exp_elt_opcode (UNOP_SIZEOF); } + { write_exp_elt_opcode (pstate, UNOP_SIZEOF); } ; exp : SIZE exp %prec UNARY - { write_exp_elt_opcode (UNOP_SIZEOF); } + { write_exp_elt_opcode (pstate, UNOP_SIZEOF); } ; exp : INC '(' exp ')' - { write_exp_elt_opcode(UNOP_PREINCREMENT); } + { write_exp_elt_opcode (pstate, UNOP_PREINCREMENT); } ; exp : INC '(' exp ',' exp ')' - { write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); - write_exp_elt_opcode(BINOP_ADD); - write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); } + { write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); + write_exp_elt_opcode (pstate, BINOP_ADD); + write_exp_elt_opcode (pstate, + BINOP_ASSIGN_MODIFY); } ; exp : DEC '(' exp ')' - { write_exp_elt_opcode(UNOP_PREDECREMENT);} + { write_exp_elt_opcode (pstate, UNOP_PREDECREMENT);} ; exp : DEC '(' exp ',' exp ')' - { write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); - write_exp_elt_opcode(BINOP_SUB); - write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); } + { write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); + write_exp_elt_opcode (pstate, BINOP_SUB); + write_exp_elt_opcode (pstate, + BINOP_ASSIGN_MODIFY); } ; exp : exp DOT NAME - { write_exp_elt_opcode (STRUCTOP_STRUCT); - write_exp_string ($3); - write_exp_elt_opcode (STRUCTOP_STRUCT); } + { write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); + write_exp_string (pstate, $3); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } ; exp : set @@ -349,13 +356,14 @@ exp : exp '[' function types */ { start_arglist(); } non_empty_arglist ']' %prec DOT - { write_exp_elt_opcode (MULTI_SUBSCRIPT); - write_exp_elt_longcst ((LONGEST) end_arglist()); - write_exp_elt_opcode (MULTI_SUBSCRIPT); } + { write_exp_elt_opcode (pstate, MULTI_SUBSCRIPT); + write_exp_elt_longcst (pstate, + (LONGEST) end_arglist()); + write_exp_elt_opcode (pstate, MULTI_SUBSCRIPT); } ; exp : exp '[' exp ']' - { write_exp_elt_opcode (BINOP_SUBSCRIPT); } + { write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); } ; exp : exp '(' @@ -363,9 +371,10 @@ exp : exp '(' being accumulated by an outer function call. */ { start_arglist (); } arglist ')' %prec DOT - { write_exp_elt_opcode (OP_FUNCALL); - write_exp_elt_longcst ((LONGEST) end_arglist ()); - write_exp_elt_opcode (OP_FUNCALL); } + { write_exp_elt_opcode (pstate, OP_FUNCALL); + write_exp_elt_longcst (pstate, + (LONGEST) end_arglist ()); + write_exp_elt_opcode (pstate, OP_FUNCALL); } ; arglist : @@ -391,15 +400,15 @@ non_empty_arglist /* GDB construct */ exp : '{' type '}' exp %prec UNARY - { write_exp_elt_opcode (UNOP_MEMVAL); - write_exp_elt_type ($2); - write_exp_elt_opcode (UNOP_MEMVAL); } + { write_exp_elt_opcode (pstate, UNOP_MEMVAL); + write_exp_elt_type (pstate, $2); + write_exp_elt_opcode (pstate, UNOP_MEMVAL); } ; exp : type '(' exp ')' %prec UNARY - { write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type ($1); - write_exp_elt_opcode (UNOP_CAST); } + { write_exp_elt_opcode (pstate, UNOP_CAST); + write_exp_elt_type (pstate, $1); + write_exp_elt_opcode (pstate, UNOP_CAST); } ; exp : '(' exp ')' @@ -411,131 +420,140 @@ exp : '(' exp ')' /* GDB construct */ exp : exp '@' exp - { write_exp_elt_opcode (BINOP_REPEAT); } + { write_exp_elt_opcode (pstate, BINOP_REPEAT); } ; exp : exp '*' exp - { write_exp_elt_opcode (BINOP_MUL); } + { write_exp_elt_opcode (pstate, BINOP_MUL); } ; exp : exp '/' exp - { write_exp_elt_opcode (BINOP_DIV); } + { write_exp_elt_opcode (pstate, BINOP_DIV); } ; exp : exp DIV exp - { write_exp_elt_opcode (BINOP_INTDIV); } + { write_exp_elt_opcode (pstate, BINOP_INTDIV); } ; exp : exp MOD exp - { write_exp_elt_opcode (BINOP_REM); } + { write_exp_elt_opcode (pstate, BINOP_REM); } ; exp : exp '+' exp - { write_exp_elt_opcode (BINOP_ADD); } + { write_exp_elt_opcode (pstate, BINOP_ADD); } ; exp : exp '-' exp - { write_exp_elt_opcode (BINOP_SUB); } + { write_exp_elt_opcode (pstate, BINOP_SUB); } ; exp : exp '=' exp - { write_exp_elt_opcode (BINOP_EQUAL); } + { write_exp_elt_opcode (pstate, BINOP_EQUAL); } ; exp : exp NOTEQUAL exp - { write_exp_elt_opcode (BINOP_NOTEQUAL); } + { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); } | exp '#' exp - { write_exp_elt_opcode (BINOP_NOTEQUAL); } + { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); } ; exp : exp LEQ exp - { write_exp_elt_opcode (BINOP_LEQ); } + { write_exp_elt_opcode (pstate, BINOP_LEQ); } ; exp : exp GEQ exp - { write_exp_elt_opcode (BINOP_GEQ); } + { write_exp_elt_opcode (pstate, BINOP_GEQ); } ; exp : exp '<' exp - { write_exp_elt_opcode (BINOP_LESS); } + { write_exp_elt_opcode (pstate, BINOP_LESS); } ; exp : exp '>' exp - { write_exp_elt_opcode (BINOP_GTR); } + { write_exp_elt_opcode (pstate, BINOP_GTR); } ; exp : exp LOGICAL_AND exp - { write_exp_elt_opcode (BINOP_LOGICAL_AND); } + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); } ; exp : exp OROR exp - { write_exp_elt_opcode (BINOP_LOGICAL_OR); } + { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); } ; exp : exp ASSIGN exp - { write_exp_elt_opcode (BINOP_ASSIGN); } + { write_exp_elt_opcode (pstate, BINOP_ASSIGN); } ; /* Constants */ exp : M2_TRUE - { write_exp_elt_opcode (OP_BOOL); - write_exp_elt_longcst ((LONGEST) $1); - write_exp_elt_opcode (OP_BOOL); } + { write_exp_elt_opcode (pstate, OP_BOOL); + write_exp_elt_longcst (pstate, (LONGEST) $1); + write_exp_elt_opcode (pstate, OP_BOOL); } ; exp : M2_FALSE - { write_exp_elt_opcode (OP_BOOL); - write_exp_elt_longcst ((LONGEST) $1); - write_exp_elt_opcode (OP_BOOL); } + { write_exp_elt_opcode (pstate, OP_BOOL); + write_exp_elt_longcst (pstate, (LONGEST) $1); + write_exp_elt_opcode (pstate, OP_BOOL); } ; exp : INT - { write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (parse_m2_type->builtin_int); - write_exp_elt_longcst ((LONGEST) $1); - write_exp_elt_opcode (OP_LONG); } + { write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, + parse_m2_type (pstate)->builtin_int); + write_exp_elt_longcst (pstate, (LONGEST) $1); + write_exp_elt_opcode (pstate, OP_LONG); } ; exp : UINT { - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (parse_m2_type->builtin_card); - write_exp_elt_longcst ((LONGEST) $1); - write_exp_elt_opcode (OP_LONG); + write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, + parse_m2_type (pstate) + ->builtin_card); + write_exp_elt_longcst (pstate, (LONGEST) $1); + write_exp_elt_opcode (pstate, OP_LONG); } ; exp : CHAR - { write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (parse_m2_type->builtin_char); - write_exp_elt_longcst ((LONGEST) $1); - write_exp_elt_opcode (OP_LONG); } + { write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, + parse_m2_type (pstate) + ->builtin_char); + write_exp_elt_longcst (pstate, (LONGEST) $1); + write_exp_elt_opcode (pstate, OP_LONG); } ; exp : FLOAT - { write_exp_elt_opcode (OP_DOUBLE); - write_exp_elt_type (parse_m2_type->builtin_real); - write_exp_elt_dblcst ($1); - write_exp_elt_opcode (OP_DOUBLE); } + { write_exp_elt_opcode (pstate, OP_DOUBLE); + write_exp_elt_type (pstate, + parse_m2_type (pstate) + ->builtin_real); + write_exp_elt_dblcst (pstate, $1); + write_exp_elt_opcode (pstate, OP_DOUBLE); } ; exp : variable ; exp : SIZE '(' type ')' %prec UNARY - { write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (parse_type->builtin_int); - write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3)); - write_exp_elt_opcode (OP_LONG); } + { write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, + parse_type (pstate)->builtin_int); + write_exp_elt_longcst (pstate, + (LONGEST) TYPE_LENGTH ($3)); + write_exp_elt_opcode (pstate, OP_LONG); } ; exp : STRING - { write_exp_elt_opcode (OP_M2_STRING); - write_exp_string ($1); - write_exp_elt_opcode (OP_M2_STRING); } + { write_exp_elt_opcode (pstate, OP_M2_STRING); + write_exp_string (pstate, $1); + write_exp_elt_opcode (pstate, OP_M2_STRING); } ; /* This will be used for extensions later. Like adding modules. */ @@ -545,7 +563,8 @@ block : fblock fblock : BLOCKNAME { struct symbol *sym - = lookup_symbol (copy_name ($1), expression_context_block, + = lookup_symbol (copy_name ($1), + expression_context_block, VAR_DOMAIN, 0); $$ = sym;} ; @@ -565,10 +584,10 @@ fblock : block COLONCOLON BLOCKNAME /* Useful for assigning to PROCEDURE variables */ variable: fblock - { write_exp_elt_opcode(OP_VAR_VALUE); - write_exp_elt_block (NULL); - write_exp_elt_sym ($1); - write_exp_elt_opcode (OP_VAR_VALUE); } + { write_exp_elt_opcode (pstate, OP_VAR_VALUE); + write_exp_elt_block (pstate, NULL); + write_exp_elt_sym (pstate, $1); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); } ; /* GDB internal ($foo) variable */ @@ -591,11 +610,11 @@ variable: block COLONCOLON NAME innermost_block = block_found; } - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); /* block_found is set by lookup_symbol. */ - write_exp_elt_block (block_found); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); } + write_exp_elt_block (pstate, block_found); + write_exp_elt_sym (pstate, sym); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); } ; /* Base case for variables. */ @@ -617,13 +636,13 @@ variable: NAME innermost_block = block_found; } - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); /* We want to use the selected frame, not another more inner frame which happens to be in the same block. */ - write_exp_elt_block (NULL); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_block (pstate, NULL); + write_exp_elt_sym (pstate, sym); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); } else { @@ -633,7 +652,7 @@ variable: NAME msymbol = lookup_bound_minimal_symbol (arg); if (msymbol.minsym != NULL) - write_exp_msymbol (msymbol); + write_exp_msymbol (pstate, msymbol); else if (!have_full_symbols () && !have_partial_symbols ()) error (_("No symbol table is loaded. Use the \"symbol-file\" command.")); else @@ -645,7 +664,8 @@ variable: NAME type : TYPENAME - { $$ = lookup_typename (parse_language, parse_gdbarch, + { $$ = lookup_typename (parse_language (pstate), + parse_gdbarch (pstate), copy_name ($1), expression_context_block, 0); } @@ -805,8 +825,8 @@ static struct keyword keytab[] = /* Read one token, getting characters through lexptr. */ -/* This is where we will check to make sure that the language and the operators used are - compatible */ +/* This is where we will check to make sure that the language and the + operators used are compatible */ static int yylex (void) @@ -992,7 +1012,7 @@ yylex (void) if (*tokstart == '$') { - write_dollar_variable (yylval.sval); + write_dollar_variable (pstate, yylval.sval); return INTERNAL_VAR; } @@ -1012,8 +1032,9 @@ yylex (void) sym = lookup_symbol (tmp, expression_context_block, VAR_DOMAIN, 0); if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK) return BLOCKNAME; - if (lookup_typename (parse_language, parse_gdbarch, - copy_name (yylval.sval), expression_context_block, 1)) + if (lookup_typename (parse_language (pstate), parse_gdbarch (pstate), + copy_name (yylval.sval), + expression_context_block, 1)) return TYPENAME; if(sym) @@ -1070,6 +1091,22 @@ yylex (void) } } +int +m2_parse (struct parser_state *par_state) +{ + int result; + struct cleanup *c = make_cleanup_clear_parser_state (&pstate); + + /* Setting up the parser state. */ + gdb_assert (par_state != NULL); + pstate = par_state; + + result = yyparse (); + do_cleanups (c); + + return result; +} + void yyerror (char *msg) { diff --git a/gdb/m2-lang.h b/gdb/m2-lang.h index 772221f..d363975 100644 --- a/gdb/m2-lang.h +++ b/gdb/m2-lang.h @@ -18,8 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ struct type_print_options; +struct parser_state; -extern int m2_parse (void); /* Defined in m2-exp.y */ +extern int m2_parse (struct parser_state *); /* Defined in m2-exp.y */ extern void m2_error (char *); /* Defined in m2-exp.y */ diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c index 4327895..68f0d10 100644 --- a/gdb/objc-lang.c +++ b/gdb/objc-lang.c @@ -465,7 +465,7 @@ add_msglist(struct stoken *str, int addcolon) } int -end_msglist(void) +end_msglist (struct parser_state *ps) { int val = msglist_len; struct selname *sel = selname_chain; @@ -475,12 +475,12 @@ end_msglist(void) selname_chain = sel->next; msglist_len = sel->msglist_len; msglist_sel = sel->msglist_sel; - selid = lookup_child_selector (parse_gdbarch, p); + selid = lookup_child_selector (parse_gdbarch (ps), p); if (!selid) error (_("Can't find selector \"%s\""), p); - write_exp_elt_longcst (selid); + write_exp_elt_longcst (ps, selid); xfree(p); - write_exp_elt_longcst (val); /* Number of args */ + write_exp_elt_longcst (ps, val); /* Number of args */ xfree(sel); return val; diff --git a/gdb/objc-lang.h b/gdb/objc-lang.h index 6ba576a..df1fe53 100644 --- a/gdb/objc-lang.h +++ b/gdb/objc-lang.h @@ -26,6 +26,7 @@ struct stoken; struct value; struct block; +struct parser_state; extern CORE_ADDR lookup_objc_class (struct gdbarch *gdbarch, char *classname); @@ -45,7 +46,7 @@ extern struct value *value_nsstring (struct gdbarch *gdbarch, /* for parsing Objective C */ extern void start_msglist (void); extern void add_msglist (struct stoken *str, int addcolon); -extern int end_msglist (void); +extern int end_msglist (struct parser_state *); struct symbol *lookup_struct_typedef (char *name, const struct block *block, int noerr); diff --git a/gdb/p-exp.y b/gdb/p-exp.y index f1c91ba..4e8f96c 100644 --- a/gdb/p-exp.y +++ b/gdb/p-exp.y @@ -57,7 +57,7 @@ #include "block.h" #include "completer.h" -#define parse_type builtin_type (parse_gdbarch) +#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 @@ -67,7 +67,7 @@ generators need to be fixed instead of adding those names to this list. */ #define yymaxdepth pascal_maxdepth -#define yyparse pascal_parse +#define yyparse pascal_parse_internal #define yylex pascal_lex #define yyerror pascal_error #define yylval pascal_lval @@ -119,6 +119,11 @@ #define YYFPRINTF parser_fprintf +/* The state of the parser, used internally when we are parsing the + expression. */ + +static struct parser_state *pstate = NULL; + int yyparse (void); static int yylex (void); @@ -159,7 +164,8 @@ static char *uptok (const char *, int); %{ /* YYSTYPE gets defined by %union */ -static int parse_number (const char *, int, int, YYSTYPE *); +static int parse_number (struct parser_state *, + const char *, int, int, YYSTYPE *); static struct type *current_type; static struct internalvar *intvar; @@ -252,44 +258,44 @@ normal_start : ; type_exp: type - { write_exp_elt_opcode(OP_TYPE); - write_exp_elt_type($1); - write_exp_elt_opcode(OP_TYPE); + { write_exp_elt_opcode (pstate, OP_TYPE); + write_exp_elt_type (pstate, $1); + write_exp_elt_opcode (pstate, OP_TYPE); current_type = $1; } ; /* Expressions, including the comma operator. */ exp1 : exp | exp1 ',' exp - { write_exp_elt_opcode (BINOP_COMMA); } + { write_exp_elt_opcode (pstate, BINOP_COMMA); } ; /* Expressions, not including the comma operator. */ exp : exp '^' %prec UNARY - { write_exp_elt_opcode (UNOP_IND); + { write_exp_elt_opcode (pstate, UNOP_IND); if (current_type) current_type = TYPE_TARGET_TYPE (current_type); } ; exp : '@' exp %prec UNARY - { write_exp_elt_opcode (UNOP_ADDR); + { write_exp_elt_opcode (pstate, UNOP_ADDR); if (current_type) current_type = TYPE_POINTER_TYPE (current_type); } ; exp : '-' exp %prec UNARY - { write_exp_elt_opcode (UNOP_NEG); } + { write_exp_elt_opcode (pstate, UNOP_NEG); } ; exp : NOT exp %prec UNARY - { write_exp_elt_opcode (UNOP_LOGICAL_NOT); } + { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); } ; exp : INCREMENT '(' exp ')' %prec UNARY - { write_exp_elt_opcode (UNOP_PREINCREMENT); } + { write_exp_elt_opcode (pstate, UNOP_PREINCREMENT); } ; exp : DECREMENT '(' exp ')' %prec UNARY - { write_exp_elt_opcode (UNOP_PREDECREMENT); } + { write_exp_elt_opcode (pstate, UNOP_PREDECREMENT); } ; @@ -298,9 +304,9 @@ field_exp : exp '.' %prec UNARY ; exp : field_exp FIELDNAME - { write_exp_elt_opcode (STRUCTOP_STRUCT); - write_exp_string ($2); - write_exp_elt_opcode (STRUCTOP_STRUCT); + { write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); + write_exp_string (pstate, $2); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); search_field = 0; if (current_type) { @@ -316,9 +322,9 @@ exp : field_exp FIELDNAME exp : field_exp name - { write_exp_elt_opcode (STRUCTOP_STRUCT); - write_exp_string ($2); - write_exp_elt_opcode (STRUCTOP_STRUCT); + { write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); + write_exp_string (pstate, $2); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); search_field = 0; if (current_type) { @@ -332,19 +338,19 @@ exp : field_exp name } ; exp : field_exp name COMPLETE - { mark_struct_expression (); - write_exp_elt_opcode (STRUCTOP_STRUCT); - write_exp_string ($2); - write_exp_elt_opcode (STRUCTOP_STRUCT); } + { mark_struct_expression (pstate); + 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 (); - write_exp_elt_opcode (STRUCTOP_STRUCT); + mark_struct_expression (pstate); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); s.ptr = ""; s.length = 0; - write_exp_string (s); - write_exp_elt_opcode (STRUCTOP_STRUCT); } + write_exp_string (pstate, s); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } ; exp : exp '[' @@ -365,14 +371,14 @@ exp : exp '[' strcpy (buf, arrayname); current_type = TYPE_FIELD_TYPE (current_type, arrayfieldindex - 1); - write_exp_elt_opcode (STRUCTOP_STRUCT); - write_exp_string (stringsval); - write_exp_elt_opcode (STRUCTOP_STRUCT); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); + write_exp_string (pstate, stringsval); + write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } push_current_type (); } exp1 ']' { pop_current_type (); - write_exp_elt_opcode (BINOP_SUBSCRIPT); + write_exp_elt_opcode (pstate, BINOP_SUBSCRIPT); if (current_type) current_type = TYPE_TARGET_TYPE (current_type); } ; @@ -383,9 +389,10 @@ exp : exp '(' { push_current_type (); start_arglist (); } arglist ')' %prec ARROW - { write_exp_elt_opcode (OP_FUNCALL); - write_exp_elt_longcst ((LONGEST) end_arglist ()); - write_exp_elt_opcode (OP_FUNCALL); + { write_exp_elt_opcode (pstate, OP_FUNCALL); + write_exp_elt_longcst (pstate, + (LONGEST) end_arglist ()); + write_exp_elt_opcode (pstate, OP_FUNCALL); pop_current_type (); if (current_type) current_type = TYPE_TARGET_TYPE (current_type); @@ -406,11 +413,11 @@ exp : type '(' exp ')' %prec UNARY if ((TYPE_CODE (current_type) == TYPE_CODE_PTR) && (TYPE_CODE (TYPE_TARGET_TYPE (current_type)) == TYPE_CODE_CLASS) && (TYPE_CODE ($1) == TYPE_CODE_CLASS)) - write_exp_elt_opcode (UNOP_IND); + write_exp_elt_opcode (pstate, UNOP_IND); } - write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type ($1); - write_exp_elt_opcode (UNOP_CAST); + write_exp_elt_opcode (pstate, UNOP_CAST); + write_exp_elt_type (pstate, $1); + write_exp_elt_opcode (pstate, UNOP_CAST); current_type = $1; } ; @@ -421,7 +428,7 @@ exp : '(' exp1 ')' /* Binary operators in order of decreasing precedence. */ exp : exp '*' exp - { write_exp_elt_opcode (BINOP_MUL); } + { write_exp_elt_opcode (pstate, BINOP_MUL); } ; exp : exp '/' { @@ -433,135 +440,138 @@ exp : exp '/' { if (leftdiv_is_integer && current_type && is_integral_type (current_type)) { - write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type (parse_type->builtin_long_double); - current_type = parse_type->builtin_long_double; - write_exp_elt_opcode (UNOP_CAST); + write_exp_elt_opcode (pstate, UNOP_CAST); + write_exp_elt_type (pstate, + parse_type (pstate) + ->builtin_long_double); + current_type + = parse_type (pstate)->builtin_long_double; + write_exp_elt_opcode (pstate, UNOP_CAST); leftdiv_is_integer = 0; } - write_exp_elt_opcode (BINOP_DIV); + write_exp_elt_opcode (pstate, BINOP_DIV); } ; exp : exp DIV exp - { write_exp_elt_opcode (BINOP_INTDIV); } + { write_exp_elt_opcode (pstate, BINOP_INTDIV); } ; exp : exp MOD exp - { write_exp_elt_opcode (BINOP_REM); } + { write_exp_elt_opcode (pstate, BINOP_REM); } ; exp : exp '+' exp - { write_exp_elt_opcode (BINOP_ADD); } + { write_exp_elt_opcode (pstate, BINOP_ADD); } ; exp : exp '-' exp - { write_exp_elt_opcode (BINOP_SUB); } + { write_exp_elt_opcode (pstate, BINOP_SUB); } ; exp : exp LSH exp - { write_exp_elt_opcode (BINOP_LSH); } + { write_exp_elt_opcode (pstate, BINOP_LSH); } ; exp : exp RSH exp - { write_exp_elt_opcode (BINOP_RSH); } + { write_exp_elt_opcode (pstate, BINOP_RSH); } ; exp : exp '=' exp - { write_exp_elt_opcode (BINOP_EQUAL); - current_type = parse_type->builtin_bool; + { write_exp_elt_opcode (pstate, BINOP_EQUAL); + current_type = parse_type (pstate)->builtin_bool; } ; exp : exp NOTEQUAL exp - { write_exp_elt_opcode (BINOP_NOTEQUAL); - current_type = parse_type->builtin_bool; + { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); + current_type = parse_type (pstate)->builtin_bool; } ; exp : exp LEQ exp - { write_exp_elt_opcode (BINOP_LEQ); - current_type = parse_type->builtin_bool; + { write_exp_elt_opcode (pstate, BINOP_LEQ); + current_type = parse_type (pstate)->builtin_bool; } ; exp : exp GEQ exp - { write_exp_elt_opcode (BINOP_GEQ); - current_type = parse_type->builtin_bool; + { write_exp_elt_opcode (pstate, BINOP_GEQ); + current_type = parse_type (pstate)->builtin_bool; } ; exp : exp '<' exp - { write_exp_elt_opcode (BINOP_LESS); - current_type = parse_type->builtin_bool; + { write_exp_elt_opcode (pstate, BINOP_LESS); + current_type = parse_type (pstate)->builtin_bool; } ; exp : exp '>' exp - { write_exp_elt_opcode (BINOP_GTR); - current_type = parse_type->builtin_bool; + { write_exp_elt_opcode (pstate, BINOP_GTR); + current_type = parse_type (pstate)->builtin_bool; } ; exp : exp ANDAND exp - { write_exp_elt_opcode (BINOP_BITWISE_AND); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); } ; exp : exp XOR exp - { write_exp_elt_opcode (BINOP_BITWISE_XOR); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); } ; exp : exp OR exp - { write_exp_elt_opcode (BINOP_BITWISE_IOR); } + { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); } ; exp : exp ASSIGN exp - { write_exp_elt_opcode (BINOP_ASSIGN); } + { write_exp_elt_opcode (pstate, BINOP_ASSIGN); } ; exp : TRUEKEYWORD - { write_exp_elt_opcode (OP_BOOL); - write_exp_elt_longcst ((LONGEST) $1); - current_type = parse_type->builtin_bool; - write_exp_elt_opcode (OP_BOOL); } + { write_exp_elt_opcode (pstate, OP_BOOL); + write_exp_elt_longcst (pstate, (LONGEST) $1); + current_type = parse_type (pstate)->builtin_bool; + write_exp_elt_opcode (pstate, OP_BOOL); } ; exp : FALSEKEYWORD - { write_exp_elt_opcode (OP_BOOL); - write_exp_elt_longcst ((LONGEST) $1); - current_type = parse_type->builtin_bool; - write_exp_elt_opcode (OP_BOOL); } + { write_exp_elt_opcode (pstate, OP_BOOL); + write_exp_elt_longcst (pstate, (LONGEST) $1); + current_type = parse_type (pstate)->builtin_bool; + write_exp_elt_opcode (pstate, OP_BOOL); } ; exp : INT - { write_exp_elt_opcode (OP_LONG); - write_exp_elt_type ($1.type); + { write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, $1.type); current_type = $1.type; - write_exp_elt_longcst ((LONGEST)($1.val)); - write_exp_elt_opcode (OP_LONG); } + write_exp_elt_longcst (pstate, (LONGEST)($1.val)); + write_exp_elt_opcode (pstate, OP_LONG); } ; exp : NAME_OR_INT { YYSTYPE val; - parse_number ($1.stoken.ptr, + parse_number (pstate, $1.stoken.ptr, $1.stoken.length, 0, &val); - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (val.typed_val_int.type); + write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, val.typed_val_int.type); current_type = val.typed_val_int.type; - write_exp_elt_longcst ((LONGEST) + write_exp_elt_longcst (pstate, (LONGEST) val.typed_val_int.val); - write_exp_elt_opcode (OP_LONG); + write_exp_elt_opcode (pstate, OP_LONG); } ; exp : FLOAT - { write_exp_elt_opcode (OP_DOUBLE); - write_exp_elt_type ($1.type); + { write_exp_elt_opcode (pstate, OP_DOUBLE); + write_exp_elt_type (pstate, $1.type); current_type = $1.type; - write_exp_elt_dblcst ($1.dval); - write_exp_elt_opcode (OP_DOUBLE); } + write_exp_elt_dblcst (pstate, $1.dval); + write_exp_elt_opcode (pstate, OP_DOUBLE); } ; exp : variable @@ -574,7 +584,7 @@ exp : VARIABLE struct value * val, * mark; mark = value_mark (); - val = value_of_internalvar (parse_gdbarch, + val = value_of_internalvar (parse_gdbarch (pstate), intvar); current_type = value_type (val); value_release_to_mark (mark); @@ -583,17 +593,19 @@ exp : VARIABLE ; exp : SIZEOF '(' type ')' %prec UNARY - { write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (parse_type->builtin_int); - current_type = parse_type->builtin_int; + { write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, + parse_type (pstate)->builtin_int); + current_type = parse_type (pstate)->builtin_int; CHECK_TYPEDEF ($3); - write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3)); - write_exp_elt_opcode (OP_LONG); } + write_exp_elt_longcst (pstate, + (LONGEST) TYPE_LENGTH ($3)); + write_exp_elt_opcode (pstate, OP_LONG); } ; exp : SIZEOF '(' exp ')' %prec UNARY - { write_exp_elt_opcode (UNOP_SIZEOF); - current_type = parse_type->builtin_int; } + { write_exp_elt_opcode (pstate, UNOP_SIZEOF); + current_type = parse_type (pstate)->builtin_int; } exp : STRING { /* C strings are converted into array constants with @@ -605,19 +617,25 @@ exp : STRING while (count-- > 0) { - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (parse_type->builtin_char); - write_exp_elt_longcst ((LONGEST)(*sp++)); - write_exp_elt_opcode (OP_LONG); + write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, + parse_type (pstate) + ->builtin_char); + write_exp_elt_longcst (pstate, + (LONGEST) (*sp++)); + write_exp_elt_opcode (pstate, OP_LONG); } - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (parse_type->builtin_char); - write_exp_elt_longcst ((LONGEST)'\0'); - write_exp_elt_opcode (OP_LONG); - write_exp_elt_opcode (OP_ARRAY); - write_exp_elt_longcst ((LONGEST) 0); - write_exp_elt_longcst ((LONGEST) ($1.length)); - write_exp_elt_opcode (OP_ARRAY); } + write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_type (pstate, + parse_type (pstate) + ->builtin_char); + write_exp_elt_longcst (pstate, (LONGEST)'\0'); + write_exp_elt_opcode (pstate, OP_LONG); + write_exp_elt_opcode (pstate, OP_ARRAY); + write_exp_elt_longcst (pstate, (LONGEST) 0); + write_exp_elt_longcst (pstate, + (LONGEST) ($1.length)); + write_exp_elt_opcode (pstate, OP_ARRAY); } ; /* Object pascal */ @@ -625,10 +643,11 @@ exp : THIS { struct value * this_val; struct type * this_type; - write_exp_elt_opcode (OP_THIS); - write_exp_elt_opcode (OP_THIS); + write_exp_elt_opcode (pstate, OP_THIS); + write_exp_elt_opcode (pstate, OP_THIS); /* We need type of this. */ - this_val = value_of_this_silent (parse_language); + this_val + = value_of_this_silent (parse_language (pstate)); if (this_val) this_type = value_type (this_val); else @@ -638,7 +657,7 @@ exp : THIS if (TYPE_CODE (this_type) == TYPE_CODE_PTR) { this_type = TYPE_TARGET_TYPE (this_type); - write_exp_elt_opcode (UNOP_IND); + write_exp_elt_opcode (pstate, UNOP_IND); } } @@ -684,11 +703,11 @@ variable: block COLONCOLON name error (_("No symbol \"%s\" in specified context."), copy_name ($3)); - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); /* block_found is set by lookup_symbol. */ - write_exp_elt_block (block_found); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); } + write_exp_elt_block (pstate, block_found); + write_exp_elt_sym (pstate, sym); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); } ; qualified_name: typebase COLONCOLON name @@ -699,10 +718,10 @@ qualified_name: typebase COLONCOLON name error (_("`%s' is not defined as an aggregate type."), TYPE_NAME (type)); - write_exp_elt_opcode (OP_SCOPE); - write_exp_elt_type (type); - write_exp_string ($3); - write_exp_elt_opcode (OP_SCOPE); + write_exp_elt_opcode (pstate, OP_SCOPE); + write_exp_elt_type (pstate, type); + write_exp_string (pstate, $3); + write_exp_elt_opcode (pstate, OP_SCOPE); } ; @@ -718,16 +737,16 @@ variable: qualified_name VAR_DOMAIN, NULL); if (sym) { - write_exp_elt_opcode (OP_VAR_VALUE); - write_exp_elt_block (NULL); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); + write_exp_elt_block (pstate, NULL); + write_exp_elt_sym (pstate, sym); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); break; } msymbol = lookup_bound_minimal_symbol (name); if (msymbol.minsym != NULL) - write_exp_msymbol (msymbol); + write_exp_msymbol (pstate, msymbol); else if (!have_full_symbols () && !have_partial_symbols ()) error (_("No symbol table is loaded. " @@ -751,13 +770,13 @@ variable: name_not_typename innermost_block = block_found; } - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); /* We want to use the selected frame, not another more inner frame which happens to be in the same block. */ - write_exp_elt_block (NULL); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_block (pstate, NULL); + write_exp_elt_sym (pstate, sym); + write_exp_elt_opcode (pstate, OP_VAR_VALUE); current_type = sym->type; } else if ($1.is_a_field_of_this) { @@ -770,13 +789,14 @@ variable: name_not_typename || contained_in (block_found, innermost_block)) innermost_block = block_found; - write_exp_elt_opcode (OP_THIS); - write_exp_elt_opcode (OP_THIS); - write_exp_elt_opcode (STRUCTOP_PTR); - write_exp_string ($1.stoken); - write_exp_elt_opcode (STRUCTOP_PTR); + write_exp_elt_opcode (pstate, OP_THIS); + write_exp_elt_opcode (pstate, OP_THIS); + write_exp_elt_opcode (pstate, STRUCTOP_PTR); + write_exp_string (pstate, $1.stoken); + write_exp_elt_opcode (pstate, STRUCTOP_PTR); /* We need type of this. */ - this_val = value_of_this_silent (parse_language); + this_val + = value_of_this_silent (parse_language (pstate)); if (this_val) this_type = value_type (this_val); else @@ -796,7 +816,7 @@ variable: name_not_typename msymbol = lookup_bound_minimal_symbol (arg); if (msymbol.minsym != NULL) - write_exp_msymbol (msymbol); + write_exp_msymbol (pstate, msymbol); else if (!have_full_symbols () && !have_partial_symbols ()) error (_("No symbol table is loaded. " @@ -865,7 +885,8 @@ name_not_typename : NAME /*** Needs some error checking for the float case ***/ static int -parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere) +parse_number (struct parser_state *par_state, + const char *p, int len, int parsed_float, YYSTYPE *putithere) { /* FIXME: Shouldn't these be unsigned? We don't deal with negative values here, and we do kind of silly things like cast to unsigned. */ @@ -890,7 +911,7 @@ parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere) if (parsed_float) { - if (! parse_c_float (parse_gdbarch, p, len, + if (! parse_c_float (parse_gdbarch (par_state), p, len, &putithere->typed_val_float.dval, &putithere->typed_val_float.type)) return ERROR; @@ -996,9 +1017,10 @@ parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere) un = (ULONGEST)n >> 2; if (long_p == 0 - && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0) + && (un >> (gdbarch_int_bit (parse_gdbarch (par_state)) - 2)) == 0) { - high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1); + high_bit + = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch (par_state)) - 1); /* A large decimal (not hex or octal) constant (between INT_MAX and UINT_MAX) is a long or unsigned long, according to ANSI, @@ -1006,28 +1028,29 @@ parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere) int. This probably should be fixed. GCC gives a warning on such constants. */ - unsigned_type = parse_type->builtin_unsigned_int; - signed_type = parse_type->builtin_int; + unsigned_type = parse_type (par_state)->builtin_unsigned_int; + signed_type = parse_type (par_state)->builtin_int; } else if (long_p <= 1 - && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0) + && (un >> (gdbarch_long_bit (parse_gdbarch (par_state)) - 2)) == 0) { - high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1); - unsigned_type = parse_type->builtin_unsigned_long; - signed_type = parse_type->builtin_long; + high_bit + = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch (par_state)) - 1); + unsigned_type = parse_type (par_state)->builtin_unsigned_long; + signed_type = parse_type (par_state)->builtin_long; } else { int shift; if (sizeof (ULONGEST) * HOST_CHAR_BIT - < gdbarch_long_long_bit (parse_gdbarch)) + < gdbarch_long_long_bit (parse_gdbarch (par_state))) /* A long long does not fit in a LONGEST. */ shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1); else - shift = (gdbarch_long_long_bit (parse_gdbarch) - 1); + shift = (gdbarch_long_long_bit (parse_gdbarch (par_state)) - 1); high_bit = (ULONGEST) 1 << shift; - unsigned_type = parse_type->builtin_unsigned_long_long; - signed_type = parse_type->builtin_long_long; + unsigned_type = parse_type (par_state)->builtin_unsigned_long_long; + signed_type = parse_type (par_state)->builtin_long_long; } putithere->typed_val_int.val = n; @@ -1195,12 +1218,12 @@ yylex (void) lexptr++; c = *lexptr++; if (c == '\\') - c = parse_escape (parse_gdbarch, &lexptr); + c = parse_escape (parse_gdbarch (pstate), &lexptr); else if (c == '\'') error (_("Empty character constant.")); yylval.typed_val_int.val = c; - yylval.typed_val_int.type = parse_type->builtin_char; + yylval.typed_val_int.type = parse_type (pstate)->builtin_char; c = *lexptr++; if (c != '\'') @@ -1298,7 +1321,7 @@ yylex (void) && (*p < 'A' || *p > 'Z'))) break; } - toktype = parse_number (tokstart, + toktype = parse_number (pstate, tokstart, p - tokstart, got_dot | got_e, &yylval); if (toktype == ERROR) { @@ -1365,7 +1388,7 @@ yylex (void) break; case '\\': ++tokptr; - c = parse_escape (parse_gdbarch, &tokptr); + c = parse_escape (parse_gdbarch (pstate), &tokptr); if (c == -1) { continue; @@ -1508,7 +1531,7 @@ yylex (void) but this conflicts with the GDB use for debugger variables so in expression to enter hexadecimal values we still need to use C syntax with 0xff */ - write_dollar_variable (yylval.sval); + write_dollar_variable (pstate, yylval.sval); tmp = alloca (namelen + 1); memcpy (tmp, tokstart, namelen); tmp[namelen] = '\0'; @@ -1688,8 +1711,8 @@ yylex (void) return TYPENAME; } yylval.tsym.type - = language_lookup_primitive_type_by_name (parse_language, - parse_gdbarch, tmp); + = language_lookup_primitive_type_by_name (parse_language (pstate), + parse_gdbarch (pstate), tmp); if (yylval.tsym.type != NULL) { free (uptokstart); @@ -1704,7 +1727,7 @@ yylex (void) || (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10))) { YYSTYPE newlval; /* Its value is ignored. */ - hextype = parse_number (tokstart, namelen, 0, &newlval); + hextype = parse_number (pstate, tokstart, namelen, 0, &newlval); if (hextype == INT) { yylval.ssym.sym = sym; @@ -1722,6 +1745,21 @@ 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. */ + gdb_assert (par_state != NULL); + pstate = par_state; + + result = yyparse (); + do_cleanups (c); + return result; +} + void yyerror (char *msg) { diff --git a/gdb/p-lang.h b/gdb/p-lang.h index 1a94b8f..ea2d37c 100644 --- a/gdb/p-lang.h +++ b/gdb/p-lang.h @@ -20,11 +20,12 @@ /* This file is derived from c-lang.h */ struct value; +struct parser_state; /* Defined in p-lang.c */ extern const char *pascal_main_name (void); -extern int pascal_parse (void); /* Defined in p-exp.y */ +extern int pascal_parse (struct parser_state *); /* Defined in p-exp.y */ extern void pascal_error (char *); /* Defined in p-exp.y */ diff --git a/gdb/parse.c b/gdb/parse.c index c6e25a9..b0da2ef 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -67,9 +67,6 @@ const struct exp_descriptor exp_descriptor_standard = }; /* Global variables declared in parser-defs.h (and commented there). */ -struct expression *expout; -int expout_size; -int expout_ptr; const struct block *expression_context_block; CORE_ADDR expression_context_pc; const struct block *innermost_block; @@ -185,118 +182,121 @@ free_funcalls (void *ignore) } } -/* This page contains the functions for adding data to the struct expression - being constructed. */ /* See definition in parser-defs.h. */ void -initialize_expout (int initial_size, const struct language_defn *lang, +initialize_expout (struct parser_state *ps, size_t initial_size, + const struct language_defn *lang, struct gdbarch *gdbarch) { - expout_size = initial_size; - expout_ptr = 0; - expout = xmalloc (sizeof (struct expression) - + EXP_ELEM_TO_BYTES (expout_size)); - expout->language_defn = lang; - expout->gdbarch = gdbarch; + ps->expout_size = initial_size; + ps->expout_ptr = 0; + ps->expout = xmalloc (sizeof (struct expression) + + EXP_ELEM_TO_BYTES (ps->expout_size)); + ps->expout->language_defn = lang; + ps->expout->gdbarch = gdbarch; } /* See definition in parser-defs.h. */ void -reallocate_expout (void) +reallocate_expout (struct parser_state *ps) { /* Record the actual number of expression elements, and then reallocate the expression memory so that we free up any excess elements. */ - expout->nelts = expout_ptr; - expout = xrealloc ((char *) expout, - sizeof (struct expression) - + EXP_ELEM_TO_BYTES (expout_ptr)); + ps->expout->nelts = ps->expout_ptr; + ps->expout = (struct expression *) + xrealloc (ps->expout, + sizeof (struct expression) + + EXP_ELEM_TO_BYTES (ps->expout_ptr)); } +/* This page contains the functions for adding data to the struct expression + being constructed. */ + /* Add one element to the end of the expression. */ /* To avoid a bug in the Sun 4 compiler, we pass things that can fit into a register through here. */ static void -write_exp_elt (const union exp_element *expelt) +write_exp_elt (struct parser_state *ps, const union exp_element *expelt) { - if (expout_ptr >= expout_size) + if (ps->expout_ptr >= ps->expout_size) { - expout_size *= 2; - expout = (struct expression *) - xrealloc ((char *) expout, sizeof (struct expression) - + EXP_ELEM_TO_BYTES (expout_size)); + ps->expout_size *= 2; + ps->expout = (struct expression *) + xrealloc (ps->expout, sizeof (struct expression) + + EXP_ELEM_TO_BYTES (ps->expout_size)); } - expout->elts[expout_ptr++] = *expelt; + ps->expout->elts[ps->expout_ptr++] = *expelt; } void -write_exp_elt_opcode (enum exp_opcode expelt) +write_exp_elt_opcode (struct parser_state *ps, enum exp_opcode expelt) { union exp_element tmp; memset (&tmp, 0, sizeof (union exp_element)); tmp.opcode = expelt; - write_exp_elt (&tmp); + write_exp_elt (ps, &tmp); } void -write_exp_elt_sym (struct symbol *expelt) +write_exp_elt_sym (struct parser_state *ps, struct symbol *expelt) { union exp_element tmp; memset (&tmp, 0, sizeof (union exp_element)); tmp.symbol = expelt; - write_exp_elt (&tmp); + write_exp_elt (ps, &tmp); } void -write_exp_elt_block (const struct block *b) +write_exp_elt_block (struct parser_state *ps, const struct block *b) { union exp_element tmp; memset (&tmp, 0, sizeof (union exp_element)); tmp.block = b; - write_exp_elt (&tmp); + write_exp_elt (ps, &tmp); } void -write_exp_elt_objfile (struct objfile *objfile) +write_exp_elt_objfile (struct parser_state *ps, struct objfile *objfile) { union exp_element tmp; memset (&tmp, 0, sizeof (union exp_element)); tmp.objfile = objfile; - write_exp_elt (&tmp); + write_exp_elt (ps, &tmp); } void -write_exp_elt_longcst (LONGEST expelt) +write_exp_elt_longcst (struct parser_state *ps, LONGEST expelt) { union exp_element tmp; memset (&tmp, 0, sizeof (union exp_element)); tmp.longconst = expelt; - write_exp_elt (&tmp); + write_exp_elt (ps, &tmp); } void -write_exp_elt_dblcst (DOUBLEST expelt) +write_exp_elt_dblcst (struct parser_state *ps, DOUBLEST expelt) { union exp_element tmp; memset (&tmp, 0, sizeof (union exp_element)); tmp.doubleconst = expelt; - write_exp_elt (&tmp); + write_exp_elt (ps, &tmp); } void -write_exp_elt_decfloatcst (gdb_byte expelt[16]) +write_exp_elt_decfloatcst (struct parser_state *ps, gdb_byte expelt[16]) { union exp_element tmp; int index; @@ -304,27 +304,27 @@ write_exp_elt_decfloatcst (gdb_byte expelt[16]) for (index = 0; index < 16; index++) tmp.decfloatconst[index] = expelt[index]; - write_exp_elt (&tmp); + write_exp_elt (ps, &tmp); } void -write_exp_elt_type (struct type *expelt) +write_exp_elt_type (struct parser_state *ps, struct type *expelt) { union exp_element tmp; memset (&tmp, 0, sizeof (union exp_element)); tmp.type = expelt; - write_exp_elt (&tmp); + write_exp_elt (ps, &tmp); } void -write_exp_elt_intern (struct internalvar *expelt) +write_exp_elt_intern (struct parser_state *ps, struct internalvar *expelt) { union exp_element tmp; memset (&tmp, 0, sizeof (union exp_element)); tmp.internalvar = expelt; - write_exp_elt (&tmp); + write_exp_elt (ps, &tmp); } /* Add a string constant to the end of the expression. @@ -349,10 +349,10 @@ write_exp_elt_intern (struct internalvar *expelt) void -write_exp_string (struct stoken str) +write_exp_string (struct parser_state *ps, struct stoken str) { int len = str.length; - int lenelt; + size_t lenelt; char *strdata; /* Compute the number of expression elements required to hold the string @@ -362,28 +362,19 @@ write_exp_string (struct stoken str) lenelt = 2 + BYTES_TO_EXP_ELEM (len + 1); - /* Ensure that we have enough available expression elements to store - everything. */ - - if ((expout_ptr + lenelt) >= expout_size) - { - expout_size = max (expout_size * 2, expout_ptr + lenelt + 10); - expout = (struct expression *) - xrealloc ((char *) expout, (sizeof (struct expression) - + EXP_ELEM_TO_BYTES (expout_size))); - } + increase_expout_size (ps, lenelt); /* Write the leading length expression element (which advances the current expression element index), then write the string constant followed by a terminating null byte, and then write the trailing length expression element. */ - write_exp_elt_longcst ((LONGEST) len); - strdata = (char *) &expout->elts[expout_ptr]; + write_exp_elt_longcst (ps, (LONGEST) len); + strdata = (char *) &ps->expout->elts[ps->expout_ptr]; memcpy (strdata, str.ptr, len); *(strdata + len) = '\0'; - expout_ptr += lenelt - 2; - write_exp_elt_longcst ((LONGEST) len); + ps->expout_ptr += lenelt - 2; + write_exp_elt_longcst (ps, (LONGEST) len); } /* Add a vector of string constants to the end of the expression. @@ -400,9 +391,11 @@ write_exp_string (struct stoken str) long constant, followed by the contents of the string. */ void -write_exp_string_vector (int type, struct stoken_vector *vec) +write_exp_string_vector (struct parser_state *ps, int type, + struct stoken_vector *vec) { - int i, n_slots, len; + int i, len; + size_t n_slots; /* Compute the size. We compute the size in number of slots to avoid issues with string padding. */ @@ -421,28 +414,22 @@ write_exp_string_vector (int type, struct stoken_vector *vec) len = EXP_ELEM_TO_BYTES (n_slots) - 1; n_slots += 4; - if ((expout_ptr + n_slots) >= expout_size) - { - expout_size = max (expout_size * 2, expout_ptr + n_slots + 10); - expout = (struct expression *) - xrealloc ((char *) expout, (sizeof (struct expression) - + EXP_ELEM_TO_BYTES (expout_size))); - } + increase_expout_size (ps, n_slots); - write_exp_elt_opcode (OP_STRING); - write_exp_elt_longcst (len); - write_exp_elt_longcst (type); + write_exp_elt_opcode (ps, OP_STRING); + write_exp_elt_longcst (ps, len); + write_exp_elt_longcst (ps, type); for (i = 0; i < vec->len; ++i) { - write_exp_elt_longcst (vec->tokens[i].length); - memcpy (&expout->elts[expout_ptr], vec->tokens[i].ptr, + write_exp_elt_longcst (ps, vec->tokens[i].length); + memcpy (&ps->expout->elts[ps->expout_ptr], vec->tokens[i].ptr, vec->tokens[i].length); - expout_ptr += BYTES_TO_EXP_ELEM (vec->tokens[i].length); + ps->expout_ptr += BYTES_TO_EXP_ELEM (vec->tokens[i].length); } - write_exp_elt_longcst (len); - write_exp_elt_opcode (OP_STRING); + write_exp_elt_longcst (ps, len); + write_exp_elt_opcode (ps, OP_STRING); } /* Add a bitstring constant to the end of the expression. @@ -457,11 +444,11 @@ write_exp_string_vector (int type, struct stoken_vector *vec) either end of the bitstring. */ void -write_exp_bitstring (struct stoken str) +write_exp_bitstring (struct parser_state *ps, struct stoken str) { int bits = str.length; /* length in bits */ int len = (bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT; - int lenelt; + size_t lenelt; char *strdata; /* Compute the number of expression elements required to hold the bitstring, @@ -470,33 +457,25 @@ write_exp_bitstring (struct stoken str) lenelt = 2 + BYTES_TO_EXP_ELEM (len); - /* Ensure that we have enough available expression elements to store - everything. */ - - if ((expout_ptr + lenelt) >= expout_size) - { - expout_size = max (expout_size * 2, expout_ptr + lenelt + 10); - expout = (struct expression *) - xrealloc ((char *) expout, (sizeof (struct expression) - + EXP_ELEM_TO_BYTES (expout_size))); - } + increase_expout_size (ps, lenelt); /* Write the leading length expression element (which advances the current expression element index), then write the bitstring constant, and then write the trailing length expression element. */ - write_exp_elt_longcst ((LONGEST) bits); - strdata = (char *) &expout->elts[expout_ptr]; + write_exp_elt_longcst (ps, (LONGEST) bits); + strdata = (char *) &ps->expout->elts[ps->expout_ptr]; memcpy (strdata, str.ptr, len); - expout_ptr += lenelt - 2; - write_exp_elt_longcst ((LONGEST) bits); + ps->expout_ptr += lenelt - 2; + write_exp_elt_longcst (ps, (LONGEST) bits); } /* Add the appropriate elements for a minimal symbol to the end of the expression. */ void -write_exp_msymbol (struct bound_minimal_symbol bound_msym) +write_exp_msymbol (struct parser_state *ps, + struct bound_minimal_symbol bound_msym) { struct minimal_symbol *msymbol = bound_msym.minsym; struct objfile *objfile = bound_msym.objfile; @@ -536,62 +515,62 @@ write_exp_msymbol (struct bound_minimal_symbol bound_msym) if (overlay_debugging) addr = symbol_overlayed_address (addr, section); - write_exp_elt_opcode (OP_LONG); + write_exp_elt_opcode (ps, OP_LONG); /* Let's make the type big enough to hold a 64-bit address. */ - write_exp_elt_type (objfile_type (objfile)->builtin_core_addr); - write_exp_elt_longcst ((LONGEST) addr); - write_exp_elt_opcode (OP_LONG); + write_exp_elt_type (ps, objfile_type (objfile)->builtin_core_addr); + write_exp_elt_longcst (ps, (LONGEST) addr); + write_exp_elt_opcode (ps, OP_LONG); if (section && section->the_bfd_section->flags & SEC_THREAD_LOCAL) { - write_exp_elt_opcode (UNOP_MEMVAL_TLS); - write_exp_elt_objfile (objfile); - write_exp_elt_type (objfile_type (objfile)->nodebug_tls_symbol); - write_exp_elt_opcode (UNOP_MEMVAL_TLS); + write_exp_elt_opcode (ps, UNOP_MEMVAL_TLS); + write_exp_elt_objfile (ps, objfile); + write_exp_elt_type (ps, objfile_type (objfile)->nodebug_tls_symbol); + write_exp_elt_opcode (ps, UNOP_MEMVAL_TLS); return; } - write_exp_elt_opcode (UNOP_MEMVAL); + write_exp_elt_opcode (ps, UNOP_MEMVAL); switch (type) { case mst_text: case mst_file_text: case mst_solib_trampoline: - write_exp_elt_type (objfile_type (objfile)->nodebug_text_symbol); + write_exp_elt_type (ps, objfile_type (objfile)->nodebug_text_symbol); break; case mst_text_gnu_ifunc: - write_exp_elt_type (objfile_type (objfile) - ->nodebug_text_gnu_ifunc_symbol); + write_exp_elt_type (ps, objfile_type (objfile) + ->nodebug_text_gnu_ifunc_symbol); break; case mst_data: case mst_file_data: case mst_bss: case mst_file_bss: - write_exp_elt_type (objfile_type (objfile)->nodebug_data_symbol); + write_exp_elt_type (ps, objfile_type (objfile)->nodebug_data_symbol); break; case mst_slot_got_plt: - write_exp_elt_type (objfile_type (objfile)->nodebug_got_plt_symbol); + write_exp_elt_type (ps, objfile_type (objfile)->nodebug_got_plt_symbol); break; default: - write_exp_elt_type (objfile_type (objfile)->nodebug_unknown_symbol); + write_exp_elt_type (ps, objfile_type (objfile)->nodebug_unknown_symbol); break; } - write_exp_elt_opcode (UNOP_MEMVAL); + write_exp_elt_opcode (ps, UNOP_MEMVAL); } /* Mark the current index as the starting location of a structure expression. This is used when completing on field names. */ void -mark_struct_expression (void) +mark_struct_expression (struct parser_state *ps) { gdb_assert (parse_completion && expout_tag_completion_type == TYPE_CODE_UNDEF); - expout_last_struct = expout_ptr; + expout_last_struct = ps->expout_ptr; } /* Indicate that the current parser invocation is completing a tag. @@ -638,7 +617,7 @@ mark_completion_tag (enum type_code tag, const char *ptr, int length) value in the value history, I.e. $$1 */ void -write_dollar_variable (struct stoken str) +write_dollar_variable (struct parser_state *ps, struct stoken str) { struct symbol *sym = NULL; struct bound_minimal_symbol msym; @@ -676,7 +655,7 @@ write_dollar_variable (struct stoken str) /* Handle tokens that refer to machine registers: $ followed by a register name. */ - i = user_reg_map_name_to_regnum (parse_gdbarch, + i = user_reg_map_name_to_regnum (parse_gdbarch (ps), str.ptr + 1, str.length - 1); if (i >= 0) goto handle_register; @@ -686,9 +665,9 @@ write_dollar_variable (struct stoken str) isym = lookup_only_internalvar (copy_name (str) + 1); if (isym) { - write_exp_elt_opcode (OP_INTERNALVAR); - write_exp_elt_intern (isym); - write_exp_elt_opcode (OP_INTERNALVAR); + write_exp_elt_opcode (ps, OP_INTERNALVAR); + write_exp_elt_intern (ps, isym); + write_exp_elt_opcode (ps, OP_INTERNALVAR); return; } @@ -699,36 +678,36 @@ write_dollar_variable (struct stoken str) VAR_DOMAIN, NULL); if (sym) { - write_exp_elt_opcode (OP_VAR_VALUE); - write_exp_elt_block (block_found); /* set by lookup_symbol */ - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_opcode (ps, OP_VAR_VALUE); + write_exp_elt_block (ps, block_found); /* set by lookup_symbol */ + write_exp_elt_sym (ps, sym); + write_exp_elt_opcode (ps, OP_VAR_VALUE); return; } msym = lookup_bound_minimal_symbol (copy_name (str)); if (msym.minsym) { - write_exp_msymbol (msym); + write_exp_msymbol (ps, msym); return; } /* Any other names are assumed to be debugger internal variables. */ - write_exp_elt_opcode (OP_INTERNALVAR); - write_exp_elt_intern (create_internalvar (copy_name (str) + 1)); - write_exp_elt_opcode (OP_INTERNALVAR); + write_exp_elt_opcode (ps, OP_INTERNALVAR); + write_exp_elt_intern (ps, create_internalvar (copy_name (str) + 1)); + write_exp_elt_opcode (ps, OP_INTERNALVAR); return; handle_last: - write_exp_elt_opcode (OP_LAST); - write_exp_elt_longcst ((LONGEST) i); - write_exp_elt_opcode (OP_LAST); + write_exp_elt_opcode (ps, OP_LAST); + write_exp_elt_longcst (ps, (LONGEST) i); + write_exp_elt_opcode (ps, OP_LAST); return; handle_register: - write_exp_elt_opcode (OP_REGISTER); + write_exp_elt_opcode (ps, OP_REGISTER); str.length--; str.ptr++; - write_exp_string (str); - write_exp_elt_opcode (OP_REGISTER); + write_exp_string (ps, str); + write_exp_elt_opcode (ps, OP_REGISTER); return; } @@ -1161,6 +1140,7 @@ parse_exp_in_context_1 (const char **stringptr, CORE_ADDR pc, volatile struct gdb_exception except; struct cleanup *old_chain, *inner_chain; const struct language_defn *lang = NULL; + struct parser_state ps; int subexp; lexptr = *stringptr; @@ -1233,47 +1213,48 @@ parse_exp_in_context_1 (const char **stringptr, CORE_ADDR pc, While we need CURRENT_LANGUAGE to be set to LANG (for lookup_symbol and others called from *.y) ensure CURRENT_LANGUAGE gets restored to the value matching SELECTED_FRAME as set by get_current_arch. */ - initialize_expout (10, lang, get_current_arch ()); + + initialize_expout (&ps, 10, lang, get_current_arch ()); inner_chain = make_cleanup_restore_current_language (); set_language (lang->la_language); TRY_CATCH (except, RETURN_MASK_ALL) { - if (lang->la_parser ()) + if (lang->la_parser (&ps)) lang->la_error (NULL); } if (except.reason < 0) { if (! parse_completion) { - xfree (expout); + xfree (ps.expout); throw_exception (except); } } - reallocate_expout (); + reallocate_expout (&ps); /* Convert expression from postfix form as generated by yacc parser, to a prefix form. */ if (expressiondebug) - dump_raw_expression (expout, gdb_stdlog, + dump_raw_expression (ps.expout, gdb_stdlog, "before conversion to prefix form"); - subexp = prefixify_expression (expout); + subexp = prefixify_expression (ps.expout); if (out_subexp) *out_subexp = subexp; - lang->la_post_parser (&expout, void_context_p); + lang->la_post_parser (&ps.expout, void_context_p); if (expressiondebug) - dump_prefix_expression (expout, gdb_stdlog); + dump_prefix_expression (ps.expout, gdb_stdlog); do_cleanups (inner_chain); discard_cleanups (old_chain); *stringptr = lexptr; - return expout; + return ps.expout; } /* Parse STRING as an expression, and complain if this fails @@ -1512,7 +1493,7 @@ push_type_int (int n) item. */ void -insert_type_address_space (char *string) +insert_type_address_space (struct parser_state *pstate, char *string) { union type_stack_elt element; int slot; @@ -1527,7 +1508,8 @@ insert_type_address_space (char *string) element.piece = tp_space_identifier; insert_into_type_stack (slot, element); - element.int_val = address_space_name_to_int (parse_gdbarch, string); + element.int_val = address_space_name_to_int (parse_gdbarch (pstate), + string); insert_into_type_stack (slot, element); } @@ -1909,6 +1891,21 @@ exp_uses_objfile (struct expression *exp, struct objfile *objfile) return exp_iterate (exp, exp_uses_objfile_iter, objfile); } +/* See definition in parser-defs.h. */ + +void +increase_expout_size (struct parser_state *ps, size_t lenelt) +{ + if ((ps->expout_ptr + lenelt) >= ps->expout_size) + { + ps->expout_size = max (ps->expout_size * 2, + ps->expout_ptr + lenelt + 10); + ps->expout = (struct expression *) + xrealloc (ps->expout, (sizeof (struct expression) + + EXP_ELEM_TO_BYTES (ps->expout_size))); + } +} + void _initialize_parse (void) { diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h index c3f2607..97c53b9 100644 --- a/gdb/parser-defs.h +++ b/gdb/parser-defs.h @@ -28,15 +28,29 @@ #include "expression.h" struct block; +struct language_defn; +struct internalvar; extern int parser_debug; -extern struct expression *expout; -extern int expout_size; -extern int expout_ptr; +#define parse_gdbarch(ps) ((ps)->expout->gdbarch) +#define parse_language(ps) ((ps)->expout->language_defn) -#define parse_gdbarch (expout->gdbarch) -#define parse_language (expout->language_defn) +struct parser_state +{ + /* The expression related to this parser state. */ + + struct expression *expout; + + /* The size of the expression above. */ + + size_t expout_size; + + /* The number of elements already in the expression. This is used + to know where to put new elements. */ + + size_t expout_ptr; +}; /* If this is nonzero, this block is used as the lexical context for symbol names. */ @@ -148,19 +162,21 @@ struct type_stack }; /* Helper function to initialize the expout, expout_size, expout_ptr - trio before it is used to store expression elements created during - the parsing of an expression. INITIAL_SIZE is the initial size of + trio inside PS before it is used to store expression elements created + during the parsing of an expression. INITIAL_SIZE is the initial size of the expout array. LANG is the language used to parse the expression. And GDBARCH is the gdbarch to use during parsing. */ -extern void initialize_expout (int, const struct language_defn *, - struct gdbarch *); +extern void initialize_expout (struct parser_state *ps, + size_t initial_size, + const struct language_defn *lang, + struct gdbarch *gdbarch); -/* Helper function that frees any unsed space in the expout array. - It is generally used when the parser has just been parsed and - created. */ +/* Helper function that reallocates the EXPOUT inside PS in order to + eliminate any unused space. It is generally used when the expression + has just been parsed and created. */ -extern void reallocate_expout (void); +extern void reallocate_expout (struct parser_state *ps); /* Reverse an expression from suffix form (in which it is constructed) to prefix form (in which we can conveniently print or execute it). @@ -171,35 +187,38 @@ extern void reallocate_expout (void); extern int prefixify_expression (struct expression *expr); -extern void write_exp_elt_opcode (enum exp_opcode); +extern void write_exp_elt_opcode (struct parser_state *, enum exp_opcode); -extern void write_exp_elt_sym (struct symbol *); +extern void write_exp_elt_sym (struct parser_state *, struct symbol *); -extern void write_exp_elt_longcst (LONGEST); +extern void write_exp_elt_longcst (struct parser_state *, LONGEST); -extern void write_exp_elt_dblcst (DOUBLEST); +extern void write_exp_elt_dblcst (struct parser_state *, DOUBLEST); -extern void write_exp_elt_decfloatcst (gdb_byte *); +extern void write_exp_elt_decfloatcst (struct parser_state *, gdb_byte *); -extern void write_exp_elt_type (struct type *); +extern void write_exp_elt_type (struct parser_state *, struct type *); -extern void write_exp_elt_intern (struct internalvar *); +extern void write_exp_elt_intern (struct parser_state *, struct internalvar *); -extern void write_exp_string (struct stoken); +extern void write_exp_string (struct parser_state *, struct stoken); -void write_exp_string_vector (int type, struct stoken_vector *vec); +void write_exp_string_vector (struct parser_state *, int type, + struct stoken_vector *vec); -extern void write_exp_bitstring (struct stoken); +extern void write_exp_bitstring (struct parser_state *, struct stoken); -extern void write_exp_elt_block (const struct block *); +extern void write_exp_elt_block (struct parser_state *, const struct block *); -extern void write_exp_elt_objfile (struct objfile *objfile); +extern void write_exp_elt_objfile (struct parser_state *, + struct objfile *objfile); -extern void write_exp_msymbol (struct bound_minimal_symbol); +extern void write_exp_msymbol (struct parser_state *, + struct bound_minimal_symbol); -extern void write_dollar_variable (struct stoken str); +extern void write_dollar_variable (struct parser_state *, struct stoken str); -extern void mark_struct_expression (void); +extern void mark_struct_expression (struct parser_state *); extern const char *find_template_name_end (const char *); @@ -215,7 +234,7 @@ extern void push_type (enum type_pieces); extern void push_type_int (int); -extern void insert_type_address_space (char *); +extern void insert_type_address_space (struct parser_state *, char *); extern enum type_pieces pop_type (void); @@ -375,5 +394,11 @@ extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile); extern void mark_completion_tag (enum type_code, const char *ptr, int length); +/* Reallocate the `expout' pointer inside PS so that it can accommodate + at least LENELT expression elements. This function does nothing if + there is enough room for the elements. */ + +extern void increase_expout_size (struct parser_state *ps, size_t lenelt); + #endif /* PARSER_DEFS_H */ diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c index 08c5342..5278a24 100644 --- a/gdb/ppc-linux-tdep.c +++ b/gdb/ppc-linux-tdep.c @@ -978,11 +978,11 @@ ppc_stap_parse_special_token (struct gdbarch *gdbarch, error (_("Invalid register name `%s' on expression `%s'."), regname, p->saved_arg); - write_exp_elt_opcode (OP_REGISTER); + write_exp_elt_opcode (&p->pstate, OP_REGISTER); str.ptr = regname; str.length = len; - write_exp_string (str); - write_exp_elt_opcode (OP_REGISTER); + write_exp_string (&p->pstate, str); + write_exp_elt_opcode (&p->pstate, OP_REGISTER); p->arg = s; } diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c index 986debd..dbe9f31 100644 --- a/gdb/stap-probe.c +++ b/gdb/stap-probe.c @@ -601,12 +601,12 @@ stap_parse_register_operand (struct stap_parse_info *p) p->arg = endp; /* Generating the expression for the displacement. */ - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type (gdbarch)->builtin_long); - write_exp_elt_longcst (displacement); - write_exp_elt_opcode (OP_LONG); + write_exp_elt_opcode (&p->pstate, OP_LONG); + write_exp_elt_type (&p->pstate, builtin_type (gdbarch)->builtin_long); + write_exp_elt_longcst (&p->pstate, displacement); + write_exp_elt_opcode (&p->pstate, OP_LONG); if (got_minus) - write_exp_elt_opcode (UNOP_NEG); + write_exp_elt_opcode (&p->pstate, UNOP_NEG); } /* Getting rid of register indirection prefix. */ @@ -660,23 +660,23 @@ stap_parse_register_operand (struct stap_parse_info *p) error (_("Invalid register name `%s' on expression `%s'."), regname, p->saved_arg); - write_exp_elt_opcode (OP_REGISTER); + write_exp_elt_opcode (&p->pstate, OP_REGISTER); str.ptr = regname; str.length = len; - write_exp_string (str); - write_exp_elt_opcode (OP_REGISTER); + write_exp_string (&p->pstate, str); + write_exp_elt_opcode (&p->pstate, OP_REGISTER); if (indirect_p) { if (disp_p) - write_exp_elt_opcode (BINOP_ADD); + write_exp_elt_opcode (&p->pstate, BINOP_ADD); /* Casting to the expected type. */ - write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type (lookup_pointer_type (p->arg_type)); - write_exp_elt_opcode (UNOP_CAST); + write_exp_elt_opcode (&p->pstate, UNOP_CAST); + write_exp_elt_type (&p->pstate, lookup_pointer_type (p->arg_type)); + write_exp_elt_opcode (&p->pstate, UNOP_CAST); - write_exp_elt_opcode (UNOP_IND); + write_exp_elt_opcode (&p->pstate, UNOP_IND); } /* Getting rid of the register name suffix. */ @@ -767,9 +767,9 @@ stap_parse_single_operand (struct stap_parse_info *p) ++p->arg; stap_parse_argument_conditionally (p); if (c == '-') - write_exp_elt_opcode (UNOP_NEG); + write_exp_elt_opcode (&p->pstate, UNOP_NEG); else if (c == '~') - write_exp_elt_opcode (UNOP_COMPLEMENT); + write_exp_elt_opcode (&p->pstate, UNOP_COMPLEMENT); } else { @@ -807,10 +807,11 @@ stap_parse_single_operand (struct stap_parse_info *p) const char *int_suffix; /* We are dealing with a numeric constant. */ - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type (gdbarch)->builtin_long); - write_exp_elt_longcst (number); - write_exp_elt_opcode (OP_LONG); + write_exp_elt_opcode (&p->pstate, OP_LONG); + write_exp_elt_type (&p->pstate, + builtin_type (gdbarch)->builtin_long); + write_exp_elt_longcst (&p->pstate, number); + write_exp_elt_opcode (&p->pstate, OP_LONG); p->arg = tmp; @@ -837,10 +838,10 @@ stap_parse_single_operand (struct stap_parse_info *p) number = strtol (p->arg, &endp, 10); p->arg = endp; - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type (gdbarch)->builtin_long); - write_exp_elt_longcst (number); - write_exp_elt_opcode (OP_LONG); + write_exp_elt_opcode (&p->pstate, OP_LONG); + write_exp_elt_type (&p->pstate, builtin_type (gdbarch)->builtin_long); + write_exp_elt_longcst (&p->pstate, number); + write_exp_elt_opcode (&p->pstate, OP_LONG); if (stap_check_integer_suffix (gdbarch, p->arg, &int_suffix)) p->arg += strlen (int_suffix); @@ -987,7 +988,7 @@ stap_parse_argument_1 (struct stap_parse_info *p, int has_lhs, stap_parse_argument_1 (p, 1, lookahead_prec); } - write_exp_elt_opcode (opcode); + write_exp_elt_opcode (&p->pstate, opcode); } } @@ -1028,8 +1029,8 @@ stap_parse_argument (const char **arg, struct type *atype, /* We need to initialize the expression buffer, in order to begin our parsing efforts. The language here does not matter, since we are using our own parser. */ - initialize_expout (10, current_language, gdbarch); - back_to = make_cleanup (free_current_contents, &expout); + initialize_expout (&p.pstate, 10, current_language, gdbarch); + back_to = make_cleanup (free_current_contents, &p.pstate.expout); p.saved_arg = *arg; p.arg = *arg; @@ -1044,16 +1045,17 @@ stap_parse_argument (const char **arg, struct type *atype, gdb_assert (p.inside_paren_p == 0); /* Casting the final expression to the appropriate type. */ - write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type (atype); - write_exp_elt_opcode (UNOP_CAST); + write_exp_elt_opcode (&p.pstate, UNOP_CAST); + write_exp_elt_type (&p.pstate, atype); + write_exp_elt_opcode (&p.pstate, UNOP_CAST); - reallocate_expout (); + reallocate_expout (&p.pstate); p.arg = skip_spaces_const (p.arg); *arg = p.arg; - return expout; + /* We can safely return EXPOUT here. */ + return p.pstate.expout; } /* Function which parses an argument string from PROBE, correctly splitting diff --git a/gdb/stap-probe.h b/gdb/stap-probe.h index 5b16201..6d3c12e 100644 --- a/gdb/stap-probe.h +++ b/gdb/stap-probe.h @@ -20,6 +20,9 @@ #if !defined (STAP_PROBE_H) #define STAP_PROBE_H 1 +/* For `struct parser_state'. */ +#include "parser-defs.h" + /* Structure which holds information about the parsing process of one probe's argument. */ @@ -28,6 +31,9 @@ struct stap_parse_info /* The probe's argument in a string format. */ const char *arg; + /* The parser state to be used when generating the expression. */ + struct parser_state pstate; + /* A pointer to the full chain of arguments. This is useful for printing error messages. The parser functions should not modify this argument directly; instead, they should use the ARG pointer above. */ diff --git a/gdb/utils.c b/gdb/utils.c index 364470c..a8a7cb3 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -466,6 +466,24 @@ make_cleanup_restore_current_language (void) (void *) (uintptr_t) saved_lang); } +/* Helper function for make_cleanup_clear_parser_state. */ + +static void +do_clear_parser_state (void *ptr) +{ + struct parser_state **p = (struct parser_state **) ptr; + + *p = NULL; +} + +/* Clean (i.e., set to NULL) the parser state variable P. */ + +struct cleanup * +make_cleanup_clear_parser_state (struct parser_state **p) +{ + return make_cleanup (do_clear_parser_state, (void *) p); +} + /* This function is useful for cleanups. Do diff --git a/gdb/utils.h b/gdb/utils.h index d6df2ee..33371ac 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -115,6 +115,10 @@ extern struct cleanup *make_cleanup_restore_current_language (void); extern struct cleanup *make_cleanup_htab_delete (htab_t htab); +struct parser_state; +extern struct cleanup *make_cleanup_clear_parser_state + (struct parser_state **p); + extern void free_current_contents (void *); extern void init_page_info (void); |