ASTReader.h revision 1f6d22550161fffbe82ea9a8a143b2c1247f5f3c
1//===--- ASTReader.h - AST File Reader --------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the ASTReader class, which reads AST files. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_FRONTEND_AST_READER_H 15#define LLVM_CLANG_FRONTEND_AST_READER_H 16 17#include "clang/Serialization/ASTBitCodes.h" 18#include "clang/Serialization/ContinuousRangeMap.h" 19#include "clang/Serialization/Module.h" 20#include "clang/Serialization/ModuleManager.h" 21#include "clang/Sema/ExternalSemaSource.h" 22#include "clang/AST/DeclarationName.h" 23#include "clang/AST/DeclObjC.h" 24#include "clang/AST/TemplateBase.h" 25#include "clang/Lex/ExternalPreprocessorSource.h" 26#include "clang/Lex/HeaderSearch.h" 27#include "clang/Lex/PreprocessingRecord.h" 28#include "clang/Basic/Diagnostic.h" 29#include "clang/Basic/FileManager.h" 30#include "clang/Basic/FileSystemOptions.h" 31#include "clang/Basic/IdentifierTable.h" 32#include "clang/Basic/SourceManager.h" 33#include "llvm/ADT/APFloat.h" 34#include "llvm/ADT/APInt.h" 35#include "llvm/ADT/APSInt.h" 36#include "llvm/ADT/OwningPtr.h" 37#include "llvm/ADT/SmallVector.h" 38#include "llvm/ADT/StringRef.h" 39#include "llvm/ADT/DenseSet.h" 40#include "llvm/Bitcode/BitstreamReader.h" 41#include "llvm/Support/DataTypes.h" 42#include <deque> 43#include <map> 44#include <string> 45#include <utility> 46#include <vector> 47 48namespace llvm { 49 class MemoryBuffer; 50} 51 52namespace clang { 53 54class AddrLabelExpr; 55class ASTConsumer; 56class ASTContext; 57class ASTIdentifierIterator; 58class ASTUnit; // FIXME: Layering violation and egregious hack. 59class Attr; 60class Decl; 61class DeclContext; 62class NestedNameSpecifier; 63class CXXBaseSpecifier; 64class CXXConstructorDecl; 65class CXXCtorInitializer; 66class GotoStmt; 67class MacroDefinition; 68class NamedDecl; 69class OpaqueValueExpr; 70class Preprocessor; 71class Sema; 72class SwitchCase; 73class ASTDeserializationListener; 74class ASTWriter; 75class ASTReader; 76class ASTDeclReader; 77class ASTStmtReader; 78class TypeLocReader; 79struct HeaderFileInfo; 80class VersionTuple; 81 82struct PCHPredefinesBlock { 83 /// \brief The file ID for this predefines buffer in a PCH file. 84 FileID BufferID; 85 86 /// \brief This predefines buffer in a PCH file. 87 StringRef Data; 88}; 89typedef SmallVector<PCHPredefinesBlock, 2> PCHPredefinesBlocks; 90 91/// \brief Abstract interface for callback invocations by the ASTReader. 92/// 93/// While reading an AST file, the ASTReader will call the methods of the 94/// listener to pass on specific information. Some of the listener methods can 95/// return true to indicate to the ASTReader that the information (and 96/// consequently the AST file) is invalid. 97class ASTReaderListener { 98public: 99 virtual ~ASTReaderListener(); 100 101 /// \brief Receives the language options. 102 /// 103 /// \returns true to indicate the options are invalid or false otherwise. 104 virtual bool ReadLanguageOptions(const LangOptions &LangOpts) { 105 return false; 106 } 107 108 /// \brief Receives the target triple. 109 /// 110 /// \returns true to indicate the target triple is invalid or false otherwise. 111 virtual bool ReadTargetTriple(StringRef Triple) { 112 return false; 113 } 114 115 /// \brief Receives the contents of the predefines buffer. 116 /// 117 /// \param Buffers Information about the predefines buffers. 118 /// 119 /// \param OriginalFileName The original file name for the AST file, which 120 /// will appear as an entry in the predefines buffer. 121 /// 122 /// \param SuggestedPredefines If necessary, additional definitions are added 123 /// here. 124 /// 125 /// \returns true to indicate the predefines are invalid or false otherwise. 126 virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, 127 StringRef OriginalFileName, 128 std::string &SuggestedPredefines, 129 FileManager &FileMgr) { 130 return false; 131 } 132 133 /// \brief Receives a HeaderFileInfo entry. 134 virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID) {} 135 136 /// \brief Receives __COUNTER__ value. 137 virtual void ReadCounter(unsigned Value) {} 138}; 139 140/// \brief ASTReaderListener implementation to validate the information of 141/// the PCH file against an initialized Preprocessor. 142class PCHValidator : public ASTReaderListener { 143 Preprocessor &PP; 144 ASTReader &Reader; 145 146 unsigned NumHeaderInfos; 147 148public: 149 PCHValidator(Preprocessor &PP, ASTReader &Reader) 150 : PP(PP), Reader(Reader), NumHeaderInfos(0) {} 151 152 virtual bool ReadLanguageOptions(const LangOptions &LangOpts); 153 virtual bool ReadTargetTriple(StringRef Triple); 154 virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, 155 StringRef OriginalFileName, 156 std::string &SuggestedPredefines, 157 FileManager &FileMgr); 158 virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID); 159 virtual void ReadCounter(unsigned Value); 160 161private: 162 void Error(const char *Msg); 163}; 164 165namespace serialization { 166 167class ReadMethodPoolVisitor; 168 169namespace reader { 170 class ASTIdentifierLookupTrait; 171} 172 173} // end namespace serialization 174 175/// \brief Reads an AST files chain containing the contents of a translation 176/// unit. 177/// 178/// The ASTReader class reads bitstreams (produced by the ASTWriter 179/// class) containing the serialized representation of a given 180/// abstract syntax tree and its supporting data structures. An 181/// instance of the ASTReader can be attached to an ASTContext object, 182/// which will provide access to the contents of the AST files. 183/// 184/// The AST reader provides lazy de-serialization of declarations, as 185/// required when traversing the AST. Only those AST nodes that are 186/// actually required will be de-serialized. 187class ASTReader 188 : public ExternalPreprocessorSource, 189 public ExternalPreprocessingRecordSource, 190 public ExternalHeaderFileInfoSource, 191 public ExternalSemaSource, 192 public IdentifierInfoLookup, 193 public ExternalIdentifierLookup, 194 public ExternalSLocEntrySource 195{ 196public: 197 enum ASTReadResult { Success, Failure, IgnorePCH }; 198 /// \brief Types of AST files. 199 friend class PCHValidator; 200 friend class ASTDeclReader; 201 friend class ASTStmtReader; 202 friend class ASTIdentifierIterator; 203 friend class serialization::reader::ASTIdentifierLookupTrait; 204 friend class TypeLocReader; 205 friend class ASTWriter; 206 friend class ASTUnit; // ASTUnit needs to remap source locations. 207 friend class serialization::ReadMethodPoolVisitor; 208 209 typedef serialization::Module Module; 210 typedef serialization::ModuleKind ModuleKind; 211 typedef serialization::ModuleManager ModuleManager; 212 213 typedef ModuleManager::ModuleIterator ModuleIterator; 214 typedef ModuleManager::ModuleConstIterator ModuleConstIterator; 215 typedef ModuleManager::ModuleReverseIterator ModuleReverseIterator; 216 217private: 218 /// \brief The receiver of some callbacks invoked by ASTReader. 219 llvm::OwningPtr<ASTReaderListener> Listener; 220 221 /// \brief The receiver of deserialization events. 222 ASTDeserializationListener *DeserializationListener; 223 224 SourceManager &SourceMgr; 225 FileManager &FileMgr; 226 Diagnostic &Diags; 227 228 /// \brief The semantic analysis object that will be processing the 229 /// AST files and the translation unit that uses it. 230 Sema *SemaObj; 231 232 /// \brief The preprocessor that will be loading the source file. 233 Preprocessor &PP; 234 235 /// \brief The AST context into which we'll read the AST files. 236 ASTContext &Context; 237 238 /// \brief The AST consumer. 239 ASTConsumer *Consumer; 240 241 /// \brief The module manager which manages modules and their dependencies 242 ModuleManager ModuleMgr; 243 244 /// \brief A map of global bit offsets to the module that stores entities 245 /// at those bit offsets. 246 ContinuousRangeMap<uint64_t, Module*, 4> GlobalBitOffsetsMap; 247 248 /// \brief A map of negated SLocEntryIDs to the modules containing them. 249 ContinuousRangeMap<unsigned, Module*, 64> GlobalSLocEntryMap; 250 251 /// \brief Types that have already been loaded from the chain. 252 /// 253 /// When the pointer at index I is non-NULL, the type with 254 /// ID = (I + 1) << FastQual::Width has already been loaded 255 std::vector<QualType> TypesLoaded; 256 257 typedef ContinuousRangeMap<serialization::TypeID, Module *, 4> 258 GlobalTypeMapType; 259 260 /// \brief Mapping from global type IDs to the module in which the 261 /// type resides along with the offset that should be added to the 262 /// global type ID to produce a local ID. 263 GlobalTypeMapType GlobalTypeMap; 264 265 /// \brief Declarations that have already been loaded from the chain. 266 /// 267 /// When the pointer at index I is non-NULL, the declaration with ID 268 /// = I + 1 has already been loaded. 269 std::vector<Decl *> DeclsLoaded; 270 271 typedef ContinuousRangeMap<serialization::DeclID, Module *, 4> 272 GlobalDeclMapType; 273 274 /// \brief Mapping from global declaration IDs to the module in which the 275 /// declaration resides. 276 GlobalDeclMapType GlobalDeclMap; 277 278 typedef std::pair<Module *, uint64_t> FileOffset; 279 typedef SmallVector<FileOffset, 2> FileOffsetsTy; 280 typedef llvm::DenseMap<serialization::DeclID, FileOffsetsTy> 281 DeclUpdateOffsetsMap; 282 283 /// \brief Declarations that have modifications residing in a later file 284 /// in the chain. 285 DeclUpdateOffsetsMap DeclUpdateOffsets; 286 287 typedef llvm::DenseMap<serialization::DeclID, 288 std::pair<Module *, uint64_t> > 289 DeclReplacementMap; 290 /// \brief Declarations that have been replaced in a later file in the chain. 291 DeclReplacementMap ReplacedDecls; 292 293 // Updates for visible decls can occur for other contexts than just the 294 // TU, and when we read those update records, the actual context will not 295 // be available yet (unless it's the TU), so have this pending map using the 296 // ID as a key. It will be realized when the context is actually loaded. 297 typedef SmallVector<std::pair<void *, Module*>, 1> DeclContextVisibleUpdates; 298 typedef llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates> 299 DeclContextVisibleUpdatesPending; 300 301 /// \brief Updates to the visible declarations of declaration contexts that 302 /// haven't been loaded yet. 303 DeclContextVisibleUpdatesPending PendingVisibleUpdates; 304 305 typedef SmallVector<CXXRecordDecl *, 4> ForwardRefs; 306 typedef llvm::DenseMap<const CXXRecordDecl *, ForwardRefs> 307 PendingForwardRefsMap; 308 /// \brief Forward references that have a definition but the definition decl 309 /// is still initializing. When the definition gets read it will update 310 /// the DefinitionData pointer of all pending references. 311 PendingForwardRefsMap PendingForwardRefs; 312 313 typedef llvm::DenseMap<serialization::DeclID, serialization::DeclID> 314 FirstLatestDeclIDMap; 315 /// \brief Map of first declarations from a chained PCH that point to the 316 /// most recent declarations in another AST file. 317 FirstLatestDeclIDMap FirstLatestDeclIDs; 318 319 /// \brief Set of ObjC interfaces that have categories chained to them in 320 /// other modules. 321 llvm::DenseSet<serialization::GlobalDeclID> ObjCChainedCategoriesInterfaces; 322 323 /// \brief Read the records that describe the contents of declcontexts. 324 bool ReadDeclContextStorage(Module &M, 325 llvm::BitstreamCursor &Cursor, 326 const std::pair<uint64_t, uint64_t> &Offsets, 327 serialization::DeclContextInfo &Info); 328 329 /// \brief A vector containing identifiers that have already been 330 /// loaded. 331 /// 332 /// If the pointer at index I is non-NULL, then it refers to the 333 /// IdentifierInfo for the identifier with ID=I+1 that has already 334 /// been loaded. 335 std::vector<IdentifierInfo *> IdentifiersLoaded; 336 337 typedef ContinuousRangeMap<serialization::IdentID, Module *, 4> 338 GlobalIdentifierMapType; 339 340 /// \brief Mapping from global identifer IDs to the module in which the 341 /// identifier resides along with the offset that should be added to the 342 /// global identifier ID to produce a local ID. 343 GlobalIdentifierMapType GlobalIdentifierMap; 344 345 /// \brief A vector containing selectors that have already been loaded. 346 /// 347 /// This vector is indexed by the Selector ID (-1). NULL selector 348 /// entries indicate that the particular selector ID has not yet 349 /// been loaded. 350 SmallVector<Selector, 16> SelectorsLoaded; 351 352 typedef ContinuousRangeMap<serialization::SelectorID, Module *, 4> 353 GlobalSelectorMapType; 354 355 /// \brief Mapping from global selector IDs to the module in which the 356 /// selector resides along with the offset that should be added to the 357 /// global selector ID to produce a local ID. 358 GlobalSelectorMapType GlobalSelectorMap; 359 360 /// \brief Mapping from identifiers that represent macros whose definitions 361 /// have not yet been deserialized to the global offset where the macro 362 /// record resides. 363 llvm::DenseMap<IdentifierInfo *, uint64_t> UnreadMacroRecordOffsets; 364 365 typedef ContinuousRangeMap<unsigned, Module *, 4> 366 GlobalPreprocessedEntityMapType; 367 368 /// \brief Mapping from global preprocessing entity IDs to the module in 369 /// which the preprocessed entity resides along with the offset that should be 370 /// added to the global preprocessing entitiy ID to produce a local ID. 371 GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap; 372 373 /// \name CodeGen-relevant special data 374 /// \brief Fields containing data that is relevant to CodeGen. 375 //@{ 376 377 /// \brief The IDs of all declarations that fulfill the criteria of 378 /// "interesting" decls. 379 /// 380 /// This contains the data loaded from all EXTERNAL_DEFINITIONS blocks in the 381 /// chain. The referenced declarations are deserialized and passed to the 382 /// consumer eagerly. 383 SmallVector<uint64_t, 16> ExternalDefinitions; 384 385 /// \brief The IDs of all tentative definitions stored in the the chain. 386 /// 387 /// Sema keeps track of all tentative definitions in a TU because it has to 388 /// complete them and pass them on to CodeGen. Thus, tentative definitions in 389 /// the PCH chain must be eagerly deserialized. 390 SmallVector<uint64_t, 16> TentativeDefinitions; 391 392 /// \brief The IDs of all CXXRecordDecls stored in the chain whose VTables are 393 /// used. 394 /// 395 /// CodeGen has to emit VTables for these records, so they have to be eagerly 396 /// deserialized. 397 SmallVector<uint64_t, 64> VTableUses; 398 399 /// \brief A snapshot of the pending instantiations in the chain. 400 /// 401 /// This record tracks the instantiations that Sema has to perform at the 402 /// end of the TU. It consists of a pair of values for every pending 403 /// instantiation where the first value is the ID of the decl and the second 404 /// is the instantiation location. 405 SmallVector<uint64_t, 64> PendingInstantiations; 406 407 //@} 408 409 /// \name Diagnostic-relevant special data 410 /// \brief Fields containing data that is used for generating diagnostics 411 //@{ 412 413 /// \brief A snapshot of Sema's unused file-scoped variable tracking, for 414 /// generating warnings. 415 SmallVector<uint64_t, 16> UnusedFileScopedDecls; 416 417 /// \brief A list of all the delegating constructors we've seen, to diagnose 418 /// cycles. 419 SmallVector<uint64_t, 4> DelegatingCtorDecls; 420 421 /// \brief Method selectors used in a @selector expression. Used for 422 /// implementation of -Wselector. 423 SmallVector<uint64_t, 64> ReferencedSelectorsData; 424 425 /// \brief A snapshot of Sema's weak undeclared identifier tracking, for 426 /// generating warnings. 427 SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers; 428 429 /// \brief The IDs of type aliases for ext_vectors that exist in the chain. 430 /// 431 /// Used by Sema for finding sugared names for ext_vectors in diagnostics. 432 SmallVector<uint64_t, 4> ExtVectorDecls; 433 434 //@} 435 436 /// \name Sema-relevant special data 437 /// \brief Fields containing data that is used for semantic analysis 438 //@{ 439 440 /// \brief The IDs of all locally scoped external decls in the chain. 441 /// 442 /// Sema tracks these to validate that the types are consistent across all 443 /// local external declarations. 444 SmallVector<uint64_t, 16> LocallyScopedExternalDecls; 445 446 /// \brief The IDs of all dynamic class declarations in the chain. 447 /// 448 /// Sema tracks these because it checks for the key functions being defined 449 /// at the end of the TU, in which case it directs CodeGen to emit the VTable. 450 SmallVector<uint64_t, 16> DynamicClasses; 451 452 /// \brief The IDs of the declarations Sema stores directly. 453 /// 454 /// Sema tracks a few important decls, such as namespace std, directly. 455 SmallVector<uint64_t, 4> SemaDeclRefs; 456 457 /// \brief The IDs of the types ASTContext stores directly. 458 /// 459 /// The AST context tracks a few important types, such as va_list, directly. 460 SmallVector<uint64_t, 16> SpecialTypes; 461 462 /// \brief The IDs of CUDA-specific declarations ASTContext stores directly. 463 /// 464 /// The AST context tracks a few important decls, currently cudaConfigureCall, 465 /// directly. 466 SmallVector<uint64_t, 2> CUDASpecialDeclRefs; 467 468 /// \brief The floating point pragma option settings. 469 SmallVector<uint64_t, 1> FPPragmaOptions; 470 471 /// \brief The OpenCL extension settings. 472 SmallVector<uint64_t, 1> OpenCLExtensions; 473 474 /// \brief A list of the namespaces we've seen. 475 SmallVector<uint64_t, 4> KnownNamespaces; 476 477 //@} 478 479 /// \brief The original file name that was used to build the primary AST file, 480 /// which may have been modified for relocatable-pch support. 481 std::string OriginalFileName; 482 483 /// \brief The actual original file name that was used to build the primary 484 /// AST file. 485 std::string ActualOriginalFileName; 486 487 /// \brief The file ID for the original file that was used to build the 488 /// primary AST file. 489 FileID OriginalFileID; 490 491 /// \brief The directory that the PCH was originally created in. Used to 492 /// allow resolving headers even after headers+PCH was moved to a new path. 493 std::string OriginalDir; 494 495 /// \brief The directory that the PCH we are reading is stored in. 496 std::string CurrentDir; 497 498 /// \brief Whether this precompiled header is a relocatable PCH file. 499 bool RelocatablePCH; 500 501 /// \brief The system include root to be used when loading the 502 /// precompiled header. 503 std::string isysroot; 504 505 /// \brief Whether to disable the normal validation performed on precompiled 506 /// headers when they are loaded. 507 bool DisableValidation; 508 509 /// \brief Whether to disable the use of stat caches in AST files. 510 bool DisableStatCache; 511 512 /// \brief Mapping from switch-case IDs in the chain to switch-case statements 513 /// 514 /// Statements usually don't have IDs, but switch cases need them, so that the 515 /// switch statement can refer to them. 516 std::map<unsigned, SwitchCase *> SwitchCaseStmts; 517 518 /// \brief Mapping from opaque value IDs to OpaqueValueExprs. 519 std::map<unsigned, OpaqueValueExpr*> OpaqueValueExprs; 520 521 /// \brief The number of stat() calls that hit/missed the stat 522 /// cache. 523 unsigned NumStatHits, NumStatMisses; 524 525 /// \brief The number of source location entries de-serialized from 526 /// the PCH file. 527 unsigned NumSLocEntriesRead; 528 529 /// \brief The number of source location entries in the chain. 530 unsigned TotalNumSLocEntries; 531 532 /// \brief The number of statements (and expressions) de-serialized 533 /// from the chain. 534 unsigned NumStatementsRead; 535 536 /// \brief The total number of statements (and expressions) stored 537 /// in the chain. 538 unsigned TotalNumStatements; 539 540 /// \brief The number of macros de-serialized from the chain. 541 unsigned NumMacrosRead; 542 543 /// \brief The total number of macros stored in the chain. 544 unsigned TotalNumMacros; 545 546 /// \brief The number of selectors that have been read. 547 unsigned NumSelectorsRead; 548 549 /// \brief The number of method pool entries that have been read. 550 unsigned NumMethodPoolEntriesRead; 551 552 /// \brief The number of times we have looked up a selector in the method 553 /// pool and not found anything interesting. 554 unsigned NumMethodPoolMisses; 555 556 /// \brief The total number of method pool entries in the selector table. 557 unsigned TotalNumMethodPoolEntries; 558 559 /// Number of lexical decl contexts read/total. 560 unsigned NumLexicalDeclContextsRead, TotalLexicalDeclContexts; 561 562 /// Number of visible decl contexts read/total. 563 unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts; 564 565 /// Total size of modules, in bits, currently loaded 566 uint64_t TotalModulesSizeInBits; 567 568 /// \brief Number of Decl/types that are currently deserializing. 569 unsigned NumCurrentElementsDeserializing; 570 571 /// Number of CXX base specifiers currently loaded 572 unsigned NumCXXBaseSpecifiersLoaded; 573 574 /// \brief An IdentifierInfo that has been loaded but whose top-level 575 /// declarations of the same name have not (yet) been loaded. 576 struct PendingIdentifierInfo { 577 IdentifierInfo *II; 578 SmallVector<uint32_t, 4> DeclIDs; 579 }; 580 581 /// \brief The set of identifiers that were read while the AST reader was 582 /// (recursively) loading declarations. 583 /// 584 /// The declarations on the identifier chain for these identifiers will be 585 /// loaded once the recursive loading has completed. 586 std::deque<PendingIdentifierInfo> PendingIdentifierInfos; 587 588 /// \brief Contains declarations and definitions that will be 589 /// "interesting" to the ASTConsumer, when we get that AST consumer. 590 /// 591 /// "Interesting" declarations are those that have data that may 592 /// need to be emitted, such as inline function definitions or 593 /// Objective-C protocols. 594 std::deque<Decl *> InterestingDecls; 595 596 /// \brief We delay loading of the previous declaration chain to avoid 597 /// deeply nested calls when there are many redeclarations. 598 std::deque<std::pair<Decl *, serialization::DeclID> > PendingPreviousDecls; 599 600 /// \brief Ready to load the previous declaration of the given Decl. 601 void loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID); 602 603 /// \brief When reading a Stmt tree, Stmt operands are placed in this stack. 604 SmallVector<Stmt *, 16> StmtStack; 605 606 /// \brief What kind of records we are reading. 607 enum ReadingKind { 608 Read_Decl, Read_Type, Read_Stmt 609 }; 610 611 /// \brief What kind of records we are reading. 612 ReadingKind ReadingKind; 613 614 /// \brief RAII object to change the reading kind. 615 class ReadingKindTracker { 616 ASTReader &Reader; 617 enum ReadingKind PrevKind; 618 619 ReadingKindTracker(const ReadingKindTracker&); // do not implement 620 ReadingKindTracker &operator=(const ReadingKindTracker&);// do not implement 621 622 public: 623 ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader) 624 : Reader(reader), PrevKind(Reader.ReadingKind) { 625 Reader.ReadingKind = newKind; 626 } 627 628 ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; } 629 }; 630 631 /// \brief All predefines buffers in the chain, to be treated as if 632 /// concatenated. 633 PCHPredefinesBlocks PCHPredefinesBuffers; 634 635 /// \brief Suggested contents of the predefines buffer, after this 636 /// PCH file has been processed. 637 /// 638 /// In most cases, this string will be empty, because the predefines 639 /// buffer computed to build the PCH file will be identical to the 640 /// predefines buffer computed from the command line. However, when 641 /// there are differences that the PCH reader can work around, this 642 /// predefines buffer may contain additional definitions. 643 std::string SuggestedPredefines; 644 645 /// \brief Reads a statement from the specified cursor. 646 Stmt *ReadStmtFromStream(Module &F); 647 648 /// \brief Get a FileEntry out of stored-in-PCH filename, making sure we take 649 /// into account all the necessary relocations. 650 const FileEntry *getFileEntry(StringRef filename); 651 652 void MaybeAddSystemRootToFilename(std::string &Filename); 653 654 ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type, 655 Module *ImportedBy); 656 ASTReadResult ReadASTBlock(Module &F); 657 bool CheckPredefinesBuffers(); 658 bool ParseLineTable(Module &F, SmallVectorImpl<uint64_t> &Record); 659 ASTReadResult ReadSourceManagerBlock(Module &F); 660 ASTReadResult ReadSLocEntryRecord(int ID); 661 llvm::BitstreamCursor &SLocCursorForID(int ID); 662 SourceLocation getImportLocation(Module *F); 663 bool ParseLanguageOptions(const SmallVectorImpl<uint64_t> &Record); 664 665 struct RecordLocation { 666 RecordLocation(Module *M, uint64_t O) 667 : F(M), Offset(O) {} 668 Module *F; 669 uint64_t Offset; 670 }; 671 672 QualType readTypeRecord(unsigned Index); 673 RecordLocation TypeCursorForIndex(unsigned Index); 674 void LoadedDecl(unsigned Index, Decl *D); 675 Decl *ReadDeclRecord(serialization::DeclID ID); 676 RecordLocation DeclCursorForID(serialization::DeclID ID); 677 void loadDeclUpdateRecords(serialization::DeclID ID, Decl *D); 678 void loadObjCChainedCategories(serialization::GlobalDeclID ID, 679 ObjCInterfaceDecl *D); 680 681 RecordLocation getLocalBitOffset(uint64_t GlobalOffset); 682 uint64_t getGlobalBitOffset(Module &M, uint32_t LocalOffset); 683 684 void PassInterestingDeclsToConsumer(); 685 686 /// \brief Produce an error diagnostic and return true. 687 /// 688 /// This routine should only be used for fatal errors that have to 689 /// do with non-routine failures (e.g., corrupted AST file). 690 void Error(StringRef Msg); 691 void Error(unsigned DiagID, StringRef Arg1 = StringRef(), 692 StringRef Arg2 = StringRef()); 693 694 ASTReader(const ASTReader&); // do not implement 695 ASTReader &operator=(const ASTReader &); // do not implement 696public: 697 typedef SmallVector<uint64_t, 64> RecordData; 698 699 /// \brief Load the AST file and validate its contents against the given 700 /// Preprocessor. 701 /// 702 /// \param PP the preprocessor associated with the context in which this 703 /// precompiled header will be loaded. 704 /// 705 /// \param Context the AST context that this precompiled header will be 706 /// loaded into. 707 /// 708 /// \param isysroot If non-NULL, the system include path specified by the 709 /// user. This is only used with relocatable PCH files. If non-NULL, 710 /// a relocatable PCH file will use the default path "/". 711 /// 712 /// \param DisableValidation If true, the AST reader will suppress most 713 /// of its regular consistency checking, allowing the use of precompiled 714 /// headers that cannot be determined to be compatible. 715 /// 716 /// \param DisableStatCache If true, the AST reader will ignore the 717 /// stat cache in the AST files. This performance pessimization can 718 /// help when an AST file is being used in cases where the 719 /// underlying files in the file system may have changed, but 720 /// parsing should still continue. 721 ASTReader(Preprocessor &PP, ASTContext &Context, StringRef isysroot = "", 722 bool DisableValidation = false, bool DisableStatCache = false); 723 724 ~ASTReader(); 725 726 /// \brief Load the AST file designated by the given file name. 727 ASTReadResult ReadAST(const std::string &FileName, ModuleKind Type); 728 729 /// \brief Checks that no file that is stored in PCH is out-of-sync with 730 /// the actual file in the file system. 731 ASTReadResult validateFileEntries(Module &M); 732 733 /// \brief Set the AST callbacks listener. 734 void setListener(ASTReaderListener *listener) { 735 Listener.reset(listener); 736 } 737 738 /// \brief Set the AST deserialization listener. 739 void setDeserializationListener(ASTDeserializationListener *Listener); 740 741 /// \brief Initializes the ASTContext 742 void InitializeContext(); 743 744 /// \brief Add in-memory (virtual file) buffer. 745 void addInMemoryBuffer(StringRef &FileName, llvm::MemoryBuffer *Buffer) { 746 ModuleMgr.addInMemoryBuffer(FileName, Buffer); 747 } 748 749 /// \brief Retrieve the module manager. 750 ModuleManager &getModuleManager() { return ModuleMgr; } 751 752 /// \brief Retrieve the preprocessor. 753 Preprocessor &getPreprocessor() const { return PP; } 754 755 /// \brief Retrieve the name of the original source file name 756 const std::string &getOriginalSourceFile() { return OriginalFileName; } 757 758 /// \brief Retrieve the name of the original source file name directly from 759 /// the AST file, without actually loading the AST file. 760 static std::string getOriginalSourceFile(const std::string &ASTFileName, 761 FileManager &FileMgr, 762 Diagnostic &Diags); 763 764 /// \brief Returns the suggested contents of the predefines buffer, 765 /// which contains a (typically-empty) subset of the predefines 766 /// build prior to including the precompiled header. 767 const std::string &getSuggestedPredefines() { return SuggestedPredefines; } 768 769 /// \brief Read a preallocated preprocessed entity from the external source. 770 /// 771 /// \returns null if an error occurred that prevented the preprocessed 772 /// entity from being loaded. 773 virtual PreprocessedEntity *ReadPreprocessedEntity(unsigned Index); 774 775 /// \brief Read the preprocessed entity at the given offset. 776 virtual PreprocessedEntity *ReadPreprocessedEntityAtOffset(uint64_t Offset); 777 778 /// \brief Read the header file information for the given file entry. 779 virtual HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE); 780 781 void ReadPragmaDiagnosticMappings(Diagnostic &Diag); 782 783 /// \brief Returns the number of source locations found in the chain. 784 unsigned getTotalNumSLocs() const { 785 return TotalNumSLocEntries; 786 } 787 788 /// \brief Returns the number of identifiers found in the chain. 789 unsigned getTotalNumIdentifiers() const { 790 return static_cast<unsigned>(IdentifiersLoaded.size()); 791 } 792 793 /// \brief Returns the number of types found in the chain. 794 unsigned getTotalNumTypes() const { 795 return static_cast<unsigned>(TypesLoaded.size()); 796 } 797 798 /// \brief Returns the number of declarations found in the chain. 799 unsigned getTotalNumDecls() const { 800 return static_cast<unsigned>(DeclsLoaded.size()); 801 } 802 803 /// \brief Returns the number of selectors found in the chain. 804 unsigned getTotalNumSelectors() const { 805 return static_cast<unsigned>(SelectorsLoaded.size()); 806 } 807 808 /// \brief Returns the number of preprocessed entities known to the AST 809 /// reader. 810 unsigned getTotalNumPreprocessedEntities() const { 811 unsigned Result = 0; 812 for (ModuleConstIterator I = ModuleMgr.begin(), 813 E = ModuleMgr.end(); I != E; ++I) { 814 Result += (*I)->NumPreprocessedEntities; 815 } 816 817 return Result; 818 } 819 820 /// \brief Returns the number of C++ base specifiers found in the chain. 821 unsigned getTotalNumCXXBaseSpecifiers() const { 822 return NumCXXBaseSpecifiersLoaded; 823 } 824 825 /// \brief Reads a TemplateArgumentLocInfo appropriate for the 826 /// given TemplateArgument kind. 827 TemplateArgumentLocInfo 828 GetTemplateArgumentLocInfo(Module &F, TemplateArgument::ArgKind Kind, 829 const RecordData &Record, unsigned &Idx); 830 831 /// \brief Reads a TemplateArgumentLoc. 832 TemplateArgumentLoc 833 ReadTemplateArgumentLoc(Module &F, 834 const RecordData &Record, unsigned &Idx); 835 836 /// \brief Reads a declarator info from the given record. 837 TypeSourceInfo *GetTypeSourceInfo(Module &F, 838 const RecordData &Record, unsigned &Idx); 839 840 /// \brief Resolve a type ID into a type, potentially building a new 841 /// type. 842 QualType GetType(serialization::TypeID ID); 843 844 /// \brief Resolve a local type ID within a given AST file into a type. 845 QualType getLocalType(Module &F, unsigned LocalID); 846 847 /// \brief Map a local type ID within a given AST file into a global type ID. 848 serialization::TypeID getGlobalTypeID(Module &F, unsigned LocalID) const; 849 850 /// \brief Read a type from the current position in the given record, which 851 /// was read from the given AST file. 852 QualType readType(Module &F, const RecordData &Record, unsigned &Idx) { 853 if (Idx >= Record.size()) 854 return QualType(); 855 856 return getLocalType(F, Record[Idx++]); 857 } 858 859 /// \brief Map from a local declaration ID within a given module to a 860 /// global declaration ID. 861 serialization::DeclID getGlobalDeclID(Module &F, unsigned LocalID) const; 862 863 /// \brief Returns true if global DeclID \arg ID originated from module 864 /// \arg M. 865 bool isDeclIDFromModule(serialization::GlobalDeclID ID, Module &M) const; 866 867 /// \brief Resolve a declaration ID into a declaration, potentially 868 /// building a new declaration. 869 Decl *GetDecl(serialization::DeclID ID); 870 virtual Decl *GetExternalDecl(uint32_t ID); 871 872 /// \brief Reads a declaration with the given local ID in the given module. 873 Decl *GetLocalDecl(Module &F, uint32_t LocalID) { 874 return GetDecl(getGlobalDeclID(F, LocalID)); 875 } 876 877 /// \brief Reads a declaration with the given local ID in the given module. 878 /// 879 /// \returns The requested declaration, casted to the given return type. 880 template<typename T> 881 T *GetLocalDeclAs(Module &F, uint32_t LocalID) { 882 return cast_or_null<T>(GetLocalDecl(F, LocalID)); 883 } 884 885 /// \brief Reads a declaration ID from the given position in a record in the 886 /// given module. 887 /// 888 /// \returns The declaration ID read from the record, adjusted to a global ID. 889 serialization::DeclID ReadDeclID(Module &F, const RecordData &Record, 890 unsigned &Idx); 891 892 /// \brief Reads a declaration from the given position in a record in the 893 /// given module. 894 Decl *ReadDecl(Module &F, const RecordData &R, unsigned &I) { 895 return GetDecl(ReadDeclID(F, R, I)); 896 } 897 898 /// \brief Reads a declaration from the given position in a record in the 899 /// given module. 900 /// 901 /// \returns The declaration read from this location, casted to the given 902 /// result type. 903 template<typename T> 904 T *ReadDeclAs(Module &F, const RecordData &R, unsigned &I) { 905 return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I))); 906 } 907 908 /// \brief Read a CXXBaseSpecifiers ID form the given record and 909 /// return its global bit offset. 910 uint64_t readCXXBaseSpecifiers(Module &M, const RecordData &Record, 911 unsigned &Idx); 912 913 virtual CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset); 914 915 /// \brief Resolve the offset of a statement into a statement. 916 /// 917 /// This operation will read a new statement from the external 918 /// source each time it is called, and is meant to be used via a 919 /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). 920 virtual Stmt *GetExternalDeclStmt(uint64_t Offset); 921 922 /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the 923 /// specified cursor. Read the abbreviations that are at the top of the block 924 /// and then leave the cursor pointing into the block. 925 bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID); 926 927 /// \brief Finds all the visible declarations with a given name. 928 /// The current implementation of this method just loads the entire 929 /// lookup table as unmaterialized references. 930 virtual DeclContext::lookup_result 931 FindExternalVisibleDeclsByName(const DeclContext *DC, 932 DeclarationName Name); 933 934 /// \brief Read all of the declarations lexically stored in a 935 /// declaration context. 936 /// 937 /// \param DC The declaration context whose declarations will be 938 /// read. 939 /// 940 /// \param Decls Vector that will contain the declarations loaded 941 /// from the external source. The caller is responsible for merging 942 /// these declarations with any declarations already stored in the 943 /// declaration context. 944 /// 945 /// \returns true if there was an error while reading the 946 /// declarations for this declaration context. 947 virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC, 948 bool (*isKindWeWant)(Decl::Kind), 949 SmallVectorImpl<Decl*> &Decls); 950 951 /// \brief Notify ASTReader that we started deserialization of 952 /// a decl or type so until FinishedDeserializing is called there may be 953 /// decls that are initializing. Must be paired with FinishedDeserializing. 954 virtual void StartedDeserializing() { ++NumCurrentElementsDeserializing; } 955 956 /// \brief Notify ASTReader that we finished the deserialization of 957 /// a decl or type. Must be paired with StartedDeserializing. 958 virtual void FinishedDeserializing(); 959 960 /// \brief Function that will be invoked when we begin parsing a new 961 /// translation unit involving this external AST source. 962 /// 963 /// This function will provide all of the external definitions to 964 /// the ASTConsumer. 965 virtual void StartTranslationUnit(ASTConsumer *Consumer); 966 967 /// \brief Print some statistics about AST usage. 968 virtual void PrintStats(); 969 970 /// \brief Dump information about the AST reader to standard error. 971 void dump(); 972 973 /// Return the amount of memory used by memory buffers, breaking down 974 /// by heap-backed versus mmap'ed memory. 975 virtual void getMemoryBufferSizes(MemoryBufferSizes &sizes) const; 976 977 /// \brief Initialize the semantic source with the Sema instance 978 /// being used to perform semantic analysis on the abstract syntax 979 /// tree. 980 virtual void InitializeSema(Sema &S); 981 982 /// \brief Inform the semantic consumer that Sema is no longer available. 983 virtual void ForgetSema() { SemaObj = 0; } 984 985 /// \brief Retrieve the IdentifierInfo for the named identifier. 986 /// 987 /// This routine builds a new IdentifierInfo for the given identifier. If any 988 /// declarations with this name are visible from translation unit scope, their 989 /// declarations will be deserialized and introduced into the declaration 990 /// chain of the identifier. 991 virtual IdentifierInfo *get(const char *NameStart, const char *NameEnd); 992 IdentifierInfo *get(StringRef Name) { 993 return get(Name.begin(), Name.end()); 994 } 995 996 /// \brief Retrieve an iterator into the set of all identifiers 997 /// in all loaded AST files. 998 virtual IdentifierIterator *getIdentifiers() const; 999 1000 /// \brief Load the contents of the global method pool for a given 1001 /// selector. 1002 /// 1003 /// \returns a pair of Objective-C methods lists containing the 1004 /// instance and factory methods, respectively, with this selector. 1005 virtual std::pair<ObjCMethodList, ObjCMethodList> 1006 ReadMethodPool(Selector Sel); 1007 1008 /// \brief Load the set of namespaces that are known to the external source, 1009 /// which will be used during typo correction. 1010 virtual void ReadKnownNamespaces( 1011 SmallVectorImpl<NamespaceDecl *> &Namespaces); 1012 1013 virtual void ReadTentativeDefinitions( 1014 SmallVectorImpl<VarDecl *> &TentativeDefs); 1015 1016 virtual void ReadUnusedFileScopedDecls( 1017 SmallVectorImpl<const DeclaratorDecl *> &Decls); 1018 1019 virtual void ReadDelegatingConstructors( 1020 SmallVectorImpl<CXXConstructorDecl *> &Decls); 1021 1022 virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls); 1023 1024 virtual void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls); 1025 1026 virtual void ReadLocallyScopedExternalDecls( 1027 SmallVectorImpl<NamedDecl *> &Decls); 1028 1029 virtual void ReadReferencedSelectors( 1030 SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels); 1031 1032 virtual void ReadWeakUndeclaredIdentifiers( 1033 SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI); 1034 1035 virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables); 1036 1037 virtual void ReadPendingInstantiations( 1038 SmallVectorImpl<std::pair<ValueDecl *, 1039 SourceLocation> > &Pending); 1040 1041 /// \brief Load a selector from disk, registering its ID if it exists. 1042 void LoadSelector(Selector Sel); 1043 1044 void SetIdentifierInfo(unsigned ID, IdentifierInfo *II); 1045 void SetGloballyVisibleDecls(IdentifierInfo *II, 1046 const SmallVectorImpl<uint32_t> &DeclIDs, 1047 bool Nonrecursive = false); 1048 1049 /// \brief Report a diagnostic. 1050 DiagnosticBuilder Diag(unsigned DiagID); 1051 1052 /// \brief Report a diagnostic. 1053 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); 1054 1055 IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID); 1056 1057 IdentifierInfo *GetIdentifierInfo(Module &M, const RecordData &Record, 1058 unsigned &Idx) { 1059 return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++])); 1060 } 1061 1062 virtual IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) { 1063 return DecodeIdentifierInfo(ID); 1064 } 1065 1066 IdentifierInfo *getLocalIdentifier(Module &M, unsigned LocalID); 1067 1068 serialization::IdentifierID getGlobalIdentifierID(Module &M, 1069 unsigned LocalID); 1070 1071 /// \brief Read the source location entry with index ID. 1072 virtual bool ReadSLocEntry(int ID); 1073 1074 /// \brief Retrieve a selector from the given module with its local ID 1075 /// number. 1076 Selector getLocalSelector(Module &M, unsigned LocalID); 1077 1078 Selector DecodeSelector(serialization::SelectorID Idx); 1079 1080 virtual Selector GetExternalSelector(serialization::SelectorID ID); 1081 uint32_t GetNumExternalSelectors(); 1082 1083 Selector ReadSelector(Module &M, const RecordData &Record, unsigned &Idx) { 1084 return getLocalSelector(M, Record[Idx++]); 1085 } 1086 1087 /// \brief Retrieve the global selector ID that corresponds to this 1088 /// the local selector ID in a given module. 1089 serialization::SelectorID getGlobalSelectorID(Module &F, 1090 unsigned LocalID) const; 1091 1092 /// \brief Read a declaration name. 1093 DeclarationName ReadDeclarationName(Module &F, 1094 const RecordData &Record, unsigned &Idx); 1095 void ReadDeclarationNameLoc(Module &F, 1096 DeclarationNameLoc &DNLoc, DeclarationName Name, 1097 const RecordData &Record, unsigned &Idx); 1098 void ReadDeclarationNameInfo(Module &F, DeclarationNameInfo &NameInfo, 1099 const RecordData &Record, unsigned &Idx); 1100 1101 void ReadQualifierInfo(Module &F, QualifierInfo &Info, 1102 const RecordData &Record, unsigned &Idx); 1103 1104 NestedNameSpecifier *ReadNestedNameSpecifier(Module &F, 1105 const RecordData &Record, 1106 unsigned &Idx); 1107 1108 NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(Module &F, 1109 const RecordData &Record, 1110 unsigned &Idx); 1111 1112 /// \brief Read a template name. 1113 TemplateName ReadTemplateName(Module &F, const RecordData &Record, 1114 unsigned &Idx); 1115 1116 /// \brief Read a template argument. 1117 TemplateArgument ReadTemplateArgument(Module &F, 1118 const RecordData &Record,unsigned &Idx); 1119 1120 /// \brief Read a template parameter list. 1121 TemplateParameterList *ReadTemplateParameterList(Module &F, 1122 const RecordData &Record, 1123 unsigned &Idx); 1124 1125 /// \brief Read a template argument array. 1126 void 1127 ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs, 1128 Module &F, const RecordData &Record, 1129 unsigned &Idx); 1130 1131 /// \brief Read a UnresolvedSet structure. 1132 void ReadUnresolvedSet(Module &F, UnresolvedSetImpl &Set, 1133 const RecordData &Record, unsigned &Idx); 1134 1135 /// \brief Read a C++ base specifier. 1136 CXXBaseSpecifier ReadCXXBaseSpecifier(Module &F, 1137 const RecordData &Record,unsigned &Idx); 1138 1139 /// \brief Read a CXXCtorInitializer array. 1140 std::pair<CXXCtorInitializer **, unsigned> 1141 ReadCXXCtorInitializers(Module &F, const RecordData &Record, 1142 unsigned &Idx); 1143 1144 /// \brief Read a source location from raw form. 1145 SourceLocation ReadSourceLocation(Module &Module, unsigned Raw) const { 1146 unsigned Flag = Raw & (1U << 31); 1147 unsigned Offset = Raw & ~(1U << 31); 1148 assert(Module.SLocRemap.find(Offset) != Module.SLocRemap.end() && 1149 "Cannot find offset to remap."); 1150 int Remap = Module.SLocRemap.find(Offset)->second; 1151 Offset += Remap; 1152 assert((Offset & (1U << 31)) == 0 && 1153 "Bad offset in reading source location"); 1154 return SourceLocation::getFromRawEncoding(Offset | Flag); 1155 } 1156 1157 /// \brief Read a source location. 1158 SourceLocation ReadSourceLocation(Module &Module, 1159 const RecordData &Record, unsigned& Idx) { 1160 return ReadSourceLocation(Module, Record[Idx++]); 1161 } 1162 1163 /// \brief Read a source range. 1164 SourceRange ReadSourceRange(Module &F, 1165 const RecordData &Record, unsigned& Idx); 1166 1167 /// \brief Read an integral value 1168 llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx); 1169 1170 /// \brief Read a signed integral value 1171 llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx); 1172 1173 /// \brief Read a floating-point value 1174 llvm::APFloat ReadAPFloat(const RecordData &Record, unsigned &Idx); 1175 1176 // \brief Read a string 1177 std::string ReadString(const RecordData &Record, unsigned &Idx); 1178 1179 /// \brief Read a version tuple. 1180 VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx); 1181 1182 CXXTemporary *ReadCXXTemporary(Module &F, const RecordData &Record, 1183 unsigned &Idx); 1184 1185 /// \brief Reads attributes from the current stream position. 1186 void ReadAttributes(Module &F, AttrVec &Attrs, 1187 const RecordData &Record, unsigned &Idx); 1188 1189 /// \brief Reads a statement. 1190 Stmt *ReadStmt(Module &F); 1191 1192 /// \brief Reads an expression. 1193 Expr *ReadExpr(Module &F); 1194 1195 /// \brief Reads a sub-statement operand during statement reading. 1196 Stmt *ReadSubStmt() { 1197 assert(ReadingKind == Read_Stmt && 1198 "Should be called only during statement reading!"); 1199 // Subexpressions are stored from last to first, so the next Stmt we need 1200 // is at the back of the stack. 1201 assert(!StmtStack.empty() && "Read too many sub statements!"); 1202 return StmtStack.pop_back_val(); 1203 } 1204 1205 /// \brief Reads a sub-expression operand during statement reading. 1206 Expr *ReadSubExpr(); 1207 1208 /// \brief Reads the macro record located at the given offset. 1209 void ReadMacroRecord(Module &F, uint64_t Offset); 1210 1211 /// \brief Reads the preprocessed entity located at the current stream 1212 /// position. 1213 PreprocessedEntity *LoadPreprocessedEntity(Module &F); 1214 1215 /// \brief Determine the global preprocessed entity ID that corresponds to 1216 /// the given local ID within the given module. 1217 serialization::PreprocessedEntityID 1218 getGlobalPreprocessedEntityID(Module &M, unsigned LocalID) const; 1219 1220 /// \brief Note that the identifier is a macro whose record will be loaded 1221 /// from the given AST file at the given (file-local) offset. 1222 void SetIdentifierIsMacro(IdentifierInfo *II, Module &F, 1223 uint64_t Offset); 1224 1225 /// \brief Read the set of macros defined by this external macro source. 1226 virtual void ReadDefinedMacros(); 1227 1228 /// \brief Read the macro definition for this identifier. 1229 virtual void LoadMacroDefinition(IdentifierInfo *II); 1230 1231 /// \brief Read the macro definition corresponding to this iterator 1232 /// into the unread macro record offsets table. 1233 void LoadMacroDefinition( 1234 llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos); 1235 1236 /// \brief Retrieve the AST context that this AST reader supplements. 1237 ASTContext &getContext() { return Context; } 1238 1239 // \brief Contains declarations that were loaded before we have 1240 // access to a Sema object. 1241 SmallVector<NamedDecl *, 16> PreloadedDecls; 1242 1243 /// \brief Retrieve the semantic analysis object used to analyze the 1244 /// translation unit in which the precompiled header is being 1245 /// imported. 1246 Sema *getSema() { return SemaObj; } 1247 1248 /// \brief Retrieve the identifier table associated with the 1249 /// preprocessor. 1250 IdentifierTable &getIdentifierTable(); 1251 1252 /// \brief Record that the given ID maps to the given switch-case 1253 /// statement. 1254 void RecordSwitchCaseID(SwitchCase *SC, unsigned ID); 1255 1256 /// \brief Retrieve the switch-case statement with the given ID. 1257 SwitchCase *getSwitchCaseWithID(unsigned ID); 1258 1259 void ClearSwitchCaseIDs(); 1260}; 1261 1262/// \brief Helper class that saves the current stream position and 1263/// then restores it when destroyed. 1264struct SavedStreamPosition { 1265 explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor) 1266 : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) { } 1267 1268 ~SavedStreamPosition() { 1269 Cursor.JumpToBit(Offset); 1270 } 1271 1272private: 1273 llvm::BitstreamCursor &Cursor; 1274 uint64_t Offset; 1275}; 1276 1277inline void PCHValidator::Error(const char *Msg) { 1278 Reader.Error(Msg); 1279} 1280 1281} // end namespace clang 1282 1283#endif 1284