diff options
author | Tom Tromey <tom@tromey.com> | 2021-03-08 07:27:57 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2021-03-08 07:28:04 -0700 |
commit | 00f508843cfbe5bd809256e786ff3d6a530bef0b (patch) | |
tree | 440536200c8ca40dc6c253eabb7bbaf4b2080d19 | |
parent | 3aef2a07686a5cc2b359e07fd26e42ad77fffa25 (diff) | |
download | gdb-00f508843cfbe5bd809256e786ff3d6a530bef0b.zip gdb-00f508843cfbe5bd809256e786ff3d6a530bef0b.tar.gz gdb-00f508843cfbe5bd809256e786ff3d6a530bef0b.tar.bz2 |
Split out eval_op_preinc
This splits UNOP_PREINCREMENT into a new function for future use.
gdb/ChangeLog
2021-03-08 Tom Tromey <tom@tromey.com>
* eval.c (eval_op_preinc): New function.
(evaluate_subexp_standard): Use it.
-rw-r--r-- | gdb/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/eval.c | 53 |
2 files changed, 37 insertions, 21 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 7d348f3..579e348 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2021-03-08 Tom Tromey <tom@tromey.com> + * eval.c (eval_op_preinc): New function. + (evaluate_subexp_standard): Use it. + +2021-03-08 Tom Tromey <tom@tromey.com> + * eval.c (eval_op_memval): New function. (evaluate_subexp_standard): Use it. @@ -1909,6 +1909,37 @@ eval_op_memval (struct type *expect_type, struct expression *exp, return value_at_lazy (type, value_as_address (arg1)); } +/* A helper function for UNOP_PREINCREMENT. */ + +static struct value * +eval_op_preinc (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_ADD); + } + + return value_assign (arg1, arg2); + } +} + struct value * evaluate_subexp_standard (struct type *expect_type, struct expression *exp, int *pos, @@ -2843,27 +2874,7 @@ evaluate_subexp_standard (struct type *expect_type, case UNOP_PREINCREMENT: 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_ADD); - } - - return value_assign (arg1, arg2); - } + return eval_op_preinc (expect_type, exp, noside, op, arg1); case UNOP_PREDECREMENT: arg1 = evaluate_subexp (expect_type, exp, pos, noside); |