1327952Sdim//===- ASTReader.h - AST File Reader ----------------------------*- C++ -*-===//
2212795Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6212795Sdim//
7212795Sdim//===----------------------------------------------------------------------===//
8212795Sdim//
9212795Sdim//  This file defines the ASTReader class, which reads AST files.
10212795Sdim//
11212795Sdim//===----------------------------------------------------------------------===//
12212795Sdim
13280031Sdim#ifndef LLVM_CLANG_SERIALIZATION_ASTREADER_H
14280031Sdim#define LLVM_CLANG_SERIALIZATION_ASTREADER_H
15212795Sdim
16327952Sdim#include "clang/AST/Type.h"
17212795Sdim#include "clang/Basic/Diagnostic.h"
18327952Sdim#include "clang/Basic/DiagnosticOptions.h"
19212795Sdim#include "clang/Basic/IdentifierTable.h"
20327952Sdim#include "clang/Basic/OpenCLOptions.h"
21327952Sdim#include "clang/Basic/SourceLocation.h"
22249423Sdim#include "clang/Basic/Version.h"
23249423Sdim#include "clang/Lex/ExternalPreprocessorSource.h"
24249423Sdim#include "clang/Lex/HeaderSearch.h"
25249423Sdim#include "clang/Lex/PreprocessingRecord.h"
26249423Sdim#include "clang/Sema/ExternalSemaSource.h"
27309124Sdim#include "clang/Sema/IdentifierResolver.h"
28249423Sdim#include "clang/Serialization/ASTBitCodes.h"
29249423Sdim#include "clang/Serialization/ContinuousRangeMap.h"
30360784Sdim#include "clang/Serialization/ModuleFile.h"
31296417Sdim#include "clang/Serialization/ModuleFileExtension.h"
32249423Sdim#include "clang/Serialization/ModuleManager.h"
33327952Sdim#include "llvm/ADT/ArrayRef.h"
34327952Sdim#include "llvm/ADT/DenseMap.h"
35327952Sdim#include "llvm/ADT/DenseSet.h"
36327952Sdim#include "llvm/ADT/IntrusiveRefCntPtr.h"
37243830Sdim#include "llvm/ADT/MapVector.h"
38327952Sdim#include "llvm/ADT/Optional.h"
39327952Sdim#include "llvm/ADT/STLExtras.h"
40327952Sdim#include "llvm/ADT/SetVector.h"
41234353Sdim#include "llvm/ADT/SmallPtrSet.h"
42212795Sdim#include "llvm/ADT/SmallVector.h"
43296417Sdim#include "llvm/ADT/StringMap.h"
44212795Sdim#include "llvm/ADT/StringRef.h"
45327952Sdim#include "llvm/ADT/iterator.h"
46327952Sdim#include "llvm/ADT/iterator_range.h"
47353358Sdim#include "llvm/Bitstream/BitstreamReader.h"
48327952Sdim#include "llvm/Support/MemoryBuffer.h"
49288943Sdim#include "llvm/Support/Timer.h"
50341825Sdim#include "llvm/Support/VersionTuple.h"
51327952Sdim#include <cassert>
52327952Sdim#include <cstddef>
53327952Sdim#include <cstdint>
54327952Sdim#include <ctime>
55212795Sdim#include <deque>
56276479Sdim#include <memory>
57327952Sdim#include <set>
58212795Sdim#include <string>
59212795Sdim#include <utility>
60212795Sdim#include <vector>
61212795Sdim
62212795Sdimnamespace clang {
63212795Sdim
64212795Sdimclass ASTConsumer;
65212795Sdimclass ASTContext;
66327952Sdimclass ASTDeserializationListener;
67327952Sdimclass ASTReader;
68327952Sdimclass ASTRecordReader;
69327952Sdimclass CXXTemporary;
70327952Sdimclass Decl;
71360784Sdimclass DeclarationName;
72327952Sdimclass DeclaratorDecl;
73327952Sdimclass DeclContext;
74327952Sdimclass EnumDecl;
75327952Sdimclass Expr;
76327952Sdimclass FieldDecl;
77327952Sdimclass FileEntry;
78327952Sdimclass FileManager;
79327952Sdimclass FileSystemOptions;
80327952Sdimclass FunctionDecl;
81249423Sdimclass GlobalModuleIndex;
82327952Sdimstruct HeaderFileInfo;
83327952Sdimclass HeaderSearchOptions;
84327952Sdimclass LangOptions;
85327952Sdimclass LazyASTUnresolvedSet;
86327952Sdimclass MacroInfo;
87353358Sdimclass InMemoryModuleCache;
88212795Sdimclass NamedDecl;
89327952Sdimclass NamespaceDecl;
90327952Sdimclass ObjCCategoryDecl;
91327952Sdimclass ObjCInterfaceDecl;
92327952Sdimclass PCHContainerReader;
93212795Sdimclass Preprocessor;
94243830Sdimclass PreprocessorOptions;
95327952Sdimstruct QualifierInfo;
96212795Sdimclass Sema;
97327952Sdimclass SourceManager;
98327952Sdimclass Stmt;
99212795Sdimclass SwitchCase;
100243830Sdimclass TargetOptions;
101360784Sdimclass Token;
102327952Sdimclass TypedefNameDecl;
103327952Sdimclass ValueDecl;
104327952Sdimclass VarDecl;
105212795Sdim
106341825Sdim/// Abstract interface for callback invocations by the ASTReader.
107212795Sdim///
108212795Sdim/// While reading an AST file, the ASTReader will call the methods of the
109212795Sdim/// listener to pass on specific information. Some of the listener methods can
110212795Sdim/// return true to indicate to the ASTReader that the information (and
111212795Sdim/// consequently the AST file) is invalid.
112212795Sdimclass ASTReaderListener {
113212795Sdimpublic:
114212795Sdim  virtual ~ASTReaderListener();
115212795Sdim
116341825Sdim  /// Receives the full Clang version information.
117249423Sdim  ///
118249423Sdim  /// \returns true to indicate that the version is invalid. Subclasses should
119249423Sdim  /// generally defer to this implementation.
120249423Sdim  virtual bool ReadFullVersionInformation(StringRef FullVersion) {
121249423Sdim    return FullVersion != getClangFullRepositoryVersion();
122249423Sdim  }
123249423Sdim
124276479Sdim  virtual void ReadModuleName(StringRef ModuleName) {}
125276479Sdim  virtual void ReadModuleMapFile(StringRef ModuleMapPath) {}
126276479Sdim
127341825Sdim  /// Receives the language options.
128212795Sdim  ///
129212795Sdim  /// \returns true to indicate the options are invalid or false otherwise.
130243830Sdim  virtual bool ReadLanguageOptions(const LangOptions &LangOpts,
131280031Sdim                                   bool Complain,
132280031Sdim                                   bool AllowCompatibleDifferences) {
133212795Sdim    return false;
134212795Sdim  }
135212795Sdim
136341825Sdim  /// Receives the target options.
137212795Sdim  ///
138243830Sdim  /// \returns true to indicate the target options are invalid, or false
139243830Sdim  /// otherwise.
140288943Sdim  virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
141288943Sdim                                 bool AllowCompatibleDifferences) {
142212795Sdim    return false;
143212795Sdim  }
144212795Sdim
145341825Sdim  /// Receives the diagnostic options.
146212795Sdim  ///
147243830Sdim  /// \returns true to indicate the diagnostic options are invalid, or false
148243830Sdim  /// otherwise.
149276479Sdim  virtual bool
150276479Sdim  ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
151276479Sdim                        bool Complain) {
152243830Sdim    return false;
153243830Sdim  }
154243830Sdim
155341825Sdim  /// Receives the file system options.
156212795Sdim  ///
157243830Sdim  /// \returns true to indicate the file system options are invalid, or false
158243830Sdim  /// otherwise.
159243830Sdim  virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
160243830Sdim                                     bool Complain) {
161243830Sdim    return false;
162243830Sdim  }
163243830Sdim
164341825Sdim  /// Receives the header search options.
165212795Sdim  ///
166243830Sdim  /// \returns true to indicate the header search options are invalid, or false
167243830Sdim  /// otherwise.
168243830Sdim  virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
169288943Sdim                                       StringRef SpecificModuleCachePath,
170243830Sdim                                       bool Complain) {
171243830Sdim    return false;
172243830Sdim  }
173243830Sdim
174341825Sdim  /// Receives the preprocessor options.
175212795Sdim  ///
176243830Sdim  /// \param SuggestedPredefines Can be filled in with the set of predefines
177243830Sdim  /// that are suggested by the preprocessor options. Typically only used when
178243830Sdim  /// loading a precompiled header.
179243830Sdim  ///
180243830Sdim  /// \returns true to indicate the preprocessor options are invalid, or false
181243830Sdim  /// otherwise.
182243830Sdim  virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
183243830Sdim                                       bool Complain,
184243830Sdim                                       std::string &SuggestedPredefines) {
185212795Sdim    return false;
186212795Sdim  }
187212795Sdim
188341825Sdim  /// Receives __COUNTER__ value.
189243830Sdim  virtual void ReadCounter(const serialization::ModuleFile &M,
190243830Sdim                           unsigned Value) {}
191251662Sdim
192276479Sdim  /// This is called for each AST file loaded.
193296417Sdim  virtual void visitModuleFile(StringRef Filename,
194296417Sdim                               serialization::ModuleKind Kind) {}
195276479Sdim
196341825Sdim  /// Returns true if this \c ASTReaderListener wants to receive the
197251662Sdim  /// input files of the AST file via \c visitInputFile, false otherwise.
198251662Sdim  virtual bool needsInputFileVisitation() { return false; }
199327952Sdim
200341825Sdim  /// Returns true if this \c ASTReaderListener wants to receive the
201276479Sdim  /// system input files of the AST file via \c visitInputFile, false otherwise.
202276479Sdim  virtual bool needsSystemInputFileVisitation() { return false; }
203327952Sdim
204341825Sdim  /// if \c needsInputFileVisitation returns true, this is called for
205276479Sdim  /// each non-system input file of the AST File. If
206276479Sdim  /// \c needsSystemInputFileVisitation is true, then it is called for all
207276479Sdim  /// system input files as well.
208251662Sdim  ///
209251662Sdim  /// \returns true to continue receiving the next input file, false to stop.
210276479Sdim  virtual bool visitInputFile(StringRef Filename, bool isSystem,
211296417Sdim                              bool isOverridden, bool isExplicitModule) {
212276479Sdim    return true;
213276479Sdim  }
214280031Sdim
215341825Sdim  /// Returns true if this \c ASTReaderListener wants to receive the
216280031Sdim  /// imports of the AST file via \c visitImport, false otherwise.
217280031Sdim  virtual bool needsImportVisitation() const { return false; }
218327952Sdim
219341825Sdim  /// If needsImportVisitation returns \c true, this is called for each
220280031Sdim  /// AST file imported by this AST file.
221344779Sdim  virtual void visitImport(StringRef ModuleName, StringRef Filename) {}
222296417Sdim
223296417Sdim  /// Indicates that a particular module file extension has been read.
224296417Sdim  virtual void readModuleFileExtension(
225296417Sdim                 const ModuleFileExtensionMetadata &Metadata) {}
226212795Sdim};
227212795Sdim
228341825Sdim/// Simple wrapper class for chaining listeners.
229276479Sdimclass ChainedASTReaderListener : public ASTReaderListener {
230276479Sdim  std::unique_ptr<ASTReaderListener> First;
231276479Sdim  std::unique_ptr<ASTReaderListener> Second;
232276479Sdim
233276479Sdimpublic:
234276479Sdim  /// Takes ownership of \p First and \p Second.
235280031Sdim  ChainedASTReaderListener(std::unique_ptr<ASTReaderListener> First,
236280031Sdim                           std::unique_ptr<ASTReaderListener> Second)
237280031Sdim      : First(std::move(First)), Second(std::move(Second)) {}
238276479Sdim
239280031Sdim  std::unique_ptr<ASTReaderListener> takeFirst() { return std::move(First); }
240280031Sdim  std::unique_ptr<ASTReaderListener> takeSecond() { return std::move(Second); }
241280031Sdim
242276479Sdim  bool ReadFullVersionInformation(StringRef FullVersion) override;
243276479Sdim  void ReadModuleName(StringRef ModuleName) override;
244276479Sdim  void ReadModuleMapFile(StringRef ModuleMapPath) override;
245280031Sdim  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
246280031Sdim                           bool AllowCompatibleDifferences) override;
247288943Sdim  bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
248288943Sdim                         bool AllowCompatibleDifferences) override;
249276479Sdim  bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
250276479Sdim                             bool Complain) override;
251276479Sdim  bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
252276479Sdim                             bool Complain) override;
253276479Sdim
254276479Sdim  bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
255288943Sdim                               StringRef SpecificModuleCachePath,
256276479Sdim                               bool Complain) override;
257276479Sdim  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
258276479Sdim                               bool Complain,
259276479Sdim                               std::string &SuggestedPredefines) override;
260276479Sdim
261276479Sdim  void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
262276479Sdim  bool needsInputFileVisitation() override;
263276479Sdim  bool needsSystemInputFileVisitation() override;
264296417Sdim  void visitModuleFile(StringRef Filename,
265296417Sdim                       serialization::ModuleKind Kind) override;
266276479Sdim  bool visitInputFile(StringRef Filename, bool isSystem,
267296417Sdim                      bool isOverridden, bool isExplicitModule) override;
268296417Sdim  void readModuleFileExtension(
269296417Sdim         const ModuleFileExtensionMetadata &Metadata) override;
270276479Sdim};
271276479Sdim
272341825Sdim/// ASTReaderListener implementation to validate the information of
273212795Sdim/// the PCH file against an initialized Preprocessor.
274212795Sdimclass PCHValidator : public ASTReaderListener {
275212795Sdim  Preprocessor &PP;
276212795Sdim  ASTReader &Reader;
277212795Sdim
278212795Sdimpublic:
279212795Sdim  PCHValidator(Preprocessor &PP, ASTReader &Reader)
280341825Sdim      : PP(PP), Reader(Reader) {}
281212795Sdim
282280031Sdim  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
283280031Sdim                           bool AllowCompatibleDifferences) override;
284288943Sdim  bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
285288943Sdim                         bool AllowCompatibleDifferences) override;
286276479Sdim  bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
287276479Sdim                             bool Complain) override;
288276479Sdim  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain,
289276479Sdim                               std::string &SuggestedPredefines) override;
290288943Sdim  bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
291288943Sdim                               StringRef SpecificModuleCachePath,
292288943Sdim                               bool Complain) override;
293276479Sdim  void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
294212795Sdim
295212795Sdimprivate:
296212795Sdim  void Error(const char *Msg);
297212795Sdim};
298212795Sdim
299341825Sdim/// ASTReaderListenter implementation to set SuggestedPredefines of
300314564Sdim/// ASTReader which is required to use a pch file. This is the replacement
301314564Sdim/// of PCHValidator or SimplePCHValidator when using a pch file without
302314564Sdim/// validating it.
303314564Sdimclass SimpleASTReaderListener : public ASTReaderListener {
304314564Sdim  Preprocessor &PP;
305314564Sdim
306314564Sdimpublic:
307341825Sdim  SimpleASTReaderListener(Preprocessor &PP) : PP(PP) {}
308314564Sdim
309314564Sdim  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain,
310314564Sdim                               std::string &SuggestedPredefines) override;
311314564Sdim};
312314564Sdim
313234353Sdimnamespace serialization {
314226633Sdim
315226633Sdimclass ReadMethodPoolVisitor;
316234353Sdim
317226633Sdimnamespace reader {
318234353Sdim
319327952Sdimclass ASTIdentifierLookupTrait;
320234353Sdim
321341825Sdim/// The on-disk hash table(s) used for DeclContext name lookup.
322327952Sdimstruct DeclContextLookupTable;
323327952Sdim
324327952Sdim} // namespace reader
325327952Sdim
326327952Sdim} // namespace serialization
327327952Sdim
328341825Sdim/// Reads an AST files chain containing the contents of a translation
329212795Sdim/// unit.
330212795Sdim///
331212795Sdim/// The ASTReader class reads bitstreams (produced by the ASTWriter
332212795Sdim/// class) containing the serialized representation of a given
333212795Sdim/// abstract syntax tree and its supporting data structures. An
334212795Sdim/// instance of the ASTReader can be attached to an ASTContext object,
335212795Sdim/// which will provide access to the contents of the AST files.
336212795Sdim///
337212795Sdim/// The AST reader provides lazy de-serialization of declarations, as
338212795Sdim/// required when traversing the AST. Only those AST nodes that are
339212795Sdim/// actually required will be de-serialized.
340212795Sdimclass ASTReader
341212795Sdim  : public ExternalPreprocessorSource,
342212795Sdim    public ExternalPreprocessingRecordSource,
343218893Sdim    public ExternalHeaderFileInfoSource,
344212795Sdim    public ExternalSemaSource,
345212795Sdim    public IdentifierInfoLookup,
346234353Sdim    public ExternalSLocEntrySource
347218893Sdim{
348212795Sdimpublic:
349341825Sdim  /// Types of AST files.
350327952Sdim  friend class ASTDeclReader;
351327952Sdim  friend class ASTIdentifierIterator;
352327952Sdim  friend class ASTRecordReader;
353327952Sdim  friend class ASTUnit; // ASTUnit needs to remap source locations.
354327952Sdim  friend class ASTWriter;
355327952Sdim  friend class PCHValidator;
356327952Sdim  friend class serialization::reader::ASTIdentifierLookupTrait;
357327952Sdim  friend class serialization::ReadMethodPoolVisitor;
358327952Sdim  friend class TypeLocReader;
359239462Sdim
360327952Sdim  using RecordData = SmallVector<uint64_t, 64>;
361327952Sdim  using RecordDataImpl = SmallVectorImpl<uint64_t>;
362327952Sdim
363341825Sdim  /// The result of reading the control block of an AST file, which
364243830Sdim  /// can fail for various reasons.
365243830Sdim  enum ASTReadResult {
366341825Sdim    /// The control block was read successfully. Aside from failures,
367243830Sdim    /// the AST file is safe to read into the current context.
368243830Sdim    Success,
369327952Sdim
370341825Sdim    /// The AST file itself appears corrupted.
371243830Sdim    Failure,
372327952Sdim
373341825Sdim    /// The AST file was missing.
374249423Sdim    Missing,
375327952Sdim
376341825Sdim    /// The AST file is out-of-date relative to its input files,
377243830Sdim    /// and needs to be regenerated.
378243830Sdim    OutOfDate,
379327952Sdim
380341825Sdim    /// The AST file was written by a different version of Clang.
381243830Sdim    VersionMismatch,
382327952Sdim
383341825Sdim    /// The AST file was writtten with a different language/target
384243830Sdim    /// configuration.
385243830Sdim    ConfigurationMismatch,
386327952Sdim
387341825Sdim    /// The AST file has errors.
388243830Sdim    HadErrors
389243830Sdim  };
390314564Sdim
391327952Sdim  using ModuleFile = serialization::ModuleFile;
392327952Sdim  using ModuleKind = serialization::ModuleKind;
393327952Sdim  using ModuleManager = serialization::ModuleManager;
394327952Sdim  using ModuleIterator = ModuleManager::ModuleIterator;
395327952Sdim  using ModuleConstIterator = ModuleManager::ModuleConstIterator;
396327952Sdim  using ModuleReverseIterator = ModuleManager::ModuleReverseIterator;
397234353Sdim
398212795Sdimprivate:
399341825Sdim  /// The receiver of some callbacks invoked by ASTReader.
400276479Sdim  std::unique_ptr<ASTReaderListener> Listener;
401212795Sdim
402341825Sdim  /// The receiver of deserialization events.
403314564Sdim  ASTDeserializationListener *DeserializationListener = nullptr;
404327952Sdim
405314564Sdim  bool OwnsDeserializationListener = false;
406212795Sdim
407212795Sdim  SourceManager &SourceMgr;
408212795Sdim  FileManager &FileMgr;
409288943Sdim  const PCHContainerReader &PCHContainerRdr;
410226633Sdim  DiagnosticsEngine &Diags;
411234353Sdim
412341825Sdim  /// The semantic analysis object that will be processing the
413212795Sdim  /// AST files and the translation unit that uses it.
414314564Sdim  Sema *SemaObj = nullptr;
415212795Sdim
416341825Sdim  /// The preprocessor that will be loading the source file.
417226633Sdim  Preprocessor &PP;
418212795Sdim
419341825Sdim  /// The AST context into which we'll read the AST files.
420321369Sdim  ASTContext *ContextObj = nullptr;
421234353Sdim
422341825Sdim  /// The AST consumer.
423314564Sdim  ASTConsumer *Consumer = nullptr;
424212795Sdim
425341825Sdim  /// The module manager which manages modules and their dependencies
426226633Sdim  ModuleManager ModuleMgr;
427221345Sdim
428341825Sdim  /// A dummy identifier resolver used to merge TU-scope declarations in
429309124Sdim  /// C, for the cases where we don't have a Sema object to provide a real
430309124Sdim  /// identifier resolver.
431309124Sdim  IdentifierResolver DummyIdResolver;
432309124Sdim
433296417Sdim  /// A mapping from extension block names to module file extensions.
434314564Sdim  llvm::StringMap<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions;
435296417Sdim
436341825Sdim  /// A timer used to track the time spent deserializing.
437288943Sdim  std::unique_ptr<llvm::Timer> ReadTimer;
438288943Sdim
439341825Sdim  /// The location where the module file will be considered as
440261991Sdim  /// imported from. For non-module AST types it should be invalid.
441261991Sdim  SourceLocation CurrentImportLoc;
442261991Sdim
443341825Sdim  /// The global module index, if loaded.
444276479Sdim  std::unique_ptr<GlobalModuleIndex> GlobalIndex;
445249423Sdim
446341825Sdim  /// A map of global bit offsets to the module that stores entities
447226633Sdim  /// at those bit offsets.
448234353Sdim  ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap;
449212795Sdim
450341825Sdim  /// A map of negated SLocEntryIDs to the modules containing them.
451234353Sdim  ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap;
452212795Sdim
453327952Sdim  using GlobalSLocOffsetMapType =
454327952Sdim      ContinuousRangeMap<unsigned, ModuleFile *, 64>;
455234353Sdim
456341825Sdim  /// A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset)
457226633Sdim  /// SourceLocation offsets to the modules containing them.
458226633Sdim  GlobalSLocOffsetMapType GlobalSLocOffsetMap;
459234353Sdim
460341825Sdim  /// Types that have already been loaded from the chain.
461212795Sdim  ///
462212795Sdim  /// When the pointer at index I is non-NULL, the type with
463212795Sdim  /// ID = (I + 1) << FastQual::Width has already been loaded
464212795Sdim  std::vector<QualType> TypesLoaded;
465212795Sdim
466327952Sdim  using GlobalTypeMapType =
467327952Sdim      ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4>;
468212795Sdim
469341825Sdim  /// Mapping from global type IDs to the module in which the
470226633Sdim  /// type resides along with the offset that should be added to the
471226633Sdim  /// global type ID to produce a local ID.
472226633Sdim  GlobalTypeMapType GlobalTypeMap;
473226633Sdim
474341825Sdim  /// Declarations that have already been loaded from the chain.
475212795Sdim  ///
476212795Sdim  /// When the pointer at index I is non-NULL, the declaration with ID
477212795Sdim  /// = I + 1 has already been loaded.
478212795Sdim  std::vector<Decl *> DeclsLoaded;
479212795Sdim
480327952Sdim  using GlobalDeclMapType =
481327952Sdim      ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4>;
482234353Sdim
483341825Sdim  /// Mapping from global declaration IDs to the module in which the
484226633Sdim  /// declaration resides.
485226633Sdim  GlobalDeclMapType GlobalDeclMap;
486234353Sdim
487327952Sdim  using FileOffset = std::pair<ModuleFile *, uint64_t>;
488327952Sdim  using FileOffsetsTy = SmallVector<FileOffset, 2>;
489327952Sdim  using DeclUpdateOffsetsMap =
490327952Sdim      llvm::DenseMap<serialization::DeclID, FileOffsetsTy>;
491234353Sdim
492341825Sdim  /// Declarations that have modifications residing in a later file
493218893Sdim  /// in the chain.
494218893Sdim  DeclUpdateOffsetsMap DeclUpdateOffsets;
495218893Sdim
496321369Sdim  struct PendingUpdateRecord {
497321369Sdim    Decl *D;
498321369Sdim    serialization::GlobalDeclID ID;
499327952Sdim
500321369Sdim    // Whether the declaration was just deserialized.
501321369Sdim    bool JustLoaded;
502327952Sdim
503321369Sdim    PendingUpdateRecord(serialization::GlobalDeclID ID, Decl *D,
504321369Sdim                        bool JustLoaded)
505321369Sdim        : D(D), ID(ID), JustLoaded(JustLoaded) {}
506321369Sdim  };
507327952Sdim
508341825Sdim  /// Declaration updates for already-loaded declarations that we need
509276479Sdim  /// to apply once we finish processing an import.
510321369Sdim  llvm::SmallVector<PendingUpdateRecord, 16> PendingUpdateRecords;
511276479Sdim
512288943Sdim  enum class PendingFakeDefinitionKind { NotFake, Fake, FakeLoaded };
513288943Sdim
514341825Sdim  /// The DefinitionData pointers that we faked up for class definitions
515288943Sdim  /// that we needed but hadn't loaded yet.
516288943Sdim  llvm::DenseMap<void *, PendingFakeDefinitionKind> PendingFakeDefinitionData;
517288943Sdim
518341825Sdim  /// Exception specification updates that have been loaded but not yet
519288943Sdim  /// propagated across the relevant redeclaration chain. The map key is the
520288943Sdim  /// canonical declaration (used only for deduplication) and the value is a
521288943Sdim  /// declaration that has an exception specification.
522288943Sdim  llvm::SmallMapVector<Decl *, FunctionDecl *, 4> PendingExceptionSpecUpdates;
523288943Sdim
524344779Sdim  /// Deduced return type updates that have been loaded but not yet propagated
525344779Sdim  /// across the relevant redeclaration chain. The map key is the canonical
526344779Sdim  /// declaration and the value is the deduced return type.
527344779Sdim  llvm::SmallMapVector<FunctionDecl *, QualType, 4> PendingDeducedTypeUpdates;
528344779Sdim
529341825Sdim  /// Declarations that have been imported and have typedef names for
530280031Sdim  /// linkage purposes.
531327952Sdim  llvm::DenseMap<std::pair<DeclContext *, IdentifierInfo *>, NamedDecl *>
532280031Sdim      ImportedTypedefNamesForLinkage;
533280031Sdim
534341825Sdim  /// Mergeable declaration contexts that have anonymous declarations
535280031Sdim  /// within them, and those anonymous declarations.
536341825Sdim  llvm::DenseMap<Decl*, llvm::SmallVector<NamedDecl*, 2>>
537280031Sdim    AnonymousDeclarationsForMerging;
538280031Sdim
539360784Sdim  /// Key used to identify LifetimeExtendedTemporaryDecl for merging,
540360784Sdim  /// containing the lifetime-extending declaration and the mangling number.
541360784Sdim  using LETemporaryKey = std::pair<Decl *, unsigned>;
542360784Sdim
543360784Sdim  /// Map of already deserialiazed temporaries.
544360784Sdim  llvm::DenseMap<LETemporaryKey, LifetimeExtendedTemporaryDecl *>
545360784Sdim      LETemporaryForMerging;
546360784Sdim
547234353Sdim  struct FileDeclsInfo {
548327952Sdim    ModuleFile *Mod = nullptr;
549234353Sdim    ArrayRef<serialization::LocalDeclID> Decls;
550234353Sdim
551327952Sdim    FileDeclsInfo() = default;
552234353Sdim    FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls)
553341825Sdim        : Mod(Mod), Decls(Decls) {}
554234353Sdim  };
555234353Sdim
556341825Sdim  /// Map from a FileID to the file-level declarations that it contains.
557234353Sdim  llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs;
558234353Sdim
559341825Sdim  /// An array of lexical contents of a declaration context, as a sequence of
560296417Sdim  /// Decl::Kind, DeclID pairs.
561327952Sdim  using LexicalContents = ArrayRef<llvm::support::unaligned_uint32_t>;
562296417Sdim
563341825Sdim  /// Map from a DeclContext to its lexical contents.
564296417Sdim  llvm::DenseMap<const DeclContext*, std::pair<ModuleFile*, LexicalContents>>
565296417Sdim      LexicalDecls;
566296417Sdim
567341825Sdim  /// Map from the TU to its lexical contents from each module file.
568296417Sdim  std::vector<std::pair<ModuleFile*, LexicalContents>> TULexicalDecls;
569296417Sdim
570341825Sdim  /// Map from a DeclContext to its lookup tables.
571296417Sdim  llvm::DenseMap<const DeclContext *,
572296417Sdim                 serialization::reader::DeclContextLookupTable> Lookups;
573296417Sdim
574212795Sdim  // Updates for visible decls can occur for other contexts than just the
575296417Sdim  // TU, and when we read those update records, the actual context may not
576296417Sdim  // be available yet, so have this pending map using the ID as a key. It
577296417Sdim  // will be realized when the context is actually loaded.
578296417Sdim  struct PendingVisibleUpdate {
579296417Sdim    ModuleFile *Mod;
580296417Sdim    const unsigned char *Data;
581296417Sdim  };
582327952Sdim  using DeclContextVisibleUpdates = SmallVector<PendingVisibleUpdate, 1>;
583212795Sdim
584341825Sdim  /// Updates to the visible declarations of declaration contexts that
585212795Sdim  /// haven't been loaded yet.
586296417Sdim  llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates>
587296417Sdim      PendingVisibleUpdates;
588296417Sdim
589341825Sdim  /// The set of C++ or Objective-C classes that have forward
590234353Sdim  /// declarations that have not yet been linked to their definitions.
591234353Sdim  llvm::SmallPtrSet<Decl *, 4> PendingDefinitions;
592243830Sdim
593327952Sdim  using PendingBodiesMap =
594327952Sdim      llvm::MapVector<Decl *, uint64_t,
595327952Sdim                      llvm::SmallDenseMap<Decl *, unsigned, 4>,
596327952Sdim                      SmallVector<std::pair<Decl *, uint64_t>, 4>>;
597243830Sdim
598341825Sdim  /// Functions or methods that have bodies that will be attached.
599243830Sdim  PendingBodiesMap PendingBodies;
600243830Sdim
601341825Sdim  /// Definitions for which we have added merged definitions but not yet
602288943Sdim  /// performed deduplication.
603327952Sdim  llvm::SetVector<NamedDecl *> PendingMergedDefinitionsToDeduplicate;
604288943Sdim
605341825Sdim  /// Read the record that describes the lexical contents of a DC.
606296417Sdim  bool ReadLexicalDeclContextStorage(ModuleFile &M,
607296417Sdim                                     llvm::BitstreamCursor &Cursor,
608296417Sdim                                     uint64_t Offset, DeclContext *DC);
609327952Sdim
610341825Sdim  /// Read the record that describes the visible contents of a DC.
611296417Sdim  bool ReadVisibleDeclContextStorage(ModuleFile &M,
612296417Sdim                                     llvm::BitstreamCursor &Cursor,
613296417Sdim                                     uint64_t Offset, serialization::DeclID ID);
614212795Sdim
615341825Sdim  /// A vector containing identifiers that have already been
616212795Sdim  /// loaded.
617212795Sdim  ///
618212795Sdim  /// If the pointer at index I is non-NULL, then it refers to the
619212795Sdim  /// IdentifierInfo for the identifier with ID=I+1 that has already
620212795Sdim  /// been loaded.
621212795Sdim  std::vector<IdentifierInfo *> IdentifiersLoaded;
622212795Sdim
623327952Sdim  using GlobalIdentifierMapType =
624327952Sdim      ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4>;
625234353Sdim
626341825Sdim  /// Mapping from global identifier IDs to the module in which the
627226633Sdim  /// identifier resides along with the offset that should be added to the
628226633Sdim  /// global identifier ID to produce a local ID.
629226633Sdim  GlobalIdentifierMapType GlobalIdentifierMap;
630226633Sdim
631341825Sdim  /// A vector containing macros that have already been
632243830Sdim  /// loaded.
633243830Sdim  ///
634243830Sdim  /// If the pointer at index I is non-NULL, then it refers to the
635243830Sdim  /// MacroInfo for the identifier with ID=I+1 that has already
636243830Sdim  /// been loaded.
637243830Sdim  std::vector<MacroInfo *> MacrosLoaded;
638243830Sdim
639327952Sdim  using LoadedMacroInfo =
640327952Sdim      std::pair<IdentifierInfo *, serialization::SubmoduleID>;
641288943Sdim
642341825Sdim  /// A set of #undef directives that we have loaded; used to
643288943Sdim  /// deduplicate the same #undef information coming from multiple module
644288943Sdim  /// files.
645288943Sdim  llvm::DenseSet<LoadedMacroInfo> LoadedUndefs;
646288943Sdim
647327952Sdim  using GlobalMacroMapType =
648327952Sdim      ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4>;
649243830Sdim
650341825Sdim  /// Mapping from global macro IDs to the module in which the
651243830Sdim  /// macro resides along with the offset that should be added to the
652243830Sdim  /// global macro ID to produce a local ID.
653243830Sdim  GlobalMacroMapType GlobalMacroMap;
654243830Sdim
655341825Sdim  /// A vector containing submodules that have already been loaded.
656234353Sdim  ///
657234353Sdim  /// This vector is indexed by the Submodule ID (-1). NULL submodule entries
658234353Sdim  /// indicate that the particular submodule ID has not yet been loaded.
659234353Sdim  SmallVector<Module *, 2> SubmodulesLoaded;
660341825Sdim
661327952Sdim  using GlobalSubmoduleMapType =
662327952Sdim      ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4>;
663341825Sdim
664341825Sdim  /// Mapping from global submodule IDs to the module file in which the
665234353Sdim  /// submodule resides along with the offset that should be added to the
666234353Sdim  /// global submodule ID to produce a local ID.
667234353Sdim  GlobalSubmoduleMapType GlobalSubmoduleMap;
668234353Sdim
669341825Sdim  /// A set of hidden declarations.
670327952Sdim  using HiddenNames = SmallVector<Decl *, 2>;
671327952Sdim  using HiddenNamesMapType = llvm::DenseMap<Module *, HiddenNames>;
672234353Sdim
673341825Sdim  /// A mapping from each of the hidden submodules to the deserialized
674234353Sdim  /// declarations in that submodule that could be made visible.
675234353Sdim  HiddenNamesMapType HiddenNamesMap;
676341825Sdim
677341825Sdim  /// A module import, export, or conflict that hasn't yet been resolved.
678249423Sdim  struct UnresolvedModuleRef {
679341825Sdim    /// The file in which this module resides.
680234353Sdim    ModuleFile *File;
681341825Sdim
682341825Sdim    /// The module that is importing or exporting.
683234353Sdim    Module *Mod;
684249423Sdim
685341825Sdim    /// The kind of module reference.
686249423Sdim    enum { Import, Export, Conflict } Kind;
687249423Sdim
688341825Sdim    /// The local ID of the module that is being exported.
689234353Sdim    unsigned ID;
690249423Sdim
691341825Sdim    /// Whether this is a wildcard export.
692234353Sdim    unsigned IsWildcard : 1;
693249423Sdim
694341825Sdim    /// String data.
695249423Sdim    StringRef String;
696234353Sdim  };
697341825Sdim
698341825Sdim  /// The set of module imports and exports that still need to be
699234353Sdim  /// resolved.
700249423Sdim  SmallVector<UnresolvedModuleRef, 2> UnresolvedModuleRefs;
701341825Sdim
702341825Sdim  /// A vector containing selectors that have already been loaded.
703212795Sdim  ///
704212795Sdim  /// This vector is indexed by the Selector ID (-1). NULL selector
705212795Sdim  /// entries indicate that the particular selector ID has not yet
706212795Sdim  /// been loaded.
707226633Sdim  SmallVector<Selector, 16> SelectorsLoaded;
708212795Sdim
709327952Sdim  using GlobalSelectorMapType =
710327952Sdim      ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4>;
711234353Sdim
712341825Sdim  /// Mapping from global selector IDs to the module in which the
713226633Sdim  /// global selector ID to produce a local ID.
714226633Sdim  GlobalSelectorMapType GlobalSelectorMap;
715212795Sdim
716341825Sdim  /// The generation number of the last time we loaded data from the
717234353Sdim  /// global method pool for this selector.
718234353Sdim  llvm::DenseMap<Selector, unsigned> SelectorGeneration;
719234353Sdim
720309124Sdim  /// Whether a selector is out of date. We mark a selector as out of date
721309124Sdim  /// if we load another module after the method pool entry was pulled in.
722309124Sdim  llvm::DenseMap<Selector, bool> SelectorOutOfDate;
723309124Sdim
724249423Sdim  struct PendingMacroInfo {
725249423Sdim    ModuleFile *M;
726288943Sdim    uint64_t MacroDirectivesOffset;
727249423Sdim
728288943Sdim    PendingMacroInfo(ModuleFile *M, uint64_t MacroDirectivesOffset)
729288943Sdim        : M(M), MacroDirectivesOffset(MacroDirectivesOffset) {}
730249423Sdim  };
731249423Sdim
732327952Sdim  using PendingMacroIDsMap =
733327952Sdim      llvm::MapVector<IdentifierInfo *, SmallVector<PendingMacroInfo, 2>>;
734226633Sdim
735341825Sdim  /// Mapping from identifiers that have a macro history to the global
736243830Sdim  /// IDs have not yet been deserialized to the global IDs of those macros.
737243830Sdim  PendingMacroIDsMap PendingMacroIDs;
738243830Sdim
739327952Sdim  using GlobalPreprocessedEntityMapType =
740327952Sdim      ContinuousRangeMap<unsigned, ModuleFile *, 4>;
741234353Sdim
742341825Sdim  /// Mapping from global preprocessing entity IDs to the module in
743226633Sdim  /// which the preprocessed entity resides along with the offset that should be
744321369Sdim  /// added to the global preprocessing entity ID to produce a local ID.
745226633Sdim  GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
746234353Sdim
747341825Sdim  using GlobalSkippedRangeMapType =
748341825Sdim      ContinuousRangeMap<unsigned, ModuleFile *, 4>;
749341825Sdim
750341825Sdim  /// Mapping from global skipped range base IDs to the module in which
751341825Sdim  /// the skipped ranges reside.
752341825Sdim  GlobalSkippedRangeMapType GlobalSkippedRangeMap;
753341825Sdim
754212795Sdim  /// \name CodeGen-relevant special data
755341825Sdim  /// Fields containing data that is relevant to CodeGen.
756212795Sdim  //@{
757212795Sdim
758341825Sdim  /// The IDs of all declarations that fulfill the criteria of
759212795Sdim  /// "interesting" decls.
760212795Sdim  ///
761276479Sdim  /// This contains the data loaded from all EAGERLY_DESERIALIZED_DECLS blocks
762276479Sdim  /// in the chain. The referenced declarations are deserialized and passed to
763276479Sdim  /// the consumer eagerly.
764276479Sdim  SmallVector<uint64_t, 16> EagerlyDeserializedDecls;
765212795Sdim
766341825Sdim  /// The IDs of all tentative definitions stored in the chain.
767212795Sdim  ///
768212795Sdim  /// Sema keeps track of all tentative definitions in a TU because it has to
769212795Sdim  /// complete them and pass them on to CodeGen. Thus, tentative definitions in
770212795Sdim  /// the PCH chain must be eagerly deserialized.
771226633Sdim  SmallVector<uint64_t, 16> TentativeDefinitions;
772212795Sdim
773341825Sdim  /// The IDs of all CXXRecordDecls stored in the chain whose VTables are
774212795Sdim  /// used.
775212795Sdim  ///
776212795Sdim  /// CodeGen has to emit VTables for these records, so they have to be eagerly
777212795Sdim  /// deserialized.
778226633Sdim  SmallVector<uint64_t, 64> VTableUses;
779212795Sdim
780341825Sdim  /// A snapshot of the pending instantiations in the chain.
781226633Sdim  ///
782226633Sdim  /// This record tracks the instantiations that Sema has to perform at the
783226633Sdim  /// end of the TU. It consists of a pair of values for every pending
784226633Sdim  /// instantiation where the first value is the ID of the decl and the second
785226633Sdim  /// is the instantiation location.
786226633Sdim  SmallVector<uint64_t, 64> PendingInstantiations;
787226633Sdim
788212795Sdim  //@}
789212795Sdim
790226633Sdim  /// \name DiagnosticsEngine-relevant special data
791341825Sdim  /// Fields containing data that is used for generating diagnostics
792212795Sdim  //@{
793212795Sdim
794341825Sdim  /// A snapshot of Sema's unused file-scoped variable tracking, for
795212795Sdim  /// generating warnings.
796226633Sdim  SmallVector<uint64_t, 16> UnusedFileScopedDecls;
797212795Sdim
798341825Sdim  /// A list of all the delegating constructors we've seen, to diagnose
799223017Sdim  /// cycles.
800226633Sdim  SmallVector<uint64_t, 4> DelegatingCtorDecls;
801234353Sdim
802341825Sdim  /// Method selectors used in a @selector expression. Used for
803226633Sdim  /// implementation of -Wselector.
804226633Sdim  SmallVector<uint64_t, 64> ReferencedSelectorsData;
805223017Sdim
806341825Sdim  /// A snapshot of Sema's weak undeclared identifier tracking, for
807212795Sdim  /// generating warnings.
808226633Sdim  SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers;
809212795Sdim
810341825Sdim  /// The IDs of type aliases for ext_vectors that exist in the chain.
811212795Sdim  ///
812212795Sdim  /// Used by Sema for finding sugared names for ext_vectors in diagnostics.
813226633Sdim  SmallVector<uint64_t, 4> ExtVectorDecls;
814212795Sdim
815212795Sdim  //@}
816212795Sdim
817212795Sdim  /// \name Sema-relevant special data
818341825Sdim  /// Fields containing data that is used for semantic analysis
819212795Sdim  //@{
820212795Sdim
821341825Sdim  /// The IDs of all potentially unused typedef names in the chain.
822280031Sdim  ///
823280031Sdim  /// Sema tracks these to emit warnings.
824280031Sdim  SmallVector<uint64_t, 16> UnusedLocalTypedefNameCandidates;
825280031Sdim
826341825Sdim  /// Our current depth in #pragma cuda force_host_device begin/end
827314564Sdim  /// macros.
828314564Sdim  unsigned ForceCUDAHostDeviceDepth = 0;
829314564Sdim
830341825Sdim  /// The IDs of the declarations Sema stores directly.
831212795Sdim  ///
832212795Sdim  /// Sema tracks a few important decls, such as namespace std, directly.
833226633Sdim  SmallVector<uint64_t, 4> SemaDeclRefs;
834212795Sdim
835341825Sdim  /// The IDs of the types ASTContext stores directly.
836212795Sdim  ///
837212795Sdim  /// The AST context tracks a few important types, such as va_list, directly.
838226633Sdim  SmallVector<uint64_t, 16> SpecialTypes;
839212795Sdim
840341825Sdim  /// The IDs of CUDA-specific declarations ASTContext stores directly.
841218893Sdim  ///
842218893Sdim  /// The AST context tracks a few important decls, currently cudaConfigureCall,
843218893Sdim  /// directly.
844226633Sdim  SmallVector<uint64_t, 2> CUDASpecialDeclRefs;
845218893Sdim
846341825Sdim  /// The floating point pragma option settings.
847226633Sdim  SmallVector<uint64_t, 1> FPPragmaOptions;
848218893Sdim
849341825Sdim  /// The pragma clang optimize location (if the pragma state is "off").
850276479Sdim  SourceLocation OptimizeOffPragmaLocation;
851276479Sdim
852341825Sdim  /// The PragmaMSStructKind pragma ms_struct state if set, or -1.
853314564Sdim  int PragmaMSStructState = -1;
854309124Sdim
855341825Sdim  /// The PragmaMSPointersToMembersKind pragma pointers_to_members state.
856314564Sdim  int PragmaMSPointersToMembersState = -1;
857309124Sdim  SourceLocation PointersToMembersPragmaLocation;
858309124Sdim
859341825Sdim  /// The pragma pack state.
860321369Sdim  Optional<unsigned> PragmaPackCurrentValue;
861321369Sdim  SourceLocation PragmaPackCurrentLocation;
862321369Sdim  struct PragmaPackStackEntry {
863321369Sdim    unsigned Value;
864321369Sdim    SourceLocation Location;
865327952Sdim    SourceLocation PushLocation;
866321369Sdim    StringRef SlotLabel;
867321369Sdim  };
868321369Sdim  llvm::SmallVector<PragmaPackStackEntry, 2> PragmaPackStack;
869321369Sdim  llvm::SmallVector<std::string, 2> PragmaPackStrings;
870321369Sdim
871341825Sdim  /// The OpenCL extension settings.
872314564Sdim  OpenCLOptions OpenCLExtensions;
873218893Sdim
874341825Sdim  /// Extensions required by an OpenCL type.
875314564Sdim  llvm::DenseMap<const Type *, std::set<std::string>> OpenCLTypeExtMap;
876314564Sdim
877341825Sdim  /// Extensions required by an OpenCL declaration.
878314564Sdim  llvm::DenseMap<const Decl *, std::set<std::string>> OpenCLDeclExtMap;
879314564Sdim
880341825Sdim  /// A list of the namespaces we've seen.
881226633Sdim  SmallVector<uint64_t, 4> KnownNamespaces;
882224145Sdim
883341825Sdim  /// A list of undefined decls with internal linkage followed by the
884249423Sdim  /// SourceLocation of a matching ODR-use.
885249423Sdim  SmallVector<uint64_t, 8> UndefinedButUsed;
886249423Sdim
887341825Sdim  /// Delete expressions to analyze at the end of translation unit.
888288943Sdim  SmallVector<uint64_t, 8> DelayedDeleteExprs;
889288943Sdim
890341825Sdim  // A list of late parsed template function data.
891261991Sdim  SmallVector<uint64_t, 1> LateParsedTemplates;
892261991Sdim
893314564Sdimpublic:
894276479Sdim  struct ImportedSubmodule {
895276479Sdim    serialization::SubmoduleID ID;
896276479Sdim    SourceLocation ImportLoc;
897276479Sdim
898276479Sdim    ImportedSubmodule(serialization::SubmoduleID ID, SourceLocation ImportLoc)
899341825Sdim        : ID(ID), ImportLoc(ImportLoc) {}
900276479Sdim  };
901276479Sdim
902314564Sdimprivate:
903341825Sdim  /// A list of modules that were imported by precompiled headers or
904234353Sdim  /// any other non-module AST file.
905276479Sdim  SmallVector<ImportedSubmodule, 2> ImportedModules;
906212795Sdim  //@}
907212795Sdim
908341825Sdim  /// The system include root to be used when loading the
909212795Sdim  /// precompiled header.
910226633Sdim  std::string isysroot;
911212795Sdim
912341825Sdim  /// Whether to disable the normal validation performed on precompiled
913212795Sdim  /// headers when they are loaded.
914212795Sdim  bool DisableValidation;
915234353Sdim
916341825Sdim  /// Whether to accept an AST file with compiler errors.
917234353Sdim  bool AllowASTWithCompilerErrors;
918234353Sdim
919341825Sdim  /// Whether to accept an AST file that has a different configuration
920276479Sdim  /// from the current compiler instance.
921276479Sdim  bool AllowConfigurationMismatch;
922276479Sdim
923341825Sdim  /// Whether validate system input files.
924276479Sdim  bool ValidateSystemInputs;
925276479Sdim
926360784Sdim  /// Whether validate headers and module maps using hash based on contents.
927360784Sdim  bool ValidateASTInputFilesContent;
928360784Sdim
929341825Sdim  /// Whether we are allowed to use the global module index.
930249423Sdim  bool UseGlobalIndex;
931249423Sdim
932341825Sdim  /// Whether we have tried loading the global module index yet.
933314564Sdim  bool TriedLoadingGlobalIndex = false;
934249423Sdim
935341825Sdim  ///Whether we are currently processing update records.
936314564Sdim  bool ProcessingUpdateRecords = false;
937309124Sdim
938327952Sdim  using SwitchCaseMapTy = llvm::DenseMap<unsigned, SwitchCase *>;
939327952Sdim
940341825Sdim  /// Mapping from switch-case IDs in the chain to switch-case statements
941212795Sdim  ///
942212795Sdim  /// Statements usually don't have IDs, but switch cases need them, so that the
943212795Sdim  /// switch statement can refer to them.
944239462Sdim  SwitchCaseMapTy SwitchCaseStmts;
945212795Sdim
946239462Sdim  SwitchCaseMapTy *CurrSwitchCaseStmts;
947239462Sdim
948341825Sdim  /// The number of source location entries de-serialized from
949212795Sdim  /// the PCH file.
950314564Sdim  unsigned NumSLocEntriesRead = 0;
951212795Sdim
952341825Sdim  /// The number of source location entries in the chain.
953314564Sdim  unsigned TotalNumSLocEntries = 0;
954212795Sdim
955341825Sdim  /// The number of statements (and expressions) de-serialized
956212795Sdim  /// from the chain.
957314564Sdim  unsigned NumStatementsRead = 0;
958212795Sdim
959341825Sdim  /// The total number of statements (and expressions) stored
960212795Sdim  /// in the chain.
961314564Sdim  unsigned TotalNumStatements = 0;
962212795Sdim
963341825Sdim  /// The number of macros de-serialized from the chain.
964314564Sdim  unsigned NumMacrosRead = 0;
965212795Sdim
966341825Sdim  /// The total number of macros stored in the chain.
967314564Sdim  unsigned TotalNumMacros = 0;
968212795Sdim
969341825Sdim  /// The number of lookups into identifier tables.
970314564Sdim  unsigned NumIdentifierLookups = 0;
971249423Sdim
972341825Sdim  /// The number of lookups into identifier tables that succeed.
973314564Sdim  unsigned NumIdentifierLookupHits = 0;
974249423Sdim
975341825Sdim  /// The number of selectors that have been read.
976314564Sdim  unsigned NumSelectorsRead = 0;
977212795Sdim
978341825Sdim  /// The number of method pool entries that have been read.
979314564Sdim  unsigned NumMethodPoolEntriesRead = 0;
980212795Sdim
981341825Sdim  /// The number of times we have looked up a selector in the method
982249423Sdim  /// pool.
983314564Sdim  unsigned NumMethodPoolLookups = 0;
984212795Sdim
985341825Sdim  /// The number of times we have looked up a selector in the method
986249423Sdim  /// pool and found something.
987314564Sdim  unsigned NumMethodPoolHits = 0;
988249423Sdim
989341825Sdim  /// The number of times we have looked up a selector in the method
990249423Sdim  /// pool within a specific module.
991314564Sdim  unsigned NumMethodPoolTableLookups = 0;
992249423Sdim
993341825Sdim  /// The number of times we have looked up a selector in the method
994249423Sdim  /// pool within a specific module and found something.
995314564Sdim  unsigned NumMethodPoolTableHits = 0;
996249423Sdim
997341825Sdim  /// The total number of method pool entries in the selector table.
998314564Sdim  unsigned TotalNumMethodPoolEntries = 0;
999212795Sdim
1000212795Sdim  /// Number of lexical decl contexts read/total.
1001314564Sdim  unsigned NumLexicalDeclContextsRead = 0, TotalLexicalDeclContexts = 0;
1002212795Sdim
1003212795Sdim  /// Number of visible decl contexts read/total.
1004314564Sdim  unsigned NumVisibleDeclContextsRead = 0, TotalVisibleDeclContexts = 0;
1005234353Sdim
1006226633Sdim  /// Total size of modules, in bits, currently loaded
1007314564Sdim  uint64_t TotalModulesSizeInBits = 0;
1008226633Sdim
1009341825Sdim  /// Number of Decl/types that are currently deserializing.
1010314564Sdim  unsigned NumCurrentElementsDeserializing = 0;
1011212795Sdim
1012341825Sdim  /// Set true while we are in the process of passing deserialized
1013234353Sdim  /// "interesting" decls to consumer inside FinishedDeserializing().
1014234353Sdim  /// This is used as a guard to avoid recursively repeating the process of
1015234353Sdim  /// passing decls to consumer.
1016314564Sdim  bool PassingDeclsToConsumer = false;
1017234353Sdim
1018341825Sdim  /// The set of identifiers that were read while the AST reader was
1019212795Sdim  /// (recursively) loading declarations.
1020212795Sdim  ///
1021212795Sdim  /// The declarations on the identifier chain for these identifiers will be
1022212795Sdim  /// loaded once the recursive loading has completed.
1023327952Sdim  llvm::MapVector<IdentifierInfo *, SmallVector<uint32_t, 4>>
1024249423Sdim    PendingIdentifierInfos;
1025212795Sdim
1026341825Sdim  /// The set of lookup results that we have faked in order to support
1027288943Sdim  /// merging of partially deserialized decls but that we have not yet removed.
1028288943Sdim  llvm::SmallMapVector<IdentifierInfo *, SmallVector<NamedDecl*, 2>, 16>
1029288943Sdim    PendingFakeLookupResults;
1030288943Sdim
1031341825Sdim  /// The generation number of each identifier, which keeps track of
1032234353Sdim  /// the last time we loaded information about this identifier.
1033234353Sdim  llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration;
1034321369Sdim
1035321369Sdim  class InterestingDecl {
1036321369Sdim    Decl *D;
1037321369Sdim    bool DeclHasPendingBody;
1038321369Sdim
1039321369Sdim  public:
1040321369Sdim    InterestingDecl(Decl *D, bool HasBody)
1041321369Sdim        : D(D), DeclHasPendingBody(HasBody) {}
1042327952Sdim
1043321369Sdim    Decl *getDecl() { return D; }
1044327952Sdim
1045321369Sdim    /// Whether the declaration has a pending body.
1046321369Sdim    bool hasPendingBody() { return DeclHasPendingBody; }
1047321369Sdim  };
1048321369Sdim
1049341825Sdim  /// Contains declarations and definitions that could be
1050212795Sdim  /// "interesting" to the ASTConsumer, when we get that AST consumer.
1051212795Sdim  ///
1052212795Sdim  /// "Interesting" declarations are those that have data that may
1053212795Sdim  /// need to be emitted, such as inline function definitions or
1054212795Sdim  /// Objective-C protocols.
1055321369Sdim  std::deque<InterestingDecl> PotentiallyInterestingDecls;
1056212795Sdim
1057344779Sdim  /// The list of deduced function types that we have not yet read, because
1058344779Sdim  /// they might contain a deduced return type that refers to a local type
1059344779Sdim  /// declared within the function.
1060344779Sdim  SmallVector<std::pair<FunctionDecl *, serialization::TypeID>, 16>
1061344779Sdim      PendingFunctionTypes;
1062344779Sdim
1063341825Sdim  /// The list of redeclaration chains that still need to be
1064296417Sdim  /// reconstructed, and the local offset to the corresponding list
1065296417Sdim  /// of redeclarations.
1066296417Sdim  SmallVector<std::pair<Decl *, uint64_t>, 16> PendingDeclChains;
1067218893Sdim
1068341825Sdim  /// The list of canonical declarations whose redeclaration chains
1069276479Sdim  /// need to be marked as incomplete once we're done deserializing things.
1070276479Sdim  SmallVector<Decl *, 16> PendingIncompleteDeclChains;
1071276479Sdim
1072341825Sdim  /// The Decl IDs for the Sema/Lexical DeclContext of a Decl that has
1073249423Sdim  /// been loaded but its DeclContext was not set yet.
1074249423Sdim  struct PendingDeclContextInfo {
1075249423Sdim    Decl *D;
1076249423Sdim    serialization::GlobalDeclID SemaDC;
1077249423Sdim    serialization::GlobalDeclID LexicalDC;
1078249423Sdim  };
1079249423Sdim
1080341825Sdim  /// The set of Decls that have been loaded but their DeclContexts are
1081249423Sdim  /// not set yet.
1082249423Sdim  ///
1083249423Sdim  /// The DeclContexts for these Decls will be set once recursive loading has
1084249423Sdim  /// been completed.
1085249423Sdim  std::deque<PendingDeclContextInfo> PendingDeclContextInfos;
1086249423Sdim
1087341825Sdim  /// The set of NamedDecls that have been loaded, but are members of a
1088261991Sdim  /// context that has been merged into another context where the corresponding
1089261991Sdim  /// declaration is either missing or has not yet been loaded.
1090261991Sdim  ///
1091261991Sdim  /// We will check whether the corresponding declaration is in fact missing
1092261991Sdim  /// once recursing loading has been completed.
1093261991Sdim  llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks;
1094261991Sdim
1095327952Sdim  using DataPointers =
1096327952Sdim      std::pair<CXXRecordDecl *, struct CXXRecordDecl::DefinitionData *>;
1097327952Sdim
1098341825Sdim  /// Record definitions in which we found an ODR violation.
1099327952Sdim  llvm::SmallDenseMap<CXXRecordDecl *, llvm::SmallVector<DataPointers, 2>, 2>
1100276479Sdim      PendingOdrMergeFailures;
1101276479Sdim
1102341825Sdim  /// Function definitions in which we found an ODR violation.
1103327952Sdim  llvm::SmallDenseMap<FunctionDecl *, llvm::SmallVector<FunctionDecl *, 2>, 2>
1104327952Sdim      PendingFunctionOdrMergeFailures;
1105327952Sdim
1106341825Sdim  /// Enum definitions in which we found an ODR violation.
1107341825Sdim  llvm::SmallDenseMap<EnumDecl *, llvm::SmallVector<EnumDecl *, 2>, 2>
1108341825Sdim      PendingEnumOdrMergeFailures;
1109341825Sdim
1110341825Sdim  /// DeclContexts in which we have diagnosed an ODR violation.
1111276479Sdim  llvm::SmallPtrSet<DeclContext*, 2> DiagnosedOdrMergeFailures;
1112276479Sdim
1113341825Sdim  /// The set of Objective-C categories that have been deserialized
1114234353Sdim  /// since the last time the declaration chains were linked.
1115234353Sdim  llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized;
1116234353Sdim
1117341825Sdim  /// The set of Objective-C class definitions that have already been
1118234353Sdim  /// loaded, for which we will need to check for categories whenever a new
1119234353Sdim  /// module is loaded.
1120249423Sdim  SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded;
1121276479Sdim
1122327952Sdim  using KeyDeclsMap =
1123327952Sdim      llvm::DenseMap<Decl *, SmallVector<serialization::DeclID, 2>>;
1124341825Sdim
1125341825Sdim  /// A mapping from canonical declarations to the set of global
1126288943Sdim  /// declaration IDs for key declaration that have been merged with that
1127288943Sdim  /// canonical declaration. A key declaration is a formerly-canonical
1128288943Sdim  /// declaration whose module did not import any other key declaration for that
1129288943Sdim  /// entity. These are the IDs that we use as keys when finding redecl chains.
1130288943Sdim  KeyDeclsMap KeyDecls;
1131341825Sdim
1132341825Sdim  /// A mapping from DeclContexts to the semantic DeclContext that we
1133261991Sdim  /// are treating as the definition of the entity. This is used, for instance,
1134261991Sdim  /// when merging implicit instantiations of class templates across modules.
1135261991Sdim  llvm::DenseMap<DeclContext *, DeclContext *> MergedDeclContexts;
1136261991Sdim
1137341825Sdim  /// A mapping from canonical declarations of enums to their canonical
1138261991Sdim  /// definitions. Only populated when using modules in C++.
1139261991Sdim  llvm::DenseMap<EnumDecl *, EnumDecl *> EnumDefinitions;
1140261991Sdim
1141341825Sdim  /// When reading a Stmt tree, Stmt operands are placed in this stack.
1142226633Sdim  SmallVector<Stmt *, 16> StmtStack;
1143212795Sdim
1144341825Sdim  /// What kind of records we are reading.
1145212795Sdim  enum ReadingKind {
1146261991Sdim    Read_None, Read_Decl, Read_Type, Read_Stmt
1147212795Sdim  };
1148212795Sdim
1149341825Sdim  /// What kind of records we are reading.
1150314564Sdim  ReadingKind ReadingKind = Read_None;
1151212795Sdim
1152341825Sdim  /// RAII object to change the reading kind.
1153212795Sdim  class ReadingKindTracker {
1154212795Sdim    ASTReader &Reader;
1155212795Sdim    enum ReadingKind PrevKind;
1156212795Sdim
1157212795Sdim  public:
1158212795Sdim    ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader)
1159341825Sdim        : Reader(reader), PrevKind(Reader.ReadingKind) {
1160212795Sdim      Reader.ReadingKind = newKind;
1161212795Sdim    }
1162212795Sdim
1163327952Sdim    ReadingKindTracker(const ReadingKindTracker &) = delete;
1164327952Sdim    ReadingKindTracker &operator=(const ReadingKindTracker &) = delete;
1165212795Sdim    ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; }
1166212795Sdim  };
1167212795Sdim
1168341825Sdim  /// RAII object to mark the start of processing updates.
1169309124Sdim  class ProcessingUpdatesRAIIObj {
1170309124Sdim    ASTReader &Reader;
1171309124Sdim    bool PrevState;
1172309124Sdim
1173309124Sdim  public:
1174309124Sdim    ProcessingUpdatesRAIIObj(ASTReader &reader)
1175341825Sdim        : Reader(reader), PrevState(Reader.ProcessingUpdateRecords) {
1176309124Sdim      Reader.ProcessingUpdateRecords = true;
1177309124Sdim    }
1178309124Sdim
1179327952Sdim    ProcessingUpdatesRAIIObj(const ProcessingUpdatesRAIIObj &) = delete;
1180327952Sdim    ProcessingUpdatesRAIIObj &
1181327952Sdim    operator=(const ProcessingUpdatesRAIIObj &) = delete;
1182309124Sdim    ~ProcessingUpdatesRAIIObj() { Reader.ProcessingUpdateRecords = PrevState; }
1183309124Sdim  };
1184309124Sdim
1185341825Sdim  /// Suggested contents of the predefines buffer, after this
1186212795Sdim  /// PCH file has been processed.
1187212795Sdim  ///
1188212795Sdim  /// In most cases, this string will be empty, because the predefines
1189212795Sdim  /// buffer computed to build the PCH file will be identical to the
1190212795Sdim  /// predefines buffer computed from the command line. However, when
1191212795Sdim  /// there are differences that the PCH reader can work around, this
1192212795Sdim  /// predefines buffer may contain additional definitions.
1193212795Sdim  std::string SuggestedPredefines;
1194212795Sdim
1195327952Sdim  llvm::DenseMap<const Decl *, bool> DefinitionSource;
1196321369Sdim
1197341825Sdim  /// Reads a statement from the specified cursor.
1198234353Sdim  Stmt *ReadStmtFromStream(ModuleFile &F);
1199212795Sdim
1200276479Sdim  struct InputFileInfo {
1201276479Sdim    std::string Filename;
1202360784Sdim    uint64_t ContentHash;
1203276479Sdim    off_t StoredSize;
1204276479Sdim    time_t StoredTime;
1205276479Sdim    bool Overridden;
1206296417Sdim    bool Transient;
1207321369Sdim    bool TopLevelModuleMap;
1208276479Sdim  };
1209276479Sdim
1210341825Sdim  /// Reads the stored information about an input file.
1211276479Sdim  InputFileInfo readInputFileInfo(ModuleFile &F, unsigned ID);
1212276479Sdim
1213341825Sdim  /// Retrieve the file entry and 'overridden' bit for an input
1214243830Sdim  /// file in the given module file.
1215249423Sdim  serialization::InputFile getInputFile(ModuleFile &F, unsigned ID,
1216249423Sdim                                        bool Complain = true);
1217243830Sdim
1218280031Sdimpublic:
1219280031Sdim  void ResolveImportedPath(ModuleFile &M, std::string &Filename);
1220280031Sdim  static void ResolveImportedPath(std::string &Filename, StringRef Prefix);
1221223017Sdim
1222341825Sdim  /// Returns the first key declaration for the given declaration. This
1223288943Sdim  /// is one that is formerly-canonical (or still canonical) and whose module
1224288943Sdim  /// did not import any other key declaration of the entity.
1225288943Sdim  Decl *getKeyDeclaration(Decl *D) {
1226288943Sdim    D = D->getCanonicalDecl();
1227288943Sdim    if (D->isFromASTFile())
1228288943Sdim      return D;
1229288943Sdim
1230288943Sdim    auto I = KeyDecls.find(D);
1231288943Sdim    if (I == KeyDecls.end() || I->second.empty())
1232288943Sdim      return D;
1233288943Sdim    return GetExistingDecl(I->second[0]);
1234288943Sdim  }
1235288943Sdim  const Decl *getKeyDeclaration(const Decl *D) {
1236288943Sdim    return getKeyDeclaration(const_cast<Decl*>(D));
1237288943Sdim  }
1238288943Sdim
1239341825Sdim  /// Run a callback on each imported key declaration of \p D.
1240288943Sdim  template <typename Fn>
1241288943Sdim  void forEachImportedKeyDecl(const Decl *D, Fn Visit) {
1242288943Sdim    D = D->getCanonicalDecl();
1243288943Sdim    if (D->isFromASTFile())
1244288943Sdim      Visit(D);
1245288943Sdim
1246288943Sdim    auto It = KeyDecls.find(const_cast<Decl*>(D));
1247288943Sdim    if (It != KeyDecls.end())
1248288943Sdim      for (auto ID : It->second)
1249288943Sdim        Visit(GetExistingDecl(ID));
1250288943Sdim  }
1251288943Sdim
1252341825Sdim  /// Get the loaded lookup tables for \p Primary, if any.
1253296417Sdim  const serialization::reader::DeclContextLookupTable *
1254296417Sdim  getLoadedLookupTables(DeclContext *Primary) const;
1255296417Sdim
1256280031Sdimprivate:
1257249423Sdim  struct ImportedModule {
1258249423Sdim    ModuleFile *Mod;
1259249423Sdim    ModuleFile *ImportedBy;
1260249423Sdim    SourceLocation ImportLoc;
1261249423Sdim
1262249423Sdim    ImportedModule(ModuleFile *Mod,
1263249423Sdim                   ModuleFile *ImportedBy,
1264249423Sdim                   SourceLocation ImportLoc)
1265341825Sdim        : Mod(Mod), ImportedBy(ImportedBy), ImportLoc(ImportLoc) {}
1266249423Sdim  };
1267249423Sdim
1268226633Sdim  ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type,
1269249423Sdim                            SourceLocation ImportLoc, ModuleFile *ImportedBy,
1270249423Sdim                            SmallVectorImpl<ImportedModule> &Loaded,
1271249423Sdim                            off_t ExpectedSize, time_t ExpectedModTime,
1272321369Sdim                            ASTFileSignature ExpectedSignature,
1273243830Sdim                            unsigned ClientLoadCapabilities);
1274243830Sdim  ASTReadResult ReadControlBlock(ModuleFile &F,
1275249423Sdim                                 SmallVectorImpl<ImportedModule> &Loaded,
1276276479Sdim                                 const ModuleFile *ImportedBy,
1277243830Sdim                                 unsigned ClientLoadCapabilities);
1278296417Sdim  static ASTReadResult ReadOptionsBlock(
1279296417Sdim      llvm::BitstreamCursor &Stream, unsigned ClientLoadCapabilities,
1280296417Sdim      bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener,
1281321369Sdim      std::string &SuggestedPredefines);
1282321369Sdim
1283321369Sdim  /// Read the unhashed control block.
1284321369Sdim  ///
1285321369Sdim  /// This has no effect on \c F.Stream, instead creating a fresh cursor from
1286321369Sdim  /// \c F.Data and reading ahead.
1287321369Sdim  ASTReadResult readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy,
1288321369Sdim                                         unsigned ClientLoadCapabilities);
1289321369Sdim
1290321369Sdim  static ASTReadResult
1291321369Sdim  readUnhashedControlBlockImpl(ModuleFile *F, llvm::StringRef StreamData,
1292321369Sdim                               unsigned ClientLoadCapabilities,
1293321369Sdim                               bool AllowCompatibleConfigurationMismatch,
1294321369Sdim                               ASTReaderListener *Listener,
1295321369Sdim                               bool ValidateDiagnosticOptions);
1296321369Sdim
1297276479Sdim  ASTReadResult ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities);
1298296417Sdim  ASTReadResult ReadExtensionBlock(ModuleFile &F);
1299321369Sdim  void ReadModuleOffsetMap(ModuleFile &F) const;
1300280031Sdim  bool ParseLineTable(ModuleFile &F, const RecordData &Record);
1301243830Sdim  bool ReadSourceManagerBlock(ModuleFile &F);
1302226633Sdim  llvm::BitstreamCursor &SLocCursorForID(int ID);
1303234353Sdim  SourceLocation getImportLocation(ModuleFile *F);
1304280031Sdim  ASTReadResult ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
1305280031Sdim                                       const ModuleFile *ImportedBy,
1306280031Sdim                                       unsigned ClientLoadCapabilities);
1307276479Sdim  ASTReadResult ReadSubmoduleBlock(ModuleFile &F,
1308276479Sdim                                   unsigned ClientLoadCapabilities);
1309243830Sdim  static bool ParseLanguageOptions(const RecordData &Record, bool Complain,
1310280031Sdim                                   ASTReaderListener &Listener,
1311280031Sdim                                   bool AllowCompatibleDifferences);
1312243830Sdim  static bool ParseTargetOptions(const RecordData &Record, bool Complain,
1313288943Sdim                                 ASTReaderListener &Listener,
1314288943Sdim                                 bool AllowCompatibleDifferences);
1315243830Sdim  static bool ParseDiagnosticOptions(const RecordData &Record, bool Complain,
1316243830Sdim                                     ASTReaderListener &Listener);
1317243830Sdim  static bool ParseFileSystemOptions(const RecordData &Record, bool Complain,
1318243830Sdim                                     ASTReaderListener &Listener);
1319243830Sdim  static bool ParseHeaderSearchOptions(const RecordData &Record, bool Complain,
1320243830Sdim                                       ASTReaderListener &Listener);
1321243830Sdim  static bool ParsePreprocessorOptions(const RecordData &Record, bool Complain,
1322243830Sdim                                       ASTReaderListener &Listener,
1323243830Sdim                                       std::string &SuggestedPredefines);
1324243830Sdim
1325218893Sdim  struct RecordLocation {
1326327952Sdim    ModuleFile *F;
1327327952Sdim    uint64_t Offset;
1328327952Sdim
1329341825Sdim    RecordLocation(ModuleFile *M, uint64_t O) : F(M), Offset(O) {}
1330218893Sdim  };
1331212795Sdim
1332226633Sdim  QualType readTypeRecord(unsigned Index);
1333212795Sdim  RecordLocation TypeCursorForIndex(unsigned Index);
1334212795Sdim  void LoadedDecl(unsigned Index, Decl *D);
1335226633Sdim  Decl *ReadDeclRecord(serialization::DeclID ID);
1336276479Sdim  void markIncompleteDeclChain(Decl *Canon);
1337288943Sdim
1338341825Sdim  /// Returns the most recent declaration of a declaration (which must be
1339288943Sdim  /// of a redeclarable kind) that is either local or has already been loaded
1340288943Sdim  /// merged into its redecl chain.
1341288943Sdim  Decl *getMostRecentExistingDecl(Decl *D);
1342288943Sdim
1343234353Sdim  RecordLocation DeclCursorForID(serialization::DeclID ID,
1344309124Sdim                                 SourceLocation &Location);
1345321369Sdim  void loadDeclUpdateRecords(PendingUpdateRecord &Record);
1346296417Sdim  void loadPendingDeclChain(Decl *D, uint64_t LocalOffset);
1347234353Sdim  void loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D,
1348234353Sdim                          unsigned PreviousGeneration = 0);
1349234353Sdim
1350226633Sdim  RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
1351234353Sdim  uint64_t getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset);
1352212795Sdim
1353341825Sdim  /// Returns the first preprocessed entity ID that begins or ends after
1354276479Sdim  /// \arg Loc.
1355226633Sdim  serialization::PreprocessedEntityID
1356276479Sdim  findPreprocessedEntity(SourceLocation Loc, bool EndsAfter) const;
1357226633Sdim
1358341825Sdim  /// Find the next module that contains entities and return the ID
1359226633Sdim  /// of the first entry.
1360243830Sdim  ///
1361243830Sdim  /// \param SLocMapI points at a chunk of a module that contains no
1362239462Sdim  /// preprocessed entities or the entities it contains are not the
1363239462Sdim  /// ones we are looking for.
1364226633Sdim  serialization::PreprocessedEntityID
1365226633Sdim    findNextPreprocessedEntity(
1366226633Sdim                        GlobalSLocOffsetMapType::const_iterator SLocMapI) const;
1367226633Sdim
1368341825Sdim  /// Returns (ModuleFile, Local index) pair for \p GlobalIndex of a
1369234353Sdim  /// preprocessed entity.
1370234353Sdim  std::pair<ModuleFile *, unsigned>
1371234353Sdim    getModulePreprocessedEntity(unsigned GlobalIndex);
1372234353Sdim
1373341825Sdim  /// Returns (begin, end) pair for the preprocessed entities of a
1374243830Sdim  /// particular module.
1375288943Sdim  llvm::iterator_range<PreprocessingRecord::iterator>
1376288943Sdim  getModulePreprocessedEntities(ModuleFile &Mod) const;
1377243830Sdim
1378321369Sdimpublic:
1379288943Sdim  class ModuleDeclIterator
1380288943Sdim      : public llvm::iterator_adaptor_base<
1381288943Sdim            ModuleDeclIterator, const serialization::LocalDeclID *,
1382288943Sdim            std::random_access_iterator_tag, const Decl *, ptrdiff_t,
1383288943Sdim            const Decl *, const Decl *> {
1384327952Sdim    ASTReader *Reader = nullptr;
1385327952Sdim    ModuleFile *Mod = nullptr;
1386243830Sdim
1387243830Sdim  public:
1388327952Sdim    ModuleDeclIterator() : iterator_adaptor_base(nullptr) {}
1389243830Sdim
1390243830Sdim    ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod,
1391243830Sdim                       const serialization::LocalDeclID *Pos)
1392288943Sdim        : iterator_adaptor_base(Pos), Reader(Reader), Mod(Mod) {}
1393243830Sdim
1394243830Sdim    value_type operator*() const {
1395288943Sdim      return Reader->GetDecl(Reader->getGlobalDeclID(*Mod, *I));
1396243830Sdim    }
1397327952Sdim
1398288943Sdim    value_type operator->() const { return **this; }
1399243830Sdim
1400288943Sdim    bool operator==(const ModuleDeclIterator &RHS) const {
1401288943Sdim      assert(Reader == RHS.Reader && Mod == RHS.Mod);
1402288943Sdim      return I == RHS.I;
1403243830Sdim    }
1404243830Sdim  };
1405243830Sdim
1406288943Sdim  llvm::iterator_range<ModuleDeclIterator>
1407288943Sdim  getModuleFileLevelDecls(ModuleFile &Mod);
1408243830Sdim
1409321369Sdimprivate:
1410212795Sdim  void PassInterestingDeclsToConsumer();
1411234353Sdim  void PassInterestingDeclToConsumer(Decl *D);
1412212795Sdim
1413234353Sdim  void finishPendingActions();
1414280031Sdim  void diagnoseOdrViolations();
1415234353Sdim
1416251662Sdim  void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name);
1417251662Sdim
1418249423Sdim  void addPendingDeclContextInfo(Decl *D,
1419249423Sdim                                 serialization::GlobalDeclID SemaDC,
1420249423Sdim                                 serialization::GlobalDeclID LexicalDC) {
1421249423Sdim    assert(D);
1422249423Sdim    PendingDeclContextInfo Info = { D, SemaDC, LexicalDC };
1423249423Sdim    PendingDeclContextInfos.push_back(Info);
1424249423Sdim  }
1425249423Sdim
1426341825Sdim  /// Produce an error diagnostic and return true.
1427212795Sdim  ///
1428212795Sdim  /// This routine should only be used for fatal errors that have to
1429212795Sdim  /// do with non-routine failures (e.g., corrupted AST file).
1430321369Sdim  void Error(StringRef Msg) const;
1431226633Sdim  void Error(unsigned DiagID, StringRef Arg1 = StringRef(),
1432360784Sdim             StringRef Arg2 = StringRef(), StringRef Arg3 = StringRef()) const;
1433360784Sdim  void Error(unsigned DiagID, StringRef Arg1, StringRef Arg2,
1434360784Sdim             unsigned Select) const;
1435353358Sdim  void Error(llvm::Error &&Err) const;
1436212795Sdim
1437212795Sdimpublic:
1438341825Sdim  /// Load the AST file and validate its contents against the given
1439212795Sdim  /// Preprocessor.
1440212795Sdim  ///
1441212795Sdim  /// \param PP the preprocessor associated with the context in which this
1442212795Sdim  /// precompiled header will be loaded.
1443212795Sdim  ///
1444212795Sdim  /// \param Context the AST context that this precompiled header will be
1445321369Sdim  /// loaded into, if any.
1446212795Sdim  ///
1447296417Sdim  /// \param PCHContainerRdr the PCHContainerOperations to use for loading and
1448288943Sdim  /// creating modules.
1449288943Sdim  ///
1450296417Sdim  /// \param Extensions the list of module file extensions that can be loaded
1451296417Sdim  /// from the AST files.
1452296417Sdim  ///
1453212795Sdim  /// \param isysroot If non-NULL, the system include path specified by the
1454212795Sdim  /// user. This is only used with relocatable PCH files. If non-NULL,
1455212795Sdim  /// a relocatable PCH file will use the default path "/".
1456212795Sdim  ///
1457212795Sdim  /// \param DisableValidation If true, the AST reader will suppress most
1458212795Sdim  /// of its regular consistency checking, allowing the use of precompiled
1459212795Sdim  /// headers that cannot be determined to be compatible.
1460218893Sdim  ///
1461234353Sdim  /// \param AllowASTWithCompilerErrors If true, the AST reader will accept an
1462234353Sdim  /// AST file the was created out of an AST with compiler errors,
1463234353Sdim  /// otherwise it will reject it.
1464249423Sdim  ///
1465276479Sdim  /// \param AllowConfigurationMismatch If true, the AST reader will not check
1466276479Sdim  /// for configuration differences between the AST file and the invocation.
1467276479Sdim  ///
1468276479Sdim  /// \param ValidateSystemInputs If true, the AST reader will validate
1469276479Sdim  /// system input files in addition to user input files. This is only
1470276479Sdim  /// meaningful if \p DisableValidation is false.
1471276479Sdim  ///
1472249423Sdim  /// \param UseGlobalIndex If true, the AST reader will try to load and use
1473249423Sdim  /// the global module index.
1474288943Sdim  ///
1475288943Sdim  /// \param ReadTimer If non-null, a timer used to track the time spent
1476288943Sdim  /// deserializing.
1477353358Sdim  ASTReader(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
1478353358Sdim            ASTContext *Context, const PCHContainerReader &PCHContainerRdr,
1479314564Sdim            ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
1480288943Sdim            StringRef isysroot = "", bool DisableValidation = false,
1481249423Sdim            bool AllowASTWithCompilerErrors = false,
1482276479Sdim            bool AllowConfigurationMismatch = false,
1483360784Sdim            bool ValidateSystemInputs = false,
1484360784Sdim            bool ValidateASTInputFilesContent = false,
1485360784Sdim            bool UseGlobalIndex = true,
1486288943Sdim            std::unique_ptr<llvm::Timer> ReadTimer = {});
1487327952Sdim  ASTReader(const ASTReader &) = delete;
1488327952Sdim  ASTReader &operator=(const ASTReader &) = delete;
1489288943Sdim  ~ASTReader() override;
1490212795Sdim
1491226633Sdim  SourceManager &getSourceManager() const { return SourceMgr; }
1492249423Sdim  FileManager &getFileManager() const { return FileMgr; }
1493296417Sdim  DiagnosticsEngine &getDiags() const { return Diags; }
1494234353Sdim
1495341825Sdim  /// Flags that indicate what kind of AST loading failures the client
1496243830Sdim  /// of the AST reader can directly handle.
1497243830Sdim  ///
1498243830Sdim  /// When a client states that it can handle a particular kind of failure,
1499243830Sdim  /// the AST reader will not emit errors when producing that kind of failure.
1500243830Sdim  enum LoadFailureCapabilities {
1501341825Sdim    /// The client can't handle any AST loading failures.
1502243830Sdim    ARR_None = 0,
1503327952Sdim
1504341825Sdim    /// The client can handle an AST file that cannot load because it
1505249423Sdim    /// is missing.
1506249423Sdim    ARR_Missing = 0x1,
1507327952Sdim
1508341825Sdim    /// The client can handle an AST file that cannot load because it
1509243830Sdim    /// is out-of-date relative to its input files.
1510249423Sdim    ARR_OutOfDate = 0x2,
1511327952Sdim
1512341825Sdim    /// The client can handle an AST file that cannot load because it
1513243830Sdim    /// was built with a different version of Clang.
1514249423Sdim    ARR_VersionMismatch = 0x4,
1515327952Sdim
1516341825Sdim    /// The client can handle an AST file that cannot load because it's
1517243830Sdim    /// compiled configuration doesn't match that of the context it was
1518243830Sdim    /// loaded into.
1519249423Sdim    ARR_ConfigurationMismatch = 0x8
1520243830Sdim  };
1521243830Sdim
1522341825Sdim  /// Load the AST file designated by the given file name.
1523243830Sdim  ///
1524243830Sdim  /// \param FileName The name of the AST file to load.
1525243830Sdim  ///
1526243830Sdim  /// \param Type The kind of AST being loaded, e.g., PCH, module, main file,
1527243830Sdim  /// or preamble.
1528243830Sdim  ///
1529249423Sdim  /// \param ImportLoc the location where the module file will be considered as
1530249423Sdim  /// imported from. For non-module AST types it should be invalid.
1531249423Sdim  ///
1532243830Sdim  /// \param ClientLoadCapabilities The set of client load-failure
1533243830Sdim  /// capabilities, represented as a bitset of the enumerators of
1534243830Sdim  /// LoadFailureCapabilities.
1535314564Sdim  ///
1536314564Sdim  /// \param Imported optional out-parameter to append the list of modules
1537314564Sdim  /// that were imported by precompiled headers or any other non-module AST file
1538309124Sdim  ASTReadResult ReadAST(StringRef FileName, ModuleKind Type,
1539249423Sdim                        SourceLocation ImportLoc,
1540314564Sdim                        unsigned ClientLoadCapabilities,
1541314564Sdim                        SmallVectorImpl<ImportedSubmodule> *Imported = nullptr);
1542212795Sdim
1543341825Sdim  /// Make the entities in the given module and any of its (non-explicit)
1544234353Sdim  /// submodules visible to name lookup.
1545234353Sdim  ///
1546234353Sdim  /// \param Mod The module whose names should be made visible.
1547234353Sdim  ///
1548239462Sdim  /// \param NameVisibility The level of visibility to give the names in the
1549239462Sdim  /// module.  Visibility can only be increased over time.
1550249423Sdim  ///
1551249423Sdim  /// \param ImportLoc The location at which the import occurs.
1552276479Sdim  void makeModuleVisible(Module *Mod,
1553249423Sdim                         Module::NameVisibilityKind NameVisibility,
1554288943Sdim                         SourceLocation ImportLoc);
1555276479Sdim
1556341825Sdim  /// Make the names within this set of hidden names visible.
1557288943Sdim  void makeNamesVisible(const HiddenNames &Names, Module *Owner);
1558276479Sdim
1559341825Sdim  /// Note that MergedDef is a redefinition of the canonical definition
1560314564Sdim  /// Def, so Def should be visible whenever MergedDef is.
1561314564Sdim  void mergeDefinitionVisibility(NamedDecl *Def, NamedDecl *MergedDef);
1562314564Sdim
1563341825Sdim  /// Take the AST callbacks listener.
1564280031Sdim  std::unique_ptr<ASTReaderListener> takeListener() {
1565280031Sdim    return std::move(Listener);
1566280031Sdim  }
1567280031Sdim
1568341825Sdim  /// Set the AST callbacks listener.
1569280031Sdim  void setListener(std::unique_ptr<ASTReaderListener> Listener) {
1570280031Sdim    this->Listener = std::move(Listener);
1571212795Sdim  }
1572212795Sdim
1573341825Sdim  /// Add an AST callback listener.
1574276479Sdim  ///
1575276479Sdim  /// Takes ownership of \p L.
1576280031Sdim  void addListener(std::unique_ptr<ASTReaderListener> L) {
1577276479Sdim    if (Listener)
1578360784Sdim      L = std::make_unique<ChainedASTReaderListener>(std::move(L),
1579280031Sdim                                                      std::move(Listener));
1580280031Sdim    Listener = std::move(L);
1581276479Sdim  }
1582276479Sdim
1583280031Sdim  /// RAII object to temporarily add an AST callback listener.
1584280031Sdim  class ListenerScope {
1585280031Sdim    ASTReader &Reader;
1586327952Sdim    bool Chained = false;
1587280031Sdim
1588280031Sdim  public:
1589280031Sdim    ListenerScope(ASTReader &Reader, std::unique_ptr<ASTReaderListener> L)
1590327952Sdim        : Reader(Reader) {
1591280031Sdim      auto Old = Reader.takeListener();
1592280031Sdim      if (Old) {
1593280031Sdim        Chained = true;
1594360784Sdim        L = std::make_unique<ChainedASTReaderListener>(std::move(L),
1595280031Sdim                                                        std::move(Old));
1596280031Sdim      }
1597280031Sdim      Reader.setListener(std::move(L));
1598280031Sdim    }
1599327952Sdim
1600280031Sdim    ~ListenerScope() {
1601280031Sdim      auto New = Reader.takeListener();
1602280031Sdim      if (Chained)
1603280031Sdim        Reader.setListener(static_cast<ChainedASTReaderListener *>(New.get())
1604280031Sdim                               ->takeSecond());
1605280031Sdim    }
1606280031Sdim  };
1607280031Sdim
1608341825Sdim  /// Set the AST deserialization listener.
1609276479Sdim  void setDeserializationListener(ASTDeserializationListener *Listener,
1610276479Sdim                                  bool TakeOwnership = false);
1611212795Sdim
1612341825Sdim  /// Get the AST deserialization listener.
1613341825Sdim  ASTDeserializationListener *getDeserializationListener() {
1614341825Sdim    return DeserializationListener;
1615341825Sdim  }
1616341825Sdim
1617341825Sdim  /// Determine whether this AST reader has a global index.
1618276479Sdim  bool hasGlobalIndex() const { return (bool)GlobalIndex; }
1619249423Sdim
1620341825Sdim  /// Return global module index.
1621276479Sdim  GlobalModuleIndex *getGlobalIndex() { return GlobalIndex.get(); }
1622276479Sdim
1623341825Sdim  /// Reset reader for a reload try.
1624276479Sdim  void resetForReload() { TriedLoadingGlobalIndex = false; }
1625276479Sdim
1626341825Sdim  /// Attempts to load the global index.
1627249423Sdim  ///
1628249423Sdim  /// \returns true if loading the global index has failed for any reason.
1629249423Sdim  bool loadGlobalIndex();
1630249423Sdim
1631341825Sdim  /// Determine whether we tried to load the global index, but failed,
1632249423Sdim  /// e.g., because it is out-of-date or does not exist.
1633249423Sdim  bool isGlobalIndexUnavailable() const;
1634341825Sdim
1635341825Sdim  /// Initializes the ASTContext
1636226633Sdim  void InitializeContext();
1637212795Sdim
1638341825Sdim  /// Update the state of Sema after loading some additional modules.
1639261991Sdim  void UpdateSema();
1640261991Sdim
1641341825Sdim  /// Add in-memory (virtual file) buffer.
1642280031Sdim  void addInMemoryBuffer(StringRef &FileName,
1643280031Sdim                         std::unique_ptr<llvm::MemoryBuffer> Buffer) {
1644280031Sdim    ModuleMgr.addInMemoryBuffer(FileName, std::move(Buffer));
1645221345Sdim  }
1646221345Sdim
1647341825Sdim  /// Finalizes the AST reader's state before writing an AST file to
1648234353Sdim  /// disk.
1649234353Sdim  ///
1650234353Sdim  /// This operation may undo temporary state in the AST that should not be
1651234353Sdim  /// emitted.
1652234353Sdim  void finalizeForWriting();
1653234353Sdim
1654341825Sdim  /// Retrieve the module manager.
1655226633Sdim  ModuleManager &getModuleManager() { return ModuleMgr; }
1656212795Sdim
1657341825Sdim  /// Retrieve the preprocessor.
1658226633Sdim  Preprocessor &getPreprocessor() const { return PP; }
1659234353Sdim
1660341825Sdim  /// Retrieve the name of the original source file name for the primary
1661243830Sdim  /// module file.
1662243830Sdim  StringRef getOriginalSourceFile() {
1663341825Sdim    return ModuleMgr.getPrimaryModule().OriginalSourceFileName;
1664243830Sdim  }
1665212795Sdim
1666341825Sdim  /// Retrieve the name of the original source file name directly from
1667212795Sdim  /// the AST file, without actually loading the AST file.
1668288943Sdim  static std::string
1669288943Sdim  getOriginalSourceFile(const std::string &ASTFileName, FileManager &FileMgr,
1670288943Sdim                        const PCHContainerReader &PCHContainerRdr,
1671288943Sdim                        DiagnosticsEngine &Diags);
1672212795Sdim
1673341825Sdim  /// Read the control block for the named AST file.
1674243830Sdim  ///
1675243830Sdim  /// \returns true if an error occurred, false otherwise.
1676288943Sdim  static bool
1677288943Sdim  readASTFileControlBlock(StringRef Filename, FileManager &FileMgr,
1678288943Sdim                          const PCHContainerReader &PCHContainerRdr,
1679296417Sdim                          bool FindModuleFileExtensions,
1680314564Sdim                          ASTReaderListener &Listener,
1681314564Sdim                          bool ValidateDiagnosticOptions);
1682243830Sdim
1683341825Sdim  /// Determine whether the given AST file is acceptable to load into a
1684243830Sdim  /// translation unit with the given language and target options.
1685288943Sdim  static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr,
1686288943Sdim                                  const PCHContainerReader &PCHContainerRdr,
1687243830Sdim                                  const LangOptions &LangOpts,
1688243830Sdim                                  const TargetOptions &TargetOpts,
1689288943Sdim                                  const PreprocessorOptions &PPOpts,
1690321369Sdim                                  StringRef ExistingModuleCachePath);
1691243830Sdim
1692341825Sdim  /// Returns the suggested contents of the predefines buffer,
1693212795Sdim  /// which contains a (typically-empty) subset of the predefines
1694212795Sdim  /// build prior to including the precompiled header.
1695212795Sdim  const std::string &getSuggestedPredefines() { return SuggestedPredefines; }
1696212795Sdim
1697341825Sdim  /// Read a preallocated preprocessed entity from the external source.
1698226633Sdim  ///
1699226633Sdim  /// \returns null if an error occurred that prevented the preprocessed
1700226633Sdim  /// entity from being loaded.
1701276479Sdim  PreprocessedEntity *ReadPreprocessedEntity(unsigned Index) override;
1702218893Sdim
1703341825Sdim  /// Returns a pair of [Begin, End) indices of preallocated
1704243830Sdim  /// preprocessed entities that \p Range encompasses.
1705276479Sdim  std::pair<unsigned, unsigned>
1706276479Sdim      findPreprocessedEntitiesInRange(SourceRange Range) override;
1707226633Sdim
1708341825Sdim  /// Optionally returns true or false if the preallocated preprocessed
1709243830Sdim  /// entity with index \p Index came from file \p FID.
1710276479Sdim  Optional<bool> isPreprocessedEntityInFileID(unsigned Index,
1711276479Sdim                                              FileID FID) override;
1712234353Sdim
1713341825Sdim  /// Read a preallocated skipped range from the external source.
1714341825Sdim  SourceRange ReadSkippedRange(unsigned Index) override;
1715341825Sdim
1716341825Sdim  /// Read the header file information for the given file entry.
1717276479Sdim  HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) override;
1718218893Sdim
1719226633Sdim  void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag);
1720218893Sdim
1721341825Sdim  /// Returns the number of source locations found in the chain.
1722212795Sdim  unsigned getTotalNumSLocs() const {
1723212795Sdim    return TotalNumSLocEntries;
1724212795Sdim  }
1725212795Sdim
1726341825Sdim  /// Returns the number of identifiers found in the chain.
1727212795Sdim  unsigned getTotalNumIdentifiers() const {
1728212795Sdim    return static_cast<unsigned>(IdentifiersLoaded.size());
1729212795Sdim  }
1730212795Sdim
1731341825Sdim  /// Returns the number of macros found in the chain.
1732243830Sdim  unsigned getTotalNumMacros() const {
1733243830Sdim    return static_cast<unsigned>(MacrosLoaded.size());
1734243830Sdim  }
1735243830Sdim
1736341825Sdim  /// Returns the number of types found in the chain.
1737212795Sdim  unsigned getTotalNumTypes() const {
1738212795Sdim    return static_cast<unsigned>(TypesLoaded.size());
1739212795Sdim  }
1740212795Sdim
1741341825Sdim  /// Returns the number of declarations found in the chain.
1742212795Sdim  unsigned getTotalNumDecls() const {
1743212795Sdim    return static_cast<unsigned>(DeclsLoaded.size());
1744212795Sdim  }
1745212795Sdim
1746341825Sdim  /// Returns the number of submodules known.
1747234353Sdim  unsigned getTotalNumSubmodules() const {
1748234353Sdim    return static_cast<unsigned>(SubmodulesLoaded.size());
1749234353Sdim  }
1750341825Sdim
1751341825Sdim  /// Returns the number of selectors found in the chain.
1752212795Sdim  unsigned getTotalNumSelectors() const {
1753212795Sdim    return static_cast<unsigned>(SelectorsLoaded.size());
1754212795Sdim  }
1755212795Sdim
1756341825Sdim  /// Returns the number of preprocessed entities known to the AST
1757226633Sdim  /// reader.
1758226633Sdim  unsigned getTotalNumPreprocessedEntities() const {
1759226633Sdim    unsigned Result = 0;
1760321369Sdim    for (const auto &M : ModuleMgr)
1761321369Sdim      Result += M.NumPreprocessedEntities;
1762226633Sdim    return Result;
1763218893Sdim  }
1764234353Sdim
1765341825Sdim  /// Resolve a type ID into a type, potentially building a new
1766212795Sdim  /// type.
1767212795Sdim  QualType GetType(serialization::TypeID ID);
1768212795Sdim
1769341825Sdim  /// Resolve a local type ID within a given AST file into a type.
1770234353Sdim  QualType getLocalType(ModuleFile &F, unsigned LocalID);
1771234353Sdim
1772341825Sdim  /// Map a local type ID within a given AST file into a global type ID.
1773234353Sdim  serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const;
1774234353Sdim
1775341825Sdim  /// Read a type from the current position in the given record, which
1776226633Sdim  /// was read from the given AST file.
1777234353Sdim  QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) {
1778226633Sdim    if (Idx >= Record.size())
1779341825Sdim      return {};
1780234353Sdim
1781226633Sdim    return getLocalType(F, Record[Idx++]);
1782226633Sdim  }
1783234353Sdim
1784341825Sdim  /// Map from a local declaration ID within a given module to a
1785226633Sdim  /// global declaration ID.
1786243830Sdim  serialization::DeclID getGlobalDeclID(ModuleFile &F,
1787243830Sdim                                      serialization::LocalDeclID LocalID) const;
1788212795Sdim
1789341825Sdim  /// Returns true if global DeclID \p ID originated from module \p M.
1790234353Sdim  bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const;
1791234353Sdim
1792341825Sdim  /// Retrieve the module file that owns the given declaration, or NULL
1793234353Sdim  /// if the declaration is not from a module file.
1794249423Sdim  ModuleFile *getOwningModuleFile(const Decl *D);
1795276479Sdim
1796341825Sdim  /// Get the best name we know for the module that owns the given
1797276479Sdim  /// declaration, or an empty string if the declaration is not from a module.
1798276479Sdim  std::string getOwningModuleNameForDiagnostic(const Decl *D);
1799276479Sdim
1800341825Sdim  /// Returns the source location for the decl \p ID.
1801234353Sdim  SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID);
1802234353Sdim
1803341825Sdim  /// Resolve a declaration ID into a declaration, potentially
1804212795Sdim  /// building a new declaration.
1805212795Sdim  Decl *GetDecl(serialization::DeclID ID);
1806276479Sdim  Decl *GetExternalDecl(uint32_t ID) override;
1807212795Sdim
1808341825Sdim  /// Resolve a declaration ID into a declaration. Return 0 if it's not
1809276479Sdim  /// been loaded yet.
1810276479Sdim  Decl *GetExistingDecl(serialization::DeclID ID);
1811276479Sdim
1812341825Sdim  /// Reads a declaration with the given local ID in the given module.
1813234353Sdim  Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) {
1814226633Sdim    return GetDecl(getGlobalDeclID(F, LocalID));
1815226633Sdim  }
1816226633Sdim
1817341825Sdim  /// Reads a declaration with the given local ID in the given module.
1818226633Sdim  ///
1819226633Sdim  /// \returns The requested declaration, casted to the given return type.
1820226633Sdim  template<typename T>
1821234353Sdim  T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) {
1822226633Sdim    return cast_or_null<T>(GetLocalDecl(F, LocalID));
1823226633Sdim  }
1824226633Sdim
1825341825Sdim  /// Map a global declaration ID into the declaration ID used to
1826234353Sdim  /// refer to this declaration within the given module fule.
1827234353Sdim  ///
1828234353Sdim  /// \returns the global ID of the given declaration as known in the given
1829234353Sdim  /// module file.
1830341825Sdim  serialization::DeclID
1831234353Sdim  mapGlobalIDToModuleFileGlobalID(ModuleFile &M,
1832234353Sdim                                  serialization::DeclID GlobalID);
1833341825Sdim
1834341825Sdim  /// Reads a declaration ID from the given position in a record in the
1835226633Sdim  /// given module.
1836226633Sdim  ///
1837226633Sdim  /// \returns The declaration ID read from the record, adjusted to a global ID.
1838234353Sdim  serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record,
1839226633Sdim                                   unsigned &Idx);
1840234353Sdim
1841341825Sdim  /// Reads a declaration from the given position in a record in the
1842226633Sdim  /// given module.
1843234353Sdim  Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) {
1844226633Sdim    return GetDecl(ReadDeclID(F, R, I));
1845226633Sdim  }
1846234353Sdim
1847341825Sdim  /// Reads a declaration from the given position in a record in the
1848226633Sdim  /// given module.
1849226633Sdim  ///
1850226633Sdim  /// \returns The declaration read from this location, casted to the given
1851226633Sdim  /// result type.
1852226633Sdim  template<typename T>
1853234353Sdim  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1854226633Sdim    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1855226633Sdim  }
1856226633Sdim
1857341825Sdim  /// If any redeclarations of \p D have been imported since it was
1858276479Sdim  /// last checked, this digs out those redeclarations and adds them to the
1859276479Sdim  /// redeclaration chain for \p D.
1860276479Sdim  void CompleteRedeclChain(const Decl *D) override;
1861276479Sdim
1862276479Sdim  CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
1863234353Sdim
1864341825Sdim  /// Resolve the offset of a statement into a statement.
1865212795Sdim  ///
1866212795Sdim  /// This operation will read a new statement from the external
1867212795Sdim  /// source each time it is called, and is meant to be used via a
1868212795Sdim  /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
1869276479Sdim  Stmt *GetExternalDeclStmt(uint64_t Offset) override;
1870212795Sdim
1871212795Sdim  /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
1872212795Sdim  /// specified cursor.  Read the abbreviations that are at the top of the block
1873212795Sdim  /// and then leave the cursor pointing into the block.
1874296417Sdim  static bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID);
1875212795Sdim
1876341825Sdim  /// Finds all the visible declarations with a given name.
1877212795Sdim  /// The current implementation of this method just loads the entire
1878212795Sdim  /// lookup table as unmaterialized references.
1879276479Sdim  bool FindExternalVisibleDeclsByName(const DeclContext *DC,
1880276479Sdim                                      DeclarationName Name) override;
1881212795Sdim
1882341825Sdim  /// Read all of the declarations lexically stored in a
1883212795Sdim  /// declaration context.
1884212795Sdim  ///
1885212795Sdim  /// \param DC The declaration context whose declarations will be
1886212795Sdim  /// read.
1887212795Sdim  ///
1888296417Sdim  /// \param IsKindWeWant A predicate indicating which declaration kinds
1889296417Sdim  /// we are interested in.
1890296417Sdim  ///
1891212795Sdim  /// \param Decls Vector that will contain the declarations loaded
1892212795Sdim  /// from the external source. The caller is responsible for merging
1893212795Sdim  /// these declarations with any declarations already stored in the
1894212795Sdim  /// declaration context.
1895296417Sdim  void
1896296417Sdim  FindExternalLexicalDecls(const DeclContext *DC,
1897296417Sdim                           llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
1898296417Sdim                           SmallVectorImpl<Decl *> &Decls) override;
1899212795Sdim
1900341825Sdim  /// Get the decls that are contained in a file in the Offset/Length
1901243830Sdim  /// range. \p Length can be 0 to indicate a point at \p Offset instead of
1902234353Sdim  /// a range.
1903276479Sdim  void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length,
1904276479Sdim                           SmallVectorImpl<Decl *> &Decls) override;
1905234353Sdim
1906341825Sdim  /// Notify ASTReader that we started deserialization of
1907212795Sdim  /// a decl or type so until FinishedDeserializing is called there may be
1908212795Sdim  /// decls that are initializing. Must be paired with FinishedDeserializing.
1909288943Sdim  void StartedDeserializing() override;
1910212795Sdim
1911341825Sdim  /// Notify ASTReader that we finished the deserialization of
1912212795Sdim  /// a decl or type. Must be paired with StartedDeserializing.
1913276479Sdim  void FinishedDeserializing() override;
1914212795Sdim
1915341825Sdim  /// Function that will be invoked when we begin parsing a new
1916212795Sdim  /// translation unit involving this external AST source.
1917212795Sdim  ///
1918212795Sdim  /// This function will provide all of the external definitions to
1919212795Sdim  /// the ASTConsumer.
1920276479Sdim  void StartTranslationUnit(ASTConsumer *Consumer) override;
1921212795Sdim
1922341825Sdim  /// Print some statistics about AST usage.
1923276479Sdim  void PrintStats() override;
1924212795Sdim
1925341825Sdim  /// Dump information about the AST reader to standard error.
1926226633Sdim  void dump();
1927234353Sdim
1928221345Sdim  /// Return the amount of memory used by memory buffers, breaking down
1929221345Sdim  /// by heap-backed versus mmap'ed memory.
1930276479Sdim  void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
1931221345Sdim
1932341825Sdim  /// Initialize the semantic source with the Sema instance
1933212795Sdim  /// being used to perform semantic analysis on the abstract syntax
1934212795Sdim  /// tree.
1935276479Sdim  void InitializeSema(Sema &S) override;
1936212795Sdim
1937341825Sdim  /// Inform the semantic consumer that Sema is no longer available.
1938276479Sdim  void ForgetSema() override { SemaObj = nullptr; }
1939212795Sdim
1940341825Sdim  /// Retrieve the IdentifierInfo for the named identifier.
1941212795Sdim  ///
1942212795Sdim  /// This routine builds a new IdentifierInfo for the given identifier. If any
1943212795Sdim  /// declarations with this name are visible from translation unit scope, their
1944212795Sdim  /// declarations will be deserialized and introduced into the declaration
1945212795Sdim  /// chain of the identifier.
1946296417Sdim  IdentifierInfo *get(StringRef Name) override;
1947212795Sdim
1948341825Sdim  /// Retrieve an iterator into the set of all identifiers
1949218893Sdim  /// in all loaded AST files.
1950276479Sdim  IdentifierIterator *getIdentifiers() override;
1951218893Sdim
1952341825Sdim  /// Load the contents of the global method pool for a given
1953212795Sdim  /// selector.
1954276479Sdim  void ReadMethodPool(Selector Sel) override;
1955212795Sdim
1956309124Sdim  /// Load the contents of the global method pool for a given
1957309124Sdim  /// selector if necessary.
1958309124Sdim  void updateOutOfDateSelector(Selector Sel) override;
1959309124Sdim
1960341825Sdim  /// Load the set of namespaces that are known to the external source,
1961224145Sdim  /// which will be used during typo correction.
1962276479Sdim  void ReadKnownNamespaces(
1963276479Sdim                         SmallVectorImpl<NamespaceDecl *> &Namespaces) override;
1964224145Sdim
1965276479Sdim  void ReadUndefinedButUsed(
1966309124Sdim      llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) override;
1967249423Sdim
1968288943Sdim  void ReadMismatchingDeleteExpressions(llvm::MapVector<
1969288943Sdim      FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
1970288943Sdim                                            Exprs) override;
1971288943Sdim
1972276479Sdim  void ReadTentativeDefinitions(
1973276479Sdim                            SmallVectorImpl<VarDecl *> &TentativeDefs) override;
1974226633Sdim
1975276479Sdim  void ReadUnusedFileScopedDecls(
1976276479Sdim                       SmallVectorImpl<const DeclaratorDecl *> &Decls) override;
1977226633Sdim
1978276479Sdim  void ReadDelegatingConstructors(
1979276479Sdim                         SmallVectorImpl<CXXConstructorDecl *> &Decls) override;
1980226633Sdim
1981276479Sdim  void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) override;
1982226633Sdim
1983280031Sdim  void ReadUnusedLocalTypedefNameCandidates(
1984280031Sdim      llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override;
1985280031Sdim
1986276479Sdim  void ReadReferencedSelectors(
1987327952Sdim           SmallVectorImpl<std::pair<Selector, SourceLocation>> &Sels) override;
1988226633Sdim
1989276479Sdim  void ReadWeakUndeclaredIdentifiers(
1990327952Sdim           SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo>> &WI) override;
1991226633Sdim
1992276479Sdim  void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override;
1993226633Sdim
1994276479Sdim  void ReadPendingInstantiations(
1995327952Sdim                  SmallVectorImpl<std::pair<ValueDecl *,
1996327952Sdim                                            SourceLocation>> &Pending) override;
1997226633Sdim
1998276479Sdim  void ReadLateParsedTemplates(
1999314564Sdim      llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
2000314564Sdim          &LPTMap) override;
2001261991Sdim
2002341825Sdim  /// Load a selector from disk, registering its ID if it exists.
2003212795Sdim  void LoadSelector(Selector Sel);
2004212795Sdim
2005212795Sdim  void SetIdentifierInfo(unsigned ID, IdentifierInfo *II);
2006212795Sdim  void SetGloballyVisibleDecls(IdentifierInfo *II,
2007226633Sdim                               const SmallVectorImpl<uint32_t> &DeclIDs,
2008276479Sdim                               SmallVectorImpl<Decl *> *Decls = nullptr);
2009212795Sdim
2010341825Sdim  /// Report a diagnostic.
2011321369Sdim  DiagnosticBuilder Diag(unsigned DiagID) const;
2012212795Sdim
2013341825Sdim  /// Report a diagnostic.
2014321369Sdim  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const;
2015212795Sdim
2016226633Sdim  IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID);
2017212795Sdim
2018360784Sdim  IdentifierInfo *readIdentifier(ModuleFile &M, const RecordData &Record,
2019360784Sdim                                 unsigned &Idx) {
2020226633Sdim    return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++]));
2021212795Sdim  }
2022212795Sdim
2023276479Sdim  IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) override {
2024243830Sdim    // Note that we are loading an identifier.
2025243830Sdim    Deserializing AnIdentifier(this);
2026243830Sdim
2027212795Sdim    return DecodeIdentifierInfo(ID);
2028212795Sdim  }
2029212795Sdim
2030234353Sdim  IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID);
2031234353Sdim
2032234353Sdim  serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M,
2033226633Sdim                                                    unsigned LocalID);
2034234353Sdim
2035249423Sdim  void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo);
2036249423Sdim
2037341825Sdim  /// Retrieve the macro with the given ID.
2038249423Sdim  MacroInfo *getMacro(serialization::MacroID ID);
2039243830Sdim
2040341825Sdim  /// Retrieve the global macro ID corresponding to the given local
2041243830Sdim  /// ID within the given module file.
2042243830Sdim  serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID);
2043243830Sdim
2044341825Sdim  /// Read the source location entry with index ID.
2045276479Sdim  bool ReadSLocEntry(int ID) override;
2046212795Sdim
2047341825Sdim  /// Retrieve the module import location and module name for the
2048249423Sdim  /// given source manager entry ID.
2049276479Sdim  std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID) override;
2050249423Sdim
2051341825Sdim  /// Retrieve the global submodule ID given a module and its local ID
2052234353Sdim  /// number.
2053341825Sdim  serialization::SubmoduleID
2054234353Sdim  getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID);
2055314564Sdim
2056341825Sdim  /// Retrieve the submodule that corresponds to a global submodule ID.
2057234353Sdim  ///
2058234353Sdim  Module *getSubmodule(serialization::SubmoduleID GlobalID);
2059249423Sdim
2060341825Sdim  /// Retrieve the module that corresponds to the given module ID.
2061249423Sdim  ///
2062249423Sdim  /// Note: overrides method in ExternalASTSource
2063276479Sdim  Module *getModule(unsigned ID) override;
2064249423Sdim
2065341825Sdim  bool DeclIsFromPCHWithObjectFile(const Decl *D) override;
2066341825Sdim
2067341825Sdim  /// Retrieve the module file with a given local ID within the specified
2068296417Sdim  /// ModuleFile.
2069296417Sdim  ModuleFile *getLocalModuleFile(ModuleFile &M, unsigned ID);
2070296417Sdim
2071341825Sdim  /// Get an ID for the given module file.
2072296417Sdim  unsigned getModuleFileID(ModuleFile *M);
2073296417Sdim
2074341825Sdim  /// Return a descriptor for the corresponding module.
2075288943Sdim  llvm::Optional<ASTSourceDescriptor> getSourceDescriptor(unsigned ID) override;
2076288943Sdim
2077321369Sdim  ExtKind hasExternalDefinitions(const Decl *D) override;
2078321369Sdim
2079341825Sdim  /// Retrieve a selector from the given module with its local ID
2080226633Sdim  /// number.
2081234353Sdim  Selector getLocalSelector(ModuleFile &M, unsigned LocalID);
2082212795Sdim
2083226633Sdim  Selector DecodeSelector(serialization::SelectorID Idx);
2084226633Sdim
2085276479Sdim  Selector GetExternalSelector(serialization::SelectorID ID) override;
2086276479Sdim  uint32_t GetNumExternalSelectors() override;
2087212795Sdim
2088234353Sdim  Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) {
2089226633Sdim    return getLocalSelector(M, Record[Idx++]);
2090212795Sdim  }
2091234353Sdim
2092341825Sdim  /// Retrieve the global selector ID that corresponds to this
2093226633Sdim  /// the local selector ID in a given module.
2094234353Sdim  serialization::SelectorID getGlobalSelectorID(ModuleFile &F,
2095226633Sdim                                                unsigned LocalID) const;
2096212795Sdim
2097341825Sdim  /// Read the contents of a CXXCtorInitializer array.
2098288943Sdim  CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override;
2099288943Sdim
2100341825Sdim  /// Read a source location from raw form and return it in its
2101309124Sdim  /// originating module file's source location space.
2102309124Sdim  SourceLocation ReadUntranslatedSourceLocation(uint32_t Raw) const {
2103309124Sdim    return SourceLocation::getFromRawEncoding((Raw >> 1) | (Raw << 31));
2104309124Sdim  }
2105309124Sdim
2106341825Sdim  /// Read a source location from raw form.
2107309124Sdim  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, uint32_t Raw) const {
2108309124Sdim    SourceLocation Loc = ReadUntranslatedSourceLocation(Raw);
2109309124Sdim    return TranslateSourceLocation(ModuleFile, Loc);
2110309124Sdim  }
2111309124Sdim
2112341825Sdim  /// Translate a source location from another module file's source
2113309124Sdim  /// location space into ours.
2114309124Sdim  SourceLocation TranslateSourceLocation(ModuleFile &ModuleFile,
2115309124Sdim                                         SourceLocation Loc) const {
2116321369Sdim    if (!ModuleFile.ModuleOffsetMap.empty())
2117321369Sdim      ReadModuleOffsetMap(ModuleFile);
2118309124Sdim    assert(ModuleFile.SLocRemap.find(Loc.getOffset()) !=
2119309124Sdim               ModuleFile.SLocRemap.end() &&
2120226633Sdim           "Cannot find offset to remap.");
2121234353Sdim    int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second;
2122226633Sdim    return Loc.getLocWithOffset(Remap);
2123218893Sdim  }
2124218893Sdim
2125341825Sdim  /// Read a source location.
2126234353Sdim  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
2127261991Sdim                                    const RecordDataImpl &Record,
2128261991Sdim                                    unsigned &Idx) {
2129234353Sdim    return ReadSourceLocation(ModuleFile, Record[Idx++]);
2130212795Sdim  }
2131212795Sdim
2132341825Sdim  /// Read a source range.
2133234353Sdim  SourceRange ReadSourceRange(ModuleFile &F,
2134249423Sdim                              const RecordData &Record, unsigned &Idx);
2135212795Sdim
2136341825Sdim  // Read a string
2137243830Sdim  static std::string ReadString(const RecordData &Record, unsigned &Idx);
2138212795Sdim
2139341825Sdim  // Skip a string
2140327952Sdim  static void SkipString(const RecordData &Record, unsigned &Idx) {
2141327952Sdim    Idx += Record[Idx] + 1;
2142327952Sdim  }
2143327952Sdim
2144341825Sdim  // Read a path
2145280031Sdim  std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx);
2146280031Sdim
2147353358Sdim  // Read a path
2148353358Sdim  std::string ReadPath(StringRef BaseDirectory, const RecordData &Record,
2149353358Sdim                       unsigned &Idx);
2150353358Sdim
2151341825Sdim  // Skip a path
2152327952Sdim  static void SkipPath(const RecordData &Record, unsigned &Idx) {
2153327952Sdim    SkipString(Record, Idx);
2154327952Sdim  }
2155327952Sdim
2156341825Sdim  /// Read a version tuple.
2157243830Sdim  static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx);
2158221345Sdim
2159234353Sdim  CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record,
2160226633Sdim                                 unsigned &Idx);
2161234353Sdim
2162341825Sdim  /// Reads a statement.
2163234353Sdim  Stmt *ReadStmt(ModuleFile &F);
2164212795Sdim
2165341825Sdim  /// Reads an expression.
2166234353Sdim  Expr *ReadExpr(ModuleFile &F);
2167212795Sdim
2168341825Sdim  /// Reads a sub-statement operand during statement reading.
2169212795Sdim  Stmt *ReadSubStmt() {
2170212795Sdim    assert(ReadingKind == Read_Stmt &&
2171212795Sdim           "Should be called only during statement reading!");
2172212795Sdim    // Subexpressions are stored from last to first, so the next Stmt we need
2173212795Sdim    // is at the back of the stack.
2174276479Sdim    assert(!StmtStack.empty() && "Read too many sub-statements!");
2175212795Sdim    return StmtStack.pop_back_val();
2176212795Sdim  }
2177212795Sdim
2178341825Sdim  /// Reads a sub-expression operand during statement reading.
2179212795Sdim  Expr *ReadSubExpr();
2180212795Sdim
2181341825Sdim  /// Reads a token out of a record.
2182261991Sdim  Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx);
2183251662Sdim
2184341825Sdim  /// Reads the macro record located at the given offset.
2185249423Sdim  MacroInfo *ReadMacroRecord(ModuleFile &F, uint64_t Offset);
2186234353Sdim
2187341825Sdim  /// Determine the global preprocessed entity ID that corresponds to
2188226633Sdim  /// the given local ID within the given module.
2189234353Sdim  serialization::PreprocessedEntityID
2190234353Sdim  getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const;
2191234353Sdim
2192341825Sdim  /// Add a macro to deserialize its macro directive history.
2193234353Sdim  ///
2194234353Sdim  /// \param II The name of the macro.
2195249423Sdim  /// \param M The module file.
2196249423Sdim  /// \param MacroDirectivesOffset Offset of the serialized macro directive
2197249423Sdim  /// history.
2198288943Sdim  void addPendingMacro(IdentifierInfo *II, ModuleFile *M,
2199288943Sdim                       uint64_t MacroDirectivesOffset);
2200234353Sdim
2201341825Sdim  /// Read the set of macros defined by this external macro source.
2202276479Sdim  void ReadDefinedMacros() override;
2203212795Sdim
2204341825Sdim  /// Update an out-of-date identifier.
2205276479Sdim  void updateOutOfDateIdentifier(IdentifierInfo &II) override;
2206234353Sdim
2207341825Sdim  /// Note that this identifier is up-to-date.
2208234353Sdim  void markIdentifierUpToDate(IdentifierInfo *II);
2209234353Sdim
2210341825Sdim  /// Load all external visible decls in the given DeclContext.
2211276479Sdim  void completeVisibleDeclsMap(const DeclContext *DC) override;
2212234353Sdim
2213341825Sdim  /// Retrieve the AST context that this AST reader supplements.
2214321369Sdim  ASTContext &getContext() {
2215321369Sdim    assert(ContextObj && "requested AST context when not loading AST");
2216321369Sdim    return *ContextObj;
2217321369Sdim  }
2218212795Sdim
2219341825Sdim  // Contains the IDs for declarations that were requested before we have
2220212795Sdim  // access to a Sema object.
2221280031Sdim  SmallVector<uint64_t, 16> PreloadedDeclIDs;
2222212795Sdim
2223341825Sdim  /// Retrieve the semantic analysis object used to analyze the
2224212795Sdim  /// translation unit in which the precompiled header is being
2225212795Sdim  /// imported.
2226212795Sdim  Sema *getSema() { return SemaObj; }
2227212795Sdim
2228341825Sdim  /// Get the identifier resolver used for name lookup / updates
2229309124Sdim  /// in the translation unit scope. We have one of these even if we don't
2230309124Sdim  /// have a Sema object.
2231309124Sdim  IdentifierResolver &getIdResolver();
2232309124Sdim
2233341825Sdim  /// Retrieve the identifier table associated with the
2234212795Sdim  /// preprocessor.
2235212795Sdim  IdentifierTable &getIdentifierTable();
2236212795Sdim
2237341825Sdim  /// Record that the given ID maps to the given switch-case
2238212795Sdim  /// statement.
2239212795Sdim  void RecordSwitchCaseID(SwitchCase *SC, unsigned ID);
2240212795Sdim
2241341825Sdim  /// Retrieve the switch-case statement with the given ID.
2242212795Sdim  SwitchCase *getSwitchCaseWithID(unsigned ID);
2243212795Sdim
2244218893Sdim  void ClearSwitchCaseIDs();
2245239462Sdim
2246341825Sdim  /// Cursors for comments blocks.
2247239462Sdim  SmallVector<std::pair<llvm::BitstreamCursor,
2248239462Sdim                        serialization::ModuleFile *>, 8> CommentsCursors;
2249239462Sdim
2250341825Sdim  /// Loads comments ranges.
2251276479Sdim  void ReadComments() override;
2252309124Sdim
2253321369Sdim  /// Visit all the input files of the given module file.
2254321369Sdim  void visitInputFiles(serialization::ModuleFile &MF,
2255321369Sdim                       bool IncludeSystem, bool Complain,
2256321369Sdim          llvm::function_ref<void(const serialization::InputFile &IF,
2257321369Sdim                                  bool isSystem)> Visitor);
2258321369Sdim
2259321369Sdim  /// Visit all the top-level module maps loaded when building the given module
2260321369Sdim  /// file.
2261321369Sdim  void visitTopLevelModuleMaps(serialization::ModuleFile &MF,
2262321369Sdim                               llvm::function_ref<
2263321369Sdim                                   void(const FileEntry *)> Visitor);
2264321369Sdim
2265309124Sdim  bool isProcessingUpdateRecords() { return ProcessingUpdateRecords; }
2266212795Sdim};
2267212795Sdim
2268327952Sdim} // namespace clang
2269212795Sdim
2270327952Sdim#endif // LLVM_CLANG_SERIALIZATION_ASTREADER_H
2271