src
go.h
Go to the documentation of this file.
1 #ifndef _RE2C_CODEGEN_GO_
2 #define _RE2C_CODEGEN_GO_
3 
4 #include <iostream>
5 #include <set>
6 #include <vector>
7 
8 #include "src/codegen/output.h"
9 #include "src/util/c99_stdint.h"
10 #include "src/util/forbid_copy.h"
11 
12 namespace re2c
13 {
14 
15 class BitMap;
16 class State;
17 struct If;
18 
19 struct Span
20 {
21  uint32_t ub;
22  State * to;
23 
24  FORBID_COPY (Span);
25 };
26 
27 struct Case
28 {
29  std::vector<std::pair<uint32_t, uint32_t> > ranges;
30  const State * to;
31  void emit (OutputFile & o, uint32_t ind);
32 
33  inline Case ()
34  : ranges ()
35  , to (NULL)
36  {}
37 
38  FORBID_COPY (Case);
39 };
40 
41 struct Cases
42 {
43  const State * def;
45  uint32_t cases_size;
46  void add (uint32_t lb, uint32_t ub, State * to);
47  Cases (const Span * s, uint32_t n);
48  ~Cases ();
49  void emit (OutputFile & o, uint32_t ind, bool & readCh);
50  void used_labels (std::set<label_t> & used);
51 
53 };
54 
55 struct Cond
56 {
57  std::string compare;
58  uint32_t value;
59  Cond (const std::string & cmp, uint32_t val);
60 };
61 
62 struct Binary
63 {
65  If * thn;
66  If * els;
67  Binary (const Span * s, uint32_t n, const State * next);
68  ~Binary ();
69  void emit (OutputFile & o, uint32_t ind, bool & readCh);
70  void used_labels (std::set<label_t> & used);
71 
73 };
74 
75 struct Linear
76 {
77  std::vector<std::pair<const Cond *, const State *> > branches;
78  Linear (const Span * s, uint32_t n, const State * next);
79  ~Linear ();
80  void emit (OutputFile & o, uint32_t ind, bool & readCh);
81  void used_labels (std::set<label_t> & used);
82 };
83 
84 struct If
85 {
86  enum type_t
87  {
90  } type;
91  union
92  {
95  } info;
96  If (type_t t, const Span * sp, uint32_t nsp, const State * next);
97  ~If ();
98  void emit (OutputFile & o, uint32_t ind, bool & readCh);
99  void used_labels (std::set<label_t> & used);
100 };
101 
102 struct SwitchIf
103 {
104  enum
105  {
108  } type;
109  union
110  {
112  If * ifs;
113  } info;
114  SwitchIf (const Span * sp, uint32_t nsp, const State * next);
115  ~SwitchIf ();
116  void emit (OutputFile & o, uint32_t ind, bool & readCh);
117  void used_labels (std::set<label_t> & used);
118 };
119 
120 struct GoBitmap
121 {
122  const BitMap * bitmap;
126  GoBitmap (const Span * span, uint32_t nSpans, const Span * hspan, uint32_t hSpans, const BitMap * bm, const State * bm_state, const State * next);
127  ~GoBitmap ();
128  void emit (OutputFile & o, uint32_t ind, bool & readCh);
129  void used_labels (std::set<label_t> & used);
130 
132 };
133 
135 {
136  static const uint32_t TABLE_SIZE;
137  const State ** table;
138  CpgotoTable (const Span * span, uint32_t nSpans);
139  ~CpgotoTable ();
140  void emit (OutputFile & o, uint32_t ind);
141  void used_labels (std::set<label_t> & used);
142 
143 private:
144  label_t max_label () const;
145 
146  FORBID_COPY (CpgotoTable);
147 };
148 
149 struct Cpgoto
150 {
153  Cpgoto (const Span * span, uint32_t nSpans, const Span * hspan, uint32_t hSpans, const State * next);
154  ~Cpgoto ();
155  void emit (OutputFile & o, uint32_t ind, bool & readCh);
156  void used_labels (std::set<label_t> & used);
157 
159 };
160 
161 struct Dot
162 {
163  const State * from;
165  Dot (const Span * sp, uint32_t nsp, const State * from);
166  ~Dot ();
167  void emit (OutputFile & o);
168 
169  FORBID_COPY (Dot);
170 };
171 
172 struct Go
173 {
174  uint32_t nSpans; // number of spans
176  enum
177  {
183  } type;
184  union
185  {
189  Dot * dot;
190  } info;
191 
192  Go ();
193  ~Go ();
194  void init (const State * from);
195  void emit (OutputFile & o, uint32_t ind, bool & readCh);
196  void used_labels (std::set<label_t> & used);
197 
198  Go (const Go & g)
199  : nSpans (g.nSpans)
200  , span (g.span)
201  , type (g.type)
202  , info (g.info)
203  {}
204  Go & operator = (const Go & g)
205  {
206  nSpans = g.nSpans;
207  span = g.span;
208  type = g.type;
209  info = g.info;
210  return * this;
211  }
212 };
213 
214 } // namespace re2c
215 
216 #endif // _RE2C_CODEGEN_GO_
Cond(const std::string &cmp, uint32_t val)
Definition: go_construct.cc:46
If * thn
Definition: go.h:65
void emit(OutputFile &o, uint32_t ind, bool &readCh)
Definition: go_emit.cc:135
static const uint32_t TABLE_SIZE
Definition: go.h:136
Case()
Definition: go.h:33
SwitchIf * hgo
Definition: go.h:124
CpgotoTable * table
Definition: go.h:152
enum re2c::Go::@3 type
void used_labels(std::set< label_t > &used)
uint32_t nSpans
Definition: go.h:174
void used_labels(std::set< label_t > &used)
void emit(OutputFile &o, uint32_t ind, bool &readCh)
Definition: go_emit.cc:119
void init(const State *from)
SwitchIf * hgo
Definition: go.h:151
Cpgoto(const Span *span, uint32_t nSpans, const Span *hspan, uint32_t hSpans, const State *next)
const State * def
Definition: go.h:43
Linear * linear
Definition: go.h:94
std::string compare
Definition: go.h:57
uint32_t value
Definition: go.h:58
void used_labels(std::set< label_t > &used)
uint32_t ub
Definition: go.h:21
Go(const Go &g)
Definition: go.h:198
Definition: go.h:84
void emit(OutputFile &o, uint32_t ind)
Definition: go_emit.cc:195
enum re2c::SwitchIf::@1 type
State * to
Definition: go.h:22
Dot(const Span *sp, uint32_t nsp, const State *from)
void emit(OutputFile &o, uint32_t ind, bool &readCh)
Definition: go_emit.cc:93
Binary * binary
Definition: go.h:93
Go & operator=(const Go &g)
Definition: go.h:204
const State ** table
Definition: go.h:137
void used_labels(std::set< label_t > &used)
uint32_t cases_size
Definition: go.h:45
void emit(OutputFile &o, uint32_t ind, bool &readCh)
Definition: go_emit.cc:161
void emit(OutputFile &o, uint32_t ind, bool &readCh)
Definition: go_emit.cc:220
Definition: go.h:55
FORBID_COPY(Cpgoto)
void emit(OutputFile &o, uint32_t ind, bool &readCh)
Definition: go_emit.cc:109
GoBitmap(const Span *span, uint32_t nSpans, const Span *hspan, uint32_t hSpans, const BitMap *bm, const State *bm_state, const State *next)
void emit(OutputFile &o, uint32_t ind)
Definition: go_emit.cc:71
Linear(const Span *s, uint32_t n, const State *next)
Definition: go_construct.cc:63
Case * cases
Definition: go.h:44
SwitchIf(const Span *sp, uint32_t nsp, const State *next)
Cond * cond
Definition: go.h:64
FORBID_COPY(Span)
SwitchIf * lgo
Definition: go.h:125
void add(uint32_t lb, uint32_t ub, State *to)
Definition: go_construct.cc:31
Definition: go.h:41
void used_labels(std::set< label_t > &used)
FORBID_COPY(Case)
FORBID_COPY(Cases)
SwitchIf * switchif
Definition: go.h:186
Definition: go.h:27
const State * to
Definition: go.h:30
Cases * cases
Definition: go.h:111
If(type_t t, const Span *sp, uint32_t nsp, const State *next)
std::vector< std::pair< const Cond *, const State * > > branches
Definition: go.h:77
const State * bitmap_state
Definition: go.h:123
CpgotoTable(const Span *span, uint32_t nSpans)
Dot * dot
Definition: go.h:189
Cases * cases
Definition: go.h:164
GoBitmap * bitmap
Definition: go.h:187
union re2c::If::@0 info
void used_labels(std::set< label_t > &used)
const BitMap * bitmap
Definition: go.h:122
void used_labels(std::set< label_t > &used)
FORBID_COPY(Binary)
Cases(const Span *s, uint32_t n)
Definition: go_construct.cc:19
void used_labels(std::set< label_t > &used)
union re2c::SwitchIf::@2 info
FORBID_COPY(GoBitmap)
If * els
Definition: go.h:66
FORBID_COPY(Dot)
union re2c::Go::@4 info
Definition: go.h:161
Span * span
Definition: go.h:175
void emit(OutputFile &o, uint32_t ind, bool &readCh)
Definition: go_emit.cc:250
void emit(OutputFile &o)
Definition: go_emit.cc:229
If * ifs
Definition: go.h:112
enum re2c::If::type_t type
std::vector< std::pair< uint32_t, uint32_t > > ranges
Definition: go.h:29
Definition: bitmap.cc:10
type_t
Definition: go.h:86
const State * from
Definition: go.h:163
void used_labels(std::set< label_t > &used)
Definition: go.h:19
void emit(OutputFile &o, uint32_t ind, bool &readCh)
Definition: go_emit.cc:148
Definition: go.h:172
Binary(const Span *s, uint32_t n, const State *next)
Definition: go_construct.cc:51
Cpgoto * cpgoto
Definition: go.h:188