[v3,059/206] Split out ada_unop_neg

Message ID 20210220201609.838264-60-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>

	* ada-lang.c (ada_unop_neg): New function.
	(ada_evaluate_subexp): Use it.
---
 gdb/ChangeLog  |  5 +++++
 gdb/ada-lang.c | 29 ++++++++++++++++++++---------
 2 files changed, 25 insertions(+), 9 deletions(-)

-- 
2.26.2

Patch

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 1e70db49a2c..217f4f860f6 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -10125,6 +10125,25 @@  eval_ternop_in_range (struct type *expect_type, struct expression *exp,
 			    || value_equal (arg2, arg1)));
 }
 
+/* A helper function for UNOP_NEG.  */
+
+static value *
+ada_unop_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);
+  else if (ada_is_gnat_encoded_fixed_point_type (value_type (arg1)))
+    return value_cast (value_type (arg1), value_neg (arg1));
+  else
+    {
+      unop_promote (exp->language_defn, exp->gdbarch, &arg1);
+      return value_neg (arg1);
+    }
+}
+
 /* Implement the evaluate_exp routine in the exp_descriptor structure
    for the Ada language.  */
 
@@ -10339,15 +10358,7 @@  ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
 
     case UNOP_NEG:
       arg1 = evaluate_subexp (nullptr, exp, pos, noside);
-      if (noside == EVAL_SKIP)
-	goto nosideret;
-      else if (ada_is_gnat_encoded_fixed_point_type (value_type (arg1)))
-	return value_cast (value_type (arg1), value_neg (arg1));
-      else
-	{
-	  unop_promote (exp->language_defn, exp->gdbarch, &arg1);
-	  return value_neg (arg1);
-	}
+      return ada_unop_neg (expect_type, exp, noside, op, arg1);
 
     case BINOP_LOGICAL_AND:
     case BINOP_LOGICAL_OR: