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
79/// Writes an AST file containing the contents of a translation unit.
80///
81/// The ASTWriter class produces a bitstream containing the serialized
82/// representation of a given abstract syntax tree and its supporting
83/// data structures. This bitstream can be de-serialized via an
84/// instance of the ASTReader class.
86 public ASTMutationListener {
87public:
88 friend class ASTDeclWriter;
89 friend class ASTRecordWriter;
90
94
95private:
96 /// Map that provides the ID numbers of each type within the
97 /// output stream, plus those deserialized from a chained PCH.
98 ///
99 /// The ID numbers of types are consecutive (in order of discovery)
100 /// and start at 1. 0 is reserved for NULL. When types are actually
101 /// stored in the stream, the ID number is shifted by 2 bits to
102 /// allow for the const/volatile qualifiers.
103 ///
104 /// Keys in the map never have const/volatile qualifiers.
105 using TypeIdxMap = llvm::DenseMap<QualType, serialization::TypeIdx,
107
109
110 /// The bitstream writer used to emit this precompiled header.
111 llvm::BitstreamWriter &Stream;
112
113 /// The buffer associated with the bitstream.
114 const SmallVectorImpl<char> &Buffer;
115
116 /// The PCM manager which manages memory buffers for pcm files.
117 InMemoryModuleCache &ModuleCache;
118
119 /// The ASTContext we're writing.
120 ASTContext *Context = nullptr;
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 /// Offset of each declaration in the bitstream, indexed by
229 /// the declaration's ID.
230 std::vector<serialization::DeclOffset> DeclOffsets;
231
232 /// The offset of the DECLTYPES_BLOCK. The offsets in DeclOffsets
233 /// are relative to this value.
234 uint64_t DeclTypesBlockStartOffset = 0;
235
236 /// Sorted (by file offset) vector of pairs of file offset/LocalDeclID.
237 using LocDeclIDsTy = SmallVector<std::pair<unsigned, LocalDeclID>, 64>;
238 struct DeclIDInFileInfo {
239 LocDeclIDsTy DeclIDs;
240
241 /// Set when the DeclIDs vectors from all files are joined, this
242 /// indicates the index that this particular vector has in the global one.
243 unsigned FirstDeclIndex;
244 };
245 using FileDeclIDsTy =
246 llvm::DenseMap<FileID, std::unique_ptr<DeclIDInFileInfo>>;
247
248 /// Map from file SLocEntries to info about the file-level declarations
249 /// that it contains.
250 FileDeclIDsTy FileDeclIDs;
251
252 void associateDeclWithFile(const Decl *D, LocalDeclID);
253
254 /// The first ID number we can use for our own types.
256
257 /// The type ID that will be assigned to the next new type.
258 serialization::TypeID NextTypeID = FirstTypeID;
259
260 /// Map that provides the ID numbers of each type within the
261 /// output stream, plus those deserialized from a chained PCH.
262 ///
263 /// The ID numbers of types are consecutive (in order of discovery)
264 /// and start at 1. 0 is reserved for NULL. When types are actually
265 /// stored in the stream, the ID number is shifted by 2 bits to
266 /// allow for the const/volatile qualifiers.
267 ///
268 /// Keys in the map never have const/volatile qualifiers.
269 TypeIdxMap TypeIdxs;
270
271 /// Offset of each type in the bitstream, indexed by
272 /// the type's ID.
273 std::vector<serialization::UnderalignedInt64> TypeOffsets;
274
275 /// The first ID number we can use for our own identifiers.
277
278 /// The identifier ID that will be assigned to the next new identifier.
279 serialization::IdentID NextIdentID = FirstIdentID;
280
281 /// Map that provides the ID numbers of each identifier in
282 /// the output stream.
283 ///
284 /// The ID numbers for identifiers are consecutive (in order of
285 /// discovery), starting at 1. An ID of zero refers to a NULL
286 /// IdentifierInfo.
287 llvm::MapVector<const IdentifierInfo *, serialization::IdentID> IdentifierIDs;
288
289 /// The first ID number we can use for our own macros.
291
292 /// The identifier ID that will be assigned to the next new identifier.
293 serialization::MacroID NextMacroID = FirstMacroID;
294
295 /// Map that provides the ID numbers of each macro.
296 llvm::DenseMap<MacroInfo *, serialization::MacroID> MacroIDs;
297
298 struct MacroInfoToEmitData {
299 const IdentifierInfo *Name;
300 MacroInfo *MI;
302 };
303
304 /// The macro infos to emit.
305 std::vector<MacroInfoToEmitData> MacroInfosToEmit;
306
307 llvm::DenseMap<const IdentifierInfo *, uint32_t>
308 IdentMacroDirectivesOffsetMap;
309
310 /// @name FlushStmt Caches
311 /// @{
312
313 /// Set of parent Stmts for the currently serializing sub-stmt.
314 llvm::DenseSet<Stmt *> ParentStmts;
315
316 /// Offsets of sub-stmts already serialized. The offset points
317 /// just after the stmt record.
318 llvm::DenseMap<Stmt *, uint64_t> SubStmtEntries;
319
320 /// @}
321
322 /// Offsets of each of the identifier IDs into the identifier
323 /// table.
324 std::vector<uint32_t> IdentifierOffsets;
325
326 /// The first ID number we can use for our own submodules.
327 serialization::SubmoduleID FirstSubmoduleID =
329
330 /// The submodule ID that will be assigned to the next new submodule.
331 serialization::SubmoduleID NextSubmoduleID = FirstSubmoduleID;
332
333 /// The first ID number we can use for our own selectors.
334 serialization::SelectorID FirstSelectorID =
336
337 /// The selector ID that will be assigned to the next new selector.
338 serialization::SelectorID NextSelectorID = FirstSelectorID;
339
340 /// Map that provides the ID numbers of each Selector.
341 llvm::MapVector<Selector, serialization::SelectorID> SelectorIDs;
342
343 /// Offset of each selector within the method pool/selector
344 /// table, indexed by the Selector ID (-1).
345 std::vector<uint32_t> SelectorOffsets;
346
347 /// Mapping from macro definitions (as they occur in the preprocessing
348 /// record) to the macro IDs.
349 llvm::DenseMap<const MacroDefinitionRecord *,
350 serialization::PreprocessedEntityID> MacroDefinitions;
351
352 /// Cache of indices of anonymous declarations within their lexical
353 /// contexts.
354 llvm::DenseMap<const Decl *, unsigned> AnonymousDeclarationNumbers;
355
356 /// An update to a Decl.
357 class DeclUpdate {
358 /// A DeclUpdateKind.
359 unsigned Kind;
360 union {
361 const Decl *Dcl;
362 void *Type;
364 unsigned Val;
365 Module *Mod;
366 const Attr *Attribute;
367 };
368
369 public:
370 DeclUpdate(unsigned Kind) : Kind(Kind), Dcl(nullptr) {}
371 DeclUpdate(unsigned Kind, const Decl *Dcl) : Kind(Kind), Dcl(Dcl) {}
372 DeclUpdate(unsigned Kind, QualType Type)
373 : Kind(Kind), Type(Type.getAsOpaquePtr()) {}
374 DeclUpdate(unsigned Kind, SourceLocation Loc)
375 : Kind(Kind), Loc(Loc.getRawEncoding()) {}
376 DeclUpdate(unsigned Kind, unsigned Val) : Kind(Kind), Val(Val) {}
377 DeclUpdate(unsigned Kind, Module *M) : Kind(Kind), Mod(M) {}
378 DeclUpdate(unsigned Kind, const Attr *Attribute)
379 : Kind(Kind), Attribute(Attribute) {}
380
381 unsigned getKind() const { return Kind; }
382 const Decl *getDecl() const { return Dcl; }
383 QualType getType() const { return QualType::getFromOpaquePtr(Type); }
384
385 SourceLocation getLoc() const {
387 }
388
389 unsigned getNumber() const { return Val; }
390 Module *getModule() const { return Mod; }
391 const Attr *getAttr() const { return Attribute; }
392 };
393
394 using UpdateRecord = SmallVector<DeclUpdate, 1>;
395 using DeclUpdateMap = llvm::MapVector<const Decl *, UpdateRecord>;
396
397 /// Mapping from declarations that came from a chained PCH to the
398 /// record containing modifications to them.
399 DeclUpdateMap DeclUpdates;
400
401 /// DeclUpdates added during parsing the GMF. We split these from
402 /// DeclUpdates since we want to add these updates in GMF on need.
403 /// Only meaningful for reduced BMI.
404 DeclUpdateMap DeclUpdatesFromGMF;
405
406 using FirstLatestDeclMap = llvm::DenseMap<Decl *, Decl *>;
407
408 /// Map of first declarations from a chained PCH that point to the
409 /// most recent declarations in another PCH.
410 FirstLatestDeclMap FirstLatestDecls;
411
412 /// Declarations encountered that might be external
413 /// definitions.
414 ///
415 /// We keep track of external definitions and other 'interesting' declarations
416 /// as we are emitting declarations to the AST file. The AST file contains a
417 /// separate record for these declarations, which are provided to the AST
418 /// consumer by the AST reader. This is behavior is required to properly cope with,
419 /// e.g., tentative variable definitions that occur within
420 /// headers. The declarations themselves are stored as declaration
421 /// IDs, since they will be written out to an EAGERLY_DESERIALIZED_DECLS
422 /// record.
423 RecordData EagerlyDeserializedDecls;
424 RecordData ModularCodegenDecls;
425
426 /// DeclContexts that have received extensions since their serialized
427 /// form.
428 ///
429 /// For namespaces, when we're chaining and encountering a namespace, we check
430 /// if its primary namespace comes from the chain. If it does, we add the
431 /// primary to this set, so that we can write out lexical content updates for
432 /// it.
434
435 /// Keeps track of declarations that we must emit, even though we're
436 /// not guaranteed to be able to find them by walking the AST starting at the
437 /// translation unit.
438 SmallVector<const Decl *, 16> DeclsToEmitEvenIfUnreferenced;
439
440 /// The set of Objective-C class that have categories we
441 /// should serialize.
442 llvm::SetVector<ObjCInterfaceDecl *> ObjCClassesWithCategories;
443
444 /// The set of declarations that may have redeclaration chains that
445 /// need to be serialized.
447
448 /// A cache of the first local declaration for "interesting"
449 /// redeclaration chains.
450 llvm::DenseMap<const Decl *, const Decl *> FirstLocalDeclCache;
451
452 /// Mapping from SwitchCase statements to IDs.
453 llvm::DenseMap<SwitchCase *, unsigned> SwitchCaseIDs;
454
455 /// The number of statements written to the AST file.
456 unsigned NumStatements = 0;
457
458 /// The number of macros written to the AST file.
459 unsigned NumMacros = 0;
460
461 /// The number of lexical declcontexts written to the AST
462 /// file.
463 unsigned NumLexicalDeclContexts = 0;
464
465 /// The number of visible declcontexts written to the AST
466 /// file.
467 unsigned NumVisibleDeclContexts = 0;
468
469 /// A mapping from each known submodule to its ID number, which will
470 /// be a positive integer.
471 llvm::DenseMap<const Module *, unsigned> SubmoduleIDs;
472
473 /// A list of the module file extension writers.
474 std::vector<std::unique_ptr<ModuleFileExtensionWriter>>
475 ModuleFileExtensionWriters;
476
477 /// Mapping from a source location entry to whether it is affecting or not.
478 llvm::BitVector IsSLocAffecting;
479
480 /// Mapping from \c FileID to an index into the FileID adjustment table.
481 std::vector<FileID> NonAffectingFileIDs;
482 std::vector<unsigned> NonAffectingFileIDAdjustments;
483
484 /// Mapping from an offset to an index into the offset adjustment table.
485 std::vector<SourceRange> NonAffectingRanges;
486 std::vector<SourceLocation::UIntTy> NonAffectingOffsetAdjustments;
487
488 /// Computes input files that didn't affect compilation of the current module,
489 /// and initializes data structures necessary for leaving those files out
490 /// during \c SourceManager serialization.
491 void computeNonAffectingInputFiles();
492
493 /// Returns an adjusted \c FileID, accounting for any non-affecting input
494 /// files.
495 FileID getAdjustedFileID(FileID FID) const;
496 /// Returns an adjusted number of \c FileIDs created within the specified \c
497 /// FileID, accounting for any non-affecting input files.
498 unsigned getAdjustedNumCreatedFIDs(FileID FID) const;
499 /// Returns an adjusted \c SourceLocation, accounting for any non-affecting
500 /// input files.
501 SourceLocation getAdjustedLocation(SourceLocation Loc) const;
502 /// Returns an adjusted \c SourceRange, accounting for any non-affecting input
503 /// files.
504 SourceRange getAdjustedRange(SourceRange Range) const;
505 /// Returns an adjusted \c SourceLocation offset, accounting for any
506 /// non-affecting input files.
507 SourceLocation::UIntTy getAdjustedOffset(SourceLocation::UIntTy Offset) const;
508 /// Returns an adjustment for offset into SourceManager, accounting for any
509 /// non-affecting input files.
510 SourceLocation::UIntTy getAdjustment(SourceLocation::UIntTy Offset) const;
511
512 /// Retrieve or create a submodule ID for this module.
513 unsigned getSubmoduleID(Module *Mod);
514
515 /// Write the given subexpression to the bitstream.
516 void WriteSubStmt(Stmt *S);
517
518 void WriteBlockInfoBlock();
519 void WriteControlBlock(Preprocessor &PP, ASTContext &Context,
520 StringRef isysroot);
521
522 /// Write out the signature and diagnostic options, and return the signature.
523 void writeUnhashedControlBlock(Preprocessor &PP, ASTContext &Context);
524 ASTFileSignature backpatchSignature();
525
526 /// Calculate hash of the pcm content.
527 std::pair<ASTFileSignature, ASTFileSignature> createSignature() const;
528
529 void WriteInputFiles(SourceManager &SourceMgr, HeaderSearchOptions &HSOpts);
530 void WriteSourceManagerBlock(SourceManager &SourceMgr,
531 const Preprocessor &PP);
532 void WritePreprocessor(const Preprocessor &PP, bool IsModule);
533 void WriteHeaderSearch(const HeaderSearch &HS);
534 void WritePreprocessorDetail(PreprocessingRecord &PPRec,
535 uint64_t MacroOffsetsBase);
536 void WriteSubmodules(Module *WritingModule);
537
538 void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag,
539 bool isModule);
540
541 unsigned TypeExtQualAbbrev = 0;
542 void WriteTypeAbbrevs();
543 void WriteType(QualType T);
544
545 bool isLookupResultExternal(StoredDeclsList &Result, DeclContext *DC);
546 bool isLookupResultEntirelyExternalOrUnreachable(StoredDeclsList &Result,
547 DeclContext *DC);
548
549 void GenerateNameLookupTable(const DeclContext *DC,
550 llvm::SmallVectorImpl<char> &LookupTable);
551 uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC);
552 uint64_t WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC);
553 void WriteTypeDeclOffsets();
554 void WriteFileDeclIDsMap();
555 void WriteComments();
556 void WriteSelectors(Sema &SemaRef);
557 void WriteReferencedSelectorsPool(Sema &SemaRef);
558 void WriteIdentifierTable(Preprocessor &PP, IdentifierResolver &IdResolver,
559 bool IsModule);
560 void WriteDeclAndTypes(ASTContext &Context);
561 void PrepareWritingSpecialDecls(Sema &SemaRef);
562 void WriteSpecialDeclRecords(Sema &SemaRef);
563 void WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord);
564 void WriteDeclContextVisibleUpdate(const DeclContext *DC);
565 void WriteFPPragmaOptions(const FPOptionsOverride &Opts);
566 void WriteOpenCLExtensions(Sema &SemaRef);
567 void WriteCUDAPragmas(Sema &SemaRef);
568 void WriteObjCCategories();
569 void WriteLateParsedTemplates(Sema &SemaRef);
570 void WriteOptimizePragmaOptions(Sema &SemaRef);
571 void WriteMSStructPragmaOptions(Sema &SemaRef);
572 void WriteMSPointersToMembersPragmaOptions(Sema &SemaRef);
573 void WritePackPragmaOptions(Sema &SemaRef);
574 void WriteFloatControlPragmaOptions(Sema &SemaRef);
575 void WriteModuleFileExtension(Sema &SemaRef,
576 ModuleFileExtensionWriter &Writer);
577
578 unsigned DeclParmVarAbbrev = 0;
579 unsigned DeclContextLexicalAbbrev = 0;
580 unsigned DeclContextVisibleLookupAbbrev = 0;
581 unsigned UpdateVisibleAbbrev = 0;
582 unsigned DeclRecordAbbrev = 0;
583 unsigned DeclTypedefAbbrev = 0;
584 unsigned DeclVarAbbrev = 0;
585 unsigned DeclFieldAbbrev = 0;
586 unsigned DeclEnumAbbrev = 0;
587 unsigned DeclObjCIvarAbbrev = 0;
588 unsigned DeclCXXMethodAbbrev = 0;
589 unsigned DeclDependentNonTemplateCXXMethodAbbrev = 0;
590 unsigned DeclTemplateCXXMethodAbbrev = 0;
591 unsigned DeclMemberSpecializedCXXMethodAbbrev = 0;
592 unsigned DeclTemplateSpecializedCXXMethodAbbrev = 0;
593 unsigned DeclDependentSpecializationCXXMethodAbbrev = 0;
594 unsigned DeclTemplateTypeParmAbbrev = 0;
595 unsigned DeclUsingShadowAbbrev = 0;
596
597 unsigned DeclRefExprAbbrev = 0;
598 unsigned CharacterLiteralAbbrev = 0;
599 unsigned IntegerLiteralAbbrev = 0;
600 unsigned ExprImplicitCastAbbrev = 0;
601 unsigned BinaryOperatorAbbrev = 0;
602 unsigned CompoundAssignOperatorAbbrev = 0;
603 unsigned CallExprAbbrev = 0;
604 unsigned CXXOperatorCallExprAbbrev = 0;
605 unsigned CXXMemberCallExprAbbrev = 0;
606
607 unsigned CompoundStmtAbbrev = 0;
608
609 void WriteDeclAbbrevs();
610 void WriteDecl(ASTContext &Context, Decl *D);
611
612 ASTFileSignature WriteASTCore(Sema &SemaRef, StringRef isysroot,
613 Module *WritingModule);
614
615public:
616 /// Create a new precompiled header writer that outputs to
617 /// the given bitstream.
618 ASTWriter(llvm::BitstreamWriter &Stream, SmallVectorImpl<char> &Buffer,
619 InMemoryModuleCache &ModuleCache,
620 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
621 bool IncludeTimestamps = true, bool BuildingImplicitModule = false,
622 bool GeneratingReducedBMI = false);
623 ~ASTWriter() override;
624
626 assert(Context && "requested AST context when not writing AST");
627 return *Context;
628 }
629
630 const LangOptions &getLangOpts() const;
631
632 /// Get a timestamp for output into the AST file. The actual timestamp
633 /// of the specified file may be ignored if we have been instructed to not
634 /// include timestamps in the output file.
635 time_t getTimestampForOutput(const FileEntry *E) const;
636
637 /// Write a precompiled header for the given semantic analysis.
638 ///
639 /// \param SemaRef a reference to the semantic analysis object that processed
640 /// the AST to be written into the precompiled header.
641 ///
642 /// \param WritingModule The module that we are writing. If null, we are
643 /// writing a precompiled header.
644 ///
645 /// \param isysroot if non-empty, write a relocatable file whose headers
646 /// are relative to the given system root. If we're writing a module, its
647 /// build directory will be used in preference to this if both are available.
648 ///
649 /// \return the module signature, which eventually will be a hash of
650 /// the module but currently is merely a random 32-bit number.
651 ASTFileSignature WriteAST(Sema &SemaRef, StringRef OutputFile,
652 Module *WritingModule, StringRef isysroot,
653 bool ShouldCacheASTInMemory = false);
654
655 /// Emit a token.
656 void AddToken(const Token &Tok, RecordDataImpl &Record);
657
658 /// Emit a AlignPackInfo.
659 void AddAlignPackInfo(const Sema::AlignPackInfo &Info,
661
662 /// Emit a FileID.
664
665 /// Emit a source location.
667 LocSeq *Seq = nullptr);
668
669 /// Emit a source range.
671 LocSeq *Seq = nullptr);
672
673 /// Emit a reference to an identifier.
675
676 /// Get the unique number used to refer to the given selector.
678
679 /// Get the unique number used to refer to the given identifier.
681
682 /// Get the unique number used to refer to the given macro.
684
685 /// Determine the ID of an already-emitted macro.
687
688 uint32_t getMacroDirectivesOffset(const IdentifierInfo *Name);
689
690 /// Emit a reference to a type.
692
693 /// Force a type to be emitted and get its ID.
695
696 /// Determine the type ID of an already-emitted type.
698
699 /// Find the first local declaration of a given local redeclarable
700 /// decl.
701 const Decl *getFirstLocalDecl(const Decl *D);
702
703 /// Is this a local declaration (that is, one that will be written to
704 /// our AST file)? This is the case for declarations that are neither imported
705 /// from another AST file nor predefined.
706 bool IsLocalDecl(const Decl *D) {
707 if (D->isFromASTFile())
708 return false;
709 auto I = DeclIDs.find(D);
710 return (I == DeclIDs.end() ||
711 I->second.get() >= clang::NUM_PREDEF_DECL_IDS);
712 };
713
714 /// Emit a reference to a declaration.
715 void AddDeclRef(const Decl *D, RecordDataImpl &Record);
716 // Emit a reference to a declaration if the declaration was emitted.
718
719 /// Force a declaration to be emitted and get its local ID to the module file
720 /// been writing.
721 LocalDeclID GetDeclRef(const Decl *D);
722
723 /// Determine the local declaration ID of an already-emitted
724 /// declaration.
725 LocalDeclID getDeclID(const Decl *D);
726
727 /// Whether or not the declaration got emitted. If not, it wouldn't be
728 /// emitted.
729 ///
730 /// This may only be called after we've done the job to write the
731 /// declarations (marked by DoneWritingDeclsAndTypes).
732 ///
733 /// A declaration may only be omitted in reduced BMI.
734 bool wasDeclEmitted(const Decl *D) const;
735
736 unsigned getAnonymousDeclarationNumber(const NamedDecl *D);
737
738 /// Add a string to the given record.
739 void AddString(StringRef Str, RecordDataImpl &Record);
740
741 /// Convert a path from this build process into one that is appropriate
742 /// for emission in the module file.
744
745 /// Add a path to the given record.
746 void AddPath(StringRef Path, RecordDataImpl &Record);
747
748 /// Emit the current record with the given path as a blob.
749 void EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record,
750 StringRef Path);
751
752 /// Add a version tuple to the given record
753 void AddVersionTuple(const VersionTuple &Version, RecordDataImpl &Record);
754
755 /// Retrieve or create a submodule ID for this module, or return 0 if
756 /// the submodule is neither local (a submodle of the currently-written module)
757 /// nor from an imported module.
758 unsigned getLocalOrImportedSubmoduleID(const Module *Mod);
759
760 /// Note that the identifier II occurs at the given offset
761 /// within the identifier table.
762 void SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset);
763
764 /// Note that the selector Sel occurs at the given offset
765 /// within the method pool/selector table.
766 void SetSelectorOffset(Selector Sel, uint32_t Offset);
767
768 /// Record an ID for the given switch-case statement.
769 unsigned RecordSwitchCaseID(SwitchCase *S);
770
771 /// Retrieve the ID for the given switch-case statement.
772 unsigned getSwitchCaseID(SwitchCase *S);
773
774 void ClearSwitchCaseIDs();
775
776 unsigned getTypeExtQualAbbrev() const {
777 return TypeExtQualAbbrev;
778 }
779
780 unsigned getDeclParmVarAbbrev() const { return DeclParmVarAbbrev; }
781 unsigned getDeclRecordAbbrev() const { return DeclRecordAbbrev; }
782 unsigned getDeclTypedefAbbrev() const { return DeclTypedefAbbrev; }
783 unsigned getDeclVarAbbrev() const { return DeclVarAbbrev; }
784 unsigned getDeclFieldAbbrev() const { return DeclFieldAbbrev; }
785 unsigned getDeclEnumAbbrev() const { return DeclEnumAbbrev; }
786 unsigned getDeclObjCIvarAbbrev() const { return DeclObjCIvarAbbrev; }
788 switch (Kind) {
790 return DeclCXXMethodAbbrev;
792 return DeclTemplateCXXMethodAbbrev;
794 return DeclMemberSpecializedCXXMethodAbbrev;
796 return DeclTemplateSpecializedCXXMethodAbbrev;
798 return DeclDependentNonTemplateCXXMethodAbbrev;
800 return DeclDependentSpecializationCXXMethodAbbrev;
801 }
802 llvm_unreachable("Unknwon Template Kind!");
803 }
805 return DeclTemplateTypeParmAbbrev;
806 }
807 unsigned getDeclUsingShadowAbbrev() const { return DeclUsingShadowAbbrev; }
808
809 unsigned getDeclRefExprAbbrev() const { return DeclRefExprAbbrev; }
810 unsigned getCharacterLiteralAbbrev() const { return CharacterLiteralAbbrev; }
811 unsigned getIntegerLiteralAbbrev() const { return IntegerLiteralAbbrev; }
812 unsigned getExprImplicitCastAbbrev() const { return ExprImplicitCastAbbrev; }
813 unsigned getBinaryOperatorAbbrev() const { return BinaryOperatorAbbrev; }
815 return CompoundAssignOperatorAbbrev;
816 }
817 unsigned getCallExprAbbrev() const { return CallExprAbbrev; }
818 unsigned getCXXOperatorCallExprAbbrev() { return CXXOperatorCallExprAbbrev; }
819 unsigned getCXXMemberCallExprAbbrev() { return CXXMemberCallExprAbbrev; }
820
821 unsigned getCompoundStmtAbbrev() const { return CompoundStmtAbbrev; }
822
823 bool hasChain() const { return Chain; }
824 ASTReader *getChain() const { return Chain; }
825
827 return WritingModule && WritingModule->isNamedModule();
828 }
829
830 bool isGeneratingReducedBMI() const { return GeneratingReducedBMI; }
831
832 bool getDoneWritingDeclsAndTypes() const { return DoneWritingDeclsAndTypes; }
833
834private:
835 // ASTDeserializationListener implementation
836 void ReaderInitialized(ASTReader *Reader) override;
837 void IdentifierRead(serialization::IdentID ID, IdentifierInfo *II) override;
838 void MacroRead(serialization::MacroID ID, MacroInfo *MI) override;
839 void TypeRead(serialization::TypeIdx Idx, QualType T) override;
840 void SelectorRead(serialization::SelectorID ID, Selector Sel) override;
841 void MacroDefinitionRead(serialization::PreprocessedEntityID ID,
842 MacroDefinitionRecord *MD) override;
843 void ModuleRead(serialization::SubmoduleID ID, Module *Mod) override;
844
845 // ASTMutationListener implementation.
846 void CompletedTagDefinition(const TagDecl *D) override;
847 void AddedVisibleDecl(const DeclContext *DC, const Decl *D) override;
848 void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) override;
849 void AddedCXXTemplateSpecialization(
850 const ClassTemplateDecl *TD,
851 const ClassTemplateSpecializationDecl *D) override;
852 void AddedCXXTemplateSpecialization(
853 const VarTemplateDecl *TD,
854 const VarTemplateSpecializationDecl *D) override;
855 void AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD,
856 const FunctionDecl *D) override;
857 void ResolvedExceptionSpec(const FunctionDecl *FD) override;
858 void DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) override;
859 void ResolvedOperatorDelete(const CXXDestructorDecl *DD,
860 const FunctionDecl *Delete,
861 Expr *ThisArg) override;
862 void CompletedImplicitDefinition(const FunctionDecl *D) override;
863 void InstantiationRequested(const ValueDecl *D) override;
864 void VariableDefinitionInstantiated(const VarDecl *D) override;
865 void FunctionDefinitionInstantiated(const FunctionDecl *D) override;
866 void DefaultArgumentInstantiated(const ParmVarDecl *D) override;
867 void DefaultMemberInitializerInstantiated(const FieldDecl *D) override;
868 void AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD,
869 const ObjCInterfaceDecl *IFD) override;
870 void DeclarationMarkedUsed(const Decl *D) override;
871 void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) override;
872 void DeclarationMarkedOpenMPDeclareTarget(const Decl *D,
873 const Attr *Attr) override;
874 void DeclarationMarkedOpenMPAllocate(const Decl *D, const Attr *A) override;
875 void RedefinedHiddenDefinition(const NamedDecl *D, Module *M) override;
876 void AddedAttributeToRecord(const Attr *Attr,
877 const RecordDecl *Record) override;
878 void EnteringModulePurview() override;
879 void AddedManglingNumber(const Decl *D, unsigned) override;
880 void AddedStaticLocalNumbers(const Decl *D, unsigned) override;
881 void AddedAnonymousNamespace(const TranslationUnitDecl *,
882 NamespaceDecl *AnonNamespace) override;
883};
884
885/// AST and semantic-analysis consumer that generates a
886/// precompiled header from the parsed source code.
888 Preprocessor &PP;
889 std::string OutputFile;
890 std::string isysroot;
891 Sema *SemaPtr;
892 std::shared_ptr<PCHBuffer> Buffer;
893 llvm::BitstreamWriter Stream;
894 ASTWriter Writer;
895 bool AllowASTWithErrors;
896 bool ShouldCacheASTInMemory;
897
898protected:
899 ASTWriter &getWriter() { return Writer; }
900 const ASTWriter &getWriter() const { return Writer; }
901 SmallVectorImpl<char> &getPCH() const { return Buffer->Data; }
902
903 bool isComplete() const { return Buffer->IsComplete; }
904 PCHBuffer *getBufferPtr() { return Buffer.get(); }
905 StringRef getOutputFile() const { return OutputFile; }
907 return SemaPtr->getDiagnostics();
908 }
910
911 virtual Module *getEmittingModule(ASTContext &Ctx);
912
913public:
915 StringRef OutputFile, StringRef isysroot,
916 std::shared_ptr<PCHBuffer> Buffer,
917 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
918 bool AllowASTWithErrors = false, bool IncludeTimestamps = true,
919 bool BuildingImplicitModule = false,
920 bool ShouldCacheASTInMemory = false,
921 bool GeneratingReducedBMI = false);
922 ~PCHGenerator() override;
923
924 void InitializeSema(Sema &S) override { SemaPtr = &S; }
925 void HandleTranslationUnit(ASTContext &Ctx) override;
928 bool hasEmittedPCH() const { return Buffer->IsComplete; }
929};
930
932protected:
933 virtual Module *getEmittingModule(ASTContext &Ctx) override;
934
935public:
937 StringRef OutputFile);
938
939 void HandleTranslationUnit(ASTContext &Ctx) override;
940};
941
942/// If we can elide the definition of \param D in reduced BMI.
943///
944/// Generally, we can elide the definition of a declaration if it won't affect
945/// the ABI. e.g., the non-inline function bodies.
946bool CanElideDeclDef(const Decl *D);
947
948/// A simple helper class to pack several bits in order into (a) 32 bit
949/// integer(s).
951 constexpr static uint32_t BitIndexUpbound = 32u;
952
953public:
954 BitsPacker() = default;
955 BitsPacker(const BitsPacker &) = delete;
956 BitsPacker(BitsPacker &&) = delete;
957 BitsPacker operator=(const BitsPacker &) = delete;
959 ~BitsPacker() = default;
960
961 bool canWriteNextNBits(uint32_t BitsWidth) const {
962 return CurrentBitIndex + BitsWidth < BitIndexUpbound;
963 }
964
965 void reset(uint32_t Value) {
966 UnderlyingValue = Value;
967 CurrentBitIndex = 0;
968 }
969
970 void addBit(bool Value) { addBits(Value, 1); }
971 void addBits(uint32_t Value, uint32_t BitsWidth) {
972 assert(BitsWidth < BitIndexUpbound);
973 assert((Value < (1u << BitsWidth)) && "Passing narrower bit width!");
974 assert(canWriteNextNBits(BitsWidth) &&
975 "Inserting too much bits into a value!");
976
977 UnderlyingValue |= Value << CurrentBitIndex;
978 CurrentBitIndex += BitsWidth;
979 }
980
981 operator uint32_t() { return UnderlyingValue; }
982
983private:
984 uint32_t UnderlyingValue = 0;
985 uint32_t CurrentBitIndex = 0;
986};
987
988} // namespace clang
989
990#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.
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:86
serialization::MacroID getMacroID(MacroInfo *MI)
Determine the ID of an already-emitted macro.
Definition: ASTWriter.cpp:5838
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:4714
serialization::TypeID getTypeID(QualType T) const
Determine the type ID of an already-emitted type.
Definition: ASTWriter.cpp:5963
unsigned getDeclParmVarAbbrev() const
Definition: ASTWriter.h:780
void AddEmittedDeclRef(const Decl *D, RecordDataImpl &Record)
Definition: ASTWriter.cpp:5976
void AddSourceRange(SourceRange Range, RecordDataImpl &Record, LocSeq *Seq=nullptr)
Emit a source range.
Definition: ASTWriter.cpp:5798
unsigned getBinaryOperatorAbbrev() const
Definition: ASTWriter.h:813
unsigned getDeclTemplateTypeParmAbbrev() const
Definition: ASTWriter.h:804
bool isWritingStdCXXNamedModules() const
Definition: ASTWriter.h:826
ArrayRef< uint64_t > RecordDataRef
Definition: ASTWriter.h:93
void EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record, StringRef Path)
Emit the current record with the given path as a blob.
Definition: ASTWriter.cpp:4645
void AddFileID(FileID FID, RecordDataImpl &Record)
Emit a FileID.
Definition: ASTWriter.cpp:5788
unsigned getDeclObjCIvarAbbrev() const
Definition: ASTWriter.h:786
unsigned getExprImplicitCastAbbrev() const
Definition: ASTWriter.h:812
unsigned getDeclTypedefAbbrev() const
Definition: ASTWriter.h:782
bool hasChain() const
Definition: ASTWriter.h:823
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:4639
SmallVectorImpl< uint64_t > RecordDataImpl
Definition: ASTWriter.h:92
unsigned getDeclUsingShadowAbbrev() const
Definition: ASTWriter.h:807
unsigned getTypeExtQualAbbrev() const
Definition: ASTWriter.h:776
void AddVersionTuple(const VersionTuple &Version, RecordDataImpl &Record)
Add a version tuple to the given record.
Definition: ASTWriter.cpp:4652
bool isGeneratingReducedBMI() const
Definition: ASTWriter.h:830
uint32_t getMacroDirectivesOffset(const IdentifierInfo *Name)
Definition: ASTWriter.cpp:5846
unsigned getDeclVarAbbrev() const
Definition: ASTWriter.h:783
unsigned getDeclEnumAbbrev() const
Definition: ASTWriter.h:785
void AddAlignPackInfo(const Sema::AlignPackInfo &Info, RecordDataImpl &Record)
Emit a AlignPackInfo.
Definition: ASTWriter.cpp:5720
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:706
unsigned getDeclRefExprAbbrev() const
Definition: ASTWriter.h:809
unsigned getCXXOperatorCallExprAbbrev()
Definition: ASTWriter.h:818
bool wasDeclEmitted(const Decl *D) const
Whether or not the declaration got emitted.
Definition: ASTWriter.cpp:6037
void AddString(StringRef Str, RecordDataImpl &Record)
Add a string to the given record.
Definition: ASTWriter.cpp:4611
time_t getTimestampForOutput(const FileEntry *E) const
Get a timestamp for output into the AST file.
Definition: ASTWriter.cpp:4710
~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:5987
LocalDeclID getDeclID(const Decl *D)
Determine the local declaration ID of an already-emitted declaration.
Definition: ASTWriter.cpp:6024
void AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record)
Emit a reference to an identifier.
Definition: ASTWriter.cpp:5808
serialization::TypeID GetOrCreateTypeID(QualType T)
Force a type to be emitted and get its ID.
Definition: ASTWriter.cpp:5940
serialization::MacroID getMacroRef(MacroInfo *MI, const IdentifierInfo *Name)
Get the unique number used to refer to the given macro.
Definition: ASTWriter.cpp:5822
void AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record, LocSeq *Seq=nullptr)
Emit a source location.
Definition: ASTWriter.cpp:5792
void AddTypeRef(QualType T, RecordDataImpl &Record)
Emit a reference to a type.
Definition: ASTWriter.cpp:5936
ASTContext & getASTContext() const
Definition: ASTWriter.h:625
unsigned getCXXMemberCallExprAbbrev()
Definition: ASTWriter.h:819
ASTReader * getChain() const
Definition: ASTWriter.h:824
unsigned getCompoundAssignOperatorAbbrev() const
Definition: ASTWriter.h:814
bool getDoneWritingDeclsAndTypes() const
Definition: ASTWriter.h:832
unsigned RecordSwitchCaseID(SwitchCase *S)
Record an ID for the given switch-case statement.
unsigned getCharacterLiteralAbbrev() const
Definition: ASTWriter.h:810
unsigned getDeclCXXMethodAbbrev(FunctionDecl::TemplatedKind Kind) const
Definition: ASTWriter.h:787
unsigned getCompoundStmtAbbrev() const
Definition: ASTWriter.h:821
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:2763
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:4566
serialization::SelectorID getSelectorRef(Selector Sel)
Get the unique number used to refer to the given selector.
Definition: ASTWriter.cpp:5854
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:4687
SmallVector< uint64_t, 64 > RecordData
Definition: ASTWriter.h:91
unsigned getAnonymousDeclarationNumber(const NamedDecl *D)
Definition: ASTWriter.cpp:6090
unsigned getDeclFieldAbbrev() const
Definition: ASTWriter.h:784
serialization::IdentID getIdentifierRef(const IdentifierInfo *II)
Get the unique number used to refer to the given identifier.
Definition: ASTWriter.cpp:5812
const LangOptions & getLangOpts() const
Definition: ASTWriter.cpp:4705
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:4677
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:4616
unsigned getCallExprAbbrev() const
Definition: ASTWriter.h:817
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:4667
unsigned getDeclRecordAbbrev() const
Definition: ASTWriter.h:781
void AddDeclRef(const Decl *D, RecordDataImpl &Record)
Emit a reference to a declaration.
Definition: ASTWriter.cpp:5983
unsigned getIntegerLiteralAbbrev() const
Definition: ASTWriter.h:811
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:950
~BitsPacker()=default
void addBit(bool Value)
Definition: ASTWriter.h:970
bool canWriteNextNBits(uint32_t BitsWidth) const
Definition: ASTWriter.h:961
BitsPacker operator=(BitsPacker &&)=delete
BitsPacker(BitsPacker &&)=delete
BitsPacker()=default
void addBits(uint32_t Value, uint32_t BitsWidth)
Definition: ASTWriter.h:971
void reset(uint32_t Value)
Definition: ASTWriter.h:965
BitsPacker(const BitsPacker &)=delete
BitsPacker operator=(const BitsPacker &)=delete
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:3058
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: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: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:887
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:904
Preprocessor & getPreprocessor()
Definition: ASTWriter.h:909
virtual Module * getEmittingModule(ASTContext &Ctx)
Definition: GeneratePCH.cpp:44
SmallVectorImpl< char > & getPCH() const
Definition: ASTWriter.h:901
void InitializeSema(Sema &S) override
Initialize the semantic consumer with the Sema instance being used to perform semantic analysis on th...
Definition: ASTWriter.h:924
StringRef getOutputFile() const
Definition: ASTWriter.h:905
~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:900
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:928
ASTWriter & getWriter()
Definition: ASTWriter.h:899
bool isComplete() const
Definition: ASTWriter.h:903
DiagnosticsEngine & getDiagnostics() const
Definition: ASTWriter.h:906
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:4169
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
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:457
DiagnosticsEngine & getDiagnostics() const
Definition: Sema.h:524
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:3585
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:80
const unsigned NUM_PREDEF_TYPE_IDS
The number of predefined type IDs that are reserved for the PREDEF_TYPE_* constants.
Definition: ASTBitCodes.h:1103
@ 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:77
const unsigned int NUM_PREDEF_IDENT_IDS
The number of predefined identifier IDs.
Definition: ASTBitCodes.h:129
uint32_t SubmoduleID
An ID number that refers to a submodule in a module file.
Definition: ASTBitCodes.h:163
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
Definition: ASTBitCodes.h:145
uint32_t PreprocessedEntityID
An ID number that refers to an entity in the detailed preprocessing record.
Definition: ASTBitCodes.h:160
const unsigned int NUM_PREDEF_SUBMODULE_IDS
The number of predefined submodule IDs.
Definition: ASTBitCodes.h:166
uint32_t IdentID
An ID number that refers to an identifier in an AST file.
Definition: ASTBitCodes.h:126
const unsigned int NUM_PREDEF_SELECTOR_IDS
The number of predefined selector IDs.
Definition: ASTBitCodes.h:148
const unsigned int NUM_PREDEF_MACRO_IDS
The number of predefined macro IDs.
Definition: ASTBitCodes.h:142
uint32_t MacroID
An ID number that refers to a macro in an AST file.
Definition: ASTBitCodes.h:132
@ 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
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:106