ASTReader.h revision 245431
1212795Sdim//===--- ASTReader.h - AST File Reader --------------------------*- C++ -*-===// 2212795Sdim// 3212795Sdim// The LLVM Compiler Infrastructure 4212795Sdim// 5212795Sdim// This file is distributed under the University of Illinois Open Source 6212795Sdim// License. See LICENSE.TXT for details. 7212795Sdim// 8212795Sdim//===----------------------------------------------------------------------===// 9212795Sdim// 10212795Sdim// This file defines the ASTReader class, which reads AST files. 11212795Sdim// 12212795Sdim//===----------------------------------------------------------------------===// 13212795Sdim 14212795Sdim#ifndef LLVM_CLANG_FRONTEND_AST_READER_H 15212795Sdim#define LLVM_CLANG_FRONTEND_AST_READER_H 16212795Sdim 17212795Sdim#include "clang/Serialization/ASTBitCodes.h" 18226890Sdim#include "clang/Serialization/ContinuousRangeMap.h" 19226890Sdim#include "clang/Serialization/Module.h" 20226890Sdim#include "clang/Serialization/ModuleManager.h" 21212795Sdim#include "clang/Sema/ExternalSemaSource.h" 22212795Sdim#include "clang/AST/DeclarationName.h" 23212795Sdim#include "clang/AST/DeclObjC.h" 24212795Sdim#include "clang/AST/TemplateBase.h" 25212795Sdim#include "clang/Lex/ExternalPreprocessorSource.h" 26218893Sdim#include "clang/Lex/HeaderSearch.h" 27245431Sdim#include "clang/Lex/PPMutationListener.h" 28212795Sdim#include "clang/Lex/PreprocessingRecord.h" 29212795Sdim#include "clang/Basic/Diagnostic.h" 30226890Sdim#include "clang/Basic/FileManager.h" 31226890Sdim#include "clang/Basic/FileSystemOptions.h" 32212795Sdim#include "clang/Basic/IdentifierTable.h" 33212795Sdim#include "clang/Basic/SourceManager.h" 34212795Sdim#include "llvm/ADT/APFloat.h" 35212795Sdim#include "llvm/ADT/APInt.h" 36212795Sdim#include "llvm/ADT/APSInt.h" 37245431Sdim#include "llvm/ADT/MapVector.h" 38212795Sdim#include "llvm/ADT/OwningPtr.h" 39235633Sdim#include "llvm/ADT/SmallPtrSet.h" 40235633Sdim#include "llvm/ADT/SmallSet.h" 41212795Sdim#include "llvm/ADT/SmallVector.h" 42212795Sdim#include "llvm/ADT/StringRef.h" 43226890Sdim#include "llvm/ADT/DenseSet.h" 44212795Sdim#include "llvm/Bitcode/BitstreamReader.h" 45218893Sdim#include "llvm/Support/DataTypes.h" 46212795Sdim#include <deque> 47212795Sdim#include <map> 48212795Sdim#include <string> 49212795Sdim#include <utility> 50212795Sdim#include <vector> 51212795Sdim 52212795Sdimnamespace llvm { 53212795Sdim class MemoryBuffer; 54212795Sdim} 55212795Sdim 56212795Sdimnamespace clang { 57212795Sdim 58212795Sdimclass AddrLabelExpr; 59212795Sdimclass ASTConsumer; 60212795Sdimclass ASTContext; 61218893Sdimclass ASTIdentifierIterator; 62226890Sdimclass ASTUnit; // FIXME: Layering violation and egregious hack. 63212795Sdimclass Attr; 64212795Sdimclass Decl; 65212795Sdimclass DeclContext; 66245431Sdimclass DiagnosticOptions; 67212795Sdimclass NestedNameSpecifier; 68212795Sdimclass CXXBaseSpecifier; 69223017Sdimclass CXXConstructorDecl; 70218893Sdimclass CXXCtorInitializer; 71212795Sdimclass GotoStmt; 72212795Sdimclass MacroDefinition; 73212795Sdimclass NamedDecl; 74218893Sdimclass OpaqueValueExpr; 75212795Sdimclass Preprocessor; 76245431Sdimclass PreprocessorOptions; 77212795Sdimclass Sema; 78212795Sdimclass SwitchCase; 79218893Sdimclass ASTDeserializationListener; 80226890Sdimclass ASTWriter; 81212795Sdimclass ASTReader; 82212795Sdimclass ASTDeclReader; 83218893Sdimclass ASTStmtReader; 84218893Sdimclass TypeLocReader; 85212795Sdimstruct HeaderFileInfo; 86221345Sdimclass VersionTuple; 87245431Sdimclass TargetOptions; 88212795Sdim 89212795Sdim/// \brief Abstract interface for callback invocations by the ASTReader. 90212795Sdim/// 91212795Sdim/// While reading an AST file, the ASTReader will call the methods of the 92212795Sdim/// listener to pass on specific information. Some of the listener methods can 93212795Sdim/// return true to indicate to the ASTReader that the information (and 94212795Sdim/// consequently the AST file) is invalid. 95212795Sdimclass ASTReaderListener { 96212795Sdimpublic: 97212795Sdim virtual ~ASTReaderListener(); 98212795Sdim 99212795Sdim /// \brief Receives the language options. 100212795Sdim /// 101212795Sdim /// \returns true to indicate the options are invalid or false otherwise. 102245431Sdim virtual bool ReadLanguageOptions(const LangOptions &LangOpts, 103245431Sdim bool Complain) { 104212795Sdim return false; 105212795Sdim } 106212795Sdim 107245431Sdim /// \brief Receives the target options. 108212795Sdim /// 109245431Sdim /// \returns true to indicate the target options are invalid, or false 110245431Sdim /// otherwise. 111245431Sdim virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, 112245431Sdim bool Complain) { 113212795Sdim return false; 114212795Sdim } 115212795Sdim 116245431Sdim /// \brief Receives the diagnostic options. 117212795Sdim /// 118245431Sdim /// \returns true to indicate the diagnostic options are invalid, or false 119245431Sdim /// otherwise. 120245431Sdim virtual bool ReadDiagnosticOptions(const DiagnosticOptions &DiagOpts, 121245431Sdim bool Complain) { 122245431Sdim return false; 123245431Sdim } 124245431Sdim 125245431Sdim /// \brief Receives the file system options. 126212795Sdim /// 127245431Sdim /// \returns true to indicate the file system options are invalid, or false 128245431Sdim /// otherwise. 129245431Sdim virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts, 130245431Sdim bool Complain) { 131245431Sdim return false; 132245431Sdim } 133245431Sdim 134245431Sdim /// \brief Receives the header search options. 135212795Sdim /// 136245431Sdim /// \returns true to indicate the header search options are invalid, or false 137245431Sdim /// otherwise. 138245431Sdim virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, 139245431Sdim bool Complain) { 140245431Sdim return false; 141245431Sdim } 142245431Sdim 143245431Sdim /// \brief Receives the preprocessor options. 144212795Sdim /// 145245431Sdim /// \param SuggestedPredefines Can be filled in with the set of predefines 146245431Sdim /// that are suggested by the preprocessor options. Typically only used when 147245431Sdim /// loading a precompiled header. 148245431Sdim /// 149245431Sdim /// \returns true to indicate the preprocessor options are invalid, or false 150245431Sdim /// otherwise. 151245431Sdim virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, 152245431Sdim bool Complain, 153245431Sdim std::string &SuggestedPredefines) { 154212795Sdim return false; 155212795Sdim } 156212795Sdim 157212795Sdim /// \brief Receives a HeaderFileInfo entry. 158212795Sdim virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID) {} 159212795Sdim 160212795Sdim /// \brief Receives __COUNTER__ value. 161245431Sdim virtual void ReadCounter(const serialization::ModuleFile &M, 162245431Sdim unsigned Value) {} 163212795Sdim}; 164212795Sdim 165212795Sdim/// \brief ASTReaderListener implementation to validate the information of 166212795Sdim/// the PCH file against an initialized Preprocessor. 167212795Sdimclass PCHValidator : public ASTReaderListener { 168212795Sdim Preprocessor &PP; 169212795Sdim ASTReader &Reader; 170212795Sdim 171212795Sdim unsigned NumHeaderInfos; 172212795Sdim 173212795Sdimpublic: 174212795Sdim PCHValidator(Preprocessor &PP, ASTReader &Reader) 175212795Sdim : PP(PP), Reader(Reader), NumHeaderInfos(0) {} 176212795Sdim 177245431Sdim virtual bool ReadLanguageOptions(const LangOptions &LangOpts, 178245431Sdim bool Complain); 179245431Sdim virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, 180245431Sdim bool Complain); 181245431Sdim virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, 182245431Sdim bool Complain, 183245431Sdim std::string &SuggestedPredefines); 184212795Sdim virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID); 185245431Sdim virtual void ReadCounter(const serialization::ModuleFile &M, unsigned Value); 186212795Sdim 187212795Sdimprivate: 188212795Sdim void Error(const char *Msg); 189212795Sdim}; 190212795Sdim 191235633Sdimnamespace serialization { 192226890Sdim 193226890Sdimclass ReadMethodPoolVisitor; 194235633Sdim 195226890Sdimnamespace reader { 196226890Sdim class ASTIdentifierLookupTrait; 197235633Sdim /// \brief The on-disk hash table used for the DeclContext's Name lookup table. 198235633Sdim typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait> 199235633Sdim ASTDeclContextNameLookupTable; 200226890Sdim} 201235633Sdim 202226890Sdim} // end namespace serialization 203235633Sdim 204212795Sdim/// \brief Reads an AST files chain containing the contents of a translation 205212795Sdim/// unit. 206212795Sdim/// 207212795Sdim/// The ASTReader class reads bitstreams (produced by the ASTWriter 208212795Sdim/// class) containing the serialized representation of a given 209212795Sdim/// abstract syntax tree and its supporting data structures. An 210212795Sdim/// instance of the ASTReader can be attached to an ASTContext object, 211212795Sdim/// which will provide access to the contents of the AST files. 212212795Sdim/// 213212795Sdim/// The AST reader provides lazy de-serialization of declarations, as 214212795Sdim/// required when traversing the AST. Only those AST nodes that are 215212795Sdim/// actually required will be de-serialized. 216212795Sdimclass ASTReader 217212795Sdim : public ExternalPreprocessorSource, 218212795Sdim public ExternalPreprocessingRecordSource, 219218893Sdim public ExternalHeaderFileInfoSource, 220212795Sdim public ExternalSemaSource, 221212795Sdim public IdentifierInfoLookup, 222212795Sdim public ExternalIdentifierLookup, 223235633Sdim public ExternalSLocEntrySource 224218893Sdim{ 225212795Sdimpublic: 226245431Sdim typedef SmallVector<uint64_t, 64> RecordData; 227245431Sdim 228245431Sdim /// \brief The result of reading the control block of an AST file, which 229245431Sdim /// can fail for various reasons. 230245431Sdim enum ASTReadResult { 231245431Sdim /// \brief The control block was read successfully. Aside from failures, 232245431Sdim /// the AST file is safe to read into the current context. 233245431Sdim Success, 234245431Sdim /// \brief The AST file itself appears corrupted. 235245431Sdim Failure, 236245431Sdim /// \brief The AST file is out-of-date relative to its input files, 237245431Sdim /// and needs to be regenerated. 238245431Sdim OutOfDate, 239245431Sdim /// \brief The AST file was written by a different version of Clang. 240245431Sdim VersionMismatch, 241245431Sdim /// \brief The AST file was writtten with a different language/target 242245431Sdim /// configuration. 243245431Sdim ConfigurationMismatch, 244245431Sdim /// \brief The AST file has errors. 245245431Sdim HadErrors 246245431Sdim }; 247245431Sdim 248218893Sdim /// \brief Types of AST files. 249212795Sdim friend class PCHValidator; 250212795Sdim friend class ASTDeclReader; 251218893Sdim friend class ASTStmtReader; 252218893Sdim friend class ASTIdentifierIterator; 253226890Sdim friend class serialization::reader::ASTIdentifierLookupTrait; 254218893Sdim friend class TypeLocReader; 255226890Sdim friend class ASTWriter; 256226890Sdim friend class ASTUnit; // ASTUnit needs to remap source locations. 257226890Sdim friend class serialization::ReadMethodPoolVisitor; 258235633Sdim 259235633Sdim typedef serialization::ModuleFile ModuleFile; 260226890Sdim typedef serialization::ModuleKind ModuleKind; 261226890Sdim typedef serialization::ModuleManager ModuleManager; 262235633Sdim 263226890Sdim typedef ModuleManager::ModuleIterator ModuleIterator; 264226890Sdim typedef ModuleManager::ModuleConstIterator ModuleConstIterator; 265226890Sdim typedef ModuleManager::ModuleReverseIterator ModuleReverseIterator; 266226890Sdim 267212795Sdimprivate: 268212795Sdim /// \brief The receiver of some callbacks invoked by ASTReader. 269235633Sdim OwningPtr<ASTReaderListener> Listener; 270212795Sdim 271212795Sdim /// \brief The receiver of deserialization events. 272212795Sdim ASTDeserializationListener *DeserializationListener; 273212795Sdim 274212795Sdim SourceManager &SourceMgr; 275212795Sdim FileManager &FileMgr; 276226890Sdim DiagnosticsEngine &Diags; 277235633Sdim 278212795Sdim /// \brief The semantic analysis object that will be processing the 279212795Sdim /// AST files and the translation unit that uses it. 280212795Sdim Sema *SemaObj; 281212795Sdim 282212795Sdim /// \brief The preprocessor that will be loading the source file. 283226890Sdim Preprocessor &PP; 284212795Sdim 285212795Sdim /// \brief The AST context into which we'll read the AST files. 286226890Sdim ASTContext &Context; 287235633Sdim 288212795Sdim /// \brief The AST consumer. 289212795Sdim ASTConsumer *Consumer; 290212795Sdim 291226890Sdim /// \brief The module manager which manages modules and their dependencies 292226890Sdim ModuleManager ModuleMgr; 293221345Sdim 294226890Sdim /// \brief A map of global bit offsets to the module that stores entities 295226890Sdim /// at those bit offsets. 296235633Sdim ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap; 297212795Sdim 298226890Sdim /// \brief A map of negated SLocEntryIDs to the modules containing them. 299235633Sdim ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap; 300212795Sdim 301235633Sdim typedef ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocOffsetMapType; 302235633Sdim 303226890Sdim /// \brief A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset) 304226890Sdim /// SourceLocation offsets to the modules containing them. 305226890Sdim GlobalSLocOffsetMapType GlobalSLocOffsetMap; 306235633Sdim 307212795Sdim /// \brief Types that have already been loaded from the chain. 308212795Sdim /// 309212795Sdim /// When the pointer at index I is non-NULL, the type with 310212795Sdim /// ID = (I + 1) << FastQual::Width has already been loaded 311212795Sdim std::vector<QualType> TypesLoaded; 312212795Sdim 313235633Sdim typedef ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4> 314226890Sdim GlobalTypeMapType; 315212795Sdim 316226890Sdim /// \brief Mapping from global type IDs to the module in which the 317226890Sdim /// type resides along with the offset that should be added to the 318226890Sdim /// global type ID to produce a local ID. 319226890Sdim GlobalTypeMapType GlobalTypeMap; 320226890Sdim 321212795Sdim /// \brief Declarations that have already been loaded from the chain. 322212795Sdim /// 323212795Sdim /// When the pointer at index I is non-NULL, the declaration with ID 324212795Sdim /// = I + 1 has already been loaded. 325212795Sdim std::vector<Decl *> DeclsLoaded; 326212795Sdim 327235633Sdim typedef ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4> 328226890Sdim GlobalDeclMapType; 329235633Sdim 330226890Sdim /// \brief Mapping from global declaration IDs to the module in which the 331226890Sdim /// declaration resides. 332226890Sdim GlobalDeclMapType GlobalDeclMap; 333235633Sdim 334235633Sdim typedef std::pair<ModuleFile *, uint64_t> FileOffset; 335226890Sdim typedef SmallVector<FileOffset, 2> FileOffsetsTy; 336218893Sdim typedef llvm::DenseMap<serialization::DeclID, FileOffsetsTy> 337218893Sdim DeclUpdateOffsetsMap; 338235633Sdim 339218893Sdim /// \brief Declarations that have modifications residing in a later file 340218893Sdim /// in the chain. 341218893Sdim DeclUpdateOffsetsMap DeclUpdateOffsets; 342218893Sdim 343235633Sdim struct ReplacedDeclInfo { 344235633Sdim ModuleFile *Mod; 345235633Sdim uint64_t Offset; 346235633Sdim unsigned RawLoc; 347235633Sdim 348235633Sdim ReplacedDeclInfo() : Mod(0), Offset(0), RawLoc(0) {} 349235633Sdim ReplacedDeclInfo(ModuleFile *Mod, uint64_t Offset, unsigned RawLoc) 350235633Sdim : Mod(Mod), Offset(Offset), RawLoc(RawLoc) {} 351235633Sdim }; 352235633Sdim 353235633Sdim typedef llvm::DenseMap<serialization::DeclID, ReplacedDeclInfo> 354212795Sdim DeclReplacementMap; 355212795Sdim /// \brief Declarations that have been replaced in a later file in the chain. 356212795Sdim DeclReplacementMap ReplacedDecls; 357212795Sdim 358235633Sdim struct FileDeclsInfo { 359235633Sdim ModuleFile *Mod; 360235633Sdim ArrayRef<serialization::LocalDeclID> Decls; 361235633Sdim 362235633Sdim FileDeclsInfo() : Mod(0) {} 363235633Sdim FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls) 364235633Sdim : Mod(Mod), Decls(Decls) {} 365235633Sdim }; 366235633Sdim 367235633Sdim /// \brief Map from a FileID to the file-level declarations that it contains. 368235633Sdim llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs; 369235633Sdim 370212795Sdim // Updates for visible decls can occur for other contexts than just the 371212795Sdim // TU, and when we read those update records, the actual context will not 372212795Sdim // be available yet (unless it's the TU), so have this pending map using the 373212795Sdim // ID as a key. It will be realized when the context is actually loaded. 374235633Sdim typedef 375235633Sdim SmallVector<std::pair<serialization::reader::ASTDeclContextNameLookupTable *, 376235633Sdim ModuleFile*>, 1> DeclContextVisibleUpdates; 377212795Sdim typedef llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates> 378212795Sdim DeclContextVisibleUpdatesPending; 379212795Sdim 380212795Sdim /// \brief Updates to the visible declarations of declaration contexts that 381212795Sdim /// haven't been loaded yet. 382212795Sdim DeclContextVisibleUpdatesPending PendingVisibleUpdates; 383235633Sdim 384235633Sdim /// \brief The set of C++ or Objective-C classes that have forward 385235633Sdim /// declarations that have not yet been linked to their definitions. 386235633Sdim llvm::SmallPtrSet<Decl *, 4> PendingDefinitions; 387245431Sdim 388245431Sdim typedef llvm::MapVector<Decl *, uint64_t, 389245431Sdim llvm::SmallDenseMap<Decl *, unsigned, 4>, 390245431Sdim llvm::SmallVector<std::pair<Decl *, uint64_t>, 4> > 391245431Sdim PendingBodiesMap; 392245431Sdim 393245431Sdim /// \brief Functions or methods that have bodies that will be attached. 394245431Sdim PendingBodiesMap PendingBodies; 395245431Sdim 396212795Sdim /// \brief Read the records that describe the contents of declcontexts. 397235633Sdim bool ReadDeclContextStorage(ModuleFile &M, 398226890Sdim llvm::BitstreamCursor &Cursor, 399212795Sdim const std::pair<uint64_t, uint64_t> &Offsets, 400226890Sdim serialization::DeclContextInfo &Info); 401212795Sdim 402212795Sdim /// \brief A vector containing identifiers that have already been 403212795Sdim /// loaded. 404212795Sdim /// 405212795Sdim /// If the pointer at index I is non-NULL, then it refers to the 406212795Sdim /// IdentifierInfo for the identifier with ID=I+1 that has already 407212795Sdim /// been loaded. 408212795Sdim std::vector<IdentifierInfo *> IdentifiersLoaded; 409212795Sdim 410235633Sdim typedef ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4> 411226890Sdim GlobalIdentifierMapType; 412235633Sdim 413245431Sdim /// \brief Mapping from global identifier IDs to the module in which the 414226890Sdim /// identifier resides along with the offset that should be added to the 415226890Sdim /// global identifier ID to produce a local ID. 416226890Sdim GlobalIdentifierMapType GlobalIdentifierMap; 417226890Sdim 418245431Sdim /// \brief A vector containing macros that have already been 419245431Sdim /// loaded. 420245431Sdim /// 421245431Sdim /// If the pointer at index I is non-NULL, then it refers to the 422245431Sdim /// MacroInfo for the identifier with ID=I+1 that has already 423245431Sdim /// been loaded. 424245431Sdim std::vector<MacroInfo *> MacrosLoaded; 425245431Sdim 426245431Sdim typedef ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4> 427245431Sdim GlobalMacroMapType; 428245431Sdim 429245431Sdim /// \brief Mapping from global macro IDs to the module in which the 430245431Sdim /// macro resides along with the offset that should be added to the 431245431Sdim /// global macro ID to produce a local ID. 432245431Sdim GlobalMacroMapType GlobalMacroMap; 433245431Sdim 434245431Sdim typedef llvm::DenseMap<serialization::MacroID, 435245431Sdim llvm::SmallVector<std::pair<serialization::SubmoduleID, 436245431Sdim MacroUpdate>, 1> > 437245431Sdim MacroUpdatesMap; 438245431Sdim 439245431Sdim /// \brief Mapping from (global) macro IDs to the set of updates to be 440245431Sdim /// performed to the corresponding macro. 441245431Sdim MacroUpdatesMap MacroUpdates; 442245431Sdim 443235633Sdim /// \brief A vector containing submodules that have already been loaded. 444235633Sdim /// 445235633Sdim /// This vector is indexed by the Submodule ID (-1). NULL submodule entries 446235633Sdim /// indicate that the particular submodule ID has not yet been loaded. 447235633Sdim SmallVector<Module *, 2> SubmodulesLoaded; 448235633Sdim 449235633Sdim typedef ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4> 450235633Sdim GlobalSubmoduleMapType; 451235633Sdim 452235633Sdim /// \brief Mapping from global submodule IDs to the module file in which the 453235633Sdim /// submodule resides along with the offset that should be added to the 454235633Sdim /// global submodule ID to produce a local ID. 455235633Sdim GlobalSubmoduleMapType GlobalSubmoduleMap; 456235633Sdim 457245431Sdim /// \brief An entity that has been hidden. 458245431Sdim class HiddenName { 459245431Sdim public: 460245431Sdim enum NameKind { 461245431Sdim Declaration, 462245431Sdim MacroVisibility, 463245431Sdim MacroUndef 464245431Sdim } Kind; 465245431Sdim 466245431Sdim private: 467245431Sdim unsigned Loc; 468245431Sdim 469245431Sdim union { 470245431Sdim Decl *D; 471245431Sdim MacroInfo *MI; 472245431Sdim }; 473245431Sdim 474245431Sdim IdentifierInfo *Id; 475245431Sdim 476245431Sdim public: 477245431Sdim HiddenName(Decl *D) : Kind(Declaration), Loc(), D(D), Id() { } 478245431Sdim 479245431Sdim HiddenName(IdentifierInfo *II, MacroInfo *MI) 480245431Sdim : Kind(MacroVisibility), Loc(), MI(MI), Id(II) { } 481245431Sdim 482245431Sdim HiddenName(IdentifierInfo *II, MacroInfo *MI, SourceLocation Loc) 483245431Sdim : Kind(MacroUndef), Loc(Loc.getRawEncoding()), MI(MI), Id(II) { } 484245431Sdim 485245431Sdim NameKind getKind() const { return Kind; } 486245431Sdim 487245431Sdim Decl *getDecl() const { 488245431Sdim assert(getKind() == Declaration && "Hidden name is not a declaration"); 489245431Sdim return D; 490245431Sdim } 491245431Sdim 492245431Sdim std::pair<IdentifierInfo *, MacroInfo *> getMacro() const { 493245431Sdim assert((getKind() == MacroUndef || getKind() == MacroVisibility) 494245431Sdim && "Hidden name is not a macro!"); 495245431Sdim return std::make_pair(Id, MI); 496245431Sdim } 497245431Sdim 498245431Sdim SourceLocation getMacroUndefLoc() const { 499245431Sdim assert(getKind() == MacroUndef && "Hidden name is not an undef!"); 500245431Sdim return SourceLocation::getFromRawEncoding(Loc); 501245431Sdim } 502245431Sdim}; 503245431Sdim 504235633Sdim /// \brief A set of hidden declarations. 505245431Sdim typedef llvm::SmallVector<HiddenName, 2> 506235633Sdim HiddenNames; 507235633Sdim 508235633Sdim typedef llvm::DenseMap<Module *, HiddenNames> HiddenNamesMapType; 509235633Sdim 510235633Sdim /// \brief A mapping from each of the hidden submodules to the deserialized 511235633Sdim /// declarations in that submodule that could be made visible. 512235633Sdim HiddenNamesMapType HiddenNamesMap; 513235633Sdim 514235633Sdim 515235633Sdim /// \brief A module import or export that hasn't yet been resolved. 516235633Sdim struct UnresolvedModuleImportExport { 517235633Sdim /// \brief The file in which this module resides. 518235633Sdim ModuleFile *File; 519235633Sdim 520235633Sdim /// \brief The module that is importing or exporting. 521235633Sdim Module *Mod; 522235633Sdim 523235633Sdim /// \brief The local ID of the module that is being exported. 524235633Sdim unsigned ID; 525235633Sdim 526235633Sdim /// \brief Whether this is an import (vs. an export). 527235633Sdim unsigned IsImport : 1; 528235633Sdim 529235633Sdim /// \brief Whether this is a wildcard export. 530235633Sdim unsigned IsWildcard : 1; 531235633Sdim }; 532235633Sdim 533235633Sdim /// \brief The set of module imports and exports that still need to be 534235633Sdim /// resolved. 535235633Sdim llvm::SmallVector<UnresolvedModuleImportExport, 2> 536235633Sdim UnresolvedModuleImportExports; 537235633Sdim 538212795Sdim /// \brief A vector containing selectors that have already been loaded. 539212795Sdim /// 540212795Sdim /// This vector is indexed by the Selector ID (-1). NULL selector 541212795Sdim /// entries indicate that the particular selector ID has not yet 542212795Sdim /// been loaded. 543226890Sdim SmallVector<Selector, 16> SelectorsLoaded; 544212795Sdim 545235633Sdim typedef ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4> 546226890Sdim GlobalSelectorMapType; 547235633Sdim 548226890Sdim /// \brief Mapping from global selector IDs to the module in which the 549226890Sdim /// selector resides along with the offset that should be added to the 550226890Sdim /// global selector ID to produce a local ID. 551226890Sdim GlobalSelectorMapType GlobalSelectorMap; 552212795Sdim 553235633Sdim /// \brief The generation number of the last time we loaded data from the 554235633Sdim /// global method pool for this selector. 555235633Sdim llvm::DenseMap<Selector, unsigned> SelectorGeneration; 556235633Sdim 557245431Sdim typedef llvm::MapVector<IdentifierInfo *, 558245431Sdim llvm::SmallVector<serialization::MacroID, 2> > 559245431Sdim PendingMacroIDsMap; 560226890Sdim 561245431Sdim /// \brief Mapping from identifiers that have a macro history to the global 562245431Sdim /// IDs have not yet been deserialized to the global IDs of those macros. 563245431Sdim PendingMacroIDsMap PendingMacroIDs; 564245431Sdim 565235633Sdim typedef ContinuousRangeMap<unsigned, ModuleFile *, 4> 566226890Sdim GlobalPreprocessedEntityMapType; 567235633Sdim 568226890Sdim /// \brief Mapping from global preprocessing entity IDs to the module in 569226890Sdim /// which the preprocessed entity resides along with the offset that should be 570226890Sdim /// added to the global preprocessing entitiy ID to produce a local ID. 571226890Sdim GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap; 572235633Sdim 573212795Sdim /// \name CodeGen-relevant special data 574212795Sdim /// \brief Fields containing data that is relevant to CodeGen. 575212795Sdim //@{ 576212795Sdim 577212795Sdim /// \brief The IDs of all declarations that fulfill the criteria of 578212795Sdim /// "interesting" decls. 579212795Sdim /// 580212795Sdim /// This contains the data loaded from all EXTERNAL_DEFINITIONS blocks in the 581212795Sdim /// chain. The referenced declarations are deserialized and passed to the 582212795Sdim /// consumer eagerly. 583226890Sdim SmallVector<uint64_t, 16> ExternalDefinitions; 584212795Sdim 585245431Sdim /// \brief The IDs of all tentative definitions stored in the chain. 586212795Sdim /// 587212795Sdim /// Sema keeps track of all tentative definitions in a TU because it has to 588212795Sdim /// complete them and pass them on to CodeGen. Thus, tentative definitions in 589212795Sdim /// the PCH chain must be eagerly deserialized. 590226890Sdim SmallVector<uint64_t, 16> TentativeDefinitions; 591212795Sdim 592212795Sdim /// \brief The IDs of all CXXRecordDecls stored in the chain whose VTables are 593212795Sdim /// used. 594212795Sdim /// 595212795Sdim /// CodeGen has to emit VTables for these records, so they have to be eagerly 596212795Sdim /// deserialized. 597226890Sdim SmallVector<uint64_t, 64> VTableUses; 598212795Sdim 599226890Sdim /// \brief A snapshot of the pending instantiations in the chain. 600226890Sdim /// 601226890Sdim /// This record tracks the instantiations that Sema has to perform at the 602226890Sdim /// end of the TU. It consists of a pair of values for every pending 603226890Sdim /// instantiation where the first value is the ID of the decl and the second 604226890Sdim /// is the instantiation location. 605226890Sdim SmallVector<uint64_t, 64> PendingInstantiations; 606226890Sdim 607212795Sdim //@} 608212795Sdim 609226890Sdim /// \name DiagnosticsEngine-relevant special data 610212795Sdim /// \brief Fields containing data that is used for generating diagnostics 611212795Sdim //@{ 612212795Sdim 613212795Sdim /// \brief A snapshot of Sema's unused file-scoped variable tracking, for 614212795Sdim /// generating warnings. 615226890Sdim SmallVector<uint64_t, 16> UnusedFileScopedDecls; 616212795Sdim 617223017Sdim /// \brief A list of all the delegating constructors we've seen, to diagnose 618223017Sdim /// cycles. 619226890Sdim SmallVector<uint64_t, 4> DelegatingCtorDecls; 620235633Sdim 621226890Sdim /// \brief Method selectors used in a @selector expression. Used for 622226890Sdim /// implementation of -Wselector. 623226890Sdim SmallVector<uint64_t, 64> ReferencedSelectorsData; 624223017Sdim 625212795Sdim /// \brief A snapshot of Sema's weak undeclared identifier tracking, for 626212795Sdim /// generating warnings. 627226890Sdim SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers; 628212795Sdim 629212795Sdim /// \brief The IDs of type aliases for ext_vectors that exist in the chain. 630212795Sdim /// 631212795Sdim /// Used by Sema for finding sugared names for ext_vectors in diagnostics. 632226890Sdim SmallVector<uint64_t, 4> ExtVectorDecls; 633212795Sdim 634212795Sdim //@} 635212795Sdim 636212795Sdim /// \name Sema-relevant special data 637212795Sdim /// \brief Fields containing data that is used for semantic analysis 638212795Sdim //@{ 639212795Sdim 640212795Sdim /// \brief The IDs of all locally scoped external decls in the chain. 641212795Sdim /// 642212795Sdim /// Sema tracks these to validate that the types are consistent across all 643212795Sdim /// local external declarations. 644226890Sdim SmallVector<uint64_t, 16> LocallyScopedExternalDecls; 645212795Sdim 646212795Sdim /// \brief The IDs of all dynamic class declarations in the chain. 647212795Sdim /// 648212795Sdim /// Sema tracks these because it checks for the key functions being defined 649212795Sdim /// at the end of the TU, in which case it directs CodeGen to emit the VTable. 650226890Sdim SmallVector<uint64_t, 16> DynamicClasses; 651212795Sdim 652212795Sdim /// \brief The IDs of the declarations Sema stores directly. 653212795Sdim /// 654212795Sdim /// Sema tracks a few important decls, such as namespace std, directly. 655226890Sdim SmallVector<uint64_t, 4> SemaDeclRefs; 656212795Sdim 657212795Sdim /// \brief The IDs of the types ASTContext stores directly. 658212795Sdim /// 659212795Sdim /// The AST context tracks a few important types, such as va_list, directly. 660226890Sdim SmallVector<uint64_t, 16> SpecialTypes; 661212795Sdim 662218893Sdim /// \brief The IDs of CUDA-specific declarations ASTContext stores directly. 663218893Sdim /// 664218893Sdim /// The AST context tracks a few important decls, currently cudaConfigureCall, 665218893Sdim /// directly. 666226890Sdim SmallVector<uint64_t, 2> CUDASpecialDeclRefs; 667218893Sdim 668218893Sdim /// \brief The floating point pragma option settings. 669226890Sdim SmallVector<uint64_t, 1> FPPragmaOptions; 670218893Sdim 671218893Sdim /// \brief The OpenCL extension settings. 672226890Sdim SmallVector<uint64_t, 1> OpenCLExtensions; 673218893Sdim 674224145Sdim /// \brief A list of the namespaces we've seen. 675226890Sdim SmallVector<uint64_t, 4> KnownNamespaces; 676224145Sdim 677235633Sdim /// \brief A list of modules that were imported by precompiled headers or 678235633Sdim /// any other non-module AST file. 679235633Sdim SmallVector<serialization::SubmoduleID, 2> ImportedModules; 680212795Sdim //@} 681212795Sdim 682218893Sdim /// \brief The directory that the PCH we are reading is stored in. 683218893Sdim std::string CurrentDir; 684218893Sdim 685212795Sdim /// \brief The system include root to be used when loading the 686212795Sdim /// precompiled header. 687226890Sdim std::string isysroot; 688212795Sdim 689212795Sdim /// \brief Whether to disable the normal validation performed on precompiled 690212795Sdim /// headers when they are loaded. 691212795Sdim bool DisableValidation; 692235633Sdim 693235633Sdim /// \brief Whether to accept an AST file with compiler errors. 694235633Sdim bool AllowASTWithCompilerErrors; 695235633Sdim 696235633Sdim /// \brief The current "generation" of the module file import stack, which 697235633Sdim /// indicates how many separate module file load operations have occurred. 698235633Sdim unsigned CurrentGeneration; 699235633Sdim 700245431Sdim typedef llvm::DenseMap<unsigned, SwitchCase *> SwitchCaseMapTy; 701212795Sdim /// \brief Mapping from switch-case IDs in the chain to switch-case statements 702212795Sdim /// 703212795Sdim /// Statements usually don't have IDs, but switch cases need them, so that the 704212795Sdim /// switch statement can refer to them. 705245431Sdim SwitchCaseMapTy SwitchCaseStmts; 706212795Sdim 707245431Sdim SwitchCaseMapTy *CurrSwitchCaseStmts; 708212795Sdim 709212795Sdim /// \brief The number of source location entries de-serialized from 710212795Sdim /// the PCH file. 711212795Sdim unsigned NumSLocEntriesRead; 712212795Sdim 713212795Sdim /// \brief The number of source location entries in the chain. 714212795Sdim unsigned TotalNumSLocEntries; 715212795Sdim 716212795Sdim /// \brief The number of statements (and expressions) de-serialized 717212795Sdim /// from the chain. 718212795Sdim unsigned NumStatementsRead; 719212795Sdim 720212795Sdim /// \brief The total number of statements (and expressions) stored 721212795Sdim /// in the chain. 722212795Sdim unsigned TotalNumStatements; 723212795Sdim 724212795Sdim /// \brief The number of macros de-serialized from the chain. 725212795Sdim unsigned NumMacrosRead; 726212795Sdim 727212795Sdim /// \brief The total number of macros stored in the chain. 728212795Sdim unsigned TotalNumMacros; 729212795Sdim 730212795Sdim /// \brief The number of selectors that have been read. 731212795Sdim unsigned NumSelectorsRead; 732212795Sdim 733212795Sdim /// \brief The number of method pool entries that have been read. 734212795Sdim unsigned NumMethodPoolEntriesRead; 735212795Sdim 736212795Sdim /// \brief The number of times we have looked up a selector in the method 737212795Sdim /// pool and not found anything interesting. 738212795Sdim unsigned NumMethodPoolMisses; 739212795Sdim 740212795Sdim /// \brief The total number of method pool entries in the selector table. 741212795Sdim unsigned TotalNumMethodPoolEntries; 742212795Sdim 743212795Sdim /// Number of lexical decl contexts read/total. 744212795Sdim unsigned NumLexicalDeclContextsRead, TotalLexicalDeclContexts; 745212795Sdim 746212795Sdim /// Number of visible decl contexts read/total. 747212795Sdim unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts; 748235633Sdim 749226890Sdim /// Total size of modules, in bits, currently loaded 750226890Sdim uint64_t TotalModulesSizeInBits; 751226890Sdim 752212795Sdim /// \brief Number of Decl/types that are currently deserializing. 753212795Sdim unsigned NumCurrentElementsDeserializing; 754212795Sdim 755235633Sdim /// \brief Set true while we are in the process of passing deserialized 756235633Sdim /// "interesting" decls to consumer inside FinishedDeserializing(). 757235633Sdim /// This is used as a guard to avoid recursively repeating the process of 758235633Sdim /// passing decls to consumer. 759235633Sdim bool PassingDeclsToConsumer; 760235633Sdim 761226890Sdim /// Number of CXX base specifiers currently loaded 762226890Sdim unsigned NumCXXBaseSpecifiersLoaded; 763226890Sdim 764212795Sdim /// \brief An IdentifierInfo that has been loaded but whose top-level 765212795Sdim /// declarations of the same name have not (yet) been loaded. 766212795Sdim struct PendingIdentifierInfo { 767212795Sdim IdentifierInfo *II; 768226890Sdim SmallVector<uint32_t, 4> DeclIDs; 769212795Sdim }; 770212795Sdim 771212795Sdim /// \brief The set of identifiers that were read while the AST reader was 772212795Sdim /// (recursively) loading declarations. 773212795Sdim /// 774212795Sdim /// The declarations on the identifier chain for these identifiers will be 775212795Sdim /// loaded once the recursive loading has completed. 776212795Sdim std::deque<PendingIdentifierInfo> PendingIdentifierInfos; 777212795Sdim 778235633Sdim /// \brief The generation number of each identifier, which keeps track of 779235633Sdim /// the last time we loaded information about this identifier. 780235633Sdim llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration; 781235633Sdim 782212795Sdim /// \brief Contains declarations and definitions that will be 783212795Sdim /// "interesting" to the ASTConsumer, when we get that AST consumer. 784212795Sdim /// 785212795Sdim /// "Interesting" declarations are those that have data that may 786212795Sdim /// need to be emitted, such as inline function definitions or 787212795Sdim /// Objective-C protocols. 788212795Sdim std::deque<Decl *> InterestingDecls; 789212795Sdim 790245431Sdim /// \brief The set of redeclarable declarations that have been deserialized 791235633Sdim /// since the last time the declaration chains were linked. 792235633Sdim llvm::SmallPtrSet<Decl *, 16> RedeclsDeserialized; 793235633Sdim 794235633Sdim /// \brief The list of redeclaration chains that still need to be 795235633Sdim /// reconstructed. 796235633Sdim /// 797235633Sdim /// Each element is the global declaration ID of the first declaration in 798235633Sdim /// the chain. Elements in this vector should be unique; use 799235633Sdim /// PendingDeclChainsKnown to ensure uniqueness. 800235633Sdim llvm::SmallVector<serialization::DeclID, 16> PendingDeclChains; 801218893Sdim 802235633Sdim /// \brief Keeps track of the elements added to PendingDeclChains. 803235633Sdim llvm::SmallSet<serialization::DeclID, 16> PendingDeclChainsKnown; 804235633Sdim 805235633Sdim /// \brief The set of Objective-C categories that have been deserialized 806235633Sdim /// since the last time the declaration chains were linked. 807235633Sdim llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized; 808235633Sdim 809235633Sdim /// \brief The set of Objective-C class definitions that have already been 810235633Sdim /// loaded, for which we will need to check for categories whenever a new 811235633Sdim /// module is loaded. 812235633Sdim llvm::SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded; 813235633Sdim 814235633Sdim typedef llvm::DenseMap<Decl *, llvm::SmallVector<serialization::DeclID, 2> > 815235633Sdim MergedDeclsMap; 816235633Sdim 817235633Sdim /// \brief A mapping from canonical declarations to the set of additional 818235633Sdim /// (global, previously-canonical) declaration IDs that have been merged with 819235633Sdim /// that canonical declaration. 820235633Sdim MergedDeclsMap MergedDecls; 821235633Sdim 822235633Sdim typedef llvm::DenseMap<serialization::GlobalDeclID, 823235633Sdim llvm::SmallVector<serialization::DeclID, 2> > 824235633Sdim StoredMergedDeclsMap; 825235633Sdim 826235633Sdim /// \brief A mapping from canonical declaration IDs to the set of additional 827235633Sdim /// declaration IDs that have been merged with that canonical declaration. 828235633Sdim /// 829235633Sdim /// This is the deserialized representation of the entries in MergedDecls. 830235633Sdim /// When we query entries in MergedDecls, they will be augmented with entries 831235633Sdim /// from StoredMergedDecls. 832235633Sdim StoredMergedDeclsMap StoredMergedDecls; 833235633Sdim 834235633Sdim /// \brief Combine the stored merged declarations for the given canonical 835235633Sdim /// declaration into the set of merged declarations. 836235633Sdim /// 837235633Sdim /// \returns An iterator into MergedDecls that corresponds to the position of 838235633Sdim /// the given canonical declaration. 839235633Sdim MergedDeclsMap::iterator 840235633Sdim combineStoredMergedDecls(Decl *Canon, serialization::GlobalDeclID CanonID); 841235633Sdim 842218893Sdim /// \brief Ready to load the previous declaration of the given Decl. 843218893Sdim void loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID); 844218893Sdim 845212795Sdim /// \brief When reading a Stmt tree, Stmt operands are placed in this stack. 846226890Sdim SmallVector<Stmt *, 16> StmtStack; 847212795Sdim 848212795Sdim /// \brief What kind of records we are reading. 849212795Sdim enum ReadingKind { 850212795Sdim Read_Decl, Read_Type, Read_Stmt 851212795Sdim }; 852212795Sdim 853235633Sdim /// \brief What kind of records we are reading. 854212795Sdim ReadingKind ReadingKind; 855212795Sdim 856212795Sdim /// \brief RAII object to change the reading kind. 857212795Sdim class ReadingKindTracker { 858212795Sdim ASTReader &Reader; 859212795Sdim enum ReadingKind PrevKind; 860212795Sdim 861245431Sdim ReadingKindTracker(const ReadingKindTracker &) LLVM_DELETED_FUNCTION; 862245431Sdim void operator=(const ReadingKindTracker &) LLVM_DELETED_FUNCTION; 863212795Sdim 864212795Sdim public: 865212795Sdim ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader) 866212795Sdim : Reader(reader), PrevKind(Reader.ReadingKind) { 867212795Sdim Reader.ReadingKind = newKind; 868212795Sdim } 869212795Sdim 870212795Sdim ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; } 871212795Sdim }; 872212795Sdim 873212795Sdim /// \brief Suggested contents of the predefines buffer, after this 874212795Sdim /// PCH file has been processed. 875212795Sdim /// 876212795Sdim /// In most cases, this string will be empty, because the predefines 877212795Sdim /// buffer computed to build the PCH file will be identical to the 878212795Sdim /// predefines buffer computed from the command line. However, when 879212795Sdim /// there are differences that the PCH reader can work around, this 880212795Sdim /// predefines buffer may contain additional definitions. 881212795Sdim std::string SuggestedPredefines; 882212795Sdim 883212795Sdim /// \brief Reads a statement from the specified cursor. 884235633Sdim Stmt *ReadStmtFromStream(ModuleFile &F); 885212795Sdim 886245431Sdim typedef llvm::PointerIntPair<const FileEntry *, 1, bool> InputFile; 887245431Sdim 888245431Sdim /// \brief Retrieve the file entry and 'overridden' bit for an input 889245431Sdim /// file in the given module file. 890245431Sdim InputFile getInputFile(ModuleFile &F, unsigned ID, bool Complain = true); 891245431Sdim 892223017Sdim /// \brief Get a FileEntry out of stored-in-PCH filename, making sure we take 893223017Sdim /// into account all the necessary relocations. 894226890Sdim const FileEntry *getFileEntry(StringRef filename); 895223017Sdim 896245431Sdim void MaybeAddSystemRootToFilename(ModuleFile &M, std::string &Filename); 897212795Sdim 898226890Sdim ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type, 899245431Sdim ModuleFile *ImportedBy, 900245431Sdim llvm::SmallVectorImpl<ModuleFile *> &Loaded, 901245431Sdim unsigned ClientLoadCapabilities); 902245431Sdim ASTReadResult ReadControlBlock(ModuleFile &F, 903245431Sdim llvm::SmallVectorImpl<ModuleFile *> &Loaded, 904245431Sdim unsigned ClientLoadCapabilities); 905245431Sdim bool ReadASTBlock(ModuleFile &F); 906235633Sdim bool ParseLineTable(ModuleFile &F, SmallVectorImpl<uint64_t> &Record); 907245431Sdim bool ReadSourceManagerBlock(ModuleFile &F); 908226890Sdim llvm::BitstreamCursor &SLocCursorForID(int ID); 909235633Sdim SourceLocation getImportLocation(ModuleFile *F); 910245431Sdim bool ReadSubmoduleBlock(ModuleFile &F); 911245431Sdim static bool ParseLanguageOptions(const RecordData &Record, bool Complain, 912245431Sdim ASTReaderListener &Listener); 913245431Sdim static bool ParseTargetOptions(const RecordData &Record, bool Complain, 914245431Sdim ASTReaderListener &Listener); 915245431Sdim static bool ParseDiagnosticOptions(const RecordData &Record, bool Complain, 916245431Sdim ASTReaderListener &Listener); 917245431Sdim static bool ParseFileSystemOptions(const RecordData &Record, bool Complain, 918245431Sdim ASTReaderListener &Listener); 919245431Sdim static bool ParseHeaderSearchOptions(const RecordData &Record, bool Complain, 920245431Sdim ASTReaderListener &Listener); 921245431Sdim static bool ParsePreprocessorOptions(const RecordData &Record, bool Complain, 922245431Sdim ASTReaderListener &Listener, 923245431Sdim std::string &SuggestedPredefines); 924245431Sdim 925218893Sdim struct RecordLocation { 926235633Sdim RecordLocation(ModuleFile *M, uint64_t O) 927218893Sdim : F(M), Offset(O) {} 928235633Sdim ModuleFile *F; 929218893Sdim uint64_t Offset; 930218893Sdim }; 931212795Sdim 932226890Sdim QualType readTypeRecord(unsigned Index); 933212795Sdim RecordLocation TypeCursorForIndex(unsigned Index); 934212795Sdim void LoadedDecl(unsigned Index, Decl *D); 935226890Sdim Decl *ReadDeclRecord(serialization::DeclID ID); 936235633Sdim RecordLocation DeclCursorForID(serialization::DeclID ID, 937235633Sdim unsigned &RawLocation); 938226890Sdim void loadDeclUpdateRecords(serialization::DeclID ID, Decl *D); 939235633Sdim void loadPendingDeclChain(serialization::GlobalDeclID ID); 940235633Sdim void loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D, 941235633Sdim unsigned PreviousGeneration = 0); 942235633Sdim 943226890Sdim RecordLocation getLocalBitOffset(uint64_t GlobalOffset); 944235633Sdim uint64_t getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset); 945212795Sdim 946245431Sdim /// \brief Returns the first preprocessed entity ID that ends after BLoc. 947226890Sdim serialization::PreprocessedEntityID 948226890Sdim findBeginPreprocessedEntity(SourceLocation BLoc) const; 949226890Sdim 950245431Sdim /// \brief Returns the first preprocessed entity ID that begins after ELoc. 951226890Sdim serialization::PreprocessedEntityID 952226890Sdim findEndPreprocessedEntity(SourceLocation ELoc) const; 953226890Sdim 954245431Sdim /// \brief Find the next module that contains entities and return the ID 955226890Sdim /// of the first entry. 956245431Sdim /// 957245431Sdim /// \param SLocMapI points at a chunk of a module that contains no 958245431Sdim /// preprocessed entities or the entities it contains are not the 959245431Sdim /// ones we are looking for. 960226890Sdim serialization::PreprocessedEntityID 961226890Sdim findNextPreprocessedEntity( 962226890Sdim GlobalSLocOffsetMapType::const_iterator SLocMapI) const; 963226890Sdim 964245431Sdim /// \brief Returns (ModuleFile, Local index) pair for \p GlobalIndex of a 965235633Sdim /// preprocessed entity. 966235633Sdim std::pair<ModuleFile *, unsigned> 967235633Sdim getModulePreprocessedEntity(unsigned GlobalIndex); 968235633Sdim 969245431Sdim /// \brief Returns (begin, end) pair for the preprocessed entities of a 970245431Sdim /// particular module. 971245431Sdim std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator> 972245431Sdim getModulePreprocessedEntities(ModuleFile &Mod) const; 973245431Sdim 974245431Sdim class ModuleDeclIterator { 975245431Sdim ASTReader *Reader; 976245431Sdim ModuleFile *Mod; 977245431Sdim const serialization::LocalDeclID *Pos; 978245431Sdim 979245431Sdim public: 980245431Sdim typedef const Decl *value_type; 981245431Sdim typedef value_type& reference; 982245431Sdim typedef value_type* pointer; 983245431Sdim 984245431Sdim ModuleDeclIterator() : Reader(0), Mod(0), Pos(0) { } 985245431Sdim 986245431Sdim ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod, 987245431Sdim const serialization::LocalDeclID *Pos) 988245431Sdim : Reader(Reader), Mod(Mod), Pos(Pos) { } 989245431Sdim 990245431Sdim value_type operator*() const { 991245431Sdim return Reader->GetDecl(Reader->getGlobalDeclID(*Mod, *Pos)); 992245431Sdim } 993245431Sdim 994245431Sdim ModuleDeclIterator &operator++() { 995245431Sdim ++Pos; 996245431Sdim return *this; 997245431Sdim } 998245431Sdim 999245431Sdim ModuleDeclIterator operator++(int) { 1000245431Sdim ModuleDeclIterator Prev(*this); 1001245431Sdim ++Pos; 1002245431Sdim return Prev; 1003245431Sdim } 1004245431Sdim 1005245431Sdim ModuleDeclIterator &operator--() { 1006245431Sdim --Pos; 1007245431Sdim return *this; 1008245431Sdim } 1009245431Sdim 1010245431Sdim ModuleDeclIterator operator--(int) { 1011245431Sdim ModuleDeclIterator Prev(*this); 1012245431Sdim --Pos; 1013245431Sdim return Prev; 1014245431Sdim } 1015245431Sdim 1016245431Sdim friend bool operator==(const ModuleDeclIterator &LHS, 1017245431Sdim const ModuleDeclIterator &RHS) { 1018245431Sdim assert(LHS.Reader == RHS.Reader && LHS.Mod == RHS.Mod); 1019245431Sdim return LHS.Pos == RHS.Pos; 1020245431Sdim } 1021245431Sdim 1022245431Sdim friend bool operator!=(const ModuleDeclIterator &LHS, 1023245431Sdim const ModuleDeclIterator &RHS) { 1024245431Sdim assert(LHS.Reader == RHS.Reader && LHS.Mod == RHS.Mod); 1025245431Sdim return LHS.Pos != RHS.Pos; 1026245431Sdim } 1027245431Sdim }; 1028245431Sdim 1029245431Sdim std::pair<ModuleDeclIterator, ModuleDeclIterator> 1030245431Sdim getModuleFileLevelDecls(ModuleFile &Mod); 1031245431Sdim 1032212795Sdim void PassInterestingDeclsToConsumer(); 1033235633Sdim void PassInterestingDeclToConsumer(Decl *D); 1034212795Sdim 1035235633Sdim void finishPendingActions(); 1036235633Sdim 1037212795Sdim /// \brief Produce an error diagnostic and return true. 1038212795Sdim /// 1039212795Sdim /// This routine should only be used for fatal errors that have to 1040212795Sdim /// do with non-routine failures (e.g., corrupted AST file). 1041226890Sdim void Error(StringRef Msg); 1042226890Sdim void Error(unsigned DiagID, StringRef Arg1 = StringRef(), 1043226890Sdim StringRef Arg2 = StringRef()); 1044212795Sdim 1045245431Sdim ASTReader(const ASTReader &) LLVM_DELETED_FUNCTION; 1046245431Sdim void operator=(const ASTReader &) LLVM_DELETED_FUNCTION; 1047212795Sdimpublic: 1048212795Sdim /// \brief Load the AST file and validate its contents against the given 1049212795Sdim /// Preprocessor. 1050212795Sdim /// 1051212795Sdim /// \param PP the preprocessor associated with the context in which this 1052212795Sdim /// precompiled header will be loaded. 1053212795Sdim /// 1054212795Sdim /// \param Context the AST context that this precompiled header will be 1055212795Sdim /// loaded into. 1056212795Sdim /// 1057212795Sdim /// \param isysroot If non-NULL, the system include path specified by the 1058212795Sdim /// user. This is only used with relocatable PCH files. If non-NULL, 1059212795Sdim /// a relocatable PCH file will use the default path "/". 1060212795Sdim /// 1061212795Sdim /// \param DisableValidation If true, the AST reader will suppress most 1062212795Sdim /// of its regular consistency checking, allowing the use of precompiled 1063212795Sdim /// headers that cannot be determined to be compatible. 1064218893Sdim /// 1065235633Sdim /// \param AllowASTWithCompilerErrors If true, the AST reader will accept an 1066235633Sdim /// AST file the was created out of an AST with compiler errors, 1067235633Sdim /// otherwise it will reject it. 1068226890Sdim ASTReader(Preprocessor &PP, ASTContext &Context, StringRef isysroot = "", 1069245431Sdim bool DisableValidation = false, 1070235633Sdim bool AllowASTWithCompilerErrors = false); 1071212795Sdim 1072212795Sdim ~ASTReader(); 1073212795Sdim 1074226890Sdim SourceManager &getSourceManager() const { return SourceMgr; } 1075235633Sdim 1076245431Sdim /// \brief Flags that indicate what kind of AST loading failures the client 1077245431Sdim /// of the AST reader can directly handle. 1078245431Sdim /// 1079245431Sdim /// When a client states that it can handle a particular kind of failure, 1080245431Sdim /// the AST reader will not emit errors when producing that kind of failure. 1081245431Sdim enum LoadFailureCapabilities { 1082245431Sdim /// \brief The client can't handle any AST loading failures. 1083245431Sdim ARR_None = 0, 1084245431Sdim /// \brief The client can handle an AST file that cannot load because it 1085245431Sdim /// is out-of-date relative to its input files. 1086245431Sdim ARR_OutOfDate = 0x1, 1087245431Sdim /// \brief The client can handle an AST file that cannot load because it 1088245431Sdim /// was built with a different version of Clang. 1089245431Sdim ARR_VersionMismatch = 0x2, 1090245431Sdim /// \brief The client can handle an AST file that cannot load because it's 1091245431Sdim /// compiled configuration doesn't match that of the context it was 1092245431Sdim /// loaded into. 1093245431Sdim ARR_ConfigurationMismatch = 0x4 1094245431Sdim }; 1095245431Sdim 1096226890Sdim /// \brief Load the AST file designated by the given file name. 1097245431Sdim /// 1098245431Sdim /// \param FileName The name of the AST file to load. 1099245431Sdim /// 1100245431Sdim /// \param Type The kind of AST being loaded, e.g., PCH, module, main file, 1101245431Sdim /// or preamble. 1102245431Sdim /// 1103245431Sdim /// \param ClientLoadCapabilities The set of client load-failure 1104245431Sdim /// capabilities, represented as a bitset of the enumerators of 1105245431Sdim /// LoadFailureCapabilities. 1106245431Sdim ASTReadResult ReadAST(const std::string &FileName, ModuleKind Type, 1107245431Sdim unsigned ClientLoadCapabilities); 1108212795Sdim 1109235633Sdim /// \brief Make the entities in the given module and any of its (non-explicit) 1110235633Sdim /// submodules visible to name lookup. 1111235633Sdim /// 1112235633Sdim /// \param Mod The module whose names should be made visible. 1113235633Sdim /// 1114245431Sdim /// \param NameVisibility The level of visibility to give the names in the 1115245431Sdim /// module. Visibility can only be increased over time. 1116235633Sdim void makeModuleVisible(Module *Mod, 1117235633Sdim Module::NameVisibilityKind NameVisibility); 1118235633Sdim 1119235633Sdim /// \brief Make the names within this set of hidden names visible. 1120235633Sdim void makeNamesVisible(const HiddenNames &Names); 1121235633Sdim 1122212795Sdim /// \brief Set the AST callbacks listener. 1123212795Sdim void setListener(ASTReaderListener *listener) { 1124212795Sdim Listener.reset(listener); 1125212795Sdim } 1126212795Sdim 1127212795Sdim /// \brief Set the AST deserialization listener. 1128212795Sdim void setDeserializationListener(ASTDeserializationListener *Listener); 1129212795Sdim 1130226890Sdim /// \brief Initializes the ASTContext 1131226890Sdim void InitializeContext(); 1132212795Sdim 1133226890Sdim /// \brief Add in-memory (virtual file) buffer. 1134226890Sdim void addInMemoryBuffer(StringRef &FileName, llvm::MemoryBuffer *Buffer) { 1135226890Sdim ModuleMgr.addInMemoryBuffer(FileName, Buffer); 1136221345Sdim } 1137221345Sdim 1138235633Sdim /// \brief Finalizes the AST reader's state before writing an AST file to 1139235633Sdim /// disk. 1140235633Sdim /// 1141235633Sdim /// This operation may undo temporary state in the AST that should not be 1142235633Sdim /// emitted. 1143235633Sdim void finalizeForWriting(); 1144235633Sdim 1145226890Sdim /// \brief Retrieve the module manager. 1146226890Sdim ModuleManager &getModuleManager() { return ModuleMgr; } 1147212795Sdim 1148226890Sdim /// \brief Retrieve the preprocessor. 1149226890Sdim Preprocessor &getPreprocessor() const { return PP; } 1150235633Sdim 1151245431Sdim /// \brief Retrieve the name of the original source file name for the primary 1152245431Sdim /// module file. 1153245431Sdim StringRef getOriginalSourceFile() { 1154245431Sdim return ModuleMgr.getPrimaryModule().OriginalSourceFileName; 1155245431Sdim } 1156212795Sdim 1157212795Sdim /// \brief Retrieve the name of the original source file name directly from 1158212795Sdim /// the AST file, without actually loading the AST file. 1159212795Sdim static std::string getOriginalSourceFile(const std::string &ASTFileName, 1160218893Sdim FileManager &FileMgr, 1161226890Sdim DiagnosticsEngine &Diags); 1162212795Sdim 1163245431Sdim /// \brief Read the control block for the named AST file. 1164245431Sdim /// 1165245431Sdim /// \returns true if an error occurred, false otherwise. 1166245431Sdim static bool readASTFileControlBlock(StringRef Filename, 1167245431Sdim FileManager &FileMgr, 1168245431Sdim ASTReaderListener &Listener); 1169245431Sdim 1170245431Sdim /// \brief Determine whether the given AST file is acceptable to load into a 1171245431Sdim /// translation unit with the given language and target options. 1172245431Sdim static bool isAcceptableASTFile(StringRef Filename, 1173245431Sdim FileManager &FileMgr, 1174245431Sdim const LangOptions &LangOpts, 1175245431Sdim const TargetOptions &TargetOpts, 1176245431Sdim const PreprocessorOptions &PPOpts); 1177245431Sdim 1178212795Sdim /// \brief Returns the suggested contents of the predefines buffer, 1179212795Sdim /// which contains a (typically-empty) subset of the predefines 1180212795Sdim /// build prior to including the precompiled header. 1181212795Sdim const std::string &getSuggestedPredefines() { return SuggestedPredefines; } 1182212795Sdim 1183226890Sdim /// \brief Read a preallocated preprocessed entity from the external source. 1184226890Sdim /// 1185226890Sdim /// \returns null if an error occurred that prevented the preprocessed 1186226890Sdim /// entity from being loaded. 1187226890Sdim virtual PreprocessedEntity *ReadPreprocessedEntity(unsigned Index); 1188218893Sdim 1189226890Sdim /// \brief Returns a pair of [Begin, End) indices of preallocated 1190245431Sdim /// preprocessed entities that \p Range encompasses. 1191226890Sdim virtual std::pair<unsigned, unsigned> 1192226890Sdim findPreprocessedEntitiesInRange(SourceRange Range); 1193226890Sdim 1194235633Sdim /// \brief Optionally returns true or false if the preallocated preprocessed 1195245431Sdim /// entity with index \p Index came from file \p FID. 1196235633Sdim virtual llvm::Optional<bool> isPreprocessedEntityInFileID(unsigned Index, 1197235633Sdim FileID FID); 1198235633Sdim 1199218893Sdim /// \brief Read the header file information for the given file entry. 1200218893Sdim virtual HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE); 1201218893Sdim 1202226890Sdim void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag); 1203218893Sdim 1204212795Sdim /// \brief Returns the number of source locations found in the chain. 1205212795Sdim unsigned getTotalNumSLocs() const { 1206212795Sdim return TotalNumSLocEntries; 1207212795Sdim } 1208212795Sdim 1209212795Sdim /// \brief Returns the number of identifiers found in the chain. 1210212795Sdim unsigned getTotalNumIdentifiers() const { 1211212795Sdim return static_cast<unsigned>(IdentifiersLoaded.size()); 1212212795Sdim } 1213212795Sdim 1214245431Sdim /// \brief Returns the number of macros found in the chain. 1215245431Sdim unsigned getTotalNumMacros() const { 1216245431Sdim return static_cast<unsigned>(MacrosLoaded.size()); 1217245431Sdim } 1218245431Sdim 1219212795Sdim /// \brief Returns the number of types found in the chain. 1220212795Sdim unsigned getTotalNumTypes() const { 1221212795Sdim return static_cast<unsigned>(TypesLoaded.size()); 1222212795Sdim } 1223212795Sdim 1224212795Sdim /// \brief Returns the number of declarations found in the chain. 1225212795Sdim unsigned getTotalNumDecls() const { 1226212795Sdim return static_cast<unsigned>(DeclsLoaded.size()); 1227212795Sdim } 1228212795Sdim 1229235633Sdim /// \brief Returns the number of submodules known. 1230235633Sdim unsigned getTotalNumSubmodules() const { 1231235633Sdim return static_cast<unsigned>(SubmodulesLoaded.size()); 1232235633Sdim } 1233235633Sdim 1234212795Sdim /// \brief Returns the number of selectors found in the chain. 1235212795Sdim unsigned getTotalNumSelectors() const { 1236212795Sdim return static_cast<unsigned>(SelectorsLoaded.size()); 1237212795Sdim } 1238212795Sdim 1239226890Sdim /// \brief Returns the number of preprocessed entities known to the AST 1240226890Sdim /// reader. 1241226890Sdim unsigned getTotalNumPreprocessedEntities() const { 1242226890Sdim unsigned Result = 0; 1243226890Sdim for (ModuleConstIterator I = ModuleMgr.begin(), 1244226890Sdim E = ModuleMgr.end(); I != E; ++I) { 1245226890Sdim Result += (*I)->NumPreprocessedEntities; 1246226890Sdim } 1247235633Sdim 1248226890Sdim return Result; 1249218893Sdim } 1250235633Sdim 1251218893Sdim /// \brief Returns the number of C++ base specifiers found in the chain. 1252226890Sdim unsigned getTotalNumCXXBaseSpecifiers() const { 1253226890Sdim return NumCXXBaseSpecifiersLoaded; 1254226890Sdim } 1255235633Sdim 1256212795Sdim /// \brief Reads a TemplateArgumentLocInfo appropriate for the 1257212795Sdim /// given TemplateArgument kind. 1258212795Sdim TemplateArgumentLocInfo 1259235633Sdim GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind, 1260212795Sdim const RecordData &Record, unsigned &Idx); 1261212795Sdim 1262212795Sdim /// \brief Reads a TemplateArgumentLoc. 1263212795Sdim TemplateArgumentLoc 1264235633Sdim ReadTemplateArgumentLoc(ModuleFile &F, 1265212795Sdim const RecordData &Record, unsigned &Idx); 1266212795Sdim 1267212795Sdim /// \brief Reads a declarator info from the given record. 1268235633Sdim TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F, 1269212795Sdim const RecordData &Record, unsigned &Idx); 1270212795Sdim 1271212795Sdim /// \brief Resolve a type ID into a type, potentially building a new 1272212795Sdim /// type. 1273212795Sdim QualType GetType(serialization::TypeID ID); 1274212795Sdim 1275226890Sdim /// \brief Resolve a local type ID within a given AST file into a type. 1276235633Sdim QualType getLocalType(ModuleFile &F, unsigned LocalID); 1277235633Sdim 1278226890Sdim /// \brief Map a local type ID within a given AST file into a global type ID. 1279235633Sdim serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const; 1280235633Sdim 1281235633Sdim /// \brief Read a type from the current position in the given record, which 1282226890Sdim /// was read from the given AST file. 1283235633Sdim QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) { 1284226890Sdim if (Idx >= Record.size()) 1285226890Sdim return QualType(); 1286235633Sdim 1287226890Sdim return getLocalType(F, Record[Idx++]); 1288226890Sdim } 1289235633Sdim 1290235633Sdim /// \brief Map from a local declaration ID within a given module to a 1291226890Sdim /// global declaration ID. 1292245431Sdim serialization::DeclID getGlobalDeclID(ModuleFile &F, 1293245431Sdim serialization::LocalDeclID LocalID) const; 1294212795Sdim 1295245431Sdim /// \brief Returns true if global DeclID \p ID originated from module \p M. 1296235633Sdim bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const; 1297235633Sdim 1298235633Sdim /// \brief Retrieve the module file that owns the given declaration, or NULL 1299235633Sdim /// if the declaration is not from a module file. 1300235633Sdim ModuleFile *getOwningModuleFile(Decl *D); 1301226890Sdim 1302245431Sdim /// \brief Returns the source location for the decl \p ID. 1303235633Sdim SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID); 1304235633Sdim 1305212795Sdim /// \brief Resolve a declaration ID into a declaration, potentially 1306212795Sdim /// building a new declaration. 1307212795Sdim Decl *GetDecl(serialization::DeclID ID); 1308212795Sdim virtual Decl *GetExternalDecl(uint32_t ID); 1309212795Sdim 1310226890Sdim /// \brief Reads a declaration with the given local ID in the given module. 1311235633Sdim Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) { 1312226890Sdim return GetDecl(getGlobalDeclID(F, LocalID)); 1313226890Sdim } 1314226890Sdim 1315226890Sdim /// \brief Reads a declaration with the given local ID in the given module. 1316226890Sdim /// 1317226890Sdim /// \returns The requested declaration, casted to the given return type. 1318226890Sdim template<typename T> 1319235633Sdim T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) { 1320226890Sdim return cast_or_null<T>(GetLocalDecl(F, LocalID)); 1321226890Sdim } 1322226890Sdim 1323235633Sdim /// \brief Map a global declaration ID into the declaration ID used to 1324235633Sdim /// refer to this declaration within the given module fule. 1325235633Sdim /// 1326235633Sdim /// \returns the global ID of the given declaration as known in the given 1327235633Sdim /// module file. 1328235633Sdim serialization::DeclID 1329235633Sdim mapGlobalIDToModuleFileGlobalID(ModuleFile &M, 1330235633Sdim serialization::DeclID GlobalID); 1331235633Sdim 1332235633Sdim /// \brief Reads a declaration ID from the given position in a record in the 1333226890Sdim /// given module. 1334226890Sdim /// 1335226890Sdim /// \returns The declaration ID read from the record, adjusted to a global ID. 1336235633Sdim serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record, 1337226890Sdim unsigned &Idx); 1338235633Sdim 1339226890Sdim /// \brief Reads a declaration from the given position in a record in the 1340226890Sdim /// given module. 1341235633Sdim Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) { 1342226890Sdim return GetDecl(ReadDeclID(F, R, I)); 1343226890Sdim } 1344235633Sdim 1345226890Sdim /// \brief Reads a declaration from the given position in a record in the 1346226890Sdim /// given module. 1347226890Sdim /// 1348226890Sdim /// \returns The declaration read from this location, casted to the given 1349226890Sdim /// result type. 1350226890Sdim template<typename T> 1351235633Sdim T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) { 1352226890Sdim return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I))); 1353226890Sdim } 1354226890Sdim 1355226890Sdim /// \brief Read a CXXBaseSpecifiers ID form the given record and 1356226890Sdim /// return its global bit offset. 1357235633Sdim uint64_t readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record, 1358226890Sdim unsigned &Idx); 1359235633Sdim 1360218893Sdim virtual CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset); 1361235633Sdim 1362212795Sdim /// \brief Resolve the offset of a statement into a statement. 1363212795Sdim /// 1364212795Sdim /// This operation will read a new statement from the external 1365212795Sdim /// source each time it is called, and is meant to be used via a 1366212795Sdim /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). 1367212795Sdim virtual Stmt *GetExternalDeclStmt(uint64_t Offset); 1368212795Sdim 1369212795Sdim /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the 1370212795Sdim /// specified cursor. Read the abbreviations that are at the top of the block 1371212795Sdim /// and then leave the cursor pointing into the block. 1372212795Sdim bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID); 1373212795Sdim 1374212795Sdim /// \brief Finds all the visible declarations with a given name. 1375212795Sdim /// The current implementation of this method just loads the entire 1376212795Sdim /// lookup table as unmaterialized references. 1377212795Sdim virtual DeclContext::lookup_result 1378212795Sdim FindExternalVisibleDeclsByName(const DeclContext *DC, 1379212795Sdim DeclarationName Name); 1380212795Sdim 1381212795Sdim /// \brief Read all of the declarations lexically stored in a 1382212795Sdim /// declaration context. 1383212795Sdim /// 1384212795Sdim /// \param DC The declaration context whose declarations will be 1385212795Sdim /// read. 1386212795Sdim /// 1387212795Sdim /// \param Decls Vector that will contain the declarations loaded 1388212795Sdim /// from the external source. The caller is responsible for merging 1389212795Sdim /// these declarations with any declarations already stored in the 1390212795Sdim /// declaration context. 1391212795Sdim /// 1392212795Sdim /// \returns true if there was an error while reading the 1393212795Sdim /// declarations for this declaration context. 1394224145Sdim virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC, 1395218893Sdim bool (*isKindWeWant)(Decl::Kind), 1396226890Sdim SmallVectorImpl<Decl*> &Decls); 1397212795Sdim 1398235633Sdim /// \brief Get the decls that are contained in a file in the Offset/Length 1399245431Sdim /// range. \p Length can be 0 to indicate a point at \p Offset instead of 1400235633Sdim /// a range. 1401235633Sdim virtual void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length, 1402235633Sdim SmallVectorImpl<Decl *> &Decls); 1403235633Sdim 1404212795Sdim /// \brief Notify ASTReader that we started deserialization of 1405212795Sdim /// a decl or type so until FinishedDeserializing is called there may be 1406212795Sdim /// decls that are initializing. Must be paired with FinishedDeserializing. 1407212795Sdim virtual void StartedDeserializing() { ++NumCurrentElementsDeserializing; } 1408212795Sdim 1409212795Sdim /// \brief Notify ASTReader that we finished the deserialization of 1410212795Sdim /// a decl or type. Must be paired with StartedDeserializing. 1411212795Sdim virtual void FinishedDeserializing(); 1412212795Sdim 1413212795Sdim /// \brief Function that will be invoked when we begin parsing a new 1414212795Sdim /// translation unit involving this external AST source. 1415212795Sdim /// 1416212795Sdim /// This function will provide all of the external definitions to 1417212795Sdim /// the ASTConsumer. 1418212795Sdim virtual void StartTranslationUnit(ASTConsumer *Consumer); 1419212795Sdim 1420212795Sdim /// \brief Print some statistics about AST usage. 1421212795Sdim virtual void PrintStats(); 1422212795Sdim 1423226890Sdim /// \brief Dump information about the AST reader to standard error. 1424226890Sdim void dump(); 1425235633Sdim 1426221345Sdim /// Return the amount of memory used by memory buffers, breaking down 1427221345Sdim /// by heap-backed versus mmap'ed memory. 1428221345Sdim virtual void getMemoryBufferSizes(MemoryBufferSizes &sizes) const; 1429221345Sdim 1430212795Sdim /// \brief Initialize the semantic source with the Sema instance 1431212795Sdim /// being used to perform semantic analysis on the abstract syntax 1432212795Sdim /// tree. 1433212795Sdim virtual void InitializeSema(Sema &S); 1434212795Sdim 1435212795Sdim /// \brief Inform the semantic consumer that Sema is no longer available. 1436212795Sdim virtual void ForgetSema() { SemaObj = 0; } 1437212795Sdim 1438212795Sdim /// \brief Retrieve the IdentifierInfo for the named identifier. 1439212795Sdim /// 1440212795Sdim /// This routine builds a new IdentifierInfo for the given identifier. If any 1441212795Sdim /// declarations with this name are visible from translation unit scope, their 1442212795Sdim /// declarations will be deserialized and introduced into the declaration 1443212795Sdim /// chain of the identifier. 1444212795Sdim virtual IdentifierInfo *get(const char *NameStart, const char *NameEnd); 1445226890Sdim IdentifierInfo *get(StringRef Name) { 1446212795Sdim return get(Name.begin(), Name.end()); 1447212795Sdim } 1448212795Sdim 1449218893Sdim /// \brief Retrieve an iterator into the set of all identifiers 1450218893Sdim /// in all loaded AST files. 1451218893Sdim virtual IdentifierIterator *getIdentifiers() const; 1452218893Sdim 1453212795Sdim /// \brief Load the contents of the global method pool for a given 1454212795Sdim /// selector. 1455235633Sdim virtual void ReadMethodPool(Selector Sel); 1456212795Sdim 1457224145Sdim /// \brief Load the set of namespaces that are known to the external source, 1458224145Sdim /// which will be used during typo correction. 1459224145Sdim virtual void ReadKnownNamespaces( 1460226890Sdim SmallVectorImpl<NamespaceDecl *> &Namespaces); 1461224145Sdim 1462226890Sdim virtual void ReadTentativeDefinitions( 1463226890Sdim SmallVectorImpl<VarDecl *> &TentativeDefs); 1464226890Sdim 1465226890Sdim virtual void ReadUnusedFileScopedDecls( 1466226890Sdim SmallVectorImpl<const DeclaratorDecl *> &Decls); 1467226890Sdim 1468226890Sdim virtual void ReadDelegatingConstructors( 1469226890Sdim SmallVectorImpl<CXXConstructorDecl *> &Decls); 1470226890Sdim 1471226890Sdim virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls); 1472226890Sdim 1473226890Sdim virtual void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls); 1474226890Sdim 1475226890Sdim virtual void ReadLocallyScopedExternalDecls( 1476226890Sdim SmallVectorImpl<NamedDecl *> &Decls); 1477235633Sdim 1478226890Sdim virtual void ReadReferencedSelectors( 1479226890Sdim SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels); 1480226890Sdim 1481226890Sdim virtual void ReadWeakUndeclaredIdentifiers( 1482226890Sdim SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI); 1483226890Sdim 1484226890Sdim virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables); 1485226890Sdim 1486226890Sdim virtual void ReadPendingInstantiations( 1487235633Sdim SmallVectorImpl<std::pair<ValueDecl *, 1488226890Sdim SourceLocation> > &Pending); 1489226890Sdim 1490212795Sdim /// \brief Load a selector from disk, registering its ID if it exists. 1491212795Sdim void LoadSelector(Selector Sel); 1492212795Sdim 1493212795Sdim void SetIdentifierInfo(unsigned ID, IdentifierInfo *II); 1494212795Sdim void SetGloballyVisibleDecls(IdentifierInfo *II, 1495226890Sdim const SmallVectorImpl<uint32_t> &DeclIDs, 1496212795Sdim bool Nonrecursive = false); 1497212795Sdim 1498212795Sdim /// \brief Report a diagnostic. 1499212795Sdim DiagnosticBuilder Diag(unsigned DiagID); 1500212795Sdim 1501212795Sdim /// \brief Report a diagnostic. 1502212795Sdim DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); 1503212795Sdim 1504226890Sdim IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID); 1505212795Sdim 1506235633Sdim IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record, 1507226890Sdim unsigned &Idx) { 1508226890Sdim return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++])); 1509212795Sdim } 1510212795Sdim 1511226890Sdim virtual IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) { 1512245431Sdim // Note that we are loading an identifier. 1513245431Sdim Deserializing AnIdentifier(this); 1514245431Sdim 1515212795Sdim return DecodeIdentifierInfo(ID); 1516212795Sdim } 1517212795Sdim 1518235633Sdim IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID); 1519235633Sdim 1520235633Sdim serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M, 1521226890Sdim unsigned LocalID); 1522235633Sdim 1523245431Sdim /// \brief Retrieve the macro with the given ID. 1524245431Sdim MacroInfo *getMacro(serialization::MacroID ID, MacroInfo *Hint = 0); 1525245431Sdim 1526245431Sdim /// \brief Retrieve the global macro ID corresponding to the given local 1527245431Sdim /// ID within the given module file. 1528245431Sdim serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID); 1529245431Sdim 1530212795Sdim /// \brief Read the source location entry with index ID. 1531226890Sdim virtual bool ReadSLocEntry(int ID); 1532212795Sdim 1533235633Sdim /// \brief Retrieve the global submodule ID given a module and its local ID 1534235633Sdim /// number. 1535235633Sdim serialization::SubmoduleID 1536235633Sdim getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID); 1537235633Sdim 1538235633Sdim /// \brief Retrieve the submodule that corresponds to a global submodule ID. 1539235633Sdim /// 1540235633Sdim Module *getSubmodule(serialization::SubmoduleID GlobalID); 1541235633Sdim 1542226890Sdim /// \brief Retrieve a selector from the given module with its local ID 1543226890Sdim /// number. 1544235633Sdim Selector getLocalSelector(ModuleFile &M, unsigned LocalID); 1545212795Sdim 1546226890Sdim Selector DecodeSelector(serialization::SelectorID Idx); 1547226890Sdim 1548226890Sdim virtual Selector GetExternalSelector(serialization::SelectorID ID); 1549212795Sdim uint32_t GetNumExternalSelectors(); 1550212795Sdim 1551235633Sdim Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) { 1552226890Sdim return getLocalSelector(M, Record[Idx++]); 1553212795Sdim } 1554235633Sdim 1555226890Sdim /// \brief Retrieve the global selector ID that corresponds to this 1556226890Sdim /// the local selector ID in a given module. 1557235633Sdim serialization::SelectorID getGlobalSelectorID(ModuleFile &F, 1558226890Sdim unsigned LocalID) const; 1559212795Sdim 1560212795Sdim /// \brief Read a declaration name. 1561235633Sdim DeclarationName ReadDeclarationName(ModuleFile &F, 1562226890Sdim const RecordData &Record, unsigned &Idx); 1563235633Sdim void ReadDeclarationNameLoc(ModuleFile &F, 1564218893Sdim DeclarationNameLoc &DNLoc, DeclarationName Name, 1565218893Sdim const RecordData &Record, unsigned &Idx); 1566235633Sdim void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo, 1567218893Sdim const RecordData &Record, unsigned &Idx); 1568212795Sdim 1569235633Sdim void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, 1570218893Sdim const RecordData &Record, unsigned &Idx); 1571218893Sdim 1572235633Sdim NestedNameSpecifier *ReadNestedNameSpecifier(ModuleFile &F, 1573226890Sdim const RecordData &Record, 1574212795Sdim unsigned &Idx); 1575212795Sdim 1576235633Sdim NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F, 1577219077Sdim const RecordData &Record, 1578219077Sdim unsigned &Idx); 1579219077Sdim 1580212795Sdim /// \brief Read a template name. 1581235633Sdim TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record, 1582218893Sdim unsigned &Idx); 1583212795Sdim 1584212795Sdim /// \brief Read a template argument. 1585235633Sdim TemplateArgument ReadTemplateArgument(ModuleFile &F, 1586212795Sdim const RecordData &Record,unsigned &Idx); 1587235633Sdim 1588212795Sdim /// \brief Read a template parameter list. 1589235633Sdim TemplateParameterList *ReadTemplateParameterList(ModuleFile &F, 1590218893Sdim const RecordData &Record, 1591212795Sdim unsigned &Idx); 1592235633Sdim 1593212795Sdim /// \brief Read a template argument array. 1594212795Sdim void 1595226890Sdim ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs, 1596235633Sdim ModuleFile &F, const RecordData &Record, 1597218893Sdim unsigned &Idx); 1598212795Sdim 1599212795Sdim /// \brief Read a UnresolvedSet structure. 1600235633Sdim void ReadUnresolvedSet(ModuleFile &F, UnresolvedSetImpl &Set, 1601212795Sdim const RecordData &Record, unsigned &Idx); 1602212795Sdim 1603212795Sdim /// \brief Read a C++ base specifier. 1604235633Sdim CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F, 1605212795Sdim const RecordData &Record,unsigned &Idx); 1606212795Sdim 1607218893Sdim /// \brief Read a CXXCtorInitializer array. 1608218893Sdim std::pair<CXXCtorInitializer **, unsigned> 1609235633Sdim ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, 1610218893Sdim unsigned &Idx); 1611212795Sdim 1612218893Sdim /// \brief Read a source location from raw form. 1613235633Sdim SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, unsigned Raw) const { 1614226890Sdim SourceLocation Loc = SourceLocation::getFromRawEncoding(Raw); 1615235633Sdim assert(ModuleFile.SLocRemap.find(Loc.getOffset()) != ModuleFile.SLocRemap.end() && 1616226890Sdim "Cannot find offset to remap."); 1617235633Sdim int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second; 1618226890Sdim return Loc.getLocWithOffset(Remap); 1619218893Sdim } 1620218893Sdim 1621212795Sdim /// \brief Read a source location. 1622235633Sdim SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, 1623218893Sdim const RecordData &Record, unsigned& Idx) { 1624235633Sdim return ReadSourceLocation(ModuleFile, Record[Idx++]); 1625212795Sdim } 1626212795Sdim 1627212795Sdim /// \brief Read a source range. 1628235633Sdim SourceRange ReadSourceRange(ModuleFile &F, 1629218893Sdim const RecordData &Record, unsigned& Idx); 1630212795Sdim 1631212795Sdim /// \brief Read an integral value 1632212795Sdim llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx); 1633212795Sdim 1634212795Sdim /// \brief Read a signed integral value 1635212795Sdim llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx); 1636212795Sdim 1637212795Sdim /// \brief Read a floating-point value 1638212795Sdim llvm::APFloat ReadAPFloat(const RecordData &Record, unsigned &Idx); 1639212795Sdim 1640212795Sdim // \brief Read a string 1641245431Sdim static std::string ReadString(const RecordData &Record, unsigned &Idx); 1642212795Sdim 1643221345Sdim /// \brief Read a version tuple. 1644245431Sdim static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx); 1645221345Sdim 1646235633Sdim CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record, 1647226890Sdim unsigned &Idx); 1648235633Sdim 1649212795Sdim /// \brief Reads attributes from the current stream position. 1650235633Sdim void ReadAttributes(ModuleFile &F, AttrVec &Attrs, 1651218893Sdim const RecordData &Record, unsigned &Idx); 1652212795Sdim 1653212795Sdim /// \brief Reads a statement. 1654235633Sdim Stmt *ReadStmt(ModuleFile &F); 1655212795Sdim 1656212795Sdim /// \brief Reads an expression. 1657235633Sdim Expr *ReadExpr(ModuleFile &F); 1658212795Sdim 1659212795Sdim /// \brief Reads a sub-statement operand during statement reading. 1660212795Sdim Stmt *ReadSubStmt() { 1661212795Sdim assert(ReadingKind == Read_Stmt && 1662212795Sdim "Should be called only during statement reading!"); 1663212795Sdim // Subexpressions are stored from last to first, so the next Stmt we need 1664212795Sdim // is at the back of the stack. 1665212795Sdim assert(!StmtStack.empty() && "Read too many sub statements!"); 1666212795Sdim return StmtStack.pop_back_val(); 1667212795Sdim } 1668212795Sdim 1669212795Sdim /// \brief Reads a sub-expression operand during statement reading. 1670212795Sdim Expr *ReadSubExpr(); 1671212795Sdim 1672212795Sdim /// \brief Reads the macro record located at the given offset. 1673245431Sdim void ReadMacroRecord(ModuleFile &F, uint64_t Offset, MacroInfo *Hint = 0); 1674235633Sdim 1675226890Sdim /// \brief Determine the global preprocessed entity ID that corresponds to 1676226890Sdim /// the given local ID within the given module. 1677235633Sdim serialization::PreprocessedEntityID 1678235633Sdim getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const; 1679235633Sdim 1680245431Sdim /// \brief Note that the identifier has a macro history. 1681235633Sdim /// 1682235633Sdim /// \param II The name of the macro. 1683235633Sdim /// 1684245431Sdim /// \param IDs The global macro IDs that are associated with this identifier. 1685245431Sdim void setIdentifierIsMacro(IdentifierInfo *II, 1686245431Sdim ArrayRef<serialization::MacroID> IDs); 1687235633Sdim 1688212795Sdim /// \brief Read the set of macros defined by this external macro source. 1689212795Sdim virtual void ReadDefinedMacros(); 1690212795Sdim 1691235633Sdim /// \brief Update an out-of-date identifier. 1692235633Sdim virtual void updateOutOfDateIdentifier(IdentifierInfo &II); 1693235633Sdim 1694235633Sdim /// \brief Note that this identifier is up-to-date. 1695235633Sdim void markIdentifierUpToDate(IdentifierInfo *II); 1696235633Sdim 1697235633Sdim /// \brief Load all external visible decls in the given DeclContext. 1698235633Sdim void completeVisibleDeclsMap(const DeclContext *DC); 1699235633Sdim 1700212795Sdim /// \brief Retrieve the AST context that this AST reader supplements. 1701226890Sdim ASTContext &getContext() { return Context; } 1702212795Sdim 1703212795Sdim // \brief Contains declarations that were loaded before we have 1704212795Sdim // access to a Sema object. 1705226890Sdim SmallVector<NamedDecl *, 16> PreloadedDecls; 1706212795Sdim 1707212795Sdim /// \brief Retrieve the semantic analysis object used to analyze the 1708212795Sdim /// translation unit in which the precompiled header is being 1709212795Sdim /// imported. 1710212795Sdim Sema *getSema() { return SemaObj; } 1711212795Sdim 1712212795Sdim /// \brief Retrieve the identifier table associated with the 1713212795Sdim /// preprocessor. 1714212795Sdim IdentifierTable &getIdentifierTable(); 1715212795Sdim 1716212795Sdim /// \brief Record that the given ID maps to the given switch-case 1717212795Sdim /// statement. 1718212795Sdim void RecordSwitchCaseID(SwitchCase *SC, unsigned ID); 1719212795Sdim 1720212795Sdim /// \brief Retrieve the switch-case statement with the given ID. 1721212795Sdim SwitchCase *getSwitchCaseWithID(unsigned ID); 1722212795Sdim 1723218893Sdim void ClearSwitchCaseIDs(); 1724245431Sdim 1725245431Sdim /// \brief Cursors for comments blocks. 1726245431Sdim SmallVector<std::pair<llvm::BitstreamCursor, 1727245431Sdim serialization::ModuleFile *>, 8> CommentsCursors; 1728245431Sdim 1729245431Sdim /// \brief Loads comments ranges. 1730245431Sdim void ReadComments(); 1731212795Sdim}; 1732212795Sdim 1733212795Sdim/// \brief Helper class that saves the current stream position and 1734212795Sdim/// then restores it when destroyed. 1735212795Sdimstruct SavedStreamPosition { 1736212795Sdim explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor) 1737212795Sdim : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) { } 1738212795Sdim 1739212795Sdim ~SavedStreamPosition() { 1740212795Sdim Cursor.JumpToBit(Offset); 1741212795Sdim } 1742212795Sdim 1743212795Sdimprivate: 1744212795Sdim llvm::BitstreamCursor &Cursor; 1745212795Sdim uint64_t Offset; 1746212795Sdim}; 1747212795Sdim 1748212795Sdiminline void PCHValidator::Error(const char *Msg) { 1749212795Sdim Reader.Error(Msg); 1750212795Sdim} 1751212795Sdim 1752212795Sdim} // end namespace clang 1753212795Sdim 1754212795Sdim#endif 1755