Skip to content

Commit a2f9d1d

Browse files
authored
[clang][serialization] Enable ASTWriter to work with Preprocessor only (#115237)
This PR builds on top of #115235 and makes it possible to call `ASTWriter::WriteAST()` with `Preprocessor` only instead of full `Sema` object. So far, there are no clients that leverage the new capability - that will come in a follow-up commit.
1 parent 058ac83 commit a2f9d1d

File tree

4 files changed

+115
-88
lines changed

4 files changed

+115
-88
lines changed

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ class ASTWriter : public ASTDeserializationListener,
564564
void WriteHeaderSearch(const HeaderSearch &HS);
565565
void WritePreprocessorDetail(PreprocessingRecord &PPRec,
566566
uint64_t MacroOffsetsBase);
567-
void WriteSubmodules(Module *WritingModule, ASTContext &Context);
567+
void WriteSubmodules(Module *WritingModule, ASTContext *Context);
568568

569569
void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag,
570570
bool isModule);
@@ -585,7 +585,7 @@ class ASTWriter : public ASTDeserializationListener,
585585
void WriteComments(ASTContext &Context);
586586
void WriteSelectors(Sema &SemaRef);
587587
void WriteReferencedSelectorsPool(Sema &SemaRef);
588-
void WriteIdentifierTable(Preprocessor &PP, IdentifierResolver &IdResolver,
588+
void WriteIdentifierTable(Preprocessor &PP, IdentifierResolver *IdResolver,
589589
bool IsModule);
590590
void WriteDeclAndTypes(ASTContext &Context);
591591
void PrepareWritingSpecialDecls(Sema &SemaRef);
@@ -642,7 +642,7 @@ class ASTWriter : public ASTDeserializationListener,
642642
void WriteDeclAbbrevs();
643643
void WriteDecl(ASTContext &Context, Decl *D);
644644

645-
ASTFileSignature WriteASTCore(Sema &SemaRef, StringRef isysroot,
645+
ASTFileSignature WriteASTCore(Sema *SemaPtr, StringRef isysroot,
646646
Module *WritingModule);
647647

648648
public:
@@ -662,10 +662,13 @@ class ASTWriter : public ASTDeserializationListener,
662662
/// include timestamps in the output file.
663663
time_t getTimestampForOutput(const FileEntry *E) const;
664664

665-
/// Write a precompiled header for the given semantic analysis.
665+
/// Write a precompiled header or a module with the AST produced by the
666+
/// \c Sema object, or a dependency scanner module with the preprocessor state
667+
/// produced by the \c Preprocessor object.
666668
///
667-
/// \param SemaRef a reference to the semantic analysis object that processed
668-
/// the AST to be written into the precompiled header.
669+
/// \param Subject The \c Sema object that processed the AST to be written, or
670+
/// in the case of a dependency scanner module the \c Preprocessor that holds
671+
/// the state.
669672
///
670673
/// \param WritingModule The module that we are writing. If null, we are
671674
/// writing a precompiled header.
@@ -676,8 +679,9 @@ class ASTWriter : public ASTDeserializationListener,
676679
///
677680
/// \return the module signature, which eventually will be a hash of
678681
/// the module but currently is merely a random 32-bit number.
679-
ASTFileSignature WriteAST(Sema &SemaRef, StringRef OutputFile,
680-
Module *WritingModule, StringRef isysroot,
682+
ASTFileSignature WriteAST(llvm::PointerUnion<Sema *, Preprocessor *> Subject,
683+
StringRef OutputFile, Module *WritingModule,
684+
StringRef isysroot,
681685
bool ShouldCacheASTInMemory = false);
682686

683687
/// Emit a token.

clang/lib/Frontend/ASTUnit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2359,7 +2359,7 @@ bool ASTUnit::Save(StringRef File) {
23592359

23602360
static bool serializeUnit(ASTWriter &Writer, SmallVectorImpl<char> &Buffer,
23612361
Sema &S, raw_ostream &OS) {
2362-
Writer.WriteAST(S, std::string(), nullptr, "");
2362+
Writer.WriteAST(&S, std::string(), nullptr, "");
23632363

23642364
// Write the generated bitstream to "Out".
23652365
if (!Buffer.empty())

0 commit comments

Comments
 (0)