From 1597947cea96f766e6f41f1e375391b7b47d8ebd Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Wed, 11 Mar 2015 15:02:19 +0000 Subject: [PATCH] Moved bitmap statistics to 'Go' class. --- re2c/code.cc | 49 +++++++++++++++++++++++-------------------------- re2c/dfa.h | 10 ++++++++++ 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/re2c/code.cc b/re2c/code.cc index 00f0d5d5..31191830 100644 --- a/re2c/code.cc +++ b/re2c/code.cc @@ -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 ; } } } diff --git a/re2c/dfa.h b/re2c/dfa.h index f244a5c8..d840e142 100644 --- a/re2c/dfa.h +++ b/re2c/dfa.h @@ -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]; } }; -- 2.40.0