]> granicus.if.org Git - re2c/commitdiff
Make unreachable rule analysis conditional to further sppedup closure pruning.
authorUlya Trofimovich <skvadrik@gmail.com>
Wed, 8 May 2019 09:54:00 +0000 (10:54 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Wed, 8 May 2019 09:54:00 +0000 (10:54 +0100)
src/dfa/closure.cc
src/msg/warn.cc
src/msg/warn.h

index a5082a0ce6e881421d418c7d59e5991676721a52..c3b7ba51c8e98df4bb0f98b0dba065d8d1d70b16 100644 (file)
@@ -132,8 +132,8 @@ template<typename ctx_t>
 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<Rule> &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<Rule> &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);
+                }
             }
         }
     }
index 1fb8a51d5d80b864cde46b21faebcb2d65a20ac6..83d02105a36350f33b598e263e42cf008d2d4765 100644 (file)
@@ -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) {
index 2168b0c4d559977ac5d80aa6e8375ba4bbd449e6..949bdeb233f4316b275baa9ee183880d94d316ed 100644 (file)
@@ -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);