diff --git a/clang/include/clang/AST/ASTImporter.h b/clang/include/clang/AST/ASTImporter.h --- a/clang/include/clang/AST/ASTImporter.h +++ b/clang/include/clang/AST/ASTImporter.h @@ -183,7 +183,7 @@ /// \return Error information (success or error). template 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(); @@ -193,40 +193,29 @@ /// 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 Import_New(QualType FromT); - // FIXME: Remove this version. - QualType Import(QualType FromT); + llvm::Expected 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 Import_New(TypeSourceInfo *FromTSI); - // FIXME: Remove this version. - TypeSourceInfo *Import(TypeSourceInfo *FromTSI); + llvm::Expected 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 Import_New(const Attr *FromAttr); - // FIXME: Remove this version. - Attr *Import(const Attr *FromAttr); + llvm::Expected 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 Import_New(Decl *FromD); - llvm::Expected Import_New(const Decl *FromD) { - return Import_New(const_cast(FromD)); - } - // FIXME: Remove this version. - Decl *Import(Decl *FromD); - Decl *Import(const Decl *FromD) { + llvm::Expected Import(Decl *FromD); + llvm::Expected Import(const Decl *FromD) { return Import(const_cast(FromD)); } @@ -251,28 +240,21 @@ /// /// \returns The equivalent expression in the "to" context, or the import /// error. - llvm::Expected Import_New(Expr *FromE); - // FIXME: Remove this version. - Expr *Import(Expr *FromE); + llvm::Expected 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 Import_New(Stmt *FromS); - // FIXME: Remove this version. - Stmt *Import(Stmt *FromS); + llvm::Expected 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 - Import_New(NestedNameSpecifier *FromNNS); - // FIXME: Remove this version. - NestedNameSpecifier *Import(NestedNameSpecifier *FromNNS); + llvm::Expected Import(NestedNameSpecifier *FromNNS); /// Import the given nested-name-specifier-loc from the "from" /// context into the "to" context. @@ -280,42 +262,32 @@ /// \returns The equivalent nested-name-specifier-loc in the "to" /// context, or the import error. llvm::Expected - 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 Import_New(TemplateName From); - // FIXME: Remove this version. - TemplateName Import(TemplateName From); + llvm::Expected 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 Import_New(SourceLocation FromLoc); - // FIXME: Remove this version. - SourceLocation Import(SourceLocation FromLoc); + llvm::Expected 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 Import_New(SourceRange FromRange); - // FIXME: Remove this version. - SourceRange Import(SourceRange FromRange); + llvm::Expected 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 Import_New(DeclarationName FromName); - // FIXME: Remove this version. - DeclarationName Import(DeclarationName FromName); + llvm::Expected Import(DeclarationName FromName); /// Import the given identifier from the "from" context /// into the "to" context. @@ -329,46 +301,32 @@ /// /// \returns The equivalent selector in the "to" context, or the import /// error. - llvm::Expected Import_New(Selector FromSel); - // FIXME: Remove this version. - Selector Import(Selector FromSel); + llvm::Expected 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 Import_New(FileID, bool IsBuiltin = false); - // FIXME: Remove this version. - FileID Import(FileID, bool IsBuiltin = false); + llvm::Expected 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 - Import_New(CXXCtorInitializer *FromInit); - // FIXME: Remove this version. - CXXCtorInitializer *Import(CXXCtorInitializer *FromInit); + llvm::Expected 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 - Import_New(const CXXBaseSpecifier *FromSpec); - // FIXME: Remove this version. - CXXBaseSpecifier *Import(const CXXBaseSpecifier *FromSpec); + llvm::Expected 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. diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -148,7 +148,7 @@ // Use this to import pointers of specific type. template 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(*ToOrErr); return ToOrErr.takeError(); @@ -158,7 +158,7 @@ // cast the return value to `T`. template Expected import(T *From) { - auto ToOrErr = Importer.Import_New(From); + auto ToOrErr = Importer.Import(From); if (!ToOrErr) return ToOrErr.takeError(); return cast_or_null(*ToOrErr); @@ -172,7 +172,7 @@ // Call the import function of ASTImporter for type `T`. template Expected import(const T &From) { - return Importer.Import_New(From); + return Importer.Import(From); } template @@ -1671,7 +1671,7 @@ 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(*ToTypedefOrErr)); else return ToTypedefOrErr.takeError(); @@ -5033,13 +5033,21 @@ 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) + // FIXME: return the error? + consumeError(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) + // FIXME: return the error? + consumeError(ToOrErr.takeError()); + } // TODO Import instantiated default arguments. // TODO Import instantiated exception specifications. @@ -7666,7 +7674,7 @@ AddToLookupTable(ToD); } -Expected ASTImporter::Import_New(QualType FromT) { +Expected ASTImporter::Import(QualType FromT) { if (FromT.isNull()) return QualType{}; @@ -7689,56 +7697,32 @@ return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); } -QualType ASTImporter::Import(QualType From) { - llvm::Expected To = Import_New(From); - if (To) - return *To; - else - llvm::consumeError(To.takeError()); - return {}; -} -Expected ASTImporter::Import_New(TypeSourceInfo *FromTSI) { +Expected 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 To = Import_New(From); - if (To) - return *To; - else - llvm::consumeError(To.takeError()); - return nullptr; -} -Expected ASTImporter::Import_New(const Attr *FromAttr) { +Expected 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 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); @@ -7755,7 +7739,7 @@ return FromDPos->second->getTranslationUnitDecl(); } -Expected ASTImporter::Import_New(Decl *FromD) { +Expected ASTImporter::Import(Decl *FromD) { if (!FromD) return nullptr; @@ -7794,20 +7778,12 @@ updateFlags(FromD, ToD); return ToDOrErr; } -Decl *ASTImporter::Import(Decl *From) { - llvm::Expected To = Import_New(From); - if (To) - return *To; - else - llvm::consumeError(To.takeError()); - return nullptr; -} Expected ASTImporter::ImportContext(DeclContext *FromDC) { if (!FromDC) return FromDC; - ExpectedDecl ToDCOrErr = Import_New(cast(FromDC)); + ExpectedDecl ToDCOrErr = Import(cast(FromDC)); if (!ToDCOrErr) return ToDCOrErr.takeError(); auto *ToDC = cast(*ToDCOrErr); @@ -7863,22 +7839,14 @@ return ToDC; } -Expected ASTImporter::Import_New(Expr *FromE) { - if (ExpectedStmt ToSOrErr = Import_New(cast_or_null(FromE))) +Expected ASTImporter::Import(Expr *FromE) { + if (ExpectedStmt ToSOrErr = Import(cast_or_null(FromE))) return cast_or_null(*ToSOrErr); else return ToSOrErr.takeError(); } -Expr *ASTImporter::Import(Expr *From) { - llvm::Expected To = Import_New(From); - if (To) - return *To; - else - llvm::consumeError(To.takeError()); - return nullptr; -} -Expected ASTImporter::Import_New(Stmt *FromS) { +Expected ASTImporter::Import(Stmt *FromS) { if (!FromS) return nullptr; @@ -7910,17 +7878,9 @@ ImportedStmts[FromS] = *ToSOrErr; return ToSOrErr; } -Stmt *ASTImporter::Import(Stmt *From) { - llvm::Expected To = Import_New(From); - if (To) - return *To; - else - llvm::consumeError(To.takeError()); - return nullptr; -} Expected -ASTImporter::Import_New(NestedNameSpecifier *FromNNS) { +ASTImporter::Import(NestedNameSpecifier *FromNNS) { if (!FromNNS) return nullptr; @@ -7935,14 +7895,14 @@ 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(*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(*NSADOrErr)); else @@ -7952,7 +7912,7 @@ 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(*RDOrErr)); else @@ -7961,7 +7921,7 @@ case NestedNameSpecifier::TypeSpec: case NestedNameSpecifier::TypeSpecWithTemplate: if (Expected TyOrErr = - Import_New(QualType(FromNNS->getAsType(), 0u))) { + Import(QualType(FromNNS->getAsType(), 0u))) { bool TSTemplate = FromNNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate; return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate, @@ -7973,17 +7933,9 @@ llvm_unreachable("Invalid nested name specifier kind"); } -NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *From) { - llvm::Expected To = Import_New(From); - if (To) - return *To; - else - llvm::consumeError(To.takeError()); - return nullptr; -} Expected -ASTImporter::Import_New(NestedNameSpecifierLoc FromNNS) { +ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { // Copied from NestedNameSpecifier mostly. SmallVector NestedNames; NestedNameSpecifierLoc NNS = FromNNS; @@ -8048,7 +8000,7 @@ break; case NestedNameSpecifier::Super: { - auto ToSourceRangeOrErr = Import_New(NNS.getSourceRange()); + auto ToSourceRangeOrErr = Import(NNS.getSourceRange()); if (!ToSourceRangeOrErr) return ToSourceRangeOrErr.takeError(); @@ -8061,19 +8013,11 @@ return Builder.getWithLocInContext(getToContext()); } -NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc From) { - llvm::Expected To = Import_New(From); - if (To) - return *To; - else - llvm::consumeError(To.takeError()); - return {}; -} -Expected ASTImporter::Import_New(TemplateName From) { +Expected 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(*ToTemplateOrErr)); else return ToTemplateOrErr.takeError(); @@ -8082,7 +8026,7 @@ 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(*ToOrErr)); else return ToOrErr.takeError(); @@ -8093,11 +8037,11 @@ 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(*ToTemplateOrErr)); @@ -8107,7 +8051,7 @@ case TemplateName::DependentTemplate: { DependentTemplateName *DTN = From.getAsDependentTemplateName(); - auto QualifierOrErr = Import_New(DTN->getQualifier()); + auto QualifierOrErr = Import(DTN->getQualifier()); if (!QualifierOrErr) return QualifierOrErr.takeError(); @@ -8123,11 +8067,11 @@ 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(); @@ -8138,7 +8082,7 @@ case TemplateName::SubstTemplateTemplateParmPack: { SubstTemplateTemplateParmPackStorage *SubstPack = From.getAsSubstTemplateTemplateParmPack(); - ExpectedDecl ParamOrErr = Import_New(SubstPack->getParameterPack()); + ExpectedDecl ParamOrErr = Import(SubstPack->getParameterPack()); if (!ParamOrErr) return ParamOrErr.takeError(); @@ -8155,16 +8099,8 @@ llvm_unreachable("Invalid template name kind"); } -TemplateName ASTImporter::Import(TemplateName From) { - llvm::Expected To = Import_New(From); - if (To) - return *To; - else - llvm::consumeError(To.takeError()); - return {}; -} -Expected ASTImporter::Import_New(SourceLocation FromLoc) { +Expected ASTImporter::Import(SourceLocation FromLoc) { if (FromLoc.isInvalid()) return SourceLocation{}; @@ -8172,22 +8108,14 @@ bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc); std::pair Decomposed = FromSM.getDecomposedLoc(FromLoc); - Expected ToFileIDOrErr = Import_New(Decomposed.first, IsBuiltin); + Expected 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 To = Import_New(From); - if (To) - return *To; - else - llvm::consumeError(To.takeError()); - return {}; -} -Expected ASTImporter::Import_New(SourceRange FromRange) { +Expected ASTImporter::Import(SourceRange FromRange) { SourceLocation ToBegin, ToEnd; if (Error Err = importInto(ToBegin, FromRange.getBegin())) return std::move(Err); @@ -8196,16 +8124,8 @@ return SourceRange(ToBegin, ToEnd); } -SourceRange ASTImporter::Import(SourceRange From) { - llvm::Expected To = Import_New(From); - if (To) - return *To; - else - llvm::consumeError(To.takeError()); - return {}; -} -Expected ASTImporter::Import_New(FileID FromID, bool IsBuiltin) { +Expected ASTImporter::Import(FileID FromID, bool IsBuiltin) { llvm::DenseMap::iterator Pos = ImportedFileIDs.find(FromID); if (Pos != ImportedFileIDs.end()) return Pos->second; @@ -8218,10 +8138,10 @@ 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); @@ -8229,7 +8149,7 @@ 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 @@ -8241,8 +8161,7 @@ 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(); @@ -8284,31 +8203,22 @@ ImportedFileIDs[FromID] = ToID; return ToID; } -FileID ASTImporter::Import(FileID From, bool IsBuiltin) { - llvm::Expected To = Import_New(From, IsBuiltin); - if (To) - return *To; - else - llvm::consumeError(To.takeError()); - return {}; -} -Expected -ASTImporter::Import_New(CXXCtorInitializer *From) { - ExpectedExpr ToExprOrErr = Import_New(From->getInit()); +Expected 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(); @@ -8321,11 +8231,11 @@ 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(); @@ -8333,11 +8243,11 @@ ToContext, cast_or_null(*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(); @@ -8345,7 +8255,7 @@ ToContext, cast_or_null(*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(); @@ -8357,28 +8267,20 @@ return make_error(); } } -CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { - llvm::Expected To = Import_New(From); - if (To) - return *To; - else - llvm::consumeError(To.takeError()); - return nullptr; -} Expected -ASTImporter::Import_New(const CXXBaseSpecifier *BaseSpec) { +ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); if (Pos != ImportedCXXBaseSpecifiers.end()) return Pos->second; - Expected ToSourceRange = Import_New(BaseSpec->getSourceRange()); + Expected ToSourceRange = Import(BaseSpec->getSourceRange()); if (!ToSourceRange) return ToSourceRange.takeError(); - Expected ToTSI = Import_New(BaseSpec->getTypeSourceInfo()); + Expected 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( @@ -8387,19 +8289,12 @@ ImportedCXXBaseSpecifiers[BaseSpec] = Imported; return Imported; } -CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *From) { - llvm::Expected 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(); +Error ASTImporter::ImportDefinition(Decl *From) { + ExpectedDecl ToOrErr = Import(From); + if (!ToOrErr) + return ToOrErr.takeError(); + Decl *To = *ToOrErr; auto *FromDC = cast(From); ASTNodeImporter Importer(*this); @@ -8438,12 +8333,7 @@ return Importer.ImportDeclContext(FromDC, true); } -void ASTImporter::ImportDefinition(Decl *From) { - Error Err = ImportDefinition_New(From); - llvm::consumeError(std::move(Err)); -} - -Expected ASTImporter::Import_New(DeclarationName FromName) { +Expected ASTImporter::Import(DeclarationName FromName) { if (!FromName) return DeclarationName{}; @@ -8454,13 +8344,13 @@ 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 @@ -8468,7 +8358,7 @@ } case DeclarationName::CXXDestructorName: { - if (auto ToTyOrErr = Import_New(FromName.getCXXNameType())) + if (auto ToTyOrErr = Import(FromName.getCXXNameType())) return ToContext.DeclarationNames.getCXXDestructorName( ToContext.getCanonicalType(*ToTyOrErr)); else @@ -8476,8 +8366,7 @@ } case DeclarationName::CXXDeductionGuideName: { - if (auto ToTemplateOrErr = - Import_New(FromName.getCXXDeductionGuideTemplate())) + if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate())) return ToContext.DeclarationNames.getCXXDeductionGuideName( cast(*ToTemplateOrErr)); else @@ -8485,7 +8374,7 @@ } case DeclarationName::CXXConversionFunctionName: { - if (auto ToTyOrErr = Import_New(FromName.getCXXNameType())) + if (auto ToTyOrErr = Import(FromName.getCXXNameType())) return ToContext.DeclarationNames.getCXXConversionFunctionName( ToContext.getCanonicalType(*ToTyOrErr)); else @@ -8507,14 +8396,6 @@ llvm_unreachable("Invalid DeclarationName Kind!"); } -DeclarationName ASTImporter::Import(DeclarationName From) { - llvm::Expected To = Import_New(From); - if (To) - return *To; - else - llvm::consumeError(To.takeError()); - return {}; -} IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { if (!FromId) @@ -8528,7 +8409,7 @@ return ToId; } -Expected ASTImporter::Import_New(Selector FromSel) { +Expected ASTImporter::Import(Selector FromSel) { if (FromSel.isNull()) return Selector{}; @@ -8546,14 +8427,6 @@ unsigned NumDecls) { return Name; } -Selector ASTImporter::Import(Selector From) { - llvm::Expected To = Import_New(From); - if (To) - return *To; - else - llvm::consumeError(To.takeError()); - return {}; -} DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { if (LastDiagFromFrom) @@ -8609,7 +8482,7 @@ llvm::DenseMap::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 { diff --git a/clang/lib/AST/ExternalASTMerger.cpp b/clang/lib/AST/ExternalASTMerger.cpp --- a/clang/lib/AST/ExternalASTMerger.cpp +++ b/clang/lib/AST/ExternalASTMerger.cpp @@ -56,7 +56,7 @@ } auto *ND = cast(DC); DeclarationName Name = ND->getDeclName(); - auto SourceNameOrErr = ReverseImporter.Import_New(Name); + auto SourceNameOrErr = ReverseImporter.Import(Name); if (!SourceNameOrErr) { llvm::consumeError(SourceNameOrErr.takeError()); return nullptr; @@ -233,7 +233,7 @@ if (!SourceTag->getDefinition()) return false; Forward.MapImported(SourceTag, Tag); - if (llvm::Error Err = Forward.ImportDefinition_New(SourceTag)) + if (llvm::Error Err = Forward.ImportDefinition(SourceTag)) llvm::consumeError(std::move(Err)); Tag->setCompleteDefinition(SourceTag->isCompleteDefinition()); return true; @@ -253,7 +253,7 @@ if (!SourceInterface->getDefinition()) return false; Forward.MapImported(SourceInterface, Interface); - if (llvm::Error Err = Forward.ImportDefinition_New(SourceInterface)) + if (llvm::Error Err = Forward.ImportDefinition(SourceInterface)) llvm::consumeError(std::move(Err)); return true; }); @@ -360,7 +360,7 @@ template static bool importSpecializations(DeclTy *D, ASTImporter *Importer) { for (auto *Spec : D->specializations()) { - auto ImportedSpecOrError = Importer->Import_New(Spec); + auto ImportedSpecOrError = Importer->Import(Spec); if (!ImportedSpecOrError) { llvm::consumeError(ImportedSpecOrError.takeError()); return true; @@ -395,7 +395,7 @@ ForEachMatchingDC(DC, [&](ASTImporter &Forward, ASTImporter &Reverse, Source SourceDC) -> bool { - auto FromNameOrErr = Reverse.Import_New(Name); + auto FromNameOrErr = Reverse.Import(Name); if (!FromNameOrErr) { llvm::consumeError(FromNameOrErr.takeError()); return false; @@ -415,7 +415,7 @@ for (const Candidate &C : Candidates) { Decl *LookupRes = C.first.get(); ASTImporter *Importer = C.second; - auto NDOrErr = Importer->Import_New(LookupRes); + auto NDOrErr = Importer->Import(LookupRes); assert(NDOrErr); (void)static_cast(NDOrErr); NamedDecl *ND = cast_or_null(*NDOrErr); @@ -440,7 +440,7 @@ Source SourceDC) -> bool { for (const Decl *SourceDecl : SourceDC.get()->decls()) { if (IsKindWeWant(SourceDecl->getKind())) { - auto ImportedDeclOrErr = Forward.Import_New(SourceDecl); + auto ImportedDeclOrErr = Forward.Import(SourceDecl); if (ImportedDeclOrErr) assert(!(*ImportedDeclOrErr) || IsSameDC((*ImportedDeclOrErr)->getDeclContext(), DC)); diff --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp b/clang/lib/CrossTU/CrossTranslationUnit.cpp --- a/clang/lib/CrossTU/CrossTranslationUnit.cpp +++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp @@ -398,7 +398,7 @@ assert(hasBodyOrInit(D) && "Decls to be imported should have body or init."); ASTImporter &Importer = getOrCreateASTImporter(D->getASTContext()); - auto ToDeclOrError = Importer.Import_New(D); + auto ToDeclOrError = Importer.Import(D); if (!ToDeclOrError) { handleAllErrors(ToDeclOrError.takeError(), [&](const ImportError &IE) { diff --git a/clang/lib/Frontend/ASTMerge.cpp b/clang/lib/Frontend/ASTMerge.cpp --- a/clang/lib/Frontend/ASTMerge.cpp +++ b/clang/lib/Frontend/ASTMerge.cpp @@ -65,7 +65,7 @@ if (II->isStr("__va_list_tag") || II->isStr("__builtin_va_list")) continue; - llvm::Expected ToDOrError = Importer.Import_New(D); + llvm::Expected ToDOrError = Importer.Import(D); if (ToDOrError) { DeclGroupRef DGR(*ToDOrError); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -100,7 +100,7 @@ createVirtualFileIfNeeded(To, FromFileName, From->getBufferForFile(FromFileName)); - auto Imported = Importer.Import_New(Node); + auto Imported = Importer.Import(Node); if (Imported) { // This should dump source locations and assert if some source locations @@ -369,7 +369,7 @@ Decl *import(ASTImporterLookupTable &LookupTable, ASTUnit *ToAST, Decl *FromDecl) { lazyInitImporter(LookupTable, ToAST); - if (auto ImportedOrErr = Importer->Import_New(FromDecl)) + if (auto ImportedOrErr = Importer->Import(FromDecl)) return *ImportedOrErr; else { llvm::consumeError(ImportedOrErr.takeError()); @@ -380,7 +380,7 @@ QualType import(ASTImporterLookupTable &LookupTable, ASTUnit *ToAST, QualType FromType) { lazyInitImporter(LookupTable, ToAST); - if (auto ImportedOrErr = Importer->Import_New(FromType)) + if (auto ImportedOrErr = Importer->Import(FromType)) return *ImportedOrErr; else { llvm::consumeError(ImportedOrErr.takeError()); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp @@ -1968,7 +1968,14 @@ return QualType(); } - return merger.ImporterForOrigin(from_context).Import(type); + if (llvm::Expected type_or_error = + merger.ImporterForOrigin(from_context).Import(type)) { + return *type_or_error; + } else { + Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS); + LLDB_LOG_ERROR(log, type_or_error.takeError(), "Couldn't import type: {0}"); + return QualType(); + } } clang::Decl *ClangASTSource::CopyDecl(Decl *src_decl) { @@ -1981,7 +1988,16 @@ return nullptr; } - return m_merger_up->ImporterForOrigin(from_context).Import(src_decl); + if (llvm::Expected decl_or_error = + m_merger_up->ImporterForOrigin(from_context).Import(src_decl)) { + return *decl_or_error; + } else { + Log *log = + lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS); + LLDB_LOG_ERROR(log, decl_or_error.takeError(), + "Couldn't import decl: {0}"); + return nullptr; + } } else { lldbassert(0 && "No mechanism for copying a decl!"); return nullptr; diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp @@ -272,9 +272,15 @@ merger.AddSources(importer_source); clang::ASTImporter &exporter = merger.ImporterForOrigin(source); CompleteAllDeclContexts(exporter, file, root); - clang::QualType ret = exporter.Import(root); + llvm::Expected ret_or_error = exporter.Import(root); merger.RemoveSources(importer_source); - return ret; + if (ret_or_error) { + return *ret_or_error; + } else { + Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS); + LLDB_LOG_ERROR(log, ret_or_error.takeError(), "Couldn't import type: {0}"); + return clang::QualType(); + } } TypeFromUser ClangExpressionDeclMap::DeportType(ClangASTContext &target, diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp --- a/lldb/source/Symbol/ClangASTContext.cpp +++ b/lldb/source/Symbol/ClangASTContext.cpp @@ -1415,7 +1415,14 @@ FileManager file_manager(file_system_options); ASTImporter importer(*dst_ast, file_manager, *src_ast, file_manager, false); - return importer.Import(source_decl); + if (llvm::Expected ret_or_error = + importer.Import(source_decl)) { + return *ret_or_error; + } else { + Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS); + LLDB_LOG_ERROR(log, ret_or_error.takeError(), "Couldn't import decl: {0}"); + return nullptr; + } } bool ClangASTContext::AreTypesSame(CompilerType type1, CompilerType type2, diff --git a/lldb/source/Symbol/ClangASTImporter.cpp b/lldb/source/Symbol/ClangASTImporter.cpp --- a/lldb/source/Symbol/ClangASTImporter.cpp +++ b/lldb/source/Symbol/ClangASTImporter.cpp @@ -62,8 +62,16 @@ ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, dst_ast); - if (delegate_sp) - return delegate_sp->Import(type); + if (delegate_sp) { + if (llvm::Expected ret_or_error = delegate_sp->Import(type)) { + return *ret_or_error; + } else { + Log *log = + lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS); + LLDB_LOG_ERROR(log, ret_or_error.takeError(), + "Couldn't import type: {0}"); + } + } return QualType(); } @@ -106,7 +114,7 @@ ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, dst_ast); if (delegate_sp) { - clang::Decl *result = delegate_sp->Import(decl); + llvm::Expected result = delegate_sp->Import(decl); if (!result) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); @@ -127,9 +135,13 @@ "metadata 0x%" PRIx64, decl->getDeclKindName(), user_id); } + + llvm::consumeError(result.takeError()); + + return nullptr; } - return result; + return *result; } return nullptr; @@ -624,6 +636,8 @@ if (!RequireCompleteType(type)) return false; + Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS); + if (const TagType *tag_type = type->getAs()) { TagDecl *tag_decl = tag_type->getDecl(); @@ -641,7 +655,12 @@ TagDecl *origin_tag_decl = llvm::dyn_cast(decl_origin.decl); for (Decl *origin_child_decl : origin_tag_decl->decls()) { - delegate_sp->Import(origin_child_decl); + llvm::Expected imported_or_err = + delegate_sp->Import(origin_child_decl); + if (!imported_or_err) + // FIXME return with false? + LLDB_LOG_ERROR(log, imported_or_err.takeError(), + "Couldn't import decl: {0}"); } if (RecordDecl *record_decl = dyn_cast(origin_tag_decl)) { @@ -666,7 +685,12 @@ llvm::dyn_cast(decl_origin.decl); for (Decl *origin_child_decl : origin_interface_decl->decls()) { - delegate_sp->Import(origin_child_decl); + llvm::Expected imported_or_err = + delegate_sp->Import(origin_child_decl); + if (!imported_or_err) + // FIXME return with false? + LLDB_LOG_ERROR(log, imported_or_err.takeError(), + "Couldn't import decl: {0}"); } return true; @@ -919,7 +943,13 @@ 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(to)) { if (clang::TagDecl *from_tag = dyn_cast(from)) { @@ -949,13 +979,17 @@ if (!from_superclass) break; - Decl *imported_from_superclass_decl = Import(from_superclass); + llvm::Expected 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(imported_from_superclass_decl); + dyn_cast(*imported_from_superclass_decl); if (!imported_from_superclass) break; diff --git a/lldb/source/Symbol/CxxModuleHandler.cpp b/lldb/source/Symbol/CxxModuleHandler.cpp --- a/lldb/source/Symbol/CxxModuleHandler.cpp +++ b/lldb/source/Symbol/CxxModuleHandler.cpp @@ -9,6 +9,7 @@ #include "lldb/Symbol/CxxModuleHandler.h" #include "lldb/Symbol/ClangASTContext.h" +#include "lldb/Utility/Log.h" #include "clang/Sema/Lookup.h" #include "llvm/Support/Error.h" @@ -214,13 +215,15 @@ // Import the foreign template arguments. llvm::SmallVector imported_args; + Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS); + // If this logic is changed, also update templateArgsAreSupported. for (const TemplateArgument &arg : foreign_args.asArray()) { switch (arg.getKind()) { case TemplateArgument::Type: { - llvm::Expected type = m_importer->Import_New(arg.getAsType()); + llvm::Expected type = m_importer->Import(arg.getAsType()); if (!type) { - llvm::consumeError(type.takeError()); + LLDB_LOG_ERROR(log, type.takeError(), "Couldn't import type: {0}"); return {}; } imported_args.push_back(TemplateArgument(*type)); @@ -229,9 +232,9 @@ case TemplateArgument::Integral: { llvm::APSInt integral = arg.getAsIntegral(); llvm::Expected type = - m_importer->Import_New(arg.getIntegralType()); + m_importer->Import(arg.getIntegralType()); if (!type) { - llvm::consumeError(type.takeError()); + LLDB_LOG_ERROR(log, type.takeError(), "Couldn't import type: {0}"); return {}; } imported_args.push_back(