[PATCH 037/203] Split out eval_op_f_abs

Tom Tromey
2021-01-01T21:47:54Z

This splits UNOP_ABS into a new function for future use.

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

* f-lang.c (eval_op_f_abs): New function.
(evaluate_subexp_f): Use it.
---
gdb/ChangeLog | 5 +++++
gdb/f-lang.c | 50 ++++++++++++++++++++++++++++++--------------------
2 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index da66ba8361f..2098a89e133 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -702,6 +702,35 @@ fortran_value_subarray (struct value *array, struct expression *exp,
return array;
}

+/* A helper function for UNOP_ABS. */
+
+static struct value *
+eval_op_f_abs (struct type *expect_type, struct expression *exp,
+ enum noside noside,
+ struct value *arg1)
+{
+ if (noside == EVAL_SKIP)
+ return eval_skip_value (exp);
+ struct type *type = value_type (arg1);
+ switch (type->code ())
+ {
+ case TYPE_CODE_FLT:
+ {
+ double d
+ = fabs (target_float_to_host_double (value_contents (arg1),
+ value_type (arg1)));
+ return value_from_host_double (type, d);
+ }
+ case TYPE_CODE_INT:
+ {
+ LONGEST l = value_as_long (arg1);
+ l = llabs (l);
+ return value_from_longest (type, l);
+ }
+ }
+ error (_("ABS of type %s not supported"), TYPE_SAFE_NAME (type));
+}
+
/* Special expression evaluation cases for Fortran. */

static struct value *
@@ -725,26 +754,7 @@ evaluate_subexp_f (struct type *expect_type, struct expression *exp,

case UNOP_ABS:
arg1 = evaluate_subexp (nullptr, exp, pos, noside);
- if (noside == EVAL_SKIP)
- return eval_skip_value (exp);
- type = value_type (arg1);
- switch (type->code ())
- {
- case TYPE_CODE_FLT:
- {
- double d
- = fabs (target_float_to_host_double (value_contents (arg1),
- value_type (arg1)));
- return value_from_host_double (type, d);
- }
- case TYPE_CODE_INT:
- {
- LONGEST l = value_as_long (arg1);
- l = llabs (l);
- return value_from_longest (type, l);
- }
- }
- error (_("ABS of type %s not supported"), TYPE_SAFE_NAME (type));
+ return eval_op_f_abs (expect_type, exp, noside, arg1);

case BINOP_MOD:
arg1 = evaluate_subexp (nullptr, exp, pos, noside);
--
2.26.2