Add cpp_constructor and cpp_destructor

This commit is contained in:
Jonathan Müller 2017-01-24 21:27:41 +01:00
commit 7c896453b5
5 changed files with 106 additions and 0 deletions

View file

@ -38,6 +38,8 @@ namespace cppast
function_t,
member_function_t,
conversion_op_t,
constructor_t,
destructor_t,
count,
};

View file

@ -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<cpp_constructor>
{
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<cpp_destructor>
{
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

View file

@ -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;
}

View file

@ -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;
}

View file

@ -55,6 +55,8 @@ bool detail::visit(const cpp_entity& e, detail::visitor_callback_t cb, void* fun
return handle_container<cpp_member_function>(e, cb, functor);
case cpp_entity_kind::conversion_op_t:
return handle_container<cpp_conversion_op>(e, cb, functor);
case cpp_entity_kind::constructor_t:
return handle_container<cpp_constructor>(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: