From 46916f2bcbaf4532aab9fecb2344330710129ffa Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 8 Mar 2021 07:27:57 -0700 Subject: [PATCH] Implement binary comparison operations This implements the binary comparison operations via a template class. gdb/ChangeLog 2021-03-08 Tom Tromey * 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. --- gdb/ChangeLog | 8 +++++++ gdb/eval.c | 12 +++++------ gdb/expop.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 6 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b84ebfb1ec7..1f3287aefb3 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2021-03-08 Tom Tromey + + * 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. + 2021-03-08 Tom Tromey * expop.h (class subscript_operation): New. diff --git a/gdb/eval.c b/gdb/eval.c index 056daa05160..83d0147f96e 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1594,7 +1594,7 @@ eval_op_subscript (struct type *expect_type, struct expression *exp, /* A helper function for BINOP_EQUAL. */ -static struct value * +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) @@ -1617,7 +1617,7 @@ eval_op_equal (struct type *expect_type, struct expression *exp, /* A helper function for BINOP_NOTEQUAL. */ -static struct value * +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) @@ -1640,7 +1640,7 @@ eval_op_notequal (struct type *expect_type, struct expression *exp, /* A helper function for BINOP_LESS. */ -static struct value * +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) @@ -1663,7 +1663,7 @@ eval_op_less (struct type *expect_type, struct expression *exp, /* A helper function for BINOP_GTR. */ -static struct value * +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) @@ -1686,7 +1686,7 @@ eval_op_gtr (struct type *expect_type, struct expression *exp, /* A helper function for BINOP_GEQ. */ -static struct value * +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) @@ -1709,7 +1709,7 @@ eval_op_geq (struct type *expect_type, struct expression *exp, /* A helper function for BINOP_LEQ. */ -static struct value * +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) diff --git a/gdb/expop.h b/gdb/expop.h index 5c3b0afee55..af378d011f8 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 +class comparison_operation + : public usual_ax_binop_operation +{ +public: + + using usual_ax_binop_operation::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; +using notequal_operation + = comparison_operation; +using less_operation = comparison_operation; +using gtr_operation = comparison_operation; +using geq_operation = comparison_operation; +using leq_operation = comparison_operation; + } /* namespace expr */ #endif /* EXPOP_H */ -- 2.30.2