@@ -119,9 +119,6 @@ class ASTWriter : public ASTDeserializationListener,
119119 // / The PCM manager which manages memory buffers for pcm files.
120120 InMemoryModuleCache &ModuleCache;
121121
122- // / The ASTContext we're writing.
123- ASTContext *Context = nullptr ;
124-
125122 // / The preprocessor we're writing.
126123 Preprocessor *PP = nullptr ;
127124
@@ -537,55 +534,55 @@ class ASTWriter : public ASTDeserializationListener,
537534 unsigned getSubmoduleID (Module *Mod);
538535
539536 // / Write the given subexpression to the bitstream.
540- void WriteSubStmt (Stmt *S);
537+ void WriteSubStmt (ASTContext &Context, Stmt *S);
541538
542539 void WriteBlockInfoBlock ();
543- void WriteControlBlock (Preprocessor &PP, ASTContext &Context,
544- StringRef isysroot);
540+ void WriteControlBlock (Preprocessor &PP, StringRef isysroot);
545541
546542 // / Write out the signature and diagnostic options, and return the signature.
547- void writeUnhashedControlBlock (Preprocessor &PP, ASTContext &Context );
543+ void writeUnhashedControlBlock (Preprocessor &PP);
548544 ASTFileSignature backpatchSignature ();
549545
550546 // / Calculate hash of the pcm content.
551547 std::pair<ASTFileSignature, ASTFileSignature> createSignature () const ;
552548 ASTFileSignature createSignatureForNamedModule () const ;
553549
554550 void WriteInputFiles (SourceManager &SourceMgr, HeaderSearchOptions &HSOpts);
555- void WriteSourceManagerBlock (SourceManager &SourceMgr,
556- const Preprocessor &PP);
551+ void WriteSourceManagerBlock (SourceManager &SourceMgr);
557552 void WritePreprocessor (const Preprocessor &PP, bool IsModule);
558553 void WriteHeaderSearch (const HeaderSearch &HS);
559554 void WritePreprocessorDetail (PreprocessingRecord &PPRec,
560555 uint64_t MacroOffsetsBase);
561- void WriteSubmodules (Module *WritingModule);
556+ void WriteSubmodules (Module *WritingModule, ASTContext *Context );
562557
563558 void WritePragmaDiagnosticMappings (const DiagnosticsEngine &Diag,
564559 bool isModule);
565560
566561 unsigned TypeExtQualAbbrev = 0 ;
567562 void WriteTypeAbbrevs ();
568- void WriteType (QualType T);
563+ void WriteType (ASTContext &Context, QualType T);
569564
570565 bool isLookupResultExternal (StoredDeclsList &Result, DeclContext *DC);
571566
572- void GenerateNameLookupTable (const DeclContext *DC,
567+ void GenerateNameLookupTable (ASTContext &Context, const DeclContext *DC,
573568 llvm::SmallVectorImpl<char > &LookupTable);
574569 uint64_t WriteDeclContextLexicalBlock (ASTContext &Context,
575570 const DeclContext *DC);
576571 uint64_t WriteDeclContextVisibleBlock (ASTContext &Context, DeclContext *DC);
577572 void WriteTypeDeclOffsets ();
578573 void WriteFileDeclIDsMap ();
579- void WriteComments ();
574+ void WriteComments (ASTContext &Context );
580575 void WriteSelectors (Sema &SemaRef);
581576 void WriteReferencedSelectorsPool (Sema &SemaRef);
582- void WriteIdentifierTable (Preprocessor &PP, IdentifierResolver & IdResolver,
577+ void WriteIdentifierTable (Preprocessor &PP, IdentifierResolver * IdResolver,
583578 bool IsModule);
584579 void WriteDeclAndTypes (ASTContext &Context);
585580 void PrepareWritingSpecialDecls (Sema &SemaRef);
586581 void WriteSpecialDeclRecords (Sema &SemaRef);
587- void WriteDeclUpdatesBlocks (RecordDataImpl &OffsetsRecord);
588- void WriteDeclContextVisibleUpdate (const DeclContext *DC);
582+ void WriteDeclUpdatesBlocks (ASTContext &Context,
583+ RecordDataImpl &OffsetsRecord);
584+ void WriteDeclContextVisibleUpdate (ASTContext &Context,
585+ const DeclContext *DC);
589586 void WriteFPPragmaOptions (const FPOptionsOverride &Opts);
590587 void WriteOpenCLExtensions (Sema &SemaRef);
591588 void WriteCUDAPragmas (Sema &SemaRef);
@@ -634,7 +631,7 @@ class ASTWriter : public ASTDeserializationListener,
634631 void WriteDeclAbbrevs ();
635632 void WriteDecl (ASTContext &Context, Decl *D);
636633
637- ASTFileSignature WriteASTCore (Sema &SemaRef , StringRef isysroot,
634+ ASTFileSignature WriteASTCore (Sema *SemaPtr , StringRef isysroot,
638635 Module *WritingModule);
639636
640637public:
@@ -647,22 +644,20 @@ class ASTWriter : public ASTDeserializationListener,
647644 bool GeneratingReducedBMI = false );
648645 ~ASTWriter () override ;
649646
650- ASTContext &getASTContext () const {
651- assert (Context && " requested AST context when not writing AST" );
652- return *Context;
653- }
654-
655647 const LangOptions &getLangOpts () const ;
656648
657649 // / Get a timestamp for output into the AST file. The actual timestamp
658650 // / of the specified file may be ignored if we have been instructed to not
659651 // / include timestamps in the output file.
660652 time_t getTimestampForOutput (const FileEntry *E) const ;
661653
662- // / Write a precompiled header for the given semantic analysis.
654+ // / Write a precompiled header or a module with the AST produced by the
655+ // / \c Sema object, or a dependency scanner module with the preprocessor state
656+ // / produced by the \c Preprocessor object.
663657 // /
664- // / \param SemaRef a reference to the semantic analysis object that processed
665- // / the AST to be written into the precompiled header.
658+ // / \param Subject The \c Sema object that processed the AST to be written, or
659+ // / in the case of a dependency scanner module the \c Preprocessor that holds
660+ // / the state.
666661 // /
667662 // / \param WritingModule The module that we are writing. If null, we are
668663 // / writing a precompiled header.
@@ -673,8 +668,9 @@ class ASTWriter : public ASTDeserializationListener,
673668 // /
674669 // / \return the module signature, which eventually will be a hash of
675670 // / the module but currently is merely a random 32-bit number.
676- ASTFileSignature WriteAST (Sema &SemaRef, StringRef OutputFile,
677- Module *WritingModule, StringRef isysroot,
671+ ASTFileSignature WriteAST (llvm::PointerUnion<Sema *, Preprocessor *> Subject,
672+ StringRef OutputFile, Module *WritingModule,
673+ StringRef isysroot,
678674 bool ShouldCacheASTInMemory = false );
679675
680676 // / Emit a token.
@@ -717,10 +713,10 @@ class ASTWriter : public ASTDeserializationListener,
717713 uint32_t getMacroDirectivesOffset (const IdentifierInfo *Name);
718714
719715 // / Emit a reference to a type.
720- void AddTypeRef (QualType T, RecordDataImpl &Record);
716+ void AddTypeRef (ASTContext &Context, QualType T, RecordDataImpl &Record);
721717
722718 // / Force a type to be emitted and get its ID.
723- serialization::TypeID GetOrCreateTypeID (QualType T);
719+ serialization::TypeID GetOrCreateTypeID (ASTContext &Context, QualType T);
724720
725721 // / Find the first local declaration of a given local redeclarable
726722 // / decl.
@@ -921,9 +917,9 @@ class PCHGenerator : public SemaConsumer {
921917 void anchor () override ;
922918
923919 Preprocessor &PP;
920+ llvm::PointerUnion<Sema *, Preprocessor *> Subject;
924921 std::string OutputFile;
925922 std::string isysroot;
926- Sema *SemaPtr;
927923 std::shared_ptr<PCHBuffer> Buffer;
928924 llvm::BitstreamWriter Stream;
929925 ASTWriter Writer;
@@ -938,9 +934,7 @@ class PCHGenerator : public SemaConsumer {
938934 bool isComplete () const { return Buffer->IsComplete ; }
939935 PCHBuffer *getBufferPtr () { return Buffer.get (); }
940936 StringRef getOutputFile () const { return OutputFile; }
941- DiagnosticsEngine &getDiagnostics () const {
942- return SemaPtr->getDiagnostics ();
943- }
937+ DiagnosticsEngine &getDiagnostics () const ;
944938 Preprocessor &getPreprocessor () { return PP; }
945939
946940 virtual Module *getEmittingModule (ASTContext &Ctx);
@@ -956,7 +950,7 @@ class PCHGenerator : public SemaConsumer {
956950 bool GeneratingReducedBMI = false );
957951 ~PCHGenerator () override ;
958952
959- void InitializeSema (Sema &S) override { SemaPtr = &S; }
953+ void InitializeSema (Sema &S) override ;
960954 void HandleTranslationUnit (ASTContext &Ctx) override ;
961955 void HandleVTable (CXXRecordDecl *RD) override { Writer.handleVTable (RD); }
962956 ASTMutationListener *GetASTMutationListener () override ;
0 commit comments