clang 20.0.0git
ASTWriter.h
Go to the documentation of this file.
1//===- ASTWriter.h - AST File Writer ----------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the ASTWriter class, which writes an AST file
10// containing a serialized representation of a translation unit.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_SERIALIZATION_ASTWRITER_H
15#define LLVM_CLANG_SERIALIZATION_ASTWRITER_H
16
18#include "clang/AST/Decl.h"
19#include "clang/AST/Type.h"
20#include "clang/Basic/LLVM.h"
22#include "clang/Sema/Sema.h"
28#include "llvm/ADT/ArrayRef.h"
29#include "llvm/ADT/DenseMap.h"
30#include "llvm/ADT/DenseSet.h"
31#include "llvm/ADT/MapVector.h"
32#include "llvm/ADT/STLExtras.h"
33#include "llvm/ADT/SetVector.h"
34#include "llvm/ADT/SmallVector.h"
35#include "llvm/ADT/StringRef.h"
36#include "llvm/Bitstream/BitstreamWriter.h"
37#include <cassert>
38#include <cstddef>
39#include <cstdint>
40#include <ctime>
41#include <memory>
42#include <queue>
43#include <string>
44#include <utility>
45#include <vector>
46
47namespace clang {
48
49class ASTContext;
50class ASTReader;
51class Attr;
52class CXXRecordDecl;
53class FileEntry;
54class FPOptionsOverride;
55class FunctionDecl;
56class HeaderSearch;
57class HeaderSearchOptions;
58class IdentifierResolver;
59class LangOptions;
60class MacroDefinitionRecord;
61class MacroInfo;
62class Module;
63class InMemoryModuleCache;
64class ModuleFileExtension;
65class ModuleFileExtensionWriter;
66class NamedDecl;
67class ObjCInterfaceDecl;
68class PreprocessingRecord;
69class Preprocessor;
70class RecordDecl;
71class Sema;
72class SourceManager;
73class Stmt;
74class StoredDeclsList;
75class SwitchCase;
76class Token;
77
78namespace SrcMgr {
79class FileInfo;
80} // namespace SrcMgr
81
82/// Writes an AST file containing the contents of a translation unit.
83///
84/// The ASTWriter class produces a bitstream containing the serialized
85/// representation of a given abstract syntax tree and its supporting
86/// data structures. This bitstream can be de-serialized via an
87/// instance of the ASTReader class.
89 public ASTMutationListener {
90public:
91 friend class ASTDeclWriter;
92 friend class ASTRecordWriter;
93
97
98private:
99 /// Map that provides the ID numbers of each type within the
100 /// output stream, plus those deserialized from a chained PCH.
101 ///
102 /// The ID numbers of types are consecutive (in order of discovery)
103 /// and start at 1. 0 is reserved for NULL. When types are actually
104 /// stored in the stream, the ID number is shifted by 2 bits to
105 /// allow for the const/volatile qualifiers.
106 ///
107 /// Keys in the map never have const/volatile qualifiers.
108 using TypeIdxMap = llvm::DenseMap<QualType, serialization::TypeIdx,
110
112
113 /// The bitstream writer used to emit this precompiled header.
114 llvm::BitstreamWriter &Stream;
115
116 /// The buffer associated with the bitstream.
117 const SmallVectorImpl<char> &Buffer;
118
119 /// The PCM manager which manages memory buffers for pcm files.
120 InMemoryModuleCache &ModuleCache;
121
122 /// The ASTContext we're writing.
123 ASTContext *Context = nullptr;
124
125 /// The preprocessor we're writing.
126 Preprocessor *PP = nullptr;
127
128 /// The reader of existing AST files, if we're chaining.
129 ASTReader *Chain = nullptr;
130
131 /// The module we're currently writing, if any.
132 Module *WritingModule = nullptr;
133
134 /// The byte range representing all the UNHASHED_CONTROL_BLOCK.
135 std::pair<uint64_t, uint64_t> UnhashedControlBlockRange;
136 /// The bit offset of the AST block hash blob.
137 uint64_t ASTBlockHashOffset = 0;
138 /// The bit offset of the signature blob.
139 uint64_t SignatureOffset = 0;
140
141 /// The bit offset of the first bit inside the AST_BLOCK.
142 uint64_t ASTBlockStartOffset = 0;
143
144 /// The byte range representing all the AST_BLOCK.
145 std::pair<uint64_t, uint64_t> ASTBlockRange;
146
147 /// The base directory for any relative paths we emit.
148 std::string BaseDirectory;
149
150 /// Indicates whether timestamps should be written to the produced
151 /// module file. This is the case for files implicitly written to the
152 /// module cache, where we need the timestamps to determine if the module
153 /// file is up to date, but not otherwise.
154 bool IncludeTimestamps;
155
156 /// Indicates whether the AST file being written is an implicit module.
157 /// If that's the case, we may be able to skip writing some information that
158 /// are guaranteed to be the same in the importer by the context hash.
159 bool BuildingImplicitModule = false;
160
161 /// Indicates when the AST writing is actively performing
162 /// serialization, rather than just queueing updates.
163 bool WritingAST = false;
164
165 /// Indicates that we are done serializing the collection of decls
166 /// and types to emit.
167 bool DoneWritingDeclsAndTypes = false;
168
169 /// Indicates that the AST contained compiler errors.
170 bool ASTHasCompilerErrors = false;
171
172 /// Indicates that we're going to generate the reduced BMI for C++20
173 /// named modules.
174 bool GeneratingReducedBMI = false;
175
176 /// Mapping from input file entries to the index into the
177 /// offset table where information about that input file is stored.
178 llvm::DenseMap<const FileEntry *, uint32_t> InputFileIDs;
179
180 /// Stores a declaration or a type to be written to the AST file.
181 class DeclOrType {
182 public:
183 DeclOrType(Decl *D) : Stored(D), IsType(false) {}
184 DeclOrType(QualType T) : Stored(T.getAsOpaquePtr()), IsType(true) {}
185
186 bool isType() const { return IsType; }
187 bool isDecl() const { return !IsType; }
188
189 QualType getType() const {
190 assert(isType() && "Not a type!");
191 return QualType::getFromOpaquePtr(Stored);
192 }
193
194 Decl *getDecl() const {
195 assert(isDecl() && "Not a decl!");
196 return static_cast<Decl *>(Stored);
197 }
198
199 private:
200 void *Stored;
201 bool IsType;
202 };
203
204 /// The declarations and types to emit.
205 std::queue<DeclOrType> DeclTypesToEmit;
206
207 /// The delayed namespace to emit. Only meaningful for reduced BMI.
208 ///
209 /// In reduced BMI, we want to elide the unreachable declarations in
210 /// the global module fragment. However, in ASTWriterDecl, when we see
211 /// a namespace, all the declarations in the namespace would be emitted.
212 /// So the optimization become meaningless. To solve the issue, we
213 /// delay recording all the declarations until we emit all the declarations.
214 /// Then we can safely record the reached declarations only.
216
217 /// The first ID number we can use for our own declarations.
219
220 /// The decl ID that will be assigned to the next new decl.
221 LocalDeclID NextDeclID = FirstDeclID;
222
223 /// Map that provides the ID numbers of each declaration within
224 /// the output stream, as well as those deserialized from a chained PCH.
225 ///
226 /// The ID numbers of declarations are consecutive (in order of
227 /// discovery) and start at 2. 1 is reserved for the translation
228 /// unit, while 0 is reserved for NULL.
229 llvm::DenseMap<const Decl *, LocalDeclID> DeclIDs;
230
231 /// Set of predefined decls. This is a helper data to determine if a decl
232 /// is predefined. It should be more clear and safer to query the set
233 /// instead of comparing the result of `getDeclID()` or `GetDeclRef()`.
235
236 /// Offset of each declaration in the bitstream, indexed by
237 /// the declaration's ID.
238 std::vector<serialization::DeclOffset> DeclOffsets;
239
240 /// The offset of the DECLTYPES_BLOCK. The offsets in DeclOffsets
241 /// are relative to this value.
242 uint64_t DeclTypesBlockStartOffset = 0;
243
244 /// Sorted (by file offset) vector of pairs of file offset/LocalDeclID.
245 using LocDeclIDsTy = SmallVector<std::pair<unsigned, LocalDeclID>, 64>;
246 struct DeclIDInFileInfo {
247 LocDeclIDsTy DeclIDs;
248
249 /// Set when the DeclIDs vectors from all files are joined, this
250 /// indicates the index that this particular vector has in the global one.
251 unsigned FirstDeclIndex;
252 };
253 using FileDeclIDsTy =
254 llvm::DenseMap<FileID, std::unique_ptr<DeclIDInFileInfo>>;
255
256 /// Map from file SLocEntries to info about the file-level declarations
257 /// that it contains.
258 FileDeclIDsTy FileDeclIDs;
259
260 void associateDeclWithFile(const Decl *D, LocalDeclID);
261
262 /// The first ID number we can use for our own types.
264
265 /// The type ID that will be assigned to the next new type.
266 serialization::TypeID NextTypeID = FirstTypeID;
267
268 /// Map that provides the ID numbers of each type within the
269 /// output stream, plus those deserialized from a chained PCH.
270 ///
271 /// The ID numbers of types are consecutive (in order of discovery)
272 /// and start at 1. 0 is reserved for NULL. When types are actually
273 /// stored in the stream, the ID number is shifted by 2 bits to
274 /// allow for the const/volatile qualifiers.
275 ///
276 /// Keys in the map never have const/volatile qualifiers.
277 TypeIdxMap TypeIdxs;
278
279 /// Offset of each type in the bitstream, indexed by
280 /// the type's ID.
281 std::vector<serialization::UnalignedUInt64> TypeOffsets;
282
283 /// The first ID number we can use for our own identifiers.
285
286 /// The identifier ID that will be assigned to the next new identifier.
287 serialization::IdentifierID NextIdentID = FirstIdentID;
288
289 /// Map that provides the ID numbers of each identifier in
290 /// the output stream.
291 ///
292 /// The ID numbers for identifiers are consecutive (in order of
293 /// discovery), starting at 1. An ID of zero refers to a NULL
294 /// IdentifierInfo.
295 llvm::MapVector<const IdentifierInfo *, serialization::IdentifierID> IdentifierIDs;
296
297 /// The first ID number we can use for our own macros.
299
300 /// The identifier ID that will be assigned to the next new identifier.
301 serialization::MacroID NextMacroID = FirstMacroID;
302
303 /// Map that provides the ID numbers of each macro.
304 llvm::DenseMap<MacroInfo *, serialization::MacroID> MacroIDs;
305
306 struct MacroInfoToEmitData {
307 const IdentifierInfo *Name;
308 MacroInfo *MI;
310 };
311
312 /// The macro infos to emit.
313 std::vector<MacroInfoToEmitData> MacroInfosToEmit;
314
315 llvm::DenseMap<const IdentifierInfo *, uint32_t>
316 IdentMacroDirectivesOffsetMap;
317
318 /// @name FlushStmt Caches
319 /// @{
320
321 /// Set of parent Stmts for the currently serializing sub-stmt.
322 llvm::DenseSet<Stmt *> ParentStmts;
323
324 /// Offsets of sub-stmts already serialized. The offset points
325 /// just after the stmt record.
326 llvm::DenseMap<Stmt *, uint64_t> SubStmtEntries;
327
328 /// @}
329
330 /// Offsets of each of the identifier IDs into the identifier
331 /// table.
332 std::vector<uint32_t> IdentifierOffsets;
333
334 /// The first ID number we can use for our own submodules.
335 serialization::SubmoduleID FirstSubmoduleID =
337
338 /// The submodule ID that will be assigned to the next new submodule.
339 serialization::SubmoduleID NextSubmoduleID = FirstSubmoduleID;
340
341 /// The first ID number we can use for our own selectors.
342 serialization::SelectorID FirstSelectorID =
344
345 /// The selector ID that will be assigned to the next new selector.
346 serialization::SelectorID NextSelectorID = FirstSelectorID;
347
348 /// Map that provides the ID numbers of each Selector.
349 llvm::MapVector<Selector, serialization::SelectorID> SelectorIDs;
350
351 /// Offset of each selector within the method pool/selector
352 /// table, indexed by the Selector ID (-1).
353 std::vector<uint32_t> SelectorOffsets;
354
355 /// Mapping from macro definitions (as they occur in the preprocessing
356 /// record) to the macro IDs.
357 llvm::DenseMap<const MacroDefinitionRecord *,
358 serialization::PreprocessedEntityID> MacroDefinitions;
359
360 /// Cache of indices of anonymous declarations within their lexical
361 /// contexts.
362 llvm::DenseMap<const Decl *, unsigned> AnonymousDeclarationNumbers;
363
364 /// The external top level module during the writing process. Used to
365 /// generate signature for the module file being written.
366 ///
367 /// Only meaningful for standard C++ named modules. See the comments in
368 /// createSignatureForNamedModule() for details.
369 llvm::DenseSet<Module *> TouchedTopLevelModules;
370
371 /// An update to a Decl.
372 class DeclUpdate {
373 /// A DeclUpdateKind.
374 unsigned Kind;
375 union {
376 const Decl *Dcl;
377 void *Type;
379 unsigned Val;
380 Module *Mod;
381 const Attr *Attribute;
382 };
383
384 public:
385 DeclUpdate(unsigned Kind) : Kind(Kind), Dcl(nullptr) {}
386 DeclUpdate(unsigned Kind, const Decl *Dcl) : Kind(Kind), Dcl(Dcl) {}
387 DeclUpdate(unsigned Kind, QualType Type)
388 : Kind(Kind), Type(Type.getAsOpaquePtr()) {}
389 DeclUpdate(unsigned Kind, SourceLocation Loc)
390 : Kind(Kind), Loc(Loc.getRawEncoding()) {}
391 DeclUpdate(unsigned Kind, unsigned Val) : Kind(Kind), Val(Val) {}
392 DeclUpdate(unsigned Kind, Module *M) : Kind(Kind), Mod(M) {}
393 DeclUpdate(unsigned Kind, const Attr *Attribute)
394 : Kind(Kind), Attribute(Attribute) {}
395
396 unsigned getKind() const { return Kind; }
397 const Decl *getDecl() const { return Dcl; }
398 QualType getType() const { return QualType::getFromOpaquePtr(Type); }
399
400 SourceLocation getLoc() const {
402 }
403
404 unsigned getNumber() const { return Val; }
405 Module *getModule() const { return Mod; }
406 const Attr *getAttr() const { return Attribute; }
407 };
408
409 using UpdateRecord = SmallVector<DeclUpdate, 1>;
410 using DeclUpdateMap = llvm::MapVector<const Decl *, UpdateRecord>;
411
412 /// Mapping from declarations that came from a chained PCH to the
413 /// record containing modifications to them.
414 DeclUpdateMap DeclUpdates;
415
416 /// DeclUpdates added during parsing the GMF. We split these from
417 /// DeclUpdates since we want to add these updates in GMF on need.
418 /// Only meaningful for reduced BMI.
419 DeclUpdateMap DeclUpdatesFromGMF;
420
421 using FirstLatestDeclMap = llvm::DenseMap<Decl *, Decl *>;
422
423 /// Map of first declarations from a chained PCH that point to the
424 /// most recent declarations in another PCH.
425 FirstLatestDeclMap FirstLatestDecls;
426
427 /// Declarations encountered that might be external
428 /// definitions.
429 ///
430 /// We keep track of external definitions and other 'interesting' declarations
431 /// as we are emitting declarations to the AST file. The AST file contains a
432 /// separate record for these declarations, which are provided to the AST
433 /// consumer by the AST reader. This is behavior is required to properly cope with,
434 /// e.g., tentative variable definitions that occur within
435 /// headers. The declarations themselves are stored as declaration
436 /// IDs, since they will be written out to an EAGERLY_DESERIALIZED_DECLS
437 /// record.
438 RecordData EagerlyDeserializedDecls;
439 RecordData ModularCodegenDecls;
440
441 /// DeclContexts that have received extensions since their serialized
442 /// form.
443 ///
444 /// For namespaces, when we're chaining and encountering a namespace, we check
445 /// if its primary namespace comes from the chain. If it does, we add the
446 /// primary to this set, so that we can write out lexical content updates for
447 /// it.
449
450 /// Keeps track of declarations that we must emit, even though we're
451 /// not guaranteed to be able to find them by walking the AST starting at the
452 /// translation unit.
453 SmallVector<const Decl *, 16> DeclsToEmitEvenIfUnreferenced;
454
455 /// The set of Objective-C class that have categories we
456 /// should serialize.
457 llvm::SetVector<ObjCInterfaceDecl *> ObjCClassesWithCategories;
458
459 /// The set of declarations that may have redeclaration chains that
460 /// need to be serialized.
462
463 /// A cache of the first local declaration for "interesting"
464 /// redeclaration chains.
465 llvm::DenseMap<const Decl *, const Decl *> FirstLocalDeclCache;
466
467 /// Mapping from SwitchCase statements to IDs.
468 llvm::DenseMap<SwitchCase *, unsigned> SwitchCaseIDs;
469
470 /// The number of statements written to the AST file.
471 unsigned NumStatements = 0;
472
473 /// The number of macros written to the AST file.
474 unsigned NumMacros = 0;
475
476 /// The number of lexical declcontexts written to the AST
477 /// file.
478 unsigned NumLexicalDeclContexts = 0;
479
480 /// The number of visible declcontexts written to the AST
481 /// file.
482 unsigned NumVisibleDeclContexts = 0;
483
484 /// A mapping from each known submodule to its ID number, which will
485 /// be a positive integer.
486 llvm::DenseMap<const Module *, unsigned> SubmoduleIDs;
487
488 /// A list of the module file extension writers.
489 std::vector<std::unique_ptr<ModuleFileExtensionWriter>>
490 ModuleFileExtensionWriters;
491
492 /// Mapping from a source location entry to whether it is affecting or not.
493 llvm::BitVector IsSLocAffecting;
494
495 /// Mapping from \c FileID to an index into the FileID adjustment table.
496 std::vector<FileID> NonAffectingFileIDs;
497 std::vector<unsigned> NonAffectingFileIDAdjustments;
498
499 /// Mapping from an offset to an index into the offset adjustment table.
500 std::vector<SourceRange> NonAffectingRanges;
501 std::vector<SourceLocation::UIntTy> NonAffectingOffsetAdjustments;
502
503 /// A list of classes which need to emit the VTable in the corresponding
504 /// object file.
505 llvm::SmallVector<CXXRecordDecl *> PendingEmittingVTables;
506
507 /// Computes input files that didn't affect compilation of the current module,
508 /// and initializes data structures necessary for leaving those files out
509 /// during \c SourceManager serialization.
510 void computeNonAffectingInputFiles();
511
512 /// Some affecting files can be included from files that are not affecting.
513 /// This function erases source locations pointing into such files.
514 SourceLocation getAffectingIncludeLoc(const SourceManager &SourceMgr,
515 const SrcMgr::FileInfo &File);
516
517 /// Returns an adjusted \c FileID, accounting for any non-affecting input
518 /// files.
519 FileID getAdjustedFileID(FileID FID) const;
520 /// Returns an adjusted number of \c FileIDs created within the specified \c
521 /// FileID, accounting for any non-affecting input files.
522 unsigned getAdjustedNumCreatedFIDs(FileID FID) const;
523 /// Returns an adjusted \c SourceLocation, accounting for any non-affecting
524 /// input files.
525 SourceLocation getAdjustedLocation(SourceLocation Loc) const;
526 /// Returns an adjusted \c SourceRange, accounting for any non-affecting input
527 /// files.
528 SourceRange getAdjustedRange(SourceRange Range) const;
529 /// Returns an adjusted \c SourceLocation offset, accounting for any
530 /// non-affecting input files.
531 SourceLocation::UIntTy getAdjustedOffset(SourceLocation::UIntTy Offset) const;
532 /// Returns an adjustment for offset into SourceManager, accounting for any
533 /// non-affecting input files.
534 SourceLocation::UIntTy getAdjustment(SourceLocation::UIntTy Offset) const;
535
536 /// Retrieve or create a submodule ID for this module.
537 unsigned getSubmoduleID(Module *Mod);
538
539 /// Write the given subexpression to the bitstream.
540 void WriteSubStmt(Stmt *S);
541
542 void WriteBlockInfoBlock();
543 void WriteControlBlock(Preprocessor &PP, ASTContext &Context,
544 StringRef isysroot);
545
546 /// Write out the signature and diagnostic options, and return the signature.
547 void writeUnhashedControlBlock(Preprocessor &PP, ASTContext &Context);
548 ASTFileSignature backpatchSignature();
549
550 /// Calculate hash of the pcm content.
551 std::pair<ASTFileSignature, ASTFileSignature> createSignature() const;
552 ASTFileSignature createSignatureForNamedModule() const;
553
554 void WriteInputFiles(SourceManager &SourceMgr, HeaderSearchOptions &HSOpts);
555 void WriteSourceManagerBlock(SourceManager &SourceMgr,
556 const Preprocessor &PP);
557 void WritePreprocessor(const Preprocessor &PP, bool IsModule);
558 void WriteHeaderSearch(const HeaderSearch &HS);
559 void WritePreprocessorDetail(PreprocessingRecord &PPRec,
560 uint64_t MacroOffsetsBase);
561 void WriteSubmodules(Module *WritingModule);
562
563 void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag,
564 bool isModule);
565
566 unsigned TypeExtQualAbbrev = 0;
567 void WriteTypeAbbrevs();
568 void WriteType(QualType T);
569
570 bool isLookupResultExternal(StoredDeclsList &Result, DeclContext *DC);
571
572 void GenerateNameLookupTable(const DeclContext *DC,
573 llvm::SmallVectorImpl<char> &LookupTable);
574 uint64_t WriteDeclContextLexicalBlock(ASTContext &Context,
575 const DeclContext *DC);
576 uint64_t WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC);
577 void WriteTypeDeclOffsets();
578 void WriteFileDeclIDsMap();
579 void WriteComments();
580 void WriteSelectors(Sema &SemaRef);
581 void WriteReferencedSelectorsPool(Sema &SemaRef);
582 void WriteIdentifierTable(Preprocessor &PP, IdentifierResolver &IdResolver,
583 bool IsModule);
584 void WriteDeclAndTypes(ASTContext &Context);
585 void PrepareWritingSpecialDecls(Sema &SemaRef);
586 void WriteSpecialDeclRecords(Sema &SemaRef);
587 void WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord);
588 void WriteDeclContextVisibleUpdate(const DeclContext *DC);
589 void WriteFPPragmaOptions(const FPOptionsOverride &Opts);
590 void WriteOpenCLExtensions(Sema &SemaRef);
591 void WriteCUDAPragmas(Sema &SemaRef);
592 void WriteObjCCategories();
593 void WriteLateParsedTemplates(Sema &SemaRef);
594 void WriteOptimizePragmaOptions(Sema &SemaRef);
595 void WriteMSStructPragmaOptions(Sema &SemaRef);
596 void WriteMSPointersToMembersPragmaOptions(Sema &SemaRef);
597 void WritePackPragmaOptions(Sema &SemaRef);
598 void WriteFloatControlPragmaOptions(Sema &SemaRef);
599 void WriteModuleFileExtension(Sema &SemaRef,
600 ModuleFileExtensionWriter &Writer);
601
602 unsigned DeclParmVarAbbrev = 0;
603 unsigned DeclContextLexicalAbbrev = 0;
604 unsigned DeclContextVisibleLookupAbbrev = 0;
605 unsigned UpdateVisibleAbbrev = 0;
606 unsigned DeclRecordAbbrev = 0;
607 unsigned DeclTypedefAbbrev = 0;
608 unsigned DeclVarAbbrev = 0;
609 unsigned DeclFieldAbbrev = 0;
610 unsigned DeclEnumAbbrev = 0;
611 unsigned DeclObjCIvarAbbrev = 0;
612 unsigned DeclCXXMethodAbbrev = 0;
613 unsigned DeclDependentNonTemplateCXXMethodAbbrev = 0;
614 unsigned DeclTemplateCXXMethodAbbrev = 0;
615 unsigned DeclMemberSpecializedCXXMethodAbbrev = 0;
616 unsigned DeclTemplateSpecializedCXXMethodAbbrev = 0;
617 unsigned DeclDependentSpecializationCXXMethodAbbrev = 0;
618 unsigned DeclTemplateTypeParmAbbrev = 0;
619 unsigned DeclUsingShadowAbbrev = 0;
620
621 unsigned DeclRefExprAbbrev = 0;
622 unsigned CharacterLiteralAbbrev = 0;
623 unsigned IntegerLiteralAbbrev = 0;
624 unsigned ExprImplicitCastAbbrev = 0;
625 unsigned BinaryOperatorAbbrev = 0;
626 unsigned CompoundAssignOperatorAbbrev = 0;
627 unsigned CallExprAbbrev = 0;
628 unsigned CXXOperatorCallExprAbbrev = 0;
629 unsigned CXXMemberCallExprAbbrev = 0;
630
631 unsigned CompoundStmtAbbrev = 0;
632
633 void WriteDeclAbbrevs();
634 void WriteDecl(ASTContext &Context, Decl *D);
635
636 ASTFileSignature WriteASTCore(Sema &SemaRef, StringRef isysroot,
637 Module *WritingModule);
638
639public:
640 /// Create a new precompiled header writer that outputs to
641 /// the given bitstream.
642 ASTWriter(llvm::BitstreamWriter &Stream, SmallVectorImpl<char> &Buffer,
643 InMemoryModuleCache &ModuleCache,
644 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
645 bool IncludeTimestamps = true, bool BuildingImplicitModule = false,
646 bool GeneratingReducedBMI = false);
647 ~ASTWriter() override;
648
650 assert(Context && "requested AST context when not writing AST");
651 return *Context;
652 }
653
654 const LangOptions &getLangOpts() const;
655
656 /// Get a timestamp for output into the AST file. The actual timestamp
657 /// of the specified file may be ignored if we have been instructed to not
658 /// include timestamps in the output file.
659 time_t getTimestampForOutput(const FileEntry *E) const;
660
661 /// Write a precompiled header for the given semantic analysis.
662 ///
663 /// \param SemaRef a reference to the semantic analysis object that processed
664 /// the AST to be written into the precompiled header.
665 ///
666 /// \param WritingModule The module that we are writing. If null, we are
667 /// writing a precompiled header.
668 ///
669 /// \param isysroot if non-empty, write a relocatable file whose headers
670 /// are relative to the given system root. If we're writing a module, its
671 /// build directory will be used in preference to this if both are available.
672 ///
673 /// \return the module signature, which eventually will be a hash of
674 /// the module but currently is merely a random 32-bit number.
675 ASTFileSignature WriteAST(Sema &SemaRef, StringRef OutputFile,
676 Module *WritingModule, StringRef isysroot,
677 bool ShouldCacheASTInMemory = false);
678
679 /// Emit a token.
680 void AddToken(const Token &Tok, RecordDataImpl &Record);
681
682 /// Emit a AlignPackInfo.
683 void AddAlignPackInfo(const Sema::AlignPackInfo &Info,
685
686 /// Emit a FileID.
688
689 /// Emit a source location.
691 LocSeq *Seq = nullptr);
692
693 /// Return the raw encodings for source locations.
696
697 /// Emit a source range.
699 LocSeq *Seq = nullptr);
700
701 /// Emit a reference to an identifier.
703
704 /// Get the unique number used to refer to the given selector.
706
707 /// Get the unique number used to refer to the given identifier.
709
710 /// Get the unique number used to refer to the given macro.
712
713 /// Determine the ID of an already-emitted macro.
715
716 uint32_t getMacroDirectivesOffset(const IdentifierInfo *Name);
717
718 /// Emit a reference to a type.
720
721 /// Force a type to be emitted and get its ID.
723
724 /// Find the first local declaration of a given local redeclarable
725 /// decl.
726 const Decl *getFirstLocalDecl(const Decl *D);
727
728 /// Is this a local declaration (that is, one that will be written to
729 /// our AST file)? This is the case for declarations that are neither imported
730 /// from another AST file nor predefined.
731 bool IsLocalDecl(const Decl *D) {
732 if (D->isFromASTFile())
733 return false;
734 auto I = DeclIDs.find(D);
735 return (I == DeclIDs.end() || I->second >= clang::NUM_PREDEF_DECL_IDS);
736 };
737
738 /// Emit a reference to a declaration.
739 void AddDeclRef(const Decl *D, RecordDataImpl &Record);
740 // Emit a reference to a declaration if the declaration was emitted.
742
743 /// Force a declaration to be emitted and get its local ID to the module file
744 /// been writing.
746
747 /// Determine the local declaration ID of an already-emitted
748 /// declaration.
749 LocalDeclID getDeclID(const Decl *D);
750
751 /// Whether or not the declaration got emitted. If not, it wouldn't be
752 /// emitted.
753 ///
754 /// This may only be called after we've done the job to write the
755 /// declarations (marked by DoneWritingDeclsAndTypes).
756 ///
757 /// A declaration may only be omitted in reduced BMI.
758 bool wasDeclEmitted(const Decl *D) const;
759
761
762 /// Add a string to the given record.
763 void AddString(StringRef Str, RecordDataImpl &Record);
764
765 /// Convert a path from this build process into one that is appropriate
766 /// for emission in the module file.
768
769 /// Add a path to the given record.
770 void AddPath(StringRef Path, RecordDataImpl &Record);
771
772 /// Emit the current record with the given path as a blob.
773 void EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record,
774 StringRef Path);
775
776 /// Add a version tuple to the given record
777 void AddVersionTuple(const VersionTuple &Version, RecordDataImpl &Record);
778
779 /// Retrieve or create a submodule ID for this module, or return 0 if
780 /// the submodule is neither local (a submodle of the currently-written module)
781 /// nor from an imported module.
782 unsigned getLocalOrImportedSubmoduleID(const Module *Mod);
783
784 /// Note that the identifier II occurs at the given offset
785 /// within the identifier table.
786 void SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset);
787
788 /// Note that the selector Sel occurs at the given offset
789 /// within the method pool/selector table.
790 void SetSelectorOffset(Selector Sel, uint32_t Offset);
791
792 /// Record an ID for the given switch-case statement.
793 unsigned RecordSwitchCaseID(SwitchCase *S);
794
795 /// Retrieve the ID for the given switch-case statement.
796 unsigned getSwitchCaseID(SwitchCase *S);
797
798 void ClearSwitchCaseIDs();
799
800 unsigned getTypeExtQualAbbrev() const {
801 return TypeExtQualAbbrev;
802 }
803
804 unsigned getDeclParmVarAbbrev() const { return DeclParmVarAbbrev; }
805 unsigned getDeclRecordAbbrev() const { return DeclRecordAbbrev; }
806 unsigned getDeclTypedefAbbrev() const { return DeclTypedefAbbrev; }
807 unsigned getDeclVarAbbrev() const { return DeclVarAbbrev; }
808 unsigned getDeclFieldAbbrev() const { return DeclFieldAbbrev; }
809 unsigned getDeclEnumAbbrev() const { return DeclEnumAbbrev; }
810 unsigned getDeclObjCIvarAbbrev() const { return DeclObjCIvarAbbrev; }
812 switch (Kind) {
814 return DeclCXXMethodAbbrev;
816 return DeclTemplateCXXMethodAbbrev;
818 return DeclMemberSpecializedCXXMethodAbbrev;
820 return DeclTemplateSpecializedCXXMethodAbbrev;
822 return DeclDependentNonTemplateCXXMethodAbbrev;
824 return DeclDependentSpecializationCXXMethodAbbrev;
825 }
826 llvm_unreachable("Unknwon Template Kind!");
827 }
829 return DeclTemplateTypeParmAbbrev;
830 }
831 unsigned getDeclUsingShadowAbbrev() const { return DeclUsingShadowAbbrev; }
832
833 unsigned getDeclRefExprAbbrev() const { return DeclRefExprAbbrev; }
834 unsigned getCharacterLiteralAbbrev() const { return CharacterLiteralAbbrev; }
835 unsigned getIntegerLiteralAbbrev() const { return IntegerLiteralAbbrev; }
836 unsigned getExprImplicitCastAbbrev() const { return ExprImplicitCastAbbrev; }
837 unsigned getBinaryOperatorAbbrev() const { return BinaryOperatorAbbrev; }
839 return CompoundAssignOperatorAbbrev;
840 }
841 unsigned getCallExprAbbrev() const { return CallExprAbbrev; }
842 unsigned getCXXOperatorCallExprAbbrev() { return CXXOperatorCallExprAbbrev; }
843 unsigned getCXXMemberCallExprAbbrev() { return CXXMemberCallExprAbbrev; }
844
845 unsigned getCompoundStmtAbbrev() const { return CompoundStmtAbbrev; }
846
847 bool hasChain() const { return Chain; }
848 ASTReader *getChain() const { return Chain; }
849
850 bool isWritingModule() const { return WritingModule; }
851
853 return WritingModule && WritingModule->isNamedModule();
854 }
855
856 bool isGeneratingReducedBMI() const { return GeneratingReducedBMI; }
857
858 bool getDoneWritingDeclsAndTypes() const { return DoneWritingDeclsAndTypes; }
859
860 bool isDeclPredefined(const Decl *D) const {
861 return PredefinedDecls.count(D);
862 }
863
864 void handleVTable(CXXRecordDecl *RD);
865
866private:
867 // ASTDeserializationListener implementation
868 void ReaderInitialized(ASTReader *Reader) override;
869 void IdentifierRead(serialization::IdentifierID ID, IdentifierInfo *II) override;
870 void MacroRead(serialization::MacroID ID, MacroInfo *MI) override;
871 void TypeRead(serialization::TypeIdx Idx, QualType T) override;
872 void PredefinedDeclBuilt(PredefinedDeclIDs ID, const Decl *D) override;
873 void SelectorRead(serialization::SelectorID ID, Selector Sel) override;
874 void MacroDefinitionRead(serialization::PreprocessedEntityID ID,
875 MacroDefinitionRecord *MD) override;
876 void ModuleRead(serialization::SubmoduleID ID, Module *Mod) override;
877
878 // ASTMutationListener implementation.
879 void CompletedTagDefinition(const TagDecl *D) override;
880 void AddedVisibleDecl(const DeclContext *DC, const Decl *D) override;
881 void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) override;
882 void AddedCXXTemplateSpecialization(
883 const ClassTemplateDecl *TD,
884 const ClassTemplateSpecializationDecl *D) override;
885 void AddedCXXTemplateSpecialization(
886 const VarTemplateDecl *TD,
887 const VarTemplateSpecializationDecl *D) override;
888 void AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD,
889 const FunctionDecl *D) override;
890 void ResolvedExceptionSpec(const FunctionDecl *FD) override;
891 void DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) override;
892 void ResolvedOperatorDelete(const CXXDestructorDecl *DD,
893 const FunctionDecl *Delete,
894 Expr *ThisArg) override;
895 void CompletedImplicitDefinition(const FunctionDecl *D) override;
896 void InstantiationRequested(const ValueDecl *D) override;
897 void VariableDefinitionInstantiated(const VarDecl *D) override;
898 void FunctionDefinitionInstantiated(const FunctionDecl *D) override;
899 void DefaultArgumentInstantiated(const ParmVarDecl *D) override;
900 void DefaultMemberInitializerInstantiated(const FieldDecl *D) override;
901 void AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD,
902 const ObjCInterfaceDecl *IFD) override;
903 void DeclarationMarkedUsed(const Decl *D) override;
904 void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) override;
905 void DeclarationMarkedOpenMPDeclareTarget(const Decl *D,
906 const Attr *Attr) override;
907 void DeclarationMarkedOpenMPAllocate(const Decl *D, const Attr *A) override;
908 void RedefinedHiddenDefinition(const NamedDecl *D, Module *M) override;
909 void AddedAttributeToRecord(const Attr *Attr,
910 const RecordDecl *Record) override;
911 void EnteringModulePurview() override;
912 void AddedManglingNumber(const Decl *D, unsigned) override;
913 void AddedStaticLocalNumbers(const Decl *D, unsigned) override;
914 void AddedAnonymousNamespace(const TranslationUnitDecl *,
915 NamespaceDecl *AnonNamespace) override;
916};
917
918/// AST and semantic-analysis consumer that generates a
919/// precompiled header from the parsed source code.
921 void anchor() override;
922
923 Preprocessor &PP;
924 std::string OutputFile;
925 std::string isysroot;
926 Sema *SemaPtr;
927 std::shared_ptr<PCHBuffer> Buffer;
928 llvm::BitstreamWriter Stream;
929 ASTWriter Writer;
930 bool AllowASTWithErrors;
931 bool ShouldCacheASTInMemory;
932
933protected:
934 ASTWriter &getWriter() { return Writer; }
935 const ASTWriter &getWriter() const { return Writer; }
936 SmallVectorImpl<char> &getPCH() const { return Buffer->Data; }
937
938 bool isComplete() const { return Buffer->IsComplete; }
939 PCHBuffer *getBufferPtr() { return Buffer.get(); }
940 StringRef getOutputFile() const { return OutputFile; }
942 return SemaPtr->getDiagnostics();
943 }
945
946 virtual Module *getEmittingModule(ASTContext &Ctx);
947
948public:
950 StringRef OutputFile, StringRef isysroot,
951 std::shared_ptr<PCHBuffer> Buffer,
952 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
953 bool AllowASTWithErrors = false, bool IncludeTimestamps = true,
954 bool BuildingImplicitModule = false,
955 bool ShouldCacheASTInMemory = false,
956 bool GeneratingReducedBMI = false);
957 ~PCHGenerator() override;
958
959 void InitializeSema(Sema &S) override { SemaPtr = &S; }
960 void HandleTranslationUnit(ASTContext &Ctx) override;
961 void HandleVTable(CXXRecordDecl *RD) override { Writer.handleVTable(RD); }
964 bool hasEmittedPCH() const { return Buffer->IsComplete; }
965};
966
968 void anchor() override;
969
970protected:
971 virtual Module *getEmittingModule(ASTContext &Ctx) override;
972
974 StringRef OutputFile, bool GeneratingReducedBMI);
975
976public:
978 StringRef OutputFile)
979 : CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
980 /*GeneratingReducedBMI=*/false) {}
981
982 void HandleTranslationUnit(ASTContext &Ctx) override;
983};
984
986 void anchor() override;
987
988public:
990 StringRef OutputFile)
991 : CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
992 /*GeneratingReducedBMI=*/true) {}
993};
994
995/// If we can elide the definition of \param D in reduced BMI.
996///
997/// Generally, we can elide the definition of a declaration if it won't affect
998/// the ABI. e.g., the non-inline function bodies.
999bool CanElideDeclDef(const Decl *D);
1000
1001/// A simple helper class to pack several bits in order into (a) 32 bit
1002/// integer(s).
1004 constexpr static uint32_t BitIndexUpbound = 32u;
1005
1006public:
1007 BitsPacker() = default;
1008 BitsPacker(const BitsPacker &) = delete;
1012 ~BitsPacker() = default;
1013
1014 bool canWriteNextNBits(uint32_t BitsWidth) const {
1015 return CurrentBitIndex + BitsWidth < BitIndexUpbound;
1016 }
1017
1018 void reset(uint32_t Value) {
1019 UnderlyingValue = Value;
1020 CurrentBitIndex = 0;
1021 }
1022
1023 void addBit(bool Value) { addBits(Value, 1); }
1024 void addBits(uint32_t Value, uint32_t BitsWidth) {
1025 assert(BitsWidth < BitIndexUpbound);
1026 assert((Value < (1u << BitsWidth)) && "Passing narrower bit width!");
1027 assert(canWriteNextNBits(BitsWidth) &&
1028 "Inserting too much bits into a value!");
1029
1030 UnderlyingValue |= Value << CurrentBitIndex;
1031 CurrentBitIndex += BitsWidth;
1032 }
1033
1034 operator uint32_t() { return UnderlyingValue; }
1035
1036private:
1037 uint32_t UnderlyingValue = 0;
1038 uint32_t CurrentBitIndex = 0;
1039};
1040
1041} // namespace clang
1042
1043#endif // LLVM_CLANG_SERIALIZATION_ASTWRITER_H
MatchType Type
static char ID
Definition: Arena.cpp:183
const Decl * D
IndirectLocalPath & Path
enum clang::sema::@1653::IndirectLocalPathEntry::EntryKind Kind
Expr * E
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
llvm::MachO::Record Record
Definition: MachO.h:31
SourceRange Range
Definition: SemaObjC.cpp:758
SourceLocation Loc
Definition: SemaObjC.cpp:759
Defines the clang::SourceLocation class and associated facilities.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:378
An object for streaming information to a record.
Writes an AST file containing the contents of a translation unit.
Definition: ASTWriter.h:89
serialization::MacroID getMacroID(MacroInfo *MI)
Determine the ID of an already-emitted macro.
Definition: ASTWriter.cpp:6061
ASTFileSignature WriteAST(Sema &SemaRef, StringRef OutputFile, Module *WritingModule, StringRef isysroot, bool ShouldCacheASTInMemory=false)
Write a precompiled header for the given semantic analysis.
Definition: ASTWriter.cpp:4860
unsigned getDeclParmVarAbbrev() const
Definition: ASTWriter.h:804
void AddEmittedDeclRef(const Decl *D, RecordDataImpl &Record)
Definition: ASTWriter.cpp:6211
void AddSourceRange(SourceRange Range, RecordDataImpl &Record, LocSeq *Seq=nullptr)
Emit a source range.
Definition: ASTWriter.cpp:6021
unsigned getBinaryOperatorAbbrev() const
Definition: ASTWriter.h:837
unsigned getDeclTemplateTypeParmAbbrev() const
Definition: ASTWriter.h:828
bool isWritingStdCXXNamedModules() const
Definition: ASTWriter.h:852
ArrayRef< uint64_t > RecordDataRef
Definition: ASTWriter.h:96
void EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record, StringRef Path)
Emit the current record with the given path as a blob.
Definition: ASTWriter.cpp:4784
void AddFileID(FileID FID, RecordDataImpl &Record)
Emit a FileID.
Definition: ASTWriter.cpp:5987
unsigned getDeclObjCIvarAbbrev() const
Definition: ASTWriter.h:810
unsigned getExprImplicitCastAbbrev() const
Definition: ASTWriter.h:836
bool isDeclPredefined(const Decl *D) const
Definition: ASTWriter.h:860
unsigned getDeclTypedefAbbrev() const
Definition: ASTWriter.h:806
bool hasChain() const
Definition: ASTWriter.h:847
unsigned getSwitchCaseID(SwitchCase *S)
Retrieve the ID for the given switch-case statement.
void AddPath(StringRef Path, RecordDataImpl &Record)
Add a path to the given record.
Definition: ASTWriter.cpp:4778
SmallVectorImpl< uint64_t > RecordDataImpl
Definition: ASTWriter.h:95
unsigned getDeclUsingShadowAbbrev() const
Definition: ASTWriter.h:831
unsigned getTypeExtQualAbbrev() const
Definition: ASTWriter.h:800
void AddVersionTuple(const VersionTuple &Version, RecordDataImpl &Record)
Add a version tuple to the given record.
Definition: ASTWriter.cpp:4791
bool isGeneratingReducedBMI() const
Definition: ASTWriter.h:856
uint32_t getMacroDirectivesOffset(const IdentifierInfo *Name)
Definition: ASTWriter.cpp:6069
unsigned getDeclVarAbbrev() const
Definition: ASTWriter.h:807
unsigned getDeclEnumAbbrev() const
Definition: ASTWriter.h:809
void AddAlignPackInfo(const Sema::AlignPackInfo &Info, RecordDataImpl &Record)
Emit a AlignPackInfo.
Definition: ASTWriter.cpp:5919
bool IsLocalDecl(const Decl *D)
Is this a local declaration (that is, one that will be written to our AST file)? This is the case for...
Definition: ASTWriter.h:731
unsigned getDeclRefExprAbbrev() const
Definition: ASTWriter.h:833
unsigned getCXXOperatorCallExprAbbrev()
Definition: ASTWriter.h:842
bool wasDeclEmitted(const Decl *D) const
Whether or not the declaration got emitted.
Definition: ASTWriter.cpp:6276
void AddString(StringRef Str, RecordDataImpl &Record)
Add a string to the given record.
Definition: ASTWriter.cpp:4750
time_t getTimestampForOutput(const FileEntry *E) const
Get a timestamp for output into the AST file.
Definition: ASTWriter.cpp:4856
~ASTWriter() override
bool isWritingModule() const
Definition: ASTWriter.h:850
LocalDeclID GetDeclRef(const Decl *D)
Force a declaration to be emitted and get its local ID to the module file been writing.
Definition: ASTWriter.cpp:6222
LocalDeclID getDeclID(const Decl *D)
Determine the local declaration ID of an already-emitted declaration.
Definition: ASTWriter.cpp:6263
void AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record)
Emit a reference to an identifier.
Definition: ASTWriter.cpp:6031
serialization::TypeID GetOrCreateTypeID(QualType T)
Force a type to be emitted and get its ID.
Definition: ASTWriter.cpp:6188
serialization::MacroID getMacroRef(MacroInfo *MI, const IdentifierInfo *Name)
Get the unique number used to refer to the given macro.
Definition: ASTWriter.cpp:6045
void AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record, LocSeq *Seq=nullptr)
Emit a source location.
Definition: ASTWriter.cpp:6015
void AddTypeRef(QualType T, RecordDataImpl &Record)
Emit a reference to a type.
Definition: ASTWriter.cpp:6159
ASTContext & getASTContext() const
Definition: ASTWriter.h:649
unsigned getCXXMemberCallExprAbbrev()
Definition: ASTWriter.h:843
ASTReader * getChain() const
Definition: ASTWriter.h:848
unsigned getCompoundAssignOperatorAbbrev() const
Definition: ASTWriter.h:838
bool getDoneWritingDeclsAndTypes() const
Definition: ASTWriter.h:858
serialization::IdentifierID getIdentifierRef(const IdentifierInfo *II)
Get the unique number used to refer to the given identifier.
Definition: ASTWriter.cpp:6035
unsigned RecordSwitchCaseID(SwitchCase *S)
Record an ID for the given switch-case statement.
unsigned getCharacterLiteralAbbrev() const
Definition: ASTWriter.h:834
unsigned getDeclCXXMethodAbbrev(FunctionDecl::TemplatedKind Kind) const
Definition: ASTWriter.h:811
void handleVTable(CXXRecordDecl *RD)
Definition: ASTWriter.cpp:3965
unsigned getCompoundStmtAbbrev() const
Definition: ASTWriter.h:845
unsigned getLocalOrImportedSubmoduleID(const Module *Mod)
Retrieve or create a submodule ID for this module, or return 0 if the submodule is neither local (a s...
Definition: ASTWriter.cpp:2860
const Decl * getFirstLocalDecl(const Decl *D)
Find the first local declaration of a given local redeclarable decl.
void AddToken(const Token &Tok, RecordDataImpl &Record)
Emit a token.
Definition: ASTWriter.cpp:4704
serialization::SelectorID getSelectorRef(Selector Sel)
Get the unique number used to refer to the given selector.
Definition: ASTWriter.cpp:6077
SourceLocationEncoding::RawLocEncoding getRawSourceLocationEncoding(SourceLocation Loc, LocSeq *Seq=nullptr)
Return the raw encodings for source locations.
Definition: ASTWriter.cpp:5992
ASTWriter(llvm::BitstreamWriter &Stream, SmallVectorImpl< char > &Buffer, InMemoryModuleCache &ModuleCache, ArrayRef< std::shared_ptr< ModuleFileExtension > > Extensions, bool IncludeTimestamps=true, bool BuildingImplicitModule=false, bool GeneratingReducedBMI=false)
Create a new precompiled header writer that outputs to the given bitstream.
Definition: ASTWriter.cpp:4833
SmallVector< uint64_t, 64 > RecordData
Definition: ASTWriter.h:94
unsigned getAnonymousDeclarationNumber(const NamedDecl *D)
Definition: ASTWriter.cpp:6330
unsigned getDeclFieldAbbrev() const
Definition: ASTWriter.h:808
const LangOptions & getLangOpts() const
Definition: ASTWriter.cpp:4851
void SetSelectorOffset(Selector Sel, uint32_t Offset)
Note that the selector Sel occurs at the given offset within the method pool/selector table.
Definition: ASTWriter.cpp:4823
bool PreparePathForOutput(SmallVectorImpl< char > &Path)
Convert a path from this build process into one that is appropriate for emission in the module file.
Definition: ASTWriter.cpp:4755
unsigned getCallExprAbbrev() const
Definition: ASTWriter.h:841
void SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset)
Note that the identifier II occurs at the given offset within the identifier table.
Definition: ASTWriter.cpp:4806
unsigned getDeclRecordAbbrev() const
Definition: ASTWriter.h:805
void AddDeclRef(const Decl *D, RecordDataImpl &Record)
Emit a reference to a declaration.
Definition: ASTWriter.cpp:6218
unsigned getIntegerLiteralAbbrev() const
Definition: ASTWriter.h:835
Attr - This represents one attribute.
Definition: Attr.h:42
A simple helper class to pack several bits in order into (a) 32 bit integer(s).
Definition: ASTWriter.h:1003
~BitsPacker()=default
void addBit(bool Value)
Definition: ASTWriter.h:1023
bool canWriteNextNBits(uint32_t BitsWidth) const
Definition: ASTWriter.h:1014
BitsPacker operator=(BitsPacker &&)=delete
BitsPacker(BitsPacker &&)=delete
BitsPacker()=default
void addBits(uint32_t Value, uint32_t BitsWidth)
Definition: ASTWriter.h:1024
void reset(uint32_t Value)
Definition: ASTWriter.h:1018
BitsPacker(const BitsPacker &)=delete
BitsPacker operator=(const BitsPacker &)=delete
void HandleTranslationUnit(ASTContext &Ctx) override
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
virtual Module * getEmittingModule(ASTContext &Ctx) override
CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache, StringRef OutputFile)
Definition: ASTWriter.h:977
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2803
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Declaration of a class template.
Represents a class template specialization, which refers to a class template with a given set of temp...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1436
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:192
This represents one expression.
Definition: Expr.h:110
Represents a member of a struct/union/class.
Definition: Decl.h:3030
Cached information about one file (either on disk or in the virtual file system).
Definition: FileEntry.h:300
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Represents a function declaration or definition.
Definition: Decl.h:1932
TemplatedKind
The kind of templated function a FunctionDecl can be.
Definition: Decl.h:1937
@ TK_MemberSpecialization
Definition: Decl.h:1944
@ TK_DependentNonTemplate
Definition: Decl.h:1953
@ TK_FunctionTemplateSpecialization
Definition: Decl.h:1948
@ TK_DependentFunctionTemplateSpecialization
Definition: Decl.h:1951
Declaration of a template function.
Definition: DeclTemplate.h:957
One of these records is kept for each identifier that is lexed.
In-memory cache for modules.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:461
Record the location of a macro definition.
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
Describes a module or submodule.
Definition: Module.h:105
bool isNamedModule() const
Does this Module is a named module of a standard named module?
Definition: Module.h:185
This represents a decl that may have a name.
Definition: Decl.h:249
Represent a C++ namespace.
Definition: Decl.h:547
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2328
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
AST and semantic-analysis consumer that generates a precompiled header from the parsed source code.
Definition: ASTWriter.h:920
ASTMutationListener * GetASTMutationListener() override
If the consumer is interested in entities getting modified after their initial creation,...
Definition: GeneratePCH.cpp:83
PCHBuffer * getBufferPtr()
Definition: ASTWriter.h:939
Preprocessor & getPreprocessor()
Definition: ASTWriter.h:944
virtual Module * getEmittingModule(ASTContext &Ctx)
Definition: GeneratePCH.cpp:44
SmallVectorImpl< char > & getPCH() const
Definition: ASTWriter.h:936
void InitializeSema(Sema &S) override
Initialize the semantic consumer with the Sema instance being used to perform semantic analysis on th...
Definition: ASTWriter.h:959
StringRef getOutputFile() const
Definition: ASTWriter.h:940
~PCHGenerator() override
Definition: GeneratePCH.cpp:41
void HandleVTable(CXXRecordDecl *RD) override
Callback involved at the end of a translation unit to notify the consumer that a vtable for the given...
Definition: ASTWriter.h:961
ASTDeserializationListener * GetASTDeserializationListener() override
If the consumer is interested in entities being deserialized from AST files, it should return a point...
Definition: GeneratePCH.cpp:87
const ASTWriter & getWriter() const
Definition: ASTWriter.h:935
void HandleTranslationUnit(ASTContext &Ctx) override
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
Definition: GeneratePCH.cpp:59
bool hasEmittedPCH() const
Definition: ASTWriter.h:964
ASTWriter & getWriter()
Definition: ASTWriter.h:934
bool isComplete() const
Definition: ASTWriter.h:938
DiagnosticsEngine & getDiagnostics() const
Definition: ASTWriter.h:941
Represents a parameter to a function.
Definition: Decl.h:1722
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:137
A (possibly-)qualified type.
Definition: Type.h:941
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:990
Represents a struct/union/class.
Definition: Decl.h:4145
ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache, StringRef OutputFile)
Definition: ASTWriter.h:989
Smart pointer class that efficiently represents Objective-C method names.
An abstract interface that should be implemented by clients that read ASTs and then require further s...
Definition: SemaConsumer.h:25
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:493
DiagnosticsEngine & getDiagnostics() const
Definition: Sema.h:557
Serialized encoding of a sequence of SourceLocations.
Encodes a location in the source.
static SourceLocation getFromRawEncoding(UIntTy Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
A trivial tuple used to represent a source range.
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3561
Token - This structure provides full information about a lexed token.
Definition: Token.h:36
The top declaration context.
Definition: Decl.h:84
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:667
Represents a variable declaration or definition.
Definition: Decl.h:879
Declaration of a variable template.
Represents a variable template specialization, which refers to a variable template with a given set o...
A type index; the type ID with the qualifier bits removed.
Definition: ASTBitCodes.h:99
const unsigned NUM_PREDEF_TYPE_IDS
The number of predefined type IDs that are reserved for the PREDEF_TYPE_* constants.
Definition: ASTBitCodes.h:1142
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
uint64_t TypeID
An ID number that refers to a type in an AST file.
Definition: ASTBitCodes.h:88
const unsigned int NUM_PREDEF_IDENT_IDS
The number of predefined identifier IDs.
Definition: ASTBitCodes.h:66
uint32_t SubmoduleID
An ID number that refers to a submodule in a module file.
Definition: ASTBitCodes.h:185
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
Definition: ASTBitCodes.h:167
uint32_t PreprocessedEntityID
An ID number that refers to an entity in the detailed preprocessing record.
Definition: ASTBitCodes.h:182
const unsigned int NUM_PREDEF_SUBMODULE_IDS
The number of predefined submodule IDs.
Definition: ASTBitCodes.h:188
const unsigned int NUM_PREDEF_SELECTOR_IDS
The number of predefined selector IDs.
Definition: ASTBitCodes.h:170
uint64_t IdentifierID
An ID number that refers to an identifier in an AST file.
Definition: ASTBitCodes.h:63
const unsigned int NUM_PREDEF_MACRO_IDS
The number of predefined macro IDs.
Definition: ASTBitCodes.h:164
uint32_t MacroID
An ID number that refers to a macro in an AST file.
Definition: ASTBitCodes.h:154
@ HeaderSearch
Remove unused header search paths including header maps.
The JSON file list parser is used to communicate input to InstallAPI.
@ Seq
'seq' clause, allowed on 'loop' and 'routine' directives.
@ Delete
'delete' clause, allowed on the 'exit data' construct.
const unsigned int NUM_PREDEF_DECL_IDS
The number of declaration IDs that are predefined.
Definition: DeclID.h:93
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
PredefinedDeclIDs
Predefined declaration IDs.
Definition: DeclID.h:33
@ Result
The result type of a method or function.
bool CanElideDeclDef(const Decl *D)
If we can elide the definition of.
const FunctionProtoType * T
unsigned long uint64_t
#define true
Definition: stdbool.h:25
#define false
Definition: stdbool.h:26
The signature of a module, which is a hash of the AST content.
Definition: Module.h:57
A structure for putting "fast"-unqualified QualTypes into a DenseMap.
Definition: ASTBitCodes.h:134