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:21 -0700 |
commit | 6d89e2962a8cc245b8364e1968396873bd0bb9b1 (patch) | |
tree | 887a2ef7f58f1b8cf0872dfa24ae6f455c22fa70 /gdb/expop.h | |
parent | 9307d17b7a97bd49baf0d877785c43cf203b7cee (diff) | |
download | gdb-6d89e2962a8cc245b8364e1968396873bd0bb9b1.zip gdb-6d89e2962a8cc245b8364e1968396873bd0bb9b1.tar.gz gdb-6d89e2962a8cc245b8364e1968396873bd0bb9b1.tar.bz2 |
Implement unary increment and decrement operations
This implements the unary increment and decrement operations, "++" and
"--".
gdb/ChangeLog
2021-03-08 Tom Tromey <tom@tromey.com>
* 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.
Diffstat (limited to 'gdb/expop.h')
-rw-r--r-- | gdb/expop.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/gdb/expop.h b/gdb/expop.h index abd914a..ec73109 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<UNOP_LOGICAL_NOT, eval_op_lognot>; +/* Handle pre- and post- increment and -decrement. */ +template<enum exp_opcode OP, unary_ftype FUNC> +class unop_incr_operation + : public tuple_holding_operation<operation_up> +{ +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<UNOP_PREINCREMENT, eval_op_preinc>; +using predec_operation + = unop_incr_operation<UNOP_PREDECREMENT, eval_op_predec>; +using postinc_operation + = unop_incr_operation<UNOP_POSTINCREMENT, eval_op_postinc>; +using postdec_operation + = unop_incr_operation<UNOP_POSTDECREMENT, eval_op_postdec>; + } /* namespace expr */ #endif /* EXPOP_H */ |