src
match_empty.cc
Go to the documentation of this file.
1 #include <map>
2 #include <set>
3 
4 #include "src/conf/warn.h"
5 #include "src/globals.h"
6 #include "src/ir/rule_rank.h"
7 #include "src/ir/skeleton/path.h"
9 #include "src/parse/rules.h"
10 
11 namespace re2c
12 {
13 
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 }
48 
49 } // namespace re2c
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
void warn_match_empty()
Definition: match_empty.cc:14
void match_empty_string(uint32_t line)
Definition: warn.cc:109
std::set< rule_t > reachable
Definition: skeleton.h:89
bool end() const
Definition: skeleton.cc:67
rules_t rules
Definition: skeleton.h:116
bool is_none() const
Definition: rule_rank.cc:37
Definition: bitmap.cc:10
rule_rank_t rank
Definition: path.h:14
bool ctx
Definition: skeleton.h:81