src
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
re2c::Skeleton Struct Reference

#include <skeleton.h>

Collaboration diagram for re2c::Skeleton:
Collaboration graph
[legend]

Public Member Functions

 Skeleton (const dfa_t &dfa, const charset_t &cs, const rules_t &rs, const std::string &dfa_name, const std::string &dfa_cond, uint32_t dfa_line)
 
 ~Skeleton ()
 
void warn_undefined_control_flow ()
 
void warn_unreachable_rules ()
 
void warn_match_empty ()
 
void emit_data (const char *fname)
 
void emit_start (OutputFile &o, size_t maxfill, bool backup, bool backupctx, bool accept) const
 
void emit_end (OutputFile &o, bool backup, bool backupctx) const
 
void emit_action (OutputFile &o, uint32_t ind, rule_rank_t rank) const
 
uint32_t rule2key (rule_rank_t r) const
 

Static Public Member Functions

static void emit_prolog (OutputFile &o)
 
static void emit_epilog (OutputFile &o, const std::set< std::string > &names)
 
template<typename key_t >
static key_t rule2key (rule_rank_t r)
 

Public Attributes

const std::string name
 
const std::string cond
 
const uint32_t line
 
const size_t nodes_count
 
Nodenodes
 
size_t sizeof_key
 
rules_t rules
 

Detailed Description

Definition at line 107 of file skeleton.h.

Constructor & Destructor Documentation

re2c::Skeleton::Skeleton ( const dfa_t dfa,
const charset_t cs,
const rules_t rs,
const std::string &  dfa_name,
const std::string &  dfa_cond,
uint32_t  dfa_line 
)

Definition at line 73 of file skeleton.cc.

80  : name (dfa_name)
81  , cond (dfa_cond)
82  , line (dfa_line)
83  , nodes_count (dfa.states.size())
84  , nodes (new Node [nodes_count + 1]) // +1 for default state
85  , sizeof_key (4)
86  , rules (rs)
87 {
88  const size_t nc = cs.size() - 1;
89 
90  // initialize skeleton nodes
91  Node *nil = &nodes[nodes_count];
92  for (size_t i = 0; i < nodes_count; ++i)
93  {
94  dfa_state_t *s = dfa.states[i];
95  std::vector<std::pair<Node*, uint32_t> > arcs;
96  for (size_t c = 0; c < nc;)
97  {
98  const size_t j = s->arcs[c];
99  for (;++c < nc && s->arcs[c] == j;);
100  Node *to = j == dfa_t::NIL
101  ? nil
102  : &nodes[j];
103  arcs.push_back(std::make_pair(to, cs[c]));
104  }
105  // all arcs go to default node => this node is final, drop arcs
106  if (arcs.size() == 1 && arcs[0].first == nil)
107  {
108  arcs.clear();
109  }
110  nodes[i].init(s->ctx, s->rule, arcs);
111  }
112 
113  // calculate maximal path length, check overflow
114  nodes->calc_dist ();
115  const uint32_t maxlen = nodes->dist;
116  if (maxlen == Node::DIST_MAX)
117  {
118  error ("DFA path %sis too long", incond (cond).c_str ());
119  exit (1);
120  }
121 
122  // calculate maximal rule rank (disregarding default and none rules)
123  uint32_t maxrule = 0;
124  for (uint32_t i = 0; i < nodes_count; ++i)
125  {
126  const rule_rank_t r = nodes[i].rule.rank;
127  if (!r.is_none () && !r.is_def ())
128  {
129  maxrule = std::max (maxrule, r.uint32 ());
130  }
131  }
132  // two upper values reserved for default and none rules)
133  maxrule += 2;
134 
135  // initialize size of key
136  const uint32_t max = std::max (maxlen, maxrule);
137  if (max <= std::numeric_limits<uint8_t>::max())
138  {
139  sizeof_key = 1;
140  }
141  else if (max <= std::numeric_limits<uint16_t>::max())
142  {
143  sizeof_key = 2;
144  }
145 }
Node * nodes
Definition: skeleton.h:114
void error(const char *fmt,...)
Definition: msg.cc:10
void calc_dist()
Definition: maxlen.cc:18
const uint32_t line
Definition: skeleton.h:111
rule_t rule
Definition: skeleton.h:78
uint32_t dist
Definition: skeleton.h:86
arcs_t arcs
Definition: skeleton.h:70
void init(bool b, RuleOp *r, const std::vector< std::pair< Node *, uint32_t > > &arcs)
Definition: skeleton.cc:26
const std::string cond
Definition: skeleton.h:110
const size_t nodes_count
Definition: skeleton.h:113
static const size_t NIL
Definition: dfa.h:38
rules_t rules
Definition: skeleton.h:116
size_t sizeof_key
Definition: skeleton.h:115
static const uint32_t DIST_MAX
Definition: skeleton.h:85
rule_rank_t rank
Definition: path.h:14
const std::string name
Definition: skeleton.h:109
std::string incond(const std::string &cond)
Definition: msg.cc:242

