class ASTImporter

Declaration

class ASTImporter { /* full declaration omitted */ };

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:62

Member Variables

private std::shared_ptr<ASTImporterSharedState> SharedState = nullptr
private clang::ASTImporter::ImportPathTy ImportPath
The path which we go through during the import of a given AST node.
private clang::ASTImporter::SavedImportPathsTy SavedImportPaths
private clang::ASTContext& ToContext
The contexts we're importing to and from.
private clang::ASTContext& FromContext
The contexts we're importing to and from.
private clang::FileManager& ToFileManager
The file managers we're importing to and from.
private clang::FileManager& FromFileManager
The file managers we're importing to and from.
private bool Minimal
Whether to perform a minimal import.
private clang::ASTImporter::ODRHandlingType ODRHandling
private bool LastDiagFromFrom = false
Whether the last diagnostic came from the "from" context.
private llvm::DenseMap<const Type*, const Type*> ImportedTypes
Mapping from the already-imported types in the "from" context to the corresponding types in the "to" context.
private llvm::DenseMap<Decl*, Decl*> ImportedDecls
Mapping from the already-imported declarations in the "from" context to the corresponding declarations in the "to" context.
private llvm::DenseMap<Decl*, ASTImportError> ImportDeclErrors
Mapping from the already-imported declarations in the "from" context to the error status of the import of that declaration. This map contains only the declarations that were not correctly imported. The same declaration may or may not be included in ImportedDecls. This map is updated continuously during imports and never cleared (like ImportedDecls).
private llvm::DenseMap<Decl*, Decl*> ImportedFromDecls
Mapping from the already-imported declarations in the "to" context to the corresponding declarations in the "from" context.
private llvm::DenseMap<Stmt*, Stmt*> ImportedStmts
Mapping from the already-imported statements in the "from" context to the corresponding statements in the "to" context.
private llvm::DenseMap<FileID, FileID> ImportedFileIDs
Mapping from the already-imported FileIDs in the "from" source manager to the corresponding FileIDs in the "to" source manager.
private clang::ASTImporter::ImportedCXXBaseSpecifierMap ImportedCXXBaseSpecifiers
Mapping from the already-imported CXXBasesSpecifier in the "from" source manager to the corresponding CXXBasesSpecifier in the "to" source manager.
private clang::ASTImporter::NonEquivalentDeclSet NonEquivalentDecls
Declaration (from, to) pairs that are known not to be equivalent (which we have already complained about).

