From: Ulya Trofimovich Date: Mon, 18 Feb 2019 22:15:50 +0000 (+0000) Subject: libre2c: simplified construction of configurations. X-Git-Tag: 1.2~160 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=94a431f43a25c2c707bab7867df9713cbd22d74e;p=re2c libre2c: simplified construction of configurations. --- diff --git a/re2c/lib/regex_impl.h b/re2c/lib/regex_impl.h index 82401848..4cfd0a0d 100644 --- a/re2c/lib/regex_impl.h +++ b/re2c/lib/regex_impl.h @@ -41,6 +41,10 @@ struct conf_t nfa_state_t *state; uint32_t origin; int32_t thist; + + inline conf_t(): state(NULL), origin(0), thist(history_t::ROOT) {} + inline conf_t(nfa_state_t *s, uint32_t o, int32_t h) + : state(s), origin(o), thist(h) {} }; struct ran_or_fin_t diff --git a/re2c/lib/regexec_nfa_leftmost.cc b/re2c/lib/regexec_nfa_leftmost.cc index 7f2bff69..70432b50 100644 --- a/re2c/lib/regexec_nfa_leftmost.cc +++ b/re2c/lib/regexec_nfa_leftmost.cc @@ -19,7 +19,7 @@ int regexec_nfa_leftmost(const regex_t *preg, const char *string { simctx_t ctx(preg, string); - const conf_t c0 = {ctx.nfa->root, 0, history_t::ROOT}; + const conf_t c0(ctx.nfa->root, 0, history_t::ROOT); ctx.reach.push_back(c0); closure_leftmost(ctx); @@ -75,7 +75,7 @@ void reach_on_symbol(simctx_t &ctx, uint32_t sym) if (s->type == nfa_state_t::RAN) { for (const Range *r = s->ran.ran; r; r = r->next()) { if (r->lower() <= sym && sym < r->upper()) { - conf_t c = {s->ran.out, s->coreid, history_t::ROOT}; + conf_t c(s->ran.out, s->coreid, history_t::ROOT); reach.push_back(c); update_offsets(ctx, *i); break; @@ -97,9 +97,11 @@ void closure_leftmost(simctx_t &ctx) state.clear(); for (; !wl.empty(); ) { - conf_t x = wl.back(); - wl.pop_back(); + const conf_t &x = wl.back(); nfa_state_t *n = x.state; + const uint32_t o = x.origin; + const int32_t h = x.thist; + wl.pop_back(); if (n->clos != NOCLOS) continue; @@ -108,19 +110,15 @@ void closure_leftmost(simctx_t &ctx) switch (n->type) { case nfa_state_t::NIL: - x.state = n->nil.out; - wl.push_back(x); + wl.push_back(conf_t(n->nil.out, o, h)); break; case nfa_state_t::ALT: - x.state = n->alt.out2; - wl.push_back(x); - x.state = n->alt.out1; - wl.push_back(x); + wl.push_back(conf_t(n->alt.out2, o, h)); + wl.push_back(conf_t(n->alt.out1, o, h)); break; case nfa_state_t::TAG: - x.state = n->tag.out; - x.thist = ctx.hist.push(x.thist, ctx.step, n->tag.info, x.origin); - wl.push_back(x); + wl.push_back(conf_t(n->tag.out, o + , ctx.hist.push(h, ctx.step, n->tag.info, o))); break; default: break; diff --git a/re2c/lib/regexec_nfa_posix.cc b/re2c/lib/regexec_nfa_posix.cc index 6b23e6be..6b03498e 100644 --- a/re2c/lib/regexec_nfa_posix.cc +++ b/re2c/lib/regexec_nfa_posix.cc @@ -40,7 +40,7 @@ int regexec_nfa_posix(const regex_t *preg, const char *string simctx_t ctx(preg, string); const nfa_t *nfa = ctx.nfa; - const conf_t c0 = {nfa->root, 0, history_t::ROOT}; + const conf_t c0(nfa->root, 0, history_t::ROOT); ctx.reach.push_back(c0); closure_posix(ctx); @@ -102,7 +102,7 @@ void reach_on_symbol(simctx_t &ctx, uint32_t sym) if (s->type == nfa_state_t::RAN) { for (const Range *r = s->ran.ran; r; r = r->next()) { if (r->lower() <= sym && sym < r->upper()) { - conf_t c = {s->ran.out, s->coreid, history_t::ROOT}; + const conf_t c(s->ran.out, s->coreid, history_t::ROOT); reach.push_back(c); state[j++] = *i; break; @@ -190,38 +190,39 @@ inline bool cmp_gor1_t::operator()(const conf_t &x, const conf_t &y) const bool scan(simctx_t &ctx, nfa_state_t *q, bool all) { bool any = false; - conf_t x = ctx.state[q->clos]; + + const conf_t &x = ctx.state[q->clos]; + const uint32_t o = x.origin; + const int32_t h = x.thist; + switch (q->type) { case nfa_state_t::NIL: if (q->arcidx == 0) { - x.state = q->nil.out; - any |= relax_gor1(ctx, x); + any |= relax_gor1(ctx, conf_t(q->nil.out, o, h)); ++q->arcidx; } break; case nfa_state_t::ALT: if (q->arcidx == 0) { - x.state = q->alt.out1; - any |= relax_gor1(ctx, x); + any |= relax_gor1(ctx, conf_t(q->alt.out1, o, h)); ++q->arcidx; } if (q->arcidx == 1 && (!any || all)) { - x.state = q->alt.out2; - any |= relax_gor1(ctx, x); + any |= relax_gor1(ctx, conf_t(q->alt.out2, o, h)); ++q->arcidx; } break; case nfa_state_t::TAG: if (q->arcidx == 0) { - x.state = q->tag.out; - x.thist = ctx.hist.push(x.thist, ctx.step, q->tag.info, x.origin); - any |= relax_gor1(ctx, x); + any |= relax_gor1(ctx, conf_t(q->tag.out, o + , ctx.hist.push(h, ctx.step, q->tag.info, o))); ++q->arcidx; } break; default: break; } + return any; } @@ -270,23 +271,22 @@ void closure_posix_gtop(simctx_t &ctx) nfa_state_t *q = heap.top(); heap.pop(); q->active = 0; - conf_t x = state[q->clos]; + + const conf_t &x = state[q->clos]; + const uint32_t o = x.origin; + const int32_t h = x.thist; switch (q->type) { case nfa_state_t::NIL: - x.state = q->nil.out; - relax_gtop(ctx, x); + relax_gtop(ctx, conf_t(q->nil.out, o, h)); break; case nfa_state_t::ALT: - x.state = q->alt.out1; - relax_gtop(ctx, x); - x.state = q->alt.out2; - relax_gtop(ctx, x); + relax_gtop(ctx, conf_t(q->alt.out1, o, h)); + relax_gtop(ctx, conf_t(q->alt.out2, o, h)); break; case nfa_state_t::TAG: - x.state = q->tag.out; - x.thist = ctx.hist.push(x.thist, ctx.step, q->tag.info, x.origin); - relax_gtop(ctx, x); + relax_gtop(ctx, conf_t(q->tag.out, o + , ctx.hist.push(h, ctx.step, q->tag.info, o))); break; default: break; diff --git a/re2c/lib/regexec_nfa_posix_trie.cc b/re2c/lib/regexec_nfa_posix_trie.cc index f251436b..68422656 100644 --- a/re2c/lib/regexec_nfa_posix_trie.cc +++ b/re2c/lib/regexec_nfa_posix_trie.cc @@ -56,7 +56,7 @@ int regexec_nfa_posix_trie(const regex_t *preg, const char *string const nfa_t *nfa = ctx.nfa; confset_t &state = ctx.state; - const conf_t c0 = {nfa->root, index(nfa, nfa->root), history_t::ROOT}; + const conf_t c0(nfa->root, index(nfa, nfa->root), history_t::ROOT); ctx.reach.push_back(c0); closure_posix(ctx); @@ -94,7 +94,7 @@ void reach_on_symbol(simctx_t &ctx, uint32_t sym) if (s->type == nfa_state_t::RAN) { for (const Range *r = s->ran.ran; r; r = r->next()) { if (r->lower() <= sym && sym < r->upper()) { - conf_t c = {s->ran.out, index(nfa, s), i->thist}; + const conf_t c(s->ran.out, index(nfa, s), i->thist); reach.push_back(c); break; } @@ -119,23 +119,22 @@ void closure_posix(simctx_t &ctx) nfa_state_t *q = heap.top(); heap.pop(); q->active = 0; - conf_t x = state[q->clos]; + + const conf_t &x = state[q->clos]; + const uint32_t o = x.origin; + const int32_t h = x.thist; switch (q->type) { case nfa_state_t::NIL: - x.state = q->nil.out; - relax(ctx, x); + relax(ctx, conf_t(q->nil.out, o, h)); break; case nfa_state_t::ALT: - x.state = q->alt.out1; - relax(ctx, x); - x.state = q->alt.out2; - relax(ctx, x); + relax(ctx, conf_t(q->alt.out1, o, h)); + relax(ctx, conf_t(q->alt.out2, o, h)); break; case nfa_state_t::TAG: - x.state = q->tag.out; - x.thist = ctx.hist.push(x.thist, ctx.step, q->tag.info, x.origin); - relax(ctx, x); + relax(ctx, conf_t(q->tag.out, o + , ctx.hist.push(h, ctx.step, q->tag.info, o))); break; case nfa_state_t::FIN: ctx.marker = ctx.cursor + 1;