Here is the call graph for this function:

re2c::Skeleton::~Skeleton ( )

Definition at line 147 of file skeleton.cc.

148 {
149  delete [] nodes;
150 }
Node * nodes
Definition: skeleton.h:114

Member Function Documentation

void re2c::Skeleton::emit_action ( OutputFile o,
uint32_t  ind,
rule_rank_t  rank 
) const

Definition at line 317 of file generate_code.cc.

318 {
319  o.wind(ind).ws("status = action_").wstring(name).ws("(i, keys, input, token, &cursor, ").wu32(rule2key (rank)).ws(");\n");
320  o.wind(ind).ws("continue;\n");
321 }
static key_t rule2key(rule_rank_t r)
Definition: skeleton.h:160
const std::string name
Definition: skeleton.h:109

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::Skeleton::emit_data ( const char *  fname)

Definition at line 127 of file generate_data.cc.

128 {
129  const std::string input_name = std::string (fname) + "." + name + ".input";
130  FILE * input = fopen (input_name.c_str (), "wb");
131  if (!input)
132  {
133  error ("cannot open file: %s", input_name.c_str ());
134  exit (1);
135  }
136  const std::string keys_name = std::string (fname) + "." + name + ".keys";
137  FILE * keys = fopen (keys_name.c_str (), "wb");
138  if (!keys)
139  {
140  error ("cannot open file: %s", keys_name.c_str ());
141  exit (1);
142  }
143 
144  generate_paths (input, keys);
145 
146  fclose (input);
147  fclose (keys);
148 }
void error(const char *fmt,...)
Definition: msg.cc:10
const std::string name
Definition: skeleton.h:109

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::Skeleton::emit_end ( OutputFile o,
bool  backup,
bool  backupctx 
) const

Definition at line 256 of file generate_code.cc.

260 {
261  o.ws("\n").wind(1).ws("}");
262  o.ws("\n").wind(1).ws("if (status == 0) {");
263  o.ws("\n").wind(2).ws("if (cursor != eof) {");
264  o.ws("\n").wind(3).ws("status = 1;");
265  o.ws("\n").wind(3).ws("const long pos = token - input;");
266  o.ws("\n").wind(3).ws("fprintf(stderr, \"error: lex_").wstring(name).ws(": unused input strings left at position %ld\\n\", pos);");
267  o.ws("\n").wind(2).ws("}");
268  o.ws("\n").wind(2).ws("if (i != keys_count) {");
269  o.ws("\n").wind(3).ws("status = 1;");
270  o.ws("\n").wind(3).ws("fprintf(stderr, \"error: lex_").wstring(name).ws(": unused keys left after %u iterations\\n\", i);");
271  o.ws("\n").wind(2).ws("}");
272  o.ws("\n").wind(1).ws("}");
273  o.ws("\n");
274  o.ws("\nend:");
275  o.ws("\n").wind(1).ws("free(input);");
276  o.ws("\n").wind(1).ws("free(keys);");
277  o.ws("\n");
278  o.ws("\n").wind(1).ws("return status;");
279  o.ws("\n}");
280  o.ws("\n");
281  o.ws("\n#undef YYCTYPE");
282  o.ws("\n#undef YYKEYTYPE");
283  o.ws("\n#undef YYPEEK");
284  o.ws("\n#undef YYSKIP");
285  if (backup)
286  {
287  o.ws("\n#undef YYBACKUP");
288  o.ws("\n#undef YYRESTORE");
289  }
290  if (backupctx)
291  {
292  o.ws("\n#undef YYBACKUPCTX");
293  o.ws("\n#undef YYRESTORECTX");
294  }
295  o.ws("\n#undef YYLESSTHAN");
296  o.ws("\n#undef YYFILL");
297  o.ws("\n");
298 }
const std::string name
Definition: skeleton.h:109

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::Skeleton::emit_epilog ( OutputFile o,
const std::set< std::string > &  names 
)
static

