clang 18.0.0git
|
Writes an AST file containing the contents of a translation unit. More...
#include "clang/Serialization/ASTWriter.h"
Public Types | |
using | RecordData = SmallVector< uint64_t, 64 > |
using | RecordDataImpl = SmallVectorImpl< uint64_t > |
using | RecordDataRef = ArrayRef< uint64_t > |
Public Member Functions | |
ASTWriter (llvm::BitstreamWriter &Stream, SmallVectorImpl< char > &Buffer, InMemoryModuleCache &ModuleCache, ArrayRef< std::shared_ptr< ModuleFileExtension > > Extensions, bool IncludeTimestamps=true, bool BuildingImplicitModule=false) | |
Create a new precompiled header writer that outputs to the given bitstream. | |
~ASTWriter () override | |
ASTContext & | getASTContext () const |
const LangOptions & | getLangOpts () const |
time_t | getTimestampForOutput (const FileEntry *E) const |
Get a timestamp for output into the AST file. | |
ASTFileSignature | WriteAST (Sema &SemaRef, StringRef OutputFile, Module *WritingModule, StringRef isysroot, bool hasErrors=false, bool ShouldCacheASTInMemory=false) |
Write a precompiled header for the given semantic analysis. | |
void | AddToken (const Token &Tok, RecordDataImpl &Record) |
Emit a token. | |
void | AddAlignPackInfo (const Sema::AlignPackInfo &Info, RecordDataImpl &Record) |
Emit a AlignPackInfo. | |
void | AddFileID (FileID FID, RecordDataImpl &Record) |
Emit a FileID. | |
void | AddSourceLocation (SourceLocation Loc, RecordDataImpl &Record, LocSeq *Seq=nullptr) |
Emit a source location. | |
void | AddSourceRange (SourceRange Range, RecordDataImpl &Record, LocSeq *Seq=nullptr) |
Emit a source range. | |
void | AddIdentifierRef (const IdentifierInfo *II, RecordDataImpl &Record) |
Emit a reference to an identifier. | |
serialization::SelectorID | getSelectorRef (Selector Sel) |
Get the unique number used to refer to the given selector. | |
serialization::IdentID | getIdentifierRef (const IdentifierInfo *II) |
Get the unique number used to refer to the given identifier. | |
serialization::MacroID | getMacroRef (MacroInfo *MI, const IdentifierInfo *Name) |
Get the unique number used to refer to the given macro. | |
serialization::MacroID | getMacroID (MacroInfo *MI) |
Determine the ID of an already-emitted macro. | |
uint32_t | getMacroDirectivesOffset (const IdentifierInfo *Name) |
void | AddTypeRef (QualType T, RecordDataImpl &Record) |
Emit a reference to a type. | |
serialization::TypeID | GetOrCreateTypeID (QualType T) |
Force a type to be emitted and get its ID. | |
serialization::TypeID | getTypeID (QualType T) const |
Determine the type ID of an already-emitted type. | |
const Decl * | getFirstLocalDecl (const Decl *D) |
Find the first local declaration of a given local redeclarable decl. | |
bool | IsLocalDecl (const Decl *D) |
Is this a local declaration (that is, one that will be written to our AST file)? This is the case for declarations that are neither imported from another AST file nor predefined. | |
void | AddDeclRef (const Decl *D, RecordDataImpl &Record) |
Emit a reference to a declaration. | |
serialization::DeclID | GetDeclRef (const Decl *D) |
Force a declaration to be emitted and get its ID. | |
serialization::DeclID | getDeclID (const Decl *D) |
Determine the declaration ID of an already-emitted declaration. | |
unsigned | getAnonymousDeclarationNumber (const NamedDecl *D) |
void | AddString (StringRef Str, RecordDataImpl &Record) |
Add a string to the given record. | |
bool | PreparePathForOutput (SmallVectorImpl< char > &Path) |
Convert a path from this build process into one that is appropriate for emission in the module file. | |
void | AddPath (StringRef Path, RecordDataImpl &Record) |
Add a path to the given record. | |
void | EmitRecordWithPath (unsigned Abbrev, RecordDataRef Record, StringRef Path) |
Emit the current record with the given path as a blob. | |
void | AddVersionTuple (const VersionTuple &Version, RecordDataImpl &Record) |
Add a version tuple to the given record. | |
unsigned | getLocalOrImportedSubmoduleID (const Module *Mod) |
Retrieve or create a submodule ID for this module, or return 0 if the submodule is neither local (a submodle of the currently-written module) nor from an imported module. | |
void | SetIdentifierOffset (const IdentifierInfo *II, uint32_t Offset) |
Note that the identifier II occurs at the given offset within the identifier table. | |
void | SetSelectorOffset (Selector Sel, uint32_t Offset) |
Note that the selector Sel occurs at the given offset within the method pool/selector table. | |
unsigned | RecordSwitchCaseID (SwitchCase *S) |
Record an ID for the given switch-case statement. | |
unsigned | getSwitchCaseID (SwitchCase *S) |
Retrieve the ID for the given switch-case statement. | |
void | ClearSwitchCaseIDs () |
unsigned | getTypeExtQualAbbrev () const |
unsigned | getDeclParmVarAbbrev () const |
unsigned | getDeclRecordAbbrev () const |
unsigned | getDeclTypedefAbbrev () const |
unsigned | getDeclVarAbbrev () const |
unsigned | getDeclFieldAbbrev () const |
unsigned | getDeclEnumAbbrev () const |
unsigned | getDeclObjCIvarAbbrev () const |
unsigned | getDeclCXXMethodAbbrev () const |
unsigned | getDeclRefExprAbbrev () const |
unsigned | getCharacterLiteralAbbrev () const |
unsigned | getIntegerLiteralAbbrev () const |
unsigned | getExprImplicitCastAbbrev () const |
bool | hasChain () const |
ASTReader * | getChain () const |
bool | isWritingStdCXXNamedModules () const |
![]() | |
virtual | ~ASTDeserializationListener () |
virtual void | ReaderInitialized (ASTReader *Reader) |
The ASTReader was initialized. | |
virtual void | IdentifierRead (serialization::IdentID ID, IdentifierInfo *II) |
An identifier was deserialized from the AST file. | |
virtual void | MacroRead (serialization::MacroID ID, MacroInfo *MI) |
A macro was read from the AST file. | |
virtual void | TypeRead (serialization::TypeIdx Idx, QualType T) |
A type was deserialized from the AST file. | |
virtual void | DeclRead (serialization::DeclID ID, const Decl *D) |
A decl was deserialized from the AST file. | |
virtual void | SelectorRead (serialization::SelectorID iD, Selector Sel) |
A selector was read from the AST file. | |
virtual void | MacroDefinitionRead (serialization::PreprocessedEntityID, MacroDefinitionRecord *MD) |
A macro definition was read from the AST file. | |
virtual void | ModuleRead (serialization::SubmoduleID ID, Module *Mod) |
A module definition was read from the AST file. | |
virtual void | ModuleImportRead (serialization::SubmoduleID ID, SourceLocation ImportLoc) |
A module import was read from the AST file. | |
![]() | |
virtual | ~ASTMutationListener () |
virtual void | CompletedTagDefinition (const TagDecl *D) |
A new TagDecl definition was completed. | |
virtual void | AddedVisibleDecl (const DeclContext *DC, const Decl *D) |
A new declaration with name has been added to a DeclContext. | |
virtual void | AddedCXXImplicitMember (const CXXRecordDecl *RD, const Decl *D) |
An implicit member was added after the definition was completed. | |
virtual void | AddedCXXTemplateSpecialization (const ClassTemplateDecl *TD, const ClassTemplateSpecializationDecl *D) |
A template specialization (or partial one) was added to the template declaration. | |
virtual void | AddedCXXTemplateSpecialization (const VarTemplateDecl *TD, const VarTemplateSpecializationDecl *D) |
A template specialization (or partial one) was added to the template declaration. | |
virtual void | AddedCXXTemplateSpecialization (const FunctionTemplateDecl *TD, const FunctionDecl *D) |
A template specialization (or partial one) was added to the template declaration. | |
virtual void | ResolvedExceptionSpec (const FunctionDecl *FD) |
A function's exception specification has been evaluated or instantiated. | |
virtual void | DeducedReturnType (const FunctionDecl *FD, QualType ReturnType) |
A function's return type has been deduced. | |
virtual void | ResolvedOperatorDelete (const CXXDestructorDecl *DD, const FunctionDecl *Delete, Expr *ThisArg) |
A virtual destructor's operator delete has been resolved. | |
virtual void | CompletedImplicitDefinition (const FunctionDecl *D) |
An implicit member got a definition. | |
virtual void | InstantiationRequested (const ValueDecl *D) |
The instantiation of a templated function or variable was requested. | |
virtual void | VariableDefinitionInstantiated (const VarDecl *D) |
A templated variable's definition was implicitly instantiated. | |
virtual void | FunctionDefinitionInstantiated (const FunctionDecl *D) |
A function template's definition was instantiated. | |
virtual void | DefaultArgumentInstantiated (const ParmVarDecl *D) |
A default argument was instantiated. | |
virtual void | DefaultMemberInitializerInstantiated (const FieldDecl *D) |
A default member initializer was instantiated. | |
virtual void | AddedObjCCategoryToInterface (const ObjCCategoryDecl *CatD, const ObjCInterfaceDecl *IFD) |
A new objc category class was added for an interface. | |
virtual void | DeclarationMarkedUsed (const Decl *D) |
A declaration is marked used which was not previously marked used. | |
virtual void | DeclarationMarkedOpenMPThreadPrivate (const Decl *D) |
A declaration is marked as OpenMP threadprivate which was not previously marked as threadprivate. | |
virtual void | DeclarationMarkedOpenMPDeclareTarget (const Decl *D, const Attr *Attr) |
A declaration is marked as OpenMP declaretarget which was not previously marked as declaretarget. | |
virtual void | DeclarationMarkedOpenMPAllocate (const Decl *D, const Attr *A) |
A declaration is marked as a variable with OpenMP allocator. | |
virtual void | RedefinedHiddenDefinition (const NamedDecl *D, Module *M) |
A definition has been made visible by being redefined locally. | |
virtual void | AddedAttributeToRecord (const Attr *Attr, const RecordDecl *Record) |
An attribute was added to a RecordDecl. | |
Friends | |
class | ASTDeclWriter |
class | ASTRecordWriter |
Writes an AST file containing the contents of a translation unit.
The ASTWriter class produces a bitstream containing the serialized representation of a given abstract syntax tree and its supporting data structures. This bitstream can be de-serialized via an instance of the ASTReader class.
Definition at line 85 of file ASTWriter.h.
using clang::ASTWriter::RecordData = SmallVector<uint64_t, 64> |
Definition at line 91 of file ASTWriter.h.
using clang::ASTWriter::RecordDataImpl = SmallVectorImpl<uint64_t> |
Definition at line 92 of file ASTWriter.h.
using clang::ASTWriter::RecordDataRef = ArrayRef<uint64_t> |
Definition at line 93 of file ASTWriter.h.
ASTWriter::ASTWriter | ( | llvm::BitstreamWriter & | Stream, |
SmallVectorImpl< char > & | Buffer, | ||
InMemoryModuleCache & | ModuleCache, | ||
ArrayRef< std::shared_ptr< ModuleFileExtension > > | Extensions, | ||
bool | IncludeTimestamps = true , |
||
bool | BuildingImplicitModule = false |
||
) |
Create a new precompiled header writer that outputs to the given bitstream.
Definition at line 4598 of file ASTWriter.cpp.
|
overridedefault |
void ASTWriter::AddAlignPackInfo | ( | const Sema::AlignPackInfo & | Info, |
RecordDataImpl & | Record | ||
) |
Emit a AlignPackInfo.
Definition at line 5431 of file ASTWriter.cpp.
References clang::Sema::AlignPackInfo::getRawEncoding().
void ASTWriter::AddDeclRef | ( | const Decl * | D, |
RecordDataImpl & | Record | ||
) |
Emit a reference to a declaration.
Definition at line 5686 of file ASTWriter.cpp.
References GetDeclRef().
Referenced by clang::ASTRecordWriter::AddDeclRef(), and AddLazyVectorDecls().
void ASTWriter::AddFileID | ( | FileID | FID, |
RecordDataImpl & | Record | ||
) |
Emit a FileID.
Definition at line 5499 of file ASTWriter.cpp.
void ASTWriter::AddIdentifierRef | ( | const IdentifierInfo * | II, |
RecordDataImpl & | Record | ||
) |
Emit a reference to an identifier.
Definition at line 5519 of file ASTWriter.cpp.
References getIdentifierRef().
Referenced by clang::ASTRecordWriter::AddIdentifierRef(), and AddToken().
void ASTWriter::AddPath | ( | StringRef | Path, |
RecordDataImpl & | Record | ||
) |
Add a path to the given record.
Definition at line 4550 of file ASTWriter.cpp.
References AddString(), and PreparePathForOutput().
Referenced by clang::ASTRecordWriter::AddPath().
void ASTWriter::AddSourceLocation | ( | SourceLocation | Loc, |
RecordDataImpl & | Record, | ||
LocSeq * | Seq = nullptr |
||
) |
Emit a source location.
Definition at line 5503 of file ASTWriter.cpp.
References clang::SourceLocationEncoding::encode().
Referenced by clang::ASTRecordWriter::AddSourceLocation(), AddSourceRange(), and AddToken().
void ASTWriter::AddSourceRange | ( | SourceRange | Range, |
RecordDataImpl & | Record, | ||
LocSeq * | Seq = nullptr |
||
) |
Emit a source range.
Definition at line 5509 of file ASTWriter.cpp.
References AddSourceLocation().
Referenced by clang::ASTRecordWriter::AddSourceRange().
void ASTWriter::AddString | ( | StringRef | Str, |
RecordDataImpl & | Record | ||
) |
Add a string to the given record.
Definition at line 4522 of file ASTWriter.cpp.
Referenced by AddPath(), clang::ASTRecordWriter::AddString(), and AddToken().
void ASTWriter::AddToken | ( | const Token & | Tok, |
RecordDataImpl & | Record | ||
) |
Emit a token.
Definition at line 4479 of file ASTWriter.cpp.
References AddIdentifierRef(), AddSourceLocation(), AddString(), AddToken(), clang::Token::getAnnotationEndLoc(), clang::Token::getAnnotationValue(), clang::Token::getFlags(), clang::Token::getIdentifierInfo(), clang::Token::getKind(), clang::Token::getLength(), clang::Token::getLocation(), and clang::Token::isAnnotation().
Referenced by AddToken().
void ASTWriter::AddTypeRef | ( | QualType | T, |
RecordDataImpl & | Record | ||
) |
Emit a reference to a type.
Definition at line 5646 of file ASTWriter.cpp.
References GetOrCreateTypeID().
Referenced by clang::ASTRecordWriter::AddTypeRef().
void ASTWriter::AddVersionTuple | ( | const VersionTuple & | Version, |
RecordDataImpl & | Record | ||
) |
Add a version tuple to the given record.
Definition at line 4563 of file ASTWriter.cpp.
Referenced by clang::ASTRecordWriter::AddVersionTuple().
void ASTWriter::ClearSwitchCaseIDs | ( | ) |
Definition at line 2730 of file ASTWriterStmt.cpp.
Referenced by clang::ASTRecordWriter::AddFunctionDefinition().
void ASTWriter::EmitRecordWithPath | ( | unsigned | Abbrev, |
RecordDataRef | Record, | ||
StringRef | Path | ||
) |
Emit the current record with the given path as a blob.
Definition at line 4556 of file ASTWriter.cpp.
References PreparePathForOutput().
Definition at line 5770 of file ASTWriter.cpp.
References clang::Decl::getLexicalDeclContext(), clang::serialization::needsAnonymousDeclarationNumber(), and clang::serialization::numberAnonymousDeclsWithin().
Referenced by clang::ASTDeclWriter::VisitNamedDecl().
|
inline |
Definition at line 588 of file ASTWriter.h.
|
inline |
Definition at line 747 of file ASTWriter.h.
|
inline |
Definition at line 742 of file ASTWriter.h.
|
inline |
Definition at line 739 of file ASTWriter.h.
Referenced by clang::ASTDeclWriter::VisitCXXMethodDecl().
|
inline |
Definition at line 737 of file ASTWriter.h.
Referenced by clang::ASTDeclWriter::VisitEnumDecl().
|
inline |
Definition at line 736 of file ASTWriter.h.
Referenced by clang::ASTDeclWriter::VisitFieldDecl().
DeclID ASTWriter::getDeclID | ( | const Decl * | D | ) |
Determine the declaration ID of an already-emitted declaration.
Definition at line 5719 of file ASTWriter.cpp.
References clang::Decl::getGlobalID(), and clang::Decl::isFromASTFile().
|
inline |
Definition at line 738 of file ASTWriter.h.
Referenced by clang::ASTDeclWriter::VisitObjCIvarDecl().
|
inline |
Definition at line 732 of file ASTWriter.h.
Referenced by clang::ASTDeclWriter::VisitParmVarDecl().
|
inline |
Definition at line 733 of file ASTWriter.h.
Referenced by clang::ASTDeclWriter::VisitRecordDecl().
DeclID ASTWriter::GetDeclRef | ( | const Decl * | D | ) |
Force a declaration to be emitted and get its ID.
Definition at line 5690 of file ASTWriter.cpp.
References clang::Decl::getGlobalID(), and clang::Decl::isFromASTFile().
Referenced by AddDeclRef(), clang::ASTRecordWriter::AddFunctionDefinition(), clang::ASTDeclWriter::VisitObjCInterfaceDecl(), clang::ASTDeclWriter::VisitRedeclarable(), and clang::ASTDeclWriter::VisitVarDecl().
|
inline |
Definition at line 741 of file ASTWriter.h.
|
inline |
Definition at line 734 of file ASTWriter.h.
Referenced by clang::ASTDeclWriter::VisitTypedefDecl().
|
inline |
Definition at line 735 of file ASTWriter.h.
Referenced by clang::ASTDeclWriter::VisitVarDecl().
|
inline |
Definition at line 744 of file ASTWriter.h.
Find the first local declaration of a given local redeclarable decl.
Definition at line 1884 of file ASTWriterDecl.cpp.
References clang::Decl::getCanonicalDecl(), clang::Decl::getPreviousDecl(), and IsLocalDecl().
Referenced by clang::ASTDeclWriter::RegisterTemplateSpecialization(), and clang::ASTDeclWriter::VisitRedeclarable().
IdentID ASTWriter::getIdentifierRef | ( | const IdentifierInfo * | II | ) |
Get the unique number used to refer to the given identifier.
Definition at line 5523 of file ASTWriter.cpp.
Referenced by AddIdentifierRef().
|
inline |
Definition at line 743 of file ASTWriter.h.
const LangOptions & ASTWriter::getLangOpts | ( | ) | const |
Definition at line 4614 of file ASTWriter.cpp.
References clang::ASTContext::getLangOpts().
Referenced by getLocalOrImportedSubmoduleID().
Retrieve or create a submodule ID for this module, or return 0 if the submodule is neither local (a submodle of the currently-written module) nor from an imported module.
Definition at line 2723 of file ASTWriter.cpp.
References getLangOpts(), and clang::Module::getTopLevelModule().
uint32_t ASTWriter::getMacroDirectivesOffset | ( | const IdentifierInfo * | Name | ) |
Definition at line 5557 of file ASTWriter.cpp.
Determine the ID of an already-emitted macro.
Definition at line 5549 of file ASTWriter.cpp.
References clang::MacroInfo::isBuiltinMacro().
MacroID ASTWriter::getMacroRef | ( | MacroInfo * | MI, |
const IdentifierInfo * | Name | ||
) |
Get the unique number used to refer to the given macro.
Definition at line 5533 of file ASTWriter.cpp.
References clang::MacroInfo::isBuiltinMacro().
TypeID ASTWriter::GetOrCreateTypeID | ( | QualType | T | ) |
Force a type to be emitted and get its ID.
Definition at line 5650 of file ASTWriter.cpp.
References clang::serialization::TypeIdx::getIndex(), clang::QualType::getLocalFastQualifiers(), clang::QualType::isNull(), and clang::serialization::MakeTypeID().
Referenced by AddTypeRef().
SelectorID ASTWriter::getSelectorRef | ( | Selector | Sel | ) |
Get the unique number used to refer to the given selector.
Definition at line 5565 of file ASTWriter.cpp.
References clang::Selector::getAsOpaquePtr(), and clang::ASTReader::LoadSelector().
unsigned ASTWriter::getSwitchCaseID | ( | SwitchCase * | S | ) |
Retrieve the ID for the given switch-case statement.
Definition at line 2725 of file ASTWriterStmt.cpp.
time_t ASTWriter::getTimestampForOutput | ( | const FileEntry * | E | ) | const |
Get a timestamp for output into the AST file.
The actual timestamp of the specified file may be ignored if we have been instructed to not include timestamps in the output file.
Definition at line 4619 of file ASTWriter.cpp.
References clang::FileEntry::getModificationTime().
|
inline |
Definition at line 728 of file ASTWriter.h.
TypeID ASTWriter::getTypeID | ( | QualType | T | ) | const |
Determine the type ID of an already-emitted type.
Definition at line 5673 of file ASTWriter.cpp.
References clang::QualType::getLocalFastQualifiers(), clang::QualType::isNull(), and clang::serialization::MakeTypeID().
|
inline |
Definition at line 746 of file ASTWriter.h.
Referenced by clang::ASTDeclWriter::VisitNamespaceDecl().
Is this a local declaration (that is, one that will be written to our AST file)? This is the case for declarations that are neither imported from another AST file nor predefined.
Definition at line 670 of file ASTWriter.h.
References clang::Decl::isFromASTFile(), and clang::serialization::NUM_PREDEF_DECL_IDS.
Referenced by getFirstLocalDecl().
|
inline |
Definition at line 749 of file ASTWriter.h.
References clang::Module::isModulePurview().
bool ASTWriter::PreparePathForOutput | ( | SmallVectorImpl< char > & | Path | ) |
Convert a path from this build process into one that is appropriate for emission in the module file.
Definition at line 4527 of file ASTWriter.cpp.
References adjustFilenameForRelocatableAST(), cleanPathForOutput(), clang::SourceManager::getFileManager(), and clang::ASTContext::getSourceManager().
Referenced by AddPath(), and EmitRecordWithPath().
unsigned ASTWriter::RecordSwitchCaseID | ( | SwitchCase * | S | ) |
Record an ID for the given switch-case statement.
Definition at line 2718 of file ASTWriterStmt.cpp.
void ASTWriter::SetIdentifierOffset | ( | const IdentifierInfo * | II, |
uint32_t | Offset | ||
) |
Note that the identifier II occurs at the given offset within the identifier table.
Definition at line 4578 of file ASTWriter.cpp.
void ASTWriter::SetSelectorOffset | ( | Selector | Sel, |
uint32_t | Offset | ||
) |
Note that the selector Sel occurs at the given offset within the method pool/selector table.
Definition at line 4588 of file ASTWriter.cpp.
ASTFileSignature ASTWriter::WriteAST | ( | Sema & | SemaRef, |
StringRef | OutputFile, | ||
Module * | WritingModule, | ||
StringRef | isysroot, | ||
bool | hasErrors = false , |
||
bool | ShouldCacheASTInMemory = false |
||
) |
Write a precompiled header for the given semantic analysis.
SemaRef | a reference to the semantic analysis object that processed the AST to be written into the precompiled header. |
WritingModule | The module that we are writing. If null, we are writing a precompiled header. |
isysroot | if non-empty, write a relocatable file whose headers are relative to the given system root. If we're writing a module, its build directory will be used in preference to this if both are available. |
Definition at line 4623 of file ASTWriter.cpp.
References clang::InMemoryModuleCache::addBuiltPCM(), clang::Sema::Context, and clang::Sema::PP.
Referenced by clang::PCHGenerator::HandleTranslationUnit(), and serializeUnit().
|
friend |
Definition at line 88 of file ASTWriter.h.
|
friend |
Definition at line 89 of file ASTWriter.h.