]> granicus.if.org Git - re2c/commitdiff
Moved bitmap statistics to 'Go' class.
authorUlya Trofimovich <skvadrik@gmail.com>
Wed, 11 Mar 2015 15:02:19 +0000 (15:02 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Wed, 11 Mar 2015 15:02:19 +0000 (15:02 +0000)
re2c/code.cc
re2c/dfa.h

index 00f0d5d59103bea9fd1f3bb88b1b859d90da87eb..31191830a0cd34cb24a653dee1fb85ba964c2436 100644 (file)
@@ -976,7 +976,7 @@ static void genGoto (OutputFile & o, uint ind, const Go & go, const State *from,
 
        uint dSpans = 0;
        uint nBitmaps = 0;
-       for (uint i = 0; i < go.nSpans - go.hSpans; ++i)
+       for (uint i = 0; i < go.nSpans; ++i)
        {
                State *to = go.span[i].to;
 
@@ -986,15 +986,18 @@ static void genGoto (OutputFile & o, uint ind, const Go & go, const State *from,
 
                        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++;
                }
        }
@@ -1008,34 +1011,28 @@ static void genGoto (OutputFile & o, uint ind, const Go & go, const State *from,
        {
                for (uint i = 0; i < go.nSpans; ++i)
                {
-                       State *to = go.span[i].to;
-
-                       if (to && to->isBase)
+                       if (const BitMap * b = go.bitmaps[i])
                        {
-                               const BitMap *b = BitMap::find(to);
-                               if (b && matches(b->go, b->on, &go, to))
+                               Go go1;
+                               go1.span = new Span[go.nSpans];
+                               unmap (go1, go, go.span[i].to);
+                               const std::string sYych = genGotoProlog(o, ind, from, next, readCh, go.hspan, go.hSpans);
+                               bUsedYYBitmap = true;
+                               o << "if (" << mapCodeName["yybm"] << "[" << b->i << "+" << sYych << "] & ";
+                               if (yybmHexTable)
                                {
-                                       Go go1;
-                                       go1.span = new Span[go.nSpans];
-                                       unmap (go1, go, to);
-                                       const std::string sYych = genGotoProlog(o, ind, from, next, readCh, go.hspan, go.hSpans);
-                                       bUsedYYBitmap = true;
-                                       o << "if (" << mapCodeName["yybm"] << "[" << b->i << "+" << sYych << "] & ";
-                                       if (yybmHexTable)
-                                       {
-                                               o.write_hex (b->m);
-                                       }
-                                       else
-                                       {
-                                               o << (uint) b->m;
-                                       }
-                                       o << ") {\n";
-                                       genGoTo(o, ind+1, from, to, readCh);
-                                       o << indent(ind) << "}\n";
-                                       genBase(o, ind, from, next, readCh, go1.span, go1.nSpans);
-                                       delete [] go1.span;
-                                       return ;
+                                       o.write_hex (b->m);
+                               }
+                               else
+                               {
+                                       o << (uint) b->m;
                                }
+                               o << ") {\n";
+                               genGoTo(o, ind+1, from, go.span[i].to, readCh);
+                               o << indent(ind) << "}\n";
+                               genBase(o, ind, from, next, readCh, go1.span, go1.nSpans);
+                               delete [] go1.span;
+                               return ;
                        }
                }
        }
index f244a5c8b611bff578bc8715bafab1c723bdbf9f..d840e142014419efd864066bf9e01a5d4791ab0c 100644 (file)
@@ -163,20 +163,29 @@ 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)
@@ -188,6 +197,7 @@ struct Go
                                break;
                        }
                }
+               bitmaps = new const BitMap * [nSpans];
        }
 };