summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2016-06-03 14:07:38 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2016-06-03 14:07:38 +0000
commitb53452b2b1c8709054e5e2f0bf879c2bdd5fac6f (patch)
treefc1c9c7cdd9a0ba9ebc84b253c7a135a5286da49
parentd906bf13699ca115a27d78e2d42ab71c2e851fe1 (diff)
downloadbcm5719-llvm-b53452b2b1c8709054e5e2f0bf879c2bdd5fac6f.tar.gz
bcm5719-llvm-b53452b2b1c8709054e5e2f0bf879c2bdd5fac6f.zip
[include-fixer] Be smarter about inserting symbols for a prefix.
If prefix search finds something where nothing can be nested under (e.g. a variable or macro) don't add it to the result. This is for cases like: header.h: extern int a; file.cc: namespace a { SOME_MACRO } We will look up a::SOME_MACRO, which doesn't have any results. Then we look up 'a' and find something before we ever look up just 'SOME_MACRO'. With some basic filtering we can avoid this case. Differential Revision: http://reviews.llvm.org/D20960 llvm-svn: 271671
-rw-r--r--clang-tools-extra/include-fixer/SymbolIndexManager.cpp12
-rw-r--r--clang-tools-extra/test/include-fixer/Inputs/fake_yaml_db.yaml8
-rw-r--r--clang-tools-extra/test/include-fixer/prefix_variable.cpp11
3 files changed, 31 insertions, 0 deletions
diff --git a/clang-tools-extra/include-fixer/SymbolIndexManager.cpp b/clang-tools-extra/include-fixer/SymbolIndexManager.cpp
index 70b143f7428..b3ecca49289 100644
--- a/clang-tools-extra/include-fixer/SymbolIndexManager.cpp
+++ b/clang-tools-extra/include-fixer/SymbolIndexManager.cpp
@@ -66,6 +66,7 @@ SymbolIndexManager::search(llvm::StringRef Identifier) const {
// This is to support nested classes which aren't recorded in the database.
// Eventually we will either hit a class (namespaces aren't in the database
// either) and can report that result.
+ bool TookPrefix = false;
std::vector<std::string> Results;
while (Results.empty() && !Names.empty()) {
std::vector<clang::find_all_symbols::SymbolInfo> Symbols;
@@ -109,6 +110,16 @@ SymbolIndexManager::search(llvm::StringRef Identifier) const {
// FIXME: Support full match. At this point, we only find symbols in
// database which end with the same contexts with the identifier.
if (IsMatched && IdentiferContext == Names.rend()) {
+ // If we're in a situation where we took a prefix but the thing we
+ // found couldn't possibly have a nested member ignore it.
+ if (TookPrefix &&
+ (Symbol.getSymbolKind() == SymbolInfo::SymbolKind::Function ||
+ Symbol.getSymbolKind() == SymbolInfo::SymbolKind::Variable ||
+ Symbol.getSymbolKind() ==
+ SymbolInfo::SymbolKind::EnumConstantDecl ||
+ Symbol.getSymbolKind() == SymbolInfo::SymbolKind::Macro))
+ continue;
+
// FIXME: file path should never be in the form of <...> or "...", but
// the unit test with fixed database use <...> file path, which might
// need to be changed.
@@ -122,6 +133,7 @@ SymbolIndexManager::search(llvm::StringRef Identifier) const {
}
}
Names.pop_back();
+ TookPrefix = true;
}
return Results;
diff --git a/clang-tools-extra/test/include-fixer/Inputs/fake_yaml_db.yaml b/clang-tools-extra/test/include-fixer/Inputs/fake_yaml_db.yaml
index 4d9c219150a..a2f991324f7 100644
--- a/clang-tools-extra/test/include-fixer/Inputs/fake_yaml_db.yaml
+++ b/clang-tools-extra/test/include-fixer/Inputs/fake_yaml_db.yaml
@@ -43,3 +43,11 @@ FilePath: ../include/zbar.h
LineNumber: 1
Type: Class
NumOccurrences: 3
+---
+Name: b
+Contexts:
+FilePath: var.h
+LineNumber: 1
+Type: Variable
+NumOccurrences: 1
+...
diff --git a/clang-tools-extra/test/include-fixer/prefix_variable.cpp b/clang-tools-extra/test/include-fixer/prefix_variable.cpp
new file mode 100644
index 00000000000..f2f565d4a81
--- /dev/null
+++ b/clang-tools-extra/test/include-fixer/prefix_variable.cpp
@@ -0,0 +1,11 @@
+// REQUIRES: shell
+// RUN: sed -e 's#//.*$##' %s > %t.cpp
+// RUN: clang-include-fixer -db=yaml -input=%p/Inputs/fake_yaml_db.yaml %t.cpp --
+// RUN: FileCheck %s -input-file=%t.cpp
+
+// CHECK-NOT: #include
+// CHECK: doesnotexist f;
+
+namespace b {
+doesnotexist f;
+}
OpenPOWER on IntegriCloud