/// \return Error information (success or error).
template <typename ImportT>
LLVM_NODISCARD llvm::Error importInto(ImportT &To, const ImportT &From) {
- auto ToOrErr = Import_New(From);
+ auto ToOrErr = Import(From);
if (ToOrErr)
To = *ToOrErr;
return ToOrErr.takeError();
/// context. A null type is imported as a null type (no error).
///
/// \returns The equivalent type in the "to" context, or the import error.
- llvm::Expected<QualType> Import_New(QualType FromT);
- // FIXME: Remove this version.
- QualType Import(QualType FromT);
+ llvm::Expected<QualType> Import(QualType FromT);
/// 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 the import error.
- llvm::Expected<TypeSourceInfo *> Import_New(TypeSourceInfo *FromTSI);
- // FIXME: Remove this version.
- TypeSourceInfo *Import(TypeSourceInfo *FromTSI);
+ llvm::Expected<TypeSourceInfo *> Import(TypeSourceInfo *FromTSI);
/// Import the given attribute from the "from" context into 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);
+ llvm::Expected<Attr *> Import(const Attr *FromAttr);
/// Import the given declaration from the "from" context into the
/// "to" context.
///
/// \returns The equivalent declaration in the "to" context, or the import
/// error.
- llvm::Expected<Decl *> Import_New(Decl *FromD);
- llvm::Expected<const Decl *> Import_New(const Decl *FromD) {
- return Import_New(const_cast<Decl *>(FromD));
- }
- // FIXME: Remove this version.
- Decl *Import(Decl *FromD);
- Decl *Import(const Decl *FromD) {
+ llvm::Expected<Decl *> Import(Decl *FromD);
+ llvm::Expected<const Decl *> Import(const Decl *FromD) {
return Import(const_cast<Decl *>(FromD));
}
///
/// \returns The equivalent expression in the "to" context, or the import
/// error.
- llvm::Expected<Expr *> Import_New(Expr *FromE);
- // FIXME: Remove this version.
- Expr *Import(Expr *FromE);
+ llvm::Expected<Expr *> Import(Expr *FromE);
/// Import the given statement from the "from" context into the
/// "to" context.
///
/// \returns The equivalent statement in the "to" context, or the import
/// error.
- llvm::Expected<Stmt *> Import_New(Stmt *FromS);
- // FIXME: Remove this version.
- Stmt *Import(Stmt *FromS);
+ llvm::Expected<Stmt *> Import(Stmt *FromS);
/// 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.
- llvm::Expected<NestedNameSpecifier *>
- Import_New(NestedNameSpecifier *FromNNS);
- // FIXME: Remove this version.
- NestedNameSpecifier *Import(NestedNameSpecifier *FromNNS);
+ llvm::Expected<NestedNameSpecifier *> Import(NestedNameSpecifier *FromNNS);
/// 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.
llvm::Expected<NestedNameSpecifierLoc>
- Import_New(NestedNameSpecifierLoc FromNNS);
- // FIXME: Remove this version.
- NestedNameSpecifierLoc Import(NestedNameSpecifierLoc FromNNS);
+ Import(NestedNameSpecifierLoc FromNNS);
/// Import the given template name from the "from" context into the
/// "to" context, or the import error.
- llvm::Expected<TemplateName> Import_New(TemplateName From);
- // FIXME: Remove this version.
- TemplateName Import(TemplateName From);
+ llvm::Expected<TemplateName> Import(TemplateName From);
/// Import the given source location from the "from" context into
/// the "to" context.
///
/// \returns The equivalent source location in the "to" context, or the
/// import error.
- llvm::Expected<SourceLocation> Import_New(SourceLocation FromLoc);
- // FIXME: Remove this version.
- SourceLocation Import(SourceLocation FromLoc);
+ llvm::Expected<SourceLocation> Import(SourceLocation FromLoc);
/// Import the given source range from the "from" context into
/// the "to" context.
///
/// \returns The equivalent source range in the "to" context, or the import
/// error.
- llvm::Expected<SourceRange> Import_New(SourceRange FromRange);
- // FIXME: Remove this version.
- SourceRange Import(SourceRange FromRange);
+ llvm::Expected<SourceRange> Import(SourceRange FromRange);
/// 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.
- llvm::Expected<DeclarationName> Import_New(DeclarationName FromName);
- // FIXME: Remove this version.
- DeclarationName Import(DeclarationName FromName);
+ llvm::Expected<DeclarationName> Import(DeclarationName FromName);
/// Import the given identifier from the "from" context
/// into 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);
+ llvm::Expected<Selector> Import(Selector FromSel);
/// 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.
- llvm::Expected<FileID> Import_New(FileID, bool IsBuiltin = false);
- // FIXME: Remove this version.
- FileID Import(FileID, bool IsBuiltin = false);
+ llvm::Expected<FileID> Import(FileID, bool IsBuiltin = false);
/// 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.
- llvm::Expected<CXXCtorInitializer *>
- Import_New(CXXCtorInitializer *FromInit);
- // FIXME: Remove this version.
- CXXCtorInitializer *Import(CXXCtorInitializer *FromInit);
+ llvm::Expected<CXXCtorInitializer *> Import(CXXCtorInitializer *FromInit);
/// Import the given CXXBaseSpecifier from the "from" context into
/// the "to" context.
///
/// \returns The equivalent CXXBaseSpecifier in the source manager of the
/// "to" context, or the import error.
- llvm::Expected<CXXBaseSpecifier *>
- Import_New(const CXXBaseSpecifier *FromSpec);
- // FIXME: Remove this version.
- CXXBaseSpecifier *Import(const CXXBaseSpecifier *FromSpec);
+ llvm::Expected<CXXBaseSpecifier *> Import(const CXXBaseSpecifier *FromSpec);
/// Import the definition of the given declaration, including all of
/// the declarations it contains.
- LLVM_NODISCARD llvm::Error ImportDefinition_New(Decl *From);
-
- // FIXME: Compatibility function.
- // Usages of this should be changed to ImportDefinition_New.
- void ImportDefinition(Decl *From);
+ LLVM_NODISCARD llvm::Error ImportDefinition(Decl *From);
/// Cope with a name conflict when importing a declaration into the
/// given context.
// Use this to import pointers of specific type.
template <typename ImportT>
LLVM_NODISCARD Error importInto(ImportT *&To, ImportT *From) {
- auto ToOrErr = Importer.Import_New(From);
+ auto ToOrErr = Importer.Import(From);
if (ToOrErr)
To = cast_or_null<ImportT>(*ToOrErr);
return ToOrErr.takeError();
// cast the return value to `T`.
template <typename T>
Expected<T *> import(T *From) {
- auto ToOrErr = Importer.Import_New(From);
+ auto ToOrErr = Importer.Import(From);
if (!ToOrErr)
return ToOrErr.takeError();
return cast_or_null<T>(*ToOrErr);
// Call the import function of ASTImporter for type `T`.
template <typename T>
Expected<T> import(const T &From) {
- return Importer.Import_New(From);
+ return Importer.Import(From);
}
// Import an Optional<T> by importing the contained T, if any.
static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To,
ASTImporter &Importer) {
if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
- if (ExpectedDecl ToTypedefOrErr = Importer.Import_New(FromTypedef))
+ if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef))
To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr));
else
return ToTypedefOrErr.takeError();
Importer.MapImported(D, PrevDecl->getDefinition());
// Import those default field initializers which have been
// instantiated in the "From" context, but not in the "To" context.
- for (auto *FromField : D->fields())
- Importer.Import(FromField);
+ for (auto *FromField : D->fields()) {
+ auto ToOrErr = import(FromField);
+ if (!ToOrErr)
+ return ToOrErr.takeError();
+ }
// Import those methods which have been instantiated in the
// "From" context, but not in the "To" context.
- for (CXXMethodDecl *FromM : D->methods())
- Importer.Import(FromM);
+ for (CXXMethodDecl *FromM : D->methods()) {
+ auto ToOrErr = import(FromM);
+ if (!ToOrErr)
+ return ToOrErr.takeError();
+ }
// TODO Import instantiated default arguments.
// TODO Import instantiated exception specifications.
AddToLookupTable(ToD);
}
-Expected<QualType> ASTImporter::Import_New(QualType FromT) {
+Expected<QualType> ASTImporter::Import(QualType FromT) {
if (FromT.isNull())
return QualType{};
return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers());
}
-QualType ASTImporter::Import(QualType From) {
- llvm::Expected<QualType> To = Import_New(From);
- if (To)
- return *To;
- else
- llvm::consumeError(To.takeError());
- return {};
-}
-Expected<TypeSourceInfo *> ASTImporter::Import_New(TypeSourceInfo *FromTSI) {
+Expected<TypeSourceInfo *> ASTImporter::Import(TypeSourceInfo *FromTSI) {
if (!FromTSI)
return FromTSI;
// FIXME: For now we just create a "trivial" type source info based
// on the type and a single location. Implement a real version of this.
- ExpectedType TOrErr = Import_New(FromTSI->getType());
+ ExpectedType TOrErr = Import(FromTSI->getType());
if (!TOrErr)
return TOrErr.takeError();
- ExpectedSLoc BeginLocOrErr = Import_New(FromTSI->getTypeLoc().getBeginLoc());
+ ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
if (!BeginLocOrErr)
return BeginLocOrErr.takeError();
return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
}
-TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *From) {
- llvm::Expected<TypeSourceInfo *> To = Import_New(From);
- if (To)
- return *To;
- else
- llvm::consumeError(To.takeError());
- return nullptr;
-}
-Expected<Attr *> ASTImporter::Import_New(const Attr *FromAttr) {
+Expected<Attr *> ASTImporter::Import(const Attr *FromAttr) {
Attr *ToAttr = FromAttr->clone(ToContext);
- if (auto ToRangeOrErr = Import_New(FromAttr->getRange()))
+ if (auto ToRangeOrErr = Import(FromAttr->getRange()))
ToAttr->setRange(*ToRangeOrErr);
else
return ToRangeOrErr.takeError();
return ToAttr;
}
-Attr *ASTImporter::Import(const Attr *From) {
- llvm::Expected<Attr *> To = Import_New(From);
- if (To)
- return *To;
- else
- llvm::consumeError(To.takeError());
- return nullptr;
-}
Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const {
auto Pos = ImportedDecls.find(FromD);
return FromDPos->second->getTranslationUnitDecl();
}
-Expected<Decl *> ASTImporter::Import_New(Decl *FromD) {
+Expected<Decl *> ASTImporter::Import(Decl *FromD) {
if (!FromD)
return nullptr;
updateFlags(FromD, ToD);
return ToDOrErr;
}
-Decl *ASTImporter::Import(Decl *From) {
- llvm::Expected<Decl *> To = Import_New(From);
- if (To)
- return *To;
- else
- llvm::consumeError(To.takeError());
- return nullptr;
-}
Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) {
if (!FromDC)
return FromDC;
- ExpectedDecl ToDCOrErr = Import_New(cast<Decl>(FromDC));
+ ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
if (!ToDCOrErr)
return ToDCOrErr.takeError();
auto *ToDC = cast<DeclContext>(*ToDCOrErr);
return ToDC;
}
-Expected<Expr *> ASTImporter::Import_New(Expr *FromE) {
- if (ExpectedStmt ToSOrErr = Import_New(cast_or_null<Stmt>(FromE)))
+Expected<Expr *> ASTImporter::Import(Expr *FromE) {
+ if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
return cast_or_null<Expr>(*ToSOrErr);
else
return ToSOrErr.takeError();
}
-Expr *ASTImporter::Import(Expr *From) {
- llvm::Expected<Expr *> To = Import_New(From);
- if (To)
- return *To;
- else
- llvm::consumeError(To.takeError());
- return nullptr;
-}
-Expected<Stmt *> ASTImporter::Import_New(Stmt *FromS) {
+Expected<Stmt *> ASTImporter::Import(Stmt *FromS) {
if (!FromS)
return nullptr;
ImportedStmts[FromS] = *ToSOrErr;
return ToSOrErr;
}
-Stmt *ASTImporter::Import(Stmt *From) {
- llvm::Expected<Stmt *> To = Import_New(From);
- if (To)
- return *To;
- else
- llvm::consumeError(To.takeError());
- return nullptr;
-}
Expected<NestedNameSpecifier *>
-ASTImporter::Import_New(NestedNameSpecifier *FromNNS) {
+ASTImporter::Import(NestedNameSpecifier *FromNNS) {
if (!FromNNS)
return nullptr;
Import(FromNNS->getAsIdentifier()));
case NestedNameSpecifier::Namespace:
- if (ExpectedDecl NSOrErr = Import_New(FromNNS->getAsNamespace())) {
+ if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) {
return NestedNameSpecifier::Create(ToContext, Prefix,
cast<NamespaceDecl>(*NSOrErr));
} else
return NSOrErr.takeError();
case NestedNameSpecifier::NamespaceAlias:
- if (ExpectedDecl NSADOrErr = Import_New(FromNNS->getAsNamespaceAlias()))
+ if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias()))
return NestedNameSpecifier::Create(ToContext, Prefix,
cast<NamespaceAliasDecl>(*NSADOrErr));
else
return NestedNameSpecifier::GlobalSpecifier(ToContext);
case NestedNameSpecifier::Super:
- if (ExpectedDecl RDOrErr = Import_New(FromNNS->getAsRecordDecl()))
+ if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl()))
return NestedNameSpecifier::SuperSpecifier(ToContext,
cast<CXXRecordDecl>(*RDOrErr));
else
case NestedNameSpecifier::TypeSpec:
case NestedNameSpecifier::TypeSpecWithTemplate:
if (Expected<QualType> TyOrErr =
- Import_New(QualType(FromNNS->getAsType(), 0u))) {
+ Import(QualType(FromNNS->getAsType(), 0u))) {
bool TSTemplate =
FromNNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate;
return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate,
llvm_unreachable("Invalid nested name specifier kind");
}
-NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *From) {
- llvm::Expected<NestedNameSpecifier *> To = Import_New(From);
- if (To)
- return *To;
- else
- llvm::consumeError(To.takeError());
- return nullptr;
-}
Expected<NestedNameSpecifierLoc>
-ASTImporter::Import_New(NestedNameSpecifierLoc FromNNS) {
+ASTImporter::Import(NestedNameSpecifierLoc FromNNS) {
// Copied from NestedNameSpecifier mostly.
SmallVector<NestedNameSpecifierLoc , 8> NestedNames;
NestedNameSpecifierLoc NNS = FromNNS;
break;
case NestedNameSpecifier::Super: {
- auto ToSourceRangeOrErr = Import_New(NNS.getSourceRange());
+ auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
if (!ToSourceRangeOrErr)
return ToSourceRangeOrErr.takeError();
return Builder.getWithLocInContext(getToContext());
}
-NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc From) {
- llvm::Expected<NestedNameSpecifierLoc> To = Import_New(From);
- if (To)
- return *To;
- else
- llvm::consumeError(To.takeError());
- return {};
-}
-Expected<TemplateName> ASTImporter::Import_New(TemplateName From) {
+Expected<TemplateName> ASTImporter::Import(TemplateName From) {
switch (From.getKind()) {
case TemplateName::Template:
- if (ExpectedDecl ToTemplateOrErr = Import_New(From.getAsTemplateDecl()))
+ if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
return TemplateName(cast<TemplateDecl>(*ToTemplateOrErr));
else
return ToTemplateOrErr.takeError();
OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate();
UnresolvedSet<2> ToTemplates;
for (auto *I : *FromStorage) {
- if (auto ToOrErr = Import_New(I))
+ if (auto ToOrErr = Import(I))
ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
else
return ToOrErr.takeError();
case TemplateName::AssumedTemplate: {
AssumedTemplateStorage *FromStorage = From.getAsAssumedTemplateName();
- auto DeclNameOrErr = Import_New(FromStorage->getDeclName());
+ auto DeclNameOrErr = Import(FromStorage->getDeclName());
if (!DeclNameOrErr)
return DeclNameOrErr.takeError();
return ToContext.getAssumedTemplateName(*DeclNameOrErr);
case TemplateName::QualifiedTemplate: {
QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName();
- auto QualifierOrErr = Import_New(QTN->getQualifier());
+ auto QualifierOrErr = Import(QTN->getQualifier());
if (!QualifierOrErr)
return QualifierOrErr.takeError();
- if (ExpectedDecl ToTemplateOrErr = Import_New(From.getAsTemplateDecl()))
+ if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
return ToContext.getQualifiedTemplateName(
*QualifierOrErr, QTN->hasTemplateKeyword(),
cast<TemplateDecl>(*ToTemplateOrErr));
case TemplateName::DependentTemplate: {
DependentTemplateName *DTN = From.getAsDependentTemplateName();
- auto QualifierOrErr = Import_New(DTN->getQualifier());
+ auto QualifierOrErr = Import(DTN->getQualifier());
if (!QualifierOrErr)
return QualifierOrErr.takeError();
case TemplateName::SubstTemplateTemplateParm: {
SubstTemplateTemplateParmStorage *Subst =
From.getAsSubstTemplateTemplateParm();
- ExpectedDecl ParamOrErr = Import_New(Subst->getParameter());
+ ExpectedDecl ParamOrErr = Import(Subst->getParameter());
if (!ParamOrErr)
return ParamOrErr.takeError();
- auto ReplacementOrErr = Import_New(Subst->getReplacement());
+ auto ReplacementOrErr = Import(Subst->getReplacement());
if (!ReplacementOrErr)
return ReplacementOrErr.takeError();
case TemplateName::SubstTemplateTemplateParmPack: {
SubstTemplateTemplateParmPackStorage *SubstPack
= From.getAsSubstTemplateTemplateParmPack();
- ExpectedDecl ParamOrErr = Import_New(SubstPack->getParameterPack());
+ ExpectedDecl ParamOrErr = Import(SubstPack->getParameterPack());
if (!ParamOrErr)
return ParamOrErr.takeError();
llvm_unreachable("Invalid template name kind");
}
-TemplateName ASTImporter::Import(TemplateName From) {
- llvm::Expected<TemplateName> To = Import_New(From);
- if (To)
- return *To;
- else
- llvm::consumeError(To.takeError());
- return {};
-}
-Expected<SourceLocation> ASTImporter::Import_New(SourceLocation FromLoc) {
+Expected<SourceLocation> ASTImporter::Import(SourceLocation FromLoc) {
if (FromLoc.isInvalid())
return SourceLocation{};
bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc);
- Expected<FileID> ToFileIDOrErr = Import_New(Decomposed.first, IsBuiltin);
+ Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
if (!ToFileIDOrErr)
return ToFileIDOrErr.takeError();
SourceManager &ToSM = ToContext.getSourceManager();
return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
}
-SourceLocation ASTImporter::Import(SourceLocation From) {
- llvm::Expected<SourceLocation> To = Import_New(From);
- if (To)
- return *To;
- else
- llvm::consumeError(To.takeError());
- return {};
-}
-Expected<SourceRange> ASTImporter::Import_New(SourceRange FromRange) {
+Expected<SourceRange> ASTImporter::Import(SourceRange FromRange) {
SourceLocation ToBegin, ToEnd;
if (Error Err = importInto(ToBegin, FromRange.getBegin()))
return std::move(Err);
return SourceRange(ToBegin, ToEnd);
}
-SourceRange ASTImporter::Import(SourceRange From) {
- llvm::Expected<SourceRange> To = Import_New(From);
- if (To)
- return *To;
- else
- llvm::consumeError(To.takeError());
- return {};
-}
-Expected<FileID> ASTImporter::Import_New(FileID FromID, bool IsBuiltin) {
+Expected<FileID> ASTImporter::Import(FileID FromID, bool IsBuiltin) {
llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
if (Pos != ImportedFileIDs.end())
return Pos->second;
FileID ToID;
if (FromSLoc.isExpansion()) {
const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
- ExpectedSLoc ToSpLoc = Import_New(FromEx.getSpellingLoc());
+ ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
if (!ToSpLoc)
return ToSpLoc.takeError();
- ExpectedSLoc ToExLocS = Import_New(FromEx.getExpansionLocStart());
+ ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
if (!ToExLocS)
return ToExLocS.takeError();
unsigned TokenLen = FromSM.getFileIDSize(FromID);
if (FromEx.isMacroArgExpansion()) {
MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, TokenLen);
} else {
- if (ExpectedSLoc ToExLocE = Import_New(FromEx.getExpansionLocEnd()))
+ if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, TokenLen,
FromEx.isExpansionTokenRange());
else
if (!IsBuiltin) {
// Include location of this file.
- ExpectedSLoc ToIncludeLoc =
- Import_New(FromSLoc.getFile().getIncludeLoc());
+ ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
if (!ToIncludeLoc)
return ToIncludeLoc.takeError();
ImportedFileIDs[FromID] = ToID;
return ToID;
}
-FileID ASTImporter::Import(FileID From, bool IsBuiltin) {
- llvm::Expected<FileID> To = Import_New(From, IsBuiltin);
- if (To)
- return *To;
- else
- llvm::consumeError(To.takeError());
- return {};
-}
-Expected<CXXCtorInitializer *>
-ASTImporter::Import_New(CXXCtorInitializer *From) {
- ExpectedExpr ToExprOrErr = Import_New(From->getInit());
+Expected<CXXCtorInitializer *> ASTImporter::Import(CXXCtorInitializer *From) {
+ ExpectedExpr ToExprOrErr = Import(From->getInit());
if (!ToExprOrErr)
return ToExprOrErr.takeError();
- auto LParenLocOrErr = Import_New(From->getLParenLoc());
+ auto LParenLocOrErr = Import(From->getLParenLoc());
if (!LParenLocOrErr)
return LParenLocOrErr.takeError();
- auto RParenLocOrErr = Import_New(From->getRParenLoc());
+ auto RParenLocOrErr = Import(From->getRParenLoc());
if (!RParenLocOrErr)
return RParenLocOrErr.takeError();
if (From->isBaseInitializer()) {
- auto ToTInfoOrErr = Import_New(From->getTypeSourceInfo());
+ auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
if (!ToTInfoOrErr)
return ToTInfoOrErr.takeError();
ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
*ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
} else if (From->isMemberInitializer()) {
- ExpectedDecl ToFieldOrErr = Import_New(From->getMember());
+ ExpectedDecl ToFieldOrErr = Import(From->getMember());
if (!ToFieldOrErr)
return ToFieldOrErr.takeError();
- auto MemberLocOrErr = Import_New(From->getMemberLocation());
+ auto MemberLocOrErr = Import(From->getMemberLocation());
if (!MemberLocOrErr)
return MemberLocOrErr.takeError();
ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
*LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
} else if (From->isIndirectMemberInitializer()) {
- ExpectedDecl ToIFieldOrErr = Import_New(From->getIndirectMember());
+ ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
if (!ToIFieldOrErr)
return ToIFieldOrErr.takeError();
- auto MemberLocOrErr = Import_New(From->getMemberLocation());
+ auto MemberLocOrErr = Import(From->getMemberLocation());
if (!MemberLocOrErr)
return MemberLocOrErr.takeError();
ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
*MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
} else if (From->isDelegatingInitializer()) {
- auto ToTInfoOrErr = Import_New(From->getTypeSourceInfo());
+ auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
if (!ToTInfoOrErr)
return ToTInfoOrErr.takeError();
return make_error<ImportError>();
}
}
-CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) {
- llvm::Expected<CXXCtorInitializer *> To = Import_New(From);
- if (To)
- return *To;
- else
- llvm::consumeError(To.takeError());
- return nullptr;
-}
Expected<CXXBaseSpecifier *>
-ASTImporter::Import_New(const CXXBaseSpecifier *BaseSpec) {
+ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) {
auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
if (Pos != ImportedCXXBaseSpecifiers.end())
return Pos->second;
- Expected<SourceRange> ToSourceRange = Import_New(BaseSpec->getSourceRange());
+ Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
if (!ToSourceRange)
return ToSourceRange.takeError();
- Expected<TypeSourceInfo *> ToTSI = Import_New(BaseSpec->getTypeSourceInfo());
+ Expected<TypeSourceInfo *> ToTSI = Import(BaseSpec->getTypeSourceInfo());
if (!ToTSI)
return ToTSI.takeError();
- ExpectedSLoc ToEllipsisLoc = Import_New(BaseSpec->getEllipsisLoc());
+ ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
if (!ToEllipsisLoc)
return ToEllipsisLoc.takeError();
CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
return Imported;
}
-CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *From) {
- llvm::Expected<CXXBaseSpecifier *> To = Import_New(From);
- if (To)
- return *To;
- else
- llvm::consumeError(To.takeError());
- return nullptr;
-}
-Error ASTImporter::ImportDefinition_New(Decl *From) {
- Decl *To = Import(From);
- if (!To)
- return llvm::make_error<ImportError>();
+Error ASTImporter::ImportDefinition(Decl *From) {
+ ExpectedDecl ToOrErr = Import(From);
+ if (!ToOrErr)
+ return ToOrErr.takeError();
+ Decl *To = *ToOrErr;
auto *FromDC = cast<DeclContext>(From);
ASTNodeImporter Importer(*this);
return Importer.ImportDeclContext(FromDC, true);
}
-void ASTImporter::ImportDefinition(Decl *From) {
- Error Err = ImportDefinition_New(From);
- llvm::consumeError(std::move(Err));
-}
-
-Expected<DeclarationName> ASTImporter::Import_New(DeclarationName FromName) {
+Expected<DeclarationName> ASTImporter::Import(DeclarationName FromName) {
if (!FromName)
return DeclarationName{};
case DeclarationName::ObjCZeroArgSelector:
case DeclarationName::ObjCOneArgSelector:
case DeclarationName::ObjCMultiArgSelector:
- if (auto ToSelOrErr = Import_New(FromName.getObjCSelector()))
+ if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
return DeclarationName(*ToSelOrErr);
else
return ToSelOrErr.takeError();
case DeclarationName::CXXConstructorName: {
- if (auto ToTyOrErr = Import_New(FromName.getCXXNameType()))
+ if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
return ToContext.DeclarationNames.getCXXConstructorName(
ToContext.getCanonicalType(*ToTyOrErr));
else
}
case DeclarationName::CXXDestructorName: {
- if (auto ToTyOrErr = Import_New(FromName.getCXXNameType()))
+ if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
return ToContext.DeclarationNames.getCXXDestructorName(
ToContext.getCanonicalType(*ToTyOrErr));
else
}
case DeclarationName::CXXDeductionGuideName: {
- if (auto ToTemplateOrErr =
- Import_New(FromName.getCXXDeductionGuideTemplate()))
+ if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
return ToContext.DeclarationNames.getCXXDeductionGuideName(
cast<TemplateDecl>(*ToTemplateOrErr));
else
}
case DeclarationName::CXXConversionFunctionName: {
- if (auto ToTyOrErr = Import_New(FromName.getCXXNameType()))
+ if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
return ToContext.DeclarationNames.getCXXConversionFunctionName(
ToContext.getCanonicalType(*ToTyOrErr));
else
llvm_unreachable("Invalid DeclarationName Kind!");
}
-DeclarationName ASTImporter::Import(DeclarationName From) {
- llvm::Expected<DeclarationName> To = Import_New(From);
- if (To)
- return *To;
- else
- llvm::consumeError(To.takeError());
- return {};
-}
IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) {
if (!FromId)
return ToId;
}
-Expected<Selector> ASTImporter::Import_New(Selector FromSel) {
+Expected<Selector> ASTImporter::Import(Selector FromSel) {
if (FromSel.isNull())
return Selector{};
unsigned NumDecls) {
return Name;
}
-Selector ASTImporter::Import(Selector From) {
- llvm::Expected<Selector> To = Import_New(From);
- if (To)
- return *To;
- else
- llvm::consumeError(To.takeError());
- return {};
-}
DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) {
if (LastDiagFromFrom)
llvm::DenseMap<const Type *, const Type *>::iterator Pos =
ImportedTypes.find(From.getTypePtr());
if (Pos != ImportedTypes.end()) {
- if (ExpectedType ToFromOrErr = Import_New(From)) {
+ if (ExpectedType ToFromOrErr = Import(From)) {
if (ToContext.hasSameType(*ToFromOrErr, To))
return true;
} else {
ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, dst_ast);
- if (delegate_sp)
- return delegate_sp->Import(type);
-
- return QualType();
+ if (!delegate_sp)
+ return QualType();
+
+ llvm::Expected<QualType> ret_or_error = delegate_sp->Import(type);
+ if (!ret_or_error) {
+ Log *log =
+ lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS);
+ LLDB_LOG_ERROR(log, ret_or_error.takeError(),
+ "Couldn't import type: {0}");
+ return QualType();
+ }
+ return *ret_or_error;
}
lldb::opaque_compiler_type_t
ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, dst_ast);
- if (delegate_sp) {
- clang::Decl *result = delegate_sp->Import(decl);
-
- if (!result) {
- Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+ if (!delegate_sp)
+ return nullptr;
- if (log) {
- lldb::user_id_t user_id = LLDB_INVALID_UID;
- ClangASTMetadata *metadata = GetDeclMetadata(decl);
- if (metadata)
- user_id = metadata->GetUserID();
-
- if (NamedDecl *named_decl = dyn_cast<NamedDecl>(decl))
- log->Printf(" [ClangASTImporter] WARNING: Failed to import a %s "
- "'%s', metadata 0x%" PRIx64,
- decl->getDeclKindName(),
- named_decl->getNameAsString().c_str(), user_id);
- else
- log->Printf(" [ClangASTImporter] WARNING: Failed to import a %s, "
- "metadata 0x%" PRIx64,
- decl->getDeclKindName(), user_id);
- }
+ llvm::Expected<clang::Decl *> result = delegate_sp->Import(decl);
+ if (!result) {
+ Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+ LLDB_LOG_ERROR(log, result.takeError(), "Couldn't import decl: {0}");
+ if (log) {
+ lldb::user_id_t user_id = LLDB_INVALID_UID;
+ ClangASTMetadata *metadata = GetDeclMetadata(decl);
+ if (metadata)
+ user_id = metadata->GetUserID();
+
+ if (NamedDecl *named_decl = dyn_cast<NamedDecl>(decl))
+ log->Printf(" [ClangASTImporter] WARNING: Failed to import a %s "
+ "'%s', metadata 0x%" PRIx64,
+ decl->getDeclKindName(),
+ named_decl->getNameAsString().c_str(), user_id);
+ else
+ log->Printf(" [ClangASTImporter] WARNING: Failed to import a %s, "
+ "metadata 0x%" PRIx64,
+ decl->getDeclKindName(), user_id);
}
-
- return result;
+ return nullptr;
}
- return nullptr;
+ return *result;
}
class DeclContextOverride {
if (!RequireCompleteType(type))
return false;
+ Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS);
+
if (const TagType *tag_type = type->getAs<TagType>()) {
TagDecl *tag_decl = tag_type->getDecl();
TagDecl *origin_tag_decl = llvm::dyn_cast<TagDecl>(decl_origin.decl);
for (Decl *origin_child_decl : origin_tag_decl->decls()) {
- delegate_sp->Import(origin_child_decl);
+ llvm::Expected<Decl *> imported_or_err =
+ delegate_sp->Import(origin_child_decl);
+ if (!imported_or_err) {
+ LLDB_LOG_ERROR(log, imported_or_err.takeError(),
+ "Couldn't import decl: {0}");
+ return false;
+ }
}
if (RecordDecl *record_decl = dyn_cast<RecordDecl>(origin_tag_decl)) {
llvm::dyn_cast<ObjCInterfaceDecl>(decl_origin.decl);
for (Decl *origin_child_decl : origin_interface_decl->decls()) {
- delegate_sp->Import(origin_child_decl);
+ llvm::Expected<Decl *> imported_or_err =
+ delegate_sp->Import(origin_child_decl);
+ if (!imported_or_err) {
+ LLDB_LOG_ERROR(log, imported_or_err.takeError(),
+ "Couldn't import decl: {0}");
+ return false;
+ }
}
return true;
to_cxx_record->startDefinition();
*/
- ImportDefinition(from);
+ Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS);
+
+ if (llvm::Error err = ImportDefinition(from)) {
+ LLDB_LOG_ERROR(log, std::move(err),
+ "[ClangASTImporter] Error during importing definition: {0}");
+ return;
+ }
if (clang::TagDecl *to_tag = dyn_cast<clang::TagDecl>(to)) {
if (clang::TagDecl *from_tag = dyn_cast<clang::TagDecl>(from)) {
if (!from_superclass)
break;
- Decl *imported_from_superclass_decl = Import(from_superclass);
+ llvm::Expected<Decl *> imported_from_superclass_decl =
+ Import(from_superclass);
- if (!imported_from_superclass_decl)
+ if (!imported_from_superclass_decl) {
+ LLDB_LOG_ERROR(log, imported_from_superclass_decl.takeError(),
+ "Couldn't import decl: {0}");
break;
+ }
ObjCInterfaceDecl *imported_from_superclass =
- dyn_cast<ObjCInterfaceDecl>(imported_from_superclass_decl);
+ dyn_cast<ObjCInterfaceDecl>(*imported_from_superclass_decl);
if (!imported_from_superclass)
break;