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 <tom@tromey.com> * 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) <first_opcode>: New method. * eval.c (parse_and_eval_type): Use first_opcode. * dtrace-probe.c (dtrace_process_dof_probe): Use first_opcode.
This commit is contained in:
parent
1ab8280d7d
commit
2adab65cc0
9 changed files with 31 additions and 11 deletions
|
@ -1,3 +1,15 @@
|
|||
2020-12-15 Tom Tromey <tom@tromey.com>
|
||||
|
||||
* 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) <first_opcode>: 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 <tom@tromey.com>
|
||||
|
||||
* f-lang.c (evaluate_subexp_f): Update.
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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."));
|
||||
|
|
|
@ -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:
|
||||
{
|
||||
|
|
|
@ -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. */
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Add table
Reference in a new issue