From: Tom Tromey Date: Mon, 8 Mar 2021 14:27:57 +0000 (-0700) Subject: Implement C++ cast operations X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d9ad79d8800c18b70e90e9672b5085246e4fd537;p=binutils-gdb.git Implement C++ cast operations This adds class cxx_cast_operation, which is used to implement the C++ dynamic_cast and reinterpret_cast operations. gdb/ChangeLog 2021-03-08 Tom Tromey * expop.h (cxx_cast_ftype): New typedef. (cxx_cast_operation): New template. (dynamic_cast_operation, reinterpret_cast_operation): New typedefs. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 609e91f7cd5..053f9a919a1 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2021-03-08 Tom Tromey + + * expop.h (cxx_cast_ftype): New typedef. + (cxx_cast_operation): New template. + (dynamic_cast_operation, reinterpret_cast_operation): New + typedefs. + 2021-03-08 Tom Tromey * expop.h (class unop_cast_type_operation): New. diff --git a/gdb/expop.h b/gdb/expop.h index 1d1ce0b664a..3ab412e35a1 100644 --- a/gdb/expop.h +++ b/gdb/expop.h @@ -1895,6 +1895,40 @@ protected: override; }; +typedef value *cxx_cast_ftype (struct type *, value *); + +/* This implements dynamic_cast and reinterpret_cast. static_cast and + const_cast are handled by the ordinary case operations. */ +template +class cxx_cast_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); + struct type *type = value_type (val); + value *rhs = std::get<1> (m_storage)->evaluate (type, exp, noside); + if (noside == EVAL_SKIP) + return eval_skip_value (exp); + return FUNC (type, rhs); + } + + enum exp_opcode opcode () const override + { return OP; } +}; + +using dynamic_cast_operation = cxx_cast_operation; +using reinterpret_cast_operation = cxx_cast_operation; + } /* namespace expr */ #endif /* EXPOP_H */