clang API Documentation

Public Types | Public Member Functions
clang::ASTImporter Class Reference

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

#include <ASTImporter.h>

List of all members.

Public Types

typedef llvm::DenseSet
< std::pair< Decl *, Decl * > > 
NonEquivalentDeclSet

Public Member Functions

 ASTImporter (ASTContext &ToContext, FileManager &ToFileManager, ASTContext &FromContext, FileManager &FromFileManager, bool MinimalImport)
 Create a new AST importer.
virtual ~ASTImporter ()
bool isMinimalImport () const
 Whether the importer will perform a minimal import, creating to-be-completed forward declarations when possible.
QualType Import (QualType FromT)
 Import the given type from the "from" context into the "to" context.
TypeSourceInfoImport (TypeSourceInfo *FromTSI)
 Import the given type source information from the "from" context into the "to" context.
DeclImport (Decl *FromD)
 Import the given declaration from the "from" context into the "to" context.
DeclContextImportContext (DeclContext *FromDC)
 Import the given declaration context from the "from" AST context into the "to" AST context.
ExprImport (Expr *FromE)
 Import the given expression from the "from" context into the "to" context.
StmtImport (Stmt *FromS)
 Import the given statement from the "from" context into the "to" context.
NestedNameSpecifierImport (NestedNameSpecifier *FromNNS)
 Import the given nested-name-specifier from the "from" context into the "to" context.
NestedNameSpecifierLoc Import (NestedNameSpecifierLoc FromNNS)
 Import the given nested-name-specifier from the "from" context into the "to" context.
TemplateName Import (TemplateName From)
 Import the goven template name from the "from" context into the "to" context.
SourceLocation Import (SourceLocation FromLoc)
 Import the given source location from the "from" context into the "to" context.
SourceRange Import (SourceRange FromRange)
 Import the given source range from the "from" context into the "to" context.
DeclarationName Import (DeclarationName FromName)
 Import the given declaration name from the "from" context into the "to" context.
IdentifierInfoImport (const IdentifierInfo *FromId)
 Import the given identifier from the "from" context into the "to" context.
Selector Import (Selector FromSel)
 Import the given Objective-C selector from the "from" context into the "to" context.
FileID Import (FileID)
 Import the given file ID from the "from" context into the "to" context.
void ImportDefinition (Decl *From)
 Import the definition of the given declaration, including all of the declarations it contains.
virtual 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.
ASTContextgetToContext () const
 Retrieve the context that AST nodes are being imported into.
ASTContextgetFromContext () const
 Retrieve the context that AST nodes are being imported from.
FileManagergetToFileManager () const
 Retrieve the file manager that AST nodes are being imported into.
FileManagergetFromFileManager () 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.
NonEquivalentDeclSetgetNonEquivalentDecls ()
 Return the set of declarations that we know are not equivalent.
virtual void CompleteDecl (Decl *D)
 Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl. Mark the Decl as complete, filling it in as much as possible.
virtual DeclImported (Decl *From, Decl *To)
 Note that we have imported the "from" declaration by mapping it to the (potentially-newly-created) "to" declaration.
bool IsStructurallyEquivalent (QualType From, QualType To)
 Determine whether the given types are structurally equivalent.

Detailed Description

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

Definition at line 38 of file ASTImporter.h.


Member Typedef Documentation

typedef llvm::DenseSet<std::pair<Decl *, Decl *> > clang::ASTImporter::NonEquivalentDeclSet

Definition at line 40 of file ASTImporter.h.


Constructor & Destructor Documentation

ASTImporter::ASTImporter ( ASTContext ToContext,
FileManager ToFileManager,
ASTContext FromContext,
FileManager FromFileManager,
bool  MinimalImport 
)

Create a new AST importer.

Parameters:
ToContextThe context we'll be importing into.
ToFileManagerThe file manager we'll be importing into.
FromContextThe context we'll be importing from.
FromFileManagerThe file manager we'll be importing into.
MinimalImportIf 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.

Definition at line 4130 of file ASTImporter.cpp.

References clang::ASTContext::getTranslationUnitDecl().

ASTImporter::~ASTImporter ( ) [virtual]

Definition at line 4141 of file ASTImporter.cpp.


Member Function Documentation

void ASTImporter::CompleteDecl ( Decl D) [virtual]

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

Parameters:
DA declaration in the "to" context.

Definition at line 4644 of file ASTImporter.cpp.

Referenced by ImportContext().

