From 5747320a214329d62856363dc84fb19d2dfc4bb9 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Tue, 8 Sep 2015 17:33:34 +0100 Subject: [PATCH] A more logical way to update rules when constructing skeleton paths. There's no need to keep rule one step behind path's arcs and update it manually. Also, it is reasonable to set rule in constructor. --- re2c/src/codegen/skeleton/generate_data.cc | 15 ++++++--------- re2c/src/codegen/skeleton/path.h | 19 ++++++------------- re2c/src/codegen/skeleton/skeleton.cc | 3 +-- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/re2c/src/codegen/skeleton/generate_data.cc b/re2c/src/codegen/skeleton/generate_data.cc index 099a8d2c..538825b3 100644 --- a/re2c/src/codegen/skeleton/generate_data.cc +++ b/re2c/src/codegen/skeleton/generate_data.cc @@ -101,9 +101,7 @@ void Node::permutate (const multipath_t & prefix, FILE * input, std::ofstream & { if (end ()) { - multipath_t new_prefix = prefix; - new_prefix.update (rule); - permutate_one (input, keys, new_prefix); + permutate_one (input, keys, prefix); } else if (loop < 2) { @@ -111,7 +109,7 @@ void Node::permutate (const multipath_t & prefix, FILE * input, std::ofstream & for (arcs_t::iterator i = arcs.begin (); i != arcs.end (); ++i) { multipath_t new_prefix = prefix; - new_prefix.extend (rule, &i->second); + new_prefix.extend (i->first->rule, &i->second); i->first->permutate (new_prefix, input, keys); } } @@ -155,7 +153,7 @@ arccount_t Node::cover (const multipath_t & prefix, FILE * input, std::ofstream for (arcs_t::iterator i = arcs.begin (); i != arcs.end (); ++i) { multipath_t new_prefix = prefix; - new_prefix.extend (rule, &i->second); + new_prefix.extend (i->first->rule, &i->second); size = size + i->first->cover (new_prefix, input, keys); if (size.overflow ()) { @@ -163,9 +161,8 @@ arccount_t Node::cover (const multipath_t & prefix, FILE * input, std::ofstream } if (i->first->suffix != NULL && suffix == NULL) { - suffix = new path_t; - suffix->extend (rule, i->second[0]); - suffix->append (i->first->suffix); + suffix = new path_t (rule); + suffix->append (i->second[0], i->first->suffix); } } } @@ -174,7 +171,7 @@ arccount_t Node::cover (const multipath_t & prefix, FILE * input, std::ofstream void Skeleton::generate_paths (uint32_t line, const std::string & cond, FILE * input, std::ofstream & keys) { - multipath_t prefix; + multipath_t prefix (nodes->rule); if (nodes->sizeof_permutate (arccount_t (1u), arccount_t (0u)).overflow ()) { if (nodes->cover (prefix, input, keys).overflow ()) diff --git a/re2c/src/codegen/skeleton/path.h b/re2c/src/codegen/skeleton/path.h index 92140e27..c3476989 100644 --- a/re2c/src/codegen/skeleton/path.h +++ b/re2c/src/codegen/skeleton/path.h @@ -17,9 +17,9 @@ class generic_path_t size_t rule_pos; public: - generic_path_t () + explicit generic_path_t (rule_rank_t r) : arcs () - , rule (rule_rank_t::none ()) + , rule (r) , rule_pos (0) {} size_t len () const @@ -38,31 +38,24 @@ public: { return arcs[i]; } - void update (rule_rank_t r) + void extend (rule_rank_t r, const arc_t & a) { + arcs.push_back (a); if (!r.is_none ()) { rule = r; rule_pos = arcs.size (); } } - void extend (rule_rank_t r, arc_t a) + void append (const arc_t & a, const generic_path_t * p) { - update (r); arcs.push_back (a); - } - void append (const generic_path_t * p) - { if (!p->rule.is_none ()) { rule = p->rule; rule_pos = arcs.size () + p->rule_pos; } - const size_t sz = p->arcs.size (); - for (size_t i = 0; i < sz; ++i) - { - arcs.push_back (p->arcs[i]); - } + arcs.insert (arcs.end (), p->arcs.begin (), p->arcs.end ()); } }; diff --git a/re2c/src/codegen/skeleton/skeleton.cc b/re2c/src/codegen/skeleton/skeleton.cc index 6a28fec9..6e287bcc 100644 --- a/re2c/src/codegen/skeleton/skeleton.cc +++ b/re2c/src/codegen/skeleton/skeleton.cc @@ -21,8 +21,7 @@ Node::Node (const State * s, const s2n_map & s2n) const bool is_final = !s || (s->go.nSpans == 1 && !s->go.span[0].to); if (is_final) { - suffix = new path_t; - suffix->update (rule); + suffix = new path_t (rule); } else { -- 2.40.0