it->second = it->second ? mkAlt (def_rule, it->second) : def_rule;
}
- dfa_map[it->first] = genCode(it->second, o, it->first);
+ dfa_map[it->first] = genCode(it->second, o);
}
if (parseMode != Scanner::Rules && dfa_map.find(it->first) != dfa_map.end())
{
{
if (parseMode != Scanner::Reuse)
{
- dfa_map[""] = genCode(spec, o, "");
+ dfa_map[""] = genCode(spec, o);
}
if (parseMode != Scanner::Rules && dfa_map.find("") != dfa_map.end())
{
head->action.set_initial (initial_label, head->action.type == Action::SAVE);
// Generate prolog
+ skeleton->warn_undefined_control_flow (o.get_block_line (), condName);
if (flag_skeleton)
{
- emit_prolog (o, ind, output.max_fill);
+ skeleton->emit_data (o.get_block_line (), condName, o.file_name);
+ Skeleton::emit_prolog (o, ind, output.max_fill);
}
if (bProlog)
{
}
if (flag_skeleton)
{
- emit_epilog (o, ind);
+ Skeleton::emit_epilog (o, ind);
}
// Cleanup
namespace re2c
{
-void emit_prolog (OutputFile & o, uint32_t ind, uint32_t maxfill)
+void Skeleton::emit_prolog (OutputFile & o, uint32_t ind, uint32_t maxfill)
{
std::string yyctype;
switch (encoding.szCodeUnit ())
o << indent (ind + 2) << "const YYCTYPE * token = cursor;\n";
}
-void emit_epilog (OutputFile & o, uint32_t ind)
+void Skeleton::emit_epilog (OutputFile & o, uint32_t ind)
{
o << indent (ind + 1) << "}\n";
o << "#undef " << mapCodeName["YYCTYPE"] << "\n";
~Skeleton ();
void warn_undefined_control_flow (uint32_t line, const std::string & cond);
void emit_data (uint32_t line, const std::string & cond, const char * fname);
+ static void emit_prolog (OutputFile & o, uint32_t ind, uint32_t maxfill);
+ static void emit_epilog (OutputFile & o, uint32_t ind);
private:
void generate_paths (uint32_t line, const std::string & cond, FILE * input, std::ofstream & keys);
FORBID_COPY (Skeleton);
};
-void emit_prolog (OutputFile & o, uint32_t ind, uint32_t maxfill);
-void emit_epilog (OutputFile & o, uint32_t ind);
-
} // namespace re2c
#endif // _RE2C_CODEGEN_SKELETON_SKELETON_
static void optimize (Ins * i);
-smart_ptr<DFA> genCode (RegExp *re, Output & output, const std::string & cond)
+smart_ptr<DFA> genCode (RegExp *re, Output & output)
{
CharSet cs;
re->split(cs);
smart_ptr<DFA> dfa = make_smart_ptr(new DFA(ins, size, 0, encoding.nCodeUnits(), rep));
- OutputFile & o = output.source;
-
- Skeleton skeleton (*dfa);
- skeleton.warn_undefined_control_flow (o.get_block_line (), cond);
-
- if (flag_skeleton)
- {
- skeleton.emit_data (o.get_block_line (), cond, o.file_name);
- }
-
- dfa->prepare (o, output.max_fill);
+ dfa->prepare (output.source, output.max_fill);
return dfa;
}
namespace re2c
{
-smart_ptr<DFA> genCode (RegExp * re, Output & output, const std::string & cond);
+smart_ptr<DFA> genCode (RegExp * re, Output & output);
} // namespace re2c
#include <string.h>
+#include "src/codegen/skeleton/skeleton.h"
#include "src/ir/dfa/dfa.h"
#include "src/ir/regexp/regexp_rule.h"
#include "src/util/allocate.h"
};
DFA::DFA(Ins *ins, uint32_t ni, uint32_t lb, uint32_t ub, const Char *rep)
- : lbChar(lb)
+ : accepts ()
+ , skeleton (NULL)
+ , lbChar(lb)
, ubChar(ub)
, nStates(0)
, head(NULL)
, toDo(NULL)
, free_ins(ins)
, free_rep(rep)
- , accepts ()
-
{
Ins **work = new Ins * [ni + 1];
uint32_t nc = ub - lb;
delete [] work;
delete [] goTo;
operator delete (span);
+
+ // skeleton must be constructed after DFA construction
+ // but prior to any other DFA transformations
+ skeleton = new Skeleton (*this);
}
DFA::~DFA()
}
delete [] free_ins;
delete [] free_rep;
+
+ delete skeleton;
}
void DFA::addState(State **a, State *s)
namespace re2c
{
+struct Skeleton;
+
class DFA
{
+ accept_t accepts;
+ Skeleton * skeleton;
+
public:
uint32_t lbChar;
uint32_t ubChar;
const Ins * free_ins;
const Char * free_rep;
-protected:
- accept_t accepts;
-
public:
DFA (Ins *, uint32_t, uint32_t, uint32_t, const Char *);
~DFA ();
it->second = it->second ? mkAlt (def_rule, it->second) : def_rule;
}
- dfa_map[it->first] = genCode(it->second, o, it->first);
+ dfa_map[it->first] = genCode(it->second, o);
}
if (parseMode != Scanner::Rules && dfa_map.find(it->first) != dfa_map.end())
{
{
if (parseMode != Scanner::Reuse)
{
- dfa_map[""] = genCode(spec, o, "");
+ dfa_map[""] = genCode(spec, o);
}
if (parseMode != Scanner::Rules && dfa_map.find("") != dfa_map.end())
{
-re2c: warning: line 13: control flow in condition 'r1' is undefined for strings that match '[\x0-\x30\x33-\x60\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
-re2c: warning: line 13: control flow in condition 'r2' is undefined for strings that match '[\x0-\x30\x33-\x61\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
+re2c: warning: line 22: control flow in condition 'r1' is undefined for strings that match '[\x0-\x30\x33-\x60\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
+re2c: warning: line 22: control flow in condition 'r2' is undefined for strings that match '[\x0-\x30\x33-\x61\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
+re2c: warning: line 34: control flow in condition 'r1' is undefined for strings that match '[\x0-\x30\x33-\x60\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
+re2c: warning: line 34: control flow in condition 'r2' is undefined for strings that match '[\x0-\x30\x33-\x61\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
+re2c: warning: line 46: control flow in condition 'r1' is undefined for strings that match '[\x0-\x30\x33-\x60\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
+re2c: warning: line 46: control flow in condition 'r2' is undefined for strings that match '[\x0-\x30\x33-\x61\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
/* Generated by re2c */
// multiple scanners
-re2c: warning: line 13: control flow in condition 'r1' is undefined for strings that match '[\x0-\x30\x33-\x60\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
-re2c: warning: line 13: control flow in condition 'r2' is undefined for strings that match '[\x0-\x30\x33-\x61\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
+re2c: warning: line 20: control flow in condition 'r1' is undefined for strings that match '[\x0-\x30\x33-\x60\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
+re2c: warning: line 20: control flow in condition 'r2' is undefined for strings that match '[\x0-\x30\x33-\x61\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
+re2c: warning: line 32: control flow in condition 'r1' is undefined for strings that match '[\x0-\x30\x33-\x60\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
+re2c: warning: line 32: control flow in condition 'r2' is undefined for strings that match '[\x0-\x30\x33-\x61\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
+re2c: warning: line 44: control flow in condition 'r1' is undefined for strings that match '[\x0-\x30\x33-\x60\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
+re2c: warning: line 44: control flow in condition 'r2' is undefined for strings that match '[\x0-\x30\x33-\x61\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
/* Generated by re2c */
// multiple scanners
-re2c: warning: line 14: control flow in condition 'r1' is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
-re2c: warning: line 14: control flow in condition 'r2' is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
re2c: warning: line 18: control flow in condition 'r1' is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
re2c: warning: line 18: control flow in condition 'r2' is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
re2c: warning: line 28: control flow in condition 'r1' is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
-re2c: warning: line 14: control flow in condition 'r1' is undefined for strings that match '[\x0-\x30\x33-\x60\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
-re2c: warning: line 14: control flow in condition 'r2' is undefined for strings that match '[\x0-\x30\x33-\x61\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
+re2c: warning: line 18: control flow in condition 'r1' is undefined for strings that match '[\x0-\x30\x33-\x60\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
+re2c: warning: line 18: control flow in condition 'r2' is undefined for strings that match '[\x0-\x30\x33-\x61\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
re2c: error: line 20, column 1: cannot have a second 'rules:re2c' block
-re2c: warning: line 14: control flow is undefined for strings that match '[\x0-\x60\x65-\xFF]', use default rule '*' [-Wundefined-control-flow]
re2c: warning: line 24: control flow is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
re2c: warning: line 39: control flow is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
re2c: warning: line 54: control flow is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
-re2c: warning: line 14: control flow is undefined for strings that match '[\x0-\x60\x65-\xFF]', use default rule '*' [-Wundefined-control-flow]
re2c: warning: line 27: control flow is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
re2c: warning: line 45: control flow is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
re2c: warning: line 63: control flow is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
-re2c: warning: line 14: control flow is undefined for strings that match '[\x0-\x60\x65-\xFF]', use default rule '*' [-Wundefined-control-flow]
re2c: warning: line 27: control flow is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
re2c: warning: line 45: control flow is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
re2c: error: line 52, column 17: Cannot set UTF32 encoding: please reset USC2 encoding first
-re2c: warning: line 10: control flow in condition 'r1' is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
-re2c: warning: line 10: control flow in condition 'r2' is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
re2c: error: line 13, column 9: code to default rule 'r1' is already defined
-re2c: warning: line 17: control flow in condition 'r2' is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
re2c: error: line 11, column 9: code to default rule 'r1' is already defined
-re2c: warning: line 10: control flow in condition 'r1' is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
-re2c: warning: line 10: control flow in condition 'r2' is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
re2c: error: line 13, column 9: code to setup rule 'r1' is already defined
-re2c: warning: line 17: control flow in condition 'r1' is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
-re2c: warning: line 17: control flow in condition 'r2' is undefined for strings that match '\xA', use default rule '*' [-Wundefined-control-flow]
re2c: error: line 11, column 9: code to setup rule 'r1' is already defined