[PATCH] D20960: [include-fixer] Be smarter about inserting symbols for a prefix.
Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 3 07:14:07 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL271671: [include-fixer] Be smarter about inserting symbols for a prefix. (authored by d0k).
Changed prior to commit:
http://reviews.llvm.org/D20960?vs=59545&id=59550#toc
Repository:
rL LLVM
http://reviews.llvm.org/D20960
Files:
clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
clang-tools-extra/trunk/test/include-fixer/Inputs/fake_yaml_db.yaml
clang-tools-extra/trunk/test/include-fixer/prefix_variable.cpp
Index: clang-tools-extra/trunk/test/include-fixer/Inputs/fake_yaml_db.yaml
===================================================================
--- clang-tools-extra/trunk/test/include-fixer/Inputs/fake_yaml_db.yaml
+++ clang-tools-extra/trunk/test/include-fixer/Inputs/fake_yaml_db.yaml
@@ -43,3 +43,11 @@
LineNumber: 1
Type: Class
NumOccurrences: 3
+---
+Name: b
+Contexts:
+FilePath: var.h
+LineNumber: 1
+Type: Variable
+NumOccurrences: 1
+...
Index: clang-tools-extra/trunk/test/include-fixer/prefix_variable.cpp
===================================================================
--- clang-tools-extra/trunk/test/include-fixer/prefix_variable.cpp
+++ clang-tools-extra/trunk/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;
+}
Index: clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
===================================================================
--- clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
+++ clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
@@ -66,6 +66,7 @@
// 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 @@
// 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 @@
}
}
Names.pop_back();
+ TookPrefix = true;
}
return Results;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20960.59550.patch
Type: text/x-patch
Size: 2803 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160603/9016d177/attachment.bin>
More information about the cfe-commits
mailing list