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.
This commit is contained in:
Tom Tromey
2022-01-23 12:48:38 -07:00
parent 451c003d5f
commit f10522c0e7
2 changed files with 29 additions and 54 deletions

View File

@ -33,11 +33,6 @@ extern struct value *eval_op_rust_array (struct type *expect_type,
enum exp_opcode opcode, enum exp_opcode opcode,
struct value *ncopies, struct value *ncopies,
struct value *elt); 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, extern struct value *rust_subscript (struct type *expect_type,
struct expression *exp, struct expression *exp,
enum noside noside, bool for_addr, enum noside noside, bool for_addr,
@ -46,16 +41,6 @@ extern struct value *rust_range (struct type *expect_type,
struct expression *exp, struct expression *exp,
enum noside noside, enum range_flag kind, enum noside noside, enum range_flag kind,
struct value *low, struct value *high); 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 namespace expr
{ {
@ -75,14 +60,7 @@ public:
value *evaluate (struct type *expect_type, value *evaluate (struct type *expect_type,
struct expression *exp, struct expression *exp,
enum noside noside) override 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);
}
}; };
/* Subscript operator for Rust. */ /* Subscript operator for Rust. */
@ -174,13 +152,7 @@ public:
value *evaluate (struct type *expect_type, value *evaluate (struct type *expect_type,
struct expression *exp, struct expression *exp,
enum noside noside) override 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 enum exp_opcode opcode () const override
{ return STRUCTOP_ANONYMOUS; } { return STRUCTOP_ANONYMOUS; }
@ -196,12 +168,7 @@ public:
value *evaluate (struct type *expect_type, value *evaluate (struct type *expect_type,
struct expression *exp, struct expression *exp,
enum noside noside) override 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 ());
}
value *evaluate_funcall (struct type *expect_type, value *evaluate_funcall (struct type *expect_type,
struct expression *exp, struct expression *exp,

View File

@ -1244,15 +1244,19 @@ rust_subscript (struct type *expect_type, struct expression *exp,
return result; return result;
} }
/* A helper function for UNOP_IND. */ namespace expr
{
struct value * struct value *
eval_op_rust_ind (struct type *expect_type, struct expression *exp, rust_unop_ind_operation::evaluate (struct type *expect_type,
enum noside noside, struct expression *exp,
enum exp_opcode opcode, enum noside noside)
struct value *value)
{ {
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); struct value *trait_ptr = rust_get_trait_object_pointer (value);
if (trait_ptr != NULL) if (trait_ptr != NULL)
value = trait_ptr; value = trait_ptr;
@ -1260,6 +1264,8 @@ eval_op_rust_ind (struct type *expect_type, struct expression *exp,
return value_ind (value); return value_ind (value);
} }
} /* namespace expr */
/* A helper function for UNOP_COMPLEMENT. */ /* A helper function for UNOP_COMPLEMENT. */
struct value * 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 * struct value *
eval_op_rust_struct_anon (struct type *expect_type, struct expression *exp, rust_struct_anon::evaluate (struct type *expect_type,
enum noside noside, struct expression *exp,
int field_number, struct value *lhs) 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); struct type *type = value_type (lhs);
if (type->code () == TYPE_CODE_STRUCT) 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")); tuple structs, and tuple-like enum variants"));
} }
/* A helper function for STRUCTOP_STRUCT. */
struct value * struct value *
eval_op_rust_structop (struct type *expect_type, struct expression *exp, rust_structop::evaluate (struct type *expect_type,
enum noside noside, struct expression *exp,
struct value *lhs, const char *field_name) 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 value *result;
struct type *type = value_type (lhs); struct type *type = value_type (lhs);
if (type->code () == TYPE_CODE_STRUCT && rust_enum_p (type)) 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; return result;
} }
namespace expr
{
value * value *
rust_aggregate_operation::evaluate (struct type *expect_type, rust_aggregate_operation::evaluate (struct type *expect_type,
struct expression *exp, struct expression *exp,