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