hokein created this revision.
hokein added a reviewer: ilya-biryukov.
Herald added subscribers: ioeric, jkorous-apple, klimek.
DeclrationAndMacrosFinder will find some declarations (not macro!) that are
referened inside the macro somehow, isSearchedLocation() is not sufficient, we
don't know whether the searched source location is macro or not.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D44293
Files:
clangd/XRefs.cpp
unittests/clangd/XRefsTests.cpp
Index: unittests/clangd/XRefsTests.cpp
===================================================================
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -213,6 +213,15 @@
#undef macro
)cpp",
+ R"cpp(// Macro
+ class TTT { public: int a; };
+ #define [[FF(S) if (int b = S.a) {}]]
+ void f() {
+ TTT t;
+ F^F(t);
+ }
+ )cpp",
+
R"cpp(// Forward class declaration
class Foo;
[[class Foo {}]];
Index: clangd/XRefs.cpp
===================================================================
--- clangd/XRefs.cpp
+++ clangd/XRefs.cpp
@@ -197,19 +197,21 @@
indexTopLevelDecls(AST.getASTContext(), AST.getTopLevelDecls(),
DeclMacrosFinder, IndexOpts);
- std::vector<const Decl *> Decls = DeclMacrosFinder->takeDecls();
std::vector<MacroDecl> MacroInfos = DeclMacrosFinder->takeMacroInfos();
+ if (!MacroInfos.empty()) {
+ for (auto Item : MacroInfos) {
+ SourceRange SR(Item.Info->getDefinitionLoc(),
+ Item.Info->getDefinitionEndLoc());
+ auto L = getDeclarationLocation(AST, SR);
+ if (L)
+ Result.push_back(*L);
+ }
- for (auto Item : Decls) {
- auto L = getDeclarationLocation(AST, Item->getSourceRange());
- if (L)
- Result.push_back(*L);
+ return Result;
}
- for (auto Item : MacroInfos) {
- SourceRange SR(Item.Info->getDefinitionLoc(),
- Item.Info->getDefinitionEndLoc());
- auto L = getDeclarationLocation(AST, SR);
+ for (auto Item : DeclMacrosFinder->takeDecls()) {
+ auto L = getDeclarationLocation(AST, Item->getSourceRange());
if (L)
Result.push_back(*L);
}
Index: unittests/clangd/XRefsTests.cpp
===================================================================
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -213,6 +213,15 @@
#undef macro
)cpp",
+ R"cpp(// Macro
+ class TTT { public: int a; };
+ #define [[FF(S) if (int b = S.a) {}]]
+ void f() {
+ TTT t;
+ F^F(t);
+ }
+ )cpp",
+
R"cpp(// Forward class declaration
class Foo;
[[class Foo {}]];
Index: clangd/XRefs.cpp
===================================================================
--- clangd/XRefs.cpp
+++ clangd/XRefs.cpp
@@ -197,19 +197,21 @@
indexTopLevelDecls(AST.getASTContext(), AST.getTopLevelDecls(),
DeclMacrosFinder, IndexOpts);
- std::vector<const Decl *> Decls = DeclMacrosFinder->takeDecls();
std::vector<MacroDecl> MacroInfos = DeclMacrosFinder->takeMacroInfos();
+ if (!MacroInfos.empty()) {
+ for (auto Item : MacroInfos) {
+ SourceRange SR(Item.Info->getDefinitionLoc(),
+ Item.Info->getDefinitionEndLoc());
+ auto L = getDeclarationLocation(AST, SR);
+ if (L)
+ Result.push_back(*L);
+ }
- for (auto Item : Decls) {
- auto L = getDeclarationLocation(AST, Item->getSourceRange());
- if (L)
- Result.push_back(*L);
+ return Result;
}
- for (auto Item : MacroInfos) {
- SourceRange SR(Item.Info->getDefinitionLoc(),
- Item.Info->getDefinitionEndLoc());
- auto L = getDeclarationLocation(AST, SR);
+ for (auto Item : DeclMacrosFinder->takeDecls()) {
+ auto L = getDeclarationLocation(AST, Item->getSourceRange());
if (L)
Result.push_back(*L);
}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits