[155/203] Introduce ada_bitwise_operation

Message ID 20210101214723.1784144-156-tom@tromey.com
State Superseded
Headers show
Series
  • Refactor expressions
Related show

Commit Message

Tom Tromey Jan. 1, 2021, 9:46 p.m.
This adds class ada_bitwise_operation, which is used to implement the
Ada bitwise operators.

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

	* ada-exp.h (ada_bitwise_operation): New template class.
	(ada_bitwise_and_operation, ada_bitwise_ior_operation)
	(ada_bitwise_xor_operation): New typedefs.
---
 gdb/ChangeLog |  6 ++++++
 gdb/ada-exp.h | 27 +++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

-- 
2.26.2

Patch

diff --git a/gdb/ada-exp.h b/gdb/ada-exp.h
index 3091323c89e..d8f18b9c61f 100644
--- a/gdb/ada-exp.h
+++ b/gdb/ada-exp.h
@@ -186,6 +186,33 @@  class ada_binop_equal_operation
   { return std::get<0> (m_storage); }
 };
 
+/* Bitwise operators for Ada.  */
+template<enum exp_opcode OP>
+class ada_bitwise_operation
+  : public maybe_constant_operation<operation_up, operation_up>
+{
+public:
+
+  using maybe_constant_operation::maybe_constant_operation;
+
+  value *evaluate (struct type *expect_type,
+		   struct expression *exp,
+		   enum noside noside) override
+  {
+    value *lhs = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
+    value *rhs = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+    value *result = eval_op_binary (expect_type, exp, noside, OP, lhs, rhs);
+    return value_cast (value_type (lhs), result);
+  }
+
+  enum exp_opcode opcode () const override
+  { return OP; }
+};
+
+using ada_bitwise_and_operation = ada_bitwise_operation<BINOP_BITWISE_AND>;
+using ada_bitwise_ior_operation = ada_bitwise_operation<BINOP_BITWISE_IOR>;
+using ada_bitwise_xor_operation = ada_bitwise_operation<BINOP_BITWISE_XOR>;
+
 } /* namespace expr */
 
 #endif /* ADA_EXP_H */