[v3,091/206] Introduce objc_nsstring_operation

Message ID 20210220201609.838264-92-tom@tromey.com
State New
Headers show
Series
  • Refactor expressions
Related show

Commit Message

Tom Tromey Feb. 20, 2021, 8:14 p.m.
This adds class objc_nsstring_operation, which implements
OP_OBJC_NSSTRING.

gdb/ChangeLog
2021-02-20  Tom Tromey  <tom@tromey.com>

	* eval.c: Include c-exp.h.
	* c-exp.h (class objc_nsstring_operation): New.
---
 gdb/ChangeLog |  5 +++++
 gdb/c-exp.h   | 22 ++++++++++++++++++++++
 gdb/eval.c    |  1 +
 3 files changed, 28 insertions(+)

-- 
2.26.2

Patch

diff --git a/gdb/c-exp.h b/gdb/c-exp.h
index 5558a773e98..a7b11b5a25d 100644
--- a/gdb/c-exp.h
+++ b/gdb/c-exp.h
@@ -21,6 +21,7 @@ 
 #define C_EXP_H
 
 #include "expop.h"
+#include "objc-lang.h"
 
 namespace expr
 {
@@ -41,6 +42,27 @@  class c_string_operation
   { return OP_STRING; }
 };
 
+class objc_nsstring_operation
+  : public tuple_holding_operation<std::string>
+{
+public:
+
+  using tuple_holding_operation::tuple_holding_operation;
+
+  value *evaluate (struct type *expect_type,
+		   struct expression *exp,
+		   enum noside noside) override
+  {
+    if (noside == EVAL_SKIP)
+      return eval_skip_value (exp);
+    const std::string &str = std::get<0> (m_storage);
+    return value_nsstring (exp->gdbarch, str.c_str (), str.size () + 1);
+  }
+
+  enum exp_opcode opcode () const override
+  { return OP_OBJC_NSSTRING; }
+};
+
 }/* namespace expr */
 
 #endif /* C_EXP_H */
diff --git a/gdb/eval.c b/gdb/eval.c
index 0d7af96d21a..7960946c984 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -41,6 +41,7 @@ 
 #include "typeprint.h"
 #include <ctype.h>
 #include "expop.h"
+#include "c-exp.h"
 
 /* Prototypes for local functions.  */