From: Ulya Trofimovich Date: Sun, 19 Apr 2015 21:38:50 +0000 (+0100) Subject: Continued adding "--skeleton" switch. X-Git-Tag: 0.15~297 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=86e29ab5521fe1b028d6114c20d897cdadfdfb4b;p=re2c Continued adding "--skeleton" switch. Keep all generated paths in memory (we are careful not to generate too much of them, and we keep second part of data (positions) in memory anyway). --- diff --git a/re2c/skeleton.cc b/re2c/skeleton.cc index 3ccd960b..3377086e 100644 --- a/re2c/skeleton.cc +++ b/re2c/skeleton.cc @@ -138,7 +138,7 @@ void generate_data (DataFile & o, uint ind, SkeletonState * s, const std::vector } */ -void update (Path & p, SkeletonState * s) +void update (Path & p, const SkeletonState * s) { if (s->rule != ~0u) { @@ -160,25 +160,13 @@ void append (Path & p1, const Path & p2) } } -void dump_paths (DataFile & o, uint ind, const std::vector & path) -{ - o.file << indent (ind); - for (uint i = 0 ; i < path.size (); ++i) - { - prtChOrHex (o.file, path[i]); - o.file << ","; - } - o.file << "\n"; -} - -void generate (DataFile & o, uint ind, SkeletonState * s, const std::vector & prefixes, std::vector & results) +void generate (SkeletonState * s, const std::vector & prefixes, std::vector & results) { if (s == NULL) { for (uint i = 0; i < prefixes.size (); ++i) { - results.push_back (Result (prefixes[i])); - dump_paths (o, ind, prefixes[i].chars); + results.push_back (prefixes[i]); } } else if (s->visited < 2) @@ -192,7 +180,7 @@ void generate (DataFile & o, uint ind, SkeletonState * s, const std::vectorpath); } - generate (o, ind, NULL, zs, results); + generate (NULL, zs, results); } else { @@ -211,7 +199,7 @@ void generate (DataFile & o, uint ind, SkeletonState * s, const std::vectorsecond[j]); } - generate (o, ind, i->first, zs, results); + generate (i->first, zs, results); if (s->path == NULL && i->first->path != NULL) { s->path = new Path (std::vector (1, i->second[0]), 0, s->rule); @@ -224,7 +212,7 @@ void generate (DataFile & o, uint ind, SkeletonState * s, const std::vector & results) +void Skeleton::generate_data (std::vector & results) { // set paths for final states and default state // (those with zero outgoing arrows) @@ -238,7 +226,7 @@ void Skeleton::generate_data (DataFile & o, uint ind, std::vector & resu std::vector prefixes; prefixes.push_back (Path (std::vector (), 0, ~0)); - generate (o, ind, states, prefixes, results); + generate (states, prefixes, results); // cleanup: delete all paths for (uint i = 0; i < states_count; ++i) @@ -280,18 +268,28 @@ void Skeleton::emit_data (DataFile & o) o.file << indent (ind) << "YYCTYPE data [] =\n"; o.file << indent (ind) << "{\n"; - std::vector ys; - generate_data (o, ind + 1, ys); + std::vector ys; + generate_data (ys); const uint count = ys.size (); uint max_len = 0; for (uint i = 0; i < count; ++i) { - if (max_len < ys[i].processed) + if (max_len < ys[i].chars.size ()) + { + max_len = ys[i].chars.size (); + } + } + for (uint i = 0; i < count; ++i) + { + o.file << indent (ind + 1); + for (uint j = 0 ; j < ys[i].chars.size (); ++j) { - max_len = ys[i].processed; + prtChOrHex (o.file, ys[i].chars[j]); + o.file << ","; } + o.file << "\n"; } o.file << indent (ind + 1); for (uint j = 0 ; j < max_len; ++j) // pad with YMAXFILL zeroes @@ -315,8 +313,8 @@ void Skeleton::emit_data (DataFile & o) o.file << indent (ind) << "{\n"; for (uint i = 0; i < count; ++i) { - o.file << indent (ind + 1) << "Result (" << pos + ys[i].consumed << "," << pos + ys[i].processed << "," << ys[i].rule << "),\n"; - pos += ys[i].processed; + o.file << indent (ind + 1) << "Result (" << pos + ys[i].length << "," << pos + ys[i].chars.size () << "," << ys[i].rule << "),\n"; + pos += ys[i].chars.size (); } o.file << indent (ind) << "};\n"; diff --git a/re2c/skeleton.h b/re2c/skeleton.h index 01361e32..85d18766 100644 --- a/re2c/skeleton.h +++ b/re2c/skeleton.h @@ -22,18 +22,6 @@ struct Path {} }; -struct Result -{ - uint processed; - uint consumed; - uint rule; - inline explicit Result (const Path & p) - : processed (p.chars.size ()) - , consumed (p.length) - , rule (p.rule) - {} -}; - struct SkeletonState { typedef std::map > go_t; @@ -68,17 +56,16 @@ struct Skeleton Skeleton (const DFA & dfa); ~Skeleton (); unsigned long count (); - void generate_data (DataFile & o, uint ind, std::vector & results); + void generate_data (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 update (Path & p, SkeletonState * s); +void update (Path & p, const SkeletonState * s); void append (Path & p1, const Path * p2); -void dump_paths (DataFile & o, uint ind, const std::vector & path); -void generate (DataFile & o, uint ind, SkeletonState * s, const std::vector & prefixes, std::vector & results); +void generate (SkeletonState * s, const std::vector & prefixes, std::vector & results); } // namespace re2c