From d1b118187bd6a7af92cbb5906b755f743d8cf7ff Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Fri, 24 Jun 2016 22:46:16 +0100 Subject: [PATCH] Fixed bug #145 "Values for enum YYCONDTYPE are not generated when default rules with conditions are used". Default rule is handled in a special (delayed) way; re2c uses different code for default rule than for normal rules. This special code simply forgot to add condition name to the list of conditions. Thanks to sirzooro for bug report. --- re2c/bootstrap/src/parse/lex.cc | 2 +- re2c/bootstrap/src/parse/parser.cc | 14 +++-- re2c/src/parse/parser.ypp | 4 ++ re2c/test/bug145.ci.c | 60 +++++++++++++++++++ re2c/test/bug145.ci.re | 32 ++++++++++ re2c/test/default_dup_star_1.ic.c | 2 + .../reuse_conds_default_1.cgir--skeleton.c | 1 + re2c/test/reuse_conds_default_1.cgir.c | 7 ++- 8 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 re2c/test/bug145.ci.c create mode 100644 re2c/test/bug145.ci.re diff --git a/re2c/bootstrap/src/parse/lex.cc b/re2c/bootstrap/src/parse/lex.cc index 0033c1ab..2740a37d 100644 --- a/re2c/bootstrap/src/parse/lex.cc +++ b/re2c/bootstrap/src/parse/lex.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.16 on Wed May 11 15:12:59 2016 */ +/* Generated by re2c 0.16 on Fri Jun 24 22:37:48 2016 */ #line 1 "../src/parse/lex.re" #include "src/util/c99_stdint.h" #include diff --git a/re2c/bootstrap/src/parse/parser.cc b/re2c/bootstrap/src/parse/parser.cc index 8a795325..4d58acad 100644 --- a/re2c/bootstrap/src/parse/parser.cc +++ b/re2c/bootstrap/src/parse/parser.cc @@ -206,6 +206,10 @@ void default_rule(CondList *clist, const Code * code) context_check(clist); for(CondList::const_iterator it = clist->begin(); it != clist->end(); ++it) { + if (specMap.find(*it) == specMap.end()) + { + condnames.push_back (*it); + } RuleOp * def = new RuleOp ( code->loc , in->mkDefault () @@ -593,11 +597,11 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 193, 193, 195, 199, 203, 211, 219, 223, 227, - 231, 247, 264, 268, 274, 279, 285, 289, 303, 319, - 324, 330, 345, 362, 381, 387, 395, 398, 405, 411, - 421, 424, 432, 435, 442, 446, 453, 457, 464, 468, - 475, 479, 494, 513, 517, 521, 525, 532, 542, 546 + 0, 197, 197, 199, 203, 207, 215, 223, 227, 231, + 235, 251, 268, 272, 278, 283, 289, 293, 307, 323, + 328, 334, 349, 366, 385, 391, 399, 402, 409, 415, + 425, 428, 436, 439, 446, 450, 457, 461, 468, 472, + 479, 483, 498, 517, 521, 525, 529, 536, 546, 550 }; #endif diff --git a/re2c/src/parse/parser.ypp b/re2c/src/parse/parser.ypp index 76540ecc..d1877280 100644 --- a/re2c/src/parse/parser.ypp +++ b/re2c/src/parse/parser.ypp @@ -138,6 +138,10 @@ void default_rule(CondList *clist, const Code * code) context_check(clist); for(CondList::const_iterator it = clist->begin(); it != clist->end(); ++it) { + if (specMap.find(*it) == specMap.end()) + { + condnames.push_back (*it); + } RuleOp * def = new RuleOp ( code->loc , in->mkDefault () diff --git a/re2c/test/bug145.ci.c b/re2c/test/bug145.ci.c new file mode 100644 index 00000000..2be9c75a --- /dev/null +++ b/re2c/test/bug145.ci.c @@ -0,0 +1,60 @@ +/* Generated by re2c */ +#include + + +enum YYCONDTYPE { + yycinit, + yycC2, +}; + + +int test(const char* str) +{ + const unsigned char* YYCURSOR = (const unsigned char*)str; + const unsigned char* YYMARKER; + const unsigned char *YYCTXMARKER; + int c = yycinit; + + +{ + unsigned char yych; + switch (c) { + case yycinit: goto yyc_init; + case yycC2: goto yyc_C2; + } +/* *********************************** */ +yyc_C2: + yych = *YYCURSOR; + switch (yych) { + case 'B': goto yy5; + default: goto yy3; + } +yy3: + ++YYCURSOR; + { return 0; } +yy5: + ++YYCURSOR; + { return 1; } +/* *********************************** */ +yyc_init: + yych = *YYCURSOR; + switch (yych) { + case 'A': goto yy11; + default: goto yy9; + } +yy9: + ++YYCURSOR; + { return 0; } +yy11: + ++YYCURSOR; + c = yycC2; + goto yyc_C2; +} + +} + +int main() +{ + printf("%d\n", test("AB")); + return 0; +} diff --git a/re2c/test/bug145.ci.re b/re2c/test/bug145.ci.re new file mode 100644 index 00000000..9cf0793d --- /dev/null +++ b/re2c/test/bug145.ci.re @@ -0,0 +1,32 @@ +#include + +/*!types:re2c*/ + +int test(const char* str) +{ + const unsigned char* YYCURSOR = (const unsigned char*)str; + const unsigned char* YYMARKER; + const unsigned char *YYCTXMARKER; + int c = yycinit; + + /*!re2c + re2c:define:YYCTYPE = "unsigned char"; + re2c:yyfill:enable = 0; + re2c:define:YYGETCONDITION = "c"; + re2c:define:YYGETCONDITION:naked = 1; + re2c:define:YYSETCONDITION = "c = @@;"; + re2c:define:YYSETCONDITION:naked = 1; + + //<*>* { return 0; } + * { return 0; } + "A" :=> C2 + * { return 0; } + "B" { return 1; } + */ +} + +int main() +{ + printf("%d\n", test("AB")); + return 0; +} diff --git a/re2c/test/default_dup_star_1.ic.c b/re2c/test/default_dup_star_1.ic.c index 940756bf..e6718c95 100644 --- a/re2c/test/default_dup_star_1.ic.c +++ b/re2c/test/default_dup_star_1.ic.c @@ -3,6 +3,8 @@ { YYCTYPE yych; switch (YYGETCONDITION()) { + case yycc1: goto yyc_c1; + case yycc2: goto yyc_c2; case yycc3: goto yyc_c3; } /* *********************************** */ diff --git a/re2c/test/reuse_conds_default_1.cgir--skeleton.c b/re2c/test/reuse_conds_default_1.cgir--skeleton.c index 6230086d..6968f899 100644 --- a/re2c/test/reuse_conds_default_1.cgir--skeleton.c +++ b/re2c/test/reuse_conds_default_1.cgir--skeleton.c @@ -49,6 +49,7 @@ error: } enum YYCONDTYPE { + yycr1, yycr2, }; diff --git a/re2c/test/reuse_conds_default_1.cgir.c b/re2c/test/reuse_conds_default_1.cgir.c index ee35adf2..5107fc74 100644 --- a/re2c/test/reuse_conds_default_1.cgir.c +++ b/re2c/test/reuse_conds_default_1.cgir.c @@ -5,6 +5,7 @@ enum YYCONDTYPE { + yycr1, yycr2, }; @@ -14,7 +15,8 @@ void scan(unsigned char* in) { YYCTYPE yych; - static void *yyctable[1] = { + static void *yyctable[2] = { + &&yyc_r1, &&yyc_r2, }; goto *yyctable[YYGETCONDITION()]; @@ -108,7 +110,8 @@ void scan(unsigned short* in) { YYCTYPE yych; - static void *yyctable[1] = { + static void *yyctable[2] = { + &&yyc_r1, &&yyc_r2, }; goto *yyctable[YYGETCONDITION()]; -- 2.50.1