clang  6.0.0svn
Public Types | Public Member Functions | List of all members
clang::ASTImporter Class Reference

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

#include "clang/AST/ASTImporter.h"

Public Types

typedef llvm::DenseSet< std::pair< Decl *, Decl * > > NonEquivalentDeclSet
 
typedef llvm::DenseMap< const CXXBaseSpecifier *, CXXBaseSpecifier * > ImportedCXXBaseSpecifierMap
 

Public Member Functions

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

Detailed Description

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

Definition at line 40 of file ASTImporter.h.

Member Typedef Documentation

◆ ImportedCXXBaseSpecifierMap

Definition at line 44 of file ASTImporter.h.

◆ NonEquivalentDeclSet

Definition at line 42 of file ASTImporter.h.

Constructor & Destructor Documentation

◆ ASTImporter()

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 5956 of file ASTImporter.cpp.

References clang::ASTContext::getTranslationUnitDecl().

◆ ~ASTImporter()

ASTImporter::~ASTImporter ( )
virtual

Definition at line 5967 of file ASTImporter.cpp.

Member Function Documentation

◆ CompleteDecl()

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 6644 of file ASTImporter.cpp.

Referenced by getNonEquivalentDecls(), and ImportContext().

◆ FromDiag()

DiagnosticBuilder ASTImporter::FromDiag ( SourceLocation  Loc,
unsigned  DiagID 
)

Report a diagnostic in the "from" context.

Definition at line 6636 of file ASTImporter.cpp.

References clang::ASTContext::getDiagnostics(), clang::DiagnosticsEngine::notePriorDiagnosticFrom(), and clang::DiagnosticsEngine::Report().

Referenced by getFromFileManager().

◆ GetAlreadyImportedOrNull()

Decl * ASTImporter::GetAlreadyImportedOrNull ( Decl FromD)

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

Otherwise return NULL.

Definition at line 6007 of file ASTImporter.cpp.

References clang::ASTNodeImporter::ImportDefinitionIfNeeded().

Referenced by isMinimalImport().

◆ getFromContext()

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

Retrieve the context that AST nodes are being imported from.

Definition at line 272 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 278 of file ASTImporter.h.

References FromDiag(), and ToDiag().

◆ getNonEquivalentDecls()

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

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

Definition at line 287 of file ASTImporter.h.

References CompleteDecl(), and Imported().

◆ GetOriginalDecl()

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

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.

Definition at line 308 of file ASTImporter.h.

References IsStructurallyEquivalent().

◆ getToContext()

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

Retrieve the context that AST nodes are being imported into.

Definition at line 269 of file ASTImporter.h.

◆ getToFileManager()

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

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

Definition at line 275 of file ASTImporter.h.

◆ HandleNameConflict()

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 6620 of file ASTImporter.cpp.

Referenced by isMinimalImport().

◆ Import() [1/16]

QualType ASTImporter::Import ( QualType  FromT)

◆ Import() [2/16]

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 5993 of file ASTImporter.cpp.

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

◆ Import() [3/16]

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 6018 of file ASTImporter.cpp.

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

◆ Import() [4/16]

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 6120 of file ASTImporter.cpp.

References Import().

◆ Import() [5/16]

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 6127 of file ASTImporter.cpp.

◆ Import() [6/16]

NestedNameSpecifier * ASTImporter::Import ( NestedNameSpecifier FromNNS)

◆ Import() [7/16]

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 6200 of file ASTImporter.cpp.

References clang::NestedNameSpecifierLoc::getPrefix().

◆ Import() [8/16]

TemplateName ASTImporter::Import ( TemplateName  From)

◆ Import() [9/16]

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 6360 of file ASTImporter.cpp.

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

◆ Import() [10/16]

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 6380 of file ASTImporter.cpp.

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

◆ Import() [11/16]

DeclarationName ASTImporter::Import ( DeclarationName  FromName)

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

Returns
the equivalent declaration name in the "to" context, or an empty declaration name if an error occurred.

Definition at line 6533 of file ASTImporter.cpp.

