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