Parse cpp_namespace_alias

This commit is contained in:
Jonathan Müller 2017-02-22 11:04:34 +01:00
commit 45e9e5305b
9 changed files with 161 additions and 11 deletions

View file

@ -9,6 +9,14 @@
namespace cppast
{
enum class cpp_entity_kind;
/// \exclude
namespace detail
{
void check_entity_cast(const cpp_entity& e, cpp_entity_kind expected_kind);
} // namespace detail
/// A basic reference to some kind of [cppast::cpp_entity]().
template <typename T, typename Predicate>
class basic_cpp_entity_ref
@ -36,6 +44,9 @@ namespace cppast
type_safe::optional_ref<const T> get(const cpp_entity_index& idx) const noexcept
{
auto entity = idx.lookup(target_);
if (!entity)
return type_safe::nullopt;
detail::check_entity_cast(entity.value(), T::kind());
return static_cast<const T&>(entity.value());
}

View file

@ -88,12 +88,16 @@ namespace cppast
class cpp_namespace_alias final : public cpp_entity
{
public:
static cpp_entity_kind kind() noexcept;
/// \returns A newly created and registered namespace alias.
static std::unique_ptr<cpp_namespace_alias> build(const cpp_entity_index& idx,
cpp_entity_id id, std::string name,
cpp_namespace_ref target);
/// \returns The [cppast::cpp_namespace_ref]() to the aliased namespace.
/// \notes If the namespace aliases aliases another namespace alias,
/// the target entity will still be the namespace, not the alias.
const cpp_namespace_ref& target() const noexcept
{
return target_;