From 72e3ada34499f8c70a07ec510f60a29377480ec3 Mon Sep 17 00:00:00 2001 From: helly Date: Sun, 9 Apr 2006 02:08:59 +0000 Subject: [PATCH] - Fixed #1454253 Piece of code saving a backtracking point not generated. --- CHANGELOG | 1 + code.cc | 28 ++++++++++++++++++++-------- dfa.h | 7 +++++-- htdocs/index.html | 1 + test/bug1454253.c | 3 +-- test/bug1454253.s.c | 3 +-- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 69343d4b..672ee99a 100644 --- 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 790051d0..3a994f7d 100644 --- 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 5a855664..0165b706 100644 --- 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) diff --git a/htdocs/index.html b/htdocs/index.html index 4c938be5..c7a1784e 100755 --- a/htdocs/index.html +++ b/htdocs/index.html @@ -102,6 +102,7 @@ provide re2c packages.
  • 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/test/bug1454253.c b/test/bug1454253.c index f68f3f16..d877a8da 100755 --- a/test/bug1454253.c +++ b/test/bug1454253.c @@ -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: diff --git a/test/bug1454253.s.c b/test/bug1454253.s.c index d188a326..5ad6df3a 100755 --- a/test/bug1454253.s.c +++ b/test/bug1454253.s.c @@ -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: -- 2.40.0