Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/EnumeratedRange.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
/* Iterator over contiguous enum values */
8
9
/*
10
 * Implements generator functions that create a range to iterate over the values
11
 * of a scoped or unscoped enum. Unlike IntegerRange, which can only function on
12
 * the underlying integral type, the elements of the generated sequence will
13
 * have the type of the enum in question.
14
 *
15
 * Note that the enum values should be contiguous in the iterated range;
16
 * unfortunately there exists no way for EnumeratedRange to enforce this
17
 * either dynamically or at compile time.
18
 */
19
20
#ifndef mozilla_EnumeratedRange_h
21
#define mozilla_EnumeratedRange_h
22
23
#include <type_traits>
24
25
#include "mozilla/ReverseIterator.h"
26
27
namespace mozilla {
28
29
namespace detail {
30
31
template<typename EnumTypeT>
32
class EnumeratedIterator
33
{
34
public:
35
  typedef typename std::underlying_type<EnumTypeT>::type IntTypeT;
36
37
  template<typename EnumType>
38
  explicit EnumeratedIterator(EnumType aCurrent)
39
1.02k
    : mCurrent(aCurrent) { }
Unexecuted instantiation: mozilla::detail::EnumeratedIterator<CrashReporter::Annotation>::EnumeratedIterator<CrashReporter::Annotation>(CrashReporter::Annotation)
Unexecuted instantiation: mozilla::detail::EnumeratedIterator<mozilla::hal::SensorType>::EnumeratedIterator<mozilla::hal::SensorType>(mozilla::hal::SensorType)
Unexecuted instantiation: mozilla::detail::EnumeratedIterator<txEXSLTType>::EnumeratedIterator<txEXSLTType>(txEXSLTType)
mozilla::detail::EnumeratedIterator<js::gcstats::PhaseKind>::EnumeratedIterator<js::gcstats::PhaseKind>(js::gcstats::PhaseKind)
Line
Count
Source
39
300
    : mCurrent(aCurrent) { }
mozilla::detail::EnumeratedIterator<js::gcstats::Phase>::EnumeratedIterator<js::gcstats::Phase>(js::gcstats::Phase)
Line
Count
Source
39
386
    : mCurrent(aCurrent) { }
Unexecuted instantiation: mozilla::detail::EnumeratedIterator<js::jit::CreateDependentString::FallbackKind>::EnumeratedIterator<js::jit::CreateDependentString::FallbackKind>(js::jit::CreateDependentString::FallbackKind)
mozilla::detail::EnumeratedIterator<js::gc::AllocKind>::EnumeratedIterator<js::gc::AllocKind>(js::gc::AllocKind)
Line
Count
Source
39
336
    : mCurrent(aCurrent) { }
Unexecuted instantiation: mozilla::detail::EnumeratedIterator<js::wasm::SymbolicAddress>::EnumeratedIterator<js::wasm::SymbolicAddress>(js::wasm::SymbolicAddress)
Unexecuted instantiation: mozilla::detail::EnumeratedIterator<js::wasm::Trap>::EnumeratedIterator<js::wasm::Trap>(js::wasm::Trap)
40
41
  template<typename EnumType>
42
  explicit EnumeratedIterator(const EnumeratedIterator<EnumType>& aOther)
43
    : mCurrent(aOther.mCurrent) { }
44
45
34.1k
  EnumTypeT operator*() const { return mCurrent; }
Unexecuted instantiation: mozilla::detail::EnumeratedIterator<CrashReporter::Annotation>::operator*() const
Unexecuted instantiation: mozilla::detail::EnumeratedIterator<mozilla::hal::SensorType>::operator*() const
Unexecuted instantiation: mozilla::detail::EnumeratedIterator<txEXSLTType>::operator*() const
mozilla::detail::EnumeratedIterator<js::gc::AllocKind>::operator*() const
Line
Count
Source
45
3.86k
  EnumTypeT operator*() const { return mCurrent; }
mozilla::detail::EnumeratedIterator<js::gcstats::PhaseKind>::operator*() const
Line
Count
Source
45
9.82k
  EnumTypeT operator*() const { return mCurrent; }
mozilla::detail::EnumeratedIterator<js::gcstats::Phase>::operator*() const
Line
Count
Source
45
20.4k
  EnumTypeT operator*() const { return mCurrent; }
Unexecuted instantiation: mozilla::detail::EnumeratedIterator<js::jit::CreateDependentString::FallbackKind>::operator*() const
Unexecuted instantiation: mozilla::detail::EnumeratedIterator<js::wasm::SymbolicAddress>::operator*() const
Unexecuted instantiation: mozilla::detail::EnumeratedIterator<js::wasm::Trap>::operator*() const
46
47
  /* Increment and decrement operators */
48
49
  EnumeratedIterator& operator++()
50
34.1k
  {
51
34.1k
    mCurrent = EnumTypeT(IntTypeT(mCurrent) + IntTypeT(1));
52
34.1k
    return *this;
53
34.1k
  }
Unexecuted instantiation: mozilla::detail::EnumeratedIterator<CrashReporter::Annotation>::operator++()
Unexecuted instantiation: mozilla::detail::EnumeratedIterator<mozilla::hal::SensorType>::operator++()
Unexecuted instantiation: mozilla::detail::EnumeratedIterator<txEXSLTType>::operator++()
mozilla::detail::EnumeratedIterator<js::gc::AllocKind>::operator++()
Line
Count
Source
50
3.82k
  {
51
3.82k
    mCurrent = EnumTypeT(IntTypeT(mCurrent) + IntTypeT(1));
52
3.82k
    return *this;
53
3.82k
  }
mozilla::detail::EnumeratedIterator<js::gcstats::PhaseKind>::operator++()
Line
Count
Source
50
9.82k
  {
51
9.82k
    mCurrent = EnumTypeT(IntTypeT(mCurrent) + IntTypeT(1));
52
9.82k
    return *this;
53
9.82k
  }
mozilla::detail::EnumeratedIterator<js::gcstats::Phase>::operator++()
Line
Count
Source
50
20.4k
  {
51
20.4k
    mCurrent = EnumTypeT(IntTypeT(mCurrent) + IntTypeT(1));
52
20.4k
    return *this;
53
20.4k
  }
Unexecuted instantiation: mozilla::detail::EnumeratedIterator<js::jit::CreateDependentString::FallbackKind>::operator++()
Unexecuted instantiation: mozilla::detail::EnumeratedIterator<js::wasm::SymbolicAddress>::operator++()
Unexecuted instantiation: mozilla::detail::EnumeratedIterator<js::wasm::Trap>::operator++()
54
  EnumeratedIterator& operator--()
55
  {
56
    mCurrent = EnumTypeT(IntTypeT(mCurrent) - IntTypeT(1));
57
    return *this;
58
  }
59
  EnumeratedIterator operator++(int)
60
  {
61
    auto ret = *this;
62
    mCurrent = EnumTypeT(IntTypeT(mCurrent) + IntTypeT(1));
63
    return ret;
64
  }
65
  EnumeratedIterator operator--(int)
66
  {
67
    auto ret = *this;
68
    mCurrent = EnumTypeT(IntTypeT(mCurrent) - IntTypeT(1));
69
    return ret;
70
  }
71
72
  /* Comparison operators */
73
74
  template<typename EnumType>
75
  friend bool operator==(const EnumeratedIterator<EnumType>& aIter1,
76
                         const EnumeratedIterator<EnumType>& aIter2);
77
  template<typename EnumType>
78
  friend bool operator!=(const EnumeratedIterator<EnumType>& aIter1,
79
                         const EnumeratedIterator<EnumType>& aIter2);
80
  template<typename EnumType>
81
  friend bool operator<(const EnumeratedIterator<EnumType>& aIter1,
82
                        const EnumeratedIterator<EnumType>& aIter2);
83
  template<typename EnumType>
84
  friend bool operator<=(const EnumeratedIterator<EnumType>& aIter1,
85
                         const EnumeratedIterator<EnumType>& aIter2);
86
  template<typename EnumType>
87
  friend bool operator>(const EnumeratedIterator<EnumType>& aIter1,
88
                        const EnumeratedIterator<EnumType>& aIter2);
89
  template<typename EnumType>
90
  friend bool operator>=(const EnumeratedIterator<EnumType>& aIter1,
91
                         const EnumeratedIterator<EnumType>& aIter2);
92
93
private:
94
  EnumTypeT mCurrent;
95
};
96
97
template<typename EnumType>
98
bool operator==(const EnumeratedIterator<EnumType>& aIter1,
99
                const EnumeratedIterator<EnumType>& aIter2)
100
{
101
  return aIter1.mCurrent == aIter2.mCurrent;
102
}
103
104
template<typename EnumType>
105
bool operator!=(const EnumeratedIterator<EnumType>& aIter1,
106
                const EnumeratedIterator<EnumType>& aIter2)
107
34.6k
{
108
34.6k
  return aIter1.mCurrent != aIter2.mCurrent;
109
34.6k
}
Unexecuted instantiation: bool mozilla::detail::operator!=<CrashReporter::Annotation>(mozilla::detail::EnumeratedIterator<CrashReporter::Annotation> const&, mozilla::detail::EnumeratedIterator<CrashReporter::Annotation> const&)
Unexecuted instantiation: bool mozilla::detail::operator!=<mozilla::hal::SensorType>(mozilla::detail::EnumeratedIterator<mozilla::hal::SensorType> const&, mozilla::detail::EnumeratedIterator<mozilla::hal::SensorType> const&)
Unexecuted instantiation: bool mozilla::detail::operator!=<txEXSLTType>(mozilla::detail::EnumeratedIterator<txEXSLTType> const&, mozilla::detail::EnumeratedIterator<txEXSLTType> const&)
bool mozilla::detail::operator!=<js::gc::AllocKind>(mozilla::detail::EnumeratedIterator<js::gc::AllocKind> const&, mozilla::detail::EnumeratedIterator<js::gc::AllocKind> const&)
Line
Count
Source
107
3.99k
{
108
3.99k
  return aIter1.mCurrent != aIter2.mCurrent;
109
3.99k
}
bool mozilla::detail::operator!=<js::gcstats::PhaseKind>(mozilla::detail::EnumeratedIterator<js::gcstats::PhaseKind> const&, mozilla::detail::EnumeratedIterator<js::gcstats::PhaseKind> const&)
Line
Count
Source
107
9.97k
{
108
9.97k
  return aIter1.mCurrent != aIter2.mCurrent;
109
9.97k
}
bool mozilla::detail::operator!=<js::gcstats::Phase>(mozilla::detail::EnumeratedIterator<js::gcstats::Phase> const&, mozilla::detail::EnumeratedIterator<js::gcstats::Phase> const&)
Line
Count
Source
107
20.6k
{
108
20.6k
  return aIter1.mCurrent != aIter2.mCurrent;
109
20.6k
}
Unexecuted instantiation: bool mozilla::detail::operator!=<js::jit::CreateDependentString::FallbackKind>(mozilla::detail::EnumeratedIterator<js::jit::CreateDependentString::FallbackKind> const&, mozilla::detail::EnumeratedIterator<js::jit::CreateDependentString::FallbackKind> const&)
Unexecuted instantiation: bool mozilla::detail::operator!=<js::wasm::SymbolicAddress>(mozilla::detail::EnumeratedIterator<js::wasm::SymbolicAddress> const&, mozilla::detail::EnumeratedIterator<js::wasm::SymbolicAddress> const&)
Unexecuted instantiation: bool mozilla::detail::operator!=<js::wasm::Trap>(mozilla::detail::EnumeratedIterator<js::wasm::Trap> const&, mozilla::detail::EnumeratedIterator<js::wasm::Trap> const&)
110
111
template<typename EnumType>
112
bool operator<(const EnumeratedIterator<EnumType>& aIter1,
113
               const EnumeratedIterator<EnumType>& aIter2)
114
{
115
  return aIter1.mCurrent < aIter2.mCurrent;
116
}
117
118
template<typename EnumType>
119
bool operator<=(const EnumeratedIterator<EnumType>& aIter1,
120
                const EnumeratedIterator<EnumType>& aIter2)
121
{
122
  return aIter1.mCurrent <= aIter2.mCurrent;
123
}
124
125
template<typename EnumType>
126
bool operator>(const EnumeratedIterator<EnumType>& aIter1,
127
               const EnumeratedIterator<EnumType>& aIter2)
128
{
129
  return aIter1.mCurrent > aIter2.mCurrent;
130
}
131
132
template<typename EnumType>
133
bool operator>=(const EnumeratedIterator<EnumType>& aIter1,
134
                const EnumeratedIterator<EnumType>& aIter2)
135
{
136
  return aIter1.mCurrent >= aIter2.mCurrent;
137
}
138
139
template<typename EnumTypeT>
140
class EnumeratedRange
141
{
142
public:
143
  typedef EnumeratedIterator<EnumTypeT> iterator;
144
  typedef EnumeratedIterator<EnumTypeT> const_iterator;
145
  typedef ReverseIterator<iterator> reverse_iterator;
146
  typedef ReverseIterator<const_iterator> const_reverse_iterator;
147
148
  template<typename EnumType>
149
  EnumeratedRange(EnumType aBegin, EnumType aEnd)
150
511
    : mBegin(aBegin), mEnd(aEnd) { }
Unexecuted instantiation: mozilla::detail::EnumeratedRange<CrashReporter::Annotation>::EnumeratedRange<CrashReporter::Annotation>(CrashReporter::Annotation, CrashReporter::Annotation)
Unexecuted instantiation: mozilla::detail::EnumeratedRange<mozilla::hal::SensorType>::EnumeratedRange<mozilla::hal::SensorType>(mozilla::hal::SensorType, mozilla::hal::SensorType)
Unexecuted instantiation: mozilla::detail::EnumeratedRange<txEXSLTType>::EnumeratedRange<txEXSLTType>(txEXSLTType, txEXSLTType)
mozilla::detail::EnumeratedRange<js::gcstats::Phase>::EnumeratedRange<js::gcstats::Phase>(js::gcstats::Phase, js::gcstats::Phase)
Line
Count
Source
150
193
    : mBegin(aBegin), mEnd(aEnd) { }
mozilla::detail::EnumeratedRange<js::gcstats::PhaseKind>::EnumeratedRange<js::gcstats::PhaseKind>(js::gcstats::PhaseKind, js::gcstats::PhaseKind)
Line
Count
Source
150
150
    : mBegin(aBegin), mEnd(aEnd) { }
Unexecuted instantiation: mozilla::detail::EnumeratedRange<js::jit::CreateDependentString::FallbackKind>::EnumeratedRange<js::jit::CreateDependentString::FallbackKind>(js::jit::CreateDependentString::FallbackKind, js::jit::CreateDependentString::FallbackKind)
mozilla::detail::EnumeratedRange<js::gc::AllocKind>::EnumeratedRange<js::gc::AllocKind>(js::gc::AllocKind, js::gc::AllocKind)
Line
Count
Source
150
168
    : mBegin(aBegin), mEnd(aEnd) { }
Unexecuted instantiation: mozilla::detail::EnumeratedRange<js::wasm::SymbolicAddress>::EnumeratedRange<js::wasm::SymbolicAddress>(js::wasm::SymbolicAddress, js::wasm::SymbolicAddress)
Unexecuted instantiation: mozilla::detail::EnumeratedRange<js::wasm::Trap>::EnumeratedRange<js::wasm::Trap>(js::wasm::Trap, js::wasm::Trap)
151
152
511
  iterator begin() const { return iterator(mBegin); }
Unexecuted instantiation: mozilla::detail::EnumeratedRange<CrashReporter::Annotation>::begin() const
Unexecuted instantiation: mozilla::detail::EnumeratedRange<mozilla::hal::SensorType>::begin() const
Unexecuted instantiation: mozilla::detail::EnumeratedRange<txEXSLTType>::begin() const
mozilla::detail::EnumeratedRange<js::gc::AllocKind>::begin() const
Line
Count
Source
152
168
  iterator begin() const { return iterator(mBegin); }
mozilla::detail::EnumeratedRange<js::gcstats::PhaseKind>::begin() const
Line
Count
Source
152
150
  iterator begin() const { return iterator(mBegin); }
mozilla::detail::EnumeratedRange<js::gcstats::Phase>::begin() const
Line
Count
Source
152
193
  iterator begin() const { return iterator(mBegin); }
Unexecuted instantiation: mozilla::detail::EnumeratedRange<js::jit::CreateDependentString::FallbackKind>::begin() const
Unexecuted instantiation: mozilla::detail::EnumeratedRange<js::wasm::SymbolicAddress>::begin() const
Unexecuted instantiation: mozilla::detail::EnumeratedRange<js::wasm::Trap>::begin() const
153
  const_iterator cbegin() const { return begin(); }
154
511
  iterator end() const { return iterator(mEnd); }
Unexecuted instantiation: mozilla::detail::EnumeratedRange<CrashReporter::Annotation>::end() const
Unexecuted instantiation: mozilla::detail::EnumeratedRange<mozilla::hal::SensorType>::end() const
Unexecuted instantiation: mozilla::detail::EnumeratedRange<txEXSLTType>::end() const
mozilla::detail::EnumeratedRange<js::gc::AllocKind>::end() const
Line
Count
Source
154
168
  iterator end() const { return iterator(mEnd); }
mozilla::detail::EnumeratedRange<js::gcstats::PhaseKind>::end() const
Line
Count
Source
154
150
  iterator end() const { return iterator(mEnd); }
mozilla::detail::EnumeratedRange<js::gcstats::Phase>::end() const
Line
Count
Source
154
193
  iterator end() const { return iterator(mEnd); }
Unexecuted instantiation: mozilla::detail::EnumeratedRange<js::jit::CreateDependentString::FallbackKind>::end() const
Unexecuted instantiation: mozilla::detail::EnumeratedRange<js::wasm::SymbolicAddress>::end() const
Unexecuted instantiation: mozilla::detail::EnumeratedRange<js::wasm::Trap>::end() const
155
  const_iterator cend() const { return end(); }
156
  reverse_iterator rbegin() const { return reverse_iterator(mEnd); }
157
  const_reverse_iterator crbegin() const { return rbegin(); }
158
  reverse_iterator rend() const { return reverse_iterator(mBegin); }
159
  const_reverse_iterator crend() const { return rend(); }
160
161
private:
162
  EnumTypeT mBegin;
163
  EnumTypeT mEnd;
164
};
165
166
} // namespace detail
167
168
#ifdef __GNUC__
169
// Enums can have an unsigned underlying type, which makes some of the
170
// comparisons below always true or always false. Temporarily disable
171
// -Wtype-limits to avoid breaking -Werror builds.
172
#  pragma GCC diagnostic push
173
#  pragma GCC diagnostic ignored "-Wtype-limits"
174
#endif
175
176
// Create a range to iterate from aBegin to aEnd, exclusive.
177
template<typename EnumType>
178
inline detail::EnumeratedRange<EnumType>
179
MakeEnumeratedRange(EnumType aBegin, EnumType aEnd)
180
511
{
181
511
  MOZ_ASSERT(aBegin <= aEnd, "Cannot generate invalid, unbounded range!");
182
511
  return detail::EnumeratedRange<EnumType>(aBegin, aEnd);
183
511
}
Unexecuted instantiation: mozilla::detail::EnumeratedRange<CrashReporter::Annotation> mozilla::MakeEnumeratedRange<CrashReporter::Annotation>(CrashReporter::Annotation, CrashReporter::Annotation)
Unexecuted instantiation: mozilla::detail::EnumeratedRange<mozilla::hal::SensorType> mozilla::MakeEnumeratedRange<mozilla::hal::SensorType>(mozilla::hal::SensorType, mozilla::hal::SensorType)
Unexecuted instantiation: mozilla::detail::EnumeratedRange<txEXSLTType> mozilla::MakeEnumeratedRange<txEXSLTType>(txEXSLTType, txEXSLTType)
mozilla::detail::EnumeratedRange<js::gc::AllocKind> mozilla::MakeEnumeratedRange<js::gc::AllocKind>(js::gc::AllocKind, js::gc::AllocKind)
Line
Count
Source
180
168
{
181
168
  MOZ_ASSERT(aBegin <= aEnd, "Cannot generate invalid, unbounded range!");
182
168
  return detail::EnumeratedRange<EnumType>(aBegin, aEnd);
183
168
}
mozilla::detail::EnumeratedRange<js::gcstats::Phase> mozilla::MakeEnumeratedRange<js::gcstats::Phase>(js::gcstats::Phase, js::gcstats::Phase)
Line
Count
Source
180
193
{
181
193
  MOZ_ASSERT(aBegin <= aEnd, "Cannot generate invalid, unbounded range!");
182
193
  return detail::EnumeratedRange<EnumType>(aBegin, aEnd);
183
193
}
mozilla::detail::EnumeratedRange<js::gcstats::PhaseKind> mozilla::MakeEnumeratedRange<js::gcstats::PhaseKind>(js::gcstats::PhaseKind, js::gcstats::PhaseKind)
Line
Count
Source
180
150
{
181
150
  MOZ_ASSERT(aBegin <= aEnd, "Cannot generate invalid, unbounded range!");
182
150
  return detail::EnumeratedRange<EnumType>(aBegin, aEnd);
183
150
}
Unexecuted instantiation: mozilla::detail::EnumeratedRange<js::jit::CreateDependentString::FallbackKind> mozilla::MakeEnumeratedRange<js::jit::CreateDependentString::FallbackKind>(js::jit::CreateDependentString::FallbackKind, js::jit::CreateDependentString::FallbackKind)
Unexecuted instantiation: mozilla::detail::EnumeratedRange<js::wasm::SymbolicAddress> mozilla::MakeEnumeratedRange<js::wasm::SymbolicAddress>(js::wasm::SymbolicAddress, js::wasm::SymbolicAddress)
Unexecuted instantiation: mozilla::detail::EnumeratedRange<js::wasm::Trap> mozilla::MakeEnumeratedRange<js::wasm::Trap>(js::wasm::Trap, js::wasm::Trap)
184
185
// Create a range to iterate from EnumType(0) to aEnd, exclusive. EnumType(0)
186
// should exist, but note that there is no way for us to ensure that it does!
187
template<typename EnumType>
188
inline detail::EnumeratedRange<EnumType>
189
MakeEnumeratedRange(EnumType aEnd)
190
0
{
191
0
  return MakeEnumeratedRange(EnumType(0), aEnd);
192
0
}
Unexecuted instantiation: mozilla::detail::EnumeratedRange<CrashReporter::Annotation> mozilla::MakeEnumeratedRange<CrashReporter::Annotation>(CrashReporter::Annotation)
Unexecuted instantiation: mozilla::detail::EnumeratedRange<mozilla::hal::SensorType> mozilla::MakeEnumeratedRange<mozilla::hal::SensorType>(mozilla::hal::SensorType)
Unexecuted instantiation: mozilla::detail::EnumeratedRange<txEXSLTType> mozilla::MakeEnumeratedRange<txEXSLTType>(txEXSLTType)
Unexecuted instantiation: mozilla::detail::EnumeratedRange<js::jit::CreateDependentString::FallbackKind> mozilla::MakeEnumeratedRange<js::jit::CreateDependentString::FallbackKind>(js::jit::CreateDependentString::FallbackKind)
Unexecuted instantiation: mozilla::detail::EnumeratedRange<js::wasm::SymbolicAddress> mozilla::MakeEnumeratedRange<js::wasm::SymbolicAddress>(js::wasm::SymbolicAddress)
Unexecuted instantiation: mozilla::detail::EnumeratedRange<js::wasm::Trap> mozilla::MakeEnumeratedRange<js::wasm::Trap>(js::wasm::Trap)
193
194
#ifdef __GNUC__
195
#  pragma GCC diagnostic pop
196
#endif
197
198
} // namespace mozilla
199
200
#endif // mozilla_EnumeratedRange_h
201