DiagnosticBuilder ASTImporter::FromDiag ( SourceLocation  Loc,
unsigned  DiagID 
)
ASTContext& clang::ASTImporter::getFromContext ( ) const [inline]

Retrieve the context that AST nodes are being imported from.

Definition at line 242 of file ASTImporter.h.

Referenced by clang::ASTNodeImporter::ImportDefinition(), clang::ASTNodeImporter::IsStructuralMatch(), and clang::ASTNodeImporter::VisitTemplateSpecializationType().

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

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

Definition at line 248 of file ASTImporter.h.

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

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

Definition at line 257 of file ASTImporter.h.

Referenced by clang::ASTNodeImporter::IsStructuralMatch().

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

Retrieve the context that AST nodes are being imported into.

Definition at line 239 of file ASTImporter.h.

Referenced by clang::ASTNodeImporter::ImportDefinition(), clang::ASTNodeImporter::ImportTemplateArgument(), clang::ASTNodeImporter::ImportTemplateParameterList(), clang::ASTNodeImporter::IsStructuralMatch(), clang::ASTNodeImporter::VisitAutoType(), clang::ASTNodeImporter::VisitBinaryOperator(), clang::ASTNodeImporter::VisitBlockPointerType(), clang::ASTNodeImporter::VisitBuiltinType(), clang::ASTNodeImporter::VisitCharacterLiteral(), clang::ASTNodeImporter::VisitClassTemplateDecl(), clang::ASTNodeImporter::VisitClassTemplateSpecializationDecl(), clang::ASTNodeImporter::VisitComplexType(), clang::ASTNodeImporter::VisitCompoundAssignOperator(), clang::ASTNodeImporter::VisitConstantArrayType(), clang::ASTNodeImporter::VisitCStyleCastExpr(), clang::ASTNodeImporter::VisitDeclRefExpr(), clang::ASTNodeImporter::VisitDecltypeType(), clang::ASTNodeImporter::VisitElaboratedType(), clang::ASTNodeImporter::VisitEnumConstantDecl(), clang::ASTNodeImporter::VisitEnumDecl(), clang::ASTNodeImporter::VisitEnumType(), clang::ASTNodeImporter::VisitExtVectorType(), clang::ASTNodeImporter::VisitFieldDecl(), clang::ASTNodeImporter::VisitFunctionDecl(), clang::ASTNodeImporter::VisitFunctionNoProtoType(), clang::ASTNodeImporter::VisitFunctionProtoType(), clang::ASTNodeImporter::VisitImplicitCastExpr(), clang::ASTNodeImporter::VisitImplicitParamDecl(), clang::ASTNodeImporter::VisitIncompleteArrayType(), clang::ASTNodeImporter::VisitIndirectFieldDecl(), clang::ASTNodeImporter::VisitIntegerLiteral(), clang::ASTNodeImporter::VisitLValueReferenceType(), clang::ASTNodeImporter::VisitMemberPointerType(), clang::ASTNodeImporter::VisitNamespaceDecl(), clang::ASTNodeImporter::VisitNonTypeTemplateParmDecl(), clang::ASTNodeImporter::VisitObjCCategoryDecl(), clang::ASTNodeImporter::VisitObjCCategoryImplDecl(), clang::ASTNodeImporter::VisitObjCImplementationDecl(), clang::ASTNodeImporter::VisitObjCInterfaceDecl(), clang::ASTNodeImporter::VisitObjCInterfaceType(), clang::ASTNodeImporter::VisitObjCIvarDecl(), clang::ASTNodeImporter::VisitObjCMethodDecl(), clang::ASTNodeImporter::VisitObjCObjectPointerType(), clang::ASTNodeImporter::VisitObjCObjectType(), clang::ASTNodeImporter::VisitObjCPropertyDecl(), clang::ASTNodeImporter::VisitObjCPropertyImplDecl(), clang::ASTNodeImporter::VisitObjCProtocolDecl(), clang::ASTNodeImporter::VisitParenExpr(), clang::ASTNodeImporter::VisitParenType(), clang::ASTNodeImporter::VisitParmVarDecl(), clang::ASTNodeImporter::VisitPointerType(), clang::ASTNodeImporter::VisitRecordDecl(), clang::ASTNodeImporter::VisitRecordType(), clang::ASTNodeImporter::VisitRValueReferenceType(), clang::ASTNodeImporter::VisitTemplateSpecializationType(), clang::ASTNodeImporter::VisitTemplateTemplateParmDecl(), clang::ASTNodeImporter::VisitTemplateTypeParmDecl(), clang::ASTNodeImporter::VisitTranslationUnitDecl(), clang::ASTNodeImporter::VisitTypedefNameDecl(), clang::ASTNodeImporter::VisitTypedefType(), clang::ASTNodeImporter::VisitTypeOfExprType(), clang::ASTNodeImporter::VisitTypeOfType(), clang::ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(), clang::ASTNodeImporter::VisitUnaryOperator(), clang::ASTNodeImporter::VisitUnaryTransformType(), clang::ASTNodeImporter::VisitVarDecl(), clang::ASTNodeImporter::VisitVariableArrayType(), and clang::ASTNodeImporter::VisitVectorType().

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

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

