clang  14.0.0git
Classes | Public Types | Public Member Functions | Friends | List of all members
clang::ASTWriter Class Reference

Writes an AST file containing the contents of a translation unit. More...

#include "clang/Serialization/ASTWriter.h"

Inheritance diagram for clang::ASTWriter:
Inheritance graph
[legend]
Collaboration diagram for clang::ASTWriter:
Collaboration graph
[legend]

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)
 Create a new precompiled header writer that outputs to the given bitstream. More...
 
 ~ASTWriter () override
 
ASTContextgetASTContext () const
 
const LangOptionsgetLangOpts () const
 
time_t getTimestampForOutput (const FileEntry *E) const
 Get a timestamp for output into the AST file. More...
 
ASTFileSignature WriteAST (Sema &SemaRef, const std::string &OutputFile, Module *WritingModule, StringRef isysroot, bool hasErrors=false, bool ShouldCacheASTInMemory=false)
 Write a precompiled header for the given semantic analysis. More...
 
void AddToken (const Token &Tok, RecordDataImpl &Record)
 Emit a token. More...
 
void AddAlignPackInfo (const Sema::AlignPackInfo &Info, RecordDataImpl &Record)
 Emit a AlignPackInfo. More...
 
void AddSourceLocation (SourceLocation Loc, RecordDataImpl &Record)
 Emit a source location. More...
 
void AddSourceRange (SourceRange Range, RecordDataImpl &Record)
 Emit a source range. More...
 
void AddIdentifierRef (const IdentifierInfo *II, RecordDataImpl &Record)
 Emit a reference to an identifier. More...
 
serialization::SelectorID getSelectorRef (Selector Sel)
 Get the unique number used to refer to the given selector. More...
 
serialization::IdentID getIdentifierRef (const IdentifierInfo *II)
 Get the unique number used to refer to the given identifier. More...
 
serialization::MacroID getMacroRef (MacroInfo *MI, const IdentifierInfo *Name)
 Get the unique number used to refer to the given macro. More...
 
serialization::MacroID getMacroID (MacroInfo *MI)
 Determine the ID of an already-emitted macro. More...
 
uint32_t getMacroDirectivesOffset (const IdentifierInfo *Name)
 
void AddTypeRef (QualType T, RecordDataImpl &Record)
 Emit a reference to a type. More...
 
serialization::TypeID GetOrCreateTypeID (QualType T)
 Force a type to be emitted and get its ID. More...
 
serialization::TypeID getTypeID (QualType T) const
 Determine the type ID of an already-emitted type. More...
 
const DeclgetFirstLocalDecl (const Decl *D)
 Find the first local declaration of a given local redeclarable decl. More...
 
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. More...
 
void AddDeclRef (const Decl *D, RecordDataImpl &Record)
 Emit a reference to a declaration. More...
 
serialization::DeclID GetDeclRef (const Decl *D)
 Force a declaration to be emitted and get its ID. More...
 
serialization::DeclID getDeclID (const Decl *D)
 Determine the declaration ID of an already-emitted declaration. More...
 
unsigned getAnonymousDeclarationNumber (const NamedDecl *D)
 
void AddString (StringRef Str, RecordDataImpl &Record)
 Add a string to the given record. More...
 
bool PreparePathForOutput (SmallVectorImpl< char > &Path)
 Convert a path from this build process into one that is appropriate for emission in the module file. More...
 
void AddPath (StringRef Path, RecordDataImpl &Record)
 Add a path to the given record. More...
 
void EmitRecordWithPath (unsigned Abbrev, RecordDataRef Record, StringRef Path)
 Emit the current record with the given path as a blob. More...
 
void AddVersionTuple (const VersionTuple &Version, RecordDataImpl &Record)
 Add a version tuple to the given record. More...
 
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. More...
 
void SetIdentifierOffset (const IdentifierInfo *II, uint32_t Offset)
 Note that the identifier II occurs at the given offset within the identifier table. More...
 
void SetSelectorOffset (Selector Sel, uint32_t Offset)
 Note that the selector Sel occurs at the given offset within the method pool/selector table. More...
 
unsigned RecordSwitchCaseID (SwitchCase *S)
 Record an ID for the given switch-case statement. More...
 
unsigned getSwitchCaseID (SwitchCase *S)
 Retrieve the ID for the given switch-case statement. More...
 
