From a015cab273705d1198d13e8389c2f4775f539a8b Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 2 Dec 2011 17:30:13 +0000 Subject: [PATCH] Notify the AST writer (via ASTDeserializationListener) when a (sub)module is read from an AST file. This makes sure that the AST writer knows how to map all modules to their global IDs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145685 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Serialization/ASTDeserializationListener.h | 3 +++ include/clang/Serialization/ASTWriter.h | 3 ++- lib/Serialization/ASTReader.cpp | 6 ++++++ lib/Serialization/ASTWriter.cpp | 5 +++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/clang/Serialization/ASTDeserializationListener.h b/include/clang/Serialization/ASTDeserializationListener.h index 588fe0e63c..731148ecf8 100644 --- a/include/clang/Serialization/ASTDeserializationListener.h +++ b/include/clang/Serialization/ASTDeserializationListener.h @@ -23,6 +23,7 @@ class Decl; class ASTReader; class QualType; class MacroDefinition; +class Module; class ASTDeserializationListener { protected: @@ -47,6 +48,8 @@ public: /// \brief A macro definition was read from the AST file. virtual void MacroDefinitionRead(serialization::PreprocessedEntityID, MacroDefinition *MD) { } + /// \brief A module definition was read from the AST file. + virtual void ModuleRead(serialization::SubmoduleID ID, Module *Mod) { } }; } diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h index 1abce1869b..fd2b9ec77e 100644 --- a/include/clang/Serialization/ASTWriter.h +++ b/include/clang/Serialization/ASTWriter.h @@ -667,7 +667,8 @@ public: void SelectorRead(serialization::SelectorID ID, Selector Sel); void MacroDefinitionRead(serialization::PreprocessedEntityID ID, MacroDefinition *MD); - + void ModuleRead(serialization::SubmoduleID ID, Module *Mod); + // ASTMutationListener implementation. virtual void CompletedTagDefinition(const TagDecl *D); virtual void AddedVisibleDecl(const DeclContext *DC, const Decl *D); diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 4594a393dd..d8fb3113d5 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -2973,6 +2973,12 @@ ASTReader::ASTReadResult ASTReader::ReadSubmoduleBlock(ModuleFile &F) { Error("too many submodules"); return Failure; } + + if (DeserializationListener) + DeserializationListener->ModuleRead( + CurrentModuleGlobalIndex + NUM_PREDEF_SUBMODULE_IDS, + CurrentModule); + SubmodulesLoaded[CurrentModuleGlobalIndex++] = CurrentModule; break; } diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 5580f90b83..6d51dbce3e 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -4167,6 +4167,11 @@ void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID, MacroDefinitions[MD] = ID; } +void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) { + assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end()); + SubmoduleIDs[Mod] = ID; +} + void ASTWriter::CompletedTagDefinition(const TagDecl *D) { assert(D->isCompleteDefinition()); assert(!WritingAST && "Already writing the AST!"); -- 2.40.0