]> granicus.if.org Git - re2c/commitdiff
- Use nested if's for -bf
authorhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 6 May 2007 21:21:55 +0000 (21:21 +0000)
committerhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 6 May 2007 21:21:55 +0000 (21:21 +0000)
re2c/bootstrap/scanner.cc
re2c/code.cc
re2c/re.h
re2c/scanner.re
re2c/test/condition_08.cbif.c
re2c/test/condition_09.cbif.c
re2c/test/push.fb.c

index 2173e8053f3f374fd015823b0fcd6eac1dc38f68..2bb3d6d98764eab76f8845c512a31837b5c68a8f 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.13.0.dev on Sun May  6 21:32:27 2007 */
+/* Generated by re2c 0.13.0.dev on Sun May  6 23:11:01 2007 */
 #line 1 "scanner.re"
 /* $Id$ */
 #include <stdlib.h>
@@ -316,7 +316,7 @@ yy35:
 #line 134 "scanner.re"
        {
                                        tok = pos = cursor;
-                                       genGetState(out, topIndent, 0);
+                                       genGetStateGoto(out, topIndent, 0);
                                        ignore_eoc = true;
                                        goto echo;
                                }
index ea147f7774081c0e9164ed9383705aec7fcfbf61..4a05b45442f4c53bfd8beef3b38c5684d70ac82e 100644 (file)
@@ -68,15 +68,27 @@ static void genYYFill(std::ostream &o, uint ind, uint need)
        }
 }
 
-static void genGetCondition(std::ostream &o)
+static std::string genGetState()
+{
+       if (bUseYYGetStateNaked)
+       {
+               return mapCodeName["YYGETSTATE"];
+       }
+       else
+       {
+               return mapCodeName["YYGETSTATE"] + "()";
+       }
+}
+
+static std::string genGetCondition()
 {
        if (bUseYYGetConditionNaked)
        {
-               o << mapCodeName["YYGETCONDITION"];
+               return mapCodeName["YYGETCONDITION"];
        }
        else
        {
-               o << mapCodeName["YYGETCONDITION"] << "()";
+               return mapCodeName["YYGETCONDITION"] + "()";
        }
 }
 
