From: Aaron Ballman Date: Mon, 17 Mar 2014 17:14:12 +0000 (+0000) Subject: [C++11] Replacing DeclContext iterators using_directives_begin() and using_directives... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=930c249394a5deeb6ccd389cd84f3c51ffa21d61;p=clang [C++11] Replacing DeclContext iterators using_directives_begin() and using_directives_end() with iterator_range using_directives(). Updating all of the usages of the iterators with range-based for loops, and removing the no-longer-needed iterator versions. Also used as an opportunity to normalize the name from getUsingDirectives() to using_directives(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204061 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index 6dc5598a85..a08f1c50a0 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -1592,21 +1592,9 @@ public: all_lookups_iterator noload_lookups_begin() const; all_lookups_iterator noload_lookups_end() const; - /// udir_iterator - Iterates through the using-directives stored - /// within this context. - typedef UsingDirectiveDecl * const * udir_iterator; - - typedef llvm::iterator_range udir_range; - - udir_range getUsingDirectives() const; + typedef llvm::iterator_range udir_range; - udir_iterator using_directives_begin() const { - return getUsingDirectives().begin(); - } - - udir_iterator using_directives_end() const { - return getUsingDirectives().end(); - } + udir_range using_directives() const; // These are all defined in DependentDiagnostic.h. class ddiag_iterator; diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index c95a64aa2e..d4c8235f8a 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -1523,13 +1523,13 @@ void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D, bool Internal) { /// Returns iterator range [First, Last) of UsingDirectiveDecls stored within /// this context. -DeclContext::udir_range -DeclContext::getUsingDirectives() const { +DeclContext::udir_range DeclContext::using_directives() const { // FIXME: Use something more efficient than normal lookup for using // directives. In C++, using directives are looked up more than anything else. lookup_const_result Result = lookup(UsingDirectiveDecl::getName()); - return udir_range(reinterpret_cast(Result.begin()), - reinterpret_cast(Result.end())); + return udir_range( + reinterpret_cast(Result.begin()), + reinterpret_cast(Result.end())); } //===----------------------------------------------------------------------===// diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 29671aa65d..42c9acbdd8 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -151,7 +151,7 @@ namespace { void addUsingDirectives(DeclContext *DC, DeclContext *EffectiveDC) { SmallVector queue; while (true) { - for (auto UD : DC->getUsingDirectives()) { + for (auto UD : DC->using_directives()) { DeclContext *NS = UD->getNominatedNamespace(); if (visited.insert(NS)) { addUsingDirective(UD, EffectiveDC); @@ -1448,10 +1448,8 @@ static bool LookupQualifiedNameInUsingDirectives(Sema &S, LookupResult &R, DeclContext *StartDC) { assert(StartDC->isFileContext() && "start context is not a file context"); - DeclContext::udir_iterator I = StartDC->using_directives_begin(); - DeclContext::udir_iterator E = StartDC->using_directives_end(); - - if (I == E) return false; + DeclContext::udir_range UsingDirectives = StartDC->using_directives(); + if (UsingDirectives.begin() == UsingDirectives.end()) return false; // We have at least added all these contexts to the queue. llvm::SmallPtrSet Visited; @@ -1463,8 +1461,8 @@ static bool LookupQualifiedNameInUsingDirectives(Sema &S, LookupResult &R, // We have already looked into the initial namespace; seed the queue // with its using-children. - for (; I != E; ++I) { - NamespaceDecl *ND = (*I)->getNominatedNamespace()->getOriginalNamespace(); + for (auto *I : UsingDirectives) { + NamespaceDecl *ND = I->getNominatedNamespace()->getOriginalNamespace(); if (Visited.insert(ND)) Queue.push_back(ND); } @@ -1511,7 +1509,7 @@ static bool LookupQualifiedNameInUsingDirectives(Sema &S, LookupResult &R, continue; } - for (auto I : ND->getUsingDirectives()) { + for (auto I : ND->using_directives()) { NamespaceDecl *Nom = I->getNominatedNamespace(); if (Visited.insert(Nom)) Queue.push_back(Nom); @@ -3074,7 +3072,7 @@ static void LookupVisibleDecls(DeclContext *Ctx, LookupResult &Result, // Traverse using directives for qualified name lookup. if (QualifiedNameLookup) { ShadowContextRAII Shadow(Visited); - for (auto I : Ctx->getUsingDirectives()) { + for (auto I : Ctx->using_directives()) { LookupVisibleDecls(I->getNominatedNamespace(), Result, QualifiedNameLookup, InBaseClass, Consumer, Visited); }