ASTReader.h revision e169807aaea2464cbe68305f013ec7b41625af30
1//===--- ASTReader.h - AST File Reader --------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//  This file defines the ASTReader class, which reads AST files.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_FRONTEND_AST_READER_H
15#define LLVM_CLANG_FRONTEND_AST_READER_H
16
17#include "clang/AST/DeclObjC.h"
18#include "clang/AST/DeclarationName.h"
19#include "clang/AST/TemplateBase.h"
20#include "clang/Basic/Diagnostic.h"
21#include "clang/Basic/FileManager.h"
22#include "clang/Basic/FileSystemOptions.h"
23#include "clang/Basic/IdentifierTable.h"
24#include "clang/Basic/SourceManager.h"
25#include "clang/Lex/ExternalPreprocessorSource.h"
26#include "clang/Lex/HeaderSearch.h"
27#include "clang/Lex/PPMutationListener.h"
28#include "clang/Lex/PreprocessingRecord.h"
29#include "clang/Sema/ExternalSemaSource.h"
30#include "clang/Serialization/ASTBitCodes.h"
31#include "clang/Serialization/ContinuousRangeMap.h"
32#include "clang/Serialization/Module.h"
33#include "clang/Serialization/ModuleManager.h"
34#include "llvm/ADT/APFloat.h"
35#include "llvm/ADT/APInt.h"
36#include "llvm/ADT/APSInt.h"
37#include "llvm/ADT/DenseSet.h"
38#include "llvm/ADT/MapVector.h"
39#include "llvm/ADT/OwningPtr.h"
40#include "llvm/ADT/SmallPtrSet.h"
41#include "llvm/ADT/SmallSet.h"
42#include "llvm/ADT/SmallVector.h"
43#include "llvm/ADT/StringRef.h"
44#include "llvm/Bitcode/BitstreamReader.h"
45#include "llvm/Support/DataTypes.h"
46#include <deque>
47#include <map>
48#include <string>
49#include <utility>
50#include <vector>
51
52namespace llvm {
53  class MemoryBuffer;
54}
55
56namespace clang {
57
58class AddrLabelExpr;
59class ASTConsumer;
60class ASTContext;
61class ASTIdentifierIterator;
62class ASTUnit; // FIXME: Layering violation and egregious hack.
63class Attr;
64class Decl;
65class DeclContext;
66class DiagnosticOptions;
67class NestedNameSpecifier;
68class CXXBaseSpecifier;
69class CXXConstructorDecl;
70class CXXCtorInitializer;
71class GotoStmt;
72class MacroDefinition;
73class NamedDecl;
74class OpaqueValueExpr;
75class Preprocessor;
76class PreprocessorOptions;
77class Sema;
78class SwitchCase;
79class ASTDeserializationListener;
80class ASTWriter;
81class ASTReader;
82class ASTDeclReader;
83class ASTStmtReader;
84class TypeLocReader;
85struct HeaderFileInfo;
86class VersionTuple;
87class TargetOptions;
88class ASTUnresolvedSet;
89
90/// \brief Abstract interface for callback invocations by the ASTReader.
91///
92/// While reading an AST file, the ASTReader will call the methods of the
93/// listener to pass on specific information. Some of the listener methods can
94/// return true to indicate to the ASTReader that the information (and
95/// consequently the AST file) is invalid.
96class ASTReaderListener {
97public:
98  virtual ~ASTReaderListener();
99
100  /// \brief Receives the language options.
101  ///
102  /// \returns true to indicate the options are invalid or false otherwise.
103  virtual bool ReadLanguageOptions(const LangOptions &LangOpts,
104                                   bool Complain) {
105    return false;
106  }
107
108  /// \brief Receives the target options.
109  ///
110  /// \returns true to indicate the target options are invalid, or false
111  /// otherwise.
112  virtual bool ReadTargetOptions(const TargetOptions &TargetOpts,
113                                 bool Complain) {
114    return false;
115  }
116
117  /// \brief Receives the diagnostic options.
118  ///
119  /// \returns true to indicate the diagnostic options are invalid, or false
120  /// otherwise.
121  virtual bool ReadDiagnosticOptions(const DiagnosticOptions &DiagOpts,
122                                     bool Complain) {
123    return false;
124  }
125
126  /// \brief Receives the file system options.
127  ///
128  /// \returns true to indicate the file system options are invalid, or false
129  /// otherwise.
130  virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
131                                     bool Complain) {
132    return false;
133  }
134
135  /// \brief Receives the header search options.
136  ///
137  /// \returns true to indicate the header search options are invalid, or false
138  /// otherwise.
139  virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
140                                       bool Complain) {
141    return false;
142  }
143
144  /// \brief Receives the preprocessor options.
145  ///
146  /// \param SuggestedPredefines Can be filled in with the set of predefines
147  /// that are suggested by the preprocessor options. Typically only used when
148  /// loading a precompiled header.
149  ///
150  /// \returns true to indicate the preprocessor options are invalid, or false
151  /// otherwise.
152  virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
153                                       bool Complain,
154                                       std::string &SuggestedPredefines) {
155    return false;
156  }
157
158  /// \brief Receives a HeaderFileInfo entry.
159  virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID) {}
160
161  /// \brief Receives __COUNTER__ value.
162  virtual void ReadCounter(const serialization::ModuleFile &M,
163                           unsigned Value) {}
164};
165
166/// \brief ASTReaderListener implementation to validate the information of
167/// the PCH file against an initialized Preprocessor.
168class PCHValidator : public ASTReaderListener {
169  Preprocessor &PP;
170  ASTReader &Reader;
171
172  unsigned NumHeaderInfos;
173
174public:
175  PCHValidator(Preprocessor &PP, ASTReader &Reader)
176    : PP(PP), Reader(Reader), NumHeaderInfos(0) {}
177
178  virtual bool ReadLanguageOptions(const LangOptions &LangOpts,
179                                   bool Complain);
180  virtual bool ReadTargetOptions(const TargetOptions &TargetOpts,
181                                 bool Complain);
182  virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
183                                       bool Complain,
184                                       std::string &SuggestedPredefines);
185  virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID);
186  virtual void ReadCounter(const serialization::ModuleFile &M, unsigned Value);
187
188private:
189  void Error(const char *Msg);
190};
191
192namespace serialization {
193
194class ReadMethodPoolVisitor;
195
196namespace reader {
197  class ASTIdentifierLookupTrait;
198  /// \brief The on-disk hash table used for the DeclContext's Name lookup table.
199  typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait>
200    ASTDeclContextNameLookupTable;
201}
202
203} // end namespace serialization
204
205/// \brief Reads an AST files chain containing the contents of a translation
206/// unit.
207///
208/// The ASTReader class reads bitstreams (produced by the ASTWriter
209/// class) containing the serialized representation of a given
210/// abstract syntax tree and its supporting data structures. An
211/// instance of the ASTReader can be attached to an ASTContext object,
212/// which will provide access to the contents of the AST files.
213///
214/// The AST reader provides lazy de-serialization of declarations, as
215/// required when traversing the AST. Only those AST nodes that are
216/// actually required will be de-serialized.
217class ASTReader
218  : public ExternalPreprocessorSource,
219    public ExternalPreprocessingRecordSource,
220    public ExternalHeaderFileInfoSource,
221    public ExternalSemaSource,
222    public IdentifierInfoLookup,
223    public ExternalIdentifierLookup,
224    public ExternalSLocEntrySource
225{
226public:
227  typedef SmallVector<uint64_t, 64> RecordData;
228
229  /// \brief The result of reading the control block of an AST file, which
230  /// can fail for various reasons.
231  enum ASTReadResult {
232    /// \brief The control block was read successfully. Aside from failures,
233    /// the AST file is safe to read into the current context.
234    Success,
235    /// \brief The AST file itself appears corrupted.
236    Failure,
237    /// \brief The AST file is out-of-date relative to its input files,
238    /// and needs to be regenerated.
239    OutOfDate,
240    /// \brief The AST file was written by a different version of Clang.
241    VersionMismatch,
242    /// \brief The AST file was writtten with a different language/target
243    /// configuration.
244    ConfigurationMismatch,
245    /// \brief The AST file has errors.
246    HadErrors
247  };
248
249  /// \brief Types of AST files.
250  friend class PCHValidator;
251  friend class ASTDeclReader;
252  friend class ASTStmtReader;
253  friend class ASTIdentifierIterator;
254  friend class serialization::reader::ASTIdentifierLookupTrait;
255  friend class TypeLocReader;
256  friend class ASTWriter;
257  friend class ASTUnit; // ASTUnit needs to remap source locations.
258  friend class serialization::ReadMethodPoolVisitor;
259
260  typedef serialization::ModuleFile ModuleFile;
261  typedef serialization::ModuleKind ModuleKind;
262  typedef serialization::ModuleManager ModuleManager;
263
264  typedef ModuleManager::ModuleIterator ModuleIterator;
265  typedef ModuleManager::ModuleConstIterator ModuleConstIterator;
266  typedef ModuleManager::ModuleReverseIterator ModuleReverseIterator;
267
268private:
269  /// \brief The receiver of some callbacks invoked by ASTReader.
270  OwningPtr<ASTReaderListener> Listener;
271
272  /// \brief The receiver of deserialization events.
273  ASTDeserializationListener *DeserializationListener;
274
275  SourceManager &SourceMgr;
276  FileManager &FileMgr;
277  DiagnosticsEngine &Diags;
278
279  /// \brief The semantic analysis object that will be processing the
280  /// AST files and the translation unit that uses it.
281  Sema *SemaObj;
282
283  /// \brief The preprocessor that will be loading the source file.
284  Preprocessor &PP;
285
286  /// \brief The AST context into which we'll read the AST files.
287  ASTContext &Context;
288
289  /// \brief The AST consumer.
290  ASTConsumer *Consumer;
291
292  /// \brief The module manager which manages modules and their dependencies
293  ModuleManager ModuleMgr;
294
295  /// \brief A map of global bit offsets to the module that stores entities
296  /// at those bit offsets.
297  ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap;
298
299  /// \brief A map of negated SLocEntryIDs to the modules containing them.
300  ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap;
301
302  typedef ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocOffsetMapType;
303
304  /// \brief A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset)
305  /// SourceLocation offsets to the modules containing them.
306  GlobalSLocOffsetMapType GlobalSLocOffsetMap;
307
308  /// \brief Types that have already been loaded from the chain.
309  ///
310  /// When the pointer at index I is non-NULL, the type with
311  /// ID = (I + 1) << FastQual::Width has already been loaded
312  std::vector<QualType> TypesLoaded;
313
314  typedef ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4>
315    GlobalTypeMapType;
316
317  /// \brief Mapping from global type IDs to the module in which the
318  /// type resides along with the offset that should be added to the
319  /// global type ID to produce a local ID.
320  GlobalTypeMapType GlobalTypeMap;
321
322  /// \brief Declarations that have already been loaded from the chain.
323  ///
324  /// When the pointer at index I is non-NULL, the declaration with ID
325  /// = I + 1 has already been loaded.
326  std::vector<Decl *> DeclsLoaded;
327
328  typedef ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4>
329    GlobalDeclMapType;
330
331  /// \brief Mapping from global declaration IDs to the module in which the
332  /// declaration resides.
333  GlobalDeclMapType GlobalDeclMap;
334
335  typedef std::pair<ModuleFile *, uint64_t> FileOffset;
336  typedef SmallVector<FileOffset, 2> FileOffsetsTy;
337  typedef llvm::DenseMap<serialization::DeclID, FileOffsetsTy>
338      DeclUpdateOffsetsMap;
339
340  /// \brief Declarations that have modifications residing in a later file
341  /// in the chain.
342  DeclUpdateOffsetsMap DeclUpdateOffsets;
343
344  struct ReplacedDeclInfo {
345    ModuleFile *Mod;
346    uint64_t Offset;
347    unsigned RawLoc;
348
349    ReplacedDeclInfo() : Mod(0), Offset(0), RawLoc(0) {}
350    ReplacedDeclInfo(ModuleFile *Mod, uint64_t Offset, unsigned RawLoc)
351      : Mod(Mod), Offset(Offset), RawLoc(RawLoc) {}
352  };
353
354  typedef llvm::DenseMap<serialization::DeclID, ReplacedDeclInfo>
355      DeclReplacementMap;
356  /// \brief Declarations that have been replaced in a later file in the chain.
357  DeclReplacementMap ReplacedDecls;
358
359  struct FileDeclsInfo {
360    ModuleFile *Mod;
361    ArrayRef<serialization::LocalDeclID> Decls;
362
363    FileDeclsInfo() : Mod(0) {}
364    FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls)
365      : Mod(Mod), Decls(Decls) {}
366  };
367
368  /// \brief Map from a FileID to the file-level declarations that it contains.
369  llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs;
370
371  // Updates for visible decls can occur for other contexts than just the
372  // TU, and when we read those update records, the actual context will not
373  // be available yet (unless it's the TU), so have this pending map using the
374  // ID as a key. It will be realized when the context is actually loaded.
375  typedef
376    SmallVector<std::pair<serialization::reader::ASTDeclContextNameLookupTable *,
377                          ModuleFile*>, 1> DeclContextVisibleUpdates;
378  typedef llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates>
379      DeclContextVisibleUpdatesPending;
380
381  /// \brief Updates to the visible declarations of declaration contexts that
382  /// haven't been loaded yet.
383  DeclContextVisibleUpdatesPending PendingVisibleUpdates;
384
385  /// \brief The set of C++ or Objective-C classes that have forward
386  /// declarations that have not yet been linked to their definitions.
387  llvm::SmallPtrSet<Decl *, 4> PendingDefinitions;
388
389  typedef llvm::MapVector<Decl *, uint64_t,
390                          llvm::SmallDenseMap<Decl *, unsigned, 4>,
391                          SmallVector<std::pair<Decl *, uint64_t>, 4> >
392    PendingBodiesMap;
393
394  /// \brief Functions or methods that have bodies that will be attached.
395  PendingBodiesMap PendingBodies;
396
397  /// \brief Read the records that describe the contents of declcontexts.
398  bool ReadDeclContextStorage(ModuleFile &M,
399                              llvm::BitstreamCursor &Cursor,
400                              const std::pair<uint64_t, uint64_t> &Offsets,
401                              serialization::DeclContextInfo &Info);
402
403  /// \brief A vector containing identifiers that have already been
404  /// loaded.
405  ///
406  /// If the pointer at index I is non-NULL, then it refers to the
407  /// IdentifierInfo for the identifier with ID=I+1 that has already
408  /// been loaded.
409  std::vector<IdentifierInfo *> IdentifiersLoaded;
410
411  typedef ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4>
412    GlobalIdentifierMapType;
413
414  /// \brief Mapping from global identifier IDs to the module in which the
415  /// identifier resides along with the offset that should be added to the
416  /// global identifier ID to produce a local ID.
417  GlobalIdentifierMapType GlobalIdentifierMap;
418
419  /// \brief A vector containing macros that have already been
420  /// loaded.
421  ///
422  /// If the pointer at index I is non-NULL, then it refers to the
423  /// MacroInfo for the identifier with ID=I+1 that has already
424  /// been loaded.
425  std::vector<MacroInfo *> MacrosLoaded;
426
427  typedef ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4>
428    GlobalMacroMapType;
429
430  /// \brief Mapping from global macro IDs to the module in which the
431  /// macro resides along with the offset that should be added to the
432  /// global macro ID to produce a local ID.
433  GlobalMacroMapType GlobalMacroMap;
434
435  typedef llvm::DenseMap<serialization::MacroID,
436            SmallVector<std::pair<serialization::SubmoduleID,
437                                        MacroUpdate>, 1> >
438    MacroUpdatesMap;
439
440  /// \brief Mapping from (global) macro IDs to the set of updates to be
441  /// performed to the corresponding macro.
442  MacroUpdatesMap MacroUpdates;
443
444  /// \brief A vector containing submodules that have already been loaded.
445  ///
446  /// This vector is indexed by the Submodule ID (-1). NULL submodule entries
447  /// indicate that the particular submodule ID has not yet been loaded.
448  SmallVector<Module *, 2> SubmodulesLoaded;
449
450  typedef ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4>
451    GlobalSubmoduleMapType;
452
453  /// \brief Mapping from global submodule IDs to the module file in which the
454  /// submodule resides along with the offset that should be added to the
455  /// global submodule ID to produce a local ID.
456  GlobalSubmoduleMapType GlobalSubmoduleMap;
457
458  /// \brief An entity that has been hidden.
459  class HiddenName {
460  public:
461    enum NameKind {
462      Declaration,
463      MacroVisibility,
464      MacroUndef
465    } Kind;
466
467  private:
468    unsigned Loc;
469
470    union {
471      Decl *D;
472      MacroInfo *MI;
473    };
474
475    IdentifierInfo *Id;
476
477  public:
478    HiddenName(Decl *D) : Kind(Declaration), Loc(), D(D), Id() { }
479
480    HiddenName(IdentifierInfo *II, MacroInfo *MI)
481      : Kind(MacroVisibility), Loc(), MI(MI), Id(II) { }
482
483    HiddenName(IdentifierInfo *II, MacroInfo *MI, SourceLocation Loc)
484      : Kind(MacroUndef), Loc(Loc.getRawEncoding()), MI(MI), Id(II) { }
485
486    NameKind getKind() const { return Kind; }
487
488    Decl *getDecl() const {
489      assert(getKind() == Declaration && "Hidden name is not a declaration");
490      return D;
491    }
492
493    std::pair<IdentifierInfo *, MacroInfo *> getMacro() const {
494      assert((getKind() == MacroUndef || getKind() == MacroVisibility)
495             && "Hidden name is not a macro!");
496      return std::make_pair(Id, MI);
497    }
498
499    SourceLocation getMacroUndefLoc() const {
500      assert(getKind() == MacroUndef && "Hidden name is not an undef!");
501      return SourceLocation::getFromRawEncoding(Loc);
502    }
503};
504
505  /// \brief A set of hidden declarations.
506  typedef SmallVector<HiddenName, 2> HiddenNames;
507
508  typedef llvm::DenseMap<Module *, HiddenNames> HiddenNamesMapType;
509
510  /// \brief A mapping from each of the hidden submodules to the deserialized
511  /// declarations in that submodule that could be made visible.
512  HiddenNamesMapType HiddenNamesMap;
513
514
515  /// \brief A module import or export that hasn't yet been resolved.
516  struct UnresolvedModuleImportExport {
517    /// \brief The file in which this module resides.
518    ModuleFile *File;
519
520    /// \brief The module that is importing or exporting.
521    Module *Mod;
522
523    /// \brief The local ID of the module that is being exported.
524    unsigned ID;
525
526    /// \brief Whether this is an import (vs. an export).
527    unsigned IsImport : 1;
528
529    /// \brief Whether this is a wildcard export.
530    unsigned IsWildcard : 1;
531  };
532
533  /// \brief The set of module imports and exports that still need to be
534  /// resolved.
535  SmallVector<UnresolvedModuleImportExport, 2> UnresolvedModuleImportExports;
536
537  /// \brief A vector containing selectors that have already been loaded.
538  ///
539  /// This vector is indexed by the Selector ID (-1). NULL selector
540  /// entries indicate that the particular selector ID has not yet
541  /// been loaded.
542  SmallVector<Selector, 16> SelectorsLoaded;
543
544  typedef ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4>
545    GlobalSelectorMapType;
546
547  /// \brief Mapping from global selector IDs to the module in which the
548  /// selector resides along with the offset that should be added to the
549  /// global selector ID to produce a local ID.
550  GlobalSelectorMapType GlobalSelectorMap;
551
552  /// \brief The generation number of the last time we loaded data from the
553  /// global method pool for this selector.
554  llvm::DenseMap<Selector, unsigned> SelectorGeneration;
555
556  typedef llvm::MapVector<IdentifierInfo *,
557                          SmallVector<serialization::MacroID, 2> >
558    PendingMacroIDsMap;
559
560  /// \brief Mapping from identifiers that have a macro history to the global
561  /// IDs have not yet been deserialized to the global IDs of those macros.
562  PendingMacroIDsMap PendingMacroIDs;
563
564  typedef ContinuousRangeMap<unsigned, ModuleFile *, 4>
565    GlobalPreprocessedEntityMapType;
566
567  /// \brief Mapping from global preprocessing entity IDs to the module in
568  /// which the preprocessed entity resides along with the offset that should be
569  /// added to the global preprocessing entitiy ID to produce a local ID.
570  GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
571
572  /// \name CodeGen-relevant special data
573  /// \brief Fields containing data that is relevant to CodeGen.
574  //@{
575
576  /// \brief The IDs of all declarations that fulfill the criteria of
577  /// "interesting" decls.
578  ///
579  /// This contains the data loaded from all EXTERNAL_DEFINITIONS blocks in the
580  /// chain. The referenced declarations are deserialized and passed to the
581  /// consumer eagerly.
582  SmallVector<uint64_t, 16> ExternalDefinitions;
583
584  /// \brief The IDs of all tentative definitions stored in the chain.
585  ///
586  /// Sema keeps track of all tentative definitions in a TU because it has to
587  /// complete them and pass them on to CodeGen. Thus, tentative definitions in
588  /// the PCH chain must be eagerly deserialized.
589  SmallVector<uint64_t, 16> TentativeDefinitions;
590
591  /// \brief The IDs of all CXXRecordDecls stored in the chain whose VTables are
592  /// used.
593  ///
594  /// CodeGen has to emit VTables for these records, so they have to be eagerly
595  /// deserialized.
596  SmallVector<uint64_t, 64> VTableUses;
597
598  /// \brief A snapshot of the pending instantiations in the chain.
599  ///
600  /// This record tracks the instantiations that Sema has to perform at the
601  /// end of the TU. It consists of a pair of values for every pending
602  /// instantiation where the first value is the ID of the decl and the second
603  /// is the instantiation location.
604  SmallVector<uint64_t, 64> PendingInstantiations;
605
606  //@}
607
608  /// \name DiagnosticsEngine-relevant special data
609  /// \brief Fields containing data that is used for generating diagnostics
610  //@{
611
612  /// \brief A snapshot of Sema's unused file-scoped variable tracking, for
613  /// generating warnings.
614  SmallVector<uint64_t, 16> UnusedFileScopedDecls;
615
616  /// \brief A list of all the delegating constructors we've seen, to diagnose
617  /// cycles.
618  SmallVector<uint64_t, 4> DelegatingCtorDecls;
619
620  /// \brief Method selectors used in a @selector expression. Used for
621  /// implementation of -Wselector.
622  SmallVector<uint64_t, 64> ReferencedSelectorsData;
623
624  /// \brief A snapshot of Sema's weak undeclared identifier tracking, for
625  /// generating warnings.
626  SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers;
627
628  /// \brief The IDs of type aliases for ext_vectors that exist in the chain.
629  ///
630  /// Used by Sema for finding sugared names for ext_vectors in diagnostics.
631  SmallVector<uint64_t, 4> ExtVectorDecls;
632
633  //@}
634
635  /// \name Sema-relevant special data
636  /// \brief Fields containing data that is used for semantic analysis
637  //@{
638
639  /// \brief The IDs of all locally scoped extern "C" decls in the chain.
640  ///
641  /// Sema tracks these to validate that the types are consistent across all
642  /// local extern "C" declarations.
643  SmallVector<uint64_t, 16> LocallyScopedExternCDecls;
644
645  /// \brief The IDs of all dynamic class declarations in the chain.
646  ///
647  /// Sema tracks these because it checks for the key functions being defined
648  /// at the end of the TU, in which case it directs CodeGen to emit the VTable.
649  SmallVector<uint64_t, 16> DynamicClasses;
650
651  /// \brief The IDs of the declarations Sema stores directly.
652  ///
653  /// Sema tracks a few important decls, such as namespace std, directly.
654  SmallVector<uint64_t, 4> SemaDeclRefs;
655
656  /// \brief The IDs of the types ASTContext stores directly.
657  ///
658  /// The AST context tracks a few important types, such as va_list, directly.
659  SmallVector<uint64_t, 16> SpecialTypes;
660
661  /// \brief The IDs of CUDA-specific declarations ASTContext stores directly.
662  ///
663  /// The AST context tracks a few important decls, currently cudaConfigureCall,
664  /// directly.
665  SmallVector<uint64_t, 2> CUDASpecialDeclRefs;
666
667  /// \brief The floating point pragma option settings.
668  SmallVector<uint64_t, 1> FPPragmaOptions;
669
670  /// \brief The OpenCL extension settings.
671  SmallVector<uint64_t, 1> OpenCLExtensions;
672
673  /// \brief A list of the namespaces we've seen.
674  SmallVector<uint64_t, 4> KnownNamespaces;
675
676  /// \brief A list of modules that were imported by precompiled headers or
677  /// any other non-module AST file.
678  SmallVector<serialization::SubmoduleID, 2> ImportedModules;
679  //@}
680
681  /// \brief The directory that the PCH we are reading is stored in.
682  std::string CurrentDir;
683
684  /// \brief The system include root to be used when loading the
685  /// precompiled header.
686  std::string isysroot;
687
688  /// \brief Whether to disable the normal validation performed on precompiled
689  /// headers when they are loaded.
690  bool DisableValidation;
691
692  /// \brief Whether to accept an AST file with compiler errors.
693  bool AllowASTWithCompilerErrors;
694
695  /// \brief The current "generation" of the module file import stack, which
696  /// indicates how many separate module file load operations have occurred.
697  unsigned CurrentGeneration;
698
699  typedef llvm::DenseMap<unsigned, SwitchCase *> SwitchCaseMapTy;
700  /// \brief Mapping from switch-case IDs in the chain to switch-case statements
701  ///
702  /// Statements usually don't have IDs, but switch cases need them, so that the
703  /// switch statement can refer to them.
704  SwitchCaseMapTy SwitchCaseStmts;
705
706  SwitchCaseMapTy *CurrSwitchCaseStmts;
707
708  /// \brief The number of source location entries de-serialized from
709  /// the PCH file.
710  unsigned NumSLocEntriesRead;
711
712  /// \brief The number of source location entries in the chain.
713  unsigned TotalNumSLocEntries;
714
715  /// \brief The number of statements (and expressions) de-serialized
716  /// from the chain.
717  unsigned NumStatementsRead;
718
719  /// \brief The total number of statements (and expressions) stored
720  /// in the chain.
721  unsigned TotalNumStatements;
722
723  /// \brief The number of macros de-serialized from the chain.
724  unsigned NumMacrosRead;
725
726  /// \brief The total number of macros stored in the chain.
727  unsigned TotalNumMacros;
728
729  /// \brief The number of lookups into identifier tables.
730  unsigned NumIdentifierLookups;
731
732  /// \brief The number of lookups into identifier tables that succeed.
733  unsigned NumIdentifierLookupHits;
734
735  /// \brief The number of selectors that have been read.
736  unsigned NumSelectorsRead;
737
738  /// \brief The number of method pool entries that have been read.
739  unsigned NumMethodPoolEntriesRead;
740
741  /// \brief The number of times we have looked up a selector in the method
742  /// pool and not found anything interesting.
743  unsigned NumMethodPoolMisses;
744
745  /// \brief The total number of method pool entries in the selector table.
746  unsigned TotalNumMethodPoolEntries;
747
748  /// Number of lexical decl contexts read/total.
749  unsigned NumLexicalDeclContextsRead, TotalLexicalDeclContexts;
750
751  /// Number of visible decl contexts read/total.
752  unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts;
753
754  /// Total size of modules, in bits, currently loaded
755  uint64_t TotalModulesSizeInBits;
756
757  /// \brief Number of Decl/types that are currently deserializing.
758  unsigned NumCurrentElementsDeserializing;
759
760  /// \brief Set true while we are in the process of passing deserialized
761  /// "interesting" decls to consumer inside FinishedDeserializing().
762  /// This is used as a guard to avoid recursively repeating the process of
763  /// passing decls to consumer.
764  bool PassingDeclsToConsumer;
765
766  /// Number of CXX base specifiers currently loaded
767  unsigned NumCXXBaseSpecifiersLoaded;
768
769  /// \brief An IdentifierInfo that has been loaded but whose top-level
770  /// declarations of the same name have not (yet) been loaded.
771  struct PendingIdentifierInfo {
772    IdentifierInfo *II;
773    SmallVector<uint32_t, 4> DeclIDs;
774  };
775
776  /// \brief The set of identifiers that were read while the AST reader was
777  /// (recursively) loading declarations.
778  ///
779  /// The declarations on the identifier chain for these identifiers will be
780  /// loaded once the recursive loading has completed.
781  std::deque<PendingIdentifierInfo> PendingIdentifierInfos;
782
783  /// \brief The generation number of each identifier, which keeps track of
784  /// the last time we loaded information about this identifier.
785  llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration;
786
787  /// \brief Contains declarations and definitions that will be
788  /// "interesting" to the ASTConsumer, when we get that AST consumer.
789  ///
790  /// "Interesting" declarations are those that have data that may
791  /// need to be emitted, such as inline function definitions or
792  /// Objective-C protocols.
793  std::deque<Decl *> InterestingDecls;
794
795  /// \brief The set of redeclarable declarations that have been deserialized
796  /// since the last time the declaration chains were linked.
797  llvm::SmallPtrSet<Decl *, 16> RedeclsDeserialized;
798
799  /// \brief The list of redeclaration chains that still need to be
800  /// reconstructed.
801  ///
802  /// Each element is the global declaration ID of the first declaration in
803  /// the chain. Elements in this vector should be unique; use
804  /// PendingDeclChainsKnown to ensure uniqueness.
805  SmallVector<serialization::DeclID, 16> PendingDeclChains;
806
807  /// \brief Keeps track of the elements added to PendingDeclChains.
808  llvm::SmallSet<serialization::DeclID, 16> PendingDeclChainsKnown;
809
810  /// \brief The set of Objective-C categories that have been deserialized
811  /// since the last time the declaration chains were linked.
812  llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized;
813
814  /// \brief The set of Objective-C class definitions that have already been
815  /// loaded, for which we will need to check for categories whenever a new
816  /// module is loaded.
817  SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded;
818
819  typedef llvm::DenseMap<Decl *, SmallVector<serialization::DeclID, 2> >
820    MergedDeclsMap;
821
822  /// \brief A mapping from canonical declarations to the set of additional
823  /// (global, previously-canonical) declaration IDs that have been merged with
824  /// that canonical declaration.
825  MergedDeclsMap MergedDecls;
826
827  typedef llvm::DenseMap<serialization::GlobalDeclID,
828                         SmallVector<serialization::DeclID, 2> >
829    StoredMergedDeclsMap;
830
831  /// \brief A mapping from canonical declaration IDs to the set of additional
832  /// declaration IDs that have been merged with that canonical declaration.
833  ///
834  /// This is the deserialized representation of the entries in MergedDecls.
835  /// When we query entries in MergedDecls, they will be augmented with entries
836  /// from StoredMergedDecls.
837  StoredMergedDeclsMap StoredMergedDecls;
838
839  /// \brief Combine the stored merged declarations for the given canonical
840  /// declaration into the set of merged declarations.
841  ///
842  /// \returns An iterator into MergedDecls that corresponds to the position of
843  /// the given canonical declaration.
844  MergedDeclsMap::iterator
845  combineStoredMergedDecls(Decl *Canon, serialization::GlobalDeclID CanonID);
846
847  /// \brief Ready to load the previous declaration of the given Decl.
848  void loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID);
849
850  /// \brief When reading a Stmt tree, Stmt operands are placed in this stack.
851  SmallVector<Stmt *, 16> StmtStack;
852
853  /// \brief What kind of records we are reading.
854  enum ReadingKind {
855    Read_Decl, Read_Type, Read_Stmt
856  };
857
858  /// \brief What kind of records we are reading.
859  ReadingKind ReadingKind;
860
861  /// \brief RAII object to change the reading kind.
862  class ReadingKindTracker {
863    ASTReader &Reader;
864    enum ReadingKind PrevKind;
865
866    ReadingKindTracker(const ReadingKindTracker &) LLVM_DELETED_FUNCTION;
867    void operator=(const ReadingKindTracker &) LLVM_DELETED_FUNCTION;
868
869  public:
870    ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader)
871      : Reader(reader), PrevKind(Reader.ReadingKind) {
872      Reader.ReadingKind = newKind;
873    }
874
875    ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; }
876  };
877
878  /// \brief Suggested contents of the predefines buffer, after this
879  /// PCH file has been processed.
880  ///
881  /// In most cases, this string will be empty, because the predefines
882  /// buffer computed to build the PCH file will be identical to the
883  /// predefines buffer computed from the command line. However, when
884  /// there are differences that the PCH reader can work around, this
885  /// predefines buffer may contain additional definitions.
886  std::string SuggestedPredefines;
887
888  /// \brief Reads a statement from the specified cursor.
889  Stmt *ReadStmtFromStream(ModuleFile &F);
890
891  typedef llvm::PointerIntPair<const FileEntry *, 1, bool> InputFile;
892
893  /// \brief Retrieve the file entry and 'overridden' bit for an input
894  /// file in the given module file.
895  InputFile getInputFile(ModuleFile &F, unsigned ID, bool Complain = true);
896
897  /// \brief Get a FileEntry out of stored-in-PCH filename, making sure we take
898  /// into account all the necessary relocations.
899  const FileEntry *getFileEntry(StringRef filename);
900
901  void MaybeAddSystemRootToFilename(ModuleFile &M, std::string &Filename);
902
903  struct ImportedModule {
904    ModuleFile *Mod;
905    ModuleFile *ImportedBy;
906    SourceLocation ImportLoc;
907
908    ImportedModule(ModuleFile *Mod,
909                   ModuleFile *ImportedBy,
910                   SourceLocation ImportLoc)
911      : Mod(Mod), ImportedBy(ImportedBy), ImportLoc(ImportLoc) { }
912  };
913
914  ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type,
915                            SourceLocation ImportLoc, ModuleFile *ImportedBy,
916                            SmallVectorImpl<ImportedModule> &Loaded,
917                            unsigned ClientLoadCapabilities);
918  ASTReadResult ReadControlBlock(ModuleFile &F,
919                                 SmallVectorImpl<ImportedModule> &Loaded,
920                                 unsigned ClientLoadCapabilities);
921  bool ReadASTBlock(ModuleFile &F);
922  bool ParseLineTable(ModuleFile &F, SmallVectorImpl<uint64_t> &Record);
923  bool ReadSourceManagerBlock(ModuleFile &F);
924  llvm::BitstreamCursor &SLocCursorForID(int ID);
925  SourceLocation getImportLocation(ModuleFile *F);
926  bool ReadSubmoduleBlock(ModuleFile &F);
927  static bool ParseLanguageOptions(const RecordData &Record, bool Complain,
928                                   ASTReaderListener &Listener);
929  static bool ParseTargetOptions(const RecordData &Record, bool Complain,
930                                 ASTReaderListener &Listener);
931  static bool ParseDiagnosticOptions(const RecordData &Record, bool Complain,
932                                     ASTReaderListener &Listener);
933  static bool ParseFileSystemOptions(const RecordData &Record, bool Complain,
934                                     ASTReaderListener &Listener);
935  static bool ParseHeaderSearchOptions(const RecordData &Record, bool Complain,
936                                       ASTReaderListener &Listener);
937  static bool ParsePreprocessorOptions(const RecordData &Record, bool Complain,
938                                       ASTReaderListener &Listener,
939                                       std::string &SuggestedPredefines);
940
941  struct RecordLocation {
942    RecordLocation(ModuleFile *M, uint64_t O)
943      : F(M), Offset(O) {}
944    ModuleFile *F;
945    uint64_t Offset;
946  };
947
948  QualType readTypeRecord(unsigned Index);
949  RecordLocation TypeCursorForIndex(unsigned Index);
950  void LoadedDecl(unsigned Index, Decl *D);
951  Decl *ReadDeclRecord(serialization::DeclID ID);
952  RecordLocation DeclCursorForID(serialization::DeclID ID,
953                                 unsigned &RawLocation);
954  void loadDeclUpdateRecords(serialization::DeclID ID, Decl *D);
955  void loadPendingDeclChain(serialization::GlobalDeclID ID);
956  void loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D,
957                          unsigned PreviousGeneration = 0);
958
959  RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
960  uint64_t getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset);
961
962  /// \brief Returns the first preprocessed entity ID that ends after BLoc.
963  serialization::PreprocessedEntityID
964    findBeginPreprocessedEntity(SourceLocation BLoc) const;
965
966  /// \brief Returns the first preprocessed entity ID that begins after ELoc.
967  serialization::PreprocessedEntityID
968    findEndPreprocessedEntity(SourceLocation ELoc) const;
969
970  /// \brief Find the next module that contains entities and return the ID
971  /// of the first entry.
972  ///
973  /// \param SLocMapI points at a chunk of a module that contains no
974  /// preprocessed entities or the entities it contains are not the
975  /// ones we are looking for.
976  serialization::PreprocessedEntityID
977    findNextPreprocessedEntity(
978                        GlobalSLocOffsetMapType::const_iterator SLocMapI) const;
979
980  /// \brief Returns (ModuleFile, Local index) pair for \p GlobalIndex of a
981  /// preprocessed entity.
982  std::pair<ModuleFile *, unsigned>
983    getModulePreprocessedEntity(unsigned GlobalIndex);
984
985  /// \brief Returns (begin, end) pair for the preprocessed entities of a
986  /// particular module.
987  std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator>
988    getModulePreprocessedEntities(ModuleFile &Mod) const;
989
990  class ModuleDeclIterator {
991    ASTReader *Reader;
992    ModuleFile *Mod;
993    const serialization::LocalDeclID *Pos;
994
995  public:
996    typedef const Decl *value_type;
997    typedef value_type&         reference;
998    typedef value_type*         pointer;
999
1000    ModuleDeclIterator() : Reader(0), Mod(0), Pos(0) { }
1001
1002    ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod,
1003                       const serialization::LocalDeclID *Pos)
1004      : Reader(Reader), Mod(Mod), Pos(Pos) { }
1005
1006    value_type operator*() const {
1007      return Reader->GetDecl(Reader->getGlobalDeclID(*Mod, *Pos));
1008    }
1009
1010    ModuleDeclIterator &operator++() {
1011      ++Pos;
1012      return *this;
1013    }
1014
1015    ModuleDeclIterator operator++(int) {
1016      ModuleDeclIterator Prev(*this);
1017      ++Pos;
1018      return Prev;
1019    }
1020
1021    ModuleDeclIterator &operator--() {
1022      --Pos;
1023      return *this;
1024    }
1025
1026    ModuleDeclIterator operator--(int) {
1027      ModuleDeclIterator Prev(*this);
1028      --Pos;
1029      return Prev;
1030    }
1031
1032    friend bool operator==(const ModuleDeclIterator &LHS,
1033                           const ModuleDeclIterator &RHS) {
1034      assert(LHS.Reader == RHS.Reader && LHS.Mod == RHS.Mod);
1035      return LHS.Pos == RHS.Pos;
1036    }
1037
1038    friend bool operator!=(const ModuleDeclIterator &LHS,
1039                           const ModuleDeclIterator &RHS) {
1040      assert(LHS.Reader == RHS.Reader && LHS.Mod == RHS.Mod);
1041      return LHS.Pos != RHS.Pos;
1042    }
1043  };
1044
1045  std::pair<ModuleDeclIterator, ModuleDeclIterator>
1046    getModuleFileLevelDecls(ModuleFile &Mod);
1047
1048  void PassInterestingDeclsToConsumer();
1049  void PassInterestingDeclToConsumer(Decl *D);
1050
1051  void finishPendingActions();
1052
1053  /// \brief Produce an error diagnostic and return true.
1054  ///
1055  /// This routine should only be used for fatal errors that have to
1056  /// do with non-routine failures (e.g., corrupted AST file).
1057  void Error(StringRef Msg);
1058  void Error(unsigned DiagID, StringRef Arg1 = StringRef(),
1059             StringRef Arg2 = StringRef());
1060
1061  ASTReader(const ASTReader &) LLVM_DELETED_FUNCTION;
1062  void operator=(const ASTReader &) LLVM_DELETED_FUNCTION;
1063public:
1064  /// \brief Load the AST file and validate its contents against the given
1065  /// Preprocessor.
1066  ///
1067  /// \param PP the preprocessor associated with the context in which this
1068  /// precompiled header will be loaded.
1069  ///
1070  /// \param Context the AST context that this precompiled header will be
1071  /// loaded into.
1072  ///
1073  /// \param isysroot If non-NULL, the system include path specified by the
1074  /// user. This is only used with relocatable PCH files. If non-NULL,
1075  /// a relocatable PCH file will use the default path "/".
1076  ///
1077  /// \param DisableValidation If true, the AST reader will suppress most
1078  /// of its regular consistency checking, allowing the use of precompiled
1079  /// headers that cannot be determined to be compatible.
1080  ///
1081  /// \param AllowASTWithCompilerErrors If true, the AST reader will accept an
1082  /// AST file the was created out of an AST with compiler errors,
1083  /// otherwise it will reject it.
1084  ASTReader(Preprocessor &PP, ASTContext &Context, StringRef isysroot = "",
1085            bool DisableValidation = false,
1086            bool AllowASTWithCompilerErrors = false);
1087
1088  ~ASTReader();
1089
1090  SourceManager &getSourceManager() const { return SourceMgr; }
1091
1092  /// \brief Flags that indicate what kind of AST loading failures the client
1093  /// of the AST reader can directly handle.
1094  ///
1095  /// When a client states that it can handle a particular kind of failure,
1096  /// the AST reader will not emit errors when producing that kind of failure.
1097  enum LoadFailureCapabilities {
1098    /// \brief The client can't handle any AST loading failures.
1099    ARR_None = 0,
1100    /// \brief The client can handle an AST file that cannot load because it
1101    /// is out-of-date relative to its input files.
1102    ARR_OutOfDate = 0x1,
1103    /// \brief The client can handle an AST file that cannot load because it
1104    /// was built with a different version of Clang.
1105    ARR_VersionMismatch = 0x2,
1106    /// \brief The client can handle an AST file that cannot load because it's
1107    /// compiled configuration doesn't match that of the context it was
1108    /// loaded into.
1109    ARR_ConfigurationMismatch = 0x4
1110  };
1111
1112  /// \brief Load the AST file designated by the given file name.
1113  ///
1114  /// \param FileName The name of the AST file to load.
1115  ///
1116  /// \param Type The kind of AST being loaded, e.g., PCH, module, main file,
1117  /// or preamble.
1118  ///
1119  /// \param ImportLoc the location where the module file will be considered as
1120  /// imported from. For non-module AST types it should be invalid.
1121  ///
1122  /// \param ClientLoadCapabilities The set of client load-failure
1123  /// capabilities, represented as a bitset of the enumerators of
1124  /// LoadFailureCapabilities.
1125  ASTReadResult ReadAST(const std::string &FileName, ModuleKind Type,
1126                        SourceLocation ImportLoc,
1127                        unsigned ClientLoadCapabilities);
1128
1129  /// \brief Make the entities in the given module and any of its (non-explicit)
1130  /// submodules visible to name lookup.
1131  ///
1132  /// \param Mod The module whose names should be made visible.
1133  ///
1134  /// \param NameVisibility The level of visibility to give the names in the
1135  /// module.  Visibility can only be increased over time.
1136  void makeModuleVisible(Module *Mod,
1137                         Module::NameVisibilityKind NameVisibility);
1138
1139  /// \brief Make the names within this set of hidden names visible.
1140  void makeNamesVisible(const HiddenNames &Names);
1141
1142  /// \brief Set the AST callbacks listener.
1143  void setListener(ASTReaderListener *listener) {
1144    Listener.reset(listener);
1145  }
1146
1147  /// \brief Set the AST deserialization listener.
1148  void setDeserializationListener(ASTDeserializationListener *Listener);
1149
1150  /// \brief Initializes the ASTContext
1151  void InitializeContext();
1152
1153  /// \brief Add in-memory (virtual file) buffer.
1154  void addInMemoryBuffer(StringRef &FileName, llvm::MemoryBuffer *Buffer) {
1155    ModuleMgr.addInMemoryBuffer(FileName, Buffer);
1156  }
1157
1158  /// \brief Finalizes the AST reader's state before writing an AST file to
1159  /// disk.
1160  ///
1161  /// This operation may undo temporary state in the AST that should not be
1162  /// emitted.
1163  void finalizeForWriting();
1164
1165  /// \brief Retrieve the module manager.
1166  ModuleManager &getModuleManager() { return ModuleMgr; }
1167
1168  /// \brief Retrieve the preprocessor.
1169  Preprocessor &getPreprocessor() const { return PP; }
1170
1171  /// \brief Retrieve the name of the original source file name for the primary
1172  /// module file.
1173  StringRef getOriginalSourceFile() {
1174    return ModuleMgr.getPrimaryModule().OriginalSourceFileName;
1175  }
1176
1177  /// \brief Retrieve the name of the original source file name directly from
1178  /// the AST file, without actually loading the AST file.
1179  static std::string getOriginalSourceFile(const std::string &ASTFileName,
1180                                           FileManager &FileMgr,
1181                                           DiagnosticsEngine &Diags);
1182
1183  /// \brief Read the control block for the named AST file.
1184  ///
1185  /// \returns true if an error occurred, false otherwise.
1186  static bool readASTFileControlBlock(StringRef Filename,
1187                                      FileManager &FileMgr,
1188                                      ASTReaderListener &Listener);
1189
1190  /// \brief Determine whether the given AST file is acceptable to load into a
1191  /// translation unit with the given language and target options.
1192  static bool isAcceptableASTFile(StringRef Filename,
1193                                  FileManager &FileMgr,
1194                                  const LangOptions &LangOpts,
1195                                  const TargetOptions &TargetOpts,
1196                                  const PreprocessorOptions &PPOpts);
1197
1198  /// \brief Returns the suggested contents of the predefines buffer,
1199  /// which contains a (typically-empty) subset of the predefines
1200  /// build prior to including the precompiled header.
1201  const std::string &getSuggestedPredefines() { return SuggestedPredefines; }
1202
1203  /// \brief Read a preallocated preprocessed entity from the external source.
1204  ///
1205  /// \returns null if an error occurred that prevented the preprocessed
1206  /// entity from being loaded.
1207  virtual PreprocessedEntity *ReadPreprocessedEntity(unsigned Index);
1208
1209  /// \brief Returns a pair of [Begin, End) indices of preallocated
1210  /// preprocessed entities that \p Range encompasses.
1211  virtual std::pair<unsigned, unsigned>
1212      findPreprocessedEntitiesInRange(SourceRange Range);
1213
1214  /// \brief Optionally returns true or false if the preallocated preprocessed
1215  /// entity with index \p Index came from file \p FID.
1216  virtual llvm::Optional<bool> isPreprocessedEntityInFileID(unsigned Index,
1217                                                            FileID FID);
1218
1219  /// \brief Read the header file information for the given file entry.
1220  virtual HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE);
1221
1222  void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag);
1223
1224  /// \brief Returns the number of source locations found in the chain.
1225  unsigned getTotalNumSLocs() const {
1226    return TotalNumSLocEntries;
1227  }
1228
1229  /// \brief Returns the number of identifiers found in the chain.
1230  unsigned getTotalNumIdentifiers() const {
1231    return static_cast<unsigned>(IdentifiersLoaded.size());
1232  }
1233
1234  /// \brief Returns the number of macros found in the chain.
1235  unsigned getTotalNumMacros() const {
1236    return static_cast<unsigned>(MacrosLoaded.size());
1237  }
1238
1239  /// \brief Returns the number of types found in the chain.
1240  unsigned getTotalNumTypes() const {
1241    return static_cast<unsigned>(TypesLoaded.size());
1242  }
1243
1244  /// \brief Returns the number of declarations found in the chain.
1245  unsigned getTotalNumDecls() const {
1246    return static_cast<unsigned>(DeclsLoaded.size());
1247  }
1248
1249  /// \brief Returns the number of submodules known.
1250  unsigned getTotalNumSubmodules() const {
1251    return static_cast<unsigned>(SubmodulesLoaded.size());
1252  }
1253
1254  /// \brief Returns the number of selectors found in the chain.
1255  unsigned getTotalNumSelectors() const {
1256    return static_cast<unsigned>(SelectorsLoaded.size());
1257  }
1258
1259  /// \brief Returns the number of preprocessed entities known to the AST
1260  /// reader.
1261  unsigned getTotalNumPreprocessedEntities() const {
1262    unsigned Result = 0;
1263    for (ModuleConstIterator I = ModuleMgr.begin(),
1264        E = ModuleMgr.end(); I != E; ++I) {
1265      Result += (*I)->NumPreprocessedEntities;
1266    }
1267
1268    return Result;
1269  }
1270
1271  /// \brief Returns the number of C++ base specifiers found in the chain.
1272  unsigned getTotalNumCXXBaseSpecifiers() const {
1273    return NumCXXBaseSpecifiersLoaded;
1274  }
1275
1276  /// \brief Reads a TemplateArgumentLocInfo appropriate for the
1277  /// given TemplateArgument kind.
1278  TemplateArgumentLocInfo
1279  GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind,
1280                             const RecordData &Record, unsigned &Idx);
1281
1282  /// \brief Reads a TemplateArgumentLoc.
1283  TemplateArgumentLoc
1284  ReadTemplateArgumentLoc(ModuleFile &F,
1285                          const RecordData &Record, unsigned &Idx);
1286
1287  /// \brief Reads a declarator info from the given record.
1288  TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F,
1289                                    const RecordData &Record, unsigned &Idx);
1290
1291  /// \brief Resolve a type ID into a type, potentially building a new
1292  /// type.
1293  QualType GetType(serialization::TypeID ID);
1294
1295  /// \brief Resolve a local type ID within a given AST file into a type.
1296  QualType getLocalType(ModuleFile &F, unsigned LocalID);
1297
1298  /// \brief Map a local type ID within a given AST file into a global type ID.
1299  serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const;
1300
1301  /// \brief Read a type from the current position in the given record, which
1302  /// was read from the given AST file.
1303  QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) {
1304    if (Idx >= Record.size())
1305      return QualType();
1306
1307    return getLocalType(F, Record[Idx++]);
1308  }
1309
1310  /// \brief Map from a local declaration ID within a given module to a
1311  /// global declaration ID.
1312  serialization::DeclID getGlobalDeclID(ModuleFile &F,
1313                                      serialization::LocalDeclID LocalID) const;
1314
1315  /// \brief Returns true if global DeclID \p ID originated from module \p M.
1316  bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const;
1317
1318  /// \brief Retrieve the module file that owns the given declaration, or NULL
1319  /// if the declaration is not from a module file.
1320  ModuleFile *getOwningModuleFile(const Decl *D);
1321
1322  /// \brief Returns the source location for the decl \p ID.
1323  SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID);
1324
1325  /// \brief Resolve a declaration ID into a declaration, potentially
1326  /// building a new declaration.
1327  Decl *GetDecl(serialization::DeclID ID);
1328  virtual Decl *GetExternalDecl(uint32_t ID);
1329
1330  /// \brief Reads a declaration with the given local ID in the given module.
1331  Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) {
1332    return GetDecl(getGlobalDeclID(F, LocalID));
1333  }
1334
1335  /// \brief Reads a declaration with the given local ID in the given module.
1336  ///
1337  /// \returns The requested declaration, casted to the given return type.
1338  template<typename T>
1339  T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) {
1340    return cast_or_null<T>(GetLocalDecl(F, LocalID));
1341  }
1342
1343  /// \brief Map a global declaration ID into the declaration ID used to
1344  /// refer to this declaration within the given module fule.
1345  ///
1346  /// \returns the global ID of the given declaration as known in the given
1347  /// module file.
1348  serialization::DeclID
1349  mapGlobalIDToModuleFileGlobalID(ModuleFile &M,
1350                                  serialization::DeclID GlobalID);
1351
1352  /// \brief Reads a declaration ID from the given position in a record in the
1353  /// given module.
1354  ///
1355  /// \returns The declaration ID read from the record, adjusted to a global ID.
1356  serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record,
1357                                   unsigned &Idx);
1358
1359  /// \brief Reads a declaration from the given position in a record in the
1360  /// given module.
1361  Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) {
1362    return GetDecl(ReadDeclID(F, R, I));
1363  }
1364
1365  /// \brief Reads a declaration from the given position in a record in the
1366  /// given module.
1367  ///
1368  /// \returns The declaration read from this location, casted to the given
1369  /// result type.
1370  template<typename T>
1371  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1372    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1373  }
1374
1375  /// \brief Read a CXXBaseSpecifiers ID form the given record and
1376  /// return its global bit offset.
1377  uint64_t readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record,
1378                                 unsigned &Idx);
1379
1380  virtual CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset);
1381
1382  /// \brief Resolve the offset of a statement into a statement.
1383  ///
1384  /// This operation will read a new statement from the external
1385  /// source each time it is called, and is meant to be used via a
1386  /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
1387  virtual Stmt *GetExternalDeclStmt(uint64_t Offset);
1388
1389  /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
1390  /// specified cursor.  Read the abbreviations that are at the top of the block
1391  /// and then leave the cursor pointing into the block.
1392  bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID);
1393
1394  /// \brief Finds all the visible declarations with a given name.
1395  /// The current implementation of this method just loads the entire
1396  /// lookup table as unmaterialized references.
1397  virtual DeclContext::lookup_result
1398  FindExternalVisibleDeclsByName(const DeclContext *DC,
1399                                 DeclarationName Name);
1400
1401  /// \brief Read all of the declarations lexically stored in a
1402  /// declaration context.
1403  ///
1404  /// \param DC The declaration context whose declarations will be
1405  /// read.
1406  ///
1407  /// \param Decls Vector that will contain the declarations loaded
1408  /// from the external source. The caller is responsible for merging
1409  /// these declarations with any declarations already stored in the
1410  /// declaration context.
1411  ///
1412  /// \returns true if there was an error while reading the
1413  /// declarations for this declaration context.
1414  virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
1415                                        bool (*isKindWeWant)(Decl::Kind),
1416                                        SmallVectorImpl<Decl*> &Decls);
1417
1418  /// \brief Get the decls that are contained in a file in the Offset/Length
1419  /// range. \p Length can be 0 to indicate a point at \p Offset instead of
1420  /// a range.
1421  virtual void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length,
1422                                   SmallVectorImpl<Decl *> &Decls);
1423
1424  /// \brief Notify ASTReader that we started deserialization of
1425  /// a decl or type so until FinishedDeserializing is called there may be
1426  /// decls that are initializing. Must be paired with FinishedDeserializing.
1427  virtual void StartedDeserializing() { ++NumCurrentElementsDeserializing; }
1428
1429  /// \brief Notify ASTReader that we finished the deserialization of
1430  /// a decl or type. Must be paired with StartedDeserializing.
1431  virtual void FinishedDeserializing();
1432
1433  /// \brief Function that will be invoked when we begin parsing a new
1434  /// translation unit involving this external AST source.
1435  ///
1436  /// This function will provide all of the external definitions to
1437  /// the ASTConsumer.
1438  virtual void StartTranslationUnit(ASTConsumer *Consumer);
1439
1440  /// \brief Print some statistics about AST usage.
1441  virtual void PrintStats();
1442
1443  /// \brief Dump information about the AST reader to standard error.
1444  void dump();
1445
1446  /// Return the amount of memory used by memory buffers, breaking down
1447  /// by heap-backed versus mmap'ed memory.
1448  virtual void getMemoryBufferSizes(MemoryBufferSizes &sizes) const;
1449
1450  /// \brief Initialize the semantic source with the Sema instance
1451  /// being used to perform semantic analysis on the abstract syntax
1452  /// tree.
1453  virtual void InitializeSema(Sema &S);
1454
1455  /// \brief Inform the semantic consumer that Sema is no longer available.
1456  virtual void ForgetSema() { SemaObj = 0; }
1457
1458  /// \brief Retrieve the IdentifierInfo for the named identifier.
1459  ///
1460  /// This routine builds a new IdentifierInfo for the given identifier. If any
1461  /// declarations with this name are visible from translation unit scope, their
1462  /// declarations will be deserialized and introduced into the declaration
1463  /// chain of the identifier.
1464  virtual IdentifierInfo *get(const char *NameStart, const char *NameEnd);
1465  IdentifierInfo *get(StringRef Name) {
1466    return get(Name.begin(), Name.end());
1467  }
1468
1469  /// \brief Retrieve an iterator into the set of all identifiers
1470  /// in all loaded AST files.
1471  virtual IdentifierIterator *getIdentifiers() const;
1472
1473  /// \brief Load the contents of the global method pool for a given
1474  /// selector.
1475  virtual void ReadMethodPool(Selector Sel);
1476
1477  /// \brief Load the set of namespaces that are known to the external source,
1478  /// which will be used during typo correction.
1479  virtual void ReadKnownNamespaces(
1480                           SmallVectorImpl<NamespaceDecl *> &Namespaces);
1481
1482  virtual void ReadTentativeDefinitions(
1483                 SmallVectorImpl<VarDecl *> &TentativeDefs);
1484
1485  virtual void ReadUnusedFileScopedDecls(
1486                 SmallVectorImpl<const DeclaratorDecl *> &Decls);
1487
1488  virtual void ReadDelegatingConstructors(
1489                 SmallVectorImpl<CXXConstructorDecl *> &Decls);
1490
1491  virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls);
1492
1493  virtual void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls);
1494
1495  virtual void ReadLocallyScopedExternCDecls(
1496                 SmallVectorImpl<NamedDecl *> &Decls);
1497
1498  virtual void ReadReferencedSelectors(
1499                 SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels);
1500
1501  virtual void ReadWeakUndeclaredIdentifiers(
1502                 SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI);
1503
1504  virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables);
1505
1506  virtual void ReadPendingInstantiations(
1507                 SmallVectorImpl<std::pair<ValueDecl *,
1508                                           SourceLocation> > &Pending);
1509
1510  /// \brief Load a selector from disk, registering its ID if it exists.
1511  void LoadSelector(Selector Sel);
1512
1513  void SetIdentifierInfo(unsigned ID, IdentifierInfo *II);
1514  void SetGloballyVisibleDecls(IdentifierInfo *II,
1515                               const SmallVectorImpl<uint32_t> &DeclIDs,
1516                               bool Nonrecursive = false);
1517
1518  /// \brief Report a diagnostic.
1519  DiagnosticBuilder Diag(unsigned DiagID);
1520
1521  /// \brief Report a diagnostic.
1522  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
1523
1524  IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID);
1525
1526  IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record,
1527                                    unsigned &Idx) {
1528    return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++]));
1529  }
1530
1531  virtual IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) {
1532    // Note that we are loading an identifier.
1533    Deserializing AnIdentifier(this);
1534
1535    return DecodeIdentifierInfo(ID);
1536  }
1537
1538  IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID);
1539
1540  serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M,
1541                                                    unsigned LocalID);
1542
1543  /// \brief Retrieve the macro with the given ID.
1544  MacroInfo *getMacro(serialization::MacroID ID, MacroInfo *Hint = 0);
1545
1546  /// \brief Retrieve the global macro ID corresponding to the given local
1547  /// ID within the given module file.
1548  serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID);
1549
1550  /// \brief Read the source location entry with index ID.
1551  virtual bool ReadSLocEntry(int ID);
1552
1553  /// \brief Retrieve the module import location and module name for the
1554  /// given source manager entry ID.
1555  virtual std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID);
1556
1557  /// \brief Retrieve the global submodule ID given a module and its local ID
1558  /// number.
1559  serialization::SubmoduleID
1560  getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID);
1561
1562  /// \brief Retrieve the submodule that corresponds to a global submodule ID.
1563  ///
1564  Module *getSubmodule(serialization::SubmoduleID GlobalID);
1565
1566  /// \brief Retrieve the module that corresponds to the given module ID.
1567  ///
1568  /// Note: overrides method in ExternalASTSource
1569  virtual Module *getModule(unsigned ID);
1570
1571  /// \brief Retrieve a selector from the given module with its local ID
1572  /// number.
1573  Selector getLocalSelector(ModuleFile &M, unsigned LocalID);
1574
1575  Selector DecodeSelector(serialization::SelectorID Idx);
1576
1577  virtual Selector GetExternalSelector(serialization::SelectorID ID);
1578  uint32_t GetNumExternalSelectors();
1579
1580  Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) {
1581    return getLocalSelector(M, Record[Idx++]);
1582  }
1583
1584  /// \brief Retrieve the global selector ID that corresponds to this
1585  /// the local selector ID in a given module.
1586  serialization::SelectorID getGlobalSelectorID(ModuleFile &F,
1587                                                unsigned LocalID) const;
1588
1589  /// \brief Read a declaration name.
1590  DeclarationName ReadDeclarationName(ModuleFile &F,
1591                                      const RecordData &Record, unsigned &Idx);
1592  void ReadDeclarationNameLoc(ModuleFile &F,
1593                              DeclarationNameLoc &DNLoc, DeclarationName Name,
1594                              const RecordData &Record, unsigned &Idx);
1595  void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo,
1596                               const RecordData &Record, unsigned &Idx);
1597
1598  void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info,
1599                         const RecordData &Record, unsigned &Idx);
1600
1601  NestedNameSpecifier *ReadNestedNameSpecifier(ModuleFile &F,
1602                                               const RecordData &Record,
1603                                               unsigned &Idx);
1604
1605  NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F,
1606                                                    const RecordData &Record,
1607                                                    unsigned &Idx);
1608
1609  /// \brief Read a template name.
1610  TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record,
1611                                unsigned &Idx);
1612
1613  /// \brief Read a template argument.
1614  TemplateArgument ReadTemplateArgument(ModuleFile &F,
1615                                        const RecordData &Record,unsigned &Idx);
1616
1617  /// \brief Read a template parameter list.
1618  TemplateParameterList *ReadTemplateParameterList(ModuleFile &F,
1619                                                   const RecordData &Record,
1620                                                   unsigned &Idx);
1621
1622  /// \brief Read a template argument array.
1623  void
1624  ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs,
1625                           ModuleFile &F, const RecordData &Record,
1626                           unsigned &Idx);
1627
1628  /// \brief Read a UnresolvedSet structure.
1629  void ReadUnresolvedSet(ModuleFile &F, ASTUnresolvedSet &Set,
1630                         const RecordData &Record, unsigned &Idx);
1631
1632  /// \brief Read a C++ base specifier.
1633  CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F,
1634                                        const RecordData &Record,unsigned &Idx);
1635
1636  /// \brief Read a CXXCtorInitializer array.
1637  std::pair<CXXCtorInitializer **, unsigned>
1638  ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record,
1639                          unsigned &Idx);
1640
1641  /// \brief Read a source location from raw form.
1642  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, unsigned Raw) const {
1643    SourceLocation Loc = SourceLocation::getFromRawEncoding(Raw);
1644    assert(ModuleFile.SLocRemap.find(Loc.getOffset()) != ModuleFile.SLocRemap.end() &&
1645           "Cannot find offset to remap.");
1646    int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second;
1647    return Loc.getLocWithOffset(Remap);
1648  }
1649
1650  /// \brief Read a source location.
1651  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
1652                                    const RecordData &Record, unsigned& Idx) {
1653    return ReadSourceLocation(ModuleFile, Record[Idx++]);
1654  }
1655
1656  /// \brief Read a source range.
1657  SourceRange ReadSourceRange(ModuleFile &F,
1658                              const RecordData &Record, unsigned& Idx);
1659
1660  /// \brief Read an integral value
1661  llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx);
1662
1663  /// \brief Read a signed integral value
1664  llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx);
1665
1666  /// \brief Read a floating-point value
1667  llvm::APFloat ReadAPFloat(const RecordData &Record,
1668                            const llvm::fltSemantics &Sem, unsigned &Idx);
1669
1670  // \brief Read a string
1671  static std::string ReadString(const RecordData &Record, unsigned &Idx);
1672
1673  /// \brief Read a version tuple.
1674  static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx);
1675
1676  CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record,
1677                                 unsigned &Idx);
1678
1679  /// \brief Reads attributes from the current stream position.
1680  void ReadAttributes(ModuleFile &F, AttrVec &Attrs,
1681                      const RecordData &Record, unsigned &Idx);
1682
1683  /// \brief Reads a statement.
1684  Stmt *ReadStmt(ModuleFile &F);
1685
1686  /// \brief Reads an expression.
1687  Expr *ReadExpr(ModuleFile &F);
1688
1689  /// \brief Reads a sub-statement operand during statement reading.
1690  Stmt *ReadSubStmt() {
1691    assert(ReadingKind == Read_Stmt &&
1692           "Should be called only during statement reading!");
1693    // Subexpressions are stored from last to first, so the next Stmt we need
1694    // is at the back of the stack.
1695    assert(!StmtStack.empty() && "Read too many sub statements!");
1696    return StmtStack.pop_back_val();
1697  }
1698
1699  /// \brief Reads a sub-expression operand during statement reading.
1700  Expr *ReadSubExpr();
1701
1702  /// \brief Reads the macro record located at the given offset.
1703  void ReadMacroRecord(ModuleFile &F, uint64_t Offset, MacroInfo *Hint = 0);
1704
1705  /// \brief Determine the global preprocessed entity ID that corresponds to
1706  /// the given local ID within the given module.
1707  serialization::PreprocessedEntityID
1708  getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const;
1709
1710  /// \brief Note that the identifier has a macro history.
1711  ///
1712  /// \param II The name of the macro.
1713  ///
1714  /// \param IDs The global macro IDs that are associated with this identifier.
1715  void setIdentifierIsMacro(IdentifierInfo *II,
1716                            ArrayRef<serialization::MacroID> IDs);
1717
1718  /// \brief Read the set of macros defined by this external macro source.
1719  virtual void ReadDefinedMacros();
1720
1721  /// \brief Update an out-of-date identifier.
1722  virtual void updateOutOfDateIdentifier(IdentifierInfo &II);
1723
1724  /// \brief Note that this identifier is up-to-date.
1725  void markIdentifierUpToDate(IdentifierInfo *II);
1726
1727  /// \brief Load all external visible decls in the given DeclContext.
1728  void completeVisibleDeclsMap(const DeclContext *DC);
1729
1730  /// \brief Retrieve the AST context that this AST reader supplements.
1731  ASTContext &getContext() { return Context; }
1732
1733  // \brief Contains declarations that were loaded before we have
1734  // access to a Sema object.
1735  SmallVector<NamedDecl *, 16> PreloadedDecls;
1736
1737  /// \brief Retrieve the semantic analysis object used to analyze the
1738  /// translation unit in which the precompiled header is being
1739  /// imported.
1740  Sema *getSema() { return SemaObj; }
1741
1742  /// \brief Retrieve the identifier table associated with the
1743  /// preprocessor.
1744  IdentifierTable &getIdentifierTable();
1745
1746  /// \brief Record that the given ID maps to the given switch-case
1747  /// statement.
1748  void RecordSwitchCaseID(SwitchCase *SC, unsigned ID);
1749
1750  /// \brief Retrieve the switch-case statement with the given ID.
1751  SwitchCase *getSwitchCaseWithID(unsigned ID);
1752
1753  void ClearSwitchCaseIDs();
1754
1755  /// \brief Cursors for comments blocks.
1756  SmallVector<std::pair<llvm::BitstreamCursor,
1757                        serialization::ModuleFile *>, 8> CommentsCursors;
1758
1759  /// \brief Loads comments ranges.
1760  void ReadComments();
1761};
1762
1763/// \brief Helper class that saves the current stream position and
1764/// then restores it when destroyed.
1765struct SavedStreamPosition {
1766  explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor)
1767    : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) { }
1768
1769  ~SavedStreamPosition() {
1770    Cursor.JumpToBit(Offset);
1771  }
1772
1773private:
1774  llvm::BitstreamCursor &Cursor;
1775  uint64_t Offset;
1776};
1777
1778inline void PCHValidator::Error(const char *Msg) {
1779  Reader.Error(Msg);
1780}
1781
1782} // end namespace clang
1783
1784#endif
1785