Definition at line 300 of file generate_code.cc.

301 {
302  o.ws("\n").ws("int main()");
303  o.ws("\n").ws("{");
304 
305  for (std::set<std::string>::const_iterator i = names.begin (); i != names.end (); ++i)
306  {
307  o.ws("\n").wind(1).ws("if(lex_").wstring(*i).ws("() != 0) {");
308  o.ws("\n").wind(2).ws("return 1;");
309  o.ws("\n").wind(1).ws("}");
310  }
311 
312  o.ws("\n").wind(1).ws("return 0;");
313  o.ws("\n}");
314  o.ws("\n");
315 }

Here is the call graph for this function:

void re2c::Skeleton::emit_prolog ( OutputFile o)
static

Definition at line 54 of file generate_code.cc.

55 {
56  o.ws("\n#include <stdio.h>");
57  o.ws("\n#include <stdlib.h> /* malloc, free */");
58  o.ws("\n");
59  o.ws("\nstatic void *read_file");
60  o.ws("\n").wind(1).ws("( const char *fname");
61  o.ws("\n").wind(1).ws(", size_t unit");
62  o.ws("\n").wind(1).ws(", size_t padding");
63  o.ws("\n").wind(1).ws(", size_t *pfsize");
64  o.ws("\n").wind(1).ws(")");
65  o.ws("\n{");
66  o.ws("\n").wind(1).ws("void *buffer = NULL;");
67  o.ws("\n").wind(1).ws("size_t fsize = 0;");
68  o.ws("\n");
69  o.ws("\n").wind(1).ws("/* open file */");
70  o.ws("\n").wind(1).ws("FILE *f = fopen(fname, \"rb\");");
71  o.ws("\n").wind(1).ws("if(f == NULL) {");
72  o.ws("\n").wind(2).ws("goto error;");
73  o.ws("\n").wind(1).ws("}");
74  o.ws("\n");
75  o.ws("\n").wind(1).ws("/* get file size */");
76  o.ws("\n").wind(1).ws("fseek(f, 0, SEEK_END);");
77  o.ws("\n").wind(1).ws("fsize = (size_t) ftell(f) / unit;");
78  o.ws("\n").wind(1).ws("fseek(f, 0, SEEK_SET);");
79  o.ws("\n");
80  o.ws("\n").wind(1).ws("/* allocate memory for file and padding */");
81  o.ws("\n").wind(1).ws("buffer = malloc(unit * (fsize + padding));");
82  o.ws("\n").wind(1).ws("if (buffer == NULL) {");
83  o.ws("\n").wind(2).ws("goto error;");
84  o.ws("\n").wind(1).ws("}");
85  o.ws("\n");
86  o.ws("\n").wind(1).ws("/* read the whole file in memory */");
87  o.ws("\n").wind(1).ws("if (fread(buffer, unit, fsize, f) != fsize) {");
88  o.ws("\n").wind(2).ws("goto error;");
89  o.ws("\n").wind(1).ws("}");
90  o.ws("\n");
91  o.ws("\n").wind(1).ws("fclose(f);");
92  o.ws("\n").wind(1).ws("*pfsize = fsize;");
93  o.ws("\n").wind(1).ws("return buffer;");
94  o.ws("\n");
95  o.ws("\nerror:");
96  o.ws("\n").wind(1).ws("fprintf(stderr, \"error: cannot read file '%s'\\n\", fname);");
97  o.ws("\n").wind(1).ws("free(buffer);");
98  o.ws("\n").wind(1).ws("if (f != NULL) {");
99  o.ws("\n").wind(2).ws("fclose(f);");
100  o.ws("\n").wind(1).ws("}");
101  o.ws("\n").wind(1).ws("return NULL;");
102  o.ws("\n}");
103  o.ws("\n");
104 }

