From 9d60bd2992f090d3756a5eb779a011ae99511f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Sat, 21 Jan 2017 13:44:35 +0100 Subject: [PATCH] Add cpp_using_declaration --- include/cppast/cpp_entity_type.hpp | 1 + include/cppast/cpp_namespace.hpp | 37 +++++++++++++++++++++++++++++- src/cpp_entity_type.cpp | 1 + 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/include/cppast/cpp_entity_type.hpp b/include/cppast/cpp_entity_type.hpp index 8759456..684e9bf 100644 --- a/include/cppast/cpp_entity_type.hpp +++ b/include/cppast/cpp_entity_type.hpp @@ -17,6 +17,7 @@ namespace cppast namespace_t, namespace_alias_t, using_directive_t, + using_declaration_t, count, }; diff --git a/include/cppast/cpp_namespace.hpp b/include/cppast/cpp_namespace.hpp index 9c31b4a..94ad7ea 100644 --- a/include/cppast/cpp_namespace.hpp +++ b/include/cppast/cpp_namespace.hpp @@ -117,7 +117,7 @@ namespace cppast return std::unique_ptr(new cpp_using_directive(target)); } - /// \returns The [cppast::cpp_namespace_ref]() that is exposed. + /// \returns The [cppast::cpp_namespace_ref]() that is being used. /// \notes The name of the reference is the same as the name of this entity. cpp_namespace_ref target() const { @@ -137,6 +137,41 @@ namespace cppast cpp_entity_id target_; }; + + /// A [cppast::cpp_entity]() modelling a using declaration. + /// + /// A using declaration is `using std::vector`, for example. + class cpp_using_declaration final : public cpp_entity + { + public: + /// \returns A newly created using declaration. + /// \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_entity_ref& target) + { + return std::unique_ptr(new cpp_using_declaration(target)); + } + + /// \returns The [cppast::cpp_entity_ref]() that is being used. + /// \notes The name of the reference is the same as the name of this entity. + cpp_entity_ref target() const + { + return {target_, name()}; + } + + private: + cpp_using_declaration(const cpp_entity_ref& target) + : cpp_entity(target.name()), target_(target.id()) + { + } + + cpp_entity_type do_get_entity_type() const noexcept override + { + return cpp_entity_type::using_declaration_t; + } + + 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 bedde8d..83283fa 100644 --- a/src/cpp_entity_type.cpp +++ b/src/cpp_entity_type.cpp @@ -16,6 +16,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: + case cpp_entity_type::using_declaration_t: case cpp_entity_type::count: break; }