In libclang, when visiting preprocessed entities in a source range, use
PreprocessingRecord's getPreprocessedEntitiesInRange.
Also remove all the stuff that were added in ASTUnit that are unnecessary now
that we do a binary search for preprocessed entities and deserialize only
what is necessary.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140063 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index 8390a7c..5916d5c 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -263,10 +263,6 @@
bool visitPreprocessedEntitiesInRegion();
template<typename InputIterator>
- bool visitPreprocessedEntitiesInRegion(InputIterator First,
- InputIterator Last);
-
- template<typename InputIterator>
bool visitPreprocessedEntities(InputIterator First, InputIterator Last);
bool VisitChildren(CXCursor Parent);
@@ -399,62 +395,19 @@
PreprocessingRecord &PPRec
= *AU->getPreprocessor().getPreprocessingRecord();
+ if (RegionOfInterest.isValid()) {
+ std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator>
+ Entities = PPRec.getPreprocessedEntitiesInRange(RegionOfInterest);
+ return visitPreprocessedEntities(Entities.first, Entities.second);
+ }
+
bool OnlyLocalDecls
= !AU->isMainFileAST() && AU->getOnlyLocalDecls();
- if (OnlyLocalDecls && RegionOfInterest.isValid()) {
- // If we would only look at local declarations but we have a region of
- // interest, check whether that region of interest is in the main file.
- // If not, we should traverse all declarations.
- // FIXME: My kingdom for a proper binary search approach to finding
- // cursors!
- std::pair<FileID, unsigned> Location
- = AU->getSourceManager().getDecomposedExpansionLoc(
- RegionOfInterest.getBegin());
- if (Location.first != AU->getSourceManager().getMainFileID())
- OnlyLocalDecls = false;
- }
-
- PreprocessingRecord::iterator StartEntity, EndEntity;
- if (OnlyLocalDecls && AU->pp_entity_begin() != AU->pp_entity_end())
- return visitPreprocessedEntitiesInRegion(AU->pp_entity_begin(),
- AU->pp_entity_end());
- else
- return visitPreprocessedEntitiesInRegion(PPRec.begin(), PPRec.end());
-}
+ if (OnlyLocalDecls)
+ return visitPreprocessedEntities(PPRec.local_begin(), PPRec.local_end());
-template<typename InputIterator>
-bool CursorVisitor::visitPreprocessedEntitiesInRegion(InputIterator First,
- InputIterator Last) {
- // There is no region of interest; we have to walk everything.
- if (RegionOfInterest.isInvalid())
- return visitPreprocessedEntities(First, Last);
-
- // Find the file in which the region of interest lands.
- SourceManager &SM = AU->getSourceManager();
- std::pair<FileID, unsigned> Begin
- = SM.getDecomposedExpansionLoc(RegionOfInterest.getBegin());
- std::pair<FileID, unsigned> End
- = SM.getDecomposedExpansionLoc(RegionOfInterest.getEnd());
-
- // The region of interest spans files; we have to walk everything.
- if (Begin.first != End.first)
- return visitPreprocessedEntities(First, Last);
-
- ASTUnit::PreprocessedEntitiesByFileMap &ByFileMap
- = AU->getPreprocessedEntitiesByFile();
- if (ByFileMap.empty()) {
- // Build the mapping from files to sets of preprocessed entities.
- for (; First != Last; ++First) {
- std::pair<FileID, unsigned> P
- = SM.getDecomposedExpansionLoc((*First)->getSourceRange().getBegin());
-
- ByFileMap[P.first].push_back(*First);
- }
- }
-
- return visitPreprocessedEntities(ByFileMap[Begin.first].begin(),
- ByFileMap[Begin.first].end());
+ return visitPreprocessedEntities(PPRec.begin(), PPRec.end());
}
template<typename InputIterator>