ASTReader.h revision 309124
1212795Sdim//===--- ASTReader.h - AST File Reader --------------------------*- C++ -*-===//
2212795Sdim//
3212795Sdim//                     The LLVM Compiler Infrastructure
4212795Sdim//
5212795Sdim// This file is distributed under the University of Illinois Open Source
6212795Sdim// License. See LICENSE.TXT for details.
7212795Sdim//
8212795Sdim//===----------------------------------------------------------------------===//
9212795Sdim//
10212795Sdim//  This file defines the ASTReader class, which reads AST files.
11212795Sdim//
12212795Sdim//===----------------------------------------------------------------------===//
13212795Sdim
14280031Sdim#ifndef LLVM_CLANG_SERIALIZATION_ASTREADER_H
15280031Sdim#define LLVM_CLANG_SERIALIZATION_ASTREADER_H
16212795Sdim
17249423Sdim#include "clang/AST/DeclObjC.h"
18212795Sdim#include "clang/AST/DeclarationName.h"
19212795Sdim#include "clang/AST/TemplateBase.h"
20212795Sdim#include "clang/Basic/Diagnostic.h"
21226633Sdim#include "clang/Basic/FileManager.h"
22226633Sdim#include "clang/Basic/FileSystemOptions.h"
23212795Sdim#include "clang/Basic/IdentifierTable.h"
24212795Sdim#include "clang/Basic/SourceManager.h"
25249423Sdim#include "clang/Basic/Version.h"
26249423Sdim#include "clang/Lex/ExternalPreprocessorSource.h"
27249423Sdim#include "clang/Lex/HeaderSearch.h"
28249423Sdim#include "clang/Lex/PreprocessingRecord.h"
29249423Sdim#include "clang/Sema/ExternalSemaSource.h"
30309124Sdim#include "clang/Sema/IdentifierResolver.h"
31249423Sdim#include "clang/Serialization/ASTBitCodes.h"
32249423Sdim#include "clang/Serialization/ContinuousRangeMap.h"
33249423Sdim#include "clang/Serialization/Module.h"
34296417Sdim#include "clang/Serialization/ModuleFileExtension.h"
35249423Sdim#include "clang/Serialization/ModuleManager.h"
36212795Sdim#include "llvm/ADT/APFloat.h"
37212795Sdim#include "llvm/ADT/APInt.h"
38212795Sdim#include "llvm/ADT/APSInt.h"
39243830Sdim#include "llvm/ADT/MapVector.h"
40234353Sdim#include "llvm/ADT/SmallPtrSet.h"
41234353Sdim#include "llvm/ADT/SmallSet.h"
42212795Sdim#include "llvm/ADT/SmallVector.h"
43296417Sdim#include "llvm/ADT/StringMap.h"
44212795Sdim#include "llvm/ADT/StringRef.h"
45276479Sdim#include "llvm/ADT/TinyPtrVector.h"
46212795Sdim#include "llvm/Bitcode/BitstreamReader.h"
47218893Sdim#include "llvm/Support/DataTypes.h"
48288943Sdim#include "llvm/Support/Timer.h"
49212795Sdim#include <deque>
50212795Sdim#include <map>
51276479Sdim#include <memory>
52212795Sdim#include <string>
53212795Sdim#include <utility>
54212795Sdim#include <vector>
55212795Sdim
56212795Sdimnamespace llvm {
57212795Sdim  class MemoryBuffer;
58212795Sdim}
59212795Sdim
60212795Sdimnamespace clang {
61212795Sdim
62212795Sdimclass AddrLabelExpr;
63212795Sdimclass ASTConsumer;
64212795Sdimclass ASTContext;
65218893Sdimclass ASTIdentifierIterator;
66226633Sdimclass ASTUnit; // FIXME: Layering violation and egregious hack.
67212795Sdimclass Attr;
68212795Sdimclass Decl;
69212795Sdimclass DeclContext;
70276479Sdimclass DefMacroDirective;
71243830Sdimclass DiagnosticOptions;
72212795Sdimclass NestedNameSpecifier;
73212795Sdimclass CXXBaseSpecifier;
74223017Sdimclass CXXConstructorDecl;
75218893Sdimclass CXXCtorInitializer;
76249423Sdimclass GlobalModuleIndex;
77212795Sdimclass GotoStmt;
78212795Sdimclass MacroDefinition;
79249423Sdimclass MacroDirective;
80288943Sdimclass ModuleMacro;
81212795Sdimclass NamedDecl;
82218893Sdimclass OpaqueValueExpr;
83212795Sdimclass Preprocessor;
84243830Sdimclass PreprocessorOptions;
85212795Sdimclass Sema;
86212795Sdimclass SwitchCase;
87218893Sdimclass ASTDeserializationListener;
88226633Sdimclass ASTWriter;
89212795Sdimclass ASTReader;
90212795Sdimclass ASTDeclReader;
91218893Sdimclass ASTStmtReader;
92218893Sdimclass TypeLocReader;
93212795Sdimstruct HeaderFileInfo;
94221345Sdimclass VersionTuple;
95243830Sdimclass TargetOptions;
96261991Sdimclass LazyASTUnresolvedSet;
97212795Sdim
98212795Sdim/// \brief Abstract interface for callback invocations by the ASTReader.
99212795Sdim///
100212795Sdim/// While reading an AST file, the ASTReader will call the methods of the
101212795Sdim/// listener to pass on specific information. Some of the listener methods can
102212795Sdim/// return true to indicate to the ASTReader that the information (and
103212795Sdim/// consequently the AST file) is invalid.
104212795Sdimclass ASTReaderListener {
105212795Sdimpublic:
106212795Sdim  virtual ~ASTReaderListener();
107212795Sdim
108249423Sdim  /// \brief Receives the full Clang version information.
109249423Sdim  ///
110249423Sdim  /// \returns true to indicate that the version is invalid. Subclasses should
111249423Sdim  /// generally defer to this implementation.
112249423Sdim  virtual bool ReadFullVersionInformation(StringRef FullVersion) {
113249423Sdim    return FullVersion != getClangFullRepositoryVersion();
114249423Sdim  }
115249423Sdim
116276479Sdim  virtual void ReadModuleName(StringRef ModuleName) {}
117276479Sdim  virtual void ReadModuleMapFile(StringRef ModuleMapPath) {}
118276479Sdim
119212795Sdim  /// \brief Receives the language options.
120212795Sdim  ///
121212795Sdim  /// \returns true to indicate the options are invalid or false otherwise.
122243830Sdim  virtual bool ReadLanguageOptions(const LangOptions &LangOpts,
123280031Sdim                                   bool Complain,
124280031Sdim                                   bool AllowCompatibleDifferences) {
125212795Sdim    return false;
126212795Sdim  }
127212795Sdim
128243830Sdim  /// \brief Receives the target options.
129212795Sdim  ///
130243830Sdim  /// \returns true to indicate the target options are invalid, or false
131243830Sdim  /// otherwise.
132288943Sdim  virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
133288943Sdim                                 bool AllowCompatibleDifferences) {
134212795Sdim    return false;
135212795Sdim  }
136212795Sdim
137243830Sdim  /// \brief Receives the diagnostic options.
138212795Sdim  ///
139243830Sdim  /// \returns true to indicate the diagnostic options are invalid, or false
140243830Sdim  /// otherwise.
141276479Sdim  virtual bool
142276479Sdim  ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
143276479Sdim                        bool Complain) {
144243830Sdim    return false;
145243830Sdim  }
146243830Sdim
147243830Sdim  /// \brief Receives the file system options.
148212795Sdim  ///
149243830Sdim  /// \returns true to indicate the file system options are invalid, or false
150243830Sdim  /// otherwise.
151243830Sdim  virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
152243830Sdim                                     bool Complain) {
153243830Sdim    return false;
154243830Sdim  }
155243830Sdim
156243830Sdim  /// \brief Receives the header search options.
157212795Sdim  ///
158243830Sdim  /// \returns true to indicate the header search options are invalid, or false
159243830Sdim  /// otherwise.
160243830Sdim  virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
161288943Sdim                                       StringRef SpecificModuleCachePath,
162243830Sdim                                       bool Complain) {
163243830Sdim    return false;
164243830Sdim  }
165243830Sdim
166243830Sdim  /// \brief Receives the preprocessor options.
167212795Sdim  ///
168243830Sdim  /// \param SuggestedPredefines Can be filled in with the set of predefines
169243830Sdim  /// that are suggested by the preprocessor options. Typically only used when
170243830Sdim  /// loading a precompiled header.
171243830Sdim  ///
172243830Sdim  /// \returns true to indicate the preprocessor options are invalid, or false
173243830Sdim  /// otherwise.
174243830Sdim  virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
175243830Sdim                                       bool Complain,
176243830Sdim                                       std::string &SuggestedPredefines) {
177212795Sdim    return false;
178212795Sdim  }
179212795Sdim
180212795Sdim  /// \brief Receives __COUNTER__ value.
181243830Sdim  virtual void ReadCounter(const serialization::ModuleFile &M,
182243830Sdim                           unsigned Value) {}
183251662Sdim
184276479Sdim  /// This is called for each AST file loaded.
185296417Sdim  virtual void visitModuleFile(StringRef Filename,
186296417Sdim                               serialization::ModuleKind Kind) {}
187276479Sdim
188251662Sdim  /// \brief Returns true if this \c ASTReaderListener wants to receive the
189251662Sdim  /// input files of the AST file via \c visitInputFile, false otherwise.
190251662Sdim  virtual bool needsInputFileVisitation() { return false; }
191276479Sdim  /// \brief Returns true if this \c ASTReaderListener wants to receive the
192276479Sdim  /// system input files of the AST file via \c visitInputFile, false otherwise.
193276479Sdim  virtual bool needsSystemInputFileVisitation() { return false; }
194276479Sdim  /// \brief if \c needsInputFileVisitation returns true, this is called for
195276479Sdim  /// each non-system input file of the AST File. If
196276479Sdim  /// \c needsSystemInputFileVisitation is true, then it is called for all
197276479Sdim  /// system input files as well.
198251662Sdim  ///
199251662Sdim  /// \returns true to continue receiving the next input file, false to stop.
200276479Sdim  virtual bool visitInputFile(StringRef Filename, bool isSystem,
201296417Sdim                              bool isOverridden, bool isExplicitModule) {
202276479Sdim    return true;
203276479Sdim  }
204280031Sdim
205280031Sdim  /// \brief Returns true if this \c ASTReaderListener wants to receive the
206280031Sdim  /// imports of the AST file via \c visitImport, false otherwise.
207280031Sdim  virtual bool needsImportVisitation() const { return false; }
208280031Sdim  /// \brief If needsImportVisitation returns \c true, this is called for each
209280031Sdim  /// AST file imported by this AST file.
210280031Sdim  virtual void visitImport(StringRef Filename) {}
211296417Sdim
212296417Sdim  /// Indicates that a particular module file extension has been read.
213296417Sdim  virtual void readModuleFileExtension(
214296417Sdim                 const ModuleFileExtensionMetadata &Metadata) {}
215212795Sdim};
216212795Sdim
217276479Sdim/// \brief Simple wrapper class for chaining listeners.
218276479Sdimclass ChainedASTReaderListener : public ASTReaderListener {
219276479Sdim  std::unique_ptr<ASTReaderListener> First;
220276479Sdim  std::unique_ptr<ASTReaderListener> Second;
221276479Sdim
222276479Sdimpublic:
223276479Sdim  /// Takes ownership of \p First and \p Second.
224280031Sdim  ChainedASTReaderListener(std::unique_ptr<ASTReaderListener> First,
225280031Sdim                           std::unique_ptr<ASTReaderListener> Second)
226280031Sdim      : First(std::move(First)), Second(std::move(Second)) {}
227276479Sdim
228280031Sdim  std::unique_ptr<ASTReaderListener> takeFirst() { return std::move(First); }
229280031Sdim  std::unique_ptr<ASTReaderListener> takeSecond() { return std::move(Second); }
230280031Sdim
231276479Sdim  bool ReadFullVersionInformation(StringRef FullVersion) override;
232276479Sdim  void ReadModuleName(StringRef ModuleName) override;
233276479Sdim  void ReadModuleMapFile(StringRef ModuleMapPath) override;
234280031Sdim  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
235280031Sdim                           bool AllowCompatibleDifferences) override;
236288943Sdim  bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
237288943Sdim                         bool AllowCompatibleDifferences) override;
238276479Sdim  bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
239276479Sdim                             bool Complain) override;
240276479Sdim  bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
241276479Sdim                             bool Complain) override;
242276479Sdim
243276479Sdim  bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
244288943Sdim                               StringRef SpecificModuleCachePath,
245276479Sdim                               bool Complain) override;
246276479Sdim  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
247276479Sdim                               bool Complain,
248276479Sdim                               std::string &SuggestedPredefines) override;
249276479Sdim
250276479Sdim  void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
251276479Sdim  bool needsInputFileVisitation() override;
252276479Sdim  bool needsSystemInputFileVisitation() override;
253296417Sdim  void visitModuleFile(StringRef Filename,
254296417Sdim                       serialization::ModuleKind Kind) override;
255276479Sdim  bool visitInputFile(StringRef Filename, bool isSystem,
256296417Sdim                      bool isOverridden, bool isExplicitModule) override;
257296417Sdim  void readModuleFileExtension(
258296417Sdim         const ModuleFileExtensionMetadata &Metadata) override;
259276479Sdim};
260276479Sdim
261212795Sdim/// \brief ASTReaderListener implementation to validate the information of
262212795Sdim/// the PCH file against an initialized Preprocessor.
263212795Sdimclass PCHValidator : public ASTReaderListener {
264212795Sdim  Preprocessor &PP;
265212795Sdim  ASTReader &Reader;
266212795Sdim
267212795Sdimpublic:
268212795Sdim  PCHValidator(Preprocessor &PP, ASTReader &Reader)
269261991Sdim    : PP(PP), Reader(Reader) {}
270212795Sdim
271280031Sdim  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
272280031Sdim                           bool AllowCompatibleDifferences) override;
273288943Sdim  bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
274288943Sdim                         bool AllowCompatibleDifferences) override;
275276479Sdim  bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
276276479Sdim                             bool Complain) override;
277276479Sdim  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain,
278276479Sdim                               std::string &SuggestedPredefines) override;
279288943Sdim  bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
280288943Sdim                               StringRef SpecificModuleCachePath,
281288943Sdim                               bool Complain) override;
282276479Sdim  void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
283212795Sdim
284212795Sdimprivate:
285212795Sdim  void Error(const char *Msg);
286212795Sdim};
287212795Sdim
288234353Sdimnamespace serialization {
289226633Sdim
290226633Sdimclass ReadMethodPoolVisitor;
291234353Sdim
292226633Sdimnamespace reader {
293226633Sdim  class ASTIdentifierLookupTrait;
294296417Sdim  /// \brief The on-disk hash table(s) used for DeclContext name lookup.
295296417Sdim  struct DeclContextLookupTable;
296226633Sdim}
297234353Sdim
298226633Sdim} // end namespace serialization
299234353Sdim
300212795Sdim/// \brief Reads an AST files chain containing the contents of a translation
301212795Sdim/// unit.
302212795Sdim///
303212795Sdim/// The ASTReader class reads bitstreams (produced by the ASTWriter
304212795Sdim/// class) containing the serialized representation of a given
305212795Sdim/// abstract syntax tree and its supporting data structures. An
306212795Sdim/// instance of the ASTReader can be attached to an ASTContext object,
307212795Sdim/// which will provide access to the contents of the AST files.
308212795Sdim///
309212795Sdim/// The AST reader provides lazy de-serialization of declarations, as
310212795Sdim/// required when traversing the AST. Only those AST nodes that are
311212795Sdim/// actually required will be de-serialized.
312212795Sdimclass ASTReader
313212795Sdim  : public ExternalPreprocessorSource,
314212795Sdim    public ExternalPreprocessingRecordSource,
315218893Sdim    public ExternalHeaderFileInfoSource,
316212795Sdim    public ExternalSemaSource,
317212795Sdim    public IdentifierInfoLookup,
318234353Sdim    public ExternalSLocEntrySource
319218893Sdim{
320212795Sdimpublic:
321239462Sdim  typedef SmallVector<uint64_t, 64> RecordData;
322261991Sdim  typedef SmallVectorImpl<uint64_t> RecordDataImpl;
323239462Sdim
324243830Sdim  /// \brief The result of reading the control block of an AST file, which
325243830Sdim  /// can fail for various reasons.
326243830Sdim  enum ASTReadResult {
327243830Sdim    /// \brief The control block was read successfully. Aside from failures,
328243830Sdim    /// the AST file is safe to read into the current context.
329243830Sdim    Success,
330243830Sdim    /// \brief The AST file itself appears corrupted.
331243830Sdim    Failure,
332249423Sdim    /// \brief The AST file was missing.
333249423Sdim    Missing,
334243830Sdim    /// \brief The AST file is out-of-date relative to its input files,
335243830Sdim    /// and needs to be regenerated.
336243830Sdim    OutOfDate,
337243830Sdim    /// \brief The AST file was written by a different version of Clang.
338243830Sdim    VersionMismatch,
339243830Sdim    /// \brief The AST file was writtten with a different language/target
340243830Sdim    /// configuration.
341243830Sdim    ConfigurationMismatch,
342243830Sdim    /// \brief The AST file has errors.
343243830Sdim    HadErrors
344243830Sdim  };
345243830Sdim
346218893Sdim  /// \brief Types of AST files.
347212795Sdim  friend class PCHValidator;
348212795Sdim  friend class ASTDeclReader;
349218893Sdim  friend class ASTStmtReader;
350218893Sdim  friend class ASTIdentifierIterator;
351226633Sdim  friend class serialization::reader::ASTIdentifierLookupTrait;
352218893Sdim  friend class TypeLocReader;
353226633Sdim  friend class ASTWriter;
354226633Sdim  friend class ASTUnit; // ASTUnit needs to remap source locations.
355226633Sdim  friend class serialization::ReadMethodPoolVisitor;
356234353Sdim
357234353Sdim  typedef serialization::ModuleFile ModuleFile;
358226633Sdim  typedef serialization::ModuleKind ModuleKind;
359226633Sdim  typedef serialization::ModuleManager ModuleManager;
360234353Sdim
361226633Sdim  typedef ModuleManager::ModuleIterator ModuleIterator;
362226633Sdim  typedef ModuleManager::ModuleConstIterator ModuleConstIterator;
363226633Sdim  typedef ModuleManager::ModuleReverseIterator ModuleReverseIterator;
364226633Sdim
365212795Sdimprivate:
366212795Sdim  /// \brief The receiver of some callbacks invoked by ASTReader.
367276479Sdim  std::unique_ptr<ASTReaderListener> Listener;
368212795Sdim
369212795Sdim  /// \brief The receiver of deserialization events.
370212795Sdim  ASTDeserializationListener *DeserializationListener;
371276479Sdim  bool OwnsDeserializationListener;
372212795Sdim
373212795Sdim  SourceManager &SourceMgr;
374212795Sdim  FileManager &FileMgr;
375288943Sdim  const PCHContainerReader &PCHContainerRdr;
376226633Sdim  DiagnosticsEngine &Diags;
377234353Sdim
378212795Sdim  /// \brief The semantic analysis object that will be processing the
379212795Sdim  /// AST files and the translation unit that uses it.
380212795Sdim  Sema *SemaObj;
381212795Sdim
382212795Sdim  /// \brief The preprocessor that will be loading the source file.
383226633Sdim  Preprocessor &PP;
384212795Sdim
385212795Sdim  /// \brief The AST context into which we'll read the AST files.
386226633Sdim  ASTContext &Context;
387234353Sdim
388212795Sdim  /// \brief The AST consumer.
389212795Sdim  ASTConsumer *Consumer;
390212795Sdim
391226633Sdim  /// \brief The module manager which manages modules and their dependencies
392226633Sdim  ModuleManager ModuleMgr;
393221345Sdim
394309124Sdim  /// \brief A dummy identifier resolver used to merge TU-scope declarations in
395309124Sdim  /// C, for the cases where we don't have a Sema object to provide a real
396309124Sdim  /// identifier resolver.
397309124Sdim  IdentifierResolver DummyIdResolver;
398309124Sdim
399296417Sdim  /// A mapping from extension block names to module file extensions.
400296417Sdim  llvm::StringMap<IntrusiveRefCntPtr<ModuleFileExtension>> ModuleFileExtensions;
401296417Sdim
402288943Sdim  /// \brief A timer used to track the time spent deserializing.
403288943Sdim  std::unique_ptr<llvm::Timer> ReadTimer;
404288943Sdim
405261991Sdim  /// \brief The location where the module file will be considered as
406261991Sdim  /// imported from. For non-module AST types it should be invalid.
407261991Sdim  SourceLocation CurrentImportLoc;
408261991Sdim
409249423Sdim  /// \brief The global module index, if loaded.
410276479Sdim  std::unique_ptr<GlobalModuleIndex> GlobalIndex;
411249423Sdim
412226633Sdim  /// \brief A map of global bit offsets to the module that stores entities
413226633Sdim  /// at those bit offsets.
414234353Sdim  ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap;
415212795Sdim
416226633Sdim  /// \brief A map of negated SLocEntryIDs to the modules containing them.
417234353Sdim  ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap;
418212795Sdim
419234353Sdim  typedef ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocOffsetMapType;
420234353Sdim
421226633Sdim  /// \brief A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset)
422226633Sdim  /// SourceLocation offsets to the modules containing them.
423226633Sdim  GlobalSLocOffsetMapType GlobalSLocOffsetMap;
424234353Sdim
425212795Sdim  /// \brief Types that have already been loaded from the chain.
426212795Sdim  ///
427212795Sdim  /// When the pointer at index I is non-NULL, the type with
428212795Sdim  /// ID = (I + 1) << FastQual::Width has already been loaded
429212795Sdim  std::vector<QualType> TypesLoaded;
430212795Sdim
431234353Sdim  typedef ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4>
432226633Sdim    GlobalTypeMapType;
433212795Sdim
434226633Sdim  /// \brief Mapping from global type IDs to the module in which the
435226633Sdim  /// type resides along with the offset that should be added to the
436226633Sdim  /// global type ID to produce a local ID.
437226633Sdim  GlobalTypeMapType GlobalTypeMap;
438226633Sdim
439212795Sdim  /// \brief Declarations that have already been loaded from the chain.
440212795Sdim  ///
441212795Sdim  /// When the pointer at index I is non-NULL, the declaration with ID
442212795Sdim  /// = I + 1 has already been loaded.
443212795Sdim  std::vector<Decl *> DeclsLoaded;
444212795Sdim
445234353Sdim  typedef ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4>
446226633Sdim    GlobalDeclMapType;
447234353Sdim
448226633Sdim  /// \brief Mapping from global declaration IDs to the module in which the
449226633Sdim  /// declaration resides.
450226633Sdim  GlobalDeclMapType GlobalDeclMap;
451234353Sdim
452234353Sdim  typedef std::pair<ModuleFile *, uint64_t> FileOffset;
453226633Sdim  typedef SmallVector<FileOffset, 2> FileOffsetsTy;
454218893Sdim  typedef llvm::DenseMap<serialization::DeclID, FileOffsetsTy>
455218893Sdim      DeclUpdateOffsetsMap;
456234353Sdim
457218893Sdim  /// \brief Declarations that have modifications residing in a later file
458218893Sdim  /// in the chain.
459218893Sdim  DeclUpdateOffsetsMap DeclUpdateOffsets;
460218893Sdim
461276479Sdim  /// \brief Declaration updates for already-loaded declarations that we need
462276479Sdim  /// to apply once we finish processing an import.
463276479Sdim  llvm::SmallVector<std::pair<serialization::GlobalDeclID, Decl*>, 16>
464276479Sdim      PendingUpdateRecords;
465276479Sdim
466288943Sdim  enum class PendingFakeDefinitionKind { NotFake, Fake, FakeLoaded };
467288943Sdim
468288943Sdim  /// \brief The DefinitionData pointers that we faked up for class definitions
469288943Sdim  /// that we needed but hadn't loaded yet.
470288943Sdim  llvm::DenseMap<void *, PendingFakeDefinitionKind> PendingFakeDefinitionData;
471288943Sdim
472288943Sdim  /// \brief Exception specification updates that have been loaded but not yet
473288943Sdim  /// propagated across the relevant redeclaration chain. The map key is the
474288943Sdim  /// canonical declaration (used only for deduplication) and the value is a
475288943Sdim  /// declaration that has an exception specification.
476288943Sdim  llvm::SmallMapVector<Decl *, FunctionDecl *, 4> PendingExceptionSpecUpdates;
477288943Sdim
478280031Sdim  /// \brief Declarations that have been imported and have typedef names for
479280031Sdim  /// linkage purposes.
480280031Sdim  llvm::DenseMap<std::pair<DeclContext*, IdentifierInfo*>, NamedDecl*>
481280031Sdim      ImportedTypedefNamesForLinkage;
482280031Sdim
483280031Sdim  /// \brief Mergeable declaration contexts that have anonymous declarations
484280031Sdim  /// within them, and those anonymous declarations.
485280031Sdim  llvm::DenseMap<DeclContext*, llvm::SmallVector<NamedDecl*, 2>>
486280031Sdim    AnonymousDeclarationsForMerging;
487280031Sdim
488234353Sdim  struct FileDeclsInfo {
489234353Sdim    ModuleFile *Mod;
490234353Sdim    ArrayRef<serialization::LocalDeclID> Decls;
491234353Sdim
492276479Sdim    FileDeclsInfo() : Mod(nullptr) {}
493234353Sdim    FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls)
494234353Sdim      : Mod(Mod), Decls(Decls) {}
495234353Sdim  };
496234353Sdim
497234353Sdim  /// \brief Map from a FileID to the file-level declarations that it contains.
498234353Sdim  llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs;
499234353Sdim
500296417Sdim  /// \brief An array of lexical contents of a declaration context, as a sequence of
501296417Sdim  /// Decl::Kind, DeclID pairs.
502296417Sdim  typedef ArrayRef<llvm::support::unaligned_uint32_t> LexicalContents;
503296417Sdim
504296417Sdim  /// \brief Map from a DeclContext to its lexical contents.
505296417Sdim  llvm::DenseMap<const DeclContext*, std::pair<ModuleFile*, LexicalContents>>
506296417Sdim      LexicalDecls;
507296417Sdim
508296417Sdim  /// \brief Map from the TU to its lexical contents from each module file.
509296417Sdim  std::vector<std::pair<ModuleFile*, LexicalContents>> TULexicalDecls;
510296417Sdim
511296417Sdim  /// \brief Map from a DeclContext to its lookup tables.
512296417Sdim  llvm::DenseMap<const DeclContext *,
513296417Sdim                 serialization::reader::DeclContextLookupTable> Lookups;
514296417Sdim
515212795Sdim  // Updates for visible decls can occur for other contexts than just the
516296417Sdim  // TU, and when we read those update records, the actual context may not
517296417Sdim  // be available yet, so have this pending map using the ID as a key. It
518296417Sdim  // will be realized when the context is actually loaded.
519296417Sdim  struct PendingVisibleUpdate {
520296417Sdim    ModuleFile *Mod;
521296417Sdim    const unsigned char *Data;
522296417Sdim  };
523296417Sdim  typedef SmallVector<PendingVisibleUpdate, 1> DeclContextVisibleUpdates;
524212795Sdim
525212795Sdim  /// \brief Updates to the visible declarations of declaration contexts that
526212795Sdim  /// haven't been loaded yet.
527296417Sdim  llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates>
528296417Sdim      PendingVisibleUpdates;
529296417Sdim
530234353Sdim  /// \brief The set of C++ or Objective-C classes that have forward
531234353Sdim  /// declarations that have not yet been linked to their definitions.
532234353Sdim  llvm::SmallPtrSet<Decl *, 4> PendingDefinitions;
533243830Sdim
534243830Sdim  typedef llvm::MapVector<Decl *, uint64_t,
535243830Sdim                          llvm::SmallDenseMap<Decl *, unsigned, 4>,
536249423Sdim                          SmallVector<std::pair<Decl *, uint64_t>, 4> >
537243830Sdim    PendingBodiesMap;
538243830Sdim
539243830Sdim  /// \brief Functions or methods that have bodies that will be attached.
540243830Sdim  PendingBodiesMap PendingBodies;
541243830Sdim
542288943Sdim  /// \brief Definitions for which we have added merged definitions but not yet
543288943Sdim  /// performed deduplication.
544288943Sdim  llvm::SetVector<NamedDecl*> PendingMergedDefinitionsToDeduplicate;
545288943Sdim
546296417Sdim  /// \brief Read the record that describes the lexical contents of a DC.
547296417Sdim  bool ReadLexicalDeclContextStorage(ModuleFile &M,
548296417Sdim                                     llvm::BitstreamCursor &Cursor,
549296417Sdim                                     uint64_t Offset, DeclContext *DC);
550296417Sdim  /// \brief Read the record that describes the visible contents of a DC.
551296417Sdim  bool ReadVisibleDeclContextStorage(ModuleFile &M,
552296417Sdim                                     llvm::BitstreamCursor &Cursor,
553296417Sdim                                     uint64_t Offset, serialization::DeclID ID);
554212795Sdim
555212795Sdim  /// \brief A vector containing identifiers that have already been
556212795Sdim  /// loaded.
557212795Sdim  ///
558212795Sdim  /// If the pointer at index I is non-NULL, then it refers to the
559212795Sdim  /// IdentifierInfo for the identifier with ID=I+1 that has already
560212795Sdim  /// been loaded.
561212795Sdim  std::vector<IdentifierInfo *> IdentifiersLoaded;
562212795Sdim
563234353Sdim  typedef ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4>
564226633Sdim    GlobalIdentifierMapType;
565234353Sdim
566243830Sdim  /// \brief Mapping from global identifier IDs to the module in which the
567226633Sdim  /// identifier resides along with the offset that should be added to the
568226633Sdim  /// global identifier ID to produce a local ID.
569226633Sdim  GlobalIdentifierMapType GlobalIdentifierMap;
570226633Sdim
571243830Sdim  /// \brief A vector containing macros that have already been
572243830Sdim  /// loaded.
573243830Sdim  ///
574243830Sdim  /// If the pointer at index I is non-NULL, then it refers to the
575243830Sdim  /// MacroInfo for the identifier with ID=I+1 that has already
576243830Sdim  /// been loaded.
577243830Sdim  std::vector<MacroInfo *> MacrosLoaded;
578243830Sdim
579288943Sdim  typedef std::pair<IdentifierInfo *, serialization::SubmoduleID>
580288943Sdim      LoadedMacroInfo;
581288943Sdim
582288943Sdim  /// \brief A set of #undef directives that we have loaded; used to
583288943Sdim  /// deduplicate the same #undef information coming from multiple module
584288943Sdim  /// files.
585288943Sdim  llvm::DenseSet<LoadedMacroInfo> LoadedUndefs;
586288943Sdim
587243830Sdim  typedef ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4>
588243830Sdim    GlobalMacroMapType;
589243830Sdim
590243830Sdim  /// \brief Mapping from global macro IDs to the module in which the
591243830Sdim  /// macro resides along with the offset that should be added to the
592243830Sdim  /// global macro ID to produce a local ID.
593243830Sdim  GlobalMacroMapType GlobalMacroMap;
594243830Sdim
595234353Sdim  /// \brief A vector containing submodules that have already been loaded.
596234353Sdim  ///
597234353Sdim  /// This vector is indexed by the Submodule ID (-1). NULL submodule entries
598234353Sdim  /// indicate that the particular submodule ID has not yet been loaded.
599234353Sdim  SmallVector<Module *, 2> SubmodulesLoaded;
600234353Sdim
601234353Sdim  typedef ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4>
602234353Sdim    GlobalSubmoduleMapType;
603234353Sdim
604234353Sdim  /// \brief Mapping from global submodule IDs to the module file in which the
605234353Sdim  /// submodule resides along with the offset that should be added to the
606234353Sdim  /// global submodule ID to produce a local ID.
607234353Sdim  GlobalSubmoduleMapType GlobalSubmoduleMap;
608234353Sdim
609234353Sdim  /// \brief A set of hidden declarations.
610288943Sdim  typedef SmallVector<Decl*, 2> HiddenNames;
611234353Sdim  typedef llvm::DenseMap<Module *, HiddenNames> HiddenNamesMapType;
612234353Sdim
613234353Sdim  /// \brief A mapping from each of the hidden submodules to the deserialized
614234353Sdim  /// declarations in that submodule that could be made visible.
615234353Sdim  HiddenNamesMapType HiddenNamesMap;
616234353Sdim
617234353Sdim
618249423Sdim  /// \brief A module import, export, or conflict that hasn't yet been resolved.
619249423Sdim  struct UnresolvedModuleRef {
620234353Sdim    /// \brief The file in which this module resides.
621234353Sdim    ModuleFile *File;
622234353Sdim
623234353Sdim    /// \brief The module that is importing or exporting.
624234353Sdim    Module *Mod;
625249423Sdim
626249423Sdim    /// \brief The kind of module reference.
627249423Sdim    enum { Import, Export, Conflict } Kind;
628249423Sdim
629234353Sdim    /// \brief The local ID of the module that is being exported.
630234353Sdim    unsigned ID;
631249423Sdim
632234353Sdim    /// \brief Whether this is a wildcard export.
633234353Sdim    unsigned IsWildcard : 1;
634249423Sdim
635249423Sdim    /// \brief String data.
636249423Sdim    StringRef String;
637234353Sdim  };
638234353Sdim
639234353Sdim  /// \brief The set of module imports and exports that still need to be
640234353Sdim  /// resolved.
641249423Sdim  SmallVector<UnresolvedModuleRef, 2> UnresolvedModuleRefs;
642234353Sdim
643212795Sdim  /// \brief A vector containing selectors that have already been loaded.
644212795Sdim  ///
645212795Sdim  /// This vector is indexed by the Selector ID (-1). NULL selector
646212795Sdim  /// entries indicate that the particular selector ID has not yet
647212795Sdim  /// been loaded.
648226633Sdim  SmallVector<Selector, 16> SelectorsLoaded;
649212795Sdim
650234353Sdim  typedef ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4>
651226633Sdim    GlobalSelectorMapType;
652234353Sdim
653226633Sdim  /// \brief Mapping from global selector IDs to the module in which the
654249423Sdim
655226633Sdim  /// global selector ID to produce a local ID.
656226633Sdim  GlobalSelectorMapType GlobalSelectorMap;
657212795Sdim
658234353Sdim  /// \brief The generation number of the last time we loaded data from the
659234353Sdim  /// global method pool for this selector.
660234353Sdim  llvm::DenseMap<Selector, unsigned> SelectorGeneration;
661234353Sdim
662309124Sdim  /// Whether a selector is out of date. We mark a selector as out of date
663309124Sdim  /// if we load another module after the method pool entry was pulled in.
664309124Sdim  llvm::DenseMap<Selector, bool> SelectorOutOfDate;
665309124Sdim
666249423Sdim  struct PendingMacroInfo {
667249423Sdim    ModuleFile *M;
668288943Sdim    uint64_t MacroDirectivesOffset;
669249423Sdim
670288943Sdim    PendingMacroInfo(ModuleFile *M, uint64_t MacroDirectivesOffset)
671288943Sdim        : M(M), MacroDirectivesOffset(MacroDirectivesOffset) {}
672249423Sdim  };
673249423Sdim
674249423Sdim  typedef llvm::MapVector<IdentifierInfo *, SmallVector<PendingMacroInfo, 2> >
675243830Sdim    PendingMacroIDsMap;
676226633Sdim
677243830Sdim  /// \brief Mapping from identifiers that have a macro history to the global
678243830Sdim  /// IDs have not yet been deserialized to the global IDs of those macros.
679243830Sdim  PendingMacroIDsMap PendingMacroIDs;
680243830Sdim
681234353Sdim  typedef ContinuousRangeMap<unsigned, ModuleFile *, 4>
682226633Sdim    GlobalPreprocessedEntityMapType;
683234353Sdim
684226633Sdim  /// \brief Mapping from global preprocessing entity IDs to the module in
685226633Sdim  /// which the preprocessed entity resides along with the offset that should be
686226633Sdim  /// added to the global preprocessing entitiy ID to produce a local ID.
687226633Sdim  GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
688234353Sdim
689212795Sdim  /// \name CodeGen-relevant special data
690212795Sdim  /// \brief Fields containing data that is relevant to CodeGen.
691212795Sdim  //@{
692212795Sdim
693212795Sdim  /// \brief The IDs of all declarations that fulfill the criteria of
694212795Sdim  /// "interesting" decls.
695212795Sdim  ///
696276479Sdim  /// This contains the data loaded from all EAGERLY_DESERIALIZED_DECLS blocks
697276479Sdim  /// in the chain. The referenced declarations are deserialized and passed to
698276479Sdim  /// the consumer eagerly.
699276479Sdim  SmallVector<uint64_t, 16> EagerlyDeserializedDecls;
700212795Sdim
701239462Sdim  /// \brief The IDs of all tentative definitions stored in the chain.
702212795Sdim  ///
703212795Sdim  /// Sema keeps track of all tentative definitions in a TU because it has to
704212795Sdim  /// complete them and pass them on to CodeGen. Thus, tentative definitions in
705212795Sdim  /// the PCH chain must be eagerly deserialized.
706226633Sdim  SmallVector<uint64_t, 16> TentativeDefinitions;
707212795Sdim
708212795Sdim  /// \brief The IDs of all CXXRecordDecls stored in the chain whose VTables are
709212795Sdim  /// used.
710212795Sdim  ///
711212795Sdim  /// CodeGen has to emit VTables for these records, so they have to be eagerly
712212795Sdim  /// deserialized.
713226633Sdim  SmallVector<uint64_t, 64> VTableUses;
714212795Sdim
715226633Sdim  /// \brief A snapshot of the pending instantiations in the chain.
716226633Sdim  ///
717226633Sdim  /// This record tracks the instantiations that Sema has to perform at the
718226633Sdim  /// end of the TU. It consists of a pair of values for every pending
719226633Sdim  /// instantiation where the first value is the ID of the decl and the second
720226633Sdim  /// is the instantiation location.
721226633Sdim  SmallVector<uint64_t, 64> PendingInstantiations;
722226633Sdim
723212795Sdim  //@}
724212795Sdim
725226633Sdim  /// \name DiagnosticsEngine-relevant special data
726212795Sdim  /// \brief Fields containing data that is used for generating diagnostics
727212795Sdim  //@{
728212795Sdim
729212795Sdim  /// \brief A snapshot of Sema's unused file-scoped variable tracking, for
730212795Sdim  /// generating warnings.
731226633Sdim  SmallVector<uint64_t, 16> UnusedFileScopedDecls;
732212795Sdim
733223017Sdim  /// \brief A list of all the delegating constructors we've seen, to diagnose
734223017Sdim  /// cycles.
735226633Sdim  SmallVector<uint64_t, 4> DelegatingCtorDecls;
736234353Sdim
737226633Sdim  /// \brief Method selectors used in a @selector expression. Used for
738226633Sdim  /// implementation of -Wselector.
739226633Sdim  SmallVector<uint64_t, 64> ReferencedSelectorsData;
740223017Sdim
741212795Sdim  /// \brief A snapshot of Sema's weak undeclared identifier tracking, for
742212795Sdim  /// generating warnings.
743226633Sdim  SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers;
744212795Sdim
745212795Sdim  /// \brief The IDs of type aliases for ext_vectors that exist in the chain.
746212795Sdim  ///
747212795Sdim  /// Used by Sema for finding sugared names for ext_vectors in diagnostics.
748226633Sdim  SmallVector<uint64_t, 4> ExtVectorDecls;
749212795Sdim
750212795Sdim  //@}
751212795Sdim
752212795Sdim  /// \name Sema-relevant special data
753212795Sdim  /// \brief Fields containing data that is used for semantic analysis
754212795Sdim  //@{
755212795Sdim
756280031Sdim  /// \brief The IDs of all potentially unused typedef names in the chain.
757280031Sdim  ///
758280031Sdim  /// Sema tracks these to emit warnings.
759280031Sdim  SmallVector<uint64_t, 16> UnusedLocalTypedefNameCandidates;
760280031Sdim
761212795Sdim  /// \brief The IDs of the declarations Sema stores directly.
762212795Sdim  ///
763212795Sdim  /// Sema tracks a few important decls, such as namespace std, directly.
764226633Sdim  SmallVector<uint64_t, 4> SemaDeclRefs;
765212795Sdim
766212795Sdim  /// \brief The IDs of the types ASTContext stores directly.
767212795Sdim  ///
768212795Sdim  /// The AST context tracks a few important types, such as va_list, directly.
769226633Sdim  SmallVector<uint64_t, 16> SpecialTypes;
770212795Sdim
771218893Sdim  /// \brief The IDs of CUDA-specific declarations ASTContext stores directly.
772218893Sdim  ///
773218893Sdim  /// The AST context tracks a few important decls, currently cudaConfigureCall,
774218893Sdim  /// directly.
775226633Sdim  SmallVector<uint64_t, 2> CUDASpecialDeclRefs;
776218893Sdim
777218893Sdim  /// \brief The floating point pragma option settings.
778226633Sdim  SmallVector<uint64_t, 1> FPPragmaOptions;
779218893Sdim
780276479Sdim  /// \brief The pragma clang optimize location (if the pragma state is "off").
781276479Sdim  SourceLocation OptimizeOffPragmaLocation;
782276479Sdim
783309124Sdim  /// \brief The PragmaMSStructKind pragma ms_struct state if set, or -1.
784309124Sdim  int PragmaMSStructState;
785309124Sdim
786309124Sdim  /// \brief The PragmaMSPointersToMembersKind pragma pointers_to_members state.
787309124Sdim  int PragmaMSPointersToMembersState;
788309124Sdim  SourceLocation PointersToMembersPragmaLocation;
789309124Sdim
790218893Sdim  /// \brief The OpenCL extension settings.
791226633Sdim  SmallVector<uint64_t, 1> OpenCLExtensions;
792218893Sdim
793224145Sdim  /// \brief A list of the namespaces we've seen.
794226633Sdim  SmallVector<uint64_t, 4> KnownNamespaces;
795224145Sdim
796249423Sdim  /// \brief A list of undefined decls with internal linkage followed by the
797249423Sdim  /// SourceLocation of a matching ODR-use.
798249423Sdim  SmallVector<uint64_t, 8> UndefinedButUsed;
799249423Sdim
800288943Sdim  /// \brief Delete expressions to analyze at the end of translation unit.
801288943Sdim  SmallVector<uint64_t, 8> DelayedDeleteExprs;
802288943Sdim
803261991Sdim  // \brief A list of late parsed template function data.
804261991Sdim  SmallVector<uint64_t, 1> LateParsedTemplates;
805261991Sdim
806276479Sdim  struct ImportedSubmodule {
807276479Sdim    serialization::SubmoduleID ID;
808276479Sdim    SourceLocation ImportLoc;
809276479Sdim
810276479Sdim    ImportedSubmodule(serialization::SubmoduleID ID, SourceLocation ImportLoc)
811276479Sdim      : ID(ID), ImportLoc(ImportLoc) {}
812276479Sdim  };
813276479Sdim
814234353Sdim  /// \brief A list of modules that were imported by precompiled headers or
815234353Sdim  /// any other non-module AST file.
816276479Sdim  SmallVector<ImportedSubmodule, 2> ImportedModules;
817212795Sdim  //@}
818212795Sdim
819218893Sdim  /// \brief The directory that the PCH we are reading is stored in.
820218893Sdim  std::string CurrentDir;
821218893Sdim
822212795Sdim  /// \brief The system include root to be used when loading the
823212795Sdim  /// precompiled header.
824226633Sdim  std::string isysroot;
825212795Sdim
826212795Sdim  /// \brief Whether to disable the normal validation performed on precompiled
827212795Sdim  /// headers when they are loaded.
828212795Sdim  bool DisableValidation;
829234353Sdim
830234353Sdim  /// \brief Whether to accept an AST file with compiler errors.
831234353Sdim  bool AllowASTWithCompilerErrors;
832234353Sdim
833276479Sdim  /// \brief Whether to accept an AST file that has a different configuration
834276479Sdim  /// from the current compiler instance.
835276479Sdim  bool AllowConfigurationMismatch;
836276479Sdim
837276479Sdim  /// \brief Whether validate system input files.
838276479Sdim  bool ValidateSystemInputs;
839276479Sdim
840249423Sdim  /// \brief Whether we are allowed to use the global module index.
841249423Sdim  bool UseGlobalIndex;
842249423Sdim
843249423Sdim  /// \brief Whether we have tried loading the global module index yet.
844249423Sdim  bool TriedLoadingGlobalIndex;
845249423Sdim
846309124Sdim  ///\brief Whether we are currently processing update records.
847309124Sdim  bool ProcessingUpdateRecords;
848309124Sdim
849239462Sdim  typedef llvm::DenseMap<unsigned, SwitchCase *> SwitchCaseMapTy;
850212795Sdim  /// \brief Mapping from switch-case IDs in the chain to switch-case statements
851212795Sdim  ///
852212795Sdim  /// Statements usually don't have IDs, but switch cases need them, so that the
853212795Sdim  /// switch statement can refer to them.
854239462Sdim  SwitchCaseMapTy SwitchCaseStmts;
855212795Sdim
856239462Sdim  SwitchCaseMapTy *CurrSwitchCaseStmts;
857239462Sdim
858212795Sdim  /// \brief The number of source location entries de-serialized from
859212795Sdim  /// the PCH file.
860212795Sdim  unsigned NumSLocEntriesRead;
861212795Sdim
862212795Sdim  /// \brief The number of source location entries in the chain.
863212795Sdim  unsigned TotalNumSLocEntries;
864212795Sdim
865212795Sdim  /// \brief The number of statements (and expressions) de-serialized
866212795Sdim  /// from the chain.
867212795Sdim  unsigned NumStatementsRead;
868212795Sdim
869212795Sdim  /// \brief The total number of statements (and expressions) stored
870212795Sdim  /// in the chain.
871212795Sdim  unsigned TotalNumStatements;
872212795Sdim
873212795Sdim  /// \brief The number of macros de-serialized from the chain.
874212795Sdim  unsigned NumMacrosRead;
875212795Sdim
876212795Sdim  /// \brief The total number of macros stored in the chain.
877212795Sdim  unsigned TotalNumMacros;
878212795Sdim
879249423Sdim  /// \brief The number of lookups into identifier tables.
880249423Sdim  unsigned NumIdentifierLookups;
881249423Sdim
882249423Sdim  /// \brief The number of lookups into identifier tables that succeed.
883249423Sdim  unsigned NumIdentifierLookupHits;
884249423Sdim
885212795Sdim  /// \brief The number of selectors that have been read.
886212795Sdim  unsigned NumSelectorsRead;
887212795Sdim
888212795Sdim  /// \brief The number of method pool entries that have been read.
889212795Sdim  unsigned NumMethodPoolEntriesRead;
890212795Sdim
891212795Sdim  /// \brief The number of times we have looked up a selector in the method
892249423Sdim  /// pool.
893249423Sdim  unsigned NumMethodPoolLookups;
894212795Sdim
895249423Sdim  /// \brief The number of times we have looked up a selector in the method
896249423Sdim  /// pool and found something.
897249423Sdim  unsigned NumMethodPoolHits;
898249423Sdim
899249423Sdim  /// \brief The number of times we have looked up a selector in the method
900249423Sdim  /// pool within a specific module.
901249423Sdim  unsigned NumMethodPoolTableLookups;
902249423Sdim
903249423Sdim  /// \brief The number of times we have looked up a selector in the method
904249423Sdim  /// pool within a specific module and found something.
905249423Sdim  unsigned NumMethodPoolTableHits;
906249423Sdim
907212795Sdim  /// \brief The total number of method pool entries in the selector table.
908212795Sdim  unsigned TotalNumMethodPoolEntries;
909212795Sdim
910212795Sdim  /// Number of lexical decl contexts read/total.
911212795Sdim  unsigned NumLexicalDeclContextsRead, TotalLexicalDeclContexts;
912212795Sdim
913212795Sdim  /// Number of visible decl contexts read/total.
914212795Sdim  unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts;
915234353Sdim
916226633Sdim  /// Total size of modules, in bits, currently loaded
917226633Sdim  uint64_t TotalModulesSizeInBits;
918226633Sdim
919212795Sdim  /// \brief Number of Decl/types that are currently deserializing.
920212795Sdim  unsigned NumCurrentElementsDeserializing;
921212795Sdim
922234353Sdim  /// \brief Set true while we are in the process of passing deserialized
923234353Sdim  /// "interesting" decls to consumer inside FinishedDeserializing().
924234353Sdim  /// This is used as a guard to avoid recursively repeating the process of
925234353Sdim  /// passing decls to consumer.
926234353Sdim  bool PassingDeclsToConsumer;
927234353Sdim
928212795Sdim  /// \brief The set of identifiers that were read while the AST reader was
929212795Sdim  /// (recursively) loading declarations.
930212795Sdim  ///
931212795Sdim  /// The declarations on the identifier chain for these identifiers will be
932212795Sdim  /// loaded once the recursive loading has completed.
933249423Sdim  llvm::MapVector<IdentifierInfo *, SmallVector<uint32_t, 4> >
934249423Sdim    PendingIdentifierInfos;
935212795Sdim
936288943Sdim  /// \brief The set of lookup results that we have faked in order to support
937288943Sdim  /// merging of partially deserialized decls but that we have not yet removed.
938288943Sdim  llvm::SmallMapVector<IdentifierInfo *, SmallVector<NamedDecl*, 2>, 16>
939288943Sdim    PendingFakeLookupResults;
940288943Sdim
941234353Sdim  /// \brief The generation number of each identifier, which keeps track of
942234353Sdim  /// the last time we loaded information about this identifier.
943234353Sdim  llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration;
944234353Sdim
945212795Sdim  /// \brief Contains declarations and definitions that will be
946212795Sdim  /// "interesting" to the ASTConsumer, when we get that AST consumer.
947212795Sdim  ///
948212795Sdim  /// "Interesting" declarations are those that have data that may
949212795Sdim  /// need to be emitted, such as inline function definitions or
950212795Sdim  /// Objective-C protocols.
951212795Sdim  std::deque<Decl *> InterestingDecls;
952212795Sdim
953234353Sdim  /// \brief The list of redeclaration chains that still need to be
954296417Sdim  /// reconstructed, and the local offset to the corresponding list
955296417Sdim  /// of redeclarations.
956296417Sdim  SmallVector<std::pair<Decl *, uint64_t>, 16> PendingDeclChains;
957218893Sdim
958276479Sdim  /// \brief The list of canonical declarations whose redeclaration chains
959276479Sdim  /// need to be marked as incomplete once we're done deserializing things.
960276479Sdim  SmallVector<Decl *, 16> PendingIncompleteDeclChains;
961276479Sdim
962249423Sdim  /// \brief The Decl IDs for the Sema/Lexical DeclContext of a Decl that has
963249423Sdim  /// been loaded but its DeclContext was not set yet.
964249423Sdim  struct PendingDeclContextInfo {
965249423Sdim    Decl *D;
966249423Sdim    serialization::GlobalDeclID SemaDC;
967249423Sdim    serialization::GlobalDeclID LexicalDC;
968249423Sdim  };
969249423Sdim
970249423Sdim  /// \brief The set of Decls that have been loaded but their DeclContexts are
971249423Sdim  /// not set yet.
972249423Sdim  ///
973249423Sdim  /// The DeclContexts for these Decls will be set once recursive loading has
974249423Sdim  /// been completed.
975249423Sdim  std::deque<PendingDeclContextInfo> PendingDeclContextInfos;
976249423Sdim
977261991Sdim  /// \brief The set of NamedDecls that have been loaded, but are members of a
978261991Sdim  /// context that has been merged into another context where the corresponding
979261991Sdim  /// declaration is either missing or has not yet been loaded.
980261991Sdim  ///
981261991Sdim  /// We will check whether the corresponding declaration is in fact missing
982261991Sdim  /// once recursing loading has been completed.
983261991Sdim  llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks;
984261991Sdim
985276479Sdim  /// \brief Record definitions in which we found an ODR violation.
986276479Sdim  llvm::SmallDenseMap<CXXRecordDecl *, llvm::TinyPtrVector<CXXRecordDecl *>, 2>
987276479Sdim      PendingOdrMergeFailures;
988276479Sdim
989276479Sdim  /// \brief DeclContexts in which we have diagnosed an ODR violation.
990276479Sdim  llvm::SmallPtrSet<DeclContext*, 2> DiagnosedOdrMergeFailures;
991276479Sdim
992234353Sdim  /// \brief The set of Objective-C categories that have been deserialized
993234353Sdim  /// since the last time the declaration chains were linked.
994234353Sdim  llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized;
995234353Sdim
996234353Sdim  /// \brief The set of Objective-C class definitions that have already been
997234353Sdim  /// loaded, for which we will need to check for categories whenever a new
998234353Sdim  /// module is loaded.
999249423Sdim  SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded;
1000276479Sdim
1001249423Sdim  typedef llvm::DenseMap<Decl *, SmallVector<serialization::DeclID, 2> >
1002288943Sdim    KeyDeclsMap;
1003234353Sdim
1004288943Sdim  /// \brief A mapping from canonical declarations to the set of global
1005288943Sdim  /// declaration IDs for key declaration that have been merged with that
1006288943Sdim  /// canonical declaration. A key declaration is a formerly-canonical
1007288943Sdim  /// declaration whose module did not import any other key declaration for that
1008288943Sdim  /// entity. These are the IDs that we use as keys when finding redecl chains.
1009288943Sdim  KeyDeclsMap KeyDecls;
1010234353Sdim
1011261991Sdim  /// \brief A mapping from DeclContexts to the semantic DeclContext that we
1012261991Sdim  /// are treating as the definition of the entity. This is used, for instance,
1013261991Sdim  /// when merging implicit instantiations of class templates across modules.
1014261991Sdim  llvm::DenseMap<DeclContext *, DeclContext *> MergedDeclContexts;
1015261991Sdim
1016261991Sdim  /// \brief A mapping from canonical declarations of enums to their canonical
1017261991Sdim  /// definitions. Only populated when using modules in C++.
1018261991Sdim  llvm::DenseMap<EnumDecl *, EnumDecl *> EnumDefinitions;
1019261991Sdim
1020212795Sdim  /// \brief When reading a Stmt tree, Stmt operands are placed in this stack.
1021226633Sdim  SmallVector<Stmt *, 16> StmtStack;
1022212795Sdim
1023212795Sdim  /// \brief What kind of records we are reading.
1024212795Sdim  enum ReadingKind {
1025261991Sdim    Read_None, Read_Decl, Read_Type, Read_Stmt
1026212795Sdim  };
1027212795Sdim
1028234353Sdim  /// \brief What kind of records we are reading.
1029212795Sdim  ReadingKind ReadingKind;
1030212795Sdim
1031212795Sdim  /// \brief RAII object to change the reading kind.
1032212795Sdim  class ReadingKindTracker {
1033212795Sdim    ASTReader &Reader;
1034212795Sdim    enum ReadingKind PrevKind;
1035212795Sdim
1036288943Sdim    ReadingKindTracker(const ReadingKindTracker &) = delete;
1037288943Sdim    void operator=(const ReadingKindTracker &) = delete;
1038212795Sdim
1039212795Sdim  public:
1040212795Sdim    ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader)
1041212795Sdim      : Reader(reader), PrevKind(Reader.ReadingKind) {
1042212795Sdim      Reader.ReadingKind = newKind;
1043212795Sdim    }
1044212795Sdim
1045212795Sdim    ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; }
1046212795Sdim  };
1047212795Sdim
1048309124Sdim  /// \brief RAII object to mark the start of processing updates.
1049309124Sdim  class ProcessingUpdatesRAIIObj {
1050309124Sdim    ASTReader &Reader;
1051309124Sdim    bool PrevState;
1052309124Sdim
1053309124Sdim    ProcessingUpdatesRAIIObj(const ProcessingUpdatesRAIIObj &) = delete;
1054309124Sdim    void operator=(const ProcessingUpdatesRAIIObj &) = delete;
1055309124Sdim
1056309124Sdim  public:
1057309124Sdim    ProcessingUpdatesRAIIObj(ASTReader &reader)
1058309124Sdim      : Reader(reader), PrevState(Reader.ProcessingUpdateRecords) {
1059309124Sdim      Reader.ProcessingUpdateRecords = true;
1060309124Sdim    }
1061309124Sdim
1062309124Sdim    ~ProcessingUpdatesRAIIObj() { Reader.ProcessingUpdateRecords = PrevState; }
1063309124Sdim  };
1064309124Sdim
1065212795Sdim  /// \brief Suggested contents of the predefines buffer, after this
1066212795Sdim  /// PCH file has been processed.
1067212795Sdim  ///
1068212795Sdim  /// In most cases, this string will be empty, because the predefines
1069212795Sdim  /// buffer computed to build the PCH file will be identical to the
1070212795Sdim  /// predefines buffer computed from the command line. However, when
1071212795Sdim  /// there are differences that the PCH reader can work around, this
1072212795Sdim  /// predefines buffer may contain additional definitions.
1073212795Sdim  std::string SuggestedPredefines;
1074212795Sdim
1075212795Sdim  /// \brief Reads a statement from the specified cursor.
1076234353Sdim  Stmt *ReadStmtFromStream(ModuleFile &F);
1077212795Sdim
1078276479Sdim  struct InputFileInfo {
1079276479Sdim    std::string Filename;
1080276479Sdim    off_t StoredSize;
1081276479Sdim    time_t StoredTime;
1082276479Sdim    bool Overridden;
1083296417Sdim    bool Transient;
1084276479Sdim  };
1085276479Sdim
1086276479Sdim  /// \brief Reads the stored information about an input file.
1087276479Sdim  InputFileInfo readInputFileInfo(ModuleFile &F, unsigned ID);
1088276479Sdim
1089243830Sdim  /// \brief Retrieve the file entry and 'overridden' bit for an input
1090243830Sdim  /// file in the given module file.
1091249423Sdim  serialization::InputFile getInputFile(ModuleFile &F, unsigned ID,
1092249423Sdim                                        bool Complain = true);
1093243830Sdim
1094280031Sdimpublic:
1095280031Sdim  void ResolveImportedPath(ModuleFile &M, std::string &Filename);
1096280031Sdim  static void ResolveImportedPath(std::string &Filename, StringRef Prefix);
1097223017Sdim
1098288943Sdim  /// \brief Returns the first key declaration for the given declaration. This
1099288943Sdim  /// is one that is formerly-canonical (or still canonical) and whose module
1100288943Sdim  /// did not import any other key declaration of the entity.
1101288943Sdim  Decl *getKeyDeclaration(Decl *D) {
1102288943Sdim    D = D->getCanonicalDecl();
1103288943Sdim    if (D->isFromASTFile())
1104288943Sdim      return D;
1105288943Sdim
1106288943Sdim    auto I = KeyDecls.find(D);
1107288943Sdim    if (I == KeyDecls.end() || I->second.empty())
1108288943Sdim      return D;
1109288943Sdim    return GetExistingDecl(I->second[0]);
1110288943Sdim  }
1111288943Sdim  const Decl *getKeyDeclaration(const Decl *D) {
1112288943Sdim    return getKeyDeclaration(const_cast<Decl*>(D));
1113288943Sdim  }
1114288943Sdim
1115288943Sdim  /// \brief Run a callback on each imported key declaration of \p D.
1116288943Sdim  template <typename Fn>
1117288943Sdim  void forEachImportedKeyDecl(const Decl *D, Fn Visit) {
1118288943Sdim    D = D->getCanonicalDecl();
1119288943Sdim    if (D->isFromASTFile())
1120288943Sdim      Visit(D);
1121288943Sdim
1122288943Sdim    auto It = KeyDecls.find(const_cast<Decl*>(D));
1123288943Sdim    if (It != KeyDecls.end())
1124288943Sdim      for (auto ID : It->second)
1125288943Sdim        Visit(GetExistingDecl(ID));
1126288943Sdim  }
1127288943Sdim
1128296417Sdim  /// \brief Get the loaded lookup tables for \p Primary, if any.
1129296417Sdim  const serialization::reader::DeclContextLookupTable *
1130296417Sdim  getLoadedLookupTables(DeclContext *Primary) const;
1131296417Sdim
1132280031Sdimprivate:
1133249423Sdim  struct ImportedModule {
1134249423Sdim    ModuleFile *Mod;
1135249423Sdim    ModuleFile *ImportedBy;
1136249423Sdim    SourceLocation ImportLoc;
1137249423Sdim
1138249423Sdim    ImportedModule(ModuleFile *Mod,
1139249423Sdim                   ModuleFile *ImportedBy,
1140249423Sdim                   SourceLocation ImportLoc)
1141249423Sdim      : Mod(Mod), ImportedBy(ImportedBy), ImportLoc(ImportLoc) { }
1142249423Sdim  };
1143249423Sdim
1144226633Sdim  ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type,
1145249423Sdim                            SourceLocation ImportLoc, ModuleFile *ImportedBy,
1146249423Sdim                            SmallVectorImpl<ImportedModule> &Loaded,
1147249423Sdim                            off_t ExpectedSize, time_t ExpectedModTime,
1148280031Sdim                            serialization::ASTFileSignature ExpectedSignature,
1149243830Sdim                            unsigned ClientLoadCapabilities);
1150243830Sdim  ASTReadResult ReadControlBlock(ModuleFile &F,
1151249423Sdim                                 SmallVectorImpl<ImportedModule> &Loaded,
1152276479Sdim                                 const ModuleFile *ImportedBy,
1153243830Sdim                                 unsigned ClientLoadCapabilities);
1154296417Sdim  static ASTReadResult ReadOptionsBlock(
1155296417Sdim      llvm::BitstreamCursor &Stream, unsigned ClientLoadCapabilities,
1156296417Sdim      bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener,
1157296417Sdim      std::string &SuggestedPredefines);
1158276479Sdim  ASTReadResult ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities);
1159296417Sdim  ASTReadResult ReadExtensionBlock(ModuleFile &F);
1160280031Sdim  bool ParseLineTable(ModuleFile &F, const RecordData &Record);
1161243830Sdim  bool ReadSourceManagerBlock(ModuleFile &F);
1162226633Sdim  llvm::BitstreamCursor &SLocCursorForID(int ID);
1163234353Sdim  SourceLocation getImportLocation(ModuleFile *F);
1164280031Sdim  ASTReadResult ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
1165280031Sdim                                       const ModuleFile *ImportedBy,
1166280031Sdim                                       unsigned ClientLoadCapabilities);
1167276479Sdim  ASTReadResult ReadSubmoduleBlock(ModuleFile &F,
1168276479Sdim                                   unsigned ClientLoadCapabilities);
1169243830Sdim  static bool ParseLanguageOptions(const RecordData &Record, bool Complain,
1170280031Sdim                                   ASTReaderListener &Listener,
1171280031Sdim                                   bool AllowCompatibleDifferences);
1172243830Sdim  static bool ParseTargetOptions(const RecordData &Record, bool Complain,
1173288943Sdim                                 ASTReaderListener &Listener,
1174288943Sdim                                 bool AllowCompatibleDifferences);
1175243830Sdim  static bool ParseDiagnosticOptions(const RecordData &Record, bool Complain,
1176243830Sdim                                     ASTReaderListener &Listener);
1177243830Sdim  static bool ParseFileSystemOptions(const RecordData &Record, bool Complain,
1178243830Sdim                                     ASTReaderListener &Listener);
1179243830Sdim  static bool ParseHeaderSearchOptions(const RecordData &Record, bool Complain,
1180243830Sdim                                       ASTReaderListener &Listener);
1181243830Sdim  static bool ParsePreprocessorOptions(const RecordData &Record, bool Complain,
1182243830Sdim                                       ASTReaderListener &Listener,
1183243830Sdim                                       std::string &SuggestedPredefines);
1184243830Sdim
1185218893Sdim  struct RecordLocation {
1186234353Sdim    RecordLocation(ModuleFile *M, uint64_t O)
1187218893Sdim      : F(M), Offset(O) {}
1188234353Sdim    ModuleFile *F;
1189218893Sdim    uint64_t Offset;
1190218893Sdim  };
1191212795Sdim
1192226633Sdim  QualType readTypeRecord(unsigned Index);
1193276479Sdim  void readExceptionSpec(ModuleFile &ModuleFile,
1194276479Sdim                         SmallVectorImpl<QualType> &ExceptionStorage,
1195280031Sdim                         FunctionProtoType::ExceptionSpecInfo &ESI,
1196276479Sdim                         const RecordData &Record, unsigned &Index);
1197212795Sdim  RecordLocation TypeCursorForIndex(unsigned Index);
1198212795Sdim  void LoadedDecl(unsigned Index, Decl *D);
1199226633Sdim  Decl *ReadDeclRecord(serialization::DeclID ID);
1200276479Sdim  void markIncompleteDeclChain(Decl *Canon);
1201288943Sdim
1202288943Sdim  /// \brief Returns the most recent declaration of a declaration (which must be
1203288943Sdim  /// of a redeclarable kind) that is either local or has already been loaded
1204288943Sdim  /// merged into its redecl chain.
1205288943Sdim  Decl *getMostRecentExistingDecl(Decl *D);
1206288943Sdim
1207234353Sdim  RecordLocation DeclCursorForID(serialization::DeclID ID,
1208309124Sdim                                 SourceLocation &Location);
1209226633Sdim  void loadDeclUpdateRecords(serialization::DeclID ID, Decl *D);
1210296417Sdim  void loadPendingDeclChain(Decl *D, uint64_t LocalOffset);
1211234353Sdim  void loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D,
1212234353Sdim                          unsigned PreviousGeneration = 0);
1213234353Sdim
1214226633Sdim  RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
1215234353Sdim  uint64_t getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset);
1216212795Sdim
1217276479Sdim  /// \brief Returns the first preprocessed entity ID that begins or ends after
1218276479Sdim  /// \arg Loc.
1219226633Sdim  serialization::PreprocessedEntityID
1220276479Sdim  findPreprocessedEntity(SourceLocation Loc, bool EndsAfter) const;
1221226633Sdim
1222239462Sdim  /// \brief Find the next module that contains entities and return the ID
1223226633Sdim  /// of the first entry.
1224243830Sdim  ///
1225243830Sdim  /// \param SLocMapI points at a chunk of a module that contains no
1226239462Sdim  /// preprocessed entities or the entities it contains are not the
1227239462Sdim  /// ones we are looking for.
1228226633Sdim  serialization::PreprocessedEntityID
1229226633Sdim    findNextPreprocessedEntity(
1230226633Sdim                        GlobalSLocOffsetMapType::const_iterator SLocMapI) const;
1231226633Sdim
1232243830Sdim  /// \brief Returns (ModuleFile, Local index) pair for \p GlobalIndex of a
1233234353Sdim  /// preprocessed entity.
1234234353Sdim  std::pair<ModuleFile *, unsigned>
1235234353Sdim    getModulePreprocessedEntity(unsigned GlobalIndex);
1236234353Sdim
1237243830Sdim  /// \brief Returns (begin, end) pair for the preprocessed entities of a
1238243830Sdim  /// particular module.
1239288943Sdim  llvm::iterator_range<PreprocessingRecord::iterator>
1240288943Sdim  getModulePreprocessedEntities(ModuleFile &Mod) const;
1241243830Sdim
1242288943Sdim  class ModuleDeclIterator
1243288943Sdim      : public llvm::iterator_adaptor_base<
1244288943Sdim            ModuleDeclIterator, const serialization::LocalDeclID *,
1245288943Sdim            std::random_access_iterator_tag, const Decl *, ptrdiff_t,
1246288943Sdim            const Decl *, const Decl *> {
1247243830Sdim    ASTReader *Reader;
1248243830Sdim    ModuleFile *Mod;
1249243830Sdim
1250243830Sdim  public:
1251288943Sdim    ModuleDeclIterator()
1252288943Sdim        : iterator_adaptor_base(nullptr), Reader(nullptr), Mod(nullptr) {}
1253243830Sdim
1254243830Sdim    ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod,
1255243830Sdim                       const serialization::LocalDeclID *Pos)
1256288943Sdim        : iterator_adaptor_base(Pos), Reader(Reader), Mod(Mod) {}
1257243830Sdim
1258243830Sdim    value_type operator*() const {
1259288943Sdim      return Reader->GetDecl(Reader->getGlobalDeclID(*Mod, *I));
1260243830Sdim    }
1261288943Sdim    value_type operator->() const { return **this; }
1262243830Sdim
1263288943Sdim    bool operator==(const ModuleDeclIterator &RHS) const {
1264288943Sdim      assert(Reader == RHS.Reader && Mod == RHS.Mod);
1265288943Sdim      return I == RHS.I;
1266243830Sdim    }
1267243830Sdim  };
1268243830Sdim
1269288943Sdim  llvm::iterator_range<ModuleDeclIterator>
1270288943Sdim  getModuleFileLevelDecls(ModuleFile &Mod);
1271243830Sdim
1272212795Sdim  void PassInterestingDeclsToConsumer();
1273234353Sdim  void PassInterestingDeclToConsumer(Decl *D);
1274212795Sdim
1275234353Sdim  void finishPendingActions();
1276280031Sdim  void diagnoseOdrViolations();
1277234353Sdim
1278251662Sdim  void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name);
1279251662Sdim
1280249423Sdim  void addPendingDeclContextInfo(Decl *D,
1281249423Sdim                                 serialization::GlobalDeclID SemaDC,
1282249423Sdim                                 serialization::GlobalDeclID LexicalDC) {
1283249423Sdim    assert(D);
1284249423Sdim    PendingDeclContextInfo Info = { D, SemaDC, LexicalDC };
1285249423Sdim    PendingDeclContextInfos.push_back(Info);
1286249423Sdim  }
1287249423Sdim
1288212795Sdim  /// \brief Produce an error diagnostic and return true.
1289212795Sdim  ///
1290212795Sdim  /// This routine should only be used for fatal errors that have to
1291212795Sdim  /// do with non-routine failures (e.g., corrupted AST file).
1292226633Sdim  void Error(StringRef Msg);
1293226633Sdim  void Error(unsigned DiagID, StringRef Arg1 = StringRef(),
1294226633Sdim             StringRef Arg2 = StringRef());
1295212795Sdim
1296288943Sdim  ASTReader(const ASTReader &) = delete;
1297288943Sdim  void operator=(const ASTReader &) = delete;
1298212795Sdimpublic:
1299212795Sdim  /// \brief Load the AST file and validate its contents against the given
1300212795Sdim  /// Preprocessor.
1301212795Sdim  ///
1302212795Sdim  /// \param PP the preprocessor associated with the context in which this
1303212795Sdim  /// precompiled header will be loaded.
1304212795Sdim  ///
1305212795Sdim  /// \param Context the AST context that this precompiled header will be
1306212795Sdim  /// loaded into.
1307212795Sdim  ///
1308296417Sdim  /// \param PCHContainerRdr the PCHContainerOperations to use for loading and
1309288943Sdim  /// creating modules.
1310288943Sdim  ///
1311296417Sdim  /// \param Extensions the list of module file extensions that can be loaded
1312296417Sdim  /// from the AST files.
1313296417Sdim  ///
1314212795Sdim  /// \param isysroot If non-NULL, the system include path specified by the
1315212795Sdim  /// user. This is only used with relocatable PCH files. If non-NULL,
1316212795Sdim  /// a relocatable PCH file will use the default path "/".
1317212795Sdim  ///
1318212795Sdim  /// \param DisableValidation If true, the AST reader will suppress most
1319212795Sdim  /// of its regular consistency checking, allowing the use of precompiled
1320212795Sdim  /// headers that cannot be determined to be compatible.
1321218893Sdim  ///
1322234353Sdim  /// \param AllowASTWithCompilerErrors If true, the AST reader will accept an
1323234353Sdim  /// AST file the was created out of an AST with compiler errors,
1324234353Sdim  /// otherwise it will reject it.
1325249423Sdim  ///
1326276479Sdim  /// \param AllowConfigurationMismatch If true, the AST reader will not check
1327276479Sdim  /// for configuration differences between the AST file and the invocation.
1328276479Sdim  ///
1329276479Sdim  /// \param ValidateSystemInputs If true, the AST reader will validate
1330276479Sdim  /// system input files in addition to user input files. This is only
1331276479Sdim  /// meaningful if \p DisableValidation is false.
1332276479Sdim  ///
1333249423Sdim  /// \param UseGlobalIndex If true, the AST reader will try to load and use
1334249423Sdim  /// the global module index.
1335288943Sdim  ///
1336288943Sdim  /// \param ReadTimer If non-null, a timer used to track the time spent
1337288943Sdim  /// deserializing.
1338288943Sdim  ASTReader(Preprocessor &PP, ASTContext &Context,
1339288943Sdim            const PCHContainerReader &PCHContainerRdr,
1340296417Sdim            ArrayRef<IntrusiveRefCntPtr<ModuleFileExtension>> Extensions,
1341288943Sdim            StringRef isysroot = "", bool DisableValidation = false,
1342249423Sdim            bool AllowASTWithCompilerErrors = false,
1343276479Sdim            bool AllowConfigurationMismatch = false,
1344288943Sdim            bool ValidateSystemInputs = false, bool UseGlobalIndex = true,
1345288943Sdim            std::unique_ptr<llvm::Timer> ReadTimer = {});
1346212795Sdim
1347288943Sdim  ~ASTReader() override;
1348212795Sdim
1349226633Sdim  SourceManager &getSourceManager() const { return SourceMgr; }
1350249423Sdim  FileManager &getFileManager() const { return FileMgr; }
1351296417Sdim  DiagnosticsEngine &getDiags() const { return Diags; }
1352234353Sdim
1353243830Sdim  /// \brief Flags that indicate what kind of AST loading failures the client
1354243830Sdim  /// of the AST reader can directly handle.
1355243830Sdim  ///
1356243830Sdim  /// When a client states that it can handle a particular kind of failure,
1357243830Sdim  /// the AST reader will not emit errors when producing that kind of failure.
1358243830Sdim  enum LoadFailureCapabilities {
1359243830Sdim    /// \brief The client can't handle any AST loading failures.
1360243830Sdim    ARR_None = 0,
1361243830Sdim    /// \brief The client can handle an AST file that cannot load because it
1362249423Sdim    /// is missing.
1363249423Sdim    ARR_Missing = 0x1,
1364249423Sdim    /// \brief The client can handle an AST file that cannot load because it
1365243830Sdim    /// is out-of-date relative to its input files.
1366249423Sdim    ARR_OutOfDate = 0x2,
1367243830Sdim    /// \brief The client can handle an AST file that cannot load because it
1368243830Sdim    /// was built with a different version of Clang.
1369249423Sdim    ARR_VersionMismatch = 0x4,
1370243830Sdim    /// \brief The client can handle an AST file that cannot load because it's
1371243830Sdim    /// compiled configuration doesn't match that of the context it was
1372243830Sdim    /// loaded into.
1373249423Sdim    ARR_ConfigurationMismatch = 0x8
1374243830Sdim  };
1375243830Sdim
1376226633Sdim  /// \brief Load the AST file designated by the given file name.
1377243830Sdim  ///
1378243830Sdim  /// \param FileName The name of the AST file to load.
1379243830Sdim  ///
1380243830Sdim  /// \param Type The kind of AST being loaded, e.g., PCH, module, main file,
1381243830Sdim  /// or preamble.
1382243830Sdim  ///
1383249423Sdim  /// \param ImportLoc the location where the module file will be considered as
1384249423Sdim  /// imported from. For non-module AST types it should be invalid.
1385249423Sdim  ///
1386243830Sdim  /// \param ClientLoadCapabilities The set of client load-failure
1387243830Sdim  /// capabilities, represented as a bitset of the enumerators of
1388243830Sdim  /// LoadFailureCapabilities.
1389309124Sdim  ASTReadResult ReadAST(StringRef FileName, ModuleKind Type,
1390249423Sdim                        SourceLocation ImportLoc,
1391243830Sdim                        unsigned ClientLoadCapabilities);
1392212795Sdim
1393234353Sdim  /// \brief Make the entities in the given module and any of its (non-explicit)
1394234353Sdim  /// submodules visible to name lookup.
1395234353Sdim  ///
1396234353Sdim  /// \param Mod The module whose names should be made visible.
1397234353Sdim  ///
1398239462Sdim  /// \param NameVisibility The level of visibility to give the names in the
1399239462Sdim  /// module.  Visibility can only be increased over time.
1400249423Sdim  ///
1401249423Sdim  /// \param ImportLoc The location at which the import occurs.
1402276479Sdim  void makeModuleVisible(Module *Mod,
1403249423Sdim                         Module::NameVisibilityKind NameVisibility,
1404288943Sdim                         SourceLocation ImportLoc);
1405276479Sdim
1406234353Sdim  /// \brief Make the names within this set of hidden names visible.
1407288943Sdim  void makeNamesVisible(const HiddenNames &Names, Module *Owner);
1408276479Sdim
1409280031Sdim  /// \brief Take the AST callbacks listener.
1410280031Sdim  std::unique_ptr<ASTReaderListener> takeListener() {
1411280031Sdim    return std::move(Listener);
1412280031Sdim  }
1413280031Sdim
1414212795Sdim  /// \brief Set the AST callbacks listener.
1415280031Sdim  void setListener(std::unique_ptr<ASTReaderListener> Listener) {
1416280031Sdim    this->Listener = std::move(Listener);
1417212795Sdim  }
1418212795Sdim
1419280031Sdim  /// \brief Add an AST callback listener.
1420276479Sdim  ///
1421276479Sdim  /// Takes ownership of \p L.
1422280031Sdim  void addListener(std::unique_ptr<ASTReaderListener> L) {
1423276479Sdim    if (Listener)
1424280031Sdim      L = llvm::make_unique<ChainedASTReaderListener>(std::move(L),
1425280031Sdim                                                      std::move(Listener));
1426280031Sdim    Listener = std::move(L);
1427276479Sdim  }
1428276479Sdim
1429280031Sdim  /// RAII object to temporarily add an AST callback listener.
1430280031Sdim  class ListenerScope {
1431280031Sdim    ASTReader &Reader;
1432280031Sdim    bool Chained;
1433280031Sdim
1434280031Sdim  public:
1435280031Sdim    ListenerScope(ASTReader &Reader, std::unique_ptr<ASTReaderListener> L)
1436280031Sdim        : Reader(Reader), Chained(false) {
1437280031Sdim      auto Old = Reader.takeListener();
1438280031Sdim      if (Old) {
1439280031Sdim        Chained = true;
1440280031Sdim        L = llvm::make_unique<ChainedASTReaderListener>(std::move(L),
1441280031Sdim                                                        std::move(Old));
1442280031Sdim      }
1443280031Sdim      Reader.setListener(std::move(L));
1444280031Sdim    }
1445280031Sdim    ~ListenerScope() {
1446280031Sdim      auto New = Reader.takeListener();
1447280031Sdim      if (Chained)
1448280031Sdim        Reader.setListener(static_cast<ChainedASTReaderListener *>(New.get())
1449280031Sdim                               ->takeSecond());
1450280031Sdim    }
1451280031Sdim  };
1452280031Sdim
1453212795Sdim  /// \brief Set the AST deserialization listener.
1454276479Sdim  void setDeserializationListener(ASTDeserializationListener *Listener,
1455276479Sdim                                  bool TakeOwnership = false);
1456212795Sdim
1457249423Sdim  /// \brief Determine whether this AST reader has a global index.
1458276479Sdim  bool hasGlobalIndex() const { return (bool)GlobalIndex; }
1459249423Sdim
1460276479Sdim  /// \brief Return global module index.
1461276479Sdim  GlobalModuleIndex *getGlobalIndex() { return GlobalIndex.get(); }
1462276479Sdim
1463276479Sdim  /// \brief Reset reader for a reload try.
1464276479Sdim  void resetForReload() { TriedLoadingGlobalIndex = false; }
1465276479Sdim
1466249423Sdim  /// \brief Attempts to load the global index.
1467249423Sdim  ///
1468249423Sdim  /// \returns true if loading the global index has failed for any reason.
1469249423Sdim  bool loadGlobalIndex();
1470249423Sdim
1471249423Sdim  /// \brief Determine whether we tried to load the global index, but failed,
1472249423Sdim  /// e.g., because it is out-of-date or does not exist.
1473249423Sdim  bool isGlobalIndexUnavailable() const;
1474249423Sdim
1475226633Sdim  /// \brief Initializes the ASTContext
1476226633Sdim  void InitializeContext();
1477212795Sdim
1478261991Sdim  /// \brief Update the state of Sema after loading some additional modules.
1479261991Sdim  void UpdateSema();
1480261991Sdim
1481226633Sdim  /// \brief Add in-memory (virtual file) buffer.
1482280031Sdim  void addInMemoryBuffer(StringRef &FileName,
1483280031Sdim                         std::unique_ptr<llvm::MemoryBuffer> Buffer) {
1484280031Sdim    ModuleMgr.addInMemoryBuffer(FileName, std::move(Buffer));
1485221345Sdim  }
1486221345Sdim
1487234353Sdim  /// \brief Finalizes the AST reader's state before writing an AST file to
1488234353Sdim  /// disk.
1489234353Sdim  ///
1490234353Sdim  /// This operation may undo temporary state in the AST that should not be
1491234353Sdim  /// emitted.
1492234353Sdim  void finalizeForWriting();
1493234353Sdim
1494226633Sdim  /// \brief Retrieve the module manager.
1495226633Sdim  ModuleManager &getModuleManager() { return ModuleMgr; }
1496212795Sdim
1497226633Sdim  /// \brief Retrieve the preprocessor.
1498226633Sdim  Preprocessor &getPreprocessor() const { return PP; }
1499234353Sdim
1500243830Sdim  /// \brief Retrieve the name of the original source file name for the primary
1501243830Sdim  /// module file.
1502243830Sdim  StringRef getOriginalSourceFile() {
1503243830Sdim    return ModuleMgr.getPrimaryModule().OriginalSourceFileName;
1504243830Sdim  }
1505212795Sdim
1506212795Sdim  /// \brief Retrieve the name of the original source file name directly from
1507212795Sdim  /// the AST file, without actually loading the AST file.
1508288943Sdim  static std::string
1509288943Sdim  getOriginalSourceFile(const std::string &ASTFileName, FileManager &FileMgr,
1510288943Sdim                        const PCHContainerReader &PCHContainerRdr,
1511288943Sdim                        DiagnosticsEngine &Diags);
1512212795Sdim
1513243830Sdim  /// \brief Read the control block for the named AST file.
1514243830Sdim  ///
1515243830Sdim  /// \returns true if an error occurred, false otherwise.
1516288943Sdim  static bool
1517288943Sdim  readASTFileControlBlock(StringRef Filename, FileManager &FileMgr,
1518288943Sdim                          const PCHContainerReader &PCHContainerRdr,
1519296417Sdim                          bool FindModuleFileExtensions,
1520288943Sdim                          ASTReaderListener &Listener);
1521243830Sdim
1522243830Sdim  /// \brief Determine whether the given AST file is acceptable to load into a
1523243830Sdim  /// translation unit with the given language and target options.
1524288943Sdim  static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr,
1525288943Sdim                                  const PCHContainerReader &PCHContainerRdr,
1526243830Sdim                                  const LangOptions &LangOpts,
1527243830Sdim                                  const TargetOptions &TargetOpts,
1528288943Sdim                                  const PreprocessorOptions &PPOpts,
1529288943Sdim                                  std::string ExistingModuleCachePath);
1530243830Sdim
1531212795Sdim  /// \brief Returns the suggested contents of the predefines buffer,
1532212795Sdim  /// which contains a (typically-empty) subset of the predefines
1533212795Sdim  /// build prior to including the precompiled header.
1534212795Sdim  const std::string &getSuggestedPredefines() { return SuggestedPredefines; }
1535212795Sdim
1536226633Sdim  /// \brief Read a preallocated preprocessed entity from the external source.
1537226633Sdim  ///
1538226633Sdim  /// \returns null if an error occurred that prevented the preprocessed
1539226633Sdim  /// entity from being loaded.
1540276479Sdim  PreprocessedEntity *ReadPreprocessedEntity(unsigned Index) override;
1541218893Sdim
1542226633Sdim  /// \brief Returns a pair of [Begin, End) indices of preallocated
1543243830Sdim  /// preprocessed entities that \p Range encompasses.
1544276479Sdim  std::pair<unsigned, unsigned>
1545276479Sdim      findPreprocessedEntitiesInRange(SourceRange Range) override;
1546226633Sdim
1547234353Sdim  /// \brief Optionally returns true or false if the preallocated preprocessed
1548243830Sdim  /// entity with index \p Index came from file \p FID.
1549276479Sdim  Optional<bool> isPreprocessedEntityInFileID(unsigned Index,
1550276479Sdim                                              FileID FID) override;
1551234353Sdim
1552218893Sdim  /// \brief Read the header file information for the given file entry.
1553276479Sdim  HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) override;
1554218893Sdim
1555226633Sdim  void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag);
1556218893Sdim
1557212795Sdim  /// \brief Returns the number of source locations found in the chain.
1558212795Sdim  unsigned getTotalNumSLocs() const {
1559212795Sdim    return TotalNumSLocEntries;
1560212795Sdim  }
1561212795Sdim
1562212795Sdim  /// \brief Returns the number of identifiers found in the chain.
1563212795Sdim  unsigned getTotalNumIdentifiers() const {
1564212795Sdim    return static_cast<unsigned>(IdentifiersLoaded.size());
1565212795Sdim  }
1566212795Sdim
1567243830Sdim  /// \brief Returns the number of macros found in the chain.
1568243830Sdim  unsigned getTotalNumMacros() const {
1569243830Sdim    return static_cast<unsigned>(MacrosLoaded.size());
1570243830Sdim  }
1571243830Sdim
1572212795Sdim  /// \brief Returns the number of types found in the chain.
1573212795Sdim  unsigned getTotalNumTypes() const {
1574212795Sdim    return static_cast<unsigned>(TypesLoaded.size());
1575212795Sdim  }
1576212795Sdim
1577212795Sdim  /// \brief Returns the number of declarations found in the chain.
1578212795Sdim  unsigned getTotalNumDecls() const {
1579212795Sdim    return static_cast<unsigned>(DeclsLoaded.size());
1580212795Sdim  }
1581212795Sdim
1582234353Sdim  /// \brief Returns the number of submodules known.
1583234353Sdim  unsigned getTotalNumSubmodules() const {
1584234353Sdim    return static_cast<unsigned>(SubmodulesLoaded.size());
1585234353Sdim  }
1586234353Sdim
1587212795Sdim  /// \brief Returns the number of selectors found in the chain.
1588212795Sdim  unsigned getTotalNumSelectors() const {
1589212795Sdim    return static_cast<unsigned>(SelectorsLoaded.size());
1590212795Sdim  }
1591212795Sdim
1592226633Sdim  /// \brief Returns the number of preprocessed entities known to the AST
1593226633Sdim  /// reader.
1594226633Sdim  unsigned getTotalNumPreprocessedEntities() const {
1595226633Sdim    unsigned Result = 0;
1596226633Sdim    for (ModuleConstIterator I = ModuleMgr.begin(),
1597226633Sdim        E = ModuleMgr.end(); I != E; ++I) {
1598226633Sdim      Result += (*I)->NumPreprocessedEntities;
1599226633Sdim    }
1600234353Sdim
1601226633Sdim    return Result;
1602218893Sdim  }
1603234353Sdim
1604212795Sdim  /// \brief Reads a TemplateArgumentLocInfo appropriate for the
1605212795Sdim  /// given TemplateArgument kind.
1606212795Sdim  TemplateArgumentLocInfo
1607234353Sdim  GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind,
1608212795Sdim                             const RecordData &Record, unsigned &Idx);
1609212795Sdim
1610212795Sdim  /// \brief Reads a TemplateArgumentLoc.
1611212795Sdim  TemplateArgumentLoc
1612234353Sdim  ReadTemplateArgumentLoc(ModuleFile &F,
1613212795Sdim                          const RecordData &Record, unsigned &Idx);
1614212795Sdim
1615261991Sdim  const ASTTemplateArgumentListInfo*
1616261991Sdim  ReadASTTemplateArgumentListInfo(ModuleFile &F,
1617261991Sdim                                  const RecordData &Record, unsigned &Index);
1618261991Sdim
1619212795Sdim  /// \brief Reads a declarator info from the given record.
1620234353Sdim  TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F,
1621212795Sdim                                    const RecordData &Record, unsigned &Idx);
1622212795Sdim
1623212795Sdim  /// \brief Resolve a type ID into a type, potentially building a new
1624212795Sdim  /// type.
1625212795Sdim  QualType GetType(serialization::TypeID ID);
1626212795Sdim
1627226633Sdim  /// \brief Resolve a local type ID within a given AST file into a type.
1628234353Sdim  QualType getLocalType(ModuleFile &F, unsigned LocalID);
1629234353Sdim
1630226633Sdim  /// \brief Map a local type ID within a given AST file into a global type ID.
1631234353Sdim  serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const;
1632234353Sdim
1633234353Sdim  /// \brief Read a type from the current position in the given record, which
1634226633Sdim  /// was read from the given AST file.
1635234353Sdim  QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) {
1636226633Sdim    if (Idx >= Record.size())
1637226633Sdim      return QualType();
1638234353Sdim
1639226633Sdim    return getLocalType(F, Record[Idx++]);
1640226633Sdim  }
1641234353Sdim
1642234353Sdim  /// \brief Map from a local declaration ID within a given module to a
1643226633Sdim  /// global declaration ID.
1644243830Sdim  serialization::DeclID getGlobalDeclID(ModuleFile &F,
1645243830Sdim                                      serialization::LocalDeclID LocalID) const;
1646212795Sdim
1647243830Sdim  /// \brief Returns true if global DeclID \p ID originated from module \p M.
1648234353Sdim  bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const;
1649234353Sdim
1650234353Sdim  /// \brief Retrieve the module file that owns the given declaration, or NULL
1651234353Sdim  /// if the declaration is not from a module file.
1652249423Sdim  ModuleFile *getOwningModuleFile(const Decl *D);
1653276479Sdim
1654276479Sdim  /// \brief Get the best name we know for the module that owns the given
1655276479Sdim  /// declaration, or an empty string if the declaration is not from a module.
1656276479Sdim  std::string getOwningModuleNameForDiagnostic(const Decl *D);
1657276479Sdim
1658243830Sdim  /// \brief Returns the source location for the decl \p ID.
1659234353Sdim  SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID);
1660234353Sdim
1661212795Sdim  /// \brief Resolve a declaration ID into a declaration, potentially
1662212795Sdim  /// building a new declaration.
1663212795Sdim  Decl *GetDecl(serialization::DeclID ID);
1664276479Sdim  Decl *GetExternalDecl(uint32_t ID) override;
1665212795Sdim
1666276479Sdim  /// \brief Resolve a declaration ID into a declaration. Return 0 if it's not
1667276479Sdim  /// been loaded yet.
1668276479Sdim  Decl *GetExistingDecl(serialization::DeclID ID);
1669276479Sdim
1670226633Sdim  /// \brief Reads a declaration with the given local ID in the given module.
1671234353Sdim  Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) {
1672226633Sdim    return GetDecl(getGlobalDeclID(F, LocalID));
1673226633Sdim  }
1674226633Sdim
1675226633Sdim  /// \brief Reads a declaration with the given local ID in the given module.
1676226633Sdim  ///
1677226633Sdim  /// \returns The requested declaration, casted to the given return type.
1678226633Sdim  template<typename T>
1679234353Sdim  T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) {
1680226633Sdim    return cast_or_null<T>(GetLocalDecl(F, LocalID));
1681226633Sdim  }
1682226633Sdim
1683234353Sdim  /// \brief Map a global declaration ID into the declaration ID used to
1684234353Sdim  /// refer to this declaration within the given module fule.
1685234353Sdim  ///
1686234353Sdim  /// \returns the global ID of the given declaration as known in the given
1687234353Sdim  /// module file.
1688234353Sdim  serialization::DeclID
1689234353Sdim  mapGlobalIDToModuleFileGlobalID(ModuleFile &M,
1690234353Sdim                                  serialization::DeclID GlobalID);
1691234353Sdim
1692234353Sdim  /// \brief Reads a declaration ID from the given position in a record in the
1693226633Sdim  /// given module.
1694226633Sdim  ///
1695226633Sdim  /// \returns The declaration ID read from the record, adjusted to a global ID.
1696234353Sdim  serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record,
1697226633Sdim                                   unsigned &Idx);
1698234353Sdim
1699226633Sdim  /// \brief Reads a declaration from the given position in a record in the
1700226633Sdim  /// given module.
1701234353Sdim  Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) {
1702226633Sdim    return GetDecl(ReadDeclID(F, R, I));
1703226633Sdim  }
1704234353Sdim
1705226633Sdim  /// \brief Reads a declaration from the given position in a record in the
1706226633Sdim  /// given module.
1707226633Sdim  ///
1708226633Sdim  /// \returns The declaration read from this location, casted to the given
1709226633Sdim  /// result type.
1710226633Sdim  template<typename T>
1711234353Sdim  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1712226633Sdim    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1713226633Sdim  }
1714226633Sdim
1715276479Sdim  /// \brief If any redeclarations of \p D have been imported since it was
1716276479Sdim  /// last checked, this digs out those redeclarations and adds them to the
1717276479Sdim  /// redeclaration chain for \p D.
1718276479Sdim  void CompleteRedeclChain(const Decl *D) override;
1719276479Sdim
1720276479Sdim  CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
1721234353Sdim
1722212795Sdim  /// \brief Resolve the offset of a statement into a statement.
1723212795Sdim  ///
1724212795Sdim  /// This operation will read a new statement from the external
1725212795Sdim  /// source each time it is called, and is meant to be used via a
1726212795Sdim  /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
1727276479Sdim  Stmt *GetExternalDeclStmt(uint64_t Offset) override;
1728212795Sdim
1729212795Sdim  /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
1730212795Sdim  /// specified cursor.  Read the abbreviations that are at the top of the block
1731212795Sdim  /// and then leave the cursor pointing into the block.
1732296417Sdim  static bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID);
1733212795Sdim
1734212795Sdim  /// \brief Finds all the visible declarations with a given name.
1735212795Sdim  /// The current implementation of this method just loads the entire
1736212795Sdim  /// lookup table as unmaterialized references.
1737276479Sdim  bool FindExternalVisibleDeclsByName(const DeclContext *DC,
1738276479Sdim                                      DeclarationName Name) override;
1739212795Sdim
1740212795Sdim  /// \brief Read all of the declarations lexically stored in a
1741212795Sdim  /// declaration context.
1742212795Sdim  ///
1743212795Sdim  /// \param DC The declaration context whose declarations will be
1744212795Sdim  /// read.
1745212795Sdim  ///
1746296417Sdim  /// \param IsKindWeWant A predicate indicating which declaration kinds
1747296417Sdim  /// we are interested in.
1748296417Sdim  ///
1749212795Sdim  /// \param Decls Vector that will contain the declarations loaded
1750212795Sdim  /// from the external source. The caller is responsible for merging
1751212795Sdim  /// these declarations with any declarations already stored in the
1752212795Sdim  /// declaration context.
1753296417Sdim  void
1754296417Sdim  FindExternalLexicalDecls(const DeclContext *DC,
1755296417Sdim                           llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
1756296417Sdim                           SmallVectorImpl<Decl *> &Decls) override;
1757212795Sdim
1758234353Sdim  /// \brief Get the decls that are contained in a file in the Offset/Length
1759243830Sdim  /// range. \p Length can be 0 to indicate a point at \p Offset instead of
1760234353Sdim  /// a range.
1761276479Sdim  void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length,
1762276479Sdim                           SmallVectorImpl<Decl *> &Decls) override;
1763234353Sdim
1764212795Sdim  /// \brief Notify ASTReader that we started deserialization of
1765212795Sdim  /// a decl or type so until FinishedDeserializing is called there may be
1766212795Sdim  /// decls that are initializing. Must be paired with FinishedDeserializing.
1767288943Sdim  void StartedDeserializing() override;
1768212795Sdim
1769212795Sdim  /// \brief Notify ASTReader that we finished the deserialization of
1770212795Sdim  /// a decl or type. Must be paired with StartedDeserializing.
1771276479Sdim  void FinishedDeserializing() override;
1772212795Sdim
1773212795Sdim  /// \brief Function that will be invoked when we begin parsing a new
1774212795Sdim  /// translation unit involving this external AST source.
1775212795Sdim  ///
1776212795Sdim  /// This function will provide all of the external definitions to
1777212795Sdim  /// the ASTConsumer.
1778276479Sdim  void StartTranslationUnit(ASTConsumer *Consumer) override;
1779212795Sdim
1780212795Sdim  /// \brief Print some statistics about AST usage.
1781276479Sdim  void PrintStats() override;
1782212795Sdim
1783226633Sdim  /// \brief Dump information about the AST reader to standard error.
1784226633Sdim  void dump();
1785234353Sdim
1786221345Sdim  /// Return the amount of memory used by memory buffers, breaking down
1787221345Sdim  /// by heap-backed versus mmap'ed memory.
1788276479Sdim  void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
1789221345Sdim
1790212795Sdim  /// \brief Initialize the semantic source with the Sema instance
1791212795Sdim  /// being used to perform semantic analysis on the abstract syntax
1792212795Sdim  /// tree.
1793276479Sdim  void InitializeSema(Sema &S) override;
1794212795Sdim
1795212795Sdim  /// \brief Inform the semantic consumer that Sema is no longer available.
1796276479Sdim  void ForgetSema() override { SemaObj = nullptr; }
1797212795Sdim
1798212795Sdim  /// \brief Retrieve the IdentifierInfo for the named identifier.
1799212795Sdim  ///
1800212795Sdim  /// This routine builds a new IdentifierInfo for the given identifier. If any
1801212795Sdim  /// declarations with this name are visible from translation unit scope, their
1802212795Sdim  /// declarations will be deserialized and introduced into the declaration
1803212795Sdim  /// chain of the identifier.
1804296417Sdim  IdentifierInfo *get(StringRef Name) override;
1805212795Sdim
1806218893Sdim  /// \brief Retrieve an iterator into the set of all identifiers
1807218893Sdim  /// in all loaded AST files.
1808276479Sdim  IdentifierIterator *getIdentifiers() override;
1809218893Sdim
1810212795Sdim  /// \brief Load the contents of the global method pool for a given
1811212795Sdim  /// selector.
1812276479Sdim  void ReadMethodPool(Selector Sel) override;
1813212795Sdim
1814309124Sdim  /// Load the contents of the global method pool for a given
1815309124Sdim  /// selector if necessary.
1816309124Sdim  void updateOutOfDateSelector(Selector Sel) override;
1817309124Sdim
1818224145Sdim  /// \brief Load the set of namespaces that are known to the external source,
1819224145Sdim  /// which will be used during typo correction.
1820276479Sdim  void ReadKnownNamespaces(
1821276479Sdim                         SmallVectorImpl<NamespaceDecl *> &Namespaces) override;
1822224145Sdim
1823276479Sdim  void ReadUndefinedButUsed(
1824309124Sdim      llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) override;
1825249423Sdim
1826288943Sdim  void ReadMismatchingDeleteExpressions(llvm::MapVector<
1827288943Sdim      FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
1828288943Sdim                                            Exprs) override;
1829288943Sdim
1830276479Sdim  void ReadTentativeDefinitions(
1831276479Sdim                            SmallVectorImpl<VarDecl *> &TentativeDefs) override;
1832226633Sdim
1833276479Sdim  void ReadUnusedFileScopedDecls(
1834276479Sdim                       SmallVectorImpl<const DeclaratorDecl *> &Decls) override;
1835226633Sdim
1836276479Sdim  void ReadDelegatingConstructors(
1837276479Sdim                         SmallVectorImpl<CXXConstructorDecl *> &Decls) override;
1838226633Sdim
1839276479Sdim  void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) override;
1840226633Sdim
1841280031Sdim  void ReadUnusedLocalTypedefNameCandidates(
1842280031Sdim      llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override;
1843280031Sdim
1844276479Sdim  void ReadReferencedSelectors(
1845276479Sdim          SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) override;
1846226633Sdim
1847276479Sdim  void ReadWeakUndeclaredIdentifiers(
1848276479Sdim          SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI) override;
1849226633Sdim
1850276479Sdim  void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override;
1851226633Sdim
1852276479Sdim  void ReadPendingInstantiations(
1853234353Sdim                 SmallVectorImpl<std::pair<ValueDecl *,
1854276479Sdim                                           SourceLocation> > &Pending) override;
1855226633Sdim
1856276479Sdim  void ReadLateParsedTemplates(
1857288943Sdim      llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap)
1858288943Sdim      override;
1859261991Sdim
1860212795Sdim  /// \brief Load a selector from disk, registering its ID if it exists.
1861212795Sdim  void LoadSelector(Selector Sel);
1862212795Sdim
1863212795Sdim  void SetIdentifierInfo(unsigned ID, IdentifierInfo *II);
1864212795Sdim  void SetGloballyVisibleDecls(IdentifierInfo *II,
1865226633Sdim                               const SmallVectorImpl<uint32_t> &DeclIDs,
1866276479Sdim                               SmallVectorImpl<Decl *> *Decls = nullptr);
1867212795Sdim
1868212795Sdim  /// \brief Report a diagnostic.
1869212795Sdim  DiagnosticBuilder Diag(unsigned DiagID);
1870212795Sdim
1871212795Sdim  /// \brief Report a diagnostic.
1872212795Sdim  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
1873212795Sdim
1874226633Sdim  IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID);
1875212795Sdim
1876234353Sdim  IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record,
1877226633Sdim                                    unsigned &Idx) {
1878226633Sdim    return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++]));
1879212795Sdim  }
1880212795Sdim
1881276479Sdim  IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) override {
1882243830Sdim    // Note that we are loading an identifier.
1883243830Sdim    Deserializing AnIdentifier(this);
1884243830Sdim
1885212795Sdim    return DecodeIdentifierInfo(ID);
1886212795Sdim  }
1887212795Sdim
1888234353Sdim  IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID);
1889234353Sdim
1890234353Sdim  serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M,
1891226633Sdim                                                    unsigned LocalID);
1892234353Sdim
1893249423Sdim  void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo);
1894249423Sdim
1895243830Sdim  /// \brief Retrieve the macro with the given ID.
1896249423Sdim  MacroInfo *getMacro(serialization::MacroID ID);
1897243830Sdim
1898243830Sdim  /// \brief Retrieve the global macro ID corresponding to the given local
1899243830Sdim  /// ID within the given module file.
1900243830Sdim  serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID);
1901243830Sdim
1902212795Sdim  /// \brief Read the source location entry with index ID.
1903276479Sdim  bool ReadSLocEntry(int ID) override;
1904212795Sdim
1905249423Sdim  /// \brief Retrieve the module import location and module name for the
1906249423Sdim  /// given source manager entry ID.
1907276479Sdim  std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID) override;
1908249423Sdim
1909234353Sdim  /// \brief Retrieve the global submodule ID given a module and its local ID
1910234353Sdim  /// number.
1911234353Sdim  serialization::SubmoduleID
1912234353Sdim  getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID);
1913234353Sdim
1914234353Sdim  /// \brief Retrieve the submodule that corresponds to a global submodule ID.
1915234353Sdim  ///
1916234353Sdim  Module *getSubmodule(serialization::SubmoduleID GlobalID);
1917249423Sdim
1918249423Sdim  /// \brief Retrieve the module that corresponds to the given module ID.
1919249423Sdim  ///
1920249423Sdim  /// Note: overrides method in ExternalASTSource
1921276479Sdim  Module *getModule(unsigned ID) override;
1922249423Sdim
1923296417Sdim  /// \brief Retrieve the module file with a given local ID within the specified
1924296417Sdim  /// ModuleFile.
1925296417Sdim  ModuleFile *getLocalModuleFile(ModuleFile &M, unsigned ID);
1926296417Sdim
1927296417Sdim  /// \brief Get an ID for the given module file.
1928296417Sdim  unsigned getModuleFileID(ModuleFile *M);
1929296417Sdim
1930288943Sdim  /// \brief Return a descriptor for the corresponding module.
1931288943Sdim  llvm::Optional<ASTSourceDescriptor> getSourceDescriptor(unsigned ID) override;
1932288943Sdim
1933226633Sdim  /// \brief Retrieve a selector from the given module with its local ID
1934226633Sdim  /// number.
1935234353Sdim  Selector getLocalSelector(ModuleFile &M, unsigned LocalID);
1936212795Sdim
1937226633Sdim  Selector DecodeSelector(serialization::SelectorID Idx);
1938226633Sdim
1939276479Sdim  Selector GetExternalSelector(serialization::SelectorID ID) override;
1940276479Sdim  uint32_t GetNumExternalSelectors() override;
1941212795Sdim
1942234353Sdim  Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) {
1943226633Sdim    return getLocalSelector(M, Record[Idx++]);
1944212795Sdim  }
1945234353Sdim
1946226633Sdim  /// \brief Retrieve the global selector ID that corresponds to this
1947226633Sdim  /// the local selector ID in a given module.
1948234353Sdim  serialization::SelectorID getGlobalSelectorID(ModuleFile &F,
1949226633Sdim                                                unsigned LocalID) const;
1950212795Sdim
1951212795Sdim  /// \brief Read a declaration name.
1952234353Sdim  DeclarationName ReadDeclarationName(ModuleFile &F,
1953226633Sdim                                      const RecordData &Record, unsigned &Idx);
1954234353Sdim  void ReadDeclarationNameLoc(ModuleFile &F,
1955218893Sdim                              DeclarationNameLoc &DNLoc, DeclarationName Name,
1956218893Sdim                              const RecordData &Record, unsigned &Idx);
1957234353Sdim  void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo,
1958218893Sdim                               const RecordData &Record, unsigned &Idx);
1959212795Sdim
1960234353Sdim  void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info,
1961218893Sdim                         const RecordData &Record, unsigned &Idx);
1962218893Sdim
1963234353Sdim  NestedNameSpecifier *ReadNestedNameSpecifier(ModuleFile &F,
1964226633Sdim                                               const RecordData &Record,
1965212795Sdim                                               unsigned &Idx);
1966212795Sdim
1967234353Sdim  NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F,
1968219077Sdim                                                    const RecordData &Record,
1969219077Sdim                                                    unsigned &Idx);
1970219077Sdim
1971212795Sdim  /// \brief Read a template name.
1972234353Sdim  TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record,
1973218893Sdim                                unsigned &Idx);
1974212795Sdim
1975212795Sdim  /// \brief Read a template argument.
1976296417Sdim  TemplateArgument ReadTemplateArgument(ModuleFile &F, const RecordData &Record,
1977296417Sdim                                        unsigned &Idx,
1978296417Sdim                                        bool Canonicalize = false);
1979234353Sdim
1980212795Sdim  /// \brief Read a template parameter list.
1981234353Sdim  TemplateParameterList *ReadTemplateParameterList(ModuleFile &F,
1982218893Sdim                                                   const RecordData &Record,
1983212795Sdim                                                   unsigned &Idx);
1984234353Sdim
1985212795Sdim  /// \brief Read a template argument array.
1986296417Sdim  void ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs,
1987296417Sdim                                ModuleFile &F, const RecordData &Record,
1988296417Sdim                                unsigned &Idx, bool Canonicalize = false);
1989212795Sdim
1990212795Sdim  /// \brief Read a UnresolvedSet structure.
1991261991Sdim  void ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set,
1992212795Sdim                         const RecordData &Record, unsigned &Idx);
1993212795Sdim
1994212795Sdim  /// \brief Read a C++ base specifier.
1995234353Sdim  CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F,
1996212795Sdim                                        const RecordData &Record,unsigned &Idx);
1997212795Sdim
1998218893Sdim  /// \brief Read a CXXCtorInitializer array.
1999288943Sdim  CXXCtorInitializer **
2000234353Sdim  ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record,
2001218893Sdim                          unsigned &Idx);
2002212795Sdim
2003288943Sdim  /// \brief Read the contents of a CXXCtorInitializer array.
2004288943Sdim  CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override;
2005288943Sdim
2006309124Sdim  /// \brief Read a source location from raw form and return it in its
2007309124Sdim  /// originating module file's source location space.
2008309124Sdim  SourceLocation ReadUntranslatedSourceLocation(uint32_t Raw) const {
2009309124Sdim    return SourceLocation::getFromRawEncoding((Raw >> 1) | (Raw << 31));
2010309124Sdim  }
2011309124Sdim
2012218893Sdim  /// \brief Read a source location from raw form.
2013309124Sdim  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, uint32_t Raw) const {
2014309124Sdim    SourceLocation Loc = ReadUntranslatedSourceLocation(Raw);
2015309124Sdim    return TranslateSourceLocation(ModuleFile, Loc);
2016309124Sdim  }
2017309124Sdim
2018309124Sdim  /// \brief Translate a source location from another module file's source
2019309124Sdim  /// location space into ours.
2020309124Sdim  SourceLocation TranslateSourceLocation(ModuleFile &ModuleFile,
2021309124Sdim                                         SourceLocation Loc) const {
2022309124Sdim    assert(ModuleFile.SLocRemap.find(Loc.getOffset()) !=
2023309124Sdim               ModuleFile.SLocRemap.end() &&
2024226633Sdim           "Cannot find offset to remap.");
2025234353Sdim    int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second;
2026226633Sdim    return Loc.getLocWithOffset(Remap);
2027218893Sdim  }
2028218893Sdim
2029212795Sdim  /// \brief Read a source location.
2030234353Sdim  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
2031261991Sdim                                    const RecordDataImpl &Record,
2032261991Sdim                                    unsigned &Idx) {
2033234353Sdim    return ReadSourceLocation(ModuleFile, Record[Idx++]);
2034212795Sdim  }
2035212795Sdim
2036212795Sdim  /// \brief Read a source range.
2037234353Sdim  SourceRange ReadSourceRange(ModuleFile &F,
2038249423Sdim                              const RecordData &Record, unsigned &Idx);
2039212795Sdim
2040212795Sdim  /// \brief Read an integral value
2041212795Sdim  llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx);
2042212795Sdim
2043212795Sdim  /// \brief Read a signed integral value
2044212795Sdim  llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx);
2045212795Sdim
2046212795Sdim  /// \brief Read a floating-point value
2047249423Sdim  llvm::APFloat ReadAPFloat(const RecordData &Record,
2048249423Sdim                            const llvm::fltSemantics &Sem, unsigned &Idx);
2049212795Sdim
2050212795Sdim  // \brief Read a string
2051243830Sdim  static std::string ReadString(const RecordData &Record, unsigned &Idx);
2052212795Sdim
2053280031Sdim  // \brief Read a path
2054280031Sdim  std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx);
2055280031Sdim
2056221345Sdim  /// \brief Read a version tuple.
2057243830Sdim  static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx);
2058221345Sdim
2059234353Sdim  CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record,
2060226633Sdim                                 unsigned &Idx);
2061234353Sdim
2062212795Sdim  /// \brief Reads attributes from the current stream position.
2063234353Sdim  void ReadAttributes(ModuleFile &F, AttrVec &Attrs,
2064218893Sdim                      const RecordData &Record, unsigned &Idx);
2065212795Sdim
2066212795Sdim  /// \brief Reads a statement.
2067234353Sdim  Stmt *ReadStmt(ModuleFile &F);
2068212795Sdim
2069212795Sdim  /// \brief Reads an expression.
2070234353Sdim  Expr *ReadExpr(ModuleFile &F);
2071212795Sdim
2072212795Sdim  /// \brief Reads a sub-statement operand during statement reading.
2073212795Sdim  Stmt *ReadSubStmt() {
2074212795Sdim    assert(ReadingKind == Read_Stmt &&
2075212795Sdim           "Should be called only during statement reading!");
2076212795Sdim    // Subexpressions are stored from last to first, so the next Stmt we need
2077212795Sdim    // is at the back of the stack.
2078276479Sdim    assert(!StmtStack.empty() && "Read too many sub-statements!");
2079212795Sdim    return StmtStack.pop_back_val();
2080212795Sdim  }
2081212795Sdim
2082212795Sdim  /// \brief Reads a sub-expression operand during statement reading.
2083212795Sdim  Expr *ReadSubExpr();
2084212795Sdim
2085251662Sdim  /// \brief Reads a token out of a record.
2086261991Sdim  Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx);
2087251662Sdim
2088212795Sdim  /// \brief Reads the macro record located at the given offset.
2089249423Sdim  MacroInfo *ReadMacroRecord(ModuleFile &F, uint64_t Offset);
2090234353Sdim
2091226633Sdim  /// \brief Determine the global preprocessed entity ID that corresponds to
2092226633Sdim  /// the given local ID within the given module.
2093234353Sdim  serialization::PreprocessedEntityID
2094234353Sdim  getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const;
2095234353Sdim
2096288943Sdim  /// \brief Add a macro to deserialize its macro directive history.
2097234353Sdim  ///
2098234353Sdim  /// \param II The name of the macro.
2099249423Sdim  /// \param M The module file.
2100249423Sdim  /// \param MacroDirectivesOffset Offset of the serialized macro directive
2101249423Sdim  /// history.
2102288943Sdim  void addPendingMacro(IdentifierInfo *II, ModuleFile *M,
2103288943Sdim                       uint64_t MacroDirectivesOffset);
2104234353Sdim
2105212795Sdim  /// \brief Read the set of macros defined by this external macro source.
2106276479Sdim  void ReadDefinedMacros() override;
2107212795Sdim
2108234353Sdim  /// \brief Update an out-of-date identifier.
2109276479Sdim  void updateOutOfDateIdentifier(IdentifierInfo &II) override;
2110234353Sdim
2111234353Sdim  /// \brief Note that this identifier is up-to-date.
2112234353Sdim  void markIdentifierUpToDate(IdentifierInfo *II);
2113234353Sdim
2114234353Sdim  /// \brief Load all external visible decls in the given DeclContext.
2115276479Sdim  void completeVisibleDeclsMap(const DeclContext *DC) override;
2116234353Sdim
2117212795Sdim  /// \brief Retrieve the AST context that this AST reader supplements.
2118226633Sdim  ASTContext &getContext() { return Context; }
2119212795Sdim
2120280031Sdim  // \brief Contains the IDs for declarations that were requested before we have
2121212795Sdim  // access to a Sema object.
2122280031Sdim  SmallVector<uint64_t, 16> PreloadedDeclIDs;
2123212795Sdim
2124212795Sdim  /// \brief Retrieve the semantic analysis object used to analyze the
2125212795Sdim  /// translation unit in which the precompiled header is being
2126212795Sdim  /// imported.
2127212795Sdim  Sema *getSema() { return SemaObj; }
2128212795Sdim
2129309124Sdim  /// \brief Get the identifier resolver used for name lookup / updates
2130309124Sdim  /// in the translation unit scope. We have one of these even if we don't
2131309124Sdim  /// have a Sema object.
2132309124Sdim  IdentifierResolver &getIdResolver();
2133309124Sdim
2134212795Sdim  /// \brief Retrieve the identifier table associated with the
2135212795Sdim  /// preprocessor.
2136212795Sdim  IdentifierTable &getIdentifierTable();
2137212795Sdim
2138212795Sdim  /// \brief Record that the given ID maps to the given switch-case
2139212795Sdim  /// statement.
2140212795Sdim  void RecordSwitchCaseID(SwitchCase *SC, unsigned ID);
2141212795Sdim
2142212795Sdim  /// \brief Retrieve the switch-case statement with the given ID.
2143212795Sdim  SwitchCase *getSwitchCaseWithID(unsigned ID);
2144212795Sdim
2145218893Sdim  void ClearSwitchCaseIDs();
2146239462Sdim
2147239462Sdim  /// \brief Cursors for comments blocks.
2148239462Sdim  SmallVector<std::pair<llvm::BitstreamCursor,
2149239462Sdim                        serialization::ModuleFile *>, 8> CommentsCursors;
2150239462Sdim
2151296417Sdim  /// \brief Loads comments ranges.
2152276479Sdim  void ReadComments() override;
2153309124Sdim
2154309124Sdim  bool isProcessingUpdateRecords() { return ProcessingUpdateRecords; }
2155212795Sdim};
2156212795Sdim
2157212795Sdim/// \brief Helper class that saves the current stream position and
2158212795Sdim/// then restores it when destroyed.
2159212795Sdimstruct SavedStreamPosition {
2160212795Sdim  explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor)
2161249423Sdim    : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) { }
2162212795Sdim
2163212795Sdim  ~SavedStreamPosition() {
2164212795Sdim    Cursor.JumpToBit(Offset);
2165212795Sdim  }
2166212795Sdim
2167212795Sdimprivate:
2168212795Sdim  llvm::BitstreamCursor &Cursor;
2169212795Sdim  uint64_t Offset;
2170212795Sdim};
2171212795Sdim
2172212795Sdiminline void PCHValidator::Error(const char *Msg) {
2173212795Sdim  Reader.Error(Msg);
2174212795Sdim}
2175212795Sdim
2176212795Sdim} // end namespace clang
2177212795Sdim
2178212795Sdim#endif
2179