Method Overview

  • public ASTImporter(clang::ASTContext & ToContext, clang::FileManager & ToFileManager, clang::ASTContext & FromContext, clang::FileManager & FromFileManager, bool MinimalImport, std::shared_ptr<ASTImporterSharedState> SharedState = nullptr)
  • private void AddToLookupTable(clang::Decl * ToD)
  • public virtual void CompleteDecl(clang::Decl * D)
  • public clang::DiagnosticBuilder FromDiag(clang::SourceLocation Loc, unsigned int DiagID)
  • public clang::Decl * GetAlreadyImportedOrNull(const clang::Decl * FromD) const
  • public clang::TranslationUnitDecl * GetFromTU(clang::Decl * ToD)
  • public virtual clang::Decl * GetOriginalDecl(clang::Decl * To)
  • public virtual Expected<clang::DeclarationName> HandleNameConflict(clang::DeclarationName Name, clang::DeclContext * DC, unsigned int IDNS, clang::NamedDecl ** Decls, unsigned int NumDecls)
  • public llvm::Expected<NestedNameSpecifier *> Import(clang::NestedNameSpecifier * FromNNS)
  • public llvm::Expected<DeclarationName> Import(clang::DeclarationName FromName)
  • public llvm::Expected<NestedNameSpecifierLoc> Import(clang::NestedNameSpecifierLoc FromNNS)
  • public llvm::Expected<TemplateName> Import(clang::TemplateName From)
  • public llvm::Expected<SourceLocation> Import(clang::SourceLocation FromLoc)
  • public llvm::Expected<SourceRange> Import(clang::SourceRange FromRange)
  • public clang::IdentifierInfo * Import(const clang::IdentifierInfo * FromId)
  • public llvm::Expected<Selector> Import(clang::Selector FromSel)
  • public llvm::Expected<FileID> Import(clang::FileID, bool IsBuiltin = false)
  • public llvm::Expected<CXXCtorInitializer *> Import(clang::CXXCtorInitializer * FromInit)
  • public llvm::Expected<CXXBaseSpecifier *> Import(const clang::CXXBaseSpecifier * FromSpec)
  • public llvm::Expected<APValue> Import(const clang::APValue & FromValue)
  • public llvm::Expected<Expr *> Import(clang::Expr * FromE)
  • public llvm::Expected<Stmt *> Import(clang::Stmt * FromS)
  • public llvm::Expected<ExprWithCleanups::CleanupObject> Import(ExprWithCleanups::CleanupObject From)
  • public llvm::Expected<const Type *> Import(const clang::Type * FromT)
  • public llvm::Expected<QualType> Import(clang::QualType FromT)
  • public llvm::Expected<TypeSourceInfo *> Import(clang::TypeSourceInfo * FromTSI)
  • public llvm::Expected<Attr *> Import(const clang::Attr * FromAttr)
  • public llvm::Expected<Decl *> Import(clang::Decl * FromD)
  • public llvm::Expected<const Decl *> Import(const clang::Decl * FromD)
  • public llvm::Expected<InheritedConstructor> Import(const clang::InheritedConstructor & From)
  • public llvm::Expected<DeclContext *> ImportContext(clang::DeclContext * FromDC)
  • public llvm::Error ImportDefinition(clang::Decl * From)
  • protected virtual Expected<clang::Decl *> ImportImpl(clang::Decl * From)
  • public virtual void Imported(clang::Decl * From, clang::Decl * To)
  • public bool IsStructurallyEquivalent(clang::QualType From, clang::QualType To, bool Complain = true)
  • public clang::Decl * MapImported(clang::Decl * From, clang::Decl * To)
  • public void RegisterImportedDecl(clang::Decl * FromD, clang::Decl * ToD)
  • public clang::DiagnosticBuilder ToDiag(clang::SourceLocation Loc, unsigned int DiagID)
  • private clang::ASTImporter::FoundDeclsTy findDeclsInToCtx(clang::DeclContext * DC, clang::DeclarationName Name)
  • public static llvm::Optional<unsigned int> getFieldIndex(clang::Decl * F)
  • public clang::ASTContext & getFromContext() const
  • public clang::FileManager & getFromFileManager() const
  • public llvm::Optional<ASTImportError> getImportDeclErrorIfAny(clang::Decl * FromD) const
  • public template <typename DeclT>llvm::Optional<DeclT *> getImportedFromDecl(const DeclT * ToD) const
  • public clang::ASTImporter::NonEquivalentDeclSet & getNonEquivalentDecls()
  • public clang::ASTContext & getToContext() const
  • public clang::FileManager & getToFileManager() const
  • public template <typename ImportT>llvm::Error importInto(ImportT & To, const ImportT & From)
  • public bool isMinimalImport() const
  • protected virtual bool returnWithErrorInTest()
  • public void setImportDeclError(clang::Decl * From, clang::ASTImportError Error)
  • public void setODRHandling(clang::ASTImporter::ODRHandlingType T)
  • public virtual ~ASTImporter()

Methods

ASTImporter(
    clang::ASTContext& ToContext,
    clang::FileManager& ToFileManager,
    clang::ASTContext& FromContext,
    clang::FileManager& FromFileManager,
    bool MinimalImport,
    std::shared_ptr<ASTImporterSharedState>
        SharedState = nullptr)

Declared at: clang/include/clang/AST/ASTImporter.h:288

Parameters

