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 <tom@tromey.com> * 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.
This commit is contained in:
parent
5133d78b7b
commit
373907ffb2
3 changed files with 82 additions and 1 deletions
|
@ -1,3 +1,13 @@
|
||||||
|
2021-03-08 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* 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 <tom@tromey.com>
|
2021-03-08 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* expop.h (class sub_operation): New.
|
* expop.h (class sub_operation): New.
|
||||||
|
|
|
@ -1511,7 +1511,7 @@ eval_op_sub (struct type *expect_type, struct expression *exp,
|
||||||
|
|
||||||
/* Helper function for several different binary operations. */
|
/* Helper function for several different binary operations. */
|
||||||
|
|
||||||
static struct value *
|
struct value *
|
||||||
eval_op_binary (struct type *expect_type, struct expression *exp,
|
eval_op_binary (struct type *expect_type, struct expression *exp,
|
||||||
enum noside noside, enum exp_opcode op,
|
enum noside noside, enum exp_opcode op,
|
||||||
struct value *arg1, struct value *arg2)
|
struct value *arg1, struct value *arg2)
|
||||||
|
|
71
gdb/expop.h
71
gdb/expop.h
|
@ -96,6 +96,10 @@ extern struct value *eval_op_sub (struct type *expect_type,
|
||||||
struct expression *exp,
|
struct expression *exp,
|
||||||
enum noside noside,
|
enum noside noside,
|
||||||
struct value *arg1, struct value *arg2);
|
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
|
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<enum exp_opcode OP, binary_ftype FUNC>
|
||||||
|
class binop_operation
|
||||||
|
: public maybe_constant_operation<operation_up, operation_up>
|
||||||
|
{
|
||||||
|
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<enum exp_opcode OP, binary_ftype FUNC>
|
||||||
|
class usual_ax_binop_operation
|
||||||
|
: public binop_operation<OP, FUNC>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
using binop_operation<OP, FUNC>::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<BINOP_EXP, eval_op_binary>;
|
||||||
|
using intdiv_operation = binop_operation<BINOP_INTDIV, eval_op_binary>;
|
||||||
|
using mod_operation = binop_operation<BINOP_MOD, eval_op_binary>;
|
||||||
|
|
||||||
|
using mul_operation = usual_ax_binop_operation<BINOP_MUL, eval_op_binary>;
|
||||||
|
using div_operation = usual_ax_binop_operation<BINOP_DIV, eval_op_binary>;
|
||||||
|
using rem_operation = usual_ax_binop_operation<BINOP_REM, eval_op_binary>;
|
||||||
|
using lsh_operation = usual_ax_binop_operation<BINOP_LSH, eval_op_binary>;
|
||||||
|
using rsh_operation = usual_ax_binop_operation<BINOP_RSH, eval_op_binary>;
|
||||||
|
using bitwise_and_operation
|
||||||
|
= usual_ax_binop_operation<BINOP_BITWISE_AND, eval_op_binary>;
|
||||||
|
using bitwise_ior_operation
|
||||||
|
= usual_ax_binop_operation<BINOP_BITWISE_IOR, eval_op_binary>;
|
||||||
|
using bitwise_xor_operation
|
||||||
|
= usual_ax_binop_operation<BINOP_BITWISE_XOR, eval_op_binary>;
|
||||||
|
|
||||||
} /* namespace expr */
|
} /* namespace expr */
|
||||||
|
|
||||||
#endif /* EXPOP_H */
|
#endif /* EXPOP_H */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue