r213098 - Switching some iterator-based for loops to use range-based for loops. No functional changes intended.

Aaron Ballman aaron at aaronballman.com
Tue Jul 15 15:03:52 PDT 2014


Author: aaronballman
Date: Tue Jul 15 17:03:49 2014
New Revision: 213098

URL: http://llvm.org/viewvc/llvm-project?rev=213098&view=rev
Log:
Switching some iterator-based for loops to use range-based for loops. No functional changes intended.

Modified:
    cfe/trunk/lib/Sema/SemaLookup.cpp

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=213098&r1=213097&r2=213098&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Jul 15 17:03:49 2014
@@ -1767,9 +1767,7 @@ bool Sema::LookupQualifiedName(LookupRes
 
   // Lookup in a base class succeeded; return these results.
 
-  DeclContext::lookup_result DR = Paths.front().Decls;
-  for (DeclContext::lookup_iterator I = DR.begin(), E = DR.end(); I != E; ++I) {
-    NamedDecl *D = *I;
+  for (auto *D : Paths.front().Decls) {
     AccessSpecifier AS = CXXRecordDecl::MergeAccess(SubobjectAccess,
                                                     D->getAccess());
     R.addDecl(D, AS);
@@ -1877,16 +1875,15 @@ void Sema::DiagnoseAmbiguousLookup(Looku
 
     llvm::SmallPtrSet<NamedDecl*,8> TagDecls;
 
-    LookupResult::iterator DI, DE = Result.end();
-    for (DI = Result.begin(); DI != DE; ++DI)
-      if (TagDecl *TD = dyn_cast<TagDecl>(*DI)) {
+    for (auto *D : Result)
+      if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
         TagDecls.insert(TD);
         Diag(TD->getLocation(), diag::note_hidden_tag);
       }
 
-    for (DI = Result.begin(); DI != DE; ++DI)
-      if (!isa<TagDecl>(*DI))
-        Diag((*DI)->getLocation(), diag::note_hiding_object);
+    for (auto *D : Result)
+      if (!isa<TagDecl>(D))
+        Diag(D->getLocation(), diag::note_hiding_object);
 
     // For recovery purposes, go ahead and implement the hiding.
     LookupResult::Filter F = Result.makeFilter();
@@ -1901,9 +1898,8 @@ void Sema::DiagnoseAmbiguousLookup(Looku
   case LookupResult::AmbiguousReference: {
     Diag(NameLoc, diag::err_ambiguous_reference) << Name << LookupRange;
 
-    LookupResult::iterator DI = Result.begin(), DE = Result.end();
-    for (; DI != DE; ++DI)
-      Diag((*DI)->getLocation(), diag::note_ambiguous_candidate) << *DI;
+    for (auto *D : Result)
+      Diag(D->getLocation(), diag::note_ambiguous_candidate) << D;
     break;
   }
   }
@@ -2298,10 +2294,9 @@ void Sema::FindAssociatedClassesAndNames
     UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Arg);
     if (!ULE) continue;
 
-    for (UnresolvedSetIterator I = ULE->decls_begin(), E = ULE->decls_end();
-           I != E; ++I) {
+    for (const auto *D : ULE->decls()) {
       // Look through any using declarations to find the underlying function.
-      FunctionDecl *FDecl = (*I)->getUnderlyingDecl()->getAsFunction();
+      const FunctionDecl *FDecl = D->getUnderlyingDecl()->getAsFunction();
 
       // Add the classes and namespaces associated with the parameter
       // types and return type of this function.
@@ -2472,11 +2467,7 @@ Sema::SpecialMemberOverloadResult *Sema:
   // from an external source and invalidate lookup_result.
   SmallVector<NamedDecl *, 8> Candidates(R.begin(), R.end());
 
-  for (SmallVectorImpl<NamedDecl *>::iterator I = Candidates.begin(),
-                                              E = Candidates.end();
-       I != E; ++I) {
-    NamedDecl *Cand = *I;
-
+  for (auto *Cand : Candidates) {
     if (Cand->isInvalidDecl())
       continue;
 
@@ -2804,9 +2795,7 @@ void Sema::ArgumentDependentLookup(Decla
   //
   // Here, we compute Y and add its members to the overloaded
   // candidate set.
-  for (AssociatedNamespaceSet::iterator NS = AssociatedNamespaces.begin(),
-                                     NSEnd = AssociatedNamespaces.end();
-       NS != NSEnd; ++NS) {
+  for (auto *NS : AssociatedNamespaces) {
     //   When considering an associated namespace, the lookup is the
     //   same as the lookup performed when the associated namespace is
     //   used as a qualifier (3.4.3.2) except that:
@@ -2818,10 +2807,8 @@ void Sema::ArgumentDependentLookup(Decla
     //        associated classes are visible within their respective
     //        namespaces even if they are not visible during an ordinary
     //        lookup (11.4).
-    DeclContext::lookup_result R = (*NS)->lookup(Name);
-    for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E;
-         ++I) {
-      NamedDecl *D = *I;
+    DeclContext::lookup_result R = NS->lookup(Name);
+    for (auto *D : R) {
       // If the only declaration here is an ordinary friend, consider
       // it only if it was declared in an associated classes.
       if ((D->getIdentifierNamespace() & Decl::IDNS_Ordinary) == 0) {
@@ -2938,31 +2925,29 @@ NamedDecl *VisibleDeclsRecord::checkHidd
     if (Pos == SM->end())
       continue;
 
-    for (ShadowMapEntry::iterator I = Pos->second.begin(),
-                               IEnd = Pos->second.end();
-         I != IEnd; ++I) {
+    for (auto *D : Pos->second) {
       // A tag declaration does not hide a non-tag declaration.
-      if ((*I)->hasTagIdentifierNamespace() &&
+      if (D->hasTagIdentifierNamespace() &&
           (IDNS & (Decl::IDNS_Member | Decl::IDNS_Ordinary |
                    Decl::IDNS_ObjCProtocol)))
         continue;
 
       // Protocols are in distinct namespaces from everything else.
-      if ((((*I)->getIdentifierNamespace() & Decl::IDNS_ObjCProtocol)
+      if (((D->getIdentifierNamespace() & Decl::IDNS_ObjCProtocol)
            || (IDNS & Decl::IDNS_ObjCProtocol)) &&
-          (*I)->getIdentifierNamespace() != IDNS)
+          D->getIdentifierNamespace() != IDNS)
         continue;
 
       // Functions and function templates in the same scope overload
       // rather than hide.  FIXME: Look for hiding based on function
       // signatures!
-      if ((*I)->getUnderlyingDecl()->isFunctionOrFunctionTemplate() &&
+      if (D->getUnderlyingDecl()->isFunctionOrFunctionTemplate() &&
           ND->getUnderlyingDecl()->isFunctionOrFunctionTemplate() &&
           SM == ShadowMaps.rbegin())
         continue;
 
       // We've found a declaration that hides this one.
-      return *I;
+      return D;
     }
   }
 
@@ -3787,10 +3772,8 @@ void TypoCorrectionConsumer::NamespaceSp
     std::sort(sortedDistances.begin(), sortedDistances.end());
 
   Specifiers.clear();
-  for (SmallVectorImpl<unsigned>::iterator DI = sortedDistances.begin(),
-                                        DIEnd = sortedDistances.end();
-       DI != DIEnd; ++DI) {
-    SpecifierInfoList &SpecList = DistanceMap[*DI];
+  for (auto D : sortedDistances) {
+    SpecifierInfoList &SpecList = DistanceMap[D];
     Specifiers.append(SpecList.begin(), SpecList.end());
   }
 
@@ -4302,10 +4285,8 @@ TypoCorrection Sema::CorrectTypo(const D
     // For unqualified lookup, look through all of the names that we have
     // seen in this translation unit.
     // FIXME: Re-add the ability to skip very unlikely potential corrections.
-    for (IdentifierTable::iterator I = Context.Idents.begin(),
-                                IEnd = Context.Idents.end();
-         I != IEnd; ++I)
-      Consumer.FoundName(I->getKey());
+    for (const auto &I : Context.Idents)
+      Consumer.FoundName(I.getKey());
 
     // Walk through identifiers in external identifier sources.
     // FIXME: Re-add the ability to skip very unlikely potential corrections.
@@ -4344,8 +4325,8 @@ TypoCorrection Sema::CorrectTypo(const D
       SmallVector<NamespaceDecl *, 4> ExternalKnownNamespaces;
       LoadedExternalKnownNamespaces = true;
       ExternalSource->ReadKnownNamespaces(ExternalKnownNamespaces);
-      for (unsigned I = 0, N = ExternalKnownNamespaces.size(); I != N; ++I)
-        KnownNamespaces[ExternalKnownNamespaces[I]] = true;
+      for (auto *N : ExternalKnownNamespaces)
+        KnownNamespaces[N] = true;
     }
 
     Consumer.addNamespaces(KnownNamespaces);
@@ -4488,11 +4469,9 @@ bool FunctionCallFilterCCC::ValidateCand
   if (!candidate.getCorrectionDecl())
     return candidate.isKeyword();
 
-  for (TypoCorrection::const_decl_iterator DI = candidate.begin(),
-                                           DIEnd = candidate.end();
-       DI != DIEnd; ++DI) {
+  for (auto *C : candidate) {
     FunctionDecl *FD = nullptr;
-    NamedDecl *ND = (*DI)->getUnderlyingDecl();
+    NamedDecl *ND = C->getUnderlyingDecl();
     if (FunctionTemplateDecl *FTD = dyn_cast<FunctionTemplateDecl>(ND))
       FD = FTD->getTemplatedDecl();
     if (!HasExplicitTemplateArgs && !FD) {





More information about the cfe-commits mailing list