1 //===--- ASTWriter.h - AST File Writer --------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the ASTWriter class, which writes an AST file
11 // containing a serialized representation of a translation unit.
13 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_FRONTEND_AST_WRITER_H
15 #define LLVM_CLANG_FRONTEND_AST_WRITER_H
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"
35 class BitstreamWriter;
41 class NestedNameSpecifier;
42 class CXXBaseSpecifier;
43 class CXXCtorInitializer;
46 class MacroDefinition;
47 class MemorizeStatCalls;
48 class OpaqueValueExpr;
51 class PreprocessedEntity;
52 class PreprocessingRecord;
60 /// \brief Writes an AST file containing the contents of a translation unit.
62 /// The ASTWriter class produces a bitstream containing the serialized
63 /// representation of a given abstract syntax tree and its supporting
64 /// data structures. This bitstream can be de-serialized via an
65 /// instance of the ASTReader class.
66 class ASTWriter : public ASTDeserializationListener,
67 public ASTMutationListener {
69 typedef SmallVector<uint64_t, 64> RecordData;
70 typedef SmallVectorImpl<uint64_t> RecordDataImpl;
72 friend class ASTDeclWriter;
74 /// \brief Map that provides the ID numbers of each type within the
75 /// output stream, plus those deserialized from a chained PCH.
77 /// The ID numbers of types are consecutive (in order of discovery)
78 /// and start at 1. 0 is reserved for NULL. When types are actually
79 /// stored in the stream, the ID number is shifted by 2 bits to
80 /// allow for the const/volatile qualifiers.
82 /// Keys in the map never have const/volatile qualifiers.
83 typedef llvm::DenseMap<QualType, serialization::TypeIdx,
84 serialization::UnsafeQualTypeDenseMapInfo>
87 /// \brief The bitstream writer used to emit this precompiled header.
88 llvm::BitstreamWriter &Stream;
90 /// \brief The ASTContext we're writing.
93 /// \brief The reader of existing AST files, if we're chaining.
96 /// \brief Indicates when the AST writing is actively performing
97 /// serialization, rather than just queueing updates.
100 /// \brief Stores a declaration or a type to be written to the AST file.
103 DeclOrType(Decl *D) : Stored(D), IsType(false) { }
104 DeclOrType(QualType T) : Stored(T.getAsOpaquePtr()), IsType(true) { }
106 bool isType() const { return IsType; }
107 bool isDecl() const { return !IsType; }
109 QualType getType() const {
110 assert(isType() && "Not a type!");
111 return QualType::getFromOpaquePtr(Stored);
114 Decl *getDecl() const {
115 assert(isDecl() && "Not a decl!");
116 return static_cast<Decl *>(Stored);
124 /// \brief The declarations and types to emit.
125 std::queue<DeclOrType> DeclTypesToEmit;
127 /// \brief The first ID number we can use for our own declarations.
128 serialization::DeclID FirstDeclID;
130 /// \brief The decl ID that will be assigned to the next new decl.
131 serialization::DeclID NextDeclID;
133 /// \brief Map that provides the ID numbers of each declaration within
134 /// the output stream, as well as those deserialized from a chained PCH.
136 /// The ID numbers of declarations are consecutive (in order of
137 /// discovery) and start at 2. 1 is reserved for the translation
138 /// unit, while 0 is reserved for NULL.
139 llvm::DenseMap<const Decl *, serialization::DeclID> DeclIDs;
141 /// \brief Offset of each declaration in the bitstream, indexed by
142 /// the declaration's ID.
143 std::vector<uint32_t> DeclOffsets;
145 /// \brief The first ID number we can use for our own types.
146 serialization::TypeID FirstTypeID;
148 /// \brief The type ID that will be assigned to the next new type.
149 serialization::TypeID NextTypeID;
151 /// \brief Map that provides the ID numbers of each type within the
152 /// output stream, plus those deserialized from a chained PCH.
154 /// The ID numbers of types are consecutive (in order of discovery)
155 /// and start at 1. 0 is reserved for NULL. When types are actually
156 /// stored in the stream, the ID number is shifted by 2 bits to
157 /// allow for the const/volatile qualifiers.
159 /// Keys in the map never have const/volatile qualifiers.
162 /// \brief Offset of each type in the bitstream, indexed by
164 std::vector<uint32_t> TypeOffsets;
166 /// \brief The first ID number we can use for our own identifiers.
167 serialization::IdentID FirstIdentID;
169 /// \brief The identifier ID that will be assigned to the next new identifier.
170 serialization::IdentID NextIdentID;
172 /// \brief Map that provides the ID numbers of each identifier in
173 /// the output stream.
175 /// The ID numbers for identifiers are consecutive (in order of
176 /// discovery), starting at 1. An ID of zero refers to a NULL
178 llvm::DenseMap<const IdentifierInfo *, serialization::IdentID> IdentifierIDs;
180 /// \brief Offsets of each of the identifier IDs into the identifier
182 std::vector<uint32_t> IdentifierOffsets;
184 /// \brief The first ID number we can use for our own selectors.
185 serialization::SelectorID FirstSelectorID;
187 /// \brief The selector ID that will be assigned to the next new identifier.
188 serialization::SelectorID NextSelectorID;
190 /// \brief Map that provides the ID numbers of each Selector.
191 llvm::DenseMap<Selector, serialization::SelectorID> SelectorIDs;
193 /// \brief Offset of each selector within the method pool/selector
194 /// table, indexed by the Selector ID (-1).
195 std::vector<uint32_t> SelectorOffsets;
197 /// \brief Offsets of each of the macro identifiers into the
200 /// For each identifier that is associated with a macro, this map
201 /// provides the offset into the bitstream where that macro is
203 llvm::DenseMap<const IdentifierInfo *, uint64_t> MacroOffsets;
205 /// \brief The set of identifiers that had macro definitions at some point.
206 std::vector<const IdentifierInfo *> DeserializedMacroNames;
208 /// \brief Mapping from macro definitions (as they occur in the preprocessing
209 /// record) to the macro IDs.
210 llvm::DenseMap<const MacroDefinition *, serialization::PreprocessedEntityID>
213 typedef SmallVector<uint64_t, 2> UpdateRecord;
214 typedef llvm::DenseMap<const Decl *, UpdateRecord> DeclUpdateMap;
215 /// \brief Mapping from declarations that came from a chained PCH to the
216 /// record containing modifications to them.
217 DeclUpdateMap DeclUpdates;
219 typedef llvm::DenseMap<Decl *, Decl *> FirstLatestDeclMap;
220 /// \brief Map of first declarations from a chained PCH that point to the
221 /// most recent declarations in another PCH.
222 FirstLatestDeclMap FirstLatestDecls;
224 /// \brief Declarations encountered that might be external
227 /// We keep track of external definitions (as well as tentative
228 /// definitions) as we are emitting declarations to the AST
229 /// file. The AST file contains a separate record for these external
230 /// definitions, which are provided to the AST consumer by the AST
231 /// reader. This is behavior is required to properly cope with,
232 /// e.g., tentative variable definitions that occur within
233 /// headers. The declarations themselves are stored as declaration
234 /// IDs, since they will be written out to an EXTERNAL_DEFINITIONS
236 SmallVector<uint64_t, 16> ExternalDefinitions;
238 /// \brief DeclContexts that have received extensions since their serialized
241 /// For namespaces, when we're chaining and encountering a namespace, we check if
242 /// its primary namespace comes from the chain. If it does, we add the primary
243 /// to this set, so that we can write out lexical content updates for it.
244 llvm::SmallPtrSet<const DeclContext *, 16> UpdatedDeclContexts;
246 typedef llvm::SmallPtrSet<const Decl *, 16> DeclsToRewriteTy;
247 /// \brief Decls that will be replaced in the current dependent AST file.
248 DeclsToRewriteTy DeclsToRewrite;
250 struct ChainedObjCCategoriesData {
251 /// \brief The interface in the imported module.
252 const ObjCInterfaceDecl *Interface;
253 /// \brief The local tail category ID that got chained to the imported
255 const ObjCCategoryDecl *TailCategory;
257 /// \brief ID corresponding to \c Interface.
258 serialization::DeclID InterfaceID;
260 /// \brief ID corresponding to TailCategoryID.
261 serialization::DeclID TailCategoryID;
263 /// \brief ObjC categories that got chained to an interface imported from
265 SmallVector<ChainedObjCCategoriesData, 16> LocalChainedObjCCategories;
267 /// \brief Decls that have been replaced in the current dependent AST file.
269 /// When a decl changes fundamentally after being deserialized (this shouldn't
270 /// happen, but the ObjC AST nodes are designed this way), it will be
271 /// serialized again. In this case, it is registered here, so that the reader
272 /// knows to read the updated version.
273 SmallVector<std::pair<serialization::DeclID, uint64_t>, 16>
276 /// \brief Statements that we've encountered while serializing a
277 /// declaration or type.
278 SmallVector<Stmt *, 16> StmtsToEmit;
280 /// \brief Statements collection to use for ASTWriter::AddStmt().
281 /// It will point to StmtsToEmit unless it is overriden.
282 SmallVector<Stmt *, 16> *CollectedStmts;
284 /// \brief Mapping from SwitchCase statements to IDs.
285 std::map<SwitchCase *, unsigned> SwitchCaseIDs;
287 /// \brief Mapping from OpaqueValueExpr expressions to IDs.
288 llvm::DenseMap<OpaqueValueExpr *, unsigned> OpaqueValues;
290 /// \brief The number of statements written to the AST file.
291 unsigned NumStatements;
293 /// \brief The number of macros written to the AST file.
296 /// \brief The number of lexical declcontexts written to the AST
298 unsigned NumLexicalDeclContexts;
300 /// \brief The number of visible declcontexts written to the AST
302 unsigned NumVisibleDeclContexts;
304 /// \brief The offset of each CXXBaseSpecifier set within the AST.
305 SmallVector<uint32_t, 4> CXXBaseSpecifiersOffsets;
307 /// \brief The first ID number we can use for our own base specifiers.
308 serialization::CXXBaseSpecifiersID FirstCXXBaseSpecifiersID;
310 /// \brief The base specifiers ID that will be assigned to the next new
311 /// set of C++ base specifiers.
312 serialization::CXXBaseSpecifiersID NextCXXBaseSpecifiersID;
314 /// \brief A set of C++ base specifiers that is queued to be written into the
316 struct QueuedCXXBaseSpecifiers {
317 QueuedCXXBaseSpecifiers() : ID(), Bases(), BasesEnd() { }
319 QueuedCXXBaseSpecifiers(serialization::CXXBaseSpecifiersID ID,
320 CXXBaseSpecifier const *Bases,
321 CXXBaseSpecifier const *BasesEnd)
322 : ID(ID), Bases(Bases), BasesEnd(BasesEnd) { }
324 serialization::CXXBaseSpecifiersID ID;
325 CXXBaseSpecifier const * Bases;
326 CXXBaseSpecifier const * BasesEnd;
329 /// \brief Queue of C++ base specifiers to be written to the AST file,
330 /// in the order they should be written.
331 SmallVector<QueuedCXXBaseSpecifiers, 2> CXXBaseSpecifiersToWrite;
333 /// \brief Write the given subexpression to the bitstream.
334 void WriteSubStmt(Stmt *S);
336 void WriteBlockInfoBlock();
337 void WriteMetadata(ASTContext &Context, StringRef isysroot,
338 const std::string &OutputFile);
339 void WriteLanguageOptions(const LangOptions &LangOpts);
340 void WriteStatCache(MemorizeStatCalls &StatCalls);
341 void WriteSourceManagerBlock(SourceManager &SourceMgr,
342 const Preprocessor &PP,
344 void WritePreprocessor(const Preprocessor &PP, bool IsModule);
345 void WriteHeaderSearch(HeaderSearch &HS, StringRef isysroot);
346 void WritePreprocessorDetail(PreprocessingRecord &PPRec);
347 void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag);
348 void WriteCXXBaseSpecifiersOffsets();
349 void WriteType(QualType T);
350 uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC);
351 uint64_t WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC);
352 void WriteTypeDeclOffsets();
353 void WriteSelectors(Sema &SemaRef);
354 void WriteReferencedSelectorsPool(Sema &SemaRef);
355 void WriteIdentifierTable(Preprocessor &PP, bool IsModule);
356 void WriteAttributes(const AttrVec &Attrs, RecordDataImpl &Record);
357 void ResolveDeclUpdatesBlocks();
358 void WriteDeclUpdatesBlocks();
359 void WriteDeclReplacementsBlock();
360 void ResolveChainedObjCCategories();
361 void WriteChainedObjCCategories();
362 void WriteDeclContextVisibleUpdate(const DeclContext *DC);
363 void WriteFPPragmaOptions(const FPOptions &Opts);
364 void WriteOpenCLExtensions(Sema &SemaRef);
366 unsigned DeclParmVarAbbrev;
367 unsigned DeclContextLexicalAbbrev;
368 unsigned DeclContextVisibleLookupAbbrev;
369 unsigned UpdateVisibleAbbrev;
370 unsigned DeclRefExprAbbrev;
371 unsigned CharacterLiteralAbbrev;
372 unsigned DeclRecordAbbrev;
373 unsigned IntegerLiteralAbbrev;
374 unsigned DeclTypedefAbbrev;
375 unsigned DeclVarAbbrev;
376 unsigned DeclFieldAbbrev;
377 unsigned DeclEnumAbbrev;
378 unsigned DeclObjCIvarAbbrev;
380 void WriteDeclsBlockAbbrevs();
381 void WriteDecl(ASTContext &Context, Decl *D);
383 void WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
384 StringRef isysroot, const std::string &OutputFile,
388 /// \brief Create a new precompiled header writer that outputs to
389 /// the given bitstream.
390 ASTWriter(llvm::BitstreamWriter &Stream);
392 /// \brief Write a precompiled header for the given semantic analysis.
394 /// \param SemaRef a reference to the semantic analysis object that processed
395 /// the AST to be written into the precompiled header.
397 /// \param StatCalls the object that cached all of the stat() calls made while
398 /// searching for source files and headers.
400 /// \param IsModule Whether we're writing a module (otherwise, we're writing a
401 /// precompiled header).
403 /// \param isysroot if non-empty, write a relocatable file whose headers
404 /// are relative to the given system root.
405 void WriteAST(Sema &SemaRef, MemorizeStatCalls *StatCalls,
406 const std::string &OutputFile,
407 bool IsModule, StringRef isysroot);
409 /// \brief Emit a source location.
410 void AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record);
412 /// \brief Emit a source range.
413 void AddSourceRange(SourceRange Range, RecordDataImpl &Record);
415 /// \brief Emit an integral value.
416 void AddAPInt(const llvm::APInt &Value, RecordDataImpl &Record);
418 /// \brief Emit a signed integral value.
419 void AddAPSInt(const llvm::APSInt &Value, RecordDataImpl &Record);
421 /// \brief Emit a floating-point value.
422 void AddAPFloat(const llvm::APFloat &Value, RecordDataImpl &Record);
424 /// \brief Emit a reference to an identifier.
425 void AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record);
427 /// \brief Emit a Selector (which is a smart pointer reference).
428 void AddSelectorRef(Selector, RecordDataImpl &Record);
430 /// \brief Emit a CXXTemporary.
431 void AddCXXTemporary(const CXXTemporary *Temp, RecordDataImpl &Record);
433 /// \brief Emit a set of C++ base specifiers to the record.
434 void AddCXXBaseSpecifiersRef(CXXBaseSpecifier const *Bases,
435 CXXBaseSpecifier const *BasesEnd,
436 RecordDataImpl &Record);
438 /// \brief Get the unique number used to refer to the given selector.
439 serialization::SelectorID getSelectorRef(Selector Sel);
441 /// \brief Get the unique number used to refer to the given identifier.
442 serialization::IdentID getIdentifierRef(const IdentifierInfo *II);
444 /// \brief Retrieve the offset of the macro definition for the given
447 /// The identifier must refer to a macro.
448 uint64_t getMacroOffset(const IdentifierInfo *II) {
449 assert(MacroOffsets.find(II) != MacroOffsets.end() &&
450 "Identifier does not name a macro");
451 return MacroOffsets[II];
454 /// \brief Emit a reference to a type.
455 void AddTypeRef(QualType T, RecordDataImpl &Record);
457 /// \brief Force a type to be emitted and get its ID.
458 serialization::TypeID GetOrCreateTypeID(QualType T);
460 /// \brief Determine the type ID of an already-emitted type.
461 serialization::TypeID getTypeID(QualType T) const;
463 /// \brief Force a type to be emitted and get its index.
464 serialization::TypeIdx GetOrCreateTypeIdx( QualType T);
466 /// \brief Determine the type index of an already-emitted type.
467 serialization::TypeIdx getTypeIdx(QualType T) const;
469 /// \brief Emits a reference to a declarator info.
470 void AddTypeSourceInfo(TypeSourceInfo *TInfo, RecordDataImpl &Record);
472 /// \brief Emits a type with source-location information.
473 void AddTypeLoc(TypeLoc TL, RecordDataImpl &Record);
475 /// \brief Emits a template argument location info.
476 void AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind,
477 const TemplateArgumentLocInfo &Arg,
478 RecordDataImpl &Record);
480 /// \brief Emits a template argument location.
481 void AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg,
482 RecordDataImpl &Record);
484 /// \brief Emit a reference to a declaration.
485 void AddDeclRef(const Decl *D, RecordDataImpl &Record);
488 /// \brief Force a declaration to be emitted and get its ID.
489 serialization::DeclID GetDeclRef(const Decl *D);
491 /// \brief Determine the declaration ID of an already-emitted
493 serialization::DeclID getDeclID(const Decl *D);
495 /// \brief Emit a declaration name.
496 void AddDeclarationName(DeclarationName Name, RecordDataImpl &Record);
497 void AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc,
498 DeclarationName Name, RecordDataImpl &Record);
499 void AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
500 RecordDataImpl &Record);
502 void AddQualifierInfo(const QualifierInfo &Info, RecordDataImpl &Record);
504 /// \brief Emit a nested name specifier.
505 void AddNestedNameSpecifier(NestedNameSpecifier *NNS, RecordDataImpl &Record);
507 /// \brief Emit a nested name specifier with source-location information.
508 void AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
509 RecordDataImpl &Record);
511 /// \brief Emit a template name.
512 void AddTemplateName(TemplateName Name, RecordDataImpl &Record);
514 /// \brief Emit a template argument.
515 void AddTemplateArgument(const TemplateArgument &Arg, RecordDataImpl &Record);
517 /// \brief Emit a template parameter list.
518 void AddTemplateParameterList(const TemplateParameterList *TemplateParams,
519 RecordDataImpl &Record);
521 /// \brief Emit a template argument list.
522 void AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs,
523 RecordDataImpl &Record);
525 /// \brief Emit a UnresolvedSet structure.
526 void AddUnresolvedSet(const UnresolvedSetImpl &Set, RecordDataImpl &Record);
528 /// \brief Emit a C++ base specifier.
529 void AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, RecordDataImpl &Record);
531 /// \brief Emit a CXXCtorInitializer array.
532 void AddCXXCtorInitializers(
533 const CXXCtorInitializer * const *CtorInitializers,
534 unsigned NumCtorInitializers,
535 RecordDataImpl &Record);
537 void AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Record);
539 /// \brief Add a string to the given record.
540 void AddString(StringRef Str, RecordDataImpl &Record);
542 /// \brief Add a version tuple to the given record
543 void AddVersionTuple(const VersionTuple &Version, RecordDataImpl &Record);
545 /// \brief Mark a declaration context as needing an update.
546 void AddUpdatedDeclContext(const DeclContext *DC) {
547 UpdatedDeclContexts.insert(DC);
550 void RewriteDecl(const Decl *D) {
551 DeclsToRewrite.insert(D);
552 // Reset the flag, so that we don't add this decl multiple times.
553 const_cast<Decl *>(D)->setChangedSinceDeserialization(false);
556 /// \brief Note that the identifier II occurs at the given offset
557 /// within the identifier table.
558 void SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset);
560 /// \brief Note that the selector Sel occurs at the given offset
561 /// within the method pool/selector table.
562 void SetSelectorOffset(Selector Sel, uint32_t Offset);
564 /// \brief Add the given statement or expression to the queue of
565 /// statements to emit.
567 /// This routine should be used when emitting types and declarations
568 /// that have expressions as part of their formulation. Once the
569 /// type or declaration has been written, call FlushStmts() to write
570 /// the corresponding statements just after the type or
572 void AddStmt(Stmt *S) {
573 CollectedStmts->push_back(S);
576 /// \brief Flush all of the statements and expressions that have
577 /// been added to the queue via AddStmt().
580 /// \brief Flush all of the C++ base specifier sets that have been added
581 /// via \c AddCXXBaseSpecifiersRef().
582 void FlushCXXBaseSpecifiers();
584 /// \brief Record an ID for the given switch-case statement.
585 unsigned RecordSwitchCaseID(SwitchCase *S);
587 /// \brief Retrieve the ID for the given switch-case statement.
588 unsigned getSwitchCaseID(SwitchCase *S);
590 void ClearSwitchCaseIDs();
592 /// \brief Retrieve the ID for the given opaque value expression.
593 unsigned getOpaqueValueID(OpaqueValueExpr *e);
595 unsigned getDeclParmVarAbbrev() const { return DeclParmVarAbbrev; }
596 unsigned getDeclRefExprAbbrev() const { return DeclRefExprAbbrev; }
597 unsigned getCharacterLiteralAbbrev() const { return CharacterLiteralAbbrev; }
598 unsigned getDeclRecordAbbrev() const { return DeclRecordAbbrev; }
599 unsigned getIntegerLiteralAbbrev() const { return IntegerLiteralAbbrev; }
600 unsigned getDeclTypedefAbbrev() const { return DeclTypedefAbbrev; }
601 unsigned getDeclVarAbbrev() const { return DeclVarAbbrev; }
602 unsigned getDeclFieldAbbrev() const { return DeclFieldAbbrev; }
603 unsigned getDeclEnumAbbrev() const { return DeclEnumAbbrev; }
604 unsigned getDeclObjCIvarAbbrev() const { return DeclObjCIvarAbbrev; }
606 bool hasChain() const { return Chain; }
608 // ASTDeserializationListener implementation
609 void ReaderInitialized(ASTReader *Reader);
610 void IdentifierRead(serialization::IdentID ID, IdentifierInfo *II);
611 void TypeRead(serialization::TypeIdx Idx, QualType T);
612 void DeclRead(serialization::DeclID ID, const Decl *D);
613 void SelectorRead(serialization::SelectorID ID, Selector Sel);
614 void MacroDefinitionRead(serialization::PreprocessedEntityID ID,
615 MacroDefinition *MD);
617 // ASTMutationListener implementation.
618 virtual void CompletedTagDefinition(const TagDecl *D);
619 virtual void AddedVisibleDecl(const DeclContext *DC, const Decl *D);
620 virtual void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D);
621 virtual void AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD,
622 const ClassTemplateSpecializationDecl *D);
623 virtual void AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD,
624 const FunctionDecl *D);
625 virtual void CompletedImplicitDefinition(const FunctionDecl *D);
626 virtual void StaticDataMemberInstantiated(const VarDecl *D);
627 virtual void AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD,
628 const ObjCInterfaceDecl *IFD);
631 /// \brief AST and semantic-analysis consumer that generates a
632 /// precompiled header from the parsed source code.
633 class PCHGenerator : public SemaConsumer {
634 const Preprocessor &PP;
635 std::string OutputFile;
637 std::string isysroot;
640 MemorizeStatCalls *StatCalls; // owned by the FileManager
641 std::vector<unsigned char> Buffer;
642 llvm::BitstreamWriter Stream;
646 ASTWriter &getWriter() { return Writer; }
647 const ASTWriter &getWriter() const { return Writer; }
650 PCHGenerator(const Preprocessor &PP, StringRef OutputFile,
652 StringRef isysroot, raw_ostream *Out);
654 virtual void InitializeSema(Sema &S) { SemaPtr = &S; }
655 virtual void HandleTranslationUnit(ASTContext &Ctx);
656 virtual ASTMutationListener *GetASTMutationListener();
657 virtual ASTDeserializationListener *GetASTDeserializationListener();
660 } // end namespace clang