From eda463ec9667395bf23ae6d8e76eb1bf53bf94ab Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Wed, 27 May 2015 13:04:53 +0100 Subject: [PATCH] Separated code generation for DFA actions and DFA states. Removes debugging utilities for DFA states (we should either add debug builds explicitely or throw away temporary debug stuff). --- re2c/Makefile.am | 1 - re2c/src/codegen/emit_dfa.cc | 17 +++++++------- re2c/src/dfa/state.cc | 43 ------------------------------------ re2c/src/dfa/state.h | 22 ++++++++++++++---- 4 files changed, 27 insertions(+), 56 deletions(-) delete mode 100644 re2c/src/dfa/state.cc diff --git a/re2c/Makefile.am b/re2c/Makefile.am index 8975d988..7df34789 100644 --- a/re2c/Makefile.am +++ b/re2c/Makefile.am @@ -90,7 +90,6 @@ SRC = \ $(srcdir)/src/dfa/encoding/utf8/utf8_range.cc \ $(srcdir)/src/dfa/encoding/utf8/utf8_regexp.cc \ $(srcdir)/src/dfa/dfa.cc \ - $(srcdir)/src/dfa/state.cc \ $(srcdir)/src/main.cc \ $(srcdir)/src/mbo_getopt.cc \ $(srcdir)/src/parse/input.cc \ diff --git a/re2c/src/codegen/emit_dfa.cc b/re2c/src/codegen/emit_dfa.cc index c6aa233b..9a534ef2 100644 --- a/re2c/src/codegen/emit_dfa.cc +++ b/re2c/src/codegen/emit_dfa.cc @@ -15,6 +15,7 @@ static std::string genGetCondition (); static void genCondGotoSub (OutputFile & o, uint32_t ind, RegExpIndices & vCondList, uint32_t cMin, uint32_t cMax); static void genCondTable (OutputFile & o, uint32_t ind, const RegExpMap & specMap); static void genCondGoto (OutputFile & o, uint32_t ind, const RegExpMap & specMap); +static void emit_state (OutputFile & o, uint32_t ind, const State * s); std::string genGetCondition() { @@ -45,24 +46,23 @@ void genGoTo(OutputFile & o, uint32_t ind, const State *from, const State *to, b o << indent(ind) << "goto " << labelPrefix << to->label << ";\n"; } -void State::emit(OutputFile & o, uint32_t ind, bool &readCh, const std::string& condName) const +void emit_state (OutputFile & o, uint32_t ind, const State * s) { if (!DFlag) { - if (vUsedLabels.count(label)) + if (vUsedLabels.count(s->label)) { - o << labelPrefix << label << ":\n"; + o << labelPrefix << s->label << ":\n"; } - if (dFlag && (action.type != Action::INITIAL)) + if (dFlag && (s->action.type != Action::INITIAL)) { - o << indent(ind) << mapCodeName["YYDEBUG"] << "(" << label << ", " << input_api.expr_peek () << ");\n"; + o << indent(ind) << mapCodeName["YYDEBUG"] << "(" << s->label << ", " << input_api.expr_peek () << ");\n"; } - if (isPreCtxt) + if (s->isPreCtxt) { o << input_api.stmt_backupctx (ind); } } - emit_action (action, o, ind, readCh, this, condName); } void DFA::emit(Output & output, uint32_t& ind, const RegExpMap* specMap, const std::string& condName, bool isLastCond, bool& bPrologBrace) @@ -206,7 +206,8 @@ void DFA::emit(Output & output, uint32_t& ind, const RegExpMap* specMap, const s for (s = head; s; s = s->next) { bool readCh = false; - s->emit(o, ind, readCh, condName); + emit_state (o, ind, s); + emit_action (s->action, o, ind, readCh, s, condName); s->go.emit(o, ind, readCh); } diff --git a/re2c/src/dfa/state.cc b/re2c/src/dfa/state.cc deleted file mode 100644 index 3f463f63..00000000 --- a/re2c/src/dfa/state.cc +++ /dev/null @@ -1,43 +0,0 @@ -#include "src/dfa/state.h" - -namespace re2c -{ - -State::State () - : label (0) - , rule (NULL) - , next (0) - , link (NULL) - , depth (0) - , kCount (0) - , kernel (NULL) - , isPreCtxt (false) - , isBase (false) - , go () - , action () -{} - -State::~State () -{ - delete [] kernel; - operator delete (go.span); -} - -std::ostream & operator << (std::ostream & o, const State & s) -{ - o << "state " << s.label; - if (s.rule) - { - o << " accepts " << s.rule->accept; - } - o << "\n"; - uint32_t lb = 0; - for (uint32_t i = 0; i < s.go.nSpans; ++i) - { - lb = s.go.span[i].show(o, lb); - } - return o; -} - -} // namespace re2c - diff --git a/re2c/src/dfa/state.h b/re2c/src/dfa/state.h index 884ecd87..9c11b0a5 100644 --- a/re2c/src/dfa/state.h +++ b/re2c/src/dfa/state.h @@ -25,10 +25,24 @@ public: Go go; Action action; - State (); - ~State (); - void emit (OutputFile &, uint32_t, bool &, const std::string &) const; - friend std::ostream& operator << (std::ostream &, const State &); + State () + : label (0) + , rule (NULL) + , next (0) + , link (NULL) + , depth (0) + , kCount (0) + , kernel (NULL) + , isPreCtxt (false) + , isBase (false) + , go () + , action () + {} + ~State () + { + delete [] kernel; + operator delete (go.span); + } FORBID_COPY (State); }; -- 2.40.0