From: Ulya Trofimovich Date: Thu, 18 Jul 2019 16:16:04 +0000 (+0100) Subject: Fixed the case of missing default label which is used only by EOF checks. X-Git-Tag: 1.2~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7ecd5e8e1a12754bc0dae720c0055467fc56e7c7;p=re2c Fixed the case of missing default label which is used only by EOF checks. The current fix may sometimes cause generation of unused default label, because at the time when it's generated we haven't geerated the code for EOF checks yet and do nt know if default label is really needed. This is what happens in the updated test cases. --- diff --git a/src/adfa/adfa.h b/src/adfa/adfa.h index f50ae9b7..3cf7bc53 100644 --- a/src/adfa/adfa.h +++ b/src/adfa/adfa.h @@ -118,7 +118,7 @@ private: void findBaseState(const opt_t *opts); void hoist_tags(const opt_t *opts); void hoist_tags_and_skip(const opt_t *opts); - void count_used_labels(std::set &used, label_t start, label_t initial, bool force_start, bool fFlag) const; + void count_used_labels(std::set &used, label_t start, label_t initial, const opt_t *opts) const; void emit_body (Output &, uint32_t &, const std::set & used_labels, label_t initial) const; void emit_dot(Output &o, bool last_cond) const; diff --git a/src/codegen/emit_dfa.cc b/src/codegen/emit_dfa.cc index 85a41a2b..f977dfa0 100644 --- a/src/codegen/emit_dfa.cc +++ b/src/codegen/emit_dfa.cc @@ -56,30 +56,30 @@ void emit_eof(Output & o, uint32_t ind, const Code *code) o.wdelay_line_info_output(); } -void DFA::count_used_labels (std::set & used, label_t start, - label_t initial, bool force_start, bool fFlag) const +void DFA::count_used_labels(std::set &used, label_t start + , label_t initial, const opt_t *opts) const { // In '-f' mode, default state is always state 0 - if (fFlag) - { - used.insert (label_t::first ()); + if (opts->fFlag) { + used.insert(label_t::first()); } - if (force_start) - { - used.insert (start); + if (opts->startlabel_force && opts->startlabel.empty()) { + used.insert(start); } - for (State * s = head; s; s = s->next) - { - s->go.used_labels (used); + // FIXME: default label may be used by EOF checks, but they are generated + // later and at this point we do not know if default label is really used + if (defstate && opts->eof != NOEOF) { + used.insert(defstate->label); } - for (uint32_t i = 0; i < accepts.size (); ++i) - { - used.insert (accepts[i].first->label); + for (State * s = head; s; s = s->next) { + s->go.used_labels(used); + } + for (uint32_t i = 0; i < accepts.size(); ++i) { + used.insert(accepts[i].first->label); } // must go last: it needs the set of used labels - if (used.count (head->label)) - { - used.insert (initial); + if (used.count(head->label)) { + used.insert(initial); } } @@ -190,8 +190,7 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra s->label = output.label_counter.next (); } std::set used_labels; - count_used_labels (used_labels, start_label, initial_label, - opts->startlabel_force && opts->startlabel.empty(), opts->fFlag); + count_used_labels (used_labels, start_label, initial_label, opts); head->action.set_initial(initial_label); diff --git a/test/eof/eof_02.i.c b/test/eof/eof_02.i.c index 347a6da3..22d8c26c 100644 --- a/test/eof/eof_02.i.c +++ b/test/eof/eof_02.i.c @@ -72,6 +72,7 @@ yy1_: } yy2: ++in.cur; +yy3: { return false; } yy4: ++in.cur; diff --git a/test/eof/eof_03.i.c b/test/eof/eof_03.i.c index 3fe39c2f..75b2c4fc 100644 --- a/test/eof/eof_03.i.c +++ b/test/eof/eof_03.i.c @@ -72,6 +72,7 @@ yy1_: } yy2: ++in.cur; +yy3: { return false; } yy4: ++in.cur;