[PATCH 116/203] Introduce type_instance_operation

Tom Tromey tom@tromey.com
Fri Jan 1 21:45:56 GMT 2021


This adds class type_instance_operation, which implements
TYPE_INSTANCE.

gdb/ChangeLog
2021-01-01  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(+)

diff --git a/gdb/eval.c b/gdb/eval.c
index 1ada2f3986b..65214a2bd3a 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -633,6 +633,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 394191ce6e5..e172e11a828 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -1729,6 +1729,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 */
-- 
2.26.2



More information about the Gdb-patches mailing list