From 7676381de33a25f91a34cbc3e75bdc19a07bc185 Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 15 Jan 2018 06:40:56 +0100 Subject: [PATCH] All headers should now be included when finding usages of an override method --- libclangmm | 2 +- src/usages_clang.cc | 47 +++++++++++++++++++++++--------------- src/usages_clang.h | 4 +++- tests/usages_clang_test.cc | 2 +- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/libclangmm b/libclangmm index ee37617..997d02a 160000 --- a/libclangmm +++ b/libclangmm @@ -1 +1 @@ -Subproject commit ee37617c5723da334fa8f7867a6028f7ea50872f +Subproject commit 997d02a8de78ff879577a3522e1de5ebec9802e7 diff --git a/src/usages_clang.cc b/src/usages_clang.cc index 7edd638..e59bc9d 100644 --- a/src/usages_clang.cc +++ b/src/usages_clang.cc @@ -141,7 +141,12 @@ std::vector Usages::Clang::get_usages(const boost::filesy auto paths = find_paths(project_path, build_path, debug_path); auto pair = parse_paths(spelling, paths); - auto pair2 = find_potential_paths(cursor.get_canonical().get_source_location().get_path(), project_path, pair.first, pair.second); + PathSet all_cursors_paths; + auto canonical=cursor.get_canonical(); + all_cursors_paths.emplace(canonical.get_source_location().get_path()); + for(auto &cursor: canonical.get_all_overridden_cursors()) + all_cursors_paths.emplace(cursor.get_source_location().get_path()); + auto pair2 = find_potential_paths(all_cursors_paths, project_path, pair.first, pair.second); auto &potential_paths = pair2.first; auto &all_includes = pair2.second; @@ -642,29 +647,35 @@ Usages::Clang::PathSet Usages::Clang::get_all_includes(const boost::filesystem:: return all_includes; } -std::pair Usages::Clang::find_potential_paths(const boost::filesystem::path &path, const boost::filesystem::path &project_path, +std::pair Usages::Clang::find_potential_paths(const PathSet &paths, const boost::filesystem::path &project_path, const std::map &paths_includes, const PathSet &paths_with_spelling) { PathSet potential_paths; PathSet all_includes; - if(filesystem::file_in_path(path, project_path)) { - for(auto &path_with_spelling : paths_with_spelling) { - auto path_all_includes = get_all_includes(path_with_spelling, paths_includes); - if((path_all_includes.find(path) != path_all_includes.end() || path_with_spelling == path)) { - potential_paths.emplace(path_with_spelling); - - for(auto &include : path_all_includes) - all_includes.emplace(include); + bool first=true; + for(auto &path: paths) { + if(filesystem::file_in_path(path, project_path)) { + for(auto &path_with_spelling : paths_with_spelling) { + auto path_all_includes = get_all_includes(path_with_spelling, paths_includes); + if((path_all_includes.find(path) != path_all_includes.end() || path_with_spelling == path)) { + potential_paths.emplace(path_with_spelling); + + for(auto &include : path_all_includes) + all_includes.emplace(include); + } } } - } - else { - for(auto &path_with_spelling : paths_with_spelling) { - potential_paths.emplace(path_with_spelling); - - auto path_all_includes = get_all_includes(path_with_spelling, paths_includes); - for(auto &include : path_all_includes) - all_includes.emplace(include); + else { + if(first) { + for(auto &path_with_spelling : paths_with_spelling) { + potential_paths.emplace(path_with_spelling); + + auto path_all_includes = get_all_includes(path_with_spelling, paths_includes); + for(auto &include : path_all_includes) + all_includes.emplace(include); + } + first=false; + } } } diff --git a/src/usages_clang.h b/src/usages_clang.h index 46ab254..492a21c 100644 --- a/src/usages_clang.h +++ b/src/usages_clang.h @@ -138,9 +138,11 @@ namespace Usages { static std::pair, PathSet> parse_paths(const std::string &spelling, const PathSet &paths); + /// Recursively find and return all the include paths of path static PathSet get_all_includes(const boost::filesystem::path &path, const std::map &paths_includes); - static std::pair find_potential_paths(const boost::filesystem::path &project_path, const boost::filesystem::path &include_path, + /// Based on cursor paths, paths_includes and paths_with_spelling return potential paths that might contain the sought after symbol + static std::pair find_potential_paths(const PathSet &paths, const boost::filesystem::path &project_path, const std::map &paths_includes, const PathSet &paths_with_spelling); static void write_cache(const boost::filesystem::path &path, const Cache &cache); diff --git a/tests/usages_clang_test.cc b/tests/usages_clang_test.cc index 84545bc..c74b04d 100644 --- a/tests/usages_clang_test.cc +++ b/tests/usages_clang_test.cc @@ -81,7 +81,7 @@ int main() { assert(paths_with_spelling.find(project_path / "test.hpp") != paths_with_spelling.end()); assert(paths_with_spelling.find(project_path / "test2.hpp") != paths_with_spelling.end()); - auto pair2 = Usages::Clang::find_potential_paths(cursor.get_canonical().get_source_location().get_path(), project_path, pair.first, pair.second); + auto pair2 = Usages::Clang::find_potential_paths({cursor.get_canonical().get_source_location().get_path()}, project_path, pair.first, pair.second); auto &potential_paths = pair2.first; assert(potential_paths.size() == 3);