Definition at line 245 of file ASTImporter.h.

DeclarationName ASTImporter::HandleNameConflict ( DeclarationName  Name,
DeclContext DC,
unsigned  IDNS,
NamedDecl **  Decls,
unsigned  NumDecls 
) [virtual]

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:
Namethe name of the declaration being imported, which conflicts with other declarations.
DCthe declaration context (in the "to" AST context) in which the name is being imported.
IDNSthe identifier namespace in which the name will be found.
Declsthe set of declarations with the same name as the declaration being imported.
NumDeclsthe number of conflicting declarations in Decls.
Returns:
the name that the newly-imported declaration should have.

Definition at line 4628 of file ASTImporter.cpp.

Referenced by clang::ASTNodeImporter::VisitClassTemplateDecl(), clang::ASTNodeImporter::VisitEnumConstantDecl(), clang::ASTNodeImporter::VisitEnumDecl(), clang::ASTNodeImporter::VisitFunctionDecl(), clang::ASTNodeImporter::VisitNamespaceDecl(), clang::ASTNodeImporter::VisitRecordDecl(), clang::ASTNodeImporter::VisitTypedefNameDecl(), and clang::ASTNodeImporter::VisitVarDecl().

QualType ASTImporter::Import ( QualType  FromT)

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

Returns:
the equivalent type in the "to" context, or a NULL type if an error occurred.

Definition at line 4143 of file ASTImporter.cpp.

References clang::QualType::getLocalQualifiers(), clang::ASTContext::getQualifiedType(), clang::QualType::getTypePtr(), clang::QualType::isNull(), and clang::TypeVisitor< ImplClass, RetTy >::Visit().

