From: Sebastian Redl Date: Wed, 22 Sep 2010 20:19:08 +0000 (+0000) Subject: Change source manager serialization to be less tied to the PCH model. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8db9faed418ea743f55c31e1ccecadbb23bd55b7;p=clang Change source manager serialization to be less tied to the PCH model. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114575 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 097eb76dd0..2b3dbf1569 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -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(IdentifiersLoaded.size()); diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 672e912dc6..91f0d36118 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -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), diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index b32354b46c..24ec7ea4b7 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -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]));