From 6d89e2962a8cc245b8364e1968396873bd0bb9b1 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 8 Mar 2021 07:27:57 -0700 Subject: [PATCH] Implement unary increment and decrement operations This implements the unary increment and decrement operations, "++" and "--". gdb/ChangeLog 2021-03-08 Tom Tromey * expop.h (unop_incr_operation): New template. (preinc_operation, predec_operation, postinc_operation) (postdec_operation): New typedefs. * eval.c (eval_op_preinc, eval_op_predec, eval_op_postinc) (eval_op_postdec): No longer static. --- gdb/ChangeLog | 8 ++++++++ gdb/eval.c | 8 ++++---- gdb/expop.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 17281bf5ba4..582489891b4 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2021-03-08 Tom Tromey + + * expop.h (unop_incr_operation): New template. + (preinc_operation, predec_operation, postinc_operation) + (postdec_operation): New typedefs. + * eval.c (eval_op_preinc, eval_op_predec, eval_op_postinc) + (eval_op_postdec): No longer static. + 2021-03-08 Tom Tromey * expop.h (unary_ftype): New typedef. diff --git a/gdb/eval.c b/gdb/eval.c index 8d75c08541b..4f12c7b666a 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1912,7 +1912,7 @@ eval_op_memval (struct type *expect_type, struct expression *exp, /* A helper function for UNOP_PREINCREMENT. */ -static struct value * +struct value * eval_op_preinc (struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1) @@ -1943,7 +1943,7 @@ eval_op_preinc (struct type *expect_type, struct expression *exp, /* A helper function for UNOP_PREDECREMENT. */ -static struct value * +struct value * eval_op_predec (struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1) @@ -1974,7 +1974,7 @@ eval_op_predec (struct type *expect_type, struct expression *exp, /* A helper function for UNOP_POSTINCREMENT. */ -static struct value * +struct value * eval_op_postinc (struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1) @@ -2008,7 +2008,7 @@ eval_op_postinc (struct type *expect_type, struct expression *exp, /* A helper function for UNOP_POSTDECREMENT. */ -static struct value * +struct value * eval_op_postdec (struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1) diff --git a/gdb/expop.h b/gdb/expop.h index abd914ad574..ec73109f8a3 100644 --- a/gdb/expop.h +++ b/gdb/expop.h @@ -162,6 +162,26 @@ extern struct value *eval_op_lognot (struct type *expect_type, enum noside noside, enum exp_opcode op, struct value *arg1); +extern struct value *eval_op_preinc (struct type *expect_type, + struct expression *exp, + enum noside noside, + enum exp_opcode op, + struct value *arg1); +extern struct value *eval_op_predec (struct type *expect_type, + struct expression *exp, + enum noside noside, + enum exp_opcode op, + struct value *arg1); +extern struct value *eval_op_postinc (struct type *expect_type, + struct expression *exp, + enum noside noside, + enum exp_opcode op, + struct value *arg1); +extern struct value *eval_op_postdec (struct type *expect_type, + struct expression *exp, + enum noside noside, + enum exp_opcode op, + struct value *arg1); namespace expr { @@ -1316,6 +1336,36 @@ using unary_complement_operation using unary_logical_not_operation = usual_ax_unop_operation; +/* Handle pre- and post- increment and -decrement. */ +template +class unop_incr_operation + : public tuple_holding_operation +{ +public: + + using tuple_holding_operation::tuple_holding_operation; + + value *evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) override + { + value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside); + return FUNC (expect_type, exp, noside, OP, val); + } + + enum exp_opcode opcode () const override + { return OP; } +}; + +using preinc_operation + = unop_incr_operation; +using predec_operation + = unop_incr_operation; +using postinc_operation + = unop_incr_operation; +using postdec_operation + = unop_incr_operation; + } /* namespace expr */ #endif /* EXPOP_H */ -- 2.30.2