[PATCH 096/203] Introduce concat_operation

Tom Tromey
2021-01-01T21:48:32Z

This adds class concat_operation, which implements BINOP_CONCAT.

gdb/ChangeLog
2021-01-01 Tom Tromey <tom@tromey.com>

* expop.h (class concat_operation): New.
* eval.c (eval_op_concat): No longer static. Remove "op"
parameter.
(evaluate_subexp_standard): Update.
---
gdb/ChangeLog | 7 +++++++
gdb/eval.c | 11 +++++------
gdb/expop.h | 26 ++++++++++++++++++++++++++
3 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/gdb/eval.c b/gdb/eval.c
index 3aa362db66c..3942e4afaf2 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1298,15 +1298,14 @@ eval_op_objc_selector (struct type *expect_type, struct expression *exp,
lookup_child_selector (exp->gdbarch, sel));
}

-static struct value *
+struct value *
eval_op_concat (struct type *expect_type, struct expression *exp,
- enum noside noside,
- enum exp_opcode op, struct value *arg1, struct value *arg2)
+ enum noside noside, struct value *arg1, struct value *arg2)
{
if (noside == EVAL_SKIP)
return eval_skip_value (exp);
- if (binop_user_defined_p (op, arg1, arg2))
- return value_x_binop (arg1, arg2, op, OP_NULL, noside);
+ if (binop_user_defined_p (BINOP_CONCAT, arg1, arg2))
+ return value_x_binop (arg1, arg2, BINOP_CONCAT, OP_NULL, noside);
else
return value_concat (arg1, arg2);
}
@@ -2766,7 +2765,7 @@ evaluate_subexp_standard (struct type *expect_type,
case BINOP_CONCAT:
arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
- return eval_op_concat (expect_type, exp, noside, op, arg1, arg2);
+ return eval_op_concat (expect_type, exp, noside, arg1, arg2);

case BINOP_ASSIGN:
arg1 = evaluate_subexp (nullptr, exp, pos, noside);
diff --git a/gdb/expop.h b/gdb/expop.h
index bfb8f1db6f8..9b7119b9e92 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -83,6 +83,10 @@ extern struct value *eval_op_member (struct type *expect_type,
struct expression *exp,
enum noside noside,
struct value *arg1, struct value *arg2);
+extern struct value *eval_op_concat (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside,
+ struct value *arg1, struct value *arg2);

namespace expr
{
@@ -924,6 +928,28 @@ class structop_mptr_operation
{ return STRUCTOP_MPTR; }
};

+class concat_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_with_coercion (exp, noside);
+ value *rhs
+ = std::get<1> (m_storage)->evaluate_with_coercion (exp, noside);
+ return eval_op_concat (expect_type, exp, noside, lhs, rhs);
+ }
+
+ enum exp_opcode opcode () const override
+ { return BINOP_CONCAT; }
+};
+
} /* namespace expr */

#endif /* EXPOP_H */
--
2.26.2