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:20 -0700 |
commit | 46916f2bcbaf4532aab9fecb2344330710129ffa (patch) | |
tree | bb6f37c488243ab4adeccf3a814891584f956910 /gdb/expop.h | |
parent | 224d6424bab021a0a8e16f07d52f8af5e153e91f (diff) | |
download | gdb-46916f2bcbaf4532aab9fecb2344330710129ffa.zip gdb-46916f2bcbaf4532aab9fecb2344330710129ffa.tar.gz gdb-46916f2bcbaf4532aab9fecb2344330710129ffa.tar.bz2 |
Implement binary comparison operations
This implements the binary comparison operations via a template class.
gdb/ChangeLog
2021-03-08 Tom Tromey <tom@tromey.com>
* expop.h (class comparison_operation): New.
(equal_operation, notequal_operation, less_operation)
(gtr_operation, geq_operation, leq_operation): New typedefs.
* eval.c (eval_op_equal, eval_op_notequal, eval_op_less)
(eval_op_gtr, eval_op_geq, eval_op_leq): No longer static.
Diffstat (limited to 'gdb/expop.h')
-rw-r--r-- | gdb/expop.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/gdb/expop.h b/gdb/expop.h index 5c3b0af..af378d0 100644 --- a/gdb/expop.h +++ b/gdb/expop.h @@ -105,6 +105,36 @@ extern struct value *eval_op_subscript (struct type *expect_type, enum noside noside, enum exp_opcode op, struct value *arg1, struct value *arg2); +extern struct value *eval_op_equal (struct type *expect_type, + struct expression *exp, + enum noside noside, enum exp_opcode op, + struct value *arg1, + struct value *arg2); +extern struct value *eval_op_notequal (struct type *expect_type, + struct expression *exp, + enum noside noside, enum exp_opcode op, + struct value *arg1, + struct value *arg2); +extern struct value *eval_op_less (struct type *expect_type, + struct expression *exp, + enum noside noside, enum exp_opcode op, + struct value *arg1, + struct value *arg2); +extern struct value *eval_op_gtr (struct type *expect_type, + struct expression *exp, + enum noside noside, enum exp_opcode op, + struct value *arg1, + struct value *arg2); +extern struct value *eval_op_geq (struct type *expect_type, + struct expression *exp, + enum noside noside, enum exp_opcode op, + struct value *arg1, + struct value *arg2); +extern struct value *eval_op_leq (struct type *expect_type, + struct expression *exp, + enum noside noside, enum exp_opcode op, + struct value *arg1, + struct value *arg2); namespace expr { @@ -1128,6 +1158,36 @@ public: enum noside noside) override; }; +/* Implementation of comparison operations. */ +template<enum exp_opcode OP, binary_ftype FUNC> +class comparison_operation + : public usual_ax_binop_operation<OP, FUNC> +{ +public: + + using usual_ax_binop_operation<OP, FUNC>::usual_ax_binop_operation; + + value *evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) override + { + value *lhs + = std::get<0> (this->m_storage)->evaluate (nullptr, exp, noside); + value *rhs + = std::get<1> (this->m_storage)->evaluate (value_type (lhs), exp, + noside); + return FUNC (expect_type, exp, noside, OP, lhs, rhs); + } +}; + +using equal_operation = comparison_operation<BINOP_EQUAL, eval_op_equal>; +using notequal_operation + = comparison_operation<BINOP_NOTEQUAL, eval_op_notequal>; +using less_operation = comparison_operation<BINOP_LESS, eval_op_less>; +using gtr_operation = comparison_operation<BINOP_GTR, eval_op_gtr>; +using geq_operation = comparison_operation<BINOP_GEQ, eval_op_geq>; +using leq_operation = comparison_operation<BINOP_LEQ, eval_op_leq>; + } /* namespace expr */ #endif /* EXPOP_H */ |