]> granicus.if.org Git - re2c/commitdiff
Separated code generation for DFA actions and DFA states.
authorUlya Trofimovich <skvadrik@gmail.com>
Wed, 27 May 2015 12:04:53 +0000 (13:04 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Wed, 27 May 2015 12:04:53 +0000 (13:04 +0100)
Removes debugging utilities for DFA states (we should either add
debug builds explicitely or throw away temporary debug stuff).

re2c/Makefile.am
re2c/src/codegen/emit_dfa.cc
re2c/src/dfa/state.cc [deleted file]
re2c/src/dfa/state.h

index 8975d98812303d75bbecb1b4ce506b01ac5deaea..7df34789caebdd0840c081a87d52c97e59f5306c 100644 (file)
@@ -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 \
index c6aa233b4f58a4745a9739c370fc4815a9c3dde9..9a534ef245a297e7fa096853cee68cee9f14dc6b 100644 (file)
@@ -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 (file)
index 3f463f6..0000000
+++ /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
-
index 884ecd87db1e91ac3de84b43d996899c669af9e4..9c11b0a5b9800e8cf71c32295acadba948440266 100644 (file)
@@ -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);
 };