]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Introduce typeid_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:22 +0000 (07:28 -0700)
This adds class typeid_operation, which implements OP_TYPEID.

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

* expop.h (class typeid_operation): New.

gdb/ChangeLog
gdb/expop.h

index 5f9e2bc70cc2215cf28c6f6f38a8ae84e763ea08..fb0eea2ee86c72a7330e093c7926d042b94f41f6 100644 (file)
@@ -1,3 +1,7 @@
+2021-03-08  Tom Tromey  <tom@tromey.com>
+
+       * expop.h (class typeid_operation): New.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
        * expop.h (class decltype_operation): New.
index 183137805f98afe68bba9cfd6ef6038c2528baab..804f51654b21a5e36656ea2401f32cf33a953deb 100644 (file)
@@ -1517,6 +1517,35 @@ public:
   { return OP_DECLTYPE; }
 };
 
+/* Implement 'typeid'.  */
+class typeid_operation
+  : public tuple_holding_operation<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 sub_op = std::get<0> (m_storage)->opcode ();
+    enum noside sub_noside
+      = ((sub_op == OP_TYPE || sub_op == OP_DECLTYPE || sub_op == OP_TYPEOF)
+        ? EVAL_AVOID_SIDE_EFFECTS
+        : noside);
+
+    value *result = std::get<0> (m_storage)->evaluate (nullptr, exp,
+                                                      sub_noside);
+    if (noside != EVAL_NORMAL)
+      return allocate_value (cplus_typeid_type (exp->gdbarch));
+    return cplus_typeid (result);
+  }
+
+  enum exp_opcode opcode () const override
+  { return OP_TYPEID; }
+};
+
 } /* namespace expr */
 
 #endif /* EXPOP_H */