9 #ifndef LLVM_ADT_FALLIBLE_ITERATOR_H 10 #define LLVM_ADT_FALLIBLE_ITERATOR_H 16 #include <type_traits> 71 using enable_if_struct_deref_supported = std::enable_if<
72 !std::is_void<decltype(std::declval<T>().operator->())>::value,
73 decltype(std::declval<T>().operator->())>;
99 auto operator*() -> decltype(*std::declval<Underlying>()) {
return *I; }
108 template <
typename T = Underlying>
109 typename enable_if_struct_deref_supported<T>::type
operator->() {
110 return I.operator->();
115 template <
typename T = Underlying>
116 typename enable_if_struct_deref_supported<const T>::type
operator->()
const {
117 return I.operator->();
128 assert(getErrPtr() &&
"Cannot increment end iterator");
129 if (
auto Err = I.inc())
130 handleError(std::move(Err));
144 assert(getErrPtr() &&
"Cannot decrement end iterator");
145 if (
auto Err = I.dec())
146 handleError(std::move(Err));
168 if (LHS.isEnd() && RHS.isEnd())
171 assert(LHS.isValid() && RHS.isValid() &&
172 "Invalid iterators can only be compared against end");
174 bool Equal = LHS.I == RHS.I;
180 (
void)!!*RHS.getErrPtr();
182 (
void)!!*LHS.getErrPtr();
193 return !(LHS == RHS);
198 : I(std::move(I)), ErrState(Err,
false) {}
200 Error *getErrPtr()
const {
return ErrState.getPointer(); }
202 bool isEnd()
const {
return getErrPtr() ==
nullptr; }
204 bool isValid()
const {
return !ErrState.getInt(); }
206 void handleError(
Error Err) {
207 *getErrPtr() = std::move(Err);
208 ErrState.setPointer(
nullptr);
209 ErrState.setInt(
true);
212 void resetCheckedFlag() {
222 template <
typename Underlying>
229 template <
typename Underlying>
234 template <
typename Underlying>
243 #endif // LLVM_ADT_FALLIBLE_ITERATOR_H
static fallible_iterator itr(Underlying I, Error &Err)
Construct a fallible iterator that cannot be used as an end-of-range value.
auto operator*() const -> decltype(*std::declval< const Underlying >())
Forward const dereference to the underlying iterator.
This class represents lattice values for constants.
fallible_iterator & operator++()
Increment the fallible iterator.
auto operator*() -> decltype(*std::declval< Underlying >())
Forward dereference to the underlying iterator.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
static fallible_iterator end(Underlying I)
Construct a fallible iteratro that can be used as an end-of-range value.
enable_if_struct_deref_supported< const T >::type operator->() const
Forward const structure dereference to the underlying iterator (if the underlying iterator supports i...
friend bool operator==(const fallible_iterator &LHS, const fallible_iterator &RHS)
Compare fallible iterators for equality.
fallible_iterator & operator--()
Decrement the fallible iterator.
friend bool operator!=(const fallible_iterator &LHS, const fallible_iterator &RHS)
Compare fallible iterators for inequality.
PointerIntPair - This class implements a pair of a pointer and small integer.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
A wrapper class for fallible iterators.
std::underlying_type< E >::type Underlying(E Val)
Check that Val is in range for E, and return Val cast to E's underlying type.
iterator_range< fallible_iterator< Underlying > > make_fallible_range(Underlying I, Underlying E, Error &Err)
fallible_iterator< Underlying > make_fallible_end(Underlying E)
Convenience wrapper to make a fallible_iterator end value from an instance of an underlying iterator...
fallible_iterator< Underlying > make_fallible_itr(Underlying I, Error &Err)
Convenience wrapper to make a fallible_iterator value from an instance of an underlying iterator and ...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
static ErrorSuccess success()
Create a success value.
A range adaptor for a pair of iterators.
enable_if_struct_deref_supported< T >::type operator->()
Forward structure dereference to the underlying iterator (if the underlying iterator supports it)...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.