From 8f64ca152985ac199ba8e2e6a94ebdba2ebd2db6 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 8 Dec 2015 22:43:32 +0000 Subject: [PATCH] Module file extensions: pass a Sema through to the extension writer. Module file extensions are likely to need access to Sema/Preprocessor/ASTContext, and cannot get it through other sources. llvm-svn: 255065 --- clang/include/clang/Serialization/ASTWriter.h | 3 ++- clang/include/clang/Serialization/ModuleFileExtension.h | 8 +++++--- clang/lib/Frontend/TestModuleFileExtension.cpp | 1 + clang/lib/Frontend/TestModuleFileExtension.h | 3 ++- clang/lib/Serialization/ASTWriter.cpp | 7 ++++--- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h index 86dbcee..ed34547 100644 --- a/clang/include/clang/Serialization/ASTWriter.h +++ b/clang/include/clang/Serialization/ASTWriter.h @@ -551,7 +551,8 @@ private: void WriteObjCCategories(); void WriteLateParsedTemplates(Sema &SemaRef); void WriteOptimizePragmaOptions(Sema &SemaRef); - void WriteModuleFileExtension(ModuleFileExtensionWriter &Writer); + void WriteModuleFileExtension(Sema &SemaRef, + ModuleFileExtensionWriter &Writer); unsigned DeclParmVarAbbrev; unsigned DeclContextLexicalAbbrev; diff --git a/clang/include/clang/Serialization/ModuleFileExtension.h b/clang/include/clang/Serialization/ModuleFileExtension.h index a8f8386..ba2e2fd 100644 --- a/clang/include/clang/Serialization/ModuleFileExtension.h +++ b/clang/include/clang/Serialization/ModuleFileExtension.h @@ -25,7 +25,8 @@ namespace clang { class ASTReader; class ASTWriter; - +class Sema; + namespace serialization { class ModuleFile; } // end namespace serialization @@ -79,7 +80,7 @@ public: /// The default implementation of this function simply returns the /// hash code as given, so the presence/absence of this extension /// does not distinguish module files. - virtual llvm::hash_code hashExtension(llvm::hash_code Code) const; + virtual llvm::hash_code hashExtension(llvm::hash_code c) const; /// Create a new module file extension writer, which will be /// responsible for writing the extension contents into a particular @@ -120,7 +121,8 @@ public: /// Responsible for writing the contents of the extension into the /// given stream. All of the contents should be written into custom /// records with IDs >= FIRST_EXTENSION_RECORD_ID. - virtual void writeExtensionContents(llvm::BitstreamWriter &Stream) = 0; + virtual void writeExtensionContents(Sema &SemaRef, + llvm::BitstreamWriter &Stream) = 0; }; /// Abstract base class that reads a module file extension block from diff --git a/clang/lib/Frontend/TestModuleFileExtension.cpp b/clang/lib/Frontend/TestModuleFileExtension.cpp index c020468..d1b20c4 100644 --- a/clang/lib/Frontend/TestModuleFileExtension.cpp +++ b/clang/lib/Frontend/TestModuleFileExtension.cpp @@ -19,6 +19,7 @@ using namespace clang::serialization; TestModuleFileExtension::Writer::~Writer() { } void TestModuleFileExtension::Writer::writeExtensionContents( + Sema &SemaRef, llvm::BitstreamWriter &Stream) { using namespace llvm; diff --git a/clang/lib/Frontend/TestModuleFileExtension.h b/clang/lib/Frontend/TestModuleFileExtension.h index 2a72454..41f3ca9 100644 --- a/clang/lib/Frontend/TestModuleFileExtension.h +++ b/clang/lib/Frontend/TestModuleFileExtension.h @@ -30,7 +30,8 @@ class TestModuleFileExtension : public ModuleFileExtension { Writer(ModuleFileExtension *Ext) : ModuleFileExtensionWriter(Ext) { } ~Writer() override; - void writeExtensionContents(llvm::BitstreamWriter &Stream) override; + void writeExtensionContents(Sema &SemaRef, + llvm::BitstreamWriter &Stream) override; }; class Reader : public ModuleFileExtensionReader { diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 7d3cefe..128935c 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -3880,7 +3880,8 @@ void ASTWriter::WriteOptimizePragmaOptions(Sema &SemaRef) { Stream.EmitRecord(OPTIMIZE_PRAGMA_OPTIONS, Record); } -void ASTWriter::WriteModuleFileExtension(ModuleFileExtensionWriter &Writer) { +void ASTWriter::WriteModuleFileExtension(Sema &SemaRef, + ModuleFileExtensionWriter &Writer) { // Enter the extension block. Stream.EnterSubblock(EXTENSION_BLOCK_ID, 4); @@ -3908,7 +3909,7 @@ void ASTWriter::WriteModuleFileExtension(ModuleFileExtensionWriter &Writer) { Stream.EmitRecordWithBlob(Abbrev, Record, Buffer); // Emit the contents of the extension block. - Writer.writeExtensionContents(Stream); + Writer.writeExtensionContents(SemaRef, Stream); // Exit the extension block. Stream.ExitBlock(); @@ -4563,7 +4564,7 @@ uint64_t ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot, // Write the module file extension blocks. for (const auto &ExtWriter : ModuleFileExtensionWriters) - WriteModuleFileExtension(*ExtWriter); + WriteModuleFileExtension(SemaRef, *ExtWriter); return Signature; } -- 2.7.4