[v3,093/206] Introduce complex_operation

Message ID 20210220201609.838264-94-tom@tromey.com
State New
Headers show
Series
  • Refactor expressions
Related show

Commit Message

Tom Tromey Feb. 20, 2021, 8:14 p.m.
This adds class complex_operation, which implements OP_COMPLEX.

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

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

-- 
2.26.2

Patch

diff --git a/gdb/expop.h b/gdb/expop.h
index 0f5b5042c10..9c63f129594 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -765,6 +765,27 @@  class ternop_cond_operation
     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 */