src
Public Types | Public Member Functions | List of all members
re2c::Warn Class Reference

#include <warn.h>

Public Types

enum  type_t {
  W, CONDITION_ORDER, EMPTY_CHARACTER_CLASS, MATCH_EMPTY_STRING,
  SWAPPED_RANGE, UNDEFINED_CONTROL_FLOW, UNREACHABLE_RULES, USELESS_ESCAPE,
  TYPES
}
 
enum  option_t { W, WNO, WERROR, WNOERROR }
 

Public Member Functions

 Warn ()
 
bool error () const
 
void set (type_t t, option_t o)
 
void set_all ()
 
void set_all_error ()
 
void fail (type_t t, uint32_t line, const char *s)
 
void condition_order (uint32_t line)
 
void empty_class (uint32_t line)
 
void match_empty_string (uint32_t line)
 
void swapped_range (uint32_t line, uint32_t l, uint32_t u)
 
void undefined_control_flow (uint32_t line, const std::string &cond, std::vector< way_t > &ways, bool overflow)
 
void unreachable_rule (const std::string &cond, const rule_info_t &rule, const rules_t &rules)
 
void useless_escape (uint32_t line, uint32_t col, char c)
 

Detailed Description

Definition at line 22 of file warn.h.

Member Enumeration Documentation

Enumerator
WNO 
WERROR 
WNOERROR 

Definition at line 32 of file warn.h.

33  {
34  W,
35  WNO,
36  WERROR,
37  WNOERROR
38  };
Enumerator
CONDITION_ORDER 
EMPTY_CHARACTER_CLASS 
MATCH_EMPTY_STRING 
SWAPPED_RANGE 
UNDEFINED_CONTROL_FLOW 
UNREACHABLE_RULES 
USELESS_ESCAPE 
TYPES 

Definition at line 25 of file warn.h.

26  {
27 #define W(x, y) x
29 #undef W
30  TYPES // count
31  };
#define RE2C_WARNING_TYPES
Definition: warn.h:13

Constructor & Destructor Documentation

re2c::Warn::Warn ( )

Definition at line 24 of file warn.cc.

25  : mask ()
26  , error_accuml (false)
27 {
28  for (uint32_t i = 0; i < TYPES; ++i)
29  {
30  mask[i] = SILENT;
31  }
32 }

Member Function Documentation

void re2c::Warn::condition_order ( uint32_t  line)

Definition at line 86 of file warn.cc.

87 {
88  if (mask[CONDITION_ORDER] & WARNING)
89  {
90  const bool e = mask[CONDITION_ORDER] & ERROR;
91  error_accuml |= e;
92  warning (names[CONDITION_ORDER], line, e,
93  "looks like you use hardcoded numbers instead of autogenerated condition names: "
94  "better add '/*!types:re2c*/' directive or '-t, --type-header' option "
95  "and don't rely on fixed condition order.");
96  }
97 }
void warning(const char *type, uint32_t line, bool error, const char *fmt,...)
Definition: msg.cc:48

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::Warn::empty_class ( uint32_t  line)

Definition at line 99 of file warn.cc.

100 {
101  if (mask[EMPTY_CHARACTER_CLASS] & WARNING)
102  {
103  const bool e = mask[EMPTY_CHARACTER_CLASS] & ERROR;
104  error_accuml |= e;
105  warning (names[EMPTY_CHARACTER_CLASS], line, e, "empty character class");
106  }
107 }
void warning(const char *type, uint32_t line, bool error, const char *fmt,...)
Definition: msg.cc:48

Here is the call graph for this function:

bool re2c::Warn::error ( ) const

Definition at line 34 of file warn.cc.

35 {
36  return error_accuml;
37 }

Here is the caller graph for this function:

void re2c::Warn::fail ( type_t  t,
uint32_t  line,
const char *  s 
)

Definition at line 77 of file warn.cc.

78 {
79  if (mask[t] & WARNING)
80  {
81  // -Werror has no effect
82  warning (names[t], line, false, "%s", s);
83  }
84 }
void warning(const char *type, uint32_t line, bool error, const char *fmt,...)
Definition: msg.cc:48

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::Warn::match_empty_string ( uint32_t  line)

Definition at line 109 of file warn.cc.

110 {
111  if (mask[MATCH_EMPTY_STRING] & WARNING)
112  {
113  const bool e = mask[MATCH_EMPTY_STRING] & ERROR;
114  error_accuml |= e;
115  warning (names[MATCH_EMPTY_STRING], line, e, "rule matches empty string");
116  }
117 }
void warning(const char *type, uint32_t line, bool error, const char *fmt,...)
Definition: msg.cc:48

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::Warn::set ( type_t  t,
option_t  o 
)

Definition at line 39 of file warn.cc.

