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 @@ -186,8 +186,11 @@ return import(*From); } - // Helper for error management in importSeq. - template T checkImport(Error &Err, const T &From) { + // Helper for chaining together multiple imports. If an error is detected, + // subsequent imports will return default constructed nodes, so that failure + // can be detected with a single conditional branch after a sequence of + // imports. + template T importChecked(Error &Err, const T &From) { // Don't attempt to import nodes if we hit an error earlier. if (Err) return T{}; @@ -199,19 +202,6 @@ return *MaybeVal; } - // Import multiple objects with a single function call. - // This should work for every type for which a variant of `import` exists. - // The arguments are processed from left to right and import is stopped on - // first error. - template - Expected> importSeq(const Args &... args) { - Error E = Error::success(); - std::tuple Res{checkImport(E, args)...}; - if (E) - return std::move(E); - return std::move(Res); - } - // Wrapper for an overload set. template struct CallOverloadedCreateFun { template @@ -1150,12 +1140,11 @@ ExpectedType ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { - QualType ToElementType; - const Expr *ToSizeExpr; - if (auto Imp = importSeq(T->getElementType(), T->getSizeExpr())) - std::tie(ToElementType, ToSizeExpr) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToElementType = importChecked(Err, T->getElementType()); + auto ToSizeExpr = importChecked(Err, T->getSizeExpr()); + if (Err) + return std::move(Err); return Importer.getToContext().getConstantArrayType( ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(), @@ -1175,15 +1164,12 @@ ExpectedType ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { - QualType ToElementType; - Expr *ToSizeExpr; - SourceRange ToBracketsRange; - if (auto Imp = importSeq( - T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) - std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; - else - return Imp.takeError(); - + Error Err = Error::success(); + QualType ToElementType = importChecked(Err, T->getElementType()); + Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr()); + SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange()); + if (Err) + return std::move(Err); return Importer.getToContext().getVariableArrayType( ToElementType, ToSizeExpr, T->getSizeModifier(), T->getIndexTypeCVRQualifiers(), ToBracketsRange); @@ -1191,14 +1177,12 @@ ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( const DependentSizedArrayType *T) { - QualType ToElementType; - Expr *ToSizeExpr; - SourceRange ToBracketsRange; - if (auto Imp = importSeq( - T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) - std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + QualType ToElementType = importChecked(Err, T->getElementType()); + Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr()); + SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange()); + if (Err) + return std::move(Err); // SizeExpr may be null if size is not specified directly. // For example, 'int a[]'. @@ -1263,26 +1247,24 @@ } FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); + Error Err = Error::success(); FunctionProtoType::ExtProtoInfo ToEPI; - - auto Imp = importSeq( - FromEPI.ExceptionSpec.NoexceptExpr, - FromEPI.ExceptionSpec.SourceDecl, - FromEPI.ExceptionSpec.SourceTemplate); - if (!Imp) - return Imp.takeError(); - ToEPI.ExtInfo = FromEPI.ExtInfo; ToEPI.Variadic = FromEPI.Variadic; ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; ToEPI.TypeQuals = FromEPI.TypeQuals; ToEPI.RefQualifier = FromEPI.RefQualifier; ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; + ToEPI.ExceptionSpec.NoexceptExpr = + importChecked(Err, FromEPI.ExceptionSpec.NoexceptExpr); + ToEPI.ExceptionSpec.SourceDecl = + importChecked(Err, FromEPI.ExceptionSpec.SourceDecl); + ToEPI.ExceptionSpec.SourceTemplate = + importChecked(Err, FromEPI.ExceptionSpec.SourceTemplate); ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; - std::tie( - ToEPI.ExceptionSpec.NoexceptExpr, - ToEPI.ExceptionSpec.SourceDecl, - ToEPI.ExceptionSpec.SourceTemplate) = *Imp; + + if (Err) + return std::move(Err); return Importer.getToContext().getFunctionType( *ToReturnTypeOrErr, ArgTypes, ToEPI); @@ -1290,12 +1272,11 @@ ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( const UnresolvedUsingType *T) { - UnresolvedUsingTypenameDecl *ToD; - Decl *ToPrevD; - if (auto Imp = importSeq(T->getDecl(), T->getDecl()->getPreviousDecl())) - std::tie(ToD, ToPrevD) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToD = importChecked(Err, T->getDecl()); + auto ToPrevD = importChecked(Err, T->getDecl()->getPreviousDecl()); + if (Err) + return std::move(Err); return Importer.getToContext().getTypeDeclType( ToD, cast_or_null(ToPrevD)); @@ -2249,14 +2230,13 @@ DeclContext *DC = *DCOrErr; DeclContext *LexicalDC = DC; - SourceLocation ToLocation, ToRParenLoc; - Expr *ToAssertExpr; - StringLiteral *ToMessage; - if (auto Imp = importSeq( - D->getLocation(), D->getAssertExpr(), D->getMessage(), D->getRParenLoc())) - std::tie(ToLocation, ToAssertExpr, ToMessage, ToRParenLoc) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToLocation = importChecked(Err, D->getLocation()); + auto ToRParenLoc = importChecked(Err, D->getRParenLoc()); + auto ToAssertExpr = importChecked(Err, D->getAssertExpr()); + auto ToMessage = importChecked(Err, D->getMessage()); + if (Err) + return std::move(Err); StaticAssertDecl *ToD; if (GetImportedOrCreateDecl( @@ -2365,17 +2345,15 @@ // NOTE: No conflict resolution is done for namespace aliases now. - SourceLocation ToNamespaceLoc, ToAliasLoc, ToTargetNameLoc; - NestedNameSpecifierLoc ToQualifierLoc; - NamespaceDecl *ToNamespace; - if (auto Imp = importSeq( - D->getNamespaceLoc(), D->getAliasLoc(), D->getQualifierLoc(), - D->getTargetNameLoc(), D->getNamespace())) - std::tie( - ToNamespaceLoc, ToAliasLoc, ToQualifierLoc, ToTargetNameLoc, - ToNamespace) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc()); + auto ToAliasLoc = importChecked(Err, D->getAliasLoc()); + auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); + auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc()); + auto ToNamespace = importChecked(Err, D->getNamespace()); + if (Err) + return std::move(Err); + IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); NamespaceAliasDecl *ToD; @@ -2444,17 +2422,16 @@ } } - QualType ToUnderlyingType; - TypeSourceInfo *ToTypeSourceInfo; - SourceLocation ToBeginLoc; - if (auto Imp = importSeq( - D->getUnderlyingType(), D->getTypeSourceInfo(), D->getBeginLoc())) - std::tie(ToUnderlyingType, ToTypeSourceInfo, ToBeginLoc) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToUnderlyingType = importChecked(Err, D->getUnderlyingType()); + auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); + auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); + if (Err) + return std::move(Err); // Create the new typedef node. // FIXME: ToUnderlyingType is not used. + (void)ToUnderlyingType; TypedefNameDecl *ToTypedef; if (IsAlias) { if (GetImportedOrCreateDecl( @@ -2522,12 +2499,11 @@ } } - TemplateParameterList *ToTemplateParameters; - TypeAliasDecl *ToTemplatedDecl; - if (auto Imp = importSeq(D->getTemplateParameters(), D->getTemplatedDecl())) - std::tie(ToTemplateParameters, ToTemplatedDecl) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters()); + auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl()); + if (Err) + return std::move(Err); TypeAliasTemplateDecl *ToAlias; if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, @@ -2637,15 +2613,13 @@ } } - SourceLocation ToBeginLoc; - NestedNameSpecifierLoc ToQualifierLoc; - QualType ToIntegerType; - SourceRange ToBraceRange; - if (auto Imp = importSeq(D->getBeginLoc(), D->getQualifierLoc(), - D->getIntegerType(), D->getBraceRange())) - std::tie(ToBeginLoc, ToQualifierLoc, ToIntegerType, ToBraceRange) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); + auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); + auto ToIntegerType = importChecked(Err, D->getIntegerType()); + auto ToBraceRange = importChecked(Err, D->getBraceRange()); + if (Err) + return std::move(Err); // Create the enum declaration. EnumDecl *D2; @@ -3288,18 +3262,16 @@ FromReturnTy, FromFPT->getParamTypes(), FromEPI); } - QualType T; - TypeSourceInfo *TInfo; - SourceLocation ToInnerLocStart, ToEndLoc; - NestedNameSpecifierLoc ToQualifierLoc; - Expr *TrailingRequiresClause; - if (auto Imp = importSeq( - FromTy, D->getTypeSourceInfo(), D->getInnerLocStart(), - D->getQualifierLoc(), D->getEndLoc(), D->getTrailingRequiresClause())) - std::tie(T, TInfo, ToInnerLocStart, ToQualifierLoc, ToEndLoc, - TrailingRequiresClause) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto T = importChecked(Err, FromTy); + auto TInfo = importChecked(Err, D->getTypeSourceInfo()); + auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); + auto ToEndLoc = importChecked(Err, D->getEndLoc()); + auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); + auto TrailingRequiresClause = + importChecked(Err, D->getTrailingRequiresClause()); + if (Err) + return std::move(Err); // Import the function parameters. SmallVector Parameters; @@ -3315,10 +3287,10 @@ if (auto *FromConstructor = dyn_cast(D)) { Expr *ExplicitExpr = nullptr; if (FromConstructor->getExplicitSpecifier().getExpr()) { - auto Imp = importSeq(FromConstructor->getExplicitSpecifier().getExpr()); + auto Imp = import(FromConstructor->getExplicitSpecifier().getExpr()); if (!Imp) return Imp.takeError(); - std::tie(ExplicitExpr) = *Imp; + ExplicitExpr = *Imp; } if (GetImportedOrCreateDecl( ToFunction, D, Importer.getToContext(), cast(DC), @@ -3333,16 +3305,12 @@ return ToFunction; } else if (CXXDestructorDecl *FromDtor = dyn_cast(D)) { - auto Imp = - importSeq(const_cast(FromDtor->getOperatorDelete()), - FromDtor->getOperatorDeleteThisArg()); - - if (!Imp) - return Imp.takeError(); - - FunctionDecl *ToOperatorDelete; - Expr *ToThisArg; - std::tie(ToOperatorDelete, ToThisArg) = *Imp; + Error Err = Error::success(); + auto ToOperatorDelete = importChecked( + Err, const_cast(FromDtor->getOperatorDelete())); + auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg()); + if (Err) + return std::move(Err); if (GetImportedOrCreateDecl( ToFunction, D, Importer.getToContext(), cast(DC), @@ -3357,10 +3325,10 @@ dyn_cast(D)) { Expr *ExplicitExpr = nullptr; if (FromConversion->getExplicitSpecifier().getExpr()) { - auto Imp = importSeq(FromConversion->getExplicitSpecifier().getExpr()); + auto Imp = import(FromConversion->getExplicitSpecifier().getExpr()); if (!Imp) return Imp.takeError(); - std::tie(ExplicitExpr) = *Imp; + ExplicitExpr = *Imp; } if (GetImportedOrCreateDecl( ToFunction, D, Importer.getToContext(), cast(DC), @@ -3559,18 +3527,14 @@ } } - QualType ToType; - TypeSourceInfo *ToTInfo; - Expr *ToBitWidth; - SourceLocation ToInnerLocStart; - Expr *ToInitializer; - if (auto Imp = importSeq( - D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), - D->getInnerLocStart(), D->getInClassInitializer())) - std::tie( - ToType, ToTInfo, ToBitWidth, ToInnerLocStart, ToInitializer) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToType = importChecked(Err, D->getType()); + auto ToTInfo = importChecked(Err, D->getTypeSourceInfo()); + auto ToBitWidth = importChecked(Err, D->getBitWidth()); + auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); + auto ToInitializer = importChecked(Err, D->getInClassInitializer()); + if (Err) + return std::move(Err); FieldDecl *ToField; if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, @@ -3761,15 +3725,13 @@ } } - QualType ToType; - TypeSourceInfo *ToTypeSourceInfo; - Expr *ToBitWidth; - SourceLocation ToInnerLocStart; - if (auto Imp = importSeq( - D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), D->getInnerLocStart())) - std::tie(ToType, ToTypeSourceInfo, ToBitWidth, ToInnerLocStart) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToType = importChecked(Err, D->getType()); + auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); + auto ToBitWidth = importChecked(Err, D->getBitWidth()); + auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); + if (Err) + return std::move(Err); ObjCIvarDecl *ToIvar; if (GetImportedOrCreateDecl( @@ -3883,16 +3845,13 @@ } } - QualType ToType; - TypeSourceInfo *ToTypeSourceInfo; - SourceLocation ToInnerLocStart; - NestedNameSpecifierLoc ToQualifierLoc; - if (auto Imp = importSeq( - D->getType(), D->getTypeSourceInfo(), D->getInnerLocStart(), - D->getQualifierLoc())) - std::tie(ToType, ToTypeSourceInfo, ToInnerLocStart, ToQualifierLoc) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToType = importChecked(Err, D->getType()); + auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); + auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); + auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); + if (Err) + return std::move(Err); // Create the imported variable. VarDecl *ToVar; @@ -3935,13 +3894,12 @@ // into the function declaration's context afterward. DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); - DeclarationName ToDeclName; - SourceLocation ToLocation; - QualType ToType; - if (auto Imp = importSeq(D->getDeclName(), D->getLocation(), D->getType())) - std::tie(ToDeclName, ToLocation, ToType) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToDeclName = importChecked(Err, D->getDeclName()); + auto ToLocation = importChecked(Err, D->getLocation()); + auto ToType = importChecked(Err, D->getType()); + if (Err) + return std::move(Err); // Create the imported parameter. ImplicitParamDecl *ToParm = nullptr; @@ -3979,18 +3937,14 @@ // into the function declaration's context afterward. DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); - DeclarationName ToDeclName; - SourceLocation ToLocation, ToInnerLocStart; - QualType ToType; - TypeSourceInfo *ToTypeSourceInfo; - if (auto Imp = importSeq( - D->getDeclName(), D->getLocation(), D->getType(), D->getInnerLocStart(), - D->getTypeSourceInfo())) - std::tie( - ToDeclName, ToLocation, ToType, ToInnerLocStart, - ToTypeSourceInfo) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToDeclName = importChecked(Err, D->getDeclName()); + auto ToLocation = importChecked(Err, D->getLocation()); + auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); + auto ToType = importChecked(Err, D->getType()); + auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); + if (Err) + return std::move(Err); ParmVarDecl *ToParm; if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, @@ -4093,14 +4047,13 @@ } } - SourceLocation ToEndLoc; - QualType ToReturnType; - TypeSourceInfo *ToReturnTypeSourceInfo; - if (auto Imp = importSeq( - D->getEndLoc(), D->getReturnType(), D->getReturnTypeSourceInfo())) - std::tie(ToEndLoc, ToReturnType, ToReturnTypeSourceInfo) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToEndLoc = importChecked(Err, D->getEndLoc()); + auto ToReturnType = importChecked(Err, D->getReturnType()); + auto ToReturnTypeSourceInfo = + importChecked(Err, D->getReturnTypeSourceInfo()); + if (Err) + return std::move(Err); ObjCMethodDecl *ToMethod; if (GetImportedOrCreateDecl( @@ -4161,14 +4114,13 @@ if (ToD) return ToD; - SourceLocation ToVarianceLoc, ToLocation, ToColonLoc; - TypeSourceInfo *ToTypeSourceInfo; - if (auto Imp = importSeq( - D->getVarianceLoc(), D->getLocation(), D->getColonLoc(), - D->getTypeSourceInfo())) - std::tie(ToVarianceLoc, ToLocation, ToColonLoc, ToTypeSourceInfo) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc()); + auto ToLocation = importChecked(Err, D->getLocation()); + auto ToColonLoc = importChecked(Err, D->getColonLoc()); + auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); + if (Err) + return std::move(Err); ObjCTypeParamDecl *Result; if (GetImportedOrCreateDecl( @@ -4202,16 +4154,14 @@ = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); ObjCCategoryDecl *ToCategory = MergeWithCategory; if (!ToCategory) { - SourceLocation ToAtStartLoc, ToCategoryNameLoc; - SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; - if (auto Imp = importSeq( - D->getAtStartLoc(), D->getCategoryNameLoc(), - D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) - std::tie( - ToAtStartLoc, ToCategoryNameLoc, - ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; - else - return Imp.takeError(); + + Error Err = Error::success(); + auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); + auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc()); + auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc()); + auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc()); + if (Err) + return std::move(Err); if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, ToAtStartLoc, Loc, @@ -4420,13 +4370,12 @@ if (ToD) return ToD; - SourceLocation ToLoc, ToUsingLoc; - NestedNameSpecifierLoc ToQualifierLoc; - if (auto Imp = importSeq( - D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc())) - std::tie(ToLoc, ToUsingLoc, ToQualifierLoc) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToLoc = importChecked(Err, D->getNameInfo().getLoc()); + auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); + auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); + if (Err) + return std::move(Err); DeclarationNameInfo NameInfo(Name, ToLoc); if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) @@ -4517,18 +4466,15 @@ if (!ToComAncestorOrErr) return ToComAncestorOrErr.takeError(); - NamespaceDecl *ToNominatedNamespace; - SourceLocation ToUsingLoc, ToNamespaceKeyLocation, ToIdentLocation; - NestedNameSpecifierLoc ToQualifierLoc; - if (auto Imp = importSeq( - D->getNominatedNamespace(), D->getUsingLoc(), - D->getNamespaceKeyLocation(), D->getQualifierLoc(), - D->getIdentLocation())) - std::tie( - ToNominatedNamespace, ToUsingLoc, ToNamespaceKeyLocation, - ToQualifierLoc, ToIdentLocation) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace()); + auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); + auto ToNamespaceKeyLocation = + importChecked(Err, D->getNamespaceKeyLocation()); + auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); + auto ToIdentLocation = importChecked(Err, D->getIdentLocation()); + if (Err) + return std::move(Err); UsingDirectiveDecl *ToUsingDir; if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, @@ -4556,14 +4502,13 @@ if (ToD) return ToD; - SourceLocation ToLoc, ToUsingLoc, ToEllipsisLoc; - NestedNameSpecifierLoc ToQualifierLoc; - if (auto Imp = importSeq( - D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc(), - D->getEllipsisLoc())) - std::tie(ToLoc, ToUsingLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToLoc = importChecked(Err, D->getNameInfo().getLoc()); + auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); + auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); + auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc()); + if (Err) + return std::move(Err); DeclarationNameInfo NameInfo(Name, ToLoc); if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) @@ -4593,14 +4538,13 @@ if (ToD) return ToD; - SourceLocation ToUsingLoc, ToTypenameLoc, ToEllipsisLoc; - NestedNameSpecifierLoc ToQualifierLoc; - if (auto Imp = importSeq( - D->getUsingLoc(), D->getTypenameLoc(), D->getQualifierLoc(), - D->getEllipsisLoc())) - std::tie(ToUsingLoc, ToTypenameLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); + auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc()); + auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); + auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc()); + if (Err) + return std::move(Err); UnresolvedUsingTypenameDecl *ToUsing; if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, @@ -4835,12 +4779,12 @@ if (Error Err = ImportDeclContext(D, DC, LexicalDC)) return std::move(Err); - SourceLocation ToLocation, ToAtStartLoc, ToCategoryNameLoc; - if (auto Imp = importSeq( - D->getLocation(), D->getAtStartLoc(), D->getCategoryNameLoc())) - std::tie(ToLocation, ToAtStartLoc, ToCategoryNameLoc) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToLocation = importChecked(Err, D->getLocation()); + auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); + auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc()); + if (Err) + return std::move(Err); if (GetImportedOrCreateDecl( ToImpl, D, Importer.getToContext(), DC, @@ -4880,16 +4824,14 @@ if (Error Err = ImportDeclContext(D, DC, LexicalDC)) return std::move(Err); - SourceLocation ToLocation, ToAtStartLoc, ToSuperClassLoc; - SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; - if (auto Imp = importSeq( - D->getLocation(), D->getAtStartLoc(), D->getSuperClassLoc(), - D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) - std::tie( - ToLocation, ToAtStartLoc, ToSuperClassLoc, - ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToLocation = importChecked(Err, D->getLocation()); + auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); + auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc()); + auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc()); + auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc()); + if (Err) + return std::move(Err); if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), DC, Iface, Super, @@ -4979,14 +4921,13 @@ } } - QualType ToType; - TypeSourceInfo *ToTypeSourceInfo; - SourceLocation ToAtLoc, ToLParenLoc; - if (auto Imp = importSeq( - D->getType(), D->getTypeSourceInfo(), D->getAtLoc(), D->getLParenLoc())) - std::tie(ToType, ToTypeSourceInfo, ToAtLoc, ToLParenLoc) = *Imp; - else - return Imp.takeError(); + Error Err = Error::success(); + auto ToType = importChecked(Err, D->getType()); + auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); + auto ToAtLoc = importChecked(Err, D->getAtLoc()); + auto ToLParenLoc = importChecked(Err, D->getLParenLoc()); + if (Err) + return std::move(Err); // Create the new property. ObjCPropertyDecl *ToProperty; @@ -4997,22 +4938,15 @@ ToTypeSourceInfo, D->getPropertyImplementation())) return ToProperty; - Selector ToGetterName, ToSetterName; - SourceLocation ToGetterNameLoc, ToSetterNameLoc; - ObjCMethodDecl *ToGetterMethodDecl, *ToSetterMethodDecl; - ObjCIvarDecl *ToPropertyIvarDecl; - if (auto Imp = importSeq( - D->getGetterName(), D->getSetterName(), - D->getGetterNameLoc(), D->getSetterNameLoc(), - D->getGetterMethodDecl(), D->getSetterMethodDecl(), - D->getPropertyIvarDecl())) - std::tie( - ToGetterName, ToSetterName, - ToGetterNameLoc, ToSetterNameLoc, - ToGetterMethodDecl, ToSetterMethodDecl, - ToPropertyIvarDecl) = *Imp; - else - return Imp.takeError(); + auto ToGetterName = importChecked(Err, D->getGetterName()); + auto ToSetterName = importChecked(Err, D->getSetterName()); + auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc()); + auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc()); + auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl()); + auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl()); + auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl()); + if (Err) + return std::move(Err); ToProperty->setLexicalDeclContext(LexicalDC); LexicalDC->addDeclInternal(ToProperty); @@ -5049,12 +4983,14 @@ = InImpl->FindPropertyImplDecl(Property->getIdentifier(), Property->getQueryKind()); if (!ToImpl) { - SourceLocation ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc; - if (auto Imp = importSeq( - D->getBeginLoc(), D->getLocation(), D->getPropertyIvarDeclLoc())) - std::tie(ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc) = *Imp; - else - return Imp.takeError(); + + Error Err = Error::success(); + auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); + auto ToLocation = importChecked(Err, D->getLocation()); + auto ToPropertyIvarDeclLoc = + importChecked(Err, D->getPropertyIvarDeclLoc()); + if (Err) + return std::move(Err); if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, ToBeginLoc, @@ -5132,20 +5068,16 @@ // Import the type-constraint if (const TypeConstraint *TC = D->getTypeConstraint()) { - NestedNameSpecifierLoc ToNNS; - DeclarationName ToName; - SourceLocation ToNameLoc; - NamedDecl *ToFoundDecl; - ConceptDecl *ToNamedConcept; - Expr *ToIDC; - if (auto Imp = importSeq(TC->getNestedNameSpecifierLoc(), - TC->getConceptNameInfo().getName(), TC->getConceptNameInfo().getLoc(), - TC->getFoundDecl(), TC->getNamedConcept(), - TC->getImmediatelyDeclaredConstraint())) - std::tie(ToNNS, ToName, ToNameLoc, ToFoundDecl, ToNamedConcept, - ToIDC) = *Imp; - else - return Imp.takeError(); + + Error Err = Error::success(); + auto ToNNS = importChecked(Err, TC->getNestedNameSpecifierLoc()); + auto ToName = importChecked(Err, TC->getConceptNameInfo().getName()); + auto ToNameLoc = importChecked(Err, TC->getConceptNameInfo().getLoc()); + auto ToFoundDecl = importChecked(Err, TC->getFoundDecl()); + auto ToNamedConcept = importChecked(Err, TC->getNamedConcept()); + auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint()); + if (Err) + return std::move(Err); TemplateArgumentListInfo ToTAInfo; const auto *ASTTemplateArgs = TC->getTemplateArgsAsWritten(); @@ -5167,18 +5099,15 @@ ExpectedDecl ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { - DeclarationName ToDeclName; - SourceLocation ToLocation, ToInnerLocStart; - QualType ToType; - TypeSourceInfo *ToTypeSourceInfo; - if (auto Imp = importSeq( - D->getDeclName(), D->getLocation(), D->getType(), D->getTypeSourceInfo(), - D->getInnerLocStart())) - std::tie( - ToDeclName, ToLocation, ToType, ToTypeSourceInfo, - ToInnerLocStart) = *Imp; - else - return Imp.takeError(); + + Error Err = Error::success(); + auto ToDeclName = importChecked(Err, D->getDeclName()); + auto ToLocation = importChecked(Err, D->getLocation()); + auto ToType = importChecked(Err, D->getType()); + auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); + auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); + if (Err) + return std::move(Err); // FIXME: Import default argument. @@ -5932,14 +5861,13 @@ } ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { - auto Imp = importSeq(S->getDeclGroup(), S->getBeginLoc(), S->getEndLoc()); - if (!Imp) - return Imp.takeError(); - - DeclGroupRef ToDG; - SourceLocation ToBeginLoc, ToEndLoc; - std::tie(ToDG, ToBeginLoc, ToEndLoc) = *Imp; + Error Err = Error::success(); + auto ToDG = importChecked(Err, S->getDeclGroup()); + auto ToBeginLoc = importChecked(Err, S->getBeginLoc()); + auto ToEndLoc = importChecked(Err, S->getEndLoc()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); } @@ -5971,17 +5899,16 @@ } ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { - auto Imp = importSeq( - S->getLHS(), S->getRHS(), S->getSubStmt(), S->getCaseLoc(), - S->getEllipsisLoc(), S->getColonLoc()); - if (!Imp) - return Imp.takeError(); - - Expr *ToLHS, *ToRHS; - Stmt *ToSubStmt; - SourceLocation ToCaseLoc, ToEllipsisLoc, ToColonLoc; - std::tie(ToLHS, ToRHS, ToSubStmt, ToCaseLoc, ToEllipsisLoc, ToColonLoc) = - *Imp; + + Error Err = Error::success(); + auto ToLHS = importChecked(Err, S->getLHS()); + auto ToRHS = importChecked(Err, S->getRHS()); + auto ToSubStmt = importChecked(Err, S->getSubStmt()); + auto ToCaseLoc = importChecked(Err, S->getCaseLoc()); + auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc()); + auto ToColonLoc = importChecked(Err, S->getColonLoc()); + if (Err) + return std::move(Err); auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, ToCaseLoc, ToEllipsisLoc, ToColonLoc); @@ -5991,27 +5918,26 @@ } ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { - auto Imp = importSeq(S->getDefaultLoc(), S->getColonLoc(), S->getSubStmt()); - if (!Imp) - return Imp.takeError(); - SourceLocation ToDefaultLoc, ToColonLoc; - Stmt *ToSubStmt; - std::tie(ToDefaultLoc, ToColonLoc, ToSubStmt) = *Imp; + Error Err = Error::success(); + auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc()); + auto ToColonLoc = importChecked(Err, S->getColonLoc()); + auto ToSubStmt = importChecked(Err, S->getSubStmt()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) DefaultStmt( ToDefaultLoc, ToColonLoc, ToSubStmt); } ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { - auto Imp = importSeq(S->getIdentLoc(), S->getDecl(), S->getSubStmt()); - if (!Imp) - return Imp.takeError(); - SourceLocation ToIdentLoc; - LabelDecl *ToLabelDecl; - Stmt *ToSubStmt; - std::tie(ToIdentLoc, ToLabelDecl, ToSubStmt) = *Imp; + Error Err = Error::success(); + auto ToIdentLoc = importChecked(Err, S->getIdentLoc()); + auto ToLabelDecl = importChecked(Err, S->getDecl()); + auto ToSubStmt = importChecked(Err, S->getSubStmt()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) LabelStmt( ToIdentLoc, ToLabelDecl, ToSubStmt); @@ -6034,19 +5960,17 @@ } ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { - auto Imp = importSeq( - S->getIfLoc(), S->getInit(), S->getConditionVariable(), S->getCond(), - S->getThen(), S->getElseLoc(), S->getElse()); - if (!Imp) - return Imp.takeError(); - - SourceLocation ToIfLoc, ToElseLoc; - Stmt *ToInit, *ToThen, *ToElse; - VarDecl *ToConditionVariable; - Expr *ToCond; - std::tie( - ToIfLoc, ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, ToElse) = - *Imp; + + Error Err = Error::success(); + auto ToIfLoc = importChecked(Err, S->getIfLoc()); + auto ToInit = importChecked(Err, S->getInit()); + auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); + auto ToCond = importChecked(Err, S->getCond()); + auto ToThen = importChecked(Err, S->getThen()); + auto ToElseLoc = importChecked(Err, S->getElseLoc()); + auto ToElse = importChecked(Err, S->getElse()); + if (Err) + return std::move(Err); return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, @@ -6054,17 +5978,15 @@ } ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { - auto Imp = importSeq( - S->getInit(), S->getConditionVariable(), S->getCond(), - S->getBody(), S->getSwitchLoc()); - if (!Imp) - return Imp.takeError(); - - Stmt *ToInit, *ToBody; - VarDecl *ToConditionVariable; - Expr *ToCond; - SourceLocation ToSwitchLoc; - std::tie(ToInit, ToConditionVariable, ToCond, ToBody, ToSwitchLoc) = *Imp; + + Error Err = Error::success(); + auto ToInit = importChecked(Err, S->getInit()); + auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); + auto ToCond = importChecked(Err, S->getCond()); + auto ToBody = importChecked(Err, S->getBody()); + auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc()); + if (Err) + return std::move(Err); auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable, ToCond); @@ -6089,52 +6011,47 @@ } ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { - auto Imp = importSeq( - S->getConditionVariable(), S->getCond(), S->getBody(), S->getWhileLoc()); - if (!Imp) - return Imp.takeError(); - VarDecl *ToConditionVariable; - Expr *ToCond; - Stmt *ToBody; - SourceLocation ToWhileLoc; - std::tie(ToConditionVariable, ToCond, ToBody, ToWhileLoc) = *Imp; + Error Err = Error::success(); + auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); + auto ToCond = importChecked(Err, S->getCond()); + auto ToBody = importChecked(Err, S->getBody()); + auto ToWhileLoc = importChecked(Err, S->getWhileLoc()); + if (Err) + return std::move(Err); return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, ToBody, ToWhileLoc); } ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { - auto Imp = importSeq( - S->getBody(), S->getCond(), S->getDoLoc(), S->getWhileLoc(), - S->getRParenLoc()); - if (!Imp) - return Imp.takeError(); - Stmt *ToBody; - Expr *ToCond; - SourceLocation ToDoLoc, ToWhileLoc, ToRParenLoc; - std::tie(ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc) = *Imp; + Error Err = Error::success(); + auto ToBody = importChecked(Err, S->getBody()); + auto ToCond = importChecked(Err, S->getCond()); + auto ToDoLoc = importChecked(Err, S->getDoLoc()); + auto ToWhileLoc = importChecked(Err, S->getWhileLoc()); + auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) DoStmt( ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); } ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { - auto Imp = importSeq( - S->getInit(), S->getCond(), S->getConditionVariable(), S->getInc(), - S->getBody(), S->getForLoc(), S->getLParenLoc(), S->getRParenLoc()); - if (!Imp) - return Imp.takeError(); - - Stmt *ToInit; - Expr *ToCond, *ToInc; - VarDecl *ToConditionVariable; - Stmt *ToBody; - SourceLocation ToForLoc, ToLParenLoc, ToRParenLoc; - std::tie( - ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, - ToLParenLoc, ToRParenLoc) = *Imp; + + Error Err = Error::success(); + auto ToInit = importChecked(Err, S->getInit()); + auto ToCond = importChecked(Err, S->getCond()); + auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); + auto ToInc = importChecked(Err, S->getInc()); + auto ToBody = importChecked(Err, S->getBody()); + auto ToForLoc = importChecked(Err, S->getForLoc()); + auto ToLParenLoc = importChecked(Err, S->getLParenLoc()); + auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) ForStmt( Importer.getToContext(), @@ -6143,26 +6060,26 @@ } ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { - auto Imp = importSeq(S->getLabel(), S->getGotoLoc(), S->getLabelLoc()); - if (!Imp) - return Imp.takeError(); - LabelDecl *ToLabel; - SourceLocation ToGotoLoc, ToLabelLoc; - std::tie(ToLabel, ToGotoLoc, ToLabelLoc) = *Imp; + Error Err = Error::success(); + auto ToLabel = importChecked(Err, S->getLabel()); + auto ToGotoLoc = importChecked(Err, S->getGotoLoc()); + auto ToLabelLoc = importChecked(Err, S->getLabelLoc()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) GotoStmt( ToLabel, ToGotoLoc, ToLabelLoc); } ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { - auto Imp = importSeq(S->getGotoLoc(), S->getStarLoc(), S->getTarget()); - if (!Imp) - return Imp.takeError(); - SourceLocation ToGotoLoc, ToStarLoc; - Expr *ToTarget; - std::tie(ToGotoLoc, ToStarLoc, ToTarget) = *Imp; + Error Err = Error::success(); + auto ToGotoLoc = importChecked(Err, S->getGotoLoc()); + auto ToStarLoc = importChecked(Err, S->getStarLoc()); + auto ToTarget = importChecked(Err, S->getTarget()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) IndirectGotoStmt( ToGotoLoc, ToStarLoc, ToTarget); @@ -6183,30 +6100,26 @@ } ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { - auto Imp = importSeq( - S->getReturnLoc(), S->getRetValue(), S->getNRVOCandidate()); - if (!Imp) - return Imp.takeError(); - SourceLocation ToReturnLoc; - Expr *ToRetValue; - const VarDecl *ToNRVOCandidate; - std::tie(ToReturnLoc, ToRetValue, ToNRVOCandidate) = *Imp; + Error Err = Error::success(); + auto ToReturnLoc = importChecked(Err, S->getReturnLoc()); + auto ToRetValue = importChecked(Err, S->getRetValue()); + auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate()); + if (Err) + return std::move(Err); return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, ToNRVOCandidate); } ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { - auto Imp = importSeq( - S->getCatchLoc(), S->getExceptionDecl(), S->getHandlerBlock()); - if (!Imp) - return Imp.takeError(); - SourceLocation ToCatchLoc; - VarDecl *ToExceptionDecl; - Stmt *ToHandlerBlock; - std::tie(ToCatchLoc, ToExceptionDecl, ToHandlerBlock) = *Imp; + Error Err = Error::success(); + auto ToCatchLoc = importChecked(Err, S->getCatchLoc()); + auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl()); + auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) CXXCatchStmt ( ToCatchLoc, ToExceptionDecl, ToHandlerBlock); @@ -6235,24 +6148,22 @@ } ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { - auto Imp1 = importSeq( - S->getInit(), S->getRangeStmt(), S->getBeginStmt(), S->getEndStmt(), - S->getCond(), S->getInc(), S->getLoopVarStmt(), S->getBody()); - if (!Imp1) - return Imp1.takeError(); - auto Imp2 = importSeq( - S->getForLoc(), S->getCoawaitLoc(), S->getColonLoc(), S->getRParenLoc()); - if (!Imp2) - return Imp2.takeError(); - - DeclStmt *ToRangeStmt, *ToBeginStmt, *ToEndStmt, *ToLoopVarStmt; - Expr *ToCond, *ToInc; - Stmt *ToInit, *ToBody; - std::tie( - ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, - ToBody) = *Imp1; - SourceLocation ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc; - std::tie(ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc) = *Imp2; + + Error Err = Error::success(); + auto ToInit = importChecked(Err, S->getInit()); + auto ToRangeStmt = importChecked(Err, S->getRangeStmt()); + auto ToBeginStmt = importChecked(Err, S->getBeginStmt()); + auto ToEndStmt = importChecked(Err, S->getEndStmt()); + auto ToCond = importChecked(Err, S->getCond()); + auto ToInc = importChecked(Err, S->getInc()); + auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt()); + auto ToBody = importChecked(Err, S->getBody()); + auto ToForLoc = importChecked(Err, S->getForLoc()); + auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc()); + auto ToColonLoc = importChecked(Err, S->getColonLoc()); + auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) CXXForRangeStmt( ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, @@ -6261,16 +6172,14 @@ ExpectedStmt ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { - auto Imp = importSeq( - S->getElement(), S->getCollection(), S->getBody(), - S->getForLoc(), S->getRParenLoc()); - if (!Imp) - return Imp.takeError(); - - Stmt *ToElement, *ToBody; - Expr *ToCollection; - SourceLocation ToForLoc, ToRParenLoc; - std::tie(ToElement, ToCollection, ToBody, ToForLoc, ToRParenLoc) = *Imp; + Error Err = Error::success(); + auto ToElement = importChecked(Err, S->getElement()); + auto ToCollection = importChecked(Err, S->getCollection()); + auto ToBody = importChecked(Err, S->getBody()); + auto ToForLoc = importChecked(Err, S->getForLoc()); + auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, ToCollection, @@ -6280,16 +6189,14 @@ } ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { - auto Imp = importSeq( - S->getAtCatchLoc(), S->getRParenLoc(), S->getCatchParamDecl(), - S->getCatchBody()); - if (!Imp) - return Imp.takeError(); - SourceLocation ToAtCatchLoc, ToRParenLoc; - VarDecl *ToCatchParamDecl; - Stmt *ToCatchBody; - std::tie(ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody) = *Imp; + Error Err = Error::success(); + auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc()); + auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); + auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl()); + auto ToCatchBody = importChecked(Err, S->getCatchBody()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) ObjCAtCatchStmt ( ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); @@ -6307,14 +6214,13 @@ } ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { - auto Imp = importSeq( - S->getAtTryLoc(), S->getTryBody(), S->getFinallyStmt()); - if (!Imp) - return Imp.takeError(); - SourceLocation ToAtTryLoc; - Stmt *ToTryBody, *ToFinallyStmt; - std::tie(ToAtTryLoc, ToTryBody, ToFinallyStmt) = *Imp; + Error Err = Error::success(); + auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc()); + auto ToTryBody = importChecked(Err, S->getTryBody()); + auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt()); + if (Err) + return std::move(Err); SmallVector ToCatchStmts(S->getNumCatchStmts()); for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { @@ -6331,17 +6237,15 @@ ToFinallyStmt); } -ExpectedStmt ASTNodeImporter::VisitObjCAtSynchronizedStmt - (ObjCAtSynchronizedStmt *S) { - auto Imp = importSeq( - S->getAtSynchronizedLoc(), S->getSynchExpr(), S->getSynchBody()); - if (!Imp) - return Imp.takeError(); +ExpectedStmt +ASTNodeImporter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { - SourceLocation ToAtSynchronizedLoc; - Expr *ToSynchExpr; - Stmt *ToSynchBody; - std::tie(ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody) = *Imp; + Error Err = Error::success(); + auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc()); + auto ToSynchExpr = importChecked(Err, S->getSynchExpr()); + auto ToSynchBody = importChecked(Err, S->getSynchBody()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) ObjCAtSynchronizedStmt( ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); @@ -6380,18 +6284,15 @@ } ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { - auto Imp = importSeq( - E->getBuiltinLoc(), E->getSubExpr(), E->getWrittenTypeInfo(), - E->getRParenLoc(), E->getType()); - if (!Imp) - return Imp.takeError(); - - SourceLocation ToBuiltinLoc, ToRParenLoc; - Expr *ToSubExpr; - TypeSourceInfo *ToWrittenTypeInfo; - QualType ToType; - std::tie(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType) = - *Imp; + + Error Err = Error::success(); + auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); + auto ToSubExpr = importChecked(Err, E->getSubExpr()); + auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo()); + auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); + auto ToType = importChecked(Err, E->getType()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) VAArgExpr( ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, @@ -6399,17 +6300,16 @@ } ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) { - auto Imp = importSeq(E->getCond(), E->getLHS(), E->getRHS(), - E->getBuiltinLoc(), E->getRParenLoc(), E->getType()); - if (!Imp) - return Imp.takeError(); - - Expr *ToCond; - Expr *ToLHS; - Expr *ToRHS; - SourceLocation ToBuiltinLoc, ToRParenLoc; - QualType ToType; - std::tie(ToCond, ToLHS, ToRHS, ToBuiltinLoc, ToRParenLoc, ToType) = *Imp; + + Error Err = Error::success(); + auto ToCond = importChecked(Err, E->getCond()); + auto ToLHS = importChecked(Err, E->getLHS()); + auto ToRHS = importChecked(Err, E->getRHS()); + auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); + auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); + auto ToType = importChecked(Err, E->getType()); + if (Err) + return std::move(Err); ExprValueKind VK = E->getValueKind(); ExprObjectKind OK = E->getObjectKind(); @@ -6439,33 +6339,28 @@ } ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { - auto Imp = importSeq( - E->getBeginLoc(), E->getType(), E->getFunctionName()); - if (!Imp) - return Imp.takeError(); - SourceLocation ToBeginLoc; - QualType ToType; - StringLiteral *ToFunctionName; - std::tie(ToBeginLoc, ToType, ToFunctionName) = *Imp; + Error Err = Error::success(); + auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); + auto ToType = importChecked(Err, E->getType()); + auto ToFunctionName = importChecked(Err, E->getFunctionName()); + if (Err) + return std::move(Err); return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, E->getIdentKind(), ToFunctionName); } ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { - auto Imp = importSeq( - E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDecl(), - E->getLocation(), E->getType()); - if (!Imp) - return Imp.takeError(); - - NestedNameSpecifierLoc ToQualifierLoc; - SourceLocation ToTemplateKeywordLoc, ToLocation; - ValueDecl *ToDecl; - QualType ToType; - std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, ToLocation, ToType) = - *Imp; + + Error Err = Error::success(); + auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); + auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); + auto ToDecl = importChecked(Err, E->getDecl()); + auto ToLocation = importChecked(Err, E->getLocation()); + auto ToType = importChecked(Err, E->getType()); + if (Err) + return std::move(Err); NamedDecl *ToFoundD = nullptr; if (E->getDecl() != E->getFoundDecl()) { @@ -6614,17 +6509,14 @@ } ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { - auto Imp = importSeq( - E->getLParenLoc(), E->getTypeSourceInfo(), E->getType(), - E->getInitializer()); - if (!Imp) - return Imp.takeError(); - - SourceLocation ToLParenLoc; - TypeSourceInfo *ToTypeSourceInfo; - QualType ToType; - Expr *ToInitializer; - std::tie(ToLParenLoc, ToTypeSourceInfo, ToType, ToInitializer) = *Imp; + + Error Err = Error::success(); + auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); + auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); + auto ToType = importChecked(Err, E->getType()); + auto ToInitializer = importChecked(Err, E->getInitializer()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) CompoundLiteralExpr( ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), @@ -6632,14 +6524,13 @@ } ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { - auto Imp = importSeq( - E->getBuiltinLoc(), E->getType(), E->getRParenLoc()); - if (!Imp) - return Imp.takeError(); - SourceLocation ToBuiltinLoc, ToRParenLoc; - QualType ToType; - std::tie(ToBuiltinLoc, ToType, ToRParenLoc) = *Imp; + Error Err = Error::success(); + auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); + auto ToType = importChecked(Err, E->getType()); + auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); + if (Err) + return std::move(Err); SmallVector ToExprs(E->getNumSubExprs()); if (Error Err = ImportArrayChecked( @@ -6648,33 +6539,30 @@ return std::move(Err); return new (Importer.getToContext()) AtomicExpr( + ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); } ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { - auto Imp = importSeq( - E->getAmpAmpLoc(), E->getLabelLoc(), E->getLabel(), E->getType()); - if (!Imp) - return Imp.takeError(); - - SourceLocation ToAmpAmpLoc, ToLabelLoc; - LabelDecl *ToLabel; - QualType ToType; - std::tie(ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType) = *Imp; + Error Err = Error::success(); + auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc()); + auto ToLabelLoc = importChecked(Err, E->getLabelLoc()); + auto ToLabel = importChecked(Err, E->getLabel()); + auto ToType = importChecked(Err, E->getType()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) AddrLabelExpr( ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); } - ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { - auto Imp = importSeq(E->getSubExpr()); - if (!Imp) - return Imp.takeError(); - - Expr *ToSubExpr; - std::tie(ToSubExpr) = *Imp; + Error Err = Error::success(); + auto ToSubExpr = importChecked(Err, E->getSubExpr()); + if (Err) + return std::move(Err); // TODO : Handle APValue::ValueKind that require importing. + APValue::ValueKind Kind = E->getResultAPValueKind(); if (Kind == APValue::Int || Kind == APValue::Float || Kind == APValue::FixedPoint || Kind == APValue::ComplexFloat || @@ -6683,15 +6571,13 @@ E->getAPValueResult()); return ConstantExpr::Create(Importer.getToContext(), ToSubExpr); } - ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { - auto Imp = importSeq(E->getLParen(), E->getRParen(), E->getSubExpr()); - if (!Imp) - return Imp.takeError(); - - SourceLocation ToLParen, ToRParen; - Expr *ToSubExpr; - std::tie(ToLParen, ToRParen, ToSubExpr) = *Imp; + Error Err = Error::success(); + auto ToLParen = importChecked(Err, E->getLParen()); + auto ToRParen = importChecked(Err, E->getRParen()); + auto ToSubExpr = importChecked(Err, E->getSubExpr()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) ParenExpr(ToLParen, ToRParen, ToSubExpr); @@ -6715,30 +6601,25 @@ } ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { - auto Imp = importSeq( - E->getSubStmt(), E->getType(), E->getLParenLoc(), E->getRParenLoc()); - if (!Imp) - return Imp.takeError(); - - CompoundStmt *ToSubStmt; - QualType ToType; - SourceLocation ToLParenLoc, ToRParenLoc; - std::tie(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc) = *Imp; + Error Err = Error::success(); + auto ToSubStmt = importChecked(Err, E->getSubStmt()); + auto ToType = importChecked(Err, E->getType()); + auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); + auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) StmtExpr( ToSubStmt, ToType, ToLParenLoc, ToRParenLoc); } ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { - auto Imp = importSeq( - E->getSubExpr(), E->getType(), E->getOperatorLoc()); - if (!Imp) - return Imp.takeError(); - - Expr *ToSubExpr; - QualType ToType; - SourceLocation ToOperatorLoc; - std::tie(ToSubExpr, ToType, ToOperatorLoc) = *Imp; + Error Err = Error::success(); + auto ToSubExpr = importChecked(Err, E->getSubExpr()); + auto ToType = importChecked(Err, E->getType()); + auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) UnaryOperator( ToSubExpr, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(), @@ -6746,14 +6627,14 @@ } ExpectedStmt -ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { - auto Imp = importSeq(E->getType(), E->getOperatorLoc(), E->getRParenLoc()); - if (!Imp) - return Imp.takeError(); - QualType ToType; - SourceLocation ToOperatorLoc, ToRParenLoc; - std::tie(ToType, ToOperatorLoc, ToRParenLoc) = *Imp; +ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { + Error Err = Error::success(); + auto ToType = importChecked(Err, E->getType()); + auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); + auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); + if (Err) + return std::move(Err); if (E->isArgumentType()) { Expected ToArgumentTypeInfoOrErr = @@ -6775,15 +6656,13 @@ } ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { - auto Imp = importSeq( - E->getLHS(), E->getRHS(), E->getType(), E->getOperatorLoc()); - if (!Imp) - return Imp.takeError(); - - Expr *ToLHS, *ToRHS; - QualType ToType; - SourceLocation ToOperatorLoc; - std::tie(ToLHS, ToRHS, ToType, ToOperatorLoc) = *Imp; + Error Err = Error::success(); + auto ToLHS = importChecked(Err, E->getLHS()); + auto ToRHS = importChecked(Err, E->getRHS()); + auto ToType = importChecked(Err, E->getType()); + auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) BinaryOperator( ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), @@ -6791,37 +6670,34 @@ } ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { - auto Imp = importSeq( - E->getCond(), E->getQuestionLoc(), E->getLHS(), E->getColonLoc(), - E->getRHS(), E->getType()); - if (!Imp) - return Imp.takeError(); - - Expr *ToCond, *ToLHS, *ToRHS; - SourceLocation ToQuestionLoc, ToColonLoc; - QualType ToType; - std::tie(ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType) = *Imp; + Error Err = Error::success(); + auto ToCond = importChecked(Err, E->getCond()); + auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc()); + auto ToLHS = importChecked(Err, E->getLHS()); + auto ToColonLoc = importChecked(Err, E->getColonLoc()); + auto ToRHS = importChecked(Err, E->getRHS()); + auto ToType = importChecked(Err, E->getType()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) ConditionalOperator( ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, E->getValueKind(), E->getObjectKind()); } -ExpectedStmt ASTNodeImporter::VisitBinaryConditionalOperator( - BinaryConditionalOperator *E) { - auto Imp = importSeq( - E->getCommon(), E->getOpaqueValue(), E->getCond(), E->getTrueExpr(), - E->getFalseExpr(), E->getQuestionLoc(), E->getColonLoc(), E->getType()); - if (!Imp) - return Imp.takeError(); - - Expr *ToCommon, *ToCond, *ToTrueExpr, *ToFalseExpr; - OpaqueValueExpr *ToOpaqueValue; - SourceLocation ToQuestionLoc, ToColonLoc; - QualType ToType; - std::tie( - ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, ToQuestionLoc, - ToColonLoc, ToType) = *Imp; +ExpectedStmt +ASTNodeImporter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) { + Error Err = Error::success(); + auto ToCommon = importChecked(Err, E->getCommon()); + auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue()); + auto ToCond = importChecked(Err, E->getCond()); + auto ToTrueExpr = importChecked(Err, E->getTrueExpr()); + auto ToFalseExpr = importChecked(Err, E->getFalseExpr()); + auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc()); + auto ToColonLoc = importChecked(Err, E->getColonLoc()); + auto ToType = importChecked(Err, E->getType()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) BinaryConditionalOperator( ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, @@ -6830,19 +6706,15 @@ } ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { - auto Imp = importSeq( - E->getBeginLoc(), E->getQueriedTypeSourceInfo(), - E->getDimensionExpression(), E->getEndLoc(), E->getType()); - if (!Imp) - return Imp.takeError(); - - SourceLocation ToBeginLoc, ToEndLoc; - TypeSourceInfo *ToQueriedTypeSourceInfo; - Expr *ToDimensionExpression; - QualType ToType; - std::tie( - ToBeginLoc, ToQueriedTypeSourceInfo, ToDimensionExpression, ToEndLoc, - ToType) = *Imp; + Error Err = Error::success(); + auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); + auto ToQueriedTypeSourceInfo = + importChecked(Err, E->getQueriedTypeSourceInfo()); + auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression()); + auto ToEndLoc = importChecked(Err, E->getEndLoc()); + auto ToType = importChecked(Err, E->getType()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) ArrayTypeTraitExpr( ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), @@ -6850,15 +6722,13 @@ } ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { - auto Imp = importSeq( - E->getBeginLoc(), E->getQueriedExpression(), E->getEndLoc(), E->getType()); - if (!Imp) - return Imp.takeError(); - - SourceLocation ToBeginLoc, ToEndLoc; - Expr *ToQueriedExpression; - QualType ToType; - std::tie(ToBeginLoc, ToQueriedExpression, ToEndLoc, ToType) = *Imp; + Error Err = Error::success(); + auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); + auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression()); + auto ToEndLoc = importChecked(Err, E->getEndLoc()); + auto ToType = importChecked(Err, E->getType()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) ExpressionTraitExpr( ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), @@ -6866,30 +6736,25 @@ } ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { - auto Imp = importSeq( - E->getLocation(), E->getType(), E->getSourceExpr()); - if (!Imp) - return Imp.takeError(); - - SourceLocation ToLocation; - QualType ToType; - Expr *ToSourceExpr; - std::tie(ToLocation, ToType, ToSourceExpr) = *Imp; + Error Err = Error::success(); + auto ToLocation = importChecked(Err, E->getLocation()); + auto ToType = importChecked(Err, E->getType()); + auto ToSourceExpr = importChecked(Err, E->getSourceExpr()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) OpaqueValueExpr( ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); } ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { - auto Imp = importSeq( - E->getLHS(), E->getRHS(), E->getType(), E->getRBracketLoc()); - if (!Imp) - return Imp.takeError(); - - Expr *ToLHS, *ToRHS; - SourceLocation ToRBracketLoc; - QualType ToType; - std::tie(ToLHS, ToRHS, ToType, ToRBracketLoc) = *Imp; + Error Err = Error::success(); + auto ToLHS = importChecked(Err, E->getLHS()); + auto ToRHS = importChecked(Err, E->getRHS()); + auto ToType = importChecked(Err, E->getType()); + auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) ArraySubscriptExpr( ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), @@ -6898,17 +6763,16 @@ ExpectedStmt ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { - auto Imp = importSeq( - E->getLHS(), E->getRHS(), E->getType(), E->getComputationLHSType(), - E->getComputationResultType(), E->getOperatorLoc()); - if (!Imp) - return Imp.takeError(); - - Expr *ToLHS, *ToRHS; - QualType ToType, ToComputationLHSType, ToComputationResultType; - SourceLocation ToOperatorLoc; - std::tie(ToLHS, ToRHS, ToType, ToComputationLHSType, ToComputationResultType, - ToOperatorLoc) = *Imp; + Error Err = Error::success(); + auto ToLHS = importChecked(Err, E->getLHS()); + auto ToRHS = importChecked(Err, E->getRHS()); + auto ToType = importChecked(Err, E->getType()); + auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType()); + auto ToComputationResultType = + importChecked(Err, E->getComputationResultType()); + auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) CompoundAssignOperator( ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), @@ -6947,15 +6811,12 @@ } ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { - auto Imp1 = importSeq( - E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten()); - if (!Imp1) - return Imp1.takeError(); - - QualType ToType; - Expr *ToSubExpr; - TypeSourceInfo *ToTypeInfoAsWritten; - std::tie(ToType, ToSubExpr, ToTypeInfoAsWritten) = *Imp1; + Error Err = Error::success(); + auto ToType = importChecked(Err, E->getType()); + auto ToSubExpr = importChecked(Err, E->getSubExpr()); + auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten()); + if (Err) + return std::move(Err); Expected ToBasePathOrErr = ImportCastPath(E); if (!ToBasePathOrErr) @@ -7015,11 +6876,13 @@ const OffsetOfNode &FromNode = E->getComponent(I); SourceLocation ToBeginLoc, ToEndLoc; + if (FromNode.getKind() != OffsetOfNode::Base) { - auto Imp = importSeq(FromNode.getBeginLoc(), FromNode.getEndLoc()); - if (!Imp) - return Imp.takeError(); - std::tie(ToBeginLoc, ToEndLoc) = *Imp; + Error Err = Error::success(); + ToBeginLoc = importChecked(Err, FromNode.getBeginLoc()); + ToEndLoc = importChecked(Err, FromNode.getEndLoc()); + if (Err) + return std::move(Err); } switch (FromNode.getKind()) { @@ -7057,16 +6920,13 @@ ToExprs[I] = *ToIndexExprOrErr; } - auto Imp = importSeq( - E->getType(), E->getTypeSourceInfo(), E->getOperatorLoc(), - E->getRParenLoc()); - if (!Imp) - return Imp.takeError(); - - QualType ToType; - TypeSourceInfo *ToTypeSourceInfo; - SourceLocation ToOperatorLoc, ToRParenLoc; - std::tie(ToType, ToTypeSourceInfo, ToOperatorLoc, ToRParenLoc) = *Imp; + Error Err = Error::success(); + auto ToType = importChecked(Err, E->getType()); + auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); + auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); + auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); + if (Err) + return std::move(Err); return OffsetOfExpr::Create( Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, @@ -7074,15 +6934,13 @@ } ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { - auto Imp = importSeq( - E->getType(), E->getOperand(), E->getBeginLoc(), E->getEndLoc()); - if (!Imp) - return Imp.takeError(); - - QualType ToType; - Expr *ToOperand; - SourceLocation ToBeginLoc, ToEndLoc; - std::tie(ToType, ToOperand, ToBeginLoc, ToEndLoc) = *Imp; + Error Err = Error::success(); + auto ToType = importChecked(Err, E->getType()); + auto ToOperand = importChecked(Err, E->getOperand()); + auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); + auto ToEndLoc = importChecked(Err, E->getEndLoc()); + if (Err) + return std::move(Err); CanThrowResult ToCanThrow; if (E->isValueDependent()) @@ -7095,14 +6953,12 @@ } ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { - auto Imp = importSeq(E->getSubExpr(), E->getType(), E->getThrowLoc()); - if (!Imp) - return Imp.takeError(); - - Expr *ToSubExpr; - QualType ToType; - SourceLocation ToThrowLoc; - std::tie(ToSubExpr, ToType, ToThrowLoc) = *Imp; + Error Err = Error::success(); + auto ToSubExpr = importChecked(Err, E->getSubExpr()); + auto ToType = importChecked(Err, E->getType()); + auto ToThrowLoc = importChecked(Err, E->getThrowLoc()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) CXXThrowExpr( ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); @@ -7142,15 +6998,12 @@ ExpectedStmt ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { - auto Imp = importSeq( - E->getType(), E->getTypeSourceInfo(), E->getRParenLoc()); - if (!Imp) - return Imp.takeError(); - - QualType ToType; - TypeSourceInfo *ToTypeSourceInfo; - SourceLocation ToRParenLoc; - std::tie(ToType, ToTypeSourceInfo, ToRParenLoc) = *Imp; + Error Err = Error::success(); + auto ToType = importChecked(Err, E->getType()); + auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); + auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) CXXScalarValueInitExpr( ToType, ToTypeSourceInfo, ToRParenLoc); @@ -7172,18 +7025,15 @@ } ExpectedStmt + ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { - auto Imp = importSeq( - E->getConstructor(), E->getType(), E->getTypeSourceInfo(), - E->getParenOrBraceRange()); - if (!Imp) - return Imp.takeError(); - - CXXConstructorDecl *ToConstructor; - QualType ToType; - TypeSourceInfo *ToTypeSourceInfo; - SourceRange ToParenOrBraceRange; - std::tie(ToConstructor, ToType, ToTypeSourceInfo, ToParenOrBraceRange) = *Imp; + Error Err = Error::success(); + auto ToConstructor = importChecked(Err, E->getConstructor()); + auto ToType = importChecked(Err, E->getType()); + auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); + auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange()); + if (Err) + return std::move(Err); SmallVector ToArgs(E->getNumArgs()); if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) @@ -7202,14 +7052,11 @@ if (Error Err = ImportDeclContext(D, DC, LexicalDC)) return std::move(Err); - auto Imp = importSeq(D->getTemporaryExpr(), D->getExtendingDecl()); - // FIXME: the APValue should be imported as well if present. - if (!Imp) - return Imp.takeError(); - - Expr *Temporary; - ValueDecl *ExtendingDecl; - std::tie(Temporary, ExtendingDecl) = *Imp; + Error Err = Error::success(); + auto Temporary = importChecked(Err, D->getTemporaryExpr()); + auto ExtendingDecl = importChecked(Err, D->getExtendingDecl()); + if (Err) + return std::move(Err); // FIXME: Should ManglingNumber get numbers associated with 'to' context? LifetimeExtendedTemporaryDecl *To; @@ -7224,17 +7071,15 @@ ExpectedStmt ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { - auto Imp = importSeq(E->getType(), - E->getLifetimeExtendedTemporaryDecl() ? nullptr - : E->getSubExpr(), - E->getLifetimeExtendedTemporaryDecl()); - if (!Imp) - return Imp.takeError(); - - QualType ToType; - Expr *ToTemporaryExpr; - LifetimeExtendedTemporaryDecl *ToMaterializedDecl; - std::tie(ToType, ToTemporaryExpr, ToMaterializedDecl) = *Imp; + Error Err = Error::success(); + auto ToType = importChecked(Err, E->getType()); + Expr *ToTemporaryExpr = importChecked( + Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr()); + auto ToMaterializedDecl = + importChecked(Err, E->getLifetimeExtendedTemporaryDecl()); + if (Err) + return std::move(Err); + if (!ToTemporaryExpr) ToTemporaryExpr = cast(ToMaterializedDecl->getTemporaryExpr()); @@ -7246,29 +7091,25 @@ } ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { - auto Imp = importSeq( - E->getType(), E->getPattern(), E->getEllipsisLoc()); - if (!Imp) - return Imp.takeError(); - - QualType ToType; - Expr *ToPattern; - SourceLocation ToEllipsisLoc; - std::tie(ToType, ToPattern, ToEllipsisLoc) = *Imp; + Error Err = Error::success(); + auto ToType = importChecked(Err, E->getType()); + auto ToPattern = importChecked(Err, E->getPattern()); + auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) PackExpansionExpr( ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); } ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { - auto Imp = importSeq( - E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc()); - if (!Imp) - return Imp.takeError(); - - SourceLocation ToOperatorLoc, ToPackLoc, ToRParenLoc; - NamedDecl *ToPack; - std::tie(ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc) = *Imp; + Error Err = Error::success(); + auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); + auto ToPack = importChecked(Err, E->getPack()); + auto ToPackLoc = importChecked(Err, E->getPackLoc()); + auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); + if (Err) + return std::move(Err); Optional Length; if (!E->isValueDependent()) @@ -7290,23 +7131,19 @@ ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { - auto Imp = importSeq( - E->getOperatorNew(), E->getOperatorDelete(), E->getTypeIdParens(), - E->getArraySize(), E->getInitializer(), E->getType(), - E->getAllocatedTypeSourceInfo(), E->getSourceRange(), - E->getDirectInitRange()); - if (!Imp) - return Imp.takeError(); - - FunctionDecl *ToOperatorNew, *ToOperatorDelete; - SourceRange ToTypeIdParens, ToSourceRange, ToDirectInitRange; - Optional ToArraySize; - Expr *ToInitializer; - QualType ToType; - TypeSourceInfo *ToAllocatedTypeSourceInfo; - std::tie( - ToOperatorNew, ToOperatorDelete, ToTypeIdParens, ToArraySize, ToInitializer, - ToType, ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange) = *Imp; + Error Err = Error::success(); + auto ToOperatorNew = importChecked(Err, E->getOperatorNew()); + auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete()); + auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens()); + auto ToArraySize = importChecked(Err, E->getArraySize()); + auto ToInitializer = importChecked(Err, E->getInitializer()); + auto ToType = importChecked(Err, E->getType()); + auto ToAllocatedTypeSourceInfo = + importChecked(Err, E->getAllocatedTypeSourceInfo()); + auto ToSourceRange = importChecked(Err, E->getSourceRange()); + auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange()); + if (Err) + return std::move(Err); SmallVector ToPlacementArgs(E->getNumPlacementArgs()); if (Error Err = @@ -7322,16 +7159,13 @@ } ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { - auto Imp = importSeq( - E->getType(), E->getOperatorDelete(), E->getArgument(), E->getBeginLoc()); - if (!Imp) - return Imp.takeError(); - - QualType ToType; - FunctionDecl *ToOperatorDelete; - Expr *ToArgument; - SourceLocation ToBeginLoc; - std::tie(ToType, ToOperatorDelete, ToArgument, ToBeginLoc) = *Imp; + Error Err = Error::success(); + auto ToType = importChecked(Err, E->getType()); + auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete()); + auto ToArgument = importChecked(Err, E->getArgument()); + auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) CXXDeleteExpr( ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), @@ -7340,17 +7174,13 @@ } ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { - auto Imp = importSeq( - E->getType(), E->getLocation(), E->getConstructor(), - E->getParenOrBraceRange()); - if (!Imp) - return Imp.takeError(); - - QualType ToType; - SourceLocation ToLocation; - CXXConstructorDecl *ToConstructor; - SourceRange ToParenOrBraceRange; - std::tie(ToType, ToLocation, ToConstructor, ToParenOrBraceRange) = *Imp; + Error Err = Error::success(); + auto ToType = importChecked(Err, E->getType()); + auto ToLocation = importChecked(Err, E->getLocation()); + auto ToConstructor = importChecked(Err, E->getConstructor()); + auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange()); + if (Err) + return std::move(Err); SmallVector ToArgs(E->getNumArgs()); if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) @@ -7379,15 +7209,12 @@ } ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { - auto Imp = importSeq( - E->getCallee(), E->getType(), E->getRParenLoc()); - if (!Imp) - return Imp.takeError(); - - Expr *ToCallee; - QualType ToType; - SourceLocation ToRParenLoc; - std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; + Error Err = Error::success(); + auto ToCallee = importChecked(Err, E->getCallee()); + auto ToType = importChecked(Err, E->getType()); + auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); + if (Err) + return std::move(Err); SmallVector ToArgs(E->getNumArgs()); if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) @@ -7424,30 +7251,18 @@ } ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { - auto Imp1 = importSeq( - E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), - E->getTemplateKeywordLoc(), E->getMemberDecl(), E->getType()); - if (!Imp1) - return Imp1.takeError(); - - Expr *ToBase; - SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; - NestedNameSpecifierLoc ToQualifierLoc; - ValueDecl *ToMemberDecl; - QualType ToType; - std::tie( - ToBase, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, - ToType) = *Imp1; - - auto Imp2 = importSeq( - E->getFoundDecl().getDecl(), E->getMemberNameInfo().getName(), - E->getMemberNameInfo().getLoc(), E->getLAngleLoc(), E->getRAngleLoc()); - if (!Imp2) - return Imp2.takeError(); - NamedDecl *ToDecl; - DeclarationName ToName; - SourceLocation ToLoc, ToLAngleLoc, ToRAngleLoc; - std::tie(ToDecl, ToName, ToLoc, ToLAngleLoc, ToRAngleLoc) = *Imp2; + Error Err = Error::success(); + auto ToBase = importChecked(Err, E->getBase()); + auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); + auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); + auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); + auto ToMemberDecl = importChecked(Err, E->getMemberDecl()); + auto ToType = importChecked(Err, E->getType()); + auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl()); + auto ToName = importChecked(Err, E->getMemberNameInfo().getName()); + auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc()); + if (Err) + return std::move(Err); DeclAccessPair ToFoundDecl = DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); @@ -7472,19 +7287,15 @@ ExpectedStmt ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { - auto Imp = importSeq( - E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), - E->getScopeTypeInfo(), E->getColonColonLoc(), E->getTildeLoc()); - if (!Imp) - return Imp.takeError(); - - Expr *ToBase; - SourceLocation ToOperatorLoc, ToColonColonLoc, ToTildeLoc; - NestedNameSpecifierLoc ToQualifierLoc; - TypeSourceInfo *ToScopeTypeInfo; - std::tie( - ToBase, ToOperatorLoc, ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, - ToTildeLoc) = *Imp; + Error Err = Error::success(); + auto ToBase = importChecked(Err, E->getBase()); + auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); + auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); + auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo()); + auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc()); + auto ToTildeLoc = importChecked(Err, E->getTildeLoc()); + if (Err) + return std::move(Err); PseudoDestructorTypeStorage Storage; if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { @@ -7507,19 +7318,15 @@ ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( CXXDependentScopeMemberExpr *E) { - auto Imp = importSeq( - E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), - E->getTemplateKeywordLoc(), E->getFirstQualifierFoundInScope()); - if (!Imp) - return Imp.takeError(); - - QualType ToType; - SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; - NestedNameSpecifierLoc ToQualifierLoc; - NamedDecl *ToFirstQualifierFoundInScope; - std::tie( - ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, - ToFirstQualifierFoundInScope) = *Imp; + Error Err = Error::success(); + auto ToType = importChecked(Err, E->getType()); + auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); + auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); + auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); + auto ToFirstQualifierFoundInScope = + importChecked(Err, E->getFirstQualifierFoundInScope()); + if (Err) + return std::move(Err); Expr *ToBase = nullptr; if (!E->isImplicitAccess()) { @@ -7530,22 +7337,23 @@ } TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; + if (E->hasExplicitTemplateArgs()) { - if (Error Err = ImportTemplateArgumentListInfo( - E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), - ToTAInfo)) + if (Error Err = + ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), + E->template_arguments(), ToTAInfo)) return std::move(Err); ResInfo = &ToTAInfo; } + auto ToMember = importChecked(Err, E->getMember()); + auto ToMemberLoc = importChecked(Err, E->getMemberLoc()); + if (Err) + return std::move(Err); + DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc); - auto ToMemberNameInfoOrErr = importSeq(E->getMember(), E->getMemberLoc()); - if (!ToMemberNameInfoOrErr) - return ToMemberNameInfoOrErr.takeError(); - DeclarationNameInfo ToMemberNameInfo( - std::get<0>(*ToMemberNameInfoOrErr), std::get<1>(*ToMemberNameInfoOrErr)); // Import additional name location/type info. - if (Error Err = ImportDeclarationNameLoc( - E->getMemberNameInfo(), ToMemberNameInfo)) + if (Error Err = + ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo)) return std::move(Err); return CXXDependentScopeMemberExpr::Create( @@ -7556,17 +7364,15 @@ ExpectedStmt ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { - auto Imp = importSeq(E->getQualifierLoc(), E->getTemplateKeywordLoc(), - E->getDeclName(), E->getNameInfo().getLoc(), - E->getLAngleLoc(), E->getRAngleLoc()); - if (!Imp) - return Imp.takeError(); - - NestedNameSpecifierLoc ToQualifierLoc; - SourceLocation ToTemplateKeywordLoc, ToNameLoc, ToLAngleLoc, ToRAngleLoc; - DeclarationName ToDeclName; - std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToNameLoc, - ToLAngleLoc, ToRAngleLoc) = *Imp; + Error Err = Error::success(); + auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); + auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); + auto ToDeclName = importChecked(Err, E->getDeclName()); + auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc()); + auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc()); + auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc()); + if (Err) + return std::move(Err); DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc); if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) @@ -7588,14 +7394,12 @@ ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( CXXUnresolvedConstructExpr *E) { - auto Imp = importSeq( - E->getLParenLoc(), E->getRParenLoc(), E->getTypeSourceInfo()); - if (!Imp) - return Imp.takeError(); - - SourceLocation ToLParenLoc, ToRParenLoc; - TypeSourceInfo *ToTypeSourceInfo; - std::tie(ToLParenLoc, ToRParenLoc, ToTypeSourceInfo) = *Imp; + Error Err = Error::success(); + auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); + auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); + auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); + if (Err) + return std::move(Err); SmallVector ToArgs(E->arg_size()); if (Error Err = @@ -7617,11 +7421,13 @@ if (!ToQualifierLocOrErr) return ToQualifierLocOrErr.takeError(); - auto ToNameInfoOrErr = importSeq(E->getName(), E->getNameLoc()); - if (!ToNameInfoOrErr) - return ToNameInfoOrErr.takeError(); - DeclarationNameInfo ToNameInfo( - std::get<0>(*ToNameInfoOrErr), std::get<1>(*ToNameInfoOrErr)); + Error Err = Error::success(); + auto ToName = importChecked(Err, E->getName()); + auto ToNameLoc = importChecked(Err, E->getNameLoc()); + if (Err) + return std::move(Err); + DeclarationNameInfo ToNameInfo(ToName, ToNameLoc); + // Import additional name location/type info. if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) return std::move(Err); @@ -7658,21 +7464,17 @@ ExpectedStmt ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { - auto Imp1 = importSeq( - E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), - E->getTemplateKeywordLoc()); - if (!Imp1) - return Imp1.takeError(); - - QualType ToType; - SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; - NestedNameSpecifierLoc ToQualifierLoc; - std::tie(ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc) = *Imp1; - - auto Imp2 = importSeq(E->getName(), E->getNameLoc()); - if (!Imp2) - return Imp2.takeError(); - DeclarationNameInfo ToNameInfo(std::get<0>(*Imp2), std::get<1>(*Imp2)); + Error Err = Error::success(); + auto ToType = importChecked(Err, E->getType()); + auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); + auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); + auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); + auto ToName = importChecked(Err, E->getName()); + auto ToNameLoc = importChecked(Err, E->getNameLoc()); + if (Err) + return std::move(Err); + + DeclarationNameInfo ToNameInfo(ToName, ToNameLoc); // Import additional name location/type info. if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) return std::move(Err); @@ -7709,14 +7511,12 @@ } ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { - auto Imp = importSeq(E->getCallee(), E->getType(), E->getRParenLoc()); - if (!Imp) - return Imp.takeError(); - - Expr *ToCallee; - QualType ToType; - SourceLocation ToRParenLoc; - std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; + Error Err = Error::success(); + auto ToCallee = importChecked(Err, E->getCallee()); + auto ToType = importChecked(Err, E->getType()); + auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); + if (Err) + return std::move(Err); unsigned NumArgs = E->getNumArgs(); llvm::SmallVector ToArgs(NumArgs); @@ -7759,14 +7559,12 @@ if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) return std::move(Err); - auto Imp = importSeq( - E->getIntroducerRange(), E->getCaptureDefaultLoc(), E->getEndLoc()); - if (!Imp) - return Imp.takeError(); - - SourceRange ToIntroducerRange; - SourceLocation ToCaptureDefaultLoc, ToEndLoc; - std::tie(ToIntroducerRange, ToCaptureDefaultLoc, ToEndLoc) = *Imp; + Error Err = Error::success(); + auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange()); + auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc()); + auto ToEndLoc = importChecked(Err, E->getEndLoc()); + if (Err) + return std::move(Err); return LambdaExpr::Create( Importer.getToContext(), ToClass, ToIntroducerRange, @@ -7777,13 +7575,12 @@ ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { - auto Imp = importSeq(E->getLBraceLoc(), E->getRBraceLoc(), E->getType()); - if (!Imp) - return Imp.takeError(); - - SourceLocation ToLBraceLoc, ToRBraceLoc; - QualType ToType; - std::tie(ToLBraceLoc, ToRBraceLoc, ToType) = *Imp; + Error Err = Error::success(); + auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc()); + auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc()); + auto ToType = importChecked(Err, E->getType()); + if (Err) + return std::move(Err); SmallVector ToExprs(E->getNumInits()); if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) @@ -7838,14 +7635,12 @@ ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( CXXInheritedCtorInitExpr *E) { - auto Imp = importSeq(E->getLocation(), E->getType(), E->getConstructor()); - if (!Imp) - return Imp.takeError(); - - SourceLocation ToLocation; - QualType ToType; - CXXConstructorDecl *ToConstructor; - std::tie(ToLocation, ToType, ToConstructor) = *Imp; + Error Err = Error::success(); + auto ToLocation = importChecked(Err, E->getLocation()); + auto ToType = importChecked(Err, E->getType()); + auto ToConstructor = importChecked(Err, E->getConstructor()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) CXXInheritedCtorInitExpr( ToLocation, ToType, ToConstructor, E->constructsVBase(), @@ -7853,13 +7648,12 @@ } ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { - auto Imp = importSeq(E->getType(), E->getCommonExpr(), E->getSubExpr()); - if (!Imp) - return Imp.takeError(); - - QualType ToType; - Expr *ToCommonExpr, *ToSubExpr; - std::tie(ToType, ToCommonExpr, ToSubExpr) = *Imp; + Error Err = Error::success(); + auto ToType = importChecked(Err, E->getType()); + auto ToCommonExpr = importChecked(Err, E->getCommonExpr()); + auto ToSubExpr = importChecked(Err, E->getSubExpr()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) ArrayInitLoopExpr( ToType, ToCommonExpr, ToSubExpr); @@ -7890,20 +7684,15 @@ } ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { - auto Imp = importSeq( - E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten(), - E->getOperatorLoc(), E->getRParenLoc(), E->getAngleBrackets()); - if (!Imp) - return Imp.takeError(); - - QualType ToType; - Expr *ToSubExpr; - TypeSourceInfo *ToTypeInfoAsWritten; - SourceLocation ToOperatorLoc, ToRParenLoc; - SourceRange ToAngleBrackets; - std::tie( - ToType, ToSubExpr, ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, - ToAngleBrackets) = *Imp; + Error Err = Error::success(); + auto ToType = importChecked(Err, E->getType()); + auto ToSubExpr = importChecked(Err, E->getSubExpr()); + auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten()); + auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); + auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); + auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets()); + if (Err) + return std::move(Err); ExprValueKind VK = E->getValueKind(); CastKind CK = E->getCastKind(); @@ -7935,30 +7724,25 @@ ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( SubstNonTypeTemplateParmExpr *E) { - auto Imp = importSeq( - E->getType(), E->getExprLoc(), E->getParameter(), E->getReplacement()); - if (!Imp) - return Imp.takeError(); - - QualType ToType; - SourceLocation ToExprLoc; - NonTypeTemplateParmDecl *ToParameter; - Expr *ToReplacement; - std::tie(ToType, ToExprLoc, ToParameter, ToReplacement) = *Imp; + Error Err = Error::success(); + auto ToType = importChecked(Err, E->getType()); + auto ToExprLoc = importChecked(Err, E->getExprLoc()); + auto ToParameter = importChecked(Err, E->getParameter()); + auto ToReplacement = importChecked(Err, E->getReplacement()); + if (Err) + return std::move(Err); return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); } ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { - auto Imp = importSeq( - E->getType(), E->getBeginLoc(), E->getEndLoc()); - if (!Imp) - return Imp.takeError(); - - QualType ToType; - SourceLocation ToBeginLoc, ToEndLoc; - std::tie(ToType, ToBeginLoc, ToEndLoc) = *Imp; + Error Err = Error::success(); + auto ToType = importChecked(Err, E->getType()); + auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); + auto ToEndLoc = importChecked(Err, E->getEndLoc()); + if (Err) + return std::move(Err); SmallVector ToArgs(E->getNumArgs()); if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))