gen_fintags(o, ind, dfa, rule);
if (opts->target == opt_t::SKELETON) {
- emit_action(*dfa.skeleton, o, ind, rule_idx);
+ emit_action(o, ind, dfa.name, dfa.key_size, dfa.def_rule, rule_idx);
} else {
const std::string &cond = info->newcond;
if (!cond.empty() && dfa.cond != cond) {
if (opts->target == opt_t::SKELETON) {
if (output.skeletons.insert (name).second)
{
- emit_start(*skeleton, o, max_fill, need_backup,
+ emit_start(o, max_fill, name, key_size, def_rule, need_backup,
need_accept, oldstyle_ctxmarker, tagnames, tagvars);
uint32_t i = 2;
emit_body (o, i, used_labels, initial_label);
- emit_end(*skeleton, o, need_backup, oldstyle_ctxmarker);
+ emit_end(o, name, need_backup, oldstyle_ctxmarker);
}
} else if (opts->target == opt_t::DOT) {
emit_dot(o, isLastCond, ob.types);
DFA::DFA
( const dfa_t &dfa
, const std::vector<size_t> &fill
- , Skeleton *skel
+ , size_t def
+ , size_t key
, const charset_t &charset
, const std::string &n
, const std::string &c
, uint32_t l
)
: accepts ()
- , skeleton (skel)
, name (n)
, cond (c)
, line (l)
, need_accept (false)
, oldstyle_ctxmarker (false)
, maxtagver (dfa.maxtagver)
+ , def_rule (def)
+ , key_size (key)
{
const size_t nstates = dfa.states.size();
const size_t nchars = dfa.nchars;
delete s;
}
- delete skeleton;
delete &rules;
delete &tags;
delete &tcpool;
namespace re2c
{
-struct Skeleton;
struct Output;
struct OutputFile;
struct dfa_t;
struct DFA
{
accept_t accepts;
- Skeleton * skeleton;
const std::string name;
const std::string cond;
const uint32_t line;
bool need_accept;
bool oldstyle_ctxmarker;
tagver_t maxtagver;
+ const size_t def_rule;
+ const size_t key_size;
DFA ( const dfa_t &dfa
, const std::vector<size_t> &fill
- , Skeleton *skel
+ , size_t def
+ , size_t key
, const charset_t &charset
, const std::string &n
, const std::string &c
// skeleton must be constructed after DFA construction
// but prior to any other DFA transformations
- Skeleton *skeleton = new Skeleton(dfa, cs, defrule, name, cond, line);
- warn_undefined_control_flow(*skeleton);
+ Skeleton skeleton(dfa, cs, defrule, name, cond, line);
+ warn_undefined_control_flow(skeleton);
if (opts->target == opt_t::SKELETON) {
- emit_data(*skeleton);
+ emit_data(skeleton);
}
cutoff_dead_rules(dfa, defrule, cond);
fillpoints(dfa, fill);
// ADFA stands for 'DFA with actions'
- DFA *adfa = new DFA(dfa, fill, skeleton, cs, name, cond, line);
+ DFA *adfa = new DFA(dfa, fill, defrule, skeleton.sizeof_key, cs, name, cond, line);
// see note [reordering DFA states]
adfa->reorder();
o.ws("\n");
}
-void emit_start(const Skeleton &skel, OutputFile &o, size_t maxfill,
- bool backup, bool accept, bool oldstyle_ctxmarker,
- const std::set<std::string> &tagnames,
- const std::set<std::string> &tagvars)
+void emit_start(OutputFile &o, size_t maxfill, const std::string &name,
+ size_t sizeof_key, size_t def, bool backup, bool accept, bool oldstyle_ctxmarker,
+ const std::set<std::string> &tagnames, const std::set<std::string> &tagvars)
{
- const size_t
- sizeof_cunit = opts->encoding.szCodeUnit(),
- sizeof_key = skel.sizeof_key;
- const size_t norule = skel.rule2key(Rule::NONE);
- const std::string &name = skel.name;
+ const size_t sizeof_cunit = opts->encoding.szCodeUnit();
+ const size_t norule = rule2key(Rule::NONE, sizeof_key, def);
std::string filename = opts->output_file;
if (filename.empty()) {
filename = "<stdout>";
o.ws("\n");
}
-void emit_end(const Skeleton &skel, OutputFile &o, bool backup, bool oldstyle_ctxmarker)
+void emit_end(OutputFile &o, const std::string &name, bool backup, bool oldstyle_ctxmarker)
{
- const std::string &name = skel.name;
-
o.ws("\n").wind(1).ws("}");
o.ws("\n").wind(1).ws("if (status == 0) {");
o.ws("\n").wind(2).ws("if (cursor != eof) {");
o.ws("\n");
}
-void emit_action(const Skeleton &skel, OutputFile &o, uint32_t ind, size_t rule)
+void emit_action(OutputFile &o, uint32_t ind, const std::string &name,
+ size_t key, size_t def, size_t rule)
{
- o.wind(ind).ws("status = action_").wstring(skel.name)
+ o.wind(ind).ws("status = action_").wstring(name)
.ws("(i, keys, input, token, &cursor, ")
- .wu64(skel.rule2key(rule)).ws(");\n");
+ .wu64(rule2key(rule, key, def)).ws(");\n");
o.wind(ind).ws("continue;\n");
}
delete[] buffer;
// keys
- const key_t match = skel.rule2key<key_t>(path.match(skel), skel.defrule);
+ const key_t match = rule2key<key_t>(path.match(skel), skel.defrule);
keygen<key_t>(cover.keys, width, len, path.len_matching(skel), match);
return size;
delete[] nodes;
}
-size_t Skeleton::rule2key(size_t r) const
+size_t rule2key(size_t rule, size_t key, size_t def)
{
- switch (sizeof_key) {
- default: // shouldn't happen
- case 8: return rule2key<uint64_t>(r, defrule);
- case 4: return rule2key<uint32_t>(r, defrule);
- case 2: return rule2key<uint16_t>(r, defrule);
- case 1: return rule2key<uint8_t>(r, defrule);
+ switch (key) {
+ default: assert(false); // shouldn't happen
+ case 8: return rule2key<uint64_t>(rule, def);
+ case 4: return rule2key<uint32_t>(rule, def);
+ case 2: return rule2key<uint16_t>(rule, def);
+ case 1: return rule2key<uint8_t>(rule, def);
}
}
Node *nodes;
size_t sizeof_key;
- const size_t defrule;
+ size_t defrule;
const std::valarray<Rule> &rules;
const std::valarray<Tag> &tags;
const std::string &dfa_name, const std::string &dfa_cond,
uint32_t dfa_line);
~Skeleton ();
- size_t rule2key(size_t r) const;
- template<typename key_t> key_t rule2key(size_t r, size_t def) const;
-
FORBID_COPY(Skeleton);
};
-template<typename key_t> key_t Skeleton::rule2key(size_t r, size_t def) const
+template<typename key_t> key_t rule2key(size_t r, size_t def)
{
if (r == Rule::NONE) {
return std::numeric_limits<key_t>::max();
}
}
+size_t rule2key(size_t rule, size_t key, size_t def);
uint32_t maxpath(const Skeleton &skel);
void warn_undefined_control_flow(const Skeleton &skel);
void fprint_default_path(FILE *f, const Skeleton &skel, const path_t &p);
void emit_data(const Skeleton &skel);
void emit_prolog(OutputFile & o);
-void emit_start(const Skeleton &skel, OutputFile &o, size_t maxfill,
- bool backup, bool accept, bool oldstyle_ctxmarker,
- const std::set<std::string> &tagnames,
- const std::set<std::string> &tagvars);
-void emit_end(const Skeleton &skel, OutputFile &o, bool backup, bool oldstyle_ctxmarker);
+void emit_start(OutputFile &o, size_t maxfill, const std::string &name,
+ size_t sizeof_key, size_t def, bool backup, bool accept, bool oldstyle_ctxmarker,
+ const std::set<std::string> &tagnames, const std::set<std::string> &tagvars);
+void emit_end(OutputFile &o, const std::string &name, bool backup, bool oldstyle_ctxmarker);
void emit_epilog(OutputFile &o, const std::set<std::string> &names);
-void emit_action(const Skeleton &skel, OutputFile &o, uint32_t ind,
- size_t rule);
+void emit_action(OutputFile &o, uint32_t ind, const std::string &name, size_t key, size_t def, size_t rule);
} // namespace re2c