[v3,117/206] Introduce type_instance_operation

Message ID 20210220201609.838264-118-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 type_instance_operation, which implements
TYPE_INSTANCE.

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

	* expop.h (class type_instance_operation): New.
	* eval.c (type_instance_operation::evaluate): New method.
---
 gdb/ChangeLog |  5 +++++
 gdb/eval.c    | 18 ++++++++++++++++++
 gdb/expop.h   | 17 +++++++++++++++++
 3 files changed, 40 insertions(+)

-- 
2.26.2

Patch

diff --git a/gdb/eval.c b/gdb/eval.c
index b34c695ae73..373a5c0b7a6 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -636,6 +636,24 @@  fake_method::~fake_method ()
   xfree (m_type.fields ());
 }
 
+namespace expr
+{
+
+value *
+type_instance_operation::evaluate (struct type *expect_type,
+				   struct expression *exp,
+				   enum noside noside)
+{
+  type_instance_flags flags = std::get<0> (m_storage);
+  std::vector<type *> &types = std::get<1> (m_storage);
+
+  fake_method fake_expect_type (flags, types.size (), types.data ());
+  return std::get<2> (m_storage)->evaluate (fake_expect_type.type (),
+					    exp, noside);
+}
+
+}
+
 /* Helper for evaluating an OP_VAR_VALUE.  */
 
 value *
diff --git a/gdb/expop.h b/gdb/expop.h
index 7c0768ca6c1..b196de52d0b 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -1740,6 +1740,23 @@  class op_this_operation
     override;
 };
 
+/* Implement the "type instance" operation.  */
+class type_instance_operation
+  : public tuple_holding_operation<type_instance_flags, std::vector<type *>,
+				   operation_up>
+{
+public:
+
+  using tuple_holding_operation::tuple_holding_operation;
+
+  value *evaluate (struct type *expect_type,
+		   struct expression *exp,
+		   enum noside noside) override;
+
+  enum exp_opcode opcode () const override
+  { return TYPE_INSTANCE; }
+};
+
 } /* namespace expr */
 
 #endif /* EXPOP_H */