[PATCH v2 026/206] Split out eval_op_complement

Tom Tromey tom@tromey.com
Sat Feb 13 19:59:56 GMT 2021


This splits UNOP_COMPLEMENT into a new function for future use.

2021-02-13  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_complement): New function.
	(evaluate_subexp_standard): Use it.
---
 gdb/ChangeLog |  5 +++++
 gdb/eval.c    | 28 +++++++++++++++++++---------
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/gdb/eval.c b/gdb/eval.c
index b6adb47c74e..b43c3b4541b 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1784,6 +1784,24 @@ eval_op_neg (struct type *expect_type, struct expression *exp,
     }
 }
 
+/* A helper function for UNOP_COMPLEMENT.  */
+
+static struct value *
+eval_op_complement (struct type *expect_type, struct expression *exp,
+		    enum noside noside, enum exp_opcode op,
+		    struct value *arg1)
+{
+  if (noside == EVAL_SKIP)
+    return eval_skip_value (exp);
+  if (unop_user_defined_p (UNOP_COMPLEMENT, arg1))
+    return value_x_unop (arg1, UNOP_COMPLEMENT, noside);
+  else
+    {
+      unop_promote (exp->language_defn, exp->gdbarch, &arg1);
+      return value_complement (arg1);
+    }
+}
+
 struct value *
 evaluate_subexp_standard (struct type *expect_type,
 			  struct expression *exp, int *pos,
@@ -2643,15 +2661,7 @@ evaluate_subexp_standard (struct type *expect_type,
       /* C++: check for and handle destructor names.  */
 
       arg1 = evaluate_subexp (nullptr, exp, pos, noside);
-      if (noside == EVAL_SKIP)
-	return eval_skip_value (exp);
-      if (unop_user_defined_p (UNOP_COMPLEMENT, arg1))
-	return value_x_unop (arg1, UNOP_COMPLEMENT, noside);
-      else
-	{
-	  unop_promote (exp->language_defn, exp->gdbarch, &arg1);
-	  return value_complement (arg1);
-	}
+      return eval_op_complement (expect_type, exp, noside, op, arg1);
 
     case UNOP_LOGICAL_NOT:
       arg1 = evaluate_subexp (nullptr, exp, pos, noside);
-- 
2.26.2



More information about the Gdb-patches mailing list