From 66e62fa8cf93b097bd05d6636ebeb9120751a159 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Tue, 10 May 2016 15:17:51 +0100 Subject: [PATCH] Added tests for bug #121 "trailing contexts are fundamentally broken". --- re2c/test/tags/bug121_fix.i--input(custom).c | 58 +++++++++++++++ re2c/test/tags/bug121_fix.i--input(custom).re | 11 +++ re2c/test/tags/bug121_fix.i.c | 47 ++++++++++++ re2c/test/tags/bug121_fix.i.re | 8 +++ .../bug121_var_multiple.i--input(custom).c | 71 +++++++++++++++++++ .../bug121_var_multiple.i--input(custom).re | 8 +++ re2c/test/tags/bug121_var_multiple.i.c | 68 ++++++++++++++++++ re2c/test/tags/bug121_var_multiple.i.re | 8 +++ ...c => bug121_var_single.i--input(custom).c} | 11 ++- .../bug121_var_single.i--input(custom).re | 10 +++ .../{overlap.i.c => bug121_var_single.i.c} | 11 ++- re2c/test/tags/bug121_var_single.i.re | 10 +++ re2c/test/tags/overlap.i--input(custom).re | 5 -- re2c/test/tags/overlap.i.re | 5 -- 14 files changed, 315 insertions(+), 16 deletions(-) create mode 100644 re2c/test/tags/bug121_fix.i--input(custom).c create mode 100644 re2c/test/tags/bug121_fix.i--input(custom).re create mode 100644 re2c/test/tags/bug121_fix.i.c create mode 100644 re2c/test/tags/bug121_fix.i.re create mode 100644 re2c/test/tags/bug121_var_multiple.i--input(custom).c create mode 100644 re2c/test/tags/bug121_var_multiple.i--input(custom).re create mode 100644 re2c/test/tags/bug121_var_multiple.i.c create mode 100644 re2c/test/tags/bug121_var_multiple.i.re rename re2c/test/tags/{overlap.i--input(custom).c => bug121_var_single.i--input(custom).c} (76%) create mode 100644 re2c/test/tags/bug121_var_single.i--input(custom).re rename re2c/test/tags/{overlap.i.c => bug121_var_single.i.c} (77%) create mode 100644 re2c/test/tags/bug121_var_single.i.re delete mode 100644 re2c/test/tags/overlap.i--input(custom).re delete mode 100644 re2c/test/tags/overlap.i.re diff --git a/re2c/test/tags/bug121_fix.i--input(custom).c b/re2c/test/tags/bug121_fix.i--input(custom).c new file mode 100644 index 00000000..fd31bb1e --- /dev/null +++ b/re2c/test/tags/bug121_fix.i--input(custom).c @@ -0,0 +1,58 @@ +/* Generated by re2c */ +// overlapping trailing contexts of fixed length: +// because of generic API we cannot take advantage of +// fixed length and have to use multiple tags, which +// further are deduplicated and we end up with single +// tag + + +{ + YYCTYPE yych; + if (YYLESSTHAN (4)) YYFILL(4); + yych = YYPEEK (); + switch (yych) { + case 'a': goto yy4; + default: goto yy2; + } +yy2: + YYSKIP (); +yy3: + { d } +yy4: + YYSKIP (); + yych = YYPEEK (); + switch (yych) { + case 'b': + YYBACKUPCTX (); + goto yy5; + default: goto yy3; + } +yy5: + YYSKIP (); + YYBACKUP (); + yych = YYPEEK (); + switch (yych) { + case 'b': goto yy7; + default: goto yy6; + } +yy6: + YYRESTORECTX (); + { 1 } +yy7: + YYSKIP (); + yych = YYPEEK (); + switch (yych) { + case 'c': + YYBACKUPCTX (); + goto yy9; + default: goto yy8; + } +yy8: + YYRESTORE (); + goto yy6; +yy9: + YYSKIP (); + YYRESTORECTX (); + { 0 } +} + diff --git a/re2c/test/tags/bug121_fix.i--input(custom).re b/re2c/test/tags/bug121_fix.i--input(custom).re new file mode 100644 index 00000000..822349eb --- /dev/null +++ b/re2c/test/tags/bug121_fix.i--input(custom).re @@ -0,0 +1,11 @@ +// overlapping trailing contexts of fixed length: +// because of generic API we cannot take advantage of +// fixed length and have to use multiple tags, which +// further are deduplicated and we end up with single +// tag + +/*!re2c + "abb" / "c" { 0 } + "a" / "b" { 1 } + * { d } +*/ diff --git a/re2c/test/tags/bug121_fix.i.c b/re2c/test/tags/bug121_fix.i.c new file mode 100644 index 00000000..13f3d33e --- /dev/null +++ b/re2c/test/tags/bug121_fix.i.c @@ -0,0 +1,47 @@ +/* Generated by re2c */ +// overlapping trailing contexts of fixed length: +// we don't need any tags at all + + +{ + YYCTYPE yych; + if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4); + yych = *YYCURSOR; + switch (yych) { + case 'a': goto yy4; + default: goto yy2; + } +yy2: + ++YYCURSOR; +yy3: + { d } +yy4: + yych = *++YYCURSOR; + switch (yych) { + case 'b': goto yy5; + default: goto yy3; + } +yy5: + yych = *(YYMARKER = ++YYCURSOR); + switch (yych) { + case 'b': goto yy7; + default: goto yy6; + } +yy6: + YYCURSOR -= 1; + { 1 } +yy7: + yych = *++YYCURSOR; + switch (yych) { + case 'c': goto yy9; + default: goto yy8; + } +yy8: + YYCURSOR = YYMARKER; + goto yy6; +yy9: + ++YYCURSOR; + YYCURSOR -= 1; + { 0 } +} + diff --git a/re2c/test/tags/bug121_fix.i.re b/re2c/test/tags/bug121_fix.i.re new file mode 100644 index 00000000..1d455e43 --- /dev/null +++ b/re2c/test/tags/bug121_fix.i.re @@ -0,0 +1,8 @@ +// overlapping trailing contexts of fixed length: +// we don't need any tags at all + +/*!re2c + "abb" / "c" { 0 } + "a" / "b" { 1 } + * { d } +*/ diff --git a/re2c/test/tags/bug121_var_multiple.i--input(custom).c b/re2c/test/tags/bug121_var_multiple.i--input(custom).c new file mode 100644 index 00000000..2189a3b1 --- /dev/null +++ b/re2c/test/tags/bug121_var_multiple.i--input(custom).c @@ -0,0 +1,71 @@ +/* Generated by re2c */ +// overlapping trailing contexts of variable length: +// we need multiple tags and we cannot deduplicate them + + +{ + YYCTYPE yych; + long yytag0; + long yytag1; + YYBACKUPCTX (); + if (YYLESSTHAN (4)) YYFILL(4); + yych = YYPEEK (); + switch (yych) { + case 'a': goto yy4; + default: goto yy2; + } +yy2: + YYSKIP (); + { d } +yy4: + YYSKIP (); + yytag1 = YYDIST(); + switch ((yych = YYPEEK ())) { + case 'b': goto yy6; + default: goto yy5; + } +yy5: + YYRESTORECTX (yytag1); + { 1 } +yy6: + YYSKIP (); + YYBACKUP (); + yych = YYPEEK (); + switch (yych) { + case 'c': + yytag0 = YYDIST(); + goto yy9; + default: goto yy8; + } +yy7: + YYSKIP (); + if (YYLESSTHAN (1)) YYFILL(1); + yych = YYPEEK (); +yy8: + switch (yych) { + case 'b': goto yy7; + default: goto yy5; + } +yy9: + YYSKIP (); + yych = YYPEEK (); + switch (yych) { + case 'c': goto yy11; + default: goto yy10; + } +yy10: + YYRESTORE (); + goto yy5; +yy11: + YYSKIP (); + if (YYLESSTHAN (1)) YYFILL(1); + yych = YYPEEK (); + switch (yych) { + case 'c': goto yy11; + default: goto yy13; + } +yy13: + YYRESTORECTX (yytag0); + { 0 } +} + diff --git a/re2c/test/tags/bug121_var_multiple.i--input(custom).re b/re2c/test/tags/bug121_var_multiple.i--input(custom).re new file mode 100644 index 00000000..b661c89e --- /dev/null +++ b/re2c/test/tags/bug121_var_multiple.i--input(custom).re @@ -0,0 +1,8 @@ +// overlapping trailing contexts of variable length: +// we need multiple tags and we cannot deduplicate them + +/*!re2c + "ab" / "c"{2,} { 0 } + "a" / "b"* { 1 } + * { d } +*/ diff --git a/re2c/test/tags/bug121_var_multiple.i.c b/re2c/test/tags/bug121_var_multiple.i.c new file mode 100644 index 00000000..74903c14 --- /dev/null +++ b/re2c/test/tags/bug121_var_multiple.i.c @@ -0,0 +1,68 @@ +/* Generated by re2c */ +// overlapping trailing contexts of variable length: +// we need multiple tags and we cannot deduplicate them + + +{ + YYCTYPE yych; + long yytag0; + long yytag1; + YYCTXMARKER = YYCURSOR; + if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4); + yych = *YYCURSOR; + switch (yych) { + case 'a': goto yy4; + default: goto yy2; + } +yy2: + ++YYCURSOR; + { d } +yy4: + ++YYCURSOR; + yytag1 = (YYCURSOR - YYCTXMARKER); + switch ((yych = *YYCURSOR)) { + case 'b': goto yy6; + default: goto yy5; + } +yy5: + YYCURSOR = YYCTXMARKER + yytag1; + { 1 } +yy6: + yych = *(YYMARKER = ++YYCURSOR); + switch (yych) { + case 'c': + yytag0 = (YYCURSOR - YYCTXMARKER); + goto yy9; + default: goto yy8; + } +yy7: + ++YYCURSOR; + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy8: + switch (yych) { + case 'b': goto yy7; + default: goto yy5; + } +yy9: + yych = *++YYCURSOR; + switch (yych) { + case 'c': goto yy11; + default: goto yy10; + } +yy10: + YYCURSOR = YYMARKER; + goto yy5; +yy11: + ++YYCURSOR; + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch (yych) { + case 'c': goto yy11; + default: goto yy13; + } +yy13: + YYCURSOR = YYCTXMARKER + yytag0; + { 0 } +} + diff --git a/re2c/test/tags/bug121_var_multiple.i.re b/re2c/test/tags/bug121_var_multiple.i.re new file mode 100644 index 00000000..b661c89e --- /dev/null +++ b/re2c/test/tags/bug121_var_multiple.i.re @@ -0,0 +1,8 @@ +// overlapping trailing contexts of variable length: +// we need multiple tags and we cannot deduplicate them + +/*!re2c + "ab" / "c"{2,} { 0 } + "a" / "b"* { 1 } + * { d } +*/ diff --git a/re2c/test/tags/overlap.i--input(custom).c b/re2c/test/tags/bug121_var_single.i--input(custom).c similarity index 76% rename from re2c/test/tags/overlap.i--input(custom).c rename to re2c/test/tags/bug121_var_single.i--input(custom).c index bb596524..fbcb38aa 100644 --- a/re2c/test/tags/overlap.i--input(custom).c +++ b/re2c/test/tags/bug121_var_single.i--input(custom).c @@ -1,4 +1,9 @@ /* Generated by re2c */ +// overlapping trailing contexts of variable length: +// in principle, we need multiple tags here, but in this +// particular case all tags can be implemented using sinle +// variable (due to tag deduplication) + { YYCTYPE yych; @@ -10,7 +15,7 @@ } yy2: YYSKIP (); - {} + { d } yy4: YYSKIP (); YYBACKUPCTX (); @@ -20,7 +25,7 @@ yy4: } yy5: YYRESTORECTX (); - {} + { 1 } yy6: YYSKIP (); switch ((yych = YYPEEK ())) { @@ -34,7 +39,7 @@ yy6: } yy7: YYRESTORECTX (); - {} + { 0 } yy8: YYSKIP (); if (YYLESSTHAN (1)) YYFILL(1); diff --git a/re2c/test/tags/bug121_var_single.i--input(custom).re b/re2c/test/tags/bug121_var_single.i--input(custom).re new file mode 100644 index 00000000..065a337e --- /dev/null +++ b/re2c/test/tags/bug121_var_single.i--input(custom).re @@ -0,0 +1,10 @@ +// overlapping trailing contexts of variable length: +// in principle, we need multiple tags here, but in this +// particular case all tags can be implemented using sinle +// variable (due to tag deduplication) + +/*!re2c + "ab" / "c"* { 0 } + "a" / "b"* { 1 } + * { d } +*/ diff --git a/re2c/test/tags/overlap.i.c b/re2c/test/tags/bug121_var_single.i.c similarity index 77% rename from re2c/test/tags/overlap.i.c rename to re2c/test/tags/bug121_var_single.i.c index 8ae0b146..a9619bf9 100644 --- a/re2c/test/tags/overlap.i.c +++ b/re2c/test/tags/bug121_var_single.i.c @@ -1,4 +1,9 @@ /* Generated by re2c */ +// overlapping trailing contexts of variable length: +// in principle, we need multiple tags here, but in this +// particular case all tags can be implemented using sinle +// variable (due to tag deduplication) + { YYCTYPE yych; @@ -10,7 +15,7 @@ } yy2: ++YYCURSOR; - {} + { d } yy4: ++YYCURSOR; YYCTXMARKER = YYCURSOR; @@ -20,7 +25,7 @@ yy4: } yy5: YYCURSOR = YYCTXMARKER; - {} + { 1 } yy6: ++YYCURSOR; switch ((yych = *YYCURSOR)) { @@ -34,7 +39,7 @@ yy6: } yy7: YYCURSOR = YYCTXMARKER; - {} + { 0 } yy8: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); diff --git a/re2c/test/tags/bug121_var_single.i.re b/re2c/test/tags/bug121_var_single.i.re new file mode 100644 index 00000000..065a337e --- /dev/null +++ b/re2c/test/tags/bug121_var_single.i.re @@ -0,0 +1,10 @@ +// overlapping trailing contexts of variable length: +// in principle, we need multiple tags here, but in this +// particular case all tags can be implemented using sinle +// variable (due to tag deduplication) + +/*!re2c + "ab" / "c"* { 0 } + "a" / "b"* { 1 } + * { d } +*/ diff --git a/re2c/test/tags/overlap.i--input(custom).re b/re2c/test/tags/overlap.i--input(custom).re deleted file mode 100644 index 986fac74..00000000 --- a/re2c/test/tags/overlap.i--input(custom).re +++ /dev/null @@ -1,5 +0,0 @@ -/*!re2c - "ab" / "c"* {} - "a" / "b"* {} - * {} -*/ diff --git a/re2c/test/tags/overlap.i.re b/re2c/test/tags/overlap.i.re deleted file mode 100644 index 986fac74..00000000 --- a/re2c/test/tags/overlap.i.re +++ /dev/null @@ -1,5 +0,0 @@ -/*!re2c - "ab" / "c"* {} - "a" / "b"* {} - * {} -*/ -- 2.40.0