]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Remove a couple Objective-C expression helpers
authorTom Tromey <tom@tromey.com>
Sun, 16 Nov 2025 21:01:42 +0000 (14:01 -0700)
committerTom Tromey <tom@tromey.com>
Tue, 2 Dec 2025 16:22:45 +0000 (09:22 -0700)
The Objective-C expression code has a couple of helper functions with
just a single caller.  This patch unifies them with the appropriate
evaluate method.

gdb/c-exp.h
gdb/eval.c
gdb/objc-lang.c
gdb/objc-lang.h

index f15185f4da093f5d8204f1f660efc443cab620d3..8dbbce0f406d05919dc10b2596c20c7d7e642634 100644 (file)
 #include "expop.h"
 #include "objc-lang.h"
 
-extern struct value *eval_op_objc_selector (struct type *expect_type,
-                                           struct expression *exp,
-                                           enum noside noside,
-                                           const char *sel);
 extern struct value *opencl_value_cast (struct type *type, struct value *arg);
 extern struct value *eval_opencl_assign (struct type *expect_type,
                                         struct expression *exp,
@@ -72,11 +68,7 @@ public:
 
   value *evaluate (struct type *expect_type,
                   struct expression *exp,
-                  enum noside noside) override
-  {
-    const std::string &str = std::get<0> (m_storage);
-    return value_nsstring (exp->gdbarch, str.c_str (), str.size () + 1);
-  }
+                  enum noside noside) override;
 
   enum exp_opcode opcode () const override
   { return OP_OBJC_NSSTRING; }
@@ -91,11 +83,7 @@ public:
 
   value *evaluate (struct type *expect_type,
                   struct expression *exp,
-                  enum noside noside) override
-  {
-    return eval_op_objc_selector (expect_type, exp, noside,
-                                 std::get<0> (m_storage).c_str ());
-  }
+                  enum noside noside) override;
 
   enum exp_opcode opcode () const override
   { return OP_OBJC_SELECTOR; }
index 9aa9665e9599d84d7930d40e6a5e17cb71189abf..530d5871a9c02e3f2516ef9f4ed928ce7a8813d3 100644 (file)
@@ -1185,20 +1185,19 @@ ternop_slice_operation::evaluate (struct type *expect_type,
   return value_slice (array, lowbound, upperbound - lowbound + 1);
 }
 
-} /* namespace expr */
-
-/* Helper function that implements the body of OP_OBJC_SELECTOR.  */
-
 struct value *
-eval_op_objc_selector (struct type *expect_type, struct expression *exp,
-                      enum noside noside,
-                      const char *sel)
+objc_selector_operation::evaluate (struct type *expect_type,
+                                  struct expression *exp,
+                                  enum noside noside)
 {
+  const char *sel = std::get<0> (m_storage).c_str ();
   struct type *selector_type = builtin_type (exp->gdbarch)->builtin_data_ptr;
   return value_from_longest (selector_type,
                             lookup_child_selector (exp->gdbarch, sel));
 }
 
+} /* namespace expr */
+
 /* A helper function for STRUCTOP_STRUCT.  */
 
 struct value *
index b307a0022b5d68b16bdc49f0e5b26664118e2373..a6abcd600897e282d10a7bc38a0565da38e6d828 100644 (file)
@@ -151,9 +151,17 @@ lookup_child_selector (struct gdbarch *gdbarch, const char *selname)
   return value_as_long (call_function_by_hand (function, NULL, selstring));
 }
 
+namespace expr
+{
+
 struct value *
-value_nsstring (struct gdbarch *gdbarch, const char *ptr, int len)
+objc_nsstring_operation::evaluate (struct type *expect_type,
+                                  struct expression *exp,
+                                  enum noside noside)
 {
+  const std::string &str = std::get<0> (m_storage);
+  struct gdbarch *gdbarch = exp->gdbarch;
+
   struct type *char_type = builtin_type (gdbarch)->builtin_char;
   struct value *stringValue[3];
   struct value *function, *nsstringValue;
@@ -163,8 +171,8 @@ value_nsstring (struct gdbarch *gdbarch, const char *ptr, int len)
   if (!target_has_execution ())
     return 0;          /* Can't call into inferior to create NSString.  */
 
-  stringValue[2] = value_string(ptr, len, char_type);
-  stringValue[2] = value_coerce_array(stringValue[2]);
+  stringValue[2] = value_string (str.c_str (), str.size () + 1, char_type);
+  stringValue[2] = value_coerce_array (stringValue[2]);
   /* _NSNewStringFromCString replaces "istr" after Lantern2A.  */
   if (lookup_minimal_symbol (current_program_space,
                             "_NSNewStringFromCString").minsym != nullptr)
@@ -207,6 +215,8 @@ value_nsstring (struct gdbarch *gdbarch, const char *ptr, int len)
   return nsstringValue;
 }
 
+} /* namespace expr */
+
 /* Class representing the Objective-C language.  */
 
 class objc_language : public language_defn
index d6a7509f21a92e3e2a0d506b3a1adec69d30be33..a472556d019acd80ba097750a218f75ed3bccee4 100644 (file)
@@ -36,9 +36,6 @@ extern int find_objc_msgcall (CORE_ADDR pc, CORE_ADDR *new_pc);
 extern const char *find_imps (const char *method,
                              std::vector<const char *> *symbol_names);
 
-extern struct value *value_nsstring (struct gdbarch *gdbarch,
-                                    const char *ptr, int len);
-
 /* for parsing Objective C */
 extern void start_msglist (void);
 extern void add_msglist (struct stoken *str, int addcolon);