bin_PROGRAMS = re2c
win_BINARIES = $(WINBUILDDIR)/re2c.exe
-re2c_SOURCES = cases.cc code.cc dfa.cc main.cc parser.cc actions.cc scanner.re substr.cc range.cc \
+re2c_SOURCES = cases.cc code.cc dfa.cc go.cc main.cc parser.cc actions.cc scanner.re substr.cc range.cc \
translate.cc scanner.cc mbo_getopt.cc print.cc input.cc input_api.cc output.cc \
enc.cc utf8.cc utf8_range.cc utf8_regexp.cc utf16.cc utf16_range.cc utf16_regexp.cc range_suffix.cc \
- basics.h cases.h code.h code_names.h dfa.h enc.h indent.h input.h input_api.h free_list.h globals.h ins.h \
+ basics.h cases.h code.h code_names.h dfa.h go.h enc.h indent.h input.h input_api.h free_list.h globals.h ins.h \
mbo_getopt.h parser.h print.h range.h range_suffix.h re.h \
scanner.h smart_ptr.h substr.h token.h output.h \
utf16.h utf16_range.h utf16_regexp.h utf8.h utf8_range.h utf8_regexp.h
#include "cases.h"
#include "code.h"
#include "globals.h"
+#include "go.h"
#include "dfa.h"
#include "indent.h"
#include "input_api.h"
}
}
-// All spans in g1 that lead to s1 are pairwise equal to that in g2 leading to s2
-static bool matches(const Go *g1, const State *s1, const Go *g2, const State *s2)
-{
- Span *b1 = g1->span, *e1 = &b1[g1->nSpans];
- uint lb1 = 0;
- Span *b2 = g2->span, *e2 = &b2[g2->nSpans];
- uint lb2 = 0;
-
- for (;;)
- {
- for (; b1 < e1 && b1->to != s1; ++b1)
- {
- lb1 = b1->ub;
- }
-
- for (; b2 < e2 && b2->to != s2; ++b2)
- {
- lb2 = b2->ub;
- }
-
- if (b1 == e1)
- {
- return b2 == e2;
- }
-
- if (b2 == e2)
- {
- return false;
- }
-
- if (lb1 != lb2 || b1->ub != b2->ub)
- {
- return false;
- }
-
- ++b1;
- ++b2;
- }
-}
-
BitMap *BitMap::first = NULL;
BitMap::BitMap(const Go *g, const State *x)
return;
}
- uint dSpans = 0;
- uint nBitmaps = 0;
- for (uint i = 0; i < go.nSpans; ++i)
- {
- State *to = go.span[i].to;
-
- if (to && to->isBase)
- {
- const BitMap *b = BitMap::find(to);
-
- if (b && matches(b->go, b->on, &go, to))
- {
- go.bitmaps[i] = b;
- nBitmaps++;
- }
- else
- {
- go.bitmaps[i] = NULL;
- dSpans++;
- }
- }
- else
- {
- go.bitmaps[i] = NULL;
- dSpans++;
- }
- }
-
+ const uint dSpans = go.nSpans - go.hSpans - go.nBitmaps;
if (gFlag && (dSpans >= cGotoThreshold))
{
genCpGoto(o, ind, from, next, readCh, go.span, go.nSpans, go.hspan, go.hSpans);
#define _code_h
#include "re.h"
-#include "dfa.h"
namespace re2c
{
+struct Go;
+class State;
+
class BitMap
{
public:
namespace re2c
{
-uint Span::show(std::ostream &o, uint lb) const
-{
- if (to)
- {
- printSpan(o, lb, ub);
- o << " " << to->label << "; ";
- }
-
- return ub;
-}
-
std::ostream& operator<<(std::ostream &o, const State &s)
{
o << "state " << s.label;
#include <iosfwd>
#include <map>
+
+#include "go.h"
#include "re.h"
namespace re2c
#endif
};
-class Span
-{
-
-public:
- uint ub;
- State *to;
-
-public:
- uint show(std::ostream&, uint) const;
-};
-
-class BitMap;
-
-struct Go
-{
- uint nSpans; // number of spans
- uint hSpans; // number of spans with upper bound > 0x100
- Span * span;
- Span * hspan;
- const BitMap ** bitmaps;
-
- Go ()
- : nSpans (0)
- , hSpans (0)
- , span (NULL)
- , hspan (NULL)
- , bitmaps (NULL)
- {}
-
- ~Go ()
- {
- delete [] bitmaps;
- }
-
- void init ()
- {
- for (uint i = 0; i < nSpans; ++i)
- {
- if (span[i].ub > 0x100)
- {
- hspan = &span[i];
- hSpans = nSpans - i;
- break;
- }
- }
- bitmaps = new const BitMap * [nSpans];
- }
-};
-
class State
{
--- /dev/null
+#include "dfa.h"
+#include "go.h"
+#include "print.h"
+
+namespace re2c
+{
+
+uint Span::show (std::ostream & o, uint lb) const
+{
+ if (to)
+ {
+ printSpan(o, lb, ub);
+ o << " " << to->label << "; ";
+ }
+ return ub;
+}
+
+Go::Go ()
+ : nSpans (0)
+ , hSpans (0)
+ , span (NULL)
+ , hspan (NULL)
+ , nBitmaps (0)
+ , bitmaps (NULL)
+{}
+
+Go::~Go ()
+{
+ delete [] bitmaps;
+}
+
+void Go::init ()
+{
+ // initialize high (wide) spans
+ for (uint i = 0; i < nSpans; ++i)
+ {
+ if (span[i].ub > 0x100)
+ {
+ hspan = &span[i];
+ hSpans = nSpans - i;
+ break;
+ }
+ }
+ // initialize bitmaps
+ bitmaps = new const BitMap * [nSpans];
+ memset (bitmaps, 0, nSpans * sizeof (BitMap *));
+ for (uint i = 0; i < nSpans; ++i)
+ {
+ if (span[i].to && span[i].to->isBase)
+ {
+ const BitMap *b = BitMap::find (span[i].to);
+ if (b && matches(b->go, b->on, this, span[i].to))
+ {
+ bitmaps[i] = b;
+ nBitmaps++;
+ }
+ }
+ }
+}
+
+// All spans in g1 that lead to s1 are pairwise equal to that in g2 leading to s2
+bool matches(const Go * g1, const State * s1, const Go * g2, const State * s2)
+{
+ Span *b1 = g1->span, *e1 = &b1[g1->nSpans];
+ uint lb1 = 0;
+ Span *b2 = g2->span, *e2 = &b2[g2->nSpans];
+ uint lb2 = 0;
+
+ for (;;)
+ {
+ for (; b1 < e1 && b1->to != s1; ++b1)
+ {
+ lb1 = b1->ub;
+ }
+ for (; b2 < e2 && b2->to != s2; ++b2)
+ {
+ lb2 = b2->ub;
+ }
+ if (b1 == e1)
+ {
+ return b2 == e2;
+ }
+ if (b2 == e2)
+ {
+ return false;
+ }
+ if (lb1 != lb2 || b1->ub != b2->ub)
+ {
+ return false;
+ }
+ ++b1;
+ ++b2;
+ }
+}
+
+} // namespace re2c
--- /dev/null
+#ifndef _go_h
+#define _go_h
+
+#include <iostream>
+
+#include "basics.h"
+#include "code.h"
+
+namespace re2c
+{
+
+class State;
+
+struct Span
+{
+ uint ub;
+ State * to;
+
+ uint show(std::ostream&, uint) const;
+};
+
+struct Go
+{
+ uint nSpans; // number of spans
+ uint hSpans; // number of spans with upper bound > 0x100
+ Span * span;
+ Span * hspan;
+ uint nBitmaps;
+ const BitMap ** bitmaps;
+
+ Go ();
+ ~Go ();
+ void init ();
+};
+
+bool matches(const Go * g1, const State * s1, const Go * g2, const State * s2);
+
+} // namespace re2c
+
+#endif // _go_h