]> granicus.if.org Git - re2c/commitdiff
Skeleton: apply 'copy' commands before 'save' commands.
authorUlya Trofimovich <skvadrik@gmail.com>
Wed, 30 Nov 2016 12:37:38 +0000 (12:37 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Wed, 30 Nov 2016 12:37:38 +0000 (12:37 +0000)
This is how the generated TDFA does and how it should be done.

Found by slyfox's fuzzer. :)

re2c/src/ir/skeleton/generate_data.cc
re2c/test/tags/copy_save.i--tags.c [new file with mode: 0644]
re2c/test/tags/copy_save.i--tags.re [new file with mode: 0644]

index 204125e3a6f1a9805248a4643d6344ccbce907e5..103b98e4e93bb7c35e0246c9005baeefd8698156 100644 (file)
@@ -93,12 +93,12 @@ static uint32_t nsteps(uint32_t lower, uint32_t upper)
 static void apply(size_t *tags, const tcmd_t *cmd, size_t pos)
 {
        if (!cmd) return;
-       for (const tagsave_t *p = cmd->save; p; p = p->next) {
-               tags[p->ver] = p->bottom ? Skeleton::DEFTAG : pos;
-       }
        for (const tagcopy_t *p = cmd->copy; p; p = p->next) {
                tags[p->lhs] = tags[p->rhs];
        }
+       for (const tagsave_t *p = cmd->save; p; p = p->next) {
+               tags[p->ver] = p->bottom ? Skeleton::DEFTAG : pos;
+       }
 }
 
 static size_t path_width(const path_t &path, const Skeleton &skel)
diff --git a/re2c/test/tags/copy_save.i--tags.c b/re2c/test/tags/copy_save.i--tags.c
new file mode 100644 (file)
index 0000000..dbb5b41
--- /dev/null
@@ -0,0 +1,56 @@
+/* Generated by re2c */
+
+{
+       YYCTYPE yych;
+       if (YYLIMIT <= YYCURSOR) YYFILL(1);
+       yych = *YYCURSOR;
+       switch (yych) {
+       case 'a':
+               yyt2 = NULL;
+               yyt1 = YYCURSOR;
+               goto yy3;
+       default:
+               yyt1 = NULL;
+               goto yy2;
+       }
+yy2:
+       p = yyt1;
+       {}
+yy3:
+       ++YYCURSOR;
+       if (YYLIMIT <= YYCURSOR) YYFILL(1);
+       yych = *YYCURSOR;
+       switch (yych) {
+       case 'a':
+               yyt2 = yyt1;
+               yyt1 = YYCURSOR;
+               goto yy3;
+       case 'b':       goto yy5;
+       default:        goto yy2;
+       }
+yy5:
+       YYMARKER = ++YYCURSOR;
+       if (YYLIMIT <= YYCURSOR) YYFILL(1);
+       yych = *YYCURSOR;
+       switch (yych) {
+       case 'a':       goto yy6;
+       default:
+               yyt1 = yyt2;
+               goto yy2;
+       }
+yy6:
+       ++YYCURSOR;
+       if (YYLIMIT <= YYCURSOR) YYFILL(1);
+       yych = *YYCURSOR;
+       switch (yych) {
+       case 'b':       goto yy5;
+       default:        goto yy7;
+       }
+yy7:
+       YYCURSOR = YYMARKER;
+       yyt1 = yyt2;
+       goto yy2;
+}
+
+re2c: warning: line 3: rule matches empty string [-Wmatch-empty-string]
+re2c: warning: line 3: tag 'p' is nondeterministic [-Wnondeterministic-tags]
diff --git a/re2c/test/tags/copy_save.i--tags.re b/re2c/test/tags/copy_save.i--tags.re
new file mode 100644 (file)
index 0000000..acc3367
--- /dev/null
@@ -0,0 +1,5 @@
+/*!re2c
+
+(@p "a")* "ab"* {}
+
+*/