void ClearSwitchCaseIDs ()
 
unsigned getTypeExtQualAbbrev () const
 
unsigned getTypeFunctionProtoAbbrev () 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
 
ASTReadergetChain () const
 
- Public Member Functions inherited from clang::ASTDeserializationListener
virtual ~ASTDeserializationListener ()
 
virtual void DeclRead (serialization::DeclID ID, const Decl *D)
 A decl was deserialized from the AST file. More...
 
virtual void ModuleImportRead (serialization::SubmoduleID ID, SourceLocation ImportLoc)
 A module import was read from the AST file. More...
 
- Public Member Functions inherited from clang::ASTMutationListener
virtual ~ASTMutationListener ()
 

Friends

class ASTDeclWriter
 
class ASTRecordWriter
 

Detailed Description

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 99 of file ASTWriter.h.

Member Typedef Documentation

◆ RecordData

Definition at line 105 of file ASTWriter.h.

◆ RecordDataImpl

Definition at line 106 of file ASTWriter.h.

◆ RecordDataRef

Definition at line 107 of file ASTWriter.h.

Constructor & Destructor Documentation

◆ ASTWriter()

ASTWriter::ASTWriter ( llvm::BitstreamWriter &  Stream,
SmallVectorImpl< char > &  Buffer,
InMemoryModuleCache ModuleCache,
ArrayRef< std::shared_ptr< ModuleFileExtension >>  Extensions,
bool  IncludeTimestamps = true 
)

Create a new precompiled header writer that outputs to the given bitstream.

Definition at line 4287 of file ASTWriter.cpp.

◆ ~ASTWriter()

ASTWriter::~ASTWriter ( )
overridedefault

Member Function Documentation

◆ AddAlignPackInfo()

void ASTWriter::AddAlignPackInfo ( const Sema::AlignPackInfo Info,
RecordDataImpl Record 
)

Emit a AlignPackInfo.

Definition at line 5051 of file ASTWriter.cpp.

References clang::Sema::AlignPackInfo::getRawEncoding().

◆ AddDeclRef()

void ASTWriter::AddDeclRef ( const Decl D,
RecordDataImpl Record 
)

◆ AddIdentifierRef()

void ASTWriter::AddIdentifierRef ( const IdentifierInfo II,
RecordDataImpl Record 
)

Emit a reference to an identifier.

Definition at line 5071 of file ASTWriter.cpp.

References getIdentifierRef().

Referenced by clang::ASTRecordWriter::AddIdentifierRef(), and clang::ASTRecordWriter::AddNestedNameSpecifierLoc().

◆ AddPath()

void ASTWriter::AddPath ( StringRef  Path,
RecordDataImpl Record 
)

Add a path to the given record.

Definition at line 4239 of file ASTWriter.cpp.

Referenced by clang::ASTRecordWriter::AddPath().

◆ AddSourceLocation()

void ASTWriter::AddSourceLocation ( SourceLocation  Loc,
RecordDataImpl Record 
)

◆ AddSourceRange()

void ASTWriter::AddSourceRange ( SourceRange  Range,
RecordDataImpl Record 
)

◆ AddString()

void ASTWriter::AddString ( StringRef  Str,
RecordDataImpl Record 
)

Add a string to the given record.

Definition at line 4216 of file ASTWriter.cpp.

Referenced by clang::ASTRecordWriter::AddString().

◆ AddToken()

void ASTWriter::AddToken ( const Token Tok,
RecordDataImpl Record 
)

◆ AddTypeRef()

void ASTWriter::AddTypeRef ( QualType  T,
RecordDataImpl Record 
)

◆ AddVersionTuple()

void ASTWriter::AddVersionTuple ( const VersionTuple &  Version,
RecordDataImpl Record 
)

Add a version tuple to the given record.

Definition at line 4252 of file ASTWriter.cpp.

Referenced by clang::ASTRecordWriter::AddVersionTuple().

◆ ClearSwitchCaseIDs()

void ASTWriter::ClearSwitchCaseIDs ( )

Definition at line 2610 of file ASTWriterStmt.cpp.

◆ EmitRecordWithPath()

void ASTWriter::EmitRecordWithPath ( unsigned  Abbrev,
RecordDataRef  Record,
StringRef  Path 
)

Emit the current record with the given path as a blob.

Definition at line 4245 of file ASTWriter.cpp.

