Allow loading source locations from any file in the chain. WIP
llvm-svn: 108942
diff --git a/clang/lib/Frontend/PCHReader.cpp b/clang/lib/Frontend/PCHReader.cpp
index b12025f..126036a 100644
--- a/clang/lib/Frontend/PCHReader.cpp
+++ b/clang/lib/Frontend/PCHReader.cpp
@@ -953,6 +953,26 @@
}
}
+/// \brief Get a cursor that's correctly positioned for reading the source
+/// location entry with the given ID.
+llvm::BitstreamCursor &PCHReader::SLocCursorForID(unsigned ID) {
+ assert(ID != 0 && ID <= TotalNumSLocEntries &&
+ "SLocCursorForID should only be called for real IDs.");
+
+ ID -= 1;
+ PerFileData *F = 0;
+ for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
+ F = Chain[N - I - 1];
+ if (ID < F->LocalNumSLocEntries)
+ break;
+ ID -= F->LocalNumSLocEntries;
+ }
+ assert(F && F->LocalNumSLocEntries > ID && "Chain corrupted");
+
+ F->SLocEntryCursor.JumpToBit(F->SLocOffsets[ID]);
+ return F->SLocEntryCursor;
+}
+
/// \brief Read in the source location entry with the given ID.
PCHReader::PCHReadResult PCHReader::ReadSLocEntryRecord(unsigned ID) {
if (ID == 0)
@@ -963,10 +983,9 @@
return Failure;
}
- llvm::BitstreamCursor &SLocEntryCursor = Chain[0]->SLocEntryCursor;
+ llvm::BitstreamCursor &SLocEntryCursor = SLocCursorForID(ID);
++NumSLocEntriesRead;
- SLocEntryCursor.JumpToBit(Chain[0]->SLocOffsets[ID - 1]);
unsigned Code = SLocEntryCursor.ReadCode();
if (Code == llvm::bitc::END_BLOCK ||
Code == llvm::bitc::ENTER_SUBBLOCK ||