From: Tom Tromey Date: Mon, 8 Mar 2021 14:27:57 +0000 (-0700) Subject: Introduce rust_subscript_operation X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6ce1ad679a7aa1f82e483451669d5d77bfc1b8fb;p=binutils-gdb.git Introduce rust_subscript_operation This adds class rust_subscript_operation, which implements BINOP_SUBSCRIPT for Rust. gdb/ChangeLog 2021-03-08 Tom Tromey * rust-lang.c (rust_subscript): No longer static. * rust-exp.h (class rust_subscript_operation): New. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 397a6067bfc..a9b47648e2f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2021-03-08 Tom Tromey + + * rust-lang.c (rust_subscript): No longer static. + * rust-exp.h (class rust_subscript_operation): New. + 2021-03-08 Tom Tromey * rust-lang.c (eval_op_rust_ind): No longer static. Add "opcode" 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 +{ +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 +{ +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 (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 f1f4cd33401..81b670240f6 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)