clang: clang::ASTImporter Class Reference (original) (raw)

Imports selected nodes from one AST context into another context, merging AST nodes where appropriate. More...

#include "[clang/AST/ASTImporter.h](ASTImporter%5F8h%5Fsource.html)"

Public Types
enum class ODRHandlingType { Conservative, Liberal }
using NonEquivalentDeclSet
using ImportedCXXBaseSpecifierMap
Public Member Functions
ASTImporter (ASTContext &ToContext, FileManager &ToFileManager, ASTContext &FromContext, FileManager &FromFileManager, bool MinimalImport, std::shared_ptr< ASTImporterSharedState > SharedState=nullptr)
virtual ~ASTImporter ()
bool isMinimalImport () const
Whether the importer will perform a minimal import, creating to-be-completed forward declarations when possible.
void setODRHandling (ODRHandlingType T)
template
llvm::Error importInto (ImportT &To, const ImportT &From)
Import the given object, returns the result.
llvm::Expected< ExprWithCleanups::CleanupObject > Import (ExprWithCleanups::CleanupObject From)
Import cleanup objects owned by ExprWithCleanup.
llvm::Expected< const Type * > Import (const Type *FromT)
Import the given type from the "from" context into the "to" context.
llvm::Expected< QualType > Import (QualType FromT)
Import the given qualified type from the "from" context into the "to" context.
llvm::Expected< TypeSourceInfo * > Import (TypeSourceInfo *FromTSI)
Import the given type source information from the "from" context into the "to" context.
llvm::Expected< Attr * > Import (const Attr *FromAttr)
Import the given attribute from the "from" context into the "to" context.
llvm::Expected< Decl * > Import (Decl *FromD)
Import the given declaration from the "from" context into the "to" context.
llvm::Expected< const Decl * > Import (const Decl *FromD)
llvm::Expected< InheritedConstructor > Import (const InheritedConstructor &From)
Decl * GetAlreadyImportedOrNull (const Decl *FromD) const
Return the copy of the given declaration in the "to" context if it has already been imported from the "from" context.
TranslationUnitDecl * GetFromTU (Decl *ToD)
Return the translation unit from where the declaration was imported.
template
std::optional< DeclT * > getImportedFromDecl (const DeclT *ToD) const
Return the declaration in the "from" context from which the declaration in the "to" context was imported.
llvm::Expected< DeclContext * > ImportContext (DeclContext *FromDC)
Import the given declaration context from the "from" AST context into the "to" AST context.
llvm::Expected< Expr * > Import (Expr *FromE)
Import the given expression from the "from" context into the "to" context.
llvm::Expected< Stmt * > Import (Stmt *FromS)
Import the given statement from the "from" context into the "to" context.
llvm::Expected< NestedNameSpecifier > Import (NestedNameSpecifier FromNNS)
Import the given nested-name-specifier from the "from" context into the "to" context.
llvm::Expected< NestedNameSpecifierLoc > Import (NestedNameSpecifierLoc FromNNS)
Import the given nested-name-specifier-loc from the "from" context into the "to" context.
llvm::Expected< TemplateName > Import (TemplateName From)
Import the given template name from the "from" context into the "to" context, or the import error.
llvm::Expected< SourceLocation > Import (SourceLocation FromLoc)
Import the given source location from the "from" context into the "to" context.
llvm::Expected< SourceRange > Import (SourceRange FromRange)
Import the given source range from the "from" context into the "to" context.
llvm::Expected< DeclarationName > Import (DeclarationName FromName)
Import the given declaration name from the "from" context into the "to" context.
IdentifierInfo * Import (const IdentifierInfo *FromId)
Import the given identifier from the "from" context into the "to" context.
IdentifierOrOverloadedOperator Import (IdentifierOrOverloadedOperator FromIO)
Import the given identifier or overloaded operator from the "from" context into the "to" context.
llvm::Expected< Selector > Import (Selector FromSel)
Import the given Objective-C selector from the "from" context into the "to" context.
llvm::Expected< FileID > Import (FileID, bool IsBuiltin=false)
Import the given file ID from the "from" context into the "to" context.
llvm::Expected< CXXCtorInitializer * > Import (CXXCtorInitializer *FromInit)
Import the given C++ constructor initializer from the "from" context into the "to" context.
llvm::Expected< CXXBaseSpecifier * > Import (const CXXBaseSpecifier *FromSpec)
Import the given CXXBaseSpecifier from the "from" context into the "to" context.
llvm::Expected< APValue > Import (const APValue &FromValue)
Import the given APValue from the "from" context into the "to" context.
llvm::Error ImportDefinition (Decl *From)
Import the definition of the given declaration, including all of the declarations it contains.
llvm::Error ImportTemplateArguments (ArrayRef< TemplateArgument > FromArgs, SmallVectorImpl< TemplateArgument > &ToArgs)
Expected< TemplateArgument > Import (const TemplateArgument &From)
virtual Expected< DeclarationName > HandleNameConflict (DeclarationName Name, DeclContext *DC, unsigned IDNS, NamedDecl **Decls, unsigned NumDecls)
Cope with a name conflict when importing a declaration into the given context.
ASTContext & getToContext () const
Retrieve the context that AST nodes are being imported into.
ASTContext & getFromContext () const
Retrieve the context that AST nodes are being imported from.
FileManager & getToFileManager () const
Retrieve the file manager that AST nodes are being imported into.
FileManager & getFromFileManager () const
Retrieve the file manager that AST nodes are being imported from.
DiagnosticBuilder ToDiag (SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "to" context.
DiagnosticBuilder FromDiag (SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "from" context.
NonEquivalentDeclSet & getNonEquivalentDecls ()
Return the set of declarations that we know are not equivalent.
virtual void CompleteDecl (Decl *D)
Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl.
virtual void Imported (Decl *From, Decl *To)
Subclasses can override this function to observe all of the From -> To declaration mappings as they are imported.
void RegisterImportedDecl (Decl *FromD, Decl *ToD)
Decl * MapImported (Decl *From, Decl *To)
Store and assign the imported declaration to its counterpart.
virtual Decl * GetOriginalDecl (Decl *To)
Called by StructuralEquivalenceContext.
std::optional< ASTImportError > getImportDeclErrorIfAny (Decl *FromD) const
Return if import of the given declaration has failed and if yes the kind of the problem.
void setImportDeclError (Decl *From, ASTImportError Error)
Mark (newly) imported declaration with error.
bool IsStructurallyEquivalent (QualType From, QualType To, bool Complain=true)
Determine whether the given types are structurally equivalent.
Static Public Member Functions
static UnsignedOrNone getFieldIndex (Decl *F)
Determine the index of a field in its parent record.
Protected Member Functions
virtual Expected< Decl * > ImportImpl (Decl *From)
Can be overwritten by subclasses to implement their own import logic.
virtual bool returnWithErrorInTest ()
Used only in unittests to verify the behaviour of the error handling.
Friends
class ASTNodeImporter

Imports selected nodes from one AST context into another context, merging AST nodes where appropriate.

Definition at line 62 of file ASTImporter.h.

ImportedCXXBaseSpecifierMap

Initial value:

llvm::DenseMap<const CXXBaseSpecifier *, CXXBaseSpecifier *>

Definition at line 67 of file ASTImporter.h.

NonEquivalentDeclSet

Initial value:

llvm::DenseSet<std::tuple<Decl *, Decl *, int>>

Definition at line 65 of file ASTImporter.h.

ODRHandlingType

Enumerator
Conservative
Liberal

Definition at line 70 of file ASTImporter.h.

Parameters

ToContext The context we'll be importing into.
ToFileManager The file manager we'll be importing into.
FromContext The context we'll be importing from.
FromFileManager The file manager we'll be importing into.
MinimalImport If true, the importer will attempt to import as little as it can, e.g., by importing declarations as forward declarations that can be completed at a later point.
SharedState The importer specific lookup table which may be shared amongst several ASTImporter objects. If not set then the original C/C++ lookup is used.

Definition at line 9363 of file ASTImporter.cpp.

References Conservative.

~ASTImporter()

ASTImporter::~ASTImporter ( ) virtualdefault

CompleteDecl()

void ASTImporter::CompleteDecl ( Decl * D) virtual

FromDiag()

GetAlreadyImportedOrNull()

Decl * ASTImporter::GetAlreadyImportedOrNull ( const Decl * FromD ) const

Return the copy of the given declaration in the "to" context if it has already been imported from the "from" context.

Otherwise return nullptr.

Definition at line 9785 of file ASTImporter.cpp.

Referenced by Import().

getFieldIndex()

getFromContext()

ASTContext & clang::ASTImporter::getFromContext ( ) const inline

Retrieve the context that AST nodes are being imported from.

Definition at line 552 of file ASTImporter.h.

getFromFileManager()

FileManager & clang::ASTImporter::getFromFileManager ( ) const inline

Retrieve the file manager that AST nodes are being imported from.

Definition at line 558 of file ASTImporter.h.

GetFromTU()

getImportDeclErrorIfAny()

std::optional< ASTImportError > ASTImporter::getImportDeclErrorIfAny ( Decl * FromD ) const

Return if import of the given declaration has failed and if yes the kind of the problem.

This gives the first error encountered with the node.

Definition at line 10819 of file ASTImporter.cpp.

Referenced by Import().

getImportedFromDecl()

template

std::optional< DeclT * > clang::ASTImporter::getImportedFromDecl ( const DeclT * ToD) const inline

Return the declaration in the "from" context from which the declaration in the "to" context was imported.

If it was not imported or of the wrong type a null value is returned.

Definition at line 387 of file ASTImporter.h.

getNonEquivalentDecls()

NonEquivalentDeclSet & clang::ASTImporter::getNonEquivalentDecls ( ) inline

Return the set of declarations that we know are not equivalent.

Definition at line 567 of file ASTImporter.h.

GetOriginalDecl()

virtual Decl * clang::ASTImporter::GetOriginalDecl ( Decl * To) inlinevirtual

getToContext()

ASTContext & clang::ASTImporter::getToContext ( ) const inline

getToFileManager()

FileManager & clang::ASTImporter::getToFileManager ( ) const inline

Retrieve the file manager that AST nodes are being imported into.

Definition at line 555 of file ASTImporter.h.

HandleNameConflict()

Cope with a name conflict when importing a declaration into the given context.

This routine is invoked whenever there is a name conflict while importing a declaration. The returned name will become the name of the imported declaration. By default, the returned name is the same as the original name, leaving the conflict unresolve such that name lookup for this name is likely to find an ambiguity later.

Subclasses may override this routine to resolve the conflict, e.g., by renaming the declaration being imported.

Parameters

Name the name of the declaration being imported, which conflicts with other declarations.
DC the declaration context (in the "to" AST context) in which the name is being imported.
IDNS the identifier namespace in which the name will be found.
Decls the set of declarations with the same name as the declaration being imported.
NumDecls the number of conflicting declarations in Decls.

Returns

the name that the newly-imported declaration should have. Or an error if we can't handle the name conflict.

Definition at line 10752 of file ASTImporter.cpp.

References Conservative, and clang::ASTImportError::NameConflict.

Import() [1/24]

Import() [2/24]

Import() [3/24]

Import() [4/24]

Import() [5/24]

Import() [6/24]

Import() [7/24]

Import() [8/24]

Import() [9/24]

Import the given C++ constructor initializer from the "from" context into the "to" context.

Returns

The equivalent initializer in the "to" context, or the import error.

Definition at line 10365 of file ASTImporter.cpp.

References clang::Error, clang::CXXCtorInitializer::getEllipsisLoc(), clang::CXXCtorInitializer::getIndirectMember(), clang::CXXCtorInitializer::getInit(), clang::CXXCtorInitializer::getLParenLoc(), clang::CXXCtorInitializer::getMember(), clang::CXXCtorInitializer::getMemberLocation(), clang::CXXCtorInitializer::getRParenLoc(), clang::CXXCtorInitializer::getTypeSourceInfo(), Import(), importInto(), clang::CXXCtorInitializer::isBaseInitializer(), clang::CXXCtorInitializer::isBaseVirtual(), clang::CXXCtorInitializer::isDelegatingInitializer(), clang::CXXCtorInitializer::isIndirectMemberInitializer(), clang::CXXCtorInitializer::isMemberInitializer(), and clang::CXXCtorInitializer::isPackExpansion().

Import() [10/24]

Import the given declaration from the "from" context into the "to" context.

Returns

The equivalent declaration in the "to" context, or the import error.

Definition at line 9796 of file ASTImporter.cpp.

References clang::Decl::addAttr(), clang::Error, GetAlreadyImportedOrNull(), clang::Decl::getAttrs(), clang::Decl::getDeclContext(), getImportDeclErrorIfAny(), clang::Decl::hasAttrs(), Import(), Imported(), ImportImpl(), setImportDeclError(), and clang::updateFlags().

Import() [11/24]

Import the given declaration name from the "from" context into the "to" context.

Returns

The equivalent declaration name in the "to" context, or the import error.

Definition at line 10499 of file ASTImporter.cpp.

References clang::cast(), clang::DeclarationName::CXXConstructorName, clang::DeclarationName::CXXConversionFunctionName, clang::DeclarationName::CXXDeductionGuideName, clang::DeclarationName::CXXDestructorName, clang::DeclarationName::CXXLiteralOperatorName, clang::DeclarationName::CXXOperatorName, clang::DeclarationName::CXXUsingDirective, clang::DeclarationName::getAsIdentifierInfo(), clang::DeclarationName::getCXXDeductionGuideTemplate(), clang::DeclarationName::getCXXLiteralIdentifier(), clang::DeclarationName::getCXXNameType(), clang::DeclarationName::getCXXOverloadedOperator(), clang::DeclarationName::getNameKind(), clang::DeclarationName::getObjCSelector(), clang::DeclarationName::getUsingDirectiveName(), clang::DeclarationName::Identifier, Import(), clang::DeclarationName::ObjCMultiArgSelector, clang::DeclarationName::ObjCOneArgSelector, and clang::DeclarationName::ObjCZeroArgSelector.

Import() [12/24]

Import the given expression from the "from" context into the "to" context.

Returns

The equivalent expression in the "to" context, or the import error.

Definition at line 10019 of file ASTImporter.cpp.

References Import().

Import() [13/24]

Import cleanup objects owned by ExprWithCleanup.

Definition at line 9469 of file ASTImporter.cpp.

References clang::cast(), Import(), and clang::ASTImportError::UnsupportedConstruct.

Referenced by clang::ASTMergeAction::ExecuteAction(), clang::ExternalASTMerger::FindExternalVisibleDeclsByName(), Import(), Import(), Import(), Import(), Import(), Import(), Import(), Import(), Import(), Import(), Import(), Import(), Import(), Import(), Import(), Import(), Import(), ImportContext(), ImportDefinition(), importInto(), importSpecializations(), IsStructurallyEquivalent(), and setTypedefNameForAnonDecl().

Import() [14/24]

Import the given file ID from the "from" context into the "to" context.

Returns

The equivalent file ID in the source manager of the "to" context, or the import error.

Definition at line 10278 of file ASTImporter.cpp.

References clang::Cache, clang::SourceManager::createExpansionLoc(), clang::SourceManager::createFileID(), clang::SourceManager::createMacroArgExpansionLoc(), clang::SrcMgr::FileInfo::getContentCache(), clang::SrcMgr::SLocEntry::getExpansion(), clang::SrcMgr::ExpansionInfo::getExpansionLocEnd(), clang::SrcMgr::ExpansionInfo::getExpansionLocStart(), clang::SrcMgr::SLocEntry::getFile(), clang::SrcMgr::FileInfo::getFileCharacteristic(), clang::SourceManager::getFileID(), clang::SourceManager::getFileIDSize(), clang::SourceManager::getFileManager(), clang::SrcMgr::FileInfo::getIncludeLoc(), clang::SourceManager::getLocForStartOfFile(), clang::SourceManager::getMainFileID(), clang::SourceManager::getSLocEntry(), clang::SrcMgr::ExpansionInfo::getSpellingLoc(), Import(), clang::SrcMgr::SLocEntry::isExpansion(), clang::SrcMgr::ExpansionInfo::isExpansionTokenRange(), clang::FileID::isInvalid(), clang::SrcMgr::ExpansionInfo::isMacroArgExpansion(), clang::FileID::isValid(), and clang::ASTImportError::Unknown.

Import() [15/24]

Import() [16/24]

Import the given nested-name-specifier from the "from" context into the "to" context.

Returns

The equivalent nested-name-specifier in the "to" context, or the import error.

Definition at line 10055 of file ASTImporter.cpp.

References clang::cast(), clang::NestedNameSpecifier::getAsMicrosoftSuper(), clang::NestedNameSpecifier::getAsNamespaceAndPrefix(), clang::NestedNameSpecifier::getAsType(), clang::NestedNameSpecifier::getKind(), clang::NestedNameSpecifier::Global, Import(), clang::NestedNameSpecifier::MicrosoftSuper, clang::NestedNameSpecifier::Namespace, clang::NestedNameSpecifier::Null, and clang::NestedNameSpecifier::Type.

Import() [17/24]

Import the given nested-name-specifier-loc from the "from" context into the "to" context.

Returns

The equivalent nested-name-specifier-loc in the "to" context, or the import error.

Definition at line 10087 of file ASTImporter.cpp.

References clang::NestedNameSpecifierLoc::castAsTypeLoc(), clang::Error, clang::NestedNameSpecifier::getAsMicrosoftSuper(), clang::NestedNameSpecifier::getAsNamespaceAndPrefix(), clang::NestedNameSpecifierLoc::getAsNamespaceAndPrefix(), clang::NestedNameSpecifier::getAsType(), clang::TypeLoc::getBeginLoc(), clang::NestedNameSpecifier::getKind(), clang::NestedNameSpecifierLoc::getLocalBeginLoc(), clang::NestedNameSpecifierLoc::getLocalEndLoc(), clang::NestedNameSpecifierLoc::getNestedNameSpecifier(), clang::NestedNameSpecifierLoc::getSourceRange(), getToContext(), clang::ASTContext::getTrivialTypeSourceInfo(), clang::TypeSourceInfo::getTypeLoc(), clang::NestedNameSpecifierLocBuilder::getWithLocInContext(), clang::NestedNameSpecifier::Global, Import(), importInto(), clang::NestedNameSpecifier::MicrosoftSuper, clang::NamespaceAndPrefix::Namespace, clang::NestedNameSpecifier::Namespace, clang::NestedNameSpecifier::Null, clang::NamespaceAndPrefixLoc::Prefix, and clang::NestedNameSpecifier::Type.

Import() [18/24]

Import() [19/24]

Import() [20/24]

Import() [21/24]

Import() [22/24]

Import() [23/24]

Import the given template name from the "from" context into the "to" context, or the import error.

Definition at line 10157 of file ASTImporter.cpp.

References clang::UnresolvedSetImpl::addDecl(), clang::TemplateName::AssumedTemplate, ASTNodeImporter, clang::UnresolvedSetImpl::begin(), clang::cast(), clang::TemplateName::DeducedTemplate, clang::TemplateName::DependentTemplate, clang::UnresolvedSetImpl::end(), clang::SubstTemplateTemplateParmPackStorage::getArgumentPack(), clang::TemplateName::getAsAssumedTemplateName(), clang::TemplateName::getAsDependentTemplateName(), clang::TemplateName::getAsOverloadedTemplate(), clang::TemplateName::getAsQualifiedTemplateName(), clang::SubstTemplateTemplateParmPackStorage::getAssociatedDecl(), clang::SubstTemplateTemplateParmStorage::getAssociatedDecl(), clang::TemplateName::getAsSubstTemplateTemplateParm(), clang::TemplateName::getAsSubstTemplateTemplateParmPack(), clang::TemplateName::getAsTemplateDecl(), clang::TemplateName::getAsUsingShadowDecl(), clang::AssumedTemplateStorage::getDeclName(), clang::SubstTemplateTemplateParmPackStorage::getFinal(), clang::SubstTemplateTemplateParmStorage::getFinal(), clang::SubstTemplateTemplateParmPackStorage::getIndex(), clang::SubstTemplateTemplateParmStorage::getIndex(), clang::TemplateName::getKind(), clang::DependentTemplateStorage::getName(), clang::SubstTemplateTemplateParmStorage::getPackIndex(), clang::DependentTemplateStorage::getQualifier(), clang::QualifiedTemplateName::getQualifier(), clang::SubstTemplateTemplateParmStorage::getReplacement(), clang::QualifiedTemplateName::getUnderlyingTemplate(), clang::DependentTemplateStorage::hasTemplateKeyword(), clang::QualifiedTemplateName::hasTemplateKeyword(), Import(), clang::ASTNodeImporter::ImportTemplateArgument(), clang::TemplateName::OverloadedTemplate, clang::TemplateName::QualifiedTemplate, clang::TemplateName::SubstTemplateTemplateParm, clang::TemplateName::SubstTemplateTemplateParmPack, clang::TemplateName::Template, clang::TemplateName, and clang::TemplateName::UsingTemplate.

Import() [24/24]

ImportContext()

ImportDefinition()

Error ASTImporter::ImportDefinition ( Decl * From) nodiscard

Import the definition of the given declaration, including all of the declarations it contains.

Definition at line 10456 of file ASTImporter.cpp.

References ASTNodeImporter, clang::cast(), clang::Error, clang::ASTNodeImporter::IDK_Everything, Import(), clang::ASTNodeImporter::ImportDeclContext(), and clang::ASTNodeImporter::ImportDefinition().

Referenced by clang::ASTNodeImporter::ImportDefinitionIfNeeded(), clang::ASTNodeImporter::ImportFieldDeclDefinition(), clang::ASTNodeImporter::VisitClassTemplateSpecializationDecl(), clang::ASTNodeImporter::VisitEnumDecl(), clang::ASTNodeImporter::VisitObjCInterfaceDecl(), clang::ASTNodeImporter::VisitObjCProtocolDecl(), and clang::ASTNodeImporter::VisitRecordDecl().

Imported()

virtual void clang::ASTImporter::Imported ( Decl * From, Decl * To ) inlinevirtual

ImportImpl()

importInto()

template

llvm::Error clang::ASTImporter::importInto ( ImportT & To, const ImportT & From ) inlinenodiscard

Import the given object, returns the result.

Parameters

To Import the object into this variable.
From Object to import.

Returns

Error information (success or error).

Definition at line 324 of file ASTImporter.h.

References Import().

Referenced by Import(), Import(), Import(), clang::ASTNodeImporter::ImportDeclParts(), clang::ASTNodeImporter::ImportDeclParts(), clang::ASTNodeImporter::ImportDefinitionIfNeeded(), clang::ASTNodeImporter::VisitClassTemplateDecl(), clang::ASTNodeImporter::VisitClassTemplateSpecializationDecl(), clang::ASTNodeImporter::VisitEnumDecl(), clang::ASTNodeImporter::VisitFriendDecl(), clang::ASTNodeImporter::VisitFunctionTemplateDecl(), clang::ASTNodeImporter::VisitObjCCategoryDecl(), clang::ASTNodeImporter::VisitObjCCategoryImplDecl(), clang::ASTNodeImporter::VisitObjCImplementationDecl(), clang::ASTNodeImporter::VisitObjCPropertyImplDecl(), clang::ASTNodeImporter::VisitRecordDecl(), clang::ASTNodeImporter::VisitVarTemplateDecl(), and clang::ASTNodeImporter::VisitVarTemplateSpecializationDecl().

ImportTemplateArguments()

isMinimalImport()

bool clang::ASTImporter::isMinimalImport ( ) const inline

IsStructurallyEquivalent()

MapImported()

RegisterImportedDecl()

void ASTImporter::RegisterImportedDecl ( Decl * FromD,
Decl * ToD )

returnWithErrorInTest()

virtual bool clang::ASTImporter::returnWithErrorInTest ( ) inlineprotectedvirtual

Used only in unittests to verify the behaviour of the error handling.

Definition at line 286 of file ASTImporter.h.

setImportDeclError()

setODRHandling()

void clang::ASTImporter::setODRHandling ( ODRHandlingType T) inline

ToDiag()

ASTNodeImporter

Definition at line 63 of file ASTImporter.h.

References ASTNodeImporter.

Referenced by ASTNodeImporter, Import(), Import(), Import(), Import(), Import(), ImportContext(), clang::ASTNodeImporter::ImportDeclParts(), clang::ASTNodeImporter::ImportDeclParts(), ImportDefinition(), and ImportImpl().


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