From: Tom Tromey Date: Wed, 16 Dec 2020 01:14:42 +0000 (-0700) Subject: Introduce expression::first_opcode X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2adab65cc07f07a581d57b05dfbc100952fab748;p=binutils-gdb.git Introduce expression::first_opcode This adds a new helper method, expression::first_opcode, that extracts the outermost opcode of an expression. This simplifies some patches in the expression rewrite series. Note that this patch requires the earlier patch to avoid manual dissection of OP_TYPE operations. 2020-12-15 Tom Tromey * varobj.c (varobj_create): Use first_opcode. * value.c (init_if_undefined_command): Use first_opcode. * typeprint.c (whatis_exp): Use first_opcode. * tracepoint.c (validate_actionline): Use first_opcode. (encode_actions_1): Use first_opcode. * stack.c (return_command): Use first_opcode. * expression.h (struct expression) : New method. * eval.c (parse_and_eval_type): Use first_opcode. * dtrace-probe.c (dtrace_process_dof_probe): Use first_opcode. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 464054c83cf..58075c921bb 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,15 @@ +2020-12-15 Tom Tromey + + * varobj.c (varobj_create): Use first_opcode. + * value.c (init_if_undefined_command): Use first_opcode. + * typeprint.c (whatis_exp): Use first_opcode. + * tracepoint.c (validate_actionline): Use first_opcode. + (encode_actions_1): Use first_opcode. + * stack.c (return_command): Use first_opcode. + * expression.h (struct expression) : New method. + * eval.c (parse_and_eval_type): Use first_opcode. + * dtrace-probe.c (dtrace_process_dof_probe): Use first_opcode. + 2020-12-15 Tom Tromey * f-lang.c (evaluate_subexp_f): Update. diff --git a/gdb/dtrace-probe.c b/gdb/dtrace-probe.c index 3ea047fce80..b709390039f 100644 --- a/gdb/dtrace-probe.c +++ b/gdb/dtrace-probe.c @@ -492,7 +492,7 @@ dtrace_process_dof_probe (struct objfile *objfile, { } - if (expr != NULL && expr.get ()->elts[0].opcode == OP_TYPE) + if (expr != NULL && expr->first_opcode () == OP_TYPE) type = value_type (evaluate_type (expr.get ())); args.emplace_back (type, std::move (type_str), std::move (expr)); diff --git a/gdb/eval.c b/gdb/eval.c index 6066a320414..2d088c8818d 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -3104,7 +3104,7 @@ parse_and_eval_type (const char *p, int length) tmp[length + 2] = '0'; tmp[length + 3] = '\0'; expression_up expr = parse_expression (tmp); - if (expr->elts[0].opcode != UNOP_CAST) + if (expr->first_opcode () != UNOP_CAST) error (_("Internal error in eval_type.")); return expr->elts[1].type; } diff --git a/gdb/expression.h b/gdb/expression.h index 0c4dc7bae17..c07111c316f 100644 --- a/gdb/expression.h +++ b/gdb/expression.h @@ -91,6 +91,13 @@ struct expression void resize (size_t); + /* Return the opcode for the outermost sub-expression of this + expression. */ + enum exp_opcode first_opcode () const + { + return elts[0].opcode; + } + /* Language it was entered in. */ const struct language_defn *language_defn; /* Architecture it was parsed in. */ diff --git a/gdb/stack.c b/gdb/stack.c index 7618f72319a..943b3db0875 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -2770,8 +2770,8 @@ return_command (const char *retval_exp, int from_tty) return_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun)); if (return_type == NULL) { - if (retval_expr->elts[0].opcode != UNOP_CAST - && retval_expr->elts[0].opcode != UNOP_CAST_TYPE) + if (retval_expr->first_opcode () != UNOP_CAST + && retval_expr->first_opcode () != UNOP_CAST_TYPE) error (_("Return value type not available for selected " "stack frame.\n" "Please use an explicit cast of the value to return.")); diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index c2f923b8fa2..cb2b3b65c33 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -687,7 +687,7 @@ validate_actionline (const char *line, struct breakpoint *b) expression_up exp = parse_exp_1 (&p, loc->address, block_for_pc (loc->address), 1); - if (exp->elts[0].opcode == OP_VAR_VALUE) + if (exp->first_opcode () == OP_VAR_VALUE) { if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_CONST) { @@ -1383,7 +1383,7 @@ encode_actions_1 (struct command_line *action, block_for_pc (tloc->address), 1); - switch (exp->elts[0].opcode) + switch (exp->first_opcode ()) { case OP_REGISTER: { diff --git a/gdb/typeprint.c b/gdb/typeprint.c index 2f671d9c80f..49877710fa4 100644 --- a/gdb/typeprint.c +++ b/gdb/typeprint.c @@ -493,7 +493,7 @@ whatis_exp (const char *exp, int show) val = evaluate_type (expr.get ()); type = value_type (val); - if (show == -1 && expr->elts[0].opcode == OP_TYPE) + if (show == -1 && expr->first_opcode () == OP_TYPE) { /* The user expression names a type directly. */ diff --git a/gdb/value.c b/gdb/value.c index eba5bce6d2e..9584fc13c27 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1981,7 +1981,7 @@ init_if_undefined_command (const char* args, int from_tty) /* Validate the expression. Was the expression an assignment? Or even an expression at all? */ - if (expr->nelts == 0 || expr->elts[0].opcode != BINOP_ASSIGN) + if (expr->nelts == 0 || expr->first_opcode () != BINOP_ASSIGN) error (_("Init-if-undefined requires an assignment expression.")); /* Extract the variable from the parsed expression. diff --git a/gdb/varobj.c b/gdb/varobj.c index 19a90c71196..6a95e1ec0c2 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -311,9 +311,10 @@ varobj_create (const char *objname, } /* Don't allow variables to be created for types. */ - if (var->root->exp->elts[0].opcode == OP_TYPE - || var->root->exp->elts[0].opcode == OP_TYPEOF - || var->root->exp->elts[0].opcode == OP_DECLTYPE) + enum exp_opcode opcode = var->root->exp->first_opcode (); + if (opcode == OP_TYPE + || opcode == OP_TYPEOF + || opcode == OP_DECLTYPE) { fprintf_unfiltered (gdb_stderr, "Attempt to use a type name" " as an expression.\n");