@@ -119,9 +119,6 @@ class ASTWriter : public ASTDeserializationListener,
119
119
// / The PCM manager which manages memory buffers for pcm files.
120
120
InMemoryModuleCache &ModuleCache;
121
121
122
- // / The ASTContext we're writing.
123
- ASTContext *Context = nullptr ;
124
-
125
122
// / The preprocessor we're writing.
126
123
Preprocessor *PP = nullptr ;
127
124
@@ -537,55 +534,55 @@ class ASTWriter : public ASTDeserializationListener,
537
534
unsigned getSubmoduleID (Module *Mod);
538
535
539
536
// / Write the given subexpression to the bitstream.
540
- void WriteSubStmt (Stmt *S);
537
+ void WriteSubStmt (ASTContext &Context, Stmt *S);
541
538
542
539
void WriteBlockInfoBlock ();
543
- void WriteControlBlock (Preprocessor &PP, ASTContext &Context,
544
- StringRef isysroot);
540
+ void WriteControlBlock (Preprocessor &PP, StringRef isysroot);
545
541
546
542
// / Write out the signature and diagnostic options, and return the signature.
547
- void writeUnhashedControlBlock (Preprocessor &PP, ASTContext &Context );
543
+ void writeUnhashedControlBlock (Preprocessor &PP);
548
544
ASTFileSignature backpatchSignature ();
549
545
550
546
// / Calculate hash of the pcm content.
551
547
std::pair<ASTFileSignature, ASTFileSignature> createSignature () const ;
552
548
ASTFileSignature createSignatureForNamedModule () const ;
553
549
554
550
void WriteInputFiles (SourceManager &SourceMgr, HeaderSearchOptions &HSOpts);
555
- void WriteSourceManagerBlock (SourceManager &SourceMgr,
556
- const Preprocessor &PP);
551
+ void WriteSourceManagerBlock (SourceManager &SourceMgr);
557
552
void WritePreprocessor (const Preprocessor &PP, bool IsModule);
558
553
void WriteHeaderSearch (const HeaderSearch &HS);
559
554
void WritePreprocessorDetail (PreprocessingRecord &PPRec,
560
555
uint64_t MacroOffsetsBase);
561
- void WriteSubmodules (Module *WritingModule);
556
+ void WriteSubmodules (Module *WritingModule, ASTContext *Context );
562
557
563
558
void WritePragmaDiagnosticMappings (const DiagnosticsEngine &Diag,
564
559
bool isModule);
565
560
566
561
unsigned TypeExtQualAbbrev = 0 ;
567
562
void WriteTypeAbbrevs ();
568
- void WriteType (QualType T);
563
+ void WriteType (ASTContext &Context, QualType T);
569
564
570
565
bool isLookupResultExternal (StoredDeclsList &Result, DeclContext *DC);
571
566
572
- void GenerateNameLookupTable (const DeclContext *DC,
567
+ void GenerateNameLookupTable (ASTContext &Context, const DeclContext *DC,
573
568
llvm::SmallVectorImpl<char > &LookupTable);
574
569
uint64_t WriteDeclContextLexicalBlock (ASTContext &Context,
575
570
const DeclContext *DC);
576
571
uint64_t WriteDeclContextVisibleBlock (ASTContext &Context, DeclContext *DC);
577
572
void WriteTypeDeclOffsets ();
578
573
void WriteFileDeclIDsMap ();
579
- void WriteComments ();
574
+ void WriteComments (ASTContext &Context );
580
575
void WriteSelectors (Sema &SemaRef);
581
576
void WriteReferencedSelectorsPool (Sema &SemaRef);
582
- void WriteIdentifierTable (Preprocessor &PP, IdentifierResolver & IdResolver,
577
+ void WriteIdentifierTable (Preprocessor &PP, IdentifierResolver * IdResolver,
583
578
bool IsModule);
584
579
void WriteDeclAndTypes (ASTContext &Context);
585
580
void PrepareWritingSpecialDecls (Sema &SemaRef);
586
581
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);
589
586
void WriteFPPragmaOptions (const FPOptionsOverride &Opts);
590
587
void WriteOpenCLExtensions (Sema &SemaRef);
591
588
void WriteCUDAPragmas (Sema &SemaRef);
@@ -634,7 +631,7 @@ class ASTWriter : public ASTDeserializationListener,
634
631
void WriteDeclAbbrevs ();
635
632
void WriteDecl (ASTContext &Context, Decl *D);
636
633
637
- ASTFileSignature WriteASTCore (Sema &SemaRef , StringRef isysroot,
634
+ ASTFileSignature WriteASTCore (Sema *SemaPtr , StringRef isysroot,
638
635
Module *WritingModule);
639
636
640
637
public:
@@ -647,22 +644,20 @@ class ASTWriter : public ASTDeserializationListener,
647
644
bool GeneratingReducedBMI = false );
648
645
~ASTWriter () override ;
649
646
650
- ASTContext &getASTContext () const {
651
- assert (Context && " requested AST context when not writing AST" );
652
- return *Context;
653
- }
654
-
655
647
const LangOptions &getLangOpts () const ;
656
648
657
649
// / Get a timestamp for output into the AST file. The actual timestamp
658
650
// / of the specified file may be ignored if we have been instructed to not
659
651
// / include timestamps in the output file.
660
652
time_t getTimestampForOutput (const FileEntry *E) const ;
661
653
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.
663
657
// /
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.
666
661
// /
667
662
// / \param WritingModule The module that we are writing. If null, we are
668
663
// / writing a precompiled header.
@@ -673,8 +668,9 @@ class ASTWriter : public ASTDeserializationListener,
673
668
// /
674
669
// / \return the module signature, which eventually will be a hash of
675
670
// / 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,
678
674
bool ShouldCacheASTInMemory = false );
679
675
680
676
// / Emit a token.
@@ -717,10 +713,10 @@ class ASTWriter : public ASTDeserializationListener,
717
713
uint32_t getMacroDirectivesOffset (const IdentifierInfo *Name);
718
714
719
715
// / Emit a reference to a type.
720
- void AddTypeRef (QualType T, RecordDataImpl &Record);
716
+ void AddTypeRef (ASTContext &Context, QualType T, RecordDataImpl &Record);
721
717
722
718
// / Force a type to be emitted and get its ID.
723
- serialization::TypeID GetOrCreateTypeID (QualType T);
719
+ serialization::TypeID GetOrCreateTypeID (ASTContext &Context, QualType T);
724
720
725
721
// / Find the first local declaration of a given local redeclarable
726
722
// / decl.
@@ -921,9 +917,9 @@ class PCHGenerator : public SemaConsumer {
921
917
void anchor () override ;
922
918
923
919
Preprocessor &PP;
920
+ llvm::PointerUnion<Sema *, Preprocessor *> Subject;
924
921
std::string OutputFile;
925
922
std::string isysroot;
926
- Sema *SemaPtr;
927
923
std::shared_ptr<PCHBuffer> Buffer;
928
924
llvm::BitstreamWriter Stream;
929
925
ASTWriter Writer;
@@ -938,9 +934,7 @@ class PCHGenerator : public SemaConsumer {
938
934
bool isComplete () const { return Buffer->IsComplete ; }
939
935
PCHBuffer *getBufferPtr () { return Buffer.get (); }
940
936
StringRef getOutputFile () const { return OutputFile; }
941
- DiagnosticsEngine &getDiagnostics () const {
942
- return SemaPtr->getDiagnostics ();
943
- }
937
+ DiagnosticsEngine &getDiagnostics () const ;
944
938
Preprocessor &getPreprocessor () { return PP; }
945
939
946
940
virtual Module *getEmittingModule (ASTContext &Ctx);
@@ -956,7 +950,7 @@ class PCHGenerator : public SemaConsumer {
956
950
bool GeneratingReducedBMI = false );
957
951
~PCHGenerator () override ;
958
952
959
- void InitializeSema (Sema &S) override { SemaPtr = &S; }
953
+ void InitializeSema (Sema &S) override ;
960
954
void HandleTranslationUnit (ASTContext &Ctx) override ;
961
955
void HandleVTable (CXXRecordDecl *RD) override { Writer.handleVTable (RD); }
962
956
ASTMutationListener *GetASTMutationListener () override ;
0 commit comments