Remove eval_op_scope

Message ID 20250310114357.2372035-1-tom@tromey.com
State New
Headers
Series Remove eval_op_scope |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply

Commit Message

Tom Tromey March 10, 2025, 11:43 a.m. UTC
  eval_op_scope is very similar to
scope_operation::evaluate_for_address.  This patch combines the two
into a single method of scope_operation.

Regression tested on x86-64 Fedora 40.
---
 gdb/eval.c  | 32 ++++++++++----------------------
 gdb/expop.h | 18 ++++++++++--------
 2 files changed, 20 insertions(+), 30 deletions(-)
  

Comments

Simon Marchi March 10, 2025, 3:48 p.m. UTC | #1
On 3/10/25 7:43 AM, Tom Tromey wrote:
> eval_op_scope is very similar to
> scope_operation::evaluate_for_address.  This patch combines the two
> into a single method of scope_operation.
> 
> Regression tested on x86-64 Fedora 40.

Looks good, thanks.

Simon
  
Simon Marchi March 10, 2025, 3:52 p.m. UTC | #2
On 3/10/25 11:48 AM, Simon Marchi wrote:
> On 3/10/25 7:43 AM, Tom Tromey wrote:
>> eval_op_scope is very similar to
>> scope_operation::evaluate_for_address.  This patch combines the two
>> into a single method of scope_operation.
>>
>> Regression tested on x86-64 Fedora 40.
> 
> Looks good, thanks.
> 
> Simon

Forgot the tag:

Approved-By: Simon Marchi <simon.marchi@efficios.com>
  

Patch

diff --git a/gdb/eval.c b/gdb/eval.c
index 457a4362289..63961cc4349 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1071,20 +1071,6 @@  is_integral_or_integral_reference (struct type *type)
 	  && is_integral_type (type->target_type ()));
 }
 
-/* Helper function that implements the body of OP_SCOPE.  */
-
-struct value *
-eval_op_scope (struct type *expect_type, struct expression *exp,
-	       enum noside noside,
-	       struct type *type, const char *string)
-{
-  struct value *arg1 = value_aggregate_elt (type, string, expect_type,
-					    0, noside);
-  if (arg1 == NULL)
-    error (_("There is no field named %s"), string);
-  return arg1;
-}
-
 /* Helper function that implements the body of OP_VAR_ENTRY_VALUE.  */
 
 struct value *
@@ -2615,14 +2601,16 @@  operation::evaluate_for_address (struct expression *exp, enum noside noside)
 }
 
 value *
-scope_operation::evaluate_for_address (struct expression *exp,
-				       enum noside noside)
-{
-  value *x = value_aggregate_elt (std::get<0> (m_storage),
-				  std::get<1> (m_storage).c_str (),
-				  NULL, 1, noside);
-  if (x == NULL)
-    error (_("There is no field named %s"), std::get<1> (m_storage).c_str ());
+scope_operation::evaluate_internal (struct type *expect_type,
+				    struct expression *exp,
+				    enum noside noside,
+				    bool want_address)
+{
+  const char *string = std::get<1> (m_storage).c_str ();
+  value *x = value_aggregate_elt (std::get<0> (m_storage), string,
+				  expect_type, want_address, noside);
+  if (x == nullptr)
+    error (_("There is no field named %s"), string);
   return x;
 }
 
diff --git a/gdb/expop.h b/gdb/expop.h
index a7b2c1bf627..580a71e9429 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -45,10 +45,6 @@  extern void gen_expr_unop (struct expression *exp,
 			   expr::operation *lhs,
 			   struct agent_expr *ax, struct axs_value *value);
 
-extern struct value *eval_op_scope (struct type *expect_type,
-				    struct expression *exp,
-				    enum noside noside,
-				    struct type *type, const char *string);
 extern struct value *eval_op_var_msym_value (struct type *expect_type,
 					     struct expression *exp,
 					     enum noside noside,
@@ -600,13 +596,14 @@  class scope_operation
 		   struct expression *exp,
 		   enum noside noside) override
   {
-    return eval_op_scope (expect_type, exp, noside,
-			  std::get<0> (m_storage),
-			  std::get<1> (m_storage).c_str ());
+    return evaluate_internal (expect_type, exp, noside, false);
   }
 
   value *evaluate_for_address (struct expression *exp,
-			       enum noside noside) override;
+			       enum noside noside) override
+  {
+    return evaluate_internal (nullptr, exp, noside, true);
+  }
 
   value *evaluate_funcall (struct type *expect_type,
 			   struct expression *exp,
@@ -623,6 +620,11 @@  class scope_operation
 		       struct axs_value *value,
 		       struct type *cast_type)
     override;
+
+private:
+
+  value *evaluate_internal (struct type *expect_type, struct expression *exp,
+			    enum noside noside, bool want_address);
 };
 
 /* Compute the value of a variable.  */