Referenced by Import(), ImportContext(), clang::ASTNodeImporter::ImportDeclarationNameLoc(), clang::ASTNodeImporter::ImportDeclContext(), clang::ASTNodeImporter::ImportDeclParts(), clang::ASTNodeImporter::ImportDefinition(), ImportDefinition(), clang::ASTNodeImporter::ImportDefinitionIfNeeded(), clang::ASTNodeImporter::ImportTemplateArgument(), clang::ASTNodeImporter::ImportTemplateParameterList(), IsStructurallyEquivalent(), clang::ASTNodeImporter::VisitAutoType(), clang::ASTNodeImporter::VisitBinaryOperator(), clang::ASTNodeImporter::VisitBlockPointerType(), clang::ASTNodeImporter::VisitCharacterLiteral(), clang::ASTNodeImporter::VisitClassTemplateDecl(), clang::ASTNodeImporter::VisitClassTemplateSpecializationDecl(), clang::ASTNodeImporter::VisitComplexType(), clang::ASTNodeImporter::VisitCompoundAssignOperator(), clang::ASTNodeImporter::VisitConstantArrayType(), clang::ASTNodeImporter::VisitCStyleCastExpr(), clang::ASTNodeImporter::VisitDeclRefExpr(), clang::ASTNodeImporter::VisitDecltypeType(), clang::ASTNodeImporter::VisitElaboratedType(), clang::ASTNodeImporter::VisitEnumConstantDecl(), clang::ASTNodeImporter::VisitEnumDecl(), clang::ASTNodeImporter::VisitEnumType(), clang::ASTNodeImporter::VisitExtVectorType(), clang::ASTNodeImporter::VisitFieldDecl(), clang::ASTNodeImporter::VisitFunctionDecl(), clang::ASTNodeImporter::VisitFunctionNoProtoType(), clang::ASTNodeImporter::VisitFunctionProtoType(), clang::ASTNodeImporter::VisitImplicitCastExpr(), clang::ASTNodeImporter::VisitImplicitParamDecl(), clang::ASTNodeImporter::VisitIncompleteArrayType(), clang::ASTNodeImporter::VisitIndirectFieldDecl(), clang::ASTNodeImporter::VisitIntegerLiteral(), clang::ASTNodeImporter::VisitLValueReferenceType(), clang::ASTNodeImporter::VisitMemberPointerType(), clang::ASTNodeImporter::VisitNamespaceDecl(), clang::ASTNodeImporter::VisitNonTypeTemplateParmDecl(), clang::ASTNodeImporter::VisitObjCCategoryDecl(), clang::ASTNodeImporter::VisitObjCCategoryImplDecl(), clang::ASTNodeImporter::VisitObjCImplementationDecl(), clang::ASTNodeImporter::VisitObjCInterfaceDecl(), clang::ASTNodeImporter::VisitObjCInterfaceType(), clang::ASTNodeImporter::VisitObjCIvarDecl(), clang::ASTNodeImporter::VisitObjCMethodDecl(), clang::ASTNodeImporter::VisitObjCObjectPointerType(), clang::ASTNodeImporter::VisitObjCObjectType(), clang::ASTNodeImporter::VisitObjCPropertyDecl(), clang::ASTNodeImporter::VisitObjCPropertyImplDecl(), clang::ASTNodeImporter::VisitObjCProtocolDecl(), clang::ASTNodeImporter::VisitParenExpr(), clang::ASTNodeImporter::VisitParenType(), clang::ASTNodeImporter::VisitParmVarDecl(), clang::ASTNodeImporter::VisitPointerType(), clang::ASTNodeImporter::VisitRecordDecl(), clang::ASTNodeImporter::VisitRecordType(), clang::ASTNodeImporter::VisitRValueReferenceType(), clang::ASTNodeImporter::VisitTemplateSpecializationType(), clang::ASTNodeImporter::VisitTemplateTemplateParmDecl(), clang::ASTNodeImporter::VisitTemplateTypeParmDecl(), clang::ASTNodeImporter::VisitTypedefNameDecl(), clang::ASTNodeImporter::VisitTypedefType(), clang::ASTNodeImporter::VisitTypeOfExprType(), clang::ASTNodeImporter::VisitTypeOfType(), clang::ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(), clang::ASTNodeImporter::VisitUnaryOperator(), clang::ASTNodeImporter::VisitUnaryTransformType(), clang::ASTNodeImporter::VisitVarDecl(), clang::ASTNodeImporter::VisitVariableArrayType(), and clang::ASTNodeImporter::VisitVectorType().

TypeSourceInfo * ASTImporter::Import ( TypeSourceInfo FromTSI)

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

Returns:
the equivalent type source information in the "to" context, or NULL if an error occurred.

Definition at line 4167 of file ASTImporter.cpp.

References clang::TypeLoc::getLocStart(), clang::ASTContext::getTrivialTypeSourceInfo(), clang::TypeSourceInfo::getType(), clang::TypeSourceInfo::getTypeLoc(), Import(), and clang::QualType::isNull().

Decl * ASTImporter::Import ( Decl FromD)

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

Returns:
the equivalent declaration in the "to" context, or a NULL type if an error occurred.

Definition at line 4181 of file ASTImporter.cpp.

References Import(), clang::ASTNodeImporter::ImportDefinitionIfNeeded(), and clang::TypeVisitor< ImplClass, RetTy >::Visit().

Expr * ASTImporter::Import ( Expr FromE)

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

Returns:
the equivalent expression in the "to" context, or NULL if an error occurred.

Definition at line 4283 of file ASTImporter.cpp.

References Import().

Stmt * ASTImporter::Import ( Stmt FromS)

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

Returns:
the equivalent statement in the "to" context, or NULL if an error occurred.

Definition at line 4290 of file ASTImporter.cpp.

NestedNameSpecifier * ASTImporter::Import ( NestedNameSpecifier FromNNS)
NestedNameSpecifierLoc ASTImporter::Import ( NestedNameSpecifierLoc  FromNNS)

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

Returns:
the equivalent nested-name-specifier in the "to" context.

Definition at line 4356 of file ASTImporter.cpp.

TemplateName ASTImporter::Import ( TemplateName  From)

Import the goven template name from the "from" context into the "to" context.

Definition at line 4361 of file ASTImporter.cpp.

