ASTReader.h revision 235633
1212795Sdim//===--- ASTReader.h - AST File Reader --------------------------*- C++ -*-===// 2212795Sdim// 3212795Sdim// The LLVM Compiler Infrastructure 4212795Sdim// 5212795Sdim// This file is distributed under the University of Illinois Open Source 6212795Sdim// License. See LICENSE.TXT for details. 7212795Sdim// 8212795Sdim//===----------------------------------------------------------------------===// 9212795Sdim// 10212795Sdim// This file defines the ASTReader class, which reads AST files. 11212795Sdim// 12212795Sdim//===----------------------------------------------------------------------===// 13212795Sdim 14212795Sdim#ifndef LLVM_CLANG_FRONTEND_AST_READER_H 15212795Sdim#define LLVM_CLANG_FRONTEND_AST_READER_H 16212795Sdim 17212795Sdim#include "clang/Serialization/ASTBitCodes.h" 18226890Sdim#include "clang/Serialization/ContinuousRangeMap.h" 19226890Sdim#include "clang/Serialization/Module.h" 20226890Sdim#include "clang/Serialization/ModuleManager.h" 21212795Sdim#include "clang/Sema/ExternalSemaSource.h" 22212795Sdim#include "clang/AST/DeclarationName.h" 23212795Sdim#include "clang/AST/DeclObjC.h" 24212795Sdim#include "clang/AST/TemplateBase.h" 25212795Sdim#include "clang/Lex/ExternalPreprocessorSource.h" 26218893Sdim#include "clang/Lex/HeaderSearch.h" 27212795Sdim#include "clang/Lex/PreprocessingRecord.h" 28212795Sdim#include "clang/Basic/Diagnostic.h" 29226890Sdim#include "clang/Basic/FileManager.h" 30226890Sdim#include "clang/Basic/FileSystemOptions.h" 31212795Sdim#include "clang/Basic/IdentifierTable.h" 32212795Sdim#include "clang/Basic/SourceManager.h" 33212795Sdim#include "llvm/ADT/APFloat.h" 34212795Sdim#include "llvm/ADT/APInt.h" 35212795Sdim#include "llvm/ADT/APSInt.h" 36212795Sdim#include "llvm/ADT/OwningPtr.h" 37235633Sdim#include "llvm/ADT/SmallPtrSet.h" 38235633Sdim#include "llvm/ADT/SmallSet.h" 39212795Sdim#include "llvm/ADT/SmallVector.h" 40212795Sdim#include "llvm/ADT/StringRef.h" 41226890Sdim#include "llvm/ADT/DenseSet.h" 42212795Sdim#include "llvm/Bitcode/BitstreamReader.h" 43218893Sdim#include "llvm/Support/DataTypes.h" 44212795Sdim#include <deque> 45212795Sdim#include <map> 46212795Sdim#include <string> 47212795Sdim#include <utility> 48212795Sdim#include <vector> 49212795Sdim 50212795Sdimnamespace llvm { 51212795Sdim class MemoryBuffer; 52212795Sdim} 53212795Sdim 54212795Sdimnamespace clang { 55212795Sdim 56212795Sdimclass AddrLabelExpr; 57212795Sdimclass ASTConsumer; 58212795Sdimclass ASTContext; 59218893Sdimclass ASTIdentifierIterator; 60226890Sdimclass ASTUnit; // FIXME: Layering violation and egregious hack. 61212795Sdimclass Attr; 62212795Sdimclass Decl; 63212795Sdimclass DeclContext; 64212795Sdimclass NestedNameSpecifier; 65212795Sdimclass CXXBaseSpecifier; 66223017Sdimclass CXXConstructorDecl; 67218893Sdimclass CXXCtorInitializer; 68212795Sdimclass GotoStmt; 69212795Sdimclass MacroDefinition; 70212795Sdimclass NamedDecl; 71218893Sdimclass OpaqueValueExpr; 72212795Sdimclass Preprocessor; 73212795Sdimclass Sema; 74212795Sdimclass SwitchCase; 75218893Sdimclass ASTDeserializationListener; 76226890Sdimclass ASTWriter; 77212795Sdimclass ASTReader; 78212795Sdimclass ASTDeclReader; 79218893Sdimclass ASTStmtReader; 80218893Sdimclass TypeLocReader; 81212795Sdimstruct HeaderFileInfo; 82221345Sdimclass VersionTuple; 83212795Sdim 84212795Sdimstruct PCHPredefinesBlock { 85212795Sdim /// \brief The file ID for this predefines buffer in a PCH file. 86212795Sdim FileID BufferID; 87212795Sdim 88212795Sdim /// \brief This predefines buffer in a PCH file. 89226890Sdim StringRef Data; 90212795Sdim}; 91226890Sdimtypedef SmallVector<PCHPredefinesBlock, 2> PCHPredefinesBlocks; 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 103212795Sdim /// \brief Receives the language options. 104212795Sdim /// 105212795Sdim /// \returns true to indicate the options are invalid or false otherwise. 106212795Sdim virtual bool ReadLanguageOptions(const LangOptions &LangOpts) { 107212795Sdim return false; 108212795Sdim } 109212795Sdim 110212795Sdim /// \brief Receives the target triple. 111212795Sdim /// 112212795Sdim /// \returns true to indicate the target triple is invalid or false otherwise. 113226890Sdim virtual bool ReadTargetTriple(StringRef Triple) { 114212795Sdim return false; 115212795Sdim } 116212795Sdim 117212795Sdim /// \brief Receives the contents of the predefines buffer. 118212795Sdim /// 119212795Sdim /// \param Buffers Information about the predefines buffers. 120212795Sdim /// 121212795Sdim /// \param OriginalFileName The original file name for the AST file, which 122212795Sdim /// will appear as an entry in the predefines buffer. 123212795Sdim /// 124212795Sdim /// \param SuggestedPredefines If necessary, additional definitions are added 125212795Sdim /// here. 126212795Sdim /// 127212795Sdim /// \returns true to indicate the predefines are invalid or false otherwise. 128212795Sdim virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, 129226890Sdim StringRef OriginalFileName, 130219077Sdim std::string &SuggestedPredefines, 131219077Sdim FileManager &FileMgr) { 132212795Sdim return false; 133212795Sdim } 134212795Sdim 135212795Sdim /// \brief Receives a HeaderFileInfo entry. 136212795Sdim virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID) {} 137212795Sdim 138212795Sdim /// \brief Receives __COUNTER__ value. 139212795Sdim virtual void ReadCounter(unsigned Value) {} 140212795Sdim}; 141212795Sdim 142212795Sdim/// \brief ASTReaderListener implementation to validate the information of 143212795Sdim/// the PCH file against an initialized Preprocessor. 144212795Sdimclass PCHValidator : public ASTReaderListener { 145212795Sdim Preprocessor &PP; 146212795Sdim ASTReader &Reader; 147212795Sdim 148212795Sdim unsigned NumHeaderInfos; 149212795Sdim 150212795Sdimpublic: 151212795Sdim PCHValidator(Preprocessor &PP, ASTReader &Reader) 152212795Sdim : PP(PP), Reader(Reader), NumHeaderInfos(0) {} 153212795Sdim 154212795Sdim virtual bool ReadLanguageOptions(const LangOptions &LangOpts); 155226890Sdim virtual bool ReadTargetTriple(StringRef Triple); 156212795Sdim virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, 157226890Sdim StringRef OriginalFileName, 158219077Sdim std::string &SuggestedPredefines, 159219077Sdim FileManager &FileMgr); 160212795Sdim virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID); 161212795Sdim virtual void ReadCounter(unsigned Value); 162212795Sdim 163212795Sdimprivate: 164212795Sdim void Error(const char *Msg); 165212795Sdim}; 166212795Sdim 167235633Sdimnamespace serialization { 168226890Sdim 169226890Sdimclass ReadMethodPoolVisitor; 170235633Sdim 171226890Sdimnamespace reader { 172226890Sdim class ASTIdentifierLookupTrait; 173235633Sdim /// \brief The on-disk hash table used for the DeclContext's Name lookup table. 174235633Sdim typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait> 175235633Sdim ASTDeclContextNameLookupTable; 176226890Sdim} 177235633Sdim 178226890Sdim} // end namespace serialization 179235633Sdim 180212795Sdim/// \brief Reads an AST files chain containing the contents of a translation 181212795Sdim/// unit. 182212795Sdim/// 183212795Sdim/// The ASTReader class reads bitstreams (produced by the ASTWriter 184212795Sdim/// class) containing the serialized representation of a given 185212795Sdim/// abstract syntax tree and its supporting data structures. An 186212795Sdim/// instance of the ASTReader can be attached to an ASTContext object, 187212795Sdim/// which will provide access to the contents of the AST files. 188212795Sdim/// 189212795Sdim/// The AST reader provides lazy de-serialization of declarations, as 190212795Sdim/// required when traversing the AST. Only those AST nodes that are 191212795Sdim/// actually required will be de-serialized. 192212795Sdimclass ASTReader 193212795Sdim : public ExternalPreprocessorSource, 194212795Sdim public ExternalPreprocessingRecordSource, 195218893Sdim public ExternalHeaderFileInfoSource, 196212795Sdim public ExternalSemaSource, 197212795Sdim public IdentifierInfoLookup, 198212795Sdim public ExternalIdentifierLookup, 199235633Sdim public ExternalSLocEntrySource 200218893Sdim{ 201212795Sdimpublic: 202212795Sdim enum ASTReadResult { Success, Failure, IgnorePCH }; 203218893Sdim /// \brief Types of AST files. 204212795Sdim friend class PCHValidator; 205212795Sdim friend class ASTDeclReader; 206218893Sdim friend class ASTStmtReader; 207218893Sdim friend class ASTIdentifierIterator; 208226890Sdim friend class serialization::reader::ASTIdentifierLookupTrait; 209218893Sdim friend class TypeLocReader; 210226890Sdim friend class ASTWriter; 211226890Sdim friend class ASTUnit; // ASTUnit needs to remap source locations. 212226890Sdim friend class serialization::ReadMethodPoolVisitor; 213235633Sdim 214235633Sdim typedef serialization::ModuleFile ModuleFile; 215226890Sdim typedef serialization::ModuleKind ModuleKind; 216226890Sdim typedef serialization::ModuleManager ModuleManager; 217235633Sdim 218226890Sdim typedef ModuleManager::ModuleIterator ModuleIterator; 219226890Sdim typedef ModuleManager::ModuleConstIterator ModuleConstIterator; 220226890Sdim typedef ModuleManager::ModuleReverseIterator ModuleReverseIterator; 221226890Sdim 222212795Sdimprivate: 223212795Sdim /// \brief The receiver of some callbacks invoked by ASTReader. 224235633Sdim OwningPtr<ASTReaderListener> Listener; 225212795Sdim 226212795Sdim /// \brief The receiver of deserialization events. 227212795Sdim ASTDeserializationListener *DeserializationListener; 228212795Sdim 229212795Sdim SourceManager &SourceMgr; 230212795Sdim FileManager &FileMgr; 231226890Sdim DiagnosticsEngine &Diags; 232235633Sdim 233212795Sdim /// \brief The semantic analysis object that will be processing the 234212795Sdim /// AST files and the translation unit that uses it. 235212795Sdim Sema *SemaObj; 236212795Sdim 237212795Sdim /// \brief The preprocessor that will be loading the source file. 238226890Sdim Preprocessor &PP; 239212795Sdim 240212795Sdim /// \brief The AST context into which we'll read the AST files. 241226890Sdim ASTContext &Context; 242235633Sdim 243212795Sdim /// \brief The AST consumer. 244212795Sdim ASTConsumer *Consumer; 245212795Sdim 246226890Sdim /// \brief The module manager which manages modules and their dependencies 247226890Sdim ModuleManager ModuleMgr; 248221345Sdim 249226890Sdim /// \brief A map of global bit offsets to the module that stores entities 250226890Sdim /// at those bit offsets. 251235633Sdim ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap; 252212795Sdim 253226890Sdim /// \brief A map of negated SLocEntryIDs to the modules containing them. 254235633Sdim ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap; 255212795Sdim 256235633Sdim typedef ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocOffsetMapType; 257235633Sdim 258226890Sdim /// \brief A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset) 259226890Sdim /// SourceLocation offsets to the modules containing them. 260226890Sdim GlobalSLocOffsetMapType GlobalSLocOffsetMap; 261235633Sdim 262212795Sdim /// \brief Types that have already been loaded from the chain. 263212795Sdim /// 264212795Sdim /// When the pointer at index I is non-NULL, the type with 265212795Sdim /// ID = (I + 1) << FastQual::Width has already been loaded 266212795Sdim std::vector<QualType> TypesLoaded; 267212795Sdim 268235633Sdim typedef ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4> 269226890Sdim GlobalTypeMapType; 270212795Sdim 271226890Sdim /// \brief Mapping from global type IDs to the module in which the 272226890Sdim /// type resides along with the offset that should be added to the 273226890Sdim /// global type ID to produce a local ID. 274226890Sdim GlobalTypeMapType GlobalTypeMap; 275226890Sdim 276212795Sdim /// \brief Declarations that have already been loaded from the chain. 277212795Sdim /// 278212795Sdim /// When the pointer at index I is non-NULL, the declaration with ID 279212795Sdim /// = I + 1 has already been loaded. 280212795Sdim std::vector<Decl *> DeclsLoaded; 281212795Sdim 282235633Sdim typedef ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4> 283226890Sdim GlobalDeclMapType; 284235633Sdim 285226890Sdim /// \brief Mapping from global declaration IDs to the module in which the 286226890Sdim /// declaration resides. 287226890Sdim GlobalDeclMapType GlobalDeclMap; 288235633Sdim 289235633Sdim typedef std::pair<ModuleFile *, uint64_t> FileOffset; 290226890Sdim typedef SmallVector<FileOffset, 2> FileOffsetsTy; 291218893Sdim typedef llvm::DenseMap<serialization::DeclID, FileOffsetsTy> 292218893Sdim DeclUpdateOffsetsMap; 293235633Sdim 294218893Sdim /// \brief Declarations that have modifications residing in a later file 295218893Sdim /// in the chain. 296218893Sdim DeclUpdateOffsetsMap DeclUpdateOffsets; 297218893Sdim 298235633Sdim struct ReplacedDeclInfo { 299235633Sdim ModuleFile *Mod; 300235633Sdim uint64_t Offset; 301235633Sdim unsigned RawLoc; 302235633Sdim 303235633Sdim ReplacedDeclInfo() : Mod(0), Offset(0), RawLoc(0) {} 304235633Sdim ReplacedDeclInfo(ModuleFile *Mod, uint64_t Offset, unsigned RawLoc) 305235633Sdim : Mod(Mod), Offset(Offset), RawLoc(RawLoc) {} 306235633Sdim }; 307235633Sdim 308235633Sdim typedef llvm::DenseMap<serialization::DeclID, ReplacedDeclInfo> 309212795Sdim DeclReplacementMap; 310212795Sdim /// \brief Declarations that have been replaced in a later file in the chain. 311212795Sdim DeclReplacementMap ReplacedDecls; 312212795Sdim 313235633Sdim struct FileDeclsInfo { 314235633Sdim ModuleFile *Mod; 315235633Sdim ArrayRef<serialization::LocalDeclID> Decls; 316235633Sdim 317235633Sdim FileDeclsInfo() : Mod(0) {} 318235633Sdim FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls) 319235633Sdim : Mod(Mod), Decls(Decls) {} 320235633Sdim }; 321235633Sdim 322235633Sdim /// \brief Map from a FileID to the file-level declarations that it contains. 323235633Sdim llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs; 324235633Sdim 325212795Sdim // Updates for visible decls can occur for other contexts than just the 326212795Sdim // TU, and when we read those update records, the actual context will not 327212795Sdim // be available yet (unless it's the TU), so have this pending map using the 328212795Sdim // ID as a key. It will be realized when the context is actually loaded. 329235633Sdim typedef 330235633Sdim SmallVector<std::pair<serialization::reader::ASTDeclContextNameLookupTable *, 331235633Sdim ModuleFile*>, 1> DeclContextVisibleUpdates; 332212795Sdim typedef llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates> 333212795Sdim DeclContextVisibleUpdatesPending; 334212795Sdim 335212795Sdim /// \brief Updates to the visible declarations of declaration contexts that 336212795Sdim /// haven't been loaded yet. 337212795Sdim DeclContextVisibleUpdatesPending PendingVisibleUpdates; 338235633Sdim 339235633Sdim /// \brief The set of C++ or Objective-C classes that have forward 340235633Sdim /// declarations that have not yet been linked to their definitions. 341235633Sdim llvm::SmallPtrSet<Decl *, 4> PendingDefinitions; 342235633Sdim 343212795Sdim /// \brief Read the records that describe the contents of declcontexts. 344235633Sdim bool ReadDeclContextStorage(ModuleFile &M, 345226890Sdim llvm::BitstreamCursor &Cursor, 346212795Sdim const std::pair<uint64_t, uint64_t> &Offsets, 347226890Sdim serialization::DeclContextInfo &Info); 348212795Sdim 349212795Sdim /// \brief A vector containing identifiers that have already been 350212795Sdim /// loaded. 351212795Sdim /// 352212795Sdim /// If the pointer at index I is non-NULL, then it refers to the 353212795Sdim /// IdentifierInfo for the identifier with ID=I+1 that has already 354212795Sdim /// been loaded. 355212795Sdim std::vector<IdentifierInfo *> IdentifiersLoaded; 356212795Sdim 357235633Sdim typedef ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4> 358226890Sdim GlobalIdentifierMapType; 359235633Sdim 360226890Sdim /// \brief Mapping from global identifer IDs to the module in which the 361226890Sdim /// identifier resides along with the offset that should be added to the 362226890Sdim /// global identifier ID to produce a local ID. 363226890Sdim GlobalIdentifierMapType GlobalIdentifierMap; 364226890Sdim 365235633Sdim /// \brief A vector containing submodules that have already been loaded. 366235633Sdim /// 367235633Sdim /// This vector is indexed by the Submodule ID (-1). NULL submodule entries 368235633Sdim /// indicate that the particular submodule ID has not yet been loaded. 369235633Sdim SmallVector<Module *, 2> SubmodulesLoaded; 370235633Sdim 371235633Sdim typedef ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4> 372235633Sdim GlobalSubmoduleMapType; 373235633Sdim 374235633Sdim /// \brief Mapping from global submodule IDs to the module file in which the 375235633Sdim /// submodule resides along with the offset that should be added to the 376235633Sdim /// global submodule ID to produce a local ID. 377235633Sdim GlobalSubmoduleMapType GlobalSubmoduleMap; 378235633Sdim 379235633Sdim /// \brief A set of hidden declarations. 380235633Sdim typedef llvm::SmallVector<llvm::PointerUnion<Decl *, IdentifierInfo *>, 2> 381235633Sdim HiddenNames; 382235633Sdim 383235633Sdim typedef llvm::DenseMap<Module *, HiddenNames> HiddenNamesMapType; 384235633Sdim 385235633Sdim /// \brief A mapping from each of the hidden submodules to the deserialized 386235633Sdim /// declarations in that submodule that could be made visible. 387235633Sdim HiddenNamesMapType HiddenNamesMap; 388235633Sdim 389235633Sdim 390235633Sdim /// \brief A module import or export that hasn't yet been resolved. 391235633Sdim struct UnresolvedModuleImportExport { 392235633Sdim /// \brief The file in which this module resides. 393235633Sdim ModuleFile *File; 394235633Sdim 395235633Sdim /// \brief The module that is importing or exporting. 396235633Sdim Module *Mod; 397235633Sdim 398235633Sdim /// \brief The local ID of the module that is being exported. 399235633Sdim unsigned ID; 400235633Sdim 401235633Sdim /// \brief Whether this is an import (vs. an export). 402235633Sdim unsigned IsImport : 1; 403235633Sdim 404235633Sdim /// \brief Whether this is a wildcard export. 405235633Sdim unsigned IsWildcard : 1; 406235633Sdim }; 407235633Sdim 408235633Sdim /// \brief The set of module imports and exports that still need to be 409235633Sdim /// resolved. 410235633Sdim llvm::SmallVector<UnresolvedModuleImportExport, 2> 411235633Sdim UnresolvedModuleImportExports; 412235633Sdim 413212795Sdim /// \brief A vector containing selectors that have already been loaded. 414212795Sdim /// 415212795Sdim /// This vector is indexed by the Selector ID (-1). NULL selector 416212795Sdim /// entries indicate that the particular selector ID has not yet 417212795Sdim /// been loaded. 418226890Sdim SmallVector<Selector, 16> SelectorsLoaded; 419212795Sdim 420235633Sdim typedef ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4> 421226890Sdim GlobalSelectorMapType; 422235633Sdim 423226890Sdim /// \brief Mapping from global selector IDs to the module in which the 424226890Sdim /// selector resides along with the offset that should be added to the 425226890Sdim /// global selector ID to produce a local ID. 426226890Sdim GlobalSelectorMapType GlobalSelectorMap; 427212795Sdim 428235633Sdim /// \brief The generation number of the last time we loaded data from the 429235633Sdim /// global method pool for this selector. 430235633Sdim llvm::DenseMap<Selector, unsigned> SelectorGeneration; 431235633Sdim 432218893Sdim /// \brief Mapping from identifiers that represent macros whose definitions 433218893Sdim /// have not yet been deserialized to the global offset where the macro 434218893Sdim /// record resides. 435218893Sdim llvm::DenseMap<IdentifierInfo *, uint64_t> UnreadMacroRecordOffsets; 436226890Sdim 437235633Sdim typedef ContinuousRangeMap<unsigned, ModuleFile *, 4> 438226890Sdim GlobalPreprocessedEntityMapType; 439235633Sdim 440226890Sdim /// \brief Mapping from global preprocessing entity IDs to the module in 441226890Sdim /// which the preprocessed entity resides along with the offset that should be 442226890Sdim /// added to the global preprocessing entitiy ID to produce a local ID. 443226890Sdim GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap; 444235633Sdim 445212795Sdim /// \name CodeGen-relevant special data 446212795Sdim /// \brief Fields containing data that is relevant to CodeGen. 447212795Sdim //@{ 448212795Sdim 449212795Sdim /// \brief The IDs of all declarations that fulfill the criteria of 450212795Sdim /// "interesting" decls. 451212795Sdim /// 452212795Sdim /// This contains the data loaded from all EXTERNAL_DEFINITIONS blocks in the 453212795Sdim /// chain. The referenced declarations are deserialized and passed to the 454212795Sdim /// consumer eagerly. 455226890Sdim SmallVector<uint64_t, 16> ExternalDefinitions; 456212795Sdim 457212795Sdim /// \brief The IDs of all tentative definitions stored in the the chain. 458212795Sdim /// 459212795Sdim /// Sema keeps track of all tentative definitions in a TU because it has to 460212795Sdim /// complete them and pass them on to CodeGen. Thus, tentative definitions in 461212795Sdim /// the PCH chain must be eagerly deserialized. 462226890Sdim SmallVector<uint64_t, 16> TentativeDefinitions; 463212795Sdim 464212795Sdim /// \brief The IDs of all CXXRecordDecls stored in the chain whose VTables are 465212795Sdim /// used. 466212795Sdim /// 467212795Sdim /// CodeGen has to emit VTables for these records, so they have to be eagerly 468212795Sdim /// deserialized. 469226890Sdim SmallVector<uint64_t, 64> VTableUses; 470212795Sdim 471226890Sdim /// \brief A snapshot of the pending instantiations in the chain. 472226890Sdim /// 473226890Sdim /// This record tracks the instantiations that Sema has to perform at the 474226890Sdim /// end of the TU. It consists of a pair of values for every pending 475226890Sdim /// instantiation where the first value is the ID of the decl and the second 476226890Sdim /// is the instantiation location. 477226890Sdim SmallVector<uint64_t, 64> PendingInstantiations; 478226890Sdim 479212795Sdim //@} 480212795Sdim 481226890Sdim /// \name DiagnosticsEngine-relevant special data 482212795Sdim /// \brief Fields containing data that is used for generating diagnostics 483212795Sdim //@{ 484212795Sdim 485212795Sdim /// \brief A snapshot of Sema's unused file-scoped variable tracking, for 486212795Sdim /// generating warnings. 487226890Sdim SmallVector<uint64_t, 16> UnusedFileScopedDecls; 488212795Sdim 489223017Sdim /// \brief A list of all the delegating constructors we've seen, to diagnose 490223017Sdim /// cycles. 491226890Sdim SmallVector<uint64_t, 4> DelegatingCtorDecls; 492235633Sdim 493226890Sdim /// \brief Method selectors used in a @selector expression. Used for 494226890Sdim /// implementation of -Wselector. 495226890Sdim SmallVector<uint64_t, 64> ReferencedSelectorsData; 496223017Sdim 497212795Sdim /// \brief A snapshot of Sema's weak undeclared identifier tracking, for 498212795Sdim /// generating warnings. 499226890Sdim SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers; 500212795Sdim 501212795Sdim /// \brief The IDs of type aliases for ext_vectors that exist in the chain. 502212795Sdim /// 503212795Sdim /// Used by Sema for finding sugared names for ext_vectors in diagnostics. 504226890Sdim SmallVector<uint64_t, 4> ExtVectorDecls; 505212795Sdim 506212795Sdim //@} 507212795Sdim 508212795Sdim /// \name Sema-relevant special data 509212795Sdim /// \brief Fields containing data that is used for semantic analysis 510212795Sdim //@{ 511212795Sdim 512212795Sdim /// \brief The IDs of all locally scoped external decls in the chain. 513212795Sdim /// 514212795Sdim /// Sema tracks these to validate that the types are consistent across all 515212795Sdim /// local external declarations. 516226890Sdim SmallVector<uint64_t, 16> LocallyScopedExternalDecls; 517212795Sdim 518212795Sdim /// \brief The IDs of all dynamic class declarations in the chain. 519212795Sdim /// 520212795Sdim /// Sema tracks these because it checks for the key functions being defined 521212795Sdim /// at the end of the TU, in which case it directs CodeGen to emit the VTable. 522226890Sdim SmallVector<uint64_t, 16> DynamicClasses; 523212795Sdim 524212795Sdim /// \brief The IDs of the declarations Sema stores directly. 525212795Sdim /// 526212795Sdim /// Sema tracks a few important decls, such as namespace std, directly. 527226890Sdim SmallVector<uint64_t, 4> SemaDeclRefs; 528212795Sdim 529212795Sdim /// \brief The IDs of the types ASTContext stores directly. 530212795Sdim /// 531212795Sdim /// The AST context tracks a few important types, such as va_list, directly. 532226890Sdim SmallVector<uint64_t, 16> SpecialTypes; 533212795Sdim 534218893Sdim /// \brief The IDs of CUDA-specific declarations ASTContext stores directly. 535218893Sdim /// 536218893Sdim /// The AST context tracks a few important decls, currently cudaConfigureCall, 537218893Sdim /// directly. 538226890Sdim SmallVector<uint64_t, 2> CUDASpecialDeclRefs; 539218893Sdim 540218893Sdim /// \brief The floating point pragma option settings. 541226890Sdim SmallVector<uint64_t, 1> FPPragmaOptions; 542218893Sdim 543218893Sdim /// \brief The OpenCL extension settings. 544226890Sdim SmallVector<uint64_t, 1> OpenCLExtensions; 545218893Sdim 546224145Sdim /// \brief A list of the namespaces we've seen. 547226890Sdim SmallVector<uint64_t, 4> KnownNamespaces; 548224145Sdim 549235633Sdim /// \brief A list of modules that were imported by precompiled headers or 550235633Sdim /// any other non-module AST file. 551235633Sdim SmallVector<serialization::SubmoduleID, 2> ImportedModules; 552212795Sdim //@} 553212795Sdim 554212795Sdim /// \brief The original file name that was used to build the primary AST file, 555212795Sdim /// which may have been modified for relocatable-pch support. 556212795Sdim std::string OriginalFileName; 557212795Sdim 558212795Sdim /// \brief The actual original file name that was used to build the primary 559212795Sdim /// AST file. 560212795Sdim std::string ActualOriginalFileName; 561212795Sdim 562223017Sdim /// \brief The file ID for the original file that was used to build the 563223017Sdim /// primary AST file. 564223017Sdim FileID OriginalFileID; 565235633Sdim 566218893Sdim /// \brief The directory that the PCH was originally created in. Used to 567218893Sdim /// allow resolving headers even after headers+PCH was moved to a new path. 568218893Sdim std::string OriginalDir; 569218893Sdim 570218893Sdim /// \brief The directory that the PCH we are reading is stored in. 571218893Sdim std::string CurrentDir; 572218893Sdim 573212795Sdim /// \brief Whether this precompiled header is a relocatable PCH file. 574212795Sdim bool RelocatablePCH; 575212795Sdim 576212795Sdim /// \brief The system include root to be used when loading the 577212795Sdim /// precompiled header. 578226890Sdim std::string isysroot; 579212795Sdim 580212795Sdim /// \brief Whether to disable the normal validation performed on precompiled 581212795Sdim /// headers when they are loaded. 582212795Sdim bool DisableValidation; 583235633Sdim 584218893Sdim /// \brief Whether to disable the use of stat caches in AST files. 585218893Sdim bool DisableStatCache; 586218893Sdim 587235633Sdim /// \brief Whether to accept an AST file with compiler errors. 588235633Sdim bool AllowASTWithCompilerErrors; 589235633Sdim 590235633Sdim /// \brief The current "generation" of the module file import stack, which 591235633Sdim /// indicates how many separate module file load operations have occurred. 592235633Sdim unsigned CurrentGeneration; 593235633Sdim 594212795Sdim /// \brief Mapping from switch-case IDs in the chain to switch-case statements 595212795Sdim /// 596212795Sdim /// Statements usually don't have IDs, but switch cases need them, so that the 597212795Sdim /// switch statement can refer to them. 598212795Sdim std::map<unsigned, SwitchCase *> SwitchCaseStmts; 599212795Sdim 600212795Sdim /// \brief The number of stat() calls that hit/missed the stat 601212795Sdim /// cache. 602212795Sdim unsigned NumStatHits, NumStatMisses; 603212795Sdim 604212795Sdim /// \brief The number of source location entries de-serialized from 605212795Sdim /// the PCH file. 606212795Sdim unsigned NumSLocEntriesRead; 607212795Sdim 608212795Sdim /// \brief The number of source location entries in the chain. 609212795Sdim unsigned TotalNumSLocEntries; 610212795Sdim 611212795Sdim /// \brief The number of statements (and expressions) de-serialized 612212795Sdim /// from the chain. 613212795Sdim unsigned NumStatementsRead; 614212795Sdim 615212795Sdim /// \brief The total number of statements (and expressions) stored 616212795Sdim /// in the chain. 617212795Sdim unsigned TotalNumStatements; 618212795Sdim 619212795Sdim /// \brief The number of macros de-serialized from the chain. 620212795Sdim unsigned NumMacrosRead; 621212795Sdim 622212795Sdim /// \brief The total number of macros stored in the chain. 623212795Sdim unsigned TotalNumMacros; 624212795Sdim 625212795Sdim /// \brief The number of selectors that have been read. 626212795Sdim unsigned NumSelectorsRead; 627212795Sdim 628212795Sdim /// \brief The number of method pool entries that have been read. 629212795Sdim unsigned NumMethodPoolEntriesRead; 630212795Sdim 631212795Sdim /// \brief The number of times we have looked up a selector in the method 632212795Sdim /// pool and not found anything interesting. 633212795Sdim unsigned NumMethodPoolMisses; 634212795Sdim 635212795Sdim /// \brief The total number of method pool entries in the selector table. 636212795Sdim unsigned TotalNumMethodPoolEntries; 637212795Sdim 638212795Sdim /// Number of lexical decl contexts read/total. 639212795Sdim unsigned NumLexicalDeclContextsRead, TotalLexicalDeclContexts; 640212795Sdim 641212795Sdim /// Number of visible decl contexts read/total. 642212795Sdim unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts; 643235633Sdim 644226890Sdim /// Total size of modules, in bits, currently loaded 645226890Sdim uint64_t TotalModulesSizeInBits; 646226890Sdim 647212795Sdim /// \brief Number of Decl/types that are currently deserializing. 648212795Sdim unsigned NumCurrentElementsDeserializing; 649212795Sdim 650235633Sdim /// \brief Set true while we are in the process of passing deserialized 651235633Sdim /// "interesting" decls to consumer inside FinishedDeserializing(). 652235633Sdim /// This is used as a guard to avoid recursively repeating the process of 653235633Sdim /// passing decls to consumer. 654235633Sdim bool PassingDeclsToConsumer; 655235633Sdim 656226890Sdim /// Number of CXX base specifiers currently loaded 657226890Sdim unsigned NumCXXBaseSpecifiersLoaded; 658226890Sdim 659212795Sdim /// \brief An IdentifierInfo that has been loaded but whose top-level 660212795Sdim /// declarations of the same name have not (yet) been loaded. 661212795Sdim struct PendingIdentifierInfo { 662212795Sdim IdentifierInfo *II; 663226890Sdim SmallVector<uint32_t, 4> DeclIDs; 664212795Sdim }; 665212795Sdim 666212795Sdim /// \brief The set of identifiers that were read while the AST reader was 667212795Sdim /// (recursively) loading declarations. 668212795Sdim /// 669212795Sdim /// The declarations on the identifier chain for these identifiers will be 670212795Sdim /// loaded once the recursive loading has completed. 671212795Sdim std::deque<PendingIdentifierInfo> PendingIdentifierInfos; 672212795Sdim 673235633Sdim /// \brief The generation number of each identifier, which keeps track of 674235633Sdim /// the last time we loaded information about this identifier. 675235633Sdim llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration; 676235633Sdim 677212795Sdim /// \brief Contains declarations and definitions that will be 678212795Sdim /// "interesting" to the ASTConsumer, when we get that AST consumer. 679212795Sdim /// 680212795Sdim /// "Interesting" declarations are those that have data that may 681212795Sdim /// need to be emitted, such as inline function definitions or 682212795Sdim /// Objective-C protocols. 683212795Sdim std::deque<Decl *> InterestingDecls; 684212795Sdim 685235633Sdim /// \brief The set of redeclarable declaraations that have been deserialized 686235633Sdim /// since the last time the declaration chains were linked. 687235633Sdim llvm::SmallPtrSet<Decl *, 16> RedeclsDeserialized; 688235633Sdim 689235633Sdim /// \brief The list of redeclaration chains that still need to be 690235633Sdim /// reconstructed. 691235633Sdim /// 692235633Sdim /// Each element is the global declaration ID of the first declaration in 693235633Sdim /// the chain. Elements in this vector should be unique; use 694235633Sdim /// PendingDeclChainsKnown to ensure uniqueness. 695235633Sdim llvm::SmallVector<serialization::DeclID, 16> PendingDeclChains; 696218893Sdim 697235633Sdim /// \brief Keeps track of the elements added to PendingDeclChains. 698235633Sdim llvm::SmallSet<serialization::DeclID, 16> PendingDeclChainsKnown; 699235633Sdim 700235633Sdim /// \brief The set of Objective-C categories that have been deserialized 701235633Sdim /// since the last time the declaration chains were linked. 702235633Sdim llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized; 703235633Sdim 704235633Sdim /// \brief The set of Objective-C class definitions that have already been 705235633Sdim /// loaded, for which we will need to check for categories whenever a new 706235633Sdim /// module is loaded. 707235633Sdim llvm::SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded; 708235633Sdim 709235633Sdim typedef llvm::DenseMap<Decl *, llvm::SmallVector<serialization::DeclID, 2> > 710235633Sdim MergedDeclsMap; 711235633Sdim 712235633Sdim /// \brief A mapping from canonical declarations to the set of additional 713235633Sdim /// (global, previously-canonical) declaration IDs that have been merged with 714235633Sdim /// that canonical declaration. 715235633Sdim MergedDeclsMap MergedDecls; 716235633Sdim 717235633Sdim typedef llvm::DenseMap<serialization::GlobalDeclID, 718235633Sdim llvm::SmallVector<serialization::DeclID, 2> > 719235633Sdim StoredMergedDeclsMap; 720235633Sdim 721235633Sdim /// \brief A mapping from canonical declaration IDs to the set of additional 722235633Sdim /// declaration IDs that have been merged with that canonical declaration. 723235633Sdim /// 724235633Sdim /// This is the deserialized representation of the entries in MergedDecls. 725235633Sdim /// When we query entries in MergedDecls, they will be augmented with entries 726235633Sdim /// from StoredMergedDecls. 727235633Sdim StoredMergedDeclsMap StoredMergedDecls; 728235633Sdim 729235633Sdim /// \brief Combine the stored merged declarations for the given canonical 730235633Sdim /// declaration into the set of merged declarations. 731235633Sdim /// 732235633Sdim /// \returns An iterator into MergedDecls that corresponds to the position of 733235633Sdim /// the given canonical declaration. 734235633Sdim MergedDeclsMap::iterator 735235633Sdim combineStoredMergedDecls(Decl *Canon, serialization::GlobalDeclID CanonID); 736235633Sdim 737218893Sdim /// \brief Ready to load the previous declaration of the given Decl. 738218893Sdim void loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID); 739218893Sdim 740212795Sdim /// \brief When reading a Stmt tree, Stmt operands are placed in this stack. 741226890Sdim SmallVector<Stmt *, 16> StmtStack; 742212795Sdim 743212795Sdim /// \brief What kind of records we are reading. 744212795Sdim enum ReadingKind { 745212795Sdim Read_Decl, Read_Type, Read_Stmt 746212795Sdim }; 747212795Sdim 748235633Sdim /// \brief What kind of records we are reading. 749212795Sdim ReadingKind ReadingKind; 750212795Sdim 751212795Sdim /// \brief RAII object to change the reading kind. 752212795Sdim class ReadingKindTracker { 753212795Sdim ASTReader &Reader; 754212795Sdim enum ReadingKind PrevKind; 755212795Sdim 756212795Sdim ReadingKindTracker(const ReadingKindTracker&); // do not implement 757212795Sdim ReadingKindTracker &operator=(const ReadingKindTracker&);// do not implement 758212795Sdim 759212795Sdim public: 760212795Sdim ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader) 761212795Sdim : Reader(reader), PrevKind(Reader.ReadingKind) { 762212795Sdim Reader.ReadingKind = newKind; 763212795Sdim } 764212795Sdim 765212795Sdim ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; } 766212795Sdim }; 767212795Sdim 768212795Sdim /// \brief All predefines buffers in the chain, to be treated as if 769212795Sdim /// concatenated. 770212795Sdim PCHPredefinesBlocks PCHPredefinesBuffers; 771212795Sdim 772212795Sdim /// \brief Suggested contents of the predefines buffer, after this 773212795Sdim /// PCH file has been processed. 774212795Sdim /// 775212795Sdim /// In most cases, this string will be empty, because the predefines 776212795Sdim /// buffer computed to build the PCH file will be identical to the 777212795Sdim /// predefines buffer computed from the command line. However, when 778212795Sdim /// there are differences that the PCH reader can work around, this 779212795Sdim /// predefines buffer may contain additional definitions. 780212795Sdim std::string SuggestedPredefines; 781212795Sdim 782212795Sdim /// \brief Reads a statement from the specified cursor. 783235633Sdim Stmt *ReadStmtFromStream(ModuleFile &F); 784212795Sdim 785223017Sdim /// \brief Get a FileEntry out of stored-in-PCH filename, making sure we take 786223017Sdim /// into account all the necessary relocations. 787226890Sdim const FileEntry *getFileEntry(StringRef filename); 788223017Sdim 789212795Sdim void MaybeAddSystemRootToFilename(std::string &Filename); 790212795Sdim 791226890Sdim ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type, 792235633Sdim ModuleFile *ImportedBy); 793235633Sdim ASTReadResult ReadASTBlock(ModuleFile &F); 794212795Sdim bool CheckPredefinesBuffers(); 795235633Sdim bool ParseLineTable(ModuleFile &F, SmallVectorImpl<uint64_t> &Record); 796235633Sdim ASTReadResult ReadSourceManagerBlock(ModuleFile &F); 797226890Sdim ASTReadResult ReadSLocEntryRecord(int ID); 798226890Sdim llvm::BitstreamCursor &SLocCursorForID(int ID); 799235633Sdim SourceLocation getImportLocation(ModuleFile *F); 800235633Sdim ASTReadResult ReadSubmoduleBlock(ModuleFile &F); 801226890Sdim bool ParseLanguageOptions(const SmallVectorImpl<uint64_t> &Record); 802235633Sdim 803218893Sdim struct RecordLocation { 804235633Sdim RecordLocation(ModuleFile *M, uint64_t O) 805218893Sdim : F(M), Offset(O) {} 806235633Sdim ModuleFile *F; 807218893Sdim uint64_t Offset; 808218893Sdim }; 809212795Sdim 810226890Sdim QualType readTypeRecord(unsigned Index); 811212795Sdim RecordLocation TypeCursorForIndex(unsigned Index); 812212795Sdim void LoadedDecl(unsigned Index, Decl *D); 813226890Sdim Decl *ReadDeclRecord(serialization::DeclID ID); 814235633Sdim RecordLocation DeclCursorForID(serialization::DeclID ID, 815235633Sdim unsigned &RawLocation); 816226890Sdim void loadDeclUpdateRecords(serialization::DeclID ID, Decl *D); 817235633Sdim void loadPendingDeclChain(serialization::GlobalDeclID ID); 818235633Sdim void loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D, 819235633Sdim unsigned PreviousGeneration = 0); 820235633Sdim 821226890Sdim RecordLocation getLocalBitOffset(uint64_t GlobalOffset); 822235633Sdim uint64_t getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset); 823212795Sdim 824226890Sdim /// \brief Returns the first preprocessed entity ID that ends after \arg BLoc. 825226890Sdim serialization::PreprocessedEntityID 826226890Sdim findBeginPreprocessedEntity(SourceLocation BLoc) const; 827226890Sdim 828235633Sdim /// \brief Returns the first preprocessed entity ID that begins after \arg 829235633Sdim /// ELoc. 830226890Sdim serialization::PreprocessedEntityID 831226890Sdim findEndPreprocessedEntity(SourceLocation ELoc) const; 832226890Sdim 833226890Sdim /// \brief \arg SLocMapI points at a chunk of a module that contains no 834226890Sdim /// preprocessed entities or the entities it contains are not the ones we are 835226890Sdim /// looking for. Find the next module that contains entities and return the ID 836226890Sdim /// of the first entry. 837226890Sdim serialization::PreprocessedEntityID 838226890Sdim findNextPreprocessedEntity( 839226890Sdim GlobalSLocOffsetMapType::const_iterator SLocMapI) const; 840226890Sdim 841235633Sdim /// \brief Returns (ModuleFile, Local index) pair for \arg GlobalIndex of a 842235633Sdim /// preprocessed entity. 843235633Sdim std::pair<ModuleFile *, unsigned> 844235633Sdim getModulePreprocessedEntity(unsigned GlobalIndex); 845235633Sdim 846212795Sdim void PassInterestingDeclsToConsumer(); 847235633Sdim void PassInterestingDeclToConsumer(Decl *D); 848212795Sdim 849235633Sdim void finishPendingActions(); 850235633Sdim 851212795Sdim /// \brief Produce an error diagnostic and return true. 852212795Sdim /// 853212795Sdim /// This routine should only be used for fatal errors that have to 854212795Sdim /// do with non-routine failures (e.g., corrupted AST file). 855226890Sdim void Error(StringRef Msg); 856226890Sdim void Error(unsigned DiagID, StringRef Arg1 = StringRef(), 857226890Sdim StringRef Arg2 = StringRef()); 858212795Sdim 859212795Sdim ASTReader(const ASTReader&); // do not implement 860212795Sdim ASTReader &operator=(const ASTReader &); // do not implement 861212795Sdimpublic: 862226890Sdim typedef SmallVector<uint64_t, 64> RecordData; 863212795Sdim 864212795Sdim /// \brief Load the AST file and validate its contents against the given 865212795Sdim /// Preprocessor. 866212795Sdim /// 867212795Sdim /// \param PP the preprocessor associated with the context in which this 868212795Sdim /// precompiled header will be loaded. 869212795Sdim /// 870212795Sdim /// \param Context the AST context that this precompiled header will be 871212795Sdim /// loaded into. 872212795Sdim /// 873212795Sdim /// \param isysroot If non-NULL, the system include path specified by the 874212795Sdim /// user. This is only used with relocatable PCH files. If non-NULL, 875212795Sdim /// a relocatable PCH file will use the default path "/". 876212795Sdim /// 877212795Sdim /// \param DisableValidation If true, the AST reader will suppress most 878212795Sdim /// of its regular consistency checking, allowing the use of precompiled 879212795Sdim /// headers that cannot be determined to be compatible. 880218893Sdim /// 881218893Sdim /// \param DisableStatCache If true, the AST reader will ignore the 882218893Sdim /// stat cache in the AST files. This performance pessimization can 883218893Sdim /// help when an AST file is being used in cases where the 884218893Sdim /// underlying files in the file system may have changed, but 885218893Sdim /// parsing should still continue. 886235633Sdim /// 887235633Sdim /// \param AllowASTWithCompilerErrors If true, the AST reader will accept an 888235633Sdim /// AST file the was created out of an AST with compiler errors, 889235633Sdim /// otherwise it will reject it. 890226890Sdim ASTReader(Preprocessor &PP, ASTContext &Context, StringRef isysroot = "", 891235633Sdim bool DisableValidation = false, bool DisableStatCache = false, 892235633Sdim bool AllowASTWithCompilerErrors = false); 893212795Sdim 894212795Sdim ~ASTReader(); 895212795Sdim 896226890Sdim SourceManager &getSourceManager() const { return SourceMgr; } 897235633Sdim 898226890Sdim /// \brief Load the AST file designated by the given file name. 899226890Sdim ASTReadResult ReadAST(const std::string &FileName, ModuleKind Type); 900212795Sdim 901223017Sdim /// \brief Checks that no file that is stored in PCH is out-of-sync with 902223017Sdim /// the actual file in the file system. 903235633Sdim ASTReadResult validateFileEntries(ModuleFile &M); 904223017Sdim 905235633Sdim /// \brief Make the entities in the given module and any of its (non-explicit) 906235633Sdim /// submodules visible to name lookup. 907235633Sdim /// 908235633Sdim /// \param Mod The module whose names should be made visible. 909235633Sdim /// 910235633Sdim /// \param Visibility The level of visibility to give the names in the module. 911235633Sdim /// Visibility can only be increased over time. 912235633Sdim void makeModuleVisible(Module *Mod, 913235633Sdim Module::NameVisibilityKind NameVisibility); 914235633Sdim 915235633Sdim /// \brief Make the names within this set of hidden names visible. 916235633Sdim void makeNamesVisible(const HiddenNames &Names); 917235633Sdim 918212795Sdim /// \brief Set the AST callbacks listener. 919212795Sdim void setListener(ASTReaderListener *listener) { 920212795Sdim Listener.reset(listener); 921212795Sdim } 922212795Sdim 923212795Sdim /// \brief Set the AST deserialization listener. 924212795Sdim void setDeserializationListener(ASTDeserializationListener *Listener); 925212795Sdim 926226890Sdim /// \brief Initializes the ASTContext 927226890Sdim void InitializeContext(); 928212795Sdim 929226890Sdim /// \brief Add in-memory (virtual file) buffer. 930226890Sdim void addInMemoryBuffer(StringRef &FileName, llvm::MemoryBuffer *Buffer) { 931226890Sdim ModuleMgr.addInMemoryBuffer(FileName, Buffer); 932221345Sdim } 933221345Sdim 934235633Sdim /// \brief Finalizes the AST reader's state before writing an AST file to 935235633Sdim /// disk. 936235633Sdim /// 937235633Sdim /// This operation may undo temporary state in the AST that should not be 938235633Sdim /// emitted. 939235633Sdim void finalizeForWriting(); 940235633Sdim 941226890Sdim /// \brief Retrieve the module manager. 942226890Sdim ModuleManager &getModuleManager() { return ModuleMgr; } 943212795Sdim 944226890Sdim /// \brief Retrieve the preprocessor. 945226890Sdim Preprocessor &getPreprocessor() const { return PP; } 946235633Sdim 947212795Sdim /// \brief Retrieve the name of the original source file name 948212795Sdim const std::string &getOriginalSourceFile() { return OriginalFileName; } 949212795Sdim 950212795Sdim /// \brief Retrieve the name of the original source file name directly from 951212795Sdim /// the AST file, without actually loading the AST file. 952212795Sdim static std::string getOriginalSourceFile(const std::string &ASTFileName, 953218893Sdim FileManager &FileMgr, 954226890Sdim DiagnosticsEngine &Diags); 955212795Sdim 956212795Sdim /// \brief Returns the suggested contents of the predefines buffer, 957212795Sdim /// which contains a (typically-empty) subset of the predefines 958212795Sdim /// build prior to including the precompiled header. 959212795Sdim const std::string &getSuggestedPredefines() { return SuggestedPredefines; } 960212795Sdim 961226890Sdim /// \brief Read a preallocated preprocessed entity from the external source. 962226890Sdim /// 963226890Sdim /// \returns null if an error occurred that prevented the preprocessed 964226890Sdim /// entity from being loaded. 965226890Sdim virtual PreprocessedEntity *ReadPreprocessedEntity(unsigned Index); 966218893Sdim 967226890Sdim /// \brief Returns a pair of [Begin, End) indices of preallocated 968226890Sdim /// preprocessed entities that \arg Range encompasses. 969226890Sdim virtual std::pair<unsigned, unsigned> 970226890Sdim findPreprocessedEntitiesInRange(SourceRange Range); 971226890Sdim 972235633Sdim /// \brief Optionally returns true or false if the preallocated preprocessed 973235633Sdim /// entity with index \arg Index came from file \arg FID. 974235633Sdim virtual llvm::Optional<bool> isPreprocessedEntityInFileID(unsigned Index, 975235633Sdim FileID FID); 976235633Sdim 977218893Sdim /// \brief Read the header file information for the given file entry. 978218893Sdim virtual HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE); 979218893Sdim 980226890Sdim void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag); 981218893Sdim 982212795Sdim /// \brief Returns the number of source locations found in the chain. 983212795Sdim unsigned getTotalNumSLocs() const { 984212795Sdim return TotalNumSLocEntries; 985212795Sdim } 986212795Sdim 987212795Sdim /// \brief Returns the number of identifiers found in the chain. 988212795Sdim unsigned getTotalNumIdentifiers() const { 989212795Sdim return static_cast<unsigned>(IdentifiersLoaded.size()); 990212795Sdim } 991212795Sdim 992212795Sdim /// \brief Returns the number of types found in the chain. 993212795Sdim unsigned getTotalNumTypes() const { 994212795Sdim return static_cast<unsigned>(TypesLoaded.size()); 995212795Sdim } 996212795Sdim 997212795Sdim /// \brief Returns the number of declarations found in the chain. 998212795Sdim unsigned getTotalNumDecls() const { 999212795Sdim return static_cast<unsigned>(DeclsLoaded.size()); 1000212795Sdim } 1001212795Sdim 1002235633Sdim /// \brief Returns the number of submodules known. 1003235633Sdim unsigned getTotalNumSubmodules() const { 1004235633Sdim return static_cast<unsigned>(SubmodulesLoaded.size()); 1005235633Sdim } 1006235633Sdim 1007212795Sdim /// \brief Returns the number of selectors found in the chain. 1008212795Sdim unsigned getTotalNumSelectors() const { 1009212795Sdim return static_cast<unsigned>(SelectorsLoaded.size()); 1010212795Sdim } 1011212795Sdim 1012226890Sdim /// \brief Returns the number of preprocessed entities known to the AST 1013226890Sdim /// reader. 1014226890Sdim unsigned getTotalNumPreprocessedEntities() const { 1015226890Sdim unsigned Result = 0; 1016226890Sdim for (ModuleConstIterator I = ModuleMgr.begin(), 1017226890Sdim E = ModuleMgr.end(); I != E; ++I) { 1018226890Sdim Result += (*I)->NumPreprocessedEntities; 1019226890Sdim } 1020235633Sdim 1021226890Sdim return Result; 1022218893Sdim } 1023235633Sdim 1024218893Sdim /// \brief Returns the number of C++ base specifiers found in the chain. 1025226890Sdim unsigned getTotalNumCXXBaseSpecifiers() const { 1026226890Sdim return NumCXXBaseSpecifiersLoaded; 1027226890Sdim } 1028235633Sdim 1029212795Sdim /// \brief Reads a TemplateArgumentLocInfo appropriate for the 1030212795Sdim /// given TemplateArgument kind. 1031212795Sdim TemplateArgumentLocInfo 1032235633Sdim GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind, 1033212795Sdim const RecordData &Record, unsigned &Idx); 1034212795Sdim 1035212795Sdim /// \brief Reads a TemplateArgumentLoc. 1036212795Sdim TemplateArgumentLoc 1037235633Sdim ReadTemplateArgumentLoc(ModuleFile &F, 1038212795Sdim const RecordData &Record, unsigned &Idx); 1039212795Sdim 1040212795Sdim /// \brief Reads a declarator info from the given record. 1041235633Sdim TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F, 1042212795Sdim const RecordData &Record, unsigned &Idx); 1043212795Sdim 1044212795Sdim /// \brief Resolve a type ID into a type, potentially building a new 1045212795Sdim /// type. 1046212795Sdim QualType GetType(serialization::TypeID ID); 1047212795Sdim 1048226890Sdim /// \brief Resolve a local type ID within a given AST file into a type. 1049235633Sdim QualType getLocalType(ModuleFile &F, unsigned LocalID); 1050235633Sdim 1051226890Sdim /// \brief Map a local type ID within a given AST file into a global type ID. 1052235633Sdim serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const; 1053235633Sdim 1054235633Sdim /// \brief Read a type from the current position in the given record, which 1055226890Sdim /// was read from the given AST file. 1056235633Sdim QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) { 1057226890Sdim if (Idx >= Record.size()) 1058226890Sdim return QualType(); 1059235633Sdim 1060226890Sdim return getLocalType(F, Record[Idx++]); 1061226890Sdim } 1062235633Sdim 1063235633Sdim /// \brief Map from a local declaration ID within a given module to a 1064226890Sdim /// global declaration ID. 1065235633Sdim serialization::DeclID getGlobalDeclID(ModuleFile &F, unsigned LocalID) const; 1066212795Sdim 1067226890Sdim /// \brief Returns true if global DeclID \arg ID originated from module 1068226890Sdim /// \arg M. 1069235633Sdim bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const; 1070235633Sdim 1071235633Sdim /// \brief Retrieve the module file that owns the given declaration, or NULL 1072235633Sdim /// if the declaration is not from a module file. 1073235633Sdim ModuleFile *getOwningModuleFile(Decl *D); 1074226890Sdim 1075235633Sdim /// \brief Returns the source location for the decl \arg ID. 1076235633Sdim SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID); 1077235633Sdim 1078212795Sdim /// \brief Resolve a declaration ID into a declaration, potentially 1079212795Sdim /// building a new declaration. 1080212795Sdim Decl *GetDecl(serialization::DeclID ID); 1081212795Sdim virtual Decl *GetExternalDecl(uint32_t ID); 1082212795Sdim 1083226890Sdim /// \brief Reads a declaration with the given local ID in the given module. 1084235633Sdim Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) { 1085226890Sdim return GetDecl(getGlobalDeclID(F, LocalID)); 1086226890Sdim } 1087226890Sdim 1088226890Sdim /// \brief Reads a declaration with the given local ID in the given module. 1089226890Sdim /// 1090226890Sdim /// \returns The requested declaration, casted to the given return type. 1091226890Sdim template<typename T> 1092235633Sdim T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) { 1093226890Sdim return cast_or_null<T>(GetLocalDecl(F, LocalID)); 1094226890Sdim } 1095226890Sdim 1096235633Sdim /// \brief Map a global declaration ID into the declaration ID used to 1097235633Sdim /// refer to this declaration within the given module fule. 1098235633Sdim /// 1099235633Sdim /// \returns the global ID of the given declaration as known in the given 1100235633Sdim /// module file. 1101235633Sdim serialization::DeclID 1102235633Sdim mapGlobalIDToModuleFileGlobalID(ModuleFile &M, 1103235633Sdim serialization::DeclID GlobalID); 1104235633Sdim 1105235633Sdim /// \brief Reads a declaration ID from the given position in a record in the 1106226890Sdim /// given module. 1107226890Sdim /// 1108226890Sdim /// \returns The declaration ID read from the record, adjusted to a global ID. 1109235633Sdim serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record, 1110226890Sdim unsigned &Idx); 1111235633Sdim 1112226890Sdim /// \brief Reads a declaration from the given position in a record in the 1113226890Sdim /// given module. 1114235633Sdim Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) { 1115226890Sdim return GetDecl(ReadDeclID(F, R, I)); 1116226890Sdim } 1117235633Sdim 1118226890Sdim /// \brief Reads a declaration from the given position in a record in the 1119226890Sdim /// given module. 1120226890Sdim /// 1121226890Sdim /// \returns The declaration read from this location, casted to the given 1122226890Sdim /// result type. 1123226890Sdim template<typename T> 1124235633Sdim T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) { 1125226890Sdim return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I))); 1126226890Sdim } 1127226890Sdim 1128226890Sdim /// \brief Read a CXXBaseSpecifiers ID form the given record and 1129226890Sdim /// return its global bit offset. 1130235633Sdim uint64_t readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record, 1131226890Sdim unsigned &Idx); 1132235633Sdim 1133218893Sdim virtual CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset); 1134235633Sdim 1135212795Sdim /// \brief Resolve the offset of a statement into a statement. 1136212795Sdim /// 1137212795Sdim /// This operation will read a new statement from the external 1138212795Sdim /// source each time it is called, and is meant to be used via a 1139212795Sdim /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). 1140212795Sdim virtual Stmt *GetExternalDeclStmt(uint64_t Offset); 1141212795Sdim 1142212795Sdim /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the 1143212795Sdim /// specified cursor. Read the abbreviations that are at the top of the block 1144212795Sdim /// and then leave the cursor pointing into the block. 1145212795Sdim bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID); 1146212795Sdim 1147212795Sdim /// \brief Finds all the visible declarations with a given name. 1148212795Sdim /// The current implementation of this method just loads the entire 1149212795Sdim /// lookup table as unmaterialized references. 1150212795Sdim virtual DeclContext::lookup_result 1151212795Sdim FindExternalVisibleDeclsByName(const DeclContext *DC, 1152212795Sdim DeclarationName Name); 1153212795Sdim 1154212795Sdim /// \brief Read all of the declarations lexically stored in a 1155212795Sdim /// declaration context. 1156212795Sdim /// 1157212795Sdim /// \param DC The declaration context whose declarations will be 1158212795Sdim /// read. 1159212795Sdim /// 1160212795Sdim /// \param Decls Vector that will contain the declarations loaded 1161212795Sdim /// from the external source. The caller is responsible for merging 1162212795Sdim /// these declarations with any declarations already stored in the 1163212795Sdim /// declaration context. 1164212795Sdim /// 1165212795Sdim /// \returns true if there was an error while reading the 1166212795Sdim /// declarations for this declaration context. 1167224145Sdim virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC, 1168218893Sdim bool (*isKindWeWant)(Decl::Kind), 1169226890Sdim SmallVectorImpl<Decl*> &Decls); 1170212795Sdim 1171235633Sdim /// \brief Get the decls that are contained in a file in the Offset/Length 1172235633Sdim /// range. \arg Length can be 0 to indicate a point at \arg Offset instead of 1173235633Sdim /// a range. 1174235633Sdim virtual void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length, 1175235633Sdim SmallVectorImpl<Decl *> &Decls); 1176235633Sdim 1177212795Sdim /// \brief Notify ASTReader that we started deserialization of 1178212795Sdim /// a decl or type so until FinishedDeserializing is called there may be 1179212795Sdim /// decls that are initializing. Must be paired with FinishedDeserializing. 1180212795Sdim virtual void StartedDeserializing() { ++NumCurrentElementsDeserializing; } 1181212795Sdim 1182212795Sdim /// \brief Notify ASTReader that we finished the deserialization of 1183212795Sdim /// a decl or type. Must be paired with StartedDeserializing. 1184212795Sdim virtual void FinishedDeserializing(); 1185212795Sdim 1186212795Sdim /// \brief Function that will be invoked when we begin parsing a new 1187212795Sdim /// translation unit involving this external AST source. 1188212795Sdim /// 1189212795Sdim /// This function will provide all of the external definitions to 1190212795Sdim /// the ASTConsumer. 1191212795Sdim virtual void StartTranslationUnit(ASTConsumer *Consumer); 1192212795Sdim 1193212795Sdim /// \brief Print some statistics about AST usage. 1194212795Sdim virtual void PrintStats(); 1195212795Sdim 1196226890Sdim /// \brief Dump information about the AST reader to standard error. 1197226890Sdim void dump(); 1198235633Sdim 1199221345Sdim /// Return the amount of memory used by memory buffers, breaking down 1200221345Sdim /// by heap-backed versus mmap'ed memory. 1201221345Sdim virtual void getMemoryBufferSizes(MemoryBufferSizes &sizes) const; 1202221345Sdim 1203212795Sdim /// \brief Initialize the semantic source with the Sema instance 1204212795Sdim /// being used to perform semantic analysis on the abstract syntax 1205212795Sdim /// tree. 1206212795Sdim virtual void InitializeSema(Sema &S); 1207212795Sdim 1208212795Sdim /// \brief Inform the semantic consumer that Sema is no longer available. 1209212795Sdim virtual void ForgetSema() { SemaObj = 0; } 1210212795Sdim 1211212795Sdim /// \brief Retrieve the IdentifierInfo for the named identifier. 1212212795Sdim /// 1213212795Sdim /// This routine builds a new IdentifierInfo for the given identifier. If any 1214212795Sdim /// declarations with this name are visible from translation unit scope, their 1215212795Sdim /// declarations will be deserialized and introduced into the declaration 1216212795Sdim /// chain of the identifier. 1217212795Sdim virtual IdentifierInfo *get(const char *NameStart, const char *NameEnd); 1218226890Sdim IdentifierInfo *get(StringRef Name) { 1219212795Sdim return get(Name.begin(), Name.end()); 1220212795Sdim } 1221212795Sdim 1222218893Sdim /// \brief Retrieve an iterator into the set of all identifiers 1223218893Sdim /// in all loaded AST files. 1224218893Sdim virtual IdentifierIterator *getIdentifiers() const; 1225218893Sdim 1226212795Sdim /// \brief Load the contents of the global method pool for a given 1227212795Sdim /// selector. 1228235633Sdim virtual void ReadMethodPool(Selector Sel); 1229212795Sdim 1230224145Sdim /// \brief Load the set of namespaces that are known to the external source, 1231224145Sdim /// which will be used during typo correction. 1232224145Sdim virtual void ReadKnownNamespaces( 1233226890Sdim SmallVectorImpl<NamespaceDecl *> &Namespaces); 1234224145Sdim 1235226890Sdim virtual void ReadTentativeDefinitions( 1236226890Sdim SmallVectorImpl<VarDecl *> &TentativeDefs); 1237226890Sdim 1238226890Sdim virtual void ReadUnusedFileScopedDecls( 1239226890Sdim SmallVectorImpl<const DeclaratorDecl *> &Decls); 1240226890Sdim 1241226890Sdim virtual void ReadDelegatingConstructors( 1242226890Sdim SmallVectorImpl<CXXConstructorDecl *> &Decls); 1243226890Sdim 1244226890Sdim virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls); 1245226890Sdim 1246226890Sdim virtual void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls); 1247226890Sdim 1248226890Sdim virtual void ReadLocallyScopedExternalDecls( 1249226890Sdim SmallVectorImpl<NamedDecl *> &Decls); 1250235633Sdim 1251226890Sdim virtual void ReadReferencedSelectors( 1252226890Sdim SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels); 1253226890Sdim 1254226890Sdim virtual void ReadWeakUndeclaredIdentifiers( 1255226890Sdim SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI); 1256226890Sdim 1257226890Sdim virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables); 1258226890Sdim 1259226890Sdim virtual void ReadPendingInstantiations( 1260235633Sdim SmallVectorImpl<std::pair<ValueDecl *, 1261226890Sdim SourceLocation> > &Pending); 1262226890Sdim 1263212795Sdim /// \brief Load a selector from disk, registering its ID if it exists. 1264212795Sdim void LoadSelector(Selector Sel); 1265212795Sdim 1266212795Sdim void SetIdentifierInfo(unsigned ID, IdentifierInfo *II); 1267212795Sdim void SetGloballyVisibleDecls(IdentifierInfo *II, 1268226890Sdim const SmallVectorImpl<uint32_t> &DeclIDs, 1269212795Sdim bool Nonrecursive = false); 1270212795Sdim 1271212795Sdim /// \brief Report a diagnostic. 1272212795Sdim DiagnosticBuilder Diag(unsigned DiagID); 1273212795Sdim 1274212795Sdim /// \brief Report a diagnostic. 1275212795Sdim DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); 1276212795Sdim 1277226890Sdim IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID); 1278212795Sdim 1279235633Sdim IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record, 1280226890Sdim unsigned &Idx) { 1281226890Sdim return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++])); 1282212795Sdim } 1283212795Sdim 1284226890Sdim virtual IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) { 1285212795Sdim return DecodeIdentifierInfo(ID); 1286212795Sdim } 1287212795Sdim 1288235633Sdim IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID); 1289235633Sdim 1290235633Sdim serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M, 1291226890Sdim unsigned LocalID); 1292235633Sdim 1293212795Sdim /// \brief Read the source location entry with index ID. 1294226890Sdim virtual bool ReadSLocEntry(int ID); 1295212795Sdim 1296235633Sdim /// \brief Retrieve the global submodule ID given a module and its local ID 1297235633Sdim /// number. 1298235633Sdim serialization::SubmoduleID 1299235633Sdim getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID); 1300235633Sdim 1301235633Sdim /// \brief Retrieve the submodule that corresponds to a global submodule ID. 1302235633Sdim /// 1303235633Sdim Module *getSubmodule(serialization::SubmoduleID GlobalID); 1304235633Sdim 1305226890Sdim /// \brief Retrieve a selector from the given module with its local ID 1306226890Sdim /// number. 1307235633Sdim Selector getLocalSelector(ModuleFile &M, unsigned LocalID); 1308212795Sdim 1309226890Sdim Selector DecodeSelector(serialization::SelectorID Idx); 1310226890Sdim 1311226890Sdim virtual Selector GetExternalSelector(serialization::SelectorID ID); 1312212795Sdim uint32_t GetNumExternalSelectors(); 1313212795Sdim 1314235633Sdim Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) { 1315226890Sdim return getLocalSelector(M, Record[Idx++]); 1316212795Sdim } 1317235633Sdim 1318226890Sdim /// \brief Retrieve the global selector ID that corresponds to this 1319226890Sdim /// the local selector ID in a given module. 1320235633Sdim serialization::SelectorID getGlobalSelectorID(ModuleFile &F, 1321226890Sdim unsigned LocalID) const; 1322212795Sdim 1323212795Sdim /// \brief Read a declaration name. 1324235633Sdim DeclarationName ReadDeclarationName(ModuleFile &F, 1325226890Sdim const RecordData &Record, unsigned &Idx); 1326235633Sdim void ReadDeclarationNameLoc(ModuleFile &F, 1327218893Sdim DeclarationNameLoc &DNLoc, DeclarationName Name, 1328218893Sdim const RecordData &Record, unsigned &Idx); 1329235633Sdim void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo, 1330218893Sdim const RecordData &Record, unsigned &Idx); 1331212795Sdim 1332235633Sdim void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, 1333218893Sdim const RecordData &Record, unsigned &Idx); 1334218893Sdim 1335235633Sdim NestedNameSpecifier *ReadNestedNameSpecifier(ModuleFile &F, 1336226890Sdim const RecordData &Record, 1337212795Sdim unsigned &Idx); 1338212795Sdim 1339235633Sdim NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F, 1340219077Sdim const RecordData &Record, 1341219077Sdim unsigned &Idx); 1342219077Sdim 1343212795Sdim /// \brief Read a template name. 1344235633Sdim TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record, 1345218893Sdim unsigned &Idx); 1346212795Sdim 1347212795Sdim /// \brief Read a template argument. 1348235633Sdim TemplateArgument ReadTemplateArgument(ModuleFile &F, 1349212795Sdim const RecordData &Record,unsigned &Idx); 1350235633Sdim 1351212795Sdim /// \brief Read a template parameter list. 1352235633Sdim TemplateParameterList *ReadTemplateParameterList(ModuleFile &F, 1353218893Sdim const RecordData &Record, 1354212795Sdim unsigned &Idx); 1355235633Sdim 1356212795Sdim /// \brief Read a template argument array. 1357212795Sdim void 1358226890Sdim ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs, 1359235633Sdim ModuleFile &F, const RecordData &Record, 1360218893Sdim unsigned &Idx); 1361212795Sdim 1362212795Sdim /// \brief Read a UnresolvedSet structure. 1363235633Sdim void ReadUnresolvedSet(ModuleFile &F, UnresolvedSetImpl &Set, 1364212795Sdim const RecordData &Record, unsigned &Idx); 1365212795Sdim 1366212795Sdim /// \brief Read a C++ base specifier. 1367235633Sdim CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F, 1368212795Sdim const RecordData &Record,unsigned &Idx); 1369212795Sdim 1370218893Sdim /// \brief Read a CXXCtorInitializer array. 1371218893Sdim std::pair<CXXCtorInitializer **, unsigned> 1372235633Sdim ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, 1373218893Sdim unsigned &Idx); 1374212795Sdim 1375218893Sdim /// \brief Read a source location from raw form. 1376235633Sdim SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, unsigned Raw) const { 1377226890Sdim SourceLocation Loc = SourceLocation::getFromRawEncoding(Raw); 1378235633Sdim assert(ModuleFile.SLocRemap.find(Loc.getOffset()) != ModuleFile.SLocRemap.end() && 1379226890Sdim "Cannot find offset to remap."); 1380235633Sdim int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second; 1381226890Sdim return Loc.getLocWithOffset(Remap); 1382218893Sdim } 1383218893Sdim 1384212795Sdim /// \brief Read a source location. 1385235633Sdim SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, 1386218893Sdim const RecordData &Record, unsigned& Idx) { 1387235633Sdim return ReadSourceLocation(ModuleFile, Record[Idx++]); 1388212795Sdim } 1389212795Sdim 1390212795Sdim /// \brief Read a source range. 1391235633Sdim SourceRange ReadSourceRange(ModuleFile &F, 1392218893Sdim const RecordData &Record, unsigned& Idx); 1393212795Sdim 1394212795Sdim /// \brief Read an integral value 1395212795Sdim llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx); 1396212795Sdim 1397212795Sdim /// \brief Read a signed integral value 1398212795Sdim llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx); 1399212795Sdim 1400212795Sdim /// \brief Read a floating-point value 1401212795Sdim llvm::APFloat ReadAPFloat(const RecordData &Record, unsigned &Idx); 1402212795Sdim 1403212795Sdim // \brief Read a string 1404212795Sdim std::string ReadString(const RecordData &Record, unsigned &Idx); 1405212795Sdim 1406221345Sdim /// \brief Read a version tuple. 1407221345Sdim VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx); 1408221345Sdim 1409235633Sdim CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record, 1410226890Sdim unsigned &Idx); 1411235633Sdim 1412212795Sdim /// \brief Reads attributes from the current stream position. 1413235633Sdim void ReadAttributes(ModuleFile &F, AttrVec &Attrs, 1414218893Sdim const RecordData &Record, unsigned &Idx); 1415212795Sdim 1416212795Sdim /// \brief Reads a statement. 1417235633Sdim Stmt *ReadStmt(ModuleFile &F); 1418212795Sdim 1419212795Sdim /// \brief Reads an expression. 1420235633Sdim Expr *ReadExpr(ModuleFile &F); 1421212795Sdim 1422212795Sdim /// \brief Reads a sub-statement operand during statement reading. 1423212795Sdim Stmt *ReadSubStmt() { 1424212795Sdim assert(ReadingKind == Read_Stmt && 1425212795Sdim "Should be called only during statement reading!"); 1426212795Sdim // Subexpressions are stored from last to first, so the next Stmt we need 1427212795Sdim // is at the back of the stack. 1428212795Sdim assert(!StmtStack.empty() && "Read too many sub statements!"); 1429212795Sdim return StmtStack.pop_back_val(); 1430212795Sdim } 1431212795Sdim 1432212795Sdim /// \brief Reads a sub-expression operand during statement reading. 1433212795Sdim Expr *ReadSubExpr(); 1434212795Sdim 1435212795Sdim /// \brief Reads the macro record located at the given offset. 1436235633Sdim void ReadMacroRecord(ModuleFile &F, uint64_t Offset); 1437235633Sdim 1438226890Sdim /// \brief Determine the global preprocessed entity ID that corresponds to 1439226890Sdim /// the given local ID within the given module. 1440235633Sdim serialization::PreprocessedEntityID 1441235633Sdim getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const; 1442235633Sdim 1443218893Sdim /// \brief Note that the identifier is a macro whose record will be loaded 1444218893Sdim /// from the given AST file at the given (file-local) offset. 1445235633Sdim /// 1446235633Sdim /// \param II The name of the macro. 1447235633Sdim /// 1448235633Sdim /// \param F The module file from which the macro definition was deserialized. 1449235633Sdim /// 1450235633Sdim /// \param Offset The offset into the module file at which the macro 1451235633Sdim /// definition is located. 1452235633Sdim /// 1453235633Sdim /// \param Visible Whether the macro should be made visible. 1454235633Sdim void setIdentifierIsMacro(IdentifierInfo *II, ModuleFile &F, 1455235633Sdim uint64_t Offset, bool Visible); 1456235633Sdim 1457212795Sdim /// \brief Read the set of macros defined by this external macro source. 1458212795Sdim virtual void ReadDefinedMacros(); 1459212795Sdim 1460218893Sdim /// \brief Read the macro definition for this identifier. 1461218893Sdim virtual void LoadMacroDefinition(IdentifierInfo *II); 1462218893Sdim 1463235633Sdim /// \brief Update an out-of-date identifier. 1464235633Sdim virtual void updateOutOfDateIdentifier(IdentifierInfo &II); 1465235633Sdim 1466235633Sdim /// \brief Note that this identifier is up-to-date. 1467235633Sdim void markIdentifierUpToDate(IdentifierInfo *II); 1468235633Sdim 1469218893Sdim /// \brief Read the macro definition corresponding to this iterator 1470218893Sdim /// into the unread macro record offsets table. 1471218893Sdim void LoadMacroDefinition( 1472218893Sdim llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos); 1473235633Sdim 1474235633Sdim /// \brief Load all external visible decls in the given DeclContext. 1475235633Sdim void completeVisibleDeclsMap(const DeclContext *DC); 1476235633Sdim 1477212795Sdim /// \brief Retrieve the AST context that this AST reader supplements. 1478226890Sdim ASTContext &getContext() { return Context; } 1479212795Sdim 1480212795Sdim // \brief Contains declarations that were loaded before we have 1481212795Sdim // access to a Sema object. 1482226890Sdim SmallVector<NamedDecl *, 16> PreloadedDecls; 1483212795Sdim 1484212795Sdim /// \brief Retrieve the semantic analysis object used to analyze the 1485212795Sdim /// translation unit in which the precompiled header is being 1486212795Sdim /// imported. 1487212795Sdim Sema *getSema() { return SemaObj; } 1488212795Sdim 1489212795Sdim /// \brief Retrieve the identifier table associated with the 1490212795Sdim /// preprocessor. 1491212795Sdim IdentifierTable &getIdentifierTable(); 1492212795Sdim 1493212795Sdim /// \brief Record that the given ID maps to the given switch-case 1494212795Sdim /// statement. 1495212795Sdim void RecordSwitchCaseID(SwitchCase *SC, unsigned ID); 1496212795Sdim 1497212795Sdim /// \brief Retrieve the switch-case statement with the given ID. 1498212795Sdim SwitchCase *getSwitchCaseWithID(unsigned ID); 1499212795Sdim 1500218893Sdim void ClearSwitchCaseIDs(); 1501212795Sdim}; 1502212795Sdim 1503212795Sdim/// \brief Helper class that saves the current stream position and 1504212795Sdim/// then restores it when destroyed. 1505212795Sdimstruct SavedStreamPosition { 1506212795Sdim explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor) 1507212795Sdim : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) { } 1508212795Sdim 1509212795Sdim ~SavedStreamPosition() { 1510212795Sdim Cursor.JumpToBit(Offset); 1511212795Sdim } 1512212795Sdim 1513212795Sdimprivate: 1514212795Sdim llvm::BitstreamCursor &Cursor; 1515212795Sdim uint64_t Offset; 1516212795Sdim}; 1517212795Sdim 1518212795Sdiminline void PCHValidator::Error(const char *Msg) { 1519212795Sdim Reader.Error(Msg); 1520212795Sdim} 1521212795Sdim 1522212795Sdim} // end namespace clang 1523212795Sdim 1524212795Sdim#endif 1525