From 35c5495bbbc5863cf8e6ec5e37432405af558a8f 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. llvm-svn: 204052 --- clang/include/clang/Sema/Scope.h | 9 +++++---- clang/lib/Sema/SemaCodeComplete.cpp | 5 ++--- clang/lib/Sema/SemaDecl.cpp | 4 +--- clang/lib/Sema/SemaLookup.cpp | 5 ++--- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/Sema/Scope.h b/clang/include/clang/Sema/Scope.h index 21e5cde3f7af..ccc7973c777c 100644 --- a/clang/include/clang/Sema/Scope.h +++ b/clang/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/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index fe32382226ac..d44c04b48094 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/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/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 58fe7227d207..2e8392fb8582 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/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/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 6e8de5875a20..3adea40387dd 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/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);