src
control_flow.cc
Go to the documentation of this file.
1 #include <map>
2 #include <utility>
3 #include <vector>
4 
5 #include "src/conf/warn.h"
6 #include "src/globals.h"
7 #include "src/ir/rule_rank.h"
8 #include "src/ir/skeleton/path.h"
10 #include "src/ir/skeleton/way.h"
11 #include "src/util/u32lim.h"
12 
13 namespace re2c
14 {
15 
16 // We don't need all patterns that cause undefined behaviour.
17 // We only need some examples, the shorter the better.
18 // See also note [counting skeleton edges].
19 void Node::naked_ways (way_t & prefix, std::vector<way_t> & ways, nakeds_t &size)
20 {
21  if (!rule.rank.is_none ())
22  {
23  return;
24  }
25  else if (end ())
26  {
27  ways.push_back (prefix);
28  size = size + nakeds_t::from64(prefix.size ());
29  }
30  else if (loop < 2)
31  {
32  local_inc _ (loop);
33  for (arcsets_t::iterator i = arcsets.begin ();
34  i != arcsets.end () && !size.overflow (); ++i)
35  {
36  prefix.push_back (&i->second);
37  i->first->naked_ways (prefix, ways, size);
38  prefix.pop_back ();
39  }
40  }
41 }
42 
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 }
60 
61 } // namespace re2c
Node * nodes
Definition: skeleton.h:114
Warn warn
Definition: warn.cc:11
const uint32_t line
Definition: skeleton.h:111
rule_t rule
Definition: skeleton.h:78
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
arcsets_t arcsets
Definition: skeleton.h:71
static u32lim_t from64(uint64_t x)
Definition: u32lim.h:29
uint8_t loop
Definition: skeleton.h:75
const std::string cond
Definition: skeleton.h:110
std::vector< const way_arc_t * > way_t
Definition: way.h:13
bool overflow() const
Definition: u32lim.h:41
bool end() const
Definition: skeleton.cc:67
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
bool is_none() const
Definition: rule_rank.cc:37
void warn_undefined_control_flow()
Definition: control_flow.cc:43
Definition: bitmap.cc:10
rule_rank_t rank
Definition: path.h:14