From: Ulya Trofimovich Date: Sun, 30 Dec 2018 19:53:46 +0000 (+0000) Subject: Added assert wrapper that is turned on/off with --enable-debug configure option. X-Git-Tag: 1.2~266 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0c8f6aaae97224761ae27c2e01bbea42ac4804d5;p=re2c Added assert wrapper that is turned on/off with --enable-debug configure option. --- diff --git a/re2c/Makefile.am b/re2c/Makefile.am index f00cd9ab..ebb9adec 100644 --- a/re2c/Makefile.am +++ b/re2c/Makefile.am @@ -1,6 +1,9 @@ # flags # do *not* add CXXFLAGS here, add them in configure.ac AM_CXXFLAGS = $(CXXFLAGSDEFAULT) +if DEBUG + AM_CXXFLAGS += -DRE2C_DEBUG +endif RE2CFLAGS = -b -W # binary @@ -56,6 +59,7 @@ SRC_HDR = \ src/util/attribute.h \ src/util/c99_stdint.h \ src/util/counter.h \ + src/util/debug_assert.h \ src/util/forbid_copy.h \ src/util/free_list.h \ src/util/get_dir.h \ diff --git a/re2c/__build.sh b/re2c/__build.sh index a68e9be6..1bc1018f 100755 --- a/re2c/__build.sh +++ b/re2c/__build.sh @@ -5,6 +5,6 @@ rm -rf $builddir mkdir $builddir cd $builddir -../configure && \ +../configure --enable-debug && \ make -j5 cd .. diff --git a/re2c/__build_asan.sh b/re2c/__build_asan.sh index 916ac11f..dd3d1307 100755 --- a/re2c/__build_asan.sh +++ b/re2c/__build_asan.sh @@ -5,6 +5,6 @@ rm -rf $builddir mkdir $builddir cd $builddir -../configure CXXFLAGS="-fsanitize=address" LDFLAGS="-fsanitize=address" && \ +../configure --enable-debug CXXFLAGS="-fsanitize=address" LDFLAGS="-fsanitize=address" && \ make -j5 cd .. diff --git a/re2c/__build_clang.sh b/re2c/__build_clang.sh index 9db0bd73..2f53ddba 100755 --- a/re2c/__build_clang.sh +++ b/re2c/__build_clang.sh @@ -5,6 +5,6 @@ rm -rf $builddir mkdir $builddir cd $builddir -../configure CC=clang CXX=clang++ && \ +../configure --enable-debug CC=clang CXX=clang++ && \ make -j5 cd .. diff --git a/re2c/__build_clang_msan.sh b/re2c/__build_clang_msan.sh index 524b64b0..93633555 100755 --- a/re2c/__build_clang_msan.sh +++ b/re2c/__build_clang_msan.sh @@ -5,6 +5,6 @@ rm -rf $builddir mkdir $builddir cd $builddir -../configure CC=clang CXX=clang++ CFLAGS="-fsanitize=memory" CXXFLAGS="-fsanitize=memory" LDFLAGS="-fsanitize=memory" && \ +../configure --enable-debug CC=clang CXX=clang++ CFLAGS="-fsanitize=memory" CXXFLAGS="-fsanitize=memory" LDFLAGS="-fsanitize=memory" && \ make -j5 cd .. diff --git a/re2c/__build_lsan.sh b/re2c/__build_lsan.sh index 28f16ebf..2fc0e990 100755 --- a/re2c/__build_lsan.sh +++ b/re2c/__build_lsan.sh @@ -5,6 +5,6 @@ rm -rf $builddir mkdir $builddir cd $builddir -../configure CXXFLAGS="-fsanitize=leak" LDFLAGS="-fsanitize=leak" && \ +../configure --enable-debug CXXFLAGS="-fsanitize=leak" LDFLAGS="-fsanitize=leak" && \ make -j5 cd .. diff --git a/re2c/__build_m32.sh b/re2c/__build_m32.sh index 4e8021bf..dff24936 100755 --- a/re2c/__build_m32.sh +++ b/re2c/__build_m32.sh @@ -5,6 +5,6 @@ rm -rf $builddir mkdir $builddir cd $builddir -../configure CXXFLAGS="-m32" LDFLAGS="-m32" && \ +../configure --enable-debug CXXFLAGS="-m32" LDFLAGS="-m32" && \ make -j5 cd .. diff --git a/re2c/__build_mingw.sh b/re2c/__build_mingw.sh index c6d05b00..417d0992 100755 --- a/re2c/__build_mingw.sh +++ b/re2c/__build_mingw.sh @@ -5,6 +5,6 @@ rm -rf $builddir mkdir $builddir cd $builddir -../configure --host i686-w64-mingw32 && \ +../configure --enable-debug --host i686-w64-mingw32 && \ make -j5 cd .. diff --git a/re2c/__build_redundant_exports.sh b/re2c/__build_redundant_exports.sh index 83c58b2a..9e094756 100755 --- a/re2c/__build_redundant_exports.sh +++ b/re2c/__build_redundant_exports.sh @@ -5,6 +5,6 @@ rm -rf $builddir mkdir $builddir cd $builddir -../configure CFLAGS="-ffunction-sections -fdata-sections" LDFLAGS="-Wl,--gc-sections -Wl,--print-gc-sections" && \ +../configure --enable-debug CFLAGS="-ffunction-sections -fdata-sections" LDFLAGS="-Wl,--gc-sections -Wl,--print-gc-sections" && \ make -j5 cd .. diff --git a/re2c/__build_ubsan.sh b/re2c/__build_ubsan.sh index 76d2d150..20312205 100755 --- a/re2c/__build_ubsan.sh +++ b/re2c/__build_ubsan.sh @@ -5,6 +5,6 @@ rm -rf $builddir mkdir $builddir cd $builddir -../configure CXXFLAGS="-fsanitize=undefined" LDFLAGS="-fsanitize=undefined" && \ +../configure --enable-debug CXXFLAGS="-fsanitize=undefined" LDFLAGS="-fsanitize=undefined" && \ make -j5 cd .. diff --git a/re2c/__distcheck.sh b/re2c/__distcheck.sh index c3998a3d..466a39e7 100755 --- a/re2c/__distcheck.sh +++ b/re2c/__distcheck.sh @@ -18,6 +18,7 @@ do mkdir $builddir cd $builddir # 'make' implies 'make docs'; running both in parallel may cause data races + # configure without --enable-debug, this is the release binary ../configure --enable-docs \ && $make_prog bootstrap -j5 \ && $make_prog distcheck -j5 diff --git a/re2c/configure.ac b/re2c/configure.ac index 863744c9..50b81cf7 100644 --- a/re2c/configure.ac +++ b/re2c/configure.ac @@ -14,6 +14,12 @@ AC_SUBST(PACKAGE_TARNAME) AC_SUBST(PACKAGE_RELEASE, ${PACKAGE_RELEASE:-1}) +# --enable-debug +AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug], + [enable checks and assertions])]) +AM_CONDITIONAL([DEBUG], [test "x$enable_debug" = "xyes"]) + + # --enable-docs AC_ARG_ENABLE([docs], [AS_HELP_STRING([--enable-docs], [regenerate manpage])]) AM_CONDITIONAL([REBUILD_DOCS], [test "x$enable_docs" = "xyes"]) diff --git a/re2c/src/adfa/action.h b/re2c/src/adfa/action.h index fff24e04..bf3603d1 100644 --- a/re2c/src/adfa/action.h +++ b/re2c/src/adfa/action.h @@ -1,12 +1,12 @@ #ifndef _RE2C_ADFA_ACTION_ #define _RE2C_ADFA_ACTION_ -#include #include #include "src/code/label.h" #include "src/dfa/tcmd.h" #include "src/util/c99_stdint.h" +#include "src/util/debug_assert.h" #include "src/util/uniq_vector.h" namespace re2c @@ -75,29 +75,29 @@ public: // already marked as initial, probably reuse mode info.initial->label = label; } else { - assert(false); + DASSERT(false); } } void set_save (size_t save) { - assert(type == MATCH); + DASSERT(type == MATCH); type = SAVE; info.save = save; } void set_move () { - assert(type == MATCH); + DASSERT(type == MATCH); type = MOVE; } void set_accept (const accept_t * accepts) { - assert(type == MATCH); + DASSERT(type == MATCH); type = ACCEPT; info.accepts = accepts; } void set_rule (size_t rule) { - assert(type == MATCH); + DASSERT(type == MATCH); type = RULE; info.rule = rule; } diff --git a/re2c/src/adfa/adfa.cc b/re2c/src/adfa/adfa.cc index 7afa7b52..150318b6 100644 --- a/re2c/src/adfa/adfa.cc +++ b/re2c/src/adfa/adfa.cc @@ -1,4 +1,3 @@ -#include #include #include #include @@ -10,6 +9,7 @@ #include "src/code/go.h" #include "src/dfa/dfa.h" #include "src/util/allocate.h" +#include "src/util/debug_assert.h" namespace re2c { @@ -176,7 +176,7 @@ void DFA::reorder() } } - assert(nStates == ord.size()); + DASSERT(nStates == ord.size()); ord.push_back(NULL); for(uint32_t i = 0; i < nStates; ++i) diff --git a/re2c/src/adfa/prepare.cc b/re2c/src/adfa/prepare.cc index 1ec03430..de5fac10 100644 --- a/re2c/src/adfa/prepare.cc +++ b/re2c/src/adfa/prepare.cc @@ -1,4 +1,3 @@ -#include #include "src/util/c99_stdint.h" #include #include @@ -15,6 +14,7 @@ #include "src/dfa/tcmd.h" #include "src/re/rule.h" #include "src/util/allocate.h" +#include "src/util/debug_assert.h" namespace re2c { @@ -317,7 +317,7 @@ void DFA::hoist_tags(const opt_t *opts) void DFA::hoist_tags_and_skip(const opt_t *opts) { - assert(opts->eager_skip); + DASSERT(opts->eager_skip); for (State * s = head; s; s = s->next) { Span *span = s->go.span; diff --git a/re2c/src/ast/scanner.cc b/re2c/src/ast/scanner.cc index 28fc2742..c0440970 100644 --- a/re2c/src/ast/scanner.cc +++ b/re2c/src/ast/scanner.cc @@ -1,8 +1,8 @@ -#include #include #include "src/ast/scanner.h" #include "src/conf/msg.h" +#include "src/util/debug_assert.h" namespace re2c { @@ -23,7 +23,7 @@ size_t Scanner::get_input_index() const // Find index of the current input file: the one corresponding to // buffer fragment that contains cursor. size_t i = files.size(); - assert(i > 0); + DASSERT(i > 0); for (;;) { --i; Input *in = files[i]; @@ -81,7 +81,7 @@ bool Scanner::include(const std::string &filename) bool Scanner::read(size_t want) { - assert(!files.empty()); + DASSERT(!files.empty()); for (size_t i = files.size(); i --> 0; ) { Input *in = files[i]; const size_t have = fread(lim, 1, want, in->file); @@ -105,7 +105,7 @@ void Scanner::shift_ptrs_and_fpos(ptrdiff_t offs) for (size_t i = files.size(); i --> 0; ) { Input *in = files[i]; if (in->so == ENDPOS && in->eo == ENDPOS) break; - assert(in->so != ENDPOS && in->eo != ENDPOS); + DASSERT(in->so != ENDPOS && in->eo != ENDPOS); in->so += offs; in->eo += offs; } @@ -118,7 +118,7 @@ void Scanner::pop_finished_files() // except for the first (main) file which must always remain at the // bottom of the stack. size_t i = files.size(); - assert(i > 0); + DASSERT(i > 0); for (;;) { --i; Input *in = files[i]; @@ -134,7 +134,7 @@ bool Scanner::fill(size_t need) pop_finished_files(); - assert(bot <= tok && tok <= lim); + DASSERT(bot <= tok && tok <= lim); size_t free = static_cast(tok - bot); size_t copy = static_cast(lim - tok); diff --git a/re2c/src/code/emit_action.cc b/re2c/src/code/emit_action.cc index c70e35e1..e149a250 100644 --- a/re2c/src/code/emit_action.cc +++ b/re2c/src/code/emit_action.cc @@ -1,4 +1,3 @@ -#include #include #include "src/util/c99_stdint.h" #include @@ -21,6 +20,7 @@ #include "src/re/tag.h" #include "src/skeleton/skeleton.h" #include "src/util/string_utils.h" +#include "src/util/debug_assert.h" namespace re2c { @@ -509,11 +509,11 @@ void gen_fintags(Output &o, uint32_t ind, const DFA &dfa, const Rule &rule) o.wind(ind); if (generic) { - assert(dist == 0); + DASSERT(dist == 0); if (!trailing(tag)) { o.wstring(tagname(tag)).ws(" = ").wstring(expr); } else if (!fixed_on_cursor) { - assert(!dfa.oldstyle_ctxmarker); + DASSERT(!dfa.oldstyle_ctxmarker); o.wstring(opts->yyrestoretag).ws(" (").wstring(expr).ws(")"); } } else { @@ -533,7 +533,7 @@ void gen_fintags(Output &o, uint32_t ind, const DFA &dfa, const Rule &rule) std::string tagname(const Tag &tag) { - assert(!trailing(tag)); + DASSERT(!trailing(tag)); return capture(tag) ? "yypmatch[" + to_string(tag.ncap) + "]" : *tag.name; diff --git a/re2c/src/code/go_construct.cc b/re2c/src/code/go_construct.cc index aa44c3df..c90d9850 100644 --- a/re2c/src/code/go_construct.cc +++ b/re2c/src/code/go_construct.cc @@ -1,4 +1,3 @@ -#include #include #include "src/util/c99_stdint.h" #include @@ -12,6 +11,7 @@ #include "src/conf/opt.h" #include "src/dfa/tcmd.h" #include "src/util/allocate.h" +#include "src/util/debug_assert.h" namespace re2c { @@ -41,7 +41,7 @@ Cases::Cases(const Span *spans, uint32_t nspans, bool skip, uint32_t eof) : cases(new Case[nspans]) , cases_size(0) { - assert(nspans > 0); + DASSERT(nspans > 0); // first case is default: book the place (ranges will be added later) Case &c = cases[cases_size++]; diff --git a/re2c/src/code/input_api.cc b/re2c/src/code/input_api.cc index 77e67d1a..c06e629d 100644 --- a/re2c/src/code/input_api.cc +++ b/re2c/src/code/input_api.cc @@ -1,9 +1,9 @@ -#include #include #include "src/code/emit.h" #include "src/code/input_api.h" #include "src/conf/opt.h" +#include "src/util/debug_assert.h" namespace re2c { @@ -78,35 +78,35 @@ void output_backup(std::ostream &o, uint32_t ind, const opt_t *opts) void output_skip_peek(std::ostream &o, uint32_t ind, const opt_t *opts) { - assert(opts->input_api == INPUT_DEFAULT); + DASSERT(opts->input_api == INPUT_DEFAULT); o << indent(ind, opts->indString) << opts->yych << " = " << yych_conv(opts) << "*++" << opts->yycursor << ";\n"; } void output_peek_skip(std::ostream &o, uint32_t ind, const opt_t *opts) { - assert(opts->input_api == INPUT_DEFAULT); + DASSERT(opts->input_api == INPUT_DEFAULT); o << indent(ind, opts->indString) << opts->yych << " = " << yych_conv(opts) << "*" << opts->yycursor << "++;\n"; } void output_skip_backup(std::ostream &o, uint32_t ind, const opt_t *opts) { - assert(opts->input_api == INPUT_DEFAULT); + DASSERT(opts->input_api == INPUT_DEFAULT); o << indent(ind, opts->indString) << opts->yymarker << " = ++" << opts->yycursor << ";\n"; } void output_backup_skip(std::ostream &o, uint32_t ind, const opt_t *opts) { - assert(opts->input_api == INPUT_DEFAULT); + DASSERT(opts->input_api == INPUT_DEFAULT); o << indent(ind, opts->indString) << opts->yymarker << " = " << opts->yycursor << "++;\n"; } void output_backup_peek(std::ostream &o, uint32_t ind, const opt_t *opts) { - assert(opts->input_api == INPUT_DEFAULT); + DASSERT(opts->input_api == INPUT_DEFAULT); o << indent(ind, opts->indString) << opts->yych << " = " << yych_conv(opts) << "*(" << opts->yymarker << " = " << opts->yycursor << ");\n"; @@ -114,7 +114,7 @@ void output_backup_peek(std::ostream &o, uint32_t ind, const opt_t *opts) void output_skip_backup_peek(std::ostream &o, uint32_t ind, const opt_t *opts) { - assert(opts->input_api == INPUT_DEFAULT); + DASSERT(opts->input_api == INPUT_DEFAULT); o << indent(ind, opts->indString) << opts->yych << " = " << yych_conv(opts) << "*(" << opts->yymarker << " = ++" << opts->yycursor << ");\n"; @@ -122,7 +122,7 @@ void output_skip_backup_peek(std::ostream &o, uint32_t ind, const opt_t *opts) void output_backup_peek_skip(std::ostream &o, uint32_t ind, const opt_t *opts) { - assert(opts->input_api == INPUT_DEFAULT); + DASSERT(opts->input_api == INPUT_DEFAULT); o << indent(ind, opts->indString) << opts->yych << " = " << yych_conv(opts) << "*(" << opts->yymarker << " = " << opts->yycursor << "++);\n"; diff --git a/re2c/src/dfa/cfg/liveanal.cc b/re2c/src/dfa/cfg/liveanal.cc index 62f9781a..cf9421a7 100644 --- a/re2c/src/dfa/cfg/liveanal.cc +++ b/re2c/src/dfa/cfg/liveanal.cc @@ -1,4 +1,3 @@ -#include #include #include @@ -7,6 +6,7 @@ #include "src/dfa/tcmd.h" #include "src/re/rule.h" #include "src/re/tag.h" +#include "src/util/debug_assert.h" namespace re2c { @@ -77,7 +77,7 @@ void cfg_t::liveness_analysis(const cfg_t &cfg, bool *live) bool *l = &live[i * nver]; // all final bblocks have USE tags, but no successors - assert(r && b->succb == b->succe); + DASSERT(r && b->succb == b->succe); for (size_t t = r->ltag; t < r->htag; ++t) { l[fins[t]] = !fixed(tags[t]); @@ -97,7 +97,7 @@ void cfg_t::liveness_analysis(const cfg_t &cfg, bool *live) bool *old = &live[i * nver]; // transition bblocks have no USE tags - assert(!b->rule); + DASSERT(!b->rule); memcpy(buf1, old, nver * sizeof(bool)); for (cfg_ix_t *j = b->succb; j < b->succe; ++j) { @@ -136,7 +136,7 @@ void cfg_t::liveness_analysis(const cfg_t &cfg, bool *live) const Rule *r = b->rule; // all fallback bblocks have USE tags - assert(r); + DASSERT(r); memset(buf1, 0, nver * sizeof(bool)); for (size_t t = r->ltag; t < r->htag; ++t) { diff --git a/re2c/src/dfa/cfg/normalize.cc b/re2c/src/dfa/cfg/normalize.cc index 0c81abb5..796fc907 100644 --- a/re2c/src/dfa/cfg/normalize.cc +++ b/re2c/src/dfa/cfg/normalize.cc @@ -1,4 +1,3 @@ -#include #include "src/util/c99_stdint.h" #include #include @@ -7,6 +6,7 @@ #include "src/dfa/dfa.h" #include "src/dfa/tcmd.h" #include "src/re/tag.h" +#include "src/util/debug_assert.h" namespace re2c { @@ -61,7 +61,7 @@ void cfg_t::normalization(cfg_t &cfg) static void swap(tcmd_t &x, tcmd_t &y) { - assert(!tcmd_t::isadd(&x) && !tcmd_t::isadd(&y)); + DASSERT(!tcmd_t::isadd(&x) && !tcmd_t::isadd(&y)); std::swap(x.lhs, y.lhs); std::swap(x.rhs, y.rhs); std::swap(x.history[0], y.history[0]); @@ -69,7 +69,7 @@ static void swap(tcmd_t &x, tcmd_t &y) static bool less(const tcmd_t &x, const tcmd_t &y) { - assert(!tcmd_t::isadd(&x) && !tcmd_t::isadd(&y)); + DASSERT(!tcmd_t::isadd(&x) && !tcmd_t::isadd(&y)); tagver_t u, v; u = x.lhs; v = y.lhs; diff --git a/re2c/src/dfa/closure.cc b/re2c/src/dfa/closure.cc index 0641072e..bcbbe7c9 100644 --- a/re2c/src/dfa/closure.cc +++ b/re2c/src/dfa/closure.cc @@ -1,4 +1,3 @@ -#include #include "src/util/c99_stdint.h" #include #include diff --git a/re2c/src/dfa/closure_posix.cc b/re2c/src/dfa/closure_posix.cc index afbcb010..f6f05753 100644 --- a/re2c/src/dfa/closure_posix.cc +++ b/re2c/src/dfa/closure_posix.cc @@ -1,5 +1,6 @@ #include "src/dfa/determinization.h" #include "src/nfa/nfa.h" +#include "src/util/debug_assert.h" namespace re2c @@ -95,7 +96,7 @@ void closure_posix(determ_context_t &ctx) q = i->state; q->clos = NOCLOS; q->arcidx = 0; - assert(q->status == GOR_NOPASS && q->active == 0); + DASSERT(q->status == GOR_NOPASS && q->active == 0); } } diff --git a/re2c/src/dfa/determinization.cc b/re2c/src/dfa/determinization.cc index 2c25bcf8..93174f20 100644 --- a/re2c/src/dfa/determinization.cc +++ b/re2c/src/dfa/determinization.cc @@ -1,4 +1,3 @@ -#include #include "src/util/c99_stdint.h" #include #include @@ -17,6 +16,7 @@ #include "src/nfa/nfa.h" #include "src/re/rule.h" #include "src/re/tag.h" +#include "src/util/debug_assert.h" #include "src/util/range.h" @@ -113,7 +113,7 @@ uint32_t init_tag_versions(determ_context_t &ctx) const size_t ntags = dfa.tags.size(); // all-zero tag configuration must have static number zero - assert(ZERO_TAGS == ctx.dc_tagvertbl.insert_const(TAGVER_ZERO)); + DASSERT(ZERO_TAGS == ctx.dc_tagvertbl.insert_const(TAGVER_ZERO)); // initial tag versions: [1 .. N] const uint32_t INITIAL_TAGS = ctx.dc_tagvertbl.insert_succ(1); diff --git a/re2c/src/dfa/dump.cc b/re2c/src/dfa/dump.cc index 64086081..098d1d95 100644 --- a/re2c/src/dfa/dump.cc +++ b/re2c/src/dfa/dump.cc @@ -14,7 +14,7 @@ #include "src/nfa/nfa.h" #include "src/re/rule.h" #include "src/re/tag.h" - +#include "src/util/debug_assert.h" namespace re2c { @@ -135,7 +135,7 @@ void dump_dfa_t::state(const determ_context_t &ctx, bool isnew) // see note [at most one final item per closure] c = std::find_if(b, e, clos_t::fin); - assert(c != e); + DASSERT(c != e); fprintf(stderr, " r%u [shape=none label=\"(", state); for (size_t t = r.ltag; t < r.htag; ++t) { diff --git a/re2c/src/dfa/find_state.cc b/re2c/src/dfa/find_state.cc index 036d7f16..bb74443e 100644 --- a/re2c/src/dfa/find_state.cc +++ b/re2c/src/dfa/find_state.cc @@ -1,4 +1,3 @@ -#include #include #include #include @@ -8,6 +7,7 @@ #include "src/dfa/tcmd.h" #include "src/nfa/nfa.h" #include "src/re/rule.h" +#include "src/util/debug_assert.h" #include "src/util/hash32.h" @@ -339,7 +339,7 @@ void reserve_buffers(determ_context_t &ctx) bool equal_lookahead_tags(const kernel_t *x, const kernel_t *y, const determ_context_t &ctx) { - assert(x->size == y->size); + DASSERT(x->size == y->size); if (memcmp(x->tlook, y->tlook, x->size * sizeof(hidx_t)) == 0) { return true; @@ -448,7 +448,7 @@ bool kernel_map_t::operator()(const kernel_t *x, const kernel_t *y) for (tagver_t xv = -max; xv < max; ++xv) { const tagver_t yv = x2y[xv], axv = abs(xv), ayv = abs(yv); if (yv != TAGVER_ZERO && xv != yv && !fixed(tags[x2t[xv]])) { - assert(axv != ayv); + DASSERT(axv != ayv); copy = ctx.dc_dfa.tcpool.make_copy(copy, axv, ayv); } } diff --git a/re2c/src/dfa/posix_precedence.cc b/re2c/src/dfa/posix_precedence.cc index db7890a6..e39afc47 100644 --- a/re2c/src/dfa/posix_precedence.cc +++ b/re2c/src/dfa/posix_precedence.cc @@ -1,8 +1,8 @@ -#include #include #include "src/dfa/determinization.h" #include "src/dfa/tag_history.h" +#include "src/util/debug_assert.h" namespace re2c @@ -84,14 +84,14 @@ int32_t precedence(determ_context_t &ctx, const bool neg1 = j1->neg, neg2 = j2->neg; // can't be both closing - assert(!(idx1 % 2 == 1 && idx2 % 2 == 1)); + DASSERT(!(idx1 % 2 == 1 && idx2 % 2 == 1)); // closing vs opening: closing wins if (idx1 % 2 == 1) return -1; if (idx2 % 2 == 1) return 1; // can't be both negative - assert(!(neg1 && neg2)); + DASSERT(!(neg1 && neg2)); // positive vs negative: positive wins if (neg1) return 1; @@ -105,7 +105,7 @@ int32_t precedence(determ_context_t &ctx, } // unreachable - assert(false); + DASSERT(false); return 0; } @@ -140,7 +140,7 @@ int32_t pack(int32_t longest, int32_t leftmost) uint32_t u_packed = (u_longest & 0x3fffFFFF) | (u_leftmost << 30u); int32_t packed = static_cast(u_packed); - assert(unpack_longest(packed) == longest + DASSERT(unpack_longest(packed) == longest && unpack_leftmost(packed) == leftmost); return packed; diff --git a/re2c/src/dfa/tcmd.cc b/re2c/src/dfa/tcmd.cc index 7d3503bd..216d6b40 100644 --- a/re2c/src/dfa/tcmd.cc +++ b/re2c/src/dfa/tcmd.cc @@ -1,7 +1,7 @@ -#include #include #include "src/dfa/tcmd.h" +#include "src/util/debug_assert.h" #include "src/util/hash32.h" namespace re2c @@ -65,7 +65,7 @@ bool tcmd_t::iscopy(const tcmd_t *x) bool tcmd_t::isset(const tcmd_t *x) { if (x->rhs == TAGVER_ZERO) { - assert(x->history[0] != TAGVER_ZERO); + DASSERT(x->history[0] != TAGVER_ZERO); return true; } return false; @@ -128,7 +128,7 @@ tcpool_t::tcpool_t() , index() { // empty command must have static number zero - assert(TCID0 == insert(NULL)); + DASSERT(TCID0 == insert(NULL)); } diff --git a/re2c/src/re/re.h b/re2c/src/re/re.h index e7137d9e..fd577d8b 100644 --- a/re2c/src/re/re.h +++ b/re2c/src/re/re.h @@ -1,11 +1,11 @@ #ifndef _RE2C_RE_RE_ #define _RE2C_RE_RE_ -#include "src/util/c99_stdint.h" - #include "src/conf/opt.h" #include "src/ast/ast.h" #include "src/re/rule.h" +#include "src/util/c99_stdint.h" +#include "src/util/debug_assert.h" #include "src/util/forbid_copy.h" #include "src/util/range.h" #include "src/util/slab_allocator.h" @@ -112,7 +112,7 @@ inline RE *re_tag(RE::alc_t &alc, size_t idx, bool neg) RE *x = alc.alloct(1); x->type = RE::TAG; x->tag.idx = idx & 0x7FFFffff; - assert(idx == x->tag.idx); + DASSERT(idx == x->tag.idx); x->tag.neg = neg; return x; } diff --git a/re2c/src/re/tag.cc b/re2c/src/re/tag.cc index 11da36a3..b0d97d50 100644 --- a/re2c/src/re/tag.cc +++ b/re2c/src/re/tag.cc @@ -1,5 +1,4 @@ #include "src/re/tag.h" -#include #include namespace re2c diff --git a/re2c/src/skeleton/generate_data.cc b/re2c/src/skeleton/generate_data.cc index df3fe397..b82ff700 100644 --- a/re2c/src/skeleton/generate_data.cc +++ b/re2c/src/skeleton/generate_data.cc @@ -1,4 +1,3 @@ -#include #include #include "src/util/c99_stdint.h" #include @@ -17,6 +16,7 @@ #include "src/re/tag.h" #include "src/skeleton/path.h" #include "src/skeleton/skeleton.h" +#include "src/util/debug_assert.h" #include "src/util/forbid_copy.h" #include "src/util/u32lim.h" #include "src/util/wrap_iter.h" @@ -205,9 +205,9 @@ static void write_keys(const path_t &path, const Skeleton &skel, if (trail == htag) { matched = f; } else { - assert(!fixed(skel.tags[trail])); // no fixed trailing context + DASSERT(!fixed(skel.tags[trail])); // no fixed trailing context matched = tags[skel.finvers[trail]].back(); - assert(matched != Skeleton::DEFTAG); + DASSERT(matched != Skeleton::DEFTAG); } } diff --git a/re2c/src/skeleton/maxpath.cc b/re2c/src/skeleton/maxpath.cc index 5a88fc54..455fada9 100644 --- a/re2c/src/skeleton/maxpath.cc +++ b/re2c/src/skeleton/maxpath.cc @@ -1,4 +1,3 @@ -#include #include #include "src/util/c99_stdint.h" #include @@ -10,6 +9,7 @@ #include "src/conf/msg.h" #include "src/skeleton/skeleton.h" +#include "src/util/debug_assert.h" namespace re2c { @@ -58,7 +58,7 @@ static uint32_t calc_dist(const Skeleton &skel const uint32_t d = calc_dist(skel, loops, dists, arc->first); // not necessarily true for dists[arc->first] - assert (d != DIST_ERROR); + DASSERT (d != DIST_ERROR); dist = (dist == DIST_ERROR) ? d : std::max(dist, d); } diff --git a/re2c/src/skeleton/skeleton.cc b/re2c/src/skeleton/skeleton.cc index cc27f752..817c7a72 100644 --- a/re2c/src/skeleton/skeleton.cc +++ b/re2c/src/skeleton/skeleton.cc @@ -1,8 +1,8 @@ -#include #include #include "src/dfa/dfa.h" #include "src/skeleton/skeleton.h" +#include "src/util/debug_assert.h" namespace re2c { @@ -96,7 +96,7 @@ Skeleton::~Skeleton() uint64_t rule2key(size_t rule, size_t key, size_t def) { switch (key) { - default: assert(false); // shouldn't happen + default: DASSERT(false); // shouldn't happen case 8: return rule2key(rule, def); case 4: return rule2key(rule, def); case 2: return rule2key(rule, def); diff --git a/re2c/src/util/debug_assert.h b/re2c/src/util/debug_assert.h new file mode 100644 index 00000000..0044a9f7 --- /dev/null +++ b/re2c/src/util/debug_assert.h @@ -0,0 +1,15 @@ +#ifndef _RE2C_UTIL_DEBUG_ASSERT_ +#define _RE2C_UTIL_DEBUG_ASSERT_ + +#ifdef RE2C_DEBUG + +#include +#define DASSERT(x) assert(x) + +#else // RE2C_DEBUG + +#define DASSERT(x) + +#endif // RE2C_DEBUG + +#endif // _RE2C_UTIL_DEBUG_ASSERT_ diff --git a/re2c/src/util/lookup.h b/re2c/src/util/lookup.h index 9ae7d738..59ddd935 100644 --- a/re2c/src/util/lookup.h +++ b/re2c/src/util/lookup.h @@ -2,12 +2,13 @@ #define _RE2C_UTIL_LOOKUP_ #include "src/util/c99_stdint.h" -#include #include #include #include #include +#include "src/util/debug_assert.h" + namespace re2c { @@ -84,7 +85,7 @@ uint32_t lookup_t::head(hash_t h) const template uint32_t lookup_t::push(hash_t hash, const data_t &data) { - assert(elems.size() < NIL); + DASSERT(elems.size() < NIL); const uint32_t idx = static_cast(elems.size()); elems.push_back(elem_t(head(hash), data)); lookup[hash] = idx; diff --git a/re2c/src/util/range.h b/re2c/src/util/range.h index 2c509338..19155f7d 100644 --- a/re2c/src/util/range.h +++ b/re2c/src/util/range.h @@ -1,11 +1,11 @@ #ifndef _RE2C_UTIL_RANGE_ #define _RE2C_UTIL_RANGE_ -#include #include // NULL #include "src/util/c99_stdint.h" #include "src/test/range/test.h" +#include "src/util/debug_assert.h" #include "src/util/forbid_copy.h" #include "src/util/free_list.h" @@ -48,7 +48,7 @@ private: , lb (l) , ub (u) { - assert (lb < ub); + DASSERT(lb < ub); vFreeList.insert (this); } static void append_overlapping (Range * & head, Range * & tail, const Range * r);