◆ getAnonymousDeclarationNumber()

unsigned ASTWriter::getAnonymousDeclarationNumber ( const NamedDecl D)

◆ getASTContext()

ASTContext& clang::ASTWriter::getASTContext ( ) const
inline

Definition at line 557 of file ASTWriter.h.

◆ getChain()

ASTReader* clang::ASTWriter::getChain ( ) const
inline

Definition at line 715 of file ASTWriter.h.

◆ getCharacterLiteralAbbrev()

unsigned clang::ASTWriter::getCharacterLiteralAbbrev ( ) const
inline

Definition at line 710 of file ASTWriter.h.

◆ getDeclCXXMethodAbbrev()

unsigned clang::ASTWriter::getDeclCXXMethodAbbrev ( ) const
inline

Definition at line 707 of file ASTWriter.h.

◆ getDeclEnumAbbrev()

unsigned clang::ASTWriter::getDeclEnumAbbrev ( ) const
inline

Definition at line 705 of file ASTWriter.h.

◆ getDeclFieldAbbrev()

unsigned clang::ASTWriter::getDeclFieldAbbrev ( ) const
inline

Definition at line 704 of file ASTWriter.h.

◆ getDeclID()

DeclID ASTWriter::getDeclID ( const Decl D)

Determine the declaration ID of an already-emitted declaration.

Definition at line 5270 of file ASTWriter.cpp.

References clang::Decl::getGlobalID(), and clang::Decl::isFromASTFile().

◆ getDeclObjCIvarAbbrev()

unsigned clang::ASTWriter::getDeclObjCIvarAbbrev ( ) const
inline

Definition at line 706 of file ASTWriter.h.

◆ getDeclParmVarAbbrev()

unsigned clang::ASTWriter::getDeclParmVarAbbrev ( ) const
inline

Definition at line 700 of file ASTWriter.h.

◆ getDeclRecordAbbrev()

unsigned clang::ASTWriter::getDeclRecordAbbrev ( ) const
inline

Definition at line 701 of file ASTWriter.h.

◆ GetDeclRef()

DeclID ASTWriter::GetDeclRef ( const Decl D)

Force a declaration to be emitted and get its ID.

Definition at line 5241 of file ASTWriter.cpp.

References clang::Decl::getGlobalID(), and clang::Decl::isFromASTFile().

Referenced by AddDeclRef().

◆ getDeclRefExprAbbrev()

unsigned clang::ASTWriter::getDeclRefExprAbbrev ( ) const
inline

Definition at line 709 of file ASTWriter.h.

◆ getDeclTypedefAbbrev()

unsigned clang::ASTWriter::getDeclTypedefAbbrev ( ) const
inline

Definition at line 702 of file ASTWriter.h.

◆ getDeclVarAbbrev()

unsigned clang::ASTWriter::getDeclVarAbbrev ( ) const
inline

Definition at line 703 of file ASTWriter.h.

◆ getExprImplicitCastAbbrev()

unsigned clang::ASTWriter::getExprImplicitCastAbbrev ( ) const
inline

Definition at line 712 of file ASTWriter.h.

◆ getFirstLocalDecl()

const Decl * ASTWriter::getFirstLocalDecl ( const Decl D)

Find the first local declaration of a given local redeclarable decl.

Definition at line 1781 of file ASTWriterDecl.cpp.

References clang::Decl::getCanonicalDecl(), and clang::Decl::getPreviousDecl().

Referenced by clang::ASTDeclWriter::RegisterTemplateSpecialization().

◆ getIdentifierRef()

IdentID ASTWriter::getIdentifierRef ( const IdentifierInfo II)

Get the unique number used to refer to the given identifier.

Definition at line 5075 of file ASTWriter.cpp.

Referenced by AddIdentifierRef().

◆ getIntegerLiteralAbbrev()

unsigned clang::ASTWriter::getIntegerLiteralAbbrev ( ) const
inline

Definition at line 711 of file ASTWriter.h.

◆ getLangOpts()

const LangOptions & ASTWriter::getLangOpts ( ) const

Definition at line 4302 of file ASTWriter.cpp.

References clang::ASTContext::getLangOpts().

◆ getLocalOrImportedSubmoduleID()

unsigned ASTWriter::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.

Definition at line 2507 of file ASTWriter.cpp.

References clang::Module::getTopLevelModule().

◆ getMacroDirectivesOffset()

