]> granicus.if.org Git - re2c/commitdiff
- Replace switch(yyaccept) with if expression when there is only one case
authorhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sat, 8 Apr 2006 16:39:48 +0000 (16:39 +0000)
committerhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sat, 8 Apr 2006 16:39:48 +0000 (16:39 +0000)
16 files changed:
code.cc
test/bug1163046.c
test/bug1187785.c
test/bug1297658.c
test/bug1390174.c
test/cvsignore.b.c
test/cvsignore.c
test/cvsignore.s.c
test/cvsignore.w.c
test/cvsignore.wb.c
test/input1.c
test/input11.b.c
test/input11.c
test/input11.s.c
test/sample.c
test/scanner.c

diff --git a/code.cc b/code.cc
index e40525dde9fb688f8f6685d51f364ce1379f3e74..0a5e27be6850e14058a01094f823b4cc54c7f386 100644 (file)
--- a/code.cc
+++ b/code.cc
@@ -433,8 +433,18 @@ Accept::Accept(State *x, uint n, uint *s, State **r)
 void Accept::emit(std::ostream &o, uint ind, bool &readCh) const
 {
        bool first = true;
+       uint cases = 0;
 
        for (uint i = 0; i < nRules; ++i)
+       {
+               if (saves[i] != ~0u)
+               {
+                       cases++;
+               }
+       }
+
+       for (uint i = 0; i < nRules; ++i)
+       {
                if (saves[i] != ~0u)
                {
                        if (first)
@@ -442,15 +452,31 @@ void Accept::emit(std::ostream &o, uint ind, bool &readCh) const
                                first = false;
                                bUsedYYAccept = true;
                                o << indent(ind) << "YYCURSOR = YYMARKER;\n";
-                               o << indent(ind) << "switch(yyaccept){\n";
+                               if (cases > 1)
+                               {
+                                       o << indent(ind) << "switch(yyaccept){\n";
+                               }
                        }
 
-                       o << indent(ind) << "case " << saves[i] << ":";
-                       genGoTo(o, 1, state, rules[i], readCh);
+                       if (cases > 1)
+                       {
+                               o << indent(ind) << "case " << saves[i] << ":";
+                               genGoTo(o, 1, state, rules[i], readCh);
+                       }
+                       else
+                       {
+                               o << indent(ind) << "if (yyaccept == " << saves[i] << ") {\n";
+                               genGoTo(o, ++ind, state, rules[i], readCh);
+                       }
                }
+       }
 
        if (!first)
        {
+               if (cases == 1)
+               {
+                       ind--;
+               }
                o << indent(ind) << "}\n";
        }
 }
index 5eb541b642424c6b718d421de0de0e9654395f07..658417f81f3ad3fb488bc82e4c2374895a30c01c 100755 (executable)
@@ -57,8 +57,8 @@ yy7:
        }
 yy8:
        YYCURSOR = YYMARKER;
-       switch(yyaccept){
-       case 0: goto yy3;
+       if (yyaccept == 0) {
+               goto yy3;
        }
 yy9:
        yych = *++YYCURSOR;
index bc1639c0d7124e9d1004d20d08143a19e5e77dab..6c9377c270932ec639c9fe7123eb8b4d88be134b 100755 (executable)
@@ -562,8 +562,8 @@ yy5:
        }
 yy7:
        YYCURSOR = YYMARKER;
-       switch(yyaccept){
-       case 0: goto yy3;
+       if (yyaccept == 0) {
+               goto yy3;
        }
 yy8:
        ++YYCURSOR;
index 7fda0fed58a9ca88a830647e2e029a8d9b28e03e..3da905e8cfcd21630643bfd83e9ee13aa8c11656 100644 (file)
@@ -136,8 +136,8 @@ yy12:
        }
 yy14:
        YYCURSOR = YYMARKER;
-       switch(yyaccept){
-       case 0: goto yy3;
+       if (yyaccept == 0) {
+               goto yy3;
        }
 yy15:
        ++YYCURSOR;
index 07810627eb0cf191c2c2b8638dac269f7b24f6e2..121a7830ca9d79a083fb339d4cd0d28605d6ae88 100755 (executable)
@@ -65,8 +65,8 @@ yy8:
        }
 yy10:
        YYCURSOR = YYMARKER;
-       switch(yyaccept){
-       case 0: goto yy3;
+       if (yyaccept == 0) {
+               goto yy3;
        }
 }
 #line 20 "bug1390174.re"
index fe0d91c357430f0d425f522e6be040c10052b255..2754312d772c8d360ca8ee6f6a96b2411b09ee74 100755 (executable)
@@ -104,8 +104,8 @@ yy5:
                if(yych == 'o') goto yy44;
 yy6:
                YYCURSOR = YYMARKER;
