[v3,085/206] Introduce bool_operation

Message ID 20210220201609.838264-86-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 bool_operation, which implements OP_BOOL.

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

	* expop.h (class bool_operation): New.
---
 gdb/ChangeLog |  4 ++++
 gdb/expop.h   | 22 ++++++++++++++++++++++
 2 files changed, 26 insertions(+)

-- 
2.26.2

Patch

diff --git a/gdb/expop.h b/gdb/expop.h
index a0e00302532..44098b84761 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -627,6 +627,28 @@  class register_operation
     override;
 };
 
+class bool_operation
+  : public tuple_holding_operation<bool>
+{
+public:
+
+  using tuple_holding_operation::tuple_holding_operation;
+
+  value *evaluate (struct type *expect_type,
+		   struct expression *exp,
+		   enum noside noside) override
+  {
+    struct type *type = language_bool_type (exp->language_defn, exp->gdbarch);
+    return value_from_longest (type, std::get<0> (m_storage));
+  }
+
+  enum exp_opcode opcode () const override
+  { return OP_BOOL; }
+
+  bool constant_p () const override
+  { return true; }
+};
+
 } /* namespace expr */
 
 #endif /* EXPOP_H */