, ubChar(charset.back())
, nStates(0)
, head(NULL)
- , contexts(dfa.contexts)
, rules(dfa.rules)
+ , contexts(dfa.contexts)
// statistics
, max_fill (0)
#include "src/util/c99_stdint.h"
#include <set>
#include <string>
+#include <valarray>
#include "src/codegen/go.h"
#include "src/codegen/label.h"
uint32_t ubChar;
uint32_t nStates;
State * head;
+ std::valarray<Rule> &rules;
std::vector<CtxVar> &contexts;
- std::vector<Rule> &rules;
// statistics
size_t max_fill;
const std::string &cond)
: states()
, nchars(charset.size() - 1) // (n + 1) bounds for n ranges
- , contexts(nfa.contexts)
, rules(nfa.rules)
+ , contexts(nfa.contexts)
{
std::map<size_t, std::set<size_t> > s2rules;
ord_hash_set_t kernels;
#define _RE2C_IR_DFA_DFA_
#include "src/util/c99_stdint.h"
+#include <valarray>
#include <vector>
#include <set>
std::vector<dfa_state_t*> states;
const size_t nchars;
+ std::valarray<Rule> &rules;
std::vector<CtxVar> &contexts;
- std::vector<Rule> &rules;
dfa_t(const nfa_t &nfa, const charset_t &charset,
uint32_t line, const std::string &cond);
namespace re2c
{
-static const size_t INFINITY = std::numeric_limits<size_t>::max();
-static const size_t UNDEFINED = INFINITY - 1;
+static const size_t SCC_INF = std::numeric_limits<size_t>::max();
+static const size_t SCC_UND = SCC_INF - 1;
static bool loopback(size_t node, size_t narcs, const size_t *arcs)
{
* We use lowlink to hold different kinds of information:
* - values in range [0 .. stack size] mean that this node is on stack
* (link to a node with the smallest index reachable from this one)
- * - UNDEFINED means that this node has not been visited yet
- * - INFINITY means that this node has already been popped off stack
+ * - SCC_UND means that this node has not been visited yet
+ * - SCC_INF means that this node has already been popped off stack
*
* We use stack size (rather than topological sort index) as unique index
* of a node on stack. This is safe because indices of nodes on stack are
* still unique and less than indices of nodes that have been popped off
- * stack (INFINITY).
+ * stack (SCC_INF).
*
*/
static void scc(
const size_t j = arcs[c];
if (j != dfa_t::NIL)
{
- if (lowlink[j] == UNDEFINED)
+ if (lowlink[j] == SCC_UND)
{
scc(dfa, stack, lowlink, trivial, j);
}
{
j = stack.top();
stack.pop();
- lowlink[j] = INFINITY;
+ lowlink[j] = SCC_INF;
}
while (j != i);
}
std::vector<size_t> &fill,
size_t i)
{
- if (fill[i] == UNDEFINED)
+ if (fill[i] == SCC_UND)
{
fill[i] = 0;
const size_t *arcs = dfa.states[i]->arcs;
// find DFA states that belong to non-trivial SCC
std::stack<size_t> stack;
- std::vector<size_t> lowlink(size, UNDEFINED);
+ std::vector<size_t> lowlink(size, SCC_UND);
std::vector<bool> trivial(size, false);
scc(dfa, stack, lowlink, trivial, 0);
// for each DFA state, calculate YYFILL argument:
// maximal path length to the next YYFILL state
- fill.resize(size, UNDEFINED);
+ fill.resize(size, SCC_UND);
calc_fill(dfa, trivial, fill, 0);
// The following states must trigger YYFILL:
static nfa_state_t *compile_rule(
const RegExpRule *rule,
- nfa_t &nfa)
+ nfa_t &nfa,
+ size_t nrule)
{
const std::vector<const RegExp*> &rs = rule->regexps;
const std::vector<const std::string*> &ctxnames = rule->ctxnames;
}
}
+ Rule &r = nfa.rules[nrule];
+ r.info = rule->info;
+
nfa_state_t *t = &nfa.states[nfa.size++];
- const size_t nrule = nfa.rules.size();
t->fin(nrule);
- Rule r(rule->info);
std::vector<size_t> &ctxvar = r.ctxvar;
std::vector<CtxFix> &ctxfix = r.ctxfix;
}
r.nullable = null;
- nfa.rules.push_back(r);
-
return t;
}
nfa_state_t *s = NULL;
const size_t nrs = rs.size();
if (nrs > 0) {
- s = compile_rule(rs[0], nfa);
+ s = compile_rule(rs[0], nfa, 0);
for (size_t i = 1; i < nrs; ++i) {
nfa_state_t *q = &nfa.states[nfa.size++];
- q->alt(s, compile_rule(rs[i], nfa));
+ q->alt(s, compile_rule(rs[i], nfa, i));
s = q;
}
}
: max_size(calc_size_all(rs))
, size(0)
, states(new nfa_state_t[max_size])
- , rules(*new std::vector<Rule>)
+ , rules(*new std::valarray<Rule>(rs.size()))
, contexts(*new std::vector<CtxVar>)
, root(compile_rules(rs, *this))
{}
#include <stddef.h>
#include "src/util/c99_stdint.h"
+#include <valarray>
#include <vector>
#include "src/ir/rule.h"
const size_t max_size;
size_t size;
nfa_state_t *states;
- std::vector<Rule> &rules;
+ std::valarray<Rule> &rules;
std::vector<CtxVar> &contexts;
nfa_state_t *root;
std::set<uint32_t> shadow;
bool reachable;
- explicit Rule(const RuleInfo *i)
- : info(i)
+ Rule()
+ : info(NULL)
, ctxvar()
, ctxfix()
, trail()
, shadow()
, reachable(false)
{}
- Rule (const Rule &rule)
- : info(rule.info)
- , ctxvar(rule.ctxvar)
- , ctxfix(rule.ctxfix)
- , trail(rule.trail)
- , nullable(rule.nullable)
- , shadow(rule.shadow)
- , reachable(rule.reachable)
- {}
- Rule& operator=(const Rule &rule)
- {
- info = rule.info;
- ctxvar = rule.ctxvar;
- ctxfix = rule.ctxfix;
- trail = rule.trail;
- nullable = rule.nullable;
- shadow = rule.shadow;
- reachable = rule.reachable;
- return *this;
- }
-// FORBID_COPY(Rule);
+ FORBID_COPY(Rule);
};
} // namespace re2c
#include <map>
#include <set>
#include <string>
+#include <valarray>
#include <vector>
#include <utility>
Node *nodes;
size_t sizeof_key;
- std::vector<Rule> &rules;
+ std::valarray<Rule> &rules;
const size_t defrule;
std::vector<CtxVar> &contexts;
std::vector<std::set<size_t> > reachs(nnodes);
calc_reachable(skel, loops, reachs, 0);
- std::vector<Rule> &rules = skel.rules;
+ std::valarray<Rule> &rules = skel.rules;
const size_t nrules = rules.size();
for (size_t i = 0; i < nnodes; ++i) {