From 93d7b98f2c35d2455c75b4bb6322228bb9cea108 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Wed, 8 May 2019 10:54:00 +0100 Subject: [PATCH] Make unreachable rule analysis conditional to further sppedup closure pruning. --- src/dfa/closure.cc | 16 +++++++++------- src/msg/warn.cc | 5 +++++ src/msg/warn.h | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/dfa/closure.cc b/src/dfa/closure.cc index a5082a0c..c3b7ba51 100644 --- a/src/dfa/closure.cc +++ b/src/dfa/closure.cc @@ -132,8 +132,8 @@ template void prune(ctx_t &ctx) { // Filter out configurations which states have transitions on symbols. - // If any configurations with final state, pick one with the lowest rule. - // See note [at most one final item per closure]. + // If we have any configurations with final state, pick the one with + // the lowest rule. See note [at most one final item per closure]. closure_t &closure = ctx.state, &buffer = ctx.reach; clositer_t b = closure.begin(), e = closure.end(), i, f = e; @@ -154,11 +154,13 @@ void prune(ctx_t &ctx) buffer.push_back(*f); // mark dropped rules as shadowed - std::valarray &rules = ctx.nfa.rules; - const uint32_t l = rules[f->state->rule].code->loc.line; - for (i = b; i != e; ++i) { - if (i != f && i->state->type == nfa_state_t::FIN) { - rules[i->state->rule].shadow.insert(l); + if (ctx.dc_msg.warn.is_set(Warn::UNREACHABLE_RULES)) { + std::valarray &rules = ctx.nfa.rules; + const uint32_t l = rules[f->state->rule].code->loc.line; + for (i = b; i != e; ++i) { + if (i != f && i->state->type == nfa_state_t::FIN) { + rules[i->state->rule].shadow.insert(l); + } } } } diff --git a/src/msg/warn.cc b/src/msg/warn.cc index 1fb8a51d..83d02105 100644 --- a/src/msg/warn.cc +++ b/src/msg/warn.cc @@ -75,6 +75,11 @@ void Warn::set_all_error () } } +bool Warn::is_set(type_t t) const +{ + return mask[t] > 0; +} + void Warn::fail(type_t t, const loc_t &loc, const char *s) const { if (mask[t] & WARNING) { diff --git a/src/msg/warn.h b/src/msg/warn.h index 2168b0c4..949bdeb2 100644 --- a/src/msg/warn.h +++ b/src/msg/warn.h @@ -59,6 +59,7 @@ public: void set (type_t t, option_t o); void set_all (); void set_all_error (); + bool is_set(type_t t) const; void fail(type_t t, const loc_t &loc, const char *s) const; void condition_order(const loc_t &loc); -- 2.50.1