From 1391608234b607157da1d4f742a60ba94b9b8985 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Fri, 7 Mar 2014 18:11:58 +0000 Subject: [PATCH] [C++11] Replacing IndirectFieldDecl iterators chain_begin() and chain_end() with iterator_range chains(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203261 --- clang/include/clang/AST/Decl.h | 9 +++++++-- .../clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h | 6 ++---- clang/lib/AST/ASTImporter.cpp | 5 ++--- clang/lib/AST/ExprConstant.cpp | 11 ++++------- clang/lib/AST/RecordLayoutBuilder.cpp | 6 ++---- clang/lib/CodeGen/CGClass.cpp | 6 ++---- clang/lib/Sema/SemaDecl.cpp | 5 ++--- clang/lib/Sema/SemaDeclCXX.cpp | 12 ++++-------- clang/lib/Sema/SemaExpr.cpp | 8 +++----- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 6 ++---- clang/lib/Serialization/ASTWriterDecl.cpp | 6 ++---- 11 files changed, 32 insertions(+), 48 deletions(-) diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 580b1e63..3a6bc2b 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -2331,8 +2331,13 @@ public: static IndirectFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID); typedef NamedDecl * const *chain_iterator; - chain_iterator chain_begin() const { return Chaining; } - chain_iterator chain_end() const { return Chaining+ChainingSize; } + typedef llvm::iterator_range chain_range; + + chain_range chains() const { + return chain_range(Chaining, Chaining + ChainingSize); + } + chain_iterator chain_begin() const { return chains().begin(); } + chain_iterator chain_end() const { return chains().end(); } unsigned getChainingSize() const { return ChainingSize; } diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h index 03739ed..1cb0dec 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h @@ -676,10 +676,8 @@ inline SVal ProgramState::getLValue(const FieldDecl *D, SVal Base) const { inline SVal ProgramState::getLValue(const IndirectFieldDecl *D, SVal Base) const { StoreManager &SM = *getStateManager().StoreMgr; - for (IndirectFieldDecl::chain_iterator I = D->chain_begin(), - E = D->chain_end(); - I != E; ++I) { - Base = SM.getLValueField(cast(*I), Base); + for (const auto *I : D->chains()) { + Base = SM.getLValueField(cast(I), Base); } return Base; diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index 676228b..51fcca8 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -2967,9 +2967,8 @@ Decl *ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { new (Importer.getToContext())NamedDecl*[D->getChainingSize()]; unsigned i = 0; - for (IndirectFieldDecl::chain_iterator PI = D->chain_begin(), - PE = D->chain_end(); PI != PE; ++PI) { - Decl* D = Importer.Import(*PI); + for (auto *PI : D->chains()) { + Decl *D = Importer.Import(PI); if (!D) return 0; NamedChain[i++] = cast(D); diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 92eef5e..a2b5867 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -1832,9 +1832,8 @@ static bool HandleLValueMember(EvalInfo &Info, const Expr *E, LValue &LVal, static bool HandleLValueIndirectMember(EvalInfo &Info, const Expr *E, LValue &LVal, const IndirectFieldDecl *IFD) { - for (IndirectFieldDecl::chain_iterator C = IFD->chain_begin(), - CE = IFD->chain_end(); C != CE; ++C) - if (!HandleLValueMember(Info, E, LVal, cast(*C))) + for (const auto *C : IFD->chains()) + if (!HandleLValueMember(Info, E, LVal, cast(C))) return false; return true; } @@ -3721,10 +3720,8 @@ static bool HandleConstructorCall(SourceLocation CallLoc, const LValue &This, } else if (IndirectFieldDecl *IFD = (*I)->getIndirectMember()) { // Walk the indirect field decl's chain to find the object to initialize, // and make sure we've initialized every step along it. - for (IndirectFieldDecl::chain_iterator C = IFD->chain_begin(), - CE = IFD->chain_end(); - C != CE; ++C) { - FD = cast(*C); + for (auto *C : IFD->chains()) { + FD = cast(C); CXXRecordDecl *CD = cast(FD->getParent()); // Switch the union field if it differs. This happens if we had // preceding zero-initialization, and we're now initializing a union diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp index bd58d32..a44a1a4 100644 --- a/clang/lib/AST/RecordLayoutBuilder.cpp +++ b/clang/lib/AST/RecordLayoutBuilder.cpp @@ -3002,10 +3002,8 @@ uint64_t ASTContext::getFieldOffset(const ValueDecl *VD) const { const IndirectFieldDecl *IFD = cast(VD); OffsetInBits = 0; - for (IndirectFieldDecl::chain_iterator CI = IFD->chain_begin(), - CE = IFD->chain_end(); - CI != CE; ++CI) - OffsetInBits += ::getFieldOffset(*this, cast(*CI)); + for (const auto *CI : IFD->chains()) + OffsetInBits += ::getFieldOffset(*this, cast(CI)); } return OffsetInBits; diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp index 4cab371..83c1ece 100644 --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -549,10 +549,8 @@ static void EmitMemberInitializer(CodeGenFunction &CGF, // If we are initializing an anonymous union field, drill down to // the field. IndirectFieldDecl *IndirectField = MemberInit->getIndirectMember(); - IndirectFieldDecl::chain_iterator I = IndirectField->chain_begin(), - IEnd = IndirectField->chain_end(); - for ( ; I != IEnd; ++I) - LHS = CGF.EmitLValueForFieldInitialization(LHS, cast(*I)); + for (const auto *I : IndirectField->chains()) + LHS = CGF.EmitLValueForFieldInitialization(LHS, cast(I)); FieldType = MemberInit->getIndirectMember()->getAnonField()->getType(); } else { LHS = CGF.EmitLValueForFieldInitialization(LHS, Field); diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 925515a..f57c7fc 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3487,9 +3487,8 @@ static bool InjectAnonymousStructOrUnionMembers(Sema &SemaRef, Scope *S, // anonymous union is declared. unsigned OldChainingSize = Chaining.size(); if (IndirectFieldDecl *IF = dyn_cast(VD)) - for (IndirectFieldDecl::chain_iterator PI = IF->chain_begin(), - PE = IF->chain_end(); PI != PE; ++PI) - Chaining.push_back(*PI); + for (auto *PI : IF->chains()) + Chaining.push_back(PI); else Chaining.push_back(VD); diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 4257b52..ccf2e57 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -3413,10 +3413,8 @@ struct BaseAndFieldInfo { if (!Indirect) return isInactiveUnionMember(Field); - for (IndirectFieldDecl::chain_iterator C = Indirect->chain_begin(), - CEnd = Indirect->chain_end(); - C != CEnd; ++C) { - FieldDecl *Field = dyn_cast(*C); + for (auto *C : Indirect->chains()) { + FieldDecl *Field = dyn_cast(C); if (Field && isInactiveUnionMember(Field)) return true; } @@ -3564,10 +3562,8 @@ bool Sema::SetCtorInitializers(CXXConstructorDecl *Constructor, bool AnyErrors, Info.AllBaseFields[Member->getAnyMember()] = Member; if (IndirectFieldDecl *F = Member->getIndirectMember()) { - for (IndirectFieldDecl::chain_iterator C = F->chain_begin(), - CEnd = F->chain_end(); - C != CEnd; ++C) { - FieldDecl *FD = dyn_cast(*C); + for (auto *C : F->chains()) { + FieldDecl *FD = dyn_cast(C); if (FD && FD->getParent()->isUnion()) Info.ActiveUnionMember.insert(std::make_pair( FD->getParent()->getCanonicalDecl(), FD->getCanonicalDecl())); diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index caca6d1..cb8a1b6 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -10229,12 +10229,10 @@ ExprResult Sema::BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, } if (IndirectMemberDecl) { - for (IndirectFieldDecl::chain_iterator FI = - IndirectMemberDecl->chain_begin(), - FEnd = IndirectMemberDecl->chain_end(); FI != FEnd; FI++) { - assert(isa(*FI)); + for (auto *FI : IndirectMemberDecl->chains()) { + assert(isa(FI)); Comps.push_back(OffsetOfNode(OC.LocStart, - cast(*FI), OC.LocEnd)); + cast(FI), OC.LocEnd)); } } else Comps.push_back(OffsetOfNode(OC.LocStart, MemberDecl, OC.LocEnd)); diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 5ce43da..b96aed9 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -562,10 +562,8 @@ Decl *TemplateDeclInstantiator::VisitIndirectFieldDecl(IndirectFieldDecl *D) { new (SemaRef.Context)NamedDecl*[D->getChainingSize()]; int i = 0; - for (IndirectFieldDecl::chain_iterator PI = - D->chain_begin(), PE = D->chain_end(); - PI != PE; ++PI) { - NamedDecl *Next = SemaRef.FindInstantiatedDecl(D->getLocation(), *PI, + for (auto *PI : D->chains()) { + NamedDecl *Next = SemaRef.FindInstantiatedDecl(D->getLocation(), PI, TemplateArgs); if (!Next) return 0; diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp index 5609b01..f4fabc1 100644 --- a/clang/lib/Serialization/ASTWriterDecl.cpp +++ b/clang/lib/Serialization/ASTWriterDecl.cpp @@ -686,10 +686,8 @@ void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { VisitValueDecl(D); Record.push_back(D->getChainingSize()); - for (IndirectFieldDecl::chain_iterator - P = D->chain_begin(), - PEnd = D->chain_end(); P != PEnd; ++P) - Writer.AddDeclRef(*P, Record); + for (const auto *P : D->chains()) + Writer.AddDeclRef(P, Record); Code = serialization::DECL_INDIRECTFIELD; } -- 2.7.4