src
path.h
Go to the documentation of this file.
1 #ifndef _RE2C_IR_SKELETON_PATH_
2 #define _RE2C_IR_SKELETON_PATH_
3 
4 #include <vector>
5 
6 #include "src/ir/rule_rank.h"
7 #include "src/util/c99_stdint.h"
8 
9 namespace re2c
10 {
11 
12 struct rule_t
13 {
15  bool restorectx;
16 
17  rule_t (rule_rank_t r, bool c)
18  : rank (r)
19  , restorectx (c)
20  {}
21 
22  // needed by STL containers
23  // same as 'std::pair' comparator
24  bool operator < (const rule_t & r) const
25  {
26  return rank < r.rank
27  || (!(r.rank < rank) && restorectx < r.restorectx);
28  }
29 };
30 
31 class path_t
32 {
33 public:
34  typedef std::vector<uint32_t> arc_t;
35 
36 private:
37  std::vector<const arc_t *> arcs;
38 
39  rule_t rule;
40  size_t rule_pos;
41 
42  bool ctx;
43  size_t ctx_pos;
44 
45 public:
46  explicit path_t (rule_t r, bool c)
47  : arcs ()
48  , rule (r)
49  , rule_pos (0)
50  , ctx (c)
51  , ctx_pos (0)
52  {}
53  size_t len () const
54  {
55  return arcs.size ();
56  }
57  size_t len_matching () const
58  {
59  return rule.restorectx
60  ? ctx_pos
61  : rule_pos;
62  }
63  rule_rank_t match () const
64  {
65  return rule.rank;
66  }
67  const arc_t * operator [] (size_t i) const
68  {
69  return arcs[i];
70  }
71  void extend (rule_t r, bool c, const arc_t * a)
72  {
73  arcs.push_back (a);
74  if (!r.rank.is_none ())
75  {
76  rule = r;
77  rule_pos = arcs.size ();
78  }
79  if (c)
80  {
81  ctx = true;
82  ctx_pos = arcs.size ();
83  }
84  }
85  void append (const path_t * p)
86  {
87  if (!p->rule.rank.is_none ())
88  {
89  rule = p->rule;
90  rule_pos = arcs.size () + p->rule_pos;
91  }
92  if (p->ctx)
93  {
94  ctx = true;
95  ctx_pos = arcs.size () + p->ctx_pos;
96  }
97  arcs.insert (arcs.end (), p->arcs.begin (), p->arcs.end ());
98  }
99 };
100 
101 } // namespace re2c
102 
103 #endif // _RE2C_IR_SKELETON_PATH_
void append(const path_t *p)
Definition: path.h:85
rule_rank_t match() const
Definition: path.h:63
path_t(rule_t r, bool c)
Definition: path.h:46
bool restorectx
Definition: path.h:15
rule_t(rule_rank_t r, bool c)
Definition: path.h:17
bool operator<(const rule_t &r) const
Definition: path.h:24
size_t len() const
Definition: path.h:53
size_t len_matching() const
Definition: path.h:57
std::vector< uint32_t > arc_t
Definition: path.h:34
void extend(rule_t r, bool c, const arc_t *a)
Definition: path.h:71
const arc_t * operator[](size_t i) const
Definition: path.h:67
bool is_none() const
Definition: rule_rank.cc:37
Definition: bitmap.cc:10
rule_rank_t rank
Definition: path.h:14