aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/rust-exp.h57
-rw-r--r--gdb/rust-lang.c2
3 files changed, 63 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 397a606..a9b4764 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2021-03-08 Tom Tromey <tom@tromey.com>
+ * rust-lang.c (rust_subscript): No longer static.
+ * rust-exp.h (class rust_subscript_operation): New.
+
+2021-03-08 Tom Tromey <tom@tromey.com>
+
* rust-lang.c (eval_op_rust_ind): No longer static. Add "opcode"
parameter.
(rust_evaluate_subexp): Update.
diff --git a/gdb/rust-exp.h b/gdb/rust-exp.h
index d16f921..7571009 100644
--- a/gdb/rust-exp.h
+++ b/gdb/rust-exp.h
@@ -38,6 +38,10 @@ extern struct value *eval_op_rust_ind (struct type *expect_type,
enum noside noside,
enum exp_opcode opcode,
struct value *value);
+extern struct value *rust_subscript (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside, bool for_addr,
+ struct value *lhs, struct value *rhs);
namespace expr
{
@@ -67,6 +71,59 @@ public:
}
};
+/* Subscript operator for Rust. */
+class rust_subscript_operation
+ : public tuple_holding_operation<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
+ {
+ value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
+ value *arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+ return rust_subscript (expect_type, exp, noside, false, arg1, arg2);
+ }
+
+ value *slice (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside)
+ {
+ value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
+ value *arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+ return rust_subscript (expect_type, exp, noside, true, arg1, arg2);
+ }
+
+ enum exp_opcode opcode () const override
+ { return BINOP_SUBSCRIPT; }
+};
+
+class rust_unop_addr_operation
+ : public tuple_holding_operation<operation_up>
+{
+public:
+
+ using tuple_holding_operation::tuple_holding_operation;
+
+ value *evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside) override
+ {
+ operation *oper = std::get<0> (m_storage).get ();
+ rust_subscript_operation *sub_op
+ = dynamic_cast<rust_subscript_operation *> (oper);
+ if (sub_op != nullptr)
+ return sub_op->slice (expect_type, exp, noside);
+ return oper->evaluate_for_address (exp, noside);
+ }
+
+ enum exp_opcode opcode () const override
+ { return UNOP_ADDR; }
+};
+
} /* namespace expr */
#endif /* RUST_EXP_H */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index f1f4cd3..81b6702 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1168,7 +1168,7 @@ rust_compute_range (struct type *type, struct value *range,
/* A helper for rust_evaluate_subexp that handles BINOP_SUBSCRIPT. */
-static struct value *
+struct value *
rust_subscript (struct type *expect_type, struct expression *exp,
enum noside noside, bool for_addr,
struct value *lhs, struct value *rhs)