References clang::DeclarationName::CXXConstructorName, clang::DeclarationName::CXXConversionFunctionName, clang::DeclarationName::CXXDeductionGuideName, clang::DeclarationName::CXXDestructorName, clang::DeclarationName::CXXLiteralOperatorName, clang::DeclarationName::CXXOperatorName, clang::DeclarationName::CXXUsingDirective, clang::ASTContext::DeclarationNames, clang::DeclarationName::getAsIdentifierInfo(), clang::ASTContext::getCanonicalType(), clang::DeclarationNameTable::getCXXConstructorName(), clang::DeclarationNameTable::getCXXConversionFunctionName(), clang::DeclarationNameTable::getCXXDeductionGuideName(), clang::DeclarationName::getCXXDeductionGuideTemplate(), clang::DeclarationNameTable::getCXXDestructorName(), clang::DeclarationName::getCXXLiteralIdentifier(), clang::DeclarationNameTable::getCXXLiteralOperatorName(), clang::DeclarationName::getCXXNameType(), clang::DeclarationNameTable::getCXXOperatorName(), clang::DeclarationName::getCXXOverloadedOperator(), clang::DeclarationName::getNameKind(), clang::DeclarationName::getObjCSelector(), clang::DeclarationName::getUsingDirectiveName(), clang::DeclarationName::Identifier, Import(), clang::QualType::isNull(), clang::DeclarationName::ObjCMultiArgSelector, clang::DeclarationName::ObjCOneArgSelector, clang::DeclarationName::ObjCZeroArgSelector, and clang::T.

◆ Import() [12/16]

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 6597 of file ASTImporter.cpp.

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

◆ Import() [13/16]

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 6609 of file ASTImporter.cpp.

References clang::Selector::getIdentifierInfoForSlot(), Import(), and clang::Selector::isNull().

◆ Import() [14/16]

FileID ASTImporter::Import ( FileID  FromID)

◆ Import() [15/16]

CXXCtorInitializer * ASTImporter::Import ( CXXCtorInitializer FromInit)

◆ Import() [16/16]

CXXBaseSpecifier * ASTImporter::Import ( const CXXBaseSpecifier FromSpec)

◆ ImportContext()

DeclContext * ASTImporter::ImportContext ( DeclContext FromDC)

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

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

Definition at line 6065 of file ASTImporter.cpp.

References CompleteDecl(), clang::ObjCInterfaceDecl::getDefinition(), clang::ObjCProtocolDecl::getDefinition(), clang::ASTNodeImporter::IDK_Basic, Import(), clang::ASTNodeImporter::ImportDefinition(), and clang::TagDecl::isCompleteDefinition().

Referenced by isMinimalImport().

◆ ImportDefinition()

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 6489 of file ASTImporter.cpp.

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

Referenced by clang::ExternalASTMerger::CompleteType(), and isMinimalImport().

◆ Imported()

Decl * ASTImporter::Imported ( Decl From,
Decl To 
)
virtual

Note that we have imported the "from" declaration by mapping it to the (potentially-newly-created) "to" declaration.

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

Definition at line 6664 of file ASTImporter.cpp.

References clang::Decl::addAttr(), clang::Decl::getASTContext(), clang::Decl::getAttrs(), clang::Decl::hasAttrs(), clang::Decl::isImplicit(), clang::Decl::isUsed(), clang::Decl::setImplicit(), and clang::Decl::setIsUsed().

Referenced by clang::ExternalASTMerger::CompleteType(), getNonEquivalentDecls(), and Import().

◆ isMinimalImport()

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 110 of file ASTImporter.h.

References GetAlreadyImportedOrNull(), HandleNameConflict(), Import(), ImportContext(), and ImportDefinition().

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

◆ IsStructurallyEquivalent()

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

Determine whether the given types are structurally equivalent.

Definition at line 6679 of file ASTImporter.cpp.

References clang::QualType::getTypePtr(), clang::ASTContext::hasSameType(), Import(), and clang::StructuralEquivalenceContext::IsStructurallyEquivalent().

Referenced by GetOriginalDecl().

◆ ToDiag()

DiagnosticBuilder ASTImporter::ToDiag ( SourceLocation  Loc,
unsigned  DiagID 
)

Report a diagnostic in the "to" context.

Definition at line 6628 of file ASTImporter.cpp.

References clang::ASTContext::getDiagnostics(), clang::DiagnosticsEngine::notePriorDiagnosticFrom(), and clang::DiagnosticsEngine::Report().

Referenced by getFromFileManager().


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