-               switch(yyaccept){
-               case 0: goto yy3;
+               if (yyaccept == 0) {
+                       goto yy3;
                }
 yy7:
                yych = *++YYCURSOR;
index 76a41d58be609e6c3cecdedcd212d01563b716ee..fd4309bdfcab76bd55dd0ff6e37e5767a89c7f0f 100755 (executable)
@@ -76,8 +76,8 @@ yy5:
        }
 yy6:
        YYCURSOR = YYMARKER;
-       switch(yyaccept){
-       case 0: goto yy3;
+       if (yyaccept == 0) {
+               goto yy3;
        }
 yy7:
        yych = *++YYCURSOR;
index dcb168e4762f62a5956436ee7588432911295cc9..85b69699f837c0c94885e643ef9b17c9050bbda8 100755 (executable)
@@ -69,8 +69,8 @@ yy5:
        if(yych == 'o') goto yy44;
 yy6:
        YYCURSOR = YYMARKER;
-       switch(yyaccept){
-       case 0: goto yy3;
+       if (yyaccept == 0) {
+               goto yy3;
        }
 yy7:
        yych = *++YYCURSOR;
index 56d8b060d5d3d669fefbf00d0ea92edf15466cb6..e61e60e03011f24d253ed6586105ee5d700a617d 100755 (executable)
@@ -69,8 +69,8 @@ yy5:
        if(yych == 'o') goto yy44;
 yy6:
        YYCURSOR = YYMARKER;
-       switch(yyaccept){
-       case 0: goto yy3;
+       if (yyaccept == 0) {
+               goto yy3;
        }
 yy7:
        yych = *++YYCURSOR;
index eb352d89c401c217b1d2952221c1f3452307a58a..557f83b0d0d3cd66029d248231811159d2e700f3 100755 (executable)
@@ -104,8 +104,8 @@ yy5:
                if(yych == 'o') goto yy44;
 yy6:
                YYCURSOR = YYMARKER;
-               switch(yyaccept){
-               case 0: goto yy3;
+               if (yyaccept == 0) {
+                       goto yy3;
                }
 yy7:
                yych = *++YYCURSOR;
index e0dac0dc43194cf97524e2f4a7b75b46c5167821..f43b3fb9672c73be0ae2769345d6e0666be94c2d 100644 (file)
@@ -37,8 +37,8 @@ yy5:
        }
 yy7:
        YYCURSOR = YYMARKER;
-       switch(yyaccept){
-       case 0: goto yy3;
+       if (yyaccept == 0) {
+               goto yy3;
        }
 yy8:
        yych = *++YYCURSOR;
index 63af3e41a7211b85a6043ad05092fb7a7d1a4271..be68053a0ecbcf6b748d3855d69662372c571a26 100755 (executable)
@@ -130,8 +130,8 @@ yy15:
                }
 yy19:
                YYCURSOR = YYMARKER;
-               switch(yyaccept){
-               case 0: goto yy3;
+               if (yyaccept == 0) {
+                       goto yy3;
                }
 yy20:
                ++YYCURSOR;
index b183e8838971bc8fdd3b2ef322ac92cb5281d4a4..3058942e0ad63feee3a119071399d2ce8f233d7a 100755 (executable)
@@ -284,8 +284,8 @@ yy18:
        }
 yy19:
        YYCURSOR = YYMARKER;
-       switch(yyaccept){
-       case 0: goto yy3;
+       if (yyaccept == 0) {
+               goto yy3;
        }
 yy20:
        ++YYCURSOR;
index 64c80d1bbc2bda80a940eed7b86e4b79d69115d3..b51ba88b969317aa606925a386969f35d08f015a 100755 (executable)
@@ -100,8 +100,8 @@ yy15:
        }
 yy19:
        YYCURSOR = YYMARKER;
-       switch(yyaccept){
-       case 0: goto yy3;
+       if (yyaccept == 0) {
+               goto yy3;
        }
 yy20:
        ++YYCURSOR;
index e06f8c56f12b813bd6b15cece3b28e06ac930891..6303839256927ac04dafce50a8ae229413cad0ef 100644 (file)
@@ -120,8 +120,8 @@ yy12:
        }
 yy13:
        YYCURSOR = YYMARKER;
-       switch(yyaccept){
-       case 0: goto yy6;
+       if (yyaccept == 0) {
+               goto yy6;
        }
 yy14:
        ++YYCURSOR;
index 24c80abb954b2e12ac30265ae206dd414f74c5cb..57d83b931e924e41c273b2019cb3949b259c8ac5 100644 (file)
@@ -117,8 +117,8 @@ yy7:
        }
 yy8:
        YYCURSOR = YYMARKER;
-       switch(yyaccept){
-       case 0: goto yy3;
+       if (yyaccept == 0) {
+               goto yy3;
        }
 yy9:
        yych = *++YYCURSOR;
@@ -679,8 +679,8 @@ yy87:
        }
 yy88:
        YYCURSOR = YYMARKER;
-       switch(yyaccept){
-       case 0: goto yy83;
+       if (yyaccept == 0) {
+               goto yy83;
        }
 yy89:
        ++YYCURSOR;