[PATCH 108/203] Introduce typeof_operation

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


This adds class typeof_operation, which implements OP_TYPEOF.

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

	* expop.h (class typeof_operation): New.
---
 gdb/ChangeLog |  4 ++++
 gdb/expop.h   | 25 +++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/gdb/expop.h b/gdb/expop.h
index aac3e729de9..502ad71d067 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -1434,6 +1434,31 @@ class type_operation
   { return true; }
 };
 
+/* Implement the "typeof" operation.  */
+class typeof_operation
+  : public maybe_constant_operation<operation_up>
+{
+public:
+
+  using maybe_constant_operation::maybe_constant_operation;
+
+  value *evaluate (struct type *expect_type,
+		   struct expression *exp,
+		   enum noside noside) override
+  {
+    if (noside == EVAL_SKIP)
+      return eval_skip_value (exp);
+    else if (noside == EVAL_AVOID_SIDE_EFFECTS)
+      return std::get<0> (m_storage)->evaluate (nullptr, exp,
+						EVAL_AVOID_SIDE_EFFECTS);
+    else
+      error (_("Attempt to use a type as an expression"));
+  }
+
+  enum exp_opcode opcode () const override
+  { return OP_TYPEOF; }
+};
+
 } /* namespace expr */
 
 #endif /* EXPOP_H */
-- 
2.26.2



More information about the Gdb-patches mailing list