Here is the call graph for this function:

void re2c::Skeleton::emit_start ( OutputFile o,
size_t  maxfill,
bool  backup,
bool  backupctx,
bool  accept 
) const

Definition at line 107 of file generate_code.cc.

113 {
114  const size_t sizeof_cunit = opts->encoding.szCodeUnit();
115  const uint32_t default_rule = rule2key (rule_rank_t::none ());
116 
117  o.ws("\n#define YYCTYPE ");
118  exact_uint (o, sizeof_cunit);
119  o.ws("\n#define YYKEYTYPE ");
120  exact_uint (o, sizeof_key);
121  o.ws("\n#define YYPEEK() *cursor");
122  o.ws("\n#define YYSKIP() ++cursor");
123  if (backup)
124  {
125  o.ws("\n#define YYBACKUP() marker = cursor");
126  o.ws("\n#define YYRESTORE() cursor = marker");
127  }
128  if (backupctx)
129  {
130  o.ws("\n#define YYBACKUPCTX() ctxmarker = cursor");
131  o.ws("\n#define YYRESTORECTX() cursor = ctxmarker");
132  }
133  o.ws("\n#define YYLESSTHAN(n) (limit - cursor) < n");
134  o.ws("\n#define YYFILL(n) { break; }");
135  o.ws("\n");
136  o.ws("\nstatic int action_").wstring(name);
137  o.ws("\n").wind(1).ws("( unsigned int i");
138  o.ws("\n").wind(1).ws(", const YYKEYTYPE *keys");
139  o.ws("\n").wind(1).ws(", const YYCTYPE *start");
140  o.ws("\n").wind(1).ws(", const YYCTYPE *token");
141  o.ws("\n").wind(1).ws(", const YYCTYPE **cursor");
142  o.ws("\n").wind(1).ws(", YYKEYTYPE rule_act");
143  o.ws("\n").wind(1).ws(")");
144  o.ws("\n{");
145  o.ws("\n").wind(1).ws("const long pos = token - start;");
146  o.ws("\n").wind(1).ws("const long len_act = *cursor - token;");
147  o.ws("\n").wind(1).ws("const long len_exp = (long) keys [3 * i + 1];");
148  o.ws("\n").wind(1).ws("const YYKEYTYPE rule_exp = keys [3 * i + 2];");
149  o.ws("\n").wind(1).ws("if (rule_exp == ").wu32(default_rule).ws(") {");
150  o.ws("\n").wind(2).ws("fprintf");
151  o.ws("\n").wind(3).ws("( stderr");
152  o.ws("\n").wind(3).ws(", \"warning: lex_").wstring(name).ws(": control flow is undefined for input\"");
153  o.ws("\n").wind(4).ws("\" at position %ld, rerun re2c with '-W'\\n\"");
154  o.ws("\n").wind(3).ws(", pos");
155  o.ws("\n").wind(3).ws(");");
156  o.ws("\n").wind(1).ws("}");
157  o.ws("\n").wind(1).ws("if (len_act == len_exp && rule_act == rule_exp) {");
158  o.ws("\n").wind(2).ws("const YYKEYTYPE offset = keys[3 * i];");
159  o.ws("\n").wind(2).ws("*cursor = token + offset;");
160  o.ws("\n").wind(2).ws("return 0;");
161  o.ws("\n").wind(1).ws("} else {");
162  o.ws("\n").wind(2).ws("fprintf");
163  o.ws("\n").wind(3).ws("( stderr");
164  o.ws("\n").wind(3).ws(", \"error: lex_").wstring(name).ws(": at position %ld (iteration %u):\\n\"");
165  o.ws("\n").wind(4).ws("\"\\texpected: match length %ld, rule %u\\n\"");
166  o.ws("\n").wind(4).ws("\"\\tactual: match length %ld, rule %u\\n\"");
167  o.ws("\n").wind(3).ws(", pos");
168  o.ws("\n").wind(3).ws(", i");
169  o.ws("\n").wind(3).ws(", len_exp");
170  o.ws("\n").wind(3).ws(", rule_exp");
171  o.ws("\n").wind(3).ws(", len_act");
172  o.ws("\n").wind(3).ws(", rule_act");
173  o.ws("\n").wind(3).ws(");");
174  o.ws("\n").wind(2).ws("return 1;");
175  o.ws("\n").wind(1).ws("}");
176  o.ws("\n}");
177  o.ws("\n");
178  o.ws("\nint lex_").wstring(name).ws("()");
179  o.ws("\n{");
180  o.ws("\n").wind(1).ws("const size_t padding = ").wu64(maxfill).ws("; /* YYMAXFILL */");
181  o.ws("\n").wind(1).ws("int status = 0;");
182  o.ws("\n").wind(1).ws("size_t input_len = 0;");
183  o.ws("\n").wind(1).ws("size_t keys_count = 0;");
184  o.ws("\n").wind(1).ws("YYCTYPE *input = NULL;");
185  o.ws("\n").wind(1).ws("YYKEYTYPE *keys = NULL;");
186  o.ws("\n").wind(1).ws("const YYCTYPE *cursor = NULL;");
187  o.ws("\n").wind(1).ws("const YYCTYPE *limit = NULL;");
188  o.ws("\n").wind(1).ws("const YYCTYPE *token = NULL;");
189  o.ws("\n").wind(1).ws("const YYCTYPE *eof = NULL;");
190  o.ws("\n").wind(1).ws("unsigned int i = 0;");
191  o.ws("\n");
192  o.ws("\n").wind(1).ws("input = (YYCTYPE *) read_file");
193  o.ws("\n").wind(2).ws("(\"").wstring(o.file_name).ws(".").wstring(name).ws(".input\"");
194  o.ws("\n").wind(2).ws(", sizeof (YYCTYPE)");
195  o.ws("\n").wind(2).ws(", padding");
196  o.ws("\n").wind(2).ws(", &input_len");
197  o.ws("\n").wind(2).ws(");");
198  o.ws("\n").wind(1).ws("if (input == NULL) {");
199  o.ws("\n").wind(2).ws("status = 1;");
200  o.ws("\n").wind(2).ws("goto end;");
201  o.ws("\n").wind(1).ws("}");
202  o.ws("\n");
203  if (sizeof_cunit > 1)
204  {
205  o.ws("\n").wind(1).ws("for (i = 0; i < input_len; ++i) {");
206  from_le(o, 2, sizeof_cunit, "input[i]");
207  o.ws("\n").wind(1).ws("}");
208  o.ws("\n");
209  }
210  o.ws("\n").wind(1).ws("keys = (YYKEYTYPE *) read_file");
211  o.ws("\n").wind(2).ws("(\"").wstring(o.file_name).ws(".").wstring(name).ws(".keys\"");
212  o.ws("\n").wind(2).ws(", 3 * sizeof (YYKEYTYPE)");
213  o.ws("\n").wind(2).ws(", 0");
214  o.ws("\n").wind(2).ws(", &keys_count");
215  o.ws("\n").wind(2).ws(");");
216  o.ws("\n").wind(1).ws("if (keys == NULL) {");
217  o.ws("\n").wind(2).ws("status = 1;");
218  o.ws("\n").wind(2).ws("goto end;");
219  o.ws("\n").wind(1).ws("}");
220  o.ws("\n");
221  if (sizeof_key > 1)
222  {
223  o.ws("\n").wind(1).ws("for (i = 0; i < 3 * keys_count; ++i) {");
224  from_le(o, 2, sizeof_key, "keys[i]");
225  o.ws("\n").wind(1).ws("}");
226  o.ws("\n");
227  }
228  o.ws("\n").wind(1).ws("cursor = input;");
229  o.ws("\n").wind(1).ws("limit = input + input_len + padding;");
230  o.ws("\n").wind(1).ws("eof = input + input_len;");
231  o.ws("\n");
232  o.ws("\n").wind(1).ws("for (i = 0; status == 0 && i < keys_count; ++i) {");
233  o.ws("\n").wind(2).ws("token = cursor;");
234  if (backup)
235  {
236  o.ws("\n").wind(2).ws("const YYCTYPE *marker = NULL;");
237  }
238  if (backupctx)
239  {
240  o.ws("\n").wind(2).ws("const YYCTYPE *ctxmarker = NULL;");
241  }
242  o.ws("\n").wind(2).ws("YYCTYPE yych;");
243  if (accept)
244  {
245  o.ws("\n").wind(2).ws("unsigned int yyaccept = 0;");
246  }
247  o.ws("\n");
248  if (opts->bFlag && BitMap::first)
249  {
250  BitMap::gen (o, 2, 0, std::min (0x100u, opts->encoding.nCodeUnits ()));
251  }
252  o.ws("\n");
253 }
bool bFlag
Definition: opt.h:118
static void from_le(OutputFile &o, uint32_t ind, size_t size, const char *expr)
static key_t rule2key(rule_rank_t r)
Definition: skeleton.h:160
static void gen(OutputFile &, uint32_t ind, uint32_t, uint32_t)
Definition: bitmap.cc:75
static void exact_uint(OutputFile &o, size_t width)
uint32_t szCodeUnit() const
Definition: enc.h:152
Enc encoding
Definition: opt.h:118
uint32_t nCodeUnits() const
Definition: enc.h:123
Opt opts
Definition: opt.cc:7
static BitMap * first
Definition: bitmap.h:19
static rule_rank_t none()
Definition: rule_rank.cc:23
size_t sizeof_key
Definition: skeleton.h:115
const std::string name
Definition: skeleton.h:109

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename key_t >
key_t re2c::Skeleton::rule2key ( rule_rank_t  r)
static

