[PATCH 087/203] Introduce ternop_slice_operation

Tom Tromey tom@tromey.com
Fri Jan 1 21:45:27 GMT 2021


This adds class ternop_slice_operation, which implements TERNOP_SLICE.

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

	* expop.h (class ternop_slice_operation): New.
	* eval.c (eval_op_ternop): No longer static.
---
 gdb/ChangeLog |  5 +++++
 gdb/eval.c    |  2 +-
 gdb/expop.h   | 29 +++++++++++++++++++++++++++++
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/gdb/eval.c b/gdb/eval.c
index 382eca04f15..7968d008086 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1312,7 +1312,7 @@ eval_op_concat (struct type *expect_type, struct expression *exp,
 
 /* A helper function for TERNOP_SLICE.  */
 
-static struct value *
+struct value *
 eval_op_ternop (struct type *expect_type, struct expression *exp,
 		enum noside noside,
 		struct value *array, struct value *low, struct value *upper)
diff --git a/gdb/expop.h b/gdb/expop.h
index ff4e82150e6..49a03ce70c6 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -64,6 +64,11 @@ extern struct value *eval_op_string (struct type *expect_type,
 				     struct expression *exp,
 				     enum noside noside, int len,
 				     const char *string);
+extern struct value *eval_op_ternop (struct type *expect_type,
+				     struct expression *exp,
+				     enum noside noside,
+				     struct value *array, struct value *low,
+				     struct value *upper);
 
 namespace expr
 {
@@ -694,6 +699,30 @@ class string_operation
   { return OP_STRING; }
 };
 
+class 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
+  {
+    struct value *array
+      = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
+    struct value *low
+      = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+    struct value *upper
+      = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
+    return eval_op_ternop (expect_type, exp, noside, array, low, upper);
+  }
+
+  enum exp_opcode opcode () const override
+  { return TERNOP_SLICE; }
+};
+
 } /* namespace expr */
 
 #endif /* EXPOP_H */
-- 
2.26.2



More information about the Gdb-patches mailing list