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 preprocessor we're writing.
123 Preprocessor *PP = nullptr;
124
125 /// The reader of existing AST files, if we're chaining.
126 ASTReader *Chain = nullptr;
127
128 /// The module we're currently writing, if any.
129 Module *WritingModule = nullptr;
130
131 /// The byte range representing all the UNHASHED_CONTROL_BLOCK.
132 std::pair<uint64_t, uint64_t> UnhashedControlBlockRange;
133 /// The bit offset of the AST block hash blob.
134 uint64_t ASTBlockHashOffset = 0;
135 /// The bit offset of the signature blob.
136 uint64_t SignatureOffset = 0;
137
138 /// The bit offset of the first bit inside the AST_BLOCK.
139 uint64_t ASTBlockStartOffset = 0;
140
141 /// The byte range representing all the AST_BLOCK.
142 std::pair<uint64_t, uint64_t> ASTBlockRange;
143
144 /// The base directory for any relative paths we emit.
145 std::string BaseDirectory;
146
147 /// Indicates whether timestamps should be written to the produced
148 /// module file. This is the case for files implicitly written to the
149 /// module cache, where we need the timestamps to determine if the module
150 /// file is up to date, but not otherwise.
151 bool IncludeTimestamps;
152
153 /// Indicates whether the AST file being written is an implicit module.
154 /// If that's the case, we may be able to skip writing some information that
155 /// are guaranteed to be the same in the importer by the context hash.
156 bool BuildingImplicitModule = false;
157
158 /// Indicates when the AST writing is actively performing
159 /// serialization, rather than just queueing updates.
160 bool WritingAST = false;
161
162 /// Indicates that we are done serializing the collection of decls
163 /// and types to emit.
164 bool DoneWritingDeclsAndTypes = false;
165
166 /// Indicates that the AST contained compiler errors.
167 bool ASTHasCompilerErrors = false;
168
169 /// Indicates that we're going to generate the reduced BMI for C++20
170 /// named modules.
171 bool GeneratingReducedBMI = false;
172
173 /// Mapping from input file entries to the index into the
174 /// offset table where information about that input file is stored.
175 llvm::DenseMap<const FileEntry *, uint32_t> InputFileIDs;
176
177 /// Stores a declaration or a type to be written to the AST file.
178 class DeclOrType {
179 public:
180 DeclOrType(Decl *D) : Stored(D), IsType(false) {}
181 DeclOrType(QualType T) : Stored(T.getAsOpaquePtr()), IsType(true) {}
182
183 bool isType() const { return IsType; }
184 bool isDecl() const { return !IsType; }
185
186 QualType getType() const {
187 assert(isType() && "Not a type!");
188 return QualType::getFromOpaquePtr(Stored);
189 }
190
191 Decl *getDecl() const {
192 assert(isDecl() && "Not a decl!");
193 return static_cast<Decl *>(Stored);
194 }
195
196 private:
197 void *Stored;
198 bool IsType;
199 };
200
201 /// The declarations and types to emit.
202 std::queue<DeclOrType> DeclTypesToEmit;
203
204 /// The delayed namespace to emit. Only meaningful for reduced BMI.
205 ///
206 /// In reduced BMI, we want to elide the unreachable declarations in
207 /// the global module fragment. However, in ASTWriterDecl, when we see
208 /// a namespace, all the declarations in the namespace would be emitted.
209 /// So the optimization become meaningless. To solve the issue, we
210 /// delay recording all the declarations until we emit all the declarations.
211 /// Then we can safely record the reached declarations only.
213
214 /// The first ID number we can use for our own declarations.
216
217 /// The decl ID that will be assigned to the next new decl.
218 LocalDeclID NextDeclID = FirstDeclID;
219
220 /// Map that provides the ID numbers of each declaration within
221 /// the output stream, as well as those deserialized from a chained PCH.
222 ///
223 /// The ID numbers of declarations are consecutive (in order of
224 /// discovery) and start at 2. 1 is reserved for the translation
225 /// unit, while 0 is reserved for NULL.
226 llvm::DenseMap<const Decl *, LocalDeclID> DeclIDs;
227
228 /// Set of predefined decls. This is a helper data to determine if a decl
229 /// is predefined. It should be more clear and safer to query the set
230 /// instead of comparing the result of `getDeclID()` or `GetDeclRef()`.
232
233 /// Mapping from the main decl to related decls inside the main decls.
234 ///
235 /// These related decls have to be loaded right after the main decl they
236 /// belong to. In order to have canonical declaration for related decls from
237 /// the same module as the main decl during deserialization.
238 llvm::DenseMap<LocalDeclID, SmallVector<LocalDeclID, 4>> RelatedDeclsMap;
239
240 /// Offset of each declaration in the bitstream, indexed by
241 /// the declaration's ID.
242 std::vector<serialization::DeclOffset> DeclOffsets;
243
244 /// The offset of the DECLTYPES_BLOCK. The offsets in DeclOffsets
245 /// are relative to this value.
246 uint64_t DeclTypesBlockStartOffset = 0;
247
248 /// Sorted (by file offset) vector of pairs of file offset/LocalDeclID.
249 using LocDeclIDsTy = SmallVector<std::pair<unsigned, LocalDeclID>, 64>;
250 struct DeclIDInFileInfo {
251 LocDeclIDsTy DeclIDs;
252
253 /// Set when the DeclIDs vectors from all files are joined, this
254 /// indicates the index that this particular vector has in the global one.
255 unsigned FirstDeclIndex;
256 };
257 using FileDeclIDsTy =
258 llvm::DenseMap<FileID, std::unique_ptr<DeclIDInFileInfo>>;
259
260 /// Map from file SLocEntries to info about the file-level declarations
261 /// that it contains.
262 FileDeclIDsTy FileDeclIDs;
263
264 void associateDeclWithFile(const Decl *D, LocalDeclID);
265
266 /// The first ID number we can use for our own types.
268
269 /// The type ID that will be assigned to the next new type.
270 serialization::TypeID NextTypeID = FirstTypeID;
271
272 /// Map that provides the ID numbers of each type within the
273 /// output stream, plus those deserialized from a chained PCH.
274 ///
275 /// The ID numbers of types are consecutive (in order of discovery)
276 /// and start at 1. 0 is reserved for NULL. When types are actually
277 /// stored in the stream, the ID number is shifted by 2 bits to
278 /// allow for the const/volatile qualifiers.
279 ///
280 /// Keys in the map never have const/volatile qualifiers.
281 TypeIdxMap TypeIdxs;
282
283 /// Offset of each type in the bitstream, indexed by
284 /// the type's ID.
285 std::vector<serialization::UnalignedUInt64> TypeOffsets;
286
287 /// The first ID number we can use for our own identifiers.
289
290 /// The identifier ID that will be assigned to the next new identifier.
291 serialization::IdentifierID NextIdentID = FirstIdentID;
292
293 /// Map that provides the ID numbers of each identifier in
294 /// the output stream.
295 ///
296 /// The ID numbers for identifiers are consecutive (in order of
297 /// discovery), starting at 1. An ID of zero refers to a NULL
298 /// IdentifierInfo.
299 llvm::MapVector<const IdentifierInfo *, serialization::IdentifierID> IdentifierIDs;
300
301 /// The first ID number we can use for our own macros.
303
304 /// The identifier ID that will be assigned to the next new identifier.
305 serialization::MacroID NextMacroID = FirstMacroID;
306
307 /// Map that provides the ID numbers of each macro.
308 llvm::DenseMap<MacroInfo *, serialization::MacroID> MacroIDs;
309
310 struct MacroInfoToEmitData {
311 const IdentifierInfo *Name;
312 MacroInfo *MI;
314 };
315
316 /// The macro infos to emit.
317 std::vector<MacroInfoToEmitData> MacroInfosToEmit;
318
319 llvm::DenseMap<const IdentifierInfo *, uint32_t>
320 IdentMacroDirectivesOffsetMap;
321
322 /// @name FlushStmt Caches
323 /// @{
324
325 /// Set of parent Stmts for the currently serializing sub-stmt.
326 llvm::DenseSet<Stmt *> ParentStmts;
327
328 /// Offsets of sub-stmts already serialized. The offset points
329 /// just after the stmt record.
330 llvm::DenseMap<Stmt *, uint64_t> SubStmtEntries;
331
332 /// @}
333
334 /// Offsets of each of the identifier IDs into the identifier
335 /// table.
336 std::vector<uint32_t> IdentifierOffsets;
337
338 /// The first ID number we can use for our own submodules.
339 serialization::SubmoduleID FirstSubmoduleID =
341
342 /// The submodule ID that will be assigned to the next new submodule.
343 serialization::SubmoduleID NextSubmoduleID = FirstSubmoduleID;
344
345 /// The first ID number we can use for our own selectors.
346 serialization::SelectorID FirstSelectorID =
348
349 /// The selector ID that will be assigned to the next new selector.
350 serialization::SelectorID NextSelectorID = FirstSelectorID;
351
352 /// Map that provides the ID numbers of each Selector.
353 llvm::MapVector<Selector, serialization::SelectorID> SelectorIDs;
354
355 /// Offset of each selector within the method pool/selector
356 /// table, indexed by the Selector ID (-1).
357 std::vector<uint32_t> SelectorOffsets;
358
359 /// Mapping from macro definitions (as they occur in the preprocessing
360 /// record) to the macro IDs.
361 llvm::DenseMap<const MacroDefinitionRecord *,
362 serialization::PreprocessedEntityID> MacroDefinitions;
363
364 /// Cache of indices of anonymous declarations within their lexical
365 /// contexts.
366 llvm::DenseMap<const Decl *, unsigned> AnonymousDeclarationNumbers;
367
368 /// The external top level module during the writing process. Used to
369 /// generate signature for the module file being written.
370 ///
371 /// Only meaningful for standard C++ named modules. See the comments in
372 /// createSignatureForNamedModule() for details.
373 llvm::DenseSet<Module *> TouchedTopLevelModules;
374
375 /// An update to a Decl.
376 class DeclUpdate {
377 /// A DeclUpdateKind.
378 unsigned Kind;
379 union {
380 const Decl *Dcl;
381 void *Type;
383 unsigned Val;
384 Module *Mod;
385 const Attr *Attribute;
386 };
387
388 public:
389 DeclUpdate(unsigned Kind) : Kind(Kind), Dcl(nullptr) {}
390 DeclUpdate(unsigned Kind, const Decl *Dcl) : Kind(Kind), Dcl(Dcl) {}
391 DeclUpdate(unsigned Kind, QualType Type)
392 : Kind(Kind), Type(Type.getAsOpaquePtr()) {}
393 DeclUpdate(unsigned Kind, SourceLocation Loc)
394 : Kind(Kind), Loc(Loc.getRawEncoding()) {}
395 DeclUpdate(unsigned Kind, unsigned Val) : Kind(Kind), Val(Val) {}
396 DeclUpdate(unsigned Kind, Module *M) : Kind(Kind), Mod(M) {}
397 DeclUpdate(unsigned Kind, const Attr *Attribute)
398 : Kind(Kind), Attribute(Attribute) {}
399
400 unsigned getKind() const { return Kind; }
401 const Decl *getDecl() const { return Dcl; }
402 QualType getType() const { return QualType::getFromOpaquePtr(Type); }
403
404 SourceLocation getLoc() const {
406 }
407
408 unsigned getNumber() const { return Val; }
409 Module *getModule() const { return Mod; }
410 const Attr *getAttr() const { return Attribute; }
411 };
412
413 using UpdateRecord = SmallVector<DeclUpdate, 1>;
414 using DeclUpdateMap = llvm::MapVector<const Decl *, UpdateRecord>;
415
416 /// Mapping from declarations that came from a chained PCH to the
417 /// record containing modifications to them.
418 DeclUpdateMap DeclUpdates;
419
420 /// DeclUpdates added during parsing the GMF. We split these from
421 /// DeclUpdates since we want to add these updates in GMF on need.
422 /// Only meaningful for reduced BMI.
423 DeclUpdateMap DeclUpdatesFromGMF;
424
425 /// Mapping from decl templates and its new specialization in the
426 /// current TU.
427 using SpecializationUpdateMap =
428 llvm::MapVector<const NamedDecl *, SmallVector<const Decl *>>;
429 SpecializationUpdateMap SpecializationsUpdates;
430 SpecializationUpdateMap PartialSpecializationsUpdates;
431
432 using FirstLatestDeclMap = llvm::DenseMap<Decl *, Decl *>;
433
434 /// Map of first declarations from a chained PCH that point to the
435 /// most recent declarations in another PCH.
436 FirstLatestDeclMap FirstLatestDecls;
437
438 /// Declarations encountered that might be external
439 /// definitions.
440 ///
441 /// We keep track of external definitions and other 'interesting' declarations
442 /// as we are emitting declarations to the AST file. The AST file contains a
443 /// separate record for these declarations, which are provided to the AST
444 /// consumer by the AST reader. This is behavior is required to properly cope with,
445 /// e.g., tentative variable definitions that occur within
446 /// headers. The declarations themselves are stored as declaration
447 /// IDs, since they will be written out to an EAGERLY_DESERIALIZED_DECLS
448 /// record.
449 RecordData EagerlyDeserializedDecls;
450 RecordData ModularCodegenDecls;
451
452 /// DeclContexts that have received extensions since their serialized
453 /// form.
454 ///
455 /// For namespaces, when we're chaining and encountering a namespace, we check
456 /// if its primary namespace comes from the chain. If it does, we add the
457 /// primary to this set, so that we can write out lexical content updates for
458 /// it.
460
461 /// Keeps track of declarations that we must emit, even though we're
462 /// not guaranteed to be able to find them by walking the AST starting at the
463 /// translation unit.
464 SmallVector<const Decl *, 16> DeclsToEmitEvenIfUnreferenced;
465
466 /// The set of Objective-C class that have categories we
467 /// should serialize.
468 llvm::SetVector<ObjCInterfaceDecl *> ObjCClassesWithCategories;
469
470 /// The set of declarations that may have redeclaration chains that
471 /// need to be serialized.
473
474 /// A cache of the first local declaration for "interesting"
475 /// redeclaration chains.
476 llvm::DenseMap<const Decl *, const Decl *> FirstLocalDeclCache;
477
478 /// Mapping from SwitchCase statements to IDs.
479 llvm::DenseMap<SwitchCase *, unsigned> SwitchCaseIDs;
480
481 /// The number of statements written to the AST file.
482 unsigned NumStatements = 0;
483
484 /// The number of macros written to the AST file.
485 unsigned NumMacros = 0;
486
487 /// The number of lexical declcontexts written to the AST
488 /// file.
489 unsigned NumLexicalDeclContexts = 0;
490
491 /// The number of visible declcontexts written to the AST
492 /// file.
493 unsigned NumVisibleDeclContexts = 0;
494
495 /// A mapping from each known submodule to its ID number, which will
496 /// be a positive integer.
497 llvm::DenseMap<const Module *, unsigned> SubmoduleIDs;
498
499 /// A list of the module file extension writers.
500 std::vector<std::unique_ptr<ModuleFileExtensionWriter>>
501 ModuleFileExtensionWriters;
502
503 /// Mapping from a source location entry to whether it is affecting or not.
504 llvm::BitVector IsSLocAffecting;
505 /// Mapping from a source location entry to whether it must be included as
506 /// input file.
507 llvm::BitVector IsSLocFileEntryAffecting;
508
509 /// Mapping from \c FileID to an index into the FileID adjustment table.
510 std::vector<FileID> NonAffectingFileIDs;
511 std::vector<unsigned> NonAffectingFileIDAdjustments;
512
513 /// Mapping from an offset to an index into the offset adjustment table.
514 std::vector<SourceRange> NonAffectingRanges;
515 std::vector<SourceLocation::UIntTy> NonAffectingOffsetAdjustments;
516
517 /// A list of classes in named modules which need to emit the VTable in
518 /// the corresponding object file.
519 llvm::SmallVector<CXXRecordDecl *> PendingEmittingVTables;
520
521 /// Computes input files that didn't affect compilation of the current module,
522 /// and initializes data structures necessary for leaving those files out
523 /// during \c SourceManager serialization.
524 void computeNonAffectingInputFiles();
525
526 /// Some affecting files can be included from files that are not affecting.
527 /// This function erases source locations pointing into such files.
528 SourceLocation getAffectingIncludeLoc(const SourceManager &SourceMgr,
529 const SrcMgr::FileInfo &File);
530
531 /// Returns an adjusted \c FileID, accounting for any non-affecting input
532 /// files.
533 FileID getAdjustedFileID(FileID FID) const;
534 /// Returns an adjusted number of \c FileIDs created within the specified \c
535 /// FileID, accounting for any non-affecting input files.
536 unsigned getAdjustedNumCreatedFIDs(FileID FID) const;
537 /// Returns an adjusted \c SourceLocation, accounting for any non-affecting
538 /// input files.
539 SourceLocation getAdjustedLocation(SourceLocation Loc) const;
540 /// Returns an adjusted \c SourceRange, accounting for any non-affecting input
541 /// files.
542 SourceRange getAdjustedRange(SourceRange Range) const;
543 /// Returns an adjusted \c SourceLocation offset, accounting for any
544 /// non-affecting input files.
545 SourceLocation::UIntTy getAdjustedOffset(SourceLocation::UIntTy Offset) const;
546 /// Returns an adjustment for offset into SourceManager, accounting for any
547 /// non-affecting input files.
548 SourceLocation::UIntTy getAdjustment(SourceLocation::UIntTy Offset) const;
549
550 /// Retrieve or create a submodule ID for this module.
551 unsigned getSubmoduleID(Module *Mod);
552
553 /// Write the given subexpression to the bitstream.
554 void WriteSubStmt(ASTContext &Context, Stmt *S);
555
556 void WriteBlockInfoBlock();
557 void WriteControlBlock(Preprocessor &PP, StringRef isysroot);
558
559 /// Write out the signature and diagnostic options, and return the signature.
560 void writeUnhashedControlBlock(Preprocessor &PP);
561 ASTFileSignature backpatchSignature();
562
563 /// Calculate hash of the pcm content.
564 std::pair<ASTFileSignature, ASTFileSignature> createSignature() const;
565 ASTFileSignature createSignatureForNamedModule() const;
566
567 void WriteInputFiles(SourceManager &SourceMgr, HeaderSearchOptions &HSOpts);
568 void WriteSourceManagerBlock(SourceManager &SourceMgr);
569 void WritePreprocessor(const Preprocessor &PP, bool IsModule);
570 void WriteHeaderSearch(const HeaderSearch &HS);
571 void WritePreprocessorDetail(PreprocessingRecord &PPRec,
572 uint64_t MacroOffsetsBase);
573 void WriteSubmodules(Module *WritingModule, ASTContext *Context);
574
575 void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag,
576 bool isModule);
577
578 unsigned TypeExtQualAbbrev = 0;
579 void WriteTypeAbbrevs();
580 void WriteType(ASTContext &Context, QualType T);
581
582 bool isLookupResultExternal(StoredDeclsList &Result, DeclContext *DC);
583
584 void GenerateSpecializationInfoLookupTable(
585 const NamedDecl *D, llvm::SmallVectorImpl<const Decl *> &Specializations,
586 llvm::SmallVectorImpl<char> &LookupTable, bool IsPartial);
587 uint64_t WriteSpecializationInfoLookupTable(
588 const NamedDecl *D, llvm::SmallVectorImpl<const Decl *> &Specializations,
589 bool IsPartial);
590 void GenerateNameLookupTable(ASTContext &Context, const DeclContext *DC,
591 llvm::SmallVectorImpl<char> &LookupTable);
592 uint64_t WriteDeclContextLexicalBlock(ASTContext &Context,
593 const DeclContext *DC);
594 uint64_t WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC);
595 void WriteTypeDeclOffsets();
596 void WriteFileDeclIDsMap();
597 void WriteComments(ASTContext &Context);
598 void WriteSelectors(Sema &SemaRef);
599 void WriteReferencedSelectorsPool(Sema &SemaRef);
600 void WriteIdentifierTable(Preprocessor &PP, IdentifierResolver *IdResolver,
601 bool IsModule);
602 void WriteDeclAndTypes(ASTContext &Context);
603 void PrepareWritingSpecialDecls(Sema &SemaRef);
604 void WriteSpecialDeclRecords(Sema &SemaRef);
605 void WriteSpecializationsUpdates(bool IsPartial);
606 void WriteDeclUpdatesBlocks(ASTContext &Context,
607 RecordDataImpl &OffsetsRecord);
608 void WriteDeclContextVisibleUpdate(ASTContext &Context,
609 const DeclContext *DC);
610 void WriteFPPragmaOptions(const FPOptionsOverride &Opts);
611 void WriteOpenCLExtensions(Sema &SemaRef);
612 void WriteCUDAPragmas(Sema &SemaRef);
613 void WriteObjCCategories();
614 void WriteLateParsedTemplates(Sema &SemaRef);
615 void WriteOptimizePragmaOptions(Sema &SemaRef);
616 void WriteMSStructPragmaOptions(Sema &SemaRef);
617 void WriteMSPointersToMembersPragmaOptions(Sema &SemaRef);
618 void WritePackPragmaOptions(Sema &SemaRef);
619 void WriteFloatControlPragmaOptions(Sema &SemaRef);
620 void WriteDeclsWithEffectsToVerify(Sema &SemaRef);
621 void WriteModuleFileExtension(Sema &SemaRef,
622 ModuleFileExtensionWriter &Writer);
623
624 unsigned DeclParmVarAbbrev = 0;
625 unsigned DeclContextLexicalAbbrev = 0;
626 unsigned DeclContextVisibleLookupAbbrev = 0;
627 unsigned UpdateVisibleAbbrev = 0;
628 unsigned DeclRecordAbbrev = 0;
629 unsigned DeclTypedefAbbrev = 0;
630 unsigned DeclVarAbbrev = 0;
631 unsigned DeclFieldAbbrev = 0;
632 unsigned DeclEnumAbbrev = 0;
633 unsigned DeclObjCIvarAbbrev = 0;
634 unsigned DeclCXXMethodAbbrev = 0;
635 unsigned DeclSpecializationsAbbrev = 0;
636 unsigned DeclPartialSpecializationsAbbrev = 0;
637
638 unsigned DeclDependentNonTemplateCXXMethodAbbrev = 0;
639 unsigned DeclTemplateCXXMethodAbbrev = 0;
640 unsigned DeclMemberSpecializedCXXMethodAbbrev = 0;
641 unsigned DeclTemplateSpecializedCXXMethodAbbrev = 0;
642 unsigned DeclDependentSpecializationCXXMethodAbbrev = 0;
643 unsigned DeclTemplateTypeParmAbbrev = 0;
644 unsigned DeclUsingShadowAbbrev = 0;
645
646 unsigned DeclRefExprAbbrev = 0;
647 unsigned CharacterLiteralAbbrev = 0;
648 unsigned IntegerLiteralAbbrev = 0;
649 unsigned ExprImplicitCastAbbrev = 0;
650 unsigned BinaryOperatorAbbrev = 0;
651 unsigned CompoundAssignOperatorAbbrev = 0;
652 unsigned CallExprAbbrev = 0;
653 unsigned CXXOperatorCallExprAbbrev = 0;
654 unsigned CXXMemberCallExprAbbrev = 0;
655
656 unsigned CompoundStmtAbbrev = 0;
657
658 void WriteDeclAbbrevs();
659 void WriteDecl(ASTContext &Context, Decl *D);
660
661 ASTFileSignature WriteASTCore(Sema *SemaPtr, StringRef isysroot,
662 Module *WritingModule);
663
664public:
665 /// Create a new precompiled header writer that outputs to
666 /// the given bitstream.
667 ASTWriter(llvm::BitstreamWriter &Stream, SmallVectorImpl<char> &Buffer,
668 InMemoryModuleCache &ModuleCache,
669 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
670 bool IncludeTimestamps = true, bool BuildingImplicitModule = false,
671 bool GeneratingReducedBMI = false);
672 ~ASTWriter() override;
673
674 const LangOptions &getLangOpts() const;
675
676 /// Get a timestamp for output into the AST file. The actual timestamp
677 /// of the specified file may be ignored if we have been instructed to not
678 /// include timestamps in the output file.
679 time_t getTimestampForOutput(const FileEntry *E) const;
680
681 /// Write a precompiled header or a module with the AST produced by the
682 /// \c Sema object, or a dependency scanner module with the preprocessor state
683 /// produced by the \c Preprocessor object.
684 ///
685 /// \param Subject The \c Sema object that processed the AST to be written, or
686 /// in the case of a dependency scanner module the \c Preprocessor that holds
687 /// the state.
688 ///
689 /// \param WritingModule The module that we are writing. If null, we are
690 /// writing a precompiled header.
691 ///
692 /// \param isysroot if non-empty, write a relocatable file whose headers
693 /// are relative to the given system root. If we're writing a module, its
694 /// build directory will be used in preference to this if both are available.
695 ///
696 /// \return the module signature, which eventually will be a hash of
697 /// the module but currently is merely a random 32-bit number.
698 ASTFileSignature WriteAST(llvm::PointerUnion<Sema *, Preprocessor *> Subject,
699 StringRef OutputFile, Module *WritingModule,
700 StringRef isysroot,
701 bool ShouldCacheASTInMemory = false);
702
703 /// Emit a token.
704 void AddToken(const Token &Tok, RecordDataImpl &Record);
705
706 /// Emit a AlignPackInfo.
707 void AddAlignPackInfo(const Sema::AlignPackInfo &Info,
709
710 /// Emit a FileID.
712
713 /// Emit a source location.
715 LocSeq *Seq = nullptr);
716
717 /// Return the raw encodings for source locations.
720
721 /// Emit a source range.
723 LocSeq *Seq = nullptr);
724
725 /// Emit a reference to an identifier.
727
728 /// Get the unique number used to refer to the given selector.
730
731 /// Get the unique number used to refer to the given identifier.
733
734 /// Get the unique number used to refer to the given macro.
736
737 /// Determine the ID of an already-emitted macro.
739
740 uint32_t getMacroDirectivesOffset(const IdentifierInfo *Name);
741
742 /// Emit a reference to a type.
744
745 /// Force a type to be emitted and get its ID.
747
748 /// Find the first local declaration of a given local redeclarable
749 /// decl.
750 const Decl *getFirstLocalDecl(const Decl *D);
751
752 /// Is this a local declaration (that is, one that will be written to
753 /// our AST file)? This is the case for declarations that are neither imported
754 /// from another AST file nor predefined.
755 bool IsLocalDecl(const Decl *D) {
756 if (D->isFromASTFile())
757 return false;
758 auto I = DeclIDs.find(D);
759 return (I == DeclIDs.end() || I->second >= clang::NUM_PREDEF_DECL_IDS);
760 };
761
762 /// Emit a reference to a declaration.
763 void AddDeclRef(const Decl *D, RecordDataImpl &Record);
764 // Emit a reference to a declaration if the declaration was emitted.
766
767 /// Force a declaration to be emitted and get its local ID to the module file
768 /// been writing.
770
771 /// Determine the local declaration ID of an already-emitted
772 /// declaration.
773 LocalDeclID getDeclID(const Decl *D);
774
775 /// Whether or not the declaration got emitted. If not, it wouldn't be
776 /// emitted.
777 ///
778 /// This may only be called after we've done the job to write the
779 /// declarations (marked by DoneWritingDeclsAndTypes).
780 ///
781 /// A declaration may only be omitted in reduced BMI.
782 bool wasDeclEmitted(const Decl *D) const;
783
785
786 /// Add a string to the given record.
787 void AddString(StringRef Str, RecordDataImpl &Record);
788 void AddStringBlob(StringRef Str, RecordDataImpl &Record,
790
791 /// Convert a path from this build process into one that is appropriate
792 /// for emission in the module file.
794
795 /// Add a path to the given record.
796 void AddPath(StringRef Path, RecordDataImpl &Record);
797 void AddPathBlob(StringRef Str, RecordDataImpl &Record,
799
800 /// Emit the current record with the given path as a blob.
801 void EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record,
802 StringRef Path);
803
804 /// Add a version tuple to the given record
805 void AddVersionTuple(const VersionTuple &Version, RecordDataImpl &Record);
806
807 /// Retrieve or create a submodule ID for this module, or return 0 if
808 /// the submodule is neither local (a submodle of the currently-written module)
809 /// nor from an imported module.
810 unsigned getLocalOrImportedSubmoduleID(const Module *Mod);
811
812 /// Note that the identifier II occurs at the given offset
813 /// within the identifier table.
814 void SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset);
815
816 /// Note that the selector Sel occurs at the given offset
817 /// within the method pool/selector table.
818 void SetSelectorOffset(Selector Sel, uint32_t Offset);
819
820 /// Record an ID for the given switch-case statement.
821 unsigned RecordSwitchCaseID(SwitchCase *S);
822
823 /// Retrieve the ID for the given switch-case statement.
824 unsigned getSwitchCaseID(SwitchCase *S);
825
826 void ClearSwitchCaseIDs();
827
828 unsigned getTypeExtQualAbbrev() const {
829 return TypeExtQualAbbrev;
830 }
831
832 unsigned getDeclParmVarAbbrev() const { return DeclParmVarAbbrev; }
833 unsigned getDeclRecordAbbrev() const { return DeclRecordAbbrev; }
834 unsigned getDeclTypedefAbbrev() const { return DeclTypedefAbbrev; }
835 unsigned getDeclVarAbbrev() const { return DeclVarAbbrev; }
836 unsigned getDeclFieldAbbrev() const { return DeclFieldAbbrev; }
837 unsigned getDeclEnumAbbrev() const { return DeclEnumAbbrev; }
838 unsigned getDeclObjCIvarAbbrev() const { return DeclObjCIvarAbbrev; }
840 switch (Kind) {
842 return DeclCXXMethodAbbrev;
844 return DeclTemplateCXXMethodAbbrev;
846 return DeclMemberSpecializedCXXMethodAbbrev;
848 return DeclTemplateSpecializedCXXMethodAbbrev;
850 return DeclDependentNonTemplateCXXMethodAbbrev;
852 return DeclDependentSpecializationCXXMethodAbbrev;
853 }
854 llvm_unreachable("Unknwon Template Kind!");
855 }
857 return DeclTemplateTypeParmAbbrev;
858 }
859 unsigned getDeclUsingShadowAbbrev() const { return DeclUsingShadowAbbrev; }
860
861 unsigned getDeclRefExprAbbrev() const { return DeclRefExprAbbrev; }
862 unsigned getCharacterLiteralAbbrev() const { return CharacterLiteralAbbrev; }
863 unsigned getIntegerLiteralAbbrev() const { return IntegerLiteralAbbrev; }
864 unsigned getExprImplicitCastAbbrev() const { return ExprImplicitCastAbbrev; }
865 unsigned getBinaryOperatorAbbrev() const { return BinaryOperatorAbbrev; }
867 return CompoundAssignOperatorAbbrev;
868 }
869 unsigned getCallExprAbbrev() const { return CallExprAbbrev; }
870 unsigned getCXXOperatorCallExprAbbrev() { return CXXOperatorCallExprAbbrev; }
871 unsigned getCXXMemberCallExprAbbrev() { return CXXMemberCallExprAbbrev; }
872
873 unsigned getCompoundStmtAbbrev() const { return CompoundStmtAbbrev; }
874
875 bool hasChain() const { return Chain; }
876 ASTReader *getChain() const { return Chain; }
877
878 bool isWritingModule() const { return WritingModule; }
879
881 return WritingModule && WritingModule->isNamedModule();
882 }
883
884 bool isGeneratingReducedBMI() const { return GeneratingReducedBMI; }
885
886 bool getDoneWritingDeclsAndTypes() const { return DoneWritingDeclsAndTypes; }
887
888 bool isDeclPredefined(const Decl *D) const {
889 return PredefinedDecls.count(D);
890 }
891
892 void handleVTable(CXXRecordDecl *RD);
893
894private:
895 // ASTDeserializationListener implementation
896 void ReaderInitialized(ASTReader *Reader) override;
897 void IdentifierRead(serialization::IdentifierID ID, IdentifierInfo *II) override;
898 void MacroRead(serialization::MacroID ID, MacroInfo *MI) override;
899 void TypeRead(serialization::TypeIdx Idx, QualType T) override;
900 void PredefinedDeclBuilt(PredefinedDeclIDs ID, const Decl *D) override;
901 void SelectorRead(serialization::SelectorID ID, Selector Sel) override;
902 void MacroDefinitionRead(serialization::PreprocessedEntityID ID,
903 MacroDefinitionRecord *MD) override;
904 void ModuleRead(serialization::SubmoduleID ID, Module *Mod) override;
905
906 // ASTMutationListener implementation.
907 void CompletedTagDefinition(const TagDecl *D) override;
908 void AddedVisibleDecl(const DeclContext *DC, const Decl *D) override;
909 void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) override;
910 void AddedCXXTemplateSpecialization(
911 const ClassTemplateDecl *TD,
912 const ClassTemplateSpecializationDecl *D) override;
913 void AddedCXXTemplateSpecialization(
914 const VarTemplateDecl *TD,
915 const VarTemplateSpecializationDecl *D) override;
916 void AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD,
917 const FunctionDecl *D) override;
918 void ResolvedExceptionSpec(const FunctionDecl *FD) override;
919 void DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) override;
920 void ResolvedOperatorDelete(const CXXDestructorDecl *DD,
921 const FunctionDecl *Delete,
922 Expr *ThisArg) override;
923 void CompletedImplicitDefinition(const FunctionDecl *D) override;
924 void InstantiationRequested(const ValueDecl *D) override;
925 void VariableDefinitionInstantiated(const VarDecl *D) override;
926 void FunctionDefinitionInstantiated(const FunctionDecl *D) override;
927 void DefaultArgumentInstantiated(const ParmVarDecl *D) override;
928 void DefaultMemberInitializerInstantiated(const FieldDecl *D) override;
929 void AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD,
930 const ObjCInterfaceDecl *IFD) override;
931 void DeclarationMarkedUsed(const Decl *D) override;
932 void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) override;
933 void DeclarationMarkedOpenMPDeclareTarget(const Decl *D,
934 const Attr *Attr) override;
935 void DeclarationMarkedOpenMPAllocate(const Decl *D, const Attr *A) override;
936 void RedefinedHiddenDefinition(const NamedDecl *D, Module *M) override;
937 void AddedAttributeToRecord(const Attr *Attr,
938 const RecordDecl *Record) override;
939 void EnteringModulePurview() override;
940 void AddedManglingNumber(const Decl *D, unsigned) override;
941 void AddedStaticLocalNumbers(const Decl *D, unsigned) override;
942 void AddedAnonymousNamespace(const TranslationUnitDecl *,
943 NamespaceDecl *AnonNamespace) override;
944};
945
946/// AST and semantic-analysis consumer that generates a
947/// precompiled header from the parsed source code.
949 void anchor() override;
950
951 Preprocessor &PP;
952 llvm::PointerUnion<Sema *, Preprocessor *> Subject;
953 std::string OutputFile;
954 std::string isysroot;
955 std::shared_ptr<PCHBuffer> Buffer;
956 llvm::BitstreamWriter Stream;
957 ASTWriter Writer;
958 bool AllowASTWithErrors;
959 bool ShouldCacheASTInMemory;
960
961protected:
962 ASTWriter &getWriter() { return Writer; }
963 const ASTWriter &getWriter() const { return Writer; }
964 SmallVectorImpl<char> &getPCH() const { return Buffer->Data; }
965
966 bool isComplete() const { return Buffer->IsComplete; }
967 PCHBuffer *getBufferPtr() { return Buffer.get(); }
968 StringRef getOutputFile() const { return OutputFile; }
971
972 virtual Module *getEmittingModule(ASTContext &Ctx);
973
974public:
976 StringRef OutputFile, StringRef isysroot,
977 std::shared_ptr<PCHBuffer> Buffer,
978 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
979 bool AllowASTWithErrors = false, bool IncludeTimestamps = true,
980 bool BuildingImplicitModule = false,
981 bool ShouldCacheASTInMemory = false,
982 bool GeneratingReducedBMI = false);
983 ~PCHGenerator() override;
984
985 void InitializeSema(Sema &S) override;
986 void HandleTranslationUnit(ASTContext &Ctx) override;
987 void HandleVTable(CXXRecordDecl *RD) override { Writer.handleVTable(RD); }
990 bool hasEmittedPCH() const { return Buffer->IsComplete; }
991};
992
994 void anchor() override;
995
996protected:
997 virtual Module *getEmittingModule(ASTContext &Ctx) override;
998
1000 StringRef OutputFile, bool GeneratingReducedBMI);
1001
1002public:
1004 StringRef OutputFile)
1005 : CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
1006 /*GeneratingReducedBMI=*/false) {}
1007
1008 void HandleTranslationUnit(ASTContext &Ctx) override;
1009};
1010
1012 void anchor() override;
1013
1014public:
1016 StringRef OutputFile)
1017 : CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
1018 /*GeneratingReducedBMI=*/true) {}
1019};
1020
1021/// If we can elide the definition of \param D in reduced BMI.
1022///
1023/// Generally, we can elide the definition of a declaration if it won't affect
1024/// the ABI. e.g., the non-inline function bodies.
1025bool CanElideDeclDef(const Decl *D);
1026
1027/// A simple helper class to pack several bits in order into (a) 32 bit
1028/// integer(s).
1030 constexpr static uint32_t BitIndexUpbound = 32u;
1031
1032public:
1033 BitsPacker() = default;
1034 BitsPacker(const BitsPacker &) = delete;
1038 ~BitsPacker() = default;
1039
1040 bool canWriteNextNBits(uint32_t BitsWidth) const {
1041 return CurrentBitIndex + BitsWidth < BitIndexUpbound;
1042 }
1043
1044 void reset(uint32_t Value) {
1045 UnderlyingValue = Value;
1046 CurrentBitIndex = 0;
1047 }
1048
1049 void addBit(bool Value) { addBits(Value, 1); }
1050 void addBits(uint32_t Value, uint32_t BitsWidth) {
1051 assert(BitsWidth < BitIndexUpbound);
1052 assert((Value < (1u << BitsWidth)) && "Passing narrower bit width!");
1053 assert(canWriteNextNBits(BitsWidth) &&
1054 "Inserting too much bits into a value!");
1055
1056 UnderlyingValue |= Value << CurrentBitIndex;
1057 CurrentBitIndex += BitsWidth;
1058 }
1059
1060 operator uint32_t() { return UnderlyingValue; }
1061
1062private:
1063 uint32_t UnderlyingValue = 0;
1064 uint32_t CurrentBitIndex = 0;
1065};
1066
1067} // namespace clang
1068
1069#endif // LLVM_CLANG_SERIALIZATION_ASTWRITER_H
MatchType Type
static char ID
Definition: Arena.cpp:183
const Decl * D
IndirectLocalPath & Path
Expr * E
enum clang::sema::@1718::IndirectLocalPathEntry::EntryKind Kind
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:188
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:383
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:6391
unsigned getDeclParmVarAbbrev() const
Definition: ASTWriter.h:832
void AddEmittedDeclRef(const Decl *D, RecordDataImpl &Record)
Definition: ASTWriter.cpp:6541
void AddSourceRange(SourceRange Range, RecordDataImpl &Record, LocSeq *Seq=nullptr)
Emit a source range.
Definition: ASTWriter.cpp:6351
unsigned getBinaryOperatorAbbrev() const
Definition: ASTWriter.h:865
unsigned getDeclTemplateTypeParmAbbrev() const
Definition: ASTWriter.h:856
bool isWritingStdCXXNamedModules() const
Definition: ASTWriter.h:880
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:5029
void AddFileID(FileID FID, RecordDataImpl &Record)
Emit a FileID.
Definition: ASTWriter.cpp:6318
unsigned getDeclObjCIvarAbbrev() const
Definition: ASTWriter.h:838
unsigned getExprImplicitCastAbbrev() const
Definition: ASTWriter.h:864
bool isDeclPredefined(const Decl *D) const
Definition: ASTWriter.h:888
unsigned getDeclTypedefAbbrev() const
Definition: ASTWriter.h:834
bool hasChain() const
Definition: ASTWriter.h:875
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:5016
SmallVectorImpl< uint64_t > RecordDataImpl
Definition: ASTWriter.h:95
unsigned getDeclUsingShadowAbbrev() const
Definition: ASTWriter.h:859
unsigned getTypeExtQualAbbrev() const
Definition: ASTWriter.h:828
void AddVersionTuple(const VersionTuple &Version, RecordDataImpl &Record)
Add a version tuple to the given record.
Definition: ASTWriter.cpp:5036
bool isGeneratingReducedBMI() const
Definition: ASTWriter.h:884
uint32_t getMacroDirectivesOffset(const IdentifierInfo *Name)
Definition: ASTWriter.cpp:6399
unsigned getDeclVarAbbrev() const
Definition: ASTWriter.h:835
unsigned getDeclEnumAbbrev() const
Definition: ASTWriter.h:837
void AddAlignPackInfo(const Sema::AlignPackInfo &Info, RecordDataImpl &Record)
Emit a AlignPackInfo.
Definition: ASTWriter.cpp:6250
void AddPathBlob(StringRef Str, RecordDataImpl &Record, SmallVectorImpl< char > &Blob)
Definition: ASTWriter.cpp:5022
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:755
unsigned getDeclRefExprAbbrev() const
Definition: ASTWriter.h:861
void AddTypeRef(ASTContext &Context, QualType T, RecordDataImpl &Record)
Emit a reference to a type.
Definition: ASTWriter.cpp:6489
unsigned getCXXOperatorCallExprAbbrev()
Definition: ASTWriter.h:870
bool wasDeclEmitted(const Decl *D) const
Whether or not the declaration got emitted.
Definition: ASTWriter.cpp:6606
void AddString(StringRef Str, RecordDataImpl &Record)
Add a string to the given record.
Definition: ASTWriter.cpp:4983
time_t getTimestampForOutput(const FileEntry *E) const
Get a timestamp for output into the AST file.
Definition: ASTWriter.cpp:5101
~ASTWriter() override
bool isWritingModule() const
Definition: ASTWriter.h:878
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:6552
LocalDeclID getDeclID(const Decl *D)
Determine the local declaration ID of an already-emitted declaration.
Definition: ASTWriter.cpp:6593
void AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record)
Emit a reference to an identifier.
Definition: ASTWriter.cpp:6361
serialization::MacroID getMacroRef(MacroInfo *MI, const IdentifierInfo *Name)
Get the unique number used to refer to the given macro.
Definition: ASTWriter.cpp:6375
void AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record, LocSeq *Seq=nullptr)
Emit a source location.
Definition: ASTWriter.cpp:6345
unsigned getCXXMemberCallExprAbbrev()
Definition: ASTWriter.h:871
ASTFileSignature WriteAST(llvm::PointerUnion< Sema *, Preprocessor * > Subject, StringRef OutputFile, Module *WritingModule, StringRef isysroot, bool ShouldCacheASTInMemory=false)
Write a precompiled header or a module with the AST produced by the Sema object, or a dependency scan...
Definition: ASTWriter.cpp:5106
ASTReader * getChain() const
Definition: ASTWriter.h:876
unsigned getCompoundAssignOperatorAbbrev() const
Definition: ASTWriter.h:866
bool getDoneWritingDeclsAndTypes() const
Definition: ASTWriter.h:886
serialization::IdentifierID getIdentifierRef(const IdentifierInfo *II)
Get the unique number used to refer to the given identifier.
Definition: ASTWriter.cpp:6365
unsigned RecordSwitchCaseID(SwitchCase *S)
Record an ID for the given switch-case statement.
unsigned getCharacterLiteralAbbrev() const
Definition: ASTWriter.h:862
unsigned getDeclCXXMethodAbbrev(FunctionDecl::TemplatedKind Kind) const
Definition: ASTWriter.h:839
void handleVTable(CXXRecordDecl *RD)
Definition: ASTWriter.cpp:4014
unsigned getCompoundStmtAbbrev() const
Definition: ASTWriter.h:873
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:2898
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:4937
serialization::SelectorID getSelectorRef(Selector Sel)
Get the unique number used to refer to the given selector.
Definition: ASTWriter.cpp:6407
SourceLocationEncoding::RawLocEncoding getRawSourceLocationEncoding(SourceLocation Loc, LocSeq *Seq=nullptr)
Return the raw encodings for source locations.
Definition: ASTWriter.cpp:6323
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:5078
SmallVector< uint64_t, 64 > RecordData
Definition: ASTWriter.h:94
serialization::TypeID GetOrCreateTypeID(ASTContext &Context, QualType T)
Force a type to be emitted and get its ID.
Definition: ASTWriter.cpp:6519
unsigned getAnonymousDeclarationNumber(const NamedDecl *D)
Definition: ASTWriter.cpp:6660
unsigned getDeclFieldAbbrev() const
Definition: ASTWriter.h:836
const LangOptions & getLangOpts() const
Definition: ASTWriter.cpp:5096
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:5068
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:4994
unsigned getCallExprAbbrev() const
Definition: ASTWriter.h:869
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:5051
unsigned getDeclRecordAbbrev() const
Definition: ASTWriter.h:833
void AddDeclRef(const Decl *D, RecordDataImpl &Record)
Emit a reference to a declaration.
Definition: ASTWriter.cpp:6548
void AddStringBlob(StringRef Str, RecordDataImpl &Record, SmallVectorImpl< char > &Blob)
Definition: ASTWriter.cpp:4988
unsigned getIntegerLiteralAbbrev() const
Definition: ASTWriter.h:863
Attr - This represents one attribute.
Definition: Attr.h:43
A simple helper class to pack several bits in order into (a) 32 bit integer(s).
Definition: ASTWriter.h:1029
~BitsPacker()=default
void addBit(bool Value)
Definition: ASTWriter.h:1049
bool canWriteNextNBits(uint32_t BitsWidth) const
Definition: ASTWriter.h:1040
BitsPacker operator=(BitsPacker &&)=delete
BitsPacker(BitsPacker &&)=delete
BitsPacker()=default
void addBits(uint32_t Value, uint32_t BitsWidth)
Definition: ASTWriter.h:1050
void reset(uint32_t Value)
Definition: ASTWriter.h:1044
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:1003
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2817
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:1435
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:231
This represents one expression.
Definition: Expr.h:110
Represents a member of a struct/union/class.
Definition: Decl.h:3033
Cached information about one file (either on disk or in the virtual file system).
Definition: FileEntry.h:305
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:1935
TemplatedKind
The kind of templated function a FunctionDecl can be.
Definition: Decl.h:1940
@ TK_MemberSpecialization
Definition: Decl.h:1947
@ TK_DependentNonTemplate
Definition: Decl.h:1956
@ TK_FunctionTemplateSpecialization
Definition: Decl.h:1951
@ TK_DependentFunctionTemplateSpecialization
Definition: Decl.h:1954
Declaration of a template function.
Definition: DeclTemplate.h:959
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:499
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:115
bool isNamedModule() const
Does this Module is a named module of a standard named module?
Definition: Module.h:195
This represents a decl that may have a name.
Definition: Decl.h:253
Represent a C++ namespace.
Definition: Decl.h:551
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:948
ASTMutationListener * GetASTMutationListener() override
If the consumer is interested in entities getting modified after their initial creation,...
Definition: GeneratePCH.cpp:92
void InitializeSema(Sema &S) override
Initialize the semantic consumer with the Sema instance being used to perform semantic analysis on th...
Definition: GeneratePCH.cpp:63
PCHBuffer * getBufferPtr()
Definition: ASTWriter.h:967
Preprocessor & getPreprocessor()
Definition: ASTWriter.h:970
virtual Module * getEmittingModule(ASTContext &Ctx)
Definition: GeneratePCH.cpp:44
SmallVectorImpl< char > & getPCH() const
Definition: ASTWriter.h:964
StringRef getOutputFile() const
Definition: ASTWriter.h:968
~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:987
ASTDeserializationListener * GetASTDeserializationListener() override
If the consumer is interested in entities being deserialized from AST files, it should return a point...
Definition: GeneratePCH.cpp:96
const ASTWriter & getWriter() const
Definition: ASTWriter.h:963
void HandleTranslationUnit(ASTContext &Ctx) override
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
Definition: GeneratePCH.cpp:70
bool hasEmittedPCH() const
Definition: ASTWriter.h:990
ASTWriter & getWriter()
Definition: ASTWriter.h:962
bool isComplete() const
Definition: ASTWriter.h:966
DiagnosticsEngine & getDiagnostics() const
Definition: GeneratePCH.cpp:59
Represents a parameter to a function.
Definition: Decl.h:1725
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:138
A (possibly-)qualified type.
Definition: Type.h:929
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:978
Represents a struct/union/class.
Definition: Decl.h:4148
ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache, StringRef OutputFile)
Definition: ASTWriter.h:1015
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:463
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:3564
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:671
Represents a variable declaration or definition.
Definition: Decl.h:882
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:1156
@ 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.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
PredefinedDeclIDs
Predefined declaration IDs.
Definition: DeclID.h:31
@ NUM_PREDEF_DECL_IDS
The number of declaration IDs that are predefined.
Definition: DeclID.h:90
@ 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:58
A structure for putting "fast"-unqualified QualTypes into a DenseMap.
Definition: ASTBitCodes.h:134