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