From: Aaron Ballman Date: Mon, 17 Mar 2014 15:38:09 +0000 (+0000) Subject: [C++11] Replacing FunctionProtoType iterators exception_begin() and exception_end... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=976b91306259e68e9e52cea50c8b2f7f21ceff7a;p=clang [C++11] Replacing FunctionProtoType iterators exception_begin() and exception_end() with iterator_range exceptions(). Updating all of the usages of the iterators with range-based for loops. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204046 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DataRecursiveASTVisitor.h b/include/clang/AST/DataRecursiveASTVisitor.h index a92c334957..57f4043389 100644 --- a/include/clang/AST/DataRecursiveASTVisitor.h +++ b/include/clang/AST/DataRecursiveASTVisitor.h @@ -877,10 +877,8 @@ DEF_TRAVERSE_TYPE(FunctionProtoType, { TRY_TO(TraverseType(A)); } - for (FunctionProtoType::exception_iterator E = T->exception_begin(), - EEnd = T->exception_end(); - E != EEnd; ++E) { - TRY_TO(TraverseType(*E)); + for (const auto &E : T->exceptions()) { + TRY_TO(TraverseType(E)); } }) @@ -1109,10 +1107,8 @@ DEF_TRAVERSE_TYPELOC(FunctionProtoType, { } } - for (FunctionProtoType::exception_iterator E = T->exception_begin(), - EEnd = T->exception_end(); - E != EEnd; ++E) { - TRY_TO(TraverseType(*E)); + for (const auto &E : T->exceptions()) { + TRY_TO(TraverseType(E)); } }) diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h index 608ad195df..54412bf4bc 100644 --- a/include/clang/AST/RecursiveASTVisitor.h +++ b/include/clang/AST/RecursiveASTVisitor.h @@ -958,10 +958,8 @@ DEF_TRAVERSE_TYPE(FunctionProtoType, { TRY_TO(TraverseType(A)); } - for (FunctionProtoType::exception_iterator E = T->exception_begin(), - EEnd = T->exception_end(); - E != EEnd; ++E) { - TRY_TO(TraverseType(*E)); + for (const auto &E : T->exceptions()) { + TRY_TO(TraverseType(E)); } }) @@ -1190,10 +1188,8 @@ DEF_TRAVERSE_TYPELOC(FunctionProtoType, { } } - for (FunctionProtoType::exception_iterator E = T->exception_begin(), - EEnd = T->exception_end(); - E != EEnd; ++E) { - TRY_TO(TraverseType(*E)); + for (const auto &E : T->exceptions()) { + TRY_TO(TraverseType(E)); } }) diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 6b3bac1e60..e9eeeec2c0 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -3073,6 +3073,11 @@ public: } typedef const QualType *exception_iterator; + typedef llvm::iterator_range exception_range; + + exception_range exceptions() const { + return exception_range(exception_begin(), exception_end()); + } exception_iterator exception_begin() const { // exceptions begin where arguments end return param_type_end(); diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index 318636a575..ad2dbe1248 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -1607,10 +1607,8 @@ QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { // Import exception types SmallVector ExceptionTypes; - for (FunctionProtoType::exception_iterator E = T->exception_begin(), - EEnd = T->exception_end(); - E != EEnd; ++E) { - QualType ExceptionType = Importer.Import(*E); + for (const auto &E : T->exceptions()) { + QualType ExceptionType = Importer.Import(E); if (ExceptionType.isNull()) return QualType(); ExceptionTypes.push_back(ExceptionType); diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index d056067835..fc37727344 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -212,11 +212,9 @@ Sema::ImplicitExceptionSpecification::CalledDecl(SourceLocation CallLoc, "Shouldn't collect exceptions when throw-all is guaranteed."); ComputedEST = EST_Dynamic; // Record the exceptions in this function's exception specification. - for (FunctionProtoType::exception_iterator E = Proto->exception_begin(), - EEnd = Proto->exception_end(); - E != EEnd; ++E) - if (ExceptionsSeen.insert(Self->Context.getCanonicalType(*E))) - Exceptions.push_back(*E); + for (const auto &E : Proto->exceptions()) + if (ExceptionsSeen.insert(Self->Context.getCanonicalType(E))) + Exceptions.push_back(E); } void Sema::ImplicitExceptionSpecification::CalledExpr(Expr *E) { @@ -12573,10 +12571,8 @@ bool Sema::checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method) { return true; case EST_Dynamic: - for (FunctionProtoType::exception_iterator E = Proto->exception_begin(), - EEnd = Proto->exception_end(); - E != EEnd; ++E) { - if (!Finder.TraverseType(*E)) + for (const auto &E : Proto->exceptions()) { + if (!Finder.TraverseType(E)) return true; } break; diff --git a/lib/Sema/SemaExceptionSpec.cpp b/lib/Sema/SemaExceptionSpec.cpp index 1c2a8dbc30..f9a8a5db46 100644 --- a/lib/Sema/SemaExceptionSpec.cpp +++ b/lib/Sema/SemaExceptionSpec.cpp @@ -246,16 +246,13 @@ bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New) { case EST_Dynamic: { OS << "throw("; bool OnFirstException = true; - for (FunctionProtoType::exception_iterator E = OldProto->exception_begin(), - EEnd = OldProto->exception_end(); - E != EEnd; - ++E) { + for (const auto &E : OldProto->exceptions()) { if (OnFirstException) OnFirstException = false; else OS << ", "; - OS << E->getAsString(getPrintingPolicy()); + OS << E.getAsString(getPrintingPolicy()); } OS << ")"; break; @@ -499,13 +496,11 @@ bool Sema::CheckEquivalentExceptionSpec(const PartialDiagnostic &DiagID, // Both have a dynamic exception spec. Collect the first set, then compare // to the second. llvm::SmallPtrSet OldTypes, NewTypes; - for (FunctionProtoType::exception_iterator I = Old->exception_begin(), - E = Old->exception_end(); I != E; ++I) - OldTypes.insert(Context.getCanonicalType(*I).getUnqualifiedType()); + for (const auto &I : Old->exceptions()) + OldTypes.insert(Context.getCanonicalType(I).getUnqualifiedType()); - for (FunctionProtoType::exception_iterator I = New->exception_begin(), - E = New->exception_end(); I != E && Success; ++I) { - CanQualType TypePtr = Context.getCanonicalType(*I).getUnqualifiedType(); + for (const auto &I : New->exceptions()) { + CanQualType TypePtr = Context.getCanonicalType(I).getUnqualifiedType(); if(OldTypes.count(TypePtr)) NewTypes.insert(TypePtr); else @@ -613,10 +608,9 @@ bool Sema::CheckExceptionSpecSubset( "Exception spec subset: non-dynamic case slipped through."); // Neither contains everything or nothing. Do a proper comparison. - for (FunctionProtoType::exception_iterator SubI = Subset->exception_begin(), - SubE = Subset->exception_end(); SubI != SubE; ++SubI) { + for (const auto &SubI : Subset->exceptions()) { // Take one type from the subset. - QualType CanonicalSubT = Context.getCanonicalType(*SubI); + QualType CanonicalSubT = Context.getCanonicalType(SubI); // Unwrap pointers and references so that we can do checks within a class // hierarchy. Don't unwrap member pointers; they don't have hierarchy // conversions on the pointee. @@ -635,10 +629,8 @@ bool Sema::CheckExceptionSpecSubset( bool Contained = false; // Make sure it's in the superset. - for (FunctionProtoType::exception_iterator SuperI = - Superset->exception_begin(), SuperE = Superset->exception_end(); - SuperI != SuperE; ++SuperI) { - QualType CanonicalSuperT = Context.getCanonicalType(*SuperI); + for (const auto &SuperI : Superset->exceptions()) { + QualType CanonicalSuperT = Context.getCanonicalType(SuperI); // SubT must be SuperT or derived from it, or pointer or reference to // such types. if (const ReferenceType *RefTy = CanonicalSuperT->getAs())