void Skeleton::emit_prolog (OutputFile & o, uint32_t maxfill) const
{
+ const uint32_t default_rule = sizeof_key == 1
+ ? UINT8_MAX
+ : sizeof_key == 2
+ ? UINT16_MAX
+ : UINT32_MAX;
+
o << "\n" << "#include <stdio.h>";
o << "\n" << "#include <stdlib.h> // malloc, free";
o << "\n" << "#include <string.h> // memset";
o << "\n" << indString << "const long len_act = *cursor - token;";
o << "\n" << indString << "const long len_exp = (long) match_length (keys, i);";
o << "\n" << indString << "const YYKEYTYPE rule_exp = rule (keys, i);";
+ o << "\n" << indString << "if (rule_exp == " << default_rule << ")";
+ o << "\n" << indString << "{";
+ o << "\n" << indString << indString << "fprintf";
+ o << "\n" << indString << indString << indString << "( stderr";
+ o << "\n" << indString << indString << indString << ", \"warning: control flow is undefined for input\"";
+ o << "\n" << indString << indString << indString << indString << "\" at position %ld, rerun re2c with '-W'\\n\"";
+ o << "\n" << indString << indString << indString << ", pos";
+ o << "\n" << indString << indString << indString << ");";
+ o << "\n" << indString << "}";
o << "\n" << indString << "if (len_act == len_exp && rule_act == rule_exp)";
o << "\n" << indString << "{";
o << "\n" << indString << indString << "*cursor = token + length (keys, i);";
o << "\n" << indString << "{";
o << "\n" << indString << indString << "fprintf";
o << "\n" << indString << indString << indString << "( stderr";
- o << "\n" << indString << indString << indString << ", \"error at position %ld (iteration %u):\\n\"";
+ o << "\n" << indString << indString << indString << ", \"error: at position %ld (iteration %u):\\n\"";
o << "\n" << indString << indString << indString << indString << "\"\\texpected: match length %ld, rule %u\\n\"";
o << "\n" << indString << indString << indString << indString << "\"\\tactual: match length %ld, rule %u\\n\"";
o << "\n" << indString << indString << indString << ", pos";
, line (dfa.line)
, nodes_count (dfa.nStates + 1) // +1 for default state
, nodes (new Node [nodes_count])
- , sizeof_key (0)
+ , sizeof_key (4)
{
Node * n;
// initialize size of key
const uint32_t max = std::max (maxlen, maxrule);
- if (max <= UINT8_MAX)
+ if (max < UINT8_MAX)
{
sizeof_key = 1;
}
- else if (max <= UINT16_MAX)
+ else if (max < UINT16_MAX)
{
sizeof_key = 2;
}
- else
- {
- sizeof_key = 4;
- }
}
Skeleton::~Skeleton ()