Browse Source

All headers should now be included when finding usages of an override method

merge-requests/365/head
eidheim 8 years ago
parent
commit
7676381de3
  1. 2
      libclangmm
  2. 47
      src/usages_clang.cc
  3. 4
      src/usages_clang.h
  4. 2
      tests/usages_clang_test.cc

2
libclangmm

@ -1 +1 @@
Subproject commit ee37617c5723da334fa8f7867a6028f7ea50872f
Subproject commit 997d02a8de78ff879577a3522e1de5ebec9802e7

47
src/usages_clang.cc

@ -141,7 +141,12 @@ std::vector<Usages::Clang::Usages> 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::PathSet, Usages::Clang::PathSet> Usages::Clang::find_potential_paths(const boost::filesystem::path &path, const boost::filesystem::path &project_path,
std::pair<Usages::Clang::PathSet, Usages::Clang::PathSet> Usages::Clang::find_potential_paths(const PathSet &paths, const boost::filesystem::path &project_path,
const std::map<boost::filesystem::path, PathSet> &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;
}
}
}

4
src/usages_clang.h

@ -138,9 +138,11 @@ namespace Usages {
static std::pair<std::map<boost::filesystem::path, PathSet>, 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<boost::filesystem::path, PathSet> &paths_includes);
static std::pair<Clang::PathSet, Clang::PathSet> 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<Clang::PathSet, Clang::PathSet> find_potential_paths(const PathSet &paths, const boost::filesystem::path &project_path,
const std::map<boost::filesystem::path, PathSet> &paths_includes, const PathSet &paths_with_spelling);
static void write_cache(const boost::filesystem::path &path, const Cache &cache);

2
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);

Loading…
Cancel
Save