[v3,063/206] Split out ada_abs

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

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

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

-- 
2.26.2

Patch

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 05076f223b3..a170a5bca90 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -10220,6 +10220,21 @@  ada_atr_size (struct type *expect_type,
 			       TARGET_CHAR_BIT * TYPE_LENGTH (type));
 }
 
+/* A helper function for UNOP_ABS.  */
+
+static value *
+ada_abs (struct type *expect_type,
+	 struct expression *exp,
+	 enum noside noside, enum exp_opcode op,
+	 struct value *arg1)
+{
+  unop_promote (exp->language_defn, exp->gdbarch, &arg1);
+  if (value_less (arg1, value_zero (value_type (arg1), not_lval)))
+    return value_neg (arg1);
+  else
+    return arg1;
+}
+
 /* Implement the evaluate_exp routine in the exp_descriptor structure
    for the Ada language.  */
 
@@ -11064,11 +11079,7 @@  ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       arg1 = evaluate_subexp (nullptr, exp, pos, noside);
       if (noside == EVAL_SKIP)
 	goto nosideret;
-      unop_promote (exp->language_defn, exp->gdbarch, &arg1);
-      if (value_less (arg1, value_zero (value_type (arg1), not_lval)))
-	return value_neg (arg1);
-      else
-	return arg1;
+      return ada_abs (expect_type, exp, noside, op, arg1);
 
     case UNOP_IND:
       preeval_pos = *pos;