1 #ifndef _RE2C_TEST_RANGE_TEST_IMPL_
2 #define _RE2C_TEST_RANGE_TEST_IMPL_
3
4 #include "src/test/range/test.h"
5 #include "src/util/range.h"
6 #include "src/util/static_assert.h"
7
8
9 namespace re2c_test {
10
bit_set(uint32_t n,uint32_t bit)11 static inline bool bit_set (uint32_t n, uint32_t bit)
12 {
13 return n & (1u << bit);
14 }
15
16 template <uint8_t BITS>
range(re2c::RangeMgr & rm,uint32_t n)17 re2c::Range *range(re2c::RangeMgr &rm, uint32_t n)
18 {
19 RE2C_STATIC_ASSERT (BITS <= 31);
20
21 re2c::Range * r = NULL;
22 re2c::Range ** p = &r;
23 for (uint32_t i = 0; i < BITS; ++i)
24 {
25 for (; i < BITS && !bit_set (n, i); ++i);
26 if (i == BITS && !bit_set (n, BITS - 1))
27 {
28 break;
29 }
30 const uint32_t lb = i;
31 for (; i < BITS && bit_set (n, i); ++i);
32 rm.append(p, lb, i);
33 }
34 return r;
35 }
36
37 template <uint8_t BITS>
add(re2c::RangeMgr & rm,uint32_t n1,uint32_t n2)38 re2c::Range * add (re2c::RangeMgr &rm, uint32_t n1, uint32_t n2)
39 {
40 return range<BITS> (rm, n1 | n2);
41 }
42
43 template <uint8_t BITS>
sub(re2c::RangeMgr & rm,uint32_t n1,uint32_t n2)44 re2c::Range * sub (re2c::RangeMgr &rm, uint32_t n1, uint32_t n2)
45 {
46 return range<BITS> (rm, n1 & ~n2);
47 }
48
49 } // namespace re2c_test
50
51 #endif // _RE2C_TEST_RANGE_TEST_IMPL_
52