Split out eval_op_neg

This splits UNOP NEG into a new function for future use.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_neg): New function.
	(evaluate_subexp_standard): Use it.
This commit is contained in:
Tom Tromey 2021-03-08 07:27:57 -07:00
parent 39f288bea9
commit 606d105ff1
2 changed files with 24 additions and 9 deletions

View File

@ -1,3 +1,8 @@
2021-03-08 Tom Tromey <tom@tromey.com>
* eval.c (eval_op_neg): New function.
(evaluate_subexp_standard): Use it.
2021-03-08 Tom Tromey <tom@tromey.com>
* eval.c (eval_op_plus): New function.

View File

@ -1769,6 +1769,24 @@ eval_op_plus (struct type *expect_type, struct expression *exp,
}
}
/* A helper function for UNOP_NEG. */
static struct value *
eval_op_neg (struct type *expect_type, struct expression *exp,
enum noside noside, enum exp_opcode op,
struct value *arg1)
{
if (noside == EVAL_SKIP)
return eval_skip_value (exp);
if (unop_user_defined_p (op, arg1))
return value_x_unop (arg1, op, noside);
else
{
unop_promote (exp->language_defn, exp->gdbarch, &arg1);
return value_neg (arg1);
}
}
struct value *
evaluate_subexp_standard (struct type *expect_type,
struct expression *exp, int *pos,
@ -2622,15 +2640,7 @@ evaluate_subexp_standard (struct type *expect_type,
case UNOP_NEG:
arg1 = evaluate_subexp (nullptr, exp, pos, noside);
if (noside == EVAL_SKIP)
return eval_skip_value (exp);
if (unop_user_defined_p (op, arg1))
return value_x_unop (arg1, op, noside);
else
{
unop_promote (exp->language_defn, exp->gdbarch, &arg1);
return value_neg (arg1);
}
return eval_op_neg (expect_type, exp, noside, op, arg1);
case UNOP_COMPLEMENT:
/* C++: check for and handle destructor names. */