From: Ulya Trofimovich Date: Mon, 20 Apr 2015 12:26:25 +0000 (+0100) Subject: Continued adding "--skeleton" switch. X-Git-Tag: 0.15~295 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a74b6d4a8e5e042cbc6d87164f9cb474925d0850;p=re2c Continued adding "--skeleton" switch. Give up counting data when reached certain limit ('Skeleton::MAX_PATHS'). --- diff --git a/re2c/skeleton.cc b/re2c/skeleton.cc index 5967d275..177b1aa7 100644 --- a/re2c/skeleton.cc +++ b/re2c/skeleton.cc @@ -5,6 +5,8 @@ namespace re2c { +const uint Skeleton::MAX_PATHS = 1024 * 1024; // 1Mb + Skeleton::Skeleton (const DFA & dfa) : states_count (dfa.nStates + 1) , states (new SkeletonState [states_count]) @@ -49,34 +51,36 @@ Skeleton::~Skeleton () delete [] states; } -unsigned long count_data (SkeletonState * s, unsigned long count) +bool Skeleton::count (SkeletonState * s, uint n, uint & result) { if (s->is_end ()) { - return count; + const bool overflow = MAX_PATHS - n < result; + if (!overflow) + { + result += n; + } + return overflow; } else if (s->visited < 2) { s->visited++; - unsigned long result = 0; for (SkeletonState::go_t::iterator i = s->go.begin (); i != s->go.end (); ++i) { - result += count_data (i->first, i->second.size () * count); + if (count (i->first, i->second.size () * n, result)) + { + return true; + } } s->visited--; - return result; + return false; } else { - return 0; + return false; } } -unsigned long Skeleton::count () -{ - return count_data (states, 1); -} - /* void generate_data (DataFile & o, uint ind, SkeletonState * s, const std::vector & xs, std::vector & ys) { @@ -214,7 +218,8 @@ void Skeleton::generate_data (std::vector & results) void Skeleton::emit_data (DataFile & o) { -// fprintf (stderr, "%lx\n%lx\n", 0xFFFFffffFFFFffff, count ()); + uint result = 0; + fprintf (stderr, "%d\n", count (states, 1, result)); uint ind = 0; std::string yyctype; diff --git a/re2c/skeleton.h b/re2c/skeleton.h index 28dc261e..fb816641 100644 --- a/re2c/skeleton.h +++ b/re2c/skeleton.h @@ -72,11 +72,13 @@ struct SkeletonState struct Skeleton { + static const uint MAX_PATHS; const uint states_count; SkeletonState * states; + Skeleton (const DFA & dfa); ~Skeleton (); - unsigned long count (); + bool count (SkeletonState * s, uint n, uint & result); void generate_data (std::vector & results); void emit_data (DataFile & o); };