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