1 //===--- ASTWriter.h - AST File Writer --------------------------*- 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 ASTWriter class, which writes an AST file 11 // containing a serialized representation of a translation unit. 12 // 13 //===----------------------------------------------------------------------===// 14 #ifndef LLVM_CLANG_FRONTEND_AST_WRITER_H 15 #define LLVM_CLANG_FRONTEND_AST_WRITER_H 16 17 #include "clang/AST/Decl.h" 18 #include "clang/AST/DeclarationName.h" 19 #include "clang/AST/TemplateBase.h" 20 #include "clang/AST/ASTMutationListener.h" 21 #include "clang/Serialization/ASTBitCodes.h" 22 #include "clang/Serialization/ASTDeserializationListener.h" 23 #include "clang/Sema/SemaConsumer.h" 24 #include "llvm/ADT/SmallPtrSet.h" 25 #include "llvm/ADT/SmallVector.h" 26 #include "llvm/ADT/DenseMap.h" 27 #include "llvm/Bitcode/BitstreamWriter.h" 28 #include <map> 29 #include <queue> 30 #include <vector> 31 32 namespace llvm { 33 class APFloat; 34 class APInt; 35 class BitstreamWriter; 36 } 37 38 namespace clang { 39 40 class ASTContext; 41 class ASTSerializationListener; 42 class NestedNameSpecifier; 43 class CXXBaseSpecifier; 44 class CXXCtorInitializer; 45 class FPOptions; 46 class HeaderSearch; 47 class MacroDefinition; 48 class MemorizeStatCalls; 49 class OpaqueValueExpr; 50 class OpenCLOptions; 51 class ASTReader; 52 class PreprocessedEntity; 53 class PreprocessingRecord; 54 class Preprocessor; 55 class Sema; 56 class SourceManager; 57 class SwitchCase; 58 class TargetInfo; 59 class VersionTuple; 60 61 /// \brief Writes an AST file containing the contents of a translation unit. 62 /// 63 /// The ASTWriter class produces a bitstream containing the serialized 64 /// representation of a given abstract syntax tree and its supporting 65 /// data structures. This bitstream can be de-serialized via an 66 /// instance of the ASTReader class. 67 class ASTWriter : public ASTDeserializationListener, 68 public ASTMutationListener { 69 public: 70 typedef llvm::SmallVector<uint64_t, 64> RecordData; 71 typedef llvm::SmallVectorImpl<uint64_t> RecordDataImpl; 72 73 friend class ASTDeclWriter; 74 private: 75 /// \brief The bitstream writer used to emit this precompiled header. 76 llvm::BitstreamWriter &Stream; 77 78 /// \brief The reader of existing AST files, if we're chaining. 79 ASTReader *Chain; 80 81 /// \brief A listener object that receives notifications when certain 82 /// entities are serialized. 83 ASTSerializationListener *SerializationListener; 84 85 /// \brief Stores a declaration or a type to be written to the AST file. 86 class DeclOrType { 87 public: 88 DeclOrType(Decl *D) : Stored(D), IsType(false) { } 89 DeclOrType(QualType T) : Stored(T.getAsOpaquePtr()), IsType(true) { } 90 91 bool isType() const { return IsType; } 92 bool isDecl() const { return !IsType; } 93 94 QualType getType() const { 95 assert(isType() && "Not a type!"); 96 return QualType::getFromOpaquePtr(Stored); 97 } 98 99 Decl *getDecl() const { 100 assert(isDecl() && "Not a decl!"); 101 return static_cast<Decl *>(Stored); 102 } 103 104 private: 105 void *Stored; 106 bool IsType; 107 }; 108 109 /// \brief The declarations and types to emit. 110 std::queue<DeclOrType> DeclTypesToEmit; 111 112 /// \brief The first ID number we can use for our own declarations. 113 serialization::DeclID FirstDeclID; 114 115 /// \brief The decl ID that will be assigned to the next new decl. 116 serialization::DeclID NextDeclID; 117 118 /// \brief Map that provides the ID numbers of each declaration within 119 /// the output stream, as well as those deserialized from a chained PCH. 120 /// 121 /// The ID numbers of declarations are consecutive (in order of 122 /// discovery) and start at 2. 1 is reserved for the translation 123 /// unit, while 0 is reserved for NULL. 124 llvm::DenseMap<const Decl *, serialization::DeclID> DeclIDs; 125 126 /// \brief Offset of each declaration in the bitstream, indexed by 127 /// the declaration's ID. 128 std::vector<uint32_t> DeclOffsets; 129 130 /// \brief The first ID number we can use for our own types. 131 serialization::TypeID FirstTypeID; 132 133 /// \brief The type ID that will be assigned to the next new type. 134 serialization::TypeID NextTypeID; 135 136 /// \brief Map that provides the ID numbers of each type within the 137 /// output stream, plus those deserialized from a chained PCH. 138 /// 139 /// The ID numbers of types are consecutive (in order of discovery) 140 /// and start at 1. 0 is reserved for NULL. When types are actually 141 /// stored in the stream, the ID number is shifted by 2 bits to 142 /// allow for the const/volatile qualifiers. 143 /// 144 /// Keys in the map never have const/volatile qualifiers. 145 serialization::TypeIdxMap TypeIdxs; 146 147 /// \brief Offset of each type in the bitstream, indexed by 148 /// the type's ID. 149 std::vector<uint32_t> TypeOffsets; 150 151 /// \brief The first ID number we can use for our own identifiers. 152 serialization::IdentID FirstIdentID; 153 154 /// \brief The identifier ID that will be assigned to the next new identifier. 155 serialization::IdentID NextIdentID; 156 157 /// \brief Map that provides the ID numbers of each identifier in 158 /// the output stream. 159 /// 160 /// The ID numbers for identifiers are consecutive (in order of 161 /// discovery), starting at 1. An ID of zero refers to a NULL 162 /// IdentifierInfo. 163 llvm::DenseMap<const IdentifierInfo *, serialization::IdentID> IdentifierIDs; 164 165 /// \brief Offsets of each of the identifier IDs into the identifier 166 /// table. 167 std::vector<uint32_t> IdentifierOffsets; 168 169 /// \brief The first ID number we can use for our own selectors. 170 serialization::SelectorID FirstSelectorID; 171 172 /// \brief The selector ID that will be assigned to the next new identifier. 173 serialization::SelectorID NextSelectorID; 174 175 /// \brief Map that provides the ID numbers of each Selector. 176 llvm::DenseMap<Selector, serialization::SelectorID> SelectorIDs; 177 178 /// \brief Offset of each selector within the method pool/selector 179 /// table, indexed by the Selector ID (-1). 180 std::vector<uint32_t> SelectorOffsets; 181 182 /// \brief Offsets of each of the macro identifiers into the 183 /// bitstream. 184 /// 185 /// For each identifier that is associated with a macro, this map 186 /// provides the offset into the bitstream where that macro is 187 /// defined. 188 llvm::DenseMap<const IdentifierInfo *, uint64_t> MacroOffsets; 189 190 /// \brief The set of identifiers that had macro definitions at some point. 191 std::vector<const IdentifierInfo *> DeserializedMacroNames; 192 193 /// \brief The first ID number we can use for our own macro definitions. 194 serialization::MacroID FirstMacroID; 195 196 /// \brief The decl ID that will be assigned to the next new macro definition. 197 serialization::MacroID NextMacroID; 198 199 /// \brief Mapping from macro definitions (as they occur in the preprocessing 200 /// record) to the macro IDs. 201 llvm::DenseMap<const MacroDefinition *, serialization::MacroID> 202 MacroDefinitions; 203 204 /// \brief Mapping from the macro definition indices in \c MacroDefinitions 205 /// to the corresponding offsets within the preprocessor block. 206 std::vector<uint32_t> MacroDefinitionOffsets; 207 208 typedef llvm::SmallVector<uint64_t, 2> UpdateRecord; 209 typedef llvm::DenseMap<const Decl *, UpdateRecord> DeclUpdateMap; 210 /// \brief Mapping from declarations that came from a chained PCH to the 211 /// record containing modifications to them. 212 DeclUpdateMap DeclUpdates; 213 214 typedef llvm::DenseMap<Decl *, Decl *> FirstLatestDeclMap; 215 /// \brief Map of first declarations from a chained PCH that point to the 216 /// most recent declarations in another PCH. 217 FirstLatestDeclMap FirstLatestDecls; 218 219 /// \brief Declarations encountered that might be external 220 /// definitions. 221 /// 222 /// We keep track of external definitions (as well as tentative 223 /// definitions) as we are emitting declarations to the AST 224 /// file. The AST file contains a separate record for these external 225 /// definitions, which are provided to the AST consumer by the AST 226 /// reader. This is behavior is required to properly cope with, 227 /// e.g., tentative variable definitions that occur within 228 /// headers. The declarations themselves are stored as declaration 229 /// IDs, since they will be written out to an EXTERNAL_DEFINITIONS 230 /// record. 231 llvm::SmallVector<uint64_t, 16> ExternalDefinitions; 232 233 /// \brief DeclContexts that have received extensions since their serialized 234 /// form. 235 /// 236 /// For namespaces, when we're chaining and encountering a namespace, we check if 237 /// its primary namespace comes from the chain. If it does, we add the primary 238 /// to this set, so that we can write out lexical content updates for it. 239 llvm::SmallPtrSet<const DeclContext *, 16> UpdatedDeclContexts; 240 241 typedef llvm::SmallPtrSet<const Decl *, 16> DeclsToRewriteTy; 242 /// \brief Decls that will be replaced in the current dependent AST file. 243 DeclsToRewriteTy DeclsToRewrite; 244 245 /// \brief Decls that have been replaced in the current dependent AST file. 246 /// 247 /// When a decl changes fundamentally after being deserialized (this shouldn't 248 /// happen, but the ObjC AST nodes are designed this way), it will be 249 /// serialized again. In this case, it is registered here, so that the reader 250 /// knows to read the updated version. 251 llvm::SmallVector<std::pair<serialization::DeclID, uint64_t>, 16> 252 ReplacedDecls; 253 254 /// \brief Statements that we've encountered while serializing a 255 /// declaration or type. 256 llvm::SmallVector<Stmt *, 16> StmtsToEmit; 257 258 /// \brief Statements collection to use for ASTWriter::AddStmt(). 259 /// It will point to StmtsToEmit unless it is overriden. 260 llvm::SmallVector<Stmt *, 16> *CollectedStmts; 261 262 /// \brief Mapping from SwitchCase statements to IDs. 263 std::map<SwitchCase *, unsigned> SwitchCaseIDs; 264 265 /// \brief Mapping from OpaqueValueExpr expressions to IDs. 266 llvm::DenseMap<OpaqueValueExpr *, unsigned> OpaqueValues; 267 268 /// \brief The number of statements written to the AST file. 269 unsigned NumStatements; 270 271 /// \brief The number of macros written to the AST file. 272 unsigned NumMacros; 273 274 /// \brief The number of lexical declcontexts written to the AST 275 /// file. 276 unsigned NumLexicalDeclContexts; 277 278 /// \brief The number of visible declcontexts written to the AST 279 /// file. 280 unsigned NumVisibleDeclContexts; 281 282 /// \brief The offset of each CXXBaseSpecifier set within the AST. 283 llvm::SmallVector<uint32_t, 4> CXXBaseSpecifiersOffsets; 284 285 /// \brief The first ID number we can use for our own base specifiers. 286 serialization::CXXBaseSpecifiersID FirstCXXBaseSpecifiersID; 287 288 /// \brief The base specifiers ID that will be assigned to the next new 289 /// set of C++ base specifiers. 290 serialization::CXXBaseSpecifiersID NextCXXBaseSpecifiersID; 291 292 /// \brief A set of C++ base specifiers that is queued to be written into the 293 /// AST file. 294 struct QueuedCXXBaseSpecifiers { 295 QueuedCXXBaseSpecifiers() : ID(), Bases(), BasesEnd() { } 296 297 QueuedCXXBaseSpecifiers(serialization::CXXBaseSpecifiersID ID, 298 CXXBaseSpecifier const *Bases, 299 CXXBaseSpecifier const *BasesEnd) 300 : ID(ID), Bases(Bases), BasesEnd(BasesEnd) { } 301 302 serialization::CXXBaseSpecifiersID ID; 303 CXXBaseSpecifier const * Bases; 304 CXXBaseSpecifier const * BasesEnd; 305 }; 306 307 /// \brief Queue of C++ base specifiers to be written to the AST file, 308 /// in the order they should be written. 309 llvm::SmallVector<QueuedCXXBaseSpecifiers, 2> CXXBaseSpecifiersToWrite; 310 311 /// \brief Write the given subexpression to the bitstream. 312 void WriteSubStmt(Stmt *S); 313 314 void WriteBlockInfoBlock(); 315 void WriteMetadata(ASTContext &Context, const char *isysroot, 316 const std::string &OutputFile); 317 void WriteLanguageOptions(const LangOptions &LangOpts); 318 void WriteStatCache(MemorizeStatCalls &StatCalls); 319 void WriteSourceManagerBlock(SourceManager &SourceMgr, 320 const Preprocessor &PP, 321 const char* isysroot); 322 void WritePreprocessor(const Preprocessor &PP); 323 void WriteHeaderSearch(HeaderSearch &HS, const char* isysroot); 324 void WritePreprocessorDetail(PreprocessingRecord &PPRec); 325 void WritePragmaDiagnosticMappings(const Diagnostic &Diag); 326 void WriteCXXBaseSpecifiersOffsets(); 327 void WriteType(QualType T); 328 uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC); 329 uint64_t WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC); 330 void WriteTypeDeclOffsets(); 331 void WriteSelectors(Sema &SemaRef); 332 void WriteReferencedSelectorsPool(Sema &SemaRef); 333 void WriteIdentifierTable(Preprocessor &PP); 334 void WriteAttributes(const AttrVec &Attrs, RecordDataImpl &Record); 335 void WriteDeclUpdatesBlocks(); 336 void WriteDeclReplacementsBlock(); 337 void WriteDeclContextVisibleUpdate(const DeclContext *DC); 338 void WriteFPPragmaOptions(const FPOptions &Opts); 339 void WriteOpenCLExtensions(Sema &SemaRef); 340 341 unsigned DeclParmVarAbbrev; 342 unsigned DeclContextLexicalAbbrev; 343 unsigned DeclContextVisibleLookupAbbrev; 344 unsigned UpdateVisibleAbbrev; 345 unsigned DeclRefExprAbbrev; 346 unsigned CharacterLiteralAbbrev; 347 unsigned DeclRecordAbbrev; 348 unsigned IntegerLiteralAbbrev; 349 unsigned DeclTypedefAbbrev; 350 unsigned DeclVarAbbrev; 351 unsigned DeclFieldAbbrev; 352 unsigned DeclEnumAbbrev; 353 unsigned DeclObjCIvarAbbrev; 354 355 void WriteDeclsBlockAbbrevs(); 356 void WriteDecl(ASTContext &Context, Decl *D); 357 358 void WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, 359 const char* isysroot, const std::string &OutputFile); 360 void WriteASTChain(Sema &SemaRef, MemorizeStatCalls *StatCalls, 361 const char* isysroot); 362 363 public: 364 /// \brief Create a new precompiled header writer that outputs to 365 /// the given bitstream. 366 ASTWriter(llvm::BitstreamWriter &Stream); 367 368 /// \brief Set the listener that will receive notification of serialization 369 /// events. 370 void SetSerializationListener(ASTSerializationListener *Listener) { 371 SerializationListener = Listener; 372 } 373 374 /// \brief Write a precompiled header for the given semantic analysis. 375 /// 376 /// \param SemaRef a reference to the semantic analysis object that processed 377 /// the AST to be written into the precompiled header. 378 /// 379 /// \param StatCalls the object that cached all of the stat() calls made while 380 /// searching for source files and headers. 381 /// 382 /// \param isysroot if non-NULL, write a relocatable PCH file whose headers 383 /// are relative to the given system root. 384 /// 385 /// \param PPRec Record of the preprocessing actions that occurred while 386 /// preprocessing this file, e.g., macro expansions 387 void WriteAST(Sema &SemaRef, MemorizeStatCalls *StatCalls, 388 const std::string &OutputFile, 389 const char* isysroot); 390 391 /// \brief Emit a source location. 392 void AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record); 393 394 /// \brief Emit a source range. 395 void AddSourceRange(SourceRange Range, RecordDataImpl &Record); 396 397 /// \brief Emit an integral value. 398 void AddAPInt(const llvm::APInt &Value, RecordDataImpl &Record); 399 400 /// \brief Emit a signed integral value. 401 void AddAPSInt(const llvm::APSInt &Value, RecordDataImpl &Record); 402 403 /// \brief Emit a floating-point value. 404 void AddAPFloat(const llvm::APFloat &Value, RecordDataImpl &Record); 405 406 /// \brief Emit a reference to an identifier. 407 void AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record); 408 409 /// \brief Emit a Selector (which is a smart pointer reference). 410 void AddSelectorRef(Selector, RecordDataImpl &Record); 411 412 /// \brief Emit a CXXTemporary. 413 void AddCXXTemporary(const CXXTemporary *Temp, RecordDataImpl &Record); 414 415 /// \brief Emit a set of C++ base specifiers to the record. 416 void AddCXXBaseSpecifiersRef(CXXBaseSpecifier const *Bases, 417 CXXBaseSpecifier const *BasesEnd, 418 RecordDataImpl &Record); 419 420 /// \brief Get the unique number used to refer to the given selector. 421 serialization::SelectorID getSelectorRef(Selector Sel); 422 423 /// \brief Get the unique number used to refer to the given identifier. 424 serialization::IdentID getIdentifierRef(const IdentifierInfo *II); 425 426 /// \brief Retrieve the offset of the macro definition for the given 427 /// identifier. 428 /// 429 /// The identifier must refer to a macro. 430 uint64_t getMacroOffset(const IdentifierInfo *II) { 431 assert(MacroOffsets.find(II) != MacroOffsets.end() && 432 "Identifier does not name a macro"); 433 return MacroOffsets[II]; 434 } 435 436 /// \brief Retrieve the ID number corresponding to the given macro 437 /// definition. 438 serialization::MacroID getMacroDefinitionID(MacroDefinition *MD); 439 440 /// \brief Emit a reference to a type. 441 void AddTypeRef(QualType T, RecordDataImpl &Record); 442 443 /// \brief Force a type to be emitted and get its ID. 444 serialization::TypeID GetOrCreateTypeID(QualType T); 445 446 /// \brief Determine the type ID of an already-emitted type. 447 serialization::TypeID getTypeID(QualType T) const; 448 449 /// \brief Force a type to be emitted and get its index. 450 serialization::TypeIdx GetOrCreateTypeIdx(QualType T); 451 452 /// \brief Determine the type index of an already-emitted type. 453 serialization::TypeIdx getTypeIdx(QualType T) const; 454 455 /// \brief Emits a reference to a declarator info. 456 void AddTypeSourceInfo(TypeSourceInfo *TInfo, RecordDataImpl &Record); 457 458 /// \brief Emits a type with source-location information. 459 void AddTypeLoc(TypeLoc TL, RecordDataImpl &Record); 460 461 /// \brief Emits a template argument location info. 462 void AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, 463 const TemplateArgumentLocInfo &Arg, 464 RecordDataImpl &Record); 465 466 /// \brief Emits a template argument location. 467 void AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg, 468 RecordDataImpl &Record); 469 470 /// \brief Emit a reference to a declaration. 471 void AddDeclRef(const Decl *D, RecordDataImpl &Record); 472 473 474 /// \brief Force a declaration to be emitted and get its ID. 475 serialization::DeclID GetDeclRef(const Decl *D); 476 477 /// \brief Determine the declaration ID of an already-emitted 478 /// declaration. 479 serialization::DeclID getDeclID(const Decl *D); 480 481 /// \brief Emit a declaration name. 482 void AddDeclarationName(DeclarationName Name, RecordDataImpl &Record); 483 void AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, 484 DeclarationName Name, RecordDataImpl &Record); 485 void AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo, 486 RecordDataImpl &Record); 487 488 void AddQualifierInfo(const QualifierInfo &Info, RecordDataImpl &Record); 489 490 /// \brief Emit a nested name specifier. 491 void AddNestedNameSpecifier(NestedNameSpecifier *NNS, RecordDataImpl &Record); 492 493 /// \brief Emit a nested name specifier with source-location information. 494 void AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, 495 RecordDataImpl &Record); 496 497 /// \brief Emit a template name. 498 void AddTemplateName(TemplateName Name, RecordDataImpl &Record); 499 500 /// \brief Emit a template argument. 501 void AddTemplateArgument(const TemplateArgument &Arg, RecordDataImpl &Record); 502 503 /// \brief Emit a template parameter list. 504 void AddTemplateParameterList(const TemplateParameterList *TemplateParams, 505 RecordDataImpl &Record); 506 507 /// \brief Emit a template argument list. 508 void AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs, 509 RecordDataImpl &Record); 510 511 /// \brief Emit a UnresolvedSet structure. 512 void AddUnresolvedSet(const UnresolvedSetImpl &Set, RecordDataImpl &Record); 513 514 /// \brief Emit a C++ base specifier. 515 void AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, RecordDataImpl &Record); 516 517 /// \brief Emit a CXXCtorInitializer array. 518 void AddCXXCtorInitializers( 519 const CXXCtorInitializer * const *CtorInitializers, 520 unsigned NumCtorInitializers, 521 RecordDataImpl &Record); 522 523 void AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Record); 524 525 /// \brief Add a string to the given record. 526 void AddString(llvm::StringRef Str, RecordDataImpl &Record); 527 528 /// \brief Add a version tuple to the given record 529 void AddVersionTuple(const VersionTuple &Version, RecordDataImpl &Record); 530 531 /// \brief Mark a declaration context as needing an update. 532 void AddUpdatedDeclContext(const DeclContext *DC) { 533 UpdatedDeclContexts.insert(DC); 534 } 535 536 void RewriteDecl(const Decl *D) { 537 DeclsToRewrite.insert(D); 538 // Reset the flag, so that we don't add this decl multiple times. 539 const_cast<Decl *>(D)->setChangedSinceDeserialization(false); 540 } 541 542 /// \brief Note that the identifier II occurs at the given offset 543 /// within the identifier table. 544 void SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset); 545 546 /// \brief Note that the selector Sel occurs at the given offset 547 /// within the method pool/selector table. 548 void SetSelectorOffset(Selector Sel, uint32_t Offset); 549 550 /// \brief Add the given statement or expression to the queue of 551 /// statements to emit. 552 /// 553 /// This routine should be used when emitting types and declarations 554 /// that have expressions as part of their formulation. Once the 555 /// type or declaration has been written, call FlushStmts() to write 556 /// the corresponding statements just after the type or 557 /// declaration. 558 void AddStmt(Stmt *S) { 559 CollectedStmts->push_back(S); 560 } 561 562 /// \brief Flush all of the statements and expressions that have 563 /// been added to the queue via AddStmt(). 564 void FlushStmts(); 565 566 /// \brief Flush all of the C++ base specifier sets that have been added 567 /// via \c AddCXXBaseSpecifiersRef(). 568 void FlushCXXBaseSpecifiers(); 569 570 /// \brief Record an ID for the given switch-case statement. 571 unsigned RecordSwitchCaseID(SwitchCase *S); 572 573 /// \brief Retrieve the ID for the given switch-case statement. 574 unsigned getSwitchCaseID(SwitchCase *S); 575 576 void ClearSwitchCaseIDs(); 577 578 /// \brief Retrieve the ID for the given opaque value expression. 579 unsigned getOpaqueValueID(OpaqueValueExpr *e); 580 581 unsigned getDeclParmVarAbbrev() const { return DeclParmVarAbbrev; } 582 unsigned getDeclRefExprAbbrev() const { return DeclRefExprAbbrev; } 583 unsigned getCharacterLiteralAbbrev() const { return CharacterLiteralAbbrev; } 584 unsigned getDeclRecordAbbrev() const { return DeclRecordAbbrev; } 585 unsigned getIntegerLiteralAbbrev() const { return IntegerLiteralAbbrev; } 586 unsigned getDeclTypedefAbbrev() const { return DeclTypedefAbbrev; } 587 unsigned getDeclVarAbbrev() const { return DeclVarAbbrev; } 588 unsigned getDeclFieldAbbrev() const { return DeclFieldAbbrev; } 589 unsigned getDeclEnumAbbrev() const { return DeclEnumAbbrev; } 590 unsigned getDeclObjCIvarAbbrev() const { return DeclObjCIvarAbbrev; } 591 592 bool hasChain() const { return Chain; } 593 594 // ASTDeserializationListener implementation 595 void ReaderInitialized(ASTReader *Reader); 596 void IdentifierRead(serialization::IdentID ID, IdentifierInfo *II); 597 void TypeRead(serialization::TypeIdx Idx, QualType T); 598 void DeclRead(serialization::DeclID ID, const Decl *D); 599 void SelectorRead(serialization::SelectorID ID, Selector Sel); 600 void MacroDefinitionRead(serialization::MacroID ID, MacroDefinition *MD); 601 602 // ASTMutationListener implementation. 603 virtual void CompletedTagDefinition(const TagDecl *D); 604 virtual void AddedVisibleDecl(const DeclContext *DC, const Decl *D); 605 virtual void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D); 606 virtual void AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD, 607 const ClassTemplateSpecializationDecl *D); 608 virtual void AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, 609 const FunctionDecl *D); 610 virtual void CompletedImplicitDefinition(const FunctionDecl *D); 611 virtual void StaticDataMemberInstantiated(const VarDecl *D); 612 }; 613 614 /// \brief AST and semantic-analysis consumer that generates a 615 /// precompiled header from the parsed source code. 616 class PCHGenerator : public SemaConsumer { 617 const Preprocessor &PP; 618 std::string OutputFile; 619 const char *isysroot; 620 llvm::raw_ostream *Out; 621 Sema *SemaPtr; 622 MemorizeStatCalls *StatCalls; // owned by the FileManager 623 std::vector<unsigned char> Buffer; 624 llvm::BitstreamWriter Stream; 625 ASTWriter Writer; 626 bool Chaining; 627 628 protected: 629 ASTWriter &getWriter() { return Writer; } 630 const ASTWriter &getWriter() const { return Writer; } 631 632 public: 633 PCHGenerator(const Preprocessor &PP, const std::string &OutputFile, bool Chaining, 634 const char *isysroot, llvm::raw_ostream *Out); 635 virtual void InitializeSema(Sema &S) { SemaPtr = &S; } 636 virtual void HandleTranslationUnit(ASTContext &Ctx); 637 virtual ASTMutationListener *GetASTMutationListener(); 638 virtual ASTSerializationListener *GetASTSerializationListener(); 639 virtual ASTDeserializationListener *GetASTDeserializationListener(); 640 }; 641 642 } // end namespace clang 643 644 #endif 645