[cfe-commits] r108942 - in /cfe/trunk: include/clang/Basic/SourceManager.h include/clang/Frontend/PCHReader.h lib/Frontend/PCHReader.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Tue Jul 20 14:50:20 PDT 2010


Author: cornedbee
Date: Tue Jul 20 16:50:20 2010
New Revision: 108942

URL: http://llvm.org/viewvc/llvm-project?rev=108942&view=rev
Log:
Allow loading source locations from any file in the chain. WIP

Modified:
    cfe/trunk/include/clang/Basic/SourceManager.h
    cfe/trunk/include/clang/Frontend/PCHReader.h
    cfe/trunk/lib/Frontend/PCHReader.cpp

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=108942&r1=108941&r2=108942&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Tue Jul 20 16:50:20 2010
@@ -435,7 +435,7 @@
   /// createFileID - Create a new FileID that represents the specified file
   /// being #included from the specified IncludePosition.  This returns 0 on
   /// error and translates NULL into standard input.
-  /// PreallocateID should be non-zero to specify which a pre-allocated,
+  /// PreallocateID should be non-zero to specify which pre-allocated,
   /// lazily computed source location is being filled in by this operation.
   FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos,
                       SrcMgr::CharacteristicKind FileCharacter,

Modified: cfe/trunk/include/clang/Frontend/PCHReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHReader.h?rev=108942&r1=108941&r2=108942&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Tue Jul 20 16:50:20 2010
@@ -271,6 +271,7 @@
 
   /// \brief The chain of PCH files. The first entry is the one named by the
   /// user, the last one is the one that doesn't depend on anything further.
+  /// That is, the entry I was created with -include-pch I+1.
   llvm::SmallVector<PerFileData*, 2> Chain;
 
   /// \brief Types that have already been loaded from the PCH file.
@@ -539,6 +540,7 @@
   bool ParseLineTable(llvm::SmallVectorImpl<uint64_t> &Record);
   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);

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=108942&r1=108941&r2=108942&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Tue Jul 20 16:50:20 2010
@@ -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 ||





More information about the cfe-commits mailing list