[v3,159/206] Introduce ada_ternop_slice

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

Commit Message

Tom Tromey Feb. 20, 2021, 8:15 p.m.
This adds class ada_ternop_slice, which implements TERNOP_SLICE for
Ada.

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

	* ada-lang.c (ada_ternop_slice): No longer static.
	* ada-exp.h (class ada_ternop_slice_operation): New.
---
 gdb/ChangeLog  |  5 +++++
 gdb/ada-exp.h  | 27 +++++++++++++++++++++++++++
 gdb/ada-lang.c |  2 +-
 3 files changed, 33 insertions(+), 1 deletion(-)

-- 
2.26.2

Patch

diff --git a/gdb/ada-exp.h b/gdb/ada-exp.h
index d8f18b9c61f..96e3c407b6f 100644
--- a/gdb/ada-exp.h
+++ b/gdb/ada-exp.h
@@ -50,6 +50,11 @@  extern struct value *ada_equal_binop (struct type *expect_type,
 				      struct expression *exp,
 				      enum noside noside, enum exp_opcode op,
 				      struct value *arg1, struct value *arg2);
+extern struct value *ada_ternop_slice (struct expression *exp,
+				       enum noside noside,
+				       struct value *array,
+				       struct value *low_bound_val,
+				       struct value *high_bound_val);
 
 namespace expr
 {
@@ -213,6 +218,28 @@  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>;
 
+/* Ada array- or string-slice operation.  */
+class ada_ternop_slice_operation
+  : public maybe_constant_operation<operation_up, 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 *array = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
+    value *low = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+    value *high = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
+    return ada_ternop_slice (exp, noside, array, low, high);
+  }
+
+  enum exp_opcode opcode () const override
+  { return TERNOP_SLICE; }
+};
+
 } /* namespace expr */
 
 #endif /* ADA_EXP_H */
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index a0236af57d0..072b41bca72 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -10320,7 +10320,7 @@  ada_equal_binop (struct type *expect_type,
 
 /* A helper function for TERNOP_SLICE.  */
 
-static value *
+value *
 ada_ternop_slice (struct expression *exp,
 		  enum noside noside,
 		  struct value *array, struct value *low_bound_val,