[095/203] Introduce structop_member_operation and structop_mptr_operation

Message ID 20210101214723.1784144-96-tom@tromey.com
State Superseded
Headers show
Series
  • Refactor expressions
Related show

Commit Message

Tom Tromey Jan. 1, 2021, 9:45 p.m.
This adds class structop_member_operation and structop_mptr_operation,
which implement STRUCTOP_MEMBER and STRUCTOP_MPTR.

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

	* expop.h (class structop_member_operation)
	(class structop_mptr_operation): New.
	* eval.c (eval_op_member): No longer static.
---
 gdb/ChangeLog |  6 ++++++
 gdb/eval.c    |  2 +-
 gdb/expop.h   | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+), 1 deletion(-)

-- 
2.26.2

Patch

diff --git a/gdb/eval.c b/gdb/eval.c
index 156ef8530ce..3aa362db66c 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1402,7 +1402,7 @@  eval_op_structop_ptr (struct type *expect_type, struct expression *exp,
 
 /* A helper function for STRUCTOP_MEMBER.  */
 
-static struct value *
+struct value *
 eval_op_member (struct type *expect_type, struct expression *exp,
 		enum noside noside,
 		struct value *arg1, struct value *arg2)
diff --git a/gdb/expop.h b/gdb/expop.h
index 85d2eaf063a..bfb8f1db6f8 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -79,6 +79,10 @@  extern struct value *eval_op_structop_ptr (struct type *expect_type,
 					   enum noside noside,
 					   struct value *arg1,
 					   const char *string);
+extern struct value *eval_op_member (struct type *expect_type,
+				     struct expression *exp,
+				     enum noside noside,
+				     struct value *arg1, struct value *arg2);
 
 namespace expr
 {
@@ -876,6 +880,50 @@  class structop_ptr_operation
   }
 };
 
+class structop_member_operation
+  : public tuple_holding_operation<operation_up, operation_up>
+{
+public:
+
+  using tuple_holding_operation::tuple_holding_operation;
+
+  value *evaluate (struct type *expect_type,
+		   struct expression *exp,
+		   enum noside noside) override
+  {
+    value *lhs
+      = std::get<0> (m_storage)->evaluate_for_address (exp, noside);
+    value *rhs
+      = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+    return eval_op_member (expect_type, exp, noside, lhs, rhs);
+  }
+
+  enum exp_opcode opcode () const override
+  { return STRUCTOP_MEMBER; }
+};
+
+class structop_mptr_operation
+  : public tuple_holding_operation<operation_up, operation_up>
+{
+public:
+
+  using tuple_holding_operation::tuple_holding_operation;
+
+  value *evaluate (struct type *expect_type,
+		   struct expression *exp,
+		   enum noside noside) override
+  {
+    value *lhs
+      = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
+    value *rhs
+      = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+    return eval_op_member (expect_type, exp, noside, lhs, rhs);
+  }
+
+  enum exp_opcode opcode () const override
+  { return STRUCTOP_MPTR; }
+};
+
 } /* namespace expr */
 
 #endif /* EXPOP_H */