]> granicus.if.org Git - re2c/commitdiff
Renamed and restructured various kinds of skeleton paths.
authorUlya Trofimovich <skvadrik@gmail.com>
Tue, 8 Sep 2015 11:06:52 +0000 (12:06 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Tue, 8 Sep 2015 11:06:52 +0000 (12:06 +0100)
re2c/Makefile.am
re2c/src/codegen/skeleton/control_flow.cc
re2c/src/codegen/skeleton/multipath.h [deleted file]
re2c/src/codegen/skeleton/path.cc [deleted file]
re2c/src/codegen/skeleton/path.h
re2c/src/codegen/skeleton/skeleton.h
re2c/src/codegen/skeleton/way.cc [moved from re2c/src/codegen/skeleton/multipath.cc with 53% similarity]
re2c/src/codegen/skeleton/way.h [new file with mode: 0644]
re2c/src/conf/warn.cc
re2c/src/conf/warn.h

index c82aeeed69f726cc6bf7cc3c2bc0a7dbab8167ea..924ab1453def195127cb8405ee36be3a05d8692e 100644 (file)
@@ -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 \
index 19e1919952d0123b689662e18585a8fdf1c24e7f..b61428c48a20aeede4276f6cc4698441cf399041 100644 (file)
@@ -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<multipath_t> & paths)
+arccount_t Node::generate_paths_default (const way_t & prefix, std::vector<way_t> & 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<multipath_t> paths;
-       const bool overflow = nodes->generate_paths_default (prefix, paths).overflow ();
-       if (!paths.empty ())
+       way_t prefix;
+       std::vector<way_t> 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 (file)
index ab6a30f..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-#ifndef _RE2C_CODEGEN_SKELETON_MULTIPATH_
-#define _RE2C_CODEGEN_SKELETON_MULTIPATH_
-
-#include <stdio.h>
-#include <vector>
-
-#include "src/util/c99_stdint.h"
-
-namespace re2c
-{
-
-class multipath_t
-{
-public:
-       typedef std::vector<std::pair<uint32_t, uint32_t> > arc_t;
-
-private:
-       std::vector<const arc_t *> 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 (file)
index adb62bd..0000000
+++ /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
index 29539f043be1ce6d618a80d86b864c388a237d77..92140e273d46769017f12871af5c40fe8b82255c 100644 (file)
@@ -9,23 +9,68 @@
 namespace re2c
 {
 
-class path_t
+template <typename arc_t>
+class generic_path_t
 {
-       std::vector<uint32_t> arcs;
+       std::vector<arc_t> 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<arc_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<uint32_t> path_t;
+
+typedef std::vector<uint32_t> multiarc_t;
+typedef generic_path_t<const multiarc_t *> multipath_t;
+
 } // namespace re2c
 
 #endif // _RE2C_CODEGEN_SKELETON_PATH_
index b3f9d3919e468e4ca721cd7088aaf1b1ffd929cc..f4b28120591aed2afc5d8b2c6ca97f3e9daae7f4 100644 (file)
@@ -3,8 +3,8 @@
 
 #include <map>
 
-#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<ARC_LIMIT> arccount_t;
 struct Node
 {
        typedef std::map<const State *, Node *> s2n_map;
-       typedef std::map<Node *, std::vector<uint32_t> > arcs_t;
-       typedef std::map<Node *, multipath_t::arc_t> arcsets_t;
+       typedef std::map<Node *, multiarc_t> arcs_t;
+       typedef std::map<Node *, way_arc_t> arcsets_t;
        typedef local_increment_t<uint8_t> local_inc;
        typedef wrap_iterator_t<arcs_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<path_t> & prefixes, FILE * input, std::ofstream & keys);
        arccount_t generate_paths_cover (const std::vector<path_t> & prefixes, FILE * input, std::ofstream & keys);
-       arccount_t generate_paths_default (const multipath_t & prefix, std::vector<multipath_t> & paths);
+       arccount_t generate_paths_default (const way_t & prefix, std::vector<way_t> & ways);
 
        FORBID_COPY (Node);
 };
similarity index 53%
rename from re2c/src/codegen/skeleton/multipath.cc
rename to re2c/src/codegen/skeleton/way.cc
index aad4ab753259ce7cf1d33d5b4379b72f7f11a40f..7496e25518740fdbbc6d19c23341aba165f9899b 100644 (file)
@@ -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 (file)
index 0000000..b1cce93
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef _RE2C_CODEGEN_SKELETON_WAY_
+#define _RE2C_CODEGEN_SKELETON_WAY_
+
+#include <stdio.h>
+#include <vector>
+
+#include "src/util/c99_stdint.h"
+
+namespace re2c
+{
+
+typedef std::vector<std::pair<uint32_t, uint32_t> > way_arc_t;
+typedef std::vector<const way_arc_t *> 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_
index 2a5cb7b984c8549cc69b04bacd2afe6d5a5d51d0..a6a42f4c08c78e7e8824f06799384edd8b25a3e1 100644 (file)
@@ -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<multipath_t> & paths, bool overflow)
+void Warn::undefined_control_flow (uint32_t line, const std::string & cond, std::vector<way_t> & 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<multipath_t>::iterator middle = paths.begin ();
+               std::vector<way_t>::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");
                }
index ecfec094a92c717ba1615cec73354e507c3662c1..0a70f2b707dab2f8e8447baa22523fff6294ea38 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <vector>
 
-#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<multipath_t> & paths, bool overflow);
+       void undefined_control_flow (uint32_t line, const std::string & cond, std::vector<way_t> & ways, bool overflow);
        void useless_escape (uint32_t line, uint32_t col, char c);
 };