]> granicus.if.org Git - re2c/commitdiff
- Fixed #1454253 Piece of code saving a backtracking point not generated.
authorhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 9 Apr 2006 02:08:59 +0000 (02:08 +0000)
committerhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 9 Apr 2006 02:08:59 +0000 (02:08 +0000)
CHANGELOG
code.cc
dfa.h
htdocs/index.html
test/bug1454253.c
test/bug1454253.s.c

index 69343d4bcb5deec244e91fb0ae738293692e9d92..672ee99a429c1b6def0dba0e7ae5a23dffb4eb44 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -6,6 +6,7 @@ Version 0.10.2 (????-??-??)
 - Changed to not generate yyaccept code unless needed.
 - Changed to use if- instead of switch-expression when yyaccpt has only one case.
 - Added docu, examples and tests to .src.zip package (0.10.1 zip was repackaged).
+- Fixed #1454253 Piece of code saving a backtracking point not generated.
 - Fixed #1463639 Missing forward declaration.
 - Implemented #1187127 savable state support for multiple re2c blocks.
 
diff --git a/code.cc b/code.cc
index 790051d0be72144aa98a3878e68782f29f9d325f..3a994f7dc8f84e65bfb172b80870f195610b007f 100644 (file)
--- a/code.cc
+++ b/code.cc
@@ -291,7 +291,7 @@ void genIf(std::ostream &o, uint ind, const char *cmp, uint v, bool &readCh)
        o << ") ";
 }
 
-static void need(std::ostream &o, uint ind, uint n, bool & readCh)
+static void need(std::ostream &o, uint ind, uint n, bool & readCh, bool bSetMarker)
 {
        uint fillIndex = next_fill_index;
 
@@ -315,7 +315,14 @@ static void need(std::ostream &o, uint ind, uint n, bool & readCh)
                o << "yyFillLabel" << fillIndex << ":\n";
        }
 
-       o << indent(ind) << "yych = *YYCURSOR;\n";
+       if (bSetMarker)
+       {
+               o << indent(ind) << "yych = *(YYMARKER = YYCURSOR);\n";
+       }
+       else
+       {
+               o << indent(ind) << "yych = *YYCURSOR;\n";
+       }
        readCh = false;
 }
 
@@ -339,7 +346,7 @@ void Match::emit(std::ostream &o, uint ind, bool &readCh) const
 
        if (state->link)
        {
-               need(o, ind, state->depth, readCh);
+               need(o, ind, state->depth, readCh, false);
        }
 }
 
@@ -352,7 +359,7 @@ void Enter::emit(std::ostream &o, uint ind, bool &readCh) const
                {
                        o << "yy" << label << ":\n";
                }
-               need(o, ind, state->depth, readCh);
+               need(o, ind, state->depth, readCh, false);
        }
        else
        {
@@ -382,10 +389,14 @@ void Initial::emit(std::ostream &o, uint ind, bool &readCh) const
        }
        if (state->link)
        {
-               need(o, ind, state->depth, readCh);
+               need(o, ind, state->depth, readCh, setMarker);
        }
        else
        {
+               if (setMarker)
+               {
+                       o << indent(ind) << "YYMARKER = YYCURSOR;\n";
+               }
                readCh = false;
        }
 }
@@ -400,7 +411,7 @@ void Save::emit(std::ostream &o, uint ind, bool &readCh) const
        if (state->link)
        {
                o << indent(ind) << "YYMARKER = ++YYCURSOR;\n";
-               need(o, ind, state->depth, readCh);
+               need(o, ind, state->depth, readCh, false);
        }
        else
        {
@@ -1224,6 +1235,7 @@ void DFA::emit(std::ostream &o, uint ind)
        memset(saves, ~0, (nRules)*sizeof(*saves));
 
        // mark backtracking points
+       bool bSaveOnHead = false;
 
        for (s = head; s; s = s->next)
        {
@@ -1240,8 +1252,8 @@ void DFA::emit(std::ostream &o, uint ind)
                                                saves[s->rule->accept] = nSaves++;
                                        }
 
+                                       bSaveOnHead |= s == head;
                                        (void) new Save(s, saves[s->rule->accept]); // sets s->action
-                                       continue;
                                }
                        }
                }
@@ -1333,7 +1345,7 @@ void DFA::emit(std::ostream &o, uint ind)
        
        uint start_label = next_label;
 
-       (void) new Initial(head, next_label++);
+       (void) new Initial(head, next_label++, bSaveOnHead);
 
        if (bUseStartLabel)
        {
diff --git a/dfa.h b/dfa.h
index 5a8556648a67ff795c7e4eeba2d563a535172cb7..0165b706318ab2f0619bbd040ac58e3b431d58fd 100644 (file)
--- a/dfa.h
+++ b/dfa.h
@@ -67,7 +67,10 @@ public:
 class Initial: public Enter
 {
 public:
-       Initial(State*, uint);
+       bool setMarker;
+
+public:
+       Initial(State*, uint, bool);
        void emit(std::ostream&, uint, bool&) const;
 };
 
@@ -306,7 +309,7 @@ inline bool Match::isMatch() const
 inline Enter::Enter(State *s, uint l) : Action(s), label(l)
 { }
 
-inline Initial::Initial(State *s, uint l) : Enter(s, l)
+inline Initial::Initial(State *s, uint l, bool b) : Enter(s, l), setMarker(b)
 { }
 
 inline Save::Save(State *s, uint i) : Match(s), selector(i)
index 4c938be50c9c126678b926f94b56b897fdb09a52..c7a1784e214b4a175c35bb2d756dd823c79267ad 100755 (executable)
@@ -102,6 +102,7 @@ provide re2c packages.</li>
 <li>Changed to not generate yyaccept code unless needed.</li>
 <li>Changed to use if- instead of switch-expression when yyaccpt has only one case.</li>
 <li>Added docu, examples and tests to .src.zip package (0.10.1 zip was repackaged).</li>
+<li>Fixed #1454253 Piece of code saving a backtracking point not generated.</li>
 <li>Fixed #1463639 Missing forward declaration.</li>
 <li>Implemented #1187127 savable state support for multiple re2c blocks.</li>
 </ul>
index f68f3f168611feb2832202828f8f54ad60020a73..d877a8da9fd5daebd622771ab36fca25757cfb32 100755 (executable)
@@ -24,7 +24,7 @@ size_t scan(const char *s, int l, char *r)
        YYCTYPE yych;
 
        if((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
-       yych = *YYCURSOR;
+       yych = *(YYMARKER = YYCURSOR);
        switch(yych){
        case 0x00:      goto yy5;
        case '?':       goto yy3;
@@ -107,7 +107,6 @@ yy3:
        default:        goto yy4;
        }
 yy4:
-       YYMARKER = YYCURSOR + 1;
        YYCURSOR = YYMARKER;
        goto yy2;
 yy5:
index d188a3269686c6c2920f91b5af86d475a58023a9..5ad6df3af5ea4be38a3b856b78680aa7fa90586b 100755 (executable)
@@ -24,7 +24,7 @@ size_t scan(const char *s, int l, char *r)
        YYCTYPE yych;
 
        if((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
-       yych = *YYCURSOR;
+       yych = *(YYMARKER = YYCURSOR);
        if(yych <= 0x00) goto yy5;
        if(yych == '?') goto yy3;
        goto yy7;
@@ -50,7 +50,6 @@ yy3:
                }
        }
 yy4:
-       YYMARKER = YYCURSOR + 1;
        YYCURSOR = YYMARKER;
        goto yy2;
 yy5: