]> granicus.if.org Git - re2c/commitdiff
[-Wundefined-control-flow] analyses: simplified path structure.
authorUlya Trofimovich <skvadrik@gmail.com>
Tue, 15 Mar 2016 12:41:07 +0000 (12:41 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Tue, 15 Mar 2016 12:41:07 +0000 (12:41 +0000)
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
re2c/src/ir/skeleton/way.cc
re2c/src/ir/skeleton/way.h

index fd892397f9ee89ff2d9b8bf5f5dd0875d1f25e6f..1c69d3e009aeb18d7c1ef8ffd6a6202b1e71f149 100644 (file)
@@ -33,7 +33,7 @@ void Node::naked_ways (way_t & prefix, std::vector<way_t> & 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<way_t> & ways, nakeds_t &size
 void Skeleton::warn_undefined_control_flow ()
 {
        way_t prefix;
+       prefix.push_back(&nodes[0]);
        std::vector<way_t> ways;
        Node::nakeds_t size = Node::nakeds_t::from32(0u);
 
index 0f58efe423e5cb47835555d57544c5d78e4ce7e9..778922e404d35ea6c846a7c978105171b5070224 100644 (file)
@@ -1,50 +1,54 @@
 #include <stddef.h>
 #include <algorithm>
 
+#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)
index e10010a9154f9819c6301d4c1bef97e6e76836f6..1b55aed9e9b2b88d2e7bd4f1556c9a4fe825e48f 100644 (file)
@@ -9,8 +9,10 @@
 namespace re2c
 {
 
+struct Node;
+
 typedef std::vector<std::pair<uint32_t, uint32_t> > way_arc_t;
-typedef std::vector<const way_arc_t *> way_t;
+typedef std::vector<Node*> way_t;
 
 bool cmp_ways (const way_t & w1, const way_t & w2);
 void fprint_way (FILE * f, const way_t & p);