Module file extensions: pass a Sema through to the extension writer.
authorDouglas Gregor <dgregor@apple.com>
Tue, 8 Dec 2015 22:43:32 +0000 (22:43 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 8 Dec 2015 22:43:32 +0000 (22:43 +0000)
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
clang/include/clang/Serialization/ModuleFileExtension.h
clang/lib/Frontend/TestModuleFileExtension.cpp
clang/lib/Frontend/TestModuleFileExtension.h
clang/lib/Serialization/ASTWriter.cpp

index 86dbcee..ed34547 100644 (file)
@@ -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;
index a8f8386..ba2e2fd 100644 (file)
@@ -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
index c020468..d1b20c4 100644 (file)
@@ -19,6 +19,7 @@ using namespace clang::serialization;
 TestModuleFileExtension::Writer::~Writer() { }
 
 void TestModuleFileExtension::Writer::writeExtensionContents(
+       Sema &SemaRef,
        llvm::BitstreamWriter &Stream) {
   using namespace llvm;
 
index 2a72454..41f3ca9 100644 (file)
@@ -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 {
index 7d3cefe..128935c 100644 (file)
@@ -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;
 }