src
way.cc
Go to the documentation of this file.
1 #include <stddef.h>
2 #include <algorithm>
3 
4 #include "src/ir/skeleton/way.h"
5 
6 namespace re2c
7 {
8 
9 static bool cmp_way_arcs (const way_arc_t * a1, const way_arc_t * a2);
10 static void fprint_way_arc (FILE * f, const way_arc_t & arc);
11 
12 bool cmp_way_arcs (const way_arc_t * a1, const way_arc_t * a2)
13 {
14  return std::lexicographical_compare(a1->begin(), a1->end(), a2->begin(), a2->end());
15 }
16 
17 // define strict weak ordering on patterns:
18 // 1st criterion is length (short patterns go first)
19 // 2nd criterion is lexicographical order (applies to patterns of equal length)
20 bool cmp_ways (const way_t & w1, const way_t & w2)
21 {
22  const size_t s1 = w1.size ();
23  const size_t s2 = w2.size ();
24  return (s1 == s2 && std::lexicographical_compare(w1.begin(), w1.end(), w2.begin(), w2.end(), cmp_way_arcs))
25  || s1 < s2;
26 }
27 
28 void fprint_way (FILE * f, const way_t & w)
29 {
30  fprintf (f, "'");
31  const size_t len = w.size ();
32  for (size_t i = 0 ; i < len; ++i)
33  {
34  if (i > 0)
35  {
36  fprintf (f, " ");
37  }
38  if (w[i] == NULL)
39  {
40  fprintf (stderr, "(nil)");
41  }
42  else
43  {
44  fprint_way_arc (stderr, *w[i]);
45  }
46  }
47  fprintf (f, "'");
48 }
49 
50 void fprint_way_arc (FILE * f, const way_arc_t & arc)
51 {
52  const size_t ranges = arc.size ();
53  if (ranges == 1 && arc[0].first == arc[0].second)
54  {
55  fprintf (f, "\\x%X", arc[0].first);
56  }
57  else
58  {
59  fprintf (f, "[");
60  for (size_t i = 0; i < ranges; ++i)
61  {
62  const uint32_t l = arc[i].first;
63  const uint32_t u = arc[i].second;
64  fprintf (f, "\\x%X", l);
65  if (l != u)
66  {
67  fprintf (f, "-\\x%X", u);
68  }
69  }
70  fprintf (f, "]");
71  }
72 }
73 
74 } // namespace re2c
static bool cmp_way_arcs(const way_arc_t *a1, const way_arc_t *a2)
Definition: way.cc:12
static void fprint_way_arc(FILE *f, const way_arc_t &arc)
Definition: way.cc:50
std::vector< const way_arc_t * > way_t
Definition: way.h:13
void fprint_way(FILE *f, const way_t &w)
Definition: way.cc:28
Definition: bitmap.cc:10
std::vector< std::pair< uint32_t, uint32_t > > way_arc_t
Definition: way.h:12
bool cmp_ways(const way_t &w1, const way_t &w2)
Definition: way.cc:20