Add cpp_using_directive

This commit is contained in:
Jonathan Müller 2017-01-21 13:30:53 +01:00
commit b54410cab2
4 changed files with 46 additions and 0 deletions

View file

@ -16,6 +16,7 @@ namespace cppast
namespace_t,
namespace_alias_t,
using_directive_t,
};
/// \returns Whether or not a given entity type is one derived from [cppast::cpp_scope]().

View file

@ -78,6 +78,12 @@ namespace cppast
return name_;
}
/// \returns The [cppast::cpp_entity_id]() of the namespace it refers to.
const cpp_entity_id& id() const noexcept
{
return target_;
}
/// \returns The [cppast::cpp_namespace]() it refers to.
const cpp_namespace& get(const cpp_entity_index& idx) const noexcept;
@ -90,6 +96,7 @@ namespace cppast
class cpp_namespace_alias final : public cpp_entity
{
public:
/// \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)
@ -116,6 +123,38 @@ namespace cppast
cpp_namespace_ref target_;
};
/// A [cppast::cpp_entity]() modelling a using directive.
///
/// A using directive is `using namespace std`, for example.
class cpp_using_directive final : public cpp_entity
{
public:
/// \returns A newly created using directive.
/// \notes It is not meant to be registered at the [cppast::cpp_entity_index](),
/// as nothing can refer to it.
static std::unique_ptr<cpp_using_directive> build(const cpp_namespace_ref& target)
{
return std::unique_ptr<cpp_using_directive>(new cpp_using_directive(target));
}
/// \returns The [cppast::cpp_namespace_ref]() that is exposed.
/// \notes The name of the reference is the same as the name of this entity.
cpp_namespace_ref target() const
{
return {target_, name()};
}
private:
cpp_using_directive(const cpp_namespace_ref& target)
: cpp_entity(target.name()), target_(target.id())
{
}
cpp_entity_type do_get_entity_type() const noexcept override;
cpp_entity_id target_;
};
} // namespace cppast
#endif // CPPAST_CPP_NAMESPACE_HPP_INCLUDED

View file

@ -15,6 +15,7 @@ bool cppast::is_scope(cpp_entity_type type) noexcept
case cpp_entity_type::file_t:
case cpp_entity_type::namespace_alias_t:
case cpp_entity_type::using_directive_t:
break;
}

View file

@ -23,3 +23,8 @@ cpp_entity_type cpp_namespace_alias::do_get_entity_type() const noexcept
{
return cpp_entity_type::namespace_alias_t;
}
cpp_entity_type cpp_using_directive::do_get_entity_type() const noexcept
{
return cpp_entity_type::using_directive_t;
}