Remove evaluate_expression

evaluate_expression is just a little wrapper for a method on
expression.  Removing it also removes a lot of ugly (IMO) calls to
get().
This commit is contained in:
Tom Tromey
2023-04-28 07:24:59 -06:00
parent b785bb6d18
commit 43048e46db
18 changed files with 34 additions and 52 deletions

View File

@@ -4339,7 +4339,7 @@ ada_read_renaming_var_value (struct symbol *renaming_sym,
sym_name = renaming_sym->linkage_name ();
expression_up expr = parse_exp_1 (&sym_name, 0, block, 0);
return evaluate_expression (expr.get ());
return expr->evaluate ();
}
@@ -12318,7 +12318,7 @@ should_stop_exception (const struct bp_location *bl)
try
{
scoped_value_mark mark;
stop = value_true (evaluate_expression (ada_loc->excep_cond_expr.get ()));
stop = value_true (ada_loc->excep_cond_expr->evaluate ());
}
catch (const gdb_exception_error &ex)
{

View File

@@ -2434,7 +2434,7 @@ dump_arc_instruction_command (const char *args, int from_tty)
{
struct value *val;
if (args != NULL && strlen (args) > 0)
val = evaluate_expression (parse_expression (args).get ());
val = parse_expression (args)->evaluate ();
else
val = access_value_history (0);
val->record_latest ();

View File

@@ -4984,7 +4984,7 @@ static bool
breakpoint_cond_eval (expression *exp)
{
scoped_value_mark mark;
return value_true (evaluate_expression (exp));
return value_true (exp->evaluate ());
}
/* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */

View File

@@ -567,7 +567,7 @@ execute_control_command_1 (struct command_line *cmd, int from_tty)
/* Evaluate the expression. */
{
scoped_value_mark mark;
value *val = evaluate_expression (expr.get ());
value *val = expr->evaluate ();
cond_result = value_true (val);
}
@@ -622,7 +622,7 @@ execute_control_command_1 (struct command_line *cmd, int from_tty)
/* Evaluate the conditional. */
{
scoped_value_mark mark;
value *val = evaluate_expression (expr.get ());
value *val = expr->evaluate ();
/* Choose which arm to take commands from based on the value
of the conditional expression. */

View File

@@ -723,7 +723,7 @@ info_mach_region_command (const char *exp, int from_tty)
struct inferior *inf;
expression_up expr = parse_expression (exp);
val = evaluate_expression (expr.get ());
val = expr->evaluate ();
if (TYPE_IS_REFERENCE (val->type ()))
{
val = value_ind (val);

View File

@@ -714,7 +714,7 @@ dtrace_probe::evaluate_argument (unsigned n,
struct dtrace_probe_arg *arg;
arg = this->get_arg_by_number (n, gdbarch);
return evaluate_expression (arg->expr.get (), arg->type);
return arg->expr->evaluate (arg->type);
}
/* Implementation of the compile_to_ax method. */

View File

@@ -53,7 +53,7 @@ parse_and_eval_address (const char *exp)
{
expression_up expr = parse_expression (exp);
return value_as_address (evaluate_expression (expr.get ()));
return value_as_address (expr->evaluate ());
}
/* Like parse_and_eval_address, but treats the value of the expression
@@ -63,7 +63,7 @@ parse_and_eval_long (const char *exp)
{
expression_up expr = parse_expression (exp);
return value_as_long (evaluate_expression (expr.get ()));
return value_as_long (expr->evaluate ());
}
struct value *
@@ -71,7 +71,7 @@ parse_and_eval (const char *exp)
{
expression_up expr = parse_expression (exp);
return evaluate_expression (expr.get ());
return expr->evaluate ();
}
/* Parse up to a comma (or to a closeparen)
@@ -83,7 +83,7 @@ parse_to_comma_and_eval (const char **expp)
{
expression_up expr = parse_exp_1 (expp, 0, nullptr, 1);
return evaluate_expression (expr.get ());
return expr->evaluate ();
}
@@ -116,14 +116,6 @@ expression::evaluate (struct type *expect_type, enum noside noside)
return retval;
}
/* See value.h. */
struct value *
evaluate_expression (struct expression *exp, struct type *expect_type)
{
return exp->evaluate (expect_type, EVAL_NORMAL);
}
/* Evaluate an expression, avoiding all memory references
and getting a value whose type alone is correct. */

View File

@@ -222,7 +222,8 @@ struct expression
/* Evaluate the expression. EXPECT_TYPE is the context type of the
expression; normally this should be nullptr. NOSIDE controls how
evaluation is performed. */
struct value *evaluate (struct type *expect_type, enum noside noside);
struct value *evaluate (struct type *expect_type = nullptr,
enum noside noside = EVAL_NORMAL);
/* Language it was entered in. */
const struct language_defn *language_defn;

View File

@@ -694,7 +694,7 @@ check_thread_db_callback (const td_thrhandle_t *th, void *arg)
switch_to_thread (thread_info);
expression_up expr = parse_expression ("(int) errno");
struct value *val = evaluate_expression (expr.get ());
struct value *val = expr->evaluate ();
if (tdb_testinfo->log_progress)
{

View File

@@ -1189,7 +1189,7 @@ mi_cmd_data_evaluate_expression (const char *command, char **argv, int argc)
expression_up expr = parse_expression (argv[0]);
val = evaluate_expression (expr.get ());
val = expr->evaluate ();
string_file stb;
@@ -2468,7 +2468,7 @@ print_variable_or_computed (const char *expression, enum print_values values)
if (values == PRINT_SIMPLE_VALUES)
val = evaluate_type (expr.get ());
else
val = evaluate_expression (expr.get ());
val = expr->evaluate ();
gdb::optional<ui_out_emit_tuple> tuple_emitter;
if (values != PRINT_NO_VALUES)

View File

@@ -1164,9 +1164,7 @@ print_object_command (const char *args, int from_tty)
{
expression_up expr = parse_expression (args);
object
= evaluate_expression (expr.get (),
builtin_type (expr->gdbarch)->builtin_data_ptr);
object = expr->evaluate (builtin_type (expr->gdbarch)->builtin_data_ptr);
}
/* Validate the address for sanity. */

View File

@@ -1316,7 +1316,7 @@ process_print_command_args (const char *args, value_print_options *print_opts,
/* VOIDPRINT is true to indicate that we do want to print a void
value, so invert it for parse_expression. */
expression_up expr = parse_expression (exp, nullptr, !voidprint);
return evaluate_expression (expr.get ());
return expr->evaluate ();
}
return access_value_history (0);
@@ -1495,7 +1495,7 @@ output_command (const char *exp, int from_tty)
expression_up expr = parse_expression (exp);
val = evaluate_expression (expr.get ());
val = expr->evaluate ();
annotate_value_begin (val->type ());
@@ -1534,7 +1534,7 @@ set_command (const char *exp, int from_tty)
(_("Expression is not an assignment (and might have no effect)"));
}
evaluate_expression (expr.get ());
expr->evaluate ();
}
static void
@@ -1900,7 +1900,7 @@ x_command (const char *exp, int from_tty)
command's definition. */
if (from_tty)
set_repeat_arguments ("");
val = evaluate_expression (expr.get ());
val = expr->evaluate ();
if (TYPE_IS_REFERENCE (val->type ()))
val = coerce_ref (val);
/* In rvalue contexts, such as this, functions are coerced into
@@ -2188,7 +2188,7 @@ do_one_display (struct display *d)
struct value *val;
CORE_ADDR addr;
val = evaluate_expression (d->exp.get ());
val = d->exp->evaluate ();
addr = value_as_address (val);
if (d->format.format == 'i')
addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr);
@@ -2226,7 +2226,7 @@ do_one_display (struct display *d)
{
struct value *val;
val = evaluate_expression (d->exp.get ());
val = d->exp->evaluate ();
print_formatted (val, d->format.size, &opts, gdb_stdout);
}
catch (const gdb_exception_error &ex)

View File

@@ -2722,7 +2722,7 @@ return_command (const char *retval_exp, int from_tty)
/* Compute the return value. Should the computation fail, this
call throws an error. */
return_value = evaluate_expression (retval_expr.get ());
return_value = retval_expr->evaluate ();
/* Cast return value to the return type of the function. Should
the cast fail, this call throws an error. */

View File

@@ -1444,7 +1444,7 @@ stap_probe::evaluate_argument (unsigned n, frame_info_ptr frame)
struct gdbarch *gdbarch = get_frame_arch (frame);
arg = this->get_arg_by_number (n, gdbarch);
return evaluate_expression (arg->aexpr.get (), arg->atype);
return arg->aexpr->evaluate (arg->atype);
}
/* Compile the probe's argument N (indexed from 0) to agent expression.

View File

@@ -1375,7 +1375,7 @@ encode_actions_1 (struct command_line *action,
case UNOP_MEMVAL:
{
/* Safe because we know it's a simple expression. */
tempval = evaluate_expression (exp.get ());
tempval = exp->evaluate ();
addr = tempval->address ();
expr::unop_memval_operation *memop
= (gdb::checked_static_cast<expr::unop_memval_operation *>

View File

@@ -1896,7 +1896,7 @@ init_if_undefined_command (const char* args, int from_tty)
/* Only evaluate the expression if the lvalue is void.
This may still fail if the expression is invalid. */
if (intvar->kind == INTERNALVAR_VOID)
evaluate_expression (expr.get ());
expr->evaluate ();
}

View File

@@ -1299,15 +1299,6 @@ extern int using_struct_return (struct gdbarch *gdbarch,
struct value *function,
struct type *value_type);
/* Evaluate the expression EXP. If set, EXPECT_TYPE is passed to the
outermost operation's evaluation. This is ignored by most
operations, but may be used, e.g., to determine the type of an
otherwise untyped symbol. The caller should not assume that the
returned value has this type. */
extern struct value *evaluate_expression (struct expression *exp,
struct type *expect_type = nullptr);
extern struct value *evaluate_type (struct expression *exp);
extern value *evaluate_var_value (enum noside noside, const block *blk,

View File

@@ -364,12 +364,12 @@ varobj_create (const char *objname,
select_frame (fi);
}
/* We definitely need to catch errors here.
If evaluate_expression succeeds we got the value we wanted.
But if it fails, we still go on with a call to evaluate_type(). */
/* We definitely need to catch errors here. If evaluation of
the expression succeeds, we got the value we wanted. But if
it fails, we still go on with a call to evaluate_type(). */
try
{
value = evaluate_expression (var->root->exp.get ());
value = var->root->exp->evaluate ();
}
catch (const gdb_exception_error &except)
{
@@ -979,7 +979,7 @@ varobj_set_value (struct varobj *var, const char *expression)
expression_up exp = parse_exp_1 (&s, 0, 0, 0);
try
{
value = evaluate_expression (exp.get ());
value = exp->evaluate ();
}
catch (const gdb_exception_error &except)
@@ -1995,7 +1995,7 @@ value_of_root_1 (struct varobj **var_handle)
expression fails we want to just return NULL. */
try
{
new_val = evaluate_expression (var->root->exp.get ());
new_val = var->root->exp->evaluate ();
}
catch (const gdb_exception_error &except)
{