From: Ulya Trofimovich Date: Sun, 6 Jan 2019 16:44:45 +0000 (+0000) Subject: Updated range test. X-Git-Tag: 1.2~232 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6f2b7452a3904a0dac25514c7904792673385c2b;p=re2c Updated range test. --- diff --git a/re2c/src/test/range/test-impl.h b/re2c/src/test/range/test-impl.h index 0a16f0b5..c592ee8c 100644 --- a/re2c/src/test/range/test-impl.h +++ b/re2c/src/test/range/test-impl.h @@ -5,6 +5,7 @@ #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) @@ -13,7 +14,7 @@ static inline bool bit_set (uint32_t n, uint32_t bit) } template -re2c::Range * range (uint32_t n) +re2c::Range *range(re2c::RangeMgr &rm, uint32_t n) { RE2C_STATIC_ASSERT (BITS <= 31); @@ -28,21 +29,21 @@ re2c::Range * range (uint32_t n) } 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 -re2c::Range * add (uint32_t n1, uint32_t n2) +re2c::Range * add (re2c::RangeMgr &rm, uint32_t n1, uint32_t n2) { - return range (n1 | n2); + return range (rm, n1 | n2); } template -re2c::Range * sub (uint32_t n1, uint32_t n2) +re2c::Range * sub (re2c::RangeMgr &rm, uint32_t n1, uint32_t n2) { - return range (n1 & ~n2); + return range (rm, n1 & ~n2); } } // namespace re2c_test diff --git a/re2c/src/test/range/test.cc b/re2c/src/test/range/test.cc index 18181b7a..d5821dc4 100644 --- a/re2c/src/test/range/test.cc +++ b/re2c/src/test/range/test.cc @@ -68,18 +68,17 @@ static int32_t diff 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 (i); - re2c::Range * r2 = range (j); - ok |= diff (r1, r2, add (i, j), re2c::Range::add (r1, r2), "U"); - ok |= diff (r1, r2, sub (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(rm, i); + re2c::Range * r2 = range(rm, j); + ok |= diff (r1, r2, add(rm, i, j), rm.add(r1, r2), "U"); + ok |= diff (r1, r2, sub(rm, i, j), rm.sub(r1, r2), "D"); + rm.clear(); } } diff --git a/re2c/src/test/range/test.h b/re2c/src/test/range/test.h index 18aa1aca..a6391a8c 100644 --- a/re2c/src/test/range/test.h +++ b/re2c/src/test/range/test.h @@ -3,7 +3,13 @@ #include "src/util/c99_stdint.h" -namespace re2c { class Range; } + +namespace re2c { + +class Range; +class RangeMgr; + +} namespace re2c_test { @@ -17,9 +23,9 @@ namespace re2c_test { * bitwise OR of two classes, subtraction is bitwise AND of the first * class and negated second class. */ -template re2c::Range * range (uint32_t n); -template re2c::Range * add (uint32_t n1, uint32_t n2); -template re2c::Range * sub (uint32_t n1, uint32_t n2); +template re2c::Range *range(re2c::RangeMgr &rm, uint32_t n); +template re2c::Range *add(re2c::RangeMgr &rm, uint32_t n1, uint32_t n2); +template re2c::Range *sub(re2c::RangeMgr &rm, uint32_t n1, uint32_t n2); } // namespace re2c_test diff --git a/re2c/src/util/fixed_allocator.h b/re2c/src/util/fixed_allocator.h index 81a667e9..e0358346 100644 --- a/re2c/src/util/fixed_allocator.h +++ b/re2c/src/util/fixed_allocator.h @@ -16,10 +16,7 @@ class fixed_allocator_t 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(); } @@ -31,7 +28,7 @@ public: operator delete(*i); } slabs.clear(); - index = 0; + index = SLAB_SIZE; } T *alloc() diff --git a/re2c/src/util/range.h b/re2c/src/util/range.h index 82177070..2d86440e 100644 --- a/re2c/src/util/range.h +++ b/re2c/src/util/range.h @@ -27,7 +27,6 @@ public: private: friend class RangeMgr; - template friend Range *re2c_test::range(uint32_t n); // not default- or copy-constructible Range(); @@ -51,6 +50,8 @@ private: 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 friend Range *re2c_test::range(RangeMgr &rm, uint32_t n); }; inline Range *RangeMgr::make(Range *n, uint32_t l, uint32_t u)