[PATCH 119/203] Introduce unop_cast_operation

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

This adds class unop_cast_operation, which implements UNOP_CAST.

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

* expop.h (class unop_cast_operation): New.
* ax-gdb.c (unop_cast_operation::do_generate_ax): New method.
---
gdb/ChangeLog | 5 +++++
gdb/ax-gdb.c | 10 ++++++++++
gdb/expop.h | 28 ++++++++++++++++++++++++++++
3 files changed, 43 insertions(+)

diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index f81e5b9ad29..84887da524f 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -2514,6 +2514,16 @@ unop_sizeof_operation::do_generate_ax (struct expression *exp,
value->type = builtin_type (ax->gdbarch)->builtin_int;
}

+void
+unop_cast_operation::do_generate_ax (struct expression *exp,
+ struct agent_expr *ax,
+ struct axs_value *value,
+ struct type *cast_type)
+{
+ std::get<0> (m_storage)->generate_ax (exp, ax, value,
+ std::get<1> (m_storage));
+}
+
void
unop_memval_operation::do_generate_ax (struct expression *exp,
struct agent_expr *ax,
diff --git a/gdb/expop.h b/gdb/expop.h
index b0ed119a989..664812aec19 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -1825,6 +1825,34 @@ class assign_modify_operation
override;
};

+/* A type cast. */
+class unop_cast_operation
+ : public maybe_constant_operation<operation_up, struct type *>
+{
+public:
+
+ using maybe_constant_operation::maybe_constant_operation;
+
+ value *evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside) override
+ {
+ return std::get<0> (m_storage)->evaluate_for_cast (std::get<1> (m_storage),
+ exp, noside);
+ }
+
+ enum exp_opcode opcode () const override
+ { return UNOP_CAST; }
+
+protected:
+
+ void do_generate_ax (struct expression *exp,
+ struct agent_expr *ax,
+ struct axs_value *value,
+ struct type *cast_type)
+ override;
+};
+
} /* namespace expr */

#endif /* EXPOP_H */
--
2.26.2