From: Sebastian Redl Date: Tue, 20 Jul 2010 22:37:49 +0000 (+0000) Subject: Allow loading types from any file in the chain. WIP X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aaec0aa844781dc7c3462ba140e004e589ccd355;p=clang Allow loading types from any file in the chain. WIP git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108954 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Frontend/PCHReader.h b/include/clang/Frontend/PCHReader.h index c3826e7a17..50a5ad5b10 100644 --- a/include/clang/Frontend/PCHReader.h +++ b/include/clang/Frontend/PCHReader.h @@ -541,9 +541,12 @@ private: PCHReadResult ReadSourceManagerBlock(PerFileData &F); PCHReadResult ReadSLocEntryRecord(unsigned ID); llvm::BitstreamCursor &SLocCursorForID(unsigned ID); - bool ParseLanguageOptions(const llvm::SmallVectorImpl &Record); - QualType ReadTypeRecord(uint64_t Offset); + + typedef std::pair RecordLocation; + + QualType ReadTypeRecord(unsigned Index); + RecordLocation TypeCursorForIndex(unsigned Index); void LoadedDecl(unsigned Index, Decl *D); Decl *ReadDeclRecord(uint64_t Offset, unsigned Index); diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index 126036ac4e..3abee83661 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -2150,13 +2150,28 @@ void PCHReader::ReadPreprocessedEntities() { ReadDefinedMacros(); } -/// \brief Read and return the type at the given offset. +/// \brief Get the correct cursor and offset for loading a type. +PCHReader::RecordLocation PCHReader::TypeCursorForIndex(unsigned Index) { + PerFileData *F = 0; + for (unsigned I = 0, N = Chain.size(); I != N; ++I) { + F = Chain[N - I - 1]; + if (Index < F->LocalNumTypes) + break; + Index -= F->LocalNumTypes; + } + assert(F && F->LocalNumTypes > Index && "Broken chain"); + return RecordLocation(F->DeclsCursor, F->TypeOffsets[Index]); +} + +/// \brief Read and return the type with the given index.. /// -/// This routine actually reads the record corresponding to the type -/// at the given offset in the bitstream. It is a helper routine for -/// GetType, which deals with reading type IDs. -QualType PCHReader::ReadTypeRecord(uint64_t Offset) { - llvm::BitstreamCursor &DeclsCursor = Chain[0]->DeclsCursor; +/// The index is the type ID, shifted and minus the number of predefs. This +/// routine actually reads the record corresponding to the type at the given +/// location. It is a helper routine for GetType, which deals with reading type +/// IDs. +QualType PCHReader::ReadTypeRecord(unsigned Index) { + RecordLocation Loc = TypeCursorForIndex(Index); + llvm::BitstreamCursor &DeclsCursor = Loc.first; // Keep track of where we are in the stream, then jump back there // after reading this type. @@ -2167,7 +2182,7 @@ QualType PCHReader::ReadTypeRecord(uint64_t Offset) { // Note that we are loading a type record. LoadingTypeOrDecl Loading(*this); - DeclsCursor.JumpToBit(Offset); + DeclsCursor.JumpToBit(Loc.second); RecordData Record; unsigned Code = DeclsCursor.ReadCode(); switch ((pch::TypeCode)DeclsCursor.ReadRecord(Code, Record)) { @@ -2736,9 +2751,9 @@ QualType PCHReader::GetType(pch::TypeID ID) { } Index -= pch::NUM_PREDEF_TYPE_IDS; - //assert(Index < TypesLoaded.size() && "Type index out-of-range"); + assert(Index < TypesLoaded.size() && "Type index out-of-range"); if (TypesLoaded[Index].isNull()) { - TypesLoaded[Index] = ReadTypeRecord(Chain[0]->TypeOffsets[Index]); + TypesLoaded[Index] = ReadTypeRecord(Index); TypesLoaded[Index]->setFromPCH(); if (DeserializationListener) DeserializationListener->TypeRead(ID >> Qualifiers::FastWidth,