[v3,025/206] Split out eval_op_neg

Message ID 20210220201609.838264-26-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 NEG into a new function for future use.

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

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

-- 
2.26.2

Patch

diff --git a/gdb/eval.c b/gdb/eval.c
index dbadac8eda7..4d344a70e90 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1769,6 +1769,24 @@  eval_op_plus (struct type *expect_type, struct expression *exp,
     }
 }
 
+/* A helper function for UNOP_NEG.  */
+
+static struct value *
+eval_op_neg (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 (op, arg1))
+    return value_x_unop (arg1, op, noside);
+  else
+    {
+      unop_promote (exp->language_defn, exp->gdbarch, &arg1);
+      return value_neg (arg1);
+    }
+}
+
 struct value *
 evaluate_subexp_standard (struct type *expect_type,
 			  struct expression *exp, int *pos,
@@ -2622,15 +2640,7 @@  evaluate_subexp_standard (struct type *expect_type,
       
     case UNOP_NEG:
       arg1 = evaluate_subexp (nullptr, exp, pos, noside);
-      if (noside == EVAL_SKIP)
-	return eval_skip_value (exp);
-      if (unop_user_defined_p (op, arg1))
-	return value_x_unop (arg1, op, noside);
-      else
-	{
-	  unop_promote (exp->language_defn, exp->gdbarch, &arg1);
-	  return value_neg (arg1);
-	}
+      return eval_op_neg (expect_type, exp, noside, op, arg1);
 
     case UNOP_COMPLEMENT:
       /* C++: check for and handle destructor names.  */