From: Ulya Trofimovich Date: Wed, 21 Dec 2016 11:43:22 +0000 (+0000) Subject: Don't loose condition if it consists of default rule only. X-Git-Tag: 1.0~39^2~180 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a15d55a8abcb1e915da76c10a74630ae5c92adcc;p=re2c Don't loose condition if it consists of default rule only. --- diff --git a/re2c/bootstrap/src/parse/lex.cc b/re2c/bootstrap/src/parse/lex.cc index d5a5bbe1..d4aac6e5 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 Tue Dec 20 22:40:10 2016 */ +/* Generated by re2c 0.16 on Wed Dec 21 11:41:53 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 83911476..bfda4e3f 100644 --- a/re2c/bootstrap/src/parse/parser.cc +++ b/re2c/bootstrap/src/parse/parser.cc @@ -133,6 +133,14 @@ void context_check(Scanner &in, CondList *clist) } } +static void add_cond(std::vector &names, + const std::string &name, re2c::SpecMap &specs) +{ + if (name != "*" && specs.find(name) == specs.end()) { + names.push_back(name); + } +} + void context_rule(Scanner &in, CondList *clist, const Loc &loc, RegExpRule *rule, const Code *code, const std::string *newcond) { @@ -140,9 +148,7 @@ void context_rule(Scanner &in, CondList *clist, const Loc &loc, rule->info = new RuleInfo(loc, code, newcond); for(CondList::const_iterator i = clist->begin(); i != clist->end(); ++i) { const std::string &cond = *i; - if (cond != "*" && specMap.find(cond) == specMap.end()) { - condnames.push_back(cond); - } + add_cond(condnames, cond, specMap); specMap[cond].add(rule); } delete clist; @@ -169,10 +175,12 @@ void default_rule(Scanner &in, CondList *clist, RegExpRule *rule) { context_check(in, clist); for (CondList::const_iterator i = clist->begin(); i != clist->end(); ++i) { - if (!specMap[*i].add_def(rule)) { + const std::string &cond = *i; + add_cond(condnames, cond, specMap); + if (!specMap[cond].add_def(rule)) { in.fatalf_at(rule->info->loc.line, "code to default rule '%s' is already defined", - i->c_str()); + cond.c_str()); } } delete clist; @@ -558,11 +566,11 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 165, 165, 167, 168, 169, 174, 181, 186, 189, - 193, 193, 196, 205, 216, 220, 226, 232, 242, 253, - 258, 264, 271, 272, 277, 280, 287, 291, 297, 301, - 308, 312, 319, 323, 330, 334, 351, 370, 374, 378, - 382, 389, 399, 403 + 0, 173, 173, 175, 176, 177, 182, 189, 194, 197, + 201, 201, 204, 213, 224, 228, 234, 240, 250, 261, + 266, 272, 279, 280, 285, 288, 295, 299, 305, 309, + 316, 320, 327, 331, 338, 342, 359, 378, 382, 386, + 390, 397, 407, 411 }; #endif diff --git a/re2c/src/parse/parser.ypp b/re2c/src/parse/parser.ypp index 8d949b80..5651ea6f 100644 --- a/re2c/src/parse/parser.ypp +++ b/re2c/src/parse/parser.ypp @@ -65,6 +65,14 @@ void context_check(Scanner &in, CondList *clist) } } +static void add_cond(std::vector &names, + const std::string &name, re2c::SpecMap &specs) +{ + if (name != "*" && specs.find(name) == specs.end()) { + names.push_back(name); + } +} + void context_rule(Scanner &in, CondList *clist, const Loc &loc, RegExpRule *rule, const Code *code, const std::string *newcond) { @@ -72,9 +80,7 @@ void context_rule(Scanner &in, CondList *clist, const Loc &loc, rule->info = new RuleInfo(loc, code, newcond); for(CondList::const_iterator i = clist->begin(); i != clist->end(); ++i) { const std::string &cond = *i; - if (cond != "*" && specMap.find(cond) == specMap.end()) { - condnames.push_back(cond); - } + add_cond(condnames, cond, specMap); specMap[cond].add(rule); } delete clist; @@ -101,10 +107,12 @@ void default_rule(Scanner &in, CondList *clist, RegExpRule *rule) { context_check(in, clist); for (CondList::const_iterator i = clist->begin(); i != clist->end(); ++i) { - if (!specMap[*i].add_def(rule)) { + const std::string &cond = *i; + add_cond(condnames, cond, specMap); + if (!specMap[cond].add_def(rule)) { in.fatalf_at(rule->info->loc.line, "code to default rule '%s' is already defined", - i->c_str()); + cond.c_str()); } } delete clist; diff --git a/re2c/test/default_dup_star_1.ic.c b/re2c/test/default_dup_star_1.ic.c index a9e95187..29b3418b 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.c b/re2c/test/reuse_conds_default_1.cgir.c index 2263ab34..538aa1b9 100644 --- a/re2c/test/reuse_conds_default_1.cgir.c +++ b/re2c/test/reuse_conds_default_1.cgir.c @@ -1,9 +1,6 @@ /* Generated by re2c */ -// This test currently fails with error -// 're2c: error: line 11, column 9: code to default rule 'r1' is already defined' -// This must be fixed later - enum YYCONDTYPE { + yycr1, yycr2, }; @@ -13,7 +10,8 @@ void scan(unsigned char* in) { YYCTYPE yych; - static void *yyctable[1] = { + static void *yyctable[2] = { + &&yyc_r1, &&yyc_r2, }; goto *yyctable[YYGETCONDITION()]; @@ -107,7 +105,8 @@ void scan(unsigned short* in) { YYCTYPE yych; - static void *yyctable[1] = { + static void *yyctable[2] = { + &&yyc_r1, &&yyc_r2, }; goto *yyctable[YYGETCONDITION()]; @@ -193,5 +192,5 @@ yy22: } } -re2c: warning: line 17: control flow in condition 'r2' is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow] -re2c: warning: line 32: control flow in condition 'r2' is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow] +re2c: warning: line 13: control flow in condition 'r2' is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow] +re2c: warning: line 28: control flow in condition 'r2' is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow] diff --git a/re2c/test/reuse_conds_default_1.cgir.re b/re2c/test/reuse_conds_default_1.cgir.re index 4b834c0c..7c4c4857 100644 --- a/re2c/test/reuse_conds_default_1.cgir.re +++ b/re2c/test/reuse_conds_default_1.cgir.re @@ -1,7 +1,3 @@ -// This test currently fails with error -// 're2c: error: line 11, column 9: code to default rule 'r1' is already defined' -// This must be fixed later - /*!types:re2c */ void scan(unsigned char* in)