uint32_t ASTWriter::getMacroDirectivesOffset ( const IdentifierInfo Name)

Definition at line 5109 of file ASTWriter.cpp.

◆ getMacroID()

MacroID ASTWriter::getMacroID ( MacroInfo MI)

Determine the ID of an already-emitted macro.

Definition at line 5101 of file ASTWriter.cpp.

References clang::MacroInfo::isBuiltinMacro().

◆ getMacroRef()

MacroID ASTWriter::getMacroRef ( MacroInfo MI,
const IdentifierInfo Name 
)

Get the unique number used to refer to the given macro.

Definition at line 5085 of file ASTWriter.cpp.

◆ GetOrCreateTypeID()

TypeID ASTWriter::GetOrCreateTypeID ( QualType  T)

◆ getSelectorRef()

SelectorID ASTWriter::getSelectorRef ( Selector  Sel)

Get the unique number used to refer to the given selector.

Definition at line 5117 of file ASTWriter.cpp.

References clang::Selector::getAsOpaquePtr().

◆ getSwitchCaseID()

unsigned ASTWriter::getSwitchCaseID ( SwitchCase S)

Retrieve the ID for the given switch-case statement.

Definition at line 2604 of file ASTWriterStmt.cpp.

◆ getTimestampForOutput()

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 4307 of file ASTWriter.cpp.

References clang::FileEntry::getModificationTime().

◆ getTypeExtQualAbbrev()

unsigned clang::ASTWriter::getTypeExtQualAbbrev ( ) const
inline

Definition at line 692 of file ASTWriter.h.

◆ getTypeFunctionProtoAbbrev()

unsigned clang::ASTWriter::getTypeFunctionProtoAbbrev ( ) const
inline

Definition at line 696 of file ASTWriter.h.

◆ getTypeID()

TypeID ASTWriter::getTypeID ( QualType  T) const

Determine the type ID of an already-emitted type.

Definition at line 5224 of file ASTWriter.cpp.

References clang::QualType::getLocalFastQualifiers(), clang::QualType::isNull(), and clang::serialization::MakeTypeID().

◆ hasChain()

bool clang::ASTWriter::hasChain ( ) const
inline

Definition at line 714 of file ASTWriter.h.

◆ IsLocalDecl()

bool clang::ASTWriter::IsLocalDecl ( const Decl D)
inline

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 634 of file ASTWriter.h.

References clang::Decl::isFromASTFile(), and clang::serialization::NUM_PREDEF_DECL_IDS.

◆ PreparePathForOutput()

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 4221 of file ASTWriter.cpp.

References adjustFilenameForRelocatableAST(), cleanPathForOutput(), clang::SourceManager::getFileManager(), and clang::ASTContext::getSourceManager().

◆ RecordSwitchCaseID()

unsigned ASTWriter::RecordSwitchCaseID ( SwitchCase S)

Record an ID for the given switch-case statement.

Definition at line 2596 of file ASTWriterStmt.cpp.

◆ SetIdentifierOffset()

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 4267 of file ASTWriter.cpp.

References Offset.

◆ SetSelectorOffset()

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 4277 of file ASTWriter.cpp.

References Offset.

◆ WriteAST()

ASTFileSignature ASTWriter::WriteAST ( Sema SemaRef,
const std::string OutputFile,
Module WritingModule,
StringRef  isysroot,
bool  hasErrors = false,
bool  ShouldCacheASTInMemory = false 
)

Write a precompiled header for the given semantic analysis.

Parameters
SemaRefa reference to the semantic analysis object that processed the AST to be written into the precompiled header.
WritingModuleThe module that we are writing. If null, we are writing a precompiled header.
isysrootif 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.
Returns
the module signature, which eventually will be a hash of the module but currently is merely a random 32-bit number.

Definition at line 4311 of file ASTWriter.cpp.

References clang::InMemoryModuleCache::addBuiltPCM(), clang::Sema::Context, and clang::Sema::PP.

Referenced by clang::PCHGenerator::HandleTranslationUnit().

Friends And Related Function Documentation

◆ ASTDeclWriter

friend class ASTDeclWriter
friend

Definition at line 102 of file ASTWriter.h.

◆ ASTRecordWriter

friend class ASTRecordWriter
friend

Definition at line 103 of file ASTWriter.h.


The documentation for this class was generated from the following files: