From: Tom Tromey Date: Sun, 23 Jan 2022 19:48:38 +0000 (-0700) Subject: Simplify some Rust expression-evaluation code X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f10522c0e74e26dee201aedd2582a72d0b876e3e;p=binutils-gdb.git Simplify some Rust expression-evaluation code A few Rust operations do a bit of work in their 'evaluate' functions and then call another function -- but are also the only caller. This patch simplifies this code by removing the extra layer. Tested on x86-64 Fedora 34. I'm checking this in. --- diff --git a/gdb/rust-exp.h b/gdb/rust-exp.h index 28c28a8a526..6a24f2cbc10 100644 --- a/gdb/rust-exp.h +++ b/gdb/rust-exp.h @@ -33,11 +33,6 @@ extern struct value *eval_op_rust_array (struct type *expect_type, enum exp_opcode opcode, struct value *ncopies, struct value *elt); -extern struct value *eval_op_rust_ind (struct type *expect_type, - struct expression *exp, - 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, @@ -46,16 +41,6 @@ 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 { @@ -75,14 +60,7 @@ public: value *evaluate (struct type *expect_type, struct expression *exp, - enum noside noside) override - { - if (noside != EVAL_NORMAL) - return unop_ind_operation::evaluate (expect_type, exp, noside); - - value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside); - return eval_op_rust_ind (expect_type, exp, noside, UNOP_IND, arg1); - } + enum noside noside) override; }; /* Subscript operator for Rust. */ @@ -174,13 +152,7 @@ public: 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 noside noside) override; enum exp_opcode opcode () const override { return STRUCTOP_ANONYMOUS; } @@ -196,12 +168,7 @@ public: 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 noside noside) override; value *evaluate_funcall (struct type *expect_type, struct expression *exp, diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 316e172969a..ec8cdef052f 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -1244,15 +1244,19 @@ rust_subscript (struct type *expect_type, struct expression *exp, return result; } -/* A helper function for UNOP_IND. */ +namespace expr +{ struct value * -eval_op_rust_ind (struct type *expect_type, struct expression *exp, - enum noside noside, - enum exp_opcode opcode, - struct value *value) +rust_unop_ind_operation::evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) { - gdb_assert (noside == EVAL_NORMAL); + if (noside != EVAL_NORMAL) + return unop_ind_operation::evaluate (expect_type, exp, noside); + + struct value *value = std::get<0> (m_storage)->evaluate (nullptr, exp, + noside); struct value *trait_ptr = rust_get_trait_object_pointer (value); if (trait_ptr != NULL) value = trait_ptr; @@ -1260,6 +1264,8 @@ eval_op_rust_ind (struct type *expect_type, struct expression *exp, return value_ind (value); } +} /* namespace expr */ + /* A helper function for UNOP_COMPLEMENT. */ struct value * @@ -1302,13 +1308,17 @@ eval_op_rust_array (struct type *expect_type, struct expression *exp, } } -/* A helper function for STRUCTOP_ANONYMOUS. */ +namespace expr +{ struct value * -eval_op_rust_struct_anon (struct type *expect_type, struct expression *exp, - enum noside noside, - int field_number, struct value *lhs) +rust_struct_anon::evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) { + value *lhs = std::get<1> (m_storage)->evaluate (nullptr, exp, noside); + int field_number = std::get<0> (m_storage); + struct type *type = value_type (lhs); if (type->code () == TYPE_CODE_STRUCT) @@ -1368,13 +1378,14 @@ eval_op_rust_struct_anon (struct type *expect_type, struct expression *exp, tuple structs, and tuple-like enum variants")); } -/* A helper function for STRUCTOP_STRUCT. */ - struct value * -eval_op_rust_structop (struct type *expect_type, struct expression *exp, - enum noside noside, - struct value *lhs, const char *field_name) +rust_structop::evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) { + value *lhs = std::get<0> (m_storage)->evaluate (nullptr, exp, noside); + const char *field_name = std::get<1> (m_storage).c_str (); + struct value *result; struct type *type = value_type (lhs); if (type->code () == TYPE_CODE_STRUCT && rust_enum_p (type)) @@ -1416,9 +1427,6 @@ eval_op_rust_structop (struct type *expect_type, struct expression *exp, return result; } -namespace expr -{ - value * rust_aggregate_operation::evaluate (struct type *expect_type, struct expression *exp,