Add cpp_scope_name to support templated scopes

This commit is contained in:
Jonathan Müller 2017-04-13 11:58:52 +02:00
commit 06cf090b35
7 changed files with 75 additions and 15 deletions

View file

@ -6,9 +6,38 @@
#include <cppast/cpp_entity_index.hpp>
#include <cppast/cpp_entity_kind.hpp>
#include <cppast/cpp_template.hpp>
using namespace cppast;
cpp_scope_name::cpp_scope_name(type_safe::object_ref<const cpp_entity> entity) : entity_(entity)
{
if (cppast::is_templated(*entity))
{
auto& templ = static_cast<const cpp_template&>(entity->parent().value());
if (!templ.parameters().empty())
templ_ = type_safe::ref(templ);
}
else if (is_template(entity->kind()))
{
auto& templ = static_cast<const cpp_template&>(*entity);
if (!templ.parameters().empty())
templ_ = type_safe::ref(templ);
}
}
const std::string& cpp_scope_name::name() const noexcept
{
return entity_->name();
}
detail::iteratable_intrusive_list<cpp_template_parameter> cpp_scope_name::template_parameters()
const noexcept
{
DEBUG_ASSERT(is_templated(), detail::precondition_error_handler{});
return templ_.value().parameters();
}
cpp_entity_kind cpp_unexposed_entity::kind() noexcept
{
return cpp_entity_kind::unexposed_t;

View file

@ -38,7 +38,9 @@ cpp_entity_kind cpp_enum::do_get_entity_kind() const noexcept
return kind();
}
type_safe::optional<std::string> cpp_enum::do_get_scope_name() const
type_safe::optional<cpp_scope_name> cpp_enum::do_get_scope_name() const
{
return scoped_ ? type_safe::make_optional(name()) : type_safe::nullopt;
if (scoped_)
return type_safe::ref(*this);
return type_safe::nullopt;
}