[PATCH 058/203] Split out ada_unop_neg

Tom Tromey
2021-01-01T21:48:08Z

This splits UNOP_NEG into a new function for future use.

gdb/ChangeLog
2021-01-01 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(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 4cf6335ceb5..b071c3d3f65 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -10106,6 +10106,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. */

@@ -10300,15 +10319,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:
--
2.26.2