clang::ASTContext& ToContext
The context we'll be importing into.
clang::FileManager& ToFileManager
The file manager we'll be importing into.
clang::ASTContext& FromContext
The context we'll be importing from.
clang::FileManager& FromFileManager
The file manager we'll be importing into.
bool 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.
std::shared_ptr<ASTImporterSharedState> SharedState = nullptr
The importer specific lookup table which may be shared amongst several ASTImporter objects. If not set then the original C/C++ lookup is used.

void AddToLookupTable(clang::Decl* ToD)

Declared at: clang/include/clang/AST/ASTImporter.h:260

Parameters

clang::Decl* ToD

virtual void CompleteDecl(clang::Decl* D)

Description

Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl. Mark the Decl as complete, filling it in as much as possible.

Declared at: clang/include/clang/AST/ASTImporter.h:543

Parameters

clang::Decl* D
A declaration in the "to" context.

clang::DiagnosticBuilder FromDiag(
    clang::SourceLocation Loc,
    unsigned int DiagID)

Description

Report a diagnostic in the "from" context.

Declared at: clang/include/clang/AST/ASTImporter.h:534

Parameters

clang::SourceLocation Loc
unsigned int DiagID

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

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:360

Parameters

const clang::Decl* FromD

clang::TranslationUnitDecl* GetFromTU(
    clang::Decl* ToD)

Description

Return the translation unit from where the declaration was imported. If it does not exist nullptr is returned.

Declared at: clang/include/clang/AST/ASTImporter.h:364

Parameters

clang::Decl* ToD

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

Description

Called by StructuralEquivalenceContext. If a RecordDecl is being compared to another RecordDecl as part of import, completing the other RecordDecl may trigger importation of the first RecordDecl. This happens especially for anonymous structs. If the original of the second RecordDecl can be found, we can complete it without the need for importation, eliminating this loop.

Declared at: clang/include/clang/AST/ASTImporter.h:562

Parameters

clang::Decl* To

virtual Expected<clang::DeclarationName>
HandleNameConflict(clang::DeclarationName Name,
                   clang::DeclContext* DC,
                   unsigned int IDNS,
                   clang::NamedDecl** Decls,
                   unsigned int NumDecls)

Description

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.

Declared at: clang/include/clang/AST/ASTImporter.h:515

Parameters

clang::DeclarationName Name
the name of the declaration being imported, which conflicts with other declarations.
clang::DeclContext* DC
the declaration context (in the "to" AST context) in which the name is being imported.
unsigned int IDNS
the identifier namespace in which the name will be found.
clang::NamedDecl** Decls
the set of declarations with the same name as the declaration being imported.
unsigned int NumDecls
the number of conflicting declarations in \p Decls.

Returns

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

llvm::Expected<NestedNameSpecifier*> Import(
    clang::NestedNameSpecifier* FromNNS)

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:406

Parameters

clang::NestedNameSpecifier* FromNNS

Returns

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

llvm::Expected<DeclarationName> Import(
    clang::DeclarationName FromName)

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:439

Parameters

clang::DeclarationName FromName

Returns

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

llvm::Expected<NestedNameSpecifierLoc> Import(
    clang::NestedNameSpecifierLoc FromNNS)

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:414

Parameters

clang::NestedNameSpecifierLoc FromNNS

Returns

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

llvm::Expected<TemplateName> Import(
    clang::TemplateName From)

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:418

Parameters

clang::TemplateName From

llvm::Expected<SourceLocation> Import(
    clang::SourceLocation FromLoc)

Description

Import the given source location from the "from" context into the "to" context.

Declared at: clang/include/clang/AST/ASTImporter.h:425

Parameters

clang::SourceLocation FromLoc

Returns

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

llvm::Expected<SourceRange> Import(
    clang::SourceRange FromRange)

Description

Import the given source range from the "from" context into the "to" context.

Declared at: clang/include/clang/AST/ASTImporter.h:432

Parameters

clang::SourceRange FromRange

Returns

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

clang::IdentifierInfo* Import(
    const clang::IdentifierInfo* FromId)

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:446

Parameters

const clang::IdentifierInfo* FromId

Returns

