[llvm] r212163 - Add range for-loop iterator adapter for cases in SwitchInst.

David Blaikie dblaikie at gmail.com
Wed Jul 2 08:35:08 PDT 2014


On Tue, Jul 1, 2014 at 10:32 PM, Owen Anderson <resistor at mac.com> wrote:
> Author: resistor
> Date: Wed Jul  2 00:32:13 2014
> New Revision: 212163
>
> URL: http://llvm.org/viewvc/llvm-project?rev=212163&view=rev
> Log:
> Add range for-loop iterator adapter for cases in SwitchInst.
>
> Patch by Marcello Maggioni, reviewed by Reid Kleckner.
>
> Modified:
>     llvm/trunk/include/llvm/IR/Instructions.h
>
> Modified: llvm/trunk/include/llvm/IR/Instructions.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Instructions.h?rev=212163&r1=212162&r2=212163&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/IR/Instructions.h (original)
> +++ llvm/trunk/include/llvm/IR/Instructions.h Wed Jul  2 00:32:13 2014
> @@ -2661,6 +2661,9 @@ public:
>        assert(RHS.SI == SI && "Incompatible operators.");
>        return RHS.Index != Index;
>      }
> +    Self &operator*() {
> +      return *this;
> +    }
>    };
>
>    typedef CaseIteratorT<const SwitchInst, const ConstantInt, const BasicBlock>
> @@ -2741,6 +2744,17 @@ public:
>    ConstCaseIt case_end() const {
>      return ConstCaseIt(this, getNumCases());
>    }
> +
> +  /// cases - iteration adapter for range-for loops.
> +  iterator_range<CaseIt> cases() {
> +    return iterator_range<CaseIt>(case_begin(), case_end());

FWIW I think there's "make_iterator_range" that means you don't have
to name the iterator type again in the return expression, if you want
to use that (now or in the future).

Several of our range accessors didn't use this because we didn't
bother to write it until Jim needed some one-off uses here & there
that were annoying to write out fully.

& hey, one day in the glorious C++14 future, we can just write these as:

auto foos() {
  return make_iterator_range(foos_begin(), foos_end());
}

> +  }
> +
> +  /// cases - iteration adapter for range-for loops.
> +  iterator_range<ConstCaseIt> cases() const {
> +    return iterator_range<ConstCaseIt>(case_begin(), case_end());
> +  }
> +
>    /// Returns an iterator that points to the default case.
>    /// Note: this iterator allows to resolve successor only. Attempt
>    /// to resolve case value causes an assertion.
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list