Introduce rust_range_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:27 +0000 (07:28 -0700)
This adds class rust_range_operation, which implements OP_RANGE.

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

* rust-lang.c (rust_range): No longer static.
* rust-exp.h (class rust_range_operation): New.

gdb/ChangeLog
gdb/rust-exp.h
gdb/rust-lang.c

index a9b47648e2f12fbcac33d22fe8fe7b0046893f1c..764c432d89235b2c897bfb3e1a41a620e532e77c 100644 (file)
@@ -1,3 +1,8 @@
+2021-03-08  Tom Tromey  <tom@tromey.com>
+
+       * rust-lang.c (rust_range): No longer static.
+       * rust-exp.h (class rust_range_operation): New.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
        * rust-lang.c (rust_subscript): No longer static.
index 7571009ea39552d29fffc24341e33401434136a3..263d41a79d4057eb4e53ad296aa8a404ea61b317 100644 (file)
@@ -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 @@ public:
   { 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 */
index 81b670240f699cf86999586bb7862e6379c5adc4..46eb03e5273d078132509d4f3f8268f9ddeddb27 100644 (file)
@@ -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)
This page took 0.029059 seconds and 4 git commands to generate.