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:06 -0700
commit93b2b5fae269c9a8e249e81d3549392c8ff70f38 (patch)
tree260ff4e11e599302f0d921da179d0949c0d908af /gdb
parent9f1a1f3c4f8fd9dd7422bf246ef3d199df22eb18 (diff)
downloadgdb-93b2b5fae269c9a8e249e81d3549392c8ff70f38.zip
gdb-93b2b5fae269c9a8e249e81d3549392c8ff70f38.tar.gz
gdb-93b2b5fae269c9a8e249e81d3549392c8ff70f38.tar.bz2
Split out eval_op_f_modulo
This splits BINOP_FORTRAN_MODULO into a new function for future use. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * f-lang.c (eval_op_f_modulo): New function. (evaluate_subexp_f): Use it.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/f-lang.c80
2 files changed, 49 insertions, 36 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 2d71235..5bf13a7 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_modulo): New function.
+ (evaluate_subexp_f): Use it.
+
+2021-03-08 Tom Tromey <tom@tromey.com>
+
* f-lang.c (eval_op_f_floor): New function.
(evaluate_subexp_f): Use it.
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index bd16052..5239f7a 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -1079,6 +1079,47 @@ eval_op_f_floor (struct type *expect_type, struct expression *exp,
return value_from_host_double (type, val);
}
+/* A helper function for BINOP_FORTRAN_MODULO. */
+
+static struct value *
+eval_op_f_modulo (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 MODULO ()"));
+ /* MODULO(A, P) = A - FLOOR (A / P) * P */
+ switch (type->code ())
+ {
+ case TYPE_CODE_INT:
+ {
+ LONGEST a = value_as_long (arg1);
+ LONGEST p = value_as_long (arg2);
+ LONGEST result = a - (a / p) * p;
+ if (result != 0 && (a < 0) != (p < 0))
+ result += p;
+ return value_from_longest (value_type (arg1), result);
+ }
+ case TYPE_CODE_FLT:
+ {
+ double a
+ = target_float_to_host_double (value_contents (arg1),
+ value_type (arg1));
+ double p
+ = target_float_to_host_double (value_contents (arg2),
+ value_type (arg2));
+ double result = fmod (a, p);
+ if (result != 0 && (a < 0.0) != (p < 0.0))
+ result += p;
+ return value_from_host_double (type, result);
+ }
+ }
+ error (_("MODULO of type %s not supported"), TYPE_SAFE_NAME (type));
+}
+
/* Special expression evaluation cases for Fortran. */
static struct value *
@@ -1132,42 +1173,9 @@ evaluate_subexp_f (struct type *expect_type, struct expression *exp,
}
case BINOP_FORTRAN_MODULO:
- {
- 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 MODULO ()"));
- /* MODULO(A, P) = A - FLOOR (A / P) * P */
- switch (type->code ())
- {
- case TYPE_CODE_INT:
- {
- LONGEST a = value_as_long (arg1);
- LONGEST p = value_as_long (arg2);
- LONGEST result = a - (a / p) * p;
- if (result != 0 && (a < 0) != (p < 0))
- result += p;
- return value_from_longest (value_type (arg1), result);
- }
- case TYPE_CODE_FLT:
- {
- double a
- = target_float_to_host_double (value_contents (arg1),
- value_type (arg1));
- double p
- = target_float_to_host_double (value_contents (arg2),
- value_type (arg2));
- double result = fmod (a, p);
- if (result != 0 && (a < 0.0) != (p < 0.0))
- result += p;
- return value_from_host_double (type, result);
- }
- }
- error (_("MODULO of type %s not supported"), TYPE_SAFE_NAME (type));
- }
+ arg1 = evaluate_subexp (nullptr, exp, pos, noside);
+ arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
+ return eval_op_f_modulo (expect_type, exp, noside, arg1, arg2);
case FORTRAN_LBOUND:
case FORTRAN_UBOUND: