[libclang] Make clang_findReferencesInFile also work on macros (find all expansions/definition
of a macro in a file).
As a bonus, also make searching for declarations more efficient by ignoring
preprocessing entities when we know that we are looking for a declaration.
Fixes rdar://10427411.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145369 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index 72abfa7..beb50a7 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -226,14 +226,13 @@
unsigned Offset = Begin.second;
unsigned Length = End.second - Begin.second;
- if (!VisitPreprocessorLast &&
- Unit->getPreprocessor().getPreprocessingRecord())
- visitPreprocessedEntitiesInRegion();
+ if (!VisitDeclsOnly && !VisitPreprocessorLast)
+ if (visitPreprocessedEntitiesInRegion())
+ return; // visitation break.
visitDeclsFromFileRegion(File, Offset, Length);
- if (VisitPreprocessorLast &&
- Unit->getPreprocessor().getPreprocessingRecord())
+ if (!VisitDeclsOnly && VisitPreprocessorLast)
visitPreprocessedEntitiesInRegion();
}
@@ -354,6 +353,9 @@
}
bool CursorVisitor::visitPreprocessedEntitiesInRegion() {
+ if (!AU->getPreprocessor().getPreprocessingRecord())
+ return false;
+
PreprocessingRecord &PPRec
= *AU->getPreprocessor().getPreprocessingRecord();
SourceManager &SM = AU->getSourceManager();