]> granicus.if.org Git - re2c/commitdiff
Fixed bug #145 "Values for enum YYCONDTYPE are not generated
authorUlya Trofimovich <skvadrik@gmail.com>
Fri, 24 Jun 2016 21:46:16 +0000 (22:46 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Fri, 24 Jun 2016 21:46:16 +0000 (22:46 +0100)
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
re2c/bootstrap/src/parse/parser.cc
re2c/src/parse/parser.ypp
re2c/test/bug145.ci.c [new file with mode: 0644]
re2c/test/bug145.ci.re [new file with mode: 0644]
re2c/test/default_dup_star_1.ic.c
re2c/test/reuse_conds_default_1.cgir--skeleton.c
re2c/test/reuse_conds_default_1.cgir.c

index 0033c1ab42c370c571edac3b5a0f8d15773c1550..2740a37dae977e7e10ae8714973fc863e597a39f 100644 (file)
@@ -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 <stddef.h>
index 8a795325b4c956d41f023f98736fba28515aef9e..4d58acadae7adbe02e19ae3f9d25fed4858df3fa 100644 (file)
@@ -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
 
index 76540ecc06d3a2f2c3aeff62963bd61f76431d51..d1877280a2cabe06507e2a039cbb5567697dc094 100644 (file)
@@ -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 (file)
index 0000000..2be9c75
--- /dev/null
@@ -0,0 +1,60 @@
+/* Generated by re2c */
+#include <stdio.h>
+
+
+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 (file)
index 0000000..9cf0793
--- /dev/null
@@ -0,0 +1,32 @@
+#include <stdio.h>
+
+/*!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; }
+        <init>* { return 0; }
+        <init>"A" :=> C2
+        <C2>* { return 0; }
+        <C2>"B" { return 1; }
+    */
+}
+
+int main()
+{
+    printf("%d\n", test("AB"));
+    return 0;
+}
index 940756bfd245355edec74c73aed6501d93fb9b4f..e6718c957f056ba25766b1ef1393a9cbf958e04b 100644 (file)
@@ -3,6 +3,8 @@
 {
        YYCTYPE yych;
        switch (YYGETCONDITION()) {
+       case yycc1: goto yyc_c1;
+       case yycc2: goto yyc_c2;
        case yycc3: goto yyc_c3;
        }
 /* *********************************** */
index 6230086d890767e82b5455d9a6755de55509df00..6968f899492c9adf4d94cc893a680cf4e1320f71 100644 (file)
@@ -49,6 +49,7 @@ error:
 }
 
 enum YYCONDTYPE {
+    yycr1,
     yycr2,
 };
 
index ee35adf2ebeaa84cc2d4aeec7f6a9b85c7501d7a..5107fc74b2510602765df1c618553a6da7fbfb22 100644 (file)
@@ -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()];