@@ -1664,7 +1676,7 @@ void DFA::emit(std::ostream &o, uint& ind, const RegExpMap* specMap, const std::
        if (bProlog)
        {
                genCondTable(o, ind, *specMap);
-               genGetState(o, ind, start_label);
+               genGetStateGoto(o, ind, start_label);
                if (cFlag)
                {
                        if (vUsedLabels.count(start_label))
@@ -1732,7 +1744,32 @@ void DFA::emit(std::ostream &o, uint& ind, const RegExpMap* specMap, const std::
        bUseStartLabel = false;
 }
 
-void genGetState(std::ostream &o, uint& ind, uint start_label)
+void genGetStateGotoSub(std::ostream &o, uint ind, uint start_label, int cMin, int cMax)
+{
+       if (cMin == cMax)
+       {
+               if (cMin == -1)
+               {
+                       o << indent(ind) << "goto " << labelPrefix << start_label << ";\n";
+               }
+               else
+               {
+                       o << indent(ind) << "goto " << mapCodeName["yyFillLabel"] << cMin << ";\n";
+               }
+       }
+       else
+       {
+               int cMid = cMin + ((cMax - cMin + 1) / 2);
+
+               o << indent(ind) << "if (" << genGetState() << " < " << cMid << ") {\n";
+               genGetStateGotoSub(o, ind + 1, start_label, cMin, cMid - 1);
+               o << indent(ind) << "} else {\n";
+               genGetStateGotoSub(o, ind + 1, start_label, cMid, cMax);
+               o << indent(ind) << "}\n";
+       }
+}
+
+void genGetStateGoto(std::ostream &o, uint& ind, uint start_label)
 {
        if (fFlag && !bWroteGetState)
        {
@@ -1749,11 +1786,7 @@ void genGetState(std::ostream &o, uint& ind, uint start_label)
                        o << indent(--ind) << "};\n";
                        o << "\n";
 
-                       o << indent(ind) << "if(" << mapCodeName["YYGETSTATE"];
-                       if (!bUseYYGetStateNaked)
-                       {
-                               o << "()";
-                       }
+                       o << indent(ind) << "if(" << genGetState();
                        if (bUseStateAbort)
                        {
                                o << " == -1) {";
@@ -1766,31 +1799,24 @@ void genGetState(std::ostream &o, uint& ind, uint start_label)
                        o << " goto " << labelPrefix << start_label << ";\n";
                        if (bUseStateAbort)
                        {
-                               o << indent(--ind) << "} else if (" << mapCodeName["YYGETSTATE"];
-                               if (!bUseYYGetStateNaked)
-                               {
-                                       o << "()";
-                               }
-                               o << " < -1) {\n";
+                               o << indent(--ind) << "} else if (" << genGetState() << " < -1) {\n";
                                o << indent(++ind) << "abort();\n";
                                o << indent(--ind) << "}\n";
                        }
 
-                       o << indent(ind) << "goto *" << mapCodeName["yystable"] << "[" << mapCodeName["YYGETSTATE"];
-                       if (!bUseYYGetStateNaked)
+                       o << indent(ind) << "goto *" << mapCodeName["yystable"] << "[" << genGetState() << "];\n";
+               }
+               else if (bFlag)
+               {
+                       genGetStateGotoSub(o, ind, start_label, -1, last_fill_index-1);
+                       if (bUseStateAbort)
                        {
-                               o << "()";
+                               o << indent(ind) << "abort();\n";
                        }
-                       o << "];\n";
                }
                else
                {
-                       o << indent(ind) << "switch(" << mapCodeName["YYGETSTATE"];
-                       if (!bUseYYGetStateNaked)
-                       {
-                               o << "()";
-                       }
-                       o << ") {\n";
+                       o << indent(ind) << "switch(" << genGetState() << ") {\n";
                        if (bUseStateAbort)
                        {
                                o << indent(ind) << "default: abort();\n";
@@ -1847,9 +1873,7 @@ static void genCondGotoSub(std::ostream &o, uint ind, RegExpIndices& vCondList,
        {
                uint cMid = cMin + ((cMax - cMin + 1) / 2);
 
-               o << indent(ind) << "if (";
-               genGetCondition(o);
-               o << " < " << cMid << ") {\n";
+               o << indent(ind) << "if (" << genGetCondition() << " < " << cMid << ") {\n";
                genCondGotoSub(o, ind + 1, vCondList, cMin, cMid - 1);
                o << indent(ind) << "} else {\n";
                genCondGotoSub(o, ind + 1, vCondList, cMid, cMax);
@@ -1863,9 +1887,7 @@ void genCondGoto(std::ostream &o, uint ind, const RegExpMap& specMap)
        {
                if (gFlag)
                {
-                       o << indent(ind) << "goto *" << mapCodeName["yyctable"] << "[";
-                       genGetCondition(o);
-                       o << "];\n";
+                       o << indent(ind) << "goto *" << mapCodeName["yyctable"] << "[" << genGetCondition() << "];\n";
                }
                else
                {
@@ -1881,9 +1903,7 @@ void genCondGoto(std::ostream &o, uint ind, const RegExpMap& specMap)
                        }
                        else
                        {
-                               o << indent(ind) << "switch(";
-                               genGetCondition(o);
-                               o << ") {\n";
+                               o << indent(ind) << "switch(" << genGetCondition() << ") {\n";
        
                                for(RegExpMap::const_iterator it = specMap.begin(); it != specMap.end(); ++it)
                                {
index c6b927b6114138618b0a819a1784330643573e6e..5852cf9248fa49d4cb9980ec072ec5d272674b66 100644 (file)
--- a/re2c/re.h
+++ b/re2c/re.h
@@ -495,7 +495,7 @@ typedef std::vector<std::string>        RegExpIndices;
 typedef std::list<RuleOp*>              RuleOpList;
 
 extern void genCode(std::ostream&, uint&, RegExp*, const RegExpMap*, const std::string&, bool);
-extern void genGetState(std::ostream&, uint&, uint);
+extern void genGetStateGoto(std::ostream&, uint&, uint);
 extern void genCondTable(std::ostream&, uint, const RegExpMap&);
 extern void genCondGoto(std::ostream&, uint, const RegExpMap&);
 extern void genTypes(std::string&, uint, const RegExpMap&);
index 5e2ff816ebfbd3c071057678e9a8c585fc43b393..b2063644de1c902c4c97906b96599931c6fc3f4e 100644 (file)
@@ -133,7 +133,7 @@ echo:
                                }
        "/*!getstate:re2c" {
                                        tok = pos = cursor;
-                                       genGetState(out, topIndent, 0);
+                                       genGetStateGoto(out, topIndent, 0);
                                        ignore_eoc = true;
                                        goto echo;
                                }
index ccaae1a2b0a694d514224c58ece30b983a1fce57..d460715f48314beeccc0a31b17aa3aa5f1fbd5cd 100755 (executable)
@@ -74,12 +74,22 @@ void scan(Scanner *s)
 
                {
 
-                       switch(s->state) {
-                       default: goto yy0;
-                       case 0: goto yyFillLabel0;
-                       case 1: goto yyFillLabel1;
-                       case 2: goto yyFillLabel2;
-                       case 3: goto yyFillLabel3;
+                       if (s->state < 1) {
+                               if (s->state < 0) {
+                                       goto yy0;
+                               } else {
+                                       goto yyFillLabel0;
+                               }
+                       } else {
+                               if (s->state < 2) {
+                                       goto yyFillLabel1;
+                               } else {
+                                       if (s->state < 3) {
+                                               goto yyFillLabel2;
+                                       } else {
+                                               goto yyFillLabel3;
+                                       }
+                               }
                        }
 yy0:
                        if (s->cond < 2) {
index 93a9d4aca90ddb75c7dd8009902a9952e313c5d5..92975e872b6f870c48a09d8db3ea038dabecdbf6 100755 (executable)
@@ -78,12 +78,22 @@ void scan(Scanner *s)
 {
        s->tok = s->cur;
 
-       switch(s->state) {
-       default: goto yy0;
-       case 0: goto yyFillLabel0;
-       case 1: goto yyFillLabel1;
-       case 2: goto yyFillLabel2;
-       case 3: goto yyFillLabel3;
+       if (s->state < 1) {
+               if (s->state < 0) {
+                       goto yy0;
+               } else {
+                       goto yyFillLabel0;
+               }
+       } else {
+               if (s->state < 2) {
+                       goto yyFillLabel1;
+               } else {
+                       if (s->state < 3) {
+                               goto yyFillLabel2;
+                       } else {
+                               goto yyFillLabel3;
+                       }
+               }
        }
        for(;;)
        {
index 61f1ec667803885e9ce914ccd70883935e72d21b..062714749059cb17dd8c7d361dcbb35d59d61ef6 100755 (executable)
@@ -266,11 +266,18 @@ public:
                  0,   0,   0,   0,   0,   0,   0,   0, 
                  0,   0,   0,   0,   0,   0,   0,   0, 
        };
-       switch(YYGETSTATE()) {
-       default: goto yy0;
-       case 0: goto yyFillLabel0;
-       case 1: goto yyFillLabel1;
-       case 2: goto yyFillLabel2;
+       if (YYGETSTATE() < 1) {
+               if (YYGETSTATE() < 0) {
+                       goto yy0;
+               } else {
+                       goto yyFillLabel0;
+               }
+       } else {
+               if (YYGETSTATE() < 2) {
+                       goto yyFillLabel1;
+               } else {
+                       goto yyFillLabel2;
+               }
        }
 yy0:
        YYSETSTATE(0);
@@ -359,7 +366,7 @@ yyFillLabel0:
 yy3:
 #line 246 "push.fb.re"
        { SEND(kIdentifier);     }
-#line 363 "<stdout>"
+#line 370 "<stdout>"
 yy4:
        yych = *++YYCURSOR;
        if(yych == 'o') goto yy64;
@@ -397,62 +404,62 @@ yy12:
 yy13:
 #line 247 "push.fb.re"
        { SEND(kDecimalConstant);}
-#line 401 "<stdout>"
+#line 408 "<stdout>"
 yy14:
        ++YYCURSOR;
 #line 249 "push.fb.re"
        { SEND(kEqual);          }
-#line 406 "<stdout>"
+#line 413 "<stdout>"
 yy16:
        ++YYCURSOR;
 #line 250 "push.fb.re"
        { SEND(kLeftParen);      }
-#line 411 "<stdout>"
+#line 418 "<stdout>"
 yy18:
        ++YYCURSOR;
 #line 251 "push.fb.re"
        { SEND(kRightParen);     }
-#line 416 "<stdout>"
+#line 423 "<stdout>"
 yy20:
        ++YYCURSOR;
 #line 252 "push.fb.re"
        { SEND(kMinus);          }
-#line 421 "<stdout>"
+#line 428 "<stdout>"
 yy22:
        ++YYCURSOR;
 #line 253 "push.fb.re"
        { SEND(kPlus);           }
-#line 426 "<stdout>"
+#line 433 "<stdout>"
 yy24:
        ++YYCURSOR;
 #line 254 "push.fb.re"
        { SEND(kStar);           }
-#line 431 "<stdout>"
+#line 438 "<stdout>"
 yy26:
        ++YYCURSOR;
 #line 255 "push.fb.re"
        { SEND(kSlash);          }
-#line 436 "<stdout>"
+#line 443 "<stdout>"
 yy28:
        ++YYCURSOR;
 #line 257 "push.fb.re"
        { SKIP();                }
-#line 441 "<stdout>"
+#line 448 "<stdout>"
 yy30:
        ++YYCURSOR;
 #line 258 "push.fb.re"
        { SKIP();                }
-#line 446 "<stdout>"
+#line 453 "<stdout>"
 yy32:
        ++YYCURSOR;
 #line 259 "push.fb.re"
        { send(kEOF); return 1;  }
-#line 451 "<stdout>"
+#line 458 "<stdout>"
 yy34:
        ++YYCURSOR;
 #line 260 "push.fb.re"
        { SEND(kUnknown);        }
-#line 456 "<stdout>"
+#line 463 "<stdout>"
 yy36:
        ++YYCURSOR;
        YYSETSTATE(1);
@@ -490,7 +497,7 @@ yy40:
        }
 #line 245 "push.fb.re"
        { SEND(kReturn);         }
-#line 494 "<stdout>"
+#line 501 "<stdout>"
 yy46:
        yych = *++YYCURSOR;
        if(yych != 'i') goto yy39;
@@ -504,7 +511,7 @@ yy46:
        }
 #line 244 "push.fb.re"
        { SEND(kWhile);          }
-#line 508 "<stdout>"
+#line 515 "<stdout>"
 yy51:
        yych = *++YYCURSOR;
        if(yych != 'e') goto yy39;
@@ -518,7 +525,7 @@ yy51:
        }
 #line 243 "push.fb.re"
        { SEND(kBreak);          }
-#line 522 "<stdout>"
+#line 529 "<stdout>"
 yy56:
        yych = *++YYCURSOR;
        if(yych != 't') goto yy39;
@@ -530,7 +537,7 @@ yy56:
        }
 #line 242 "push.fb.re"
        { SEND(kGoto);           }
-#line 534 "<stdout>"
+#line 541 "<stdout>"
 yy60:
        yych = *++YYCURSOR;
        if(yych != 's') goto yy39;
@@ -542,7 +549,7 @@ yy60:
        }
 #line 241 "push.fb.re"
        { SEND(kElse);           }
-#line 546 "<stdout>"
+#line 553 "<stdout>"
 yy64:
        yych = *++YYCURSOR;
        if(yych != 'r') goto yy39;
@@ -552,7 +559,7 @@ yy64:
        }
 #line 240 "push.fb.re"
        { SEND(kFor);            }
-#line 556 "<stdout>"
+#line 563 "<stdout>"
 yy67:
        ++YYCURSOR;
        if(yybm[0+(yych = *YYCURSOR)] & 128) {
@@ -560,7 +567,7 @@ yy67:
        }
 #line 239 "push.fb.re"
        { SEND(kIf);             }
-#line 564 "<stdout>"
+#line 571 "<stdout>"
 }
 #line 261 "push.fb.re"