[v3,047/206] Split out eval_op_rust_ind

Message ID 20210220201609.838264-48-tom@tromey.com
State New
Headers show
Series
  • Refactor expressions
Related show

Commit Message

Tom Tromey Feb. 20, 2021, 8:13 p.m.
This splits UNOP_IND into a new function for future use.

gdb/ChangeLog
2021-02-20  Tom Tromey  <tom@tromey.com>

	* rust-lang.c (eval_op_rust_ind): New function.
	(rust_evaluate_subexp): Use it.
---
 gdb/ChangeLog   |  5 +++++
 gdb/rust-lang.c | 22 ++++++++++++++++------
 2 files changed, 21 insertions(+), 6 deletions(-)

-- 
2.26.2

Patch

diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 5a937d95efa..173b418e2f5 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1322,6 +1322,21 @@  rust_subscript (struct type *expect_type, struct expression *exp,
   return result;
 }
 
+/* A helper function for UNOP_IND.  */
+
+static struct value *
+eval_op_rust_ind (struct type *expect_type, struct expression *exp,
+		  enum noside noside,
+		  struct value *value)
+{
+  gdb_assert (noside == EVAL_NORMAL);
+  struct value *trait_ptr = rust_get_trait_object_pointer (value);
+  if (trait_ptr != NULL)
+    value = trait_ptr;
+
+  return value_ind (value);
+}
+
 /* evaluate_exp implementation for Rust.  */
 
 static struct value *
@@ -1341,12 +1356,7 @@  rust_evaluate_subexp (struct type *expect_type, struct expression *exp,
 	    ++*pos;
 	    struct value *value = evaluate_subexp (expect_type, exp, pos,
 						   noside);
-
-	    struct value *trait_ptr = rust_get_trait_object_pointer (value);
-	    if (trait_ptr != NULL)
-	      value = trait_ptr;
-
-	    result = value_ind (value);
+	    result = eval_op_rust_ind (expect_type, exp, noside, value);
 	  }
       }
       break;