aboutsummaryrefslogtreecommitdiff
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:00 -0700
commitd9790e22f44ecada1d0fd53cc82227677d1222cb (patch)
tree680ae70c84078ad198ac7bcf32a2da569062f4fd
parentaedaf9ac06d60186e2b593ee468179f8132a2510 (diff)
downloadbinutils-d9790e22f44ecada1d0fd53cc82227677d1222cb.zip
binutils-d9790e22f44ecada1d0fd53cc82227677d1222cb.tar.gz
binutils-d9790e22f44ecada1d0fd53cc82227677d1222cb.tar.bz2
Split out eval_op_sub
This splits BINOP_SUB into a new function for future use. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * eval.c (eval_op_sub): New function. (evaluate_subexp_standard): Use it.
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/eval.c48
2 files changed, 34 insertions, 19 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 674f176..7533e9b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2021-03-08 Tom Tromey <tom@tromey.com>
+ * eval.c (eval_op_sub): New function.
+ (evaluate_subexp_standard): Use it.
+
+2021-03-08 Tom Tromey <tom@tromey.com>
+
* eval.c (eval_op_add): New function.
(evaluate_subexp_standard): Use it.
diff --git a/gdb/eval.c b/gdb/eval.c
index 4152c34..ba18723 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1480,6 +1480,34 @@ eval_op_add (struct type *expect_type, struct expression *exp,
}
}
+/* A helper function for BINOP_SUB. */
+
+static struct value *
+eval_op_sub (struct type *expect_type, struct expression *exp,
+ enum noside noside, enum exp_opcode op,
+ struct value *arg1, struct value *arg2)
+{
+ if (noside == EVAL_SKIP)
+ return eval_skip_value (exp);
+ if (binop_user_defined_p (op, arg1, arg2))
+ return value_x_binop (arg1, arg2, op, OP_NULL, noside);
+ else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
+ && ptrmath_type_p (exp->language_defn, value_type (arg2)))
+ {
+ /* FIXME -- should be ptrdiff_t */
+ struct type *type = builtin_type (exp->gdbarch)->builtin_long;
+ return value_from_longest (type, value_ptrdiff (arg1, arg2));
+ }
+ else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
+ && is_integral_or_integral_reference (value_type (arg2)))
+ return value_ptradd (arg1, - value_as_long (arg2));
+ else
+ {
+ binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
+ return value_binop (arg1, arg2, BINOP_SUB);
+ }
+}
+
struct value *
evaluate_subexp_standard (struct type *expect_type,
struct expression *exp, int *pos,
@@ -2171,25 +2199,7 @@ evaluate_subexp_standard (struct type *expect_type,
case BINOP_SUB:
arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
- if (noside == EVAL_SKIP)
- return eval_skip_value (exp);
- if (binop_user_defined_p (op, arg1, arg2))
- return value_x_binop (arg1, arg2, op, OP_NULL, noside);
- else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
- && ptrmath_type_p (exp->language_defn, value_type (arg2)))
- {
- /* FIXME -- should be ptrdiff_t */
- type = builtin_type (exp->gdbarch)->builtin_long;
- return value_from_longest (type, value_ptrdiff (arg1, arg2));
- }
- else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
- && is_integral_or_integral_reference (value_type (arg2)))
- return value_ptradd (arg1, - value_as_long (arg2));
- else
- {
- binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
- return value_binop (arg1, arg2, BINOP_SUB);
- }
+ return eval_op_sub (expect_type, exp, noside, op, arg1, arg2);
case BINOP_EXP:
case BINOP_MUL: