Introduce ada_bitwise_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:33 +0000 (07:28 -0700)
This adds class ada_bitwise_operation, which is used to implement the
Ada bitwise operators.

gdb/ChangeLog
2021-03-08  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
gdb/ada-exp.h

index f34ce4b06c76a1e5687149e32911cf863a1ebba2..62c71b7c53476fc84ea520ac8dd4779cff3fee01 100644 (file)
@@ -1,3 +1,9 @@
+2021-03-08  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.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
        * ada-lang.c (ada_equal_binop): No longer static.
index 3091323c89e3d3acd57dda45f0252e56802c2f4e..d8f18b9c61f76a496c30bcd3ab2c97609d8ffdf7 100644 (file)
@@ -186,6 +186,33 @@ public:
   { 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 */