clang 19.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 /// Computes input files that didn't affect compilation of the current module,
504 /// and initializes data structures necessary for leaving those files out
505 /// during \c SourceManager serialization.
506 void computeNonAffectingInputFiles();
507
508 /// Some affecting files can be included from files that are not affecting.
509 /// This function erases source locations pointing into such files.
510 SourceLocation getAffectingIncludeLoc(const SourceManager &SourceMgr,
511 const SrcMgr::FileInfo &File);
512
513 /// Returns an adjusted \c FileID, accounting for any non-affecting input
514 /// files.
515 FileID getAdjustedFileID(FileID FID) const;
516 /// Returns an adjusted number of \c FileIDs created within the specified \c
517 /// FileID, accounting for any non-affecting input files.
518 unsigned getAdjustedNumCreatedFIDs(FileID FID) const;
519 /// Returns an adjusted \c SourceLocation, accounting for any non-affecting
520 /// input files.
521 SourceLocation getAdjustedLocation(SourceLocation Loc) const;
522 /// Returns an adjusted \c SourceRange, accounting for any non-affecting input
523 /// files.
524 SourceRange getAdjustedRange(SourceRange Range) const;
525 /// Returns an adjusted \c SourceLocation offset, accounting for any
526 /// non-affecting input files.
527 SourceLocation::UIntTy getAdjustedOffset(SourceLocation::UIntTy Offset) const;
528 /// Returns an adjustment for offset into SourceManager, accounting for any
529 /// non-affecting input files.
530 SourceLocation::UIntTy getAdjustment(SourceLocation::UIntTy Offset) const;
531
532 /// Retrieve or create a submodule ID for this module.
533 unsigned getSubmoduleID(Module *Mod);
534
535 /// Write the given subexpression to the bitstream.
536 void WriteSubStmt(Stmt *S);
537
538 void WriteBlockInfoBlock();
539 void WriteControlBlock(Preprocessor &PP, ASTContext &Context,
540 StringRef isysroot);
541
542 /// Write out the signature and diagnostic options, and return the signature.
543 void writeUnhashedControlBlock(Preprocessor &PP, ASTContext &Context);
544 ASTFileSignature backpatchSignature();
545
546 /// Calculate hash of the pcm content.
547 std::pair<ASTFileSignature, ASTFileSignature> createSignature() const;
548 ASTFileSignature createSignatureForNamedModule() const;
549
550 void WriteInputFiles(SourceManager &SourceMgr, HeaderSearchOptions &HSOpts);
551 void WriteSourceManagerBlock(SourceManager &SourceMgr,
552 const Preprocessor &PP);
553 void WritePreprocessor(const Preprocessor &PP, bool IsModule);
554 void WriteHeaderSearch(const HeaderSearch &HS);
555 void WritePreprocessorDetail(PreprocessingRecord &PPRec,
556 uint64_t MacroOffsetsBase);
557 void WriteSubmodules(Module *WritingModule);
558
559 void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag,
560 bool isModule);
561
562 unsigned TypeExtQualAbbrev = 0;
563 void WriteTypeAbbrevs();
564 void WriteType(QualType T);
565
566 bool isLookupResultExternal(StoredDeclsList &Result, DeclContext *DC);
567
568 void GenerateNameLookupTable(const DeclContext *DC,
569 llvm::SmallVectorImpl<char> &LookupTable);
570 uint64_t WriteDeclContextLexicalBlock(ASTContext &Context,
571 const DeclContext *DC);
572 uint64_t WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC);
573 void WriteTypeDeclOffsets();
574 void WriteFileDeclIDsMap();
575 void WriteComments();
576 void WriteSelectors(Sema &SemaRef);
577 void WriteReferencedSelectorsPool(Sema &SemaRef);
578 void WriteIdentifierTable(Preprocessor &PP, IdentifierResolver &IdResolver,
579 bool IsModule);
580 void WriteDeclAndTypes(ASTContext &Context);
581 void PrepareWritingSpecialDecls(Sema &SemaRef);
582 void WriteSpecialDeclRecords(Sema &SemaRef);
583 void WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord);
584 void WriteDeclContextVisibleUpdate(const DeclContext *DC);
585 void WriteFPPragmaOptions(const FPOptionsOverride &Opts);
586 void WriteOpenCLExtensions(Sema &SemaRef);
587 void WriteCUDAPragmas(Sema &SemaRef);
588 void WriteObjCCategories();
589 void WriteLateParsedTemplates(Sema &SemaRef);
590 void WriteOptimizePragmaOptions(Sema &SemaRef);
591 void WriteMSStructPragmaOptions(Sema &SemaRef);
592 void WriteMSPointersToMembersPragmaOptions(Sema &SemaRef);
593 void WritePackPragmaOptions(Sema &SemaRef);
594 void WriteFloatControlPragmaOptions(Sema &SemaRef);
595 void WriteModuleFileExtension(Sema &SemaRef,
596 ModuleFileExtensionWriter &Writer);
597
598 unsigned DeclParmVarAbbrev = 0;
599 unsigned DeclContextLexicalAbbrev = 0;
600 unsigned DeclContextVisibleLookupAbbrev = 0;
601 unsigned UpdateVisibleAbbrev = 0;
602 unsigned DeclRecordAbbrev = 0;
603 unsigned DeclTypedefAbbrev = 0;
604 unsigned DeclVarAbbrev = 0;
605 unsigned DeclFieldAbbrev = 0;
606 unsigned DeclEnumAbbrev = 0;
607 unsigned DeclObjCIvarAbbrev = 0;
608 unsigned DeclCXXMethodAbbrev = 0;
609 unsigned DeclDependentNonTemplateCXXMethodAbbrev = 0;
610 unsigned DeclTemplateCXXMethodAbbrev = 0;
611 unsigned DeclMemberSpecializedCXXMethodAbbrev = 0;
612 unsigned DeclTemplateSpecializedCXXMethodAbbrev = 0;
613 unsigned DeclDependentSpecializationCXXMethodAbbrev = 0;
614 unsigned DeclTemplateTypeParmAbbrev = 0;
615 unsigned DeclUsingShadowAbbrev = 0;
616
617 unsigned DeclRefExprAbbrev = 0;
618 unsigned CharacterLiteralAbbrev = 0;
619 unsigned IntegerLiteralAbbrev = 0;
620 unsigned ExprImplicitCastAbbrev = 0;
621 unsigned BinaryOperatorAbbrev = 0;
622 unsigned CompoundAssignOperatorAbbrev = 0;
623 unsigned CallExprAbbrev = 0;
624 unsigned CXXOperatorCallExprAbbrev = 0;
625 unsigned CXXMemberCallExprAbbrev = 0;
626
627 unsigned CompoundStmtAbbrev = 0;
628
629 void WriteDeclAbbrevs();
630 void WriteDecl(ASTContext &Context, Decl *D);
631
632 ASTFileSignature WriteASTCore(Sema &SemaRef, StringRef isysroot,
633 Module *WritingModule);
634
635public:
636 /// Create a new precompiled header writer that outputs to
637 /// the given bitstream.
638 ASTWriter(llvm::BitstreamWriter &Stream, SmallVectorImpl<char> &Buffer,
639 InMemoryModuleCache &ModuleCache,
640 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
641 bool IncludeTimestamps = true, bool BuildingImplicitModule = false,
642 bool GeneratingReducedBMI = false);
643 ~ASTWriter() override;
644
646 assert(Context && "requested AST context when not writing AST");
647 return *Context;
648 }
649
650 const LangOptions &getLangOpts() const;
651
652 /// Get a timestamp for output into the AST file. The actual timestamp
653 /// of the specified file may be ignored if we have been instructed to not
654 /// include timestamps in the output file.
655 time_t getTimestampForOutput(const FileEntry *E) const;
656
657 /// Write a precompiled header for the given semantic analysis.
658 ///
659 /// \param SemaRef a reference to the semantic analysis object that processed
660 /// the AST to be written into the precompiled header.
661 ///
662 /// \param WritingModule The module that we are writing. If null, we are
663 /// writing a precompiled header.
664 ///
665 /// \param isysroot if non-empty, write a relocatable file whose headers
666 /// are relative to the given system root. If we're writing a module, its
667 /// build directory will be used in preference to this if both are available.
668 ///
669 /// \return the module signature, which eventually will be a hash of
670 /// the module but currently is merely a random 32-bit number.
671 ASTFileSignature WriteAST(Sema &SemaRef, StringRef OutputFile,
672 Module *WritingModule, StringRef isysroot,
673 bool ShouldCacheASTInMemory = false);
674
675 /// Emit a token.
676 void AddToken(const Token &Tok, RecordDataImpl &Record);
677
678 /// Emit a AlignPackInfo.
679 void AddAlignPackInfo(const Sema::AlignPackInfo &Info,
681
682 /// Emit a FileID.
684
685 /// Emit a source location.
687 LocSeq *Seq = nullptr);
688
689 /// Return the raw encodings for source locations.
692
693 /// Emit a source range.
695 LocSeq *Seq = nullptr);
696
697 /// Emit a reference to an identifier.
699
700 /// Get the unique number used to refer to the given selector.
702
703 /// Get the unique number used to refer to the given identifier.
705
706 /// Get the unique number used to refer to the given macro.
708
709 /// Determine the ID of an already-emitted macro.
711
712 uint32_t getMacroDirectivesOffset(const IdentifierInfo *Name);
713
714 /// Emit a reference to a type.
716
717 /// Force a type to be emitted and get its ID.
719
720 /// Find the first local declaration of a given local redeclarable
721 /// decl.
722 const Decl *getFirstLocalDecl(const Decl *D);
723
724 /// Is this a local declaration (that is, one that will be written to
725 /// our AST file)? This is the case for declarations that are neither imported
726 /// from another AST file nor predefined.
727 bool IsLocalDecl(const Decl *D) {
728 if (D->isFromASTFile())
729 return false;
730 auto I = DeclIDs.find(D);
731 return (I == DeclIDs.end() || I->second >= clang::NUM_PREDEF_DECL_IDS);
732 };
733
734 /// Emit a reference to a declaration.
735 void AddDeclRef(const Decl *D, RecordDataImpl &Record);
736 // Emit a reference to a declaration if the declaration was emitted.
738
739 /// Force a declaration to be emitted and get its local ID to the module file
740 /// been writing.
742
743 /// Determine the local declaration ID of an already-emitted
744 /// declaration.
745 LocalDeclID getDeclID(const Decl *D);
746
747 /// Whether or not the declaration got emitted. If not, it wouldn't be
748 /// emitted.
749 ///
750 /// This may only be called after we've done the job to write the
751 /// declarations (marked by DoneWritingDeclsAndTypes).
752 ///
753 /// A declaration may only be omitted in reduced BMI.
754 bool wasDeclEmitted(const Decl *D) const;
755
757
758 /// Add a string to the given record.
759 void AddString(StringRef Str, RecordDataImpl &Record);
760
761 /// Convert a path from this build process into one that is appropriate
762 /// for emission in the module file.
764
765 /// Add a path to the given record.
766 void AddPath(StringRef Path, RecordDataImpl &Record);
767
768 /// Emit the current record with the given path as a blob.
769 void EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record,
770 StringRef Path);
771
772 /// Add a version tuple to the given record
773 void AddVersionTuple(const VersionTuple &Version, RecordDataImpl &Record);
774
775 /// Retrieve or create a submodule ID for this module, or return 0 if
776 /// the submodule is neither local (a submodle of the currently-written module)
777 /// nor from an imported module.
778 unsigned getLocalOrImportedSubmoduleID(const Module *Mod);
779
780 /// Note that the identifier II occurs at the given offset
781 /// within the identifier table.
782 void SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset);
783
784 /// Note that the selector Sel occurs at the given offset
785 /// within the method pool/selector table.
786 void SetSelectorOffset(Selector Sel, uint32_t Offset);
787
788 /// Record an ID for the given switch-case statement.
789 unsigned RecordSwitchCaseID(SwitchCase *S);
790
791 /// Retrieve the ID for the given switch-case statement.
792 unsigned getSwitchCaseID(SwitchCase *S);
793
794 void ClearSwitchCaseIDs();
795
796 unsigned getTypeExtQualAbbrev() const {
797 return TypeExtQualAbbrev;
798 }
799
800 unsigned getDeclParmVarAbbrev() const { return DeclParmVarAbbrev; }
801 unsigned getDeclRecordAbbrev() const { return DeclRecordAbbrev; }
802 unsigned getDeclTypedefAbbrev() const { return DeclTypedefAbbrev; }
803 unsigned getDeclVarAbbrev() const { return DeclVarAbbrev; }
804 unsigned getDeclFieldAbbrev() const { return DeclFieldAbbrev; }
805 unsigned getDeclEnumAbbrev() const { return DeclEnumAbbrev; }
806 unsigned getDeclObjCIvarAbbrev() const { return DeclObjCIvarAbbrev; }
808 switch (Kind) {
810 return DeclCXXMethodAbbrev;
812 return DeclTemplateCXXMethodAbbrev;
814 return DeclMemberSpecializedCXXMethodAbbrev;
816 return DeclTemplateSpecializedCXXMethodAbbrev;
818 return DeclDependentNonTemplateCXXMethodAbbrev;
820 return DeclDependentSpecializationCXXMethodAbbrev;
821 }
822 llvm_unreachable("Unknwon Template Kind!");
823 }
825 return DeclTemplateTypeParmAbbrev;
826 }
827 unsigned getDeclUsingShadowAbbrev() const { return DeclUsingShadowAbbrev; }
828
829 unsigned getDeclRefExprAbbrev() const { return DeclRefExprAbbrev; }
830 unsigned getCharacterLiteralAbbrev() const { return CharacterLiteralAbbrev; }
831 unsigned getIntegerLiteralAbbrev() const { return IntegerLiteralAbbrev; }
832 unsigned getExprImplicitCastAbbrev() const { return ExprImplicitCastAbbrev; }
833 unsigned getBinaryOperatorAbbrev() const { return BinaryOperatorAbbrev; }
835 return CompoundAssignOperatorAbbrev;
836 }
837 unsigned getCallExprAbbrev() const { return CallExprAbbrev; }
838 unsigned getCXXOperatorCallExprAbbrev() { return CXXOperatorCallExprAbbrev; }
839 unsigned getCXXMemberCallExprAbbrev() { return CXXMemberCallExprAbbrev; }
840
841 unsigned getCompoundStmtAbbrev() const { return CompoundStmtAbbrev; }
842
843 bool hasChain() const { return Chain; }
844 ASTReader *getChain() const { return Chain; }
845
846 bool isWritingModule() const { return WritingModule; }
847
849 return WritingModule && WritingModule->isNamedModule();
850 }
851
852 bool isGeneratingReducedBMI() const { return GeneratingReducedBMI; }
853
854 bool getDoneWritingDeclsAndTypes() const { return DoneWritingDeclsAndTypes; }
855
856 bool isDeclPredefined(const Decl *D) const {
857 return PredefinedDecls.count(D);
858 }
859
860private:
861 // ASTDeserializationListener implementation
862 void ReaderInitialized(ASTReader *Reader) override;
863 void IdentifierRead(serialization::IdentifierID ID, IdentifierInfo *II) override;
864 void MacroRead(serialization::MacroID ID, MacroInfo *MI) override;
865 void TypeRead(serialization::TypeIdx Idx, QualType T) override;
866 void SelectorRead(serialization::SelectorID ID, Selector Sel) override;
867 void MacroDefinitionRead(serialization::PreprocessedEntityID ID,
868 MacroDefinitionRecord *MD) override;
869 void ModuleRead(serialization::SubmoduleID ID, Module *Mod) override;
870
871 // ASTMutationListener implementation.
872 void CompletedTagDefinition(const TagDecl *D) override;
873 void AddedVisibleDecl(const DeclContext *DC, const Decl *D) override;
874 void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) override;
875 void AddedCXXTemplateSpecialization(
876 const ClassTemplateDecl *TD,
877 const ClassTemplateSpecializationDecl *D) override;
878 void AddedCXXTemplateSpecialization(
879 const VarTemplateDecl *TD,
880 const VarTemplateSpecializationDecl *D) override;
881 void AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD,
882 const FunctionDecl *D) override;
883 void ResolvedExceptionSpec(const FunctionDecl *FD) override;
884 void DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) override;
885 void ResolvedOperatorDelete(const CXXDestructorDecl *DD,
886 const FunctionDecl *Delete,
887 Expr *ThisArg) override;
888 void CompletedImplicitDefinition(const FunctionDecl *D) override;
889 void InstantiationRequested(const ValueDecl *D) override;
890 void VariableDefinitionInstantiated(const VarDecl *D) override;
891 void FunctionDefinitionInstantiated(const FunctionDecl *D) override;
892 void DefaultArgumentInstantiated(const ParmVarDecl *D) override;
893 void DefaultMemberInitializerInstantiated(const FieldDecl *D) override;
894 void AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD,
895 const ObjCInterfaceDecl *IFD) override;
896 void DeclarationMarkedUsed(const Decl *D) override;
897 void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) override;
898 void DeclarationMarkedOpenMPDeclareTarget(const Decl *D,
899 const Attr *Attr) override;
900 void DeclarationMarkedOpenMPAllocate(const Decl *D, const Attr *A) override;
901 void RedefinedHiddenDefinition(const NamedDecl *D, Module *M) override;
902 void AddedAttributeToRecord(const Attr *Attr,
903 const RecordDecl *Record) override;
904 void EnteringModulePurview() override;
905 void AddedManglingNumber(const Decl *D, unsigned) override;
906 void AddedStaticLocalNumbers(const Decl *D, unsigned) override;
907 void AddedAnonymousNamespace(const TranslationUnitDecl *,
908 NamespaceDecl *AnonNamespace) override;
909};
910
911/// AST and semantic-analysis consumer that generates a
912/// precompiled header from the parsed source code.
914 void anchor() override;
915
916 Preprocessor &PP;
917 std::string OutputFile;
918 std::string isysroot;
919 Sema *SemaPtr;
920 std::shared_ptr<PCHBuffer> Buffer;
921 llvm::BitstreamWriter Stream;
922 ASTWriter Writer;
923 bool AllowASTWithErrors;
924 bool ShouldCacheASTInMemory;
925
926protected:
927 ASTWriter &getWriter() { return Writer; }
928 const ASTWriter &getWriter() const { return Writer; }
929 SmallVectorImpl<char> &getPCH() const { return Buffer->Data; }
930
931 bool isComplete() const { return Buffer->IsComplete; }
932 PCHBuffer *getBufferPtr() { return Buffer.get(); }
933 StringRef getOutputFile() const { return OutputFile; }
935 return SemaPtr->getDiagnostics();
936 }
938
939 virtual Module *getEmittingModule(ASTContext &Ctx);
940
941public:
943 StringRef OutputFile, StringRef isysroot,
944 std::shared_ptr<PCHBuffer> Buffer,
945 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
946 bool AllowASTWithErrors = false, bool IncludeTimestamps = true,
947 bool BuildingImplicitModule = false,
948 bool ShouldCacheASTInMemory = false,
949 bool GeneratingReducedBMI = false);
950 ~PCHGenerator() override;
951
952 void InitializeSema(Sema &S) override { SemaPtr = &S; }
953 void HandleTranslationUnit(ASTContext &Ctx) override;
956 bool hasEmittedPCH() const { return Buffer->IsComplete; }
957};
958
960 void anchor() override;
961
962protected:
963 virtual Module *getEmittingModule(ASTContext &Ctx) override;
964
966 StringRef OutputFile, bool GeneratingReducedBMI);
967
968public:
970 StringRef OutputFile)
971 : CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
972 /*GeneratingReducedBMI=*/false) {}
973
974 void HandleTranslationUnit(ASTContext &Ctx) override;
975};
976
978 void anchor() override;
979
980public:
982 StringRef OutputFile)
983 : CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
984 /*GeneratingReducedBMI=*/true) {}
985};
986
987/// If we can elide the definition of \param D in reduced BMI.
988///
989/// Generally, we can elide the definition of a declaration if it won't affect
990/// the ABI. e.g., the non-inline function bodies.
991bool CanElideDeclDef(const Decl *D);
992
993/// A simple helper class to pack several bits in order into (a) 32 bit
994/// integer(s).
996 constexpr static uint32_t BitIndexUpbound = 32u;
997
998public:
999 BitsPacker() = default;
1000 BitsPacker(const BitsPacker &) = delete;
1004 ~BitsPacker() = default;
1005
1006 bool canWriteNextNBits(uint32_t BitsWidth) const {
1007 return CurrentBitIndex + BitsWidth < BitIndexUpbound;
1008 }
1009
1010 void reset(uint32_t Value) {
1011 UnderlyingValue = Value;
1012 CurrentBitIndex = 0;
1013 }
1014
1015 void addBit(bool Value) { addBits(Value, 1); }
1016 void addBits(uint32_t Value, uint32_t BitsWidth) {
1017 assert(BitsWidth < BitIndexUpbound);
1018 assert((Value < (1u << BitsWidth)) && "Passing narrower bit width!");
1019 assert(canWriteNextNBits(BitsWidth) &&
1020 "Inserting too much bits into a value!");
1021
1022 UnderlyingValue |= Value << CurrentBitIndex;
1023 CurrentBitIndex += BitsWidth;
1024 }
1025
1026 operator uint32_t() { return UnderlyingValue; }
1027
1028private:
1029 uint32_t UnderlyingValue = 0;
1030 uint32_t CurrentBitIndex = 0;
1031};
1032
1033} // namespace clang
1034
1035#endif // LLVM_CLANG_SERIALIZATION_ASTWRITER_H
MatchType Type
static char ID
Definition: Arena.cpp:183
const Decl * D
IndirectLocalPath & Path
enum clang::sema::@1646::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:757
SourceLocation Loc
Definition: SemaObjC.cpp:758
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:186
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:366
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:6037
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:4854
unsigned getDeclParmVarAbbrev() const
Definition: ASTWriter.h:800
void AddEmittedDeclRef(const Decl *D, RecordDataImpl &Record)
Definition: ASTWriter.cpp:6187
void AddSourceRange(SourceRange Range, RecordDataImpl &Record, LocSeq *Seq=nullptr)
Emit a source range.
Definition: ASTWriter.cpp:5997
unsigned getBinaryOperatorAbbrev() const
Definition: ASTWriter.h:833
unsigned getDeclTemplateTypeParmAbbrev() const
Definition: ASTWriter.h:824
bool isWritingStdCXXNamedModules() const
Definition: ASTWriter.h:848
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:4778
void AddFileID(FileID FID, RecordDataImpl &Record)
Emit a FileID.
Definition: ASTWriter.cpp:5963
unsigned getDeclObjCIvarAbbrev() const
Definition: ASTWriter.h:806
unsigned getExprImplicitCastAbbrev() const
Definition: ASTWriter.h:832
bool isDeclPredefined(const Decl *D) const
Definition: ASTWriter.h:856
unsigned getDeclTypedefAbbrev() const
Definition: ASTWriter.h:802
bool hasChain() const
Definition: ASTWriter.h:843
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:4772
SmallVectorImpl< uint64_t > RecordDataImpl
Definition: ASTWriter.h:95
unsigned getDeclUsingShadowAbbrev() const
Definition: ASTWriter.h:827
unsigned getTypeExtQualAbbrev() const
Definition: ASTWriter.h:796
void AddVersionTuple(const VersionTuple &Version, RecordDataImpl &Record)
Add a version tuple to the given record.
Definition: ASTWriter.cpp:4785
bool isGeneratingReducedBMI() const
Definition: ASTWriter.h:852
uint32_t getMacroDirectivesOffset(const IdentifierInfo *Name)
Definition: ASTWriter.cpp:6045
unsigned getDeclVarAbbrev() const
Definition: ASTWriter.h:803
unsigned getDeclEnumAbbrev() const
Definition: ASTWriter.h:805
void AddAlignPackInfo(const Sema::AlignPackInfo &Info, RecordDataImpl &Record)
Emit a AlignPackInfo.
Definition: ASTWriter.cpp:5895
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:727
unsigned getDeclRefExprAbbrev() const
Definition: ASTWriter.h:829
unsigned getCXXOperatorCallExprAbbrev()
Definition: ASTWriter.h:838
bool wasDeclEmitted(const Decl *D) const
Whether or not the declaration got emitted.
Definition: ASTWriter.cpp:6252
void AddString(StringRef Str, RecordDataImpl &Record)
Add a string to the given record.
Definition: ASTWriter.cpp:4744
time_t getTimestampForOutput(const FileEntry *E) const
Get a timestamp for output into the AST file.
Definition: ASTWriter.cpp:4850
~ASTWriter() override
bool isWritingModule() const
Definition: ASTWriter.h:846
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:6198
LocalDeclID getDeclID(const Decl *D)
Determine the local declaration ID of an already-emitted declaration.
Definition: ASTWriter.cpp:6239
void AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record)
Emit a reference to an identifier.
Definition: ASTWriter.cpp:6007
serialization::TypeID GetOrCreateTypeID(QualType T)
Force a type to be emitted and get its ID.
Definition: ASTWriter.cpp:6164
serialization::MacroID getMacroRef(MacroInfo *MI, const IdentifierInfo *Name)
Get the unique number used to refer to the given macro.
Definition: ASTWriter.cpp:6021
void AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record, LocSeq *Seq=nullptr)
Emit a source location.
Definition: ASTWriter.cpp:5991
void AddTypeRef(QualType T, RecordDataImpl &Record)
Emit a reference to a type.
Definition: ASTWriter.cpp:6135
ASTContext & getASTContext() const
Definition: ASTWriter.h:645
unsigned getCXXMemberCallExprAbbrev()
Definition: ASTWriter.h:839
ASTReader * getChain() const
Definition: ASTWriter.h:844
unsigned getCompoundAssignOperatorAbbrev() const
Definition: ASTWriter.h:834
bool getDoneWritingDeclsAndTypes() const
Definition: ASTWriter.h:854
serialization::IdentifierID getIdentifierRef(const IdentifierInfo *II)
Get the unique number used to refer to the given identifier.
Definition: ASTWriter.cpp:6011
unsigned RecordSwitchCaseID(SwitchCase *S)
Record an ID for the given switch-case statement.
unsigned getCharacterLiteralAbbrev() const
Definition: ASTWriter.h:830
unsigned getDeclCXXMethodAbbrev(FunctionDecl::TemplatedKind Kind) const
Definition: ASTWriter.h:807
unsigned getCompoundStmtAbbrev() const
Definition: ASTWriter.h:841
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:2859
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:4699
serialization::SelectorID getSelectorRef(Selector Sel)
Get the unique number used to refer to the given selector.
Definition: ASTWriter.cpp:6053
SourceLocationEncoding::RawLocEncoding getRawSourceLocationEncoding(SourceLocation Loc, LocSeq *Seq=nullptr)
Return the raw encodings for source locations.
Definition: ASTWriter.cpp:5968
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:4827
SmallVector< uint64_t, 64 > RecordData
Definition: ASTWriter.h:94
unsigned getAnonymousDeclarationNumber(const NamedDecl *D)
Definition: ASTWriter.cpp:6306
unsigned getDeclFieldAbbrev() const
Definition: ASTWriter.h:804
const LangOptions & getLangOpts() const
Definition: ASTWriter.cpp:4845
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:4817
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:4749
unsigned getCallExprAbbrev() const
Definition: ASTWriter.h:837
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:4800
unsigned getDeclRecordAbbrev() const
Definition: ASTWriter.h:801
void AddDeclRef(const Decl *D, RecordDataImpl &Record)
Emit a reference to a declaration.
Definition: ASTWriter.cpp:6194
unsigned getIntegerLiteralAbbrev() const
Definition: ASTWriter.h:831
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:995
~BitsPacker()=default
void addBit(bool Value)
Definition: ASTWriter.h:1015
bool canWriteNextNBits(uint32_t BitsWidth) const
Definition: ASTWriter.h:1006
BitsPacker operator=(BitsPacker &&)=delete
BitsPacker(BitsPacker &&)=delete
BitsPacker()=default
void addBits(uint32_t Value, uint32_t BitsWidth)
Definition: ASTWriter.h:1016
void reset(uint32_t Value)
Definition: ASTWriter.h:1010
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:969
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2799
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:1425
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:3069
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:1971
TemplatedKind
The kind of templated function a FunctionDecl can be.
Definition: Decl.h:1976
@ TK_MemberSpecialization
Definition: Decl.h:1983
@ TK_DependentNonTemplate
Definition: Decl.h:1992
@ TK_FunctionTemplateSpecialization
Definition: Decl.h:1987
@ TK_DependentFunctionTemplateSpecialization
Definition: Decl.h:1990
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:2326
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:913
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:932
Preprocessor & getPreprocessor()
Definition: ASTWriter.h:937
virtual Module * getEmittingModule(ASTContext &Ctx)
Definition: GeneratePCH.cpp:44
SmallVectorImpl< char > & getPCH() const
Definition: ASTWriter.h:929
void InitializeSema(Sema &S) override
Initialize the semantic consumer with the Sema instance being used to perform semantic analysis on th...
Definition: ASTWriter.h:952
StringRef getOutputFile() const
Definition: ASTWriter.h:933
~PCHGenerator() override
Definition: GeneratePCH.cpp:41
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:928
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:956
ASTWriter & getWriter()
Definition: ASTWriter.h:927
bool isComplete() const
Definition: ASTWriter.h:931
DiagnosticsEngine & getDiagnostics() const
Definition: ASTWriter.h:934
Represents a parameter to a function.
Definition: Decl.h:1761
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:137
A (possibly-)qualified type.
Definition: Type.h:942
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:991
Represents a struct/union/class.
Definition: Decl.h:4180
ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache, StringRef OutputFile)
Definition: ASTWriter.h:981
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:535
DiagnosticsEngine & getDiagnostics() const
Definition: Sema.h:596
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:3596
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:706
Represents a variable declaration or definition.
Definition: Decl.h:918
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:1136
@ 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...
@ 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