]> granicus.if.org Git - re2c/commitdiff
Fixed tags comparison in table minimization.
authorUlya Trofimovich <skvadrik@gmail.com>
Tue, 4 Oct 2016 16:05:20 +0000 (17:05 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Tue, 4 Oct 2016 16:05:20 +0000 (17:05 +0100)
Bug was introduced in commit 5958a2366cdb1361b5158076924014a36ff19dcc
"Bind contexts (a.k.a. tags) to DFA transitions, not states.":
instead of comparing tags of single transition on one particular
symbol, we compared tags for all outgoing transitions at once
(probably copy-paste from Moore minimization).

The bug was revealed by multiple tests (including '--skeleton' ones)
as soon as I ran testsute with '--dfa-determinization table'.

re2c/src/ir/dfa/minimization.cc

index c742f7862170df7552ab513062c1487e6e5d8c35..2dcffcb6851b20b9e6a1eb9b5a4a3a7942d7f5a4 100644 (file)
@@ -67,11 +67,11 @@ static void minimization_table(
                                                {
                                                        std::swap(oi, oj);
                                                }
-                                               if (oi != oj &&
-                                                       (oi == dfa_t::NIL
-                                                       || oj == dfa_t::NIL
-                                                       || tbl[oi][oj]
-                                                       || memcmp(states[i]->tags, states[j]->tags, nchars * sizeof(size_t)) != 0))
+                                               if (states[i]->tags[k] != states[j]->tags[k]
+                                                       || (oi != oj
+                                                               && (oi == dfa_t::NIL
+                                                               || oj == dfa_t::NIL
+                                                               || tbl[oi][oj])))
                                                {
                                                        tbl[i][j] = true;
                                                        loop = true;
@@ -188,8 +188,10 @@ static void minimization_moore(
                                        if (memcmp(&out[j * nchars],
                                                &out[k * nchars],
                                                nchars * sizeof(size_t)) == 0
-                                               && memcmp(states[j]->tags, states[k]->tags, nchars * sizeof(size_t)) == 0)
-                                       {
+                                        && memcmp(states[j]->tags,
+                                               states[k]->tags,
+                                               nchars * sizeof(size_t)) == 0
+                                        ) {
                                                part[j] = k;
                                                next[j] = next[k];
                                                next[k] = j;