clang  5.0.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"
19 #include "clang/AST/TemplateBase.h"
24 #include "llvm/ADT/DenseMap.h"
25 #include "llvm/ADT/DenseSet.h"
26 #include "llvm/ADT/MapVector.h"
27 #include "llvm/ADT/SetVector.h"
28 #include "llvm/ADT/SmallVector.h"
29 #include "llvm/Bitcode/BitstreamWriter.h"
30 #include <queue>
31 #include <vector>
32 
33 namespace llvm {
34  class APFloat;
35  class APInt;
36 }
37 
38 namespace clang {
39 
40 class DeclarationName;
41 class ASTContext;
42 class Attr;
43 class NestedNameSpecifier;
44 class CXXBaseSpecifier;
45 class CXXCtorInitializer;
46 class FileEntry;
47 class FPOptions;
48 class HeaderSearch;
49 class HeaderSearchOptions;
50 class IdentifierResolver;
51 class MacroDefinitionRecord;
52 class MacroDirective;
53 class MacroInfo;
54 class OpaqueValueExpr;
55 class OpenCLOptions;
56 class ASTReader;
57 class MemoryBufferCache;
58 class Module;
59 class ModuleFileExtension;
60 class ModuleFileExtensionWriter;
61 class PreprocessedEntity;
62 class PreprocessingRecord;
63 class Preprocessor;
64 class RecordDecl;
65 class Sema;
66 class SourceManager;
67 struct StoredDeclsList;
68 class SwitchCase;
69 class TargetInfo;
70 class Token;
71 class VersionTuple;
72 class ASTUnresolvedSet;
73 
74 namespace SrcMgr { class SLocEntry; }
75 
76 /// \brief Writes an AST file containing the contents of a translation unit.
77 ///
78 /// The ASTWriter class produces a bitstream containing the serialized
79 /// representation of a given abstract syntax tree and its supporting
80 /// data structures. This bitstream can be de-serialized via an
81 /// instance of the ASTReader class.
83  public ASTMutationListener {
84 public:
88 
89  friend class ASTDeclWriter;
90  friend class ASTStmtWriter;
91  friend class ASTTypeWriter;
92  friend class ASTRecordWriter;
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  /// The buffer associated with the bitstream.
112 
113  /// \brief The PCM manager which manages memory buffers for pcm files.
114  MemoryBufferCache &PCMCache;
115 
116  /// \brief The ASTContext we're writing.
117  ASTContext *Context = nullptr;
118 
119  /// \brief The preprocessor we're writing.
120  Preprocessor *PP = nullptr;
121 
122  /// \brief The reader of existing AST files, if we're chaining.
123  ASTReader *Chain = nullptr;
124 
125  /// \brief The module we're currently writing, if any.
126  Module *WritingModule = nullptr;
127 
128  /// \brief The base directory for any relative paths we emit.
129  std::string BaseDirectory;
130 
131  /// \brief Indicates whether timestamps should be written to the produced
132  /// module file. This is the case for files implicitly written to the
133  /// module cache, where we need the timestamps to determine if the module
134  /// file is up to date, but not otherwise.
135  bool IncludeTimestamps;
136 
137  /// \brief Indicates when the AST writing is actively performing
138  /// serialization, rather than just queueing updates.
139  bool WritingAST = false;
140 
141  /// \brief Indicates that we are done serializing the collection of decls
142  /// and types to emit.
143  bool DoneWritingDeclsAndTypes = false;
144 
145  /// \brief Indicates that the AST contained compiler errors.
146  bool ASTHasCompilerErrors = false;
147 
148  /// \brief Mapping from input file entries to the index into the
149  /// offset table where information about that input file is stored.
150  llvm::DenseMap<const FileEntry *, uint32_t> InputFileIDs;
151 
152  /// \brief Stores a declaration or a type to be written to the AST file.
153  class DeclOrType {
154  public:
155  DeclOrType(Decl *D) : Stored(D), IsType(false) { }
156  DeclOrType(QualType T) : Stored(T.getAsOpaquePtr()), IsType(true) { }
157 
158  bool isType() const { return IsType; }
159  bool isDecl() const { return !IsType; }
160 
161  QualType getType() const {
162  assert(isType() && "Not a type!");
163  return QualType::getFromOpaquePtr(Stored);
164  }
165 
166  Decl *getDecl() const {
167  assert(isDecl() && "Not a decl!");
168  return static_cast<Decl *>(Stored);
169  }
170 
171  private:
172  void *Stored;
173  bool IsType;
174  };
175 
176  /// \brief The declarations and types to emit.
177  std::queue<DeclOrType> DeclTypesToEmit;
178 
179  /// \brief The first ID number we can use for our own declarations.
181 
182  /// \brief The decl ID that will be assigned to the next new decl.
183  serialization::DeclID NextDeclID = FirstDeclID;
184 
185  /// \brief Map that provides the ID numbers of each declaration within
186  /// the output stream, as well as those deserialized from a chained PCH.
187  ///
188  /// The ID numbers of declarations are consecutive (in order of
189  /// discovery) and start at 2. 1 is reserved for the translation
190  /// unit, while 0 is reserved for NULL.
191  llvm::DenseMap<const Decl *, serialization::DeclID> DeclIDs;
192 
193  /// \brief Offset of each declaration in the bitstream, indexed by
194  /// the declaration's ID.
195  std::vector<serialization::DeclOffset> DeclOffsets;
196 
197  /// \brief Sorted (by file offset) vector of pairs of file offset/DeclID.
198  typedef SmallVector<std::pair<unsigned, serialization::DeclID>, 64>
199  LocDeclIDsTy;
200  struct DeclIDInFileInfo {
201  LocDeclIDsTy DeclIDs;
202  /// \brief Set when the DeclIDs vectors from all files are joined, this
203  /// indicates the index that this particular vector has in the global one.
204  unsigned FirstDeclIndex;
205  };
206  typedef llvm::DenseMap<FileID, DeclIDInFileInfo *> FileDeclIDsTy;
207 
208  /// \brief Map from file SLocEntries to info about the file-level declarations
209  /// that it contains.
210  FileDeclIDsTy FileDeclIDs;
211 
212  void associateDeclWithFile(const Decl *D, serialization::DeclID);
213 
214  /// \brief The first ID number we can use for our own types.
216 
217  /// \brief The type ID that will be assigned to the next new type.
218  serialization::TypeID NextTypeID = FirstTypeID;
219 
220  /// \brief Map that provides the ID numbers of each type within the
221  /// output stream, plus those deserialized from a chained PCH.
222  ///
223  /// The ID numbers of types are consecutive (in order of discovery)
224  /// and start at 1. 0 is reserved for NULL. When types are actually
225  /// stored in the stream, the ID number is shifted by 2 bits to
226  /// allow for the const/volatile qualifiers.
227  ///
228  /// Keys in the map never have const/volatile qualifiers.
229  TypeIdxMap TypeIdxs;
230 
231  /// \brief Offset of each type in the bitstream, indexed by
232  /// the type's ID.
233  std::vector<uint32_t> TypeOffsets;
234 
235  /// \brief The first ID number we can use for our own identifiers.
237 
238  /// \brief The identifier ID that will be assigned to the next new identifier.
239  serialization::IdentID NextIdentID = FirstIdentID;
240 
241  /// \brief Map that provides the ID numbers of each identifier in
242  /// the output stream.
243  ///
244  /// The ID numbers for identifiers are consecutive (in order of
245  /// discovery), starting at 1. An ID of zero refers to a NULL
246  /// IdentifierInfo.
247  llvm::MapVector<const IdentifierInfo *, serialization::IdentID> IdentifierIDs;
248 
249  /// \brief The first ID number we can use for our own macros.
251 
252  /// \brief The identifier ID that will be assigned to the next new identifier.
253  serialization::MacroID NextMacroID = FirstMacroID;
254 
255  /// \brief Map that provides the ID numbers of each macro.
256  llvm::DenseMap<MacroInfo *, serialization::MacroID> MacroIDs;
257 
258  struct MacroInfoToEmitData {
259  const IdentifierInfo *Name;
260  MacroInfo *MI;
262  };
263  /// \brief The macro infos to emit.
264  std::vector<MacroInfoToEmitData> MacroInfosToEmit;
265 
266  llvm::DenseMap<const IdentifierInfo *, uint64_t> IdentMacroDirectivesOffsetMap;
267 
268  /// @name FlushStmt Caches
269  /// @{
270 
271  /// \brief Set of parent Stmts for the currently serializing sub-stmt.
272  llvm::DenseSet<Stmt *> ParentStmts;
273 
274  /// \brief Offsets of sub-stmts already serialized. The offset points
275  /// just after the stmt record.
276  llvm::DenseMap<Stmt *, uint64_t> SubStmtEntries;
277 
278  /// @}
279 
280  /// \brief Offsets of each of the identifier IDs into the identifier
281  /// table.
282  std::vector<uint32_t> IdentifierOffsets;
283 
284  /// \brief The first ID number we can use for our own submodules.
285  serialization::SubmoduleID FirstSubmoduleID =
287 
288  /// \brief The submodule ID that will be assigned to the next new submodule.
289  serialization::SubmoduleID NextSubmoduleID = FirstSubmoduleID;
290 
291  /// \brief The first ID number we can use for our own selectors.
292  serialization::SelectorID FirstSelectorID =
294 
295  /// \brief The selector ID that will be assigned to the next new selector.
296  serialization::SelectorID NextSelectorID = FirstSelectorID;
297 
298  /// \brief Map that provides the ID numbers of each Selector.
299  llvm::MapVector<Selector, serialization::SelectorID> SelectorIDs;
300 
301  /// \brief Offset of each selector within the method pool/selector
302  /// table, indexed by the Selector ID (-1).
303  std::vector<uint32_t> SelectorOffsets;
304 
305  /// \brief Mapping from macro definitions (as they occur in the preprocessing
306  /// record) to the macro IDs.
307  llvm::DenseMap<const MacroDefinitionRecord *,
308  serialization::PreprocessedEntityID> MacroDefinitions;
309 
310  /// \brief Cache of indices of anonymous declarations within their lexical
311  /// contexts.
312  llvm::DenseMap<const Decl *, unsigned> AnonymousDeclarationNumbers;
313 
314  /// An update to a Decl.
315  class DeclUpdate {
316  /// A DeclUpdateKind.
317  unsigned Kind;
318  union {
319  const Decl *Dcl;
320  void *Type;
321  unsigned Loc;
322  unsigned Val;
323  Module *Mod;
324  const Attr *Attribute;
325  };
326 
327  public:
328  DeclUpdate(unsigned Kind) : Kind(Kind), Dcl(nullptr) {}
329  DeclUpdate(unsigned Kind, const Decl *Dcl) : Kind(Kind), Dcl(Dcl) {}
330  DeclUpdate(unsigned Kind, QualType Type)
331  : Kind(Kind), Type(Type.getAsOpaquePtr()) {}
332  DeclUpdate(unsigned Kind, SourceLocation Loc)
333  : Kind(Kind), Loc(Loc.getRawEncoding()) {}
334  DeclUpdate(unsigned Kind, unsigned Val)
335  : Kind(Kind), Val(Val) {}
336  DeclUpdate(unsigned Kind, Module *M)
337  : Kind(Kind), Mod(M) {}
338  DeclUpdate(unsigned Kind, const Attr *Attribute)
339  : Kind(Kind), Attribute(Attribute) {}
340 
341  unsigned getKind() const { return Kind; }
342  const Decl *getDecl() const { return Dcl; }
343  QualType getType() const { return QualType::getFromOpaquePtr(Type); }
344  SourceLocation getLoc() const {
346  }
347  unsigned getNumber() const { return Val; }
348  Module *getModule() const { return Mod; }
349  const Attr *getAttr() const { return Attribute; }
350  };
351 
352  typedef SmallVector<DeclUpdate, 1> UpdateRecord;
353  typedef llvm::MapVector<const Decl *, UpdateRecord> DeclUpdateMap;
354  /// \brief Mapping from declarations that came from a chained PCH to the
355  /// record containing modifications to them.
356  DeclUpdateMap DeclUpdates;
357 
358  typedef llvm::DenseMap<Decl *, Decl *> FirstLatestDeclMap;
359  /// \brief Map of first declarations from a chained PCH that point to the
360  /// most recent declarations in another PCH.
361  FirstLatestDeclMap FirstLatestDecls;
362 
363  /// \brief Declarations encountered that might be external
364  /// definitions.
365  ///
366  /// We keep track of external definitions and other 'interesting' declarations
367  /// as we are emitting declarations to the AST file. The AST file contains a
368  /// separate record for these declarations, which are provided to the AST
369  /// consumer by the AST reader. This is behavior is required to properly cope with,
370  /// e.g., tentative variable definitions that occur within
371  /// headers. The declarations themselves are stored as declaration
372  /// IDs, since they will be written out to an EAGERLY_DESERIALIZED_DECLS
373  /// record.
374  SmallVector<uint64_t, 16> EagerlyDeserializedDecls;
375  SmallVector<uint64_t, 16> ModularCodegenDecls;
376 
377  /// \brief DeclContexts that have received extensions since their serialized
378  /// form.
379  ///
380  /// For namespaces, when we're chaining and encountering a namespace, we check
381  /// if its primary namespace comes from the chain. If it does, we add the
382  /// primary to this set, so that we can write out lexical content updates for
383  /// it.
385 
386  /// \brief Keeps track of declarations that we must emit, even though we're
387  /// not guaranteed to be able to find them by walking the AST starting at the
388  /// translation unit.
389  SmallVector<const Decl *, 16> DeclsToEmitEvenIfUnreferenced;
390 
391  /// \brief The set of Objective-C class that have categories we
392  /// should serialize.
393  llvm::SetVector<ObjCInterfaceDecl *> ObjCClassesWithCategories;
394 
395  /// \brief The set of declarations that may have redeclaration chains that
396  /// need to be serialized.
398 
399  /// \brief A cache of the first local declaration for "interesting"
400  /// redeclaration chains.
401  llvm::DenseMap<const Decl *, const Decl *> FirstLocalDeclCache;
402 
403  /// \brief Mapping from SwitchCase statements to IDs.
404  llvm::DenseMap<SwitchCase *, unsigned> SwitchCaseIDs;
405 
406  /// \brief The number of statements written to the AST file.
407  unsigned NumStatements = 0;
408 
409  /// \brief The number of macros written to the AST file.
410  unsigned NumMacros = 0;
411 
412  /// \brief The number of lexical declcontexts written to the AST
413  /// file.
414  unsigned NumLexicalDeclContexts = 0;
415 
416  /// \brief The number of visible declcontexts written to the AST
417  /// file.
418  unsigned NumVisibleDeclContexts = 0;
419 
420  /// \brief A mapping from each known submodule to its ID number, which will
421  /// be a positive integer.
422  llvm::DenseMap<Module *, unsigned> SubmoduleIDs;
423 
424  /// \brief A list of the module file extension writers.
425  std::vector<std::unique_ptr<ModuleFileExtensionWriter>>
426  ModuleFileExtensionWriters;
427 
428  /// \brief Retrieve or create a submodule ID for this module.
429  unsigned getSubmoduleID(Module *Mod);
430 
431  /// \brief Write the given subexpression to the bitstream.
432  void WriteSubStmt(Stmt *S);
433 
434  void WriteBlockInfoBlock();
435  void WriteControlBlock(Preprocessor &PP, ASTContext &Context,
436  StringRef isysroot, const std::string &OutputFile);
437 
438  /// Write out the signature and diagnostic options, and return the signature.
439  ASTFileSignature writeUnhashedControlBlock(Preprocessor &PP,
440  ASTContext &Context);
441 
442  /// Calculate hash of the pcm content.
443  static ASTFileSignature createSignature(StringRef Bytes);
444 
445  void WriteInputFiles(SourceManager &SourceMgr, HeaderSearchOptions &HSOpts,
446  bool Modules);
447  void WriteSourceManagerBlock(SourceManager &SourceMgr,
448  const Preprocessor &PP);
449  void WritePreprocessor(const Preprocessor &PP, bool IsModule);
450  void WriteHeaderSearch(const HeaderSearch &HS);
451  void WritePreprocessorDetail(PreprocessingRecord &PPRec);
452  void WriteSubmodules(Module *WritingModule);
453 
454  void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag,
455  bool isModule);
456 
457  unsigned TypeExtQualAbbrev = 0;
458  unsigned TypeFunctionProtoAbbrev = 0;
459  void WriteTypeAbbrevs();
460  void WriteType(QualType T);
461 
462  bool isLookupResultExternal(StoredDeclsList &Result, DeclContext *DC);
463  bool isLookupResultEntirelyExternal(StoredDeclsList &Result, DeclContext *DC);
464 
465  void GenerateNameLookupTable(const DeclContext *DC,
466  llvm::SmallVectorImpl<char> &LookupTable);
467  uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC);
468  uint64_t WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC);
469  void WriteTypeDeclOffsets();
470  void WriteFileDeclIDsMap();
471  void WriteComments();
472  void WriteSelectors(Sema &SemaRef);
473  void WriteReferencedSelectorsPool(Sema &SemaRef);
474  void WriteIdentifierTable(Preprocessor &PP, IdentifierResolver &IdResolver,
475  bool IsModule);
476  void WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord);
477  void WriteDeclContextVisibleUpdate(const DeclContext *DC);
478  void WriteFPPragmaOptions(const FPOptions &Opts);
479  void WriteOpenCLExtensions(Sema &SemaRef);
480  void WriteOpenCLExtensionTypes(Sema &SemaRef);
481  void WriteOpenCLExtensionDecls(Sema &SemaRef);
482  void WriteCUDAPragmas(Sema &SemaRef);
483  void WriteObjCCategories();
484  void WriteLateParsedTemplates(Sema &SemaRef);
485  void WriteOptimizePragmaOptions(Sema &SemaRef);
486  void WriteMSStructPragmaOptions(Sema &SemaRef);
487  void WriteMSPointersToMembersPragmaOptions(Sema &SemaRef);
488  void WritePackPragmaOptions(Sema &SemaRef);
489  void WriteModuleFileExtension(Sema &SemaRef,
490  ModuleFileExtensionWriter &Writer);
491 
492  unsigned DeclParmVarAbbrev = 0;
493  unsigned DeclContextLexicalAbbrev = 0;
494  unsigned DeclContextVisibleLookupAbbrev = 0;
495  unsigned UpdateVisibleAbbrev = 0;
496  unsigned DeclRecordAbbrev = 0;
497  unsigned DeclTypedefAbbrev = 0;
498  unsigned DeclVarAbbrev = 0;
499  unsigned DeclFieldAbbrev = 0;
500  unsigned DeclEnumAbbrev = 0;
501  unsigned DeclObjCIvarAbbrev = 0;
502  unsigned DeclCXXMethodAbbrev = 0;
503 
504  unsigned DeclRefExprAbbrev = 0;
505  unsigned CharacterLiteralAbbrev = 0;
506  unsigned IntegerLiteralAbbrev = 0;
507  unsigned ExprImplicitCastAbbrev = 0;
508 
509  void WriteDeclAbbrevs();
510  void WriteDecl(ASTContext &Context, Decl *D);
511 
512  ASTFileSignature WriteASTCore(Sema &SemaRef, StringRef isysroot,
513  const std::string &OutputFile,
514  Module *WritingModule);
515 
516 public:
517  /// \brief Create a new precompiled header writer that outputs to
518  /// the given bitstream.
519  ASTWriter(llvm::BitstreamWriter &Stream, SmallVectorImpl<char> &Buffer,
520  MemoryBufferCache &PCMCache,
521  ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
522  bool IncludeTimestamps = true);
523  ~ASTWriter() override;
524 
525  const LangOptions &getLangOpts() const;
526 
527  /// \brief Get a timestamp for output into the AST file. The actual timestamp
528  /// of the specified file may be ignored if we have been instructed to not
529  /// include timestamps in the output file.
530  time_t getTimestampForOutput(const FileEntry *E) const;
531 
532  /// \brief Write a precompiled header for the given semantic analysis.
533  ///
534  /// \param SemaRef a reference to the semantic analysis object that processed
535  /// the AST to be written into the precompiled header.
536  ///
537  /// \param WritingModule The module that we are writing. If null, we are
538  /// writing a precompiled header.
539  ///
540  /// \param isysroot if non-empty, write a relocatable file whose headers
541  /// are relative to the given system root. If we're writing a module, its
542  /// build directory will be used in preference to this if both are available.
543  ///
544  /// \return the module signature, which eventually will be a hash of
545  /// the module but currently is merely a random 32-bit number.
546  ASTFileSignature WriteAST(Sema &SemaRef, const std::string &OutputFile,
547  Module *WritingModule, StringRef isysroot,
548  bool hasErrors = false);
549 
550  /// \brief Emit a token.
551  void AddToken(const Token &Tok, RecordDataImpl &Record);
552 
553  /// \brief Emit a source location.
554  void AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record);
555 
556  /// \brief Emit a source range.
557  void AddSourceRange(SourceRange Range, RecordDataImpl &Record);
558 
559  /// \brief Emit a reference to an identifier.
560  void AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record);
561 
562  /// \brief Get the unique number used to refer to the given selector.
564 
565  /// \brief Get the unique number used to refer to the given identifier.
566  serialization::IdentID getIdentifierRef(const IdentifierInfo *II);
567 
568  /// \brief Get the unique number used to refer to the given macro.
569  serialization::MacroID getMacroRef(MacroInfo *MI, const IdentifierInfo *Name);
570 
571  /// \brief Determine the ID of an already-emitted macro.
572  serialization::MacroID getMacroID(MacroInfo *MI);
573 
574  uint64_t getMacroDirectivesOffset(const IdentifierInfo *Name);
575 
576  /// \brief Emit a reference to a type.
577  void AddTypeRef(QualType T, RecordDataImpl &Record);
578 
579  /// \brief Force a type to be emitted and get its ID.
581 
582  /// \brief Determine the type ID of an already-emitted type.
583  serialization::TypeID getTypeID(QualType T) const;
584 
585  /// \brief Find the first local declaration of a given local redeclarable
586  /// decl.
587  const Decl *getFirstLocalDecl(const Decl *D);
588 
589  /// \brief Is this a local declaration (that is, one that will be written to
590  /// our AST file)? This is the case for declarations that are neither imported
591  /// from another AST file nor predefined.
592  bool IsLocalDecl(const Decl *D) {
593  if (D->isFromASTFile())
594  return false;
595  auto I = DeclIDs.find(D);
596  return (I == DeclIDs.end() ||
598  };
599 
600  /// \brief Emit a reference to a declaration.
601  void AddDeclRef(const Decl *D, RecordDataImpl &Record);
602 
603 
604  /// \brief Force a declaration to be emitted and get its ID.
606 
607  /// \brief Determine the declaration ID of an already-emitted
608  /// declaration.
610 
611  unsigned getAnonymousDeclarationNumber(const NamedDecl *D);
612 
613  /// \brief Add a string to the given record.
614  void AddString(StringRef Str, RecordDataImpl &Record);
615 
616  /// \brief Convert a path from this build process into one that is appropriate
617  /// for emission in the module file.
619 
620  /// \brief Add a path to the given record.
621  void AddPath(StringRef Path, RecordDataImpl &Record);
622 
623  /// \brief Emit the current record with the given path as a blob.
624  void EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record,
625  StringRef Path);
626 
627  /// \brief Add a version tuple to the given record
628  void AddVersionTuple(const VersionTuple &Version, RecordDataImpl &Record);
629 
630  /// \brief Retrieve or create a submodule ID for this module, or return 0 if
631  /// the submodule is neither local (a submodle of the currently-written module)
632  /// nor from an imported module.
633  unsigned getLocalOrImportedSubmoduleID(Module *Mod);
634 
635  /// \brief Note that the identifier II occurs at the given offset
636  /// within the identifier table.
637  void SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset);
638 
639  /// \brief Note that the selector Sel occurs at the given offset
640  /// within the method pool/selector table.
641  void SetSelectorOffset(Selector Sel, uint32_t Offset);
642 
643  /// \brief Record an ID for the given switch-case statement.
644  unsigned RecordSwitchCaseID(SwitchCase *S);
645 
646  /// \brief Retrieve the ID for the given switch-case statement.
647  unsigned getSwitchCaseID(SwitchCase *S);
648 
649  void ClearSwitchCaseIDs();
650 
651  unsigned getTypeExtQualAbbrev() const {
652  return TypeExtQualAbbrev;
653  }
654  unsigned getTypeFunctionProtoAbbrev() const {
655  return TypeFunctionProtoAbbrev;
656  }
657 
658  unsigned getDeclParmVarAbbrev() const { return DeclParmVarAbbrev; }
659  unsigned getDeclRecordAbbrev() const { return DeclRecordAbbrev; }
660  unsigned getDeclTypedefAbbrev() const { return DeclTypedefAbbrev; }
661  unsigned getDeclVarAbbrev() const { return DeclVarAbbrev; }
662  unsigned getDeclFieldAbbrev() const { return DeclFieldAbbrev; }
663  unsigned getDeclEnumAbbrev() const { return DeclEnumAbbrev; }
664  unsigned getDeclObjCIvarAbbrev() const { return DeclObjCIvarAbbrev; }
665  unsigned getDeclCXXMethodAbbrev() const { return DeclCXXMethodAbbrev; }
666 
667  unsigned getDeclRefExprAbbrev() const { return DeclRefExprAbbrev; }
668  unsigned getCharacterLiteralAbbrev() const { return CharacterLiteralAbbrev; }
669  unsigned getIntegerLiteralAbbrev() const { return IntegerLiteralAbbrev; }
670  unsigned getExprImplicitCastAbbrev() const { return ExprImplicitCastAbbrev; }
671 
672  bool hasChain() const { return Chain; }
673  ASTReader *getChain() const { return Chain; }
674 
675 private:
676  // ASTDeserializationListener implementation
677  void ReaderInitialized(ASTReader *Reader) override;
678  void IdentifierRead(serialization::IdentID ID, IdentifierInfo *II) override;
679  void MacroRead(serialization::MacroID ID, MacroInfo *MI) override;
680  void TypeRead(serialization::TypeIdx Idx, QualType T) override;
681  void SelectorRead(serialization::SelectorID ID, Selector Sel) override;
682  void MacroDefinitionRead(serialization::PreprocessedEntityID ID,
683  MacroDefinitionRecord *MD) override;
684  void ModuleRead(serialization::SubmoduleID ID, Module *Mod) override;
685 
686  // ASTMutationListener implementation.
687  void CompletedTagDefinition(const TagDecl *D) override;
688  void AddedVisibleDecl(const DeclContext *DC, const Decl *D) override;
689  void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) override;
690  void AddedCXXTemplateSpecialization(
691  const ClassTemplateDecl *TD,
692  const ClassTemplateSpecializationDecl *D) override;
693  void AddedCXXTemplateSpecialization(
694  const VarTemplateDecl *TD,
695  const VarTemplateSpecializationDecl *D) override;
696  void AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD,
697  const FunctionDecl *D) override;
698  void ResolvedExceptionSpec(const FunctionDecl *FD) override;
699  void DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) override;
700  void ResolvedOperatorDelete(const CXXDestructorDecl *DD,
701  const FunctionDecl *Delete) override;
702  void CompletedImplicitDefinition(const FunctionDecl *D) override;
703  void StaticDataMemberInstantiated(const VarDecl *D) override;
704  void DefaultArgumentInstantiated(const ParmVarDecl *D) override;
705  void DefaultMemberInitializerInstantiated(const FieldDecl *D) override;
706  void FunctionDefinitionInstantiated(const FunctionDecl *D) override;
707  void AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD,
708  const ObjCInterfaceDecl *IFD) override;
709  void DeclarationMarkedUsed(const Decl *D) override;
710  void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) override;
711  void DeclarationMarkedOpenMPDeclareTarget(const Decl *D,
712  const Attr *Attr) override;
713  void RedefinedHiddenDefinition(const NamedDecl *D, Module *M) override;
714  void AddedAttributeToRecord(const Attr *Attr,
715  const RecordDecl *Record) override;
716 };
717 
718 /// \brief An object for streaming information to a record.
720  ASTWriter *Writer;
722 
723  /// \brief Statements that we've encountered while serializing a
724  /// declaration or type.
725  SmallVector<Stmt *, 16> StmtsToEmit;
726 
727  /// \brief Indices of record elements that describe offsets within the
728  /// bitcode. These will be converted to offsets relative to the current
729  /// record when emitted.
730  SmallVector<unsigned, 8> OffsetIndices;
731 
732  /// \brief Flush all of the statements and expressions that have
733  /// been added to the queue via AddStmt().
734  void FlushStmts();
735  void FlushSubStmts();
736 
737  void PrepareToEmit(uint64_t MyOffset) {
738  // Convert offsets into relative form.
739  for (unsigned I : OffsetIndices) {
740  auto &StoredOffset = (*Record)[I];
741  assert(StoredOffset < MyOffset && "invalid offset");
742  if (StoredOffset)
743  StoredOffset = MyOffset - StoredOffset;
744  }
745  OffsetIndices.clear();
746  }
747 
748 public:
749  /// Construct a ASTRecordWriter that uses the default encoding scheme.
751  : Writer(&Writer), Record(&Record) {}
752 
753  /// Construct a ASTRecordWriter that uses the same encoding scheme as another
754  /// ASTRecordWriter.
756  : Writer(Parent.Writer), Record(&Record) {}
757 
758  /// Copying an ASTRecordWriter is almost certainly a bug.
759  ASTRecordWriter(const ASTRecordWriter&) = delete;
760  void operator=(const ASTRecordWriter&) = delete;
761 
762  /// \brief Extract the underlying record storage.
763  ASTWriter::RecordDataImpl &getRecordData() const { return *Record; }
764 
765  /// \brief Minimal vector-like interface.
766  /// @{
767  void push_back(uint64_t N) { Record->push_back(N); }
768  template<typename InputIterator>
769  void append(InputIterator begin, InputIterator end) {
770  Record->append(begin, end);
771  }
772  bool empty() const { return Record->empty(); }
773  size_t size() const { return Record->size(); }
774  uint64_t &operator[](size_t N) { return (*Record)[N]; }
775  /// @}
776 
777  /// \brief Emit the record to the stream, followed by its substatements, and
778  /// return its offset.
779  // FIXME: Allow record producers to suggest Abbrevs.
780  uint64_t Emit(unsigned Code, unsigned Abbrev = 0) {
781  uint64_t Offset = Writer->Stream.GetCurrentBitNo();
782  PrepareToEmit(Offset);
783  Writer->Stream.EmitRecord(Code, *Record, Abbrev);
784  FlushStmts();
785  return Offset;
786  }
787 
788  /// \brief Emit the record to the stream, preceded by its substatements.
789  uint64_t EmitStmt(unsigned Code, unsigned Abbrev = 0) {
790  FlushSubStmts();
791  PrepareToEmit(Writer->Stream.GetCurrentBitNo());
792  Writer->Stream.EmitRecord(Code, *Record, Abbrev);
793  return Writer->Stream.GetCurrentBitNo();
794  }
795 
796  /// \brief Add a bit offset into the record. This will be converted into an
797  /// offset relative to the current record when emitted.
798  void AddOffset(uint64_t BitOffset) {
799  OffsetIndices.push_back(Record->size());
800  Record->push_back(BitOffset);
801  }
802 
803  /// \brief Add the given statement or expression to the queue of
804  /// statements to emit.
805  ///
806  /// This routine should be used when emitting types and declarations
807  /// that have expressions as part of their formulation. Once the
808  /// type or declaration has been written, Emit() will write
809  /// the corresponding statements just after the record.
810  void AddStmt(Stmt *S) {
811  StmtsToEmit.push_back(S);
812  }
813 
814  /// \brief Add a definition for the given function to the queue of statements
815  /// to emit.
816  void AddFunctionDefinition(const FunctionDecl *FD);
817 
818  /// \brief Emit a source location.
820  return Writer->AddSourceLocation(Loc, *Record);
821  }
822 
823  /// \brief Emit a source range.
825  return Writer->AddSourceRange(Range, *Record);
826  }
827 
828  /// \brief Emit an integral value.
829  void AddAPInt(const llvm::APInt &Value);
830 
831  /// \brief Emit a signed integral value.
832  void AddAPSInt(const llvm::APSInt &Value);
833 
834  /// \brief Emit a floating-point value.
835  void AddAPFloat(const llvm::APFloat &Value);
836 
837  /// \brief Emit a reference to an identifier.
839  return Writer->AddIdentifierRef(II, *Record);
840  }
841 
842  /// \brief Emit a Selector (which is a smart pointer reference).
843  void AddSelectorRef(Selector S);
844 
845  /// \brief Emit a CXXTemporary.
846  void AddCXXTemporary(const CXXTemporary *Temp);
847 
848  /// \brief Emit a C++ base specifier.
850 
851  /// \brief Emit a set of C++ base specifiers.
853 
854  /// \brief Emit a reference to a type.
856  return Writer->AddTypeRef(T, *Record);
857  }
858 
859  /// \brief Emits a reference to a declarator info.
860  void AddTypeSourceInfo(TypeSourceInfo *TInfo);
861 
862  /// \brief Emits a type with source-location information.
863  void AddTypeLoc(TypeLoc TL);
864 
865  /// \brief Emits a template argument location info.
867  const TemplateArgumentLocInfo &Arg);
868 
869  /// \brief Emits a template argument location.
871 
872  /// \brief Emits an AST template argument list info.
874  const ASTTemplateArgumentListInfo *ASTTemplArgList);
875 
876  /// \brief Emit a reference to a declaration.
877  void AddDeclRef(const Decl *D) {
878  return Writer->AddDeclRef(D, *Record);
879  }
880 
881  /// \brief Emit a declaration name.
883 
884  void AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc,
886  void AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
887 
888  void AddQualifierInfo(const QualifierInfo &Info);
889 
890  /// \brief Emit a nested name specifier.
892 
893  /// \brief Emit a nested name specifier with source-location information.
895 
896  /// \brief Emit a template name.
898 
899  /// \brief Emit a template argument.
900  void AddTemplateArgument(const TemplateArgument &Arg);
901 
902  /// \brief Emit a template parameter list.
903  void AddTemplateParameterList(const TemplateParameterList *TemplateParams);
904 
905  /// \brief Emit a template argument list.
906  void AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs);
907 
908  /// \brief Emit a UnresolvedSet structure.
909  void AddUnresolvedSet(const ASTUnresolvedSet &Set);
910 
911  /// \brief Emit a CXXCtorInitializer array.
913 
914  void AddCXXDefinitionData(const CXXRecordDecl *D);
915 
916  /// \brief Emit a string.
917  void AddString(StringRef Str) {
918  return Writer->AddString(Str, *Record);
919  }
920 
921  /// \brief Emit a path.
922  void AddPath(StringRef Path) {
923  return Writer->AddPath(Path, *Record);
924  }
925 
926  /// \brief Emit a version tuple.
927  void AddVersionTuple(const VersionTuple &Version) {
928  return Writer->AddVersionTuple(Version, *Record);
929  }
930 
931  /// \brief Emit a list of attributes.
933 };
934 
935 /// \brief AST and semantic-analysis consumer that generates a
936 /// precompiled header from the parsed source code.
937 class PCHGenerator : public SemaConsumer {
938  const Preprocessor &PP;
939  std::string OutputFile;
940  std::string isysroot;
941  Sema *SemaPtr;
942  std::shared_ptr<PCHBuffer> Buffer;
943  llvm::BitstreamWriter Stream;
944  ASTWriter Writer;
945  bool AllowASTWithErrors;
946 
947 protected:
948  ASTWriter &getWriter() { return Writer; }
949  const ASTWriter &getWriter() const { return Writer; }
950  SmallVectorImpl<char> &getPCH() const { return Buffer->Data; }
951 
952 public:
953  PCHGenerator(const Preprocessor &PP, StringRef OutputFile, StringRef isysroot,
954  std::shared_ptr<PCHBuffer> Buffer,
955  ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
956  bool AllowASTWithErrors = false, bool IncludeTimestamps = true);
957  ~PCHGenerator() override;
958  void InitializeSema(Sema &S) override { SemaPtr = &S; }
959  void HandleTranslationUnit(ASTContext &Ctx) override;
962  bool hasEmittedPCH() const { return Buffer->IsComplete; }
963 };
964 
965 } // end namespace clang
966 
967 #endif
unsigned getDeclParmVarAbbrev() const
Definition: ASTWriter.h:658
unsigned getAnonymousDeclarationNumber(const NamedDecl *D)
Definition: ASTWriter.cpp:5485
uint64_t getMacroDirectivesOffset(const IdentifierInfo *Name)
Definition: ASTWriter.cpp:5228
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1618
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.
ASTWriter(llvm::BitstreamWriter &Stream, SmallVectorImpl< char > &Buffer, MemoryBufferCache &PCMCache, ArrayRef< std::shared_ptr< ModuleFileExtension >> Extensions, bool IncludeTimestamps=true)
Create a new precompiled header writer that outputs to the given bitstream.
Definition: ASTWriter.cpp:4439
Smart pointer class that efficiently represents Objective-C method names.
A (possibly-)qualified type.
Definition: Type.h:616
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:26
void AddToken(const Token &Tok, RecordDataImpl &Record)
Emit a token.
Definition: ASTWriter.cpp:4355
A structure for putting "fast"-unqualified QualTypes into a DenseMap.
Definition: ASTBitCodes.h:106
const unsigned NUM_PREDEF_TYPE_IDS
The number of predefined type IDs that are reserved for the PREDEF_TYPE_* constants.
Definition: ASTBitCodes.h:840
unsigned getTypeExtQualAbbrev() const
Definition: ASTWriter.h:651
Stmt - This represents one statement.
Definition: Stmt.h:60
void AddUnresolvedSet(const ASTUnresolvedSet &Set)
Emit a UnresolvedSet structure.
Definition: ASTWriter.cpp:5775
void AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS)
Emit a nested name specifier with source-location information.
Definition: ASTWriter.cpp:5597
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:4455
void InitializeSema(Sema &S) override
Initialize the semantic consumer with the Sema instance being used to perform semantic analysis on th...
Definition: ASTWriter.h:958
const unsigned int NUM_PREDEF_SELECTOR_IDS
The number of predefined selector IDs.
Definition: ASTBitCodes.h:145
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:81
uint64_t & operator[](size_t N)
Definition: ASTWriter.h:774
unsigned getDeclRefExprAbbrev() const
Definition: ASTWriter.h:667
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
Definition: ASTBitCodes.h:63
std::unique_ptr< llvm::MemoryBuffer > Buffer
Declaration of a variable template.
serialization::DeclID GetDeclRef(const Decl *D)
Force a declaration to be emitted and get its ID.
Definition: ASTWriter.cpp:5361
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
A container of type source information.
Definition: Decl.h:62
void AddTypeRef(QualType T, RecordDataImpl &Record)
Emit a reference to a type.
Definition: ASTWriter.cpp:5317
uint64_t Emit(unsigned Code, unsigned Abbrev=0)
Emit the record to the stream, followed by its substatements, and return its offset.
Definition: ASTWriter.h:780
serialization::MacroID getMacroRef(MacroInfo *MI, const IdentifierInfo *Name)
Get the unique number used to refer to the given macro.
Definition: ASTWriter.cpp:5204
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:758
void AddFunctionDefinition(const FunctionDecl *FD)
Add a definition for the given function to the queue of statements to emit.
Manage memory buffers across multiple users.
const unsigned int NUM_PREDEF_DECL_IDS
The number of declaration IDs that are predefined.
Definition: ASTBitCodes.h:1031
Represents a variable template specialization, which refers to a variable template with a given set o...
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:573
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:50
serialization::IdentID getIdentifierRef(const IdentifierInfo *II)
Get the unique number used to refer to the given identifier.
Definition: ASTWriter.cpp:5194
ParmVarDecl - Represents a parameter to a function.
Definition: Decl.h:1434
void AddString(StringRef Str)
Emit a string.
Definition: ASTWriter.h:917
void AddSourceRange(SourceRange Range)
Emit a source range.
Definition: ASTWriter.h:824
void AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record)
Emit a reference to an identifier.
Definition: ASTWriter.cpp:5190
void AddTypeSourceInfo(TypeSourceInfo *TInfo)
Emits a reference to a declarator info.
Definition: ASTWriter.cpp:5300
PCHGenerator(const Preprocessor &PP, StringRef OutputFile, StringRef isysroot, std::shared_ptr< PCHBuffer > Buffer, ArrayRef< std::shared_ptr< ModuleFileExtension >> Extensions, bool AllowASTWithErrors=false, bool IncludeTimestamps=true)
Definition: GeneratePCH.cpp:24
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:40
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3354
Represents a class template specialization, which refers to a class template with a given set of temp...
One of these records is kept for each identifier that is lexed.
ASTRecordWriter(ASTRecordWriter &Parent, ASTWriter::RecordDataImpl &Record)
Construct a ASTRecordWriter that uses the same encoding scheme as another ASTRecordWriter.
Definition: ASTWriter.h:755
unsigned getDeclVarAbbrev() const
Definition: ASTWriter.h:661
time_t getTimestampForOutput(const FileEntry *E) const
Get a timestamp for output into the AST file.
Definition: ASTWriter.cpp:4460
void AddTypeRef(QualType T)
Emit a reference to a type.
Definition: ASTWriter.h:855
unsigned getDeclRecordAbbrev() const
Definition: ASTWriter.h:659
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:128
A C++ nested-name-specifier augmented with source location information.
Record the location of a macro definition.
void HandleTranslationUnit(ASTContext &Ctx) override
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
Definition: GeneratePCH.cpp:40
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
unsigned getDeclEnumAbbrev() const
Definition: ASTWriter.h:663
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
Definition: Decl.h:2366
~PCHGenerator() override
Definition: GeneratePCH.cpp:37
~ASTWriter() override
Definition: ASTWriter.cpp:4451
void AddTemplateParameterList(const TemplateParameterList *TemplateParams)
Emit a template parameter list.
Definition: ASTWriter.cpp:5743
Describes a module or submodule.
Definition: Module.h:57
void AddIdentifierRef(const IdentifierInfo *II)
Emit a reference to an identifier.
Definition: ASTWriter.h:838
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:5220
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:85
void append(InputIterator begin, InputIterator end)
Definition: ASTWriter.h:769
uint32_t Offset
Definition: CacheTokens.cpp:43
void AddSourceRange(SourceRange Range, RecordDataImpl &Record)
Emit a source range.
Definition: ASTWriter.cpp:5170
void AddCXXCtorInitializers(ArrayRef< CXXCtorInitializer * > CtorInits)
Emit a CXXCtorInitializer array.
Definition: ASTWriter.cpp:5849
void AddTypeLoc(TypeLoc TL)
Emits a type with source-location information.
Definition: ASTWriter.cpp:5309
void AddAttributes(ArrayRef< const Attr * > Attrs)
Emit a list of attributes.
Definition: ASTWriter.cpp:4343
unsigned getDeclObjCIvarAbbrev() const
Definition: ASTWriter.h:664
Represents an ObjC class declaration.
Definition: DeclObjC.h:1108
detail::InMemoryDirectory::const_iterator I
serialization::TypeID getTypeID(QualType T) const
Determine the type ID of an already-emitted type.
Definition: ASTWriter.cpp:5344
unsigned RecordSwitchCaseID(SwitchCase *S)
Record an ID for the given switch-case statement.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:269
void AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, DeclarationName Name)
Definition: ASTWriter.cpp:5506
void AddCXXTemporary(const CXXTemporary *Temp)
Emit a CXXTemporary.
Definition: ASTWriter.cpp:5255
unsigned getCharacterLiteralAbbrev() const
Definition: ASTWriter.h:668
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:4391
ASTDeserializationListener * GetASTDeserializationListener() override
If the consumer is interested in entities being deserialized from AST files, it should return a point...
Definition: GeneratePCH.cpp:74
bool hasEmittedPCH() const
Definition: ASTWriter.h:962
void AddCXXDefinitionData(const CXXRecordDecl *D)
Definition: ASTWriter.cpp:5854
unsigned getExprImplicitCastAbbrev() const
Definition: ASTWriter.h:670
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2551
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:5321
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
FormatToken * Token
Represents a C++ template name within the type system.
Definition: TemplateName.h:176
void AddString(StringRef Str, RecordDataImpl &Record)
Add a string to the given record.
Definition: ASTWriter.cpp:4368
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:2669
void AddPath(StringRef Path)
Emit a path.
Definition: ASTWriter.h:922
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Definition: DeclBase.h:681
void AddDeclRef(const Decl *D)
Emit a reference to a declaration.
Definition: ASTWriter.h:877
unsigned getDeclFieldAbbrev() const
Definition: ASTWriter.h:662
void AddQualifierInfo(const QualifierInfo &Info)
Definition: ASTWriter.cpp:5544
void AddStmt(Stmt *S)
Add the given statement or expression to the queue of statements to emit.
Definition: ASTWriter.h:810
bool hasChain() const
Definition: ASTWriter.h:672
void AddSelectorRef(Selector S)
Emit a Selector (which is a smart pointer reference).
Definition: ASTWriter.cpp:5232
The result type of a method or function.
SmallVectorImpl< char > & getPCH() const
Definition: ASTWriter.h:950
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:5165
void push_back(uint64_t N)
Minimal vector-like interface.
Definition: ASTWriter.h:767
const unsigned int NUM_PREDEF_IDENT_IDS
The number of predefined identifier IDs.
Definition: ASTBitCodes.h:126
QualifierInfo - A struct with extended info about a syntactic name qualifier, to be used for the case...
Definition: Decl.h:603
const Decl * getFirstLocalDecl(const Decl *D)
Find the first local declaration of a given local redeclarable decl.
#define false
Definition: stdbool.h:33
Kind
Encodes a location in the source.
void AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, const TemplateArgumentLocInfo &Arg)
Emits a template argument location info.
Definition: ASTWriter.cpp:5259
Represents a C++ temporary.
Definition: ExprCXX.h:1103
void AddDeclarationName(DeclarationName Name)
Emit a declaration name.
Definition: ASTWriter.cpp:5447
const std::string ID
void AddOffset(uint64_t BitOffset)
Add a bit offset into the record.
Definition: ASTWriter.h:798
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2816
void AddTemplateArgument(const TemplateArgument &Arg)
Emit a template argument.
Definition: ASTWriter.cpp:5703
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2189
unsigned getIntegerLiteralAbbrev() const
Definition: ASTWriter.h:669
void AddNestedNameSpecifier(NestedNameSpecifier *NNS)
Emit a nested name specifier.
Definition: ASTWriter.cpp:5551
bool empty() const
Definition: ASTWriter.h:772
uint32_t MacroID
An ID number that refers to a macro in an AST file.
Definition: ASTBitCodes.h:129
void AddVersionTuple(const VersionTuple &Version, RecordDataImpl &Record)
Add a version tuple to the given record.
Definition: ASTWriter.cpp:4404
void AddSourceLocation(SourceLocation Loc)
Emit a source location.
Definition: ASTWriter.h:819
void AddDeclRef(const Decl *D, RecordDataImpl &Record)
Emit a reference to a declaration.
Definition: ASTWriter.cpp:5357
void AddAPFloat(const llvm::APFloat &Value)
Emit a floating-point value.
Definition: ASTWriter.cpp:5186
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:4373
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:665
void AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo)
Definition: ASTWriter.cpp:5537
SmallVectorImpl< uint64_t > RecordDataImpl
Definition: ASTWriter.h:86
DeclarationNameLoc - Additional source/type location info for a declaration name. ...
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:70
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:4419
Represents a template argument.
Definition: TemplateBase.h:40
const ASTWriter & getWriter() const
Definition: ASTWriter.h:949
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1215
StringRef Name
Definition: USRFinder.cpp:123
unsigned getDeclCXXMethodAbbrev() const
Definition: ASTWriter.h:665
void AddCXXBaseSpecifiers(ArrayRef< CXXBaseSpecifier > Bases)
Emit a set of C++ base specifiers.
Definition: ASTWriter.cpp:5809
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:328
DeclarationName - The name of a declaration.
detail::InMemoryDirectory::const_iterator E
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
SourceMgr(SourceMgr)
void AddVersionTuple(const VersionTuple &Version)
Emit a version tuple.
Definition: ASTWriter.h:927
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:592
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:34
unsigned getTypeFunctionProtoAbbrev() const
Definition: ASTWriter.h:654
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:428
ASTWriter::RecordDataImpl & getRecordData() const
Extract the underlying record storage.
Definition: ASTWriter.h:763
An UnresolvedSet-like class which uses the ASTContext's allocator.
const unsigned int NUM_PREDEF_MACRO_IDS
The number of predefined macro IDs.
Definition: ASTBitCodes.h:139
void AddAPSInt(const llvm::APSInt &Value)
Emit a signed integral value.
Definition: ASTWriter.cpp:5181
size_t size() const
Definition: ASTWriter.h:773
uint64_t EmitStmt(unsigned Code, unsigned Abbrev=0)
Emit the record to the stream, preceded by its substatements.
Definition: ASTWriter.h:789
serialization::SelectorID getSelectorRef(Selector Sel)
Get the unique number used to refer to the given selector.
Definition: ASTWriter.cpp:5236
void EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record, StringRef Path)
Emit the current record with the given path as a blob.
Definition: ASTWriter.cpp:4397
Represents a base class of a C++ class.
Definition: DeclCXX.h:158
A template argument list.
Definition: DeclTemplate.h:195
uint32_t PreprocessedEntityID
An ID number that refers to an entity in the detailed preprocessing record.
Definition: ASTBitCodes.h:157
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:4429
Represents a C++ struct/union/class.
Definition: DeclCXX.h:267
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
Definition: ASTBitCodes.h:142
An object for streaming information to a record.
Definition: ASTWriter.h:719
ASTFileSignature 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:4464
Location information for a TemplateArgument.
Definition: TemplateBase.h:369
void operator=(const ASTRecordWriter &)=delete
Declaration of a class template.
ASTReader * getChain() const
Definition: ASTWriter.h:673
Writes an AST file containing the contents of a translation unit.
Definition: ASTWriter.h:82
ArrayRef< uint64_t > RecordDataRef
Definition: ASTWriter.h:87
serialization::DeclID getDeclID(const Decl *D)
Determine the declaration ID of an already-emitted declaration.
Definition: ASTWriter.cpp:5390
void AddCXXBaseSpecifier(const CXXBaseSpecifier &Base)
Emit a C++ base specifier.
Definition: ASTWriter.cpp:5785
void AddASTTemplateArgumentListInfo(const ASTTemplateArgumentListInfo *ASTTemplArgList)
Emits an AST template argument list info.
Definition: ASTWriter.cpp:5764
void AddAPInt(const llvm::APInt &Value)
Emit an integral value.
Definition: ASTWriter.cpp:5175
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:897
unsigned getDeclTypedefAbbrev() const
Definition: ASTWriter.h:660
void AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs)
Emit a template argument list.
Definition: ASTWriter.cpp:5756
AST and semantic-analysis consumer that generates a precompiled header from the parsed source code...
Definition: ASTWriter.h:937
void AddTemplateName(TemplateName Name)
Emit a template name.
Definition: ASTWriter.cpp:5650
void AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg)
Emits a template argument location.
Definition: ASTWriter.cpp:5287
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
A trivial tuple used to represent a source range.
NamedDecl - This represents a decl with a name.
Definition: Decl.h:213
ASTWriter & getWriter()
Definition: ASTWriter.h:948
ASTRecordWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record)
Construct a ASTRecordWriter that uses the default encoding scheme.
Definition: ASTWriter.h:750
Declaration of a template function.
Definition: DeclTemplate.h:939
A type index; the type ID with the qualifier bits removed.
Definition: ASTBitCodes.h:83
Attr - This represents one attribute.
Definition: Attr.h:43
const unsigned int NUM_PREDEF_SUBMODULE_IDS
The number of predefined submodule IDs.
Definition: ASTBitCodes.h:163
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:98