diff options
Diffstat (limited to 'tools/libclang/CIndex.cpp')
-rw-r--r-- | tools/libclang/CIndex.cpp | 65 |
1 files changed, 9 insertions, 56 deletions
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 8390a7ce8d..5916d5c337 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -263,10 +263,6 @@ public: 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 @@ bool CursorVisitor::visitPreprocessedEntitiesInRegion() { 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> |