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 \
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 \
// 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 ())
{
}
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)
{
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 ();
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)
{
+++ /dev/null
-#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_
+++ /dev/null
-#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
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_
#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"
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;
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);
};
-#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)
}
}
-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
--- /dev/null
+#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_
}
}
-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)
{
// 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");
}
#include <vector>
-#include "src/codegen/skeleton/multipath.h"
+#include "src/codegen/skeleton/way.h"
#include "src/util/c99_stdint.h"
namespace re2c {
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);
};