aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-03-08 07:27:57 -0700
committerTom Tromey <tom@tromey.com>2021-03-08 07:28:05 -0700
commitcc05c68ee0d7903a2f21588b5d5b93d69fa5c1d1 (patch)
treef4662b46fb28c3ff6265d09d43029423ed4b66b4 /gdb
parentaec95807f11b3403c1e8e000618bc85e0440799e (diff)
downloadgdb-cc05c68ee0d7903a2f21588b5d5b93d69fa5c1d1.zip
gdb-cc05c68ee0d7903a2f21588b5d5b93d69fa5c1d1.tar.gz
gdb-cc05c68ee0d7903a2f21588b5d5b93d69fa5c1d1.tar.bz2
Split out eval_op_f_abs
This splits UNOP_ABS into a new function for future use. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * f-lang.c (eval_op_f_abs): New function. (evaluate_subexp_f): Use it.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/f-lang.c50
2 files changed, 35 insertions, 20 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9bafa32..058b073 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2021-03-08 Tom Tromey <tom@tromey.com>
+ * f-lang.c (eval_op_f_abs): New function.
+ (evaluate_subexp_f): Use it.
+
+2021-03-08 Tom Tromey <tom@tromey.com>
+
* eval.c (eval_op_type): New function.
(evaluate_subexp_standard): Use it.
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 01de518..76b2f27 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -974,6 +974,35 @@ fortran_associated (struct gdbarch *gdbarch, const language_defn *lang,
}
+/* 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 *
@@ -997,26 +1026,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);