From b211b92b8811a6f926a11912ca97291d56486d2a Mon Sep 17 00:00:00 2001 From: Gabor Marton Date: Wed, 15 May 2019 10:29:48 +0000 Subject: [PATCH 1/2] [ASTImporter] Use llvm::Expected and Error in the importer API Summary: This is the final phase of the refactoring towards using llvm::Expected and llvm::Error in the ASTImporter API. This involves the following: - remove old Import functions which returned with a pointer, - use the Import_New functions (which return with Err or Expected) everywhere and handle their return value - rename Import_New functions to Import This affects both Clang and LLDB. Reviewers: shafik, teemperor, aprantl, a_sidorin, balazske, a.sidorin Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits, lldb-commits Tags: #clang, #lldb Differential Revision: https://reviews.llvm.org/D61438 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360760 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ASTImporter.h | 80 ++------ lib/AST/ASTImporter.cpp | 283 +++++++------------------- lib/AST/ExternalASTMerger.cpp | 14 +- lib/CrossTU/CrossTranslationUnit.cpp | 2 +- lib/Frontend/ASTMerge.cpp | 2 +- unittests/AST/ASTImporterFixtures.cpp | 4 +- unittests/AST/ASTImporterTest.cpp | 2 +- 7 files changed, 108 insertions(+), 279 deletions(-) diff --git a/include/clang/AST/ASTImporter.h b/include/clang/AST/ASTImporter.h index 54ebd28c0cab..b0dcece5ce9a 100644 --- a/include/clang/AST/ASTImporter.h +++ b/include/clang/AST/ASTImporter.h @@ -183,7 +183,7 @@ class TypeSourceInfo; /// \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 @@ class TypeSourceInfo; /// 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 @@ class TypeSourceInfo; /// /// \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 @@ class TypeSourceInfo; /// \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 @@ class TypeSourceInfo; /// /// \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/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index 8a6f8f00375a..81ac44f7ab28 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -148,7 +148,7 @@ namespace clang { // 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 @@ namespace clang { // 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 @@ namespace clang { // Call the import function of ASTImporter for type `T`. template Expected import(const T &From) { - return Importer.Import_New(From); + return Importer.Import(From); } // Import an Optional by importing the contained T, if any. @@ -1681,7 +1681,7 @@ Error ASTNodeImporter::ImportImplicitMethods( 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(); @@ -5085,13 +5085,19 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( 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. @@ -7719,7 +7725,7 @@ void ASTImporter::RegisterImportedDecl(Decl *FromD, Decl *ToD) { AddToLookupTable(ToD); } -Expected ASTImporter::Import_New(QualType FromT) { +Expected ASTImporter::Import(QualType FromT) { if (FromT.isNull()) return QualType{}; @@ -7742,56 +7748,32 @@ Expected ASTImporter::Import_New(QualType FromT) { 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); @@ -7808,7 +7790,7 @@ TranslationUnitDecl *ASTImporter::GetFromTU(Decl *ToD) { return FromDPos->second->getTranslationUnitDecl(); } -Expected ASTImporter::Import_New(Decl *FromD) { +Expected ASTImporter::Import(Decl *FromD) { if (!FromD) return nullptr; @@ -7847,20 +7829,12 @@ Expected ASTImporter::Import_New(Decl *FromD) { 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); @@ -7916,22 +7890,14 @@ Expected ASTImporter::ImportContext(DeclContext *FromDC) { 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; @@ -7963,17 +7929,9 @@ Expected ASTImporter::Import_New(Stmt *FromS) { 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; @@ -7988,14 +7946,14 @@ ASTImporter::Import_New(NestedNameSpecifier *FromNNS) { 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 @@ -8005,7 +7963,7 @@ ASTImporter::Import_New(NestedNameSpecifier *FromNNS) { 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 @@ -8014,7 +7972,7 @@ ASTImporter::Import_New(NestedNameSpecifier *FromNNS) { 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, @@ -8026,17 +7984,9 @@ ASTImporter::Import_New(NestedNameSpecifier *FromNNS) { 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; @@ -8101,7 +8051,7 @@ ASTImporter::Import_New(NestedNameSpecifierLoc FromNNS) { break; case NestedNameSpecifier::Super: { - auto ToSourceRangeOrErr = Import_New(NNS.getSourceRange()); + auto ToSourceRangeOrErr = Import(NNS.getSourceRange()); if (!ToSourceRangeOrErr) return ToSourceRangeOrErr.takeError(); @@ -8114,19 +8064,11 @@ ASTImporter::Import_New(NestedNameSpecifierLoc FromNNS) { 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(); @@ -8135,7 +8077,7 @@ Expected ASTImporter::Import_New(TemplateName From) { 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(); @@ -8146,7 +8088,7 @@ Expected ASTImporter::Import_New(TemplateName From) { 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); @@ -8154,11 +8096,11 @@ Expected ASTImporter::Import_New(TemplateName From) { 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)); @@ -8168,7 +8110,7 @@ Expected ASTImporter::Import_New(TemplateName From) { case TemplateName::DependentTemplate: { DependentTemplateName *DTN = From.getAsDependentTemplateName(); - auto QualifierOrErr = Import_New(DTN->getQualifier()); + auto QualifierOrErr = Import(DTN->getQualifier()); if (!QualifierOrErr) return QualifierOrErr.takeError(); @@ -8184,11 +8126,11 @@ Expected ASTImporter::Import_New(TemplateName From) { 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(); @@ -8199,7 +8141,7 @@ Expected ASTImporter::Import_New(TemplateName From) { case TemplateName::SubstTemplateTemplateParmPack: { SubstTemplateTemplateParmPackStorage *SubstPack = From.getAsSubstTemplateTemplateParmPack(); - ExpectedDecl ParamOrErr = Import_New(SubstPack->getParameterPack()); + ExpectedDecl ParamOrErr = Import(SubstPack->getParameterPack()); if (!ParamOrErr) return ParamOrErr.takeError(); @@ -8216,16 +8158,8 @@ Expected ASTImporter::Import_New(TemplateName From) { 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{}; @@ -8233,22 +8167,14 @@ Expected ASTImporter::Import_New(SourceLocation FromLoc) { 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); @@ -8257,16 +8183,8 @@ Expected ASTImporter::Import_New(SourceRange FromRange) { 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; @@ -8279,10 +8197,10 @@ Expected ASTImporter::Import_New(FileID FromID, bool IsBuiltin) { 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); @@ -8290,7 +8208,7 @@ Expected ASTImporter::Import_New(FileID FromID, bool IsBuiltin) { 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 @@ -8302,8 +8220,7 @@ Expected ASTImporter::Import_New(FileID FromID, bool IsBuiltin) { 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(); @@ -8345,31 +8262,22 @@ Expected ASTImporter::Import_New(FileID FromID, bool IsBuiltin) { 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(); @@ -8382,11 +8290,11 @@ ASTImporter::Import_New(CXXCtorInitializer *From) { 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(); @@ -8394,11 +8302,11 @@ ASTImporter::Import_New(CXXCtorInitializer *From) { 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(); @@ -8406,7 +8314,7 @@ ASTImporter::Import_New(CXXCtorInitializer *From) { 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(); @@ -8418,28 +8326,20 @@ ASTImporter::Import_New(CXXCtorInitializer *From) { 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( @@ -8448,19 +8348,12 @@ ASTImporter::Import_New(const CXXBaseSpecifier *BaseSpec) { 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); @@ -8499,12 +8392,7 @@ Error ASTImporter::ImportDefinition_New(Decl *From) { 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{}; @@ -8515,13 +8403,13 @@ Expected ASTImporter::Import_New(DeclarationName FromName) { 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 @@ -8529,7 +8417,7 @@ Expected ASTImporter::Import_New(DeclarationName FromName) { } case DeclarationName::CXXDestructorName: { - if (auto ToTyOrErr = Import_New(FromName.getCXXNameType())) + if (auto ToTyOrErr = Import(FromName.getCXXNameType())) return ToContext.DeclarationNames.getCXXDestructorName( ToContext.getCanonicalType(*ToTyOrErr)); else @@ -8537,8 +8425,7 @@ Expected ASTImporter::Import_New(DeclarationName FromName) { } case DeclarationName::CXXDeductionGuideName: { - if (auto ToTemplateOrErr = - Import_New(FromName.getCXXDeductionGuideTemplate())) + if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate())) return ToContext.DeclarationNames.getCXXDeductionGuideName( cast(*ToTemplateOrErr)); else @@ -8546,7 +8433,7 @@ Expected ASTImporter::Import_New(DeclarationName FromName) { } case DeclarationName::CXXConversionFunctionName: { - if (auto ToTyOrErr = Import_New(FromName.getCXXNameType())) + if (auto ToTyOrErr = Import(FromName.getCXXNameType())) return ToContext.DeclarationNames.getCXXConversionFunctionName( ToContext.getCanonicalType(*ToTyOrErr)); else @@ -8568,14 +8455,6 @@ Expected ASTImporter::Import_New(DeclarationName FromName) { 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) @@ -8589,7 +8468,7 @@ IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { return ToId; } -Expected ASTImporter::Import_New(Selector FromSel) { +Expected ASTImporter::Import(Selector FromSel) { if (FromSel.isNull()) return Selector{}; @@ -8607,14 +8486,6 @@ DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, 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) @@ -8670,7 +8541,7 @@ bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, 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/lib/AST/ExternalASTMerger.cpp b/lib/AST/ExternalASTMerger.cpp index 0075247bb1c2..61e657da7c91 100644 --- a/lib/AST/ExternalASTMerger.cpp +++ b/lib/AST/ExternalASTMerger.cpp @@ -56,7 +56,7 @@ LookupSameContext(Source SourceTU, const DeclContext *DC, } 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 @@ void ExternalASTMerger::CompleteType(TagDecl *Tag) { 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 @@ void ExternalASTMerger::CompleteType(ObjCInterfaceDecl *Interface) { 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 @@ void ExternalASTMerger::RemoveSources(llvm::ArrayRef Sources) { 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 @@ bool ExternalASTMerger::FindExternalVisibleDeclsByName(const DeclContext *DC, 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 @@ bool ExternalASTMerger::FindExternalVisibleDeclsByName(const DeclContext *DC, 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 @@ void ExternalASTMerger::FindExternalLexicalDecls( 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/lib/CrossTU/CrossTranslationUnit.cpp b/lib/CrossTU/CrossTranslationUnit.cpp index 9b68f3726e90..f504082ad34e 100644 --- a/lib/CrossTU/CrossTranslationUnit.cpp +++ b/lib/CrossTU/CrossTranslationUnit.cpp @@ -398,7 +398,7 @@ CrossTranslationUnitContext::importDefinitionImpl(const T *D) { 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/lib/Frontend/ASTMerge.cpp b/lib/Frontend/ASTMerge.cpp index b995d25441e2..f2709755b6b7 100644 --- a/lib/Frontend/ASTMerge.cpp +++ b/lib/Frontend/ASTMerge.cpp @@ -65,7 +65,7 @@ void ASTMergeAction::ExecuteAction() { 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/unittests/AST/ASTImporterFixtures.cpp b/unittests/AST/ASTImporterFixtures.cpp index eeb4821a7153..a0273b617e53 100644 --- a/unittests/AST/ASTImporterFixtures.cpp +++ b/unittests/AST/ASTImporterFixtures.cpp @@ -72,7 +72,7 @@ void ASTImporterTestBase::TU::lazyInitImporter( Decl *ASTImporterTestBase::TU::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()); @@ -83,7 +83,7 @@ Decl *ASTImporterTestBase::TU::import(ASTImporterLookupTable &LookupTable, QualType ASTImporterTestBase::TU::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/unittests/AST/ASTImporterTest.cpp b/unittests/AST/ASTImporterTest.cpp index b310ddcfbeb3..72ff3be03cd0 100644 --- a/unittests/AST/ASTImporterTest.cpp +++ b/unittests/AST/ASTImporterTest.cpp @@ -40,7 +40,7 @@ class TestImportBase : public CompilerOptionSpecificTest, 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 From 7da1391bdec01faee1dd5af9f3a0c6df63eff243 Mon Sep 17 00:00:00 2001 From: Kevin Petit Date: Wed, 15 May 2019 16:39:28 +0000 Subject: [PATCH 2/2] Test commit Remove stray space. Signed-off-by: Kevin Petit git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360783 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaType.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 4c7c13e9e2bb..bd091a0691ea 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -7561,7 +7561,7 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type, state.getDeclarator().isPrototypeContext() && !hasOuterPointerLikeChunk(state.getDeclarator(), endIndex); if (checkNullabilityTypeSpecifier( - state, + state, type, attr, allowOnArrayType)) {