From: Ulya Trofimovich Date: Tue, 8 Sep 2015 11:06:52 +0000 (+0100) Subject: Renamed and restructured various kinds of skeleton paths. X-Git-Tag: 0.15~74 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=af651021441fe14cbc02463cf33193830669f51d;p=re2c Renamed and restructured various kinds of skeleton paths. --- diff --git a/re2c/Makefile.am b/re2c/Makefile.am index c82aeeed..924ab145 100644 --- a/re2c/Makefile.am +++ b/re2c/Makefile.am @@ -19,8 +19,8 @@ SRC_HDR = \ src/codegen/output.h \ src/codegen/print.h \ src/codegen/scc.h \ - src/codegen/skeleton/multipath.h \ src/codegen/skeleton/path.h \ + src/codegen/skeleton/way.h \ src/codegen/skeleton/skeleton.h \ src/conf/msg.h \ src/conf/opt.h \ @@ -89,9 +89,8 @@ SRC = \ src/codegen/skeleton/control_flow.cc \ src/codegen/skeleton/generate_code.cc \ src/codegen/skeleton/generate_data.cc \ - src/codegen/skeleton/multipath.cc \ - src/codegen/skeleton/path.cc \ src/codegen/skeleton/skeleton.cc \ + src/codegen/skeleton/way.cc \ src/conf/msg.cc \ src/conf/opt.cc \ src/conf/warn.cc \ diff --git a/re2c/src/codegen/skeleton/control_flow.cc b/re2c/src/codegen/skeleton/control_flow.cc index 19e19199..b61428c4 100644 --- a/re2c/src/codegen/skeleton/control_flow.cc +++ b/re2c/src/codegen/skeleton/control_flow.cc @@ -6,7 +6,7 @@ namespace re2c // see note [estimating total size of paths in skeleton] // neither do we need all default paths, nor default path cover: // just one path per each default final state, the shorter the better -arccount_t Node::generate_paths_default (const multipath_t & prefix, std::vector & paths) +arccount_t Node::generate_paths_default (const way_t & prefix, std::vector & ways) { if (!rule.is_none ()) { @@ -14,8 +14,8 @@ arccount_t Node::generate_paths_default (const multipath_t & prefix, std::vector } else if (end ()) { - paths.push_back (prefix); - return arccount_t (prefix.len ()); + ways.push_back (prefix); + return arccount_t (prefix.size ()); } else if (loop < 2) { @@ -23,9 +23,9 @@ arccount_t Node::generate_paths_default (const multipath_t & prefix, std::vector arccount_t size (0u); for (arcsets_t::iterator i = arcsets.begin (); i != arcsets.end (); ++i) { - multipath_t p = prefix; - p.extend (&i->second); - size = size + i->first->generate_paths_default (p, paths); + way_t w = prefix; + w.push_back (&i->second); + size = size + i->first->generate_paths_default (w, ways); if (size.overflow ()) { return arccount_t::limit (); @@ -41,12 +41,12 @@ arccount_t Node::generate_paths_default (const multipath_t & prefix, std::vector void Skeleton::warn_undefined_control_flow (uint32_t line, const std::string & cond) { - multipath_t prefix; - std::vector paths; - const bool overflow = nodes->generate_paths_default (prefix, paths).overflow (); - if (!paths.empty ()) + way_t prefix; + std::vector ways; + const bool overflow = nodes->generate_paths_default (prefix, ways).overflow (); + if (!ways.empty ()) { - warn.undefined_control_flow (line, cond, paths, overflow); + warn.undefined_control_flow (line, cond, ways, overflow); } else if (overflow) { diff --git a/re2c/src/codegen/skeleton/multipath.h b/re2c/src/codegen/skeleton/multipath.h deleted file mode 100644 index ab6a30f8..00000000 --- a/re2c/src/codegen/skeleton/multipath.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef _RE2C_CODEGEN_SKELETON_MULTIPATH_ -#define _RE2C_CODEGEN_SKELETON_MULTIPATH_ - -#include -#include - -#include "src/util/c99_stdint.h" - -namespace re2c -{ - -class multipath_t -{ -public: - typedef std::vector > arc_t; - -private: - std::vector arcs; - -public: - multipath_t (); - size_t len () const; - void extend (const arc_t * arc); - void fprint (FILE * f) const; - static bool compare (const multipath_t & x, const multipath_t & y); - -private: - static void fprint_arc (FILE * f, const arc_t & arc); -}; - -} // namespace re2c - -#endif // _RE2C_CODEGEN_SKELETON_MULTIPATH_ diff --git a/re2c/src/codegen/skeleton/path.cc b/re2c/src/codegen/skeleton/path.cc deleted file mode 100644 index adb62bdf..00000000 --- a/re2c/src/codegen/skeleton/path.cc +++ /dev/null @@ -1,61 +0,0 @@ -#include "src/codegen/skeleton/path.h" - -namespace re2c -{ - -path_t::path_t () - : arcs () - , rule (rule_rank_t::none ()) - , rule_pos (0) -{} - -size_t path_t::len () const -{ - return arcs.size (); -} - -size_t path_t::len_matching () const -{ - return rule_pos; -} - -rule_rank_t path_t::match () const -{ - return rule; -} - -uint32_t path_t::operator [] (size_t i) const -{ - return arcs[i]; -} - -void path_t::update (rule_rank_t r) -{ - if (!r.is_none ()) - { - rule = r; - rule_pos = arcs.size (); - } -} - -void path_t::extend (rule_rank_t r, uint32_t c) -{ - update (r); - arcs.push_back (c); -} - -void path_t::append (const 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]); - } -} - -} // namespace re2c diff --git a/re2c/src/codegen/skeleton/path.h b/re2c/src/codegen/skeleton/path.h index 29539f04..92140e27 100644 --- a/re2c/src/codegen/skeleton/path.h +++ b/re2c/src/codegen/skeleton/path.h @@ -9,23 +9,68 @@ namespace re2c { -class path_t +template +class generic_path_t { - std::vector arcs; + std::vector arcs; rule_rank_t rule; size_t rule_pos; public: - path_t (); - size_t len () const; - size_t len_matching () const; - rule_rank_t match () const; - uint32_t operator [] (size_t i) const; - void update (rule_rank_t r); - void extend (rule_rank_t r, uint32_t c); - void append (const path_t * p); + generic_path_t () + : arcs () + , rule (rule_rank_t::none ()) + , rule_pos (0) + {} + size_t len () const + { + return arcs.size (); + } + size_t len_matching () const + { + return rule_pos; + } + rule_rank_t match () const + { + return rule; + } + const arc_t & operator [] (size_t i) const + { + return arcs[i]; + } + void update (rule_rank_t r) + { + if (!r.is_none ()) + { + rule = r; + rule_pos = arcs.size (); + } + } + void extend (rule_rank_t r, arc_t a) + { + 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]); + } + } }; +typedef generic_path_t path_t; + +typedef std::vector multiarc_t; +typedef generic_path_t multipath_t; + } // namespace re2c #endif // _RE2C_CODEGEN_SKELETON_PATH_ diff --git a/re2c/src/codegen/skeleton/skeleton.h b/re2c/src/codegen/skeleton/skeleton.h index b3f9d391..f4b28120 100644 --- a/re2c/src/codegen/skeleton/skeleton.h +++ b/re2c/src/codegen/skeleton/skeleton.h @@ -3,8 +3,8 @@ #include -#include "src/codegen/skeleton/multipath.h" #include "src/codegen/skeleton/path.h" +#include "src/codegen/skeleton/way.h" #include "src/ir/dfa/dfa.h" #include "src/util/c99_stdint.h" #include "src/util/forbid_copy.h" @@ -21,8 +21,8 @@ typedef u32lim_t arccount_t; struct Node { typedef std::map s2n_map; - typedef std::map > arcs_t; - typedef std::map arcsets_t; + typedef std::map arcs_t; + typedef std::map arcsets_t; typedef local_increment_t local_inc; typedef wrap_iterator_t wrap_iter; @@ -46,7 +46,7 @@ struct Node arccount_t estimate_size_all (arccount_t inarcs, arccount_t len); void generate_paths_all (const std::vector & prefixes, FILE * input, std::ofstream & keys); arccount_t generate_paths_cover (const std::vector & prefixes, FILE * input, std::ofstream & keys); - arccount_t generate_paths_default (const multipath_t & prefix, std::vector & paths); + arccount_t generate_paths_default (const way_t & prefix, std::vector & ways); FORBID_COPY (Node); }; diff --git a/re2c/src/codegen/skeleton/multipath.cc b/re2c/src/codegen/skeleton/way.cc similarity index 53% rename from re2c/src/codegen/skeleton/multipath.cc rename to re2c/src/codegen/skeleton/way.cc index aad4ab75..7496e255 100644 --- a/re2c/src/codegen/skeleton/multipath.cc +++ b/re2c/src/codegen/skeleton/way.cc @@ -1,23 +1,38 @@ -#include "src/codegen/skeleton/multipath.h" +#include "src/codegen/skeleton/way.h" namespace re2c { -multipath_t::multipath_t () - : arcs () -{} +static void fprint_way_arc (FILE * f, const way_arc_t & arc); -size_t multipath_t::len () const +bool cmp_ways (const way_t & w1, const way_t & w2) { - return arcs.size (); + return w1.size () < w2.size (); } -void multipath_t::extend (const arc_t * arc) +void fprint_way (FILE * f, const way_t & w) { - arcs.push_back (arc); + fprintf (f, "'"); + const size_t len = w.size (); + for (size_t i = 0 ; i < len; ++i) + { + if (i > 0) + { + fprintf (f, " "); + } + if (w[i] == NULL) + { + fprintf (stderr, "(nil)"); + } + else + { + fprint_way_arc (stderr, *w[i]); + } + } + fprintf (f, "'"); } -void multipath_t::fprint_arc (FILE * f, const arc_t & arc) +void fprint_way_arc (FILE * f, const way_arc_t & arc) { const size_t ranges = arc.size (); if (ranges == 1 && arc[0].first == arc[0].second) @@ -41,31 +56,4 @@ void multipath_t::fprint_arc (FILE * f, const arc_t & arc) } } -void multipath_t::fprint (FILE * f) const -{ - fprintf (f, "'"); - const size_t len = arcs.size (); - for (size_t i = 0 ; i < len; ++i) - { - if (i > 0) - { - fprintf (f, " "); - } - if (arcs[i] == NULL) - { - fprintf (stderr, "(nil)"); - } - else - { - fprint_arc (stderr, *arcs[i]); - } - } - fprintf (f, "'"); -} - -bool multipath_t::compare (const multipath_t & x, const multipath_t & y) -{ - return x.arcs.size () < y.arcs.size (); -} - } // namespace re2c diff --git a/re2c/src/codegen/skeleton/way.h b/re2c/src/codegen/skeleton/way.h new file mode 100644 index 00000000..b1cce93d --- /dev/null +++ b/re2c/src/codegen/skeleton/way.h @@ -0,0 +1,20 @@ +#ifndef _RE2C_CODEGEN_SKELETON_WAY_ +#define _RE2C_CODEGEN_SKELETON_WAY_ + +#include +#include + +#include "src/util/c99_stdint.h" + +namespace re2c +{ + +typedef std::vector > way_arc_t; +typedef std::vector way_t; + +bool cmp_ways (const way_t & w1, const way_t & w2); +void fprint_way (FILE * f, const way_t & p); + +} // namespace re2c + +#endif // _RE2C_CODEGEN_SKELETON_WAY_ diff --git a/re2c/src/conf/warn.cc b/re2c/src/conf/warn.cc index 2a5cb7b9..a6a42f4c 100644 --- a/re2c/src/conf/warn.cc +++ b/re2c/src/conf/warn.cc @@ -126,7 +126,7 @@ void Warn::swapped_range (uint32_t line, uint32_t l, uint32_t u) } } -void Warn::undefined_control_flow (uint32_t line, const std::string & cond, std::vector & paths, bool overflow) +void Warn::undefined_control_flow (uint32_t line, const std::string & cond, std::vector & ways, bool overflow) { if (mask[UNDEFINED_CONTROL_FLOW] & WARNING) { @@ -135,27 +135,27 @@ void Warn::undefined_control_flow (uint32_t line, const std::string & cond, std: // limit the number of patterns reported static const size_t MAX = 8; - const size_t all = paths.size (); + const size_t all = ways.size (); const size_t some = std::min (MAX, all); const size_t rest = all - some; // report shorter patterns first - std::vector::iterator middle = paths.begin (); + std::vector::iterator middle = ways.begin (); std::advance (middle, some); - std::partial_sort (paths.begin (), middle, paths.end (), multipath_t::compare); + std::partial_sort (ways.begin (), middle, ways.end (), cmp_ways); warning_start (line, e); fprintf (stderr, "control flow %sis undefined for strings that match ", incond (cond).c_str ()); if (some == 1) { - paths[0].fprint (stderr); + fprint_way (stderr, ways[0]); } else { for (size_t i = 0; i < some; ++i) { fprintf (stderr, "\n\t"); - paths[i].fprint (stderr); + fprint_way (stderr, ways[i]); } fprintf (stderr, "\n"); } diff --git a/re2c/src/conf/warn.h b/re2c/src/conf/warn.h index ecfec094..0a70f2b7 100644 --- a/re2c/src/conf/warn.h +++ b/re2c/src/conf/warn.h @@ -3,7 +3,7 @@ #include -#include "src/codegen/skeleton/multipath.h" +#include "src/codegen/skeleton/way.h" #include "src/util/c99_stdint.h" namespace re2c { @@ -54,7 +54,7 @@ public: void empty_class (uint32_t line); void match_empty_string (uint32_t line); void swapped_range (uint32_t line, uint32_t l, uint32_t u); - void undefined_control_flow (uint32_t line, const std::string & cond, std::vector & paths, bool overflow); + void undefined_control_flow (uint32_t line, const std::string & cond, std::vector & ways, bool overflow); void useless_escape (uint32_t line, uint32_t col, char c); };