Introduce complex_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:18 +0000 (07:28 -0700)
This adds class complex_operation, which implements OP_COMPLEX.

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

* expop.h (class complex_operation): New.

gdb/ChangeLog
gdb/expop.h

index 9297e8f6e8d26f29be071177e9fc46b75feac966..cd7ec19365f1dbf66c521041c3de4350353c8da2 100644 (file)
@@ -1,3 +1,7 @@
+2021-03-08  Tom Tromey  <tom@tromey.com>
+
+       * expop.h (class complex_operation): New.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
        * eval.c (eval_op_objc_selector): No longer static.
index 0f5b5042c10295d57edefc9060f7396ec2a8664e..9c63f129594874c587d0e434978ce41d6e7b2c6f 100644 (file)
@@ -765,6 +765,27 @@ protected:
     override;
 };
 
+class complex_operation
+  : public maybe_constant_operation<operation_up, operation_up, struct type *>
+{
+public:
+
+  using maybe_constant_operation::maybe_constant_operation;
+
+  value *evaluate (struct type *expect_type,
+                  struct expression *exp,
+                  enum noside noside) override
+  {
+    value *real = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
+    value *imag = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+    return value_literal_complex (real, imag,
+                                 std::get<2> (m_storage));
+  }
+
+  enum exp_opcode opcode () const override
+  { return OP_COMPLEX; }
+};
+
 } /* namespace expr */
 
 #endif /* EXPOP_H */