Definition at line 160 of file skeleton.h.

161 {
162  if (r.is_none()) {
163  return std::numeric_limits<key_t>::max();
164  } else if (r.is_def()) {
165  key_t k = std::numeric_limits<key_t>::max();
166  return --k;
167  } else {
168  return static_cast<key_t>(r.uint32());
169  }
170 }

Here is the call graph for this function:

Here is the caller graph for this function:

uint32_t re2c::Skeleton::rule2key ( rule_rank_t  r) const

Definition at line 152 of file skeleton.cc.

153 {
154  switch (sizeof_key)
155  {
156  default: // shouldn't happen
157  case 4: return rule2key<uint32_t> (r);
158  case 2: return rule2key<uint16_t> (r);
159  case 1: return rule2key<uint8_t> (r);
160  }
161 }
size_t sizeof_key
Definition: skeleton.h:115
void re2c::Skeleton::warn_match_empty ( )

Definition at line 14 of file match_empty.cc.

15 {
16  Node & head = nodes[0];
17 
18  head.calc_reachable ();
19  const std::set<rule_t> & reach = head.reachable;
20 
21  // warn about rules that match empty string
22  if (!head.rule.rank.is_none ())
23  {
24  bool reachable = head.end ();
25  for (std::set<rule_t>::const_iterator i = reach.begin ();
26  !reachable && i != reach.end (); ++i)
27  {
28  reachable |= i->rank.is_none ();
29  }
30  if (reachable)
31  {
32  warn.match_empty_string (rules[head.rule.rank].line);
33  }
34  }
35 
36  // warn about rules that match empty string with nonempty trailing context
37  if (head.ctx)
38  {
39  for (std::set<rule_t>::const_iterator i = reach.begin (); i != reach.end (); ++i)
40  {
41  if (i->restorectx)
42  {
43  warn.match_empty_string (rules[i->rank].line);
44  }
45  }
46  }
47 }
Node * nodes
Definition: skeleton.h:114
void calc_reachable()
Definition: unreachable.cc:16
Warn warn
Definition: warn.cc:11
void match_empty_string(uint32_t line)
Definition: warn.cc:109
rules_t rules
Definition: skeleton.h:116

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::Skeleton::warn_undefined_control_flow ( )

