aboutsummaryrefslogtreecommitdiff
path: root/gdb/rust-lang.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2022-01-23 12:48:38 -0700
committerTom Tromey <tom@tromey.com>2022-01-23 12:52:44 -0700
commitf10522c0e74e26dee201aedd2582a72d0b876e3e (patch)
tree3532af71c0cbd5d9f744f42921bf4e59ee6505b1 /gdb/rust-lang.c
parent451c003d5fcebbc7b7bc2516d43aede6d02bd501 (diff)
downloadgdb-f10522c0e74e26dee201aedd2582a72d0b876e3e.zip
gdb-f10522c0e74e26dee201aedd2582a72d0b876e3e.tar.gz
gdb-f10522c0e74e26dee201aedd2582a72d0b876e3e.tar.bz2
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.
Diffstat (limited to 'gdb/rust-lang.c')
-rw-r--r--gdb/rust-lang.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 316e172..ec8cdef 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,