ASTReader.h revision 276479
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 14212795Sdim#ifndef LLVM_CLANG_FRONTEND_AST_READER_H 15212795Sdim#define LLVM_CLANG_FRONTEND_AST_READER_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, 118243830Sdim bool Complain) { 119212795Sdim return false; 120212795Sdim } 121212795Sdim 122243830Sdim /// \brief Receives the target options. 123212795Sdim /// 124243830Sdim /// \returns true to indicate the target options are invalid, or false 125243830Sdim /// otherwise. 126243830Sdim virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, 127243830Sdim bool Complain) { 128212795Sdim return false; 129212795Sdim } 130212795Sdim 131243830Sdim /// \brief Receives the diagnostic options. 132212795Sdim /// 133243830Sdim /// \returns true to indicate the diagnostic options are invalid, or false 134243830Sdim /// otherwise. 135276479Sdim virtual bool 136276479Sdim ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, 137276479Sdim bool Complain) { 138243830Sdim return false; 139243830Sdim } 140243830Sdim 141243830Sdim /// \brief Receives the file system options. 142212795Sdim /// 143243830Sdim /// \returns true to indicate the file system options are invalid, or false 144243830Sdim /// otherwise. 145243830Sdim virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts, 146243830Sdim bool Complain) { 147243830Sdim return false; 148243830Sdim } 149243830Sdim 150243830Sdim /// \brief Receives the header search options. 151212795Sdim /// 152243830Sdim /// \returns true to indicate the header search options are invalid, or false 153243830Sdim /// otherwise. 154243830Sdim virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, 155243830Sdim bool Complain) { 156243830Sdim return false; 157243830Sdim } 158243830Sdim 159243830Sdim /// \brief Receives the preprocessor options. 160212795Sdim /// 161243830Sdim /// \param SuggestedPredefines Can be filled in with the set of predefines 162243830Sdim /// that are suggested by the preprocessor options. Typically only used when 163243830Sdim /// loading a precompiled header. 164243830Sdim /// 165243830Sdim /// \returns true to indicate the preprocessor options are invalid, or false 166243830Sdim /// otherwise. 167243830Sdim virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, 168243830Sdim bool Complain, 169243830Sdim std::string &SuggestedPredefines) { 170212795Sdim return false; 171212795Sdim } 172212795Sdim 173212795Sdim /// \brief Receives __COUNTER__ value. 174243830Sdim virtual void ReadCounter(const serialization::ModuleFile &M, 175243830Sdim unsigned Value) {} 176251662Sdim 177276479Sdim /// This is called for each AST file loaded. 178276479Sdim virtual void visitModuleFile(StringRef Filename) {} 179276479Sdim 180251662Sdim /// \brief Returns true if this \c ASTReaderListener wants to receive the 181251662Sdim /// input files of the AST file via \c visitInputFile, false otherwise. 182251662Sdim virtual bool needsInputFileVisitation() { return false; } 183276479Sdim /// \brief Returns true if this \c ASTReaderListener wants to receive the 184276479Sdim /// system input files of the AST file via \c visitInputFile, false otherwise. 185276479Sdim virtual bool needsSystemInputFileVisitation() { return false; } 186276479Sdim /// \brief if \c needsInputFileVisitation returns true, this is called for 187276479Sdim /// each non-system input file of the AST File. If 188276479Sdim /// \c needsSystemInputFileVisitation is true, then it is called for all 189276479Sdim /// system input files as well. 190251662Sdim /// 191251662Sdim /// \returns true to continue receiving the next input file, false to stop. 192276479Sdim virtual bool visitInputFile(StringRef Filename, bool isSystem, 193276479Sdim bool isOverridden) { 194276479Sdim return true; 195276479Sdim } 196212795Sdim}; 197212795Sdim 198276479Sdim/// \brief Simple wrapper class for chaining listeners. 199276479Sdimclass ChainedASTReaderListener : public ASTReaderListener { 200276479Sdim std::unique_ptr<ASTReaderListener> First; 201276479Sdim std::unique_ptr<ASTReaderListener> Second; 202276479Sdim 203276479Sdimpublic: 204276479Sdim /// Takes ownership of \p First and \p Second. 205276479Sdim ChainedASTReaderListener(ASTReaderListener *First, ASTReaderListener *Second) 206276479Sdim : First(First), Second(Second) { } 207276479Sdim 208276479Sdim bool ReadFullVersionInformation(StringRef FullVersion) override; 209276479Sdim void ReadModuleName(StringRef ModuleName) override; 210276479Sdim void ReadModuleMapFile(StringRef ModuleMapPath) override; 211276479Sdim bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain) override; 212276479Sdim bool ReadTargetOptions(const TargetOptions &TargetOpts, 213276479Sdim bool Complain) override; 214276479Sdim bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, 215276479Sdim bool Complain) override; 216276479Sdim bool ReadFileSystemOptions(const FileSystemOptions &FSOpts, 217276479Sdim bool Complain) override; 218276479Sdim 219276479Sdim bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, 220276479Sdim bool Complain) override; 221276479Sdim bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, 222276479Sdim bool Complain, 223276479Sdim std::string &SuggestedPredefines) override; 224276479Sdim 225276479Sdim void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override; 226276479Sdim bool needsInputFileVisitation() override; 227276479Sdim bool needsSystemInputFileVisitation() override; 228276479Sdim void visitModuleFile(StringRef Filename) override; 229276479Sdim bool visitInputFile(StringRef Filename, bool isSystem, 230276479Sdim bool isOverridden) override; 231276479Sdim}; 232276479Sdim 233212795Sdim/// \brief ASTReaderListener implementation to validate the information of 234212795Sdim/// the PCH file against an initialized Preprocessor. 235212795Sdimclass PCHValidator : public ASTReaderListener { 236212795Sdim Preprocessor &PP; 237212795Sdim ASTReader &Reader; 238212795Sdim 239212795Sdimpublic: 240212795Sdim PCHValidator(Preprocessor &PP, ASTReader &Reader) 241261991Sdim : PP(PP), Reader(Reader) {} 242212795Sdim 243276479Sdim bool ReadLanguageOptions(const LangOptions &LangOpts, 244276479Sdim bool Complain) override; 245276479Sdim bool ReadTargetOptions(const TargetOptions &TargetOpts, 246276479Sdim bool Complain) override; 247276479Sdim bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, 248276479Sdim bool Complain) override; 249276479Sdim bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain, 250276479Sdim std::string &SuggestedPredefines) override; 251276479Sdim void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override; 252212795Sdim 253212795Sdimprivate: 254212795Sdim void Error(const char *Msg); 255212795Sdim}; 256212795Sdim 257234353Sdimnamespace serialization { 258226633Sdim 259226633Sdimclass ReadMethodPoolVisitor; 260234353Sdim 261226633Sdimnamespace reader { 262226633Sdim class ASTIdentifierLookupTrait; 263234982Sdim /// \brief The on-disk hash table used for the DeclContext's Name lookup table. 264276479Sdim typedef llvm::OnDiskIterableChainedHashTable<ASTDeclContextNameLookupTrait> 265234982Sdim ASTDeclContextNameLookupTable; 266226633Sdim} 267234353Sdim 268226633Sdim} // end namespace serialization 269234353Sdim 270212795Sdim/// \brief Reads an AST files chain containing the contents of a translation 271212795Sdim/// unit. 272212795Sdim/// 273212795Sdim/// The ASTReader class reads bitstreams (produced by the ASTWriter 274212795Sdim/// class) containing the serialized representation of a given 275212795Sdim/// abstract syntax tree and its supporting data structures. An 276212795Sdim/// instance of the ASTReader can be attached to an ASTContext object, 277212795Sdim/// which will provide access to the contents of the AST files. 278212795Sdim/// 279212795Sdim/// The AST reader provides lazy de-serialization of declarations, as 280212795Sdim/// required when traversing the AST. Only those AST nodes that are 281212795Sdim/// actually required will be de-serialized. 282212795Sdimclass ASTReader 283212795Sdim : public ExternalPreprocessorSource, 284212795Sdim public ExternalPreprocessingRecordSource, 285218893Sdim public ExternalHeaderFileInfoSource, 286212795Sdim public ExternalSemaSource, 287212795Sdim public IdentifierInfoLookup, 288212795Sdim public ExternalIdentifierLookup, 289234353Sdim public ExternalSLocEntrySource 290218893Sdim{ 291212795Sdimpublic: 292239462Sdim typedef SmallVector<uint64_t, 64> RecordData; 293261991Sdim typedef SmallVectorImpl<uint64_t> RecordDataImpl; 294239462Sdim 295243830Sdim /// \brief The result of reading the control block of an AST file, which 296243830Sdim /// can fail for various reasons. 297243830Sdim enum ASTReadResult { 298243830Sdim /// \brief The control block was read successfully. Aside from failures, 299243830Sdim /// the AST file is safe to read into the current context. 300243830Sdim Success, 301243830Sdim /// \brief The AST file itself appears corrupted. 302243830Sdim Failure, 303249423Sdim /// \brief The AST file was missing. 304249423Sdim Missing, 305243830Sdim /// \brief The AST file is out-of-date relative to its input files, 306243830Sdim /// and needs to be regenerated. 307243830Sdim OutOfDate, 308243830Sdim /// \brief The AST file was written by a different version of Clang. 309243830Sdim VersionMismatch, 310243830Sdim /// \brief The AST file was writtten with a different language/target 311243830Sdim /// configuration. 312243830Sdim ConfigurationMismatch, 313243830Sdim /// \brief The AST file has errors. 314243830Sdim HadErrors 315243830Sdim }; 316243830Sdim 317218893Sdim /// \brief Types of AST files. 318212795Sdim friend class PCHValidator; 319212795Sdim friend class ASTDeclReader; 320218893Sdim friend class ASTStmtReader; 321218893Sdim friend class ASTIdentifierIterator; 322226633Sdim friend class serialization::reader::ASTIdentifierLookupTrait; 323218893Sdim friend class TypeLocReader; 324226633Sdim friend class ASTWriter; 325226633Sdim friend class ASTUnit; // ASTUnit needs to remap source locations. 326226633Sdim friend class serialization::ReadMethodPoolVisitor; 327234353Sdim 328234353Sdim typedef serialization::ModuleFile ModuleFile; 329226633Sdim typedef serialization::ModuleKind ModuleKind; 330226633Sdim typedef serialization::ModuleManager ModuleManager; 331234353Sdim 332226633Sdim typedef ModuleManager::ModuleIterator ModuleIterator; 333226633Sdim typedef ModuleManager::ModuleConstIterator ModuleConstIterator; 334226633Sdim typedef ModuleManager::ModuleReverseIterator ModuleReverseIterator; 335226633Sdim 336212795Sdimprivate: 337212795Sdim /// \brief The receiver of some callbacks invoked by ASTReader. 338276479Sdim std::unique_ptr<ASTReaderListener> Listener; 339212795Sdim 340212795Sdim /// \brief The receiver of deserialization events. 341212795Sdim ASTDeserializationListener *DeserializationListener; 342276479Sdim bool OwnsDeserializationListener; 343212795Sdim 344212795Sdim SourceManager &SourceMgr; 345212795Sdim FileManager &FileMgr; 346226633Sdim DiagnosticsEngine &Diags; 347234353Sdim 348212795Sdim /// \brief The semantic analysis object that will be processing the 349212795Sdim /// AST files and the translation unit that uses it. 350212795Sdim Sema *SemaObj; 351212795Sdim 352212795Sdim /// \brief The preprocessor that will be loading the source file. 353226633Sdim Preprocessor &PP; 354212795Sdim 355212795Sdim /// \brief The AST context into which we'll read the AST files. 356226633Sdim ASTContext &Context; 357234353Sdim 358212795Sdim /// \brief The AST consumer. 359212795Sdim ASTConsumer *Consumer; 360212795Sdim 361226633Sdim /// \brief The module manager which manages modules and their dependencies 362226633Sdim ModuleManager ModuleMgr; 363221345Sdim 364261991Sdim /// \brief The location where the module file will be considered as 365261991Sdim /// imported from. For non-module AST types it should be invalid. 366261991Sdim SourceLocation CurrentImportLoc; 367261991Sdim 368249423Sdim /// \brief The global module index, if loaded. 369276479Sdim std::unique_ptr<GlobalModuleIndex> GlobalIndex; 370249423Sdim 371226633Sdim /// \brief A map of global bit offsets to the module that stores entities 372226633Sdim /// at those bit offsets. 373234353Sdim ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap; 374212795Sdim 375226633Sdim /// \brief A map of negated SLocEntryIDs to the modules containing them. 376234353Sdim ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap; 377212795Sdim 378234353Sdim typedef ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocOffsetMapType; 379234353Sdim 380226633Sdim /// \brief A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset) 381226633Sdim /// SourceLocation offsets to the modules containing them. 382226633Sdim GlobalSLocOffsetMapType GlobalSLocOffsetMap; 383234353Sdim 384212795Sdim /// \brief Types that have already been loaded from the chain. 385212795Sdim /// 386212795Sdim /// When the pointer at index I is non-NULL, the type with 387212795Sdim /// ID = (I + 1) << FastQual::Width has already been loaded 388212795Sdim std::vector<QualType> TypesLoaded; 389212795Sdim 390234353Sdim typedef ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4> 391226633Sdim GlobalTypeMapType; 392212795Sdim 393226633Sdim /// \brief Mapping from global type IDs to the module in which the 394226633Sdim /// type resides along with the offset that should be added to the 395226633Sdim /// global type ID to produce a local ID. 396226633Sdim GlobalTypeMapType GlobalTypeMap; 397226633Sdim 398212795Sdim /// \brief Declarations that have already been loaded from the chain. 399212795Sdim /// 400212795Sdim /// When the pointer at index I is non-NULL, the declaration with ID 401212795Sdim /// = I + 1 has already been loaded. 402212795Sdim std::vector<Decl *> DeclsLoaded; 403212795Sdim 404234353Sdim typedef ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4> 405226633Sdim GlobalDeclMapType; 406234353Sdim 407226633Sdim /// \brief Mapping from global declaration IDs to the module in which the 408226633Sdim /// declaration resides. 409226633Sdim GlobalDeclMapType GlobalDeclMap; 410234353Sdim 411234353Sdim typedef std::pair<ModuleFile *, uint64_t> FileOffset; 412226633Sdim typedef SmallVector<FileOffset, 2> FileOffsetsTy; 413218893Sdim typedef llvm::DenseMap<serialization::DeclID, FileOffsetsTy> 414218893Sdim DeclUpdateOffsetsMap; 415234353Sdim 416218893Sdim /// \brief Declarations that have modifications residing in a later file 417218893Sdim /// in the chain. 418218893Sdim DeclUpdateOffsetsMap DeclUpdateOffsets; 419218893Sdim 420276479Sdim /// \brief Declaration updates for already-loaded declarations that we need 421276479Sdim /// to apply once we finish processing an import. 422276479Sdim llvm::SmallVector<std::pair<serialization::GlobalDeclID, Decl*>, 16> 423276479Sdim PendingUpdateRecords; 424276479Sdim 425234353Sdim struct ReplacedDeclInfo { 426234353Sdim ModuleFile *Mod; 427234353Sdim uint64_t Offset; 428234353Sdim unsigned RawLoc; 429234353Sdim 430276479Sdim ReplacedDeclInfo() : Mod(nullptr), Offset(0), RawLoc(0) {} 431234353Sdim ReplacedDeclInfo(ModuleFile *Mod, uint64_t Offset, unsigned RawLoc) 432234353Sdim : Mod(Mod), Offset(Offset), RawLoc(RawLoc) {} 433234353Sdim }; 434234353Sdim 435234353Sdim typedef llvm::DenseMap<serialization::DeclID, ReplacedDeclInfo> 436212795Sdim DeclReplacementMap; 437212795Sdim /// \brief Declarations that have been replaced in a later file in the chain. 438212795Sdim DeclReplacementMap ReplacedDecls; 439212795Sdim 440234353Sdim struct FileDeclsInfo { 441234353Sdim ModuleFile *Mod; 442234353Sdim ArrayRef<serialization::LocalDeclID> Decls; 443234353Sdim 444276479Sdim FileDeclsInfo() : Mod(nullptr) {} 445234353Sdim FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls) 446234353Sdim : Mod(Mod), Decls(Decls) {} 447234353Sdim }; 448234353Sdim 449234353Sdim /// \brief Map from a FileID to the file-level declarations that it contains. 450234353Sdim llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs; 451234353Sdim 452212795Sdim // Updates for visible decls can occur for other contexts than just the 453212795Sdim // TU, and when we read those update records, the actual context will not 454212795Sdim // be available yet (unless it's the TU), so have this pending map using the 455212795Sdim // ID as a key. It will be realized when the context is actually loaded. 456234982Sdim typedef 457234982Sdim SmallVector<std::pair<serialization::reader::ASTDeclContextNameLookupTable *, 458234982Sdim ModuleFile*>, 1> DeclContextVisibleUpdates; 459212795Sdim typedef llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates> 460212795Sdim DeclContextVisibleUpdatesPending; 461212795Sdim 462212795Sdim /// \brief Updates to the visible declarations of declaration contexts that 463212795Sdim /// haven't been loaded yet. 464212795Sdim DeclContextVisibleUpdatesPending PendingVisibleUpdates; 465234353Sdim 466234353Sdim /// \brief The set of C++ or Objective-C classes that have forward 467234353Sdim /// declarations that have not yet been linked to their definitions. 468234353Sdim llvm::SmallPtrSet<Decl *, 4> PendingDefinitions; 469243830Sdim 470243830Sdim typedef llvm::MapVector<Decl *, uint64_t, 471243830Sdim llvm::SmallDenseMap<Decl *, unsigned, 4>, 472249423Sdim SmallVector<std::pair<Decl *, uint64_t>, 4> > 473243830Sdim PendingBodiesMap; 474243830Sdim 475243830Sdim /// \brief Functions or methods that have bodies that will be attached. 476243830Sdim PendingBodiesMap PendingBodies; 477243830Sdim 478212795Sdim /// \brief Read the records that describe the contents of declcontexts. 479234353Sdim bool ReadDeclContextStorage(ModuleFile &M, 480226633Sdim llvm::BitstreamCursor &Cursor, 481212795Sdim const std::pair<uint64_t, uint64_t> &Offsets, 482226633Sdim serialization::DeclContextInfo &Info); 483212795Sdim 484212795Sdim /// \brief A vector containing identifiers that have already been 485212795Sdim /// loaded. 486212795Sdim /// 487212795Sdim /// If the pointer at index I is non-NULL, then it refers to the 488212795Sdim /// IdentifierInfo for the identifier with ID=I+1 that has already 489212795Sdim /// been loaded. 490212795Sdim std::vector<IdentifierInfo *> IdentifiersLoaded; 491212795Sdim 492234353Sdim typedef ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4> 493226633Sdim GlobalIdentifierMapType; 494234353Sdim 495243830Sdim /// \brief Mapping from global identifier IDs to the module in which the 496226633Sdim /// identifier resides along with the offset that should be added to the 497226633Sdim /// global identifier ID to produce a local ID. 498226633Sdim GlobalIdentifierMapType GlobalIdentifierMap; 499226633Sdim 500243830Sdim /// \brief A vector containing macros that have already been 501243830Sdim /// loaded. 502243830Sdim /// 503243830Sdim /// If the pointer at index I is non-NULL, then it refers to the 504243830Sdim /// MacroInfo for the identifier with ID=I+1 that has already 505243830Sdim /// been loaded. 506243830Sdim std::vector<MacroInfo *> MacrosLoaded; 507243830Sdim 508243830Sdim typedef ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4> 509243830Sdim GlobalMacroMapType; 510243830Sdim 511243830Sdim /// \brief Mapping from global macro IDs to the module in which the 512243830Sdim /// macro resides along with the offset that should be added to the 513243830Sdim /// global macro ID to produce a local ID. 514243830Sdim GlobalMacroMapType GlobalMacroMap; 515243830Sdim 516234353Sdim /// \brief A vector containing submodules that have already been loaded. 517234353Sdim /// 518234353Sdim /// This vector is indexed by the Submodule ID (-1). NULL submodule entries 519234353Sdim /// indicate that the particular submodule ID has not yet been loaded. 520234353Sdim SmallVector<Module *, 2> SubmodulesLoaded; 521234353Sdim 522234353Sdim typedef ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4> 523234353Sdim GlobalSubmoduleMapType; 524234353Sdim 525234353Sdim /// \brief Mapping from global submodule IDs to the module file in which the 526234353Sdim /// submodule resides along with the offset that should be added to the 527234353Sdim /// global submodule ID to produce a local ID. 528234353Sdim GlobalSubmoduleMapType GlobalSubmoduleMap; 529234353Sdim 530276479Sdim /// \brief Information on a macro definition or undefinition that is visible 531276479Sdim /// at the end of a submodule. 532276479Sdim struct ModuleMacroInfo; 533276479Sdim 534243830Sdim /// \brief An entity that has been hidden. 535243830Sdim class HiddenName { 536243830Sdim public: 537243830Sdim enum NameKind { 538243830Sdim Declaration, 539276479Sdim Macro 540243830Sdim } Kind; 541243830Sdim 542243830Sdim private: 543243830Sdim union { 544243830Sdim Decl *D; 545276479Sdim ModuleMacroInfo *MMI; 546243830Sdim }; 547243830Sdim 548243830Sdim IdentifierInfo *Id; 549243830Sdim 550243830Sdim public: 551249423Sdim HiddenName(Decl *D) : Kind(Declaration), D(D), Id() { } 552243830Sdim 553276479Sdim HiddenName(IdentifierInfo *II, ModuleMacroInfo *MMI) 554276479Sdim : Kind(Macro), MMI(MMI), Id(II) { } 555243830Sdim 556243830Sdim NameKind getKind() const { return Kind; } 557243830Sdim 558243830Sdim Decl *getDecl() const { 559243830Sdim assert(getKind() == Declaration && "Hidden name is not a declaration"); 560243830Sdim return D; 561243830Sdim } 562243830Sdim 563276479Sdim std::pair<IdentifierInfo *, ModuleMacroInfo *> getMacro() const { 564276479Sdim assert(getKind() == Macro && "Hidden name is not a macro!"); 565276479Sdim return std::make_pair(Id, MMI); 566243830Sdim } 567276479Sdim }; 568243830Sdim 569276479Sdim typedef llvm::SmallDenseMap<IdentifierInfo*, 570276479Sdim ModuleMacroInfo*> HiddenMacrosMap; 571276479Sdim 572234353Sdim /// \brief A set of hidden declarations. 573276479Sdim struct HiddenNames { 574276479Sdim SmallVector<Decl*, 2> HiddenDecls; 575276479Sdim HiddenMacrosMap HiddenMacros; 576276479Sdim }; 577276479Sdim 578234353Sdim typedef llvm::DenseMap<Module *, HiddenNames> HiddenNamesMapType; 579234353Sdim 580234353Sdim /// \brief A mapping from each of the hidden submodules to the deserialized 581234353Sdim /// declarations in that submodule that could be made visible. 582234353Sdim HiddenNamesMapType HiddenNamesMap; 583234353Sdim 584234353Sdim 585249423Sdim /// \brief A module import, export, or conflict that hasn't yet been resolved. 586249423Sdim struct UnresolvedModuleRef { 587234353Sdim /// \brief The file in which this module resides. 588234353Sdim ModuleFile *File; 589234353Sdim 590234353Sdim /// \brief The module that is importing or exporting. 591234353Sdim Module *Mod; 592249423Sdim 593249423Sdim /// \brief The kind of module reference. 594249423Sdim enum { Import, Export, Conflict } Kind; 595249423Sdim 596234353Sdim /// \brief The local ID of the module that is being exported. 597234353Sdim unsigned ID; 598249423Sdim 599234353Sdim /// \brief Whether this is a wildcard export. 600234353Sdim unsigned IsWildcard : 1; 601249423Sdim 602249423Sdim /// \brief String data. 603249423Sdim StringRef String; 604234353Sdim }; 605234353Sdim 606234353Sdim /// \brief The set of module imports and exports that still need to be 607234353Sdim /// resolved. 608249423Sdim SmallVector<UnresolvedModuleRef, 2> UnresolvedModuleRefs; 609234353Sdim 610212795Sdim /// \brief A vector containing selectors that have already been loaded. 611212795Sdim /// 612212795Sdim /// This vector is indexed by the Selector ID (-1). NULL selector 613212795Sdim /// entries indicate that the particular selector ID has not yet 614212795Sdim /// been loaded. 615226633Sdim SmallVector<Selector, 16> SelectorsLoaded; 616212795Sdim 617234353Sdim typedef ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4> 618226633Sdim GlobalSelectorMapType; 619234353Sdim 620226633Sdim /// \brief Mapping from global selector IDs to the module in which the 621249423Sdim 622226633Sdim /// global selector ID to produce a local ID. 623226633Sdim GlobalSelectorMapType GlobalSelectorMap; 624212795Sdim 625234353Sdim /// \brief The generation number of the last time we loaded data from the 626234353Sdim /// global method pool for this selector. 627234353Sdim llvm::DenseMap<Selector, unsigned> SelectorGeneration; 628234353Sdim 629249423Sdim struct PendingMacroInfo { 630249423Sdim ModuleFile *M; 631249423Sdim 632249423Sdim struct ModuleMacroDataTy { 633276479Sdim uint32_t MacID; 634276479Sdim serialization::SubmoduleID *Overrides; 635249423Sdim }; 636249423Sdim struct PCHMacroDataTy { 637249423Sdim uint64_t MacroDirectivesOffset; 638249423Sdim }; 639249423Sdim 640249423Sdim union { 641249423Sdim ModuleMacroDataTy ModuleMacroData; 642249423Sdim PCHMacroDataTy PCHMacroData; 643249423Sdim }; 644249423Sdim 645249423Sdim PendingMacroInfo(ModuleFile *M, 646276479Sdim uint32_t MacID, 647276479Sdim serialization::SubmoduleID *Overrides) : M(M) { 648276479Sdim ModuleMacroData.MacID = MacID; 649276479Sdim ModuleMacroData.Overrides = Overrides; 650249423Sdim } 651249423Sdim 652249423Sdim PendingMacroInfo(ModuleFile *M, uint64_t MacroDirectivesOffset) : M(M) { 653249423Sdim PCHMacroData.MacroDirectivesOffset = MacroDirectivesOffset; 654249423Sdim } 655249423Sdim }; 656249423Sdim 657249423Sdim typedef llvm::MapVector<IdentifierInfo *, SmallVector<PendingMacroInfo, 2> > 658243830Sdim PendingMacroIDsMap; 659226633Sdim 660243830Sdim /// \brief Mapping from identifiers that have a macro history to the global 661243830Sdim /// IDs have not yet been deserialized to the global IDs of those macros. 662243830Sdim PendingMacroIDsMap PendingMacroIDs; 663243830Sdim 664234353Sdim typedef ContinuousRangeMap<unsigned, ModuleFile *, 4> 665226633Sdim GlobalPreprocessedEntityMapType; 666234353Sdim 667226633Sdim /// \brief Mapping from global preprocessing entity IDs to the module in 668226633Sdim /// which the preprocessed entity resides along with the offset that should be 669226633Sdim /// added to the global preprocessing entitiy ID to produce a local ID. 670226633Sdim GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap; 671234353Sdim 672212795Sdim /// \name CodeGen-relevant special data 673212795Sdim /// \brief Fields containing data that is relevant to CodeGen. 674212795Sdim //@{ 675212795Sdim 676212795Sdim /// \brief The IDs of all declarations that fulfill the criteria of 677212795Sdim /// "interesting" decls. 678212795Sdim /// 679276479Sdim /// This contains the data loaded from all EAGERLY_DESERIALIZED_DECLS blocks 680276479Sdim /// in the chain. The referenced declarations are deserialized and passed to 681276479Sdim /// the consumer eagerly. 682276479Sdim SmallVector<uint64_t, 16> EagerlyDeserializedDecls; 683212795Sdim 684239462Sdim /// \brief The IDs of all tentative definitions stored in the chain. 685212795Sdim /// 686212795Sdim /// Sema keeps track of all tentative definitions in a TU because it has to 687212795Sdim /// complete them and pass them on to CodeGen. Thus, tentative definitions in 688212795Sdim /// the PCH chain must be eagerly deserialized. 689226633Sdim SmallVector<uint64_t, 16> TentativeDefinitions; 690212795Sdim 691212795Sdim /// \brief The IDs of all CXXRecordDecls stored in the chain whose VTables are 692212795Sdim /// used. 693212795Sdim /// 694212795Sdim /// CodeGen has to emit VTables for these records, so they have to be eagerly 695212795Sdim /// deserialized. 696226633Sdim SmallVector<uint64_t, 64> VTableUses; 697212795Sdim 698226633Sdim /// \brief A snapshot of the pending instantiations in the chain. 699226633Sdim /// 700226633Sdim /// This record tracks the instantiations that Sema has to perform at the 701226633Sdim /// end of the TU. It consists of a pair of values for every pending 702226633Sdim /// instantiation where the first value is the ID of the decl and the second 703226633Sdim /// is the instantiation location. 704226633Sdim SmallVector<uint64_t, 64> PendingInstantiations; 705226633Sdim 706212795Sdim //@} 707212795Sdim 708226633Sdim /// \name DiagnosticsEngine-relevant special data 709212795Sdim /// \brief Fields containing data that is used for generating diagnostics 710212795Sdim //@{ 711212795Sdim 712212795Sdim /// \brief A snapshot of Sema's unused file-scoped variable tracking, for 713212795Sdim /// generating warnings. 714226633Sdim SmallVector<uint64_t, 16> UnusedFileScopedDecls; 715212795Sdim 716223017Sdim /// \brief A list of all the delegating constructors we've seen, to diagnose 717223017Sdim /// cycles. 718226633Sdim SmallVector<uint64_t, 4> DelegatingCtorDecls; 719234353Sdim 720226633Sdim /// \brief Method selectors used in a @selector expression. Used for 721226633Sdim /// implementation of -Wselector. 722226633Sdim SmallVector<uint64_t, 64> ReferencedSelectorsData; 723223017Sdim 724212795Sdim /// \brief A snapshot of Sema's weak undeclared identifier tracking, for 725212795Sdim /// generating warnings. 726226633Sdim SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers; 727212795Sdim 728212795Sdim /// \brief The IDs of type aliases for ext_vectors that exist in the chain. 729212795Sdim /// 730212795Sdim /// Used by Sema for finding sugared names for ext_vectors in diagnostics. 731226633Sdim SmallVector<uint64_t, 4> ExtVectorDecls; 732212795Sdim 733212795Sdim //@} 734212795Sdim 735212795Sdim /// \name Sema-relevant special data 736212795Sdim /// \brief Fields containing data that is used for semantic analysis 737212795Sdim //@{ 738212795Sdim 739249423Sdim /// \brief The IDs of all locally scoped extern "C" decls in the chain. 740212795Sdim /// 741212795Sdim /// Sema tracks these to validate that the types are consistent across all 742249423Sdim /// local extern "C" declarations. 743249423Sdim SmallVector<uint64_t, 16> LocallyScopedExternCDecls; 744212795Sdim 745212795Sdim /// \brief The IDs of all dynamic class declarations in the chain. 746212795Sdim /// 747212795Sdim /// Sema tracks these because it checks for the key functions being defined 748212795Sdim /// at the end of the TU, in which case it directs CodeGen to emit the VTable. 749226633Sdim SmallVector<uint64_t, 16> DynamicClasses; 750212795Sdim 751212795Sdim /// \brief The IDs of the declarations Sema stores directly. 752212795Sdim /// 753212795Sdim /// Sema tracks a few important decls, such as namespace std, directly. 754226633Sdim SmallVector<uint64_t, 4> SemaDeclRefs; 755212795Sdim 756212795Sdim /// \brief The IDs of the types ASTContext stores directly. 757212795Sdim /// 758212795Sdim /// The AST context tracks a few important types, such as va_list, directly. 759226633Sdim SmallVector<uint64_t, 16> SpecialTypes; 760212795Sdim 761218893Sdim /// \brief The IDs of CUDA-specific declarations ASTContext stores directly. 762218893Sdim /// 763218893Sdim /// The AST context tracks a few important decls, currently cudaConfigureCall, 764218893Sdim /// directly. 765226633Sdim SmallVector<uint64_t, 2> CUDASpecialDeclRefs; 766218893Sdim 767218893Sdim /// \brief The floating point pragma option settings. 768226633Sdim SmallVector<uint64_t, 1> FPPragmaOptions; 769218893Sdim 770276479Sdim /// \brief The pragma clang optimize location (if the pragma state is "off"). 771276479Sdim SourceLocation OptimizeOffPragmaLocation; 772276479Sdim 773218893Sdim /// \brief The OpenCL extension settings. 774226633Sdim SmallVector<uint64_t, 1> OpenCLExtensions; 775218893Sdim 776224145Sdim /// \brief A list of the namespaces we've seen. 777226633Sdim SmallVector<uint64_t, 4> KnownNamespaces; 778224145Sdim 779249423Sdim /// \brief A list of undefined decls with internal linkage followed by the 780249423Sdim /// SourceLocation of a matching ODR-use. 781249423Sdim SmallVector<uint64_t, 8> UndefinedButUsed; 782249423Sdim 783261991Sdim // \brief A list of late parsed template function data. 784261991Sdim SmallVector<uint64_t, 1> LateParsedTemplates; 785261991Sdim 786276479Sdim struct ImportedSubmodule { 787276479Sdim serialization::SubmoduleID ID; 788276479Sdim SourceLocation ImportLoc; 789276479Sdim 790276479Sdim ImportedSubmodule(serialization::SubmoduleID ID, SourceLocation ImportLoc) 791276479Sdim : ID(ID), ImportLoc(ImportLoc) {} 792276479Sdim }; 793276479Sdim 794234353Sdim /// \brief A list of modules that were imported by precompiled headers or 795234353Sdim /// any other non-module AST file. 796276479Sdim SmallVector<ImportedSubmodule, 2> ImportedModules; 797212795Sdim //@} 798212795Sdim 799218893Sdim /// \brief The directory that the PCH we are reading is stored in. 800218893Sdim std::string CurrentDir; 801218893Sdim 802212795Sdim /// \brief The system include root to be used when loading the 803212795Sdim /// precompiled header. 804226633Sdim std::string isysroot; 805212795Sdim 806212795Sdim /// \brief Whether to disable the normal validation performed on precompiled 807212795Sdim /// headers when they are loaded. 808212795Sdim bool DisableValidation; 809234353Sdim 810234353Sdim /// \brief Whether to accept an AST file with compiler errors. 811234353Sdim bool AllowASTWithCompilerErrors; 812234353Sdim 813276479Sdim /// \brief Whether to accept an AST file that has a different configuration 814276479Sdim /// from the current compiler instance. 815276479Sdim bool AllowConfigurationMismatch; 816276479Sdim 817276479Sdim /// \brief Whether validate system input files. 818276479Sdim bool ValidateSystemInputs; 819276479Sdim 820249423Sdim /// \brief Whether we are allowed to use the global module index. 821249423Sdim bool UseGlobalIndex; 822249423Sdim 823249423Sdim /// \brief Whether we have tried loading the global module index yet. 824249423Sdim bool TriedLoadingGlobalIndex; 825249423Sdim 826239462Sdim typedef llvm::DenseMap<unsigned, SwitchCase *> SwitchCaseMapTy; 827212795Sdim /// \brief Mapping from switch-case IDs in the chain to switch-case statements 828212795Sdim /// 829212795Sdim /// Statements usually don't have IDs, but switch cases need them, so that the 830212795Sdim /// switch statement can refer to them. 831239462Sdim SwitchCaseMapTy SwitchCaseStmts; 832212795Sdim 833239462Sdim SwitchCaseMapTy *CurrSwitchCaseStmts; 834239462Sdim 835212795Sdim /// \brief The number of source location entries de-serialized from 836212795Sdim /// the PCH file. 837212795Sdim unsigned NumSLocEntriesRead; 838212795Sdim 839212795Sdim /// \brief The number of source location entries in the chain. 840212795Sdim unsigned TotalNumSLocEntries; 841212795Sdim 842212795Sdim /// \brief The number of statements (and expressions) de-serialized 843212795Sdim /// from the chain. 844212795Sdim unsigned NumStatementsRead; 845212795Sdim 846212795Sdim /// \brief The total number of statements (and expressions) stored 847212795Sdim /// in the chain. 848212795Sdim unsigned TotalNumStatements; 849212795Sdim 850212795Sdim /// \brief The number of macros de-serialized from the chain. 851212795Sdim unsigned NumMacrosRead; 852212795Sdim 853212795Sdim /// \brief The total number of macros stored in the chain. 854212795Sdim unsigned TotalNumMacros; 855212795Sdim 856249423Sdim /// \brief The number of lookups into identifier tables. 857249423Sdim unsigned NumIdentifierLookups; 858249423Sdim 859249423Sdim /// \brief The number of lookups into identifier tables that succeed. 860249423Sdim unsigned NumIdentifierLookupHits; 861249423Sdim 862212795Sdim /// \brief The number of selectors that have been read. 863212795Sdim unsigned NumSelectorsRead; 864212795Sdim 865212795Sdim /// \brief The number of method pool entries that have been read. 866212795Sdim unsigned NumMethodPoolEntriesRead; 867212795Sdim 868212795Sdim /// \brief The number of times we have looked up a selector in the method 869249423Sdim /// pool. 870249423Sdim unsigned NumMethodPoolLookups; 871212795Sdim 872249423Sdim /// \brief The number of times we have looked up a selector in the method 873249423Sdim /// pool and found something. 874249423Sdim unsigned NumMethodPoolHits; 875249423Sdim 876249423Sdim /// \brief The number of times we have looked up a selector in the method 877249423Sdim /// pool within a specific module. 878249423Sdim unsigned NumMethodPoolTableLookups; 879249423Sdim 880249423Sdim /// \brief The number of times we have looked up a selector in the method 881249423Sdim /// pool within a specific module and found something. 882249423Sdim unsigned NumMethodPoolTableHits; 883249423Sdim 884212795Sdim /// \brief The total number of method pool entries in the selector table. 885212795Sdim unsigned TotalNumMethodPoolEntries; 886212795Sdim 887212795Sdim /// Number of lexical decl contexts read/total. 888212795Sdim unsigned NumLexicalDeclContextsRead, TotalLexicalDeclContexts; 889212795Sdim 890212795Sdim /// Number of visible decl contexts read/total. 891212795Sdim unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts; 892234353Sdim 893226633Sdim /// Total size of modules, in bits, currently loaded 894226633Sdim uint64_t TotalModulesSizeInBits; 895226633Sdim 896212795Sdim /// \brief Number of Decl/types that are currently deserializing. 897212795Sdim unsigned NumCurrentElementsDeserializing; 898212795Sdim 899234353Sdim /// \brief Set true while we are in the process of passing deserialized 900234353Sdim /// "interesting" decls to consumer inside FinishedDeserializing(). 901234353Sdim /// This is used as a guard to avoid recursively repeating the process of 902234353Sdim /// passing decls to consumer. 903234353Sdim bool PassingDeclsToConsumer; 904234353Sdim 905226633Sdim /// Number of CXX base specifiers currently loaded 906226633Sdim unsigned NumCXXBaseSpecifiersLoaded; 907226633Sdim 908212795Sdim /// \brief The set of identifiers that were read while the AST reader was 909212795Sdim /// (recursively) loading declarations. 910212795Sdim /// 911212795Sdim /// The declarations on the identifier chain for these identifiers will be 912212795Sdim /// loaded once the recursive loading has completed. 913249423Sdim llvm::MapVector<IdentifierInfo *, SmallVector<uint32_t, 4> > 914249423Sdim PendingIdentifierInfos; 915212795Sdim 916234353Sdim /// \brief The generation number of each identifier, which keeps track of 917234353Sdim /// the last time we loaded information about this identifier. 918234353Sdim llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration; 919234353Sdim 920212795Sdim /// \brief Contains declarations and definitions that will be 921212795Sdim /// "interesting" to the ASTConsumer, when we get that AST consumer. 922212795Sdim /// 923212795Sdim /// "Interesting" declarations are those that have data that may 924212795Sdim /// need to be emitted, such as inline function definitions or 925212795Sdim /// Objective-C protocols. 926212795Sdim std::deque<Decl *> InterestingDecls; 927212795Sdim 928243830Sdim /// \brief The set of redeclarable declarations that have been deserialized 929234353Sdim /// since the last time the declaration chains were linked. 930234353Sdim llvm::SmallPtrSet<Decl *, 16> RedeclsDeserialized; 931234353Sdim 932234353Sdim /// \brief The list of redeclaration chains that still need to be 933234353Sdim /// reconstructed. 934234353Sdim /// 935234353Sdim /// Each element is the global declaration ID of the first declaration in 936234353Sdim /// the chain. Elements in this vector should be unique; use 937234353Sdim /// PendingDeclChainsKnown to ensure uniqueness. 938249423Sdim SmallVector<serialization::DeclID, 16> PendingDeclChains; 939218893Sdim 940234353Sdim /// \brief Keeps track of the elements added to PendingDeclChains. 941234353Sdim llvm::SmallSet<serialization::DeclID, 16> PendingDeclChainsKnown; 942234353Sdim 943276479Sdim /// \brief The list of canonical declarations whose redeclaration chains 944276479Sdim /// need to be marked as incomplete once we're done deserializing things. 945276479Sdim SmallVector<Decl *, 16> PendingIncompleteDeclChains; 946276479Sdim 947249423Sdim /// \brief The Decl IDs for the Sema/Lexical DeclContext of a Decl that has 948249423Sdim /// been loaded but its DeclContext was not set yet. 949249423Sdim struct PendingDeclContextInfo { 950249423Sdim Decl *D; 951249423Sdim serialization::GlobalDeclID SemaDC; 952249423Sdim serialization::GlobalDeclID LexicalDC; 953249423Sdim }; 954249423Sdim 955249423Sdim /// \brief The set of Decls that have been loaded but their DeclContexts are 956249423Sdim /// not set yet. 957249423Sdim /// 958249423Sdim /// The DeclContexts for these Decls will be set once recursive loading has 959249423Sdim /// been completed. 960249423Sdim std::deque<PendingDeclContextInfo> PendingDeclContextInfos; 961249423Sdim 962261991Sdim /// \brief The set of NamedDecls that have been loaded, but are members of a 963261991Sdim /// context that has been merged into another context where the corresponding 964261991Sdim /// declaration is either missing or has not yet been loaded. 965261991Sdim /// 966261991Sdim /// We will check whether the corresponding declaration is in fact missing 967261991Sdim /// once recursing loading has been completed. 968261991Sdim llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks; 969261991Sdim 970276479Sdim /// \brief Record definitions in which we found an ODR violation. 971276479Sdim llvm::SmallDenseMap<CXXRecordDecl *, llvm::TinyPtrVector<CXXRecordDecl *>, 2> 972276479Sdim PendingOdrMergeFailures; 973276479Sdim 974276479Sdim /// \brief DeclContexts in which we have diagnosed an ODR violation. 975276479Sdim llvm::SmallPtrSet<DeclContext*, 2> DiagnosedOdrMergeFailures; 976276479Sdim 977234353Sdim /// \brief The set of Objective-C categories that have been deserialized 978234353Sdim /// since the last time the declaration chains were linked. 979234353Sdim llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized; 980234353Sdim 981234353Sdim /// \brief The set of Objective-C class definitions that have already been 982234353Sdim /// loaded, for which we will need to check for categories whenever a new 983234353Sdim /// module is loaded. 984249423Sdim SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded; 985276479Sdim 986276479Sdim /// \brief A mapping from a primary context for a declaration chain to the 987276479Sdim /// other declarations of that entity that also have name lookup tables. 988276479Sdim /// Used when we merge together two class definitions that have different 989276479Sdim /// sets of declared special member functions. 990276479Sdim llvm::DenseMap<const DeclContext*, SmallVector<const DeclContext*, 2>> 991276479Sdim MergedLookups; 992276479Sdim 993249423Sdim typedef llvm::DenseMap<Decl *, SmallVector<serialization::DeclID, 2> > 994234353Sdim MergedDeclsMap; 995234353Sdim 996234353Sdim /// \brief A mapping from canonical declarations to the set of additional 997234353Sdim /// (global, previously-canonical) declaration IDs that have been merged with 998234353Sdim /// that canonical declaration. 999234353Sdim MergedDeclsMap MergedDecls; 1000234353Sdim 1001234353Sdim typedef llvm::DenseMap<serialization::GlobalDeclID, 1002249423Sdim SmallVector<serialization::DeclID, 2> > 1003234353Sdim StoredMergedDeclsMap; 1004234353Sdim 1005234353Sdim /// \brief A mapping from canonical declaration IDs to the set of additional 1006234353Sdim /// declaration IDs that have been merged with that canonical declaration. 1007234353Sdim /// 1008234353Sdim /// This is the deserialized representation of the entries in MergedDecls. 1009234353Sdim /// When we query entries in MergedDecls, they will be augmented with entries 1010234353Sdim /// from StoredMergedDecls. 1011234353Sdim StoredMergedDeclsMap StoredMergedDecls; 1012234353Sdim 1013234353Sdim /// \brief Combine the stored merged declarations for the given canonical 1014234353Sdim /// declaration into the set of merged declarations. 1015234353Sdim /// 1016234353Sdim /// \returns An iterator into MergedDecls that corresponds to the position of 1017234353Sdim /// the given canonical declaration. 1018234353Sdim MergedDeclsMap::iterator 1019234353Sdim combineStoredMergedDecls(Decl *Canon, serialization::GlobalDeclID CanonID); 1020218893Sdim 1021261991Sdim /// \brief A mapping from DeclContexts to the semantic DeclContext that we 1022261991Sdim /// are treating as the definition of the entity. This is used, for instance, 1023261991Sdim /// when merging implicit instantiations of class templates across modules. 1024261991Sdim llvm::DenseMap<DeclContext *, DeclContext *> MergedDeclContexts; 1025261991Sdim 1026261991Sdim /// \brief A mapping from canonical declarations of enums to their canonical 1027261991Sdim /// definitions. Only populated when using modules in C++. 1028261991Sdim llvm::DenseMap<EnumDecl *, EnumDecl *> EnumDefinitions; 1029261991Sdim 1030212795Sdim /// \brief When reading a Stmt tree, Stmt operands are placed in this stack. 1031226633Sdim SmallVector<Stmt *, 16> StmtStack; 1032212795Sdim 1033212795Sdim /// \brief What kind of records we are reading. 1034212795Sdim enum ReadingKind { 1035261991Sdim Read_None, Read_Decl, Read_Type, Read_Stmt 1036212795Sdim }; 1037212795Sdim 1038234353Sdim /// \brief What kind of records we are reading. 1039212795Sdim ReadingKind ReadingKind; 1040212795Sdim 1041212795Sdim /// \brief RAII object to change the reading kind. 1042212795Sdim class ReadingKindTracker { 1043212795Sdim ASTReader &Reader; 1044212795Sdim enum ReadingKind PrevKind; 1045212795Sdim 1046243830Sdim ReadingKindTracker(const ReadingKindTracker &) LLVM_DELETED_FUNCTION; 1047243830Sdim void operator=(const ReadingKindTracker &) LLVM_DELETED_FUNCTION; 1048212795Sdim 1049212795Sdim public: 1050212795Sdim ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader) 1051212795Sdim : Reader(reader), PrevKind(Reader.ReadingKind) { 1052212795Sdim Reader.ReadingKind = newKind; 1053212795Sdim } 1054212795Sdim 1055212795Sdim ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; } 1056212795Sdim }; 1057212795Sdim 1058212795Sdim /// \brief Suggested contents of the predefines buffer, after this 1059212795Sdim /// PCH file has been processed. 1060212795Sdim /// 1061212795Sdim /// In most cases, this string will be empty, because the predefines 1062212795Sdim /// buffer computed to build the PCH file will be identical to the 1063212795Sdim /// predefines buffer computed from the command line. However, when 1064212795Sdim /// there are differences that the PCH reader can work around, this 1065212795Sdim /// predefines buffer may contain additional definitions. 1066212795Sdim std::string SuggestedPredefines; 1067212795Sdim 1068212795Sdim /// \brief Reads a statement from the specified cursor. 1069234353Sdim Stmt *ReadStmtFromStream(ModuleFile &F); 1070212795Sdim 1071276479Sdim struct InputFileInfo { 1072276479Sdim std::string Filename; 1073276479Sdim off_t StoredSize; 1074276479Sdim time_t StoredTime; 1075276479Sdim bool Overridden; 1076276479Sdim }; 1077276479Sdim 1078276479Sdim /// \brief Reads the stored information about an input file. 1079276479Sdim InputFileInfo readInputFileInfo(ModuleFile &F, unsigned ID); 1080276479Sdim /// \brief A convenience method to read the filename from an input file. 1081276479Sdim std::string getInputFileName(ModuleFile &F, unsigned ID); 1082276479Sdim 1083243830Sdim /// \brief Retrieve the file entry and 'overridden' bit for an input 1084243830Sdim /// file in the given module file. 1085249423Sdim serialization::InputFile getInputFile(ModuleFile &F, unsigned ID, 1086249423Sdim bool Complain = true); 1087243830Sdim 1088223017Sdim /// \brief Get a FileEntry out of stored-in-PCH filename, making sure we take 1089223017Sdim /// into account all the necessary relocations. 1090226633Sdim const FileEntry *getFileEntry(StringRef filename); 1091223017Sdim 1092243830Sdim void MaybeAddSystemRootToFilename(ModuleFile &M, std::string &Filename); 1093212795Sdim 1094249423Sdim struct ImportedModule { 1095249423Sdim ModuleFile *Mod; 1096249423Sdim ModuleFile *ImportedBy; 1097249423Sdim SourceLocation ImportLoc; 1098249423Sdim 1099249423Sdim ImportedModule(ModuleFile *Mod, 1100249423Sdim ModuleFile *ImportedBy, 1101249423Sdim SourceLocation ImportLoc) 1102249423Sdim : Mod(Mod), ImportedBy(ImportedBy), ImportLoc(ImportLoc) { } 1103249423Sdim }; 1104249423Sdim 1105226633Sdim ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type, 1106249423Sdim SourceLocation ImportLoc, ModuleFile *ImportedBy, 1107249423Sdim SmallVectorImpl<ImportedModule> &Loaded, 1108249423Sdim off_t ExpectedSize, time_t ExpectedModTime, 1109243830Sdim unsigned ClientLoadCapabilities); 1110243830Sdim ASTReadResult ReadControlBlock(ModuleFile &F, 1111249423Sdim SmallVectorImpl<ImportedModule> &Loaded, 1112276479Sdim const ModuleFile *ImportedBy, 1113243830Sdim unsigned ClientLoadCapabilities); 1114276479Sdim ASTReadResult ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities); 1115234353Sdim bool ParseLineTable(ModuleFile &F, SmallVectorImpl<uint64_t> &Record); 1116243830Sdim bool ReadSourceManagerBlock(ModuleFile &F); 1117226633Sdim llvm::BitstreamCursor &SLocCursorForID(int ID); 1118234353Sdim SourceLocation getImportLocation(ModuleFile *F); 1119276479Sdim ASTReadResult ReadSubmoduleBlock(ModuleFile &F, 1120276479Sdim unsigned ClientLoadCapabilities); 1121243830Sdim static bool ParseLanguageOptions(const RecordData &Record, bool Complain, 1122243830Sdim ASTReaderListener &Listener); 1123243830Sdim static bool ParseTargetOptions(const RecordData &Record, bool Complain, 1124243830Sdim ASTReaderListener &Listener); 1125243830Sdim static bool ParseDiagnosticOptions(const RecordData &Record, bool Complain, 1126243830Sdim ASTReaderListener &Listener); 1127243830Sdim static bool ParseFileSystemOptions(const RecordData &Record, bool Complain, 1128243830Sdim ASTReaderListener &Listener); 1129243830Sdim static bool ParseHeaderSearchOptions(const RecordData &Record, bool Complain, 1130243830Sdim ASTReaderListener &Listener); 1131243830Sdim static bool ParsePreprocessorOptions(const RecordData &Record, bool Complain, 1132243830Sdim ASTReaderListener &Listener, 1133243830Sdim std::string &SuggestedPredefines); 1134243830Sdim 1135218893Sdim struct RecordLocation { 1136234353Sdim RecordLocation(ModuleFile *M, uint64_t O) 1137218893Sdim : F(M), Offset(O) {} 1138234353Sdim ModuleFile *F; 1139218893Sdim uint64_t Offset; 1140218893Sdim }; 1141212795Sdim 1142226633Sdim QualType readTypeRecord(unsigned Index); 1143276479Sdim void readExceptionSpec(ModuleFile &ModuleFile, 1144276479Sdim SmallVectorImpl<QualType> &ExceptionStorage, 1145276479Sdim FunctionProtoType::ExtProtoInfo &EPI, 1146276479Sdim const RecordData &Record, unsigned &Index); 1147212795Sdim RecordLocation TypeCursorForIndex(unsigned Index); 1148212795Sdim void LoadedDecl(unsigned Index, Decl *D); 1149226633Sdim Decl *ReadDeclRecord(serialization::DeclID ID); 1150276479Sdim void markIncompleteDeclChain(Decl *Canon); 1151234353Sdim RecordLocation DeclCursorForID(serialization::DeclID ID, 1152234353Sdim unsigned &RawLocation); 1153226633Sdim void loadDeclUpdateRecords(serialization::DeclID ID, Decl *D); 1154234353Sdim void loadPendingDeclChain(serialization::GlobalDeclID ID); 1155234353Sdim void loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D, 1156234353Sdim unsigned PreviousGeneration = 0); 1157234353Sdim 1158226633Sdim RecordLocation getLocalBitOffset(uint64_t GlobalOffset); 1159234353Sdim uint64_t getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset); 1160212795Sdim 1161276479Sdim /// \brief Returns the first preprocessed entity ID that begins or ends after 1162276479Sdim /// \arg Loc. 1163226633Sdim serialization::PreprocessedEntityID 1164276479Sdim findPreprocessedEntity(SourceLocation Loc, bool EndsAfter) const; 1165226633Sdim 1166239462Sdim /// \brief Find the next module that contains entities and return the ID 1167226633Sdim /// of the first entry. 1168243830Sdim /// 1169243830Sdim /// \param SLocMapI points at a chunk of a module that contains no 1170239462Sdim /// preprocessed entities or the entities it contains are not the 1171239462Sdim /// ones we are looking for. 1172226633Sdim serialization::PreprocessedEntityID 1173226633Sdim findNextPreprocessedEntity( 1174226633Sdim GlobalSLocOffsetMapType::const_iterator SLocMapI) const; 1175226633Sdim 1176243830Sdim /// \brief Returns (ModuleFile, Local index) pair for \p GlobalIndex of a 1177234353Sdim /// preprocessed entity. 1178234353Sdim std::pair<ModuleFile *, unsigned> 1179234353Sdim getModulePreprocessedEntity(unsigned GlobalIndex); 1180234353Sdim 1181243830Sdim /// \brief Returns (begin, end) pair for the preprocessed entities of a 1182243830Sdim /// particular module. 1183243830Sdim std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator> 1184243830Sdim getModulePreprocessedEntities(ModuleFile &Mod) const; 1185243830Sdim 1186243830Sdim class ModuleDeclIterator { 1187243830Sdim ASTReader *Reader; 1188243830Sdim ModuleFile *Mod; 1189243830Sdim const serialization::LocalDeclID *Pos; 1190243830Sdim 1191243830Sdim public: 1192243830Sdim typedef const Decl *value_type; 1193243830Sdim typedef value_type& reference; 1194243830Sdim typedef value_type* pointer; 1195243830Sdim 1196276479Sdim ModuleDeclIterator() : Reader(nullptr), Mod(nullptr), Pos(nullptr) { } 1197243830Sdim 1198243830Sdim ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod, 1199243830Sdim const serialization::LocalDeclID *Pos) 1200243830Sdim : Reader(Reader), Mod(Mod), Pos(Pos) { } 1201243830Sdim 1202243830Sdim value_type operator*() const { 1203243830Sdim return Reader->GetDecl(Reader->getGlobalDeclID(*Mod, *Pos)); 1204243830Sdim } 1205243830Sdim 1206243830Sdim ModuleDeclIterator &operator++() { 1207243830Sdim ++Pos; 1208243830Sdim return *this; 1209243830Sdim } 1210243830Sdim 1211243830Sdim ModuleDeclIterator operator++(int) { 1212243830Sdim ModuleDeclIterator Prev(*this); 1213243830Sdim ++Pos; 1214243830Sdim return Prev; 1215243830Sdim } 1216243830Sdim 1217243830Sdim ModuleDeclIterator &operator--() { 1218243830Sdim --Pos; 1219243830Sdim return *this; 1220243830Sdim } 1221243830Sdim 1222243830Sdim ModuleDeclIterator operator--(int) { 1223243830Sdim ModuleDeclIterator Prev(*this); 1224243830Sdim --Pos; 1225243830Sdim return Prev; 1226243830Sdim } 1227243830Sdim 1228243830Sdim friend bool operator==(const ModuleDeclIterator &LHS, 1229243830Sdim const ModuleDeclIterator &RHS) { 1230243830Sdim assert(LHS.Reader == RHS.Reader && LHS.Mod == RHS.Mod); 1231243830Sdim return LHS.Pos == RHS.Pos; 1232243830Sdim } 1233243830Sdim 1234243830Sdim friend bool operator!=(const ModuleDeclIterator &LHS, 1235243830Sdim const ModuleDeclIterator &RHS) { 1236243830Sdim assert(LHS.Reader == RHS.Reader && LHS.Mod == RHS.Mod); 1237243830Sdim return LHS.Pos != RHS.Pos; 1238243830Sdim } 1239243830Sdim }; 1240243830Sdim 1241243830Sdim std::pair<ModuleDeclIterator, ModuleDeclIterator> 1242243830Sdim getModuleFileLevelDecls(ModuleFile &Mod); 1243243830Sdim 1244212795Sdim void PassInterestingDeclsToConsumer(); 1245234353Sdim void PassInterestingDeclToConsumer(Decl *D); 1246212795Sdim 1247234353Sdim void finishPendingActions(); 1248234353Sdim 1249251662Sdim void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name); 1250251662Sdim 1251249423Sdim void addPendingDeclContextInfo(Decl *D, 1252249423Sdim serialization::GlobalDeclID SemaDC, 1253249423Sdim serialization::GlobalDeclID LexicalDC) { 1254249423Sdim assert(D); 1255249423Sdim PendingDeclContextInfo Info = { D, SemaDC, LexicalDC }; 1256249423Sdim PendingDeclContextInfos.push_back(Info); 1257249423Sdim } 1258249423Sdim 1259212795Sdim /// \brief Produce an error diagnostic and return true. 1260212795Sdim /// 1261212795Sdim /// This routine should only be used for fatal errors that have to 1262212795Sdim /// do with non-routine failures (e.g., corrupted AST file). 1263226633Sdim void Error(StringRef Msg); 1264226633Sdim void Error(unsigned DiagID, StringRef Arg1 = StringRef(), 1265226633Sdim StringRef Arg2 = StringRef()); 1266212795Sdim 1267243830Sdim ASTReader(const ASTReader &) LLVM_DELETED_FUNCTION; 1268243830Sdim void operator=(const ASTReader &) LLVM_DELETED_FUNCTION; 1269212795Sdimpublic: 1270212795Sdim /// \brief Load the AST file and validate its contents against the given 1271212795Sdim /// Preprocessor. 1272212795Sdim /// 1273212795Sdim /// \param PP the preprocessor associated with the context in which this 1274212795Sdim /// precompiled header will be loaded. 1275212795Sdim /// 1276212795Sdim /// \param Context the AST context that this precompiled header will be 1277212795Sdim /// loaded into. 1278212795Sdim /// 1279212795Sdim /// \param isysroot If non-NULL, the system include path specified by the 1280212795Sdim /// user. This is only used with relocatable PCH files. If non-NULL, 1281212795Sdim /// a relocatable PCH file will use the default path "/". 1282212795Sdim /// 1283212795Sdim /// \param DisableValidation If true, the AST reader will suppress most 1284212795Sdim /// of its regular consistency checking, allowing the use of precompiled 1285212795Sdim /// headers that cannot be determined to be compatible. 1286218893Sdim /// 1287234353Sdim /// \param AllowASTWithCompilerErrors If true, the AST reader will accept an 1288234353Sdim /// AST file the was created out of an AST with compiler errors, 1289234353Sdim /// otherwise it will reject it. 1290249423Sdim /// 1291276479Sdim /// \param AllowConfigurationMismatch If true, the AST reader will not check 1292276479Sdim /// for configuration differences between the AST file and the invocation. 1293276479Sdim /// 1294276479Sdim /// \param ValidateSystemInputs If true, the AST reader will validate 1295276479Sdim /// system input files in addition to user input files. This is only 1296276479Sdim /// meaningful if \p DisableValidation is false. 1297276479Sdim /// 1298249423Sdim /// \param UseGlobalIndex If true, the AST reader will try to load and use 1299249423Sdim /// the global module index. 1300226633Sdim ASTReader(Preprocessor &PP, ASTContext &Context, StringRef isysroot = "", 1301243830Sdim bool DisableValidation = false, 1302249423Sdim bool AllowASTWithCompilerErrors = false, 1303276479Sdim bool AllowConfigurationMismatch = false, 1304276479Sdim bool ValidateSystemInputs = false, 1305249423Sdim bool UseGlobalIndex = true); 1306212795Sdim 1307212795Sdim ~ASTReader(); 1308212795Sdim 1309226633Sdim SourceManager &getSourceManager() const { return SourceMgr; } 1310249423Sdim FileManager &getFileManager() const { return FileMgr; } 1311234353Sdim 1312243830Sdim /// \brief Flags that indicate what kind of AST loading failures the client 1313243830Sdim /// of the AST reader can directly handle. 1314243830Sdim /// 1315243830Sdim /// When a client states that it can handle a particular kind of failure, 1316243830Sdim /// the AST reader will not emit errors when producing that kind of failure. 1317243830Sdim enum LoadFailureCapabilities { 1318243830Sdim /// \brief The client can't handle any AST loading failures. 1319243830Sdim ARR_None = 0, 1320243830Sdim /// \brief The client can handle an AST file that cannot load because it 1321249423Sdim /// is missing. 1322249423Sdim ARR_Missing = 0x1, 1323249423Sdim /// \brief The client can handle an AST file that cannot load because it 1324243830Sdim /// is out-of-date relative to its input files. 1325249423Sdim ARR_OutOfDate = 0x2, 1326243830Sdim /// \brief The client can handle an AST file that cannot load because it 1327243830Sdim /// was built with a different version of Clang. 1328249423Sdim ARR_VersionMismatch = 0x4, 1329243830Sdim /// \brief The client can handle an AST file that cannot load because it's 1330243830Sdim /// compiled configuration doesn't match that of the context it was 1331243830Sdim /// loaded into. 1332249423Sdim ARR_ConfigurationMismatch = 0x8 1333243830Sdim }; 1334243830Sdim 1335226633Sdim /// \brief Load the AST file designated by the given file name. 1336243830Sdim /// 1337243830Sdim /// \param FileName The name of the AST file to load. 1338243830Sdim /// 1339243830Sdim /// \param Type The kind of AST being loaded, e.g., PCH, module, main file, 1340243830Sdim /// or preamble. 1341243830Sdim /// 1342249423Sdim /// \param ImportLoc the location where the module file will be considered as 1343249423Sdim /// imported from. For non-module AST types it should be invalid. 1344249423Sdim /// 1345243830Sdim /// \param ClientLoadCapabilities The set of client load-failure 1346243830Sdim /// capabilities, represented as a bitset of the enumerators of 1347243830Sdim /// LoadFailureCapabilities. 1348243830Sdim ASTReadResult ReadAST(const std::string &FileName, ModuleKind Type, 1349249423Sdim SourceLocation ImportLoc, 1350243830Sdim unsigned ClientLoadCapabilities); 1351212795Sdim 1352234353Sdim /// \brief Make the entities in the given module and any of its (non-explicit) 1353234353Sdim /// submodules visible to name lookup. 1354234353Sdim /// 1355234353Sdim /// \param Mod The module whose names should be made visible. 1356234353Sdim /// 1357239462Sdim /// \param NameVisibility The level of visibility to give the names in the 1358239462Sdim /// module. Visibility can only be increased over time. 1359249423Sdim /// 1360249423Sdim /// \param ImportLoc The location at which the import occurs. 1361249423Sdim /// 1362249423Sdim /// \param Complain Whether to complain about conflicting module imports. 1363276479Sdim void makeModuleVisible(Module *Mod, 1364249423Sdim Module::NameVisibilityKind NameVisibility, 1365249423Sdim SourceLocation ImportLoc, 1366249423Sdim bool Complain); 1367276479Sdim 1368234353Sdim /// \brief Make the names within this set of hidden names visible. 1369276479Sdim void makeNamesVisible(const HiddenNames &Names, Module *Owner, 1370276479Sdim bool FromFinalization); 1371276479Sdim 1372212795Sdim /// \brief Set the AST callbacks listener. 1373212795Sdim void setListener(ASTReaderListener *listener) { 1374212795Sdim Listener.reset(listener); 1375212795Sdim } 1376212795Sdim 1377276479Sdim /// \brief Add an AST callbak listener. 1378276479Sdim /// 1379276479Sdim /// Takes ownership of \p L. 1380276479Sdim void addListener(ASTReaderListener *L) { 1381276479Sdim if (Listener) 1382276479Sdim L = new ChainedASTReaderListener(L, Listener.release()); 1383276479Sdim Listener.reset(L); 1384276479Sdim } 1385276479Sdim 1386212795Sdim /// \brief Set the AST deserialization listener. 1387276479Sdim void setDeserializationListener(ASTDeserializationListener *Listener, 1388276479Sdim bool TakeOwnership = false); 1389212795Sdim 1390249423Sdim /// \brief Determine whether this AST reader has a global index. 1391276479Sdim bool hasGlobalIndex() const { return (bool)GlobalIndex; } 1392249423Sdim 1393276479Sdim /// \brief Return global module index. 1394276479Sdim GlobalModuleIndex *getGlobalIndex() { return GlobalIndex.get(); } 1395276479Sdim 1396276479Sdim /// \brief Reset reader for a reload try. 1397276479Sdim void resetForReload() { TriedLoadingGlobalIndex = false; } 1398276479Sdim 1399249423Sdim /// \brief Attempts to load the global index. 1400249423Sdim /// 1401249423Sdim /// \returns true if loading the global index has failed for any reason. 1402249423Sdim bool loadGlobalIndex(); 1403249423Sdim 1404249423Sdim /// \brief Determine whether we tried to load the global index, but failed, 1405249423Sdim /// e.g., because it is out-of-date or does not exist. 1406249423Sdim bool isGlobalIndexUnavailable() const; 1407249423Sdim 1408226633Sdim /// \brief Initializes the ASTContext 1409226633Sdim void InitializeContext(); 1410212795Sdim 1411261991Sdim /// \brief Update the state of Sema after loading some additional modules. 1412261991Sdim void UpdateSema(); 1413261991Sdim 1414226633Sdim /// \brief Add in-memory (virtual file) buffer. 1415226633Sdim void addInMemoryBuffer(StringRef &FileName, llvm::MemoryBuffer *Buffer) { 1416226633Sdim ModuleMgr.addInMemoryBuffer(FileName, Buffer); 1417221345Sdim } 1418221345Sdim 1419234353Sdim /// \brief Finalizes the AST reader's state before writing an AST file to 1420234353Sdim /// disk. 1421234353Sdim /// 1422234353Sdim /// This operation may undo temporary state in the AST that should not be 1423234353Sdim /// emitted. 1424234353Sdim void finalizeForWriting(); 1425234353Sdim 1426226633Sdim /// \brief Retrieve the module manager. 1427226633Sdim ModuleManager &getModuleManager() { return ModuleMgr; } 1428212795Sdim 1429226633Sdim /// \brief Retrieve the preprocessor. 1430226633Sdim Preprocessor &getPreprocessor() const { return PP; } 1431234353Sdim 1432243830Sdim /// \brief Retrieve the name of the original source file name for the primary 1433243830Sdim /// module file. 1434243830Sdim StringRef getOriginalSourceFile() { 1435243830Sdim return ModuleMgr.getPrimaryModule().OriginalSourceFileName; 1436243830Sdim } 1437212795Sdim 1438212795Sdim /// \brief Retrieve the name of the original source file name directly from 1439212795Sdim /// the AST file, without actually loading the AST file. 1440212795Sdim static std::string getOriginalSourceFile(const std::string &ASTFileName, 1441218893Sdim FileManager &FileMgr, 1442226633Sdim DiagnosticsEngine &Diags); 1443212795Sdim 1444243830Sdim /// \brief Read the control block for the named AST file. 1445243830Sdim /// 1446243830Sdim /// \returns true if an error occurred, false otherwise. 1447243830Sdim static bool readASTFileControlBlock(StringRef Filename, 1448243830Sdim FileManager &FileMgr, 1449243830Sdim ASTReaderListener &Listener); 1450243830Sdim 1451243830Sdim /// \brief Determine whether the given AST file is acceptable to load into a 1452243830Sdim /// translation unit with the given language and target options. 1453243830Sdim static bool isAcceptableASTFile(StringRef Filename, 1454243830Sdim FileManager &FileMgr, 1455243830Sdim const LangOptions &LangOpts, 1456243830Sdim const TargetOptions &TargetOpts, 1457243830Sdim const PreprocessorOptions &PPOpts); 1458243830Sdim 1459212795Sdim /// \brief Returns the suggested contents of the predefines buffer, 1460212795Sdim /// which contains a (typically-empty) subset of the predefines 1461212795Sdim /// build prior to including the precompiled header. 1462212795Sdim const std::string &getSuggestedPredefines() { return SuggestedPredefines; } 1463212795Sdim 1464226633Sdim /// \brief Read a preallocated preprocessed entity from the external source. 1465226633Sdim /// 1466226633Sdim /// \returns null if an error occurred that prevented the preprocessed 1467226633Sdim /// entity from being loaded. 1468276479Sdim PreprocessedEntity *ReadPreprocessedEntity(unsigned Index) override; 1469218893Sdim 1470226633Sdim /// \brief Returns a pair of [Begin, End) indices of preallocated 1471243830Sdim /// preprocessed entities that \p Range encompasses. 1472276479Sdim std::pair<unsigned, unsigned> 1473276479Sdim findPreprocessedEntitiesInRange(SourceRange Range) override; 1474226633Sdim 1475234353Sdim /// \brief Optionally returns true or false if the preallocated preprocessed 1476243830Sdim /// entity with index \p Index came from file \p FID. 1477276479Sdim Optional<bool> isPreprocessedEntityInFileID(unsigned Index, 1478276479Sdim FileID FID) override; 1479234353Sdim 1480218893Sdim /// \brief Read the header file information for the given file entry. 1481276479Sdim HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) override; 1482218893Sdim 1483226633Sdim void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag); 1484218893Sdim 1485212795Sdim /// \brief Returns the number of source locations found in the chain. 1486212795Sdim unsigned getTotalNumSLocs() const { 1487212795Sdim return TotalNumSLocEntries; 1488212795Sdim } 1489212795Sdim 1490212795Sdim /// \brief Returns the number of identifiers found in the chain. 1491212795Sdim unsigned getTotalNumIdentifiers() const { 1492212795Sdim return static_cast<unsigned>(IdentifiersLoaded.size()); 1493212795Sdim } 1494212795Sdim 1495243830Sdim /// \brief Returns the number of macros found in the chain. 1496243830Sdim unsigned getTotalNumMacros() const { 1497243830Sdim return static_cast<unsigned>(MacrosLoaded.size()); 1498243830Sdim } 1499243830Sdim 1500212795Sdim /// \brief Returns the number of types found in the chain. 1501212795Sdim unsigned getTotalNumTypes() const { 1502212795Sdim return static_cast<unsigned>(TypesLoaded.size()); 1503212795Sdim } 1504212795Sdim 1505212795Sdim /// \brief Returns the number of declarations found in the chain. 1506212795Sdim unsigned getTotalNumDecls() const { 1507212795Sdim return static_cast<unsigned>(DeclsLoaded.size()); 1508212795Sdim } 1509212795Sdim 1510234353Sdim /// \brief Returns the number of submodules known. 1511234353Sdim unsigned getTotalNumSubmodules() const { 1512234353Sdim return static_cast<unsigned>(SubmodulesLoaded.size()); 1513234353Sdim } 1514234353Sdim 1515212795Sdim /// \brief Returns the number of selectors found in the chain. 1516212795Sdim unsigned getTotalNumSelectors() const { 1517212795Sdim return static_cast<unsigned>(SelectorsLoaded.size()); 1518212795Sdim } 1519212795Sdim 1520226633Sdim /// \brief Returns the number of preprocessed entities known to the AST 1521226633Sdim /// reader. 1522226633Sdim unsigned getTotalNumPreprocessedEntities() const { 1523226633Sdim unsigned Result = 0; 1524226633Sdim for (ModuleConstIterator I = ModuleMgr.begin(), 1525226633Sdim E = ModuleMgr.end(); I != E; ++I) { 1526226633Sdim Result += (*I)->NumPreprocessedEntities; 1527226633Sdim } 1528234353Sdim 1529226633Sdim return Result; 1530218893Sdim } 1531234353Sdim 1532218893Sdim /// \brief Returns the number of C++ base specifiers found in the chain. 1533226633Sdim unsigned getTotalNumCXXBaseSpecifiers() const { 1534226633Sdim return NumCXXBaseSpecifiersLoaded; 1535226633Sdim } 1536234353Sdim 1537212795Sdim /// \brief Reads a TemplateArgumentLocInfo appropriate for the 1538212795Sdim /// given TemplateArgument kind. 1539212795Sdim TemplateArgumentLocInfo 1540234353Sdim GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind, 1541212795Sdim const RecordData &Record, unsigned &Idx); 1542212795Sdim 1543212795Sdim /// \brief Reads a TemplateArgumentLoc. 1544212795Sdim TemplateArgumentLoc 1545234353Sdim ReadTemplateArgumentLoc(ModuleFile &F, 1546212795Sdim const RecordData &Record, unsigned &Idx); 1547212795Sdim 1548261991Sdim const ASTTemplateArgumentListInfo* 1549261991Sdim ReadASTTemplateArgumentListInfo(ModuleFile &F, 1550261991Sdim const RecordData &Record, unsigned &Index); 1551261991Sdim 1552212795Sdim /// \brief Reads a declarator info from the given record. 1553234353Sdim TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F, 1554212795Sdim const RecordData &Record, unsigned &Idx); 1555212795Sdim 1556212795Sdim /// \brief Resolve a type ID into a type, potentially building a new 1557212795Sdim /// type. 1558212795Sdim QualType GetType(serialization::TypeID ID); 1559212795Sdim 1560226633Sdim /// \brief Resolve a local type ID within a given AST file into a type. 1561234353Sdim QualType getLocalType(ModuleFile &F, unsigned LocalID); 1562234353Sdim 1563226633Sdim /// \brief Map a local type ID within a given AST file into a global type ID. 1564234353Sdim serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const; 1565234353Sdim 1566234353Sdim /// \brief Read a type from the current position in the given record, which 1567226633Sdim /// was read from the given AST file. 1568234353Sdim QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) { 1569226633Sdim if (Idx >= Record.size()) 1570226633Sdim return QualType(); 1571234353Sdim 1572226633Sdim return getLocalType(F, Record[Idx++]); 1573226633Sdim } 1574234353Sdim 1575234353Sdim /// \brief Map from a local declaration ID within a given module to a 1576226633Sdim /// global declaration ID. 1577243830Sdim serialization::DeclID getGlobalDeclID(ModuleFile &F, 1578243830Sdim serialization::LocalDeclID LocalID) const; 1579212795Sdim 1580243830Sdim /// \brief Returns true if global DeclID \p ID originated from module \p M. 1581234353Sdim bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const; 1582234353Sdim 1583234353Sdim /// \brief Retrieve the module file that owns the given declaration, or NULL 1584234353Sdim /// if the declaration is not from a module file. 1585249423Sdim ModuleFile *getOwningModuleFile(const Decl *D); 1586276479Sdim 1587276479Sdim /// \brief Get the best name we know for the module that owns the given 1588276479Sdim /// declaration, or an empty string if the declaration is not from a module. 1589276479Sdim std::string getOwningModuleNameForDiagnostic(const Decl *D); 1590276479Sdim 1591243830Sdim /// \brief Returns the source location for the decl \p ID. 1592234353Sdim SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID); 1593234353Sdim 1594212795Sdim /// \brief Resolve a declaration ID into a declaration, potentially 1595212795Sdim /// building a new declaration. 1596212795Sdim Decl *GetDecl(serialization::DeclID ID); 1597276479Sdim Decl *GetExternalDecl(uint32_t ID) override; 1598212795Sdim 1599276479Sdim /// \brief Resolve a declaration ID into a declaration. Return 0 if it's not 1600276479Sdim /// been loaded yet. 1601276479Sdim Decl *GetExistingDecl(serialization::DeclID ID); 1602276479Sdim 1603226633Sdim /// \brief Reads a declaration with the given local ID in the given module. 1604234353Sdim Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) { 1605226633Sdim return GetDecl(getGlobalDeclID(F, LocalID)); 1606226633Sdim } 1607226633Sdim 1608226633Sdim /// \brief Reads a declaration with the given local ID in the given module. 1609226633Sdim /// 1610226633Sdim /// \returns The requested declaration, casted to the given return type. 1611226633Sdim template<typename T> 1612234353Sdim T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) { 1613226633Sdim return cast_or_null<T>(GetLocalDecl(F, LocalID)); 1614226633Sdim } 1615226633Sdim 1616234353Sdim /// \brief Map a global declaration ID into the declaration ID used to 1617234353Sdim /// refer to this declaration within the given module fule. 1618234353Sdim /// 1619234353Sdim /// \returns the global ID of the given declaration as known in the given 1620234353Sdim /// module file. 1621234353Sdim serialization::DeclID 1622234353Sdim mapGlobalIDToModuleFileGlobalID(ModuleFile &M, 1623234353Sdim serialization::DeclID GlobalID); 1624234353Sdim 1625234353Sdim /// \brief Reads a declaration ID from the given position in a record in the 1626226633Sdim /// given module. 1627226633Sdim /// 1628226633Sdim /// \returns The declaration ID read from the record, adjusted to a global ID. 1629234353Sdim serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record, 1630226633Sdim unsigned &Idx); 1631234353Sdim 1632226633Sdim /// \brief Reads a declaration from the given position in a record in the 1633226633Sdim /// given module. 1634234353Sdim Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) { 1635226633Sdim return GetDecl(ReadDeclID(F, R, I)); 1636226633Sdim } 1637234353Sdim 1638226633Sdim /// \brief Reads a declaration from the given position in a record in the 1639226633Sdim /// given module. 1640226633Sdim /// 1641226633Sdim /// \returns The declaration read from this location, casted to the given 1642226633Sdim /// result type. 1643226633Sdim template<typename T> 1644234353Sdim T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) { 1645226633Sdim return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I))); 1646226633Sdim } 1647226633Sdim 1648276479Sdim /// \brief If any redeclarations of \p D have been imported since it was 1649276479Sdim /// last checked, this digs out those redeclarations and adds them to the 1650276479Sdim /// redeclaration chain for \p D. 1651276479Sdim void CompleteRedeclChain(const Decl *D) override; 1652276479Sdim 1653226633Sdim /// \brief Read a CXXBaseSpecifiers ID form the given record and 1654226633Sdim /// return its global bit offset. 1655234353Sdim uint64_t readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record, 1656226633Sdim unsigned &Idx); 1657234353Sdim 1658276479Sdim CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override; 1659234353Sdim 1660212795Sdim /// \brief Resolve the offset of a statement into a statement. 1661212795Sdim /// 1662212795Sdim /// This operation will read a new statement from the external 1663212795Sdim /// source each time it is called, and is meant to be used via a 1664212795Sdim /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). 1665276479Sdim Stmt *GetExternalDeclStmt(uint64_t Offset) override; 1666212795Sdim 1667212795Sdim /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the 1668212795Sdim /// specified cursor. Read the abbreviations that are at the top of the block 1669212795Sdim /// and then leave the cursor pointing into the block. 1670212795Sdim bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID); 1671212795Sdim 1672212795Sdim /// \brief Finds all the visible declarations with a given name. 1673212795Sdim /// The current implementation of this method just loads the entire 1674212795Sdim /// lookup table as unmaterialized references. 1675276479Sdim bool FindExternalVisibleDeclsByName(const DeclContext *DC, 1676276479Sdim DeclarationName Name) override; 1677212795Sdim 1678212795Sdim /// \brief Read all of the declarations lexically stored in a 1679212795Sdim /// declaration context. 1680212795Sdim /// 1681212795Sdim /// \param DC The declaration context whose declarations will be 1682212795Sdim /// read. 1683212795Sdim /// 1684212795Sdim /// \param Decls Vector that will contain the declarations loaded 1685212795Sdim /// from the external source. The caller is responsible for merging 1686212795Sdim /// these declarations with any declarations already stored in the 1687212795Sdim /// declaration context. 1688212795Sdim /// 1689212795Sdim /// \returns true if there was an error while reading the 1690212795Sdim /// declarations for this declaration context. 1691276479Sdim ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC, 1692276479Sdim bool (*isKindWeWant)(Decl::Kind), 1693276479Sdim SmallVectorImpl<Decl*> &Decls) override; 1694212795Sdim 1695234353Sdim /// \brief Get the decls that are contained in a file in the Offset/Length 1696243830Sdim /// range. \p Length can be 0 to indicate a point at \p Offset instead of 1697234353Sdim /// a range. 1698276479Sdim void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length, 1699276479Sdim SmallVectorImpl<Decl *> &Decls) override; 1700234353Sdim 1701212795Sdim /// \brief Notify ASTReader that we started deserialization of 1702212795Sdim /// a decl or type so until FinishedDeserializing is called there may be 1703212795Sdim /// decls that are initializing. Must be paired with FinishedDeserializing. 1704276479Sdim void StartedDeserializing() override { ++NumCurrentElementsDeserializing; } 1705212795Sdim 1706212795Sdim /// \brief Notify ASTReader that we finished the deserialization of 1707212795Sdim /// a decl or type. Must be paired with StartedDeserializing. 1708276479Sdim void FinishedDeserializing() override; 1709212795Sdim 1710212795Sdim /// \brief Function that will be invoked when we begin parsing a new 1711212795Sdim /// translation unit involving this external AST source. 1712212795Sdim /// 1713212795Sdim /// This function will provide all of the external definitions to 1714212795Sdim /// the ASTConsumer. 1715276479Sdim void StartTranslationUnit(ASTConsumer *Consumer) override; 1716212795Sdim 1717212795Sdim /// \brief Print some statistics about AST usage. 1718276479Sdim void PrintStats() override; 1719212795Sdim 1720226633Sdim /// \brief Dump information about the AST reader to standard error. 1721226633Sdim void dump(); 1722234353Sdim 1723221345Sdim /// Return the amount of memory used by memory buffers, breaking down 1724221345Sdim /// by heap-backed versus mmap'ed memory. 1725276479Sdim void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override; 1726221345Sdim 1727212795Sdim /// \brief Initialize the semantic source with the Sema instance 1728212795Sdim /// being used to perform semantic analysis on the abstract syntax 1729212795Sdim /// tree. 1730276479Sdim void InitializeSema(Sema &S) override; 1731212795Sdim 1732212795Sdim /// \brief Inform the semantic consumer that Sema is no longer available. 1733276479Sdim void ForgetSema() override { SemaObj = nullptr; } 1734212795Sdim 1735212795Sdim /// \brief Retrieve the IdentifierInfo for the named identifier. 1736212795Sdim /// 1737212795Sdim /// This routine builds a new IdentifierInfo for the given identifier. If any 1738212795Sdim /// declarations with this name are visible from translation unit scope, their 1739212795Sdim /// declarations will be deserialized and introduced into the declaration 1740212795Sdim /// chain of the identifier. 1741212795Sdim virtual IdentifierInfo *get(const char *NameStart, const char *NameEnd); 1742276479Sdim IdentifierInfo *get(StringRef Name) override { 1743212795Sdim return get(Name.begin(), Name.end()); 1744212795Sdim } 1745212795Sdim 1746218893Sdim /// \brief Retrieve an iterator into the set of all identifiers 1747218893Sdim /// in all loaded AST files. 1748276479Sdim IdentifierIterator *getIdentifiers() override; 1749218893Sdim 1750212795Sdim /// \brief Load the contents of the global method pool for a given 1751212795Sdim /// selector. 1752276479Sdim void ReadMethodPool(Selector Sel) override; 1753212795Sdim 1754224145Sdim /// \brief Load the set of namespaces that are known to the external source, 1755224145Sdim /// which will be used during typo correction. 1756276479Sdim void ReadKnownNamespaces( 1757276479Sdim SmallVectorImpl<NamespaceDecl *> &Namespaces) override; 1758224145Sdim 1759276479Sdim void ReadUndefinedButUsed( 1760276479Sdim llvm::DenseMap<NamedDecl *, SourceLocation> &Undefined) override; 1761249423Sdim 1762276479Sdim void ReadTentativeDefinitions( 1763276479Sdim SmallVectorImpl<VarDecl *> &TentativeDefs) override; 1764226633Sdim 1765276479Sdim void ReadUnusedFileScopedDecls( 1766276479Sdim SmallVectorImpl<const DeclaratorDecl *> &Decls) override; 1767226633Sdim 1768276479Sdim void ReadDelegatingConstructors( 1769276479Sdim SmallVectorImpl<CXXConstructorDecl *> &Decls) override; 1770226633Sdim 1771276479Sdim void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) override; 1772226633Sdim 1773276479Sdim void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) override; 1774226633Sdim 1775276479Sdim void ReadLocallyScopedExternCDecls( 1776276479Sdim SmallVectorImpl<NamedDecl *> &Decls) override; 1777234353Sdim 1778276479Sdim void ReadReferencedSelectors( 1779276479Sdim SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) override; 1780226633Sdim 1781276479Sdim void ReadWeakUndeclaredIdentifiers( 1782276479Sdim SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI) override; 1783226633Sdim 1784276479Sdim void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override; 1785226633Sdim 1786276479Sdim void ReadPendingInstantiations( 1787234353Sdim SmallVectorImpl<std::pair<ValueDecl *, 1788276479Sdim SourceLocation> > &Pending) override; 1789226633Sdim 1790276479Sdim void ReadLateParsedTemplates( 1791276479Sdim llvm::DenseMap<const FunctionDecl *, 1792276479Sdim LateParsedTemplate *> &LPTMap) override; 1793261991Sdim 1794212795Sdim /// \brief Load a selector from disk, registering its ID if it exists. 1795212795Sdim void LoadSelector(Selector Sel); 1796212795Sdim 1797212795Sdim void SetIdentifierInfo(unsigned ID, IdentifierInfo *II); 1798212795Sdim void SetGloballyVisibleDecls(IdentifierInfo *II, 1799226633Sdim const SmallVectorImpl<uint32_t> &DeclIDs, 1800276479Sdim SmallVectorImpl<Decl *> *Decls = nullptr); 1801212795Sdim 1802212795Sdim /// \brief Report a diagnostic. 1803212795Sdim DiagnosticBuilder Diag(unsigned DiagID); 1804212795Sdim 1805212795Sdim /// \brief Report a diagnostic. 1806212795Sdim DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); 1807212795Sdim 1808226633Sdim IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID); 1809212795Sdim 1810234353Sdim IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record, 1811226633Sdim unsigned &Idx) { 1812226633Sdim return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++])); 1813212795Sdim } 1814212795Sdim 1815276479Sdim IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) override { 1816243830Sdim // Note that we are loading an identifier. 1817243830Sdim Deserializing AnIdentifier(this); 1818243830Sdim 1819212795Sdim return DecodeIdentifierInfo(ID); 1820212795Sdim } 1821212795Sdim 1822234353Sdim IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID); 1823234353Sdim 1824234353Sdim serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M, 1825226633Sdim unsigned LocalID); 1826234353Sdim 1827276479Sdim ModuleMacroInfo *getModuleMacro(const PendingMacroInfo &PMInfo); 1828276479Sdim 1829249423Sdim void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo); 1830249423Sdim 1831249423Sdim void installPCHMacroDirectives(IdentifierInfo *II, 1832249423Sdim ModuleFile &M, uint64_t Offset); 1833249423Sdim 1834276479Sdim void installImportedMacro(IdentifierInfo *II, ModuleMacroInfo *MMI, 1835276479Sdim Module *Owner, bool FromFinalization); 1836249423Sdim 1837276479Sdim typedef llvm::TinyPtrVector<DefMacroDirective *> AmbiguousMacros; 1838276479Sdim llvm::DenseMap<IdentifierInfo*, AmbiguousMacros> AmbiguousMacroDefs; 1839276479Sdim 1840276479Sdim void 1841276479Sdim removeOverriddenMacros(IdentifierInfo *II, AmbiguousMacros &Ambig, 1842276479Sdim ArrayRef<serialization::SubmoduleID> Overrides); 1843276479Sdim 1844276479Sdim AmbiguousMacros * 1845276479Sdim removeOverriddenMacros(IdentifierInfo *II, 1846276479Sdim ArrayRef<serialization::SubmoduleID> Overrides); 1847276479Sdim 1848243830Sdim /// \brief Retrieve the macro with the given ID. 1849249423Sdim MacroInfo *getMacro(serialization::MacroID ID); 1850243830Sdim 1851243830Sdim /// \brief Retrieve the global macro ID corresponding to the given local 1852243830Sdim /// ID within the given module file. 1853243830Sdim serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID); 1854243830Sdim 1855212795Sdim /// \brief Read the source location entry with index ID. 1856276479Sdim bool ReadSLocEntry(int ID) override; 1857212795Sdim 1858249423Sdim /// \brief Retrieve the module import location and module name for the 1859249423Sdim /// given source manager entry ID. 1860276479Sdim std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID) override; 1861249423Sdim 1862234353Sdim /// \brief Retrieve the global submodule ID given a module and its local ID 1863234353Sdim /// number. 1864234353Sdim serialization::SubmoduleID 1865234353Sdim getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID); 1866234353Sdim 1867234353Sdim /// \brief Retrieve the submodule that corresponds to a global submodule ID. 1868234353Sdim /// 1869234353Sdim Module *getSubmodule(serialization::SubmoduleID GlobalID); 1870249423Sdim 1871249423Sdim /// \brief Retrieve the module that corresponds to the given module ID. 1872249423Sdim /// 1873249423Sdim /// Note: overrides method in ExternalASTSource 1874276479Sdim Module *getModule(unsigned ID) override; 1875249423Sdim 1876226633Sdim /// \brief Retrieve a selector from the given module with its local ID 1877226633Sdim /// number. 1878234353Sdim Selector getLocalSelector(ModuleFile &M, unsigned LocalID); 1879212795Sdim 1880226633Sdim Selector DecodeSelector(serialization::SelectorID Idx); 1881226633Sdim 1882276479Sdim Selector GetExternalSelector(serialization::SelectorID ID) override; 1883276479Sdim uint32_t GetNumExternalSelectors() override; 1884212795Sdim 1885234353Sdim Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) { 1886226633Sdim return getLocalSelector(M, Record[Idx++]); 1887212795Sdim } 1888234353Sdim 1889226633Sdim /// \brief Retrieve the global selector ID that corresponds to this 1890226633Sdim /// the local selector ID in a given module. 1891234353Sdim serialization::SelectorID getGlobalSelectorID(ModuleFile &F, 1892226633Sdim unsigned LocalID) const; 1893212795Sdim 1894212795Sdim /// \brief Read a declaration name. 1895234353Sdim DeclarationName ReadDeclarationName(ModuleFile &F, 1896226633Sdim const RecordData &Record, unsigned &Idx); 1897234353Sdim void ReadDeclarationNameLoc(ModuleFile &F, 1898218893Sdim DeclarationNameLoc &DNLoc, DeclarationName Name, 1899218893Sdim const RecordData &Record, unsigned &Idx); 1900234353Sdim void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo, 1901218893Sdim const RecordData &Record, unsigned &Idx); 1902212795Sdim 1903234353Sdim void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, 1904218893Sdim const RecordData &Record, unsigned &Idx); 1905218893Sdim 1906234353Sdim NestedNameSpecifier *ReadNestedNameSpecifier(ModuleFile &F, 1907226633Sdim const RecordData &Record, 1908212795Sdim unsigned &Idx); 1909212795Sdim 1910234353Sdim NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F, 1911219077Sdim const RecordData &Record, 1912219077Sdim unsigned &Idx); 1913219077Sdim 1914212795Sdim /// \brief Read a template name. 1915234353Sdim TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record, 1916218893Sdim unsigned &Idx); 1917212795Sdim 1918212795Sdim /// \brief Read a template argument. 1919234353Sdim TemplateArgument ReadTemplateArgument(ModuleFile &F, 1920212795Sdim const RecordData &Record,unsigned &Idx); 1921234353Sdim 1922212795Sdim /// \brief Read a template parameter list. 1923234353Sdim TemplateParameterList *ReadTemplateParameterList(ModuleFile &F, 1924218893Sdim const RecordData &Record, 1925212795Sdim unsigned &Idx); 1926234353Sdim 1927212795Sdim /// \brief Read a template argument array. 1928212795Sdim void 1929261991Sdim ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs, 1930234353Sdim ModuleFile &F, const RecordData &Record, 1931218893Sdim unsigned &Idx); 1932212795Sdim 1933212795Sdim /// \brief Read a UnresolvedSet structure. 1934261991Sdim void ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set, 1935212795Sdim const RecordData &Record, unsigned &Idx); 1936212795Sdim 1937212795Sdim /// \brief Read a C++ base specifier. 1938234353Sdim CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F, 1939212795Sdim const RecordData &Record,unsigned &Idx); 1940212795Sdim 1941218893Sdim /// \brief Read a CXXCtorInitializer array. 1942218893Sdim std::pair<CXXCtorInitializer **, unsigned> 1943234353Sdim ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, 1944218893Sdim unsigned &Idx); 1945212795Sdim 1946218893Sdim /// \brief Read a source location from raw form. 1947234353Sdim SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, unsigned Raw) const { 1948226633Sdim SourceLocation Loc = SourceLocation::getFromRawEncoding(Raw); 1949234353Sdim assert(ModuleFile.SLocRemap.find(Loc.getOffset()) != ModuleFile.SLocRemap.end() && 1950226633Sdim "Cannot find offset to remap."); 1951234353Sdim int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second; 1952226633Sdim return Loc.getLocWithOffset(Remap); 1953218893Sdim } 1954218893Sdim 1955212795Sdim /// \brief Read a source location. 1956234353Sdim SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, 1957261991Sdim const RecordDataImpl &Record, 1958261991Sdim unsigned &Idx) { 1959234353Sdim return ReadSourceLocation(ModuleFile, Record[Idx++]); 1960212795Sdim } 1961212795Sdim 1962212795Sdim /// \brief Read a source range. 1963234353Sdim SourceRange ReadSourceRange(ModuleFile &F, 1964249423Sdim const RecordData &Record, unsigned &Idx); 1965212795Sdim 1966212795Sdim /// \brief Read an integral value 1967212795Sdim llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx); 1968212795Sdim 1969212795Sdim /// \brief Read a signed integral value 1970212795Sdim llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx); 1971212795Sdim 1972212795Sdim /// \brief Read a floating-point value 1973249423Sdim llvm::APFloat ReadAPFloat(const RecordData &Record, 1974249423Sdim const llvm::fltSemantics &Sem, unsigned &Idx); 1975212795Sdim 1976212795Sdim // \brief Read a string 1977243830Sdim static std::string ReadString(const RecordData &Record, unsigned &Idx); 1978212795Sdim 1979221345Sdim /// \brief Read a version tuple. 1980243830Sdim static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx); 1981221345Sdim 1982234353Sdim CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record, 1983226633Sdim unsigned &Idx); 1984234353Sdim 1985212795Sdim /// \brief Reads attributes from the current stream position. 1986234353Sdim void ReadAttributes(ModuleFile &F, AttrVec &Attrs, 1987218893Sdim const RecordData &Record, unsigned &Idx); 1988212795Sdim 1989212795Sdim /// \brief Reads a statement. 1990234353Sdim Stmt *ReadStmt(ModuleFile &F); 1991212795Sdim 1992212795Sdim /// \brief Reads an expression. 1993234353Sdim Expr *ReadExpr(ModuleFile &F); 1994212795Sdim 1995212795Sdim /// \brief Reads a sub-statement operand during statement reading. 1996212795Sdim Stmt *ReadSubStmt() { 1997212795Sdim assert(ReadingKind == Read_Stmt && 1998212795Sdim "Should be called only during statement reading!"); 1999212795Sdim // Subexpressions are stored from last to first, so the next Stmt we need 2000212795Sdim // is at the back of the stack. 2001276479Sdim assert(!StmtStack.empty() && "Read too many sub-statements!"); 2002212795Sdim return StmtStack.pop_back_val(); 2003212795Sdim } 2004212795Sdim 2005212795Sdim /// \brief Reads a sub-expression operand during statement reading. 2006212795Sdim Expr *ReadSubExpr(); 2007212795Sdim 2008251662Sdim /// \brief Reads a token out of a record. 2009261991Sdim Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx); 2010251662Sdim 2011212795Sdim /// \brief Reads the macro record located at the given offset. 2012249423Sdim MacroInfo *ReadMacroRecord(ModuleFile &F, uint64_t Offset); 2013234353Sdim 2014226633Sdim /// \brief Determine the global preprocessed entity ID that corresponds to 2015226633Sdim /// the given local ID within the given module. 2016234353Sdim serialization::PreprocessedEntityID 2017234353Sdim getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const; 2018234353Sdim 2019249423Sdim /// \brief Add a macro to resolve imported from a module. 2020234353Sdim /// 2021234353Sdim /// \param II The name of the macro. 2022249423Sdim /// \param M The module file. 2023249423Sdim /// \param GMacID The global macro ID that is associated with this identifier. 2024249423Sdim void addPendingMacroFromModule(IdentifierInfo *II, 2025249423Sdim ModuleFile *M, 2026249423Sdim serialization::GlobalMacroID GMacID, 2027276479Sdim ArrayRef<serialization::SubmoduleID>); 2028249423Sdim 2029249423Sdim /// \brief Add a macro to deserialize its macro directive history from a PCH. 2030234353Sdim /// 2031249423Sdim /// \param II The name of the macro. 2032249423Sdim /// \param M The module file. 2033249423Sdim /// \param MacroDirectivesOffset Offset of the serialized macro directive 2034249423Sdim /// history. 2035249423Sdim void addPendingMacroFromPCH(IdentifierInfo *II, 2036249423Sdim ModuleFile *M, uint64_t MacroDirectivesOffset); 2037234353Sdim 2038212795Sdim /// \brief Read the set of macros defined by this external macro source. 2039276479Sdim void ReadDefinedMacros() override; 2040212795Sdim 2041234353Sdim /// \brief Update an out-of-date identifier. 2042276479Sdim void updateOutOfDateIdentifier(IdentifierInfo &II) override; 2043234353Sdim 2044234353Sdim /// \brief Note that this identifier is up-to-date. 2045234353Sdim void markIdentifierUpToDate(IdentifierInfo *II); 2046234353Sdim 2047234353Sdim /// \brief Load all external visible decls in the given DeclContext. 2048276479Sdim void completeVisibleDeclsMap(const DeclContext *DC) override; 2049234353Sdim 2050212795Sdim /// \brief Retrieve the AST context that this AST reader supplements. 2051226633Sdim ASTContext &getContext() { return Context; } 2052212795Sdim 2053212795Sdim // \brief Contains declarations that were loaded before we have 2054212795Sdim // access to a Sema object. 2055226633Sdim SmallVector<NamedDecl *, 16> PreloadedDecls; 2056212795Sdim 2057212795Sdim /// \brief Retrieve the semantic analysis object used to analyze the 2058212795Sdim /// translation unit in which the precompiled header is being 2059212795Sdim /// imported. 2060212795Sdim Sema *getSema() { return SemaObj; } 2061212795Sdim 2062212795Sdim /// \brief Retrieve the identifier table associated with the 2063212795Sdim /// preprocessor. 2064212795Sdim IdentifierTable &getIdentifierTable(); 2065212795Sdim 2066212795Sdim /// \brief Record that the given ID maps to the given switch-case 2067212795Sdim /// statement. 2068212795Sdim void RecordSwitchCaseID(SwitchCase *SC, unsigned ID); 2069212795Sdim 2070212795Sdim /// \brief Retrieve the switch-case statement with the given ID. 2071212795Sdim SwitchCase *getSwitchCaseWithID(unsigned ID); 2072212795Sdim 2073218893Sdim void ClearSwitchCaseIDs(); 2074239462Sdim 2075239462Sdim /// \brief Cursors for comments blocks. 2076239462Sdim SmallVector<std::pair<llvm::BitstreamCursor, 2077239462Sdim serialization::ModuleFile *>, 8> CommentsCursors; 2078239462Sdim 2079276479Sdim //RIDErief Loads comments ranges. 2080276479Sdim void ReadComments() override; 2081212795Sdim}; 2082212795Sdim 2083212795Sdim/// \brief Helper class that saves the current stream position and 2084212795Sdim/// then restores it when destroyed. 2085212795Sdimstruct SavedStreamPosition { 2086212795Sdim explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor) 2087249423Sdim : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) { } 2088212795Sdim 2089212795Sdim ~SavedStreamPosition() { 2090212795Sdim Cursor.JumpToBit(Offset); 2091212795Sdim } 2092212795Sdim 2093212795Sdimprivate: 2094212795Sdim llvm::BitstreamCursor &Cursor; 2095212795Sdim uint64_t Offset; 2096212795Sdim}; 2097212795Sdim 2098212795Sdiminline void PCHValidator::Error(const char *Msg) { 2099212795Sdim Reader.Error(Msg); 2100212795Sdim} 2101212795Sdim 2102212795Sdim} // end namespace clang 2103212795Sdim 2104212795Sdim#endif 2105