Definition at line 43 of file control_flow.cc.

44 {
45  way_t prefix;
46  std::vector<way_t> ways;
48 
49  nodes->naked_ways (prefix, ways, size);
50 
51  if (!ways.empty ())
52  {
53  warn.undefined_control_flow (line, cond, ways, size.overflow ());
54  }
55  else if (size.overflow ())
56  {
57  warn.fail (Warn::UNDEFINED_CONTROL_FLOW, line, "DFA is too large to check undefined control flow");
58  }
59 }
Node * nodes
Definition: skeleton.h:114
Warn warn
Definition: warn.cc:11
const uint32_t line
Definition: skeleton.h:111
static u32lim_t from32(uint32_t x)
Definition: u32lim.h:28
void undefined_control_flow(uint32_t line, const std::string &cond, std::vector< way_t > &ways, bool overflow)
Definition: warn.cc:129
u32lim_t< 1024 > nakeds_t
Definition: skeleton.h:63
const std::string cond
Definition: skeleton.h:110
std::vector< const way_arc_t * > way_t
Definition: way.h:13
void fail(type_t t, uint32_t line, const char *s)
Definition: warn.cc:77
void naked_ways(way_t &prefix, std::vector< way_t > &ways, nakeds_t &size)
Definition: control_flow.cc:19

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::Skeleton::warn_unreachable_rules ( )

