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 17252723Sdim#include "clang/AST/DeclObjC.h" 18212795Sdim#include "clang/AST/DeclarationName.h" 19212795Sdim#include "clang/AST/TemplateBase.h" 20212795Sdim#include "clang/Basic/Diagnostic.h" 21226890Sdim#include "clang/Basic/FileManager.h" 22226890Sdim#include "clang/Basic/FileSystemOptions.h" 23212795Sdim#include "clang/Basic/IdentifierTable.h" 24212795Sdim#include "clang/Basic/SourceManager.h" 25252723Sdim#include "clang/Basic/Version.h" 26252723Sdim#include "clang/Lex/ExternalPreprocessorSource.h" 27252723Sdim#include "clang/Lex/HeaderSearch.h" 28252723Sdim#include "clang/Lex/PreprocessingRecord.h" 29252723Sdim#include "clang/Sema/ExternalSemaSource.h" 30252723Sdim#include "clang/Serialization/ASTBitCodes.h" 31252723Sdim#include "clang/Serialization/ContinuousRangeMap.h" 32252723Sdim#include "clang/Serialization/Module.h" 33252723Sdim#include "clang/Serialization/ModuleManager.h" 34212795Sdim#include "llvm/ADT/APFloat.h" 35212795Sdim#include "llvm/ADT/APInt.h" 36212795Sdim#include "llvm/ADT/APSInt.h" 37252723Sdim#include "llvm/ADT/DenseSet.h" 38245431Sdim#include "llvm/ADT/MapVector.h" 39212795Sdim#include "llvm/ADT/OwningPtr.h" 40235633Sdim#include "llvm/ADT/SmallPtrSet.h" 41235633Sdim#include "llvm/ADT/SmallSet.h" 42212795Sdim#include "llvm/ADT/SmallVector.h" 43212795Sdim#include "llvm/ADT/StringRef.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> 51252723Sdim#include <sys/stat.h> 52212795Sdim 53212795Sdimnamespace llvm { 54212795Sdim class MemoryBuffer; 55212795Sdim} 56212795Sdim 57212795Sdimnamespace clang { 58212795Sdim 59212795Sdimclass AddrLabelExpr; 60212795Sdimclass ASTConsumer; 61212795Sdimclass ASTContext; 62218893Sdimclass ASTIdentifierIterator; 63226890Sdimclass ASTUnit; // FIXME: Layering violation and egregious hack. 64212795Sdimclass Attr; 65212795Sdimclass Decl; 66212795Sdimclass DeclContext; 67245431Sdimclass DiagnosticOptions; 68212795Sdimclass NestedNameSpecifier; 69212795Sdimclass CXXBaseSpecifier; 70223017Sdimclass CXXConstructorDecl; 71218893Sdimclass CXXCtorInitializer; 72252723Sdimclass GlobalModuleIndex; 73212795Sdimclass GotoStmt; 74212795Sdimclass MacroDefinition; 75252723Sdimclass MacroDirective; 76212795Sdimclass NamedDecl; 77218893Sdimclass OpaqueValueExpr; 78212795Sdimclass Preprocessor; 79245431Sdimclass PreprocessorOptions; 80212795Sdimclass Sema; 81212795Sdimclass SwitchCase; 82218893Sdimclass ASTDeserializationListener; 83226890Sdimclass ASTWriter; 84212795Sdimclass ASTReader; 85212795Sdimclass ASTDeclReader; 86218893Sdimclass ASTStmtReader; 87218893Sdimclass TypeLocReader; 88212795Sdimstruct HeaderFileInfo; 89221345Sdimclass VersionTuple; 90245431Sdimclass TargetOptions; 91263509Sdimclass LazyASTUnresolvedSet; 92212795Sdim 93212795Sdim/// \brief Abstract interface for callback invocations by the ASTReader. 94212795Sdim/// 95212795Sdim/// While reading an AST file, the ASTReader will call the methods of the 96212795Sdim/// listener to pass on specific information. Some of the listener methods can 97212795Sdim/// return true to indicate to the ASTReader that the information (and 98212795Sdim/// consequently the AST file) is invalid. 99212795Sdimclass ASTReaderListener { 100212795Sdimpublic: 101212795Sdim virtual ~ASTReaderListener(); 102212795Sdim 103252723Sdim /// \brief Receives the full Clang version information. 104252723Sdim /// 105252723Sdim /// \returns true to indicate that the version is invalid. Subclasses should 106252723Sdim /// generally defer to this implementation. 107252723Sdim virtual bool ReadFullVersionInformation(StringRef FullVersion) { 108252723Sdim return FullVersion != getClangFullRepositoryVersion(); 109252723Sdim } 110252723Sdim 111212795Sdim /// \brief Receives the language options. 112212795Sdim /// 113212795Sdim /// \returns true to indicate the options are invalid or false otherwise. 114245431Sdim virtual bool ReadLanguageOptions(const LangOptions &LangOpts, 115245431Sdim bool Complain) { 116212795Sdim return false; 117212795Sdim } 118212795Sdim 119245431Sdim /// \brief Receives the target options. 120212795Sdim /// 121245431Sdim /// \returns true to indicate the target options are invalid, or false 122245431Sdim /// otherwise. 123245431Sdim virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, 124245431Sdim bool Complain) { 125212795Sdim return false; 126212795Sdim } 127212795Sdim 128245431Sdim /// \brief Receives the diagnostic options. 129212795Sdim /// 130245431Sdim /// \returns true to indicate the diagnostic options are invalid, or false 131245431Sdim /// otherwise. 132245431Sdim virtual bool ReadDiagnosticOptions(const DiagnosticOptions &DiagOpts, 133245431Sdim bool Complain) { 134245431Sdim return false; 135245431Sdim } 136245431Sdim 137245431Sdim /// \brief Receives the file system options. 138212795Sdim /// 139245431Sdim /// \returns true to indicate the file system options are invalid, or false 140245431Sdim /// otherwise. 141245431Sdim virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts, 142245431Sdim bool Complain) { 143245431Sdim return false; 144245431Sdim } 145245431Sdim 146245431Sdim /// \brief Receives the header search options. 147212795Sdim /// 148245431Sdim /// \returns true to indicate the header search options are invalid, or false 149245431Sdim /// otherwise. 150245431Sdim virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, 151245431Sdim bool Complain) { 152245431Sdim return false; 153245431Sdim } 154245431Sdim 155245431Sdim /// \brief Receives the preprocessor options. 156212795Sdim /// 157245431Sdim /// \param SuggestedPredefines Can be filled in with the set of predefines 158245431Sdim /// that are suggested by the preprocessor options. Typically only used when 159245431Sdim /// loading a precompiled header. 160245431Sdim /// 161245431Sdim /// \returns true to indicate the preprocessor options are invalid, or false 162245431Sdim /// otherwise. 163245431Sdim virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, 164245431Sdim bool Complain, 165245431Sdim std::string &SuggestedPredefines) { 166212795Sdim return false; 167212795Sdim } 168212795Sdim 169212795Sdim /// \brief Receives __COUNTER__ value. 170245431Sdim virtual void ReadCounter(const serialization::ModuleFile &M, 171245431Sdim unsigned Value) {} 172252723Sdim 173252723Sdim /// \brief Returns true if this \c ASTReaderListener wants to receive the 174252723Sdim /// input files of the AST file via \c visitInputFile, false otherwise. 175252723Sdim virtual bool needsInputFileVisitation() { return false; } 176252723Sdim 177252723Sdim /// \brief if \c needsInputFileVisitation returns true, this is called for each 178252723Sdim /// input file of the AST file. 179252723Sdim /// 180252723Sdim /// \returns true to continue receiving the next input file, false to stop. 181252723Sdim virtual bool visitInputFile(StringRef Filename, bool isSystem) { return true;} 182212795Sdim}; 183212795Sdim 184212795Sdim/// \brief ASTReaderListener implementation to validate the information of 185212795Sdim/// the PCH file against an initialized Preprocessor. 186212795Sdimclass PCHValidator : public ASTReaderListener { 187212795Sdim Preprocessor &PP; 188212795Sdim ASTReader &Reader; 189212795Sdim 190212795Sdimpublic: 191212795Sdim PCHValidator(Preprocessor &PP, ASTReader &Reader) 192263509Sdim : PP(PP), Reader(Reader) {} 193212795Sdim 194245431Sdim virtual bool ReadLanguageOptions(const LangOptions &LangOpts, 195245431Sdim bool Complain); 196245431Sdim virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, 197245431Sdim bool Complain); 198245431Sdim virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, 199245431Sdim bool Complain, 200245431Sdim std::string &SuggestedPredefines); 201245431Sdim virtual void ReadCounter(const serialization::ModuleFile &M, unsigned Value); 202212795Sdim 203212795Sdimprivate: 204212795Sdim void Error(const char *Msg); 205212795Sdim}; 206212795Sdim 207235633Sdimnamespace serialization { 208226890Sdim 209226890Sdimclass ReadMethodPoolVisitor; 210235633Sdim 211226890Sdimnamespace reader { 212226890Sdim class ASTIdentifierLookupTrait; 213235633Sdim /// \brief The on-disk hash table used for the DeclContext's Name lookup table. 214235633Sdim typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait> 215235633Sdim ASTDeclContextNameLookupTable; 216226890Sdim} 217235633Sdim 218226890Sdim} // end namespace serialization 219235633Sdim 220212795Sdim/// \brief Reads an AST files chain containing the contents of a translation 221212795Sdim/// unit. 222212795Sdim/// 223212795Sdim/// The ASTReader class reads bitstreams (produced by the ASTWriter 224212795Sdim/// class) containing the serialized representation of a given 225212795Sdim/// abstract syntax tree and its supporting data structures. An 226212795Sdim/// instance of the ASTReader can be attached to an ASTContext object, 227212795Sdim/// which will provide access to the contents of the AST files. 228212795Sdim/// 229212795Sdim/// The AST reader provides lazy de-serialization of declarations, as 230212795Sdim/// required when traversing the AST. Only those AST nodes that are 231212795Sdim/// actually required will be de-serialized. 232212795Sdimclass ASTReader 233212795Sdim : public ExternalPreprocessorSource, 234212795Sdim public ExternalPreprocessingRecordSource, 235218893Sdim public ExternalHeaderFileInfoSource, 236212795Sdim public ExternalSemaSource, 237212795Sdim public IdentifierInfoLookup, 238212795Sdim public ExternalIdentifierLookup, 239235633Sdim public ExternalSLocEntrySource 240218893Sdim{ 241212795Sdimpublic: 242245431Sdim typedef SmallVector<uint64_t, 64> RecordData; 243263509Sdim typedef SmallVectorImpl<uint64_t> RecordDataImpl; 244245431Sdim 245245431Sdim /// \brief The result of reading the control block of an AST file, which 246245431Sdim /// can fail for various reasons. 247245431Sdim enum ASTReadResult { 248245431Sdim /// \brief The control block was read successfully. Aside from failures, 249245431Sdim /// the AST file is safe to read into the current context. 250245431Sdim Success, 251245431Sdim /// \brief The AST file itself appears corrupted. 252245431Sdim Failure, 253252723Sdim /// \brief The AST file was missing. 254252723Sdim Missing, 255245431Sdim /// \brief The AST file is out-of-date relative to its input files, 256245431Sdim /// and needs to be regenerated. 257245431Sdim OutOfDate, 258245431Sdim /// \brief The AST file was written by a different version of Clang. 259245431Sdim VersionMismatch, 260245431Sdim /// \brief The AST file was writtten with a different language/target 261245431Sdim /// configuration. 262245431Sdim ConfigurationMismatch, 263245431Sdim /// \brief The AST file has errors. 264245431Sdim HadErrors 265245431Sdim }; 266245431Sdim 267218893Sdim /// \brief Types of AST files. 268212795Sdim friend class PCHValidator; 269212795Sdim friend class ASTDeclReader; 270218893Sdim friend class ASTStmtReader; 271218893Sdim friend class ASTIdentifierIterator; 272226890Sdim friend class serialization::reader::ASTIdentifierLookupTrait; 273218893Sdim friend class TypeLocReader; 274226890Sdim friend class ASTWriter; 275226890Sdim friend class ASTUnit; // ASTUnit needs to remap source locations. 276226890Sdim friend class serialization::ReadMethodPoolVisitor; 277235633Sdim 278235633Sdim typedef serialization::ModuleFile ModuleFile; 279226890Sdim typedef serialization::ModuleKind ModuleKind; 280226890Sdim typedef serialization::ModuleManager ModuleManager; 281235633Sdim 282226890Sdim typedef ModuleManager::ModuleIterator ModuleIterator; 283226890Sdim typedef ModuleManager::ModuleConstIterator ModuleConstIterator; 284226890Sdim typedef ModuleManager::ModuleReverseIterator ModuleReverseIterator; 285226890Sdim 286212795Sdimprivate: 287212795Sdim /// \brief The receiver of some callbacks invoked by ASTReader. 288235633Sdim OwningPtr<ASTReaderListener> Listener; 289212795Sdim 290212795Sdim /// \brief The receiver of deserialization events. 291212795Sdim ASTDeserializationListener *DeserializationListener; 292212795Sdim 293212795Sdim SourceManager &SourceMgr; 294212795Sdim FileManager &FileMgr; 295226890Sdim DiagnosticsEngine &Diags; 296235633Sdim 297212795Sdim /// \brief The semantic analysis object that will be processing the 298212795Sdim /// AST files and the translation unit that uses it. 299212795Sdim Sema *SemaObj; 300212795Sdim 301212795Sdim /// \brief The preprocessor that will be loading the source file. 302226890Sdim Preprocessor &PP; 303212795Sdim 304212795Sdim /// \brief The AST context into which we'll read the AST files. 305226890Sdim ASTContext &Context; 306235633Sdim 307212795Sdim /// \brief The AST consumer. 308212795Sdim ASTConsumer *Consumer; 309212795Sdim 310226890Sdim /// \brief The module manager which manages modules and their dependencies 311226890Sdim ModuleManager ModuleMgr; 312221345Sdim 313263509Sdim /// \brief The location where the module file will be considered as 314263509Sdim /// imported from. For non-module AST types it should be invalid. 315263509Sdim SourceLocation CurrentImportLoc; 316263509Sdim 317252723Sdim /// \brief The global module index, if loaded. 318252723Sdim llvm::OwningPtr<GlobalModuleIndex> GlobalIndex; 319252723Sdim 320226890Sdim /// \brief A map of global bit offsets to the module that stores entities 321226890Sdim /// at those bit offsets. 322235633Sdim ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap; 323212795Sdim 324226890Sdim /// \brief A map of negated SLocEntryIDs to the modules containing them. 325235633Sdim ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap; 326212795Sdim 327235633Sdim typedef ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocOffsetMapType; 328235633Sdim 329226890Sdim /// \brief A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset) 330226890Sdim /// SourceLocation offsets to the modules containing them. 331226890Sdim GlobalSLocOffsetMapType GlobalSLocOffsetMap; 332235633Sdim 333212795Sdim /// \brief Types that have already been loaded from the chain. 334212795Sdim /// 335212795Sdim /// When the pointer at index I is non-NULL, the type with 336212795Sdim /// ID = (I + 1) << FastQual::Width has already been loaded 337212795Sdim std::vector<QualType> TypesLoaded; 338212795Sdim 339235633Sdim typedef ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4> 340226890Sdim GlobalTypeMapType; 341212795Sdim 342226890Sdim /// \brief Mapping from global type IDs to the module in which the 343226890Sdim /// type resides along with the offset that should be added to the 344226890Sdim /// global type ID to produce a local ID. 345226890Sdim GlobalTypeMapType GlobalTypeMap; 346226890Sdim 347212795Sdim /// \brief Declarations that have already been loaded from the chain. 348212795Sdim /// 349212795Sdim /// When the pointer at index I is non-NULL, the declaration with ID 350212795Sdim /// = I + 1 has already been loaded. 351212795Sdim std::vector<Decl *> DeclsLoaded; 352212795Sdim 353235633Sdim typedef ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4> 354226890Sdim GlobalDeclMapType; 355235633Sdim 356226890Sdim /// \brief Mapping from global declaration IDs to the module in which the 357226890Sdim /// declaration resides. 358226890Sdim GlobalDeclMapType GlobalDeclMap; 359235633Sdim 360235633Sdim typedef std::pair<ModuleFile *, uint64_t> FileOffset; 361226890Sdim typedef SmallVector<FileOffset, 2> FileOffsetsTy; 362218893Sdim typedef llvm::DenseMap<serialization::DeclID, FileOffsetsTy> 363218893Sdim DeclUpdateOffsetsMap; 364235633Sdim 365218893Sdim /// \brief Declarations that have modifications residing in a later file 366218893Sdim /// in the chain. 367218893Sdim DeclUpdateOffsetsMap DeclUpdateOffsets; 368218893Sdim 369235633Sdim struct ReplacedDeclInfo { 370235633Sdim ModuleFile *Mod; 371235633Sdim uint64_t Offset; 372235633Sdim unsigned RawLoc; 373235633Sdim 374235633Sdim ReplacedDeclInfo() : Mod(0), Offset(0), RawLoc(0) {} 375235633Sdim ReplacedDeclInfo(ModuleFile *Mod, uint64_t Offset, unsigned RawLoc) 376235633Sdim : Mod(Mod), Offset(Offset), RawLoc(RawLoc) {} 377235633Sdim }; 378235633Sdim 379235633Sdim typedef llvm::DenseMap<serialization::DeclID, ReplacedDeclInfo> 380212795Sdim DeclReplacementMap; 381212795Sdim /// \brief Declarations that have been replaced in a later file in the chain. 382212795Sdim DeclReplacementMap ReplacedDecls; 383212795Sdim 384235633Sdim struct FileDeclsInfo { 385235633Sdim ModuleFile *Mod; 386235633Sdim ArrayRef<serialization::LocalDeclID> Decls; 387235633Sdim 388235633Sdim FileDeclsInfo() : Mod(0) {} 389235633Sdim FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls) 390235633Sdim : Mod(Mod), Decls(Decls) {} 391235633Sdim }; 392235633Sdim 393235633Sdim /// \brief Map from a FileID to the file-level declarations that it contains. 394235633Sdim llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs; 395235633Sdim 396212795Sdim // Updates for visible decls can occur for other contexts than just the 397212795Sdim // TU, and when we read those update records, the actual context will not 398212795Sdim // be available yet (unless it's the TU), so have this pending map using the 399212795Sdim // ID as a key. It will be realized when the context is actually loaded. 400235633Sdim typedef 401235633Sdim SmallVector<std::pair<serialization::reader::ASTDeclContextNameLookupTable *, 402235633Sdim ModuleFile*>, 1> DeclContextVisibleUpdates; 403212795Sdim typedef llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates> 404212795Sdim DeclContextVisibleUpdatesPending; 405212795Sdim 406212795Sdim /// \brief Updates to the visible declarations of declaration contexts that 407212795Sdim /// haven't been loaded yet. 408212795Sdim DeclContextVisibleUpdatesPending PendingVisibleUpdates; 409235633Sdim 410235633Sdim /// \brief The set of C++ or Objective-C classes that have forward 411235633Sdim /// declarations that have not yet been linked to their definitions. 412235633Sdim llvm::SmallPtrSet<Decl *, 4> PendingDefinitions; 413245431Sdim 414245431Sdim typedef llvm::MapVector<Decl *, uint64_t, 415245431Sdim llvm::SmallDenseMap<Decl *, unsigned, 4>, 416252723Sdim SmallVector<std::pair<Decl *, uint64_t>, 4> > 417245431Sdim PendingBodiesMap; 418245431Sdim 419245431Sdim /// \brief Functions or methods that have bodies that will be attached. 420245431Sdim PendingBodiesMap PendingBodies; 421245431Sdim 422212795Sdim /// \brief Read the records that describe the contents of declcontexts. 423235633Sdim bool ReadDeclContextStorage(ModuleFile &M, 424226890Sdim llvm::BitstreamCursor &Cursor, 425212795Sdim const std::pair<uint64_t, uint64_t> &Offsets, 426226890Sdim serialization::DeclContextInfo &Info); 427212795Sdim 428212795Sdim /// \brief A vector containing identifiers that have already been 429212795Sdim /// loaded. 430212795Sdim /// 431212795Sdim /// If the pointer at index I is non-NULL, then it refers to the 432212795Sdim /// IdentifierInfo for the identifier with ID=I+1 that has already 433212795Sdim /// been loaded. 434212795Sdim std::vector<IdentifierInfo *> IdentifiersLoaded; 435212795Sdim 436235633Sdim typedef ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4> 437226890Sdim GlobalIdentifierMapType; 438235633Sdim 439245431Sdim /// \brief Mapping from global identifier IDs to the module in which the 440226890Sdim /// identifier resides along with the offset that should be added to the 441226890Sdim /// global identifier ID to produce a local ID. 442226890Sdim GlobalIdentifierMapType GlobalIdentifierMap; 443226890Sdim 444245431Sdim /// \brief A vector containing macros that have already been 445245431Sdim /// loaded. 446245431Sdim /// 447245431Sdim /// If the pointer at index I is non-NULL, then it refers to the 448245431Sdim /// MacroInfo for the identifier with ID=I+1 that has already 449245431Sdim /// been loaded. 450245431Sdim std::vector<MacroInfo *> MacrosLoaded; 451245431Sdim 452245431Sdim typedef ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4> 453245431Sdim GlobalMacroMapType; 454245431Sdim 455245431Sdim /// \brief Mapping from global macro IDs to the module in which the 456245431Sdim /// macro resides along with the offset that should be added to the 457245431Sdim /// global macro ID to produce a local ID. 458245431Sdim GlobalMacroMapType GlobalMacroMap; 459245431Sdim 460235633Sdim /// \brief A vector containing submodules that have already been loaded. 461235633Sdim /// 462235633Sdim /// This vector is indexed by the Submodule ID (-1). NULL submodule entries 463235633Sdim /// indicate that the particular submodule ID has not yet been loaded. 464235633Sdim SmallVector<Module *, 2> SubmodulesLoaded; 465235633Sdim 466235633Sdim typedef ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4> 467235633Sdim GlobalSubmoduleMapType; 468235633Sdim 469235633Sdim /// \brief Mapping from global submodule IDs to the module file in which the 470235633Sdim /// submodule resides along with the offset that should be added to the 471235633Sdim /// global submodule ID to produce a local ID. 472235633Sdim GlobalSubmoduleMapType GlobalSubmoduleMap; 473235633Sdim 474245431Sdim /// \brief An entity that has been hidden. 475245431Sdim class HiddenName { 476245431Sdim public: 477245431Sdim enum NameKind { 478245431Sdim Declaration, 479252723Sdim MacroVisibility 480245431Sdim } Kind; 481245431Sdim 482245431Sdim private: 483245431Sdim union { 484245431Sdim Decl *D; 485252723Sdim MacroDirective *MD; 486245431Sdim }; 487245431Sdim 488245431Sdim IdentifierInfo *Id; 489245431Sdim 490245431Sdim public: 491252723Sdim HiddenName(Decl *D) : Kind(Declaration), D(D), Id() { } 492245431Sdim 493252723Sdim HiddenName(IdentifierInfo *II, MacroDirective *MD) 494252723Sdim : Kind(MacroVisibility), MD(MD), Id(II) { } 495245431Sdim 496245431Sdim NameKind getKind() const { return Kind; } 497245431Sdim 498245431Sdim Decl *getDecl() const { 499245431Sdim assert(getKind() == Declaration && "Hidden name is not a declaration"); 500245431Sdim return D; 501245431Sdim } 502245431Sdim 503252723Sdim std::pair<IdentifierInfo *, MacroDirective *> getMacro() const { 504252723Sdim assert(getKind() == MacroVisibility && "Hidden name is not a macro!"); 505252723Sdim return std::make_pair(Id, MD); 506245431Sdim } 507245431Sdim}; 508245431Sdim 509235633Sdim /// \brief A set of hidden declarations. 510252723Sdim typedef SmallVector<HiddenName, 2> HiddenNames; 511235633Sdim 512235633Sdim typedef llvm::DenseMap<Module *, HiddenNames> HiddenNamesMapType; 513235633Sdim 514235633Sdim /// \brief A mapping from each of the hidden submodules to the deserialized 515235633Sdim /// declarations in that submodule that could be made visible. 516235633Sdim HiddenNamesMapType HiddenNamesMap; 517235633Sdim 518235633Sdim 519252723Sdim /// \brief A module import, export, or conflict that hasn't yet been resolved. 520252723Sdim struct UnresolvedModuleRef { 521235633Sdim /// \brief The file in which this module resides. 522235633Sdim ModuleFile *File; 523235633Sdim 524235633Sdim /// \brief The module that is importing or exporting. 525235633Sdim Module *Mod; 526252723Sdim 527252723Sdim /// \brief The kind of module reference. 528252723Sdim enum { Import, Export, Conflict } Kind; 529252723Sdim 530235633Sdim /// \brief The local ID of the module that is being exported. 531235633Sdim unsigned ID; 532252723Sdim 533235633Sdim /// \brief Whether this is a wildcard export. 534235633Sdim unsigned IsWildcard : 1; 535252723Sdim 536252723Sdim /// \brief String data. 537252723Sdim StringRef String; 538235633Sdim }; 539235633Sdim 540235633Sdim /// \brief The set of module imports and exports that still need to be 541235633Sdim /// resolved. 542252723Sdim SmallVector<UnresolvedModuleRef, 2> UnresolvedModuleRefs; 543235633Sdim 544212795Sdim /// \brief A vector containing selectors that have already been loaded. 545212795Sdim /// 546212795Sdim /// This vector is indexed by the Selector ID (-1). NULL selector 547212795Sdim /// entries indicate that the particular selector ID has not yet 548212795Sdim /// been loaded. 549226890Sdim SmallVector<Selector, 16> SelectorsLoaded; 550212795Sdim 551235633Sdim typedef ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4> 552226890Sdim GlobalSelectorMapType; 553235633Sdim 554226890Sdim /// \brief Mapping from global selector IDs to the module in which the 555252723Sdim 556226890Sdim /// global selector ID to produce a local ID. 557226890Sdim GlobalSelectorMapType GlobalSelectorMap; 558212795Sdim 559235633Sdim /// \brief The generation number of the last time we loaded data from the 560235633Sdim /// global method pool for this selector. 561235633Sdim llvm::DenseMap<Selector, unsigned> SelectorGeneration; 562235633Sdim 563252723Sdim struct PendingMacroInfo { 564252723Sdim ModuleFile *M; 565252723Sdim 566252723Sdim struct ModuleMacroDataTy { 567252723Sdim serialization::GlobalMacroID GMacID; 568252723Sdim unsigned ImportLoc; 569252723Sdim }; 570252723Sdim struct PCHMacroDataTy { 571252723Sdim uint64_t MacroDirectivesOffset; 572252723Sdim }; 573252723Sdim 574252723Sdim union { 575252723Sdim ModuleMacroDataTy ModuleMacroData; 576252723Sdim PCHMacroDataTy PCHMacroData; 577252723Sdim }; 578252723Sdim 579252723Sdim PendingMacroInfo(ModuleFile *M, 580252723Sdim serialization::GlobalMacroID GMacID, 581252723Sdim SourceLocation ImportLoc) : M(M) { 582252723Sdim ModuleMacroData.GMacID = GMacID; 583252723Sdim ModuleMacroData.ImportLoc = ImportLoc.getRawEncoding(); 584252723Sdim } 585252723Sdim 586252723Sdim PendingMacroInfo(ModuleFile *M, uint64_t MacroDirectivesOffset) : M(M) { 587252723Sdim PCHMacroData.MacroDirectivesOffset = MacroDirectivesOffset; 588252723Sdim } 589252723Sdim }; 590252723Sdim 591252723Sdim typedef llvm::MapVector<IdentifierInfo *, SmallVector<PendingMacroInfo, 2> > 592245431Sdim PendingMacroIDsMap; 593226890Sdim 594245431Sdim /// \brief Mapping from identifiers that have a macro history to the global 595245431Sdim /// IDs have not yet been deserialized to the global IDs of those macros. 596245431Sdim PendingMacroIDsMap PendingMacroIDs; 597245431Sdim 598235633Sdim typedef ContinuousRangeMap<unsigned, ModuleFile *, 4> 599226890Sdim GlobalPreprocessedEntityMapType; 600235633Sdim 601226890Sdim /// \brief Mapping from global preprocessing entity IDs to the module in 602226890Sdim /// which the preprocessed entity resides along with the offset that should be 603226890Sdim /// added to the global preprocessing entitiy ID to produce a local ID. 604226890Sdim GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap; 605235633Sdim 606212795Sdim /// \name CodeGen-relevant special data 607212795Sdim /// \brief Fields containing data that is relevant to CodeGen. 608212795Sdim //@{ 609212795Sdim 610212795Sdim /// \brief The IDs of all declarations that fulfill the criteria of 611212795Sdim /// "interesting" decls. 612212795Sdim /// 613212795Sdim /// This contains the data loaded from all EXTERNAL_DEFINITIONS blocks in the 614212795Sdim /// chain. The referenced declarations are deserialized and passed to the 615212795Sdim /// consumer eagerly. 616226890Sdim SmallVector<uint64_t, 16> ExternalDefinitions; 617212795Sdim 618245431Sdim /// \brief The IDs of all tentative definitions stored in the chain. 619212795Sdim /// 620212795Sdim /// Sema keeps track of all tentative definitions in a TU because it has to 621212795Sdim /// complete them and pass them on to CodeGen. Thus, tentative definitions in 622212795Sdim /// the PCH chain must be eagerly deserialized. 623226890Sdim SmallVector<uint64_t, 16> TentativeDefinitions; 624212795Sdim 625212795Sdim /// \brief The IDs of all CXXRecordDecls stored in the chain whose VTables are 626212795Sdim /// used. 627212795Sdim /// 628212795Sdim /// CodeGen has to emit VTables for these records, so they have to be eagerly 629212795Sdim /// deserialized. 630226890Sdim SmallVector<uint64_t, 64> VTableUses; 631212795Sdim 632226890Sdim /// \brief A snapshot of the pending instantiations in the chain. 633226890Sdim /// 634226890Sdim /// This record tracks the instantiations that Sema has to perform at the 635226890Sdim /// end of the TU. It consists of a pair of values for every pending 636226890Sdim /// instantiation where the first value is the ID of the decl and the second 637226890Sdim /// is the instantiation location. 638226890Sdim SmallVector<uint64_t, 64> PendingInstantiations; 639226890Sdim 640212795Sdim //@} 641212795Sdim 642226890Sdim /// \name DiagnosticsEngine-relevant special data 643212795Sdim /// \brief Fields containing data that is used for generating diagnostics 644212795Sdim //@{ 645212795Sdim 646212795Sdim /// \brief A snapshot of Sema's unused file-scoped variable tracking, for 647212795Sdim /// generating warnings. 648226890Sdim SmallVector<uint64_t, 16> UnusedFileScopedDecls; 649212795Sdim 650223017Sdim /// \brief A list of all the delegating constructors we've seen, to diagnose 651223017Sdim /// cycles. 652226890Sdim SmallVector<uint64_t, 4> DelegatingCtorDecls; 653235633Sdim 654226890Sdim /// \brief Method selectors used in a @selector expression. Used for 655226890Sdim /// implementation of -Wselector. 656226890Sdim SmallVector<uint64_t, 64> ReferencedSelectorsData; 657223017Sdim 658212795Sdim /// \brief A snapshot of Sema's weak undeclared identifier tracking, for 659212795Sdim /// generating warnings. 660226890Sdim SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers; 661212795Sdim 662212795Sdim /// \brief The IDs of type aliases for ext_vectors that exist in the chain. 663212795Sdim /// 664212795Sdim /// Used by Sema for finding sugared names for ext_vectors in diagnostics. 665226890Sdim SmallVector<uint64_t, 4> ExtVectorDecls; 666212795Sdim 667212795Sdim //@} 668212795Sdim 669212795Sdim /// \name Sema-relevant special data 670212795Sdim /// \brief Fields containing data that is used for semantic analysis 671212795Sdim //@{ 672212795Sdim 673252723Sdim /// \brief The IDs of all locally scoped extern "C" decls in the chain. 674212795Sdim /// 675212795Sdim /// Sema tracks these to validate that the types are consistent across all 676252723Sdim /// local extern "C" declarations. 677252723Sdim SmallVector<uint64_t, 16> LocallyScopedExternCDecls; 678212795Sdim 679212795Sdim /// \brief The IDs of all dynamic class declarations in the chain. 680212795Sdim /// 681212795Sdim /// Sema tracks these because it checks for the key functions being defined 682212795Sdim /// at the end of the TU, in which case it directs CodeGen to emit the VTable. 683226890Sdim SmallVector<uint64_t, 16> DynamicClasses; 684212795Sdim 685212795Sdim /// \brief The IDs of the declarations Sema stores directly. 686212795Sdim /// 687212795Sdim /// Sema tracks a few important decls, such as namespace std, directly. 688226890Sdim SmallVector<uint64_t, 4> SemaDeclRefs; 689212795Sdim 690212795Sdim /// \brief The IDs of the types ASTContext stores directly. 691212795Sdim /// 692212795Sdim /// The AST context tracks a few important types, such as va_list, directly. 693226890Sdim SmallVector<uint64_t, 16> SpecialTypes; 694212795Sdim 695218893Sdim /// \brief The IDs of CUDA-specific declarations ASTContext stores directly. 696218893Sdim /// 697218893Sdim /// The AST context tracks a few important decls, currently cudaConfigureCall, 698218893Sdim /// directly. 699226890Sdim SmallVector<uint64_t, 2> CUDASpecialDeclRefs; 700218893Sdim 701218893Sdim /// \brief The floating point pragma option settings. 702226890Sdim SmallVector<uint64_t, 1> FPPragmaOptions; 703218893Sdim 704218893Sdim /// \brief The OpenCL extension settings. 705226890Sdim SmallVector<uint64_t, 1> OpenCLExtensions; 706218893Sdim 707224145Sdim /// \brief A list of the namespaces we've seen. 708226890Sdim SmallVector<uint64_t, 4> KnownNamespaces; 709224145Sdim 710252723Sdim /// \brief A list of undefined decls with internal linkage followed by the 711252723Sdim /// SourceLocation of a matching ODR-use. 712252723Sdim SmallVector<uint64_t, 8> UndefinedButUsed; 713252723Sdim 714263509Sdim // \brief A list of late parsed template function data. 715263509Sdim SmallVector<uint64_t, 1> LateParsedTemplates; 716263509Sdim 717235633Sdim /// \brief A list of modules that were imported by precompiled headers or 718235633Sdim /// any other non-module AST file. 719235633Sdim SmallVector<serialization::SubmoduleID, 2> ImportedModules; 720212795Sdim //@} 721212795Sdim 722218893Sdim /// \brief The directory that the PCH we are reading is stored in. 723218893Sdim std::string CurrentDir; 724218893Sdim 725212795Sdim /// \brief The system include root to be used when loading the 726212795Sdim /// precompiled header. 727226890Sdim std::string isysroot; 728212795Sdim 729212795Sdim /// \brief Whether to disable the normal validation performed on precompiled 730212795Sdim /// headers when they are loaded. 731212795Sdim bool DisableValidation; 732235633Sdim 733235633Sdim /// \brief Whether to accept an AST file with compiler errors. 734235633Sdim bool AllowASTWithCompilerErrors; 735235633Sdim 736252723Sdim /// \brief Whether we are allowed to use the global module index. 737252723Sdim bool UseGlobalIndex; 738252723Sdim 739252723Sdim /// \brief Whether we have tried loading the global module index yet. 740252723Sdim bool TriedLoadingGlobalIndex; 741252723Sdim 742235633Sdim /// \brief The current "generation" of the module file import stack, which 743235633Sdim /// indicates how many separate module file load operations have occurred. 744235633Sdim unsigned CurrentGeneration; 745235633Sdim 746245431Sdim typedef llvm::DenseMap<unsigned, SwitchCase *> SwitchCaseMapTy; 747212795Sdim /// \brief Mapping from switch-case IDs in the chain to switch-case statements 748212795Sdim /// 749212795Sdim /// Statements usually don't have IDs, but switch cases need them, so that the 750212795Sdim /// switch statement can refer to them. 751245431Sdim SwitchCaseMapTy SwitchCaseStmts; 752212795Sdim 753245431Sdim SwitchCaseMapTy *CurrSwitchCaseStmts; 754212795Sdim 755212795Sdim /// \brief The number of source location entries de-serialized from 756212795Sdim /// the PCH file. 757212795Sdim unsigned NumSLocEntriesRead; 758212795Sdim 759212795Sdim /// \brief The number of source location entries in the chain. 760212795Sdim unsigned TotalNumSLocEntries; 761212795Sdim 762212795Sdim /// \brief The number of statements (and expressions) de-serialized 763212795Sdim /// from the chain. 764212795Sdim unsigned NumStatementsRead; 765212795Sdim 766212795Sdim /// \brief The total number of statements (and expressions) stored 767212795Sdim /// in the chain. 768212795Sdim unsigned TotalNumStatements; 769212795Sdim 770212795Sdim /// \brief The number of macros de-serialized from the chain. 771212795Sdim unsigned NumMacrosRead; 772212795Sdim 773212795Sdim /// \brief The total number of macros stored in the chain. 774212795Sdim unsigned TotalNumMacros; 775212795Sdim 776252723Sdim /// \brief The number of lookups into identifier tables. 777252723Sdim unsigned NumIdentifierLookups; 778252723Sdim 779252723Sdim /// \brief The number of lookups into identifier tables that succeed. 780252723Sdim unsigned NumIdentifierLookupHits; 781252723Sdim 782212795Sdim /// \brief The number of selectors that have been read. 783212795Sdim unsigned NumSelectorsRead; 784212795Sdim 785212795Sdim /// \brief The number of method pool entries that have been read. 786212795Sdim unsigned NumMethodPoolEntriesRead; 787212795Sdim 788212795Sdim /// \brief The number of times we have looked up a selector in the method 789252723Sdim /// pool. 790252723Sdim unsigned NumMethodPoolLookups; 791212795Sdim 792252723Sdim /// \brief The number of times we have looked up a selector in the method 793252723Sdim /// pool and found something. 794252723Sdim unsigned NumMethodPoolHits; 795252723Sdim 796252723Sdim /// \brief The number of times we have looked up a selector in the method 797252723Sdim /// pool within a specific module. 798252723Sdim unsigned NumMethodPoolTableLookups; 799252723Sdim 800252723Sdim /// \brief The number of times we have looked up a selector in the method 801252723Sdim /// pool within a specific module and found something. 802252723Sdim unsigned NumMethodPoolTableHits; 803252723Sdim 804212795Sdim /// \brief The total number of method pool entries in the selector table. 805212795Sdim unsigned TotalNumMethodPoolEntries; 806212795Sdim 807212795Sdim /// Number of lexical decl contexts read/total. 808212795Sdim unsigned NumLexicalDeclContextsRead, TotalLexicalDeclContexts; 809212795Sdim 810212795Sdim /// Number of visible decl contexts read/total. 811212795Sdim unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts; 812235633Sdim 813226890Sdim /// Total size of modules, in bits, currently loaded 814226890Sdim uint64_t TotalModulesSizeInBits; 815226890Sdim 816212795Sdim /// \brief Number of Decl/types that are currently deserializing. 817212795Sdim unsigned NumCurrentElementsDeserializing; 818212795Sdim 819235633Sdim /// \brief Set true while we are in the process of passing deserialized 820235633Sdim /// "interesting" decls to consumer inside FinishedDeserializing(). 821235633Sdim /// This is used as a guard to avoid recursively repeating the process of 822235633Sdim /// passing decls to consumer. 823235633Sdim bool PassingDeclsToConsumer; 824235633Sdim 825226890Sdim /// Number of CXX base specifiers currently loaded 826226890Sdim unsigned NumCXXBaseSpecifiersLoaded; 827226890Sdim 828212795Sdim /// \brief The set of identifiers that were read while the AST reader was 829212795Sdim /// (recursively) loading declarations. 830212795Sdim /// 831212795Sdim /// The declarations on the identifier chain for these identifiers will be 832212795Sdim /// loaded once the recursive loading has completed. 833252723Sdim llvm::MapVector<IdentifierInfo *, SmallVector<uint32_t, 4> > 834252723Sdim PendingIdentifierInfos; 835212795Sdim 836235633Sdim /// \brief The generation number of each identifier, which keeps track of 837235633Sdim /// the last time we loaded information about this identifier. 838235633Sdim llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration; 839235633Sdim 840212795Sdim /// \brief Contains declarations and definitions that will be 841212795Sdim /// "interesting" to the ASTConsumer, when we get that AST consumer. 842212795Sdim /// 843212795Sdim /// "Interesting" declarations are those that have data that may 844212795Sdim /// need to be emitted, such as inline function definitions or 845212795Sdim /// Objective-C protocols. 846212795Sdim std::deque<Decl *> InterestingDecls; 847212795Sdim 848245431Sdim /// \brief The set of redeclarable declarations that have been deserialized 849235633Sdim /// since the last time the declaration chains were linked. 850235633Sdim llvm::SmallPtrSet<Decl *, 16> RedeclsDeserialized; 851235633Sdim 852235633Sdim /// \brief The list of redeclaration chains that still need to be 853235633Sdim /// reconstructed. 854235633Sdim /// 855235633Sdim /// Each element is the global declaration ID of the first declaration in 856235633Sdim /// the chain. Elements in this vector should be unique; use 857235633Sdim /// PendingDeclChainsKnown to ensure uniqueness. 858252723Sdim SmallVector<serialization::DeclID, 16> PendingDeclChains; 859218893Sdim 860235633Sdim /// \brief Keeps track of the elements added to PendingDeclChains. 861235633Sdim llvm::SmallSet<serialization::DeclID, 16> PendingDeclChainsKnown; 862235633Sdim 863252723Sdim /// \brief The Decl IDs for the Sema/Lexical DeclContext of a Decl that has 864252723Sdim /// been loaded but its DeclContext was not set yet. 865252723Sdim struct PendingDeclContextInfo { 866252723Sdim Decl *D; 867252723Sdim serialization::GlobalDeclID SemaDC; 868252723Sdim serialization::GlobalDeclID LexicalDC; 869252723Sdim }; 870252723Sdim 871252723Sdim /// \brief The set of Decls that have been loaded but their DeclContexts are 872252723Sdim /// not set yet. 873252723Sdim /// 874252723Sdim /// The DeclContexts for these Decls will be set once recursive loading has 875252723Sdim /// been completed. 876252723Sdim std::deque<PendingDeclContextInfo> PendingDeclContextInfos; 877252723Sdim 878263509Sdim /// \brief The set of NamedDecls that have been loaded, but are members of a 879263509Sdim /// context that has been merged into another context where the corresponding 880263509Sdim /// declaration is either missing or has not yet been loaded. 881263509Sdim /// 882263509Sdim /// We will check whether the corresponding declaration is in fact missing 883263509Sdim /// once recursing loading has been completed. 884263509Sdim llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks; 885263509Sdim 886235633Sdim /// \brief The set of Objective-C categories that have been deserialized 887235633Sdim /// since the last time the declaration chains were linked. 888235633Sdim llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized; 889235633Sdim 890235633Sdim /// \brief The set of Objective-C class definitions that have already been 891235633Sdim /// loaded, for which we will need to check for categories whenever a new 892235633Sdim /// module is loaded. 893252723Sdim SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded; 894235633Sdim 895252723Sdim typedef llvm::DenseMap<Decl *, SmallVector<serialization::DeclID, 2> > 896235633Sdim MergedDeclsMap; 897235633Sdim 898235633Sdim /// \brief A mapping from canonical declarations to the set of additional 899235633Sdim /// (global, previously-canonical) declaration IDs that have been merged with 900235633Sdim /// that canonical declaration. 901235633Sdim MergedDeclsMap MergedDecls; 902235633Sdim 903235633Sdim typedef llvm::DenseMap<serialization::GlobalDeclID, 904252723Sdim SmallVector<serialization::DeclID, 2> > 905235633Sdim StoredMergedDeclsMap; 906235633Sdim 907235633Sdim /// \brief A mapping from canonical declaration IDs to the set of additional 908235633Sdim /// declaration IDs that have been merged with that canonical declaration. 909235633Sdim /// 910235633Sdim /// This is the deserialized representation of the entries in MergedDecls. 911235633Sdim /// When we query entries in MergedDecls, they will be augmented with entries 912235633Sdim /// from StoredMergedDecls. 913235633Sdim StoredMergedDeclsMap StoredMergedDecls; 914235633Sdim 915235633Sdim /// \brief Combine the stored merged declarations for the given canonical 916235633Sdim /// declaration into the set of merged declarations. 917235633Sdim /// 918235633Sdim /// \returns An iterator into MergedDecls that corresponds to the position of 919235633Sdim /// the given canonical declaration. 920235633Sdim MergedDeclsMap::iterator 921235633Sdim combineStoredMergedDecls(Decl *Canon, serialization::GlobalDeclID CanonID); 922218893Sdim 923263509Sdim /// \brief A mapping from DeclContexts to the semantic DeclContext that we 924263509Sdim /// are treating as the definition of the entity. This is used, for instance, 925263509Sdim /// when merging implicit instantiations of class templates across modules. 926263509Sdim llvm::DenseMap<DeclContext *, DeclContext *> MergedDeclContexts; 927263509Sdim 928263509Sdim /// \brief A mapping from canonical declarations of enums to their canonical 929263509Sdim /// definitions. Only populated when using modules in C++. 930263509Sdim llvm::DenseMap<EnumDecl *, EnumDecl *> EnumDefinitions; 931263509Sdim 932212795Sdim /// \brief When reading a Stmt tree, Stmt operands are placed in this stack. 933226890Sdim SmallVector<Stmt *, 16> StmtStack; 934212795Sdim 935212795Sdim /// \brief What kind of records we are reading. 936212795Sdim enum ReadingKind { 937263509Sdim Read_None, Read_Decl, Read_Type, Read_Stmt 938212795Sdim }; 939212795Sdim 940235633Sdim /// \brief What kind of records we are reading. 941212795Sdim ReadingKind ReadingKind; 942212795Sdim 943212795Sdim /// \brief RAII object to change the reading kind. 944212795Sdim class ReadingKindTracker { 945212795Sdim ASTReader &Reader; 946212795Sdim enum ReadingKind PrevKind; 947212795Sdim 948245431Sdim ReadingKindTracker(const ReadingKindTracker &) LLVM_DELETED_FUNCTION; 949245431Sdim void operator=(const ReadingKindTracker &) LLVM_DELETED_FUNCTION; 950212795Sdim 951212795Sdim public: 952212795Sdim ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader) 953212795Sdim : Reader(reader), PrevKind(Reader.ReadingKind) { 954212795Sdim Reader.ReadingKind = newKind; 955212795Sdim } 956212795Sdim 957212795Sdim ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; } 958212795Sdim }; 959212795Sdim 960212795Sdim /// \brief Suggested contents of the predefines buffer, after this 961212795Sdim /// PCH file has been processed. 962212795Sdim /// 963212795Sdim /// In most cases, this string will be empty, because the predefines 964212795Sdim /// buffer computed to build the PCH file will be identical to the 965212795Sdim /// predefines buffer computed from the command line. However, when 966212795Sdim /// there are differences that the PCH reader can work around, this 967212795Sdim /// predefines buffer may contain additional definitions. 968212795Sdim std::string SuggestedPredefines; 969212795Sdim 970212795Sdim /// \brief Reads a statement from the specified cursor. 971235633Sdim Stmt *ReadStmtFromStream(ModuleFile &F); 972212795Sdim 973245431Sdim /// \brief Retrieve the file entry and 'overridden' bit for an input 974245431Sdim /// file in the given module file. 975252723Sdim serialization::InputFile getInputFile(ModuleFile &F, unsigned ID, 976252723Sdim bool Complain = true); 977245431Sdim 978223017Sdim /// \brief Get a FileEntry out of stored-in-PCH filename, making sure we take 979223017Sdim /// into account all the necessary relocations. 980226890Sdim const FileEntry *getFileEntry(StringRef filename); 981223017Sdim 982245431Sdim void MaybeAddSystemRootToFilename(ModuleFile &M, std::string &Filename); 983212795Sdim 984252723Sdim struct ImportedModule { 985252723Sdim ModuleFile *Mod; 986252723Sdim ModuleFile *ImportedBy; 987252723Sdim SourceLocation ImportLoc; 988252723Sdim 989252723Sdim ImportedModule(ModuleFile *Mod, 990252723Sdim ModuleFile *ImportedBy, 991252723Sdim SourceLocation ImportLoc) 992252723Sdim : Mod(Mod), ImportedBy(ImportedBy), ImportLoc(ImportLoc) { } 993252723Sdim }; 994252723Sdim 995226890Sdim ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type, 996252723Sdim SourceLocation ImportLoc, ModuleFile *ImportedBy, 997252723Sdim SmallVectorImpl<ImportedModule> &Loaded, 998252723Sdim off_t ExpectedSize, time_t ExpectedModTime, 999245431Sdim unsigned ClientLoadCapabilities); 1000245431Sdim ASTReadResult ReadControlBlock(ModuleFile &F, 1001252723Sdim SmallVectorImpl<ImportedModule> &Loaded, 1002245431Sdim unsigned ClientLoadCapabilities); 1003245431Sdim bool ReadASTBlock(ModuleFile &F); 1004235633Sdim bool ParseLineTable(ModuleFile &F, SmallVectorImpl<uint64_t> &Record); 1005245431Sdim bool ReadSourceManagerBlock(ModuleFile &F); 1006226890Sdim llvm::BitstreamCursor &SLocCursorForID(int ID); 1007235633Sdim SourceLocation getImportLocation(ModuleFile *F); 1008245431Sdim bool ReadSubmoduleBlock(ModuleFile &F); 1009245431Sdim static bool ParseLanguageOptions(const RecordData &Record, bool Complain, 1010245431Sdim ASTReaderListener &Listener); 1011245431Sdim static bool ParseTargetOptions(const RecordData &Record, bool Complain, 1012245431Sdim ASTReaderListener &Listener); 1013245431Sdim static bool ParseDiagnosticOptions(const RecordData &Record, bool Complain, 1014245431Sdim ASTReaderListener &Listener); 1015245431Sdim static bool ParseFileSystemOptions(const RecordData &Record, bool Complain, 1016245431Sdim ASTReaderListener &Listener); 1017245431Sdim static bool ParseHeaderSearchOptions(const RecordData &Record, bool Complain, 1018245431Sdim ASTReaderListener &Listener); 1019245431Sdim static bool ParsePreprocessorOptions(const RecordData &Record, bool Complain, 1020245431Sdim ASTReaderListener &Listener, 1021245431Sdim std::string &SuggestedPredefines); 1022245431Sdim 1023218893Sdim struct RecordLocation { 1024235633Sdim RecordLocation(ModuleFile *M, uint64_t O) 1025218893Sdim : F(M), Offset(O) {} 1026235633Sdim ModuleFile *F; 1027218893Sdim uint64_t Offset; 1028218893Sdim }; 1029212795Sdim 1030226890Sdim QualType readTypeRecord(unsigned Index); 1031212795Sdim RecordLocation TypeCursorForIndex(unsigned Index); 1032212795Sdim void LoadedDecl(unsigned Index, Decl *D); 1033226890Sdim Decl *ReadDeclRecord(serialization::DeclID ID); 1034235633Sdim RecordLocation DeclCursorForID(serialization::DeclID ID, 1035235633Sdim unsigned &RawLocation); 1036226890Sdim void loadDeclUpdateRecords(serialization::DeclID ID, Decl *D); 1037235633Sdim void loadPendingDeclChain(serialization::GlobalDeclID ID); 1038235633Sdim void loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D, 1039235633Sdim unsigned PreviousGeneration = 0); 1040235633Sdim 1041226890Sdim RecordLocation getLocalBitOffset(uint64_t GlobalOffset); 1042235633Sdim uint64_t getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset); 1043212795Sdim 1044245431Sdim /// \brief Returns the first preprocessed entity ID that ends after BLoc. 1045226890Sdim serialization::PreprocessedEntityID 1046226890Sdim findBeginPreprocessedEntity(SourceLocation BLoc) const; 1047226890Sdim 1048245431Sdim /// \brief Returns the first preprocessed entity ID that begins after ELoc. 1049226890Sdim serialization::PreprocessedEntityID 1050226890Sdim findEndPreprocessedEntity(SourceLocation ELoc) const; 1051226890Sdim 1052245431Sdim /// \brief Find the next module that contains entities and return the ID 1053226890Sdim /// of the first entry. 1054245431Sdim /// 1055245431Sdim /// \param SLocMapI points at a chunk of a module that contains no 1056245431Sdim /// preprocessed entities or the entities it contains are not the 1057245431Sdim /// ones we are looking for. 1058226890Sdim serialization::PreprocessedEntityID 1059226890Sdim findNextPreprocessedEntity( 1060226890Sdim GlobalSLocOffsetMapType::const_iterator SLocMapI) const; 1061226890Sdim 1062245431Sdim /// \brief Returns (ModuleFile, Local index) pair for \p GlobalIndex of a 1063235633Sdim /// preprocessed entity. 1064235633Sdim std::pair<ModuleFile *, unsigned> 1065235633Sdim getModulePreprocessedEntity(unsigned GlobalIndex); 1066235633Sdim 1067245431Sdim /// \brief Returns (begin, end) pair for the preprocessed entities of a 1068245431Sdim /// particular module. 1069245431Sdim std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator> 1070245431Sdim getModulePreprocessedEntities(ModuleFile &Mod) const; 1071245431Sdim 1072245431Sdim class ModuleDeclIterator { 1073245431Sdim ASTReader *Reader; 1074245431Sdim ModuleFile *Mod; 1075245431Sdim const serialization::LocalDeclID *Pos; 1076245431Sdim 1077245431Sdim public: 1078245431Sdim typedef const Decl *value_type; 1079245431Sdim typedef value_type& reference; 1080245431Sdim typedef value_type* pointer; 1081245431Sdim 1082245431Sdim ModuleDeclIterator() : Reader(0), Mod(0), Pos(0) { } 1083245431Sdim 1084245431Sdim ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod, 1085245431Sdim const serialization::LocalDeclID *Pos) 1086245431Sdim : Reader(Reader), Mod(Mod), Pos(Pos) { } 1087245431Sdim 1088245431Sdim value_type operator*() const { 1089245431Sdim return Reader->GetDecl(Reader->getGlobalDeclID(*Mod, *Pos)); 1090245431Sdim } 1091245431Sdim 1092245431Sdim ModuleDeclIterator &operator++() { 1093245431Sdim ++Pos; 1094245431Sdim return *this; 1095245431Sdim } 1096245431Sdim 1097245431Sdim ModuleDeclIterator operator++(int) { 1098245431Sdim ModuleDeclIterator Prev(*this); 1099245431Sdim ++Pos; 1100245431Sdim return Prev; 1101245431Sdim } 1102245431Sdim 1103245431Sdim ModuleDeclIterator &operator--() { 1104245431Sdim --Pos; 1105245431Sdim return *this; 1106245431Sdim } 1107245431Sdim 1108245431Sdim ModuleDeclIterator operator--(int) { 1109245431Sdim ModuleDeclIterator Prev(*this); 1110245431Sdim --Pos; 1111245431Sdim return Prev; 1112245431Sdim } 1113245431Sdim 1114245431Sdim friend bool operator==(const ModuleDeclIterator &LHS, 1115245431Sdim const ModuleDeclIterator &RHS) { 1116245431Sdim assert(LHS.Reader == RHS.Reader && LHS.Mod == RHS.Mod); 1117245431Sdim return LHS.Pos == RHS.Pos; 1118245431Sdim } 1119245431Sdim 1120245431Sdim friend bool operator!=(const ModuleDeclIterator &LHS, 1121245431Sdim const ModuleDeclIterator &RHS) { 1122245431Sdim assert(LHS.Reader == RHS.Reader && LHS.Mod == RHS.Mod); 1123245431Sdim return LHS.Pos != RHS.Pos; 1124245431Sdim } 1125245431Sdim }; 1126245431Sdim 1127245431Sdim std::pair<ModuleDeclIterator, ModuleDeclIterator> 1128245431Sdim getModuleFileLevelDecls(ModuleFile &Mod); 1129245431Sdim 1130212795Sdim void PassInterestingDeclsToConsumer(); 1131235633Sdim void PassInterestingDeclToConsumer(Decl *D); 1132212795Sdim 1133235633Sdim void finishPendingActions(); 1134235633Sdim 1135252723Sdim void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name); 1136252723Sdim 1137252723Sdim void addPendingDeclContextInfo(Decl *D, 1138252723Sdim serialization::GlobalDeclID SemaDC, 1139252723Sdim serialization::GlobalDeclID LexicalDC) { 1140252723Sdim assert(D); 1141252723Sdim PendingDeclContextInfo Info = { D, SemaDC, LexicalDC }; 1142252723Sdim PendingDeclContextInfos.push_back(Info); 1143252723Sdim } 1144252723Sdim 1145212795Sdim /// \brief Produce an error diagnostic and return true. 1146212795Sdim /// 1147212795Sdim /// This routine should only be used for fatal errors that have to 1148212795Sdim /// do with non-routine failures (e.g., corrupted AST file). 1149226890Sdim void Error(StringRef Msg); 1150226890Sdim void Error(unsigned DiagID, StringRef Arg1 = StringRef(), 1151226890Sdim StringRef Arg2 = StringRef()); 1152212795Sdim 1153245431Sdim ASTReader(const ASTReader &) LLVM_DELETED_FUNCTION; 1154245431Sdim void operator=(const ASTReader &) LLVM_DELETED_FUNCTION; 1155212795Sdimpublic: 1156212795Sdim /// \brief Load the AST file and validate its contents against the given 1157212795Sdim /// Preprocessor. 1158212795Sdim /// 1159212795Sdim /// \param PP the preprocessor associated with the context in which this 1160212795Sdim /// precompiled header will be loaded. 1161212795Sdim /// 1162212795Sdim /// \param Context the AST context that this precompiled header will be 1163212795Sdim /// loaded into. 1164212795Sdim /// 1165212795Sdim /// \param isysroot If non-NULL, the system include path specified by the 1166212795Sdim /// user. This is only used with relocatable PCH files. If non-NULL, 1167212795Sdim /// a relocatable PCH file will use the default path "/". 1168212795Sdim /// 1169212795Sdim /// \param DisableValidation If true, the AST reader will suppress most 1170212795Sdim /// of its regular consistency checking, allowing the use of precompiled 1171212795Sdim /// headers that cannot be determined to be compatible. 1172218893Sdim /// 1173235633Sdim /// \param AllowASTWithCompilerErrors If true, the AST reader will accept an 1174235633Sdim /// AST file the was created out of an AST with compiler errors, 1175235633Sdim /// otherwise it will reject it. 1176252723Sdim /// 1177252723Sdim /// \param UseGlobalIndex If true, the AST reader will try to load and use 1178252723Sdim /// the global module index. 1179226890Sdim ASTReader(Preprocessor &PP, ASTContext &Context, StringRef isysroot = "", 1180245431Sdim bool DisableValidation = false, 1181252723Sdim bool AllowASTWithCompilerErrors = false, 1182252723Sdim bool UseGlobalIndex = true); 1183212795Sdim 1184212795Sdim ~ASTReader(); 1185212795Sdim 1186226890Sdim SourceManager &getSourceManager() const { return SourceMgr; } 1187252723Sdim FileManager &getFileManager() const { return FileMgr; } 1188235633Sdim 1189245431Sdim /// \brief Flags that indicate what kind of AST loading failures the client 1190245431Sdim /// of the AST reader can directly handle. 1191245431Sdim /// 1192245431Sdim /// When a client states that it can handle a particular kind of failure, 1193245431Sdim /// the AST reader will not emit errors when producing that kind of failure. 1194245431Sdim enum LoadFailureCapabilities { 1195245431Sdim /// \brief The client can't handle any AST loading failures. 1196245431Sdim ARR_None = 0, 1197245431Sdim /// \brief The client can handle an AST file that cannot load because it 1198252723Sdim /// is missing. 1199252723Sdim ARR_Missing = 0x1, 1200252723Sdim /// \brief The client can handle an AST file that cannot load because it 1201245431Sdim /// is out-of-date relative to its input files. 1202252723Sdim ARR_OutOfDate = 0x2, 1203245431Sdim /// \brief The client can handle an AST file that cannot load because it 1204245431Sdim /// was built with a different version of Clang. 1205252723Sdim ARR_VersionMismatch = 0x4, 1206245431Sdim /// \brief The client can handle an AST file that cannot load because it's 1207245431Sdim /// compiled configuration doesn't match that of the context it was 1208245431Sdim /// loaded into. 1209252723Sdim ARR_ConfigurationMismatch = 0x8 1210245431Sdim }; 1211245431Sdim 1212226890Sdim /// \brief Load the AST file designated by the given file name. 1213245431Sdim /// 1214245431Sdim /// \param FileName The name of the AST file to load. 1215245431Sdim /// 1216245431Sdim /// \param Type The kind of AST being loaded, e.g., PCH, module, main file, 1217245431Sdim /// or preamble. 1218245431Sdim /// 1219252723Sdim /// \param ImportLoc the location where the module file will be considered as 1220252723Sdim /// imported from. For non-module AST types it should be invalid. 1221252723Sdim /// 1222245431Sdim /// \param ClientLoadCapabilities The set of client load-failure 1223245431Sdim /// capabilities, represented as a bitset of the enumerators of 1224245431Sdim /// LoadFailureCapabilities. 1225245431Sdim ASTReadResult ReadAST(const std::string &FileName, ModuleKind Type, 1226252723Sdim SourceLocation ImportLoc, 1227245431Sdim unsigned ClientLoadCapabilities); 1228212795Sdim 1229235633Sdim /// \brief Make the entities in the given module and any of its (non-explicit) 1230235633Sdim /// submodules visible to name lookup. 1231235633Sdim /// 1232235633Sdim /// \param Mod The module whose names should be made visible. 1233235633Sdim /// 1234245431Sdim /// \param NameVisibility The level of visibility to give the names in the 1235245431Sdim /// module. Visibility can only be increased over time. 1236252723Sdim /// 1237252723Sdim /// \param ImportLoc The location at which the import occurs. 1238252723Sdim /// 1239252723Sdim /// \param Complain Whether to complain about conflicting module imports. 1240235633Sdim void makeModuleVisible(Module *Mod, 1241252723Sdim Module::NameVisibilityKind NameVisibility, 1242252723Sdim SourceLocation ImportLoc, 1243252723Sdim bool Complain); 1244235633Sdim 1245235633Sdim /// \brief Make the names within this set of hidden names visible. 1246252723Sdim void makeNamesVisible(const HiddenNames &Names, Module *Owner); 1247235633Sdim 1248212795Sdim /// \brief Set the AST callbacks listener. 1249212795Sdim void setListener(ASTReaderListener *listener) { 1250212795Sdim Listener.reset(listener); 1251212795Sdim } 1252212795Sdim 1253212795Sdim /// \brief Set the AST deserialization listener. 1254212795Sdim void setDeserializationListener(ASTDeserializationListener *Listener); 1255212795Sdim 1256252723Sdim /// \brief Determine whether this AST reader has a global index. 1257263509Sdim bool hasGlobalIndex() const { return GlobalIndex.isValid(); } 1258252723Sdim 1259252723Sdim /// \brief Attempts to load the global index. 1260252723Sdim /// 1261252723Sdim /// \returns true if loading the global index has failed for any reason. 1262252723Sdim bool loadGlobalIndex(); 1263252723Sdim 1264252723Sdim /// \brief Determine whether we tried to load the global index, but failed, 1265252723Sdim /// e.g., because it is out-of-date or does not exist. 1266252723Sdim bool isGlobalIndexUnavailable() const; 1267252723Sdim 1268226890Sdim /// \brief Initializes the ASTContext 1269226890Sdim void InitializeContext(); 1270212795Sdim 1271263509Sdim /// \brief Update the state of Sema after loading some additional modules. 1272263509Sdim void UpdateSema(); 1273263509Sdim 1274226890Sdim /// \brief Add in-memory (virtual file) buffer. 1275226890Sdim void addInMemoryBuffer(StringRef &FileName, llvm::MemoryBuffer *Buffer) { 1276226890Sdim ModuleMgr.addInMemoryBuffer(FileName, Buffer); 1277221345Sdim } 1278221345Sdim 1279235633Sdim /// \brief Finalizes the AST reader's state before writing an AST file to 1280235633Sdim /// disk. 1281235633Sdim /// 1282235633Sdim /// This operation may undo temporary state in the AST that should not be 1283235633Sdim /// emitted. 1284235633Sdim void finalizeForWriting(); 1285235633Sdim 1286226890Sdim /// \brief Retrieve the module manager. 1287226890Sdim ModuleManager &getModuleManager() { return ModuleMgr; } 1288212795Sdim 1289226890Sdim /// \brief Retrieve the preprocessor. 1290226890Sdim Preprocessor &getPreprocessor() const { return PP; } 1291235633Sdim 1292245431Sdim /// \brief Retrieve the name of the original source file name for the primary 1293245431Sdim /// module file. 1294245431Sdim StringRef getOriginalSourceFile() { 1295245431Sdim return ModuleMgr.getPrimaryModule().OriginalSourceFileName; 1296245431Sdim } 1297212795Sdim 1298212795Sdim /// \brief Retrieve the name of the original source file name directly from 1299212795Sdim /// the AST file, without actually loading the AST file. 1300212795Sdim static std::string getOriginalSourceFile(const std::string &ASTFileName, 1301218893Sdim FileManager &FileMgr, 1302226890Sdim DiagnosticsEngine &Diags); 1303212795Sdim 1304245431Sdim /// \brief Read the control block for the named AST file. 1305245431Sdim /// 1306245431Sdim /// \returns true if an error occurred, false otherwise. 1307245431Sdim static bool readASTFileControlBlock(StringRef Filename, 1308245431Sdim FileManager &FileMgr, 1309245431Sdim ASTReaderListener &Listener); 1310245431Sdim 1311245431Sdim /// \brief Determine whether the given AST file is acceptable to load into a 1312245431Sdim /// translation unit with the given language and target options. 1313245431Sdim static bool isAcceptableASTFile(StringRef Filename, 1314245431Sdim FileManager &FileMgr, 1315245431Sdim const LangOptions &LangOpts, 1316245431Sdim const TargetOptions &TargetOpts, 1317245431Sdim const PreprocessorOptions &PPOpts); 1318245431Sdim 1319212795Sdim /// \brief Returns the suggested contents of the predefines buffer, 1320212795Sdim /// which contains a (typically-empty) subset of the predefines 1321212795Sdim /// build prior to including the precompiled header. 1322212795Sdim const std::string &getSuggestedPredefines() { return SuggestedPredefines; } 1323212795Sdim 1324226890Sdim /// \brief Read a preallocated preprocessed entity from the external source. 1325226890Sdim /// 1326226890Sdim /// \returns null if an error occurred that prevented the preprocessed 1327226890Sdim /// entity from being loaded. 1328226890Sdim virtual PreprocessedEntity *ReadPreprocessedEntity(unsigned Index); 1329218893Sdim 1330226890Sdim /// \brief Returns a pair of [Begin, End) indices of preallocated 1331245431Sdim /// preprocessed entities that \p Range encompasses. 1332226890Sdim virtual std::pair<unsigned, unsigned> 1333226890Sdim findPreprocessedEntitiesInRange(SourceRange Range); 1334226890Sdim 1335235633Sdim /// \brief Optionally returns true or false if the preallocated preprocessed 1336245431Sdim /// entity with index \p Index came from file \p FID. 1337252723Sdim virtual Optional<bool> isPreprocessedEntityInFileID(unsigned Index, 1338252723Sdim FileID FID); 1339235633Sdim 1340218893Sdim /// \brief Read the header file information for the given file entry. 1341218893Sdim virtual HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE); 1342218893Sdim 1343226890Sdim void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag); 1344218893Sdim 1345212795Sdim /// \brief Returns the number of source locations found in the chain. 1346212795Sdim unsigned getTotalNumSLocs() const { 1347212795Sdim return TotalNumSLocEntries; 1348212795Sdim } 1349212795Sdim 1350212795Sdim /// \brief Returns the number of identifiers found in the chain. 1351212795Sdim unsigned getTotalNumIdentifiers() const { 1352212795Sdim return static_cast<unsigned>(IdentifiersLoaded.size()); 1353212795Sdim } 1354212795Sdim 1355245431Sdim /// \brief Returns the number of macros found in the chain. 1356245431Sdim unsigned getTotalNumMacros() const { 1357245431Sdim return static_cast<unsigned>(MacrosLoaded.size()); 1358245431Sdim } 1359245431Sdim 1360212795Sdim /// \brief Returns the number of types found in the chain. 1361212795Sdim unsigned getTotalNumTypes() const { 1362212795Sdim return static_cast<unsigned>(TypesLoaded.size()); 1363212795Sdim } 1364212795Sdim 1365212795Sdim /// \brief Returns the number of declarations found in the chain. 1366212795Sdim unsigned getTotalNumDecls() const { 1367212795Sdim return static_cast<unsigned>(DeclsLoaded.size()); 1368212795Sdim } 1369212795Sdim 1370235633Sdim /// \brief Returns the number of submodules known. 1371235633Sdim unsigned getTotalNumSubmodules() const { 1372235633Sdim return static_cast<unsigned>(SubmodulesLoaded.size()); 1373235633Sdim } 1374235633Sdim 1375212795Sdim /// \brief Returns the number of selectors found in the chain. 1376212795Sdim unsigned getTotalNumSelectors() const { 1377212795Sdim return static_cast<unsigned>(SelectorsLoaded.size()); 1378212795Sdim } 1379212795Sdim 1380226890Sdim /// \brief Returns the number of preprocessed entities known to the AST 1381226890Sdim /// reader. 1382226890Sdim unsigned getTotalNumPreprocessedEntities() const { 1383226890Sdim unsigned Result = 0; 1384226890Sdim for (ModuleConstIterator I = ModuleMgr.begin(), 1385226890Sdim E = ModuleMgr.end(); I != E; ++I) { 1386226890Sdim Result += (*I)->NumPreprocessedEntities; 1387226890Sdim } 1388235633Sdim 1389226890Sdim return Result; 1390218893Sdim } 1391235633Sdim 1392218893Sdim /// \brief Returns the number of C++ base specifiers found in the chain. 1393226890Sdim unsigned getTotalNumCXXBaseSpecifiers() const { 1394226890Sdim return NumCXXBaseSpecifiersLoaded; 1395226890Sdim } 1396235633Sdim 1397212795Sdim /// \brief Reads a TemplateArgumentLocInfo appropriate for the 1398212795Sdim /// given TemplateArgument kind. 1399212795Sdim TemplateArgumentLocInfo 1400235633Sdim GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind, 1401212795Sdim const RecordData &Record, unsigned &Idx); 1402212795Sdim 1403212795Sdim /// \brief Reads a TemplateArgumentLoc. 1404212795Sdim TemplateArgumentLoc 1405235633Sdim ReadTemplateArgumentLoc(ModuleFile &F, 1406212795Sdim const RecordData &Record, unsigned &Idx); 1407212795Sdim 1408263509Sdim const ASTTemplateArgumentListInfo* 1409263509Sdim ReadASTTemplateArgumentListInfo(ModuleFile &F, 1410263509Sdim const RecordData &Record, unsigned &Index); 1411263509Sdim 1412212795Sdim /// \brief Reads a declarator info from the given record. 1413235633Sdim TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F, 1414212795Sdim const RecordData &Record, unsigned &Idx); 1415212795Sdim 1416212795Sdim /// \brief Resolve a type ID into a type, potentially building a new 1417212795Sdim /// type. 1418212795Sdim QualType GetType(serialization::TypeID ID); 1419212795Sdim 1420226890Sdim /// \brief Resolve a local type ID within a given AST file into a type. 1421235633Sdim QualType getLocalType(ModuleFile &F, unsigned LocalID); 1422235633Sdim 1423226890Sdim /// \brief Map a local type ID within a given AST file into a global type ID. 1424235633Sdim serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const; 1425235633Sdim 1426235633Sdim /// \brief Read a type from the current position in the given record, which 1427226890Sdim /// was read from the given AST file. 1428235633Sdim QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) { 1429226890Sdim if (Idx >= Record.size()) 1430226890Sdim return QualType(); 1431235633Sdim 1432226890Sdim return getLocalType(F, Record[Idx++]); 1433226890Sdim } 1434235633Sdim 1435235633Sdim /// \brief Map from a local declaration ID within a given module to a 1436226890Sdim /// global declaration ID. 1437245431Sdim serialization::DeclID getGlobalDeclID(ModuleFile &F, 1438245431Sdim serialization::LocalDeclID LocalID) const; 1439212795Sdim 1440245431Sdim /// \brief Returns true if global DeclID \p ID originated from module \p M. 1441235633Sdim bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const; 1442235633Sdim 1443235633Sdim /// \brief Retrieve the module file that owns the given declaration, or NULL 1444235633Sdim /// if the declaration is not from a module file. 1445252723Sdim ModuleFile *getOwningModuleFile(const Decl *D); 1446226890Sdim 1447245431Sdim /// \brief Returns the source location for the decl \p ID. 1448235633Sdim SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID); 1449235633Sdim 1450212795Sdim /// \brief Resolve a declaration ID into a declaration, potentially 1451212795Sdim /// building a new declaration. 1452212795Sdim Decl *GetDecl(serialization::DeclID ID); 1453212795Sdim virtual Decl *GetExternalDecl(uint32_t ID); 1454212795Sdim 1455226890Sdim /// \brief Reads a declaration with the given local ID in the given module. 1456235633Sdim Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) { 1457226890Sdim return GetDecl(getGlobalDeclID(F, LocalID)); 1458226890Sdim } 1459226890Sdim 1460226890Sdim /// \brief Reads a declaration with the given local ID in the given module. 1461226890Sdim /// 1462226890Sdim /// \returns The requested declaration, casted to the given return type. 1463226890Sdim template<typename T> 1464235633Sdim T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) { 1465226890Sdim return cast_or_null<T>(GetLocalDecl(F, LocalID)); 1466226890Sdim } 1467226890Sdim 1468235633Sdim /// \brief Map a global declaration ID into the declaration ID used to 1469235633Sdim /// refer to this declaration within the given module fule. 1470235633Sdim /// 1471235633Sdim /// \returns the global ID of the given declaration as known in the given 1472235633Sdim /// module file. 1473235633Sdim serialization::DeclID 1474235633Sdim mapGlobalIDToModuleFileGlobalID(ModuleFile &M, 1475235633Sdim serialization::DeclID GlobalID); 1476235633Sdim 1477235633Sdim /// \brief Reads a declaration ID from the given position in a record in the 1478226890Sdim /// given module. 1479226890Sdim /// 1480226890Sdim /// \returns The declaration ID read from the record, adjusted to a global ID. 1481235633Sdim serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record, 1482226890Sdim unsigned &Idx); 1483235633Sdim 1484226890Sdim /// \brief Reads a declaration from the given position in a record in the 1485226890Sdim /// given module. 1486235633Sdim Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) { 1487226890Sdim return GetDecl(ReadDeclID(F, R, I)); 1488226890Sdim } 1489235633Sdim 1490226890Sdim /// \brief Reads a declaration from the given position in a record in the 1491226890Sdim /// given module. 1492226890Sdim /// 1493226890Sdim /// \returns The declaration read from this location, casted to the given 1494226890Sdim /// result type. 1495226890Sdim template<typename T> 1496235633Sdim T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) { 1497226890Sdim return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I))); 1498226890Sdim } 1499226890Sdim 1500226890Sdim /// \brief Read a CXXBaseSpecifiers ID form the given record and 1501226890Sdim /// return its global bit offset. 1502235633Sdim uint64_t readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record, 1503226890Sdim unsigned &Idx); 1504235633Sdim 1505218893Sdim virtual CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset); 1506235633Sdim 1507212795Sdim /// \brief Resolve the offset of a statement into a statement. 1508212795Sdim /// 1509212795Sdim /// This operation will read a new statement from the external 1510212795Sdim /// source each time it is called, and is meant to be used via a 1511212795Sdim /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). 1512212795Sdim virtual Stmt *GetExternalDeclStmt(uint64_t Offset); 1513212795Sdim 1514212795Sdim /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the 1515212795Sdim /// specified cursor. Read the abbreviations that are at the top of the block 1516212795Sdim /// and then leave the cursor pointing into the block. 1517212795Sdim bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID); 1518212795Sdim 1519212795Sdim /// \brief Finds all the visible declarations with a given name. 1520212795Sdim /// The current implementation of this method just loads the entire 1521212795Sdim /// lookup table as unmaterialized references. 1522252723Sdim virtual bool 1523212795Sdim FindExternalVisibleDeclsByName(const DeclContext *DC, 1524212795Sdim DeclarationName Name); 1525212795Sdim 1526212795Sdim /// \brief Read all of the declarations lexically stored in a 1527212795Sdim /// declaration context. 1528212795Sdim /// 1529212795Sdim /// \param DC The declaration context whose declarations will be 1530212795Sdim /// read. 1531212795Sdim /// 1532212795Sdim /// \param Decls Vector that will contain the declarations loaded 1533212795Sdim /// from the external source. The caller is responsible for merging 1534212795Sdim /// these declarations with any declarations already stored in the 1535212795Sdim /// declaration context. 1536212795Sdim /// 1537212795Sdim /// \returns true if there was an error while reading the 1538212795Sdim /// declarations for this declaration context. 1539224145Sdim virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC, 1540218893Sdim bool (*isKindWeWant)(Decl::Kind), 1541226890Sdim SmallVectorImpl<Decl*> &Decls); 1542212795Sdim 1543235633Sdim /// \brief Get the decls that are contained in a file in the Offset/Length 1544245431Sdim /// range. \p Length can be 0 to indicate a point at \p Offset instead of 1545235633Sdim /// a range. 1546235633Sdim virtual void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length, 1547235633Sdim SmallVectorImpl<Decl *> &Decls); 1548235633Sdim 1549212795Sdim /// \brief Notify ASTReader that we started deserialization of 1550212795Sdim /// a decl or type so until FinishedDeserializing is called there may be 1551212795Sdim /// decls that are initializing. Must be paired with FinishedDeserializing. 1552212795Sdim virtual void StartedDeserializing() { ++NumCurrentElementsDeserializing; } 1553212795Sdim 1554212795Sdim /// \brief Notify ASTReader that we finished the deserialization of 1555212795Sdim /// a decl or type. Must be paired with StartedDeserializing. 1556212795Sdim virtual void FinishedDeserializing(); 1557212795Sdim 1558212795Sdim /// \brief Function that will be invoked when we begin parsing a new 1559212795Sdim /// translation unit involving this external AST source. 1560212795Sdim /// 1561212795Sdim /// This function will provide all of the external definitions to 1562212795Sdim /// the ASTConsumer. 1563212795Sdim virtual void StartTranslationUnit(ASTConsumer *Consumer); 1564212795Sdim 1565212795Sdim /// \brief Print some statistics about AST usage. 1566212795Sdim virtual void PrintStats(); 1567212795Sdim 1568226890Sdim /// \brief Dump information about the AST reader to standard error. 1569226890Sdim void dump(); 1570235633Sdim 1571221345Sdim /// Return the amount of memory used by memory buffers, breaking down 1572221345Sdim /// by heap-backed versus mmap'ed memory. 1573221345Sdim virtual void getMemoryBufferSizes(MemoryBufferSizes &sizes) const; 1574221345Sdim 1575212795Sdim /// \brief Initialize the semantic source with the Sema instance 1576212795Sdim /// being used to perform semantic analysis on the abstract syntax 1577212795Sdim /// tree. 1578212795Sdim virtual void InitializeSema(Sema &S); 1579212795Sdim 1580212795Sdim /// \brief Inform the semantic consumer that Sema is no longer available. 1581212795Sdim virtual void ForgetSema() { SemaObj = 0; } 1582212795Sdim 1583212795Sdim /// \brief Retrieve the IdentifierInfo for the named identifier. 1584212795Sdim /// 1585212795Sdim /// This routine builds a new IdentifierInfo for the given identifier. If any 1586212795Sdim /// declarations with this name are visible from translation unit scope, their 1587212795Sdim /// declarations will be deserialized and introduced into the declaration 1588212795Sdim /// chain of the identifier. 1589212795Sdim virtual IdentifierInfo *get(const char *NameStart, const char *NameEnd); 1590226890Sdim IdentifierInfo *get(StringRef Name) { 1591212795Sdim return get(Name.begin(), Name.end()); 1592212795Sdim } 1593212795Sdim 1594218893Sdim /// \brief Retrieve an iterator into the set of all identifiers 1595218893Sdim /// in all loaded AST files. 1596252723Sdim virtual IdentifierIterator *getIdentifiers(); 1597218893Sdim 1598212795Sdim /// \brief Load the contents of the global method pool for a given 1599212795Sdim /// selector. 1600235633Sdim virtual void ReadMethodPool(Selector Sel); 1601212795Sdim 1602224145Sdim /// \brief Load the set of namespaces that are known to the external source, 1603224145Sdim /// which will be used during typo correction. 1604224145Sdim virtual void ReadKnownNamespaces( 1605226890Sdim SmallVectorImpl<NamespaceDecl *> &Namespaces); 1606224145Sdim 1607252723Sdim virtual void ReadUndefinedButUsed( 1608252723Sdim llvm::DenseMap<NamedDecl *, SourceLocation> &Undefined); 1609252723Sdim 1610226890Sdim virtual void ReadTentativeDefinitions( 1611226890Sdim SmallVectorImpl<VarDecl *> &TentativeDefs); 1612226890Sdim 1613226890Sdim virtual void ReadUnusedFileScopedDecls( 1614226890Sdim SmallVectorImpl<const DeclaratorDecl *> &Decls); 1615226890Sdim 1616226890Sdim virtual void ReadDelegatingConstructors( 1617226890Sdim SmallVectorImpl<CXXConstructorDecl *> &Decls); 1618226890Sdim 1619226890Sdim virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls); 1620226890Sdim 1621226890Sdim virtual void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls); 1622226890Sdim 1623252723Sdim virtual void ReadLocallyScopedExternCDecls( 1624226890Sdim SmallVectorImpl<NamedDecl *> &Decls); 1625235633Sdim 1626226890Sdim virtual void ReadReferencedSelectors( 1627226890Sdim SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels); 1628226890Sdim 1629226890Sdim virtual void ReadWeakUndeclaredIdentifiers( 1630226890Sdim SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI); 1631226890Sdim 1632226890Sdim virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables); 1633226890Sdim 1634226890Sdim virtual void ReadPendingInstantiations( 1635235633Sdim SmallVectorImpl<std::pair<ValueDecl *, 1636226890Sdim SourceLocation> > &Pending); 1637226890Sdim 1638263509Sdim virtual void ReadLateParsedTemplates( 1639263509Sdim llvm::DenseMap<const FunctionDecl *, LateParsedTemplate *> &LPTMap); 1640263509Sdim 1641212795Sdim /// \brief Load a selector from disk, registering its ID if it exists. 1642212795Sdim void LoadSelector(Selector Sel); 1643212795Sdim 1644212795Sdim void SetIdentifierInfo(unsigned ID, IdentifierInfo *II); 1645212795Sdim void SetGloballyVisibleDecls(IdentifierInfo *II, 1646226890Sdim const SmallVectorImpl<uint32_t> &DeclIDs, 1647252723Sdim SmallVectorImpl<Decl *> *Decls = 0); 1648212795Sdim 1649212795Sdim /// \brief Report a diagnostic. 1650212795Sdim DiagnosticBuilder Diag(unsigned DiagID); 1651212795Sdim 1652212795Sdim /// \brief Report a diagnostic. 1653212795Sdim DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); 1654212795Sdim 1655226890Sdim IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID); 1656212795Sdim 1657235633Sdim IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record, 1658226890Sdim unsigned &Idx) { 1659226890Sdim return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++])); 1660212795Sdim } 1661212795Sdim 1662226890Sdim virtual IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) { 1663245431Sdim // Note that we are loading an identifier. 1664245431Sdim Deserializing AnIdentifier(this); 1665245431Sdim 1666212795Sdim return DecodeIdentifierInfo(ID); 1667212795Sdim } 1668212795Sdim 1669235633Sdim IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID); 1670235633Sdim 1671235633Sdim serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M, 1672226890Sdim unsigned LocalID); 1673235633Sdim 1674252723Sdim void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo); 1675252723Sdim 1676252723Sdim void installPCHMacroDirectives(IdentifierInfo *II, 1677252723Sdim ModuleFile &M, uint64_t Offset); 1678252723Sdim 1679252723Sdim void installImportedMacro(IdentifierInfo *II, MacroDirective *MD, 1680252723Sdim Module *Owner); 1681252723Sdim 1682245431Sdim /// \brief Retrieve the macro with the given ID. 1683252723Sdim MacroInfo *getMacro(serialization::MacroID ID); 1684245431Sdim 1685245431Sdim /// \brief Retrieve the global macro ID corresponding to the given local 1686245431Sdim /// ID within the given module file. 1687245431Sdim serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID); 1688245431Sdim 1689212795Sdim /// \brief Read the source location entry with index ID. 1690226890Sdim virtual bool ReadSLocEntry(int ID); 1691212795Sdim 1692252723Sdim /// \brief Retrieve the module import location and module name for the 1693252723Sdim /// given source manager entry ID. 1694252723Sdim virtual std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID); 1695252723Sdim 1696235633Sdim /// \brief Retrieve the global submodule ID given a module and its local ID 1697235633Sdim /// number. 1698235633Sdim serialization::SubmoduleID 1699235633Sdim getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID); 1700235633Sdim 1701235633Sdim /// \brief Retrieve the submodule that corresponds to a global submodule ID. 1702235633Sdim /// 1703235633Sdim Module *getSubmodule(serialization::SubmoduleID GlobalID); 1704252723Sdim 1705252723Sdim /// \brief Retrieve the module that corresponds to the given module ID. 1706252723Sdim /// 1707252723Sdim /// Note: overrides method in ExternalASTSource 1708252723Sdim virtual Module *getModule(unsigned ID); 1709252723Sdim 1710226890Sdim /// \brief Retrieve a selector from the given module with its local ID 1711226890Sdim /// number. 1712235633Sdim Selector getLocalSelector(ModuleFile &M, unsigned LocalID); 1713212795Sdim 1714226890Sdim Selector DecodeSelector(serialization::SelectorID Idx); 1715226890Sdim 1716226890Sdim virtual Selector GetExternalSelector(serialization::SelectorID ID); 1717212795Sdim uint32_t GetNumExternalSelectors(); 1718212795Sdim 1719235633Sdim Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) { 1720226890Sdim return getLocalSelector(M, Record[Idx++]); 1721212795Sdim } 1722235633Sdim 1723226890Sdim /// \brief Retrieve the global selector ID that corresponds to this 1724226890Sdim /// the local selector ID in a given module. 1725235633Sdim serialization::SelectorID getGlobalSelectorID(ModuleFile &F, 1726226890Sdim unsigned LocalID) const; 1727212795Sdim 1728212795Sdim /// \brief Read a declaration name. 1729235633Sdim DeclarationName ReadDeclarationName(ModuleFile &F, 1730226890Sdim const RecordData &Record, unsigned &Idx); 1731235633Sdim void ReadDeclarationNameLoc(ModuleFile &F, 1732218893Sdim DeclarationNameLoc &DNLoc, DeclarationName Name, 1733218893Sdim const RecordData &Record, unsigned &Idx); 1734235633Sdim void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo, 1735218893Sdim const RecordData &Record, unsigned &Idx); 1736212795Sdim 1737235633Sdim void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, 1738218893Sdim const RecordData &Record, unsigned &Idx); 1739218893Sdim 1740235633Sdim NestedNameSpecifier *ReadNestedNameSpecifier(ModuleFile &F, 1741226890Sdim const RecordData &Record, 1742212795Sdim unsigned &Idx); 1743212795Sdim 1744235633Sdim NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F, 1745219077Sdim const RecordData &Record, 1746219077Sdim unsigned &Idx); 1747219077Sdim 1748212795Sdim /// \brief Read a template name. 1749235633Sdim TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record, 1750218893Sdim unsigned &Idx); 1751212795Sdim 1752212795Sdim /// \brief Read a template argument. 1753235633Sdim TemplateArgument ReadTemplateArgument(ModuleFile &F, 1754212795Sdim const RecordData &Record,unsigned &Idx); 1755235633Sdim 1756212795Sdim /// \brief Read a template parameter list. 1757235633Sdim TemplateParameterList *ReadTemplateParameterList(ModuleFile &F, 1758218893Sdim const RecordData &Record, 1759212795Sdim unsigned &Idx); 1760235633Sdim 1761212795Sdim /// \brief Read a template argument array. 1762212795Sdim void 1763263509Sdim ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs, 1764235633Sdim ModuleFile &F, const RecordData &Record, 1765218893Sdim unsigned &Idx); 1766212795Sdim 1767212795Sdim /// \brief Read a UnresolvedSet structure. 1768263509Sdim void ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set, 1769212795Sdim const RecordData &Record, unsigned &Idx); 1770212795Sdim 1771212795Sdim /// \brief Read a C++ base specifier. 1772235633Sdim CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F, 1773212795Sdim const RecordData &Record,unsigned &Idx); 1774212795Sdim 1775218893Sdim /// \brief Read a CXXCtorInitializer array. 1776218893Sdim std::pair<CXXCtorInitializer **, unsigned> 1777235633Sdim ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, 1778218893Sdim unsigned &Idx); 1779212795Sdim 1780218893Sdim /// \brief Read a source location from raw form. 1781235633Sdim SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, unsigned Raw) const { 1782226890Sdim SourceLocation Loc = SourceLocation::getFromRawEncoding(Raw); 1783235633Sdim assert(ModuleFile.SLocRemap.find(Loc.getOffset()) != ModuleFile.SLocRemap.end() && 1784226890Sdim "Cannot find offset to remap."); 1785235633Sdim int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second; 1786226890Sdim return Loc.getLocWithOffset(Remap); 1787218893Sdim } 1788218893Sdim 1789212795Sdim /// \brief Read a source location. 1790235633Sdim SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, 1791263509Sdim const RecordDataImpl &Record, 1792263509Sdim unsigned &Idx) { 1793235633Sdim return ReadSourceLocation(ModuleFile, Record[Idx++]); 1794212795Sdim } 1795212795Sdim 1796212795Sdim /// \brief Read a source range. 1797235633Sdim SourceRange ReadSourceRange(ModuleFile &F, 1798252723Sdim const RecordData &Record, unsigned &Idx); 1799212795Sdim 1800212795Sdim /// \brief Read an integral value 1801212795Sdim llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx); 1802212795Sdim 1803212795Sdim /// \brief Read a signed integral value 1804212795Sdim llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx); 1805212795Sdim 1806212795Sdim /// \brief Read a floating-point value 1807252723Sdim llvm::APFloat ReadAPFloat(const RecordData &Record, 1808252723Sdim const llvm::fltSemantics &Sem, unsigned &Idx); 1809212795Sdim 1810212795Sdim // \brief Read a string 1811245431Sdim static std::string ReadString(const RecordData &Record, unsigned &Idx); 1812212795Sdim 1813221345Sdim /// \brief Read a version tuple. 1814245431Sdim static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx); 1815221345Sdim 1816235633Sdim CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record, 1817226890Sdim unsigned &Idx); 1818235633Sdim 1819212795Sdim /// \brief Reads attributes from the current stream position. 1820235633Sdim void ReadAttributes(ModuleFile &F, AttrVec &Attrs, 1821218893Sdim const RecordData &Record, unsigned &Idx); 1822212795Sdim 1823212795Sdim /// \brief Reads a statement. 1824235633Sdim Stmt *ReadStmt(ModuleFile &F); 1825212795Sdim 1826212795Sdim /// \brief Reads an expression. 1827235633Sdim Expr *ReadExpr(ModuleFile &F); 1828212795Sdim 1829212795Sdim /// \brief Reads a sub-statement operand during statement reading. 1830212795Sdim Stmt *ReadSubStmt() { 1831212795Sdim assert(ReadingKind == Read_Stmt && 1832212795Sdim "Should be called only during statement reading!"); 1833212795Sdim // Subexpressions are stored from last to first, so the next Stmt we need 1834212795Sdim // is at the back of the stack. 1835212795Sdim assert(!StmtStack.empty() && "Read too many sub statements!"); 1836212795Sdim return StmtStack.pop_back_val(); 1837212795Sdim } 1838212795Sdim 1839212795Sdim /// \brief Reads a sub-expression operand during statement reading. 1840212795Sdim Expr *ReadSubExpr(); 1841212795Sdim 1842252723Sdim /// \brief Reads a token out of a record. 1843263509Sdim Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx); 1844252723Sdim 1845212795Sdim /// \brief Reads the macro record located at the given offset. 1846252723Sdim MacroInfo *ReadMacroRecord(ModuleFile &F, uint64_t Offset); 1847235633Sdim 1848226890Sdim /// \brief Determine the global preprocessed entity ID that corresponds to 1849226890Sdim /// the given local ID within the given module. 1850235633Sdim serialization::PreprocessedEntityID 1851235633Sdim getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const; 1852235633Sdim 1853252723Sdim /// \brief Add a macro to resolve imported from a module. 1854235633Sdim /// 1855235633Sdim /// \param II The name of the macro. 1856252723Sdim /// \param M The module file. 1857252723Sdim /// \param GMacID The global macro ID that is associated with this identifier. 1858252723Sdim /// \param ImportLoc The location where the module is imported. 1859252723Sdim void addPendingMacroFromModule(IdentifierInfo *II, 1860252723Sdim ModuleFile *M, 1861252723Sdim serialization::GlobalMacroID GMacID, 1862252723Sdim SourceLocation ImportLoc); 1863252723Sdim 1864252723Sdim /// \brief Add a macro to deserialize its macro directive history from a PCH. 1865235633Sdim /// 1866252723Sdim /// \param II The name of the macro. 1867252723Sdim /// \param M The module file. 1868252723Sdim /// \param MacroDirectivesOffset Offset of the serialized macro directive 1869252723Sdim /// history. 1870252723Sdim void addPendingMacroFromPCH(IdentifierInfo *II, 1871252723Sdim ModuleFile *M, uint64_t MacroDirectivesOffset); 1872235633Sdim 1873212795Sdim /// \brief Read the set of macros defined by this external macro source. 1874212795Sdim virtual void ReadDefinedMacros(); 1875212795Sdim 1876235633Sdim /// \brief Update an out-of-date identifier. 1877235633Sdim virtual void updateOutOfDateIdentifier(IdentifierInfo &II); 1878235633Sdim 1879235633Sdim /// \brief Note that this identifier is up-to-date. 1880235633Sdim void markIdentifierUpToDate(IdentifierInfo *II); 1881235633Sdim 1882235633Sdim /// \brief Load all external visible decls in the given DeclContext. 1883235633Sdim void completeVisibleDeclsMap(const DeclContext *DC); 1884235633Sdim 1885212795Sdim /// \brief Retrieve the AST context that this AST reader supplements. 1886226890Sdim ASTContext &getContext() { return Context; } 1887212795Sdim 1888212795Sdim // \brief Contains declarations that were loaded before we have 1889212795Sdim // access to a Sema object. 1890226890Sdim SmallVector<NamedDecl *, 16> PreloadedDecls; 1891212795Sdim 1892212795Sdim /// \brief Retrieve the semantic analysis object used to analyze the 1893212795Sdim /// translation unit in which the precompiled header is being 1894212795Sdim /// imported. 1895212795Sdim Sema *getSema() { return SemaObj; } 1896212795Sdim 1897212795Sdim /// \brief Retrieve the identifier table associated with the 1898212795Sdim /// preprocessor. 1899212795Sdim IdentifierTable &getIdentifierTable(); 1900212795Sdim 1901212795Sdim /// \brief Record that the given ID maps to the given switch-case 1902212795Sdim /// statement. 1903212795Sdim void RecordSwitchCaseID(SwitchCase *SC, unsigned ID); 1904212795Sdim 1905212795Sdim /// \brief Retrieve the switch-case statement with the given ID. 1906212795Sdim SwitchCase *getSwitchCaseWithID(unsigned ID); 1907212795Sdim 1908218893Sdim void ClearSwitchCaseIDs(); 1909245431Sdim 1910245431Sdim /// \brief Cursors for comments blocks. 1911245431Sdim SmallVector<std::pair<llvm::BitstreamCursor, 1912245431Sdim serialization::ModuleFile *>, 8> CommentsCursors; 1913245431Sdim 1914245431Sdim /// \brief Loads comments ranges. 1915245431Sdim void ReadComments(); 1916212795Sdim}; 1917212795Sdim 1918212795Sdim/// \brief Helper class that saves the current stream position and 1919212795Sdim/// then restores it when destroyed. 1920212795Sdimstruct SavedStreamPosition { 1921212795Sdim explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor) 1922252723Sdim : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) { } 1923212795Sdim 1924212795Sdim ~SavedStreamPosition() { 1925212795Sdim Cursor.JumpToBit(Offset); 1926212795Sdim } 1927212795Sdim 1928212795Sdimprivate: 1929212795Sdim llvm::BitstreamCursor &Cursor; 1930212795Sdim uint64_t Offset; 1931212795Sdim}; 1932212795Sdim 1933212795Sdiminline void PCHValidator::Error(const char *Msg) { 1934212795Sdim Reader.Error(Msg); 1935212795Sdim} 1936212795Sdim 1937212795Sdim} // end namespace clang 1938212795Sdim 1939212795Sdim#endif 1940