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