diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-10-25 00:29:50 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-10-25 00:29:50 +0000 |
commit | f226ff9fe8c8db6c5b74a61ce649eda1491c3502 (patch) | |
tree | 80afab1e791b65c151436ef8c08411c18a26b958 /lib/Serialization | |
parent | 82ccbe759b716f1747e03f54a4cd6eb164bb3427 (diff) |
[PCH] When visiting preprocessed entities, make it possible to avoid deserializing
preprocessed entities that are #included in the range that we are interested.
This is useful when we are interested in preprocessed entities of a specific file, e.g
when we are annotating tokens. There is also an optimization where we cache the last
result of PreprocessingRecord::getPreprocessedEntitiesInRange and we re-use it if
there is a call with the same range as before.
rdar://10313365
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142887 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization')
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index cf14c211fe..7afb3e43de 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -2778,14 +2778,22 @@ bool ASTReader::ParseLanguageOptions( return false; } -PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { - PreprocessedEntityID PPID = Index+1; +std::pair<Module *, unsigned> +ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) { GlobalPreprocessedEntityMapType::iterator - I = GlobalPreprocessedEntityMap.find(Index); + I = GlobalPreprocessedEntityMap.find(GlobalIndex); assert(I != GlobalPreprocessedEntityMap.end() && "Corrupted global preprocessed entity map"); - Module &M = *I->second; - unsigned LocalIndex = Index - M.BasePreprocessedEntityID; + Module *M = I->second; + unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID; + return std::make_pair(M, LocalIndex); +} + +PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { + PreprocessedEntityID PPID = Index+1; + std::pair<Module *, unsigned> PPInfo = getModulePreprocessedEntity(Index); + Module &M = *PPInfo.first; + unsigned LocalIndex = PPInfo.second; const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); @@ -3022,6 +3030,28 @@ std::pair<unsigned, unsigned> return std::make_pair(BeginID, EndID); } +/// \brief Optionally returns true or false if the preallocated preprocessed +/// entity with index \arg Index came from file \arg FID. +llvm::Optional<bool> ASTReader::isPreprocessedEntityInFileID(unsigned Index, + FileID FID) { + if (FID.isInvalid()) + return false; + + std::pair<Module *, unsigned> PPInfo = getModulePreprocessedEntity(Index); + Module &M = *PPInfo.first; + unsigned LocalIndex = PPInfo.second; + const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; + + SourceLocation Loc = ReadSourceLocation(M, PPOffs.Begin); + if (Loc.isInvalid()) + return false; + + if (SourceMgr.isInFileID(SourceMgr.getFileLoc(Loc), FID)) + return true; + else + return false; +} + namespace { /// \brief Visitor used to search for information about a header file. class HeaderFileInfoVisitor { |