[cfe-commits] r165023 - in /cfe/trunk: include/clang/Frontend/ASTUnit.h include/clang/Lex/PreprocessingRecord.h include/clang/Serialization/ASTReader.h lib/Frontend/ASTUnit.cpp lib/Serialization/ASTReader.cpp tools/libclang/Indexing.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue Oct 2 09:10:52 PDT 2012
Author: akirtzidis
Date: Tue Oct 2 11:10:51 2012
New Revision: 165023
URL: http://llvm.org/viewvc/llvm-project?rev=165023&view=rev
Log:
[libclang] When indexing an AST file, only deserialize the preprocessing record
entities of the current primary module.
Modified:
cfe/trunk/include/clang/Frontend/ASTUnit.h
cfe/trunk/include/clang/Lex/PreprocessingRecord.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/tools/libclang/Indexing.cpp
Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=165023&r1=165022&r2=165023&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Tue Oct 2 11:10:51 2012
@@ -607,6 +607,12 @@
return CachedCompletionResults.size();
}
+ /// \brief Returns an iterator range for the local preprocessing entities
+ /// of the local Preprocessor, if this is a parsed source file, or the loaded
+ /// preprocessing entities of the primary module if this is an AST file.
+ std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator>
+ getLocalPreprocessingEntities() const;
+
llvm::MemoryBuffer *getBufferForFile(StringRef Filename,
std::string *ErrorStr = 0);
Modified: cfe/trunk/include/clang/Lex/PreprocessingRecord.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessingRecord.h?rev=165023&r1=165022&r2=165023&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PreprocessingRecord.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessingRecord.h Tue Oct 2 11:10:51 2012
@@ -548,6 +548,17 @@
return iterator(this, PreprocessedEntities.size());
}
+ /// \brief begin/end iterator pair for the given range of loaded
+ /// preprocessed entities.
+ std::pair<iterator, iterator>
+ getIteratorsForLoadedRange(unsigned start, unsigned count) {
+ unsigned end = start + count;
+ assert(end <= LoadedPreprocessedEntities.size());
+ return std::make_pair(
+ iterator(this, int(start)-LoadedPreprocessedEntities.size()),
+ iterator(this, int(end)-LoadedPreprocessedEntities.size()));
+ }
+
/// \brief Returns a pair of [Begin, End) iterators of preprocessed entities
/// that source range \p R encompasses.
///
Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=165023&r1=165022&r2=165023&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Tue Oct 2 11:10:51 2012
@@ -855,6 +855,11 @@
std::pair<ModuleFile *, unsigned>
getModulePreprocessedEntity(unsigned GlobalIndex);
+ /// \brief Returns (begin, end) pair for the preprocessed entities of a
+ /// particular module.
+ std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator>
+ getModulePreprocessedEntities(ModuleFile &Mod) const;
+
void PassInterestingDeclsToConsumer();
void PassInterestingDeclToConsumer(Decl *D);
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=165023&r1=165022&r2=165023&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Tue Oct 2 11:10:51 2012
@@ -2777,6 +2777,21 @@
return SourceMgr->getLocForStartOfFile(FID);
}
+std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator>
+ASTUnit::getLocalPreprocessingEntities() const {
+ if (isMainFileAST()) {
+ serialization::ModuleFile &
+ Mod = Reader->getModuleManager().getPrimaryModule();
+ return Reader->getModulePreprocessedEntities(Mod);
+ }
+
+ if (PreprocessingRecord *PPRec = PP->getPreprocessingRecord())
+ return std::make_pair(PPRec->local_begin(), PPRec->local_end());
+
+ return std::make_pair(PreprocessingRecord::iterator(),
+ PreprocessingRecord::iterator());
+}
+
void ASTUnit::PreambleData::countLines() const {
NumLines = 0;
if (empty())
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=165023&r1=165022&r2=165023&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Oct 2 11:10:51 2012
@@ -3381,6 +3381,16 @@
return std::make_pair(M, LocalIndex);
}
+std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator>
+ASTReader::getModulePreprocessedEntities(ModuleFile &Mod) const {
+ if (PreprocessingRecord *PPRec = PP.getPreprocessingRecord())
+ return PPRec->getIteratorsForLoadedRange(Mod.BasePreprocessedEntityID,
+ Mod.NumPreprocessedEntities);
+
+ return std::make_pair(PreprocessingRecord::iterator(),
+ PreprocessingRecord::iterator());
+}
+
PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) {
PreprocessedEntityID PPID = Index+1;
std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index);
Modified: cfe/trunk/tools/libclang/Indexing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/Indexing.cpp?rev=165023&r1=165022&r2=165023&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/Indexing.cpp (original)
+++ cfe/trunk/tools/libclang/Indexing.cpp Tue Oct 2 11:10:51 2012
@@ -455,21 +455,10 @@
if (!PP.getPreprocessingRecord())
return;
- PreprocessingRecord &PPRec = *PP.getPreprocessingRecord();
-
// FIXME: Only deserialize inclusion directives.
- // FIXME: Only deserialize stuff from the last chained PCH, not the PCH/Module
- // that it depends on.
- bool OnlyLocal = !Unit.isMainFileAST() && Unit.getOnlyLocalDecls();
PreprocessingRecord::iterator I, E;
- if (OnlyLocal) {
- I = PPRec.local_begin();
- E = PPRec.local_end();
- } else {
- I = PPRec.begin();
- E = PPRec.end();
- }
+ llvm::tie(I, E) = Unit.getLocalPreprocessingEntities();
for (; I != E; ++I) {
PreprocessedEntity *PPE = *I;
More information about the cfe-commits
mailing list