From 6a8749cf2d5e7f2f48be278ed1577badc6953d9e Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Tue, 15 Mar 2016 12:41:07 +0000 Subject: [PATCH] [-Wundefined-control-flow] analyses: simplified path structure. Now paths involved in [-Wundefined-control-flow] analyses have exactly the same structure as paths involved in skeleton data generation. --- re2c/src/ir/skeleton/control_flow.cc | 3 +- re2c/src/ir/skeleton/way.cc | 60 +++++++++++++++------------- re2c/src/ir/skeleton/way.h | 4 +- 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/re2c/src/ir/skeleton/control_flow.cc b/re2c/src/ir/skeleton/control_flow.cc index fd892397..1c69d3e0 100644 --- a/re2c/src/ir/skeleton/control_flow.cc +++ b/re2c/src/ir/skeleton/control_flow.cc @@ -33,7 +33,7 @@ void Node::naked_ways (way_t & prefix, std::vector & ways, nakeds_t &size for (arcsets_t::iterator i = arcsets.begin (); i != arcsets.end () && !size.overflow (); ++i) { - prefix.push_back (&i->second); + prefix.push_back (i->first); i->first->naked_ways (prefix, ways, size); prefix.pop_back (); } @@ -43,6 +43,7 @@ void Node::naked_ways (way_t & prefix, std::vector & ways, nakeds_t &size void Skeleton::warn_undefined_control_flow () { way_t prefix; + prefix.push_back(&nodes[0]); std::vector ways; Node::nakeds_t size = Node::nakeds_t::from32(0u); diff --git a/re2c/src/ir/skeleton/way.cc b/re2c/src/ir/skeleton/way.cc index 0f58efe4..778922e4 100644 --- a/re2c/src/ir/skeleton/way.cc +++ b/re2c/src/ir/skeleton/way.cc @@ -1,50 +1,54 @@ #include #include +#include "src/ir/skeleton/skeleton.h" #include "src/ir/skeleton/way.h" namespace re2c { -static bool cmp_way_arcs (const way_arc_t * a1, const way_arc_t * a2); static void fprint_way_arc (FILE * f, const way_arc_t & arc); -bool cmp_way_arcs (const way_arc_t * a1, const way_arc_t * a2) -{ - return std::lexicographical_compare(a1->begin(), a1->end(), a2->begin(), a2->end()); -} - // define strict weak ordering on patterns: // 1st criterion is length (short patterns go first) // 2nd criterion is lexicographical order (applies to patterns of equal length) -bool cmp_ways (const way_t & w1, const way_t & w2) +bool cmp_ways (const way_t &w1, const way_t &w2) { - const size_t s1 = w1.size (); - const size_t s2 = w2.size (); - return (s1 == s2 && std::lexicographical_compare(w1.begin(), w1.end(), w2.begin(), w2.end(), cmp_way_arcs)) - || s1 < s2; + const size_t s1 = w1.size(); + const size_t s2 = w2.size(); + if (s1 == s2) { + for (size_t i = 1; i < s1; ++i) { + const way_arc_t + &a1 = w1[i - 1]->arcsets[w1[i]], + &a2 = w2[i - 1]->arcsets[w2[i]]; + const size_t l1 = a1.size(); + const size_t l2 = a2.size(); + for (size_t j = 0; j < l1; ++j) { + if (j == l2 || a2[j] < a1[j]) { + return false; + } else if (a1[j] < a2[j]) { + return true; + } + } + } + return false; + } else { + return s1 < s2; + } } -void fprint_way (FILE * f, const way_t & w) +void fprint_way(FILE *f, const way_t &w) { - 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, "'"); + const size_t len = w.size(); + for (size_t i = 1; i < len; ++i) { + if (i > 1) { + fprintf(f, " "); } + const way_arc_t &arc = w[i - 1]->arcsets[w[i]]; + fprint_way_arc(stderr, arc); } - fprintf (f, "'"); + fprintf(f, "'"); } void fprint_way_arc (FILE * f, const way_arc_t & arc) diff --git a/re2c/src/ir/skeleton/way.h b/re2c/src/ir/skeleton/way.h index e10010a9..1b55aed9 100644 --- a/re2c/src/ir/skeleton/way.h +++ b/re2c/src/ir/skeleton/way.h @@ -9,8 +9,10 @@ namespace re2c { +struct Node; + typedef std::vector > way_arc_t; -typedef std::vector way_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); -- 2.40.0