clang  3.8.0
ASTWriter.h
Go to the documentation of this file.
1 //===--- ASTWriter.h - AST File Writer --------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the ASTWriter class, which writes an AST file
11 // containing a serialized representation of a translation unit.
12 //
13 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_SERIALIZATION_ASTWRITER_H
15 #define LLVM_CLANG_SERIALIZATION_ASTWRITER_H
16 
18 #include "clang/AST/Decl.h"
21 #include "clang/AST/TemplateBase.h"
25 #include "llvm/ADT/DenseMap.h"
26 #include "llvm/ADT/DenseSet.h"
27 #include "llvm/ADT/MapVector.h"
28 #include "llvm/ADT/SetVector.h"
29 #include "llvm/ADT/SmallPtrSet.h"
30 #include "llvm/ADT/SmallVector.h"
31 #include "llvm/Bitcode/BitstreamWriter.h"
32 #include <map>
33 #include <queue>
34 #include <vector>
35 
36 namespace llvm {
37  class APFloat;
38  class APInt;
39  class BitstreamWriter;
40 }
41 
42 namespace clang {
43 
44 class ASTContext;
45 class Attr;
46 class NestedNameSpecifier;
47 class CXXBaseSpecifier;
48 class CXXCtorInitializer;
49 class FileEntry;
50 class FPOptions;
51 class HeaderSearch;
52 class HeaderSearchOptions;
53 class IdentifierResolver;
54 class MacroDefinitionRecord;
55 class MacroDirective;
56 class MacroInfo;
57 class OpaqueValueExpr;
58 class OpenCLOptions;
59 class ASTReader;
60 class Module;
61 class ModuleFileExtension;
62 class ModuleFileExtensionWriter;
63 class PreprocessedEntity;
64 class PreprocessingRecord;
65 class Preprocessor;
66 class RecordDecl;
67 class Sema;
68 class SourceManager;
69 struct StoredDeclsList;
70 class SwitchCase;
71 class TargetInfo;
72 class Token;
73 class VersionTuple;
74 class ASTUnresolvedSet;
75 
76 namespace SrcMgr { class SLocEntry; }
77 
78 /// \brief Writes an AST file containing the contents of a translation unit.
79 ///
80 /// The ASTWriter class produces a bitstream containing the serialized
81 /// representation of a given abstract syntax tree and its supporting
82 /// data structures. This bitstream can be de-serialized via an
83 /// instance of the ASTReader class.
85  public ASTMutationListener {
86 public:
90 
91  friend class ASTDeclWriter;
92  friend class ASTStmtWriter;
93 private:
94  /// \brief Map that provides the ID numbers of each type within the
95  /// output stream, plus those deserialized from a chained PCH.
96  ///
97  /// The ID numbers of types are consecutive (in order of discovery)
98  /// and start at 1. 0 is reserved for NULL. When types are actually
99  /// stored in the stream, the ID number is shifted by 2 bits to
100  /// allow for the const/volatile qualifiers.
101  ///
102  /// Keys in the map never have const/volatile qualifiers.
103  typedef llvm::DenseMap<QualType, serialization::TypeIdx,
105  TypeIdxMap;
106 
107  /// \brief The bitstream writer used to emit this precompiled header.
108  llvm::BitstreamWriter &Stream;
109 
110  /// \brief The ASTContext we're writing.
112 
113  /// \brief The preprocessor we're writing.
114  Preprocessor *PP;
115 
116  /// \brief The reader of existing AST files, if we're chaining.
117  ASTReader *Chain;
118 
119  /// \brief The module we're currently writing, if any.
120  Module *WritingModule;
121 
122  /// \brief The base directory for any relative paths we emit.
123  std::string BaseDirectory;
124 
125  /// \brief Indicates whether timestamps should be written to the produced
126  /// module file. This is the case for files implicitly written to the
127  /// module cache, where we need the timestamps to determine if the module
128  /// file is up to date, but not otherwise.
129  bool IncludeTimestamps;
130 
131  /// \brief Indicates when the AST writing is actively performing
132  /// serialization, rather than just queueing updates.
133  bool WritingAST;
134 
135  /// \brief Indicates that we are done serializing the collection of decls
136  /// and types to emit.
137  bool DoneWritingDeclsAndTypes;
138 
139  /// \brief Indicates that the AST contained compiler errors.
140  bool ASTHasCompilerErrors;
141 
142  /// \brief Mapping from input file entries to the index into the
143  /// offset table where information about that input file is stored.
144  llvm::DenseMap<const FileEntry *, uint32_t> InputFileIDs;
145 
146  /// \brief Stores a declaration or a type to be written to the AST file.
147  class DeclOrType {
148  public:
149  DeclOrType(Decl *D) : Stored(D), IsType(false) { }
150  DeclOrType(QualType T) : Stored(T.getAsOpaquePtr()), IsType(true) { }
151 
152  bool isType() const { return IsType; }
153  bool isDecl() const { return !IsType; }
154 
155  QualType getType() const {
156  assert(isType() && "Not a type!");
157  return QualType::getFromOpaquePtr(Stored);
158  }
159 
160  Decl *getDecl() const {
161  assert(isDecl() && "Not a decl!");
162  return static_cast<Decl *>(Stored);
163  }
164 
165  private:
166  void *Stored;
167  bool IsType;
168  };
169 
170  /// \brief The declarations and types to emit.
171  std::queue<DeclOrType> DeclTypesToEmit;
172 
173  /// \brief The first ID number we can use for our own declarations.
174  serialization::DeclID FirstDeclID;
175 
176  /// \brief The decl ID that will be assigned to the next new decl.
177  serialization::DeclID NextDeclID;
178 
179  /// \brief Map that provides the ID numbers of each declaration within
180  /// the output stream, as well as those deserialized from a chained PCH.
181  ///
182  /// The ID numbers of declarations are consecutive (in order of
183  /// discovery) and start at 2. 1 is reserved for the translation
184  /// unit, while 0 is reserved for NULL.
185  llvm::DenseMap<const Decl *, serialization::DeclID> DeclIDs;
186 
187  /// \brief Offset of each declaration in the bitstream, indexed by
188  /// the declaration's ID.
189  std::vector<serialization::DeclOffset> DeclOffsets;
190 
191  /// \brief Sorted (by file offset) vector of pairs of file offset/DeclID.
192  typedef SmallVector<std::pair<unsigned, serialization::DeclID>, 64>
193  LocDeclIDsTy;
194  struct DeclIDInFileInfo {
195  LocDeclIDsTy DeclIDs;
196  /// \brief Set when the DeclIDs vectors from all files are joined, this
197  /// indicates the index that this particular vector has in the global one.
198  unsigned FirstDeclIndex;
199  };
200  typedef llvm::DenseMap<FileID, DeclIDInFileInfo *> FileDeclIDsTy;
201 
202  /// \brief Map from file SLocEntries to info about the file-level declarations
203  /// that it contains.
204  FileDeclIDsTy FileDeclIDs;
205 
206  void associateDeclWithFile(const Decl *D, serialization::DeclID);
207 
208  /// \brief The first ID number we can use for our own types.
209  serialization::TypeID FirstTypeID;
210 
211  /// \brief The type ID that will be assigned to the next new type.
212  serialization::TypeID NextTypeID;
213 
214  /// \brief Map that provides the ID numbers of each type within the
215  /// output stream, plus those deserialized from a chained PCH.
216  ///
217  /// The ID numbers of types are consecutive (in order of discovery)
218  /// and start at 1. 0 is reserved for NULL. When types are actually
219  /// stored in the stream, the ID number is shifted by 2 bits to
220  /// allow for the const/volatile qualifiers.
221  ///
222  /// Keys in the map never have const/volatile qualifiers.
223  TypeIdxMap TypeIdxs;
224 
225  /// \brief Offset of each type in the bitstream, indexed by
226  /// the type's ID.
227  std::vector<uint32_t> TypeOffsets;
228 
229  /// \brief The first ID number we can use for our own identifiers.
230  serialization::IdentID FirstIdentID;
231 
232  /// \brief The identifier ID that will be assigned to the next new identifier.
233  serialization::IdentID NextIdentID;
234 
235  /// \brief Map that provides the ID numbers of each identifier in
236  /// the output stream.
237  ///
238  /// The ID numbers for identifiers are consecutive (in order of
239  /// discovery), starting at 1. An ID of zero refers to a NULL
240  /// IdentifierInfo.
241  llvm::MapVector<const IdentifierInfo *, serialization::IdentID> IdentifierIDs;
242 
243  /// \brief The first ID number we can use for our own macros.
244  serialization::MacroID FirstMacroID;
245 
246  /// \brief The identifier ID that will be assigned to the next new identifier.
247  serialization::MacroID NextMacroID;
248 
249  /// \brief Map that provides the ID numbers of each macro.
250  llvm::DenseMap<MacroInfo *, serialization::MacroID> MacroIDs;
251 
252  struct MacroInfoToEmitData {
253  const IdentifierInfo *Name;
254  MacroInfo *MI;
256  };
257  /// \brief The macro infos to emit.
258  std::vector<MacroInfoToEmitData> MacroInfosToEmit;
259 
260  llvm::DenseMap<const IdentifierInfo *, uint64_t> IdentMacroDirectivesOffsetMap;
261 
262  /// @name FlushStmt Caches
263  /// @{
264 
265  /// \brief Set of parent Stmts for the currently serializing sub-stmt.
266  llvm::DenseSet<Stmt *> ParentStmts;
267 
268  /// \brief Offsets of sub-stmts already serialized. The offset points
269  /// just after the stmt record.
270  llvm::DenseMap<Stmt *, uint64_t> SubStmtEntries;
271 
272  /// @}
273 
274  /// \brief Offsets of each of the identifier IDs into the identifier
275  /// table.
276  std::vector<uint32_t> IdentifierOffsets;
277 
278  /// \brief The first ID number we can use for our own submodules.
279  serialization::SubmoduleID FirstSubmoduleID;
280 
281  /// \brief The submodule ID that will be assigned to the next new submodule.
282  serialization::SubmoduleID NextSubmoduleID;
283 
284  /// \brief The first ID number we can use for our own selectors.
285  serialization::SelectorID FirstSelectorID;
286 
287  /// \brief The selector ID that will be assigned to the next new selector.
288  serialization::SelectorID NextSelectorID;
289 
290  /// \brief Map that provides the ID numbers of each Selector.
291  llvm::MapVector<Selector, serialization::SelectorID> SelectorIDs;
292 
293  /// \brief Offset of each selector within the method pool/selector
294  /// table, indexed by the Selector ID (-1).
295  std::vector<uint32_t> SelectorOffsets;
296 
297  /// \brief Mapping from macro definitions (as they occur in the preprocessing
298  /// record) to the macro IDs.
299  llvm::DenseMap<const MacroDefinitionRecord *,
300  serialization::PreprocessedEntityID> MacroDefinitions;
301 
302  /// \brief Cache of indices of anonymous declarations within their lexical
303  /// contexts.
304  llvm::DenseMap<const Decl *, unsigned> AnonymousDeclarationNumbers;
305 
306  /// An update to a Decl.
307  class DeclUpdate {
308  /// A DeclUpdateKind.
309  unsigned Kind;
310  union {
311  const Decl *Dcl;
312  void *Type;
313  unsigned Loc;
314  unsigned Val;
315  Module *Mod;
316  const Attr *Attribute;
317  };
318 
319  public:
320  DeclUpdate(unsigned Kind) : Kind(Kind), Dcl(nullptr) {}
321  DeclUpdate(unsigned Kind, const Decl *Dcl) : Kind(Kind), Dcl(Dcl) {}
322  DeclUpdate(unsigned Kind, QualType Type)
323  : Kind(Kind), Type(Type.getAsOpaquePtr()) {}
324  DeclUpdate(unsigned Kind, SourceLocation Loc)
325  : Kind(Kind), Loc(Loc.getRawEncoding()) {}
326  DeclUpdate(unsigned Kind, unsigned Val)
327  : Kind(Kind), Val(Val) {}
328  DeclUpdate(unsigned Kind, Module *M)
329  : Kind(Kind), Mod(M) {}
330  DeclUpdate(unsigned Kind, const Attr *Attribute)
331  : Kind(Kind), Attribute(Attribute) {}
332 
333  unsigned getKind() const { return Kind; }
334  const Decl *getDecl() const { return Dcl; }
335  QualType getType() const { return QualType::getFromOpaquePtr(Type); }
336  SourceLocation getLoc() const {
338  }
339  unsigned getNumber() const { return Val; }
340  Module *getModule() const { return Mod; }
341  const Attr *getAttr() const { return Attribute; }
342  };
343 
344  typedef SmallVector<DeclUpdate, 1> UpdateRecord;
345  typedef llvm::MapVector<const Decl *, UpdateRecord> DeclUpdateMap;
346  /// \brief Mapping from declarations that came from a chained PCH to the
347  /// record containing modifications to them.
348  DeclUpdateMap DeclUpdates;
349 
350  typedef llvm::DenseMap<Decl *, Decl *> FirstLatestDeclMap;
351  /// \brief Map of first declarations from a chained PCH that point to the
352  /// most recent declarations in another PCH.
353  FirstLatestDeclMap FirstLatestDecls;
354 
355  /// \brief Declarations encountered that might be external
356  /// definitions.
357  ///
358  /// We keep track of external definitions and other 'interesting' declarations
359  /// as we are emitting declarations to the AST file. The AST file contains a
360  /// separate record for these declarations, which are provided to the AST
361  /// consumer by the AST reader. This is behavior is required to properly cope with,
362  /// e.g., tentative variable definitions that occur within
363  /// headers. The declarations themselves are stored as declaration
364  /// IDs, since they will be written out to an EAGERLY_DESERIALIZED_DECLS
365  /// record.
366  SmallVector<uint64_t, 16> EagerlyDeserializedDecls;
367 
368  /// \brief DeclContexts that have received extensions since their serialized
369  /// form.
370  ///
371  /// For namespaces, when we're chaining and encountering a namespace, we check
372  /// if its primary namespace comes from the chain. If it does, we add the
373  /// primary to this set, so that we can write out lexical content updates for
374  /// it.
376 
377  /// \brief Keeps track of visible decls that were added in DeclContexts
378  /// coming from another AST file.
379  SmallVector<const Decl *, 16> UpdatingVisibleDecls;
380 
381  /// \brief The set of Objective-C class that have categories we
382  /// should serialize.
383  llvm::SetVector<ObjCInterfaceDecl *> ObjCClassesWithCategories;
384 
385  struct ReplacedDeclInfo {
387  uint64_t Offset;
388  unsigned Loc;
389 
390  ReplacedDeclInfo() : ID(0), Offset(0), Loc(0) {}
391  ReplacedDeclInfo(serialization::DeclID ID, uint64_t Offset,
392  SourceLocation Loc)
393  : ID(ID), Offset(Offset), Loc(Loc.getRawEncoding()) {}
394  };
395 
396  /// \brief Decls that have been replaced in the current dependent AST file.
397  ///
398  /// When a decl changes fundamentally after being deserialized (this shouldn't
399  /// happen, but the ObjC AST nodes are designed this way), it will be
400  /// serialized again. In this case, it is registered here, so that the reader
401  /// knows to read the updated version.
402  SmallVector<ReplacedDeclInfo, 16> ReplacedDecls;
403 
404  /// \brief The set of declarations that may have redeclaration chains that
405  /// need to be serialized.
407 
408  /// \brief A cache of the first local declaration for "interesting"
409  /// redeclaration chains.
410  llvm::DenseMap<const Decl *, const Decl *> FirstLocalDeclCache;
411 
412  /// \brief Statements that we've encountered while serializing a
413  /// declaration or type.
414  SmallVector<Stmt *, 16> StmtsToEmit;
415 
416  /// \brief Statements collection to use for ASTWriter::AddStmt().
417  /// It will point to StmtsToEmit unless it is overriden.
418  SmallVector<Stmt *, 16> *CollectedStmts;
419 
420  /// \brief Mapping from SwitchCase statements to IDs.
421  llvm::DenseMap<SwitchCase *, unsigned> SwitchCaseIDs;
422 
423  /// \brief The number of statements written to the AST file.
424  unsigned NumStatements;
425 
426  /// \brief The number of macros written to the AST file.
427  unsigned NumMacros;
428 
429  /// \brief The number of lexical declcontexts written to the AST
430  /// file.
431  unsigned NumLexicalDeclContexts;
432 
433  /// \brief The number of visible declcontexts written to the AST
434  /// file.
435  unsigned NumVisibleDeclContexts;
436 
437  /// \brief The offset of each CXXBaseSpecifier set within the AST.
438  SmallVector<uint32_t, 16> CXXBaseSpecifiersOffsets;
439 
440  /// \brief The first ID number we can use for our own base specifiers.
441  serialization::CXXBaseSpecifiersID FirstCXXBaseSpecifiersID;
442 
443  /// \brief The base specifiers ID that will be assigned to the next new
444  /// set of C++ base specifiers.
445  serialization::CXXBaseSpecifiersID NextCXXBaseSpecifiersID;
446 
447  /// \brief A set of C++ base specifiers that is queued to be written into the
448  /// AST file.
449  struct QueuedCXXBaseSpecifiers {
450  QueuedCXXBaseSpecifiers() : ID(), Bases(), BasesEnd() { }
451 
452  QueuedCXXBaseSpecifiers(serialization::CXXBaseSpecifiersID ID,
453  CXXBaseSpecifier const *Bases,
454  CXXBaseSpecifier const *BasesEnd)
455  : ID(ID), Bases(Bases), BasesEnd(BasesEnd) { }
456 
458  CXXBaseSpecifier const * Bases;
459  CXXBaseSpecifier const * BasesEnd;
460  };
461 
462  /// \brief Queue of C++ base specifiers to be written to the AST file,
463  /// in the order they should be written.
464  SmallVector<QueuedCXXBaseSpecifiers, 2> CXXBaseSpecifiersToWrite;
465 
466  /// \brief The offset of each CXXCtorInitializer list within the AST.
467  SmallVector<uint32_t, 16> CXXCtorInitializersOffsets;
468 
469  /// \brief The first ID number we can use for our own ctor initializers.
470  serialization::CXXCtorInitializersID FirstCXXCtorInitializersID;
471 
472  /// \brief The ctor initializers ID that will be assigned to the next new
473  /// list of C++ ctor initializers.
474  serialization::CXXCtorInitializersID NextCXXCtorInitializersID;
475 
476  /// \brief A set of C++ ctor initializers that is queued to be written
477  /// into the AST file.
478  struct QueuedCXXCtorInitializers {
479  QueuedCXXCtorInitializers() : ID() {}
480 
481  QueuedCXXCtorInitializers(serialization::CXXCtorInitializersID ID,
482  ArrayRef<CXXCtorInitializer*> Inits)
483  : ID(ID), Inits(Inits) {}
484 
486  ArrayRef<CXXCtorInitializer*> Inits;
487  };
488 
489  /// \brief Queue of C++ ctor initializers to be written to the AST file,
490  /// in the order they should be written.
491  SmallVector<QueuedCXXCtorInitializers, 2> CXXCtorInitializersToWrite;
492 
493  /// \brief A mapping from each known submodule to its ID number, which will
494  /// be a positive integer.
495  llvm::DenseMap<Module *, unsigned> SubmoduleIDs;
496 
497  /// \brief A list of the module file extension writers.
498  std::vector<std::unique_ptr<ModuleFileExtensionWriter>>
499  ModuleFileExtensionWriters;
500 
501  /// \brief Retrieve or create a submodule ID for this module.
502  unsigned getSubmoduleID(Module *Mod);
503 
504  /// \brief Write the given subexpression to the bitstream.
505  void WriteSubStmt(Stmt *S,
506  llvm::DenseMap<Stmt *, uint64_t> &SubStmtEntries,
507  llvm::DenseSet<Stmt *> &ParentStmts);
508 
509  void WriteBlockInfoBlock();
510  uint64_t WriteControlBlock(Preprocessor &PP, ASTContext &Context,
511  StringRef isysroot, const std::string &OutputFile);
512  void WriteInputFiles(SourceManager &SourceMgr, HeaderSearchOptions &HSOpts,
513  bool Modules);
514  void WriteSourceManagerBlock(SourceManager &SourceMgr,
515  const Preprocessor &PP);
516  void WritePreprocessor(const Preprocessor &PP, bool IsModule);
517  void WriteHeaderSearch(const HeaderSearch &HS);
518  void WritePreprocessorDetail(PreprocessingRecord &PPRec);
519  void WriteSubmodules(Module *WritingModule);
520 
521  void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag,
522  bool isModule);
523  void WriteCXXBaseSpecifiersOffsets();
524  void WriteCXXCtorInitializersOffsets();
525 
526  unsigned TypeExtQualAbbrev;
527  unsigned TypeFunctionProtoAbbrev;
528  void WriteTypeAbbrevs();
529  void WriteType(QualType T);
530 
531  bool isLookupResultExternal(StoredDeclsList &Result, DeclContext *DC);
532  bool isLookupResultEntirelyExternal(StoredDeclsList &Result, DeclContext *DC);
533 
534  void GenerateNameLookupTable(const DeclContext *DC,
535  llvm::SmallVectorImpl<char> &LookupTable);
536  uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC);
537  uint64_t WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC);
538  void WriteTypeDeclOffsets();
539  void WriteFileDeclIDsMap();
540  void WriteComments();
541  void WriteSelectors(Sema &SemaRef);
542  void WriteReferencedSelectorsPool(Sema &SemaRef);
543  void WriteIdentifierTable(Preprocessor &PP, IdentifierResolver &IdResolver,
544  bool IsModule);
545  void WriteAttributes(ArrayRef<const Attr*> Attrs, RecordDataImpl &Record);
546  void WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord);
547  void WriteDeclReplacementsBlock();
548  void WriteDeclContextVisibleUpdate(const DeclContext *DC);
549  void WriteFPPragmaOptions(const FPOptions &Opts);
550  void WriteOpenCLExtensions(Sema &SemaRef);
551  void WriteObjCCategories();
552  void WriteLateParsedTemplates(Sema &SemaRef);
553  void WriteOptimizePragmaOptions(Sema &SemaRef);
554  void WriteModuleFileExtension(Sema &SemaRef,
555  ModuleFileExtensionWriter &Writer);
556 
557  unsigned DeclParmVarAbbrev;
558  unsigned DeclContextLexicalAbbrev;
559  unsigned DeclContextVisibleLookupAbbrev;
560  unsigned UpdateVisibleAbbrev;
561  unsigned DeclRecordAbbrev;
562  unsigned DeclTypedefAbbrev;
563  unsigned DeclVarAbbrev;
564  unsigned DeclFieldAbbrev;
565  unsigned DeclEnumAbbrev;
566  unsigned DeclObjCIvarAbbrev;
567  unsigned DeclCXXMethodAbbrev;
568 
569  unsigned DeclRefExprAbbrev;
570  unsigned CharacterLiteralAbbrev;
571  unsigned IntegerLiteralAbbrev;
572  unsigned ExprImplicitCastAbbrev;
573 
574  void WriteDeclAbbrevs();
575  void WriteDecl(ASTContext &Context, Decl *D);
576  void AddFunctionDefinition(const FunctionDecl *FD, RecordData &Record);
577 
578  uint64_t WriteASTCore(Sema &SemaRef,
579  StringRef isysroot, const std::string &OutputFile,
580  Module *WritingModule);
581 
582 public:
583  /// \brief Create a new precompiled header writer that outputs to
584  /// the given bitstream.
585  ASTWriter(llvm::BitstreamWriter &Stream,
587  bool IncludeTimestamps = true);
588  ~ASTWriter() override;
589 
590  const LangOptions &getLangOpts() const;
591 
592  /// \brief Get a timestamp for output into the AST file. The actual timestamp
593  /// of the specified file may be ignored if we have been instructed to not
594  /// include timestamps in the output file.
595  time_t getTimestampForOutput(const FileEntry *E) const;
596 
597  /// \brief Write a precompiled header for the given semantic analysis.
598  ///
599  /// \param SemaRef a reference to the semantic analysis object that processed
600  /// the AST to be written into the precompiled header.
601  ///
602  /// \param WritingModule The module that we are writing. If null, we are
603  /// writing a precompiled header.
604  ///
605  /// \param isysroot if non-empty, write a relocatable file whose headers
606  /// are relative to the given system root. If we're writing a module, its
607  /// build directory will be used in preference to this if both are available.
608  ///
609  /// \return the module signature, which eventually will be a hash of
610  /// the module but currently is merely a random 32-bit number.
611  uint64_t WriteAST(Sema &SemaRef, const std::string &OutputFile,
612  Module *WritingModule, StringRef isysroot,
613  bool hasErrors = false);
614 
615  /// \brief Emit a token.
616  void AddToken(const Token &Tok, RecordDataImpl &Record);
617 
618  /// \brief Emit a source location.
619  void AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record);
620 
621  /// \brief Emit a source range.
622  void AddSourceRange(SourceRange Range, RecordDataImpl &Record);
623 
624  /// \brief Emit an integral value.
625  void AddAPInt(const llvm::APInt &Value, RecordDataImpl &Record);
626 
627  /// \brief Emit a signed integral value.
628  void AddAPSInt(const llvm::APSInt &Value, RecordDataImpl &Record);
629 
630  /// \brief Emit a floating-point value.
631  void AddAPFloat(const llvm::APFloat &Value, RecordDataImpl &Record);
632 
633  /// \brief Emit a reference to an identifier.
634  void AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record);
635 
636  /// \brief Emit a Selector (which is a smart pointer reference).
637  void AddSelectorRef(Selector, RecordDataImpl &Record);
638 
639  /// \brief Emit a CXXTemporary.
640  void AddCXXTemporary(const CXXTemporary *Temp, RecordDataImpl &Record);
641 
642  /// \brief Emit a set of C++ base specifiers to the record.
643  void AddCXXBaseSpecifiersRef(CXXBaseSpecifier const *Bases,
644  CXXBaseSpecifier const *BasesEnd,
645  RecordDataImpl &Record);
646 
647  /// \brief Get the unique number used to refer to the given selector.
649 
650  /// \brief Get the unique number used to refer to the given identifier.
651  serialization::IdentID getIdentifierRef(const IdentifierInfo *II);
652 
653  /// \brief Get the unique number used to refer to the given macro.
654  serialization::MacroID getMacroRef(MacroInfo *MI, const IdentifierInfo *Name);
655 
656  /// \brief Determine the ID of an already-emitted macro.
657  serialization::MacroID getMacroID(MacroInfo *MI);
658 
659  uint64_t getMacroDirectivesOffset(const IdentifierInfo *Name);
660 
661  /// \brief Emit a reference to a type.
662  void AddTypeRef(QualType T, RecordDataImpl &Record);
663 
664  /// \brief Force a type to be emitted and get its ID.
666 
667  /// \brief Determine the type ID of an already-emitted type.
668  serialization::TypeID getTypeID(QualType T) const;
669 
670  /// \brief Emits a reference to a declarator info.
671  void AddTypeSourceInfo(TypeSourceInfo *TInfo, RecordDataImpl &Record);
672 
673  /// \brief Emits a type with source-location information.
674  void AddTypeLoc(TypeLoc TL, RecordDataImpl &Record);
675 
676  /// \brief Emits a template argument location info.
678  const TemplateArgumentLocInfo &Arg,
679  RecordDataImpl &Record);
680 
681  /// \brief Emits a template argument location.
682  void AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg,
683  RecordDataImpl &Record);
684 
685  /// \brief Emits an AST template argument list info.
687  const ASTTemplateArgumentListInfo *ASTTemplArgList,
688  RecordDataImpl &Record);
689 
690  /// \brief Find the first local declaration of a given local redeclarable
691  /// decl.
692  const Decl *getFirstLocalDecl(const Decl *D);
693 
694  /// \brief Emit a reference to a declaration.
695  void AddDeclRef(const Decl *D, RecordDataImpl &Record);
696 
697 
698  /// \brief Force a declaration to be emitted and get its ID.
699  serialization::DeclID GetDeclRef(const Decl *D);
700 
701  /// \brief Determine the declaration ID of an already-emitted
702  /// declaration.
703  serialization::DeclID getDeclID(const Decl *D);
704 
705  /// \brief Emit a declaration name.
706  void AddDeclarationName(DeclarationName Name, RecordDataImpl &Record);
707  void AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc,
708  DeclarationName Name, RecordDataImpl &Record);
709  void AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
710  RecordDataImpl &Record);
711  unsigned getAnonymousDeclarationNumber(const NamedDecl *D);
712 
713  void AddQualifierInfo(const QualifierInfo &Info, RecordDataImpl &Record);
714 
715  /// \brief Emit a nested name specifier.
716  void AddNestedNameSpecifier(NestedNameSpecifier *NNS, RecordDataImpl &Record);
717 
718  /// \brief Emit a nested name specifier with source-location information.
719  void AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
720  RecordDataImpl &Record);
721 
722  /// \brief Emit a template name.
723  void AddTemplateName(TemplateName Name, RecordDataImpl &Record);
724 
725  /// \brief Emit a template argument.
726  void AddTemplateArgument(const TemplateArgument &Arg, RecordDataImpl &Record);
727 
728  /// \brief Emit a template parameter list.
729  void AddTemplateParameterList(const TemplateParameterList *TemplateParams,
730  RecordDataImpl &Record);
731 
732  /// \brief Emit a template argument list.
733  void AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs,
734  RecordDataImpl &Record);
735 
736  /// \brief Emit a UnresolvedSet structure.
737  void AddUnresolvedSet(const ASTUnresolvedSet &Set, RecordDataImpl &Record);
738 
739  /// \brief Emit a C++ base specifier.
740  void AddCXXBaseSpecifier(const CXXBaseSpecifier &Base,
741  RecordDataImpl &Record);
742 
743  /// \brief Emit the ID for a CXXCtorInitializer array and register the array
744  /// for later serialization.
745  void AddCXXCtorInitializersRef(ArrayRef<CXXCtorInitializer *> Inits,
746  RecordDataImpl &Record);
747 
748  /// \brief Emit a CXXCtorInitializer array.
750  const CXXCtorInitializer * const *CtorInitializers,
751  unsigned NumCtorInitializers,
752  RecordDataImpl &Record);
753 
754  void AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Record);
755 
756  /// \brief Add a string to the given record.
757  void AddString(StringRef Str, RecordDataImpl &Record);
758 
759  /// \brief Convert a path from this build process into one that is appropriate
760  /// for emission in the module file.
761  bool PreparePathForOutput(SmallVectorImpl<char> &Path);
762 
763  /// \brief Add a path to the given record.
764  void AddPath(StringRef Path, RecordDataImpl &Record);
765 
766  /// \brief Emit the current record with the given path as a blob.
767  void EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record,
768  StringRef Path);
769 
770  /// \brief Add a version tuple to the given record
771  void AddVersionTuple(const VersionTuple &Version, RecordDataImpl &Record);
772 
773  /// \brief Infer the submodule ID that contains an entity at the given
774  /// source location.
776 
777  /// \brief Retrieve or create a submodule ID for this module, or return 0 if
778  /// the submodule is neither local (a submodle of the currently-written module)
779  /// nor from an imported module.
780  unsigned getLocalOrImportedSubmoduleID(Module *Mod);
781 
782  /// \brief Note that the identifier II occurs at the given offset
783  /// within the identifier table.
784  void SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset);
785 
786  /// \brief Note that the selector Sel occurs at the given offset
787  /// within the method pool/selector table.
788  void SetSelectorOffset(Selector Sel, uint32_t Offset);
789 
790  /// \brief Add the given statement or expression to the queue of
791  /// statements to emit.
792  ///
793  /// This routine should be used when emitting types and declarations
794  /// that have expressions as part of their formulation. Once the
795  /// type or declaration has been written, call FlushStmts() to write
796  /// the corresponding statements just after the type or
797  /// declaration.
798  void AddStmt(Stmt *S) {
799  CollectedStmts->push_back(S);
800  }
801 
802  /// \brief Flush all of the statements and expressions that have
803  /// been added to the queue via AddStmt().
804  void FlushStmts();
805 
806  /// \brief Flush all of the C++ base specifier sets that have been added
807  /// via \c AddCXXBaseSpecifiersRef().
808  void FlushCXXBaseSpecifiers();
809 
810  /// \brief Flush all of the C++ constructor initializer lists that have been
811  /// added via \c AddCXXCtorInitializersRef().
813 
814  /// \brief Flush all pending records that are tacked onto the end of
815  /// decl and decl update records.
817  FlushStmts();
820  }
821 
822  /// \brief Record an ID for the given switch-case statement.
823  unsigned RecordSwitchCaseID(SwitchCase *S);
824 
825  /// \brief Retrieve the ID for the given switch-case statement.
826  unsigned getSwitchCaseID(SwitchCase *S);
827 
828  void ClearSwitchCaseIDs();
829 
830  unsigned getTypeExtQualAbbrev() const {
831  return TypeExtQualAbbrev;
832  }
833  unsigned getTypeFunctionProtoAbbrev() const {
834  return TypeFunctionProtoAbbrev;
835  }
836 
837  unsigned getDeclParmVarAbbrev() const { return DeclParmVarAbbrev; }
838  unsigned getDeclRecordAbbrev() const { return DeclRecordAbbrev; }
839  unsigned getDeclTypedefAbbrev() const { return DeclTypedefAbbrev; }
840  unsigned getDeclVarAbbrev() const { return DeclVarAbbrev; }
841  unsigned getDeclFieldAbbrev() const { return DeclFieldAbbrev; }
842  unsigned getDeclEnumAbbrev() const { return DeclEnumAbbrev; }
843  unsigned getDeclObjCIvarAbbrev() const { return DeclObjCIvarAbbrev; }
844  unsigned getDeclCXXMethodAbbrev() const { return DeclCXXMethodAbbrev; }
845 
846  unsigned getDeclRefExprAbbrev() const { return DeclRefExprAbbrev; }
847  unsigned getCharacterLiteralAbbrev() const { return CharacterLiteralAbbrev; }
848  unsigned getIntegerLiteralAbbrev() const { return IntegerLiteralAbbrev; }
849  unsigned getExprImplicitCastAbbrev() const { return ExprImplicitCastAbbrev; }
850 
851  bool hasChain() const { return Chain; }
852  ASTReader *getChain() const { return Chain; }
853 
854  // ASTDeserializationListener implementation
855  void ReaderInitialized(ASTReader *Reader) override;
857  void MacroRead(serialization::MacroID ID, MacroInfo *MI) override;
858  void TypeRead(serialization::TypeIdx Idx, QualType T) override;
861  MacroDefinitionRecord *MD) override;
862  void ModuleRead(serialization::SubmoduleID ID, Module *Mod) override;
863 
864  // ASTMutationListener implementation.
865  void CompletedTagDefinition(const TagDecl *D) override;
866  void AddedVisibleDecl(const DeclContext *DC, const Decl *D) override;
867  void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) override;
868  void ResolvedExceptionSpec(const FunctionDecl *FD) override;
869  void DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) override;
871  const FunctionDecl *Delete) override;
872  void CompletedImplicitDefinition(const FunctionDecl *D) override;
873  void StaticDataMemberInstantiated(const VarDecl *D) override;
874  void DefaultArgumentInstantiated(const ParmVarDecl *D) override;
875  void FunctionDefinitionInstantiated(const FunctionDecl *D) override;
877  const ObjCInterfaceDecl *IFD) override;
878  void DeclarationMarkedUsed(const Decl *D) override;
879  void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) override;
880  void RedefinedHiddenDefinition(const NamedDecl *D, Module *M) override;
881  void AddedAttributeToRecord(const Attr *Attr,
882  const RecordDecl *Record) override;
883 };
884 
885 /// \brief AST and semantic-analysis consumer that generates a
886 /// precompiled header from the parsed source code.
887 class PCHGenerator : public SemaConsumer {
888  const Preprocessor &PP;
889  std::string OutputFile;
891  std::string isysroot;
892  Sema *SemaPtr;
893  std::shared_ptr<PCHBuffer> Buffer;
894  llvm::BitstreamWriter Stream;
895  ASTWriter Writer;
896  bool AllowASTWithErrors;
897 
898 protected:
899  ASTWriter &getWriter() { return Writer; }
900  const ASTWriter &getWriter() const { return Writer; }
901  SmallVectorImpl<char> &getPCH() const { return Buffer->Data; }
902 
903 public:
904  PCHGenerator(
905  const Preprocessor &PP, StringRef OutputFile,
906  clang::Module *Module, StringRef isysroot,
907  std::shared_ptr<PCHBuffer> Buffer,
909  bool AllowASTWithErrors = false,
910  bool IncludeTimestamps = true);
911  ~PCHGenerator() override;
912  void InitializeSema(Sema &S) override { SemaPtr = &S; }
913  void HandleTranslationUnit(ASTContext &Ctx) override;
916  bool hasEmittedPCH() const { return Buffer->IsComplete; }
917 };
918 
919 } // end namespace clang
920 
921 #endif
void AddTemplateArgument(const TemplateArgument &Arg, RecordDataImpl &Record)
Emit a template argument.
Definition: ASTWriter.cpp:5302
unsigned getDeclParmVarAbbrev() const
Definition: ASTWriter.h:837
unsigned getAnonymousDeclarationNumber(const NamedDecl *D)
Definition: ASTWriter.cpp:5079
uint64_t getMacroDirectivesOffset(const IdentifierInfo *Name)
Definition: ASTWriter.cpp:4804
void AddedVisibleDecl(const DeclContext *DC, const Decl *D) override
A new declaration with name has been added to a DeclContext.
Definition: ASTWriter.cpp:5694
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1483
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.
void AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo, RecordDataImpl &Record)
Definition: ASTWriter.cpp:5133
Smart pointer class that efficiently represents Objective-C method names.
A (possibly-)qualified type.
Definition: Type.h:575
void FunctionDefinitionInstantiated(const FunctionDecl *D) override
A function template's definition was instantiated.
Definition: ASTWriter.cpp:5776
void AddToken(const Token &Tok, RecordDataImpl &Record)
Emit a token.
Definition: ASTWriter.cpp:3951
void AddAPInt(const llvm::APInt &Value, RecordDataImpl &Record)
Emit an integral value.
Definition: ASTWriter.cpp:4751
A structure for putting "fast"-unqualified QualTypes into a DenseMap.
Definition: ASTBitCodes.h:106
unsigned getTypeExtQualAbbrev() const
Definition: ASTWriter.h:830
void MacroDefinitionRead(serialization::PreprocessedEntityID ID, MacroDefinitionRecord *MD) override
A macro definition was read from the AST file.
Definition: ASTWriter.cpp:5653
uint32_t IdentID
An ID number that refers to an identifier in an AST file.
Definition: ASTBitCodes.h:123
const LangOptions & getLangOpts() const
Definition: ASTWriter.cpp:4069
void InitializeSema(Sema &S) override
Initialize the semantic consumer with the Sema instance being used to perform semantic analysis on th...
Definition: ASTWriter.h:912
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:77
void CompletedTagDefinition(const TagDecl *D) override
A new TagDecl definition was completed.
Definition: ASTWriter.cpp:5664
void ReaderInitialized(ASTReader *Reader) override
The ASTReader was initialized.
Definition: ASTWriter.cpp:5592
unsigned getDeclRefExprAbbrev() const
Definition: ASTWriter.h:846
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
Definition: ASTBitCodes.h:63
void AddTypeSourceInfo(TypeSourceInfo *TInfo, RecordDataImpl &Record)
Emits a reference to a declarator info.
Definition: ASTWriter.cpp:4897
void AddTemplateName(TemplateName Name, RecordDataImpl &Record)
Emit a template name.
Definition: ASTWriter.cpp:5249
serialization::DeclID GetDeclRef(const Decl *D)
Force a declaration to be emitted and get its ID.
Definition: ASTWriter.cpp:4959
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
void AddCXXCtorInitializersRef(ArrayRef< CXXCtorInitializer * > Inits, RecordDataImpl &Record)
Emit the ID for a CXXCtorInitializer array and register the array for later serialization.
Definition: ASTWriter.cpp:4835
void AddTypeRef(QualType T, RecordDataImpl &Record)
Emit a reference to a type.
Definition: ASTWriter.cpp:4915
serialization::MacroID getMacroRef(MacroInfo *MI, const IdentifierInfo *Name)
Get the unique number used to refer to the given macro.
Definition: ASTWriter.cpp:4780
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:699
void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) override
A declaration is marked as OpenMP threadprivate which was not previously marked as threadprivate...
Definition: ASTWriter.cpp:5824
void AddCXXTemporary(const CXXTemporary *Temp, RecordDataImpl &Record)
Emit a CXXTemporary.
Definition: ASTWriter.cpp:4831
serialization::IdentID getIdentifierRef(const IdentifierInfo *II)
Get the unique number used to refer to the given identifier.
Definition: ASTWriter.cpp:4770
ParmVarDecl - Represents a parameter to a function.
Definition: Decl.h:1299
void AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record)
Emit a reference to an identifier.
Definition: ASTWriter.cpp:4766
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3166
void AddQualifierInfo(const QualifierInfo &Info, RecordDataImpl &Record)
Definition: ASTWriter.cpp:5140
One of these records is kept for each identifier that is lexed.
unsigned getDeclVarAbbrev() const
Definition: ASTWriter.h:840
time_t getTimestampForOutput(const FileEntry *E) const
Get a timestamp for output into the AST file.
Definition: ASTWriter.cpp:4074
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4381
void AddTypeLoc(TypeLoc TL, RecordDataImpl &Record)
Emits a type with source-location information.
Definition: ASTWriter.cpp:4907
unsigned getDeclRecordAbbrev() const
Definition: ASTWriter.h:838
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:91
Record the location of a macro definition.
void RedefinedHiddenDefinition(const NamedDecl *D, Module *M) override
A definition has been made visible by being redefined locally.
Definition: ASTWriter.cpp:5832
void HandleTranslationUnit(ASTContext &Ctx) override
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
Definition: GeneratePCH.cpp:42
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
unsigned getDeclEnumAbbrev() const
Definition: ASTWriter.h:842
void ResolvedOperatorDelete(const CXXDestructorDecl *DD, const FunctionDecl *Delete) override
A virtual destructor's operator delete has been resolved.
Definition: ASTWriter.cpp:5757
~PCHGenerator() override
Definition: GeneratePCH.cpp:39
~ASTWriter() override
Definition: ASTWriter.cpp:4065
Describes a module or submodule.
Definition: Basic/Module.h:47
An abstract interface that should be implemented by clients that read ASTs and then require further s...
Definition: SemaConsumer.h:26
serialization::MacroID getMacroID(MacroInfo *MI)
Determine the ID of an already-emitted macro.
Definition: ASTWriter.cpp:4796
uint32_t SubmoduleID
An ID number that refers to a submodule in a module file.
Definition: ASTBitCodes.h:160
SmallVector< uint64_t, 64 > RecordData
Definition: ASTWriter.h:87
PCHGenerator(const Preprocessor &PP, StringRef OutputFile, clang::Module *Module, StringRef isysroot, std::shared_ptr< PCHBuffer > Buffer, ArrayRef< llvm::IntrusiveRefCntPtr< ModuleFileExtension >> Extensions, bool AllowASTWithErrors=false, bool IncludeTimestamps=true)
Definition: GeneratePCH.cpp:26
uint32_t Offset
Definition: CacheTokens.cpp:44
void IdentifierRead(serialization::IdentID ID, IdentifierInfo *II) override
An identifier was deserialized from the AST file.
Definition: ASTWriter.cpp:5621
void AddSourceRange(SourceRange Range, RecordDataImpl &Record)
Emit a source range.
Definition: ASTWriter.cpp:4746
void AddTemplateParameterList(const TemplateParameterList *TemplateParams, RecordDataImpl &Record)
Emit a template parameter list.
Definition: ASTWriter.cpp:5344
void AddSelectorRef(Selector, RecordDataImpl &Record)
Emit a Selector (which is a smart pointer reference).
Definition: ASTWriter.cpp:4808
unsigned getDeclObjCIvarAbbrev() const
Definition: ASTWriter.h:843
void AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg, RecordDataImpl &Record)
Emits a template argument location.
Definition: ASTWriter.cpp:4882
void StaticDataMemberInstantiated(const VarDecl *D) override
A static data member was implicitly instantiated.
Definition: ASTWriter.cpp:5784
Represents an ObjC class declaration.
Definition: DeclObjC.h:853
void AddDeclarationName(DeclarationName Name, RecordDataImpl &Record)
Emit a declaration name.
Definition: ASTWriter.cpp:5045
serialization::TypeID getTypeID(QualType T) const
Determine the type ID of an already-emitted type.
Definition: ASTWriter.cpp:4942
serialization::SubmoduleID inferSubmoduleIDFromLocation(SourceLocation Loc)
Infer the submodule ID that contains an entity at the given source location.
Definition: ASTWriter.cpp:2605
unsigned RecordSwitchCaseID(SwitchCase *S)
Record an ID for the given switch-case statement.
void AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, const ObjCInterfaceDecl *IFD) override
A new objc category class was added for an interface.
Definition: ASTWriter.cpp:5805
void AddedAttributeToRecord(const Attr *Attr, const RecordDecl *Record) override
An attribute was added to a RecordDecl.
Definition: ASTWriter.cpp:5838
void SelectorRead(serialization::SelectorID ID, Selector Sel) override
A selector was read from the AST file.
Definition: ASTWriter.cpp:5646
void AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, RecordDataImpl &Record)
Emit a nested name specifier with source-location information.
Definition: ASTWriter.cpp:5195
void ModuleRead(serialization::SubmoduleID ID, Module *Mod) override
A module definition was read from the AST file.
Definition: ASTWriter.cpp:5659
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:259
unsigned getCharacterLiteralAbbrev() const
Definition: ASTWriter.h:847
ASTContext * Context
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:3987
ID
Defines the set of possible language-specific address spaces.
Definition: AddressSpaces.h:27
void AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs, RecordDataImpl &Record)
Emit a template argument list.
Definition: ASTWriter.cpp:5357
void FlushCXXBaseSpecifiers()
Flush all of the C++ base specifier sets that have been added via AddCXXBaseSpecifiersRef().
Definition: ASTWriter.cpp:5400
friend class ASTContext
Definition: Type.h:4012
ASTDeserializationListener * GetASTDeserializationListener() override
If the consumer is interested in entities being deserialized from AST files, it should return a point...
Definition: GeneratePCH.cpp:63
bool hasEmittedPCH() const
Definition: ASTWriter.h:916
SourceManager & SourceMgr
Definition: Format.cpp:1352
unsigned getExprImplicitCastAbbrev() const
Definition: ASTWriter.h:849
Inits[]
Definition: OpenMPClause.h:310
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2345
ArgKind
The kind of template argument we're storing.
Definition: TemplateBase.h:43
serialization::TypeID GetOrCreateTypeID(QualType T)
Force a type to be emitted and get its ID.
Definition: ASTWriter.cpp:4919
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
FormatToken * Token
void AddString(StringRef Str, RecordDataImpl &Record)
Add a string to the given record.
Definition: ASTWriter.cpp:3964
unsigned getLocalOrImportedSubmoduleID(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:2351
void AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, RecordDataImpl &Record)
Emit a C++ base specifier.
Definition: ASTWriter.cpp:5387
void FlushPendingAfterDecl()
Flush all pending records that are tacked onto the end of decl and decl update records.
Definition: ASTWriter.h:816
unsigned getDeclFieldAbbrev() const
Definition: ASTWriter.h:841
bool hasChain() const
Definition: ASTWriter.h:851
The result type of a method or function.
void MacroRead(serialization::MacroID ID, MacroInfo *MI) override
A macro was read from the AST file.
Definition: ASTWriter.cpp:5628
SmallVectorImpl< char > & getPCH() const
Definition: ASTWriter.h:901
The l-value was considered opaque, so the alignment was determined from a type.
void AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record)
Emit a source location.
Definition: ASTWriter.cpp:4742
const Decl * getFirstLocalDecl(const Decl *D)
Find the first local declaration of a given local redeclarable decl.
#define false
Definition: stdbool.h:33
Kind
void AddAPSInt(const llvm::APSInt &Value, RecordDataImpl &Record)
Emit a signed integral value.
Definition: ASTWriter.cpp:4757
void AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, const TemplateArgumentLocInfo &Arg, RecordDataImpl &Record)
Emits a template argument location info.
Definition: ASTWriter.cpp:4853
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2644
void DefaultArgumentInstantiated(const ParmVarDecl *D) override
A default argument was instantiated.
Definition: ASTWriter.cpp:5796
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:1931
unsigned getIntegerLiteralAbbrev() const
Definition: ASTWriter.h:848
void CompletedImplicitDefinition(const FunctionDecl *D) override
An implicit member got a definition.
Definition: ASTWriter.cpp:5767
uint32_t MacroID
An ID number that refers to a macro in an AST file.
Definition: ASTBitCodes.h:129
void AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Record)
Definition: ASTWriter.cpp:5500
void AddVersionTuple(const VersionTuple &Version, RecordDataImpl &Record)
Add a version tuple to the given record.
Definition: ASTWriter.cpp:4000
void AddNestedNameSpecifier(NestedNameSpecifier *NNS, RecordDataImpl &Record)
Emit a nested name specifier.
Definition: ASTWriter.cpp:5148
void AddDeclRef(const Decl *D, RecordDataImpl &Record)
Emit a reference to a declaration.
Definition: ASTWriter.cpp:4955
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:3969
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:624
void AddCXXBaseSpecifiersRef(CXXBaseSpecifier const *Bases, CXXBaseSpecifier const *BasesEnd, RecordDataImpl &Record)
Emit a set of C++ base specifiers to the record.
Definition: ASTWriter.cpp:4843
SmallVectorImpl< uint64_t > RecordDataImpl
Definition: ASTWriter.h:88
ASTMutationListener * GetASTMutationListener() override
If the consumer is interested in entities getting modified after their initial creation, it should return a pointer to an ASTMutationListener here.
Definition: GeneratePCH.cpp:59
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:4015
void AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, DeclarationName Name, RecordDataImpl &Record)
Definition: ASTWriter.cpp:5100
void DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) override
A function's return type has been deduced.
Definition: ASTWriter.cpp:5748
const ASTWriter & getWriter() const
Definition: ASTWriter.h:900
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1121
void AddASTTemplateArgumentListInfo(const ASTTemplateArgumentListInfo *ASTTemplArgList, RecordDataImpl &Record)
Emits an AST template argument list info.
Definition: ASTWriter.cpp:5367
unsigned getDeclCXXMethodAbbrev() const
Definition: ASTWriter.h:844
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:311
void AddUnresolvedSet(const ASTUnresolvedSet &Set, RecordDataImpl &Record)
Emit a UnresolvedSet structure.
Definition: ASTWriter.cpp:5378
detail::InMemoryDirectory::const_iterator E
uint32_t CXXCtorInitializersID
An ID number that refers to a list of CXXCtorInitializers in an AST file.
Definition: ASTBitCodes.h:153
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:34
unsigned getTypeFunctionProtoAbbrev() const
Definition: ASTWriter.h:833
void ResolvedExceptionSpec(const FunctionDecl *FD) override
A function's exception specification has been evaluated or instantiated.
Definition: ASTWriter.cpp:5734
void FlushCXXCtorInitializers()
Flush all of the C++ constructor initializer lists that have been added via AddCXXCtorInitializersRef...
Definition: ASTWriter.cpp:5470
serialization::SelectorID getSelectorRef(Selector Sel)
Get the unique number used to refer to the given selector.
Definition: ASTWriter.cpp:4812
void EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record, StringRef Path)
Emit the current record with the given path as a blob.
Definition: ASTWriter.cpp:3993
uint32_t PreprocessedEntityID
An ID number that refers to an entity in the detailed preprocessing record.
Definition: ASTBitCodes.h:157
void AddStmt(Stmt *S)
Add the given statement or expression to the queue of statements to emit.
Definition: ASTWriter.h:798
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:4025
Represents a C++ struct/union/class.
Definition: DeclCXX.h:285
void FlushStmts()
Flush all of the statements and expressions that have been added to the queue via AddStmt()...
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
Definition: ASTBitCodes.h:142
void DeclarationMarkedUsed(const Decl *D) override
A declaration is marked used which was not previously marked used.
Definition: ASTWriter.cpp:5816
ASTReader * getChain() const
Definition: ASTWriter.h:852
Writes an AST file containing the contents of a translation unit.
Definition: ASTWriter.h:84
ArrayRef< uint64_t > RecordDataRef
Definition: ASTWriter.h:89
serialization::DeclID getDeclID(const Decl *D)
Determine the declaration ID of an already-emitted declaration.
Definition: ASTWriter.cpp:4988
uint64_t WriteAST(Sema &SemaRef, const std::string &OutputFile, Module *WritingModule, StringRef isysroot, bool hasErrors=false)
Write a precompiled header for the given semantic analysis.
Definition: ASTWriter.cpp:4078
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:772
unsigned getDeclTypedefAbbrev() const
Definition: ASTWriter.h:839
AST and semantic-analysis consumer that generates a precompiled header from the parsed source code...
Definition: ASTWriter.h:887
void AddCXXCtorInitializers(const CXXCtorInitializer *const *CtorInitializers, unsigned NumCtorInitializers, RecordDataImpl &Record)
Emit a CXXCtorInitializer array.
Definition: ASTWriter.cpp:5432
uint32_t TypeID
An ID number that refers to a type in an AST file.
Definition: ASTBitCodes.h:80
#define true
Definition: stdbool.h:32
NamedDecl - This represents a decl with a name.
Definition: Decl.h:145
ASTWriter & getWriter()
Definition: ASTWriter.h:899
uint32_t CXXBaseSpecifiersID
An ID number that refers to a set of CXXBaseSpecifiers in an AST file.
Definition: ASTBitCodes.h:149
void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) override
An implicit member was added after the definition was completed.
Definition: ASTWriter.cpp:5717
A type index; the type ID with the qualifier bits removed.
Definition: ASTBitCodes.h:83
Attr - This represents one attribute.
Definition: Attr.h:44
void TypeRead(serialization::TypeIdx Idx, QualType T) override
A type was deserialized from the AST file.
Definition: ASTWriter.cpp:5635
ASTWriter(llvm::BitstreamWriter &Stream, ArrayRef< llvm::IntrusiveRefCntPtr< ModuleFileExtension >> Extensions, bool IncludeTimestamps=true)
Create a new precompiled header writer that outputs to the given bitstream.
Definition: ASTWriter.cpp:4035
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:96
void AddAPFloat(const llvm::APFloat &Value, RecordDataImpl &Record)
Emit a floating-point value.
Definition: ASTWriter.cpp:4762