Introduce typeof_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:21 +0000 (07:28 -0700)
This adds class typeof_operation, which implements OP_TYPEOF.

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

* expop.h (class typeof_operation): New.

gdb/ChangeLog
gdb/expop.h

index 6496f982e5a8bfcc461984dbfec1a74ab641dc9c..89d3e6f9a744211931d41fe4240e3597669a43e6 100644 (file)
@@ -1,3 +1,7 @@
+2021-03-08  Tom Tromey  <tom@tromey.com>
+
+       * expop.h (class typeof_operation): New.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
        * expop.h (class type_operation): New.
index 8b7bfbe3af69eed6885c47045fc4086afc62dd02..da7435918e2c648f75d0068a0a00e1392b08b52d 100644 (file)
@@ -1445,6 +1445,31 @@ public:
   { 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 */