aboutsummaryrefslogtreecommitdiff
path: root/gdb/f-lang.c
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
commite08109f24b9c05f93415eb59fd8faba4889e9881 (patch)
tree0985f340b4a6815845122b0e20edc3da492626e8 /gdb/f-lang.c
parentcc05c68ee0d7903a2f21588b5d5b93d69fa5c1d1 (diff)
downloadgdb-e08109f24b9c05f93415eb59fd8faba4889e9881.zip
gdb-e08109f24b9c05f93415eb59fd8faba4889e9881.tar.gz
gdb-e08109f24b9c05f93415eb59fd8faba4889e9881.tar.bz2
Split out eval_op_f_mod
This splits BINOP_MOD into a new function for future use. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * f-lang.c (eval_op_f_mod): New function. (evaluate_subexp_f): Use it.
Diffstat (limited to 'gdb/f-lang.c')
-rw-r--r--gdb/f-lang.c68
1 files changed, 39 insertions, 29 deletions
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 76b2f27..57e3936 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -1003,6 +1003,44 @@ eval_op_f_abs (struct type *expect_type, struct expression *exp,
error (_("ABS of type %s not supported"), TYPE_SAFE_NAME (type));
}
+/* A helper function for BINOP_MOD. */
+
+static struct value *
+eval_op_f_mod (struct type *expect_type, struct expression *exp,
+ enum noside noside,
+ struct value *arg1, struct value *arg2)
+{
+ if (noside == EVAL_SKIP)
+ return eval_skip_value (exp);
+ struct type *type = value_type (arg1);
+ if (type->code () != value_type (arg2)->code ())
+ error (_("non-matching types for parameters to MOD ()"));
+ switch (type->code ())
+ {
+ case TYPE_CODE_FLT:
+ {
+ double d1
+ = target_float_to_host_double (value_contents (arg1),
+ value_type (arg1));
+ double d2
+ = target_float_to_host_double (value_contents (arg2),
+ value_type (arg2));
+ double d3 = fmod (d1, d2);
+ return value_from_host_double (type, d3);
+ }
+ case TYPE_CODE_INT:
+ {
+ LONGEST v1 = value_as_long (arg1);
+ LONGEST v2 = value_as_long (arg2);
+ if (v2 == 0)
+ error (_("calling MOD (N, 0) is undefined"));
+ LONGEST v3 = v1 - (v1 / v2) * v2;
+ return value_from_longest (value_type (arg1), v3);
+ }
+ }
+ error (_("MOD of type %s not supported"), TYPE_SAFE_NAME (type));
+}
+
/* Special expression evaluation cases for Fortran. */
static struct value *
@@ -1031,35 +1069,7 @@ evaluate_subexp_f (struct type *expect_type, struct expression *exp,
case BINOP_MOD:
arg1 = evaluate_subexp (nullptr, exp, pos, noside);
arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
- if (noside == EVAL_SKIP)
- return eval_skip_value (exp);
- type = value_type (arg1);
- if (type->code () != value_type (arg2)->code ())
- error (_("non-matching types for parameters to MOD ()"));
- switch (type->code ())
- {
- case TYPE_CODE_FLT:
- {
- double d1
- = target_float_to_host_double (value_contents (arg1),
- value_type (arg1));
- double d2
- = target_float_to_host_double (value_contents (arg2),
- value_type (arg2));
- double d3 = fmod (d1, d2);
- return value_from_host_double (type, d3);
- }
- case TYPE_CODE_INT:
- {
- LONGEST v1 = value_as_long (arg1);
- LONGEST v2 = value_as_long (arg2);
- if (v2 == 0)
- error (_("calling MOD (N, 0) is undefined"));
- LONGEST v3 = v1 - (v1 / v2) * v2;
- return value_from_longest (value_type (arg1), v3);
- }
- }
- error (_("MOD of type %s not supported"), TYPE_SAFE_NAME (type));
+ return eval_op_f_mod (expect_type, exp, noside, arg1, arg2);
case UNOP_FORTRAN_CEILING:
{