The equivalent identifier in the "to" context. Note: It returns nullptr only if the FromId was nullptr.

llvm::Expected<Selector> Import(
    clang::Selector FromSel)

Description

Import the given Objective-C selector from the "from" context into the "to" context.

Declared at: clang/include/clang/AST/ASTImporter.h:453

Parameters

clang::Selector FromSel

Returns

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

llvm::Expected<FileID> Import(
    clang::FileID,
    bool IsBuiltin = false)

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:460

Parameters

clang::FileID
bool IsBuiltin = false

Returns

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

llvm::Expected<CXXCtorInitializer*> Import(
    clang::CXXCtorInitializer* FromInit)

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:467

Parameters

clang::CXXCtorInitializer* FromInit

Returns

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

llvm::Expected<CXXBaseSpecifier*> Import(
    const clang::CXXBaseSpecifier* FromSpec)

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:474

Parameters

const clang::CXXBaseSpecifier* FromSpec

Returns

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

llvm::Expected<APValue> Import(
    const clang::APValue& FromValue)

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:481

Parameters

const clang::APValue& FromValue

Returns

the equivalent APValue in the "to" context or the import error.

llvm::Expected<Expr*> Import(clang::Expr* FromE)

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:392

Parameters

clang::Expr* FromE

Returns

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

llvm::Expected<Stmt*> Import(clang::Stmt* FromS)

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:399

Parameters

clang::Stmt* FromS

Returns

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

llvm::Expected<ExprWithCleanups::CleanupObject>
Import(ExprWithCleanups::CleanupObject From)

Description

Import cleanup objects owned by ExprWithCleanup.

Declared at: clang/include/clang/AST/ASTImporter.h:316

Parameters

ExprWithCleanups::CleanupObject From

llvm::Expected<const Type*> Import(
    const clang::Type* FromT)

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:322

Parameters

const clang::Type* FromT

Returns

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

llvm::Expected<QualType> Import(
    clang::QualType FromT)

Description

Import the given qualified type from the "from" context into the "to" context. A null type is imported as a null type (no error).

Declared at: clang/include/clang/AST/ASTImporter.h:328

Parameters

clang::QualType FromT

Returns

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

llvm::Expected<TypeSourceInfo*> Import(
    clang::TypeSourceInfo* FromTSI)

Description

Import the given type source information from the "from" context into the "to" context.

Declared at: clang/include/clang/AST/ASTImporter.h:335

Parameters

clang::TypeSourceInfo* FromTSI

Returns

The equivalent type source information in the "to" context, or the import error.

llvm::Expected<Attr*> Import(
    const clang::Attr* FromAttr)

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:342

Parameters

const clang::Attr* FromAttr

Returns

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

llvm::Expected<Decl*> Import(clang::Decl* FromD)

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:349

Parameters

clang::Decl* FromD

Returns

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

llvm::Expected<const Decl*> Import(
    const clang::Decl* FromD)

Declared at: clang/include/clang/AST/ASTImporter.h:350

Parameters

const clang::Decl* FromD

llvm::Expected<InheritedConstructor> Import(
    const clang::InheritedConstructor& From)

Declared at: clang/include/clang/AST/ASTImporter.h:355

Parameters

const clang::InheritedConstructor& From

llvm::Expected<DeclContext*> ImportContext(
    clang::DeclContext* FromDC)

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:385

Parameters

clang::DeclContext* FromDC

Returns

the equivalent declaration context in the "to" context, or error value.

llvm::Error ImportDefinition(clang::Decl* From)

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:485

Parameters

clang::Decl* From

virtual Expected<clang::Decl*> ImportImpl(
    clang::Decl* From)

Description

Can be overwritten by subclasses to implement their own import logic. The overwritten method should call this method if it didn't import the decl on its own.

Declared at: clang/include/clang/AST/ASTImporter.h:266

Parameters

clang::Decl* From

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

Description

Subclasses can override this function to observe all of the \c From ->\c To declaration mappings as they are imported.

Declared at: clang/include/clang/AST/ASTImporter.h:547