Definition at line 37 of file unreachable.cc.

38 {
40  for (uint32_t i = 0; i < nodes_count; ++i)
41  {
42  const rule_rank_t r1 = nodes[i].rule.rank;
43  const std::set<rule_t> & rs = nodes[i].reachable;
44  for (std::set<rule_t>::const_iterator j = rs.begin (); j != rs.end (); ++j)
45  {
46  const rule_rank_t r2 = j->rank;
47  if (r1 == r2 || r2.is_none ())
48  {
49  rules[r1].reachable = true;
50  }
51  else
52  {
53  rules[r1].shadow.insert (r2);
54  }
55  }
56  }
57 
58  // warn about unreachable rules:
59  // - rules that are shadowed by other rules, e.g. rule '[a]' is shadowed by '[a] [^]'
60  // - infinite rules that consume infinitely many characters and fail on YYFILL, e.g. '[^]*'
61  // - rules that contain never-matching link, e.g. '[]' with option '--empty-class match-none'
62  // default rule '*' should not be reported
63  for (rules_t::const_iterator i = rules.begin (); i != rules.end (); ++i)
64  {
65  const rule_rank_t r = i->first;
66  if (!r.is_none () && !r.is_def () && !rules[r].reachable)
67  {
68  warn.unreachable_rule (cond, i->second, rules);
69  }
70  }
71 }
Node * nodes
Definition: skeleton.h:114
void calc_reachable()
Definition: unreachable.cc:16
Warn warn
Definition: warn.cc:11
rule_t rule
Definition: skeleton.h:78
const std::string cond
Definition: skeleton.h:110
std::set< rule_t > reachable
Definition: skeleton.h:89
const size_t nodes_count
Definition: skeleton.h:113
void unreachable_rule(const std::string &cond, const rule_info_t &rule, const rules_t &rules)
Definition: warn.cc:164
rules_t rules
Definition: skeleton.h:116
rule_rank_t rank
Definition: path.h:14

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

const std::string re2c::Skeleton::cond

Definition at line 110 of file skeleton.h.

const uint32_t re2c::Skeleton::line

Definition at line 111 of file skeleton.h.

const std::string re2c::Skeleton::name

Definition at line 109 of file skeleton.h.

Node* re2c::Skeleton::nodes

Definition at line 114 of file skeleton.h.

const size_t re2c::Skeleton::nodes_count

Definition at line 113 of file skeleton.h.

rules_t re2c::Skeleton::rules

Definition at line 116 of file skeleton.h.

size_t re2c::Skeleton::sizeof_key

Definition at line 115 of file skeleton.h.


The documentation for this struct was generated from the following files: