From b54410cab29d4eda48472176f853e8fe838eaec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Sat, 21 Jan 2017 13:30:53 +0100 Subject: [PATCH] Add cpp_using_directive --- include/cppast/cpp_entity_type.hpp | 1 + include/cppast/cpp_namespace.hpp | 39 ++++++++++++++++++++++++++++++ src/cpp_entity_type.cpp | 1 + src/cpp_namespace.cpp | 5 ++++ 4 files changed, 46 insertions(+) diff --git a/include/cppast/cpp_entity_type.hpp b/include/cppast/cpp_entity_type.hpp index 34f673f..6f1f230 100644 --- a/include/cppast/cpp_entity_type.hpp +++ b/include/cppast/cpp_entity_type.hpp @@ -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](). diff --git a/include/cppast/cpp_namespace.hpp b/include/cppast/cpp_namespace.hpp index af0286b..7df1e41 100644 --- a/include/cppast/cpp_namespace.hpp +++ b/include/cppast/cpp_namespace.hpp @@ -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 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 build(const cpp_namespace_ref& target) + { + return std::unique_ptr(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 diff --git a/src/cpp_entity_type.cpp b/src/cpp_entity_type.cpp index b0bef71..4a0ef71 100644 --- a/src/cpp_entity_type.cpp +++ b/src/cpp_entity_type.cpp @@ -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; } diff --git a/src/cpp_namespace.cpp b/src/cpp_namespace.cpp index 0667433..13501c7 100644 --- a/src/cpp_namespace.cpp +++ b/src/cpp_namespace.cpp @@ -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; +}