[2/3] Remove evaluate_expression

Message ID 20230428-minor-expr-cleanuups-v1-2-0a634e8d5c25@adacore.com
State New
Headers
Series Minor expression cleanups |

Commit Message

Tom Tromey April 28, 2023, 4:02 p.m. UTC
  evaluate_expression is just a little wrapper for a method on
expression.  Removing it also removes a lot of ugly (IMO) calls to
get().
---
 gdb/ada-lang.c        |  4 ++--
 gdb/arc-tdep.c        |  2 +-
 gdb/breakpoint.c      |  2 +-
 gdb/cli/cli-script.c  |  4 ++--
 gdb/darwin-nat-info.c |  2 +-
 gdb/dtrace-probe.c    |  2 +-
 gdb/eval.c            | 16 ++++------------
 gdb/expression.h      |  3 ++-
 gdb/linux-thread-db.c |  2 +-
 gdb/mi/mi-main.c      |  4 ++--
 gdb/objc-lang.c       |  4 +---
 gdb/printcmd.c        | 12 ++++++------
 gdb/stack.c           |  2 +-
 gdb/stap-probe.c      |  2 +-
 gdb/tracepoint.c      |  2 +-
 gdb/value.c           |  2 +-
 gdb/value.h           |  9 ---------
 gdb/varobj.c          | 12 ++++++------
 18 files changed, 34 insertions(+), 52 deletions(-)
  

Patch

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 3a9f554ce4c..50d5c6f9697 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -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)
     {
diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
index bbf4846a8f8..0b541c6335a 100644
--- a/gdb/arc-tdep.c
+++ b/gdb/arc-tdep.c
@@ -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 ();
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 46287da5f87..20e016e8cb3 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -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.  */
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 294a5f18fe6..b96dd74330c 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -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.  */
diff --git a/gdb/darwin-nat-info.c b/gdb/darwin-nat-info.c
index 9e562074cf8..d5f633bccae 100644
--- a/gdb/darwin-nat-info.c
+++ b/gdb/darwin-nat-info.c
@@ -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);
diff --git a/gdb/dtrace-probe.c b/gdb/dtrace-probe.c
index 70fa1a9413e..dad15df5b99 100644
--- a/gdb/dtrace-probe.c
+++ b/gdb/dtrace-probe.c
@@ -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.  */
diff --git a/gdb/eval.c b/gdb/eval.c
index 6b362f46424..a8d5c78e09e 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -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.  */
 
diff --git a/gdb/expression.h b/gdb/expression.h
index 77949ddaf4b..5bfb051a393 100644
--- a/gdb/expression.h
+++ b/gdb/expression.h
@@ -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;
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index 0e190f94266..71a81aa0cb9 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -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)
 	{
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 0013e5dfafd..683d36d93d5 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -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)
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 4a9dee44dd7..ccbe7c19729 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -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.  */
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index dd92e31d31b..693d1a8a93c 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -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)
diff --git a/gdb/stack.c b/gdb/stack.c
index 03e903d901b..b1b25aa1c7e 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -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.  */
diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
index c7ad35db06f..756e90d2192 100644
--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -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.
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index c8bac7a0122..ffda4a6439e 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -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 *>
diff --git a/gdb/value.c b/gdb/value.c
index eab1933b256..01c30eb3f93 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -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 ();
 }
 
 
diff --git a/gdb/value.h b/gdb/value.h
index e13f92c397b..f6092aba5a4 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -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,
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 5a5e55c2d82..75b4d44b109 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -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)
 	{