[ASTImporter] Added Import functions for transition to new API.

Summary:
These Import_New functions should be used in the ASTImporter,
and the old Import functions should not be used. Later the
Import_New should be renamed to Import again and the old Import
functions must be removed. But this can happen only after LLDB
was updated to use the new Import interface.

This commit is only about introducing the new Import_New
functions. These are not implemented now, only calling the old
Import ones.

Reviewers: shafik, rsmith, a_sidorin, a.sidorin

Reviewed By: a_sidorin

Subscribers: spyffe, a_sidorin, gamesh411, shafik, rsmith, dkrupp, martong, Szelethus, cfe-commits

Differential Revision: https://reviews.llvm.org/D53751

llvm-svn: 347685
This commit is contained in:
Balazs Keri 2018-11-27 18:36:31 +00:00
parent 7ceef03dc9
commit 4a3d758ae4
2 changed files with 167 additions and 32 deletions

View File

@ -166,30 +166,41 @@ class Attr;
} }
/// Import the given type from the "from" context into the "to" /// Import the given type from the "from" context into the "to"
/// context. /// context. A null type is imported as a null type (no error).
/// ///
/// \returns the equivalent type in the "to" context, or a NULL type if /// \returns The equivalent type in the "to" context, or the import error.
/// an error occurred. llvm::Expected<QualType> Import_New(QualType FromT);
// FIXME: Remove this version.
QualType Import(QualType FromT); QualType Import(QualType FromT);
/// Import the given type source information from the /// Import the given type source information from the
/// "from" context into the "to" context. /// "from" context into the "to" context.
/// ///
/// \returns the equivalent type source information in the "to" /// \returns The equivalent type source information in the "to"
/// context, or NULL if an error occurred. /// context, or the import error.
llvm::Expected<TypeSourceInfo *> Import_New(TypeSourceInfo *FromTSI);
// FIXME: Remove this version.
TypeSourceInfo *Import(TypeSourceInfo *FromTSI); TypeSourceInfo *Import(TypeSourceInfo *FromTSI);
/// Import the given attribute from the "from" context into the /// Import the given attribute from the "from" context into the
/// "to" context. /// "to" context.
/// ///
/// \returns the equivalent attribute in the "to" context. /// \returns The equivalent attribute in the "to" context, or the import
/// error.
llvm::Expected<Attr *> Import_New(const Attr *FromAttr);
// FIXME: Remove this version.
Attr *Import(const Attr *FromAttr); Attr *Import(const Attr *FromAttr);
/// Import the given declaration from the "from" context into the /// Import the given declaration from the "from" context into the
/// "to" context. /// "to" context.
/// ///
/// \returns the equivalent declaration in the "to" context, or a NULL type /// \returns The equivalent declaration in the "to" context, or the import
/// if an error occurred. /// error.
llvm::Expected<Decl *> Import_New(Decl *FromD);
llvm::Expected<Decl *> Import_New(const Decl *FromD) {
return Import_New(const_cast<Decl *>(FromD));
}
// FIXME: Remove this version.
Decl *Import(Decl *FromD); Decl *Import(Decl *FromD);
Decl *Import(const Decl *FromD) { Decl *Import(const Decl *FromD) {
return Import(const_cast<Decl *>(FromD)); return Import(const_cast<Decl *>(FromD));
@ -210,87 +221,117 @@ class Attr;
/// Import the given expression from the "from" context into the /// Import the given expression from the "from" context into the
/// "to" context. /// "to" context.
/// ///
/// \returns the equivalent expression in the "to" context, or NULL if /// \returns The equivalent expression in the "to" context, or the import
/// an error occurred. /// error.
llvm::Expected<Expr *> Import_New(Expr *FromE);
// FIXME: Remove this version.
Expr *Import(Expr *FromE); Expr *Import(Expr *FromE);
/// Import the given statement from the "from" context into the /// Import the given statement from the "from" context into the
/// "to" context. /// "to" context.
/// ///
/// \returns the equivalent statement in the "to" context, or NULL if /// \returns The equivalent statement in the "to" context, or the import
/// an error occurred. /// error.
llvm::Expected<Stmt *> Import_New(Stmt *FromS);
// FIXME: Remove this version.
Stmt *Import(Stmt *FromS); Stmt *Import(Stmt *FromS);
/// Import the given nested-name-specifier from the "from" /// Import the given nested-name-specifier from the "from"
/// context into the "to" context. /// context into the "to" context.
/// ///
/// \returns the equivalent nested-name-specifier in the "to" /// \returns The equivalent nested-name-specifier in the "to"
/// context, or NULL if an error occurred. /// context, or the import error.
llvm::Expected<NestedNameSpecifier *>
Import_New(NestedNameSpecifier *FromNNS);
// FIXME: Remove this version.
NestedNameSpecifier *Import(NestedNameSpecifier *FromNNS); NestedNameSpecifier *Import(NestedNameSpecifier *FromNNS);
/// Import the given nested-name-specifier from the "from" /// Import the given nested-name-specifier-loc from the "from"
/// context into the "to" context. /// context into the "to" context.
/// ///
/// \returns the equivalent nested-name-specifier in the "to" /// \returns The equivalent nested-name-specifier-loc in the "to"
/// context. /// context, or the import error.
llvm::Expected<NestedNameSpecifierLoc>
Import_New(NestedNameSpecifierLoc FromNNS);
// FIXME: Remove this version.
NestedNameSpecifierLoc Import(NestedNameSpecifierLoc FromNNS); NestedNameSpecifierLoc Import(NestedNameSpecifierLoc FromNNS);
/// Import the goven template name from the "from" context into the /// Import the given template name from the "from" context into the
/// "to" context. /// "to" context, or the import error.
llvm::Expected<TemplateName> Import_New(TemplateName From);
// FIXME: Remove this version.
TemplateName Import(TemplateName From); TemplateName Import(TemplateName From);
/// Import the given source location from the "from" context into /// Import the given source location from the "from" context into
/// the "to" context. /// the "to" context.
/// ///
/// \returns the equivalent source location in the "to" context, or an /// \returns The equivalent source location in the "to" context, or the
/// invalid source location if an error occurred. /// import error.
llvm::Expected<SourceLocation> Import_New(SourceLocation FromLoc);
// FIXME: Remove this version.
SourceLocation Import(SourceLocation FromLoc); SourceLocation Import(SourceLocation FromLoc);
/// Import the given source range from the "from" context into /// Import the given source range from the "from" context into
/// the "to" context. /// the "to" context.
/// ///
/// \returns the equivalent source range in the "to" context, or an /// \returns The equivalent source range in the "to" context, or the import
/// invalid source location if an error occurred. /// error.
llvm::Expected<SourceRange> Import_New(SourceRange FromRange);
// FIXME: Remove this version.
SourceRange Import(SourceRange FromRange); SourceRange Import(SourceRange FromRange);
/// Import the given declaration name from the "from" /// Import the given declaration name from the "from"
/// context into the "to" context. /// context into the "to" context.
/// ///
/// \returns the equivalent declaration name in the "to" context, /// \returns The equivalent declaration name in the "to" context, or the
/// or an empty declaration name if an error occurred. /// import error.
llvm::Expected<DeclarationName> Import_New(DeclarationName FromName);
// FIXME: Remove this version.
DeclarationName Import(DeclarationName FromName); DeclarationName Import(DeclarationName FromName);
/// Import the given identifier from the "from" context /// Import the given identifier from the "from" context
/// into the "to" context. /// into the "to" context.
/// ///
/// \returns the equivalent identifier in the "to" context. Note: It /// \returns The equivalent identifier in the "to" context. Note: It
/// returns nullptr only if the FromId was nullptr. /// returns nullptr only if the FromId was nullptr.
IdentifierInfo *Import(const IdentifierInfo *FromId); IdentifierInfo *Import(const IdentifierInfo *FromId);
/// Import the given Objective-C selector from the "from" /// Import the given Objective-C selector from the "from"
/// context into the "to" context. /// context into the "to" context.
/// ///
/// \returns the equivalent selector in the "to" context. /// \returns The equivalent selector in the "to" context, or the import
/// error.
llvm::Expected<Selector> Import_New(Selector FromSel);
// FIXME: Remove this version.
Selector Import(Selector FromSel); Selector Import(Selector FromSel);
/// Import the given file ID from the "from" context into the /// Import the given file ID from the "from" context into the
/// "to" context. /// "to" context.
/// ///
/// \returns the equivalent file ID in the source manager of the "to" /// \returns The equivalent file ID in the source manager of the "to"
/// context. /// context, or the import error.
llvm::Expected<FileID> Import_New(FileID);
// FIXME: Remove this version.
FileID Import(FileID); FileID Import(FileID);
/// Import the given C++ constructor initializer from the "from" /// Import the given C++ constructor initializer from the "from"
/// context into the "to" context. /// context into the "to" context.
/// ///
/// \returns the equivalent initializer in the "to" context. /// \returns The equivalent initializer in the "to" context, or the import
/// error.
llvm::Expected<CXXCtorInitializer *>
Import_New(CXXCtorInitializer *FromInit);
// FIXME: Remove this version.
CXXCtorInitializer *Import(CXXCtorInitializer *FromInit); CXXCtorInitializer *Import(CXXCtorInitializer *FromInit);
/// Import the given CXXBaseSpecifier from the "from" context into /// Import the given CXXBaseSpecifier from the "from" context into
/// the "to" context. /// the "to" context.
/// ///
/// \returns the equivalent CXXBaseSpecifier in the source manager of the /// \returns The equivalent CXXBaseSpecifier in the source manager of the
/// "to" context. /// "to" context, or the import error.
llvm::Expected<CXXBaseSpecifier *>
Import_New(const CXXBaseSpecifier *FromSpec);
// FIXME: Remove this version.
CXXBaseSpecifier *Import(const CXXBaseSpecifier *FromSpec); CXXBaseSpecifier *Import(const CXXBaseSpecifier *FromSpec);
/// Import the definition of the given declaration, including all of /// Import the definition of the given declaration, including all of

View File

@ -7683,6 +7683,12 @@ ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager,
ASTImporter::~ASTImporter() = default; ASTImporter::~ASTImporter() = default;
Expected<QualType> ASTImporter::Import_New(QualType FromT) {
QualType ToT = Import(FromT);
if (ToT.isNull() && !FromT.isNull())
return make_error<ImportError>();
return ToT;
}
QualType ASTImporter::Import(QualType FromT) { QualType ASTImporter::Import(QualType FromT) {
if (FromT.isNull()) if (FromT.isNull())
return {}; return {};
@ -7709,6 +7715,12 @@ QualType ASTImporter::Import(QualType FromT) {
return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers());
} }
Expected<TypeSourceInfo *> ASTImporter::Import_New(TypeSourceInfo *FromTSI) {
TypeSourceInfo *ToTSI = Import(FromTSI);
if (!ToTSI && FromTSI)
return llvm::make_error<ImportError>();
return ToTSI;
}
TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) {
if (!FromTSI) if (!FromTSI)
return FromTSI; return FromTSI;
@ -7723,8 +7735,12 @@ TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) {
T, Import(FromTSI->getTypeLoc().getBeginLoc())); T, Import(FromTSI->getTypeLoc().getBeginLoc()));
} }
Expected<Attr *> ASTImporter::Import_New(const Attr *FromAttr) {
return Import(FromAttr);
}
Attr *ASTImporter::Import(const Attr *FromAttr) { Attr *ASTImporter::Import(const Attr *FromAttr) {
Attr *ToAttr = FromAttr->clone(ToContext); Attr *ToAttr = FromAttr->clone(ToContext);
// NOTE: Import of SourceRange may fail.
ToAttr->setRange(Import(FromAttr->getRange())); ToAttr->setRange(Import(FromAttr->getRange()));
return ToAttr; return ToAttr;
} }
@ -7742,6 +7758,12 @@ Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) {
} }
} }
Expected<Decl *> ASTImporter::Import_New(Decl *FromD) {
Decl *ToD = Import(FromD);
if (!ToD && FromD)
return llvm::make_error<ImportError>();
return ToD;
}
Decl *ASTImporter::Import(Decl *FromD) { Decl *ASTImporter::Import(Decl *FromD) {
if (!FromD) if (!FromD)
return nullptr; return nullptr;
@ -7830,6 +7852,12 @@ Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) {
return ToDC; return ToDC;
} }
Expected<Expr *> ASTImporter::Import_New(Expr *FromE) {
Expr *ToE = Import(FromE);
if (!ToE && FromE)
return llvm::make_error<ImportError>();
return ToE;
}
Expr *ASTImporter::Import(Expr *FromE) { Expr *ASTImporter::Import(Expr *FromE) {
if (!FromE) if (!FromE)
return nullptr; return nullptr;
@ -7837,6 +7865,12 @@ Expr *ASTImporter::Import(Expr *FromE) {
return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); return cast_or_null<Expr>(Import(cast<Stmt>(FromE)));
} }
Expected<Stmt *> ASTImporter::Import_New(Stmt *FromS) {
Stmt *ToS = Import(FromS);
if (!ToS && FromS)
return llvm::make_error<ImportError>();
return ToS;
}
Stmt *ASTImporter::Import(Stmt *FromS) { Stmt *ASTImporter::Import(Stmt *FromS) {
if (!FromS) if (!FromS)
return nullptr; return nullptr;
@ -7872,6 +7906,13 @@ Stmt *ASTImporter::Import(Stmt *FromS) {
return *ToSOrErr; return *ToSOrErr;
} }
Expected<NestedNameSpecifier *>
ASTImporter::Import_New(NestedNameSpecifier *FromNNS) {
NestedNameSpecifier *ToNNS = Import(FromNNS);
if (!ToNNS && FromNNS)
return llvm::make_error<ImportError>();
return ToNNS;
}
NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) {
if (!FromNNS) if (!FromNNS)
return nullptr; return nullptr;
@ -7925,6 +7966,11 @@ NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) {
llvm_unreachable("Invalid nested name specifier kind"); llvm_unreachable("Invalid nested name specifier kind");
} }
Expected<NestedNameSpecifierLoc>
ASTImporter::Import_New(NestedNameSpecifierLoc FromNNS) {
NestedNameSpecifierLoc ToNNS = Import(FromNNS);
return ToNNS;
}
NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) {
// Copied from NestedNameSpecifier mostly. // Copied from NestedNameSpecifier mostly.
SmallVector<NestedNameSpecifierLoc , 8> NestedNames; SmallVector<NestedNameSpecifierLoc , 8> NestedNames;
@ -7996,6 +8042,12 @@ NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) {
return Builder.getWithLocInContext(getToContext()); return Builder.getWithLocInContext(getToContext());
} }
Expected<TemplateName> ASTImporter::Import_New(TemplateName From) {
TemplateName To = Import(From);
if (To.isNull() && !From.isNull())
return llvm::make_error<ImportError>();
return To;
}
TemplateName ASTImporter::Import(TemplateName From) { TemplateName ASTImporter::Import(TemplateName From) {
switch (From.getKind()) { switch (From.getKind()) {
case TemplateName::Template: case TemplateName::Template:
@ -8086,6 +8138,12 @@ TemplateName ASTImporter::Import(TemplateName From) {
llvm_unreachable("Invalid template name kind"); llvm_unreachable("Invalid template name kind");
} }
Expected<SourceLocation> ASTImporter::Import_New(SourceLocation FromLoc) {
SourceLocation ToLoc = Import(FromLoc);
if (ToLoc.isInvalid() && !FromLoc.isInvalid())
return llvm::make_error<ImportError>();
return ToLoc;
}
SourceLocation ASTImporter::Import(SourceLocation FromLoc) { SourceLocation ASTImporter::Import(SourceLocation FromLoc) {
if (FromLoc.isInvalid()) if (FromLoc.isInvalid())
return {}; return {};
@ -8100,10 +8158,20 @@ SourceLocation ASTImporter::Import(SourceLocation FromLoc) {
return ToSM.getComposedLoc(ToFileID, Decomposed.second); return ToSM.getComposedLoc(ToFileID, Decomposed.second);
} }
Expected<SourceRange> ASTImporter::Import_New(SourceRange FromRange) {
SourceRange ToRange = Import(FromRange);
return ToRange;
}
SourceRange ASTImporter::Import(SourceRange FromRange) { SourceRange ASTImporter::Import(SourceRange FromRange) {
return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd()));
} }
Expected<FileID> ASTImporter::Import_New(FileID FromID) {
FileID ToID = Import(FromID);
if (ToID.isInvalid() && FromID.isValid())
return llvm::make_error<ImportError>();
return ToID;
}
FileID ASTImporter::Import(FileID FromID) { FileID ASTImporter::Import(FileID FromID) {
llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
if (Pos != ImportedFileIDs.end()) if (Pos != ImportedFileIDs.end())
@ -8161,6 +8229,13 @@ FileID ASTImporter::Import(FileID FromID) {
return ToID; return ToID;
} }
Expected<CXXCtorInitializer *>
ASTImporter::Import_New(CXXCtorInitializer *From) {
CXXCtorInitializer *To = Import(From);
if (!To && From)
return llvm::make_error<ImportError>();
return To;
}
CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) {
Expr *ToExpr = Import(From->getInit()); Expr *ToExpr = Import(From->getInit());
if (!ToExpr && From->getInit()) if (!ToExpr && From->getInit())
@ -8206,6 +8281,13 @@ CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) {
} }
} }
Expected<CXXBaseSpecifier *>
ASTImporter::Import_New(const CXXBaseSpecifier *From) {
CXXBaseSpecifier *To = Import(From);
if (!To && From)
return llvm::make_error<ImportError>();
return To;
}
CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) {
auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
if (Pos != ImportedCXXBaseSpecifiers.end()) if (Pos != ImportedCXXBaseSpecifiers.end())
@ -8271,6 +8353,12 @@ void ASTImporter::ImportDefinition(Decl *From) {
llvm::consumeError(std::move(Err)); llvm::consumeError(std::move(Err));
} }
Expected<DeclarationName> ASTImporter::Import_New(DeclarationName FromName) {
DeclarationName ToName = Import(FromName);
if (!ToName && FromName)
return llvm::make_error<ImportError>();
return ToName;
}
DeclarationName ASTImporter::Import(DeclarationName FromName) { DeclarationName ASTImporter::Import(DeclarationName FromName) {
if (!FromName) if (!FromName)
return {}; return {};
@ -8347,6 +8435,12 @@ IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) {
return ToId; return ToId;
} }
Expected<Selector> ASTImporter::Import_New(Selector FromSel) {
Selector ToSel = Import(FromSel);
if (ToSel.isNull() && !FromSel.isNull())
return llvm::make_error<ImportError>();
return ToSel;
}
Selector ASTImporter::Import(Selector FromSel) { Selector ASTImporter::Import(Selector FromSel) {
if (FromSel.isNull()) if (FromSel.isNull())
return {}; return {};