ASTReader.h revision 296417
1212795Sdim//===--- ASTReader.h - AST File Reader --------------------------*- C++ -*-===// 2212795Sdim// 3212795Sdim// The LLVM Compiler Infrastructure 4212795Sdim// 5212795Sdim// This file is distributed under the University of Illinois Open Source 6212795Sdim// License. See LICENSE.TXT for details. 7212795Sdim// 8212795Sdim//===----------------------------------------------------------------------===// 9212795Sdim// 10212795Sdim// This file defines the ASTReader class, which reads AST files. 11212795Sdim// 12212795Sdim//===----------------------------------------------------------------------===// 13212795Sdim 14280031Sdim#ifndef LLVM_CLANG_SERIALIZATION_ASTREADER_H 15280031Sdim#define LLVM_CLANG_SERIALIZATION_ASTREADER_H 16212795Sdim 17249423Sdim#include "clang/AST/DeclObjC.h" 18212795Sdim#include "clang/AST/DeclarationName.h" 19212795Sdim#include "clang/AST/TemplateBase.h" 20212795Sdim#include "clang/Basic/Diagnostic.h" 21226633Sdim#include "clang/Basic/FileManager.h" 22226633Sdim#include "clang/Basic/FileSystemOptions.h" 23212795Sdim#include "clang/Basic/IdentifierTable.h" 24212795Sdim#include "clang/Basic/SourceManager.h" 25249423Sdim#include "clang/Basic/Version.h" 26249423Sdim#include "clang/Lex/ExternalPreprocessorSource.h" 27249423Sdim#include "clang/Lex/HeaderSearch.h" 28249423Sdim#include "clang/Lex/PreprocessingRecord.h" 29249423Sdim#include "clang/Sema/ExternalSemaSource.h" 30249423Sdim#include "clang/Serialization/ASTBitCodes.h" 31249423Sdim#include "clang/Serialization/ContinuousRangeMap.h" 32249423Sdim#include "clang/Serialization/Module.h" 33296417Sdim#include "clang/Serialization/ModuleFileExtension.h" 34249423Sdim#include "clang/Serialization/ModuleManager.h" 35212795Sdim#include "llvm/ADT/APFloat.h" 36212795Sdim#include "llvm/ADT/APInt.h" 37212795Sdim#include "llvm/ADT/APSInt.h" 38243830Sdim#include "llvm/ADT/MapVector.h" 39234353Sdim#include "llvm/ADT/SmallPtrSet.h" 40234353Sdim#include "llvm/ADT/SmallSet.h" 41212795Sdim#include "llvm/ADT/SmallVector.h" 42296417Sdim#include "llvm/ADT/StringMap.h" 43212795Sdim#include "llvm/ADT/StringRef.h" 44276479Sdim#include "llvm/ADT/TinyPtrVector.h" 45212795Sdim#include "llvm/Bitcode/BitstreamReader.h" 46218893Sdim#include "llvm/Support/DataTypes.h" 47288943Sdim#include "llvm/Support/Timer.h" 48212795Sdim#include <deque> 49212795Sdim#include <map> 50276479Sdim#include <memory> 51212795Sdim#include <string> 52212795Sdim#include <utility> 53212795Sdim#include <vector> 54212795Sdim 55212795Sdimnamespace llvm { 56212795Sdim class MemoryBuffer; 57212795Sdim} 58212795Sdim 59212795Sdimnamespace clang { 60212795Sdim 61212795Sdimclass AddrLabelExpr; 62212795Sdimclass ASTConsumer; 63212795Sdimclass ASTContext; 64218893Sdimclass ASTIdentifierIterator; 65226633Sdimclass ASTUnit; // FIXME: Layering violation and egregious hack. 66212795Sdimclass Attr; 67212795Sdimclass Decl; 68212795Sdimclass DeclContext; 69276479Sdimclass DefMacroDirective; 70243830Sdimclass DiagnosticOptions; 71212795Sdimclass NestedNameSpecifier; 72212795Sdimclass CXXBaseSpecifier; 73223017Sdimclass CXXConstructorDecl; 74218893Sdimclass CXXCtorInitializer; 75249423Sdimclass GlobalModuleIndex; 76212795Sdimclass GotoStmt; 77212795Sdimclass MacroDefinition; 78249423Sdimclass MacroDirective; 79288943Sdimclass ModuleMacro; 80212795Sdimclass NamedDecl; 81218893Sdimclass OpaqueValueExpr; 82212795Sdimclass Preprocessor; 83243830Sdimclass PreprocessorOptions; 84212795Sdimclass Sema; 85212795Sdimclass SwitchCase; 86218893Sdimclass ASTDeserializationListener; 87226633Sdimclass ASTWriter; 88212795Sdimclass ASTReader; 89212795Sdimclass ASTDeclReader; 90218893Sdimclass ASTStmtReader; 91218893Sdimclass TypeLocReader; 92212795Sdimstruct HeaderFileInfo; 93221345Sdimclass VersionTuple; 94243830Sdimclass TargetOptions; 95261991Sdimclass LazyASTUnresolvedSet; 96212795Sdim 97212795Sdim/// \brief Abstract interface for callback invocations by the ASTReader. 98212795Sdim/// 99212795Sdim/// While reading an AST file, the ASTReader will call the methods of the 100212795Sdim/// listener to pass on specific information. Some of the listener methods can 101212795Sdim/// return true to indicate to the ASTReader that the information (and 102212795Sdim/// consequently the AST file) is invalid. 103212795Sdimclass ASTReaderListener { 104212795Sdimpublic: 105212795Sdim virtual ~ASTReaderListener(); 106212795Sdim 107249423Sdim /// \brief Receives the full Clang version information. 108249423Sdim /// 109249423Sdim /// \returns true to indicate that the version is invalid. Subclasses should 110249423Sdim /// generally defer to this implementation. 111249423Sdim virtual bool ReadFullVersionInformation(StringRef FullVersion) { 112249423Sdim return FullVersion != getClangFullRepositoryVersion(); 113249423Sdim } 114249423Sdim 115276479Sdim virtual void ReadModuleName(StringRef ModuleName) {} 116276479Sdim virtual void ReadModuleMapFile(StringRef ModuleMapPath) {} 117276479Sdim 118212795Sdim /// \brief Receives the language options. 119212795Sdim /// 120212795Sdim /// \returns true to indicate the options are invalid or false otherwise. 121243830Sdim virtual bool ReadLanguageOptions(const LangOptions &LangOpts, 122280031Sdim bool Complain, 123280031Sdim bool AllowCompatibleDifferences) { 124212795Sdim return false; 125212795Sdim } 126212795Sdim 127243830Sdim /// \brief Receives the target options. 128212795Sdim /// 129243830Sdim /// \returns true to indicate the target options are invalid, or false 130243830Sdim /// otherwise. 131288943Sdim virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, 132288943Sdim bool AllowCompatibleDifferences) { 133212795Sdim return false; 134212795Sdim } 135212795Sdim 136243830Sdim /// \brief Receives the diagnostic options. 137212795Sdim /// 138243830Sdim /// \returns true to indicate the diagnostic options are invalid, or false 139243830Sdim /// otherwise. 140276479Sdim virtual bool 141276479Sdim ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, 142276479Sdim bool Complain) { 143243830Sdim return false; 144243830Sdim } 145243830Sdim 146243830Sdim /// \brief Receives the file system options. 147212795Sdim /// 148243830Sdim /// \returns true to indicate the file system options are invalid, or false 149243830Sdim /// otherwise. 150243830Sdim virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts, 151243830Sdim bool Complain) { 152243830Sdim return false; 153243830Sdim } 154243830Sdim 155243830Sdim /// \brief Receives the header search options. 156212795Sdim /// 157243830Sdim /// \returns true to indicate the header search options are invalid, or false 158243830Sdim /// otherwise. 159243830Sdim virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, 160288943Sdim StringRef SpecificModuleCachePath, 161243830Sdim bool Complain) { 162243830Sdim return false; 163243830Sdim } 164243830Sdim 165243830Sdim /// \brief Receives the preprocessor options. 166212795Sdim /// 167243830Sdim /// \param SuggestedPredefines Can be filled in with the set of predefines 168243830Sdim /// that are suggested by the preprocessor options. Typically only used when 169243830Sdim /// loading a precompiled header. 170243830Sdim /// 171243830Sdim /// \returns true to indicate the preprocessor options are invalid, or false 172243830Sdim /// otherwise. 173243830Sdim virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, 174243830Sdim bool Complain, 175243830Sdim std::string &SuggestedPredefines) { 176212795Sdim return false; 177212795Sdim } 178212795Sdim 179212795Sdim /// \brief Receives __COUNTER__ value. 180243830Sdim virtual void ReadCounter(const serialization::ModuleFile &M, 181243830Sdim unsigned Value) {} 182251662Sdim 183276479Sdim /// This is called for each AST file loaded. 184296417Sdim virtual void visitModuleFile(StringRef Filename, 185296417Sdim serialization::ModuleKind Kind) {} 186276479Sdim 187251662Sdim /// \brief Returns true if this \c ASTReaderListener wants to receive the 188251662Sdim /// input files of the AST file via \c visitInputFile, false otherwise. 189251662Sdim virtual bool needsInputFileVisitation() { return false; } 190276479Sdim /// \brief Returns true if this \c ASTReaderListener wants to receive the 191276479Sdim /// system input files of the AST file via \c visitInputFile, false otherwise. 192276479Sdim virtual bool needsSystemInputFileVisitation() { return false; } 193276479Sdim /// \brief if \c needsInputFileVisitation returns true, this is called for 194276479Sdim /// each non-system input file of the AST File. If 195276479Sdim /// \c needsSystemInputFileVisitation is true, then it is called for all 196276479Sdim /// system input files as well. 197251662Sdim /// 198251662Sdim /// \returns true to continue receiving the next input file, false to stop. 199276479Sdim virtual bool visitInputFile(StringRef Filename, bool isSystem, 200296417Sdim bool isOverridden, bool isExplicitModule) { 201276479Sdim return true; 202276479Sdim } 203280031Sdim 204280031Sdim /// \brief Returns true if this \c ASTReaderListener wants to receive the 205280031Sdim /// imports of the AST file via \c visitImport, false otherwise. 206280031Sdim virtual bool needsImportVisitation() const { return false; } 207280031Sdim /// \brief If needsImportVisitation returns \c true, this is called for each 208280031Sdim /// AST file imported by this AST file. 209280031Sdim virtual void visitImport(StringRef Filename) {} 210296417Sdim 211296417Sdim /// Indicates that a particular module file extension has been read. 212296417Sdim virtual void readModuleFileExtension( 213296417Sdim const ModuleFileExtensionMetadata &Metadata) {} 214212795Sdim}; 215212795Sdim 216276479Sdim/// \brief Simple wrapper class for chaining listeners. 217276479Sdimclass ChainedASTReaderListener : public ASTReaderListener { 218276479Sdim std::unique_ptr<ASTReaderListener> First; 219276479Sdim std::unique_ptr<ASTReaderListener> Second; 220276479Sdim 221276479Sdimpublic: 222276479Sdim /// Takes ownership of \p First and \p Second. 223280031Sdim ChainedASTReaderListener(std::unique_ptr<ASTReaderListener> First, 224280031Sdim std::unique_ptr<ASTReaderListener> Second) 225280031Sdim : First(std::move(First)), Second(std::move(Second)) {} 226276479Sdim 227280031Sdim std::unique_ptr<ASTReaderListener> takeFirst() { return std::move(First); } 228280031Sdim std::unique_ptr<ASTReaderListener> takeSecond() { return std::move(Second); } 229280031Sdim 230276479Sdim bool ReadFullVersionInformation(StringRef FullVersion) override; 231276479Sdim void ReadModuleName(StringRef ModuleName) override; 232276479Sdim void ReadModuleMapFile(StringRef ModuleMapPath) override; 233280031Sdim bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, 234280031Sdim bool AllowCompatibleDifferences) override; 235288943Sdim bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, 236288943Sdim bool AllowCompatibleDifferences) override; 237276479Sdim bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, 238276479Sdim bool Complain) override; 239276479Sdim bool ReadFileSystemOptions(const FileSystemOptions &FSOpts, 240276479Sdim bool Complain) override; 241276479Sdim 242276479Sdim bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, 243288943Sdim StringRef SpecificModuleCachePath, 244276479Sdim bool Complain) override; 245276479Sdim bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, 246276479Sdim bool Complain, 247276479Sdim std::string &SuggestedPredefines) override; 248276479Sdim 249276479Sdim void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override; 250276479Sdim bool needsInputFileVisitation() override; 251276479Sdim bool needsSystemInputFileVisitation() override; 252296417Sdim void visitModuleFile(StringRef Filename, 253296417Sdim serialization::ModuleKind Kind) override; 254276479Sdim bool visitInputFile(StringRef Filename, bool isSystem, 255296417Sdim bool isOverridden, bool isExplicitModule) override; 256296417Sdim void readModuleFileExtension( 257296417Sdim const ModuleFileExtensionMetadata &Metadata) override; 258276479Sdim}; 259276479Sdim 260212795Sdim/// \brief ASTReaderListener implementation to validate the information of 261212795Sdim/// the PCH file against an initialized Preprocessor. 262212795Sdimclass PCHValidator : public ASTReaderListener { 263212795Sdim Preprocessor &PP; 264212795Sdim ASTReader &Reader; 265212795Sdim 266212795Sdimpublic: 267212795Sdim PCHValidator(Preprocessor &PP, ASTReader &Reader) 268261991Sdim : PP(PP), Reader(Reader) {} 269212795Sdim 270280031Sdim bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, 271280031Sdim bool AllowCompatibleDifferences) override; 272288943Sdim bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, 273288943Sdim bool AllowCompatibleDifferences) override; 274276479Sdim bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, 275276479Sdim bool Complain) override; 276276479Sdim bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain, 277276479Sdim std::string &SuggestedPredefines) override; 278288943Sdim bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, 279288943Sdim StringRef SpecificModuleCachePath, 280288943Sdim bool Complain) override; 281276479Sdim void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override; 282212795Sdim 283212795Sdimprivate: 284212795Sdim void Error(const char *Msg); 285212795Sdim}; 286212795Sdim 287234353Sdimnamespace serialization { 288226633Sdim 289226633Sdimclass ReadMethodPoolVisitor; 290234353Sdim 291226633Sdimnamespace reader { 292226633Sdim class ASTIdentifierLookupTrait; 293296417Sdim /// \brief The on-disk hash table(s) used for DeclContext name lookup. 294296417Sdim struct DeclContextLookupTable; 295226633Sdim} 296234353Sdim 297226633Sdim} // end namespace serialization 298234353Sdim 299212795Sdim/// \brief Reads an AST files chain containing the contents of a translation 300212795Sdim/// unit. 301212795Sdim/// 302212795Sdim/// The ASTReader class reads bitstreams (produced by the ASTWriter 303212795Sdim/// class) containing the serialized representation of a given 304212795Sdim/// abstract syntax tree and its supporting data structures. An 305212795Sdim/// instance of the ASTReader can be attached to an ASTContext object, 306212795Sdim/// which will provide access to the contents of the AST files. 307212795Sdim/// 308212795Sdim/// The AST reader provides lazy de-serialization of declarations, as 309212795Sdim/// required when traversing the AST. Only those AST nodes that are 310212795Sdim/// actually required will be de-serialized. 311212795Sdimclass ASTReader 312212795Sdim : public ExternalPreprocessorSource, 313212795Sdim public ExternalPreprocessingRecordSource, 314218893Sdim public ExternalHeaderFileInfoSource, 315212795Sdim public ExternalSemaSource, 316212795Sdim public IdentifierInfoLookup, 317234353Sdim public ExternalSLocEntrySource 318218893Sdim{ 319212795Sdimpublic: 320239462Sdim typedef SmallVector<uint64_t, 64> RecordData; 321261991Sdim typedef SmallVectorImpl<uint64_t> RecordDataImpl; 322239462Sdim 323243830Sdim /// \brief The result of reading the control block of an AST file, which 324243830Sdim /// can fail for various reasons. 325243830Sdim enum ASTReadResult { 326243830Sdim /// \brief The control block was read successfully. Aside from failures, 327243830Sdim /// the AST file is safe to read into the current context. 328243830Sdim Success, 329243830Sdim /// \brief The AST file itself appears corrupted. 330243830Sdim Failure, 331249423Sdim /// \brief The AST file was missing. 332249423Sdim Missing, 333243830Sdim /// \brief The AST file is out-of-date relative to its input files, 334243830Sdim /// and needs to be regenerated. 335243830Sdim OutOfDate, 336243830Sdim /// \brief The AST file was written by a different version of Clang. 337243830Sdim VersionMismatch, 338243830Sdim /// \brief The AST file was writtten with a different language/target 339243830Sdim /// configuration. 340243830Sdim ConfigurationMismatch, 341243830Sdim /// \brief The AST file has errors. 342243830Sdim HadErrors 343243830Sdim }; 344243830Sdim 345218893Sdim /// \brief Types of AST files. 346212795Sdim friend class PCHValidator; 347212795Sdim friend class ASTDeclReader; 348218893Sdim friend class ASTStmtReader; 349218893Sdim friend class ASTIdentifierIterator; 350226633Sdim friend class serialization::reader::ASTIdentifierLookupTrait; 351218893Sdim friend class TypeLocReader; 352226633Sdim friend class ASTWriter; 353226633Sdim friend class ASTUnit; // ASTUnit needs to remap source locations. 354226633Sdim friend class serialization::ReadMethodPoolVisitor; 355234353Sdim 356234353Sdim typedef serialization::ModuleFile ModuleFile; 357226633Sdim typedef serialization::ModuleKind ModuleKind; 358226633Sdim typedef serialization::ModuleManager ModuleManager; 359234353Sdim 360226633Sdim typedef ModuleManager::ModuleIterator ModuleIterator; 361226633Sdim typedef ModuleManager::ModuleConstIterator ModuleConstIterator; 362226633Sdim typedef ModuleManager::ModuleReverseIterator ModuleReverseIterator; 363226633Sdim 364212795Sdimprivate: 365212795Sdim /// \brief The receiver of some callbacks invoked by ASTReader. 366276479Sdim std::unique_ptr<ASTReaderListener> Listener; 367212795Sdim 368212795Sdim /// \brief The receiver of deserialization events. 369212795Sdim ASTDeserializationListener *DeserializationListener; 370276479Sdim bool OwnsDeserializationListener; 371212795Sdim 372212795Sdim SourceManager &SourceMgr; 373212795Sdim FileManager &FileMgr; 374288943Sdim const PCHContainerReader &PCHContainerRdr; 375226633Sdim DiagnosticsEngine &Diags; 376234353Sdim 377212795Sdim /// \brief The semantic analysis object that will be processing the 378212795Sdim /// AST files and the translation unit that uses it. 379212795Sdim Sema *SemaObj; 380212795Sdim 381212795Sdim /// \brief The preprocessor that will be loading the source file. 382226633Sdim Preprocessor &PP; 383212795Sdim 384212795Sdim /// \brief The AST context into which we'll read the AST files. 385226633Sdim ASTContext &Context; 386234353Sdim 387212795Sdim /// \brief The AST consumer. 388212795Sdim ASTConsumer *Consumer; 389212795Sdim 390226633Sdim /// \brief The module manager which manages modules and their dependencies 391226633Sdim ModuleManager ModuleMgr; 392221345Sdim 393296417Sdim /// A mapping from extension block names to module file extensions. 394296417Sdim llvm::StringMap<IntrusiveRefCntPtr<ModuleFileExtension>> ModuleFileExtensions; 395296417Sdim 396288943Sdim /// \brief A timer used to track the time spent deserializing. 397288943Sdim std::unique_ptr<llvm::Timer> ReadTimer; 398288943Sdim 399261991Sdim /// \brief The location where the module file will be considered as 400261991Sdim /// imported from. For non-module AST types it should be invalid. 401261991Sdim SourceLocation CurrentImportLoc; 402261991Sdim 403249423Sdim /// \brief The global module index, if loaded. 404276479Sdim std::unique_ptr<GlobalModuleIndex> GlobalIndex; 405249423Sdim 406226633Sdim /// \brief A map of global bit offsets to the module that stores entities 407226633Sdim /// at those bit offsets. 408234353Sdim ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap; 409212795Sdim 410226633Sdim /// \brief A map of negated SLocEntryIDs to the modules containing them. 411234353Sdim ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap; 412212795Sdim 413234353Sdim typedef ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocOffsetMapType; 414234353Sdim 415226633Sdim /// \brief A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset) 416226633Sdim /// SourceLocation offsets to the modules containing them. 417226633Sdim GlobalSLocOffsetMapType GlobalSLocOffsetMap; 418234353Sdim 419212795Sdim /// \brief Types that have already been loaded from the chain. 420212795Sdim /// 421212795Sdim /// When the pointer at index I is non-NULL, the type with 422212795Sdim /// ID = (I + 1) << FastQual::Width has already been loaded 423212795Sdim std::vector<QualType> TypesLoaded; 424212795Sdim 425234353Sdim typedef ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4> 426226633Sdim GlobalTypeMapType; 427212795Sdim 428226633Sdim /// \brief Mapping from global type IDs to the module in which the 429226633Sdim /// type resides along with the offset that should be added to the 430226633Sdim /// global type ID to produce a local ID. 431226633Sdim GlobalTypeMapType GlobalTypeMap; 432226633Sdim 433212795Sdim /// \brief Declarations that have already been loaded from the chain. 434212795Sdim /// 435212795Sdim /// When the pointer at index I is non-NULL, the declaration with ID 436212795Sdim /// = I + 1 has already been loaded. 437212795Sdim std::vector<Decl *> DeclsLoaded; 438212795Sdim 439234353Sdim typedef ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4> 440226633Sdim GlobalDeclMapType; 441234353Sdim 442226633Sdim /// \brief Mapping from global declaration IDs to the module in which the 443226633Sdim /// declaration resides. 444226633Sdim GlobalDeclMapType GlobalDeclMap; 445234353Sdim 446234353Sdim typedef std::pair<ModuleFile *, uint64_t> FileOffset; 447226633Sdim typedef SmallVector<FileOffset, 2> FileOffsetsTy; 448218893Sdim typedef llvm::DenseMap<serialization::DeclID, FileOffsetsTy> 449218893Sdim DeclUpdateOffsetsMap; 450234353Sdim 451218893Sdim /// \brief Declarations that have modifications residing in a later file 452218893Sdim /// in the chain. 453218893Sdim DeclUpdateOffsetsMap DeclUpdateOffsets; 454218893Sdim 455276479Sdim /// \brief Declaration updates for already-loaded declarations that we need 456276479Sdim /// to apply once we finish processing an import. 457276479Sdim llvm::SmallVector<std::pair<serialization::GlobalDeclID, Decl*>, 16> 458276479Sdim PendingUpdateRecords; 459276479Sdim 460288943Sdim enum class PendingFakeDefinitionKind { NotFake, Fake, FakeLoaded }; 461288943Sdim 462288943Sdim /// \brief The DefinitionData pointers that we faked up for class definitions 463288943Sdim /// that we needed but hadn't loaded yet. 464288943Sdim llvm::DenseMap<void *, PendingFakeDefinitionKind> PendingFakeDefinitionData; 465288943Sdim 466288943Sdim /// \brief Exception specification updates that have been loaded but not yet 467288943Sdim /// propagated across the relevant redeclaration chain. The map key is the 468288943Sdim /// canonical declaration (used only for deduplication) and the value is a 469288943Sdim /// declaration that has an exception specification. 470288943Sdim llvm::SmallMapVector<Decl *, FunctionDecl *, 4> PendingExceptionSpecUpdates; 471288943Sdim 472234353Sdim struct ReplacedDeclInfo { 473234353Sdim ModuleFile *Mod; 474234353Sdim uint64_t Offset; 475234353Sdim unsigned RawLoc; 476234353Sdim 477276479Sdim ReplacedDeclInfo() : Mod(nullptr), Offset(0), RawLoc(0) {} 478234353Sdim ReplacedDeclInfo(ModuleFile *Mod, uint64_t Offset, unsigned RawLoc) 479234353Sdim : Mod(Mod), Offset(Offset), RawLoc(RawLoc) {} 480234353Sdim }; 481234353Sdim 482234353Sdim typedef llvm::DenseMap<serialization::DeclID, ReplacedDeclInfo> 483212795Sdim DeclReplacementMap; 484212795Sdim /// \brief Declarations that have been replaced in a later file in the chain. 485212795Sdim DeclReplacementMap ReplacedDecls; 486212795Sdim 487280031Sdim /// \brief Declarations that have been imported and have typedef names for 488280031Sdim /// linkage purposes. 489280031Sdim llvm::DenseMap<std::pair<DeclContext*, IdentifierInfo*>, NamedDecl*> 490280031Sdim ImportedTypedefNamesForLinkage; 491280031Sdim 492280031Sdim /// \brief Mergeable declaration contexts that have anonymous declarations 493280031Sdim /// within them, and those anonymous declarations. 494280031Sdim llvm::DenseMap<DeclContext*, llvm::SmallVector<NamedDecl*, 2>> 495280031Sdim AnonymousDeclarationsForMerging; 496280031Sdim 497234353Sdim struct FileDeclsInfo { 498234353Sdim ModuleFile *Mod; 499234353Sdim ArrayRef<serialization::LocalDeclID> Decls; 500234353Sdim 501276479Sdim FileDeclsInfo() : Mod(nullptr) {} 502234353Sdim FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls) 503234353Sdim : Mod(Mod), Decls(Decls) {} 504234353Sdim }; 505234353Sdim 506234353Sdim /// \brief Map from a FileID to the file-level declarations that it contains. 507234353Sdim llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs; 508234353Sdim 509296417Sdim /// \brief An array of lexical contents of a declaration context, as a sequence of 510296417Sdim /// Decl::Kind, DeclID pairs. 511296417Sdim typedef ArrayRef<llvm::support::unaligned_uint32_t> LexicalContents; 512296417Sdim 513296417Sdim /// \brief Map from a DeclContext to its lexical contents. 514296417Sdim llvm::DenseMap<const DeclContext*, std::pair<ModuleFile*, LexicalContents>> 515296417Sdim LexicalDecls; 516296417Sdim 517296417Sdim /// \brief Map from the TU to its lexical contents from each module file. 518296417Sdim std::vector<std::pair<ModuleFile*, LexicalContents>> TULexicalDecls; 519296417Sdim 520296417Sdim /// \brief Map from a DeclContext to its lookup tables. 521296417Sdim llvm::DenseMap<const DeclContext *, 522296417Sdim serialization::reader::DeclContextLookupTable> Lookups; 523296417Sdim 524212795Sdim // Updates for visible decls can occur for other contexts than just the 525296417Sdim // TU, and when we read those update records, the actual context may not 526296417Sdim // be available yet, so have this pending map using the ID as a key. It 527296417Sdim // will be realized when the context is actually loaded. 528296417Sdim struct PendingVisibleUpdate { 529296417Sdim ModuleFile *Mod; 530296417Sdim const unsigned char *Data; 531296417Sdim }; 532296417Sdim typedef SmallVector<PendingVisibleUpdate, 1> DeclContextVisibleUpdates; 533212795Sdim 534212795Sdim /// \brief Updates to the visible declarations of declaration contexts that 535212795Sdim /// haven't been loaded yet. 536296417Sdim llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates> 537296417Sdim PendingVisibleUpdates; 538296417Sdim 539234353Sdim /// \brief The set of C++ or Objective-C classes that have forward 540234353Sdim /// declarations that have not yet been linked to their definitions. 541234353Sdim llvm::SmallPtrSet<Decl *, 4> PendingDefinitions; 542243830Sdim 543243830Sdim typedef llvm::MapVector<Decl *, uint64_t, 544243830Sdim llvm::SmallDenseMap<Decl *, unsigned, 4>, 545249423Sdim SmallVector<std::pair<Decl *, uint64_t>, 4> > 546243830Sdim PendingBodiesMap; 547243830Sdim 548243830Sdim /// \brief Functions or methods that have bodies that will be attached. 549243830Sdim PendingBodiesMap PendingBodies; 550243830Sdim 551288943Sdim /// \brief Definitions for which we have added merged definitions but not yet 552288943Sdim /// performed deduplication. 553288943Sdim llvm::SetVector<NamedDecl*> PendingMergedDefinitionsToDeduplicate; 554288943Sdim 555296417Sdim /// \brief Read the record that describes the lexical contents of a DC. 556296417Sdim bool ReadLexicalDeclContextStorage(ModuleFile &M, 557296417Sdim llvm::BitstreamCursor &Cursor, 558296417Sdim uint64_t Offset, DeclContext *DC); 559296417Sdim /// \brief Read the record that describes the visible contents of a DC. 560296417Sdim bool ReadVisibleDeclContextStorage(ModuleFile &M, 561296417Sdim llvm::BitstreamCursor &Cursor, 562296417Sdim uint64_t Offset, serialization::DeclID ID); 563212795Sdim 564212795Sdim /// \brief A vector containing identifiers that have already been 565212795Sdim /// loaded. 566212795Sdim /// 567212795Sdim /// If the pointer at index I is non-NULL, then it refers to the 568212795Sdim /// IdentifierInfo for the identifier with ID=I+1 that has already 569212795Sdim /// been loaded. 570212795Sdim std::vector<IdentifierInfo *> IdentifiersLoaded; 571212795Sdim 572234353Sdim typedef ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4> 573226633Sdim GlobalIdentifierMapType; 574234353Sdim 575243830Sdim /// \brief Mapping from global identifier IDs to the module in which the 576226633Sdim /// identifier resides along with the offset that should be added to the 577226633Sdim /// global identifier ID to produce a local ID. 578226633Sdim GlobalIdentifierMapType GlobalIdentifierMap; 579226633Sdim 580243830Sdim /// \brief A vector containing macros that have already been 581243830Sdim /// loaded. 582243830Sdim /// 583243830Sdim /// If the pointer at index I is non-NULL, then it refers to the 584243830Sdim /// MacroInfo for the identifier with ID=I+1 that has already 585243830Sdim /// been loaded. 586243830Sdim std::vector<MacroInfo *> MacrosLoaded; 587243830Sdim 588288943Sdim typedef std::pair<IdentifierInfo *, serialization::SubmoduleID> 589288943Sdim LoadedMacroInfo; 590288943Sdim 591288943Sdim /// \brief A set of #undef directives that we have loaded; used to 592288943Sdim /// deduplicate the same #undef information coming from multiple module 593288943Sdim /// files. 594288943Sdim llvm::DenseSet<LoadedMacroInfo> LoadedUndefs; 595288943Sdim 596243830Sdim typedef ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4> 597243830Sdim GlobalMacroMapType; 598243830Sdim 599243830Sdim /// \brief Mapping from global macro IDs to the module in which the 600243830Sdim /// macro resides along with the offset that should be added to the 601243830Sdim /// global macro ID to produce a local ID. 602243830Sdim GlobalMacroMapType GlobalMacroMap; 603243830Sdim 604234353Sdim /// \brief A vector containing submodules that have already been loaded. 605234353Sdim /// 606234353Sdim /// This vector is indexed by the Submodule ID (-1). NULL submodule entries 607234353Sdim /// indicate that the particular submodule ID has not yet been loaded. 608234353Sdim SmallVector<Module *, 2> SubmodulesLoaded; 609234353Sdim 610234353Sdim typedef ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4> 611234353Sdim GlobalSubmoduleMapType; 612234353Sdim 613234353Sdim /// \brief Mapping from global submodule IDs to the module file in which the 614234353Sdim /// submodule resides along with the offset that should be added to the 615234353Sdim /// global submodule ID to produce a local ID. 616234353Sdim GlobalSubmoduleMapType GlobalSubmoduleMap; 617234353Sdim 618234353Sdim /// \brief A set of hidden declarations. 619288943Sdim typedef SmallVector<Decl*, 2> HiddenNames; 620234353Sdim typedef llvm::DenseMap<Module *, HiddenNames> HiddenNamesMapType; 621234353Sdim 622234353Sdim /// \brief A mapping from each of the hidden submodules to the deserialized 623234353Sdim /// declarations in that submodule that could be made visible. 624234353Sdim HiddenNamesMapType HiddenNamesMap; 625234353Sdim 626234353Sdim 627249423Sdim /// \brief A module import, export, or conflict that hasn't yet been resolved. 628249423Sdim struct UnresolvedModuleRef { 629234353Sdim /// \brief The file in which this module resides. 630234353Sdim ModuleFile *File; 631234353Sdim 632234353Sdim /// \brief The module that is importing or exporting. 633234353Sdim Module *Mod; 634249423Sdim 635249423Sdim /// \brief The kind of module reference. 636249423Sdim enum { Import, Export, Conflict } Kind; 637249423Sdim 638234353Sdim /// \brief The local ID of the module that is being exported. 639234353Sdim unsigned ID; 640249423Sdim 641234353Sdim /// \brief Whether this is a wildcard export. 642234353Sdim unsigned IsWildcard : 1; 643249423Sdim 644249423Sdim /// \brief String data. 645249423Sdim StringRef String; 646234353Sdim }; 647234353Sdim 648234353Sdim /// \brief The set of module imports and exports that still need to be 649234353Sdim /// resolved. 650249423Sdim SmallVector<UnresolvedModuleRef, 2> UnresolvedModuleRefs; 651234353Sdim 652212795Sdim /// \brief A vector containing selectors that have already been loaded. 653212795Sdim /// 654212795Sdim /// This vector is indexed by the Selector ID (-1). NULL selector 655212795Sdim /// entries indicate that the particular selector ID has not yet 656212795Sdim /// been loaded. 657226633Sdim SmallVector<Selector, 16> SelectorsLoaded; 658212795Sdim 659234353Sdim typedef ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4> 660226633Sdim GlobalSelectorMapType; 661234353Sdim 662226633Sdim /// \brief Mapping from global selector IDs to the module in which the 663249423Sdim 664226633Sdim /// global selector ID to produce a local ID. 665226633Sdim GlobalSelectorMapType GlobalSelectorMap; 666212795Sdim 667234353Sdim /// \brief The generation number of the last time we loaded data from the 668234353Sdim /// global method pool for this selector. 669234353Sdim llvm::DenseMap<Selector, unsigned> SelectorGeneration; 670234353Sdim 671249423Sdim struct PendingMacroInfo { 672249423Sdim ModuleFile *M; 673288943Sdim uint64_t MacroDirectivesOffset; 674249423Sdim 675288943Sdim PendingMacroInfo(ModuleFile *M, uint64_t MacroDirectivesOffset) 676288943Sdim : M(M), MacroDirectivesOffset(MacroDirectivesOffset) {} 677249423Sdim }; 678249423Sdim 679249423Sdim typedef llvm::MapVector<IdentifierInfo *, SmallVector<PendingMacroInfo, 2> > 680243830Sdim PendingMacroIDsMap; 681226633Sdim 682243830Sdim /// \brief Mapping from identifiers that have a macro history to the global 683243830Sdim /// IDs have not yet been deserialized to the global IDs of those macros. 684243830Sdim PendingMacroIDsMap PendingMacroIDs; 685243830Sdim 686234353Sdim typedef ContinuousRangeMap<unsigned, ModuleFile *, 4> 687226633Sdim GlobalPreprocessedEntityMapType; 688234353Sdim 689226633Sdim /// \brief Mapping from global preprocessing entity IDs to the module in 690226633Sdim /// which the preprocessed entity resides along with the offset that should be 691226633Sdim /// added to the global preprocessing entitiy ID to produce a local ID. 692226633Sdim GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap; 693234353Sdim 694212795Sdim /// \name CodeGen-relevant special data 695212795Sdim /// \brief Fields containing data that is relevant to CodeGen. 696212795Sdim //@{ 697212795Sdim 698212795Sdim /// \brief The IDs of all declarations that fulfill the criteria of 699212795Sdim /// "interesting" decls. 700212795Sdim /// 701276479Sdim /// This contains the data loaded from all EAGERLY_DESERIALIZED_DECLS blocks 702276479Sdim /// in the chain. The referenced declarations are deserialized and passed to 703276479Sdim /// the consumer eagerly. 704276479Sdim SmallVector<uint64_t, 16> EagerlyDeserializedDecls; 705212795Sdim 706239462Sdim /// \brief The IDs of all tentative definitions stored in the chain. 707212795Sdim /// 708212795Sdim /// Sema keeps track of all tentative definitions in a TU because it has to 709212795Sdim /// complete them and pass them on to CodeGen. Thus, tentative definitions in 710212795Sdim /// the PCH chain must be eagerly deserialized. 711226633Sdim SmallVector<uint64_t, 16> TentativeDefinitions; 712212795Sdim 713212795Sdim /// \brief The IDs of all CXXRecordDecls stored in the chain whose VTables are 714212795Sdim /// used. 715212795Sdim /// 716212795Sdim /// CodeGen has to emit VTables for these records, so they have to be eagerly 717212795Sdim /// deserialized. 718226633Sdim SmallVector<uint64_t, 64> VTableUses; 719212795Sdim 720226633Sdim /// \brief A snapshot of the pending instantiations in the chain. 721226633Sdim /// 722226633Sdim /// This record tracks the instantiations that Sema has to perform at the 723226633Sdim /// end of the TU. It consists of a pair of values for every pending 724226633Sdim /// instantiation where the first value is the ID of the decl and the second 725226633Sdim /// is the instantiation location. 726226633Sdim SmallVector<uint64_t, 64> PendingInstantiations; 727226633Sdim 728212795Sdim //@} 729212795Sdim 730226633Sdim /// \name DiagnosticsEngine-relevant special data 731212795Sdim /// \brief Fields containing data that is used for generating diagnostics 732212795Sdim //@{ 733212795Sdim 734212795Sdim /// \brief A snapshot of Sema's unused file-scoped variable tracking, for 735212795Sdim /// generating warnings. 736226633Sdim SmallVector<uint64_t, 16> UnusedFileScopedDecls; 737212795Sdim 738223017Sdim /// \brief A list of all the delegating constructors we've seen, to diagnose 739223017Sdim /// cycles. 740226633Sdim SmallVector<uint64_t, 4> DelegatingCtorDecls; 741234353Sdim 742226633Sdim /// \brief Method selectors used in a @selector expression. Used for 743226633Sdim /// implementation of -Wselector. 744226633Sdim SmallVector<uint64_t, 64> ReferencedSelectorsData; 745223017Sdim 746212795Sdim /// \brief A snapshot of Sema's weak undeclared identifier tracking, for 747212795Sdim /// generating warnings. 748226633Sdim SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers; 749212795Sdim 750212795Sdim /// \brief The IDs of type aliases for ext_vectors that exist in the chain. 751212795Sdim /// 752212795Sdim /// Used by Sema for finding sugared names for ext_vectors in diagnostics. 753226633Sdim SmallVector<uint64_t, 4> ExtVectorDecls; 754212795Sdim 755212795Sdim //@} 756212795Sdim 757212795Sdim /// \name Sema-relevant special data 758212795Sdim /// \brief Fields containing data that is used for semantic analysis 759212795Sdim //@{ 760212795Sdim 761280031Sdim /// \brief The IDs of all potentially unused typedef names in the chain. 762280031Sdim /// 763280031Sdim /// Sema tracks these to emit warnings. 764280031Sdim SmallVector<uint64_t, 16> UnusedLocalTypedefNameCandidates; 765280031Sdim 766212795Sdim /// \brief The IDs of the declarations Sema stores directly. 767212795Sdim /// 768212795Sdim /// Sema tracks a few important decls, such as namespace std, directly. 769226633Sdim SmallVector<uint64_t, 4> SemaDeclRefs; 770212795Sdim 771212795Sdim /// \brief The IDs of the types ASTContext stores directly. 772212795Sdim /// 773212795Sdim /// The AST context tracks a few important types, such as va_list, directly. 774226633Sdim SmallVector<uint64_t, 16> SpecialTypes; 775212795Sdim 776218893Sdim /// \brief The IDs of CUDA-specific declarations ASTContext stores directly. 777218893Sdim /// 778218893Sdim /// The AST context tracks a few important decls, currently cudaConfigureCall, 779218893Sdim /// directly. 780226633Sdim SmallVector<uint64_t, 2> CUDASpecialDeclRefs; 781218893Sdim 782218893Sdim /// \brief The floating point pragma option settings. 783226633Sdim SmallVector<uint64_t, 1> FPPragmaOptions; 784218893Sdim 785276479Sdim /// \brief The pragma clang optimize location (if the pragma state is "off"). 786276479Sdim SourceLocation OptimizeOffPragmaLocation; 787276479Sdim 788218893Sdim /// \brief The OpenCL extension settings. 789226633Sdim SmallVector<uint64_t, 1> OpenCLExtensions; 790218893Sdim 791224145Sdim /// \brief A list of the namespaces we've seen. 792226633Sdim SmallVector<uint64_t, 4> KnownNamespaces; 793224145Sdim 794249423Sdim /// \brief A list of undefined decls with internal linkage followed by the 795249423Sdim /// SourceLocation of a matching ODR-use. 796249423Sdim SmallVector<uint64_t, 8> UndefinedButUsed; 797249423Sdim 798288943Sdim /// \brief Delete expressions to analyze at the end of translation unit. 799288943Sdim SmallVector<uint64_t, 8> DelayedDeleteExprs; 800288943Sdim 801261991Sdim // \brief A list of late parsed template function data. 802261991Sdim SmallVector<uint64_t, 1> LateParsedTemplates; 803261991Sdim 804276479Sdim struct ImportedSubmodule { 805276479Sdim serialization::SubmoduleID ID; 806276479Sdim SourceLocation ImportLoc; 807276479Sdim 808276479Sdim ImportedSubmodule(serialization::SubmoduleID ID, SourceLocation ImportLoc) 809276479Sdim : ID(ID), ImportLoc(ImportLoc) {} 810276479Sdim }; 811276479Sdim 812234353Sdim /// \brief A list of modules that were imported by precompiled headers or 813234353Sdim /// any other non-module AST file. 814276479Sdim SmallVector<ImportedSubmodule, 2> ImportedModules; 815212795Sdim //@} 816212795Sdim 817218893Sdim /// \brief The directory that the PCH we are reading is stored in. 818218893Sdim std::string CurrentDir; 819218893Sdim 820212795Sdim /// \brief The system include root to be used when loading the 821212795Sdim /// precompiled header. 822226633Sdim std::string isysroot; 823212795Sdim 824212795Sdim /// \brief Whether to disable the normal validation performed on precompiled 825212795Sdim /// headers when they are loaded. 826212795Sdim bool DisableValidation; 827234353Sdim 828234353Sdim /// \brief Whether to accept an AST file with compiler errors. 829234353Sdim bool AllowASTWithCompilerErrors; 830234353Sdim 831276479Sdim /// \brief Whether to accept an AST file that has a different configuration 832276479Sdim /// from the current compiler instance. 833276479Sdim bool AllowConfigurationMismatch; 834276479Sdim 835276479Sdim /// \brief Whether validate system input files. 836276479Sdim bool ValidateSystemInputs; 837276479Sdim 838249423Sdim /// \brief Whether we are allowed to use the global module index. 839249423Sdim bool UseGlobalIndex; 840249423Sdim 841249423Sdim /// \brief Whether we have tried loading the global module index yet. 842249423Sdim bool TriedLoadingGlobalIndex; 843249423Sdim 844239462Sdim typedef llvm::DenseMap<unsigned, SwitchCase *> SwitchCaseMapTy; 845212795Sdim /// \brief Mapping from switch-case IDs in the chain to switch-case statements 846212795Sdim /// 847212795Sdim /// Statements usually don't have IDs, but switch cases need them, so that the 848212795Sdim /// switch statement can refer to them. 849239462Sdim SwitchCaseMapTy SwitchCaseStmts; 850212795Sdim 851239462Sdim SwitchCaseMapTy *CurrSwitchCaseStmts; 852239462Sdim 853212795Sdim /// \brief The number of source location entries de-serialized from 854212795Sdim /// the PCH file. 855212795Sdim unsigned NumSLocEntriesRead; 856212795Sdim 857212795Sdim /// \brief The number of source location entries in the chain. 858212795Sdim unsigned TotalNumSLocEntries; 859212795Sdim 860212795Sdim /// \brief The number of statements (and expressions) de-serialized 861212795Sdim /// from the chain. 862212795Sdim unsigned NumStatementsRead; 863212795Sdim 864212795Sdim /// \brief The total number of statements (and expressions) stored 865212795Sdim /// in the chain. 866212795Sdim unsigned TotalNumStatements; 867212795Sdim 868212795Sdim /// \brief The number of macros de-serialized from the chain. 869212795Sdim unsigned NumMacrosRead; 870212795Sdim 871212795Sdim /// \brief The total number of macros stored in the chain. 872212795Sdim unsigned TotalNumMacros; 873212795Sdim 874249423Sdim /// \brief The number of lookups into identifier tables. 875249423Sdim unsigned NumIdentifierLookups; 876249423Sdim 877249423Sdim /// \brief The number of lookups into identifier tables that succeed. 878249423Sdim unsigned NumIdentifierLookupHits; 879249423Sdim 880212795Sdim /// \brief The number of selectors that have been read. 881212795Sdim unsigned NumSelectorsRead; 882212795Sdim 883212795Sdim /// \brief The number of method pool entries that have been read. 884212795Sdim unsigned NumMethodPoolEntriesRead; 885212795Sdim 886212795Sdim /// \brief The number of times we have looked up a selector in the method 887249423Sdim /// pool. 888249423Sdim unsigned NumMethodPoolLookups; 889212795Sdim 890249423Sdim /// \brief The number of times we have looked up a selector in the method 891249423Sdim /// pool and found something. 892249423Sdim unsigned NumMethodPoolHits; 893249423Sdim 894249423Sdim /// \brief The number of times we have looked up a selector in the method 895249423Sdim /// pool within a specific module. 896249423Sdim unsigned NumMethodPoolTableLookups; 897249423Sdim 898249423Sdim /// \brief The number of times we have looked up a selector in the method 899249423Sdim /// pool within a specific module and found something. 900249423Sdim unsigned NumMethodPoolTableHits; 901249423Sdim 902212795Sdim /// \brief The total number of method pool entries in the selector table. 903212795Sdim unsigned TotalNumMethodPoolEntries; 904212795Sdim 905212795Sdim /// Number of lexical decl contexts read/total. 906212795Sdim unsigned NumLexicalDeclContextsRead, TotalLexicalDeclContexts; 907212795Sdim 908212795Sdim /// Number of visible decl contexts read/total. 909212795Sdim unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts; 910234353Sdim 911226633Sdim /// Total size of modules, in bits, currently loaded 912226633Sdim uint64_t TotalModulesSizeInBits; 913226633Sdim 914212795Sdim /// \brief Number of Decl/types that are currently deserializing. 915212795Sdim unsigned NumCurrentElementsDeserializing; 916212795Sdim 917234353Sdim /// \brief Set true while we are in the process of passing deserialized 918234353Sdim /// "interesting" decls to consumer inside FinishedDeserializing(). 919234353Sdim /// This is used as a guard to avoid recursively repeating the process of 920234353Sdim /// passing decls to consumer. 921234353Sdim bool PassingDeclsToConsumer; 922234353Sdim 923212795Sdim /// \brief The set of identifiers that were read while the AST reader was 924212795Sdim /// (recursively) loading declarations. 925212795Sdim /// 926212795Sdim /// The declarations on the identifier chain for these identifiers will be 927212795Sdim /// loaded once the recursive loading has completed. 928249423Sdim llvm::MapVector<IdentifierInfo *, SmallVector<uint32_t, 4> > 929249423Sdim PendingIdentifierInfos; 930212795Sdim 931288943Sdim /// \brief The set of lookup results that we have faked in order to support 932288943Sdim /// merging of partially deserialized decls but that we have not yet removed. 933288943Sdim llvm::SmallMapVector<IdentifierInfo *, SmallVector<NamedDecl*, 2>, 16> 934288943Sdim PendingFakeLookupResults; 935288943Sdim 936234353Sdim /// \brief The generation number of each identifier, which keeps track of 937234353Sdim /// the last time we loaded information about this identifier. 938234353Sdim llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration; 939234353Sdim 940212795Sdim /// \brief Contains declarations and definitions that will be 941212795Sdim /// "interesting" to the ASTConsumer, when we get that AST consumer. 942212795Sdim /// 943212795Sdim /// "Interesting" declarations are those that have data that may 944212795Sdim /// need to be emitted, such as inline function definitions or 945212795Sdim /// Objective-C protocols. 946212795Sdim std::deque<Decl *> InterestingDecls; 947212795Sdim 948234353Sdim /// \brief The list of redeclaration chains that still need to be 949296417Sdim /// reconstructed, and the local offset to the corresponding list 950296417Sdim /// of redeclarations. 951296417Sdim SmallVector<std::pair<Decl *, uint64_t>, 16> PendingDeclChains; 952218893Sdim 953276479Sdim /// \brief The list of canonical declarations whose redeclaration chains 954276479Sdim /// need to be marked as incomplete once we're done deserializing things. 955276479Sdim SmallVector<Decl *, 16> PendingIncompleteDeclChains; 956276479Sdim 957249423Sdim /// \brief The Decl IDs for the Sema/Lexical DeclContext of a Decl that has 958249423Sdim /// been loaded but its DeclContext was not set yet. 959249423Sdim struct PendingDeclContextInfo { 960249423Sdim Decl *D; 961249423Sdim serialization::GlobalDeclID SemaDC; 962249423Sdim serialization::GlobalDeclID LexicalDC; 963249423Sdim }; 964249423Sdim 965249423Sdim /// \brief The set of Decls that have been loaded but their DeclContexts are 966249423Sdim /// not set yet. 967249423Sdim /// 968249423Sdim /// The DeclContexts for these Decls will be set once recursive loading has 969249423Sdim /// been completed. 970249423Sdim std::deque<PendingDeclContextInfo> PendingDeclContextInfos; 971249423Sdim 972261991Sdim /// \brief The set of NamedDecls that have been loaded, but are members of a 973261991Sdim /// context that has been merged into another context where the corresponding 974261991Sdim /// declaration is either missing or has not yet been loaded. 975261991Sdim /// 976261991Sdim /// We will check whether the corresponding declaration is in fact missing 977261991Sdim /// once recursing loading has been completed. 978261991Sdim llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks; 979261991Sdim 980276479Sdim /// \brief Record definitions in which we found an ODR violation. 981276479Sdim llvm::SmallDenseMap<CXXRecordDecl *, llvm::TinyPtrVector<CXXRecordDecl *>, 2> 982276479Sdim PendingOdrMergeFailures; 983276479Sdim 984276479Sdim /// \brief DeclContexts in which we have diagnosed an ODR violation. 985276479Sdim llvm::SmallPtrSet<DeclContext*, 2> DiagnosedOdrMergeFailures; 986276479Sdim 987234353Sdim /// \brief The set of Objective-C categories that have been deserialized 988234353Sdim /// since the last time the declaration chains were linked. 989234353Sdim llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized; 990234353Sdim 991234353Sdim /// \brief The set of Objective-C class definitions that have already been 992234353Sdim /// loaded, for which we will need to check for categories whenever a new 993234353Sdim /// module is loaded. 994249423Sdim SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded; 995276479Sdim 996249423Sdim typedef llvm::DenseMap<Decl *, SmallVector<serialization::DeclID, 2> > 997288943Sdim KeyDeclsMap; 998234353Sdim 999288943Sdim /// \brief A mapping from canonical declarations to the set of global 1000288943Sdim /// declaration IDs for key declaration that have been merged with that 1001288943Sdim /// canonical declaration. A key declaration is a formerly-canonical 1002288943Sdim /// declaration whose module did not import any other key declaration for that 1003288943Sdim /// entity. These are the IDs that we use as keys when finding redecl chains. 1004288943Sdim KeyDeclsMap KeyDecls; 1005234353Sdim 1006261991Sdim /// \brief A mapping from DeclContexts to the semantic DeclContext that we 1007261991Sdim /// are treating as the definition of the entity. This is used, for instance, 1008261991Sdim /// when merging implicit instantiations of class templates across modules. 1009261991Sdim llvm::DenseMap<DeclContext *, DeclContext *> MergedDeclContexts; 1010261991Sdim 1011261991Sdim /// \brief A mapping from canonical declarations of enums to their canonical 1012261991Sdim /// definitions. Only populated when using modules in C++. 1013261991Sdim llvm::DenseMap<EnumDecl *, EnumDecl *> EnumDefinitions; 1014261991Sdim 1015212795Sdim /// \brief When reading a Stmt tree, Stmt operands are placed in this stack. 1016226633Sdim SmallVector<Stmt *, 16> StmtStack; 1017212795Sdim 1018212795Sdim /// \brief What kind of records we are reading. 1019212795Sdim enum ReadingKind { 1020261991Sdim Read_None, Read_Decl, Read_Type, Read_Stmt 1021212795Sdim }; 1022212795Sdim 1023234353Sdim /// \brief What kind of records we are reading. 1024212795Sdim ReadingKind ReadingKind; 1025212795Sdim 1026212795Sdim /// \brief RAII object to change the reading kind. 1027212795Sdim class ReadingKindTracker { 1028212795Sdim ASTReader &Reader; 1029212795Sdim enum ReadingKind PrevKind; 1030212795Sdim 1031288943Sdim ReadingKindTracker(const ReadingKindTracker &) = delete; 1032288943Sdim void operator=(const ReadingKindTracker &) = delete; 1033212795Sdim 1034212795Sdim public: 1035212795Sdim ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader) 1036212795Sdim : Reader(reader), PrevKind(Reader.ReadingKind) { 1037212795Sdim Reader.ReadingKind = newKind; 1038212795Sdim } 1039212795Sdim 1040212795Sdim ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; } 1041212795Sdim }; 1042212795Sdim 1043212795Sdim /// \brief Suggested contents of the predefines buffer, after this 1044212795Sdim /// PCH file has been processed. 1045212795Sdim /// 1046212795Sdim /// In most cases, this string will be empty, because the predefines 1047212795Sdim /// buffer computed to build the PCH file will be identical to the 1048212795Sdim /// predefines buffer computed from the command line. However, when 1049212795Sdim /// there are differences that the PCH reader can work around, this 1050212795Sdim /// predefines buffer may contain additional definitions. 1051212795Sdim std::string SuggestedPredefines; 1052212795Sdim 1053212795Sdim /// \brief Reads a statement from the specified cursor. 1054234353Sdim Stmt *ReadStmtFromStream(ModuleFile &F); 1055212795Sdim 1056276479Sdim struct InputFileInfo { 1057276479Sdim std::string Filename; 1058276479Sdim off_t StoredSize; 1059276479Sdim time_t StoredTime; 1060276479Sdim bool Overridden; 1061296417Sdim bool Transient; 1062276479Sdim }; 1063276479Sdim 1064276479Sdim /// \brief Reads the stored information about an input file. 1065276479Sdim InputFileInfo readInputFileInfo(ModuleFile &F, unsigned ID); 1066276479Sdim 1067243830Sdim /// \brief Retrieve the file entry and 'overridden' bit for an input 1068243830Sdim /// file in the given module file. 1069249423Sdim serialization::InputFile getInputFile(ModuleFile &F, unsigned ID, 1070249423Sdim bool Complain = true); 1071243830Sdim 1072280031Sdimpublic: 1073280031Sdim void ResolveImportedPath(ModuleFile &M, std::string &Filename); 1074280031Sdim static void ResolveImportedPath(std::string &Filename, StringRef Prefix); 1075223017Sdim 1076288943Sdim /// \brief Returns the first key declaration for the given declaration. This 1077288943Sdim /// is one that is formerly-canonical (or still canonical) and whose module 1078288943Sdim /// did not import any other key declaration of the entity. 1079288943Sdim Decl *getKeyDeclaration(Decl *D) { 1080288943Sdim D = D->getCanonicalDecl(); 1081288943Sdim if (D->isFromASTFile()) 1082288943Sdim return D; 1083288943Sdim 1084288943Sdim auto I = KeyDecls.find(D); 1085288943Sdim if (I == KeyDecls.end() || I->second.empty()) 1086288943Sdim return D; 1087288943Sdim return GetExistingDecl(I->second[0]); 1088288943Sdim } 1089288943Sdim const Decl *getKeyDeclaration(const Decl *D) { 1090288943Sdim return getKeyDeclaration(const_cast<Decl*>(D)); 1091288943Sdim } 1092288943Sdim 1093288943Sdim /// \brief Run a callback on each imported key declaration of \p D. 1094288943Sdim template <typename Fn> 1095288943Sdim void forEachImportedKeyDecl(const Decl *D, Fn Visit) { 1096288943Sdim D = D->getCanonicalDecl(); 1097288943Sdim if (D->isFromASTFile()) 1098288943Sdim Visit(D); 1099288943Sdim 1100288943Sdim auto It = KeyDecls.find(const_cast<Decl*>(D)); 1101288943Sdim if (It != KeyDecls.end()) 1102288943Sdim for (auto ID : It->second) 1103288943Sdim Visit(GetExistingDecl(ID)); 1104288943Sdim } 1105288943Sdim 1106296417Sdim /// \brief Get the loaded lookup tables for \p Primary, if any. 1107296417Sdim const serialization::reader::DeclContextLookupTable * 1108296417Sdim getLoadedLookupTables(DeclContext *Primary) const; 1109296417Sdim 1110280031Sdimprivate: 1111249423Sdim struct ImportedModule { 1112249423Sdim ModuleFile *Mod; 1113249423Sdim ModuleFile *ImportedBy; 1114249423Sdim SourceLocation ImportLoc; 1115249423Sdim 1116249423Sdim ImportedModule(ModuleFile *Mod, 1117249423Sdim ModuleFile *ImportedBy, 1118249423Sdim SourceLocation ImportLoc) 1119249423Sdim : Mod(Mod), ImportedBy(ImportedBy), ImportLoc(ImportLoc) { } 1120249423Sdim }; 1121249423Sdim 1122226633Sdim ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type, 1123249423Sdim SourceLocation ImportLoc, ModuleFile *ImportedBy, 1124249423Sdim SmallVectorImpl<ImportedModule> &Loaded, 1125249423Sdim off_t ExpectedSize, time_t ExpectedModTime, 1126280031Sdim serialization::ASTFileSignature ExpectedSignature, 1127243830Sdim unsigned ClientLoadCapabilities); 1128243830Sdim ASTReadResult ReadControlBlock(ModuleFile &F, 1129249423Sdim SmallVectorImpl<ImportedModule> &Loaded, 1130276479Sdim const ModuleFile *ImportedBy, 1131243830Sdim unsigned ClientLoadCapabilities); 1132296417Sdim static ASTReadResult ReadOptionsBlock( 1133296417Sdim llvm::BitstreamCursor &Stream, unsigned ClientLoadCapabilities, 1134296417Sdim bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener, 1135296417Sdim std::string &SuggestedPredefines); 1136276479Sdim ASTReadResult ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities); 1137296417Sdim ASTReadResult ReadExtensionBlock(ModuleFile &F); 1138280031Sdim bool ParseLineTable(ModuleFile &F, const RecordData &Record); 1139243830Sdim bool ReadSourceManagerBlock(ModuleFile &F); 1140226633Sdim llvm::BitstreamCursor &SLocCursorForID(int ID); 1141234353Sdim SourceLocation getImportLocation(ModuleFile *F); 1142280031Sdim ASTReadResult ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, 1143280031Sdim const ModuleFile *ImportedBy, 1144280031Sdim unsigned ClientLoadCapabilities); 1145276479Sdim ASTReadResult ReadSubmoduleBlock(ModuleFile &F, 1146276479Sdim unsigned ClientLoadCapabilities); 1147243830Sdim static bool ParseLanguageOptions(const RecordData &Record, bool Complain, 1148280031Sdim ASTReaderListener &Listener, 1149280031Sdim bool AllowCompatibleDifferences); 1150243830Sdim static bool ParseTargetOptions(const RecordData &Record, bool Complain, 1151288943Sdim ASTReaderListener &Listener, 1152288943Sdim bool AllowCompatibleDifferences); 1153243830Sdim static bool ParseDiagnosticOptions(const RecordData &Record, bool Complain, 1154243830Sdim ASTReaderListener &Listener); 1155243830Sdim static bool ParseFileSystemOptions(const RecordData &Record, bool Complain, 1156243830Sdim ASTReaderListener &Listener); 1157243830Sdim static bool ParseHeaderSearchOptions(const RecordData &Record, bool Complain, 1158243830Sdim ASTReaderListener &Listener); 1159243830Sdim static bool ParsePreprocessorOptions(const RecordData &Record, bool Complain, 1160243830Sdim ASTReaderListener &Listener, 1161243830Sdim std::string &SuggestedPredefines); 1162243830Sdim 1163218893Sdim struct RecordLocation { 1164234353Sdim RecordLocation(ModuleFile *M, uint64_t O) 1165218893Sdim : F(M), Offset(O) {} 1166234353Sdim ModuleFile *F; 1167218893Sdim uint64_t Offset; 1168218893Sdim }; 1169212795Sdim 1170226633Sdim QualType readTypeRecord(unsigned Index); 1171276479Sdim void readExceptionSpec(ModuleFile &ModuleFile, 1172276479Sdim SmallVectorImpl<QualType> &ExceptionStorage, 1173280031Sdim FunctionProtoType::ExceptionSpecInfo &ESI, 1174276479Sdim const RecordData &Record, unsigned &Index); 1175212795Sdim RecordLocation TypeCursorForIndex(unsigned Index); 1176212795Sdim void LoadedDecl(unsigned Index, Decl *D); 1177226633Sdim Decl *ReadDeclRecord(serialization::DeclID ID); 1178276479Sdim void markIncompleteDeclChain(Decl *Canon); 1179288943Sdim 1180288943Sdim /// \brief Returns the most recent declaration of a declaration (which must be 1181288943Sdim /// of a redeclarable kind) that is either local or has already been loaded 1182288943Sdim /// merged into its redecl chain. 1183288943Sdim Decl *getMostRecentExistingDecl(Decl *D); 1184288943Sdim 1185234353Sdim RecordLocation DeclCursorForID(serialization::DeclID ID, 1186234353Sdim unsigned &RawLocation); 1187226633Sdim void loadDeclUpdateRecords(serialization::DeclID ID, Decl *D); 1188296417Sdim void loadPendingDeclChain(Decl *D, uint64_t LocalOffset); 1189234353Sdim void loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D, 1190234353Sdim unsigned PreviousGeneration = 0); 1191234353Sdim 1192226633Sdim RecordLocation getLocalBitOffset(uint64_t GlobalOffset); 1193234353Sdim uint64_t getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset); 1194212795Sdim 1195276479Sdim /// \brief Returns the first preprocessed entity ID that begins or ends after 1196276479Sdim /// \arg Loc. 1197226633Sdim serialization::PreprocessedEntityID 1198276479Sdim findPreprocessedEntity(SourceLocation Loc, bool EndsAfter) const; 1199226633Sdim 1200239462Sdim /// \brief Find the next module that contains entities and return the ID 1201226633Sdim /// of the first entry. 1202243830Sdim /// 1203243830Sdim /// \param SLocMapI points at a chunk of a module that contains no 1204239462Sdim /// preprocessed entities or the entities it contains are not the 1205239462Sdim /// ones we are looking for. 1206226633Sdim serialization::PreprocessedEntityID 1207226633Sdim findNextPreprocessedEntity( 1208226633Sdim GlobalSLocOffsetMapType::const_iterator SLocMapI) const; 1209226633Sdim 1210243830Sdim /// \brief Returns (ModuleFile, Local index) pair for \p GlobalIndex of a 1211234353Sdim /// preprocessed entity. 1212234353Sdim std::pair<ModuleFile *, unsigned> 1213234353Sdim getModulePreprocessedEntity(unsigned GlobalIndex); 1214234353Sdim 1215243830Sdim /// \brief Returns (begin, end) pair for the preprocessed entities of a 1216243830Sdim /// particular module. 1217288943Sdim llvm::iterator_range<PreprocessingRecord::iterator> 1218288943Sdim getModulePreprocessedEntities(ModuleFile &Mod) const; 1219243830Sdim 1220288943Sdim class ModuleDeclIterator 1221288943Sdim : public llvm::iterator_adaptor_base< 1222288943Sdim ModuleDeclIterator, const serialization::LocalDeclID *, 1223288943Sdim std::random_access_iterator_tag, const Decl *, ptrdiff_t, 1224288943Sdim const Decl *, const Decl *> { 1225243830Sdim ASTReader *Reader; 1226243830Sdim ModuleFile *Mod; 1227243830Sdim 1228243830Sdim public: 1229288943Sdim ModuleDeclIterator() 1230288943Sdim : iterator_adaptor_base(nullptr), Reader(nullptr), Mod(nullptr) {} 1231243830Sdim 1232243830Sdim ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod, 1233243830Sdim const serialization::LocalDeclID *Pos) 1234288943Sdim : iterator_adaptor_base(Pos), Reader(Reader), Mod(Mod) {} 1235243830Sdim 1236243830Sdim value_type operator*() const { 1237288943Sdim return Reader->GetDecl(Reader->getGlobalDeclID(*Mod, *I)); 1238243830Sdim } 1239288943Sdim value_type operator->() const { return **this; } 1240243830Sdim 1241288943Sdim bool operator==(const ModuleDeclIterator &RHS) const { 1242288943Sdim assert(Reader == RHS.Reader && Mod == RHS.Mod); 1243288943Sdim return I == RHS.I; 1244243830Sdim } 1245243830Sdim }; 1246243830Sdim 1247288943Sdim llvm::iterator_range<ModuleDeclIterator> 1248288943Sdim getModuleFileLevelDecls(ModuleFile &Mod); 1249243830Sdim 1250212795Sdim void PassInterestingDeclsToConsumer(); 1251234353Sdim void PassInterestingDeclToConsumer(Decl *D); 1252212795Sdim 1253234353Sdim void finishPendingActions(); 1254280031Sdim void diagnoseOdrViolations(); 1255234353Sdim 1256251662Sdim void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name); 1257251662Sdim 1258249423Sdim void addPendingDeclContextInfo(Decl *D, 1259249423Sdim serialization::GlobalDeclID SemaDC, 1260249423Sdim serialization::GlobalDeclID LexicalDC) { 1261249423Sdim assert(D); 1262249423Sdim PendingDeclContextInfo Info = { D, SemaDC, LexicalDC }; 1263249423Sdim PendingDeclContextInfos.push_back(Info); 1264249423Sdim } 1265249423Sdim 1266212795Sdim /// \brief Produce an error diagnostic and return true. 1267212795Sdim /// 1268212795Sdim /// This routine should only be used for fatal errors that have to 1269212795Sdim /// do with non-routine failures (e.g., corrupted AST file). 1270226633Sdim void Error(StringRef Msg); 1271226633Sdim void Error(unsigned DiagID, StringRef Arg1 = StringRef(), 1272226633Sdim StringRef Arg2 = StringRef()); 1273212795Sdim 1274288943Sdim ASTReader(const ASTReader &) = delete; 1275288943Sdim void operator=(const ASTReader &) = delete; 1276212795Sdimpublic: 1277212795Sdim /// \brief Load the AST file and validate its contents against the given 1278212795Sdim /// Preprocessor. 1279212795Sdim /// 1280212795Sdim /// \param PP the preprocessor associated with the context in which this 1281212795Sdim /// precompiled header will be loaded. 1282212795Sdim /// 1283212795Sdim /// \param Context the AST context that this precompiled header will be 1284212795Sdim /// loaded into. 1285212795Sdim /// 1286296417Sdim /// \param PCHContainerRdr the PCHContainerOperations to use for loading and 1287288943Sdim /// creating modules. 1288288943Sdim /// 1289296417Sdim /// \param Extensions the list of module file extensions that can be loaded 1290296417Sdim /// from the AST files. 1291296417Sdim /// 1292212795Sdim /// \param isysroot If non-NULL, the system include path specified by the 1293212795Sdim /// user. This is only used with relocatable PCH files. If non-NULL, 1294212795Sdim /// a relocatable PCH file will use the default path "/". 1295212795Sdim /// 1296212795Sdim /// \param DisableValidation If true, the AST reader will suppress most 1297212795Sdim /// of its regular consistency checking, allowing the use of precompiled 1298212795Sdim /// headers that cannot be determined to be compatible. 1299218893Sdim /// 1300234353Sdim /// \param AllowASTWithCompilerErrors If true, the AST reader will accept an 1301234353Sdim /// AST file the was created out of an AST with compiler errors, 1302234353Sdim /// otherwise it will reject it. 1303249423Sdim /// 1304276479Sdim /// \param AllowConfigurationMismatch If true, the AST reader will not check 1305276479Sdim /// for configuration differences between the AST file and the invocation. 1306276479Sdim /// 1307276479Sdim /// \param ValidateSystemInputs If true, the AST reader will validate 1308276479Sdim /// system input files in addition to user input files. This is only 1309276479Sdim /// meaningful if \p DisableValidation is false. 1310276479Sdim /// 1311249423Sdim /// \param UseGlobalIndex If true, the AST reader will try to load and use 1312249423Sdim /// the global module index. 1313288943Sdim /// 1314288943Sdim /// \param ReadTimer If non-null, a timer used to track the time spent 1315288943Sdim /// deserializing. 1316288943Sdim ASTReader(Preprocessor &PP, ASTContext &Context, 1317288943Sdim const PCHContainerReader &PCHContainerRdr, 1318296417Sdim ArrayRef<IntrusiveRefCntPtr<ModuleFileExtension>> Extensions, 1319288943Sdim StringRef isysroot = "", bool DisableValidation = false, 1320249423Sdim bool AllowASTWithCompilerErrors = false, 1321276479Sdim bool AllowConfigurationMismatch = false, 1322288943Sdim bool ValidateSystemInputs = false, bool UseGlobalIndex = true, 1323288943Sdim std::unique_ptr<llvm::Timer> ReadTimer = {}); 1324212795Sdim 1325288943Sdim ~ASTReader() override; 1326212795Sdim 1327226633Sdim SourceManager &getSourceManager() const { return SourceMgr; } 1328249423Sdim FileManager &getFileManager() const { return FileMgr; } 1329296417Sdim DiagnosticsEngine &getDiags() const { return Diags; } 1330234353Sdim 1331243830Sdim /// \brief Flags that indicate what kind of AST loading failures the client 1332243830Sdim /// of the AST reader can directly handle. 1333243830Sdim /// 1334243830Sdim /// When a client states that it can handle a particular kind of failure, 1335243830Sdim /// the AST reader will not emit errors when producing that kind of failure. 1336243830Sdim enum LoadFailureCapabilities { 1337243830Sdim /// \brief The client can't handle any AST loading failures. 1338243830Sdim ARR_None = 0, 1339243830Sdim /// \brief The client can handle an AST file that cannot load because it 1340249423Sdim /// is missing. 1341249423Sdim ARR_Missing = 0x1, 1342249423Sdim /// \brief The client can handle an AST file that cannot load because it 1343243830Sdim /// is out-of-date relative to its input files. 1344249423Sdim ARR_OutOfDate = 0x2, 1345243830Sdim /// \brief The client can handle an AST file that cannot load because it 1346243830Sdim /// was built with a different version of Clang. 1347249423Sdim ARR_VersionMismatch = 0x4, 1348243830Sdim /// \brief The client can handle an AST file that cannot load because it's 1349243830Sdim /// compiled configuration doesn't match that of the context it was 1350243830Sdim /// loaded into. 1351249423Sdim ARR_ConfigurationMismatch = 0x8 1352243830Sdim }; 1353243830Sdim 1354226633Sdim /// \brief Load the AST file designated by the given file name. 1355243830Sdim /// 1356243830Sdim /// \param FileName The name of the AST file to load. 1357243830Sdim /// 1358243830Sdim /// \param Type The kind of AST being loaded, e.g., PCH, module, main file, 1359243830Sdim /// or preamble. 1360243830Sdim /// 1361249423Sdim /// \param ImportLoc the location where the module file will be considered as 1362249423Sdim /// imported from. For non-module AST types it should be invalid. 1363249423Sdim /// 1364243830Sdim /// \param ClientLoadCapabilities The set of client load-failure 1365243830Sdim /// capabilities, represented as a bitset of the enumerators of 1366243830Sdim /// LoadFailureCapabilities. 1367243830Sdim ASTReadResult ReadAST(const std::string &FileName, ModuleKind Type, 1368249423Sdim SourceLocation ImportLoc, 1369243830Sdim unsigned ClientLoadCapabilities); 1370212795Sdim 1371234353Sdim /// \brief Make the entities in the given module and any of its (non-explicit) 1372234353Sdim /// submodules visible to name lookup. 1373234353Sdim /// 1374234353Sdim /// \param Mod The module whose names should be made visible. 1375234353Sdim /// 1376239462Sdim /// \param NameVisibility The level of visibility to give the names in the 1377239462Sdim /// module. Visibility can only be increased over time. 1378249423Sdim /// 1379249423Sdim /// \param ImportLoc The location at which the import occurs. 1380276479Sdim void makeModuleVisible(Module *Mod, 1381249423Sdim Module::NameVisibilityKind NameVisibility, 1382288943Sdim SourceLocation ImportLoc); 1383276479Sdim 1384234353Sdim /// \brief Make the names within this set of hidden names visible. 1385288943Sdim void makeNamesVisible(const HiddenNames &Names, Module *Owner); 1386276479Sdim 1387280031Sdim /// \brief Take the AST callbacks listener. 1388280031Sdim std::unique_ptr<ASTReaderListener> takeListener() { 1389280031Sdim return std::move(Listener); 1390280031Sdim } 1391280031Sdim 1392212795Sdim /// \brief Set the AST callbacks listener. 1393280031Sdim void setListener(std::unique_ptr<ASTReaderListener> Listener) { 1394280031Sdim this->Listener = std::move(Listener); 1395212795Sdim } 1396212795Sdim 1397280031Sdim /// \brief Add an AST callback listener. 1398276479Sdim /// 1399276479Sdim /// Takes ownership of \p L. 1400280031Sdim void addListener(std::unique_ptr<ASTReaderListener> L) { 1401276479Sdim if (Listener) 1402280031Sdim L = llvm::make_unique<ChainedASTReaderListener>(std::move(L), 1403280031Sdim std::move(Listener)); 1404280031Sdim Listener = std::move(L); 1405276479Sdim } 1406276479Sdim 1407280031Sdim /// RAII object to temporarily add an AST callback listener. 1408280031Sdim class ListenerScope { 1409280031Sdim ASTReader &Reader; 1410280031Sdim bool Chained; 1411280031Sdim 1412280031Sdim public: 1413280031Sdim ListenerScope(ASTReader &Reader, std::unique_ptr<ASTReaderListener> L) 1414280031Sdim : Reader(Reader), Chained(false) { 1415280031Sdim auto Old = Reader.takeListener(); 1416280031Sdim if (Old) { 1417280031Sdim Chained = true; 1418280031Sdim L = llvm::make_unique<ChainedASTReaderListener>(std::move(L), 1419280031Sdim std::move(Old)); 1420280031Sdim } 1421280031Sdim Reader.setListener(std::move(L)); 1422280031Sdim } 1423280031Sdim ~ListenerScope() { 1424280031Sdim auto New = Reader.takeListener(); 1425280031Sdim if (Chained) 1426280031Sdim Reader.setListener(static_cast<ChainedASTReaderListener *>(New.get()) 1427280031Sdim ->takeSecond()); 1428280031Sdim } 1429280031Sdim }; 1430280031Sdim 1431212795Sdim /// \brief Set the AST deserialization listener. 1432276479Sdim void setDeserializationListener(ASTDeserializationListener *Listener, 1433276479Sdim bool TakeOwnership = false); 1434212795Sdim 1435249423Sdim /// \brief Determine whether this AST reader has a global index. 1436276479Sdim bool hasGlobalIndex() const { return (bool)GlobalIndex; } 1437249423Sdim 1438276479Sdim /// \brief Return global module index. 1439276479Sdim GlobalModuleIndex *getGlobalIndex() { return GlobalIndex.get(); } 1440276479Sdim 1441276479Sdim /// \brief Reset reader for a reload try. 1442276479Sdim void resetForReload() { TriedLoadingGlobalIndex = false; } 1443276479Sdim 1444249423Sdim /// \brief Attempts to load the global index. 1445249423Sdim /// 1446249423Sdim /// \returns true if loading the global index has failed for any reason. 1447249423Sdim bool loadGlobalIndex(); 1448249423Sdim 1449249423Sdim /// \brief Determine whether we tried to load the global index, but failed, 1450249423Sdim /// e.g., because it is out-of-date or does not exist. 1451249423Sdim bool isGlobalIndexUnavailable() const; 1452249423Sdim 1453226633Sdim /// \brief Initializes the ASTContext 1454226633Sdim void InitializeContext(); 1455212795Sdim 1456261991Sdim /// \brief Update the state of Sema after loading some additional modules. 1457261991Sdim void UpdateSema(); 1458261991Sdim 1459226633Sdim /// \brief Add in-memory (virtual file) buffer. 1460280031Sdim void addInMemoryBuffer(StringRef &FileName, 1461280031Sdim std::unique_ptr<llvm::MemoryBuffer> Buffer) { 1462280031Sdim ModuleMgr.addInMemoryBuffer(FileName, std::move(Buffer)); 1463221345Sdim } 1464221345Sdim 1465234353Sdim /// \brief Finalizes the AST reader's state before writing an AST file to 1466234353Sdim /// disk. 1467234353Sdim /// 1468234353Sdim /// This operation may undo temporary state in the AST that should not be 1469234353Sdim /// emitted. 1470234353Sdim void finalizeForWriting(); 1471234353Sdim 1472226633Sdim /// \brief Retrieve the module manager. 1473226633Sdim ModuleManager &getModuleManager() { return ModuleMgr; } 1474212795Sdim 1475226633Sdim /// \brief Retrieve the preprocessor. 1476226633Sdim Preprocessor &getPreprocessor() const { return PP; } 1477234353Sdim 1478243830Sdim /// \brief Retrieve the name of the original source file name for the primary 1479243830Sdim /// module file. 1480243830Sdim StringRef getOriginalSourceFile() { 1481243830Sdim return ModuleMgr.getPrimaryModule().OriginalSourceFileName; 1482243830Sdim } 1483212795Sdim 1484212795Sdim /// \brief Retrieve the name of the original source file name directly from 1485212795Sdim /// the AST file, without actually loading the AST file. 1486288943Sdim static std::string 1487288943Sdim getOriginalSourceFile(const std::string &ASTFileName, FileManager &FileMgr, 1488288943Sdim const PCHContainerReader &PCHContainerRdr, 1489288943Sdim DiagnosticsEngine &Diags); 1490212795Sdim 1491243830Sdim /// \brief Read the control block for the named AST file. 1492243830Sdim /// 1493243830Sdim /// \returns true if an error occurred, false otherwise. 1494288943Sdim static bool 1495288943Sdim readASTFileControlBlock(StringRef Filename, FileManager &FileMgr, 1496288943Sdim const PCHContainerReader &PCHContainerRdr, 1497296417Sdim bool FindModuleFileExtensions, 1498288943Sdim ASTReaderListener &Listener); 1499243830Sdim 1500243830Sdim /// \brief Determine whether the given AST file is acceptable to load into a 1501243830Sdim /// translation unit with the given language and target options. 1502288943Sdim static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr, 1503288943Sdim const PCHContainerReader &PCHContainerRdr, 1504243830Sdim const LangOptions &LangOpts, 1505243830Sdim const TargetOptions &TargetOpts, 1506288943Sdim const PreprocessorOptions &PPOpts, 1507288943Sdim std::string ExistingModuleCachePath); 1508243830Sdim 1509212795Sdim /// \brief Returns the suggested contents of the predefines buffer, 1510212795Sdim /// which contains a (typically-empty) subset of the predefines 1511212795Sdim /// build prior to including the precompiled header. 1512212795Sdim const std::string &getSuggestedPredefines() { return SuggestedPredefines; } 1513212795Sdim 1514226633Sdim /// \brief Read a preallocated preprocessed entity from the external source. 1515226633Sdim /// 1516226633Sdim /// \returns null if an error occurred that prevented the preprocessed 1517226633Sdim /// entity from being loaded. 1518276479Sdim PreprocessedEntity *ReadPreprocessedEntity(unsigned Index) override; 1519218893Sdim 1520226633Sdim /// \brief Returns a pair of [Begin, End) indices of preallocated 1521243830Sdim /// preprocessed entities that \p Range encompasses. 1522276479Sdim std::pair<unsigned, unsigned> 1523276479Sdim findPreprocessedEntitiesInRange(SourceRange Range) override; 1524226633Sdim 1525234353Sdim /// \brief Optionally returns true or false if the preallocated preprocessed 1526243830Sdim /// entity with index \p Index came from file \p FID. 1527276479Sdim Optional<bool> isPreprocessedEntityInFileID(unsigned Index, 1528276479Sdim FileID FID) override; 1529234353Sdim 1530218893Sdim /// \brief Read the header file information for the given file entry. 1531276479Sdim HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) override; 1532218893Sdim 1533226633Sdim void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag); 1534218893Sdim 1535212795Sdim /// \brief Returns the number of source locations found in the chain. 1536212795Sdim unsigned getTotalNumSLocs() const { 1537212795Sdim return TotalNumSLocEntries; 1538212795Sdim } 1539212795Sdim 1540212795Sdim /// \brief Returns the number of identifiers found in the chain. 1541212795Sdim unsigned getTotalNumIdentifiers() const { 1542212795Sdim return static_cast<unsigned>(IdentifiersLoaded.size()); 1543212795Sdim } 1544212795Sdim 1545243830Sdim /// \brief Returns the number of macros found in the chain. 1546243830Sdim unsigned getTotalNumMacros() const { 1547243830Sdim return static_cast<unsigned>(MacrosLoaded.size()); 1548243830Sdim } 1549243830Sdim 1550212795Sdim /// \brief Returns the number of types found in the chain. 1551212795Sdim unsigned getTotalNumTypes() const { 1552212795Sdim return static_cast<unsigned>(TypesLoaded.size()); 1553212795Sdim } 1554212795Sdim 1555212795Sdim /// \brief Returns the number of declarations found in the chain. 1556212795Sdim unsigned getTotalNumDecls() const { 1557212795Sdim return static_cast<unsigned>(DeclsLoaded.size()); 1558212795Sdim } 1559212795Sdim 1560234353Sdim /// \brief Returns the number of submodules known. 1561234353Sdim unsigned getTotalNumSubmodules() const { 1562234353Sdim return static_cast<unsigned>(SubmodulesLoaded.size()); 1563234353Sdim } 1564234353Sdim 1565212795Sdim /// \brief Returns the number of selectors found in the chain. 1566212795Sdim unsigned getTotalNumSelectors() const { 1567212795Sdim return static_cast<unsigned>(SelectorsLoaded.size()); 1568212795Sdim } 1569212795Sdim 1570226633Sdim /// \brief Returns the number of preprocessed entities known to the AST 1571226633Sdim /// reader. 1572226633Sdim unsigned getTotalNumPreprocessedEntities() const { 1573226633Sdim unsigned Result = 0; 1574226633Sdim for (ModuleConstIterator I = ModuleMgr.begin(), 1575226633Sdim E = ModuleMgr.end(); I != E; ++I) { 1576226633Sdim Result += (*I)->NumPreprocessedEntities; 1577226633Sdim } 1578234353Sdim 1579226633Sdim return Result; 1580218893Sdim } 1581234353Sdim 1582212795Sdim /// \brief Reads a TemplateArgumentLocInfo appropriate for the 1583212795Sdim /// given TemplateArgument kind. 1584212795Sdim TemplateArgumentLocInfo 1585234353Sdim GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind, 1586212795Sdim const RecordData &Record, unsigned &Idx); 1587212795Sdim 1588212795Sdim /// \brief Reads a TemplateArgumentLoc. 1589212795Sdim TemplateArgumentLoc 1590234353Sdim ReadTemplateArgumentLoc(ModuleFile &F, 1591212795Sdim const RecordData &Record, unsigned &Idx); 1592212795Sdim 1593261991Sdim const ASTTemplateArgumentListInfo* 1594261991Sdim ReadASTTemplateArgumentListInfo(ModuleFile &F, 1595261991Sdim const RecordData &Record, unsigned &Index); 1596261991Sdim 1597212795Sdim /// \brief Reads a declarator info from the given record. 1598234353Sdim TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F, 1599212795Sdim const RecordData &Record, unsigned &Idx); 1600212795Sdim 1601212795Sdim /// \brief Resolve a type ID into a type, potentially building a new 1602212795Sdim /// type. 1603212795Sdim QualType GetType(serialization::TypeID ID); 1604212795Sdim 1605226633Sdim /// \brief Resolve a local type ID within a given AST file into a type. 1606234353Sdim QualType getLocalType(ModuleFile &F, unsigned LocalID); 1607234353Sdim 1608226633Sdim /// \brief Map a local type ID within a given AST file into a global type ID. 1609234353Sdim serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const; 1610234353Sdim 1611234353Sdim /// \brief Read a type from the current position in the given record, which 1612226633Sdim /// was read from the given AST file. 1613234353Sdim QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) { 1614226633Sdim if (Idx >= Record.size()) 1615226633Sdim return QualType(); 1616234353Sdim 1617226633Sdim return getLocalType(F, Record[Idx++]); 1618226633Sdim } 1619234353Sdim 1620234353Sdim /// \brief Map from a local declaration ID within a given module to a 1621226633Sdim /// global declaration ID. 1622243830Sdim serialization::DeclID getGlobalDeclID(ModuleFile &F, 1623243830Sdim serialization::LocalDeclID LocalID) const; 1624212795Sdim 1625243830Sdim /// \brief Returns true if global DeclID \p ID originated from module \p M. 1626234353Sdim bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const; 1627234353Sdim 1628234353Sdim /// \brief Retrieve the module file that owns the given declaration, or NULL 1629234353Sdim /// if the declaration is not from a module file. 1630249423Sdim ModuleFile *getOwningModuleFile(const Decl *D); 1631276479Sdim 1632276479Sdim /// \brief Get the best name we know for the module that owns the given 1633276479Sdim /// declaration, or an empty string if the declaration is not from a module. 1634276479Sdim std::string getOwningModuleNameForDiagnostic(const Decl *D); 1635276479Sdim 1636243830Sdim /// \brief Returns the source location for the decl \p ID. 1637234353Sdim SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID); 1638234353Sdim 1639212795Sdim /// \brief Resolve a declaration ID into a declaration, potentially 1640212795Sdim /// building a new declaration. 1641212795Sdim Decl *GetDecl(serialization::DeclID ID); 1642276479Sdim Decl *GetExternalDecl(uint32_t ID) override; 1643212795Sdim 1644276479Sdim /// \brief Resolve a declaration ID into a declaration. Return 0 if it's not 1645276479Sdim /// been loaded yet. 1646276479Sdim Decl *GetExistingDecl(serialization::DeclID ID); 1647276479Sdim 1648226633Sdim /// \brief Reads a declaration with the given local ID in the given module. 1649234353Sdim Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) { 1650226633Sdim return GetDecl(getGlobalDeclID(F, LocalID)); 1651226633Sdim } 1652226633Sdim 1653226633Sdim /// \brief Reads a declaration with the given local ID in the given module. 1654226633Sdim /// 1655226633Sdim /// \returns The requested declaration, casted to the given return type. 1656226633Sdim template<typename T> 1657234353Sdim T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) { 1658226633Sdim return cast_or_null<T>(GetLocalDecl(F, LocalID)); 1659226633Sdim } 1660226633Sdim 1661234353Sdim /// \brief Map a global declaration ID into the declaration ID used to 1662234353Sdim /// refer to this declaration within the given module fule. 1663234353Sdim /// 1664234353Sdim /// \returns the global ID of the given declaration as known in the given 1665234353Sdim /// module file. 1666234353Sdim serialization::DeclID 1667234353Sdim mapGlobalIDToModuleFileGlobalID(ModuleFile &M, 1668234353Sdim serialization::DeclID GlobalID); 1669234353Sdim 1670234353Sdim /// \brief Reads a declaration ID from the given position in a record in the 1671226633Sdim /// given module. 1672226633Sdim /// 1673226633Sdim /// \returns The declaration ID read from the record, adjusted to a global ID. 1674234353Sdim serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record, 1675226633Sdim unsigned &Idx); 1676234353Sdim 1677226633Sdim /// \brief Reads a declaration from the given position in a record in the 1678226633Sdim /// given module. 1679234353Sdim Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) { 1680226633Sdim return GetDecl(ReadDeclID(F, R, I)); 1681226633Sdim } 1682234353Sdim 1683226633Sdim /// \brief Reads a declaration from the given position in a record in the 1684226633Sdim /// given module. 1685226633Sdim /// 1686226633Sdim /// \returns The declaration read from this location, casted to the given 1687226633Sdim /// result type. 1688226633Sdim template<typename T> 1689234353Sdim T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) { 1690226633Sdim return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I))); 1691226633Sdim } 1692226633Sdim 1693276479Sdim /// \brief If any redeclarations of \p D have been imported since it was 1694276479Sdim /// last checked, this digs out those redeclarations and adds them to the 1695276479Sdim /// redeclaration chain for \p D. 1696276479Sdim void CompleteRedeclChain(const Decl *D) override; 1697276479Sdim 1698226633Sdim /// \brief Read a CXXBaseSpecifiers ID form the given record and 1699226633Sdim /// return its global bit offset. 1700234353Sdim uint64_t readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record, 1701226633Sdim unsigned &Idx); 1702234353Sdim 1703276479Sdim CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override; 1704234353Sdim 1705212795Sdim /// \brief Resolve the offset of a statement into a statement. 1706212795Sdim /// 1707212795Sdim /// This operation will read a new statement from the external 1708212795Sdim /// source each time it is called, and is meant to be used via a 1709212795Sdim /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). 1710276479Sdim Stmt *GetExternalDeclStmt(uint64_t Offset) override; 1711212795Sdim 1712212795Sdim /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the 1713212795Sdim /// specified cursor. Read the abbreviations that are at the top of the block 1714212795Sdim /// and then leave the cursor pointing into the block. 1715296417Sdim static bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID); 1716212795Sdim 1717212795Sdim /// \brief Finds all the visible declarations with a given name. 1718212795Sdim /// The current implementation of this method just loads the entire 1719212795Sdim /// lookup table as unmaterialized references. 1720276479Sdim bool FindExternalVisibleDeclsByName(const DeclContext *DC, 1721276479Sdim DeclarationName Name) override; 1722212795Sdim 1723212795Sdim /// \brief Read all of the declarations lexically stored in a 1724212795Sdim /// declaration context. 1725212795Sdim /// 1726212795Sdim /// \param DC The declaration context whose declarations will be 1727212795Sdim /// read. 1728212795Sdim /// 1729296417Sdim /// \param IsKindWeWant A predicate indicating which declaration kinds 1730296417Sdim /// we are interested in. 1731296417Sdim /// 1732212795Sdim /// \param Decls Vector that will contain the declarations loaded 1733212795Sdim /// from the external source. The caller is responsible for merging 1734212795Sdim /// these declarations with any declarations already stored in the 1735212795Sdim /// declaration context. 1736296417Sdim void 1737296417Sdim FindExternalLexicalDecls(const DeclContext *DC, 1738296417Sdim llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, 1739296417Sdim SmallVectorImpl<Decl *> &Decls) override; 1740212795Sdim 1741234353Sdim /// \brief Get the decls that are contained in a file in the Offset/Length 1742243830Sdim /// range. \p Length can be 0 to indicate a point at \p Offset instead of 1743234353Sdim /// a range. 1744276479Sdim void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length, 1745276479Sdim SmallVectorImpl<Decl *> &Decls) override; 1746234353Sdim 1747212795Sdim /// \brief Notify ASTReader that we started deserialization of 1748212795Sdim /// a decl or type so until FinishedDeserializing is called there may be 1749212795Sdim /// decls that are initializing. Must be paired with FinishedDeserializing. 1750288943Sdim void StartedDeserializing() override; 1751212795Sdim 1752212795Sdim /// \brief Notify ASTReader that we finished the deserialization of 1753212795Sdim /// a decl or type. Must be paired with StartedDeserializing. 1754276479Sdim void FinishedDeserializing() override; 1755212795Sdim 1756212795Sdim /// \brief Function that will be invoked when we begin parsing a new 1757212795Sdim /// translation unit involving this external AST source. 1758212795Sdim /// 1759212795Sdim /// This function will provide all of the external definitions to 1760212795Sdim /// the ASTConsumer. 1761276479Sdim void StartTranslationUnit(ASTConsumer *Consumer) override; 1762212795Sdim 1763212795Sdim /// \brief Print some statistics about AST usage. 1764276479Sdim void PrintStats() override; 1765212795Sdim 1766226633Sdim /// \brief Dump information about the AST reader to standard error. 1767226633Sdim void dump(); 1768234353Sdim 1769221345Sdim /// Return the amount of memory used by memory buffers, breaking down 1770221345Sdim /// by heap-backed versus mmap'ed memory. 1771276479Sdim void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override; 1772221345Sdim 1773212795Sdim /// \brief Initialize the semantic source with the Sema instance 1774212795Sdim /// being used to perform semantic analysis on the abstract syntax 1775212795Sdim /// tree. 1776276479Sdim void InitializeSema(Sema &S) override; 1777212795Sdim 1778212795Sdim /// \brief Inform the semantic consumer that Sema is no longer available. 1779276479Sdim void ForgetSema() override { SemaObj = nullptr; } 1780212795Sdim 1781212795Sdim /// \brief Retrieve the IdentifierInfo for the named identifier. 1782212795Sdim /// 1783212795Sdim /// This routine builds a new IdentifierInfo for the given identifier. If any 1784212795Sdim /// declarations with this name are visible from translation unit scope, their 1785212795Sdim /// declarations will be deserialized and introduced into the declaration 1786212795Sdim /// chain of the identifier. 1787296417Sdim IdentifierInfo *get(StringRef Name) override; 1788212795Sdim 1789218893Sdim /// \brief Retrieve an iterator into the set of all identifiers 1790218893Sdim /// in all loaded AST files. 1791276479Sdim IdentifierIterator *getIdentifiers() override; 1792218893Sdim 1793212795Sdim /// \brief Load the contents of the global method pool for a given 1794212795Sdim /// selector. 1795276479Sdim void ReadMethodPool(Selector Sel) override; 1796212795Sdim 1797224145Sdim /// \brief Load the set of namespaces that are known to the external source, 1798224145Sdim /// which will be used during typo correction. 1799276479Sdim void ReadKnownNamespaces( 1800276479Sdim SmallVectorImpl<NamespaceDecl *> &Namespaces) override; 1801224145Sdim 1802276479Sdim void ReadUndefinedButUsed( 1803276479Sdim llvm::DenseMap<NamedDecl *, SourceLocation> &Undefined) override; 1804249423Sdim 1805288943Sdim void ReadMismatchingDeleteExpressions(llvm::MapVector< 1806288943Sdim FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> & 1807288943Sdim Exprs) override; 1808288943Sdim 1809276479Sdim void ReadTentativeDefinitions( 1810276479Sdim SmallVectorImpl<VarDecl *> &TentativeDefs) override; 1811226633Sdim 1812276479Sdim void ReadUnusedFileScopedDecls( 1813276479Sdim SmallVectorImpl<const DeclaratorDecl *> &Decls) override; 1814226633Sdim 1815276479Sdim void ReadDelegatingConstructors( 1816276479Sdim SmallVectorImpl<CXXConstructorDecl *> &Decls) override; 1817226633Sdim 1818276479Sdim void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) override; 1819226633Sdim 1820280031Sdim void ReadUnusedLocalTypedefNameCandidates( 1821280031Sdim llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override; 1822280031Sdim 1823276479Sdim void ReadReferencedSelectors( 1824276479Sdim SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) override; 1825226633Sdim 1826276479Sdim void ReadWeakUndeclaredIdentifiers( 1827276479Sdim SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI) override; 1828226633Sdim 1829276479Sdim void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override; 1830226633Sdim 1831276479Sdim void ReadPendingInstantiations( 1832234353Sdim SmallVectorImpl<std::pair<ValueDecl *, 1833276479Sdim SourceLocation> > &Pending) override; 1834226633Sdim 1835276479Sdim void ReadLateParsedTemplates( 1836288943Sdim llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap) 1837288943Sdim override; 1838261991Sdim 1839212795Sdim /// \brief Load a selector from disk, registering its ID if it exists. 1840212795Sdim void LoadSelector(Selector Sel); 1841212795Sdim 1842212795Sdim void SetIdentifierInfo(unsigned ID, IdentifierInfo *II); 1843212795Sdim void SetGloballyVisibleDecls(IdentifierInfo *II, 1844226633Sdim const SmallVectorImpl<uint32_t> &DeclIDs, 1845276479Sdim SmallVectorImpl<Decl *> *Decls = nullptr); 1846212795Sdim 1847212795Sdim /// \brief Report a diagnostic. 1848212795Sdim DiagnosticBuilder Diag(unsigned DiagID); 1849212795Sdim 1850212795Sdim /// \brief Report a diagnostic. 1851212795Sdim DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); 1852212795Sdim 1853226633Sdim IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID); 1854212795Sdim 1855234353Sdim IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record, 1856226633Sdim unsigned &Idx) { 1857226633Sdim return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++])); 1858212795Sdim } 1859212795Sdim 1860276479Sdim IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) override { 1861243830Sdim // Note that we are loading an identifier. 1862243830Sdim Deserializing AnIdentifier(this); 1863243830Sdim 1864212795Sdim return DecodeIdentifierInfo(ID); 1865212795Sdim } 1866212795Sdim 1867234353Sdim IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID); 1868234353Sdim 1869234353Sdim serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M, 1870226633Sdim unsigned LocalID); 1871234353Sdim 1872249423Sdim void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo); 1873249423Sdim 1874243830Sdim /// \brief Retrieve the macro with the given ID. 1875249423Sdim MacroInfo *getMacro(serialization::MacroID ID); 1876243830Sdim 1877243830Sdim /// \brief Retrieve the global macro ID corresponding to the given local 1878243830Sdim /// ID within the given module file. 1879243830Sdim serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID); 1880243830Sdim 1881212795Sdim /// \brief Read the source location entry with index ID. 1882276479Sdim bool ReadSLocEntry(int ID) override; 1883212795Sdim 1884249423Sdim /// \brief Retrieve the module import location and module name for the 1885249423Sdim /// given source manager entry ID. 1886276479Sdim std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID) override; 1887249423Sdim 1888234353Sdim /// \brief Retrieve the global submodule ID given a module and its local ID 1889234353Sdim /// number. 1890234353Sdim serialization::SubmoduleID 1891234353Sdim getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID); 1892234353Sdim 1893234353Sdim /// \brief Retrieve the submodule that corresponds to a global submodule ID. 1894234353Sdim /// 1895234353Sdim Module *getSubmodule(serialization::SubmoduleID GlobalID); 1896249423Sdim 1897249423Sdim /// \brief Retrieve the module that corresponds to the given module ID. 1898249423Sdim /// 1899249423Sdim /// Note: overrides method in ExternalASTSource 1900276479Sdim Module *getModule(unsigned ID) override; 1901249423Sdim 1902296417Sdim /// \brief Retrieve the module file with a given local ID within the specified 1903296417Sdim /// ModuleFile. 1904296417Sdim ModuleFile *getLocalModuleFile(ModuleFile &M, unsigned ID); 1905296417Sdim 1906296417Sdim /// \brief Get an ID for the given module file. 1907296417Sdim unsigned getModuleFileID(ModuleFile *M); 1908296417Sdim 1909288943Sdim /// \brief Return a descriptor for the corresponding module. 1910288943Sdim llvm::Optional<ASTSourceDescriptor> getSourceDescriptor(unsigned ID) override; 1911288943Sdim 1912226633Sdim /// \brief Retrieve a selector from the given module with its local ID 1913226633Sdim /// number. 1914234353Sdim Selector getLocalSelector(ModuleFile &M, unsigned LocalID); 1915212795Sdim 1916226633Sdim Selector DecodeSelector(serialization::SelectorID Idx); 1917226633Sdim 1918276479Sdim Selector GetExternalSelector(serialization::SelectorID ID) override; 1919276479Sdim uint32_t GetNumExternalSelectors() override; 1920212795Sdim 1921234353Sdim Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) { 1922226633Sdim return getLocalSelector(M, Record[Idx++]); 1923212795Sdim } 1924234353Sdim 1925226633Sdim /// \brief Retrieve the global selector ID that corresponds to this 1926226633Sdim /// the local selector ID in a given module. 1927234353Sdim serialization::SelectorID getGlobalSelectorID(ModuleFile &F, 1928226633Sdim unsigned LocalID) const; 1929212795Sdim 1930212795Sdim /// \brief Read a declaration name. 1931234353Sdim DeclarationName ReadDeclarationName(ModuleFile &F, 1932226633Sdim const RecordData &Record, unsigned &Idx); 1933234353Sdim void ReadDeclarationNameLoc(ModuleFile &F, 1934218893Sdim DeclarationNameLoc &DNLoc, DeclarationName Name, 1935218893Sdim const RecordData &Record, unsigned &Idx); 1936234353Sdim void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo, 1937218893Sdim const RecordData &Record, unsigned &Idx); 1938212795Sdim 1939234353Sdim void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, 1940218893Sdim const RecordData &Record, unsigned &Idx); 1941218893Sdim 1942234353Sdim NestedNameSpecifier *ReadNestedNameSpecifier(ModuleFile &F, 1943226633Sdim const RecordData &Record, 1944212795Sdim unsigned &Idx); 1945212795Sdim 1946234353Sdim NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F, 1947219077Sdim const RecordData &Record, 1948219077Sdim unsigned &Idx); 1949219077Sdim 1950212795Sdim /// \brief Read a template name. 1951234353Sdim TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record, 1952218893Sdim unsigned &Idx); 1953212795Sdim 1954212795Sdim /// \brief Read a template argument. 1955296417Sdim TemplateArgument ReadTemplateArgument(ModuleFile &F, const RecordData &Record, 1956296417Sdim unsigned &Idx, 1957296417Sdim bool Canonicalize = false); 1958234353Sdim 1959212795Sdim /// \brief Read a template parameter list. 1960234353Sdim TemplateParameterList *ReadTemplateParameterList(ModuleFile &F, 1961218893Sdim const RecordData &Record, 1962212795Sdim unsigned &Idx); 1963234353Sdim 1964212795Sdim /// \brief Read a template argument array. 1965296417Sdim void ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs, 1966296417Sdim ModuleFile &F, const RecordData &Record, 1967296417Sdim unsigned &Idx, bool Canonicalize = false); 1968212795Sdim 1969212795Sdim /// \brief Read a UnresolvedSet structure. 1970261991Sdim void ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set, 1971212795Sdim const RecordData &Record, unsigned &Idx); 1972212795Sdim 1973212795Sdim /// \brief Read a C++ base specifier. 1974234353Sdim CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F, 1975212795Sdim const RecordData &Record,unsigned &Idx); 1976212795Sdim 1977218893Sdim /// \brief Read a CXXCtorInitializer array. 1978288943Sdim CXXCtorInitializer ** 1979234353Sdim ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, 1980218893Sdim unsigned &Idx); 1981212795Sdim 1982288943Sdim /// \brief Read a CXXCtorInitializers ID from the given record and 1983288943Sdim /// return its global bit offset. 1984288943Sdim uint64_t ReadCXXCtorInitializersRef(ModuleFile &M, const RecordData &Record, 1985288943Sdim unsigned &Idx); 1986288943Sdim 1987288943Sdim /// \brief Read the contents of a CXXCtorInitializer array. 1988288943Sdim CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override; 1989288943Sdim 1990218893Sdim /// \brief Read a source location from raw form. 1991234353Sdim SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, unsigned Raw) const { 1992226633Sdim SourceLocation Loc = SourceLocation::getFromRawEncoding(Raw); 1993234353Sdim assert(ModuleFile.SLocRemap.find(Loc.getOffset()) != ModuleFile.SLocRemap.end() && 1994226633Sdim "Cannot find offset to remap."); 1995234353Sdim int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second; 1996226633Sdim return Loc.getLocWithOffset(Remap); 1997218893Sdim } 1998218893Sdim 1999212795Sdim /// \brief Read a source location. 2000234353Sdim SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, 2001261991Sdim const RecordDataImpl &Record, 2002261991Sdim unsigned &Idx) { 2003234353Sdim return ReadSourceLocation(ModuleFile, Record[Idx++]); 2004212795Sdim } 2005212795Sdim 2006212795Sdim /// \brief Read a source range. 2007234353Sdim SourceRange ReadSourceRange(ModuleFile &F, 2008249423Sdim const RecordData &Record, unsigned &Idx); 2009212795Sdim 2010212795Sdim /// \brief Read an integral value 2011212795Sdim llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx); 2012212795Sdim 2013212795Sdim /// \brief Read a signed integral value 2014212795Sdim llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx); 2015212795Sdim 2016212795Sdim /// \brief Read a floating-point value 2017249423Sdim llvm::APFloat ReadAPFloat(const RecordData &Record, 2018249423Sdim const llvm::fltSemantics &Sem, unsigned &Idx); 2019212795Sdim 2020212795Sdim // \brief Read a string 2021243830Sdim static std::string ReadString(const RecordData &Record, unsigned &Idx); 2022212795Sdim 2023280031Sdim // \brief Read a path 2024280031Sdim std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx); 2025280031Sdim 2026221345Sdim /// \brief Read a version tuple. 2027243830Sdim static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx); 2028221345Sdim 2029234353Sdim CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record, 2030226633Sdim unsigned &Idx); 2031234353Sdim 2032212795Sdim /// \brief Reads attributes from the current stream position. 2033234353Sdim void ReadAttributes(ModuleFile &F, AttrVec &Attrs, 2034218893Sdim const RecordData &Record, unsigned &Idx); 2035212795Sdim 2036212795Sdim /// \brief Reads a statement. 2037234353Sdim Stmt *ReadStmt(ModuleFile &F); 2038212795Sdim 2039212795Sdim /// \brief Reads an expression. 2040234353Sdim Expr *ReadExpr(ModuleFile &F); 2041212795Sdim 2042212795Sdim /// \brief Reads a sub-statement operand during statement reading. 2043212795Sdim Stmt *ReadSubStmt() { 2044212795Sdim assert(ReadingKind == Read_Stmt && 2045212795Sdim "Should be called only during statement reading!"); 2046212795Sdim // Subexpressions are stored from last to first, so the next Stmt we need 2047212795Sdim // is at the back of the stack. 2048276479Sdim assert(!StmtStack.empty() && "Read too many sub-statements!"); 2049212795Sdim return StmtStack.pop_back_val(); 2050212795Sdim } 2051212795Sdim 2052212795Sdim /// \brief Reads a sub-expression operand during statement reading. 2053212795Sdim Expr *ReadSubExpr(); 2054212795Sdim 2055251662Sdim /// \brief Reads a token out of a record. 2056261991Sdim Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx); 2057251662Sdim 2058212795Sdim /// \brief Reads the macro record located at the given offset. 2059249423Sdim MacroInfo *ReadMacroRecord(ModuleFile &F, uint64_t Offset); 2060234353Sdim 2061226633Sdim /// \brief Determine the global preprocessed entity ID that corresponds to 2062226633Sdim /// the given local ID within the given module. 2063234353Sdim serialization::PreprocessedEntityID 2064234353Sdim getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const; 2065234353Sdim 2066288943Sdim /// \brief Add a macro to deserialize its macro directive history. 2067234353Sdim /// 2068234353Sdim /// \param II The name of the macro. 2069249423Sdim /// \param M The module file. 2070249423Sdim /// \param MacroDirectivesOffset Offset of the serialized macro directive 2071249423Sdim /// history. 2072288943Sdim void addPendingMacro(IdentifierInfo *II, ModuleFile *M, 2073288943Sdim uint64_t MacroDirectivesOffset); 2074234353Sdim 2075212795Sdim /// \brief Read the set of macros defined by this external macro source. 2076276479Sdim void ReadDefinedMacros() override; 2077212795Sdim 2078234353Sdim /// \brief Update an out-of-date identifier. 2079276479Sdim void updateOutOfDateIdentifier(IdentifierInfo &II) override; 2080234353Sdim 2081234353Sdim /// \brief Note that this identifier is up-to-date. 2082234353Sdim void markIdentifierUpToDate(IdentifierInfo *II); 2083234353Sdim 2084234353Sdim /// \brief Load all external visible decls in the given DeclContext. 2085276479Sdim void completeVisibleDeclsMap(const DeclContext *DC) override; 2086234353Sdim 2087212795Sdim /// \brief Retrieve the AST context that this AST reader supplements. 2088226633Sdim ASTContext &getContext() { return Context; } 2089212795Sdim 2090280031Sdim // \brief Contains the IDs for declarations that were requested before we have 2091212795Sdim // access to a Sema object. 2092280031Sdim SmallVector<uint64_t, 16> PreloadedDeclIDs; 2093212795Sdim 2094212795Sdim /// \brief Retrieve the semantic analysis object used to analyze the 2095212795Sdim /// translation unit in which the precompiled header is being 2096212795Sdim /// imported. 2097212795Sdim Sema *getSema() { return SemaObj; } 2098212795Sdim 2099212795Sdim /// \brief Retrieve the identifier table associated with the 2100212795Sdim /// preprocessor. 2101212795Sdim IdentifierTable &getIdentifierTable(); 2102212795Sdim 2103212795Sdim /// \brief Record that the given ID maps to the given switch-case 2104212795Sdim /// statement. 2105212795Sdim void RecordSwitchCaseID(SwitchCase *SC, unsigned ID); 2106212795Sdim 2107212795Sdim /// \brief Retrieve the switch-case statement with the given ID. 2108212795Sdim SwitchCase *getSwitchCaseWithID(unsigned ID); 2109212795Sdim 2110218893Sdim void ClearSwitchCaseIDs(); 2111239462Sdim 2112239462Sdim /// \brief Cursors for comments blocks. 2113239462Sdim SmallVector<std::pair<llvm::BitstreamCursor, 2114239462Sdim serialization::ModuleFile *>, 8> CommentsCursors; 2115239462Sdim 2116296417Sdim /// \brief Loads comments ranges. 2117276479Sdim void ReadComments() override; 2118212795Sdim}; 2119212795Sdim 2120212795Sdim/// \brief Helper class that saves the current stream position and 2121212795Sdim/// then restores it when destroyed. 2122212795Sdimstruct SavedStreamPosition { 2123212795Sdim explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor) 2124249423Sdim : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) { } 2125212795Sdim 2126212795Sdim ~SavedStreamPosition() { 2127212795Sdim Cursor.JumpToBit(Offset); 2128212795Sdim } 2129212795Sdim 2130212795Sdimprivate: 2131212795Sdim llvm::BitstreamCursor &Cursor; 2132212795Sdim uint64_t Offset; 2133212795Sdim}; 2134212795Sdim 2135212795Sdiminline void PCHValidator::Error(const char *Msg) { 2136212795Sdim Reader.Error(Msg); 2137212795Sdim} 2138212795Sdim 2139212795Sdim} // end namespace clang 2140212795Sdim 2141212795Sdim#endif 2142