#include "src/util/range.h"
#include "src/util/static_assert.h"
+
namespace re2c_test {
static inline bool bit_set (uint32_t n, uint32_t bit)
}
template <uint8_t BITS>
-re2c::Range * range (uint32_t n)
+re2c::Range *range(re2c::RangeMgr &rm, uint32_t n)
{
RE2C_STATIC_ASSERT (BITS <= 31);
}
const uint32_t lb = i;
for (; i < BITS && bit_set (n, i); ++i);
- re2c::Range::append (p, lb, i);
+ rm.append(p, lb, i);
}
return r;
}
template <uint8_t BITS>
-re2c::Range * add (uint32_t n1, uint32_t n2)
+re2c::Range * add (re2c::RangeMgr &rm, uint32_t n1, uint32_t n2)
{
- return range<BITS> (n1 | n2);
+ return range<BITS> (rm, n1 | n2);
}
template <uint8_t BITS>
-re2c::Range * sub (uint32_t n1, uint32_t n2)
+re2c::Range * sub (re2c::RangeMgr &rm, uint32_t n1, uint32_t n2)
{
- return range<BITS> (n1 & ~n2);
+ return range<BITS> (rm, n1 & ~n2);
}
} // namespace re2c_test
static int32_t test ()
{
int32_t ok = 0;
+ re2c::RangeMgr rm;
static const uint32_t BITS = 8;
static const uint32_t N = 1u << BITS;
- for (uint32_t i = 0; i <= N; ++i)
- {
- for (uint32_t j = 0; j <= N; ++j)
- {
- re2c::Range * r1 = range<BITS> (i);
- re2c::Range * r2 = range<BITS> (j);
- ok |= diff (r1, r2, add<BITS> (i, j), re2c::Range::add (r1, r2), "U");
- ok |= diff (r1, r2, sub<BITS> (i, j), re2c::Range::sub (r1, r2), "D");
- re2c::Range::vFreeList.clear ();
+ for (uint32_t i = 0; i <= N; ++i) {
+ for (uint32_t j = 0; j <= N; ++j) {
+ re2c::Range * r1 = range<BITS>(rm, i);
+ re2c::Range * r2 = range<BITS>(rm, j);
+ ok |= diff (r1, r2, add<BITS>(rm, i, j), rm.add(r1, r2), "U");
+ ok |= diff (r1, r2, sub<BITS>(rm, i, j), rm.sub(r1, r2), "D");
+ rm.clear();
}
}
#include "src/util/c99_stdint.h"
-namespace re2c { class Range; }
+
+namespace re2c {
+
+class Range;
+class RangeMgr;
+
+}
namespace re2c_test {
* bitwise OR of two classes, subtraction is bitwise AND of the first
* class and negated second class.
*/
-template <uint8_t BITS> re2c::Range * range (uint32_t n);
-template <uint8_t BITS> re2c::Range * add (uint32_t n1, uint32_t n2);
-template <uint8_t BITS> re2c::Range * sub (uint32_t n1, uint32_t n2);
+template <uint8_t BITS> re2c::Range *range(re2c::RangeMgr &rm, uint32_t n);
+template <uint8_t BITS> re2c::Range *add(re2c::RangeMgr &rm, uint32_t n1, uint32_t n2);
+template <uint8_t BITS> re2c::Range *sub(re2c::RangeMgr &rm, uint32_t n1, uint32_t n2);
} // namespace re2c_test
size_t index;
public:
- fixed_allocator_t(): slabs(), index(0)
- {
- slabs.push_back(new_slab());
- }
+ fixed_allocator_t(): slabs(), index(SLAB_SIZE) {}
~fixed_allocator_t() { clear(); }
operator delete(*i);
}
slabs.clear();
- index = 0;
+ index = SLAB_SIZE;
}
T *alloc()
private:
friend class RangeMgr;
- template<uint8_t> friend Range *re2c_test::range(uint32_t n);
// not default- or copy-constructible
Range();
Range *make(Range *n, uint32_t l, uint32_t u);
void append_overlapping(Range *&head, Range *&tail, const Range *r);
void append(Range **&ptail, uint32_t l, uint32_t u);
+
+ template<uint8_t> friend Range *re2c_test::range(RangeMgr &rm, uint32_t n);
};
inline Range *RangeMgr::make(Range *n, uint32_t l, uint32_t u)