summaryrefslogtreecommitdiff
path: root/gdb/rust-exp.h
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-03-08 07:27:57 -0700
committerTom Tromey <tom@tromey.com>2021-03-08 07:28:27 -0700
commit6ce1ad679a7aa1f82e483451669d5d77bfc1b8fb (patch)
treede2631c5f3d13cdb64c0fe6d7559754c52534d3c /gdb/rust-exp.h
parent11dd3dce4427792a89a851b8ed290b3c8124f282 (diff)
downloadbinutils-gdb-6ce1ad679a7aa1f82e483451669d5d77bfc1b8fb.tar.gz
Introduce rust_subscript_operation
This adds class rust_subscript_operation, which implements BINOP_SUBSCRIPT for Rust. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * rust-lang.c (rust_subscript): No longer static. * rust-exp.h (class rust_subscript_operation): New.
Diffstat (limited to 'gdb/rust-exp.h')
-rw-r--r--gdb/rust-exp.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/gdb/rust-exp.h b/gdb/rust-exp.h
index d16f921ca00..7571009ea39 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 */