From: Tom Tromey Date: Mon, 8 Mar 2021 14:27:57 +0000 (-0700) Subject: Introduce binop_operation X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=373907ffb2db9232af14d2a7e4433f41cc1fc56c;p=binutils-gdb.git Introduce binop_operation This adds two new template classes, binop_operation and usual_ax_binop_operation, and then uses these to implement a number of binary operations that follow similar patterns. gdb/ChangeLog 2021-03-08 Tom Tromey * expop.h (class binop_operation, class usual_ax_binop_operation): New. (exp_operation, intdiv_operation, mod_operation, mul_operation) (div_operation, rem_operation, lsh_operation, rsh_operation) (bitwise_and_operation, bitwise_ior_operation) (bitwise_xor_operation): New typedefs. * eval.c (eval_op_binary): No longer static. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 50a933a3a28..0ed474f176c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2021-03-08 Tom Tromey + + * expop.h (class binop_operation, class usual_ax_binop_operation): + New. + (exp_operation, intdiv_operation, mod_operation, mul_operation) + (div_operation, rem_operation, lsh_operation, rsh_operation) + (bitwise_and_operation, bitwise_ior_operation) + (bitwise_xor_operation): New typedefs. + * eval.c (eval_op_binary): No longer static. + 2021-03-08 Tom Tromey * expop.h (class sub_operation): New. diff --git a/gdb/eval.c b/gdb/eval.c index 87c8b0d69e0..6fde03d3522 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1511,7 +1511,7 @@ eval_op_sub (struct type *expect_type, struct expression *exp, /* Helper function for several different binary operations. */ -static struct value * +struct value * eval_op_binary (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 c996d520809..4624c2fdefe 100644 --- a/gdb/expop.h +++ b/gdb/expop.h @@ -96,6 +96,10 @@ extern struct value *eval_op_sub (struct type *expect_type, struct expression *exp, enum noside noside, struct value *arg1, struct value *arg2); +extern struct value *eval_op_binary (struct type *expect_type, + struct expression *exp, + enum noside noside, enum exp_opcode op, + struct value *arg1, struct value *arg2); namespace expr { @@ -1041,6 +1045,73 @@ protected: } }; +typedef struct value *binary_ftype (struct type *expect_type, + struct expression *exp, + enum noside noside, enum exp_opcode op, + struct value *arg1, struct value *arg2); + +template +class binop_operation + : public maybe_constant_operation +{ +public: + + using maybe_constant_operation::maybe_constant_operation; + + value *evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) override + { + value *lhs + = std::get<0> (m_storage)->evaluate (nullptr, exp, noside); + value *rhs + = std::get<1> (m_storage)->evaluate (nullptr, exp, noside); + return FUNC (expect_type, exp, noside, OP, lhs, rhs); + } + + enum exp_opcode opcode () const override + { return OP; } +}; + +template +class usual_ax_binop_operation + : public binop_operation +{ +public: + + using binop_operation::binop_operation; + +protected: + + void do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) + override + { + gen_expr_binop (exp, OP, + std::get<0> (this->m_storage).get (), + std::get<1> (this->m_storage).get (), + ax, value); + } +}; + +using exp_operation = binop_operation; +using intdiv_operation = binop_operation; +using mod_operation = binop_operation; + +using mul_operation = usual_ax_binop_operation; +using div_operation = usual_ax_binop_operation; +using rem_operation = usual_ax_binop_operation; +using lsh_operation = usual_ax_binop_operation; +using rsh_operation = usual_ax_binop_operation; +using bitwise_and_operation + = usual_ax_binop_operation; +using bitwise_ior_operation + = usual_ax_binop_operation; +using bitwise_xor_operation + = usual_ax_binop_operation; + } /* namespace expr */ #endif /* EXPOP_H */