aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Redl <sebastian.redl@getdesigned.at>2010-07-20 22:46:15 +0000
committerSebastian Redl <sebastian.redl@getdesigned.at>2010-07-20 22:46:15 +0000
commitcb526aa1184d2aa19bbfdfb1080f1fc87d9bb711 (patch)
tree1b08c1837ca65ac17fca7dc2570622738afbfe01
parentaaec0aa844781dc7c3462ba140e004e589ccd355 (diff)
Allow loading declarations from any file in the chain. WIP
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108956 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Frontend/PCHReader.h3
-rw-r--r--lib/Frontend/PCHReader.cpp4
-rw-r--r--lib/Frontend/PCHReaderDecl.cpp20
3 files changed, 21 insertions, 6 deletions
diff --git a/include/clang/Frontend/PCHReader.h b/include/clang/Frontend/PCHReader.h
index 50a5ad5b10..4ef7bf19aa 100644
--- a/include/clang/Frontend/PCHReader.h
+++ b/include/clang/Frontend/PCHReader.h
@@ -548,7 +548,8 @@ private:
QualType ReadTypeRecord(unsigned Index);
RecordLocation TypeCursorForIndex(unsigned Index);
void LoadedDecl(unsigned Index, Decl *D);
- Decl *ReadDeclRecord(uint64_t Offset, unsigned Index);
+ Decl *ReadDeclRecord(unsigned Index);
+ RecordLocation DeclCursorForIndex(unsigned Index);
void PassInterestingDeclsToConsumer();
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp
index 3abee83661..532ba444a2 100644
--- a/lib/Frontend/PCHReader.cpp
+++ b/lib/Frontend/PCHReader.cpp
@@ -2805,7 +2805,7 @@ Decl *PCHReader::GetExternalDecl(uint32_t ID) {
TranslationUnitDecl *PCHReader::GetTranslationUnitDecl() {
if (!DeclsLoaded[0]) {
- ReadDeclRecord(Chain[0]->DeclOffsets[0], 0);
+ ReadDeclRecord(0);
if (DeserializationListener)
DeserializationListener->DeclRead(1, DeclsLoaded[0]);
}
@@ -2824,7 +2824,7 @@ Decl *PCHReader::GetDecl(pch::DeclID ID) {
unsigned Index = ID - 1;
if (!DeclsLoaded[Index]) {
- ReadDeclRecord(Chain[0]->DeclOffsets[Index], Index);
+ ReadDeclRecord(Index);
if (DeserializationListener)
DeserializationListener->DeclRead(ID, DeclsLoaded[Index]);
}
diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp
index e021d3caba..a4c0d8df9a 100644
--- a/lib/Frontend/PCHReaderDecl.cpp
+++ b/lib/Frontend/PCHReaderDecl.cpp
@@ -1254,9 +1254,23 @@ static bool isConsumerInterestedIn(Decl *D) {
return isa<ObjCProtocolDecl>(D);
}
+/// \brief Get the correct cursor and offset for loading a type.
+PCHReader::RecordLocation PCHReader::DeclCursorForIndex(unsigned Index) {
+ PerFileData *F = 0;
+ for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
+ F = Chain[N - I - 1];
+ if (Index < F->LocalNumDecls)
+ break;
+ Index -= F->LocalNumDecls;
+ }
+ assert(F && F->LocalNumDecls > Index && "Broken chain");
+ return RecordLocation(F->DeclsCursor, F->DeclOffsets[Index]);
+}
+
/// \brief Read the declaration at the given offset from the PCH file.
-Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
- llvm::BitstreamCursor &DeclsCursor = Chain[0]->DeclsCursor;
+Decl *PCHReader::ReadDeclRecord(unsigned Index) {
+ RecordLocation Loc = DeclCursorForIndex(Index);
+ llvm::BitstreamCursor &DeclsCursor = Loc.first;
// Keep track of where we are in the stream, then jump back there
// after reading this declaration.
SavedStreamPosition SavedPosition(DeclsCursor);
@@ -1266,7 +1280,7 @@ Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
// Note that we are loading a declaration record.
LoadingTypeOrDecl Loading(*this);
- DeclsCursor.JumpToBit(Offset);
+ DeclsCursor.JumpToBit(Loc.second);
RecordData Record;
unsigned Code = DeclsCursor.ReadCode();
unsigned Idx = 0;