src
Functions | Variables
re2c_test Namespace Reference

Functions

static bool bit_set (uint32_t n, uint32_t bit)
 
template<uint8_t BITS>
re2c::Rangerange (uint32_t n)
 
template<uint8_t BITS>
re2c::Rangeadd (uint32_t n1, uint32_t n2)
 
template<uint8_t BITS>
re2c::Rangesub (uint32_t n1, uint32_t n2)
 
static bool equal (const re2c::Range *r1, const re2c::Range *r2)
 
static void show (const re2c::Range *r)
 
static int32_t diff (const re2c::Range *r1, const re2c::Range *r2, const re2c::Range *op1, const re2c::Range *op2, const char *op)
 
static int32_t test ()
 
static char * u64_to_s_fastest_ever (uint64_t u, char *s)
 
static int32_t test_u (uint64_t i)
 
static int32_t test_i (int64_t i)
 
static int32_t test ()
 

Variables

static const uint32_t DIGITS = 256
 

Function Documentation

template<uint8_t BITS>
re2c::Range * re2c_test::add ( uint32_t  n1,
uint32_t  n2 
)

Definition at line 37 of file test-impl.h.

38 {
39  return range<BITS> (n1 | n2);
40 }
static bool re2c_test::bit_set ( uint32_t  n,
uint32_t  bit 
)
inlinestatic

Definition at line 10 of file test-impl.h.

11 {
12  return n & (1u << bit);
13 }

Here is the caller graph for this function:

static int32_t re2c_test::diff ( const re2c::Range r1,
const re2c::Range r2,
const re2c::Range op1,
const re2c::Range op2,
const char *  op 
)
static

Definition at line 43 of file test.cc.

48 {
49  if (equal (op1, op2))
50  {
51  return 0;
52  }
53  else
54  {
55  fprintf (stderr, "%s error: ", op);
56  show (r1);
57  fprintf (stderr, " %s ", op);
58  show (r2);
59  fprintf (stderr, " ====> ");
60  show (op2);
61  fprintf (stderr, " =/= ");
62  show (op1);
63  fprintf (stderr, "\n");
64  return 1;
65  }
66 }
static bool equal(const re2c::Range *r1, const re2c::Range *r2)
Definition: test.cc:8
static void show(const re2c::Range *r)
Definition: test.cc:21

Here is the call graph for this function:

Here is the caller graph for this function:

static bool re2c_test::equal ( const re2c::Range r1,
const re2c::Range r2 
)
static

Definition at line 8 of file test.cc.

9 {
10  for (; r1 && r2; r1 = r1->next (), r2 = r2->next ())
11  {
12  if (r1->lower () != r2->lower ()
13  || r1->upper () != r2->upper ())
14  {
15  return false;
16  }
17  }
18  return !r1 && !r2;
19 }
uint32_t lower() const
Definition: range.h:40
uint32_t upper() const
Definition: range.h:41
Range * next() const
Definition: range.h:39

Here is the call graph for this function:

Here is the caller graph for this function:

template<uint8_t BITS>
re2c::Range * re2c_test::range ( uint32_t  n)

Definition at line 16 of file test-impl.h.

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 }
static bool bit_set(uint32_t n, uint32_t bit)
Definition: test-impl.h:10
#define RE2C_STATIC_ASSERT(e)
Definition: static_assert.h:11

Here is the call graph for this function:

static void re2c_test::show ( const re2c::Range r)
static

Definition at line 21 of file test.cc.

22 {
23  if (!r)
24  {
25  fprintf (stderr, "[]");
26  }
27  for (; r; r = r->next ())
28  {
29  const uint32_t l = r->lower ();
30  const uint32_t u = r->upper () - 1;
31  if (l < u)
32  {
33  fprintf (stderr, "[%X-%X]", l, u);
34  }
35  else
36  {
37  fprintf (stderr, "[%X]", l);
38  }
39  }
40 }
uint32_t lower() const
Definition: range.h:40
uint32_t upper() const
Definition: range.h:41
Range * next() const
Definition: range.h:39

Here is the call graph for this function:

Here is the caller graph for this function:

template<uint8_t BITS>
re2c::Range * re2c_test::sub ( uint32_t  n1,
uint32_t  n2 
)

Definition at line 43 of file test-impl.h.

44 {
45  return range<BITS> (n1 & ~n2);
46 }
static int32_t re2c_test::test ( )
static

Definition at line 58 of file test.cc.

