From 292382f47ef08c5ec3292c612f737fe4b312c9f1 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 8 Mar 2021 07:27:57 -0700 Subject: Introduce unop_cast_type_operation This adds class unop_cast_type_operation, which implements UNOP_CAST_TYPE. gdb/ChangeLog 2021-03-08 Tom Tromey * expop.h (class unop_cast_type_operation): New. * ax-gdb.c (unop_cast_type_operation::do_generate_ax): New method. --- gdb/ChangeLog | 6 ++++++ gdb/ax-gdb.c | 12 ++++++++++++ gdb/expop.h | 31 +++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) (limited to 'gdb') diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8d1bbf0..609e91f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2021-03-08 Tom Tromey + * expop.h (class unop_cast_type_operation): New. + * ax-gdb.c (unop_cast_type_operation::do_generate_ax): New + method. + +2021-03-08 Tom Tromey + * expop.h (class unop_cast_operation): New. * ax-gdb.c (unop_cast_operation::do_generate_ax): New method. diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index 84887da..e0970e8 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -2661,6 +2661,18 @@ assign_modify_operation::do_generate_ax (struct expression *exp, "may not assign to it"), name); } +void +unop_cast_type_operation::do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) +{ + struct value *val + = std::get<0> (m_storage)->evaluate (nullptr, exp, + EVAL_AVOID_SIDE_EFFECTS); + std::get<1> (m_storage)->generate_ax (exp, ax, value, value_type (val)); +} + } /* This handles the middle-to-right-side of code generation for binary diff --git a/gdb/expop.h b/gdb/expop.h index abd5f64..1d1ce0b 100644 --- a/gdb/expop.h +++ b/gdb/expop.h @@ -1864,6 +1864,37 @@ protected: override; }; +/* A cast, but the type comes from an expression, not a "struct + type". */ +class unop_cast_type_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 *val = std::get<0> (m_storage)->evaluate (nullptr, exp, + EVAL_AVOID_SIDE_EFFECTS); + return std::get<1> (m_storage)->evaluate_for_cast (value_type (val), + exp, noside); + } + + enum exp_opcode opcode () const override + { return UNOP_CAST_TYPE; } + +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 */ -- cgit v1.1