aboutsummaryrefslogtreecommitdiff
path: root/gdb/eval.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:04 -0700
commit9e1361b760285542dd3826e1425261ea277ea10c (patch)
tree8030c5dad5f5363793c6789f3b6b59266521ef0e /gdb/eval.c
parent00f508843cfbe5bd809256e786ff3d6a530bef0b (diff)
downloadgdb-9e1361b760285542dd3826e1425261ea277ea10c.zip
gdb-9e1361b760285542dd3826e1425261ea277ea10c.tar.gz
gdb-9e1361b760285542dd3826e1425261ea277ea10c.tar.bz2
Split out eval_op_predec
This splits UNOP_PREDECREMENT into a new function for future use. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * eval.c (eval_op_predec): New file. (evaluate_subexp_standard): Use it.
Diffstat (limited to 'gdb/eval.c')
-rw-r--r--gdb/eval.c53
1 files changed, 32 insertions, 21 deletions
diff --git a/gdb/eval.c b/gdb/eval.c
index 58c8192..a958946 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1940,6 +1940,37 @@ eval_op_preinc (struct type *expect_type, struct expression *exp,
}
}
+/* A helper function for UNOP_PREDECREMENT. */
+
+static struct value *
+eval_op_predec (struct type *expect_type, struct expression *exp,
+ enum noside noside, enum exp_opcode op,
+ struct value *arg1)
+{
+ if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
+ return arg1;
+ else if (unop_user_defined_p (op, arg1))
+ {
+ return value_x_unop (arg1, op, noside);
+ }
+ else
+ {
+ struct value *arg2;
+ if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
+ arg2 = value_ptradd (arg1, -1);
+ else
+ {
+ struct value *tmp = arg1;
+
+ arg2 = value_one (value_type (arg1));
+ binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
+ arg2 = value_binop (tmp, arg2, BINOP_SUB);
+ }
+
+ return value_assign (arg1, arg2);
+ }
+}
+
struct value *
evaluate_subexp_standard (struct type *expect_type,
struct expression *exp, int *pos,
@@ -2878,27 +2909,7 @@ evaluate_subexp_standard (struct type *expect_type,
case UNOP_PREDECREMENT:
arg1 = evaluate_subexp (expect_type, exp, pos, noside);
- if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
- return arg1;
- else if (unop_user_defined_p (op, arg1))
- {
- return value_x_unop (arg1, op, noside);
- }
- else
- {
- if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
- arg2 = value_ptradd (arg1, -1);
- else
- {
- struct value *tmp = arg1;
-
- arg2 = value_one (value_type (arg1));
- binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
- arg2 = value_binop (tmp, arg2, BINOP_SUB);
- }
-
- return value_assign (arg1, arg2);
- }
+ return eval_op_predec (expect_type, exp, noside, op, arg1);
case UNOP_POSTINCREMENT:
arg1 = evaluate_subexp (expect_type, exp, pos, noside);