uint32_t active : 1; // boolean
uint32_t indeg : 27; // the rest; we are unlikely to have more than 2^27 states
uint32_t topord; // state index in fake topological ordering
+ uint32_t coreid; // core state index
void init(size_t r)
{
active = 0;
indeg = 0;
topord = 0;
+ coreid = 0;
}
void make_alt(size_t r, nfa_state_t *s1, nfa_state_t *s2)
std::valarray<Rule> &rules;
std::vector<Tag> &tags;
nfa_state_t *root;
+ uint32_t ncores;
explicit nfa_t(const RESpec &spec);
~nfa_t();
FORBID_COPY(nfa_t);
};
+static const uint32_t NONCORE = ~0u;
+
size_t estimate_size(const std::vector<RE*> &res);
} // namespace re2c
static void calc_indegrees(nfa_state_t *);
static void calc_topord(nfa_state_t *, uint32_t &);
+static void calc_coreid(nfa_state_t *, uint32_t &);
/*
, rules(spec.rules)
, tags(spec.tags)
, root(NULL)
+ , ncores(0)
{
const size_t nre = spec.res.size();
calc_topord(root, topord);
calc_indegrees(root);
}
+ calc_coreid(root, ncores);
}
nfa_t::~nfa_t()
break;
case nfa_state_t::RAN:
calc_topord(n->ran.out, topord);
+ break;
case nfa_state_t::FIN:
break;
}
n->topord = topord++;
}
+void calc_coreid(nfa_state_t *n, uint32_t &coreid)
+{
+ if (n->coreid != 0) return;
+ n->coreid = NONCORE;
+
+ switch (n->type) {
+ case nfa_state_t::NIL:
+ calc_coreid(n->nil.out, coreid);
+ break;
+ case nfa_state_t::ALT:
+ calc_coreid(n->alt.out1, coreid);
+ calc_coreid(n->alt.out2, coreid);
+ break;
+ case nfa_state_t::TAG:
+ calc_coreid(n->tag.out, coreid);
+ break;
+ case nfa_state_t::RAN:
+ n->coreid = coreid++;
+ calc_coreid(n->ran.out, coreid);
+ break;
+ case nfa_state_t::FIN:
+ n->coreid = coreid++;
+ break;
+ }
+}
+
} // namespace re2c