[PATCH 092/203] Introduce complex_operation

Tom Tromey
2021-01-01T21:48:31Z

This adds class complex_operation, which implements OP_COMPLEX.

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

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

diff --git a/gdb/expop.h b/gdb/expop.h
index 0bb9e081df0..88ceb6033ac 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -754,6 +754,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 */
--
2.26.2