From ae20647f175485633a39daf900a8967a66d34e67 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Mon, 17 Mar 2014 16:55:25 +0000 Subject: [PATCH] [C++11] Replacing Scope iterators decl_begin() and decl_end() with iterator_range decls(). Updating all of the usages of the iterators with range-based for loops, and removing the no-longer-needed iterator versions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204052 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/Scope.h | 9 +++++---- lib/Sema/SemaCodeComplete.cpp | 5 ++--- lib/Sema/SemaDecl.cpp | 4 +--- lib/Sema/SemaLookup.cpp | 5 ++--- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/include/clang/Sema/Scope.h b/include/clang/Sema/Scope.h index 21e5cde3f7..ccc7973c77 100644 --- a/include/clang/Sema/Scope.h +++ b/include/clang/Sema/Scope.h @@ -235,10 +235,11 @@ public: return PrototypeIndex++; } - typedef DeclSetTy::iterator decl_iterator; - decl_iterator decl_begin() const { return DeclsInScope.begin(); } - decl_iterator decl_end() const { return DeclsInScope.end(); } - bool decl_empty() const { return DeclsInScope.empty(); } + typedef llvm::iterator_range decl_range; + decl_range decls() const { + return decl_range(DeclsInScope.begin(), DeclsInScope.end()); + } + bool decl_empty() const { return DeclsInScope.empty(); } void AddDecl(Decl *D) { DeclsInScope.insert(D); diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index fe32382226..d44c04b480 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -4335,9 +4335,8 @@ void Sema::CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, // Look for other capturable variables. for (; S && !isNamespaceScope(S); S = S->getParent()) { - for (Scope::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); - D != DEnd; ++D) { - VarDecl *Var = dyn_cast(*D); + for (const auto *D : S->decls()) { + const auto *Var = dyn_cast(D); if (!Var || !Var->hasLocalStorage() || Var->hasAttr()) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 58fe7227d2..2e8392fb85 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1375,9 +1375,7 @@ void Sema::ActOnPopScope(SourceLocation Loc, Scope *S) { assert((S->getFlags() & (Scope::DeclScope | Scope::TemplateParamScope)) && "Scope shouldn't contain decls!"); - for (Scope::decl_iterator I = S->decl_begin(), E = S->decl_end(); - I != E; ++I) { - Decl *TmpD = (*I); + for (auto *TmpD : S->decls()) { assert(TmpD && "This decl didn't get pushed??"); assert(isa(TmpD) && "Decl isn't NamedDecl?"); diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 6e8de5875a..3adea40387 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -3190,9 +3190,8 @@ static void LookupVisibleDecls(Scope *S, LookupResult &Result, (S->getEntity())->isFunctionOrMethod()) { FindLocalExternScope FindLocals(Result); // Walk through the declarations in this Scope. - for (Scope::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); - D != DEnd; ++D) { - if (NamedDecl *ND = dyn_cast(*D)) + for (auto *D : S->decls()) { + if (NamedDecl *ND = dyn_cast(D)) if ((ND = Result.getAcceptableDecl(ND))) { Consumer.FoundDecl(ND, Visited.checkHidden(ND), 0, false); Visited.add(ND); -- 2.40.0