[cfe-commits] r108954 - in /cfe/trunk: include/clang/Frontend/PCHReader.h lib/Frontend/PCHReader.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Tue Jul 20 15:37:49 PDT 2010
Author: cornedbee
Date: Tue Jul 20 17:37:49 2010
New Revision: 108954
URL: http://llvm.org/viewvc/llvm-project?rev=108954&view=rev
Log:
Allow loading types from any file in the chain. WIP
Modified:
cfe/trunk/include/clang/Frontend/PCHReader.h
cfe/trunk/lib/Frontend/PCHReader.cpp
Modified: cfe/trunk/include/clang/Frontend/PCHReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHReader.h?rev=108954&r1=108953&r2=108954&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Tue Jul 20 17:37:49 2010
@@ -541,9 +541,12 @@
PCHReadResult ReadSourceManagerBlock(PerFileData &F);
PCHReadResult ReadSLocEntryRecord(unsigned ID);
llvm::BitstreamCursor &SLocCursorForID(unsigned ID);
-
bool ParseLanguageOptions(const llvm::SmallVectorImpl<uint64_t> &Record);
- QualType ReadTypeRecord(uint64_t Offset);
+
+ typedef std::pair<llvm::BitstreamCursor &, uint64_t> RecordLocation;
+
+ QualType ReadTypeRecord(unsigned Index);
+ RecordLocation TypeCursorForIndex(unsigned Index);
void LoadedDecl(unsigned Index, Decl *D);
Decl *ReadDeclRecord(uint64_t Offset, unsigned Index);
Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=108954&r1=108953&r2=108954&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Tue Jul 20 17:37:49 2010
@@ -2150,13 +2150,28 @@
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 @@
// 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 @@
}
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,
More information about the cfe-commits
mailing list