r203261 - [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.

Sean Silva silvas at purdue.edu
Sat Mar 8 10:09:25 PST 2014


On Fri, Mar 7, 2014 at 1:31 PM, Richard Smith <richard at metafoo.co.uk> wrote:

>
> On 7 Mar 2014 10:21, "Aaron Ballman" <aaron at aaronballman.com> wrote:
> >
> > Author: aaronballman
> > Date: Fri Mar  7 12:11:58 2014
> > New Revision: 203261
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=203261&view=rev
> > Log:
> > [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.
>
> This one should be "chain", not "chains".
>

What is the official convention here? There was a recent thread about this
but I didn't see any conclusion. Are you going for foo_begin/foo_end/foo? I
actually like that better than my foo_range suggestion.

-- Sean Silva

> > Modified:
> >     cfe/trunk/include/clang/AST/Decl.h
> >
> cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
> >     cfe/trunk/lib/AST/ASTImporter.cpp
> >     cfe/trunk/lib/AST/ExprConstant.cpp
> >     cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
> >     cfe/trunk/lib/CodeGen/CGClass.cpp
> >     cfe/trunk/lib/Sema/SemaDecl.cpp
> >     cfe/trunk/lib/Sema/SemaDeclCXX.cpp
> >     cfe/trunk/lib/Sema/SemaExpr.cpp
> >     cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
> >     cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
> >
> > Modified: cfe/trunk/include/clang/AST/Decl.h
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=203261&r1=203260&r2=203261&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/include/clang/AST/Decl.h (original)
> > +++ cfe/trunk/include/clang/AST/Decl.h Fri Mar  7 12:11:58 2014
> > @@ -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_iterator> 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; }
> >
> >
> > Modified:
> cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h?rev=203261&r1=203260&r2=203261&view=diff
> >
> ==============================================================================
> > ---
> cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
> (original)
> > +++
> cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
> Fri Mar  7 12:11:58 2014
> > @@ -676,10 +676,8 @@ inline SVal ProgramState::getLValue(cons
> >  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<FieldDecl>(*I), Base);
> > +  for (const auto *I : D->chains()) {
> > +    Base = SM.getLValueField(cast<FieldDecl>(I), Base);
> >    }
> >
> >    return Base;
> >
> > Modified: cfe/trunk/lib/AST/ASTImporter.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=203261&r1=203260&r2=203261&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/AST/ASTImporter.cpp (original)
> > +++ cfe/trunk/lib/AST/ASTImporter.cpp Fri Mar  7 12:11:58 2014
> > @@ -2967,9 +2967,8 @@ Decl *ASTNodeImporter::VisitIndirectFiel
> >      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<NamedDecl>(D);
> >
> > Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=203261&r1=203260&r2=203261&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> > +++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Mar  7 12:11:58 2014
> > @@ -1832,9 +1832,8 @@ static bool HandleLValueMember(EvalInfo
> >  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<FieldDecl>(*C)))
> > +  for (const auto *C : IFD->chains())
> > +    if (!HandleLValueMember(Info, E, LVal, cast<FieldDecl>(C)))
> >        return false;
> >    return true;
> >  }
> > @@ -3721,10 +3720,8 @@ static bool HandleConstructorCall(Source
> >      } 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<FieldDecl>(*C);
> > +      for (auto *C : IFD->chains()) {
> > +        FD = cast<FieldDecl>(C);
> >          CXXRecordDecl *CD = cast<CXXRecordDecl>(FD->getParent());
> >          // Switch the union field if it differs. This happens if we had
> >          // preceding zero-initialization, and we're now initializing a
> union
> >
> > Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=203261&r1=203260&r2=203261&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
> > +++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Fri Mar  7 12:11:58 2014
> > @@ -3002,10 +3002,8 @@ uint64_t ASTContext::getFieldOffset(cons
> >      const IndirectFieldDecl *IFD = cast<IndirectFieldDecl>(VD);
> >
> >      OffsetInBits = 0;
> > -    for (IndirectFieldDecl::chain_iterator CI = IFD->chain_begin(),
> > -                                           CE = IFD->chain_end();
> > -         CI != CE; ++CI)
> > -      OffsetInBits += ::getFieldOffset(*this, cast<FieldDecl>(*CI));
> > +    for (const auto *CI : IFD->chains())
> > +      OffsetInBits += ::getFieldOffset(*this, cast<FieldDecl>(CI));
> >    }
> >
> >    return OffsetInBits;
> >
> > Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=203261&r1=203260&r2=203261&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
> > +++ cfe/trunk/lib/CodeGen/CGClass.cpp Fri Mar  7 12:11:58 2014
> > @@ -549,10 +549,8 @@ static void EmitMemberInitializer(CodeGe
> >      // 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<FieldDecl>(*I));
> > +    for (const auto *I : IndirectField->chains())
> > +      LHS = CGF.EmitLValueForFieldInitialization(LHS,
> cast<FieldDecl>(I));
> >      FieldType =
> MemberInit->getIndirectMember()->getAnonField()->getType();
> >    } else {
> >      LHS = CGF.EmitLValueForFieldInitialization(LHS, Field);
> >
> > Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=203261&r1=203260&r2=203261&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> > +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Mar  7 12:11:58 2014
> > @@ -3487,9 +3487,8 @@ static bool InjectAnonymousStructOrUnion
> >          //   anonymous union is declared.
> >          unsigned OldChainingSize = Chaining.size();
> >          if (IndirectFieldDecl *IF = dyn_cast<IndirectFieldDecl>(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);
> >
> >
> > Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=203261&r1=203260&r2=203261&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
> > +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Mar  7 12:11:58 2014
> > @@ -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<FieldDecl>(*C);
> > +    for (auto *C : Indirect->chains()) {
> > +      FieldDecl *Field = dyn_cast<FieldDecl>(C);
> >        if (Field && isInactiveUnionMember(Field))
> >          return true;
> >      }
> > @@ -3564,10 +3562,8 @@ bool Sema::SetCtorInitializers(CXXConstr
> >        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<FieldDecl>(*C);
> > +        for (auto *C : F->chains()) {
> > +          FieldDecl *FD = dyn_cast<FieldDecl>(C);
> >            if (FD && FD->getParent()->isUnion())
> >              Info.ActiveUnionMember.insert(std::make_pair(
> >                  FD->getParent()->getCanonicalDecl(),
> FD->getCanonicalDecl()));
> >
> > Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=203261&r1=203260&r2=203261&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> > +++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Mar  7 12:11:58 2014
> > @@ -10229,12 +10229,10 @@ ExprResult Sema::BuildBuiltinOffsetOf(So
> >      }
> >
> >      if (IndirectMemberDecl) {
> > -      for (IndirectFieldDecl::chain_iterator FI =
> > -           IndirectMemberDecl->chain_begin(),
> > -           FEnd = IndirectMemberDecl->chain_end(); FI != FEnd; FI++) {
> > -        assert(isa<FieldDecl>(*FI));
> > +      for (auto *FI : IndirectMemberDecl->chains()) {
> > +        assert(isa<FieldDecl>(FI));
> >          Comps.push_back(OffsetOfNode(OC.LocStart,
> > -                                     cast<FieldDecl>(*FI), OC.LocEnd));
> > +                                     cast<FieldDecl>(FI), OC.LocEnd));
> >        }
> >      } else
> >        Comps.push_back(OffsetOfNode(OC.LocStart, MemberDecl, OC.LocEnd));
> >
> > Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=203261&r1=203260&r2=203261&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
> > +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri Mar  7
> 12:11:58 2014
> > @@ -562,10 +562,8 @@ Decl *TemplateDeclInstantiator::VisitInd
> >      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;
> >
> > Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=203261&r1=203260&r2=203261&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
> > +++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Fri Mar  7 12:11:58
> 2014
> > @@ -686,10 +686,8 @@ void ASTDeclWriter::VisitIndirectFieldDe
> >    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;
> >  }
> >
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140308/2fdd37f9/attachment.html>


More information about the cfe-commits mailing list