]> granicus.if.org Git - clang/commitdiff
While writing source-location entries to a PCH file, go through an
authorDouglas Gregor <dgregor@apple.com>
Fri, 16 Oct 2009 22:46:09 +0000 (22:46 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 16 Oct 2009 22:46:09 +0000 (22:46 +0000)
interface that can load those source-location entries on demand (from
another PCH file).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84287 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/SourceManager.h
lib/AST/StmtPrinter.cpp
lib/Frontend/PCHWriter.cpp

index 7eb988f005ec0996bfce87fbd7a7591ae00a70f4..8a69cba066b3e1ecb17fc875a8ad31d061a75525 100644 (file)
@@ -685,26 +685,19 @@ public:
   ///
   void PrintStats() const;
 
-  // Iteration over the source location entry table.
-  typedef std::vector<SrcMgr::SLocEntry>::const_iterator sloc_entry_iterator;
-
-  sloc_entry_iterator sloc_entry_begin() const {
-    return SLocEntryTable.begin();
-  }
-
-  sloc_entry_iterator sloc_entry_end() const {
-    return SLocEntryTable.end();
-  }
-
   unsigned sloc_entry_size() const { return SLocEntryTable.size(); }
 
-  const SrcMgr::SLocEntry &getSLocEntry(FileID FID) const {
-    assert(FID.ID < SLocEntryTable.size() && "Invalid id");
+  const SrcMgr::SLocEntry &getSLocEntry(unsigned ID) const {
+    assert(ID < SLocEntryTable.size() && "Invalid id");
     if (ExternalSLocEntries &&
-        FID.ID < SLocEntryLoaded.size() &&
-        !SLocEntryLoaded[FID.ID])
-      ExternalSLocEntries->ReadSLocEntry(FID.ID);
-    return SLocEntryTable[FID.ID];
+        ID < SLocEntryLoaded.size() &&
+        !SLocEntryLoaded[ID])
+      ExternalSLocEntries->ReadSLocEntry(ID);
+    return SLocEntryTable[ID];
+  }
+  
+  const SrcMgr::SLocEntry &getSLocEntry(FileID FID) const {    
+    return getSLocEntry(FID.ID);
   }
 
   unsigned getNextOffset() const { return NextOffset; }
index 05d0c26835456e5b5682177332a6f804442983d1..2af19765dfaa3aed0f1f2aa6a323112fe97d1e1a 100644 (file)
@@ -1289,7 +1289,7 @@ void Stmt::printPretty(llvm::raw_ostream &OS, ASTContext& Context,
     return;
   }
 
-  if (Policy.Dump) {
+  if (Policy.Dump && &Context) {
     dump(Context.getSourceManager());
     return;
   }
index 74bd9677abd8912d4dd4d618143e07d184693962..91c47a32b81608425f6687ef0e6f353e392de5af 100644 (file)
@@ -928,10 +928,10 @@ void PCHWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
   std::vector<uint32_t> SLocEntryOffsets;
   RecordData PreloadSLocs;
   SLocEntryOffsets.reserve(SourceMgr.sloc_entry_size() - 1);
-  for (SourceManager::sloc_entry_iterator
-         SLoc = SourceMgr.sloc_entry_begin() + 1,
-         SLocEnd = SourceMgr.sloc_entry_end();
-       SLoc != SLocEnd; ++SLoc) {
+  for (unsigned I = 1, N = SourceMgr.sloc_entry_size(); I != N; ++I) {
+    // Get this source location entry.
+    const SrcMgr::SLocEntry *SLoc = &SourceMgr.getSLocEntry(I);
+    
     // Record the offset of this source-location entry.
     SLocEntryOffsets.push_back(Stream.GetCurrentBitNo());
 
@@ -1006,9 +1006,8 @@ void PCHWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
 
       // Compute the token length for this macro expansion.
       unsigned NextOffset = SourceMgr.getNextOffset();
-      SourceManager::sloc_entry_iterator NextSLoc = SLoc;
-      if (++NextSLoc != SLocEnd)
-        NextOffset = NextSLoc->getOffset();
+      if (I + 1 != N)
+        NextOffset = SourceMgr.getSLocEntry(I + 1).getOffset();
       Record.push_back(NextOffset - SLoc->getOffset() - 1);
       Stream.EmitRecordWithAbbrev(SLocInstantiationAbbrv, Record);
     }