src
maxlen.cc
Go to the documentation of this file.
1 #include "src/util/c99_stdint.h"
2 #include <algorithm>
3 #include <limits>
4 #include <map>
5 #include <utility>
6 
8 
9 namespace re2c
10 {
11 
12 // 0 < DIST_MAX < DIST_ERROR <= std::numeric_limits<uint32_t>::max()
13 const uint32_t Node::DIST_ERROR = std::numeric_limits<uint32_t>::max();
14 const uint32_t Node::DIST_MAX = DIST_ERROR - 1;
15 
16 // different from YYMAXFILL calculation
17 // in the way it handles loops and empty regexp
19 {
20  if (dist != DIST_ERROR)
21  {
22  return;
23  }
24  else if (end ())
25  {
26  dist = 0;
27  }
28  else if (loop < 2)
29  {
30  local_inc _ (loop);
31  for (arcs_t::iterator i = arcs.begin (); i != arcs.end (); ++i)
32  {
33  i->first->calc_dist ();
34  if (i->first->dist != DIST_ERROR)
35  {
36  if (dist == DIST_ERROR)
37  {
38  dist = i->first->dist;
39  }
40  else
41  {
42  dist = std::max (dist, i->first->dist);
43  }
44  }
45  }
46  dist = std::min (dist + 1, DIST_MAX);
47  }
48 }
49 
50 } // namespace re2c
void calc_dist()
Definition: maxlen.cc:18
uint32_t dist
Definition: skeleton.h:86
arcs_t arcs
Definition: skeleton.h:70
uint8_t loop
Definition: skeleton.h:75
static const uint32_t DIST_ERROR
Definition: skeleton.h:84
bool end() const
Definition: skeleton.cc:67
static const uint32_t DIST_MAX
Definition: skeleton.h:85
Definition: bitmap.cc:10