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