Introduce structop_member_operation and structop_mptr_operation
authorTom Tromey <tom@tromey.com>
Mon, 8 Mar 2021 14:27:57 +0000 (07:27 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 8 Mar 2021 14:28:18 +0000 (07:28 -0700)
This adds class structop_member_operation and structop_mptr_operation,
which implement STRUCTOP_MEMBER and STRUCTOP_MPTR.

gdb/ChangeLog
2021-03-08  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
gdb/eval.c
gdb/expop.h

index 0a985a2fce542e41dd0da82aa8789dde732d19dd..42a8e1c8f88278b648d85591e0cc8eac067a15b2 100644 (file)
@@ -1,3 +1,9 @@
+2021-03-08  Tom Tromey  <tom@tromey.com>
+
+       * expop.h (class structop_member_operation)
+       (class structop_mptr_operation): New.
+       * eval.c (eval_op_member): No longer static.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
        * expop.h (class structop_ptr_operation): New.
index 1962777cc6d118117d039661f1b5cb04323a8b8b..de7863138b355e7ebc4e7365bedb1cc42b8ee66a 100644 (file)
@@ -1417,7 +1417,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)
index 38f3ffb5aef5bd0af8761067629a6e1a19920572..cbd4d6267dad5ee467df31fedd0c18be64162347 100644 (file)
@@ -80,6 +80,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
 {
@@ -887,6 +891,50 @@ protected:
   }
 };
 
+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 */