References clang::UnresolvedSetImpl::addDecl(), clang::UnresolvedSetImpl::begin(), clang::OverloadedTemplateStorage::begin(), clang::TemplateName::DependentTemplate, clang::UnresolvedSetImpl::end(), clang::OverloadedTemplateStorage::end(), clang::SubstTemplateTemplateParmPackStorage::getArgumentPack(), clang::TemplateName::getAsDependentTemplateName(), clang::TemplateName::getAsOverloadedTemplate(), clang::TemplateName::getAsQualifiedTemplateName(), clang::TemplateName::getAsSubstTemplateTemplateParm(), clang::TemplateName::getAsSubstTemplateTemplateParmPack(), clang::TemplateName::getAsTemplateDecl(), clang::ASTContext::getDependentTemplateName(), clang::DependentTemplateName::getIdentifier(), clang::TemplateName::getKind(), clang::DependentTemplateName::getOperator(), clang::ASTContext::getOverloadedTemplateName(), clang::SubstTemplateTemplateParmStorage::getParameter(), clang::SubstTemplateTemplateParmPackStorage::getParameterPack(), clang::ASTContext::getQualifiedTemplateName(), clang::QualifiedTemplateName::getQualifier(), clang::DependentTemplateName::getQualifier(), clang::SubstTemplateTemplateParmStorage::getReplacement(), clang::ASTContext::getSubstTemplateTemplateParm(), clang::ASTContext::getSubstTemplateTemplateParmPack(), clang::QualifiedTemplateName::hasTemplateKeyword(), Import(), clang::ASTNodeImporter::ImportTemplateArgument(), clang::DependentTemplateName::isIdentifier(), clang::TemplateName::isNull(), clang::TemplateArgument::isNull(), clang::TemplateName::OverloadedTemplate, Param, clang::TemplateName::QualifiedTemplate, clang::TemplateName::SubstTemplateTemplateParm, clang::TemplateName::SubstTemplateTemplateParmPack, and clang::TemplateName::Template.

SourceLocation ASTImporter::Import ( SourceLocation  FromLoc)

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

Returns:
the equivalent source location in the "to" context, or an invalid source location if an error occurred.

Definition at line 4450 of file ASTImporter.cpp.

References clang::SourceManager::getDecomposedLoc(), clang::SourceManager::getLocForStartOfFile(), clang::SourceLocation::getLocWithOffset(), clang::ASTContext::getSourceManager(), clang::SourceManager::getSpellingLoc(), Import(), and clang::SourceLocation::isInvalid().

SourceRange ASTImporter::Import ( SourceRange  FromRange)

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

Returns:
the equivalent source range in the "to" context, or an invalid source location if an error occurred.

Definition at line 4466 of file ASTImporter.cpp.

References clang::SourceRange::getBegin(), clang::SourceRange::getEnd(), and Import().

DeclarationName ASTImporter::Import ( DeclarationName  FromName)
IdentifierInfo * ASTImporter::Import ( const IdentifierInfo FromId)

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

Returns:
the equivalent identifier in the "to" context.

Definition at line 4610 of file ASTImporter.cpp.

References clang::IdentifierTable::get(), clang::IdentifierInfo::getName(), and clang::ASTContext::Idents.

Selector ASTImporter::Import ( Selector  FromSel)

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

Returns:
the equivalent selector in the "to" context.

Definition at line 4617 of file ASTImporter.cpp.

References clang::Selector::getIdentifierInfoForSlot(), clang::Selector::getNumArgs(), clang::SelectorTable::getSelector(), Import(), clang::Selector::isNull(), and clang::ASTContext::Selectors.

FileID ASTImporter::Import ( FileID  FromID)
DeclContext * ASTImporter::ImportContext ( DeclContext FromDC)
void ASTImporter::ImportDefinition ( Decl From)

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

This routine is intended to be used

Definition at line 4510 of file ASTImporter.cpp.

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

Decl * ASTImporter::Imported ( Decl From,
Decl To 
) [virtual]
bool clang::ASTImporter::isMinimalImport ( ) const [inline]

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

Definition at line 98 of file ASTImporter.h.

Referenced by clang::ASTNodeImporter::ImportDeclContext(), and clang::ASTNodeImporter::shouldForceImportDeclContext().

bool ASTImporter::IsStructurallyEquivalent ( QualType  From,
QualType  To 
)
DiagnosticBuilder ASTImporter::ToDiag ( SourceLocation  Loc,
unsigned  DiagID 
)

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