40 {
41  switch (o)
42  {
43  case W:
44  mask[t] |= WARNING;
45  break;
46  case WNO:
47  mask[t] &= ~WARNING;
48  break;
49  case WERROR:
50  // unlike -Werror, -Werror-<warning> implies -W<warning>
51  mask[t] |= (WARNING | ERROR);
52  break;
53  case WNOERROR:
54  mask[t] &= ~ERROR;
55  break;
56  }
57 }
void re2c::Warn::set_all ( )

Definition at line 59 of file warn.cc.

60 {
61  for (uint32_t i = 0; i < TYPES; ++i)
62  {
63  mask[i] |= WARNING;
64  }
65 }
void re2c::Warn::set_all_error ( )

Definition at line 69 of file warn.cc.

70 {
71  for (uint32_t i = 0; i < TYPES; ++i)
72  {
73  mask[i] |= ERROR;
74  }
75 }
void re2c::Warn::swapped_range ( uint32_t  line,
uint32_t  l,
uint32_t  u 
)

Definition at line 119 of file warn.cc.

120 {
121  if (mask[SWAPPED_RANGE] & WARNING)
122  {
123  const bool e = mask[SWAPPED_RANGE] & ERROR;
124  error_accuml |= e;
125  warning (names[SWAPPED_RANGE], line, e, "range lower bound (0x%X) is greater than upper bound (0x%X), swapping", l, u);
126  }
127 }
void warning(const char *type, uint32_t line, bool error, const char *fmt,...)
Definition: msg.cc:48

Here is the call graph for this function:

void re2c::Warn::undefined_control_flow ( uint32_t  line,
const std::string &  cond,
std::vector< way_t > &  ways,
bool  overflow 
)

Definition at line 129 of file warn.cc.

130 {
131  if (mask[UNDEFINED_CONTROL_FLOW] & WARNING)
132  {
133  const bool e = mask[UNDEFINED_CONTROL_FLOW] & ERROR;
134  error_accuml |= e;
135 
136  // report shorter patterns first
137  std::sort (ways.begin (), ways.end (), cmp_ways);
138 
139  warning_start (line, e);
140  fprintf (stderr, "control flow %sis undefined for strings that match ", incond (cond).c_str ());
141  const size_t count = ways.size ();
142  if (count == 1)
143  {
144  fprint_way (stderr, ways[0]);
145  }
146  else
147  {
148  for (size_t i = 0; i < count; ++i)
149  {
150  fprintf (stderr, "\n\t");
151  fprint_way (stderr, ways[i]);
152  }
153  fprintf (stderr, "\n");
154  }
155  if (overflow)
156  {
157  fprintf (stderr, " ... and a few more");
158  }
159  fprintf (stderr, ", use default rule '*'");
161  }
162 }
void warning_start(uint32_t line, bool error)
Definition: msg.cc:32
void warning_end(const char *type, bool error)
Definition: msg.cc:38
void fprint_way(FILE *f, const way_t &w)
Definition: way.cc:28
bool cmp_ways(const way_t &w1, const way_t &w2)
Definition: way.cc:20
std::string incond(const std::string &cond)
Definition: msg.cc:242

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::Warn::unreachable_rule ( const std::string &  cond,
const rule_info_t rule,
const rules_t rules 
)

Definition at line 164 of file warn.cc.

165 {
166  if (mask[UNREACHABLE_RULES] & WARNING)
167  {
168  const bool e = mask[UNREACHABLE_RULES] & ERROR;
169  error_accuml |= e;
170  warning_start (rule.line, e);
171  fprintf (stderr, "unreachable rule %s", incond (cond).c_str ());
172  const size_t shadows = rule.shadow.size ();
173  if (shadows > 0)
174  {
175  const char * pl = shadows > 1
176  ? "s"
177  : "";
178  std::set<rule_rank_t>::const_iterator i = rule.shadow.begin ();
179  fprintf (stderr, "(shadowed by rule%s at line%s %u", pl, pl, rules.find (*i)->second.line);
180  for (++i; i != rule.shadow.end (); ++i)
181  {
182  fprintf (stderr, ", %u", rules.find (*i)->second.line);
183  }
184  fprintf (stderr, ")");
185  }
186  warning_end (names[UNREACHABLE_RULES], e);
187  }
188 }
void warning_start(uint32_t line, bool error)
Definition: msg.cc:32
void warning_end(const char *type, bool error)
Definition: msg.cc:38
std::string incond(const std::string &cond)
Definition: msg.cc:242

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::Warn::useless_escape ( uint32_t  line,
uint32_t  col,
char  c 
)

Definition at line 190 of file warn.cc.

191 {
192  if (mask[USELESS_ESCAPE] & WARNING)
193  {
194  const bool e = mask[USELESS_ESCAPE] & ERROR;
195  error_accuml |= e;
196  warning (names[USELESS_ESCAPE], line, e, "column %u: escape has no effect: '\\%c'", col, c);
197  }
198 }
void warning(const char *type, uint32_t line, bool error, const char *fmt,...)
Definition: msg.cc:48

Here is the call graph for this function:


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