diff --git a/include/cppast/cpp_entity_kind.hpp b/include/cppast/cpp_entity_kind.hpp index 9f7b81b..68f672d 100644 --- a/include/cppast/cpp_entity_kind.hpp +++ b/include/cppast/cpp_entity_kind.hpp @@ -38,6 +38,8 @@ namespace cppast function_t, member_function_t, conversion_op_t, + constructor_t, + destructor_t, count, }; diff --git a/include/cppast/cpp_member_function.hpp b/include/cppast/cpp_member_function.hpp index f61a6d3..c2a330e 100644 --- a/include/cppast/cpp_member_function.hpp +++ b/include/cppast/cpp_member_function.hpp @@ -169,6 +169,91 @@ namespace cppast bool explicit_; }; + + /// A [cppast::cpp_entity]() modelling a C++ constructor. + class cpp_constructor final : public cpp_function_base + { + public: + /// Builder for [cppast::cpp_constructor](). + class builder : public basic_builder + { + public: + using basic_builder::basic_builder; + + /// \effects Marks the constructor `explicit`. + void is_explicit() noexcept + { + function->explicit_ = true; + } + + /// \effects Marks the constructor `constexpr`. + void is_constexpr() noexcept + { + function->constexpr_ = true; + } + }; + + /// \returns Whether or not the constructor is `explicit`. + bool is_explicit() const noexcept + { + return explicit_; + } + + /// \returns Whether or not the constructor is `constexpr`. + bool is_constexpr() const noexcept + { + return constexpr_; + } + + private: + cpp_constructor(std::string name) + : cpp_function_base(std::move(name)), explicit_(false), constexpr_(false) + { + } + + cpp_entity_kind do_get_entity_kind() const noexcept override; + + bool explicit_; + bool constexpr_; + }; + + /// A [cppast::cpp_entity]() modelling a C++ destructor. + class cpp_destructor final : public cpp_function_base + { + public: + /// Builds a [cppast::cpp_destructor](). + class builder : public basic_builder + { + public: + using basic_builder::basic_builder; + + /// \effects Sets the `virtual`-ness of the destructor. + void virtual_info(cpp_virtual virt) noexcept + { + function->virtual_ = virt; + } + + private: + using basic_builder::add_parameter; + using basic_builder::is_variadic; + }; + + /// \returns The `virtual`-ness of the constructor. + cpp_virtual virtual_info() const noexcept + { + return virtual_; + } + + private: + cpp_destructor(std::string name) + : cpp_function_base(std::move(name)), virtual_(cpp_virtual_none) + { + } + + cpp_entity_kind do_get_entity_kind() const noexcept override; + + cpp_virtual virtual_; + }; } // namespace cppast #endif // CPPAST_CPP_MEMBER_FUNCTION_HPP_INCLUDED diff --git a/src/cpp_entity_kind.cpp b/src/cpp_entity_kind.cpp index 20e44f9..4577978 100644 --- a/src/cpp_entity_kind.cpp +++ b/src/cpp_entity_kind.cpp @@ -55,6 +55,10 @@ const char* cppast::to_string(cpp_entity_kind kind) noexcept return "member function"; case cpp_entity_kind::conversion_op_t: return "conversion operator"; + case cpp_entity_kind::constructor_t: + return "constructor"; + case cpp_entity_kind::destructor_t: + return "destructor"; case cpp_entity_kind::count: break; @@ -88,6 +92,8 @@ bool cppast::is_type(cpp_entity_kind kind) noexcept case cpp_entity_kind::function_t: case cpp_entity_kind::member_function_t: case cpp_entity_kind::conversion_op_t: + case cpp_entity_kind::constructor_t: + case cpp_entity_kind::destructor_t: case cpp_entity_kind::count: break; } diff --git a/src/cpp_member_function.cpp b/src/cpp_member_function.cpp index 2f012f2..ed8d108 100644 --- a/src/cpp_member_function.cpp +++ b/src/cpp_member_function.cpp @@ -17,3 +17,13 @@ cpp_entity_kind cpp_conversion_op::do_get_entity_kind() const noexcept { return cpp_entity_kind::conversion_op_t; } + +cpp_entity_kind cpp_constructor::do_get_entity_kind() const noexcept +{ + return cpp_entity_kind::constructor_t; +} + +cpp_entity_kind cpp_destructor::do_get_entity_kind() const noexcept +{ + return cpp_entity_kind::destructor_t; +} diff --git a/src/visitor.cpp b/src/visitor.cpp index f576eef..6b2a3bb 100644 --- a/src/visitor.cpp +++ b/src/visitor.cpp @@ -55,6 +55,8 @@ bool detail::visit(const cpp_entity& e, detail::visitor_callback_t cb, void* fun return handle_container(e, cb, functor); case cpp_entity_kind::conversion_op_t: return handle_container(e, cb, functor); + case cpp_entity_kind::constructor_t: + return handle_container(e, cb, functor); case cpp_entity_kind::namespace_alias_t: case cpp_entity_kind::using_directive_t: @@ -67,6 +69,7 @@ bool detail::visit(const cpp_entity& e, detail::visitor_callback_t cb, void* fun case cpp_entity_kind::member_variable_t: case cpp_entity_kind::bitfield_t: case cpp_entity_kind::function_parameter_t: + case cpp_entity_kind::destructor_t: return cb(functor, e, visitor_info::leaf_entity); case cpp_entity_kind::count: