clang  6.0.0svn
ASTReader.h
Go to the documentation of this file.
1 //===- ASTReader.h - AST File Reader ----------------------------*- 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 ASTReader class, which reads AST files.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_SERIALIZATION_ASTREADER_H
15 #define LLVM_CLANG_SERIALIZATION_ASTREADER_H
16 
17 #include "clang/AST/DeclObjC.h"
19 #include "clang/AST/TemplateBase.h"
20 #include "clang/AST/TemplateName.h"
21 #include "clang/AST/Type.h"
22 #include "clang/Basic/Diagnostic.h"
26 #include "clang/Basic/Module.h"
29 #include "clang/Basic/Version.h"
32 #include "clang/Lex/HeaderSearch.h"
34 #include "clang/Lex/Token.h"
42 #include "llvm/ADT/APFloat.h"
43 #include "llvm/ADT/APInt.h"
44 #include "llvm/ADT/APSInt.h"
45 #include "llvm/ADT/ArrayRef.h"
46 #include "llvm/ADT/DenseMap.h"
47 #include "llvm/ADT/DenseSet.h"
48 #include "llvm/ADT/IntrusiveRefCntPtr.h"
49 #include "llvm/ADT/MapVector.h"
50 #include "llvm/ADT/Optional.h"
51 #include "llvm/ADT/STLExtras.h"
52 #include "llvm/ADT/SetVector.h"
53 #include "llvm/ADT/SmallPtrSet.h"
54 #include "llvm/ADT/SmallVector.h"
55 #include "llvm/ADT/StringMap.h"
56 #include "llvm/ADT/StringRef.h"
57 #include "llvm/ADT/iterator.h"
58 #include "llvm/ADT/iterator_range.h"
59 #include "llvm/Bitcode/BitstreamReader.h"
60 #include "llvm/Support/Casting.h"
61 #include "llvm/Support/Endian.h"
62 #include "llvm/Support/MemoryBuffer.h"
63 #include "llvm/Support/Timer.h"
64 #include <cassert>
65 #include <cstddef>
66 #include <cstdint>
67 #include <ctime>
68 #include <deque>
69 #include <memory>
70 #include <set>
71 #include <string>
72 #include <utility>
73 #include <vector>
74 
75 namespace clang {
76 
77 class ASTConsumer;
78 class ASTContext;
79 class ASTDeserializationListener;
80 class ASTReader;
81 class ASTRecordReader;
82 class CXXBaseSpecifier;
83 class CXXConstructorDecl;
84 class CXXCtorInitializer;
85 class CXXTemporary;
86 class Decl;
87 class DeclaratorDecl;
88 class DeclContext;
89 class EnumDecl;
90 class Expr;
91 class FieldDecl;
92 class FileEntry;
93 class FileManager;
94 class FileSystemOptions;
95 class FunctionDecl;
96 class GlobalModuleIndex;
97 struct HeaderFileInfo;
98 class HeaderSearchOptions;
99 class LangOptions;
100 class LazyASTUnresolvedSet;
101 class MacroInfo;
102 class MemoryBufferCache;
103 class NamedDecl;
104 class NamespaceDecl;
105 class NestedNameSpecifier;
106 class ObjCCategoryDecl;
107 class ObjCInterfaceDecl;
108 class PCHContainerReader;
109 class Preprocessor;
110 class PreprocessorOptions;
111 struct QualifierInfo;
112 class Sema;
113 class SourceManager;
114 class Stmt;
115 class SwitchCase;
116 class TargetOptions;
117 class TemplateParameterList;
118 class TypedefNameDecl;
119 class TypeSourceInfo;
120 class ValueDecl;
121 class VarDecl;
122 
123 /// \brief Abstract interface for callback invocations by the ASTReader.
124 ///
125 /// While reading an AST file, the ASTReader will call the methods of the
126 /// listener to pass on specific information. Some of the listener methods can
127 /// return true to indicate to the ASTReader that the information (and
128 /// consequently the AST file) is invalid.
130 public:
131  virtual ~ASTReaderListener();
132 
133  /// \brief Receives the full Clang version information.
134  ///
135  /// \returns true to indicate that the version is invalid. Subclasses should
136  /// generally defer to this implementation.
137  virtual bool ReadFullVersionInformation(StringRef FullVersion) {
138  return FullVersion != getClangFullRepositoryVersion();
139  }
140 
141  virtual void ReadModuleName(StringRef ModuleName) {}
142  virtual void ReadModuleMapFile(StringRef ModuleMapPath) {}
143 
144  /// \brief Receives the language options.
145  ///
146  /// \returns true to indicate the options are invalid or false otherwise.
147  virtual bool ReadLanguageOptions(const LangOptions &LangOpts,
148  bool Complain,
149  bool AllowCompatibleDifferences) {
150  return false;
151  }
152 
153  /// \brief Receives the target options.
154  ///
155  /// \returns true to indicate the target options are invalid, or false
156  /// otherwise.
157  virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
158  bool AllowCompatibleDifferences) {
159  return false;
160  }
161 
162  /// \brief Receives the diagnostic options.
163  ///
164  /// \returns true to indicate the diagnostic options are invalid, or false
165  /// otherwise.
166  virtual bool
168  bool Complain) {
169  return false;
170  }
171 
172  /// \brief Receives the file system options.
173  ///
174  /// \returns true to indicate the file system options are invalid, or false
175  /// otherwise.
176  virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
177  bool Complain) {
178  return false;
179  }
180 
181  /// \brief Receives the header search options.
182  ///
183  /// \returns true to indicate the header search options are invalid, or false
184  /// otherwise.
185  virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
186  StringRef SpecificModuleCachePath,
187  bool Complain) {
188  return false;
189  }
190 
191  /// \brief Receives the preprocessor options.
192  ///
193  /// \param SuggestedPredefines Can be filled in with the set of predefines
194  /// that are suggested by the preprocessor options. Typically only used when
195  /// loading a precompiled header.
196  ///
197  /// \returns true to indicate the preprocessor options are invalid, or false
198  /// otherwise.
199  virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
200  bool Complain,
201  std::string &SuggestedPredefines) {
202  return false;
203  }
204 
205  /// \brief Receives __COUNTER__ value.
206  virtual void ReadCounter(const serialization::ModuleFile &M,
207  unsigned Value) {}
208 
209  /// This is called for each AST file loaded.
210  virtual void visitModuleFile(StringRef Filename,
212 
213  /// \brief Returns true if this \c ASTReaderListener wants to receive the
214  /// input files of the AST file via \c visitInputFile, false otherwise.
215  virtual bool needsInputFileVisitation() { return false; }
216 
217  /// \brief Returns true if this \c ASTReaderListener wants to receive the
218  /// system input files of the AST file via \c visitInputFile, false otherwise.
219  virtual bool needsSystemInputFileVisitation() { return false; }
220 
221  /// \brief if \c needsInputFileVisitation returns true, this is called for
222  /// each non-system input file of the AST File. If
223  /// \c needsSystemInputFileVisitation is true, then it is called for all
224  /// system input files as well.
225  ///
226  /// \returns true to continue receiving the next input file, false to stop.
227  virtual bool visitInputFile(StringRef Filename, bool isSystem,
228  bool isOverridden, bool isExplicitModule) {
229  return true;
230  }
231 
232  /// \brief Returns true if this \c ASTReaderListener wants to receive the
233  /// imports of the AST file via \c visitImport, false otherwise.
234  virtual bool needsImportVisitation() const { return false; }
235 
236  /// \brief If needsImportVisitation returns \c true, this is called for each
237  /// AST file imported by this AST file.
238  virtual void visitImport(StringRef Filename) {}
239 
240  /// Indicates that a particular module file extension has been read.
242  const ModuleFileExtensionMetadata &Metadata) {}
243 };
244 
245 /// \brief Simple wrapper class for chaining listeners.
247  std::unique_ptr<ASTReaderListener> First;
248  std::unique_ptr<ASTReaderListener> Second;
249 
250 public:
251  /// Takes ownership of \p First and \p Second.
252  ChainedASTReaderListener(std::unique_ptr<ASTReaderListener> First,
253  std::unique_ptr<ASTReaderListener> Second)
254  : First(std::move(First)), Second(std::move(Second)) {}
255 
256  std::unique_ptr<ASTReaderListener> takeFirst() { return std::move(First); }
257  std::unique_ptr<ASTReaderListener> takeSecond() { return std::move(Second); }
258 
259  bool ReadFullVersionInformation(StringRef FullVersion) override;
260  void ReadModuleName(StringRef ModuleName) override;
261  void ReadModuleMapFile(StringRef ModuleMapPath) override;
262  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
263  bool AllowCompatibleDifferences) override;
264  bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
265  bool AllowCompatibleDifferences) override;
267  bool Complain) override;
268  bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
269  bool Complain) override;
270 
271  bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
272  StringRef SpecificModuleCachePath,
273  bool Complain) override;
274  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
275  bool Complain,
276  std::string &SuggestedPredefines) override;
277 
278  void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
279  bool needsInputFileVisitation() override;
280  bool needsSystemInputFileVisitation() override;
281  void visitModuleFile(StringRef Filename,
283  bool visitInputFile(StringRef Filename, bool isSystem,
284  bool isOverridden, bool isExplicitModule) override;
286  const ModuleFileExtensionMetadata &Metadata) override;
287 };
288 
289 /// \brief ASTReaderListener implementation to validate the information of
290 /// the PCH file against an initialized Preprocessor.
292  Preprocessor &PP;
293  ASTReader &Reader;
294 
295 public:
297  : PP(PP), Reader(Reader) {}
298 
299  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
300  bool AllowCompatibleDifferences) override;
301  bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
302  bool AllowCompatibleDifferences) override;
304  bool Complain) override;
305  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain,
306  std::string &SuggestedPredefines) override;
307  bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
308  StringRef SpecificModuleCachePath,
309  bool Complain) override;
310  void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
311 
312 private:
313  void Error(const char *Msg);
314 };
315 
316 /// \brief ASTReaderListenter implementation to set SuggestedPredefines of
317 /// ASTReader which is required to use a pch file. This is the replacement
318 /// of PCHValidator or SimplePCHValidator when using a pch file without
319 /// validating it.
321  Preprocessor &PP;
322 
323 public:
325  : PP(PP) {}
326 
327  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain,
328  std::string &SuggestedPredefines) override;
329 };
330 
331 namespace serialization {
332 
333 class ReadMethodPoolVisitor;
334 
335 namespace reader {
336 
338 
339 /// \brief The on-disk hash table(s) used for DeclContext name lookup.
341 
342 } // namespace reader
343 
344 } // namespace serialization
345 
346 /// \brief Reads an AST files chain containing the contents of a translation
347 /// unit.
348 ///
349 /// The ASTReader class reads bitstreams (produced by the ASTWriter
350 /// class) containing the serialized representation of a given
351 /// abstract syntax tree and its supporting data structures. An
352 /// instance of the ASTReader can be attached to an ASTContext object,
353 /// which will provide access to the contents of the AST files.
354 ///
355 /// The AST reader provides lazy de-serialization of declarations, as
356 /// required when traversing the AST. Only those AST nodes that are
357 /// actually required will be de-serialized.
362  public ExternalSemaSource,
363  public IdentifierInfoLookup,
365 {
366 public:
367  /// \brief Types of AST files.
368  friend class ASTDeclReader;
369  friend class ASTIdentifierIterator;
370  friend class ASTRecordReader;
371  friend class ASTStmtReader;
372  friend class ASTUnit; // ASTUnit needs to remap source locations.
373  friend class ASTWriter;
374  friend class PCHValidator;
377  friend class TypeLocReader;
378 
381 
382  /// \brief The result of reading the control block of an AST file, which
383  /// can fail for various reasons.
385  /// \brief The control block was read successfully. Aside from failures,
386  /// the AST file is safe to read into the current context.
388 
389  /// \brief The AST file itself appears corrupted.
391 
392  /// \brief The AST file was missing.
394 
395  /// \brief The AST file is out-of-date relative to its input files,
396  /// and needs to be regenerated.
398 
399  /// \brief The AST file was written by a different version of Clang.
401 
402  /// \brief The AST file was writtten with a different language/target
403  /// configuration.
405 
406  /// \brief The AST file has errors.
407  HadErrors
408  };
409 
416 
417 private:
418  /// \brief The receiver of some callbacks invoked by ASTReader.
419  std::unique_ptr<ASTReaderListener> Listener;
420 
421  /// \brief The receiver of deserialization events.
422  ASTDeserializationListener *DeserializationListener = nullptr;
423 
424  bool OwnsDeserializationListener = false;
425 
426  SourceManager &SourceMgr;
427  FileManager &FileMgr;
428  const PCHContainerReader &PCHContainerRdr;
429  DiagnosticsEngine &Diags;
430 
431  /// \brief The semantic analysis object that will be processing the
432  /// AST files and the translation unit that uses it.
433  Sema *SemaObj = nullptr;
434 
435  /// \brief The preprocessor that will be loading the source file.
436  Preprocessor &PP;
437 
438  /// \brief The AST context into which we'll read the AST files.
439  ASTContext *ContextObj = nullptr;
440 
441  /// \brief The AST consumer.
442  ASTConsumer *Consumer = nullptr;
443 
444  /// \brief The module manager which manages modules and their dependencies
445  ModuleManager ModuleMgr;
446 
447  /// The cache that manages memory buffers for PCM files.
448  MemoryBufferCache &PCMCache;
449 
450  /// \brief A dummy identifier resolver used to merge TU-scope declarations in
451  /// C, for the cases where we don't have a Sema object to provide a real
452  /// identifier resolver.
453  IdentifierResolver DummyIdResolver;
454 
455  /// A mapping from extension block names to module file extensions.
456  llvm::StringMap<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions;
457 
458  /// \brief A timer used to track the time spent deserializing.
459  std::unique_ptr<llvm::Timer> ReadTimer;
460 
461  /// \brief The location where the module file will be considered as
462  /// imported from. For non-module AST types it should be invalid.
463  SourceLocation CurrentImportLoc;
464 
465  /// \brief The global module index, if loaded.
466  std::unique_ptr<GlobalModuleIndex> GlobalIndex;
467 
468  /// \brief A map of global bit offsets to the module that stores entities
469  /// at those bit offsets.
471 
472  /// \brief A map of negated SLocEntryIDs to the modules containing them.
474 
477 
478  /// \brief A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset)
479  /// SourceLocation offsets to the modules containing them.
480  GlobalSLocOffsetMapType GlobalSLocOffsetMap;
481 
482  /// \brief Types that have already been loaded from the chain.
483  ///
484  /// When the pointer at index I is non-NULL, the type with
485  /// ID = (I + 1) << FastQual::Width has already been loaded
486  std::vector<QualType> TypesLoaded;
487 
488  using GlobalTypeMapType =
490 
491  /// \brief Mapping from global type IDs to the module in which the
492  /// type resides along with the offset that should be added to the
493  /// global type ID to produce a local ID.
494  GlobalTypeMapType GlobalTypeMap;
495 
496  /// \brief Declarations that have already been loaded from the chain.
497  ///
498  /// When the pointer at index I is non-NULL, the declaration with ID
499  /// = I + 1 has already been loaded.
500  std::vector<Decl *> DeclsLoaded;
501 
502  using GlobalDeclMapType =
504 
505  /// \brief Mapping from global declaration IDs to the module in which the
506  /// declaration resides.
507  GlobalDeclMapType GlobalDeclMap;
508 
509  using FileOffset = std::pair<ModuleFile *, uint64_t>;
511  using DeclUpdateOffsetsMap =
512  llvm::DenseMap<serialization::DeclID, FileOffsetsTy>;
513 
514  /// \brief Declarations that have modifications residing in a later file
515  /// in the chain.
516  DeclUpdateOffsetsMap DeclUpdateOffsets;
517 
518  struct PendingUpdateRecord {
519  Decl *D;
521 
522  // Whether the declaration was just deserialized.
523  bool JustLoaded;
524 
525  PendingUpdateRecord(serialization::GlobalDeclID ID, Decl *D,
526  bool JustLoaded)
527  : D(D), ID(ID), JustLoaded(JustLoaded) {}
528  };
529 
530  /// \brief Declaration updates for already-loaded declarations that we need
531  /// to apply once we finish processing an import.
532  llvm::SmallVector<PendingUpdateRecord, 16> PendingUpdateRecords;
533 
534  enum class PendingFakeDefinitionKind { NotFake, Fake, FakeLoaded };
535 
536  /// \brief The DefinitionData pointers that we faked up for class definitions
537  /// that we needed but hadn't loaded yet.
538  llvm::DenseMap<void *, PendingFakeDefinitionKind> PendingFakeDefinitionData;
539 
540  /// \brief Exception specification updates that have been loaded but not yet
541  /// propagated across the relevant redeclaration chain. The map key is the
542  /// canonical declaration (used only for deduplication) and the value is a
543  /// declaration that has an exception specification.
544  llvm::SmallMapVector<Decl *, FunctionDecl *, 4> PendingExceptionSpecUpdates;
545 
546  /// \brief Declarations that have been imported and have typedef names for
547  /// linkage purposes.
548  llvm::DenseMap<std::pair<DeclContext *, IdentifierInfo *>, NamedDecl *>
549  ImportedTypedefNamesForLinkage;
550 
551  /// \brief Mergeable declaration contexts that have anonymous declarations
552  /// within them, and those anonymous declarations.
553  llvm::DenseMap<DeclContext*, llvm::SmallVector<NamedDecl*, 2>>
554  AnonymousDeclarationsForMerging;
555 
556  struct FileDeclsInfo {
557  ModuleFile *Mod = nullptr;
559 
560  FileDeclsInfo() = default;
561  FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls)
562  : Mod(Mod), Decls(Decls) {}
563  };
564 
565  /// \brief Map from a FileID to the file-level declarations that it contains.
566  llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs;
567 
568  /// \brief An array of lexical contents of a declaration context, as a sequence of
569  /// Decl::Kind, DeclID pairs.
571 
572  /// \brief Map from a DeclContext to its lexical contents.
573  llvm::DenseMap<const DeclContext*, std::pair<ModuleFile*, LexicalContents>>
574  LexicalDecls;
575 
576  /// \brief Map from the TU to its lexical contents from each module file.
577  std::vector<std::pair<ModuleFile*, LexicalContents>> TULexicalDecls;
578 
579  /// \brief Map from a DeclContext to its lookup tables.
580  llvm::DenseMap<const DeclContext *,
582 
583  // Updates for visible decls can occur for other contexts than just the
584  // TU, and when we read those update records, the actual context may not
585  // be available yet, so have this pending map using the ID as a key. It
586  // will be realized when the context is actually loaded.
587  struct PendingVisibleUpdate {
588  ModuleFile *Mod;
589  const unsigned char *Data;
590  };
592 
593  /// \brief Updates to the visible declarations of declaration contexts that
594  /// haven't been loaded yet.
595  llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates>
596  PendingVisibleUpdates;
597 
598  /// \brief The set of C++ or Objective-C classes that have forward
599  /// declarations that have not yet been linked to their definitions.
600  llvm::SmallPtrSet<Decl *, 4> PendingDefinitions;
601 
602  using PendingBodiesMap =
603  llvm::MapVector<Decl *, uint64_t,
604  llvm::SmallDenseMap<Decl *, unsigned, 4>,
606 
607  /// \brief Functions or methods that have bodies that will be attached.
608  PendingBodiesMap PendingBodies;
609 
610  /// \brief Definitions for which we have added merged definitions but not yet
611  /// performed deduplication.
612  llvm::SetVector<NamedDecl *> PendingMergedDefinitionsToDeduplicate;
613 
614  /// \brief Read the record that describes the lexical contents of a DC.
615  bool ReadLexicalDeclContextStorage(ModuleFile &M,
616  llvm::BitstreamCursor &Cursor,
617  uint64_t Offset, DeclContext *DC);
618 
619  /// \brief Read the record that describes the visible contents of a DC.
620  bool ReadVisibleDeclContextStorage(ModuleFile &M,
621  llvm::BitstreamCursor &Cursor,
622  uint64_t Offset, serialization::DeclID ID);
623 
624  /// \brief A vector containing identifiers that have already been
625  /// loaded.
626  ///
627  /// If the pointer at index I is non-NULL, then it refers to the
628  /// IdentifierInfo for the identifier with ID=I+1 that has already
629  /// been loaded.
630  std::vector<IdentifierInfo *> IdentifiersLoaded;
631 
634 
635  /// \brief Mapping from global identifier IDs to the module in which the
636  /// identifier resides along with the offset that should be added to the
637  /// global identifier ID to produce a local ID.
638  GlobalIdentifierMapType GlobalIdentifierMap;
639 
640  /// \brief A vector containing macros that have already been
641  /// loaded.
642  ///
643  /// If the pointer at index I is non-NULL, then it refers to the
644  /// MacroInfo for the identifier with ID=I+1 that has already
645  /// been loaded.
646  std::vector<MacroInfo *> MacrosLoaded;
647 
648  using LoadedMacroInfo =
649  std::pair<IdentifierInfo *, serialization::SubmoduleID>;
650 
651  /// \brief A set of #undef directives that we have loaded; used to
652  /// deduplicate the same #undef information coming from multiple module
653  /// files.
654  llvm::DenseSet<LoadedMacroInfo> LoadedUndefs;
655 
656  using GlobalMacroMapType =
658 
659  /// \brief Mapping from global macro IDs to the module in which the
660  /// macro resides along with the offset that should be added to the
661  /// global macro ID to produce a local ID.
662  GlobalMacroMapType GlobalMacroMap;
663 
664  /// \brief A vector containing submodules that have already been loaded.
665  ///
666  /// This vector is indexed by the Submodule ID (-1). NULL submodule entries
667  /// indicate that the particular submodule ID has not yet been loaded.
668  SmallVector<Module *, 2> SubmodulesLoaded;
669 
670  using GlobalSubmoduleMapType =
672 
673  /// \brief Mapping from global submodule IDs to the module file in which the
674  /// submodule resides along with the offset that should be added to the
675  /// global submodule ID to produce a local ID.
676  GlobalSubmoduleMapType GlobalSubmoduleMap;
677 
678  /// \brief A set of hidden declarations.
680  using HiddenNamesMapType = llvm::DenseMap<Module *, HiddenNames>;
681 
682  /// \brief A mapping from each of the hidden submodules to the deserialized
683  /// declarations in that submodule that could be made visible.
684  HiddenNamesMapType HiddenNamesMap;
685 
686  /// \brief A module import, export, or conflict that hasn't yet been resolved.
687  struct UnresolvedModuleRef {
688  /// \brief The file in which this module resides.
689  ModuleFile *File;
690 
691  /// \brief The module that is importing or exporting.
692  Module *Mod;
693 
694  /// \brief The kind of module reference.
695  enum { Import, Export, Conflict } Kind;
696 
697  /// \brief The local ID of the module that is being exported.
698  unsigned ID;
699 
700  /// \brief Whether this is a wildcard export.
701  unsigned IsWildcard : 1;
702 
703  /// \brief String data.
704  StringRef String;
705  };
706 
707  /// \brief The set of module imports and exports that still need to be
708  /// resolved.
709  SmallVector<UnresolvedModuleRef, 2> UnresolvedModuleRefs;
710 
711  /// \brief A vector containing selectors that have already been loaded.
712  ///
713  /// This vector is indexed by the Selector ID (-1). NULL selector
714  /// entries indicate that the particular selector ID has not yet
715  /// been loaded.
716  SmallVector<Selector, 16> SelectorsLoaded;
717 
718  using GlobalSelectorMapType =
720 
721  /// \brief Mapping from global selector IDs to the module in which the
722  /// global selector ID to produce a local ID.
723  GlobalSelectorMapType GlobalSelectorMap;
724 
725  /// \brief The generation number of the last time we loaded data from the
726  /// global method pool for this selector.
727  llvm::DenseMap<Selector, unsigned> SelectorGeneration;
728 
729  /// Whether a selector is out of date. We mark a selector as out of date
730  /// if we load another module after the method pool entry was pulled in.
731  llvm::DenseMap<Selector, bool> SelectorOutOfDate;
732 
733  struct PendingMacroInfo {
734  ModuleFile *M;
735  uint64_t MacroDirectivesOffset;
736 
737  PendingMacroInfo(ModuleFile *M, uint64_t MacroDirectivesOffset)
738  : M(M), MacroDirectivesOffset(MacroDirectivesOffset) {}
739  };
740 
741  using PendingMacroIDsMap =
742  llvm::MapVector<IdentifierInfo *, SmallVector<PendingMacroInfo, 2>>;
743 
744  /// \brief Mapping from identifiers that have a macro history to the global
745  /// IDs have not yet been deserialized to the global IDs of those macros.
746  PendingMacroIDsMap PendingMacroIDs;
747 
750 
751  /// \brief Mapping from global preprocessing entity IDs to the module in
752  /// which the preprocessed entity resides along with the offset that should be
753  /// added to the global preprocessing entity ID to produce a local ID.
754  GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
755 
756  /// \name CodeGen-relevant special data
757  /// \brief Fields containing data that is relevant to CodeGen.
758  //@{
759 
760  /// \brief The IDs of all declarations that fulfill the criteria of
761  /// "interesting" decls.
762  ///
763  /// This contains the data loaded from all EAGERLY_DESERIALIZED_DECLS blocks
764  /// in the chain. The referenced declarations are deserialized and passed to
765  /// the consumer eagerly.
766  SmallVector<uint64_t, 16> EagerlyDeserializedDecls;
767 
768  /// \brief The IDs of all tentative definitions stored in the chain.
769  ///
770  /// Sema keeps track of all tentative definitions in a TU because it has to
771  /// complete them and pass them on to CodeGen. Thus, tentative definitions in
772  /// the PCH chain must be eagerly deserialized.
773  SmallVector<uint64_t, 16> TentativeDefinitions;
774 
775  /// \brief The IDs of all CXXRecordDecls stored in the chain whose VTables are
776  /// used.
777  ///
778  /// CodeGen has to emit VTables for these records, so they have to be eagerly
779  /// deserialized.
780  SmallVector<uint64_t, 64> VTableUses;
781 
782  /// \brief A snapshot of the pending instantiations in the chain.
783  ///
784  /// This record tracks the instantiations that Sema has to perform at the
785  /// end of the TU. It consists of a pair of values for every pending
786  /// instantiation where the first value is the ID of the decl and the second
787  /// is the instantiation location.
788  SmallVector<uint64_t, 64> PendingInstantiations;
789 
790  //@}
791 
792  /// \name DiagnosticsEngine-relevant special data
793  /// \brief Fields containing data that is used for generating diagnostics
794  //@{
795 
796  /// \brief A snapshot of Sema's unused file-scoped variable tracking, for
797  /// generating warnings.
798  SmallVector<uint64_t, 16> UnusedFileScopedDecls;
799 
800  /// \brief A list of all the delegating constructors we've seen, to diagnose
801  /// cycles.
802  SmallVector<uint64_t, 4> DelegatingCtorDecls;
803 
804  /// \brief Method selectors used in a @selector expression. Used for
805  /// implementation of -Wselector.
806  SmallVector<uint64_t, 64> ReferencedSelectorsData;
807 
808  /// \brief A snapshot of Sema's weak undeclared identifier tracking, for
809  /// generating warnings.
810  SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers;
811 
812  /// \brief The IDs of type aliases for ext_vectors that exist in the chain.
813  ///
814  /// Used by Sema for finding sugared names for ext_vectors in diagnostics.
815  SmallVector<uint64_t, 4> ExtVectorDecls;
816 
817  //@}
818 
819  /// \name Sema-relevant special data
820  /// \brief Fields containing data that is used for semantic analysis
821  //@{
822 
823  /// \brief The IDs of all potentially unused typedef names in the chain.
824  ///
825  /// Sema tracks these to emit warnings.
826  SmallVector<uint64_t, 16> UnusedLocalTypedefNameCandidates;
827 
828  /// \brief Our current depth in #pragma cuda force_host_device begin/end
829  /// macros.
830  unsigned ForceCUDAHostDeviceDepth = 0;
831 
832  /// \brief The IDs of the declarations Sema stores directly.
833  ///
834  /// Sema tracks a few important decls, such as namespace std, directly.
835  SmallVector<uint64_t, 4> SemaDeclRefs;
836 
837  /// \brief The IDs of the types ASTContext stores directly.
838  ///
839  /// The AST context tracks a few important types, such as va_list, directly.
840  SmallVector<uint64_t, 16> SpecialTypes;
841 
842  /// \brief The IDs of CUDA-specific declarations ASTContext stores directly.
843  ///
844  /// The AST context tracks a few important decls, currently cudaConfigureCall,
845  /// directly.
846  SmallVector<uint64_t, 2> CUDASpecialDeclRefs;
847 
848  /// \brief The floating point pragma option settings.
849  SmallVector<uint64_t, 1> FPPragmaOptions;
850 
851  /// \brief The pragma clang optimize location (if the pragma state is "off").
852  SourceLocation OptimizeOffPragmaLocation;
853 
854  /// \brief The PragmaMSStructKind pragma ms_struct state if set, or -1.
855  int PragmaMSStructState = -1;
856 
857  /// \brief The PragmaMSPointersToMembersKind pragma pointers_to_members state.
858  int PragmaMSPointersToMembersState = -1;
859  SourceLocation PointersToMembersPragmaLocation;
860 
861  /// \brief The pragma pack state.
862  Optional<unsigned> PragmaPackCurrentValue;
863  SourceLocation PragmaPackCurrentLocation;
864  struct PragmaPackStackEntry {
865  unsigned Value;
866  SourceLocation Location;
867  SourceLocation PushLocation;
868  StringRef SlotLabel;
869  };
871  llvm::SmallVector<std::string, 2> PragmaPackStrings;
872 
873  /// \brief The OpenCL extension settings.
874  OpenCLOptions OpenCLExtensions;
875 
876  /// \brief Extensions required by an OpenCL type.
877  llvm::DenseMap<const Type *, std::set<std::string>> OpenCLTypeExtMap;
878 
879  /// \brief Extensions required by an OpenCL declaration.
880  llvm::DenseMap<const Decl *, std::set<std::string>> OpenCLDeclExtMap;
881 
882  /// \brief A list of the namespaces we've seen.
883  SmallVector<uint64_t, 4> KnownNamespaces;
884 
885  /// \brief A list of undefined decls with internal linkage followed by the
886  /// SourceLocation of a matching ODR-use.
887  SmallVector<uint64_t, 8> UndefinedButUsed;
888 
889  /// \brief Delete expressions to analyze at the end of translation unit.
890  SmallVector<uint64_t, 8> DelayedDeleteExprs;
891 
892  // \brief A list of late parsed template function data.
893  SmallVector<uint64_t, 1> LateParsedTemplates;
894 
895 public:
899 
901  : ID(ID), ImportLoc(ImportLoc) {}
902  };
903 
904 private:
905  /// \brief A list of modules that were imported by precompiled headers or
906  /// any other non-module AST file.
907  SmallVector<ImportedSubmodule, 2> ImportedModules;
908  //@}
909 
910  /// \brief The system include root to be used when loading the
911  /// precompiled header.
912  std::string isysroot;
913 
914  /// \brief Whether to disable the normal validation performed on precompiled
915  /// headers when they are loaded.
916  bool DisableValidation;
917 
918  /// \brief Whether to accept an AST file with compiler errors.
919  bool AllowASTWithCompilerErrors;
920 
921  /// \brief Whether to accept an AST file that has a different configuration
922  /// from the current compiler instance.
923  bool AllowConfigurationMismatch;
924 
925  /// \brief Whether validate system input files.
926  bool ValidateSystemInputs;
927 
928  /// \brief Whether we are allowed to use the global module index.
929  bool UseGlobalIndex;
930 
931  /// \brief Whether we have tried loading the global module index yet.
932  bool TriedLoadingGlobalIndex = false;
933 
934  ///\brief Whether we are currently processing update records.
935  bool ProcessingUpdateRecords = false;
936 
937  using SwitchCaseMapTy = llvm::DenseMap<unsigned, SwitchCase *>;
938 
939  /// \brief Mapping from switch-case IDs in the chain to switch-case statements
940  ///
941  /// Statements usually don't have IDs, but switch cases need them, so that the
942  /// switch statement can refer to them.
943  SwitchCaseMapTy SwitchCaseStmts;
944 
945  SwitchCaseMapTy *CurrSwitchCaseStmts;
946 
947  /// \brief The number of source location entries de-serialized from
948  /// the PCH file.
949  unsigned NumSLocEntriesRead = 0;
950 
951  /// \brief The number of source location entries in the chain.
952  unsigned TotalNumSLocEntries = 0;
953 
954  /// \brief The number of statements (and expressions) de-serialized
955  /// from the chain.
956  unsigned NumStatementsRead = 0;
957 
958  /// \brief The total number of statements (and expressions) stored
959  /// in the chain.
960  unsigned TotalNumStatements = 0;
961 
962  /// \brief The number of macros de-serialized from the chain.
963  unsigned NumMacrosRead = 0;
964 
965  /// \brief The total number of macros stored in the chain.
966  unsigned TotalNumMacros = 0;
967 
968  /// \brief The number of lookups into identifier tables.
969  unsigned NumIdentifierLookups = 0;
970 
971  /// \brief The number of lookups into identifier tables that succeed.
972  unsigned NumIdentifierLookupHits = 0;
973 
974  /// \brief The number of selectors that have been read.
975  unsigned NumSelectorsRead = 0;
976 
977  /// \brief The number of method pool entries that have been read.
978  unsigned NumMethodPoolEntriesRead = 0;
979 
980  /// \brief The number of times we have looked up a selector in the method
981  /// pool.
982  unsigned NumMethodPoolLookups = 0;
983 
984  /// \brief The number of times we have looked up a selector in the method
985  /// pool and found something.
986  unsigned NumMethodPoolHits = 0;
987 
988  /// \brief The number of times we have looked up a selector in the method
989  /// pool within a specific module.
990  unsigned NumMethodPoolTableLookups = 0;
991 
992  /// \brief The number of times we have looked up a selector in the method
993  /// pool within a specific module and found something.
994  unsigned NumMethodPoolTableHits = 0;
995 
996  /// \brief The total number of method pool entries in the selector table.
997  unsigned TotalNumMethodPoolEntries = 0;
998 
999  /// Number of lexical decl contexts read/total.
1000  unsigned NumLexicalDeclContextsRead = 0, TotalLexicalDeclContexts = 0;
1001 
1002  /// Number of visible decl contexts read/total.
1003  unsigned NumVisibleDeclContextsRead = 0, TotalVisibleDeclContexts = 0;
1004 
1005  /// Total size of modules, in bits, currently loaded
1006  uint64_t TotalModulesSizeInBits = 0;
1007 
1008  /// \brief Number of Decl/types that are currently deserializing.
1009  unsigned NumCurrentElementsDeserializing = 0;
1010 
1011  /// \brief Set true while we are in the process of passing deserialized
1012  /// "interesting" decls to consumer inside FinishedDeserializing().
1013  /// This is used as a guard to avoid recursively repeating the process of
1014  /// passing decls to consumer.
1015  bool PassingDeclsToConsumer = false;
1016 
1017  /// \brief The set of identifiers that were read while the AST reader was
1018  /// (recursively) loading declarations.
1019  ///
1020  /// The declarations on the identifier chain for these identifiers will be
1021  /// loaded once the recursive loading has completed.
1022  llvm::MapVector<IdentifierInfo *, SmallVector<uint32_t, 4>>
1023  PendingIdentifierInfos;
1024 
1025  /// \brief The set of lookup results that we have faked in order to support
1026  /// merging of partially deserialized decls but that we have not yet removed.
1027  llvm::SmallMapVector<IdentifierInfo *, SmallVector<NamedDecl*, 2>, 16>
1028  PendingFakeLookupResults;
1029 
1030  /// \brief The generation number of each identifier, which keeps track of
1031  /// the last time we loaded information about this identifier.
1032  llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration;
1033 
1034  class InterestingDecl {
1035  Decl *D;
1036  bool DeclHasPendingBody;
1037 
1038  public:
1039  InterestingDecl(Decl *D, bool HasBody)
1040  : D(D), DeclHasPendingBody(HasBody) {}
1041 
1042  Decl *getDecl() { return D; }
1043 
1044  /// Whether the declaration has a pending body.
1045  bool hasPendingBody() { return DeclHasPendingBody; }
1046  };
1047 
1048  /// \brief Contains declarations and definitions that could be
1049  /// "interesting" to the ASTConsumer, when we get that AST consumer.
1050  ///
1051  /// "Interesting" declarations are those that have data that may
1052  /// need to be emitted, such as inline function definitions or
1053  /// Objective-C protocols.
1054  std::deque<InterestingDecl> PotentiallyInterestingDecls;
1055 
1056  /// \brief The list of redeclaration chains that still need to be
1057  /// reconstructed, and the local offset to the corresponding list
1058  /// of redeclarations.
1059  SmallVector<std::pair<Decl *, uint64_t>, 16> PendingDeclChains;
1060 
1061  /// \brief The list of canonical declarations whose redeclaration chains
1062  /// need to be marked as incomplete once we're done deserializing things.
1063  SmallVector<Decl *, 16> PendingIncompleteDeclChains;
1064 
1065  /// \brief The Decl IDs for the Sema/Lexical DeclContext of a Decl that has
1066  /// been loaded but its DeclContext was not set yet.
1067  struct PendingDeclContextInfo {
1068  Decl *D;
1070  serialization::GlobalDeclID LexicalDC;
1071  };
1072 
1073  /// \brief The set of Decls that have been loaded but their DeclContexts are
1074  /// not set yet.
1075  ///
1076  /// The DeclContexts for these Decls will be set once recursive loading has
1077  /// been completed.
1078  std::deque<PendingDeclContextInfo> PendingDeclContextInfos;
1079 
1080  /// \brief The set of NamedDecls that have been loaded, but are members of a
1081  /// context that has been merged into another context where the corresponding
1082  /// declaration is either missing or has not yet been loaded.
1083  ///
1084  /// We will check whether the corresponding declaration is in fact missing
1085  /// once recursing loading has been completed.
1086  llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks;
1087 
1088  using DataPointers =
1089  std::pair<CXXRecordDecl *, struct CXXRecordDecl::DefinitionData *>;
1090 
1091  /// \brief Record definitions in which we found an ODR violation.
1092  llvm::SmallDenseMap<CXXRecordDecl *, llvm::SmallVector<DataPointers, 2>, 2>
1093  PendingOdrMergeFailures;
1094 
1095  /// \brief DeclContexts in which we have diagnosed an ODR violation.
1096  llvm::SmallPtrSet<DeclContext*, 2> DiagnosedOdrMergeFailures;
1097 
1098  /// \brief The set of Objective-C categories that have been deserialized
1099  /// since the last time the declaration chains were linked.
1100  llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized;
1101 
1102  /// \brief The set of Objective-C class definitions that have already been
1103  /// loaded, for which we will need to check for categories whenever a new
1104  /// module is loaded.
1105  SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded;
1106 
1107  using KeyDeclsMap =
1108  llvm::DenseMap<Decl *, SmallVector<serialization::DeclID, 2>>;
1109 
1110  /// \brief A mapping from canonical declarations to the set of global
1111  /// declaration IDs for key declaration that have been merged with that
1112  /// canonical declaration. A key declaration is a formerly-canonical
1113  /// declaration whose module did not import any other key declaration for that
1114  /// entity. These are the IDs that we use as keys when finding redecl chains.
1115  KeyDeclsMap KeyDecls;
1116 
1117  /// \brief A mapping from DeclContexts to the semantic DeclContext that we
1118  /// are treating as the definition of the entity. This is used, for instance,
1119  /// when merging implicit instantiations of class templates across modules.
1120  llvm::DenseMap<DeclContext *, DeclContext *> MergedDeclContexts;
1121 
1122  /// \brief A mapping from canonical declarations of enums to their canonical
1123  /// definitions. Only populated when using modules in C++.
1124  llvm::DenseMap<EnumDecl *, EnumDecl *> EnumDefinitions;
1125 
1126  /// \brief When reading a Stmt tree, Stmt operands are placed in this stack.
1127  SmallVector<Stmt *, 16> StmtStack;
1128 
1129  /// \brief What kind of records we are reading.
1130  enum ReadingKind {
1131  Read_None, Read_Decl, Read_Type, Read_Stmt
1132  };
1133 
1134  /// \brief What kind of records we are reading.
1135  ReadingKind ReadingKind = Read_None;
1136 
1137  /// \brief RAII object to change the reading kind.
1138  class ReadingKindTracker {
1139  ASTReader &Reader;
1140  enum ReadingKind PrevKind;
1141 
1142  public:
1143  ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader)
1144  : Reader(reader), PrevKind(Reader.ReadingKind) {
1145  Reader.ReadingKind = newKind;
1146  }
1147 
1148  ReadingKindTracker(const ReadingKindTracker &) = delete;
1149  ReadingKindTracker &operator=(const ReadingKindTracker &) = delete;
1150  ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; }
1151  };
1152 
1153  /// \brief RAII object to mark the start of processing updates.
1154  class ProcessingUpdatesRAIIObj {
1155  ASTReader &Reader;
1156  bool PrevState;
1157 
1158  public:
1159  ProcessingUpdatesRAIIObj(ASTReader &reader)
1160  : Reader(reader), PrevState(Reader.ProcessingUpdateRecords) {
1161  Reader.ProcessingUpdateRecords = true;
1162  }
1163 
1164  ProcessingUpdatesRAIIObj(const ProcessingUpdatesRAIIObj &) = delete;
1165  ProcessingUpdatesRAIIObj &
1166  operator=(const ProcessingUpdatesRAIIObj &) = delete;
1167  ~ProcessingUpdatesRAIIObj() { Reader.ProcessingUpdateRecords = PrevState; }
1168  };
1169 
1170  /// \brief Suggested contents of the predefines buffer, after this
1171  /// PCH file has been processed.
1172  ///
1173  /// In most cases, this string will be empty, because the predefines
1174  /// buffer computed to build the PCH file will be identical to the
1175  /// predefines buffer computed from the command line. However, when
1176  /// there are differences that the PCH reader can work around, this
1177  /// predefines buffer may contain additional definitions.
1178  std::string SuggestedPredefines;
1179 
1180  llvm::DenseMap<const Decl *, bool> DefinitionSource;
1181 
1182  /// \brief Reads a statement from the specified cursor.
1183  Stmt *ReadStmtFromStream(ModuleFile &F);
1184 
1185  struct InputFileInfo {
1186  std::string Filename;
1187  off_t StoredSize;
1188  time_t StoredTime;
1189  bool Overridden;
1190  bool Transient;
1191  bool TopLevelModuleMap;
1192  };
1193 
1194  /// \brief Reads the stored information about an input file.
1195  InputFileInfo readInputFileInfo(ModuleFile &F, unsigned ID);
1196 
1197  /// \brief Retrieve the file entry and 'overridden' bit for an input
1198  /// file in the given module file.
1199  serialization::InputFile getInputFile(ModuleFile &F, unsigned ID,
1200  bool Complain = true);
1201 
1202 public:
1203  void ResolveImportedPath(ModuleFile &M, std::string &Filename);
1204  static void ResolveImportedPath(std::string &Filename, StringRef Prefix);
1205 
1206  /// \brief Returns the first key declaration for the given declaration. This
1207  /// is one that is formerly-canonical (or still canonical) and whose module
1208  /// did not import any other key declaration of the entity.
1209  Decl *getKeyDeclaration(Decl *D) {
1210  D = D->getCanonicalDecl();
1211  if (D->isFromASTFile())
1212  return D;
1213 
1214  auto I = KeyDecls.find(D);
1215  if (I == KeyDecls.end() || I->second.empty())
1216  return D;
1217  return GetExistingDecl(I->second[0]);
1218  }
1219  const Decl *getKeyDeclaration(const Decl *D) {
1220  return getKeyDeclaration(const_cast<Decl*>(D));
1221  }
1222 
1223  /// \brief Run a callback on each imported key declaration of \p D.
1224  template <typename Fn>
1225  void forEachImportedKeyDecl(const Decl *D, Fn Visit) {
1226  D = D->getCanonicalDecl();
1227  if (D->isFromASTFile())
1228  Visit(D);
1229 
1230  auto It = KeyDecls.find(const_cast<Decl*>(D));
1231  if (It != KeyDecls.end())
1232  for (auto ID : It->second)
1233  Visit(GetExistingDecl(ID));
1234  }
1235 
1236  /// \brief Get the loaded lookup tables for \p Primary, if any.
1238  getLoadedLookupTables(DeclContext *Primary) const;
1239 
1240 private:
1241  struct ImportedModule {
1242  ModuleFile *Mod;
1243  ModuleFile *ImportedBy;
1244  SourceLocation ImportLoc;
1245 
1246  ImportedModule(ModuleFile *Mod,
1247  ModuleFile *ImportedBy,
1248  SourceLocation ImportLoc)
1249  : Mod(Mod), ImportedBy(ImportedBy), ImportLoc(ImportLoc) {}
1250  };
1251 
1252  ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type,
1253  SourceLocation ImportLoc, ModuleFile *ImportedBy,
1255  off_t ExpectedSize, time_t ExpectedModTime,
1256  ASTFileSignature ExpectedSignature,
1257  unsigned ClientLoadCapabilities);
1258  ASTReadResult ReadControlBlock(ModuleFile &F,
1260  const ModuleFile *ImportedBy,
1261  unsigned ClientLoadCapabilities);
1262  static ASTReadResult ReadOptionsBlock(
1263  llvm::BitstreamCursor &Stream, unsigned ClientLoadCapabilities,
1264  bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener,
1265  std::string &SuggestedPredefines);
1266 
1267  /// Read the unhashed control block.
1268  ///
1269  /// This has no effect on \c F.Stream, instead creating a fresh cursor from
1270  /// \c F.Data and reading ahead.
1271  ASTReadResult readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy,
1272  unsigned ClientLoadCapabilities);
1273 
1274  static ASTReadResult
1275  readUnhashedControlBlockImpl(ModuleFile *F, llvm::StringRef StreamData,
1276  unsigned ClientLoadCapabilities,
1277  bool AllowCompatibleConfigurationMismatch,
1278  ASTReaderListener *Listener,
1279  bool ValidateDiagnosticOptions);
1280 
1281  ASTReadResult ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities);
1282  ASTReadResult ReadExtensionBlock(ModuleFile &F);
1283  void ReadModuleOffsetMap(ModuleFile &F) const;
1284  bool ParseLineTable(ModuleFile &F, const RecordData &Record);
1285  bool ReadSourceManagerBlock(ModuleFile &F);
1286  llvm::BitstreamCursor &SLocCursorForID(int ID);
1287  SourceLocation getImportLocation(ModuleFile *F);
1288  ASTReadResult ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
1289  const ModuleFile *ImportedBy,
1290  unsigned ClientLoadCapabilities);
1291  ASTReadResult ReadSubmoduleBlock(ModuleFile &F,
1292  unsigned ClientLoadCapabilities);
1293  static bool ParseLanguageOptions(const RecordData &Record, bool Complain,
1294  ASTReaderListener &Listener,
1295  bool AllowCompatibleDifferences);
1296  static bool ParseTargetOptions(const RecordData &Record, bool Complain,
1297  ASTReaderListener &Listener,
1298  bool AllowCompatibleDifferences);
1299  static bool ParseDiagnosticOptions(const RecordData &Record, bool Complain,
1300  ASTReaderListener &Listener);
1301  static bool ParseFileSystemOptions(const RecordData &Record, bool Complain,
1302  ASTReaderListener &Listener);
1303  static bool ParseHeaderSearchOptions(const RecordData &Record, bool Complain,
1304  ASTReaderListener &Listener);
1305  static bool ParsePreprocessorOptions(const RecordData &Record, bool Complain,
1306  ASTReaderListener &Listener,
1307  std::string &SuggestedPredefines);
1308 
1309  struct RecordLocation {
1310  ModuleFile *F;
1311  uint64_t Offset;
1312 
1313  RecordLocation(ModuleFile *M, uint64_t O)
1314  : F(M), Offset(O) {}
1315  };
1316 
1317  QualType readTypeRecord(unsigned Index);
1318  void readExceptionSpec(ModuleFile &ModuleFile,
1319  SmallVectorImpl<QualType> &ExceptionStorage,
1321  const RecordData &Record, unsigned &Index);
1322  RecordLocation TypeCursorForIndex(unsigned Index);
1323  void LoadedDecl(unsigned Index, Decl *D);
1324  Decl *ReadDeclRecord(serialization::DeclID ID);
1325  void markIncompleteDeclChain(Decl *Canon);
1326 
1327  /// \brief Returns the most recent declaration of a declaration (which must be
1328  /// of a redeclarable kind) that is either local or has already been loaded
1329  /// merged into its redecl chain.
1330  Decl *getMostRecentExistingDecl(Decl *D);
1331 
1332  RecordLocation DeclCursorForID(serialization::DeclID ID,
1333  SourceLocation &Location);
1334  void loadDeclUpdateRecords(PendingUpdateRecord &Record);
1335  void loadPendingDeclChain(Decl *D, uint64_t LocalOffset);
1336  void loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D,
1337  unsigned PreviousGeneration = 0);
1338 
1339  RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
1340  uint64_t getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset);
1341 
1342  /// \brief Returns the first preprocessed entity ID that begins or ends after
1343  /// \arg Loc.
1345  findPreprocessedEntity(SourceLocation Loc, bool EndsAfter) const;
1346 
1347  /// \brief Find the next module that contains entities and return the ID
1348  /// of the first entry.
1349  ///
1350  /// \param SLocMapI points at a chunk of a module that contains no
1351  /// preprocessed entities or the entities it contains are not the
1352  /// ones we are looking for.
1354  findNextPreprocessedEntity(
1355  GlobalSLocOffsetMapType::const_iterator SLocMapI) const;
1356 
1357  /// \brief Returns (ModuleFile, Local index) pair for \p GlobalIndex of a
1358  /// preprocessed entity.
1359  std::pair<ModuleFile *, unsigned>
1360  getModulePreprocessedEntity(unsigned GlobalIndex);
1361 
1362  /// \brief Returns (begin, end) pair for the preprocessed entities of a
1363  /// particular module.
1364  llvm::iterator_range<PreprocessingRecord::iterator>
1365  getModulePreprocessedEntities(ModuleFile &Mod) const;
1366 
1367 public:
1369  : public llvm::iterator_adaptor_base<
1370  ModuleDeclIterator, const serialization::LocalDeclID *,
1371  std::random_access_iterator_tag, const Decl *, ptrdiff_t,
1372  const Decl *, const Decl *> {
1373  ASTReader *Reader = nullptr;
1374  ModuleFile *Mod = nullptr;
1375 
1376  public:
1377  ModuleDeclIterator() : iterator_adaptor_base(nullptr) {}
1378 
1379  ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod,
1380  const serialization::LocalDeclID *Pos)
1381  : iterator_adaptor_base(Pos), Reader(Reader), Mod(Mod) {}
1382 
1383  value_type operator*() const {
1384  return Reader->GetDecl(Reader->getGlobalDeclID(*Mod, *I));
1385  }
1386 
1387  value_type operator->() const { return **this; }
1388 
1389  bool operator==(const ModuleDeclIterator &RHS) const {
1390  assert(Reader == RHS.Reader && Mod == RHS.Mod);
1391  return I == RHS.I;
1392  }
1393  };
1394 
1395  llvm::iterator_range<ModuleDeclIterator>
1396  getModuleFileLevelDecls(ModuleFile &Mod);
1397 
1398 private:
1399  void PassInterestingDeclsToConsumer();
1400  void PassInterestingDeclToConsumer(Decl *D);
1401 
1402  void finishPendingActions();
1403  void diagnoseOdrViolations();
1404 
1405  void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name);
1406 
1407  void addPendingDeclContextInfo(Decl *D,
1409  serialization::GlobalDeclID LexicalDC) {
1410  assert(D);
1411  PendingDeclContextInfo Info = { D, SemaDC, LexicalDC };
1412  PendingDeclContextInfos.push_back(Info);
1413  }
1414 
1415  /// \brief Produce an error diagnostic and return true.
1416  ///
1417  /// This routine should only be used for fatal errors that have to
1418  /// do with non-routine failures (e.g., corrupted AST file).
1419  void Error(StringRef Msg) const;
1420  void Error(unsigned DiagID, StringRef Arg1 = StringRef(),
1421  StringRef Arg2 = StringRef()) const;
1422 
1423 public:
1424  /// \brief Load the AST file and validate its contents against the given
1425  /// Preprocessor.
1426  ///
1427  /// \param PP the preprocessor associated with the context in which this
1428  /// precompiled header will be loaded.
1429  ///
1430  /// \param Context the AST context that this precompiled header will be
1431  /// loaded into, if any.
1432  ///
1433  /// \param PCHContainerRdr the PCHContainerOperations to use for loading and
1434  /// creating modules.
1435  ///
1436  /// \param Extensions the list of module file extensions that can be loaded
1437  /// from the AST files.
1438  ///
1439  /// \param isysroot If non-NULL, the system include path specified by the
1440  /// user. This is only used with relocatable PCH files. If non-NULL,
1441  /// a relocatable PCH file will use the default path "/".
1442  ///
1443  /// \param DisableValidation If true, the AST reader will suppress most
1444  /// of its regular consistency checking, allowing the use of precompiled
1445  /// headers that cannot be determined to be compatible.
1446  ///
1447  /// \param AllowASTWithCompilerErrors If true, the AST reader will accept an
1448  /// AST file the was created out of an AST with compiler errors,
1449  /// otherwise it will reject it.
1450  ///
1451  /// \param AllowConfigurationMismatch If true, the AST reader will not check
1452  /// for configuration differences between the AST file and the invocation.
1453  ///
1454  /// \param ValidateSystemInputs If true, the AST reader will validate
1455  /// system input files in addition to user input files. This is only
1456  /// meaningful if \p DisableValidation is false.
1457  ///
1458  /// \param UseGlobalIndex If true, the AST reader will try to load and use
1459  /// the global module index.
1460  ///
1461  /// \param ReadTimer If non-null, a timer used to track the time spent
1462  /// deserializing.
1463  ASTReader(Preprocessor &PP, ASTContext *Context,
1464  const PCHContainerReader &PCHContainerRdr,
1465  ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
1466  StringRef isysroot = "", bool DisableValidation = false,
1467  bool AllowASTWithCompilerErrors = false,
1468  bool AllowConfigurationMismatch = false,
1469  bool ValidateSystemInputs = false, bool UseGlobalIndex = true,
1470  std::unique_ptr<llvm::Timer> ReadTimer = {});
1471  ASTReader(const ASTReader &) = delete;
1472  ASTReader &operator=(const ASTReader &) = delete;
1473  ~ASTReader() override;
1474 
1475  SourceManager &getSourceManager() const { return SourceMgr; }
1476  FileManager &getFileManager() const { return FileMgr; }
1477  DiagnosticsEngine &getDiags() const { return Diags; }
1478 
1479  /// \brief Flags that indicate what kind of AST loading failures the client
1480  /// of the AST reader can directly handle.
1481  ///
1482  /// When a client states that it can handle a particular kind of failure,
1483  /// the AST reader will not emit errors when producing that kind of failure.
1485  /// \brief The client can't handle any AST loading failures.
1486  ARR_None = 0,
1487 
1488  /// \brief The client can handle an AST file that cannot load because it
1489  /// is missing.
1490  ARR_Missing = 0x1,
1491 
1492  /// \brief The client can handle an AST file that cannot load because it
1493  /// is out-of-date relative to its input files.
1494  ARR_OutOfDate = 0x2,
1495 
1496  /// \brief The client can handle an AST file that cannot load because it
1497  /// was built with a different version of Clang.
1498  ARR_VersionMismatch = 0x4,
1499 
1500  /// \brief The client can handle an AST file that cannot load because it's
1501  /// compiled configuration doesn't match that of the context it was
1502  /// loaded into.
1503  ARR_ConfigurationMismatch = 0x8
1504  };
1505 
1506  /// \brief Load the AST file designated by the given file name.
1507  ///
1508  /// \param FileName The name of the AST file to load.
1509  ///
1510  /// \param Type The kind of AST being loaded, e.g., PCH, module, main file,
1511  /// or preamble.
1512  ///
1513  /// \param ImportLoc the location where the module file will be considered as
1514  /// imported from. For non-module AST types it should be invalid.
1515  ///
1516  /// \param ClientLoadCapabilities The set of client load-failure
1517  /// capabilities, represented as a bitset of the enumerators of
1518  /// LoadFailureCapabilities.
1519  ///
1520  /// \param Imported optional out-parameter to append the list of modules
1521  /// that were imported by precompiled headers or any other non-module AST file
1522  ASTReadResult ReadAST(StringRef FileName, ModuleKind Type,
1523  SourceLocation ImportLoc,
1524  unsigned ClientLoadCapabilities,
1525  SmallVectorImpl<ImportedSubmodule> *Imported = nullptr);
1526 
1527  /// \brief Make the entities in the given module and any of its (non-explicit)
1528  /// submodules visible to name lookup.
1529  ///
1530  /// \param Mod The module whose names should be made visible.
1531  ///
1532  /// \param NameVisibility The level of visibility to give the names in the
1533  /// module. Visibility can only be increased over time.
1534  ///
1535  /// \param ImportLoc The location at which the import occurs.
1536  void makeModuleVisible(Module *Mod,
1537  Module::NameVisibilityKind NameVisibility,
1538  SourceLocation ImportLoc);
1539 
1540  /// \brief Make the names within this set of hidden names visible.
1541  void makeNamesVisible(const HiddenNames &Names, Module *Owner);
1542 
1543  /// \brief Note that MergedDef is a redefinition of the canonical definition
1544  /// Def, so Def should be visible whenever MergedDef is.
1545  void mergeDefinitionVisibility(NamedDecl *Def, NamedDecl *MergedDef);
1546 
1547  /// \brief Take the AST callbacks listener.
1548  std::unique_ptr<ASTReaderListener> takeListener() {
1549  return std::move(Listener);
1550  }
1551 
1552  /// \brief Set the AST callbacks listener.
1553  void setListener(std::unique_ptr<ASTReaderListener> Listener) {
1554  this->Listener = std::move(Listener);
1555  }
1556 
1557  /// \brief Add an AST callback listener.
1558  ///
1559  /// Takes ownership of \p L.
1560  void addListener(std::unique_ptr<ASTReaderListener> L) {
1561  if (Listener)
1562  L = llvm::make_unique<ChainedASTReaderListener>(std::move(L),
1563  std::move(Listener));
1564  Listener = std::move(L);
1565  }
1566 
1567  /// RAII object to temporarily add an AST callback listener.
1569  ASTReader &Reader;
1570  bool Chained = false;
1571 
1572  public:
1573  ListenerScope(ASTReader &Reader, std::unique_ptr<ASTReaderListener> L)
1574  : Reader(Reader) {
1575  auto Old = Reader.takeListener();
1576  if (Old) {
1577  Chained = true;
1578  L = llvm::make_unique<ChainedASTReaderListener>(std::move(L),
1579  std::move(Old));
1580  }
1581  Reader.setListener(std::move(L));
1582  }
1583 
1585  auto New = Reader.takeListener();
1586  if (Chained)
1587  Reader.setListener(static_cast<ChainedASTReaderListener *>(New.get())
1588  ->takeSecond());
1589  }
1590  };
1591 
1592  /// \brief Set the AST deserialization listener.
1593  void setDeserializationListener(ASTDeserializationListener *Listener,
1594  bool TakeOwnership = false);
1595 
1596  /// \brief Determine whether this AST reader has a global index.
1597  bool hasGlobalIndex() const { return (bool)GlobalIndex; }
1598 
1599  /// \brief Return global module index.
1600  GlobalModuleIndex *getGlobalIndex() { return GlobalIndex.get(); }
1601 
1602  /// \brief Reset reader for a reload try.
1603  void resetForReload() { TriedLoadingGlobalIndex = false; }
1604 
1605  /// \brief Attempts to load the global index.
1606  ///
1607  /// \returns true if loading the global index has failed for any reason.
1608  bool loadGlobalIndex();
1609 
1610  /// \brief Determine whether we tried to load the global index, but failed,
1611  /// e.g., because it is out-of-date or does not exist.
1612  bool isGlobalIndexUnavailable() const;
1613 
1614  /// \brief Initializes the ASTContext
1615  void InitializeContext();
1616 
1617  /// \brief Update the state of Sema after loading some additional modules.
1618  void UpdateSema();
1619 
1620  /// \brief Add in-memory (virtual file) buffer.
1621  void addInMemoryBuffer(StringRef &FileName,
1622  std::unique_ptr<llvm::MemoryBuffer> Buffer) {
1623  ModuleMgr.addInMemoryBuffer(FileName, std::move(Buffer));
1624  }
1625 
1626  /// \brief Finalizes the AST reader's state before writing an AST file to
1627  /// disk.
1628  ///
1629  /// This operation may undo temporary state in the AST that should not be
1630  /// emitted.
1631  void finalizeForWriting();
1632 
1633  /// \brief Retrieve the module manager.
1634  ModuleManager &getModuleManager() { return ModuleMgr; }
1635 
1636  /// \brief Retrieve the preprocessor.
1637  Preprocessor &getPreprocessor() const { return PP; }
1638 
1639  /// \brief Retrieve the name of the original source file name for the primary
1640  /// module file.
1642  return ModuleMgr.getPrimaryModule().OriginalSourceFileName;
1643  }
1644 
1645  /// \brief Retrieve the name of the original source file name directly from
1646  /// the AST file, without actually loading the AST file.
1647  static std::string
1648  getOriginalSourceFile(const std::string &ASTFileName, FileManager &FileMgr,
1649  const PCHContainerReader &PCHContainerRdr,
1650  DiagnosticsEngine &Diags);
1651 
1652  /// \brief Read the control block for the named AST file.
1653  ///
1654  /// \returns true if an error occurred, false otherwise.
1655  static bool
1656  readASTFileControlBlock(StringRef Filename, FileManager &FileMgr,
1657  const PCHContainerReader &PCHContainerRdr,
1658  bool FindModuleFileExtensions,
1659  ASTReaderListener &Listener,
1660  bool ValidateDiagnosticOptions);
1661 
1662  /// \brief Determine whether the given AST file is acceptable to load into a
1663  /// translation unit with the given language and target options.
1664  static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr,
1665  const PCHContainerReader &PCHContainerRdr,
1666  const LangOptions &LangOpts,
1667  const TargetOptions &TargetOpts,
1668  const PreprocessorOptions &PPOpts,
1669  StringRef ExistingModuleCachePath);
1670 
1671  /// \brief Returns the suggested contents of the predefines buffer,
1672  /// which contains a (typically-empty) subset of the predefines
1673  /// build prior to including the precompiled header.
1674  const std::string &getSuggestedPredefines() { return SuggestedPredefines; }
1675 
1676  /// \brief Read a preallocated preprocessed entity from the external source.
1677  ///
1678  /// \returns null if an error occurred that prevented the preprocessed
1679  /// entity from being loaded.
1680  PreprocessedEntity *ReadPreprocessedEntity(unsigned Index) override;
1681 
1682  /// \brief Returns a pair of [Begin, End) indices of preallocated
1683  /// preprocessed entities that \p Range encompasses.
1684  std::pair<unsigned, unsigned>
1685  findPreprocessedEntitiesInRange(SourceRange Range) override;
1686 
1687  /// \brief Optionally returns true or false if the preallocated preprocessed
1688  /// entity with index \p Index came from file \p FID.
1689  Optional<bool> isPreprocessedEntityInFileID(unsigned Index,
1690  FileID FID) override;
1691 
1692  /// \brief Read the header file information for the given file entry.
1693  HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) override;
1694 
1695  void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag);
1696 
1697  /// \brief Returns the number of source locations found in the chain.
1698  unsigned getTotalNumSLocs() const {
1699  return TotalNumSLocEntries;
1700  }
1701 
1702  /// \brief Returns the number of identifiers found in the chain.
1703  unsigned getTotalNumIdentifiers() const {
1704  return static_cast<unsigned>(IdentifiersLoaded.size());
1705  }
1706 
1707  /// \brief Returns the number of macros found in the chain.
1708  unsigned getTotalNumMacros() const {
1709  return static_cast<unsigned>(MacrosLoaded.size());
1710  }
1711 
1712  /// \brief Returns the number of types found in the chain.
1713  unsigned getTotalNumTypes() const {
1714  return static_cast<unsigned>(TypesLoaded.size());
1715  }
1716 
1717  /// \brief Returns the number of declarations found in the chain.
1718  unsigned getTotalNumDecls() const {
1719  return static_cast<unsigned>(DeclsLoaded.size());
1720  }
1721 
1722  /// \brief Returns the number of submodules known.
1723  unsigned getTotalNumSubmodules() const {
1724  return static_cast<unsigned>(SubmodulesLoaded.size());
1725  }
1726 
1727  /// \brief Returns the number of selectors found in the chain.
1728  unsigned getTotalNumSelectors() const {
1729  return static_cast<unsigned>(SelectorsLoaded.size());
1730  }
1731 
1732  /// \brief Returns the number of preprocessed entities known to the AST
1733  /// reader.
1735  unsigned Result = 0;
1736  for (const auto &M : ModuleMgr)
1737  Result += M.NumPreprocessedEntities;
1738  return Result;
1739  }
1740 
1741  /// \brief Reads a TemplateArgumentLocInfo appropriate for the
1742  /// given TemplateArgument kind.
1744  GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind,
1745  const RecordData &Record, unsigned &Idx);
1746 
1747  /// \brief Reads a TemplateArgumentLoc.
1749  ReadTemplateArgumentLoc(ModuleFile &F,
1750  const RecordData &Record, unsigned &Idx);
1751 
1753  ReadASTTemplateArgumentListInfo(ModuleFile &F,
1754  const RecordData &Record, unsigned &Index);
1755 
1756  /// \brief Reads a declarator info from the given record.
1757  TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F,
1758  const RecordData &Record, unsigned &Idx);
1759 
1760  /// \brief Resolve a type ID into a type, potentially building a new
1761  /// type.
1762  QualType GetType(serialization::TypeID ID);
1763 
1764  /// \brief Resolve a local type ID within a given AST file into a type.
1765  QualType getLocalType(ModuleFile &F, unsigned LocalID);
1766 
1767  /// \brief Map a local type ID within a given AST file into a global type ID.
1768  serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const;
1769 
1770  /// \brief Read a type from the current position in the given record, which
1771  /// was read from the given AST file.
1772  QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) {
1773  if (Idx >= Record.size())
1774  return QualType();
1775 
1776  return getLocalType(F, Record[Idx++]);
1777  }
1778 
1779  /// \brief Map from a local declaration ID within a given module to a
1780  /// global declaration ID.
1781  serialization::DeclID getGlobalDeclID(ModuleFile &F,
1782  serialization::LocalDeclID LocalID) const;
1783 
1784  /// \brief Returns true if global DeclID \p ID originated from module \p M.
1785  bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const;
1786 
1787  /// \brief Retrieve the module file that owns the given declaration, or NULL
1788  /// if the declaration is not from a module file.
1789  ModuleFile *getOwningModuleFile(const Decl *D);
1790 
1791  /// \brief Get the best name we know for the module that owns the given
1792  /// declaration, or an empty string if the declaration is not from a module.
1793  std::string getOwningModuleNameForDiagnostic(const Decl *D);
1794 
1795  /// \brief Returns the source location for the decl \p ID.
1796  SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID);
1797 
1798  /// \brief Resolve a declaration ID into a declaration, potentially
1799  /// building a new declaration.
1800  Decl *GetDecl(serialization::DeclID ID);
1801  Decl *GetExternalDecl(uint32_t ID) override;
1802 
1803  /// \brief Resolve a declaration ID into a declaration. Return 0 if it's not
1804  /// been loaded yet.
1805  Decl *GetExistingDecl(serialization::DeclID ID);
1806 
1807  /// \brief Reads a declaration with the given local ID in the given module.
1808  Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) {
1809  return GetDecl(getGlobalDeclID(F, LocalID));
1810  }
1811 
1812  /// \brief Reads a declaration with the given local ID in the given module.
1813  ///
1814  /// \returns The requested declaration, casted to the given return type.
1815  template<typename T>
1816  T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) {
1817  return cast_or_null<T>(GetLocalDecl(F, LocalID));
1818  }
1819 
1820  /// \brief Map a global declaration ID into the declaration ID used to
1821  /// refer to this declaration within the given module fule.
1822  ///
1823  /// \returns the global ID of the given declaration as known in the given
1824  /// module file.
1826  mapGlobalIDToModuleFileGlobalID(ModuleFile &M,
1827  serialization::DeclID GlobalID);
1828 
1829  /// \brief Reads a declaration ID from the given position in a record in the
1830  /// given module.
1831  ///
1832  /// \returns The declaration ID read from the record, adjusted to a global ID.
1833  serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record,
1834  unsigned &Idx);
1835 
1836  /// \brief Reads a declaration from the given position in a record in the
1837  /// given module.
1838  Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) {
1839  return GetDecl(ReadDeclID(F, R, I));
1840  }
1841 
1842  /// \brief Reads a declaration from the given position in a record in the
1843  /// given module.
1844  ///
1845  /// \returns The declaration read from this location, casted to the given
1846  /// result type.
1847  template<typename T>
1848  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1849  return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1850  }
1851 
1852  /// \brief If any redeclarations of \p D have been imported since it was
1853  /// last checked, this digs out those redeclarations and adds them to the
1854  /// redeclaration chain for \p D.
1855  void CompleteRedeclChain(const Decl *D) override;
1856 
1857  CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
1858 
1859  /// \brief Resolve the offset of a statement into a statement.
1860  ///
1861  /// This operation will read a new statement from the external
1862  /// source each time it is called, and is meant to be used via a
1863  /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
1864  Stmt *GetExternalDeclStmt(uint64_t Offset) override;
1865 
1866  /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
1867  /// specified cursor. Read the abbreviations that are at the top of the block
1868  /// and then leave the cursor pointing into the block.
1869  static bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID);
1870 
1871  /// \brief Finds all the visible declarations with a given name.
1872  /// The current implementation of this method just loads the entire
1873  /// lookup table as unmaterialized references.
1874  bool FindExternalVisibleDeclsByName(const DeclContext *DC,
1875  DeclarationName Name) override;
1876 
1877  /// \brief Read all of the declarations lexically stored in a
1878  /// declaration context.
1879  ///
1880  /// \param DC The declaration context whose declarations will be
1881  /// read.
1882  ///
1883  /// \param IsKindWeWant A predicate indicating which declaration kinds
1884  /// we are interested in.
1885  ///
1886  /// \param Decls Vector that will contain the declarations loaded
1887  /// from the external source. The caller is responsible for merging
1888  /// these declarations with any declarations already stored in the
1889  /// declaration context.
1890  void
1891  FindExternalLexicalDecls(const DeclContext *DC,
1892  llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
1893  SmallVectorImpl<Decl *> &Decls) override;
1894 
1895  /// \brief Get the decls that are contained in a file in the Offset/Length
1896  /// range. \p Length can be 0 to indicate a point at \p Offset instead of
1897  /// a range.
1898  void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length,
1899  SmallVectorImpl<Decl *> &Decls) override;
1900 
1901  /// \brief Notify ASTReader that we started deserialization of
1902  /// a decl or type so until FinishedDeserializing is called there may be
1903  /// decls that are initializing. Must be paired with FinishedDeserializing.
1904  void StartedDeserializing() override;
1905 
1906  /// \brief Notify ASTReader that we finished the deserialization of
1907  /// a decl or type. Must be paired with StartedDeserializing.
1908  void FinishedDeserializing() override;
1909 
1910  /// \brief Function that will be invoked when we begin parsing a new
1911  /// translation unit involving this external AST source.
1912  ///
1913  /// This function will provide all of the external definitions to
1914  /// the ASTConsumer.
1915  void StartTranslationUnit(ASTConsumer *Consumer) override;
1916 
1917  /// \brief Print some statistics about AST usage.
1918  void PrintStats() override;
1919 
1920  /// \brief Dump information about the AST reader to standard error.
1921  void dump();
1922 
1923  /// Return the amount of memory used by memory buffers, breaking down
1924  /// by heap-backed versus mmap'ed memory.
1925  void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
1926 
1927  /// \brief Initialize the semantic source with the Sema instance
1928  /// being used to perform semantic analysis on the abstract syntax
1929  /// tree.
1930  void InitializeSema(Sema &S) override;
1931 
1932  /// \brief Inform the semantic consumer that Sema is no longer available.
1933  void ForgetSema() override { SemaObj = nullptr; }
1934 
1935  /// \brief Retrieve the IdentifierInfo for the named identifier.
1936  ///
1937  /// This routine builds a new IdentifierInfo for the given identifier. If any
1938  /// declarations with this name are visible from translation unit scope, their
1939  /// declarations will be deserialized and introduced into the declaration
1940  /// chain of the identifier.
1941  IdentifierInfo *get(StringRef Name) override;
1942 
1943  /// \brief Retrieve an iterator into the set of all identifiers
1944  /// in all loaded AST files.
1945  IdentifierIterator *getIdentifiers() override;
1946 
1947  /// \brief Load the contents of the global method pool for a given
1948  /// selector.
1949  void ReadMethodPool(Selector Sel) override;
1950 
1951  /// Load the contents of the global method pool for a given
1952  /// selector if necessary.
1953  void updateOutOfDateSelector(Selector Sel) override;
1954 
1955  /// \brief Load the set of namespaces that are known to the external source,
1956  /// which will be used during typo correction.
1957  void ReadKnownNamespaces(
1958  SmallVectorImpl<NamespaceDecl *> &Namespaces) override;
1959 
1960  void ReadUndefinedButUsed(
1961  llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) override;
1962 
1963  void ReadMismatchingDeleteExpressions(llvm::MapVector<
1964  FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
1965  Exprs) override;
1966 
1967  void ReadTentativeDefinitions(
1968  SmallVectorImpl<VarDecl *> &TentativeDefs) override;
1969 
1970  void ReadUnusedFileScopedDecls(
1971  SmallVectorImpl<const DeclaratorDecl *> &Decls) override;
1972 
1973  void ReadDelegatingConstructors(
1974  SmallVectorImpl<CXXConstructorDecl *> &Decls) override;
1975 
1976  void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) override;
1977 
1978  void ReadUnusedLocalTypedefNameCandidates(
1980 
1981  void ReadReferencedSelectors(
1982  SmallVectorImpl<std::pair<Selector, SourceLocation>> &Sels) override;
1983 
1984  void ReadWeakUndeclaredIdentifiers(
1985  SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo>> &WI) override;
1986 
1987  void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override;
1988 
1989  void ReadPendingInstantiations(
1990  SmallVectorImpl<std::pair<ValueDecl *,
1991  SourceLocation>> &Pending) override;
1992 
1993  void ReadLateParsedTemplates(
1994  llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
1995  &LPTMap) override;
1996 
1997  /// \brief Load a selector from disk, registering its ID if it exists.
1998  void LoadSelector(Selector Sel);
1999 
2000  void SetIdentifierInfo(unsigned ID, IdentifierInfo *II);
2001  void SetGloballyVisibleDecls(IdentifierInfo *II,
2002  const SmallVectorImpl<uint32_t> &DeclIDs,
2003  SmallVectorImpl<Decl *> *Decls = nullptr);
2004 
2005  /// \brief Report a diagnostic.
2006  DiagnosticBuilder Diag(unsigned DiagID) const;
2007 
2008  /// \brief Report a diagnostic.
2009  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const;
2010 
2011  IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID);
2012 
2013  IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record,
2014  unsigned &Idx) {
2015  return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++]));
2016  }
2017 
2019  // Note that we are loading an identifier.
2020  Deserializing AnIdentifier(this);
2021 
2022  return DecodeIdentifierInfo(ID);
2023  }
2024 
2025  IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID);
2026 
2027  serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M,
2028  unsigned LocalID);
2029 
2030  void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo);
2031 
2032  /// \brief Retrieve the macro with the given ID.
2033  MacroInfo *getMacro(serialization::MacroID ID);
2034 
2035  /// \brief Retrieve the global macro ID corresponding to the given local
2036  /// ID within the given module file.
2037  serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID);
2038 
2039  /// \brief Read the source location entry with index ID.
2040  bool ReadSLocEntry(int ID) override;
2041 
2042  /// \brief Retrieve the module import location and module name for the
2043  /// given source manager entry ID.
2044  std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID) override;
2045 
2046  /// \brief Retrieve the global submodule ID given a module and its local ID
2047  /// number.
2049  getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID);
2050 
2051  /// \brief Retrieve the submodule that corresponds to a global submodule ID.
2052  ///
2053  Module *getSubmodule(serialization::SubmoduleID GlobalID);
2054 
2055  /// \brief Retrieve the module that corresponds to the given module ID.
2056  ///
2057  /// Note: overrides method in ExternalASTSource
2058  Module *getModule(unsigned ID) override;
2059 
2060  /// \brief Retrieve the module file with a given local ID within the specified
2061  /// ModuleFile.
2062  ModuleFile *getLocalModuleFile(ModuleFile &M, unsigned ID);
2063 
2064  /// \brief Get an ID for the given module file.
2065  unsigned getModuleFileID(ModuleFile *M);
2066 
2067  /// \brief Return a descriptor for the corresponding module.
2068  llvm::Optional<ASTSourceDescriptor> getSourceDescriptor(unsigned ID) override;
2069 
2070  ExtKind hasExternalDefinitions(const Decl *D) override;
2071 
2072  /// \brief Retrieve a selector from the given module with its local ID
2073  /// number.
2074  Selector getLocalSelector(ModuleFile &M, unsigned LocalID);
2075 
2076  Selector DecodeSelector(serialization::SelectorID Idx);
2077 
2078  Selector GetExternalSelector(serialization::SelectorID ID) override;
2079  uint32_t GetNumExternalSelectors() override;
2080 
2081  Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) {
2082  return getLocalSelector(M, Record[Idx++]);
2083  }
2084 
2085  /// \brief Retrieve the global selector ID that corresponds to this
2086  /// the local selector ID in a given module.
2087  serialization::SelectorID getGlobalSelectorID(ModuleFile &F,
2088  unsigned LocalID) const;
2089 
2090  /// \brief Read a declaration name.
2091  DeclarationName ReadDeclarationName(ModuleFile &F,
2092  const RecordData &Record, unsigned &Idx);
2093  void ReadDeclarationNameLoc(ModuleFile &F,
2094  DeclarationNameLoc &DNLoc, DeclarationName Name,
2095  const RecordData &Record, unsigned &Idx);
2096  void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo,
2097  const RecordData &Record, unsigned &Idx);
2098 
2099  void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info,
2100  const RecordData &Record, unsigned &Idx);
2101 
2102  NestedNameSpecifier *ReadNestedNameSpecifier(ModuleFile &F,
2103  const RecordData &Record,
2104  unsigned &Idx);
2105 
2106  NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F,
2107  const RecordData &Record,
2108  unsigned &Idx);
2109 
2110  /// \brief Read a template name.
2111  TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record,
2112  unsigned &Idx);
2113 
2114  /// \brief Read a template argument.
2115  TemplateArgument ReadTemplateArgument(ModuleFile &F, const RecordData &Record,
2116  unsigned &Idx,
2117  bool Canonicalize = false);
2118 
2119  /// \brief Read a template parameter list.
2120  TemplateParameterList *ReadTemplateParameterList(ModuleFile &F,
2121  const RecordData &Record,
2122  unsigned &Idx);
2123 
2124  /// \brief Read a template argument array.
2125  void ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs,
2126  ModuleFile &F, const RecordData &Record,
2127  unsigned &Idx, bool Canonicalize = false);
2128 
2129  /// \brief Read a UnresolvedSet structure.
2130  void ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set,
2131  const RecordData &Record, unsigned &Idx);
2132 
2133  /// \brief Read a C++ base specifier.
2134  CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F,
2135  const RecordData &Record,unsigned &Idx);
2136 
2137  /// \brief Read a CXXCtorInitializer array.
2139  ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record,
2140  unsigned &Idx);
2141 
2142  /// \brief Read the contents of a CXXCtorInitializer array.
2143  CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override;
2144 
2145  /// \brief Read a source location from raw form and return it in its
2146  /// originating module file's source location space.
2148  return SourceLocation::getFromRawEncoding((Raw >> 1) | (Raw << 31));
2149  }
2150 
2151  /// \brief Read a source location from raw form.
2152  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, uint32_t Raw) const {
2153  SourceLocation Loc = ReadUntranslatedSourceLocation(Raw);
2154  return TranslateSourceLocation(ModuleFile, Loc);
2155  }
2156 
2157  /// \brief Translate a source location from another module file's source
2158  /// location space into ours.
2159  SourceLocation TranslateSourceLocation(ModuleFile &ModuleFile,
2160  SourceLocation Loc) const {
2161  if (!ModuleFile.ModuleOffsetMap.empty())
2162  ReadModuleOffsetMap(ModuleFile);
2163  assert(ModuleFile.SLocRemap.find(Loc.getOffset()) !=
2164  ModuleFile.SLocRemap.end() &&
2165  "Cannot find offset to remap.");
2166  int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second;
2167  return Loc.getLocWithOffset(Remap);
2168  }
2169 
2170  /// \brief Read a source location.
2171  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
2172  const RecordDataImpl &Record,
2173  unsigned &Idx) {
2174  return ReadSourceLocation(ModuleFile, Record[Idx++]);
2175  }
2176 
2177  /// \brief Read a source range.
2178  SourceRange ReadSourceRange(ModuleFile &F,
2179  const RecordData &Record, unsigned &Idx);
2180 
2181  /// \brief Read an integral value
2182  llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx);
2183 
2184  /// \brief Read a signed integral value
2185  llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx);
2186 
2187  /// \brief Read a floating-point value
2188  llvm::APFloat ReadAPFloat(const RecordData &Record,
2189  const llvm::fltSemantics &Sem, unsigned &Idx);
2190 
2191  // \brief Read a string
2192  static std::string ReadString(const RecordData &Record, unsigned &Idx);
2193 
2194  // \brief Skip a string
2195  static void SkipString(const RecordData &Record, unsigned &Idx) {
2196  Idx += Record[Idx] + 1;
2197  }
2198 
2199  // \brief Read a path
2200  std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx);
2201 
2202  // \brief Skip a path
2203  static void SkipPath(const RecordData &Record, unsigned &Idx) {
2204  SkipString(Record, Idx);
2205  }
2206 
2207  /// \brief Read a version tuple.
2208  static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx);
2209 
2210  CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record,
2211  unsigned &Idx);
2212 
2213  /// \brief Reads attributes from the current stream position.
2214  void ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs);
2215 
2216  /// \brief Reads a statement.
2217  Stmt *ReadStmt(ModuleFile &F);
2218 
2219  /// \brief Reads an expression.
2220  Expr *ReadExpr(ModuleFile &F);
2221 
2222  /// \brief Reads a sub-statement operand during statement reading.
2224  assert(ReadingKind == Read_Stmt &&
2225  "Should be called only during statement reading!");
2226  // Subexpressions are stored from last to first, so the next Stmt we need
2227  // is at the back of the stack.
2228  assert(!StmtStack.empty() && "Read too many sub-statements!");
2229  return StmtStack.pop_back_val();
2230  }
2231 
2232  /// \brief Reads a sub-expression operand during statement reading.
2233  Expr *ReadSubExpr();
2234 
2235  /// \brief Reads a token out of a record.
2236  Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx);
2237 
2238  /// \brief Reads the macro record located at the given offset.
2239  MacroInfo *ReadMacroRecord(ModuleFile &F, uint64_t Offset);
2240 
2241  /// \brief Determine the global preprocessed entity ID that corresponds to
2242  /// the given local ID within the given module.
2244  getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const;
2245 
2246  /// \brief Add a macro to deserialize its macro directive history.
2247  ///
2248  /// \param II The name of the macro.
2249  /// \param M The module file.
2250  /// \param MacroDirectivesOffset Offset of the serialized macro directive
2251  /// history.
2252  void addPendingMacro(IdentifierInfo *II, ModuleFile *M,
2253  uint64_t MacroDirectivesOffset);
2254 
2255  /// \brief Read the set of macros defined by this external macro source.
2256  void ReadDefinedMacros() override;
2257 
2258  /// \brief Update an out-of-date identifier.
2259  void updateOutOfDateIdentifier(IdentifierInfo &II) override;
2260 
2261  /// \brief Note that this identifier is up-to-date.
2262  void markIdentifierUpToDate(IdentifierInfo *II);
2263 
2264  /// \brief Load all external visible decls in the given DeclContext.
2265  void completeVisibleDeclsMap(const DeclContext *DC) override;
2266 
2267  /// \brief Retrieve the AST context that this AST reader supplements.
2269  assert(ContextObj && "requested AST context when not loading AST");
2270  return *ContextObj;
2271  }
2272 
2273  // \brief Contains the IDs for declarations that were requested before we have
2274  // access to a Sema object.
2276 
2277  /// \brief Retrieve the semantic analysis object used to analyze the
2278  /// translation unit in which the precompiled header is being
2279  /// imported.
2280  Sema *getSema() { return SemaObj; }
2281 
2282  /// \brief Get the identifier resolver used for name lookup / updates
2283  /// in the translation unit scope. We have one of these even if we don't
2284  /// have a Sema object.
2285  IdentifierResolver &getIdResolver();
2286 
2287  /// \brief Retrieve the identifier table associated with the
2288  /// preprocessor.
2289  IdentifierTable &getIdentifierTable();
2290 
2291  /// \brief Record that the given ID maps to the given switch-case
2292  /// statement.
2293  void RecordSwitchCaseID(SwitchCase *SC, unsigned ID);
2294 
2295  /// \brief Retrieve the switch-case statement with the given ID.
2296  SwitchCase *getSwitchCaseWithID(unsigned ID);
2297 
2298  void ClearSwitchCaseIDs();
2299 
2300  /// \brief Cursors for comments blocks.
2301  SmallVector<std::pair<llvm::BitstreamCursor,
2303 
2304  /// \brief Loads comments ranges.
2305  void ReadComments() override;
2306 
2307  /// Visit all the input files of the given module file.
2308  void visitInputFiles(serialization::ModuleFile &MF,
2309  bool IncludeSystem, bool Complain,
2310  llvm::function_ref<void(const serialization::InputFile &IF,
2311  bool isSystem)> Visitor);
2312 
2313  /// Visit all the top-level module maps loaded when building the given module
2314  /// file.
2315  void visitTopLevelModuleMaps(serialization::ModuleFile &MF,
2316  llvm::function_ref<
2317  void(const FileEntry *)> Visitor);
2318 
2319  bool isProcessingUpdateRecords() { return ProcessingUpdateRecords; }
2320 };
2321 
2322 /// \brief An object for streaming information from a record.
2324  using ModuleFile = serialization::ModuleFile;
2325 
2326  ASTReader *Reader;
2327  ModuleFile *F;
2328  unsigned Idx = 0;
2329  ASTReader::RecordData Record;
2330 
2333 
2334 public:
2335  /// Construct an ASTRecordReader that uses the default encoding scheme.
2336  ASTRecordReader(ASTReader &Reader, ModuleFile &F) : Reader(&Reader), F(&F) {}
2337 
2338  /// \brief Reads a record with id AbbrevID from Cursor, resetting the
2339  /// internal state.
2340  unsigned readRecord(llvm::BitstreamCursor &Cursor, unsigned AbbrevID);
2341 
2342  /// \brief Is this a module file for a module (rather than a PCH or similar).
2343  bool isModule() const { return F->isModule(); }
2344 
2345  /// \brief Retrieve the AST context that this AST reader supplements.
2346  ASTContext &getContext() { return Reader->getContext(); }
2347 
2348  /// \brief The current position in this record.
2349  unsigned getIdx() const { return Idx; }
2350 
2351  /// \brief The length of this record.
2352  size_t size() const { return Record.size(); }
2353 
2354  /// \brief An arbitrary index in this record.
2355  const uint64_t &operator[](size_t N) { return Record[N]; }
2356 
2357  /// \brief The last element in this record.
2358  const uint64_t &back() const { return Record.back(); }
2359 
2360  /// \brief Returns the current value in this record, and advances to the
2361  /// next value.
2362  const uint64_t &readInt() { return Record[Idx++]; }
2363 
2364  /// \brief Returns the current value in this record, without advancing.
2365  const uint64_t &peekInt() { return Record[Idx]; }
2366 
2367  /// \brief Skips the specified number of values.
2368  void skipInts(unsigned N) { Idx += N; }
2369 
2370  /// \brief Retrieve the global submodule ID its local ID number.
2372  getGlobalSubmoduleID(unsigned LocalID) {
2373  return Reader->getGlobalSubmoduleID(*F, LocalID);
2374  }
2375 
2376  /// \brief Retrieve the submodule that corresponds to a global submodule ID.
2378  return Reader->getSubmodule(GlobalID);
2379  }
2380 
2381  /// \brief Read the record that describes the lexical contents of a DC.
2382  bool readLexicalDeclContextStorage(uint64_t Offset, DeclContext *DC) {
2383  return Reader->ReadLexicalDeclContextStorage(*F, F->DeclsCursor, Offset,
2384  DC);
2385  }
2386 
2387  /// \brief Read the record that describes the visible contents of a DC.
2388  bool readVisibleDeclContextStorage(uint64_t Offset,
2389  serialization::DeclID ID) {
2390  return Reader->ReadVisibleDeclContextStorage(*F, F->DeclsCursor, Offset,
2391  ID);
2392  }
2393 
2396  return Reader->readExceptionSpec(*F, ExceptionStorage, ESI, Record, Idx);
2397  }
2398 
2399  /// \brief Get the global offset corresponding to a local offset.
2400  uint64_t getGlobalBitOffset(uint32_t LocalOffset) {
2401  return Reader->getGlobalBitOffset(*F, LocalOffset);
2402  }
2403 
2404  /// \brief Reads a statement.
2405  Stmt *readStmt() { return Reader->ReadStmt(*F); }
2406 
2407  /// \brief Reads an expression.
2408  Expr *readExpr() { return Reader->ReadExpr(*F); }
2409 
2410  /// \brief Reads a sub-statement operand during statement reading.
2411  Stmt *readSubStmt() { return Reader->ReadSubStmt(); }
2412 
2413  /// \brief Reads a sub-expression operand during statement reading.
2414  Expr *readSubExpr() { return Reader->ReadSubExpr(); }
2415 
2416  /// \brief Reads a declaration with the given local ID in the given module.
2417  ///
2418  /// \returns The requested declaration, casted to the given return type.
2419  template<typename T>
2420  T *GetLocalDeclAs(uint32_t LocalID) {
2421  return cast_or_null<T>(Reader->GetLocalDecl(*F, LocalID));
2422  }
2423 
2424  /// \brief Reads a TemplateArgumentLocInfo appropriate for the
2425  /// given TemplateArgument kind, advancing Idx.
2428  return Reader->GetTemplateArgumentLocInfo(*F, Kind, Record, Idx);
2429  }
2430 
2431  /// \brief Reads a TemplateArgumentLoc, advancing Idx.
2434  return Reader->ReadTemplateArgumentLoc(*F, Record, Idx);
2435  }
2436 
2439  return Reader->ReadASTTemplateArgumentListInfo(*F, Record, Idx);
2440  }
2441 
2442  /// \brief Reads a declarator info from the given record, advancing Idx.
2444  return Reader->GetTypeSourceInfo(*F, Record, Idx);
2445  }
2446 
2447  /// \brief Map a local type ID within a given AST file to a global type ID.
2448  serialization::TypeID getGlobalTypeID(unsigned LocalID) const {
2449  return Reader->getGlobalTypeID(*F, LocalID);
2450  }
2451 
2452  /// \brief Read a type from the current position in the record.
2454  return Reader->readType(*F, Record, Idx);
2455  }
2456 
2457  /// \brief Reads a declaration ID from the given position in this record.
2458  ///
2459  /// \returns The declaration ID read from the record, adjusted to a global ID.
2461  return Reader->ReadDeclID(*F, Record, Idx);
2462  }
2463 
2464  /// \brief Reads a declaration from the given position in a record in the
2465  /// given module, advancing Idx.
2466  Decl *readDecl() {
2467  return Reader->ReadDecl(*F, Record, Idx);
2468  }
2469 
2470  /// \brief Reads a declaration from the given position in the record,
2471  /// advancing Idx.
2472  ///
2473  /// \returns The declaration read from this location, casted to the given
2474  /// result type.
2475  template<typename T>
2477  return Reader->ReadDeclAs<T>(*F, Record, Idx);
2478  }
2479 
2481  return Reader->GetIdentifierInfo(*F, Record, Idx);
2482  }
2483 
2484  /// \brief Read a selector from the Record, advancing Idx.
2486  return Reader->ReadSelector(*F, Record, Idx);
2487  }
2488 
2489  /// \brief Read a declaration name, advancing Idx.
2491  return Reader->ReadDeclarationName(*F, Record, Idx);
2492  }
2494  return Reader->ReadDeclarationNameLoc(*F, DNLoc, Name, Record, Idx);
2495  }
2497  return Reader->ReadDeclarationNameInfo(*F, NameInfo, Record, Idx);
2498  }
2499 
2501  return Reader->ReadQualifierInfo(*F, Info, Record, Idx);
2502  }
2503 
2505  return Reader->ReadNestedNameSpecifier(*F, Record, Idx);
2506  }
2507 
2509  return Reader->ReadNestedNameSpecifierLoc(*F, Record, Idx);
2510  }
2511 
2512  /// \brief Read a template name, advancing Idx.
2514  return Reader->ReadTemplateName(*F, Record, Idx);
2515  }
2516 
2517  /// \brief Read a template argument, advancing Idx.
2518  TemplateArgument readTemplateArgument(bool Canonicalize = false) {
2519  return Reader->ReadTemplateArgument(*F, Record, Idx, Canonicalize);
2520  }
2521 
2522  /// \brief Read a template parameter list, advancing Idx.
2524  return Reader->ReadTemplateParameterList(*F, Record, Idx);
2525  }
2526 
2527  /// \brief Read a template argument array, advancing Idx.
2529  bool Canonicalize = false) {
2530  return Reader->ReadTemplateArgumentList(TemplArgs, *F, Record, Idx,
2531  Canonicalize);
2532  }
2533 
2534  /// \brief Read a UnresolvedSet structure, advancing Idx.
2536  return Reader->ReadUnresolvedSet(*F, Set, Record, Idx);
2537  }
2538 
2539  /// \brief Read a C++ base specifier, advancing Idx.
2541  return Reader->ReadCXXBaseSpecifier(*F, Record, Idx);
2542  }
2543 
2544  /// \brief Read a CXXCtorInitializer array, advancing Idx.
2546  return Reader->ReadCXXCtorInitializers(*F, Record, Idx);
2547  }
2548 
2550  return Reader->ReadCXXTemporary(*F, Record, Idx);
2551  }
2552 
2553  /// \brief Read a source location, advancing Idx.
2555  return Reader->ReadSourceLocation(*F, Record, Idx);
2556  }
2557 
2558  /// \brief Read a source range, advancing Idx.
2560  return Reader->ReadSourceRange(*F, Record, Idx);
2561  }
2562 
2563  /// \brief Read an integral value, advancing Idx.
2564  llvm::APInt readAPInt() {
2565  return Reader->ReadAPInt(Record, Idx);
2566  }
2567 
2568  /// \brief Read a signed integral value, advancing Idx.
2569  llvm::APSInt readAPSInt() {
2570  return Reader->ReadAPSInt(Record, Idx);
2571  }
2572 
2573  /// \brief Read a floating-point value, advancing Idx.
2574  llvm::APFloat readAPFloat(const llvm::fltSemantics &Sem) {
2575  return Reader->ReadAPFloat(Record, Sem,Idx);
2576  }
2577 
2578  /// \brief Read a string, advancing Idx.
2579  std::string readString() {
2580  return Reader->ReadString(Record, Idx);
2581  }
2582 
2583  /// \brief Read a path, advancing Idx.
2584  std::string readPath() {
2585  return Reader->ReadPath(*F, Record, Idx);
2586  }
2587 
2588  /// \brief Read a version tuple, advancing Idx.
2590  return ASTReader::ReadVersionTuple(Record, Idx);
2591  }
2592 
2593  /// \brief Reads attributes from the current stream position, advancing Idx.
2594  void readAttributes(AttrVec &Attrs) {
2595  return Reader->ReadAttributes(*this, Attrs);
2596  }
2597 
2598  /// \brief Reads a token out of a record, advancing Idx.
2600  return Reader->ReadToken(*F, Record, Idx);
2601  }
2602 
2603  void recordSwitchCaseID(SwitchCase *SC, unsigned ID) {
2604  Reader->RecordSwitchCaseID(SC, ID);
2605  }
2606 
2607  /// \brief Retrieve the switch-case statement with the given ID.
2609  return Reader->getSwitchCaseWithID(ID);
2610  }
2611 };
2612 
2613 /// \brief Helper class that saves the current stream position and
2614 /// then restores it when destroyed.
2616  explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor)
2617  : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) {}
2618 
2620  Cursor.JumpToBit(Offset);
2621  }
2622 
2623 private:
2624  llvm::BitstreamCursor &Cursor;
2625  uint64_t Offset;
2626 };
2627 
2628 inline void PCHValidator::Error(const char *Msg) {
2629  Reader.Error(Msg);
2630 }
2631 
2632 } // namespace clang
2633 
2634 #endif // LLVM_CLANG_SERIALIZATION_ASTREADER_H
llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx)
Read an integral value.
Definition: ASTReader.cpp:8907
const uint64_t & readInt()
Returns the current value in this record, and advances to the next value.
Definition: ASTReader.h:2362
SmallVector< std::pair< llvm::BitstreamCursor, serialization::ModuleFile * >, 8 > CommentsCursors
Cursors for comments blocks.
Definition: ASTReader.h:2302
Decl * GetLocalDecl(ModuleFile &F, uint32_t LocalID)
Reads a declaration with the given local ID in the given module.
Definition: ASTReader.h:1808
ASTReadResult
The result of reading the control block of an AST file, which can fail for various reasons...
Definition: ASTReader.h:384
SourceLocation readSourceLocation()
Read a source location, advancing Idx.
Definition: ASTReader.h:2554
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1698
SourceLocation ReadUntranslatedSourceLocation(uint32_t Raw) const
Read a source location from raw form and return it in its originating module file&#39;s source location s...
Definition: ASTReader.h:2147
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.
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
Smart pointer class that efficiently represents Objective-C method names.
A (possibly-)qualified type.
Definition: Type.h:653
virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain, std::string &SuggestedPredefines)
Receives the preprocessor options.
Definition: ASTReader.h:199
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:26
virtual bool visitInputFile(StringRef Filename, bool isSystem, bool isOverridden, bool isExplicitModule)
if needsInputFileVisitation returns true, this is called for each non-system input file of the AST Fi...
Definition: ASTReader.h:227
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:116
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
Definition: ASTConsumer.h:34
virtual void visitModuleFile(StringRef Filename, serialization::ModuleKind Kind)
This is called for each AST file loaded.
Definition: ASTReader.h:210
SourceManager & getSourceManager() const
Definition: ASTReader.h:1475
RAII class for safely pairing a StartedDeserializing call with FinishedDeserializing.
OpenCL supported extensions and optional core features.
Definition: OpenCLOptions.h:23
ASTRecordReader(ASTReader &Reader, ModuleFile &F)
Construct an ASTRecordReader that uses the default encoding scheme.
Definition: ASTReader.h:2336
Stmt - This represents one statement.
Definition: Stmt.h:66
ModuleManager::ModuleReverseIterator ModuleReverseIterator
Definition: ASTReader.h:415
C Language Family Type Representation.
GlobalModuleIndex * getGlobalIndex()
Return global module index.
Definition: ASTReader.h:1600
Module * getSubmodule(serialization::SubmoduleID GlobalID)
Retrieve the submodule that corresponds to a global submodule ID.
Definition: ASTReader.cpp:8313
SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, uint32_t Raw) const
Read a source location from raw form.
Definition: ASTReader.h:2152
Defines the clang::Module class, which describes a module in the source code.
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
virtual void ReadCounter(const serialization::ModuleFile &M, unsigned Value)
Receives COUNTER value.
Definition: ASTReader.h:206
llvm::APFloat readAPFloat(const llvm::fltSemantics &Sem)
Read a floating-point value, advancing Idx.
Definition: ASTReader.h:2574
The base class of the type hierarchy.
Definition: Type.h:1353
StringRef getOriginalSourceFile()
Retrieve the name of the original source file name for the primary module file.
Definition: ASTReader.h:1641
Decl * GetDecl(serialization::DeclID ID)
Resolve a declaration ID into a declaration, potentially building a new declaration.
Definition: ASTReader.cpp:7193
ModuleManager::ModuleConstIterator ModuleConstIterator
Definition: ASTReader.h:414
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:86
Base class that describes a preprocessed entity, which may be a preprocessor directive or macro expan...
void readQualifierInfo(QualifierInfo &Info)
Definition: ASTReader.h:2500
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a C++ base specifier.
Definition: ASTReader.cpp:8698
ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod, const serialization::LocalDeclID *Pos)
Definition: ASTReader.h:1379
Manages the set of modules loaded by an AST reader.
Definition: ModuleManager.h:49
Options for controlling the target.
Definition: TargetOptions.h:26
Manage memory buffers across multiple users.
unsigned getTotalNumPreprocessedEntities() const
Returns the number of preprocessed entities known to the AST reader.
Definition: ASTReader.h:1734
void recordSwitchCaseID(SwitchCase *SC, unsigned ID)
Definition: ASTReader.h:2603
QualType readType()
Read a type from the current position in the record.
Definition: ASTReader.h:2453
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:595
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:68
T * ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I)
Reads a declaration from the given position in a record in the given module.
Definition: ASTReader.h:1848
Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.h:2081
Module * getSubmodule(serialization::SubmoduleID GlobalID)
Retrieve the submodule that corresponds to a global submodule ID.
Definition: ASTReader.h:2377
An UnresolvedSet-like class that might not have been loaded from the external AST source yet...
serialization::TypeID getGlobalTypeID(unsigned LocalID) const
Map a local type ID within a given AST file to a global type ID.
Definition: ASTReader.h:2448
StringRef ModuleOffsetMap
The module offset map data for this file.
Definition: Module.h:205
NestedNameSpecifierLoc readNestedNameSpecifierLoc()
Definition: ASTReader.h:2508
One of these records is kept for each identifier that is lexed.
T * readDeclAs()
Reads a declaration from the given position in the record, advancing Idx.
Definition: ASTReader.h:2476
T * GetLocalDeclAs(ModuleFile &F, uint32_t LocalID)
Reads a declaration with the given local ID in the given module.
Definition: ASTReader.h:1816
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:149
A C++ nested-name-specifier augmented with source location information.
Utility class for loading a ASTContext from an AST file.
Definition: ASTUnit.h:71
unsigned getTotalNumDecls() const
Returns the number of declarations found in the chain.
Definition: ASTReader.h:1718
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
Definition: Decl.h:2461
Definition: Format.h:1900
Expr * readExpr()
Reads an expression.
Definition: ASTReader.h:2408
Helper class that saves the current stream position and then restores it when destroyed.
Definition: ASTReader.h:2615
TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a template name.
Definition: ASTReader.cpp:8542
virtual bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, bool AllowCompatibleDifferences)
Receives the language options.
Definition: ASTReader.h:147
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
TemplateArgument readTemplateArgument(bool Canonicalize=false)
Read a template argument, advancing Idx.
Definition: ASTReader.h:2518
Sema * getSema()
Retrieve the semantic analysis object used to analyze the translation unit in which the precompiled h...
Definition: ASTReader.h:2280
Stmt * ReadSubStmt()
Reads a sub-statement operand during statement reading.
Definition: ASTReader.h:2223
uint32_t MacroID
An ID number that refers to a macro in an AST file.
Definition: ASTBitCodes.h:141
The signature of a module, which is a hash of the AST content.
Definition: Module.h:55
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
static void SkipString(const RecordData &Record, unsigned &Idx)
Definition: ASTReader.h:2195
TypeSourceInfo * getTypeSourceInfo()
Reads a declarator info from the given record, advancing Idx.
Definition: ASTReader.h:2443
Decl * getKeyDeclaration(Decl *D)
Returns the first key declaration for the given declaration.
Definition: ASTReader.h:1209
Describes a module or submodule.
Definition: Module.h:65
size_t size() const
The length of this record.
Definition: ASTReader.h:2352
static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx)
Read a version tuple.
Definition: ASTReader.cpp:8943
ImportedSubmodule(serialization::SubmoduleID ID, SourceLocation ImportLoc)
Definition: ASTReader.h:900
FileManager & getFileManager() const
Definition: ASTReader.h:1476
TypeSourceInfo * GetTypeSourceInfo(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Reads a declarator info from the given record.
Definition: ASTReader.cpp:6690
uint32_t Offset
Definition: CacheTokens.cpp:43
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
ModuleManager & getModuleManager()
Retrieve the module manager.
Definition: ASTReader.h:1634
void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:8528
serialization::DeclID getGlobalDeclID(ModuleFile &F, serialization::LocalDeclID LocalID) const
Map from a local declaration ID within a given module to a global declaration ID. ...
Definition: ASTReader.cpp:7061
CXXCtorInitializer ** ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a CXXCtorInitializer array.
Definition: ASTReader.cpp:8714
llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx)
Read a signed integral value.
Definition: ASTReader.cpp:8916
SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, const RecordDataImpl &Record, unsigned &Idx)
Read a source location.
Definition: ASTReader.h:2171
std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:8936
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:147
serialization::SubmoduleID getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID)
Retrieve the global submodule ID given a module and its local ID number.
Definition: ASTReader.cpp:8298
CXXTemporary * ReadCXXTemporary(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:8955
TemplateArgument ReadTemplateArgument(ModuleFile &F, const RecordData &Record, unsigned &Idx, bool Canonicalize=false)
Read a template argument.
Definition: ASTReader.cpp:8601
ASTContext & getContext()
Retrieve the AST context that this AST reader supplements.
Definition: ASTReader.h:2268
Defines the Diagnostic-related interfaces.
SourceRange readSourceRange()
Read a source range, advancing Idx.
Definition: ASTReader.h:2559
const Decl * getKeyDeclaration(const Decl *D)
Definition: ASTReader.h:1219
std::string OriginalSourceFileName
The original source file name that was used to build the primary AST file, which may have been modifi...
Definition: Module.h:130
void resetForReload()
Reset reader for a reload try.
Definition: ASTReader.h:1603
TemplateArgumentLocInfo getTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind)
Reads a TemplateArgumentLocInfo appropriate for the given TemplateArgument kind, advancing Idx...
Definition: ASTReader.h:2427
ContinuousRangeMap< uint32_t, int, 2 > SLocRemap
Remapping table for source locations in this module.
Definition: Module.h:249
const ASTTemplateArgumentListInfo * readASTTemplateArgumentListInfo()
Definition: ASTReader.h:2438
Represents an ObjC class declaration.
Definition: DeclObjC.h:1191
This abstract interface provides operations for unwrapping containers for serialized ASTs (precompile...
CXXBaseSpecifier readCXXBaseSpecifier()
Read a C++ base specifier, advancing Idx.
Definition: ASTReader.h:2540
The AST file itself appears corrupted.
Definition: ASTReader.h:390
The preprocessor keeps track of this information for each file that is #included. ...
Definition: HeaderSearch.h:51
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:865
const uint64_t & peekInt()
Returns the current value in this record, without advancing.
Definition: ASTReader.h:2365
virtual bool needsInputFileVisitation()
Returns true if this ASTReaderListener wants to receive the input files of the AST file via visitInpu...
Definition: ASTReader.h:215
static std::string ReadString(const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:8929
virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts, bool Complain)
Receives the file system options.
Definition: ASTReader.h:176
IdentifierInfo * GetIdentifierInfo(ModuleFile &M, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.h:2013
void ForgetSema() override
Inform the semantic consumer that Sema is no longer available.
Definition: ASTReader.h:1933
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:274
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:955
TemplateParameterList * readTemplateParameterList()
Read a template parameter list, advancing Idx.
Definition: ASTReader.h:2523
virtual bool needsImportVisitation() const
Returns true if this ASTReaderListener wants to receive the imports of the AST file via visitImport...
Definition: ASTReader.h:234
bool operator==(const ModuleDeclIterator &RHS) const
Definition: ASTReader.h:1389
ModuleKind
Specifies the kind of module that has been loaded.
Definition: Module.h:47
StringRef Filename
Definition: Format.cpp:1345
Provides lookups to, and iteration over, IdentiferInfo objects.
void readTemplateArgumentList(SmallVectorImpl< TemplateArgument > &TemplArgs, bool Canonicalize=false)
Read a template argument array, advancing Idx.
Definition: ASTReader.h:2528
Decl * ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I)
Reads a declaration from the given position in a record in the given module.
Definition: ASTReader.h:1838
std::string readPath()
Read a path, advancing Idx.
Definition: ASTReader.h:2584
llvm::pointee_iterator< SmallVectorImpl< std::unique_ptr< ModuleFile > >::reverse_iterator > ModuleReverseIterator
ASTReaderListener implementation to validate the information of the PCH file against an initialized P...
Definition: ASTReader.h:291
serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const
Map a local type ID within a given AST file into a global type ID.
Definition: ASTReader.cpp:6878
Abstract interface for external sources of preprocessor information.
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Definition: Decl.h:628
Expr - This represents one expression.
Definition: Expr.h:106
SwitchCase * getSwitchCaseWithID(unsigned ID)
Retrieve the switch-case statement with the given ID.
Definition: ASTReader.cpp:8985
const FunctionProtoType * T
QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a type from the current position in the given record, which was read from the given AST file...
Definition: ASTReader.h:1772
RAII object to temporarily add an AST callback listener.
Definition: ASTReader.h:1568
Stmt * ReadStmt(ModuleFile &F)
Reads a statement.
Implements an efficient mapping from strings to IdentifierInfo nodes.
Stmt * readStmt()
Reads a statement.
Definition: ASTReader.h:2405
virtual void readModuleFileExtension(const ModuleFileExtensionMetadata &Metadata)
Indicates that a particular module file extension has been read.
Definition: ASTReader.h:241
Defines version macros and version-related utility functions for Clang.
unsigned getTotalNumSubmodules() const
Returns the number of submodules known.
Definition: ASTReader.h:1723
ArgKind
The kind of template argument we&#39;re storing.
Definition: TemplateBase.h:54
SimpleASTReaderListener(Preprocessor &PP)
Definition: ASTReader.h:324
ASTReaderListenter implementation to set SuggestedPredefines of ASTReader which is required to use a ...
Definition: ASTReader.h:320
SourceRange ReadSourceRange(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a source range.
Definition: ASTReader.cpp:8899
IdentifierResolver - Keeps track of shadowed decls on enclosing scopes.
Decl * readDecl()
Reads a declaration from the given position in a record in the given module, advancing Idx...
Definition: ASTReader.h:2466
Represents a C++ template name within the type system.
Definition: TemplateName.h:178
Information about a module that has been loaded by the ASTReader.
Definition: Module.h:100
const uint64_t & back() const
The last element in this record.
Definition: ASTReader.h:2358
uint32_t IdentifierID
An ID number that refers to an identifier in an AST file.
Definition: ASTBitCodes.h:61
An iterator that walks over all of the known identifiers in the lookup table.
llvm::pointee_iterator< SmallVectorImpl< std::unique_ptr< ModuleFile > >::const_iterator > ModuleConstIterator
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
IdentifierInfo * getIdentifierInfo()
Definition: ASTReader.h:2480
SavedStreamPosition(llvm::BitstreamCursor &Cursor)
Definition: ASTReader.h:2616
The result type of a method or function.
std::string readString()
Read a string, advancing Idx.
Definition: ASTReader.h:2579
DiagnosticsEngine & getDiags() const
Definition: ASTReader.h:1477
SmallVector< uint64_t, 16 > PreloadedDeclIDs
Definition: ASTReader.h:2275
void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:8518
void skipInts(unsigned N)
Skips the specified number of values.
Definition: ASTReader.h:2368
const uint64_t & operator[](size_t N)
An arbitrary index in this record.
Definition: ASTReader.h:2355
bool isModule() const
Is this a module file for a module (rather than a PCH or similar).
Definition: ASTReader.h:2343
The AST file was missing.
Definition: ASTReader.h:393
An abstract interface that should be implemented by external AST sources that also provide informatio...
NestedNameSpecifier * ReadNestedNameSpecifier(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:8780
void addInMemoryBuffer(StringRef FileName, std::unique_ptr< llvm::MemoryBuffer > Buffer)
Add an in-memory buffer the list of known buffers.
uint32_t SubmoduleID
An ID number that refers to a submodule in a module file.
Definition: ASTBitCodes.h:172
static void SkipPath(const RecordData &Record, unsigned &Idx)
Definition: ASTReader.h:2203
Defines the clang::OpenCLOptions class.
QualifierInfo - A struct with extended info about a syntactic name qualifier, to be used for the case...
Definition: Decl.h:653
The control block was read successfully.
Definition: ASTReader.h:387
Kind
void addListener(std::unique_ptr< ASTReaderListener > L)
Add an AST callback listener.
Definition: ASTReader.h:1560
CXXTemporary * readCXXTemporary()
Definition: ASTReader.h:2549
Encodes a location in the source.
unsigned getTotalNumMacros() const
Returns the number of macros found in the chain.
Definition: ASTReader.h:1708
Stmt * readSubStmt()
Reads a sub-statement operand during statement reading.
Definition: ASTReader.h:2411
Represents a C++ temporary.
Definition: ExprCXX.h:1164
CXXCtorInitializer ** readCXXCtorInitializers()
Read a CXXCtorInitializer array, advancing Idx.
Definition: ASTReader.h:2545
An identifier-lookup iterator that enumerates all of the identifiers stored within a set of AST files...
Definition: ASTReader.cpp:7740
std::unique_ptr< ASTReaderListener > takeListener()
Take the AST callbacks listener.
Definition: ASTReader.h:1548
bool readLexicalDeclContextStorage(uint64_t Offset, DeclContext *DC)
Read the record that describes the lexical contents of a DC.
Definition: ASTReader.h:2382
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:59
bool isModule() const
Is this a module file for a module (rather than a PCH or similar).
Definition: Module.h:458
bool isProcessingUpdateRecords()
Definition: ASTReader.h:2319
void readDeclarationNameInfo(DeclarationNameInfo &NameInfo)
Definition: ASTReader.h:2496
TemplateParameterList * ReadTemplateParameterList(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a template parameter list.
Definition: ASTReader.cpp:8656
An abstract class that should be subclassed by any external source of preprocessing record entries...
Expr * readSubExpr()
Reads a sub-expression operand during statement reading.
Definition: ASTReader.h:2414
T * GetLocalDeclAs(uint32_t LocalID)
Reads a declaration with the given local ID in the given module.
Definition: ASTReader.h:2420
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
std::string getClangFullRepositoryVersion()
Retrieves the full repository version that is an amalgamation of the information in getClangRepositor...
Definition: Version.cpp:90
virtual bool ReadFullVersionInformation(StringRef FullVersion)
Receives the full Clang version information.
Definition: ASTReader.h:137
void readDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name)
Definition: ASTReader.h:2493
void addInMemoryBuffer(StringRef &FileName, std::unique_ptr< llvm::MemoryBuffer > Buffer)
Add in-memory (virtual file) buffer.
Definition: ASTReader.h:1621
PCHValidator(Preprocessor &PP, ASTReader &Reader)
Definition: ASTReader.h:296
unsigned getIdx() const
The current position in this record.
Definition: ASTReader.h:2349
ASTContext & getContext()
Retrieve the AST context that this AST reader supplements.
Definition: ASTReader.h:2346
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Definition: DeclBase.h:694
uint32_t TypeID
An ID number that refers to a type in an AST file.
Definition: ASTBitCodes.h:86
void setListener(std::unique_ptr< ASTReaderListener > Listener)
Set the AST callbacks listener.
Definition: ASTReader.h:1553
void readExceptionSpec(SmallVectorImpl< QualType > &ExceptionStorage, FunctionProtoType::ExceptionSpecInfo &ESI)
Definition: ASTReader.h:2394
serialization::SubmoduleID getGlobalSubmoduleID(unsigned LocalID)
Retrieve the global submodule ID its local ID number.
Definition: ASTReader.h:2372
External source of source location entries.
virtual void visitImport(StringRef Filename)
If needsImportVisitation returns true, this is called for each AST file imported by this AST file...
Definition: ASTReader.h:238
serialization::SubmoduleID ID
Definition: ASTReader.h:897
A global index for a set of module files, providing information about the identifiers within those mo...
uint32_t PreprocessedEntityID
An ID number that refers to an entity in the detailed preprocessing record.
Definition: ASTBitCodes.h:169
DeclarationName ReadDeclarationName(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a declaration name.
Definition: ASTReader.cpp:8441
unsigned getTotalNumSelectors() const
Returns the number of selectors found in the chain.
Definition: ASTReader.h:1728
The AST file was writtten with a different language/target configuration.
Definition: ASTReader.h:404
llvm::APFloat ReadAPFloat(const RecordData &Record, const llvm::fltSemantics &Sem, unsigned &Idx)
Read a floating-point value.
Definition: ASTReader.cpp:8922
The input file that has been loaded from this AST file, along with bools indicating whether this was ...
Definition: Module.h:59
serialization::DeclID readDeclID()
Reads a declaration ID from the given position in this record.
Definition: ASTReader.h:2460
void readAttributes(AttrVec &Attrs)
Reads attributes from the current stream position, advancing Idx.
Definition: ASTReader.h:2594
DeclarationNameLoc - Additional source/type location info for a declaration name. ...
ChainedASTReaderListener(std::unique_ptr< ASTReaderListener > First, std::unique_ptr< ASTReaderListener > Second)
Takes ownership of First and Second.
Definition: ASTReader.h:252
unsigned getTotalNumTypes() const
Returns the number of types found in the chain.
Definition: ASTReader.h:1713
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Represents a template argument.
Definition: TemplateBase.h:51
const ASTTemplateArgumentListInfo * ReadASTTemplateArgumentListInfo(ModuleFile &F, const RecordData &Record, unsigned &Index)
Definition: ASTReader.cpp:6946
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
Definition: ASTBitCodes.h:154
Dataflow Directional Tag Classes.
llvm::BitstreamCursor DeclsCursor
DeclsCursor - This is a cursor to the start of the DECLS_BLOCK block.
Definition: Module.h:387
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1252
An external source of header file information, which may supply information about header files alread...
Definition: HeaderSearch.h:134
SourceLocation TranslateSourceLocation(ModuleFile &ModuleFile, SourceLocation Loc) const
Translate a source location from another module file&#39;s source location space into ours...
Definition: ASTReader.h:2159
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:358
Selector readSelector()
Read a selector from the Record, advancing Idx.
Definition: ASTReader.h:2485
Expr * ReadExpr(ModuleFile &F)
Reads an expression.
ListenerScope(ASTReader &Reader, std::unique_ptr< ASTReaderListener > L)
Definition: ASTReader.h:1573
ModuleFile & getPrimaryModule()
Returns the primary module associated with the manager, that is, the first module loaded...
ModuleManager::ModuleIterator ModuleIterator
Definition: ASTReader.h:413
bool hasGlobalIndex() const
Determine whether this AST reader has a global index.
Definition: ASTReader.h:1597
LoadFailureCapabilities
Flags that indicate what kind of AST loading failures the client of the AST reader can directly handl...
Definition: ASTReader.h:1484
DeclarationName - The name of a declaration.
virtual void ReadModuleMapFile(StringRef ModuleMapPath)
Definition: ASTReader.h:142
TemplateArgumentLoc readTemplateArgumentLoc()
Reads a TemplateArgumentLoc, advancing Idx.
Definition: ASTReader.h:2433
A map from continuous integer ranges to some value, with a very specialized interface.
Class that performs lookup for an identifier stored in an AST file.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
void ReadDeclarationNameLoc(ModuleFile &F, DeclarationNameLoc &DNLoc, DeclarationName Name, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:8485
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
Definition: ASTBitCodes.h:69
VersionTuple readVersionTuple()
Read a version tuple, advancing Idx.
Definition: ASTReader.h:2589
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:40
SmallVector< uint64_t, 64 > RecordData
Definition: ASTReader.h:379
void ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set, const RecordData &Record, unsigned &Idx)
Read a UnresolvedSet structure.
Definition: ASTReader.cpp:8686
Abstract interface for callback invocations by the ASTReader.
Definition: ASTReader.h:129
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:450
NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Definition: ASTReader.cpp:8835
Defines the clang::FileSystemOptions interface.
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2172
uint64_t getGlobalBitOffset(uint32_t LocalOffset)
Get the global offset corresponding to a local offset.
Definition: ASTReader.h:2400
void ReadTemplateArgumentList(SmallVectorImpl< TemplateArgument > &TemplArgs, ModuleFile &F, const RecordData &Record, unsigned &Idx, bool Canonicalize=false)
Read a template argument array.
Definition: ASTReader.cpp:8676
llvm::APSInt readAPSInt()
Read a signed integral value, advancing Idx.
Definition: ASTReader.h:2569
void forEachImportedKeyDecl(const Decl *D, Fn Visit)
Run a callback on each imported key declaration of D.
Definition: ASTReader.h:1225
Preprocessor & getPreprocessor() const
Retrieve the preprocessor.
Definition: ASTReader.h:1637
Represents a base class of a C++ class.
Definition: DeclCXX.h:191
Metadata for a module file extension.
Keeps track of options that affect how file operations are performed.
virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, bool Complain)
Receives the header search options.
Definition: ASTReader.h:185
TemplateName readTemplateName()
Read a template name, advancing Idx.
Definition: ASTReader.h:2513
SmallVectorImpl< uint64_t > RecordDataImpl
Definition: ASTReader.h:380
Defines the clang::SourceLocation class and associated facilities.
TemplateArgumentLoc ReadTemplateArgumentLoc(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Reads a TemplateArgumentLoc.
Definition: ASTReader.cpp:6933
TemplateArgumentLocInfo GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind, const RecordData &Record, unsigned &Idx)
Reads a TemplateArgumentLocInfo appropriate for the given TemplateArgument kind.
Definition: ASTReader.cpp:6897
serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Reads a declaration ID from the given position in a record in the given module.
Definition: ASTReader.cpp:7231
virtual bool needsSystemInputFileVisitation()
Returns true if this ASTReaderListener wants to receive the system input files of the AST file via vi...
Definition: ASTReader.h:219
Expr * ReadSubExpr()
Reads a sub-expression operand during statement reading.
Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx)
Reads a token out of a record.
Definition: ASTReader.cpp:1548
IdentifierInfo * GetIdentifier(serialization::IdentifierID ID) override
Definition: ASTReader.h:2018
unsigned getTotalNumSLocs() const
Returns the number of source locations found in the chain.
Definition: ASTReader.h:1698
Location information for a TemplateArgument.
Definition: TemplateBase.h:393
DeclarationName readDeclarationName()
Read a declaration name, advancing Idx.
Definition: ASTReader.h:2490
virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, bool AllowCompatibleDifferences)
Receives the target options.
Definition: ASTReader.h:157
Writes an AST file containing the contents of a translation unit.
Definition: ASTWriter.h:104
virtual void ReadModuleName(StringRef ModuleName)
Definition: ASTReader.h:141
unsigned getTotalNumIdentifiers() const
Returns the number of identifiers found in the chain.
Definition: ASTReader.h:1703
llvm::APInt readAPInt()
Read an integral value, advancing Idx.
Definition: ASTReader.h:2564
The AST file is out-of-date relative to its input files, and needs to be regenerated.
Definition: ASTReader.h:397
Defines the clang::VersionTuple class, which represents a version in the form major[.minor[.subminor]].
NameVisibilityKind
Describes the visibility of the various names within a particular module.
Definition: Module.h:260
Simple wrapper class for chaining listeners.
Definition: ASTReader.h:246
An object for streaming information from a record.
Definition: ASTReader.h:2323
bool readVisibleDeclContextStorage(uint64_t Offset, serialization::DeclID ID)
Read the record that describes the visible contents of a DC.
Definition: ASTReader.h:2388
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:89
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
The AST file was written by a different version of Clang.
Definition: ASTReader.h:400
void ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs)
Reads attributes from the current stream position.
NestedNameSpecifier * readNestedNameSpecifier()
Definition: ASTReader.h:2504
Token readToken()
Reads a token out of a record, advancing Idx.
Definition: ASTReader.h:2599
std::unique_ptr< ASTReaderListener > takeSecond()
Definition: ASTReader.h:257
const std::string & getSuggestedPredefines()
Returns the suggested contents of the predefines buffer, which contains a (typically-empty) subset of...
Definition: ASTReader.h:1674
A trivial tuple used to represent a source range.
NamedDecl - This represents a decl with a name.
Definition: Decl.h:245
SwitchCase * getSwitchCaseWithID(unsigned ID)
Retrieve the switch-case statement with the given ID.
Definition: ASTReader.h:2608
llvm::pointee_iterator< SmallVectorImpl< std::unique_ptr< ModuleFile > >::iterator > ModuleIterator
std::unique_ptr< ASTReaderListener > takeFirst()
Definition: ASTReader.h:256
bool isSystem(CharacteristicKind CK)
Determine whether a file / directory characteristic is for system code.
Definition: SourceManager.h:83
This class handles loading and caching of source files into memory.
virtual bool ReadDiagnosticOptions(IntrusiveRefCntPtr< DiagnosticOptions > DiagOpts, bool Complain)
Receives the diagnostic options.
Definition: ASTReader.h:167
void RecordSwitchCaseID(SwitchCase *SC, unsigned ID)
Record that the given ID maps to the given switch-case statement.
Definition: ASTReader.cpp:8978
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:127
void readUnresolvedSet(LazyASTUnresolvedSet &Set)
Read a UnresolvedSet structure, advancing Idx.
Definition: ASTReader.h:2535