From d9f081e31280e6f12001e663245a39e1a7dec36d Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Sun, 19 Apr 2015 22:05:46 +0100 Subject: [PATCH] Continued adding "--skeleton" switch. Simplified traversal of outgoing arrows when extending prefixes. Instead of adding outgoing arrow sets (which was erroneous anyway: they should remain unmodified for another recursion entry), simply wrap iterator and keep iterating until both ingoing and outgoing arrows are counted. --- re2c/skeleton.cc | 25 +++++++++---------------- re2c/skeleton.h | 8 ++++++++ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/re2c/skeleton.cc b/re2c/skeleton.cc index dfe05311..3ccd960b 100644 --- a/re2c/skeleton.cc +++ b/re2c/skeleton.cc @@ -196,25 +196,18 @@ void generate (DataFile & o, uint ind, SkeletonState * s, const std::vectorgo.begin (); i != s->go.end (); ++i) - { - out_arrows += i->second.size (); - } - - for (; out_arrows < prefixes.size (); ++out_arrows) - { - s->go.begin ()->second.push_back (s->go.begin ()->second.back ()); - } - - uint k = 0; - const uint prefixes_size = prefixes.size (); - for (SkeletonState::go_t::iterator i = s->go.begin (); i != s->go.end (); ++i) + const uint in_arrows = prefixes.size (); + const uint out_states = s->go.size (); + SkeletonState::go_t::iterator i = s->go.begin (); + for ( uint in = 0, out = 0 + ; in < in_arrows || out < out_states + ; ++out, s->wrap (++i) + ) { std::vector zs; - for (uint j = 0; j < i->second.size (); ++j, ++k) + for (uint j = 0; j < i->second.size (); ++j, ++in) { - zs.push_back (prefixes[k % prefixes_size]); + zs.push_back (prefixes[in % in_arrows]); update (zs[j], s); zs[j].chars.push_back (i->second[j]); } diff --git a/re2c/skeleton.h b/re2c/skeleton.h index 29fd23e4..01361e32 100644 --- a/re2c/skeleton.h +++ b/re2c/skeleton.h @@ -41,6 +41,7 @@ struct SkeletonState uint rule; uchar visited; Path * path; + inline SkeletonState () : go () , rule (~0u) @@ -51,6 +52,13 @@ struct SkeletonState { return go.size () == 0; } + inline void wrap (go_t::iterator & i) + { + if (i == go.end ()) + { + i = go.begin (); + } + } }; struct Skeleton -- 2.40.0