From 8034cccb740243a72e84df8d8efc00cf1a1617cb Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Wed, 18 Mar 2015 15:01:41 +0000 Subject: [PATCH] Make 'Go' hierarchy independent of relabelling. This allows to move 'Go' initialization loop to 'DFA::prepare' and thus avoid ugly check if it is already initialized (it can happen in '-r' mode when the same DFA is used multiple times). Now that we store 'State *' pointers instead of labels in 'CpgotoTable', relabelling won't affect the generated code. --- re2c/code.cc | 14 +++++--------- re2c/go.h | 3 +-- re2c/go_construct.cc | 7 +++---- re2c/go_destruct.cc | 1 - re2c/go_emit.cc | 5 ++--- re2c/go_used_labels.cc | 3 +-- 6 files changed, 12 insertions(+), 21 deletions(-) diff --git a/re2c/code.cc b/re2c/code.cc index dba7dbd6..7fb6da1f 100644 --- a/re2c/code.cc +++ b/re2c/code.cc @@ -1076,6 +1076,11 @@ void DFA::prepare(uint & max_fill) delete head->action; head->action = NULL; + + for (s = head; s; s = s->next) + { + s->go.init (s); + } } @@ -1117,15 +1122,6 @@ void DFA::emit(Output & output, uint& ind, const RegExpMap* specMap, const std:: for (s = head; s; s = s->next) { - // This awkward check is necessary in '-r' mode, - // when the same DFA is used multiple times. - // If this for-loop was moved to 'prepare', check - // could be avoided, but in 'prepare' labels are - // not renamed properly yet. - if (s->go.type == Go::NOT_INITIALIZED) - { - s->go.init (s); - } s->go.used_labels (); } diff --git a/re2c/go.h b/re2c/go.h index 9f5d6599..51493cec 100644 --- a/re2c/go.h +++ b/re2c/go.h @@ -118,7 +118,7 @@ struct Bitmap struct CpgotoTable { static const uint TABLE_SIZE; - uint * table; + const State ** table; CpgotoTable (const Span * span, uint nSpans); ~CpgotoTable (); void emit (OutputFile & o, uint ind); @@ -150,7 +150,6 @@ struct Go Span * span; enum { - NOT_INITIALIZED, EMPTY, SWITCH_IF, BITMAP, diff --git a/re2c/go_construct.cc b/re2c/go_construct.cc index 53d231e9..04e8a481 100644 --- a/re2c/go_construct.cc +++ b/re2c/go_construct.cc @@ -135,14 +135,14 @@ Bitmap::Bitmap (const Span * span, uint nSpans, const Span * hspan, uint hSpans, const uint CpgotoTable::TABLE_SIZE = 0x100; CpgotoTable::CpgotoTable (const Span * span, uint nSpans) - : table (new uint [TABLE_SIZE]) + : table (new const State * [TABLE_SIZE]) { uint c = 0; for (uint i = 0; i < nSpans; ++i) { for(; c < span[i].ub && c < TABLE_SIZE; ++c) { - table[c] = span[i].to->label; + table[c] = span[i].to; } } } @@ -160,7 +160,7 @@ Dot::Dot (const Span * sp, uint nsp, const State * s) Go::Go () : nSpans (0) , span (NULL) - , type (NOT_INITIALIZED) + , type (EMPTY) , info () {} @@ -168,7 +168,6 @@ void Go::init (const State * from) { if (nSpans == 0) { - type = EMPTY; return; } diff --git a/re2c/go_destruct.cc b/re2c/go_destruct.cc index 1eaefff4..6b91d391 100644 --- a/re2c/go_destruct.cc +++ b/re2c/go_destruct.cc @@ -76,7 +76,6 @@ Go::~Go () { switch (type) { - case NOT_INITIALIZED: case EMPTY: break; case SWITCH_IF: diff --git a/re2c/go_emit.cc b/re2c/go_emit.cc index 82ae4fa5..8d2264b2 100644 --- a/re2c/go_emit.cc +++ b/re2c/go_emit.cc @@ -189,7 +189,7 @@ void CpgotoTable::emit (OutputFile & o, uint ind) o << indent (++ind); for (uint i = 0; i < TABLE_SIZE; ++i) { - o << "&&" << labelPrefix << table[i]; + o << "&&" << labelPrefix << table[i]->label; if (i == TABLE_SIZE - 1) { o << "\n"; @@ -200,7 +200,7 @@ void CpgotoTable::emit (OutputFile & o, uint ind) } else { - o << "," << space (table[i]); + o << "," << space (table[i]->label); } } o << indent (--ind) << "};\n"; @@ -240,7 +240,6 @@ void Go::emit (OutputFile & o, uint ind, bool & readCh) { switch (type) { - case NOT_INITIALIZED: case EMPTY: break; case SWITCH_IF: diff --git a/re2c/go_used_labels.cc b/re2c/go_used_labels.cc index 8cb837b5..e59184c6 100644 --- a/re2c/go_used_labels.cc +++ b/re2c/go_used_labels.cc @@ -69,7 +69,7 @@ void CpgotoTable::used_labels () { for (uint i = 0; i < TABLE_SIZE; ++i) { - vUsedLabels.insert (table[i]); + vUsedLabels.insert (table[i]->label); } } @@ -86,7 +86,6 @@ void Go::used_labels () { switch (type) { - case NOT_INITIALIZED: case EMPTY: case DOT: break; -- 2.40.0