ASTReader.h revision 280031
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"
30249423Sdim#include "clang/Serialization/ASTBitCodes.h"
31249423Sdim#include "clang/Serialization/ContinuousRangeMap.h"
32249423Sdim#include "clang/Serialization/Module.h"
33249423Sdim#include "clang/Serialization/ModuleManager.h"
34212795Sdim#include "llvm/ADT/APFloat.h"
35212795Sdim#include "llvm/ADT/APInt.h"
36212795Sdim#include "llvm/ADT/APSInt.h"
37243830Sdim#include "llvm/ADT/MapVector.h"
38234353Sdim#include "llvm/ADT/SmallPtrSet.h"
39234353Sdim#include "llvm/ADT/SmallSet.h"
40212795Sdim#include "llvm/ADT/SmallVector.h"
41212795Sdim#include "llvm/ADT/StringRef.h"
42276479Sdim#include "llvm/ADT/TinyPtrVector.h"
43212795Sdim#include "llvm/Bitcode/BitstreamReader.h"
44218893Sdim#include "llvm/Support/DataTypes.h"
45212795Sdim#include <deque>
46212795Sdim#include <map>
47276479Sdim#include <memory>
48212795Sdim#include <string>
49212795Sdim#include <utility>
50212795Sdim#include <vector>
51212795Sdim
52212795Sdimnamespace llvm {
53212795Sdim  class MemoryBuffer;
54212795Sdim}
55212795Sdim
56212795Sdimnamespace clang {
57212795Sdim
58212795Sdimclass AddrLabelExpr;
59212795Sdimclass ASTConsumer;
60212795Sdimclass ASTContext;
61218893Sdimclass ASTIdentifierIterator;
62226633Sdimclass ASTUnit; // FIXME: Layering violation and egregious hack.
63212795Sdimclass Attr;
64212795Sdimclass Decl;
65212795Sdimclass DeclContext;
66276479Sdimclass DefMacroDirective;
67243830Sdimclass DiagnosticOptions;
68212795Sdimclass NestedNameSpecifier;
69212795Sdimclass CXXBaseSpecifier;
70223017Sdimclass CXXConstructorDecl;
71218893Sdimclass CXXCtorInitializer;
72249423Sdimclass GlobalModuleIndex;
73212795Sdimclass GotoStmt;
74212795Sdimclass MacroDefinition;
75249423Sdimclass MacroDirective;
76212795Sdimclass NamedDecl;
77218893Sdimclass OpaqueValueExpr;
78212795Sdimclass Preprocessor;
79243830Sdimclass PreprocessorOptions;
80212795Sdimclass Sema;
81212795Sdimclass SwitchCase;
82218893Sdimclass ASTDeserializationListener;
83226633Sdimclass ASTWriter;
84212795Sdimclass ASTReader;
85212795Sdimclass ASTDeclReader;
86218893Sdimclass ASTStmtReader;
87218893Sdimclass TypeLocReader;
88212795Sdimstruct HeaderFileInfo;
89221345Sdimclass VersionTuple;
90243830Sdimclass TargetOptions;
91261991Sdimclass LazyASTUnresolvedSet;
92212795Sdim
93212795Sdim/// \brief Abstract interface for callback invocations by the ASTReader.
94212795Sdim///
95212795Sdim/// While reading an AST file, the ASTReader will call the methods of the
96212795Sdim/// listener to pass on specific information. Some of the listener methods can
97212795Sdim/// return true to indicate to the ASTReader that the information (and
98212795Sdim/// consequently the AST file) is invalid.
99212795Sdimclass ASTReaderListener {
100212795Sdimpublic:
101212795Sdim  virtual ~ASTReaderListener();
102212795Sdim
103249423Sdim  /// \brief Receives the full Clang version information.
104249423Sdim  ///
105249423Sdim  /// \returns true to indicate that the version is invalid. Subclasses should
106249423Sdim  /// generally defer to this implementation.
107249423Sdim  virtual bool ReadFullVersionInformation(StringRef FullVersion) {
108249423Sdim    return FullVersion != getClangFullRepositoryVersion();
109249423Sdim  }
110249423Sdim
111276479Sdim  virtual void ReadModuleName(StringRef ModuleName) {}
112276479Sdim  virtual void ReadModuleMapFile(StringRef ModuleMapPath) {}
113276479Sdim
114212795Sdim  /// \brief Receives the language options.
115212795Sdim  ///
116212795Sdim  /// \returns true to indicate the options are invalid or false otherwise.
117243830Sdim  virtual bool ReadLanguageOptions(const LangOptions &LangOpts,
118280031Sdim                                   bool Complain,
119280031Sdim                                   bool AllowCompatibleDifferences) {
120212795Sdim    return false;
121212795Sdim  }
122212795Sdim
123243830Sdim  /// \brief Receives the target options.
124212795Sdim  ///
125243830Sdim  /// \returns true to indicate the target options are invalid, or false
126243830Sdim  /// otherwise.
127243830Sdim  virtual bool ReadTargetOptions(const TargetOptions &TargetOpts,
128243830Sdim                                 bool Complain) {
129212795Sdim    return false;
130212795Sdim  }
131212795Sdim
132243830Sdim  /// \brief Receives the diagnostic options.
133212795Sdim  ///
134243830Sdim  /// \returns true to indicate the diagnostic options are invalid, or false
135243830Sdim  /// otherwise.
136276479Sdim  virtual bool
137276479Sdim  ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
138276479Sdim                        bool Complain) {
139243830Sdim    return false;
140243830Sdim  }
141243830Sdim
142243830Sdim  /// \brief Receives the file system options.
143212795Sdim  ///
144243830Sdim  /// \returns true to indicate the file system options are invalid, or false
145243830Sdim  /// otherwise.
146243830Sdim  virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
147243830Sdim                                     bool Complain) {
148243830Sdim    return false;
149243830Sdim  }
150243830Sdim
151243830Sdim  /// \brief Receives the header search options.
152212795Sdim  ///
153243830Sdim  /// \returns true to indicate the header search options are invalid, or false
154243830Sdim  /// otherwise.
155243830Sdim  virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
156243830Sdim                                       bool Complain) {
157243830Sdim    return false;
158243830Sdim  }
159243830Sdim
160243830Sdim  /// \brief Receives the preprocessor options.
161212795Sdim  ///
162243830Sdim  /// \param SuggestedPredefines Can be filled in with the set of predefines
163243830Sdim  /// that are suggested by the preprocessor options. Typically only used when
164243830Sdim  /// loading a precompiled header.
165243830Sdim  ///
166243830Sdim  /// \returns true to indicate the preprocessor options are invalid, or false
167243830Sdim  /// otherwise.
168243830Sdim  virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
169243830Sdim                                       bool Complain,
170243830Sdim                                       std::string &SuggestedPredefines) {
171212795Sdim    return false;
172212795Sdim  }
173212795Sdim
174212795Sdim  /// \brief Receives __COUNTER__ value.
175243830Sdim  virtual void ReadCounter(const serialization::ModuleFile &M,
176243830Sdim                           unsigned Value) {}
177251662Sdim
178276479Sdim  /// This is called for each AST file loaded.
179276479Sdim  virtual void visitModuleFile(StringRef Filename) {}
180276479Sdim
181251662Sdim  /// \brief Returns true if this \c ASTReaderListener wants to receive the
182251662Sdim  /// input files of the AST file via \c visitInputFile, false otherwise.
183251662Sdim  virtual bool needsInputFileVisitation() { return false; }
184276479Sdim  /// \brief Returns true if this \c ASTReaderListener wants to receive the
185276479Sdim  /// system input files of the AST file via \c visitInputFile, false otherwise.
186276479Sdim  virtual bool needsSystemInputFileVisitation() { return false; }
187276479Sdim  /// \brief if \c needsInputFileVisitation returns true, this is called for
188276479Sdim  /// each non-system input file of the AST File. If
189276479Sdim  /// \c needsSystemInputFileVisitation is true, then it is called for all
190276479Sdim  /// system input files as well.
191251662Sdim  ///
192251662Sdim  /// \returns true to continue receiving the next input file, false to stop.
193276479Sdim  virtual bool visitInputFile(StringRef Filename, bool isSystem,
194276479Sdim                              bool isOverridden) {
195276479Sdim    return true;
196276479Sdim  }
197280031Sdim
198280031Sdim  /// \brief Returns true if this \c ASTReaderListener wants to receive the
199280031Sdim  /// imports of the AST file via \c visitImport, false otherwise.
200280031Sdim  virtual bool needsImportVisitation() const { return false; }
201280031Sdim  /// \brief If needsImportVisitation returns \c true, this is called for each
202280031Sdim  /// AST file imported by this AST file.
203280031Sdim  virtual void visitImport(StringRef Filename) {}
204212795Sdim};
205212795Sdim
206276479Sdim/// \brief Simple wrapper class for chaining listeners.
207276479Sdimclass ChainedASTReaderListener : public ASTReaderListener {
208276479Sdim  std::unique_ptr<ASTReaderListener> First;
209276479Sdim  std::unique_ptr<ASTReaderListener> Second;
210276479Sdim
211276479Sdimpublic:
212276479Sdim  /// Takes ownership of \p First and \p Second.
213280031Sdim  ChainedASTReaderListener(std::unique_ptr<ASTReaderListener> First,
214280031Sdim                           std::unique_ptr<ASTReaderListener> Second)
215280031Sdim      : First(std::move(First)), Second(std::move(Second)) {}
216276479Sdim
217280031Sdim  std::unique_ptr<ASTReaderListener> takeFirst() { return std::move(First); }
218280031Sdim  std::unique_ptr<ASTReaderListener> takeSecond() { return std::move(Second); }
219280031Sdim
220276479Sdim  bool ReadFullVersionInformation(StringRef FullVersion) override;
221276479Sdim  void ReadModuleName(StringRef ModuleName) override;
222276479Sdim  void ReadModuleMapFile(StringRef ModuleMapPath) override;
223280031Sdim  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
224280031Sdim                           bool AllowCompatibleDifferences) override;
225276479Sdim  bool ReadTargetOptions(const TargetOptions &TargetOpts,
226276479Sdim                         bool Complain) override;
227276479Sdim  bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
228276479Sdim                             bool Complain) override;
229276479Sdim  bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
230276479Sdim                             bool Complain) override;
231276479Sdim
232276479Sdim  bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
233276479Sdim                               bool Complain) override;
234276479Sdim  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
235276479Sdim                               bool Complain,
236276479Sdim                               std::string &SuggestedPredefines) override;
237276479Sdim
238276479Sdim  void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
239276479Sdim  bool needsInputFileVisitation() override;
240276479Sdim  bool needsSystemInputFileVisitation() override;
241276479Sdim  void visitModuleFile(StringRef Filename) override;
242276479Sdim  bool visitInputFile(StringRef Filename, bool isSystem,
243276479Sdim                      bool isOverridden) override;
244276479Sdim};
245276479Sdim
246212795Sdim/// \brief ASTReaderListener implementation to validate the information of
247212795Sdim/// the PCH file against an initialized Preprocessor.
248212795Sdimclass PCHValidator : public ASTReaderListener {
249212795Sdim  Preprocessor &PP;
250212795Sdim  ASTReader &Reader;
251212795Sdim
252212795Sdimpublic:
253212795Sdim  PCHValidator(Preprocessor &PP, ASTReader &Reader)
254261991Sdim    : PP(PP), Reader(Reader) {}
255212795Sdim
256280031Sdim  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
257280031Sdim                           bool AllowCompatibleDifferences) override;
258276479Sdim  bool ReadTargetOptions(const TargetOptions &TargetOpts,
259276479Sdim                         bool Complain) override;
260276479Sdim  bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
261276479Sdim                             bool Complain) override;
262276479Sdim  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain,
263276479Sdim                               std::string &SuggestedPredefines) override;
264276479Sdim  void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
265212795Sdim
266212795Sdimprivate:
267212795Sdim  void Error(const char *Msg);
268212795Sdim};
269212795Sdim
270234353Sdimnamespace serialization {
271226633Sdim
272226633Sdimclass ReadMethodPoolVisitor;
273234353Sdim
274226633Sdimnamespace reader {
275226633Sdim  class ASTIdentifierLookupTrait;
276234982Sdim  /// \brief The on-disk hash table used for the DeclContext's Name lookup table.
277276479Sdim  typedef llvm::OnDiskIterableChainedHashTable<ASTDeclContextNameLookupTrait>
278234982Sdim    ASTDeclContextNameLookupTable;
279226633Sdim}
280234353Sdim
281226633Sdim} // end namespace serialization
282234353Sdim
283212795Sdim/// \brief Reads an AST files chain containing the contents of a translation
284212795Sdim/// unit.
285212795Sdim///
286212795Sdim/// The ASTReader class reads bitstreams (produced by the ASTWriter
287212795Sdim/// class) containing the serialized representation of a given
288212795Sdim/// abstract syntax tree and its supporting data structures. An
289212795Sdim/// instance of the ASTReader can be attached to an ASTContext object,
290212795Sdim/// which will provide access to the contents of the AST files.
291212795Sdim///
292212795Sdim/// The AST reader provides lazy de-serialization of declarations, as
293212795Sdim/// required when traversing the AST. Only those AST nodes that are
294212795Sdim/// actually required will be de-serialized.
295212795Sdimclass ASTReader
296212795Sdim  : public ExternalPreprocessorSource,
297212795Sdim    public ExternalPreprocessingRecordSource,
298218893Sdim    public ExternalHeaderFileInfoSource,
299212795Sdim    public ExternalSemaSource,
300212795Sdim    public IdentifierInfoLookup,
301212795Sdim    public ExternalIdentifierLookup,
302234353Sdim    public ExternalSLocEntrySource
303218893Sdim{
304212795Sdimpublic:
305239462Sdim  typedef SmallVector<uint64_t, 64> RecordData;
306261991Sdim  typedef SmallVectorImpl<uint64_t> RecordDataImpl;
307239462Sdim
308243830Sdim  /// \brief The result of reading the control block of an AST file, which
309243830Sdim  /// can fail for various reasons.
310243830Sdim  enum ASTReadResult {
311243830Sdim    /// \brief The control block was read successfully. Aside from failures,
312243830Sdim    /// the AST file is safe to read into the current context.
313243830Sdim    Success,
314243830Sdim    /// \brief The AST file itself appears corrupted.
315243830Sdim    Failure,
316249423Sdim    /// \brief The AST file was missing.
317249423Sdim    Missing,
318243830Sdim    /// \brief The AST file is out-of-date relative to its input files,
319243830Sdim    /// and needs to be regenerated.
320243830Sdim    OutOfDate,
321243830Sdim    /// \brief The AST file was written by a different version of Clang.
322243830Sdim    VersionMismatch,
323243830Sdim    /// \brief The AST file was writtten with a different language/target
324243830Sdim    /// configuration.
325243830Sdim    ConfigurationMismatch,
326243830Sdim    /// \brief The AST file has errors.
327243830Sdim    HadErrors
328243830Sdim  };
329243830Sdim
330218893Sdim  /// \brief Types of AST files.
331212795Sdim  friend class PCHValidator;
332212795Sdim  friend class ASTDeclReader;
333218893Sdim  friend class ASTStmtReader;
334218893Sdim  friend class ASTIdentifierIterator;
335226633Sdim  friend class serialization::reader::ASTIdentifierLookupTrait;
336218893Sdim  friend class TypeLocReader;
337226633Sdim  friend class ASTWriter;
338226633Sdim  friend class ASTUnit; // ASTUnit needs to remap source locations.
339226633Sdim  friend class serialization::ReadMethodPoolVisitor;
340234353Sdim
341234353Sdim  typedef serialization::ModuleFile ModuleFile;
342226633Sdim  typedef serialization::ModuleKind ModuleKind;
343226633Sdim  typedef serialization::ModuleManager ModuleManager;
344234353Sdim
345226633Sdim  typedef ModuleManager::ModuleIterator ModuleIterator;
346226633Sdim  typedef ModuleManager::ModuleConstIterator ModuleConstIterator;
347226633Sdim  typedef ModuleManager::ModuleReverseIterator ModuleReverseIterator;
348226633Sdim
349212795Sdimprivate:
350212795Sdim  /// \brief The receiver of some callbacks invoked by ASTReader.
351276479Sdim  std::unique_ptr<ASTReaderListener> Listener;
352212795Sdim
353212795Sdim  /// \brief The receiver of deserialization events.
354212795Sdim  ASTDeserializationListener *DeserializationListener;
355276479Sdim  bool OwnsDeserializationListener;
356212795Sdim
357212795Sdim  SourceManager &SourceMgr;
358212795Sdim  FileManager &FileMgr;
359226633Sdim  DiagnosticsEngine &Diags;
360234353Sdim
361212795Sdim  /// \brief The semantic analysis object that will be processing the
362212795Sdim  /// AST files and the translation unit that uses it.
363212795Sdim  Sema *SemaObj;
364212795Sdim
365212795Sdim  /// \brief The preprocessor that will be loading the source file.
366226633Sdim  Preprocessor &PP;
367212795Sdim
368212795Sdim  /// \brief The AST context into which we'll read the AST files.
369226633Sdim  ASTContext &Context;
370234353Sdim
371212795Sdim  /// \brief The AST consumer.
372212795Sdim  ASTConsumer *Consumer;
373212795Sdim
374226633Sdim  /// \brief The module manager which manages modules and their dependencies
375226633Sdim  ModuleManager ModuleMgr;
376221345Sdim
377261991Sdim  /// \brief The location where the module file will be considered as
378261991Sdim  /// imported from. For non-module AST types it should be invalid.
379261991Sdim  SourceLocation CurrentImportLoc;
380261991Sdim
381249423Sdim  /// \brief The global module index, if loaded.
382276479Sdim  std::unique_ptr<GlobalModuleIndex> GlobalIndex;
383249423Sdim
384226633Sdim  /// \brief A map of global bit offsets to the module that stores entities
385226633Sdim  /// at those bit offsets.
386234353Sdim  ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap;
387212795Sdim
388226633Sdim  /// \brief A map of negated SLocEntryIDs to the modules containing them.
389234353Sdim  ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap;
390212795Sdim
391234353Sdim  typedef ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocOffsetMapType;
392234353Sdim
393226633Sdim  /// \brief A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset)
394226633Sdim  /// SourceLocation offsets to the modules containing them.
395226633Sdim  GlobalSLocOffsetMapType GlobalSLocOffsetMap;
396234353Sdim
397212795Sdim  /// \brief Types that have already been loaded from the chain.
398212795Sdim  ///
399212795Sdim  /// When the pointer at index I is non-NULL, the type with
400212795Sdim  /// ID = (I + 1) << FastQual::Width has already been loaded
401212795Sdim  std::vector<QualType> TypesLoaded;
402212795Sdim
403234353Sdim  typedef ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4>
404226633Sdim    GlobalTypeMapType;
405212795Sdim
406226633Sdim  /// \brief Mapping from global type IDs to the module in which the
407226633Sdim  /// type resides along with the offset that should be added to the
408226633Sdim  /// global type ID to produce a local ID.
409226633Sdim  GlobalTypeMapType GlobalTypeMap;
410226633Sdim
411212795Sdim  /// \brief Declarations that have already been loaded from the chain.
412212795Sdim  ///
413212795Sdim  /// When the pointer at index I is non-NULL, the declaration with ID
414212795Sdim  /// = I + 1 has already been loaded.
415212795Sdim  std::vector<Decl *> DeclsLoaded;
416212795Sdim
417234353Sdim  typedef ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4>
418226633Sdim    GlobalDeclMapType;
419234353Sdim
420226633Sdim  /// \brief Mapping from global declaration IDs to the module in which the
421226633Sdim  /// declaration resides.
422226633Sdim  GlobalDeclMapType GlobalDeclMap;
423234353Sdim
424234353Sdim  typedef std::pair<ModuleFile *, uint64_t> FileOffset;
425226633Sdim  typedef SmallVector<FileOffset, 2> FileOffsetsTy;
426218893Sdim  typedef llvm::DenseMap<serialization::DeclID, FileOffsetsTy>
427218893Sdim      DeclUpdateOffsetsMap;
428234353Sdim
429218893Sdim  /// \brief Declarations that have modifications residing in a later file
430218893Sdim  /// in the chain.
431218893Sdim  DeclUpdateOffsetsMap DeclUpdateOffsets;
432218893Sdim
433276479Sdim  /// \brief Declaration updates for already-loaded declarations that we need
434276479Sdim  /// to apply once we finish processing an import.
435276479Sdim  llvm::SmallVector<std::pair<serialization::GlobalDeclID, Decl*>, 16>
436276479Sdim      PendingUpdateRecords;
437276479Sdim
438234353Sdim  struct ReplacedDeclInfo {
439234353Sdim    ModuleFile *Mod;
440234353Sdim    uint64_t Offset;
441234353Sdim    unsigned RawLoc;
442234353Sdim
443276479Sdim    ReplacedDeclInfo() : Mod(nullptr), Offset(0), RawLoc(0) {}
444234353Sdim    ReplacedDeclInfo(ModuleFile *Mod, uint64_t Offset, unsigned RawLoc)
445234353Sdim      : Mod(Mod), Offset(Offset), RawLoc(RawLoc) {}
446234353Sdim  };
447234353Sdim
448234353Sdim  typedef llvm::DenseMap<serialization::DeclID, ReplacedDeclInfo>
449212795Sdim      DeclReplacementMap;
450212795Sdim  /// \brief Declarations that have been replaced in a later file in the chain.
451212795Sdim  DeclReplacementMap ReplacedDecls;
452212795Sdim
453280031Sdim  /// \brief Declarations that have been imported and have typedef names for
454280031Sdim  /// linkage purposes.
455280031Sdim  llvm::DenseMap<std::pair<DeclContext*, IdentifierInfo*>, NamedDecl*>
456280031Sdim      ImportedTypedefNamesForLinkage;
457280031Sdim
458280031Sdim  /// \brief Mergeable declaration contexts that have anonymous declarations
459280031Sdim  /// within them, and those anonymous declarations.
460280031Sdim  llvm::DenseMap<DeclContext*, llvm::SmallVector<NamedDecl*, 2>>
461280031Sdim    AnonymousDeclarationsForMerging;
462280031Sdim
463234353Sdim  struct FileDeclsInfo {
464234353Sdim    ModuleFile *Mod;
465234353Sdim    ArrayRef<serialization::LocalDeclID> Decls;
466234353Sdim
467276479Sdim    FileDeclsInfo() : Mod(nullptr) {}
468234353Sdim    FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls)
469234353Sdim      : Mod(Mod), Decls(Decls) {}
470234353Sdim  };
471234353Sdim
472234353Sdim  /// \brief Map from a FileID to the file-level declarations that it contains.
473234353Sdim  llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs;
474234353Sdim
475212795Sdim  // Updates for visible decls can occur for other contexts than just the
476212795Sdim  // TU, and when we read those update records, the actual context will not
477212795Sdim  // be available yet (unless it's the TU), so have this pending map using the
478212795Sdim  // ID as a key. It will be realized when the context is actually loaded.
479234982Sdim  typedef
480234982Sdim    SmallVector<std::pair<serialization::reader::ASTDeclContextNameLookupTable *,
481234982Sdim                          ModuleFile*>, 1> DeclContextVisibleUpdates;
482212795Sdim  typedef llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates>
483212795Sdim      DeclContextVisibleUpdatesPending;
484212795Sdim
485212795Sdim  /// \brief Updates to the visible declarations of declaration contexts that
486212795Sdim  /// haven't been loaded yet.
487212795Sdim  DeclContextVisibleUpdatesPending PendingVisibleUpdates;
488234353Sdim
489234353Sdim  /// \brief The set of C++ or Objective-C classes that have forward
490234353Sdim  /// declarations that have not yet been linked to their definitions.
491234353Sdim  llvm::SmallPtrSet<Decl *, 4> PendingDefinitions;
492243830Sdim
493243830Sdim  typedef llvm::MapVector<Decl *, uint64_t,
494243830Sdim                          llvm::SmallDenseMap<Decl *, unsigned, 4>,
495249423Sdim                          SmallVector<std::pair<Decl *, uint64_t>, 4> >
496243830Sdim    PendingBodiesMap;
497243830Sdim
498243830Sdim  /// \brief Functions or methods that have bodies that will be attached.
499243830Sdim  PendingBodiesMap PendingBodies;
500243830Sdim
501212795Sdim  /// \brief Read the records that describe the contents of declcontexts.
502234353Sdim  bool ReadDeclContextStorage(ModuleFile &M,
503226633Sdim                              llvm::BitstreamCursor &Cursor,
504212795Sdim                              const std::pair<uint64_t, uint64_t> &Offsets,
505226633Sdim                              serialization::DeclContextInfo &Info);
506212795Sdim
507212795Sdim  /// \brief A vector containing identifiers that have already been
508212795Sdim  /// loaded.
509212795Sdim  ///
510212795Sdim  /// If the pointer at index I is non-NULL, then it refers to the
511212795Sdim  /// IdentifierInfo for the identifier with ID=I+1 that has already
512212795Sdim  /// been loaded.
513212795Sdim  std::vector<IdentifierInfo *> IdentifiersLoaded;
514212795Sdim
515234353Sdim  typedef ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4>
516226633Sdim    GlobalIdentifierMapType;
517234353Sdim
518243830Sdim  /// \brief Mapping from global identifier IDs to the module in which the
519226633Sdim  /// identifier resides along with the offset that should be added to the
520226633Sdim  /// global identifier ID to produce a local ID.
521226633Sdim  GlobalIdentifierMapType GlobalIdentifierMap;
522226633Sdim
523243830Sdim  /// \brief A vector containing macros that have already been
524243830Sdim  /// loaded.
525243830Sdim  ///
526243830Sdim  /// If the pointer at index I is non-NULL, then it refers to the
527243830Sdim  /// MacroInfo for the identifier with ID=I+1 that has already
528243830Sdim  /// been loaded.
529243830Sdim  std::vector<MacroInfo *> MacrosLoaded;
530243830Sdim
531243830Sdim  typedef ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4>
532243830Sdim    GlobalMacroMapType;
533243830Sdim
534243830Sdim  /// \brief Mapping from global macro IDs to the module in which the
535243830Sdim  /// macro resides along with the offset that should be added to the
536243830Sdim  /// global macro ID to produce a local ID.
537243830Sdim  GlobalMacroMapType GlobalMacroMap;
538243830Sdim
539234353Sdim  /// \brief A vector containing submodules that have already been loaded.
540234353Sdim  ///
541234353Sdim  /// This vector is indexed by the Submodule ID (-1). NULL submodule entries
542234353Sdim  /// indicate that the particular submodule ID has not yet been loaded.
543234353Sdim  SmallVector<Module *, 2> SubmodulesLoaded;
544234353Sdim
545234353Sdim  typedef ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4>
546234353Sdim    GlobalSubmoduleMapType;
547234353Sdim
548234353Sdim  /// \brief Mapping from global submodule IDs to the module file in which the
549234353Sdim  /// submodule resides along with the offset that should be added to the
550234353Sdim  /// global submodule ID to produce a local ID.
551234353Sdim  GlobalSubmoduleMapType GlobalSubmoduleMap;
552234353Sdim
553276479Sdim  /// \brief Information on a macro definition or undefinition that is visible
554276479Sdim  /// at the end of a submodule.
555276479Sdim  struct ModuleMacroInfo;
556276479Sdim
557243830Sdim  /// \brief An entity that has been hidden.
558243830Sdim  class HiddenName {
559243830Sdim  public:
560243830Sdim    enum NameKind {
561243830Sdim      Declaration,
562276479Sdim      Macro
563243830Sdim    } Kind;
564243830Sdim
565243830Sdim  private:
566243830Sdim    union {
567243830Sdim      Decl *D;
568276479Sdim      ModuleMacroInfo *MMI;
569243830Sdim    };
570243830Sdim
571243830Sdim    IdentifierInfo *Id;
572243830Sdim
573243830Sdim  public:
574249423Sdim    HiddenName(Decl *D) : Kind(Declaration), D(D), Id() { }
575243830Sdim
576276479Sdim    HiddenName(IdentifierInfo *II, ModuleMacroInfo *MMI)
577276479Sdim      : Kind(Macro), MMI(MMI), Id(II) { }
578243830Sdim
579243830Sdim    NameKind getKind() const { return Kind; }
580243830Sdim
581243830Sdim    Decl *getDecl() const {
582243830Sdim      assert(getKind() == Declaration && "Hidden name is not a declaration");
583243830Sdim      return D;
584243830Sdim    }
585243830Sdim
586276479Sdim    std::pair<IdentifierInfo *, ModuleMacroInfo *> getMacro() const {
587276479Sdim      assert(getKind() == Macro && "Hidden name is not a macro!");
588276479Sdim      return std::make_pair(Id, MMI);
589243830Sdim    }
590276479Sdim  };
591243830Sdim
592276479Sdim  typedef llvm::SmallDenseMap<IdentifierInfo*,
593276479Sdim                              ModuleMacroInfo*> HiddenMacrosMap;
594276479Sdim
595234353Sdim  /// \brief A set of hidden declarations.
596276479Sdim  struct HiddenNames {
597276479Sdim    SmallVector<Decl*, 2> HiddenDecls;
598276479Sdim    HiddenMacrosMap HiddenMacros;
599276479Sdim  };
600276479Sdim
601234353Sdim  typedef llvm::DenseMap<Module *, HiddenNames> HiddenNamesMapType;
602234353Sdim
603234353Sdim  /// \brief A mapping from each of the hidden submodules to the deserialized
604234353Sdim  /// declarations in that submodule that could be made visible.
605234353Sdim  HiddenNamesMapType HiddenNamesMap;
606234353Sdim
607234353Sdim
608249423Sdim  /// \brief A module import, export, or conflict that hasn't yet been resolved.
609249423Sdim  struct UnresolvedModuleRef {
610234353Sdim    /// \brief The file in which this module resides.
611234353Sdim    ModuleFile *File;
612234353Sdim
613234353Sdim    /// \brief The module that is importing or exporting.
614234353Sdim    Module *Mod;
615249423Sdim
616249423Sdim    /// \brief The kind of module reference.
617249423Sdim    enum { Import, Export, Conflict } Kind;
618249423Sdim
619234353Sdim    /// \brief The local ID of the module that is being exported.
620234353Sdim    unsigned ID;
621249423Sdim
622234353Sdim    /// \brief Whether this is a wildcard export.
623234353Sdim    unsigned IsWildcard : 1;
624249423Sdim
625249423Sdim    /// \brief String data.
626249423Sdim    StringRef String;
627234353Sdim  };
628234353Sdim
629234353Sdim  /// \brief The set of module imports and exports that still need to be
630234353Sdim  /// resolved.
631249423Sdim  SmallVector<UnresolvedModuleRef, 2> UnresolvedModuleRefs;
632234353Sdim
633212795Sdim  /// \brief A vector containing selectors that have already been loaded.
634212795Sdim  ///
635212795Sdim  /// This vector is indexed by the Selector ID (-1). NULL selector
636212795Sdim  /// entries indicate that the particular selector ID has not yet
637212795Sdim  /// been loaded.
638226633Sdim  SmallVector<Selector, 16> SelectorsLoaded;
639212795Sdim
640234353Sdim  typedef ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4>
641226633Sdim    GlobalSelectorMapType;
642234353Sdim
643226633Sdim  /// \brief Mapping from global selector IDs to the module in which the
644249423Sdim
645226633Sdim  /// global selector ID to produce a local ID.
646226633Sdim  GlobalSelectorMapType GlobalSelectorMap;
647212795Sdim
648234353Sdim  /// \brief The generation number of the last time we loaded data from the
649234353Sdim  /// global method pool for this selector.
650234353Sdim  llvm::DenseMap<Selector, unsigned> SelectorGeneration;
651234353Sdim
652249423Sdim  struct PendingMacroInfo {
653249423Sdim    ModuleFile *M;
654249423Sdim
655249423Sdim    struct ModuleMacroDataTy {
656276479Sdim      uint32_t MacID;
657276479Sdim      serialization::SubmoduleID *Overrides;
658249423Sdim    };
659249423Sdim    struct PCHMacroDataTy {
660249423Sdim      uint64_t MacroDirectivesOffset;
661249423Sdim    };
662249423Sdim
663249423Sdim    union {
664249423Sdim      ModuleMacroDataTy ModuleMacroData;
665249423Sdim      PCHMacroDataTy PCHMacroData;
666249423Sdim    };
667249423Sdim
668249423Sdim    PendingMacroInfo(ModuleFile *M,
669276479Sdim                     uint32_t MacID,
670276479Sdim                     serialization::SubmoduleID *Overrides) : M(M) {
671276479Sdim      ModuleMacroData.MacID = MacID;
672276479Sdim      ModuleMacroData.Overrides = Overrides;
673249423Sdim    }
674249423Sdim
675249423Sdim    PendingMacroInfo(ModuleFile *M, uint64_t MacroDirectivesOffset) : M(M) {
676249423Sdim      PCHMacroData.MacroDirectivesOffset = MacroDirectivesOffset;
677249423Sdim    }
678249423Sdim  };
679249423Sdim
680249423Sdim  typedef llvm::MapVector<IdentifierInfo *, SmallVector<PendingMacroInfo, 2> >
681243830Sdim    PendingMacroIDsMap;
682226633Sdim
683243830Sdim  /// \brief Mapping from identifiers that have a macro history to the global
684243830Sdim  /// IDs have not yet been deserialized to the global IDs of those macros.
685243830Sdim  PendingMacroIDsMap PendingMacroIDs;
686243830Sdim
687234353Sdim  typedef ContinuousRangeMap<unsigned, ModuleFile *, 4>
688226633Sdim    GlobalPreprocessedEntityMapType;
689234353Sdim
690226633Sdim  /// \brief Mapping from global preprocessing entity IDs to the module in
691226633Sdim  /// which the preprocessed entity resides along with the offset that should be
692226633Sdim  /// added to the global preprocessing entitiy ID to produce a local ID.
693226633Sdim  GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
694234353Sdim
695212795Sdim  /// \name CodeGen-relevant special data
696212795Sdim  /// \brief Fields containing data that is relevant to CodeGen.
697212795Sdim  //@{
698212795Sdim
699212795Sdim  /// \brief The IDs of all declarations that fulfill the criteria of
700212795Sdim  /// "interesting" decls.
701212795Sdim  ///
702276479Sdim  /// This contains the data loaded from all EAGERLY_DESERIALIZED_DECLS blocks
703276479Sdim  /// in the chain. The referenced declarations are deserialized and passed to
704276479Sdim  /// the consumer eagerly.
705276479Sdim  SmallVector<uint64_t, 16> EagerlyDeserializedDecls;
706212795Sdim
707239462Sdim  /// \brief The IDs of all tentative definitions stored in the chain.
708212795Sdim  ///
709212795Sdim  /// Sema keeps track of all tentative definitions in a TU because it has to
710212795Sdim  /// complete them and pass them on to CodeGen. Thus, tentative definitions in
711212795Sdim  /// the PCH chain must be eagerly deserialized.
712226633Sdim  SmallVector<uint64_t, 16> TentativeDefinitions;
713212795Sdim
714212795Sdim  /// \brief The IDs of all CXXRecordDecls stored in the chain whose VTables are
715212795Sdim  /// used.
716212795Sdim  ///
717212795Sdim  /// CodeGen has to emit VTables for these records, so they have to be eagerly
718212795Sdim  /// deserialized.
719226633Sdim  SmallVector<uint64_t, 64> VTableUses;
720212795Sdim
721226633Sdim  /// \brief A snapshot of the pending instantiations in the chain.
722226633Sdim  ///
723226633Sdim  /// This record tracks the instantiations that Sema has to perform at the
724226633Sdim  /// end of the TU. It consists of a pair of values for every pending
725226633Sdim  /// instantiation where the first value is the ID of the decl and the second
726226633Sdim  /// is the instantiation location.
727226633Sdim  SmallVector<uint64_t, 64> PendingInstantiations;
728226633Sdim
729212795Sdim  //@}
730212795Sdim
731226633Sdim  /// \name DiagnosticsEngine-relevant special data
732212795Sdim  /// \brief Fields containing data that is used for generating diagnostics
733212795Sdim  //@{
734212795Sdim
735212795Sdim  /// \brief A snapshot of Sema's unused file-scoped variable tracking, for
736212795Sdim  /// generating warnings.
737226633Sdim  SmallVector<uint64_t, 16> UnusedFileScopedDecls;
738212795Sdim
739223017Sdim  /// \brief A list of all the delegating constructors we've seen, to diagnose
740223017Sdim  /// cycles.
741226633Sdim  SmallVector<uint64_t, 4> DelegatingCtorDecls;
742234353Sdim
743226633Sdim  /// \brief Method selectors used in a @selector expression. Used for
744226633Sdim  /// implementation of -Wselector.
745226633Sdim  SmallVector<uint64_t, 64> ReferencedSelectorsData;
746223017Sdim
747212795Sdim  /// \brief A snapshot of Sema's weak undeclared identifier tracking, for
748212795Sdim  /// generating warnings.
749226633Sdim  SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers;
750212795Sdim
751212795Sdim  /// \brief The IDs of type aliases for ext_vectors that exist in the chain.
752212795Sdim  ///
753212795Sdim  /// Used by Sema for finding sugared names for ext_vectors in diagnostics.
754226633Sdim  SmallVector<uint64_t, 4> ExtVectorDecls;
755212795Sdim
756212795Sdim  //@}
757212795Sdim
758212795Sdim  /// \name Sema-relevant special data
759212795Sdim  /// \brief Fields containing data that is used for semantic analysis
760212795Sdim  //@{
761212795Sdim
762249423Sdim  /// \brief The IDs of all locally scoped extern "C" decls in the chain.
763212795Sdim  ///
764212795Sdim  /// Sema tracks these to validate that the types are consistent across all
765249423Sdim  /// local extern "C" declarations.
766249423Sdim  SmallVector<uint64_t, 16> LocallyScopedExternCDecls;
767212795Sdim
768212795Sdim  /// \brief The IDs of all dynamic class declarations in the chain.
769212795Sdim  ///
770212795Sdim  /// Sema tracks these because it checks for the key functions being defined
771212795Sdim  /// at the end of the TU, in which case it directs CodeGen to emit the VTable.
772226633Sdim  SmallVector<uint64_t, 16> DynamicClasses;
773212795Sdim
774280031Sdim  /// \brief The IDs of all potentially unused typedef names in the chain.
775280031Sdim  ///
776280031Sdim  /// Sema tracks these to emit warnings.
777280031Sdim  SmallVector<uint64_t, 16> UnusedLocalTypedefNameCandidates;
778280031Sdim
779212795Sdim  /// \brief The IDs of the declarations Sema stores directly.
780212795Sdim  ///
781212795Sdim  /// Sema tracks a few important decls, such as namespace std, directly.
782226633Sdim  SmallVector<uint64_t, 4> SemaDeclRefs;
783212795Sdim
784212795Sdim  /// \brief The IDs of the types ASTContext stores directly.
785212795Sdim  ///
786212795Sdim  /// The AST context tracks a few important types, such as va_list, directly.
787226633Sdim  SmallVector<uint64_t, 16> SpecialTypes;
788212795Sdim
789218893Sdim  /// \brief The IDs of CUDA-specific declarations ASTContext stores directly.
790218893Sdim  ///
791218893Sdim  /// The AST context tracks a few important decls, currently cudaConfigureCall,
792218893Sdim  /// directly.
793226633Sdim  SmallVector<uint64_t, 2> CUDASpecialDeclRefs;
794218893Sdim
795218893Sdim  /// \brief The floating point pragma option settings.
796226633Sdim  SmallVector<uint64_t, 1> FPPragmaOptions;
797218893Sdim
798276479Sdim  /// \brief The pragma clang optimize location (if the pragma state is "off").
799276479Sdim  SourceLocation OptimizeOffPragmaLocation;
800276479Sdim
801218893Sdim  /// \brief The OpenCL extension settings.
802226633Sdim  SmallVector<uint64_t, 1> OpenCLExtensions;
803218893Sdim
804224145Sdim  /// \brief A list of the namespaces we've seen.
805226633Sdim  SmallVector<uint64_t, 4> KnownNamespaces;
806224145Sdim
807249423Sdim  /// \brief A list of undefined decls with internal linkage followed by the
808249423Sdim  /// SourceLocation of a matching ODR-use.
809249423Sdim  SmallVector<uint64_t, 8> UndefinedButUsed;
810249423Sdim
811261991Sdim  // \brief A list of late parsed template function data.
812261991Sdim  SmallVector<uint64_t, 1> LateParsedTemplates;
813261991Sdim
814276479Sdim  struct ImportedSubmodule {
815276479Sdim    serialization::SubmoduleID ID;
816276479Sdim    SourceLocation ImportLoc;
817276479Sdim
818276479Sdim    ImportedSubmodule(serialization::SubmoduleID ID, SourceLocation ImportLoc)
819276479Sdim      : ID(ID), ImportLoc(ImportLoc) {}
820276479Sdim  };
821276479Sdim
822234353Sdim  /// \brief A list of modules that were imported by precompiled headers or
823234353Sdim  /// any other non-module AST file.
824276479Sdim  SmallVector<ImportedSubmodule, 2> ImportedModules;
825212795Sdim  //@}
826212795Sdim
827218893Sdim  /// \brief The directory that the PCH we are reading is stored in.
828218893Sdim  std::string CurrentDir;
829218893Sdim
830212795Sdim  /// \brief The system include root to be used when loading the
831212795Sdim  /// precompiled header.
832226633Sdim  std::string isysroot;
833212795Sdim
834212795Sdim  /// \brief Whether to disable the normal validation performed on precompiled
835212795Sdim  /// headers when they are loaded.
836212795Sdim  bool DisableValidation;
837234353Sdim
838234353Sdim  /// \brief Whether to accept an AST file with compiler errors.
839234353Sdim  bool AllowASTWithCompilerErrors;
840234353Sdim
841276479Sdim  /// \brief Whether to accept an AST file that has a different configuration
842276479Sdim  /// from the current compiler instance.
843276479Sdim  bool AllowConfigurationMismatch;
844276479Sdim
845276479Sdim  /// \brief Whether validate system input files.
846276479Sdim  bool ValidateSystemInputs;
847276479Sdim
848249423Sdim  /// \brief Whether we are allowed to use the global module index.
849249423Sdim  bool UseGlobalIndex;
850249423Sdim
851249423Sdim  /// \brief Whether we have tried loading the global module index yet.
852249423Sdim  bool TriedLoadingGlobalIndex;
853249423Sdim
854239462Sdim  typedef llvm::DenseMap<unsigned, SwitchCase *> SwitchCaseMapTy;
855212795Sdim  /// \brief Mapping from switch-case IDs in the chain to switch-case statements
856212795Sdim  ///
857212795Sdim  /// Statements usually don't have IDs, but switch cases need them, so that the
858212795Sdim  /// switch statement can refer to them.
859239462Sdim  SwitchCaseMapTy SwitchCaseStmts;
860212795Sdim
861239462Sdim  SwitchCaseMapTy *CurrSwitchCaseStmts;
862239462Sdim
863212795Sdim  /// \brief The number of source location entries de-serialized from
864212795Sdim  /// the PCH file.
865212795Sdim  unsigned NumSLocEntriesRead;
866212795Sdim
867212795Sdim  /// \brief The number of source location entries in the chain.
868212795Sdim  unsigned TotalNumSLocEntries;
869212795Sdim
870212795Sdim  /// \brief The number of statements (and expressions) de-serialized
871212795Sdim  /// from the chain.
872212795Sdim  unsigned NumStatementsRead;
873212795Sdim
874212795Sdim  /// \brief The total number of statements (and expressions) stored
875212795Sdim  /// in the chain.
876212795Sdim  unsigned TotalNumStatements;
877212795Sdim
878212795Sdim  /// \brief The number of macros de-serialized from the chain.
879212795Sdim  unsigned NumMacrosRead;
880212795Sdim
881212795Sdim  /// \brief The total number of macros stored in the chain.
882212795Sdim  unsigned TotalNumMacros;
883212795Sdim
884249423Sdim  /// \brief The number of lookups into identifier tables.
885249423Sdim  unsigned NumIdentifierLookups;
886249423Sdim
887249423Sdim  /// \brief The number of lookups into identifier tables that succeed.
888249423Sdim  unsigned NumIdentifierLookupHits;
889249423Sdim
890212795Sdim  /// \brief The number of selectors that have been read.
891212795Sdim  unsigned NumSelectorsRead;
892212795Sdim
893212795Sdim  /// \brief The number of method pool entries that have been read.
894212795Sdim  unsigned NumMethodPoolEntriesRead;
895212795Sdim
896212795Sdim  /// \brief The number of times we have looked up a selector in the method
897249423Sdim  /// pool.
898249423Sdim  unsigned NumMethodPoolLookups;
899212795Sdim
900249423Sdim  /// \brief The number of times we have looked up a selector in the method
901249423Sdim  /// pool and found something.
902249423Sdim  unsigned NumMethodPoolHits;
903249423Sdim
904249423Sdim  /// \brief The number of times we have looked up a selector in the method
905249423Sdim  /// pool within a specific module.
906249423Sdim  unsigned NumMethodPoolTableLookups;
907249423Sdim
908249423Sdim  /// \brief The number of times we have looked up a selector in the method
909249423Sdim  /// pool within a specific module and found something.
910249423Sdim  unsigned NumMethodPoolTableHits;
911249423Sdim
912212795Sdim  /// \brief The total number of method pool entries in the selector table.
913212795Sdim  unsigned TotalNumMethodPoolEntries;
914212795Sdim
915212795Sdim  /// Number of lexical decl contexts read/total.
916212795Sdim  unsigned NumLexicalDeclContextsRead, TotalLexicalDeclContexts;
917212795Sdim
918212795Sdim  /// Number of visible decl contexts read/total.
919212795Sdim  unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts;
920234353Sdim
921226633Sdim  /// Total size of modules, in bits, currently loaded
922226633Sdim  uint64_t TotalModulesSizeInBits;
923226633Sdim
924212795Sdim  /// \brief Number of Decl/types that are currently deserializing.
925212795Sdim  unsigned NumCurrentElementsDeserializing;
926212795Sdim
927234353Sdim  /// \brief Set true while we are in the process of passing deserialized
928234353Sdim  /// "interesting" decls to consumer inside FinishedDeserializing().
929234353Sdim  /// This is used as a guard to avoid recursively repeating the process of
930234353Sdim  /// passing decls to consumer.
931234353Sdim  bool PassingDeclsToConsumer;
932234353Sdim
933226633Sdim  /// Number of CXX base specifiers currently loaded
934226633Sdim  unsigned NumCXXBaseSpecifiersLoaded;
935226633Sdim
936212795Sdim  /// \brief The set of identifiers that were read while the AST reader was
937212795Sdim  /// (recursively) loading declarations.
938212795Sdim  ///
939212795Sdim  /// The declarations on the identifier chain for these identifiers will be
940212795Sdim  /// loaded once the recursive loading has completed.
941249423Sdim  llvm::MapVector<IdentifierInfo *, SmallVector<uint32_t, 4> >
942249423Sdim    PendingIdentifierInfos;
943212795Sdim
944234353Sdim  /// \brief The generation number of each identifier, which keeps track of
945234353Sdim  /// the last time we loaded information about this identifier.
946234353Sdim  llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration;
947234353Sdim
948212795Sdim  /// \brief Contains declarations and definitions that will be
949212795Sdim  /// "interesting" to the ASTConsumer, when we get that AST consumer.
950212795Sdim  ///
951212795Sdim  /// "Interesting" declarations are those that have data that may
952212795Sdim  /// need to be emitted, such as inline function definitions or
953212795Sdim  /// Objective-C protocols.
954212795Sdim  std::deque<Decl *> InterestingDecls;
955212795Sdim
956243830Sdim  /// \brief The set of redeclarable declarations that have been deserialized
957234353Sdim  /// since the last time the declaration chains were linked.
958234353Sdim  llvm::SmallPtrSet<Decl *, 16> RedeclsDeserialized;
959234353Sdim
960234353Sdim  /// \brief The list of redeclaration chains that still need to be
961234353Sdim  /// reconstructed.
962234353Sdim  ///
963234353Sdim  /// Each element is the global declaration ID of the first declaration in
964234353Sdim  /// the chain. Elements in this vector should be unique; use
965234353Sdim  /// PendingDeclChainsKnown to ensure uniqueness.
966249423Sdim  SmallVector<serialization::DeclID, 16> PendingDeclChains;
967218893Sdim
968234353Sdim  /// \brief Keeps track of the elements added to PendingDeclChains.
969234353Sdim  llvm::SmallSet<serialization::DeclID, 16> PendingDeclChainsKnown;
970234353Sdim
971276479Sdim  /// \brief The list of canonical declarations whose redeclaration chains
972276479Sdim  /// need to be marked as incomplete once we're done deserializing things.
973276479Sdim  SmallVector<Decl *, 16> PendingIncompleteDeclChains;
974276479Sdim
975249423Sdim  /// \brief The Decl IDs for the Sema/Lexical DeclContext of a Decl that has
976249423Sdim  /// been loaded but its DeclContext was not set yet.
977249423Sdim  struct PendingDeclContextInfo {
978249423Sdim    Decl *D;
979249423Sdim    serialization::GlobalDeclID SemaDC;
980249423Sdim    serialization::GlobalDeclID LexicalDC;
981249423Sdim  };
982249423Sdim
983249423Sdim  /// \brief The set of Decls that have been loaded but their DeclContexts are
984249423Sdim  /// not set yet.
985249423Sdim  ///
986249423Sdim  /// The DeclContexts for these Decls will be set once recursive loading has
987249423Sdim  /// been completed.
988249423Sdim  std::deque<PendingDeclContextInfo> PendingDeclContextInfos;
989249423Sdim
990261991Sdim  /// \brief The set of NamedDecls that have been loaded, but are members of a
991261991Sdim  /// context that has been merged into another context where the corresponding
992261991Sdim  /// declaration is either missing or has not yet been loaded.
993261991Sdim  ///
994261991Sdim  /// We will check whether the corresponding declaration is in fact missing
995261991Sdim  /// once recursing loading has been completed.
996261991Sdim  llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks;
997261991Sdim
998276479Sdim  /// \brief Record definitions in which we found an ODR violation.
999276479Sdim  llvm::SmallDenseMap<CXXRecordDecl *, llvm::TinyPtrVector<CXXRecordDecl *>, 2>
1000276479Sdim      PendingOdrMergeFailures;
1001276479Sdim
1002276479Sdim  /// \brief DeclContexts in which we have diagnosed an ODR violation.
1003276479Sdim  llvm::SmallPtrSet<DeclContext*, 2> DiagnosedOdrMergeFailures;
1004276479Sdim
1005234353Sdim  /// \brief The set of Objective-C categories that have been deserialized
1006234353Sdim  /// since the last time the declaration chains were linked.
1007234353Sdim  llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized;
1008234353Sdim
1009234353Sdim  /// \brief The set of Objective-C class definitions that have already been
1010234353Sdim  /// loaded, for which we will need to check for categories whenever a new
1011234353Sdim  /// module is loaded.
1012249423Sdim  SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded;
1013276479Sdim
1014276479Sdim  /// \brief A mapping from a primary context for a declaration chain to the
1015276479Sdim  /// other declarations of that entity that also have name lookup tables.
1016276479Sdim  /// Used when we merge together two class definitions that have different
1017276479Sdim  /// sets of declared special member functions.
1018276479Sdim  llvm::DenseMap<const DeclContext*, SmallVector<const DeclContext*, 2>>
1019276479Sdim      MergedLookups;
1020276479Sdim
1021249423Sdim  typedef llvm::DenseMap<Decl *, SmallVector<serialization::DeclID, 2> >
1022234353Sdim    MergedDeclsMap;
1023234353Sdim
1024234353Sdim  /// \brief A mapping from canonical declarations to the set of additional
1025234353Sdim  /// (global, previously-canonical) declaration IDs that have been merged with
1026234353Sdim  /// that canonical declaration.
1027234353Sdim  MergedDeclsMap MergedDecls;
1028234353Sdim
1029234353Sdim  typedef llvm::DenseMap<serialization::GlobalDeclID,
1030249423Sdim                         SmallVector<serialization::DeclID, 2> >
1031234353Sdim    StoredMergedDeclsMap;
1032234353Sdim
1033234353Sdim  /// \brief A mapping from canonical declaration IDs to the set of additional
1034234353Sdim  /// declaration IDs that have been merged with that canonical declaration.
1035234353Sdim  ///
1036234353Sdim  /// This is the deserialized representation of the entries in MergedDecls.
1037234353Sdim  /// When we query entries in MergedDecls, they will be augmented with entries
1038234353Sdim  /// from StoredMergedDecls.
1039234353Sdim  StoredMergedDeclsMap StoredMergedDecls;
1040234353Sdim
1041234353Sdim  /// \brief Combine the stored merged declarations for the given canonical
1042234353Sdim  /// declaration into the set of merged declarations.
1043234353Sdim  ///
1044234353Sdim  /// \returns An iterator into MergedDecls that corresponds to the position of
1045234353Sdim  /// the given canonical declaration.
1046234353Sdim  MergedDeclsMap::iterator
1047234353Sdim  combineStoredMergedDecls(Decl *Canon, serialization::GlobalDeclID CanonID);
1048218893Sdim
1049261991Sdim  /// \brief A mapping from DeclContexts to the semantic DeclContext that we
1050261991Sdim  /// are treating as the definition of the entity. This is used, for instance,
1051261991Sdim  /// when merging implicit instantiations of class templates across modules.
1052261991Sdim  llvm::DenseMap<DeclContext *, DeclContext *> MergedDeclContexts;
1053261991Sdim
1054261991Sdim  /// \brief A mapping from canonical declarations of enums to their canonical
1055261991Sdim  /// definitions. Only populated when using modules in C++.
1056261991Sdim  llvm::DenseMap<EnumDecl *, EnumDecl *> EnumDefinitions;
1057261991Sdim
1058212795Sdim  /// \brief When reading a Stmt tree, Stmt operands are placed in this stack.
1059226633Sdim  SmallVector<Stmt *, 16> StmtStack;
1060212795Sdim
1061212795Sdim  /// \brief What kind of records we are reading.
1062212795Sdim  enum ReadingKind {
1063261991Sdim    Read_None, Read_Decl, Read_Type, Read_Stmt
1064212795Sdim  };
1065212795Sdim
1066234353Sdim  /// \brief What kind of records we are reading.
1067212795Sdim  ReadingKind ReadingKind;
1068212795Sdim
1069212795Sdim  /// \brief RAII object to change the reading kind.
1070212795Sdim  class ReadingKindTracker {
1071212795Sdim    ASTReader &Reader;
1072212795Sdim    enum ReadingKind PrevKind;
1073212795Sdim
1074243830Sdim    ReadingKindTracker(const ReadingKindTracker &) LLVM_DELETED_FUNCTION;
1075243830Sdim    void operator=(const ReadingKindTracker &) LLVM_DELETED_FUNCTION;
1076212795Sdim
1077212795Sdim  public:
1078212795Sdim    ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader)
1079212795Sdim      : Reader(reader), PrevKind(Reader.ReadingKind) {
1080212795Sdim      Reader.ReadingKind = newKind;
1081212795Sdim    }
1082212795Sdim
1083212795Sdim    ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; }
1084212795Sdim  };
1085212795Sdim
1086212795Sdim  /// \brief Suggested contents of the predefines buffer, after this
1087212795Sdim  /// PCH file has been processed.
1088212795Sdim  ///
1089212795Sdim  /// In most cases, this string will be empty, because the predefines
1090212795Sdim  /// buffer computed to build the PCH file will be identical to the
1091212795Sdim  /// predefines buffer computed from the command line. However, when
1092212795Sdim  /// there are differences that the PCH reader can work around, this
1093212795Sdim  /// predefines buffer may contain additional definitions.
1094212795Sdim  std::string SuggestedPredefines;
1095212795Sdim
1096212795Sdim  /// \brief Reads a statement from the specified cursor.
1097234353Sdim  Stmt *ReadStmtFromStream(ModuleFile &F);
1098212795Sdim
1099276479Sdim  struct InputFileInfo {
1100276479Sdim    std::string Filename;
1101276479Sdim    off_t StoredSize;
1102276479Sdim    time_t StoredTime;
1103276479Sdim    bool Overridden;
1104276479Sdim  };
1105276479Sdim
1106276479Sdim  /// \brief Reads the stored information about an input file.
1107276479Sdim  InputFileInfo readInputFileInfo(ModuleFile &F, unsigned ID);
1108276479Sdim  /// \brief A convenience method to read the filename from an input file.
1109276479Sdim  std::string getInputFileName(ModuleFile &F, unsigned ID);
1110276479Sdim
1111243830Sdim  /// \brief Retrieve the file entry and 'overridden' bit for an input
1112243830Sdim  /// file in the given module file.
1113249423Sdim  serialization::InputFile getInputFile(ModuleFile &F, unsigned ID,
1114249423Sdim                                        bool Complain = true);
1115243830Sdim
1116280031Sdimpublic:
1117280031Sdim  void ResolveImportedPath(ModuleFile &M, std::string &Filename);
1118280031Sdim  static void ResolveImportedPath(std::string &Filename, StringRef Prefix);
1119223017Sdim
1120280031Sdimprivate:
1121249423Sdim  struct ImportedModule {
1122249423Sdim    ModuleFile *Mod;
1123249423Sdim    ModuleFile *ImportedBy;
1124249423Sdim    SourceLocation ImportLoc;
1125249423Sdim
1126249423Sdim    ImportedModule(ModuleFile *Mod,
1127249423Sdim                   ModuleFile *ImportedBy,
1128249423Sdim                   SourceLocation ImportLoc)
1129249423Sdim      : Mod(Mod), ImportedBy(ImportedBy), ImportLoc(ImportLoc) { }
1130249423Sdim  };
1131249423Sdim
1132226633Sdim  ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type,
1133249423Sdim                            SourceLocation ImportLoc, ModuleFile *ImportedBy,
1134249423Sdim                            SmallVectorImpl<ImportedModule> &Loaded,
1135249423Sdim                            off_t ExpectedSize, time_t ExpectedModTime,
1136280031Sdim                            serialization::ASTFileSignature ExpectedSignature,
1137243830Sdim                            unsigned ClientLoadCapabilities);
1138243830Sdim  ASTReadResult ReadControlBlock(ModuleFile &F,
1139249423Sdim                                 SmallVectorImpl<ImportedModule> &Loaded,
1140276479Sdim                                 const ModuleFile *ImportedBy,
1141243830Sdim                                 unsigned ClientLoadCapabilities);
1142276479Sdim  ASTReadResult ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities);
1143280031Sdim  bool ParseLineTable(ModuleFile &F, const RecordData &Record);
1144243830Sdim  bool ReadSourceManagerBlock(ModuleFile &F);
1145226633Sdim  llvm::BitstreamCursor &SLocCursorForID(int ID);
1146234353Sdim  SourceLocation getImportLocation(ModuleFile *F);
1147280031Sdim  ASTReadResult ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
1148280031Sdim                                       const ModuleFile *ImportedBy,
1149280031Sdim                                       unsigned ClientLoadCapabilities);
1150276479Sdim  ASTReadResult ReadSubmoduleBlock(ModuleFile &F,
1151276479Sdim                                   unsigned ClientLoadCapabilities);
1152243830Sdim  static bool ParseLanguageOptions(const RecordData &Record, bool Complain,
1153280031Sdim                                   ASTReaderListener &Listener,
1154280031Sdim                                   bool AllowCompatibleDifferences);
1155243830Sdim  static bool ParseTargetOptions(const RecordData &Record, bool Complain,
1156243830Sdim                                 ASTReaderListener &Listener);
1157243830Sdim  static bool ParseDiagnosticOptions(const RecordData &Record, bool Complain,
1158243830Sdim                                     ASTReaderListener &Listener);
1159243830Sdim  static bool ParseFileSystemOptions(const RecordData &Record, bool Complain,
1160243830Sdim                                     ASTReaderListener &Listener);
1161243830Sdim  static bool ParseHeaderSearchOptions(const RecordData &Record, bool Complain,
1162243830Sdim                                       ASTReaderListener &Listener);
1163243830Sdim  static bool ParsePreprocessorOptions(const RecordData &Record, bool Complain,
1164243830Sdim                                       ASTReaderListener &Listener,
1165243830Sdim                                       std::string &SuggestedPredefines);
1166243830Sdim
1167218893Sdim  struct RecordLocation {
1168234353Sdim    RecordLocation(ModuleFile *M, uint64_t O)
1169218893Sdim      : F(M), Offset(O) {}
1170234353Sdim    ModuleFile *F;
1171218893Sdim    uint64_t Offset;
1172218893Sdim  };
1173212795Sdim
1174226633Sdim  QualType readTypeRecord(unsigned Index);
1175276479Sdim  void readExceptionSpec(ModuleFile &ModuleFile,
1176276479Sdim                         SmallVectorImpl<QualType> &ExceptionStorage,
1177280031Sdim                         FunctionProtoType::ExceptionSpecInfo &ESI,
1178276479Sdim                         const RecordData &Record, unsigned &Index);
1179212795Sdim  RecordLocation TypeCursorForIndex(unsigned Index);
1180212795Sdim  void LoadedDecl(unsigned Index, Decl *D);
1181226633Sdim  Decl *ReadDeclRecord(serialization::DeclID ID);
1182276479Sdim  void markIncompleteDeclChain(Decl *Canon);
1183234353Sdim  RecordLocation DeclCursorForID(serialization::DeclID ID,
1184234353Sdim                                 unsigned &RawLocation);
1185226633Sdim  void loadDeclUpdateRecords(serialization::DeclID ID, Decl *D);
1186234353Sdim  void loadPendingDeclChain(serialization::GlobalDeclID ID);
1187234353Sdim  void loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D,
1188234353Sdim                          unsigned PreviousGeneration = 0);
1189234353Sdim
1190226633Sdim  RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
1191234353Sdim  uint64_t getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset);
1192212795Sdim
1193276479Sdim  /// \brief Returns the first preprocessed entity ID that begins or ends after
1194276479Sdim  /// \arg Loc.
1195226633Sdim  serialization::PreprocessedEntityID
1196276479Sdim  findPreprocessedEntity(SourceLocation Loc, bool EndsAfter) const;
1197226633Sdim
1198239462Sdim  /// \brief Find the next module that contains entities and return the ID
1199226633Sdim  /// of the first entry.
1200243830Sdim  ///
1201243830Sdim  /// \param SLocMapI points at a chunk of a module that contains no
1202239462Sdim  /// preprocessed entities or the entities it contains are not the
1203239462Sdim  /// ones we are looking for.
1204226633Sdim  serialization::PreprocessedEntityID
1205226633Sdim    findNextPreprocessedEntity(
1206226633Sdim                        GlobalSLocOffsetMapType::const_iterator SLocMapI) const;
1207226633Sdim
1208243830Sdim  /// \brief Returns (ModuleFile, Local index) pair for \p GlobalIndex of a
1209234353Sdim  /// preprocessed entity.
1210234353Sdim  std::pair<ModuleFile *, unsigned>
1211234353Sdim    getModulePreprocessedEntity(unsigned GlobalIndex);
1212234353Sdim
1213243830Sdim  /// \brief Returns (begin, end) pair for the preprocessed entities of a
1214243830Sdim  /// particular module.
1215243830Sdim  std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator>
1216243830Sdim    getModulePreprocessedEntities(ModuleFile &Mod) const;
1217243830Sdim
1218243830Sdim  class ModuleDeclIterator {
1219243830Sdim    ASTReader *Reader;
1220243830Sdim    ModuleFile *Mod;
1221243830Sdim    const serialization::LocalDeclID *Pos;
1222243830Sdim
1223243830Sdim  public:
1224243830Sdim    typedef const Decl *value_type;
1225243830Sdim    typedef value_type&         reference;
1226243830Sdim    typedef value_type*         pointer;
1227243830Sdim
1228276479Sdim    ModuleDeclIterator() : Reader(nullptr), Mod(nullptr), Pos(nullptr) { }
1229243830Sdim
1230243830Sdim    ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod,
1231243830Sdim                       const serialization::LocalDeclID *Pos)
1232243830Sdim      : Reader(Reader), Mod(Mod), Pos(Pos) { }
1233243830Sdim
1234243830Sdim    value_type operator*() const {
1235243830Sdim      return Reader->GetDecl(Reader->getGlobalDeclID(*Mod, *Pos));
1236243830Sdim    }
1237243830Sdim
1238243830Sdim    ModuleDeclIterator &operator++() {
1239243830Sdim      ++Pos;
1240243830Sdim      return *this;
1241243830Sdim    }
1242243830Sdim
1243243830Sdim    ModuleDeclIterator operator++(int) {
1244243830Sdim      ModuleDeclIterator Prev(*this);
1245243830Sdim      ++Pos;
1246243830Sdim      return Prev;
1247243830Sdim    }
1248243830Sdim
1249243830Sdim    ModuleDeclIterator &operator--() {
1250243830Sdim      --Pos;
1251243830Sdim      return *this;
1252243830Sdim    }
1253243830Sdim
1254243830Sdim    ModuleDeclIterator operator--(int) {
1255243830Sdim      ModuleDeclIterator Prev(*this);
1256243830Sdim      --Pos;
1257243830Sdim      return Prev;
1258243830Sdim    }
1259243830Sdim
1260243830Sdim    friend bool operator==(const ModuleDeclIterator &LHS,
1261243830Sdim                           const ModuleDeclIterator &RHS) {
1262243830Sdim      assert(LHS.Reader == RHS.Reader && LHS.Mod == RHS.Mod);
1263243830Sdim      return LHS.Pos == RHS.Pos;
1264243830Sdim    }
1265243830Sdim
1266243830Sdim    friend bool operator!=(const ModuleDeclIterator &LHS,
1267243830Sdim                           const ModuleDeclIterator &RHS) {
1268243830Sdim      assert(LHS.Reader == RHS.Reader && LHS.Mod == RHS.Mod);
1269243830Sdim      return LHS.Pos != RHS.Pos;
1270243830Sdim    }
1271243830Sdim  };
1272243830Sdim
1273243830Sdim  std::pair<ModuleDeclIterator, ModuleDeclIterator>
1274243830Sdim    getModuleFileLevelDecls(ModuleFile &Mod);
1275243830Sdim
1276212795Sdim  void PassInterestingDeclsToConsumer();
1277234353Sdim  void PassInterestingDeclToConsumer(Decl *D);
1278212795Sdim
1279234353Sdim  void finishPendingActions();
1280280031Sdim  void diagnoseOdrViolations();
1281234353Sdim
1282251662Sdim  void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name);
1283251662Sdim
1284249423Sdim  void addPendingDeclContextInfo(Decl *D,
1285249423Sdim                                 serialization::GlobalDeclID SemaDC,
1286249423Sdim                                 serialization::GlobalDeclID LexicalDC) {
1287249423Sdim    assert(D);
1288249423Sdim    PendingDeclContextInfo Info = { D, SemaDC, LexicalDC };
1289249423Sdim    PendingDeclContextInfos.push_back(Info);
1290249423Sdim  }
1291249423Sdim
1292212795Sdim  /// \brief Produce an error diagnostic and return true.
1293212795Sdim  ///
1294212795Sdim  /// This routine should only be used for fatal errors that have to
1295212795Sdim  /// do with non-routine failures (e.g., corrupted AST file).
1296226633Sdim  void Error(StringRef Msg);
1297226633Sdim  void Error(unsigned DiagID, StringRef Arg1 = StringRef(),
1298226633Sdim             StringRef Arg2 = StringRef());
1299212795Sdim
1300243830Sdim  ASTReader(const ASTReader &) LLVM_DELETED_FUNCTION;
1301243830Sdim  void operator=(const ASTReader &) LLVM_DELETED_FUNCTION;
1302212795Sdimpublic:
1303212795Sdim  /// \brief Load the AST file and validate its contents against the given
1304212795Sdim  /// Preprocessor.
1305212795Sdim  ///
1306212795Sdim  /// \param PP the preprocessor associated with the context in which this
1307212795Sdim  /// precompiled header will be loaded.
1308212795Sdim  ///
1309212795Sdim  /// \param Context the AST context that this precompiled header will be
1310212795Sdim  /// loaded into.
1311212795Sdim  ///
1312212795Sdim  /// \param isysroot If non-NULL, the system include path specified by the
1313212795Sdim  /// user. This is only used with relocatable PCH files. If non-NULL,
1314212795Sdim  /// a relocatable PCH file will use the default path "/".
1315212795Sdim  ///
1316212795Sdim  /// \param DisableValidation If true, the AST reader will suppress most
1317212795Sdim  /// of its regular consistency checking, allowing the use of precompiled
1318212795Sdim  /// headers that cannot be determined to be compatible.
1319218893Sdim  ///
1320234353Sdim  /// \param AllowASTWithCompilerErrors If true, the AST reader will accept an
1321234353Sdim  /// AST file the was created out of an AST with compiler errors,
1322234353Sdim  /// otherwise it will reject it.
1323249423Sdim  ///
1324276479Sdim  /// \param AllowConfigurationMismatch If true, the AST reader will not check
1325276479Sdim  /// for configuration differences between the AST file and the invocation.
1326276479Sdim  ///
1327276479Sdim  /// \param ValidateSystemInputs If true, the AST reader will validate
1328276479Sdim  /// system input files in addition to user input files. This is only
1329276479Sdim  /// meaningful if \p DisableValidation is false.
1330276479Sdim  ///
1331249423Sdim  /// \param UseGlobalIndex If true, the AST reader will try to load and use
1332249423Sdim  /// the global module index.
1333226633Sdim  ASTReader(Preprocessor &PP, ASTContext &Context, StringRef isysroot = "",
1334243830Sdim            bool DisableValidation = false,
1335249423Sdim            bool AllowASTWithCompilerErrors = false,
1336276479Sdim            bool AllowConfigurationMismatch = false,
1337276479Sdim            bool ValidateSystemInputs = false,
1338249423Sdim            bool UseGlobalIndex = true);
1339212795Sdim
1340212795Sdim  ~ASTReader();
1341212795Sdim
1342226633Sdim  SourceManager &getSourceManager() const { return SourceMgr; }
1343249423Sdim  FileManager &getFileManager() const { return FileMgr; }
1344234353Sdim
1345243830Sdim  /// \brief Flags that indicate what kind of AST loading failures the client
1346243830Sdim  /// of the AST reader can directly handle.
1347243830Sdim  ///
1348243830Sdim  /// When a client states that it can handle a particular kind of failure,
1349243830Sdim  /// the AST reader will not emit errors when producing that kind of failure.
1350243830Sdim  enum LoadFailureCapabilities {
1351243830Sdim    /// \brief The client can't handle any AST loading failures.
1352243830Sdim    ARR_None = 0,
1353243830Sdim    /// \brief The client can handle an AST file that cannot load because it
1354249423Sdim    /// is missing.
1355249423Sdim    ARR_Missing = 0x1,
1356249423Sdim    /// \brief The client can handle an AST file that cannot load because it
1357243830Sdim    /// is out-of-date relative to its input files.
1358249423Sdim    ARR_OutOfDate = 0x2,
1359243830Sdim    /// \brief The client can handle an AST file that cannot load because it
1360243830Sdim    /// was built with a different version of Clang.
1361249423Sdim    ARR_VersionMismatch = 0x4,
1362243830Sdim    /// \brief The client can handle an AST file that cannot load because it's
1363243830Sdim    /// compiled configuration doesn't match that of the context it was
1364243830Sdim    /// loaded into.
1365249423Sdim    ARR_ConfigurationMismatch = 0x8
1366243830Sdim  };
1367243830Sdim
1368226633Sdim  /// \brief Load the AST file designated by the given file name.
1369243830Sdim  ///
1370243830Sdim  /// \param FileName The name of the AST file to load.
1371243830Sdim  ///
1372243830Sdim  /// \param Type The kind of AST being loaded, e.g., PCH, module, main file,
1373243830Sdim  /// or preamble.
1374243830Sdim  ///
1375249423Sdim  /// \param ImportLoc the location where the module file will be considered as
1376249423Sdim  /// imported from. For non-module AST types it should be invalid.
1377249423Sdim  ///
1378243830Sdim  /// \param ClientLoadCapabilities The set of client load-failure
1379243830Sdim  /// capabilities, represented as a bitset of the enumerators of
1380243830Sdim  /// LoadFailureCapabilities.
1381243830Sdim  ASTReadResult ReadAST(const std::string &FileName, ModuleKind Type,
1382249423Sdim                        SourceLocation ImportLoc,
1383243830Sdim                        unsigned ClientLoadCapabilities);
1384212795Sdim
1385234353Sdim  /// \brief Make the entities in the given module and any of its (non-explicit)
1386234353Sdim  /// submodules visible to name lookup.
1387234353Sdim  ///
1388234353Sdim  /// \param Mod The module whose names should be made visible.
1389234353Sdim  ///
1390239462Sdim  /// \param NameVisibility The level of visibility to give the names in the
1391239462Sdim  /// module.  Visibility can only be increased over time.
1392249423Sdim  ///
1393249423Sdim  /// \param ImportLoc The location at which the import occurs.
1394249423Sdim  ///
1395249423Sdim  /// \param Complain Whether to complain about conflicting module imports.
1396276479Sdim  void makeModuleVisible(Module *Mod,
1397249423Sdim                         Module::NameVisibilityKind NameVisibility,
1398249423Sdim                         SourceLocation ImportLoc,
1399249423Sdim                         bool Complain);
1400276479Sdim
1401234353Sdim  /// \brief Make the names within this set of hidden names visible.
1402276479Sdim  void makeNamesVisible(const HiddenNames &Names, Module *Owner,
1403276479Sdim                        bool FromFinalization);
1404276479Sdim
1405280031Sdim  /// \brief Take the AST callbacks listener.
1406280031Sdim  std::unique_ptr<ASTReaderListener> takeListener() {
1407280031Sdim    return std::move(Listener);
1408280031Sdim  }
1409280031Sdim
1410212795Sdim  /// \brief Set the AST callbacks listener.
1411280031Sdim  void setListener(std::unique_ptr<ASTReaderListener> Listener) {
1412280031Sdim    this->Listener = std::move(Listener);
1413212795Sdim  }
1414212795Sdim
1415280031Sdim  /// \brief Add an AST callback listener.
1416276479Sdim  ///
1417276479Sdim  /// Takes ownership of \p L.
1418280031Sdim  void addListener(std::unique_ptr<ASTReaderListener> L) {
1419276479Sdim    if (Listener)
1420280031Sdim      L = llvm::make_unique<ChainedASTReaderListener>(std::move(L),
1421280031Sdim                                                      std::move(Listener));
1422280031Sdim    Listener = std::move(L);
1423276479Sdim  }
1424276479Sdim
1425280031Sdim  /// RAII object to temporarily add an AST callback listener.
1426280031Sdim  class ListenerScope {
1427280031Sdim    ASTReader &Reader;
1428280031Sdim    bool Chained;
1429280031Sdim
1430280031Sdim  public:
1431280031Sdim    ListenerScope(ASTReader &Reader, std::unique_ptr<ASTReaderListener> L)
1432280031Sdim        : Reader(Reader), Chained(false) {
1433280031Sdim      auto Old = Reader.takeListener();
1434280031Sdim      if (Old) {
1435280031Sdim        Chained = true;
1436280031Sdim        L = llvm::make_unique<ChainedASTReaderListener>(std::move(L),
1437280031Sdim                                                        std::move(Old));
1438280031Sdim      }
1439280031Sdim      Reader.setListener(std::move(L));
1440280031Sdim    }
1441280031Sdim    ~ListenerScope() {
1442280031Sdim      auto New = Reader.takeListener();
1443280031Sdim      if (Chained)
1444280031Sdim        Reader.setListener(static_cast<ChainedASTReaderListener *>(New.get())
1445280031Sdim                               ->takeSecond());
1446280031Sdim    }
1447280031Sdim  };
1448280031Sdim
1449212795Sdim  /// \brief Set the AST deserialization listener.
1450276479Sdim  void setDeserializationListener(ASTDeserializationListener *Listener,
1451276479Sdim                                  bool TakeOwnership = false);
1452212795Sdim
1453249423Sdim  /// \brief Determine whether this AST reader has a global index.
1454276479Sdim  bool hasGlobalIndex() const { return (bool)GlobalIndex; }
1455249423Sdim
1456276479Sdim  /// \brief Return global module index.
1457276479Sdim  GlobalModuleIndex *getGlobalIndex() { return GlobalIndex.get(); }
1458276479Sdim
1459276479Sdim  /// \brief Reset reader for a reload try.
1460276479Sdim  void resetForReload() { TriedLoadingGlobalIndex = false; }
1461276479Sdim
1462249423Sdim  /// \brief Attempts to load the global index.
1463249423Sdim  ///
1464249423Sdim  /// \returns true if loading the global index has failed for any reason.
1465249423Sdim  bool loadGlobalIndex();
1466249423Sdim
1467249423Sdim  /// \brief Determine whether we tried to load the global index, but failed,
1468249423Sdim  /// e.g., because it is out-of-date or does not exist.
1469249423Sdim  bool isGlobalIndexUnavailable() const;
1470249423Sdim
1471226633Sdim  /// \brief Initializes the ASTContext
1472226633Sdim  void InitializeContext();
1473212795Sdim
1474261991Sdim  /// \brief Update the state of Sema after loading some additional modules.
1475261991Sdim  void UpdateSema();
1476261991Sdim
1477226633Sdim  /// \brief Add in-memory (virtual file) buffer.
1478280031Sdim  void addInMemoryBuffer(StringRef &FileName,
1479280031Sdim                         std::unique_ptr<llvm::MemoryBuffer> Buffer) {
1480280031Sdim    ModuleMgr.addInMemoryBuffer(FileName, std::move(Buffer));
1481221345Sdim  }
1482221345Sdim
1483234353Sdim  /// \brief Finalizes the AST reader's state before writing an AST file to
1484234353Sdim  /// disk.
1485234353Sdim  ///
1486234353Sdim  /// This operation may undo temporary state in the AST that should not be
1487234353Sdim  /// emitted.
1488234353Sdim  void finalizeForWriting();
1489234353Sdim
1490226633Sdim  /// \brief Retrieve the module manager.
1491226633Sdim  ModuleManager &getModuleManager() { return ModuleMgr; }
1492212795Sdim
1493226633Sdim  /// \brief Retrieve the preprocessor.
1494226633Sdim  Preprocessor &getPreprocessor() const { return PP; }
1495234353Sdim
1496243830Sdim  /// \brief Retrieve the name of the original source file name for the primary
1497243830Sdim  /// module file.
1498243830Sdim  StringRef getOriginalSourceFile() {
1499243830Sdim    return ModuleMgr.getPrimaryModule().OriginalSourceFileName;
1500243830Sdim  }
1501212795Sdim
1502212795Sdim  /// \brief Retrieve the name of the original source file name directly from
1503212795Sdim  /// the AST file, without actually loading the AST file.
1504212795Sdim  static std::string getOriginalSourceFile(const std::string &ASTFileName,
1505218893Sdim                                           FileManager &FileMgr,
1506226633Sdim                                           DiagnosticsEngine &Diags);
1507212795Sdim
1508243830Sdim  /// \brief Read the control block for the named AST file.
1509243830Sdim  ///
1510243830Sdim  /// \returns true if an error occurred, false otherwise.
1511243830Sdim  static bool readASTFileControlBlock(StringRef Filename,
1512243830Sdim                                      FileManager &FileMgr,
1513243830Sdim                                      ASTReaderListener &Listener);
1514243830Sdim
1515243830Sdim  /// \brief Determine whether the given AST file is acceptable to load into a
1516243830Sdim  /// translation unit with the given language and target options.
1517243830Sdim  static bool isAcceptableASTFile(StringRef Filename,
1518243830Sdim                                  FileManager &FileMgr,
1519243830Sdim                                  const LangOptions &LangOpts,
1520243830Sdim                                  const TargetOptions &TargetOpts,
1521243830Sdim                                  const PreprocessorOptions &PPOpts);
1522243830Sdim
1523212795Sdim  /// \brief Returns the suggested contents of the predefines buffer,
1524212795Sdim  /// which contains a (typically-empty) subset of the predefines
1525212795Sdim  /// build prior to including the precompiled header.
1526212795Sdim  const std::string &getSuggestedPredefines() { return SuggestedPredefines; }
1527212795Sdim
1528226633Sdim  /// \brief Read a preallocated preprocessed entity from the external source.
1529226633Sdim  ///
1530226633Sdim  /// \returns null if an error occurred that prevented the preprocessed
1531226633Sdim  /// entity from being loaded.
1532276479Sdim  PreprocessedEntity *ReadPreprocessedEntity(unsigned Index) override;
1533218893Sdim
1534226633Sdim  /// \brief Returns a pair of [Begin, End) indices of preallocated
1535243830Sdim  /// preprocessed entities that \p Range encompasses.
1536276479Sdim  std::pair<unsigned, unsigned>
1537276479Sdim      findPreprocessedEntitiesInRange(SourceRange Range) override;
1538226633Sdim
1539234353Sdim  /// \brief Optionally returns true or false if the preallocated preprocessed
1540243830Sdim  /// entity with index \p Index came from file \p FID.
1541276479Sdim  Optional<bool> isPreprocessedEntityInFileID(unsigned Index,
1542276479Sdim                                              FileID FID) override;
1543234353Sdim
1544218893Sdim  /// \brief Read the header file information for the given file entry.
1545276479Sdim  HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) override;
1546218893Sdim
1547226633Sdim  void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag);
1548218893Sdim
1549212795Sdim  /// \brief Returns the number of source locations found in the chain.
1550212795Sdim  unsigned getTotalNumSLocs() const {
1551212795Sdim    return TotalNumSLocEntries;
1552212795Sdim  }
1553212795Sdim
1554212795Sdim  /// \brief Returns the number of identifiers found in the chain.
1555212795Sdim  unsigned getTotalNumIdentifiers() const {
1556212795Sdim    return static_cast<unsigned>(IdentifiersLoaded.size());
1557212795Sdim  }
1558212795Sdim
1559243830Sdim  /// \brief Returns the number of macros found in the chain.
1560243830Sdim  unsigned getTotalNumMacros() const {
1561243830Sdim    return static_cast<unsigned>(MacrosLoaded.size());
1562243830Sdim  }
1563243830Sdim
1564212795Sdim  /// \brief Returns the number of types found in the chain.
1565212795Sdim  unsigned getTotalNumTypes() const {
1566212795Sdim    return static_cast<unsigned>(TypesLoaded.size());
1567212795Sdim  }
1568212795Sdim
1569212795Sdim  /// \brief Returns the number of declarations found in the chain.
1570212795Sdim  unsigned getTotalNumDecls() const {
1571212795Sdim    return static_cast<unsigned>(DeclsLoaded.size());
1572212795Sdim  }
1573212795Sdim
1574234353Sdim  /// \brief Returns the number of submodules known.
1575234353Sdim  unsigned getTotalNumSubmodules() const {
1576234353Sdim    return static_cast<unsigned>(SubmodulesLoaded.size());
1577234353Sdim  }
1578234353Sdim
1579212795Sdim  /// \brief Returns the number of selectors found in the chain.
1580212795Sdim  unsigned getTotalNumSelectors() const {
1581212795Sdim    return static_cast<unsigned>(SelectorsLoaded.size());
1582212795Sdim  }
1583212795Sdim
1584226633Sdim  /// \brief Returns the number of preprocessed entities known to the AST
1585226633Sdim  /// reader.
1586226633Sdim  unsigned getTotalNumPreprocessedEntities() const {
1587226633Sdim    unsigned Result = 0;
1588226633Sdim    for (ModuleConstIterator I = ModuleMgr.begin(),
1589226633Sdim        E = ModuleMgr.end(); I != E; ++I) {
1590226633Sdim      Result += (*I)->NumPreprocessedEntities;
1591226633Sdim    }
1592234353Sdim
1593226633Sdim    return Result;
1594218893Sdim  }
1595234353Sdim
1596218893Sdim  /// \brief Returns the number of C++ base specifiers found in the chain.
1597226633Sdim  unsigned getTotalNumCXXBaseSpecifiers() const {
1598226633Sdim    return NumCXXBaseSpecifiersLoaded;
1599226633Sdim  }
1600234353Sdim
1601212795Sdim  /// \brief Reads a TemplateArgumentLocInfo appropriate for the
1602212795Sdim  /// given TemplateArgument kind.
1603212795Sdim  TemplateArgumentLocInfo
1604234353Sdim  GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind,
1605212795Sdim                             const RecordData &Record, unsigned &Idx);
1606212795Sdim
1607212795Sdim  /// \brief Reads a TemplateArgumentLoc.
1608212795Sdim  TemplateArgumentLoc
1609234353Sdim  ReadTemplateArgumentLoc(ModuleFile &F,
1610212795Sdim                          const RecordData &Record, unsigned &Idx);
1611212795Sdim
1612261991Sdim  const ASTTemplateArgumentListInfo*
1613261991Sdim  ReadASTTemplateArgumentListInfo(ModuleFile &F,
1614261991Sdim                                  const RecordData &Record, unsigned &Index);
1615261991Sdim
1616212795Sdim  /// \brief Reads a declarator info from the given record.
1617234353Sdim  TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F,
1618212795Sdim                                    const RecordData &Record, unsigned &Idx);
1619212795Sdim
1620212795Sdim  /// \brief Resolve a type ID into a type, potentially building a new
1621212795Sdim  /// type.
1622212795Sdim  QualType GetType(serialization::TypeID ID);
1623212795Sdim
1624226633Sdim  /// \brief Resolve a local type ID within a given AST file into a type.
1625234353Sdim  QualType getLocalType(ModuleFile &F, unsigned LocalID);
1626234353Sdim
1627226633Sdim  /// \brief Map a local type ID within a given AST file into a global type ID.
1628234353Sdim  serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const;
1629234353Sdim
1630234353Sdim  /// \brief Read a type from the current position in the given record, which
1631226633Sdim  /// was read from the given AST file.
1632234353Sdim  QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) {
1633226633Sdim    if (Idx >= Record.size())
1634226633Sdim      return QualType();
1635234353Sdim
1636226633Sdim    return getLocalType(F, Record[Idx++]);
1637226633Sdim  }
1638234353Sdim
1639234353Sdim  /// \brief Map from a local declaration ID within a given module to a
1640226633Sdim  /// global declaration ID.
1641243830Sdim  serialization::DeclID getGlobalDeclID(ModuleFile &F,
1642243830Sdim                                      serialization::LocalDeclID LocalID) const;
1643212795Sdim
1644243830Sdim  /// \brief Returns true if global DeclID \p ID originated from module \p M.
1645234353Sdim  bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const;
1646234353Sdim
1647234353Sdim  /// \brief Retrieve the module file that owns the given declaration, or NULL
1648234353Sdim  /// if the declaration is not from a module file.
1649249423Sdim  ModuleFile *getOwningModuleFile(const Decl *D);
1650276479Sdim
1651276479Sdim  /// \brief Get the best name we know for the module that owns the given
1652276479Sdim  /// declaration, or an empty string if the declaration is not from a module.
1653276479Sdim  std::string getOwningModuleNameForDiagnostic(const Decl *D);
1654276479Sdim
1655243830Sdim  /// \brief Returns the source location for the decl \p ID.
1656234353Sdim  SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID);
1657234353Sdim
1658212795Sdim  /// \brief Resolve a declaration ID into a declaration, potentially
1659212795Sdim  /// building a new declaration.
1660212795Sdim  Decl *GetDecl(serialization::DeclID ID);
1661276479Sdim  Decl *GetExternalDecl(uint32_t ID) override;
1662212795Sdim
1663276479Sdim  /// \brief Resolve a declaration ID into a declaration. Return 0 if it's not
1664276479Sdim  /// been loaded yet.
1665276479Sdim  Decl *GetExistingDecl(serialization::DeclID ID);
1666276479Sdim
1667226633Sdim  /// \brief Reads a declaration with the given local ID in the given module.
1668234353Sdim  Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) {
1669226633Sdim    return GetDecl(getGlobalDeclID(F, LocalID));
1670226633Sdim  }
1671226633Sdim
1672226633Sdim  /// \brief Reads a declaration with the given local ID in the given module.
1673226633Sdim  ///
1674226633Sdim  /// \returns The requested declaration, casted to the given return type.
1675226633Sdim  template<typename T>
1676234353Sdim  T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) {
1677226633Sdim    return cast_or_null<T>(GetLocalDecl(F, LocalID));
1678226633Sdim  }
1679226633Sdim
1680234353Sdim  /// \brief Map a global declaration ID into the declaration ID used to
1681234353Sdim  /// refer to this declaration within the given module fule.
1682234353Sdim  ///
1683234353Sdim  /// \returns the global ID of the given declaration as known in the given
1684234353Sdim  /// module file.
1685234353Sdim  serialization::DeclID
1686234353Sdim  mapGlobalIDToModuleFileGlobalID(ModuleFile &M,
1687234353Sdim                                  serialization::DeclID GlobalID);
1688234353Sdim
1689234353Sdim  /// \brief Reads a declaration ID from the given position in a record in the
1690226633Sdim  /// given module.
1691226633Sdim  ///
1692226633Sdim  /// \returns The declaration ID read from the record, adjusted to a global ID.
1693234353Sdim  serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record,
1694226633Sdim                                   unsigned &Idx);
1695234353Sdim
1696226633Sdim  /// \brief Reads a declaration from the given position in a record in the
1697226633Sdim  /// given module.
1698234353Sdim  Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) {
1699226633Sdim    return GetDecl(ReadDeclID(F, R, I));
1700226633Sdim  }
1701234353Sdim
1702226633Sdim  /// \brief Reads a declaration from the given position in a record in the
1703226633Sdim  /// given module.
1704226633Sdim  ///
1705226633Sdim  /// \returns The declaration read from this location, casted to the given
1706226633Sdim  /// result type.
1707226633Sdim  template<typename T>
1708234353Sdim  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1709226633Sdim    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1710226633Sdim  }
1711226633Sdim
1712276479Sdim  /// \brief If any redeclarations of \p D have been imported since it was
1713276479Sdim  /// last checked, this digs out those redeclarations and adds them to the
1714276479Sdim  /// redeclaration chain for \p D.
1715276479Sdim  void CompleteRedeclChain(const Decl *D) override;
1716276479Sdim
1717226633Sdim  /// \brief Read a CXXBaseSpecifiers ID form the given record and
1718226633Sdim  /// return its global bit offset.
1719234353Sdim  uint64_t readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record,
1720226633Sdim                                 unsigned &Idx);
1721234353Sdim
1722276479Sdim  CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
1723234353Sdim
1724212795Sdim  /// \brief Resolve the offset of a statement into a statement.
1725212795Sdim  ///
1726212795Sdim  /// This operation will read a new statement from the external
1727212795Sdim  /// source each time it is called, and is meant to be used via a
1728212795Sdim  /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
1729276479Sdim  Stmt *GetExternalDeclStmt(uint64_t Offset) override;
1730212795Sdim
1731212795Sdim  /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
1732212795Sdim  /// specified cursor.  Read the abbreviations that are at the top of the block
1733212795Sdim  /// and then leave the cursor pointing into the block.
1734212795Sdim  bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID);
1735212795Sdim
1736212795Sdim  /// \brief Finds all the visible declarations with a given name.
1737212795Sdim  /// The current implementation of this method just loads the entire
1738212795Sdim  /// lookup table as unmaterialized references.
1739276479Sdim  bool FindExternalVisibleDeclsByName(const DeclContext *DC,
1740276479Sdim                                      DeclarationName Name) override;
1741212795Sdim
1742212795Sdim  /// \brief Read all of the declarations lexically stored in a
1743212795Sdim  /// declaration context.
1744212795Sdim  ///
1745212795Sdim  /// \param DC The declaration context whose declarations will be
1746212795Sdim  /// read.
1747212795Sdim  ///
1748212795Sdim  /// \param Decls Vector that will contain the declarations loaded
1749212795Sdim  /// from the external source. The caller is responsible for merging
1750212795Sdim  /// these declarations with any declarations already stored in the
1751212795Sdim  /// declaration context.
1752212795Sdim  ///
1753212795Sdim  /// \returns true if there was an error while reading the
1754212795Sdim  /// declarations for this declaration context.
1755276479Sdim  ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
1756276479Sdim                                bool (*isKindWeWant)(Decl::Kind),
1757276479Sdim                                SmallVectorImpl<Decl*> &Decls) override;
1758212795Sdim
1759234353Sdim  /// \brief Get the decls that are contained in a file in the Offset/Length
1760243830Sdim  /// range. \p Length can be 0 to indicate a point at \p Offset instead of
1761234353Sdim  /// a range.
1762276479Sdim  void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length,
1763276479Sdim                           SmallVectorImpl<Decl *> &Decls) override;
1764234353Sdim
1765212795Sdim  /// \brief Notify ASTReader that we started deserialization of
1766212795Sdim  /// a decl or type so until FinishedDeserializing is called there may be
1767212795Sdim  /// decls that are initializing. Must be paired with FinishedDeserializing.
1768276479Sdim  void StartedDeserializing() override { ++NumCurrentElementsDeserializing; }
1769212795Sdim
1770212795Sdim  /// \brief Notify ASTReader that we finished the deserialization of
1771212795Sdim  /// a decl or type. Must be paired with StartedDeserializing.
1772276479Sdim  void FinishedDeserializing() override;
1773212795Sdim
1774212795Sdim  /// \brief Function that will be invoked when we begin parsing a new
1775212795Sdim  /// translation unit involving this external AST source.
1776212795Sdim  ///
1777212795Sdim  /// This function will provide all of the external definitions to
1778212795Sdim  /// the ASTConsumer.
1779276479Sdim  void StartTranslationUnit(ASTConsumer *Consumer) override;
1780212795Sdim
1781212795Sdim  /// \brief Print some statistics about AST usage.
1782276479Sdim  void PrintStats() override;
1783212795Sdim
1784226633Sdim  /// \brief Dump information about the AST reader to standard error.
1785226633Sdim  void dump();
1786234353Sdim
1787221345Sdim  /// Return the amount of memory used by memory buffers, breaking down
1788221345Sdim  /// by heap-backed versus mmap'ed memory.
1789276479Sdim  void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
1790221345Sdim
1791212795Sdim  /// \brief Initialize the semantic source with the Sema instance
1792212795Sdim  /// being used to perform semantic analysis on the abstract syntax
1793212795Sdim  /// tree.
1794276479Sdim  void InitializeSema(Sema &S) override;
1795212795Sdim
1796212795Sdim  /// \brief Inform the semantic consumer that Sema is no longer available.
1797276479Sdim  void ForgetSema() override { SemaObj = nullptr; }
1798212795Sdim
1799212795Sdim  /// \brief Retrieve the IdentifierInfo for the named identifier.
1800212795Sdim  ///
1801212795Sdim  /// This routine builds a new IdentifierInfo for the given identifier. If any
1802212795Sdim  /// declarations with this name are visible from translation unit scope, their
1803212795Sdim  /// declarations will be deserialized and introduced into the declaration
1804212795Sdim  /// chain of the identifier.
1805212795Sdim  virtual IdentifierInfo *get(const char *NameStart, const char *NameEnd);
1806276479Sdim  IdentifierInfo *get(StringRef Name) override {
1807212795Sdim    return get(Name.begin(), Name.end());
1808212795Sdim  }
1809212795Sdim
1810218893Sdim  /// \brief Retrieve an iterator into the set of all identifiers
1811218893Sdim  /// in all loaded AST files.
1812276479Sdim  IdentifierIterator *getIdentifiers() override;
1813218893Sdim
1814212795Sdim  /// \brief Load the contents of the global method pool for a given
1815212795Sdim  /// selector.
1816276479Sdim  void ReadMethodPool(Selector Sel) override;
1817212795Sdim
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(
1824276479Sdim               llvm::DenseMap<NamedDecl *, SourceLocation> &Undefined) override;
1825249423Sdim
1826276479Sdim  void ReadTentativeDefinitions(
1827276479Sdim                            SmallVectorImpl<VarDecl *> &TentativeDefs) override;
1828226633Sdim
1829276479Sdim  void ReadUnusedFileScopedDecls(
1830276479Sdim                       SmallVectorImpl<const DeclaratorDecl *> &Decls) override;
1831226633Sdim
1832276479Sdim  void ReadDelegatingConstructors(
1833276479Sdim                         SmallVectorImpl<CXXConstructorDecl *> &Decls) override;
1834226633Sdim
1835276479Sdim  void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) override;
1836226633Sdim
1837276479Sdim  void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) override;
1838226633Sdim
1839280031Sdim  void ReadUnusedLocalTypedefNameCandidates(
1840280031Sdim      llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override;
1841280031Sdim
1842276479Sdim  void ReadLocallyScopedExternCDecls(
1843276479Sdim                                  SmallVectorImpl<NamedDecl *> &Decls) override;
1844234353Sdim
1845276479Sdim  void ReadReferencedSelectors(
1846276479Sdim          SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) override;
1847226633Sdim
1848276479Sdim  void ReadWeakUndeclaredIdentifiers(
1849276479Sdim          SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI) override;
1850226633Sdim
1851276479Sdim  void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override;
1852226633Sdim
1853276479Sdim  void ReadPendingInstantiations(
1854234353Sdim                 SmallVectorImpl<std::pair<ValueDecl *,
1855276479Sdim                                           SourceLocation> > &Pending) override;
1856226633Sdim
1857276479Sdim  void ReadLateParsedTemplates(
1858276479Sdim                         llvm::DenseMap<const FunctionDecl *,
1859276479Sdim                                        LateParsedTemplate *> &LPTMap) override;
1860261991Sdim
1861212795Sdim  /// \brief Load a selector from disk, registering its ID if it exists.
1862212795Sdim  void LoadSelector(Selector Sel);
1863212795Sdim
1864212795Sdim  void SetIdentifierInfo(unsigned ID, IdentifierInfo *II);
1865212795Sdim  void SetGloballyVisibleDecls(IdentifierInfo *II,
1866226633Sdim                               const SmallVectorImpl<uint32_t> &DeclIDs,
1867276479Sdim                               SmallVectorImpl<Decl *> *Decls = nullptr);
1868212795Sdim
1869212795Sdim  /// \brief Report a diagnostic.
1870212795Sdim  DiagnosticBuilder Diag(unsigned DiagID);
1871212795Sdim
1872212795Sdim  /// \brief Report a diagnostic.
1873212795Sdim  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
1874212795Sdim
1875226633Sdim  IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID);
1876212795Sdim
1877234353Sdim  IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record,
1878226633Sdim                                    unsigned &Idx) {
1879226633Sdim    return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++]));
1880212795Sdim  }
1881212795Sdim
1882276479Sdim  IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) override {
1883243830Sdim    // Note that we are loading an identifier.
1884243830Sdim    Deserializing AnIdentifier(this);
1885243830Sdim
1886212795Sdim    return DecodeIdentifierInfo(ID);
1887212795Sdim  }
1888212795Sdim
1889234353Sdim  IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID);
1890234353Sdim
1891234353Sdim  serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M,
1892226633Sdim                                                    unsigned LocalID);
1893234353Sdim
1894276479Sdim  ModuleMacroInfo *getModuleMacro(const PendingMacroInfo &PMInfo);
1895276479Sdim
1896249423Sdim  void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo);
1897249423Sdim
1898249423Sdim  void installPCHMacroDirectives(IdentifierInfo *II,
1899249423Sdim                                 ModuleFile &M, uint64_t Offset);
1900249423Sdim
1901276479Sdim  void installImportedMacro(IdentifierInfo *II, ModuleMacroInfo *MMI,
1902280031Sdim                            Module *Owner);
1903249423Sdim
1904276479Sdim  typedef llvm::TinyPtrVector<DefMacroDirective *> AmbiguousMacros;
1905276479Sdim  llvm::DenseMap<IdentifierInfo*, AmbiguousMacros> AmbiguousMacroDefs;
1906276479Sdim
1907276479Sdim  void
1908280031Sdim  removeOverriddenMacros(IdentifierInfo *II, SourceLocation Loc,
1909280031Sdim                         AmbiguousMacros &Ambig,
1910276479Sdim                         ArrayRef<serialization::SubmoduleID> Overrides);
1911276479Sdim
1912276479Sdim  AmbiguousMacros *
1913280031Sdim  removeOverriddenMacros(IdentifierInfo *II, SourceLocation Loc,
1914276479Sdim                         ArrayRef<serialization::SubmoduleID> Overrides);
1915276479Sdim
1916243830Sdim  /// \brief Retrieve the macro with the given ID.
1917249423Sdim  MacroInfo *getMacro(serialization::MacroID ID);
1918243830Sdim
1919243830Sdim  /// \brief Retrieve the global macro ID corresponding to the given local
1920243830Sdim  /// ID within the given module file.
1921243830Sdim  serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID);
1922243830Sdim
1923212795Sdim  /// \brief Read the source location entry with index ID.
1924276479Sdim  bool ReadSLocEntry(int ID) override;
1925212795Sdim
1926249423Sdim  /// \brief Retrieve the module import location and module name for the
1927249423Sdim  /// given source manager entry ID.
1928276479Sdim  std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID) override;
1929249423Sdim
1930234353Sdim  /// \brief Retrieve the global submodule ID given a module and its local ID
1931234353Sdim  /// number.
1932234353Sdim  serialization::SubmoduleID
1933234353Sdim  getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID);
1934234353Sdim
1935234353Sdim  /// \brief Retrieve the submodule that corresponds to a global submodule ID.
1936234353Sdim  ///
1937234353Sdim  Module *getSubmodule(serialization::SubmoduleID GlobalID);
1938249423Sdim
1939249423Sdim  /// \brief Retrieve the module that corresponds to the given module ID.
1940249423Sdim  ///
1941249423Sdim  /// Note: overrides method in ExternalASTSource
1942276479Sdim  Module *getModule(unsigned ID) override;
1943249423Sdim
1944226633Sdim  /// \brief Retrieve a selector from the given module with its local ID
1945226633Sdim  /// number.
1946234353Sdim  Selector getLocalSelector(ModuleFile &M, unsigned LocalID);
1947212795Sdim
1948226633Sdim  Selector DecodeSelector(serialization::SelectorID Idx);
1949226633Sdim
1950276479Sdim  Selector GetExternalSelector(serialization::SelectorID ID) override;
1951276479Sdim  uint32_t GetNumExternalSelectors() override;
1952212795Sdim
1953234353Sdim  Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) {
1954226633Sdim    return getLocalSelector(M, Record[Idx++]);
1955212795Sdim  }
1956234353Sdim
1957226633Sdim  /// \brief Retrieve the global selector ID that corresponds to this
1958226633Sdim  /// the local selector ID in a given module.
1959234353Sdim  serialization::SelectorID getGlobalSelectorID(ModuleFile &F,
1960226633Sdim                                                unsigned LocalID) const;
1961212795Sdim
1962212795Sdim  /// \brief Read a declaration name.
1963234353Sdim  DeclarationName ReadDeclarationName(ModuleFile &F,
1964226633Sdim                                      const RecordData &Record, unsigned &Idx);
1965234353Sdim  void ReadDeclarationNameLoc(ModuleFile &F,
1966218893Sdim                              DeclarationNameLoc &DNLoc, DeclarationName Name,
1967218893Sdim                              const RecordData &Record, unsigned &Idx);
1968234353Sdim  void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo,
1969218893Sdim                               const RecordData &Record, unsigned &Idx);
1970212795Sdim
1971234353Sdim  void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info,
1972218893Sdim                         const RecordData &Record, unsigned &Idx);
1973218893Sdim
1974234353Sdim  NestedNameSpecifier *ReadNestedNameSpecifier(ModuleFile &F,
1975226633Sdim                                               const RecordData &Record,
1976212795Sdim                                               unsigned &Idx);
1977212795Sdim
1978234353Sdim  NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F,
1979219077Sdim                                                    const RecordData &Record,
1980219077Sdim                                                    unsigned &Idx);
1981219077Sdim
1982212795Sdim  /// \brief Read a template name.
1983234353Sdim  TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record,
1984218893Sdim                                unsigned &Idx);
1985212795Sdim
1986212795Sdim  /// \brief Read a template argument.
1987234353Sdim  TemplateArgument ReadTemplateArgument(ModuleFile &F,
1988212795Sdim                                        const RecordData &Record,unsigned &Idx);
1989234353Sdim
1990212795Sdim  /// \brief Read a template parameter list.
1991234353Sdim  TemplateParameterList *ReadTemplateParameterList(ModuleFile &F,
1992218893Sdim                                                   const RecordData &Record,
1993212795Sdim                                                   unsigned &Idx);
1994234353Sdim
1995212795Sdim  /// \brief Read a template argument array.
1996212795Sdim  void
1997261991Sdim  ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs,
1998234353Sdim                           ModuleFile &F, const RecordData &Record,
1999218893Sdim                           unsigned &Idx);
2000212795Sdim
2001212795Sdim  /// \brief Read a UnresolvedSet structure.
2002261991Sdim  void ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set,
2003212795Sdim                         const RecordData &Record, unsigned &Idx);
2004212795Sdim
2005212795Sdim  /// \brief Read a C++ base specifier.
2006234353Sdim  CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F,
2007212795Sdim                                        const RecordData &Record,unsigned &Idx);
2008212795Sdim
2009218893Sdim  /// \brief Read a CXXCtorInitializer array.
2010218893Sdim  std::pair<CXXCtorInitializer **, unsigned>
2011234353Sdim  ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record,
2012218893Sdim                          unsigned &Idx);
2013212795Sdim
2014218893Sdim  /// \brief Read a source location from raw form.
2015234353Sdim  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, unsigned Raw) const {
2016226633Sdim    SourceLocation Loc = SourceLocation::getFromRawEncoding(Raw);
2017234353Sdim    assert(ModuleFile.SLocRemap.find(Loc.getOffset()) != ModuleFile.SLocRemap.end() &&
2018226633Sdim           "Cannot find offset to remap.");
2019234353Sdim    int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second;
2020226633Sdim    return Loc.getLocWithOffset(Remap);
2021218893Sdim  }
2022218893Sdim
2023212795Sdim  /// \brief Read a source location.
2024234353Sdim  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
2025261991Sdim                                    const RecordDataImpl &Record,
2026261991Sdim                                    unsigned &Idx) {
2027234353Sdim    return ReadSourceLocation(ModuleFile, Record[Idx++]);
2028212795Sdim  }
2029212795Sdim
2030212795Sdim  /// \brief Read a source range.
2031234353Sdim  SourceRange ReadSourceRange(ModuleFile &F,
2032249423Sdim                              const RecordData &Record, unsigned &Idx);
2033212795Sdim
2034212795Sdim  /// \brief Read an integral value
2035212795Sdim  llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx);
2036212795Sdim
2037212795Sdim  /// \brief Read a signed integral value
2038212795Sdim  llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx);
2039212795Sdim
2040212795Sdim  /// \brief Read a floating-point value
2041249423Sdim  llvm::APFloat ReadAPFloat(const RecordData &Record,
2042249423Sdim                            const llvm::fltSemantics &Sem, unsigned &Idx);
2043212795Sdim
2044212795Sdim  // \brief Read a string
2045243830Sdim  static std::string ReadString(const RecordData &Record, unsigned &Idx);
2046212795Sdim
2047280031Sdim  // \brief Read a path
2048280031Sdim  std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx);
2049280031Sdim
2050221345Sdim  /// \brief Read a version tuple.
2051243830Sdim  static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx);
2052221345Sdim
2053234353Sdim  CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record,
2054226633Sdim                                 unsigned &Idx);
2055234353Sdim
2056212795Sdim  /// \brief Reads attributes from the current stream position.
2057234353Sdim  void ReadAttributes(ModuleFile &F, AttrVec &Attrs,
2058218893Sdim                      const RecordData &Record, unsigned &Idx);
2059212795Sdim
2060212795Sdim  /// \brief Reads a statement.
2061234353Sdim  Stmt *ReadStmt(ModuleFile &F);
2062212795Sdim
2063212795Sdim  /// \brief Reads an expression.
2064234353Sdim  Expr *ReadExpr(ModuleFile &F);
2065212795Sdim
2066212795Sdim  /// \brief Reads a sub-statement operand during statement reading.
2067212795Sdim  Stmt *ReadSubStmt() {
2068212795Sdim    assert(ReadingKind == Read_Stmt &&
2069212795Sdim           "Should be called only during statement reading!");
2070212795Sdim    // Subexpressions are stored from last to first, so the next Stmt we need
2071212795Sdim    // is at the back of the stack.
2072276479Sdim    assert(!StmtStack.empty() && "Read too many sub-statements!");
2073212795Sdim    return StmtStack.pop_back_val();
2074212795Sdim  }
2075212795Sdim
2076212795Sdim  /// \brief Reads a sub-expression operand during statement reading.
2077212795Sdim  Expr *ReadSubExpr();
2078212795Sdim
2079251662Sdim  /// \brief Reads a token out of a record.
2080261991Sdim  Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx);
2081251662Sdim
2082212795Sdim  /// \brief Reads the macro record located at the given offset.
2083249423Sdim  MacroInfo *ReadMacroRecord(ModuleFile &F, uint64_t Offset);
2084234353Sdim
2085226633Sdim  /// \brief Determine the global preprocessed entity ID that corresponds to
2086226633Sdim  /// the given local ID within the given module.
2087234353Sdim  serialization::PreprocessedEntityID
2088234353Sdim  getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const;
2089234353Sdim
2090249423Sdim  /// \brief Add a macro to resolve imported from a module.
2091234353Sdim  ///
2092234353Sdim  /// \param II The name of the macro.
2093249423Sdim  /// \param M The module file.
2094249423Sdim  /// \param GMacID The global macro ID that is associated with this identifier.
2095249423Sdim  void addPendingMacroFromModule(IdentifierInfo *II,
2096249423Sdim                                 ModuleFile *M,
2097249423Sdim                                 serialization::GlobalMacroID GMacID,
2098276479Sdim                                 ArrayRef<serialization::SubmoduleID>);
2099249423Sdim
2100249423Sdim  /// \brief Add a macro to deserialize its macro directive history from a PCH.
2101234353Sdim  ///
2102249423Sdim  /// \param II The name of the macro.
2103249423Sdim  /// \param M The module file.
2104249423Sdim  /// \param MacroDirectivesOffset Offset of the serialized macro directive
2105249423Sdim  /// history.
2106249423Sdim  void addPendingMacroFromPCH(IdentifierInfo *II,
2107249423Sdim                              ModuleFile *M, uint64_t MacroDirectivesOffset);
2108234353Sdim
2109212795Sdim  /// \brief Read the set of macros defined by this external macro source.
2110276479Sdim  void ReadDefinedMacros() override;
2111212795Sdim
2112234353Sdim  /// \brief Update an out-of-date identifier.
2113276479Sdim  void updateOutOfDateIdentifier(IdentifierInfo &II) override;
2114234353Sdim
2115234353Sdim  /// \brief Note that this identifier is up-to-date.
2116234353Sdim  void markIdentifierUpToDate(IdentifierInfo *II);
2117234353Sdim
2118234353Sdim  /// \brief Load all external visible decls in the given DeclContext.
2119276479Sdim  void completeVisibleDeclsMap(const DeclContext *DC) override;
2120234353Sdim
2121212795Sdim  /// \brief Retrieve the AST context that this AST reader supplements.
2122226633Sdim  ASTContext &getContext() { return Context; }
2123212795Sdim
2124280031Sdim  // \brief Contains the IDs for declarations that were requested before we have
2125212795Sdim  // access to a Sema object.
2126280031Sdim  SmallVector<uint64_t, 16> PreloadedDeclIDs;
2127212795Sdim
2128212795Sdim  /// \brief Retrieve the semantic analysis object used to analyze the
2129212795Sdim  /// translation unit in which the precompiled header is being
2130212795Sdim  /// imported.
2131212795Sdim  Sema *getSema() { return SemaObj; }
2132212795Sdim
2133212795Sdim  /// \brief Retrieve the identifier table associated with the
2134212795Sdim  /// preprocessor.
2135212795Sdim  IdentifierTable &getIdentifierTable();
2136212795Sdim
2137212795Sdim  /// \brief Record that the given ID maps to the given switch-case
2138212795Sdim  /// statement.
2139212795Sdim  void RecordSwitchCaseID(SwitchCase *SC, unsigned ID);
2140212795Sdim
2141212795Sdim  /// \brief Retrieve the switch-case statement with the given ID.
2142212795Sdim  SwitchCase *getSwitchCaseWithID(unsigned ID);
2143212795Sdim
2144218893Sdim  void ClearSwitchCaseIDs();
2145239462Sdim
2146239462Sdim  /// \brief Cursors for comments blocks.
2147239462Sdim  SmallVector<std::pair<llvm::BitstreamCursor,
2148239462Sdim                        serialization::ModuleFile *>, 8> CommentsCursors;
2149239462Sdim
2150276479Sdim  //RIDErief Loads comments ranges.
2151276479Sdim  void ReadComments() override;
2152280031Sdim
2153280031Sdim  /// Return all input files for the given module file.
2154280031Sdim  void getInputFiles(ModuleFile &F,
2155280031Sdim                     SmallVectorImpl<serialization::InputFile> &Files);
2156212795Sdim};
2157212795Sdim
2158212795Sdim/// \brief Helper class that saves the current stream position and
2159212795Sdim/// then restores it when destroyed.
2160212795Sdimstruct SavedStreamPosition {
2161212795Sdim  explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor)
2162249423Sdim    : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) { }
2163212795Sdim
2164212795Sdim  ~SavedStreamPosition() {
2165212795Sdim    Cursor.JumpToBit(Offset);
2166212795Sdim  }
2167212795Sdim
2168212795Sdimprivate:
2169212795Sdim  llvm::BitstreamCursor &Cursor;
2170212795Sdim  uint64_t Offset;
2171212795Sdim};
2172212795Sdim
2173212795Sdiminline void PCHValidator::Error(const char *Msg) {
2174212795Sdim  Reader.Error(Msg);
2175212795Sdim}
2176212795Sdim
2177212795Sdim} // end namespace clang
2178212795Sdim
2179212795Sdim#endif
2180