From d0451c517b5dfb77dcb37edc23c11d7c3faf5727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Wed, 12 Apr 2017 15:17:30 +0200 Subject: [PATCH] Skip templated and friended entities in tool --- include/cppast/cpp_entity.hpp | 4 ++++ include/cppast/cpp_friend.hpp | 4 ---- tool/main.cpp | 8 +++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/cppast/cpp_entity.hpp b/include/cppast/cpp_entity.hpp index e54f605..f955609 100644 --- a/include/cppast/cpp_entity.hpp +++ b/include/cppast/cpp_entity.hpp @@ -159,6 +159,10 @@ namespace cppast /// \notes Do not use this entity other to read information from the template entity. bool is_templated(const cpp_entity& e) noexcept; + /// \returns Whether or not the given entity is "friended", + /// that is, its declaration exists as part of a [cppast::cpp_friend]() declaration. + bool is_friended(const cpp_entity& e) noexcept; + /// \returns The full name of the [cppast::cpp_entity](), with all scopes. /// \notes Enitites without a name ([cppast::cpp_using_declaration]() etc.) do not have a full name either. /// \notes For (template) parameters the full name is the name itself. diff --git a/include/cppast/cpp_friend.hpp b/include/cppast/cpp_friend.hpp index 5e927cf..d0b605c 100644 --- a/include/cppast/cpp_friend.hpp +++ b/include/cppast/cpp_friend.hpp @@ -67,10 +67,6 @@ namespace cppast friend cpp_entity_container; }; - - /// \returns Whether or not the given entity is "friended", - /// that is, its declaration exists as part of a [cppast::cpp_friend]() declaration. - bool is_friended(const cpp_entity& e) noexcept; } // namespace cppast #endif // CPPAST_CPP_FRIEND_HPP_INCLUDED diff --git a/tool/main.cpp b/tool/main.cpp index 65d5a90..6c3cbef 100644 --- a/tool/main.cpp +++ b/tool/main.cpp @@ -133,9 +133,11 @@ void print_ast(std::ostream& out, const cppast::cpp_file& file) std::string prefix; // the current prefix string // recursively visit file and all children cppast::visit(file, [&](const cppast::cpp_entity& e, cppast::visitor_info info) { - if (e.kind() == cppast::cpp_entity_kind::file_t) - // no need to do anything for a file - // return value of true continues visit + if (e.kind() == cppast::cpp_entity_kind::file_t || cppast::is_templated(e) + || cppast::is_friended(e)) + // no need to do anything for a file, + // templated and friended entities are just proxies, so skip those as well + // return true to continue visit for children return true; else if (info.event == cppast::visitor_info::container_entity_exit) {