From f1170e99efeac09491a3ee0acbe353333a9856c9 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Mon, 20 Apr 2015 13:43:31 +0100 Subject: [PATCH] Continued adding "--skeleton" switch. Fixed backtracking error introduced by previous commit: shouldn't return prematurely, need to unmark state as visited first. Some renaming. --- re2c/skeleton.cc | 22 ++++++++++------------ re2c/skeleton.h | 5 ++--- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/re2c/skeleton.cc b/re2c/skeleton.cc index 177b1aa7..e13bb6e9 100644 --- a/re2c/skeleton.cc +++ b/re2c/skeleton.cc @@ -51,29 +51,27 @@ Skeleton::~Skeleton () delete [] states; } -bool Skeleton::count (SkeletonState * s, uint n, uint & result) +bool Skeleton::estimate_path_count (SkeletonState * s, uint prefixes, uint & result) { if (s->is_end ()) { - const bool overflow = MAX_PATHS - n < result; + const bool overflow = MAX_PATHS - prefixes < result; if (!overflow) { - result += n; + result += prefixes; } return overflow; } else if (s->visited < 2) { s->visited++; - for (SkeletonState::go_t::iterator i = s->go.begin (); i != s->go.end (); ++i) + bool overflow = false; + for (SkeletonState::go_t::iterator i = s->go.begin (); !overflow && i != s->go.end (); ++i) { - if (count (i->first, i->second.size () * n, result)) - { - return true; - } + overflow = overflow || estimate_path_count (i->first, i->second.size () * prefixes, result); } s->visited--; - return false; + return overflow; } else { @@ -193,7 +191,7 @@ void generate (SkeletonState * s, const std::vector & prefixes, std::vecto } } -void Skeleton::generate_data (std::vector & results) +void Skeleton::generate_paths (std::vector & results) { // set paths for final states and default state // (those with zero outgoing arrows) @@ -219,7 +217,7 @@ void Skeleton::generate_data (std::vector & results) void Skeleton::emit_data (DataFile & o) { uint result = 0; - fprintf (stderr, "%d\n", count (states, 1, result)); + fprintf (stderr, "%d\n", estimate_path_count (states, 1, result)); uint ind = 0; std::string yyctype; @@ -251,7 +249,7 @@ void Skeleton::emit_data (DataFile & o) o.file << indent (ind) << "{\n"; std::vector ys; - generate_data (ys); + generate_paths (ys); const uint count = ys.size (); diff --git a/re2c/skeleton.h b/re2c/skeleton.h index fb816641..28821183 100644 --- a/re2c/skeleton.h +++ b/re2c/skeleton.h @@ -78,12 +78,11 @@ struct Skeleton Skeleton (const DFA & dfa); ~Skeleton (); - bool count (SkeletonState * s, uint n, uint & result); - void generate_data (std::vector & results); + bool estimate_path_count (SkeletonState * s, uint prefixes, uint & result); + void generate_paths (std::vector & results); void emit_data (DataFile & o); }; -unsigned long count_data (SkeletonState * s, unsigned long count); void skeleton_emit_prolog (OutputFile & o, uint ind, const char * data_name); void skeleton_emit_epilog (OutputFile & o, uint ind); void generate (SkeletonState * s, const std::vector & prefixes, std::vector & results); -- 2.40.0