From: Ulya Trofimovich Date: Tue, 27 Sep 2016 14:11:05 +0000 (+0100) Subject: Use explicit constant 'ZERO_TAGS' instead of 0. X-Git-Tag: 1.0~39^2~276 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5cf0a227c58204ddfbe879af5ef72990346533ad;p=re2c Use explicit constant 'ZERO_TAGS' instead of 0. --- diff --git a/re2c/src/codegen/bitmap.cc b/re2c/src/codegen/bitmap.cc index aa8c841d..b4c3e21d 100644 --- a/re2c/src/codegen/bitmap.cc +++ b/re2c/src/codegen/bitmap.cc @@ -160,8 +160,8 @@ bool matches(const Span * b1, uint32_t n1, const State * s1, const Span * b2, ui // might go to the same state, but have different tag sets if (lb1 != lb2 || b1->ub != b2->ub - || b1->tags != 0 - || b2->tags != 0) + || b1->tags != ZERO_TAGS + || b2->tags != ZERO_TAGS) { return false; } diff --git a/re2c/src/codegen/emit_action.cc b/re2c/src/codegen/emit_action.cc index bc42965b..a29ca408 100644 --- a/re2c/src/codegen/emit_action.cc +++ b/re2c/src/codegen/emit_action.cc @@ -319,7 +319,7 @@ void genSetState(OutputFile &o, uint32_t ind, uint32_t fillIndex) void gen_goto_case(OutputFile &o, uint32_t ind, bool &readCh, const State *to, const DFA &dfa, size_t tags) { - const bool multiline = readCh || (tags != 0); + const bool multiline = readCh || (tags != ZERO_TAGS); if (multiline) { o.ws("\n"); @@ -333,7 +333,7 @@ void gen_goto_if(OutputFile &o, uint32_t ind, bool &readCh, const State *to, const DFA &dfa, size_t tags) { const int32_t linecount = (readCh && to != NULL) - + (tags != 0) + + (tags != ZERO_TAGS) + (to != NULL); if (linecount > 1) { @@ -364,7 +364,7 @@ void gen_goto(OutputFile &o, uint32_t ind, bool &readCh, void gen_settags(OutputFile &o, uint32_t ind, const DFA &dfa, size_t tags) { - if (tags != 0) { + if (tags != ZERO_TAGS) { if (dfa.basetag) { o.wstring(opts->input_api.stmt_dist(ind, dfa.tagpool[tags], dfa.tags)); diff --git a/re2c/src/codegen/go.h b/re2c/src/codegen/go.h index 1cd15e00..defa6a18 100644 --- a/re2c/src/codegen/go.h +++ b/re2c/src/codegen/go.h @@ -6,6 +6,7 @@ #include #include "src/codegen/output.h" +#include "src/ir/tagpool.h" #include "src/util/c99_stdint.h" #include "src/util/forbid_copy.h" @@ -33,7 +34,7 @@ struct Case size_t tags; void emit(OutputFile &o, uint32_t ind) const; - inline Case(): ranges(), to(NULL), tags(0) {} + inline Case(): ranges(), to(NULL), tags(ZERO_TAGS) {} FORBID_COPY(Case); }; @@ -78,7 +79,7 @@ struct Linear const State *to; size_t tags; - Branch(): cond(NULL), to(NULL), tags(0) {} + Branch(): cond(NULL), to(NULL), tags(ZERO_TAGS) {} void init(const Cond *c, const State *s, size_t ts) { cond = c; diff --git a/re2c/src/codegen/go_construct.cc b/re2c/src/codegen/go_construct.cc index 0da2b52d..e602e5ea 100644 --- a/re2c/src/codegen/go_construct.cc +++ b/re2c/src/codegen/go_construct.cc @@ -186,7 +186,7 @@ Dot::Dot (const Span * sp, uint32_t nsp, const State * s) Go::Go () : nSpans (0) , span (NULL) - , tags (0) + , tags (ZERO_TAGS) , type (EMPTY) , info () {} @@ -213,7 +213,7 @@ void Go::init (const State * from) bool low_spans_have_tags = false; for (uint32_t i = 0; i < nSpans - hSpans; ++i) { - if (span[i].tags != 0) { + if (span[i].tags != ZERO_TAGS) { low_spans_have_tags = true; break; } diff --git a/re2c/src/ir/adfa/prepare.cc b/re2c/src/ir/adfa/prepare.cc index 92dafc2a..517568ea 100644 --- a/re2c/src/ir/adfa/prepare.cc +++ b/re2c/src/ir/adfa/prepare.cc @@ -25,7 +25,7 @@ void DFA::split(State *s) s->go.span = allocate (1); s->go.span[0].ub = ubChar; s->go.span[0].to = move; - s->go.span[0].tags = 0; + s->go.span[0].tags = ZERO_TAGS; } static uint32_t merge(Span *x, State *fg, State *bg) @@ -39,7 +39,7 @@ static uint32_t merge(Span *x, State *fg, State *bg) for (;!(f == fe && b == be);) { if (f->to == b->to && f->tags == b->tags) { x->to = bg; - x->tags = 0; + x->tags = ZERO_TAGS; } else { x->to = f->to; x->tags = f->tags; @@ -214,14 +214,14 @@ void DFA::hoist_tags() if (nsp > 0) { Span *sp = s->go.span; const size_t tags0 = sp[0].tags; - bool common_tags = tags0 != 0; + bool common_tags = tags0 != ZERO_TAGS; for (uint32_t i = 1; common_tags && i < nsp; ++i) { common_tags &= sp[i].tags == tags0; } if (common_tags) { s->go.tags = tags0; for (uint32_t i = 0; i < nsp; ++i) { - sp[i].tags = 0; + sp[i].tags = ZERO_TAGS; } } } diff --git a/re2c/src/ir/dfa/determinization.cc b/re2c/src/ir/dfa/determinization.cc index a3c7f8d5..548ac58c 100644 --- a/re2c/src/ir/dfa/determinization.cc +++ b/re2c/src/ir/dfa/determinization.cc @@ -75,7 +75,7 @@ dfa_t::dfa_t(const nfa_t &nfa, bool *mask = new bool[ntags]; bool *fin = new bool[nrules]; - clos1.push_back(clos_t(nfa.root, static_cast(0))); + clos1.push_back(clos_t(nfa.root, ZERO_TAGS)); closure(clos1, clos2, ktags, badtags, ntags); find_state(clos2, clospool, tagpool); diff --git a/re2c/src/ir/dfa/dfa.h b/re2c/src/ir/dfa/dfa.h index a0eda8d4..839df748 100644 --- a/re2c/src/ir/dfa/dfa.h +++ b/re2c/src/ir/dfa/dfa.h @@ -28,7 +28,7 @@ struct dfa_state_t : arcs(new size_t[nchars]) , tags(new size_t[nchars]) , rule(Rule::NONE) - , rule_tags(0) + , rule_tags(ZERO_TAGS) , fallback(false) {} ~dfa_state_t() diff --git a/re2c/src/ir/dfa/tag_deduplication.cc b/re2c/src/ir/dfa/tag_deduplication.cc index 9d67a19b..dbba1954 100644 --- a/re2c/src/ir/dfa/tag_deduplication.cc +++ b/re2c/src/ir/dfa/tag_deduplication.cc @@ -244,7 +244,7 @@ static void patch_tags(dfa_t &dfa, const size_t *represent) static size_t fallback_tags(const dfa_t &dfa) { const size_t nstates = dfa.states.size(); - size_t tags = 0; + size_t tags = ZERO_TAGS; for (size_t i = 0; i < nstates; ++i) { const dfa_state_t *s = dfa.states[i]; if (s->fallback) { // see note [fallback states] diff --git a/re2c/src/ir/rule.h b/re2c/src/ir/rule.h index e6fda6bd..35a3098b 100644 --- a/re2c/src/ir/rule.h +++ b/re2c/src/ir/rule.h @@ -6,6 +6,7 @@ #include #include "src/ir/tag.h" +#include "src/ir/tagpool.h" #include "src/parse/code.h" #include "src/parse/loc.h" #include "src/util/forbid_copy.h" @@ -46,7 +47,7 @@ struct Rule , ltag(0) , htag(0) , trail(Tag::NONE) - , tags(0) + , tags(ZERO_TAGS) , shadow() {} diff --git a/re2c/src/ir/tagpool.cc b/re2c/src/ir/tagpool.cc index fbebe8c6..0f05fe9f 100644 --- a/re2c/src/ir/tagpool.cc +++ b/re2c/src/ir/tagpool.cc @@ -1,3 +1,5 @@ +#include + #include "src/ir/tagpool.h" #include "src/util/hash32.h" @@ -9,8 +11,8 @@ Tagpool::Tagpool(size_t n) , lookup() , buff(new bool[ntags]()) { - // all-no tag set must have number 0 - insert(buff); + // all-zero tag configuration must have static number zero + assert(ZERO_TAGS == insert(buff)); } Tagpool::~Tagpool() @@ -47,7 +49,7 @@ size_t Tagpool::orl(size_t t, size_t o) { if (t == o || o == 0) { return t; - } else if (t == 0) { + } else if (t == ZERO_TAGS) { return o; } @@ -63,8 +65,8 @@ size_t Tagpool::andl(size_t t, size_t a) { if (t == a) { return t; - } else if (t == 0 || a == 0) { - return 0; + } else if (t == ZERO_TAGS || a == ZERO_TAGS) { + return ZERO_TAGS; } const bool *tags = operator[](t); @@ -77,10 +79,10 @@ size_t Tagpool::andl(size_t t, size_t a) size_t Tagpool::andlinv(size_t t, size_t a) { - if (a == 0) { + if (a == ZERO_TAGS) { return t; - } else if (t == 0 || t == a) { - return 0; + } else if (t == ZERO_TAGS || t == a) { + return ZERO_TAGS; } const bool *tags = operator[](t); diff --git a/re2c/src/ir/tagpool.h b/re2c/src/ir/tagpool.h index 2dd12b9b..b3ef37d0 100644 --- a/re2c/src/ir/tagpool.h +++ b/re2c/src/ir/tagpool.h @@ -10,6 +10,8 @@ namespace re2c { +static const size_t ZERO_TAGS = 0; + struct eqtag_t { size_t ntags;