[PATCH 133/203] Introduce rust_range_operation

Tom Tromey tom@tromey.com
Fri Jan 1 21:46:13 GMT 2021


This adds class rust_range_operation, which implements OP_RANGE.

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

	* rust-lang.c (rust_range): No longer static.
	* rust-exp.h (class rust_range_operation): New.
---
 gdb/ChangeLog   |  5 +++++
 gdb/rust-exp.h  | 30 ++++++++++++++++++++++++++++++
 gdb/rust-lang.c |  2 +-
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/gdb/rust-exp.h b/gdb/rust-exp.h
index 7571009ea39..263d41a79d4 100644
--- a/gdb/rust-exp.h
+++ b/gdb/rust-exp.h
@@ -42,6 +42,10 @@ extern struct value *rust_subscript (struct type *expect_type,
 				     struct expression *exp,
 				     enum noside noside, bool for_addr,
 				     struct value *lhs, struct value *rhs);
+extern struct value *rust_range (struct type *expect_type,
+				 struct expression *exp,
+				 enum noside noside, enum range_flag kind,
+				 struct value *low, struct value *high);
 
 namespace expr
 {
@@ -124,6 +128,32 @@ class rust_unop_addr_operation
   { return UNOP_ADDR; }
 };
 
+/* The Rust range operators.  */
+class rust_range_operation
+  : public tuple_holding_operation<enum range_flag, operation_up, operation_up>
+{
+public:
+
+  using tuple_holding_operation::tuple_holding_operation;
+
+  value *evaluate (struct type *expect_type,
+		   struct expression *exp,
+		   enum noside noside) override
+  {
+    auto kind = std::get<0> (m_storage);
+    value *low = nullptr;
+    if (std::get<1> (m_storage) != nullptr)
+      low = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+    value *high = nullptr;
+    if (std::get<2> (m_storage) != nullptr)
+      high = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
+    return rust_range (expect_type, exp, noside, kind, low, high);
+  }
+
+  enum exp_opcode opcode () const override
+  { return OP_RANGE; }
+};
+
 } /* namespace expr */
 
 #endif /* RUST_EXP_H */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 0035a58adc4..68fbaf1642a 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1041,7 +1041,7 @@ rust_evaluate_funcall (struct expression *exp, int *pos, enum noside noside)
 
 /* A helper for rust_evaluate_subexp that handles OP_RANGE.  */
 
-static struct value *
+struct value *
 rust_range (struct type *expect_type, struct expression *exp,
 	    enum noside noside, enum range_flag kind,
 	    struct value *low, struct value *high)
-- 
2.26.2



More information about the Gdb-patches mailing list