Parameters

clang::Decl* From
clang::Decl* To

bool IsStructurallyEquivalent(
    clang::QualType From,
    clang::QualType To,
    bool Complain = true)

Description

Determine whether the given types are structurally equivalent.

Declared at: clang/include/clang/AST/ASTImporter.h:574

Parameters

clang::QualType From
clang::QualType To
bool Complain = true

clang::Decl* MapImported(clang::Decl* From,
                         clang::Decl* To)

Description

Store and assign the imported declaration to its counterpart. It may happen that several decls from the 'from' context are mapped to the same decl in the 'to' context.

Declared at: clang/include/clang/AST/ASTImporter.h:554

Parameters

clang::Decl* From
clang::Decl* To

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

Declared at: clang/include/clang/AST/ASTImporter.h:549

Parameters

clang::Decl* FromD
clang::Decl* ToD

clang::DiagnosticBuilder ToDiag(
    clang::SourceLocation Loc,
    unsigned int DiagID)

Description

Report a diagnostic in the "to" context.

Declared at: clang/include/clang/AST/ASTImporter.h:531

Parameters

clang::SourceLocation Loc
unsigned int DiagID

clang::ASTImporter::FoundDeclsTy findDeclsInToCtx(
    clang::DeclContext* DC,
    clang::DeclarationName Name)

Declared at: clang/include/clang/AST/ASTImporter.h:258

Parameters

clang::DeclContext* DC
clang::DeclarationName Name

static llvm::Optional<unsigned int> getFieldIndex(
    clang::Decl* F)

Description

Determine the index of a field in its parent record. F should be a field (or indirect field) declaration.

Declared at: clang/include/clang/AST/ASTImporter.h:581

Parameters

clang::Decl* F

Returns

The index of the field in its parent context (starting from 0). On error `None` is returned (parent context is non-record).

clang::ASTContext& getFromContext() const

Description

Retrieve the context that AST nodes are being imported from.

Declared at: clang/include/clang/AST/ASTImporter.h:522

clang::FileManager& getFromFileManager() const

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:528

llvm::Optional<ASTImportError>
getImportDeclErrorIfAny(clang::Decl* FromD) const

Description

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.

Declared at: clang/include/clang/AST/ASTImporter.h:567

Parameters

clang::Decl* FromD

template <typename DeclT>
llvm::Optional<DeclT*> getImportedFromDecl(
    const DeclT* ToD) const

Description

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.

Declared at: clang/include/clang/AST/ASTImporter.h:370

Templates

DeclT

Parameters

const DeclT* ToD

clang::ASTImporter::NonEquivalentDeclSet&
getNonEquivalentDecls()

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:537

clang::ASTContext& getToContext() const

Description

Retrieve the context that AST nodes are being imported into.

Declared at: clang/include/clang/AST/ASTImporter.h:519

clang::FileManager& getToFileManager() const

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:525

template <typename ImportT>
llvm::Error importInto(ImportT& To,
                       const ImportT& From)

Description

Import the given object, returns the result.

Declared at: clang/include/clang/AST/ASTImporter.h:307

Templates

ImportT

Parameters

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

Returns

Error information (success or error).

bool isMinimalImport() const

Description

Whether the importer will perform a minimal import, creating to-be-completed forward declarations when possible.

Declared at: clang/include/clang/AST/ASTImporter.h:297

virtual bool returnWithErrorInTest()

Description

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

Declared at: clang/include/clang/AST/ASTImporter.h:269

void setImportDeclError(
    clang::Decl* From,
    clang::ASTImportError Error)

Description

Mark (newly) imported declaration with error.

Declared at: clang/include/clang/AST/ASTImporter.h:570

Parameters

clang::Decl* From
clang::ASTImportError Error

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

Declared at: clang/include/clang/AST/ASTImporter.h:299

Parameters

clang::ASTImporter::ODRHandlingType T

virtual ~ASTImporter()

Declared at: clang/include/clang/AST/ASTImporter.h:293