]> granicus.if.org Git - clang/commitdiff
Change source manager serialization to be less tied to the PCH model.
authorSebastian Redl <sebastian.redl@getdesigned.at>
Wed, 22 Sep 2010 20:19:08 +0000 (20:19 +0000)
committerSebastian Redl <sebastian.redl@getdesigned.at>
Wed, 22 Sep 2010 20:19:08 +0000 (20:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114575 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Serialization/ASTReader.h
lib/Serialization/ASTReader.cpp
lib/Serialization/ASTWriter.cpp

index 097eb76dd04c6e20bd2b04936fa624f8af4aeee1..2b3dbf1569aba1aa9dd742a1b35bd24a3b30c79b 100644 (file)
@@ -228,8 +228,8 @@ private:
     /// AST file.
     const uint32_t *SLocOffsets;
 
-    /// \brief The next SourceLocation offset after reading this file.
-    unsigned NextOffset;
+    /// \brief The entire size of this module's source location offset range.
+    unsigned LocalSLocSize;
 
     // === Identifiers ===
 
@@ -255,6 +255,10 @@ private:
 
     // === Macros ===
 
+    /// \brief The cursor to the start of the preprocessor block, which stores
+    /// all of the macro definitions.
+    llvm::BitstreamCursor MacroCursor;
+
     /// \brief The number of macro definitions in this file.
     unsigned LocalNumMacroDefinitions;
 
@@ -264,10 +268,6 @@ private:
 
     // === Selectors ===
 
-    /// \brief The cursor to the start of the preprocessor block, which stores
-    /// all of the macro definitions.
-    llvm::BitstreamCursor MacroCursor;
-
     /// \brief The number of selectors new to this file.
     ///
     /// This is the number of entries in SelectorOffsets.
@@ -568,6 +568,9 @@ private:
   /// \brief The number of source location entries in the chain.
   unsigned TotalNumSLocEntries;
 
+  /// \brief The next offset for a SLocEntry after everything in this reader.
+  unsigned NextSLocOffset;
+
   /// \brief The number of statements (and expressions) de-serialized
   /// from the chain.
   unsigned NumStatementsRead;
@@ -788,6 +791,11 @@ public:
     return TotalNumSLocEntries;
   }
 
+  /// \brief Returns the next SLocEntry offset after the chain.
+  unsigned getNextSLocOffset() const {
+    return NextSLocOffset;
+  }
+
   /// \brief Returns the number of identifiers found in the chain.
   unsigned getTotalNumIdentifiers() const {
     return static_cast<unsigned>(IdentifiersLoaded.size());
index 672e912dc62553fa69aac883d894fca28ea77a2d..91f0d36118b0ee9a358b512132f891e1afa02f9b 100644 (file)
@@ -1879,7 +1879,7 @@ ASTReader::ReadASTBlock(PerFileData &F) {
     case SOURCE_LOCATION_OFFSETS:
       F.SLocOffsets = (const uint32_t *)BlobStart;
       F.LocalNumSLocEntries = Record[0];
-      F.NextOffset = Record[1];
+      F.LocalSLocSize = Record[1];
       break;
 
     case SOURCE_LOCATION_PRELOADS:
@@ -2000,6 +2000,7 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName) {
            TotalNumSelectors = 0;
   for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
     TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries;
+    NextSLocOffset += Chain[I]->LocalSLocSize;
     TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers;
     TotalNumTypes += Chain[I]->LocalNumTypes;
     TotalNumDecls += Chain[I]->LocalNumDecls;
@@ -2008,8 +2009,7 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName) {
     TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions;
     TotalNumSelectors += Chain[I]->LocalNumSelectors;
   }
-  SourceMgr.PreallocateSLocEntries(this, TotalNumSLocEntries,
-                                   Chain.front()->NextOffset);
+  SourceMgr.PreallocateSLocEntries(this, TotalNumSLocEntries, NextSLocOffset);
   IdentifiersLoaded.resize(TotalNumIdentifiers);
   TypesLoaded.resize(TotalNumTypes);
   DeclsLoaded.resize(TotalNumDecls);
@@ -4089,9 +4089,9 @@ ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context,
     Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context),
     Consumer(0), isysroot(isysroot), DisableValidation(DisableValidation),
     NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0),
-    TotalNumSLocEntries(0), NumStatementsRead(0), TotalNumStatements(0),
-    NumMacrosRead(0), TotalNumMacros(0), NumSelectorsRead(0),
-    NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0),
+    TotalNumSLocEntries(0), NextSLocOffset(0), NumStatementsRead(0),
+    TotalNumStatements(0), NumMacrosRead(0), TotalNumMacros(0),
+    NumSelectorsRead(0), NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0),
     TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0),
     TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0),
     TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) {
@@ -4105,12 +4105,12 @@ ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr,
     Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0),
     isysroot(isysroot), DisableValidation(DisableValidation), NumStatHits(0),
     NumStatMisses(0), NumSLocEntriesRead(0), TotalNumSLocEntries(0),
-    NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0),
-    TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0),
-    NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0),
-    NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0),
-    NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0),
-    NumCurrentElementsDeserializing(0) {
+    NextSLocOffset(0), NumStatementsRead(0), TotalNumStatements(0),
+    NumMacrosRead(0), TotalNumMacros(0), NumSelectorsRead(0),
+    NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0),
+    TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0),
+    TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0),
+    TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) {
   RelocatablePCH = false;
 }
 
@@ -4140,7 +4140,7 @@ ASTReader::~ASTReader() {
 }
 
 ASTReader::PerFileData::PerFileData()
-  : SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0),
+  : SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), LocalSLocSize(0),
     LocalNumIdentifiers(0), IdentifierOffsets(0), IdentifierTableData(0),
     IdentifierLookupTable(0), LocalNumMacroDefinitions(0),
     MacroDefinitionOffsets(0), LocalNumSelectors(0), SelectorOffsets(0),
index b32354b46ccfd530afc70c69793bc58f55fb0347..24ec7ea4b7c361a9829de90dfcfb8d5597f81463 100644 (file)
@@ -1228,7 +1228,8 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
   Record.clear();
   Record.push_back(SOURCE_LOCATION_OFFSETS);
   Record.push_back(SLocEntryOffsets.size());
-  Record.push_back(SourceMgr.getNextOffset());
+  unsigned BaseOffset = Chain ? Chain->getNextSLocOffset() : 0;
+  Record.push_back(SourceMgr.getNextOffset() - BaseOffset);
   Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record,
                             (const char *)data(SLocEntryOffsets),
                            SLocEntryOffsets.size()*sizeof(SLocEntryOffsets[0]));