]> granicus.if.org Git - clang/commitdiff
[C++11] Replacing FunctionProtoType iterators exception_begin() and exception_end...
authorAaron Ballman <aaron@aaronballman.com>
Mon, 17 Mar 2014 15:38:09 +0000 (15:38 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Mon, 17 Mar 2014 15:38:09 +0000 (15:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204046 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DataRecursiveASTVisitor.h
include/clang/AST/RecursiveASTVisitor.h
include/clang/AST/Type.h
lib/AST/ASTImporter.cpp
lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaExceptionSpec.cpp

index a92c3349579d094a713a3ee26dde31a62ae26113..57f4043389666d34bb84697e2e8b0e47699359f3 100644 (file)
@@ -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));
     }
   })
 
index 608ad195df8a8ff1221ece8b6382a0f243dfdee4..54412bf4bca6d7668762c3d0e00db7b18de6912d 100644 (file)
@@ -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));
     }
   })
 
index 6b3bac1e6038b07d030b4507022eb388db2af81a..e9eeeec2c0c4a1954ac5b15a87f3af7f5f32fb4c 100644 (file)
@@ -3073,6 +3073,11 @@ public:
   }
 
   typedef const QualType *exception_iterator;
+  typedef llvm::iterator_range<exception_iterator> 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();
index 318636a575c00ad0b91ed56d9c0060274e958cd7..ad2dbe12482d55227ed71df97abb7136e22ab55c 100644 (file)
@@ -1607,10 +1607,8 @@ QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
   
   // Import exception types
   SmallVector<QualType, 4> 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);
index d056067835375f0188063a2c296bbf465996fea9..fc37727344c4996c7b44fe793129d9ac62b04287 100644 (file)
@@ -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;
index 1c2a8dbc3012750d4d7db2d37cbac01a095d8987..f9a8a5db466a15694d7c72d5052aec9cf78f15e8 100644 (file)
@@ -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<CanQualType, 8> 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<ReferenceType>())