From e4407a202d31a6873ea240b13125bf1ae8d20401 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 8 Mar 2021 07:27:57 -0700 Subject: [PATCH] Implement Rust field operations This implements the field operations STRUCTOP_STRUCT and STRUCTOP_ANONYMOUS, for Rust. gdb/ChangeLog 2021-03-08 Tom Tromey * rust-lang.c (eval_op_rust_struct_anon, eval_op_rust_structop): No longer static. * rust-exp.h (class rust_struct_anon): New. (class rust_structop): New. --- gdb/ChangeLog | 7 +++++++ gdb/rust-exp.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ gdb/rust-lang.c | 4 ++-- 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 764c432d89..69a514cf8b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2021-03-08 Tom Tromey + + * rust-lang.c (eval_op_rust_struct_anon, eval_op_rust_structop): + No longer static. + * rust-exp.h (class rust_struct_anon): New. + (class rust_structop): New. + 2021-03-08 Tom Tromey * rust-lang.c (rust_range): No longer static. diff --git a/gdb/rust-exp.h b/gdb/rust-exp.h index 263d41a79d..19e945c806 100644 --- a/gdb/rust-exp.h +++ b/gdb/rust-exp.h @@ -46,6 +46,16 @@ 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); +extern struct value *eval_op_rust_struct_anon (struct type *expect_type, + struct expression *exp, + enum noside noside, + int field_number, + struct value *lhs); +extern struct value *eval_op_rust_structop (struct type *expect_type, + struct expression *exp, + enum noside noside, + struct value *lhs, + const char *field_name); namespace expr { @@ -154,6 +164,49 @@ public: { return OP_RANGE; } }; +/* Tuple field reference (using an integer). */ +class rust_struct_anon + : 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 *lhs = std::get<1> (m_storage)->evaluate (nullptr, exp, noside); + return eval_op_rust_struct_anon (expect_type, exp, noside, + std::get<0> (m_storage), lhs); + + } + + enum exp_opcode opcode () const override + { return STRUCTOP_ANONYMOUS; } +}; + +/* Structure (or union or enum) field reference. */ +class rust_structop + : public structop_base_operation +{ +public: + + using structop_base_operation::structop_base_operation; + + value *evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) override + { + value *lhs = std::get<0> (m_storage)->evaluate (nullptr, exp, noside); + return eval_op_rust_structop (expect_type, exp, noside, lhs, + std::get<1> (m_storage).c_str ()); + } + + enum exp_opcode opcode () const override + { return STRUCTOP_STRUCT; } +}; + } /* namespace expr */ #endif /* RUST_EXP_H */ diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 46eb03e527..1373de9403 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -1388,7 +1388,7 @@ eval_op_rust_array (struct type *expect_type, struct expression *exp, /* A helper function for STRUCTOP_ANONYMOUS. */ -static struct value * +struct value * eval_op_rust_struct_anon (struct type *expect_type, struct expression *exp, enum noside noside, int field_number, struct value *lhs) @@ -1455,7 +1455,7 @@ tuple structs, and tuple-like enum variants")); /* A helper function for STRUCTOP_STRUCT. */ -static struct value * +struct value * eval_op_rust_structop (struct type *expect_type, struct expression *exp, enum noside noside, struct value *lhs, const char *field_name) -- 2.34.1