59 {
60  int32_t ok = 0;
61 
62  static const uint64_t UDELTA = 0xFFFF;
63  // zero neighbourhood
64  for (uint64_t i = 0; i <= UDELTA; ++i)
65  {
66  ok |= test_u (i);
67  }
68  // u32_max neighbourhood
69  static const uint64_t u32_max = std::numeric_limits<uint32_t>::max();
70  for (uint64_t i = u32_max - UDELTA; i <= u32_max + UDELTA; ++i)
71  {
72  ok |= test_u (i);
73  }
74 
75  static const int64_t IDELTA = 0xFFFF;
76  // i32_min neighbourhood
77  static const int64_t i32_min = std::numeric_limits<int32_t>::min();
78  for (int64_t i = i32_min - IDELTA; i <= i32_min + IDELTA; ++i)
79  {
80  ok |= test_i (i);
81  }
82  // zero neighbourhood
83  for (int64_t i = -IDELTA; i <= IDELTA; ++i)
84  {
85  ok |= test_i (i);
86  }
87  // i32_max neighbourhood
88  static const int64_t i32_max = std::numeric_limits<int32_t>::max();
89  for (int64_t i = i32_max - IDELTA; i <= i32_max + IDELTA; ++i)
90  {
91  ok |= test_i (i);
92  }
93 
94  return ok;
95 }
static int32_t test_i(int64_t i)
Definition: test.cc:37
static int32_t test_u(uint64_t i)
Definition: test.cc:23

Here is the call graph for this function:

static int32_t re2c_test::test ( )
static

Definition at line 68 of file test.cc.

69 {
70  int32_t ok = 0;
71 
72  static const uint32_t BITS = 8;
73  static const uint32_t N = 1u << BITS;
74  for (uint32_t i = 0; i <= N; ++i)
75  {
76  for (uint32_t j = 0; j <= N; ++j)
77  {
78  re2c::Range * r1 = range<BITS> (i);
79  re2c::Range * r2 = range<BITS> (j);
80  ok |= diff (r1, r2, add<BITS> (i, j), re2c::Range::add (r1, r2), "U");
81  ok |= diff (r1, r2, sub<BITS> (i, j), re2c::Range::sub (r1, r2), "D");
82  re2c::Range::vFreeList.clear ();
83  }
84  }
85 
86  return ok;
87 }
static Range * sub(const Range *r1, const Range *r2)
Definition: range.cc:61
static free_list< Range * > vFreeList
Definition: range.h:18
static int32_t diff(const re2c::Range *r1, const re2c::Range *r2, const re2c::Range *op1, const re2c::Range *op2, const char *op)
Definition: test.cc:43
static Range * add(const Range *r1, const Range *r2)
Definition: range.cc:26

Here is the call graph for this function:

Here is the caller graph for this function:

static int32_t re2c_test::test_i ( int64_t  i)
static

Definition at line 37 of file test.cc.

38 {
39  char s [DIGITS];
40  char * const s_end = s + DIGITS;
41  const uint64_t i_abs = i < 0
42  ? static_cast<uint64_t> (-i)
43  : static_cast<uint64_t> (i);
44  char * s_start = u64_to_s_fastest_ever (i_abs, s_end);
45  if (i < 0)
46  {
47  *--s_start = '-';
48  }
49  int32_t j = i == 0; // not equal to i
50  if (s_to_i32_unsafe (s_start, s_end, j) && j != i)
51  {
52  fprintf (stderr, "signed: expected: %ld, got: %d\n", i, j);
53  return 1;
54  }
55  return 0;
56 }
static const uint32_t DIGITS
Definition: test.cc:8
static char * u64_to_s_fastest_ever(uint64_t u, char *s)
Definition: test.cc:12
bool s_to_i32_unsafe(const char *s, const char *s_end, int32_t &number)

Here is the call graph for this function:

Here is the caller graph for this function:

static int32_t re2c_test::test_u ( uint64_t  i)
static

Definition at line 23 of file test.cc.

24 {
25  char s [DIGITS];
26  char * const s_end = s + DIGITS;
27  char * const s_start = u64_to_s_fastest_ever (i, s_end);
28  uint32_t u = i == 0; // not equal to i
29  if (s_to_u32_unsafe (s_start, s_end, u) && u != i)
30  {
31  fprintf (stderr, "unsigned: expected: %lu, got: %u\n", i, u);
32  return 1;
33  }
34  return 0;
35 }
static const uint32_t DIGITS
Definition: test.cc:8
bool s_to_u32_unsafe(const char *s, const char *s_end, uint32_t &number)
static char * u64_to_s_fastest_ever(uint64_t u, char *s)
Definition: test.cc:12

Here is the call graph for this function:

Here is the caller graph for this function:

static char* re2c_test::u64_to_s_fastest_ever ( uint64_t  u,
char *  s 
)
static

Definition at line 12 of file test.cc.

13 {
14  while (u > 0)
15  {
16  const uint64_t d = u % 10 + '0';
17  *--s = static_cast<char> (d);
18  u /= 10;
19  }
20  return s;
21 }

Here is the caller graph for this function:

Variable Documentation

const uint32_t re2c_test::DIGITS = 256
static

Definition at line 8 of file test.cc.