]> granicus.if.org Git - re2c/commitdiff
- Fix goto optimization for wide mode when using a table
authorhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 15 Jan 2006 18:53:11 +0000 (18:53 +0000)
committerhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 15 Jan 2006 18:53:11 +0000 (18:53 +0000)
code.cc
dfa.cc
dfa.h

diff --git a/code.cc b/code.cc
index a0478bedf472c3ca88c446403d8cf278ce85c3b6..621ac1fc3baca866b238a985eb499df0cbf1a8f9 100644 (file)
--- a/code.cc
+++ b/code.cc
@@ -578,7 +578,7 @@ void Go::genSwitch(std::ostream &o, uint ind, const State *from, const State *ne
 {
        bool newLine = true;
 
-       if (nSpans <= 2)
+       if ((mask ? wSpans : nSpans) <= 2)
        {
                genLinear(o, ind, from, next, readCh, mask);
        }
@@ -670,33 +670,45 @@ void doBinary(std::ostream &o, uint ind, Span *s, uint n, const State *from, con
        {
                uint h = n / 2;
 
-               if (!mask || (s[h - 1].ub - 1) > 0x00FF)
-               {
-                       genIf(o, ind, "<=", s[h - 1].ub - 1, readCh);
-                       o << "{\n";
-                       ++oline;
-                       doBinary(o, ind+1, &s[0], h, from, next, readCh, mask);
-                       o << indent(ind) << "} else {\n";
-                       ++oline;
-                       doBinary(o, ind+1, &s[h], n - h, from, next, readCh, mask);
-                       o << indent(ind) << "}\n";
-                       ++oline;
-               }
-               else
-               {
-                       doBinary(o, ind, &s[h], n - h, from, next, readCh, mask);
-               }
+               genIf(o, ind, "<=", s[h - 1].ub - 1, readCh);
+               o << "{\n";
+               ++oline;
+               doBinary(o, ind+1, &s[0], h, from, next, readCh, mask);
+               o << indent(ind) << "} else {\n";
+               ++oline;
+               doBinary(o, ind+1, &s[h], n - h, from, next, readCh, mask);
+               o << indent(ind) << "}\n";
+               ++oline;
        }
 }
 
 void Go::genBinary(std::ostream &o, uint ind, const State *from, const State *next, bool &readCh, uint mask) const
 {
-       doBinary(o, ind, span, nSpans, from, next, readCh, mask);
+       if (mask)
+       {
+               Span * sc = new Span[wSpans];
+               
+               for (uint i = 0, j = 0; i < nSpans; i++)
+               {
+                       if (span[i].ub > 0xFF)
+                       {
+                               sc[j++] = span[i];
+                       }
+               }
+
+               doBinary(o, ind, sc, wSpans, from, next, readCh, mask);
+
+               delete[] sc;
+       }
+       else
+       {
+               doBinary(o, ind, span, nSpans, from, next, readCh, mask);
+       }
 }
 
 void Go::genBase(std::ostream &o, uint ind, const State *from, const State *next, bool &readCh, uint mask) const
 {
-       if (nSpans == 0)
+       if ((mask ? wSpans : nSpans) == 0)
        {
                return ;
        }
@@ -707,7 +719,7 @@ void Go::genBase(std::ostream &o, uint ind, const State *from, const State *next
                return ;
        }
 
-       if (nSpans > 8)
+       if ((mask ? wSpans : nSpans) > 8)
        {
                Span *bot = &span[0], *top = &span[nSpans - 1];
                uint util;
@@ -735,7 +747,7 @@ void Go::genBase(std::ostream &o, uint ind, const State *from, const State *next
                }
        }
 
-       if (nSpans > 5)
+       if ((mask ? wSpans : nSpans) > 5)
        {
                genBinary(o, ind, from, next, readCh, mask);
        }
@@ -749,6 +761,18 @@ void Go::genGoto(std::ostream &o, uint ind, const State *from, const State *next
 {
        if (bFlag)
        {
+               if (wSpans == ~0u && wFlag)
+               {
+                       wSpans = 0;
+                       for (uint p = 0; p < nSpans; p++)
+                       {
+                               if (span[p].ub > 0xFF)
+                               {
+                                       wSpans++;
+                               }
+                       }
+               }
+
                for (uint i = 0; i < nSpans; ++i)
                {
                        State *to = span[i].to;
@@ -1233,6 +1257,7 @@ void DFA::emit(std::ostream &o, uint ind)
                }
 
                for (i = 0; i < s->go.nSpans; ++i)
+               {
                        if (!s->go.span[i].to)
                        {
                                if (!ow)
@@ -1244,6 +1269,7 @@ void DFA::emit(std::ostream &o, uint ind)
 
                                s->go.span[i].to = ow;
                        }
+               }
        }
 
        // split ``base'' states into two parts
diff --git a/dfa.cc b/dfa.cc
index d538afd86e81196be6585be8c8aff8a69ec18bd8..74e9d7fff897b2510d196f50fd1fe1692bcecae5 100644 (file)
--- a/dfa.cc
+++ b/dfa.cc
@@ -130,7 +130,7 @@ void printSpan(std::ostream &o, uint lb, uint ub)
        o << "]";
 }
 
-uint Span::show(std::ostream &o, uint lb)
+uint Span::show(std::ostream &o, uint lb) const
 {
        if (to)
        {
diff --git a/dfa.h b/dfa.h
index f72fbf562c614205653b3ab1daae095c71789131..0059b6a5c203300111c5c7ec4803b0ca05e8a31c 100644 (file)
--- a/dfa.h
+++ b/dfa.h
@@ -149,14 +149,22 @@ public:
        State   *to;
 
 public:
-       uint show(std::ostream&, uint);
+       uint show(std::ostream&, uint) const;
 };
 
 class Go
 {
+public:
+       Go()
+               : nSpans(0)
+               , wSpans(~0u)
+               , span(NULL)
+       {
+       }
 
 public:
        uint    nSpans;
+       uint    wSpans;
        Span    *span;
 
 public: