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