/// \brief The number of types in this PCH file.
unsigned LocalNumTypes;
+ /// \brief Offset of each type within the bitstream, indexed by the
+ /// type ID, or the representation of a Type*.
+ const uint32_t *TypeOffsets;
+
/// \brief The number of declarations in this PCH file.
unsigned LocalNumDecls;
+ /// \brief Offset of each declaration within the bitstream, indexed
+ /// by the declaration ID (-1).
+ const uint32_t *DeclOffsets;
+
/// \brief Actual data for the on-disk hash table.
///
// This pointer points into a memory buffer, where the on-disk hash
/// \brief The number of source location entries in all PCH files.
unsigned TotalNumSLocEntries;
- /// \brief Offset of each type within the bitstream, indexed by the
- /// type ID, or the representation of a Type*. The offset is local to the
- /// containing file; the file is chosen using the ID.
- const uint32_t *TypeOffsets;
-
/// \brief Types that have already been loaded from the PCH file.
///
/// When the pointer at index I is non-NULL, the type with
/// ID = (I + 1) << FastQual::Width has already been loaded from the PCH chain
std::vector<QualType> TypesLoaded;
- /// \brief Offset of each declaration within the bitstream, indexed
- /// by the declaration ID (-1). The offset is local to the containing file;
- /// the file is chosen using the ID.
- const uint32_t *DeclOffsets;
-
/// \brief Declarations that have already been loaded from the PCH file.
///
/// When the pointer at index I is non-NULL, the declaration with ID
}
PCHReader::PerFileData::PerFileData()
- : StatCache(0), IdentifierTableData(0), IdentifierLookupTable(0)
+ : StatCache(0), LocalNumSLocEntries(0), LocalNumTypes(0), TypeOffsets(0),
+ LocalNumDecls(0), DeclOffsets(0), IdentifierTableData(0),
+ IdentifierLookupTable(0)
{}
}
case pch::TYPE_OFFSET:
- if (!TypesLoaded.empty()) {
+ if (F.LocalNumTypes != 0) {
Error("duplicate TYPE_OFFSET record in PCH file");
return Failure;
}
- TypeOffsets = (const uint32_t *)BlobStart;
- TypesLoaded.resize(Record[0]);
+ F.TypeOffsets = (const uint32_t *)BlobStart;
+ F.LocalNumTypes = Record[0];
break;
case pch::DECL_OFFSET:
- if (!DeclsLoaded.empty()) {
+ if (F.LocalNumDecls != 0) {
Error("duplicate DECL_OFFSET record in PCH file");
return Failure;
}
- DeclOffsets = (const uint32_t *)BlobStart;
- DeclsLoaded.resize(Record[0]);
+ F.DeclOffsets = (const uint32_t *)BlobStart;
+ F.LocalNumDecls = Record[0];
break;
case pch::LANGUAGE_OPTIONS:
// Here comes stuff that we only do once the entire chain is loaded.
+ // Allocate space for loaded decls and types.
+ unsigned TotalNumTypes = 0, TotalNumDecls = 0;
+ for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
+ TotalNumTypes += Chain[I]->LocalNumTypes;
+ TotalNumDecls += Chain[I]->LocalNumDecls;
+ }
+ TypesLoaded.resize(TotalNumTypes);
+ DeclsLoaded.resize(TotalNumDecls);
+
// Check the predefines buffers.
if (CheckPredefinesBuffers())
return IgnorePCH;
Index -= pch::NUM_PREDEF_TYPE_IDS;
//assert(Index < TypesLoaded.size() && "Type index out-of-range");
if (TypesLoaded[Index].isNull()) {
- TypesLoaded[Index] = ReadTypeRecord(TypeOffsets[Index]);
+ TypesLoaded[Index] = ReadTypeRecord(Chain[0]->TypeOffsets[Index]);
TypesLoaded[Index]->setFromPCH();
if (DeserializationListener)
DeserializationListener->TypeRead(ID >> Qualifiers::FastWidth,
TranslationUnitDecl *PCHReader::GetTranslationUnitDecl() {
if (!DeclsLoaded[0]) {
- ReadDeclRecord(DeclOffsets[0], 0);
+ ReadDeclRecord(Chain[0]->DeclOffsets[0], 0);
if (DeserializationListener)
DeserializationListener->DeclRead(1, DeclsLoaded[0]);
}
unsigned Index = ID - 1;
if (!DeclsLoaded[Index]) {
- ReadDeclRecord(DeclOffsets[Index], Index);
+ ReadDeclRecord(Chain[0]->DeclOffsets[Index], Index);
if (DeserializationListener)
DeserializationListener->DeclRead(ID, DeclsLoaded[Index]);
}