From 42ddca5a0241d66ccc78415a0705c9833da384d2 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Mon, 25 Mar 2019 14:32:39 +0000 Subject: [PATCH] Parameterize determinization/simulation context directly by history type. --- lib/regex_impl.h | 30 +++++++++++++++--------------- lib/regexec_nfa_leftmost.cc | 2 +- lib/regexec_nfa_posix.cc | 2 +- src/dfa/determinization.cc | 18 ++++++++---------- src/dfa/determinization.h | 8 ++++---- src/dfa/tag_history.h | 9 --------- 6 files changed, 29 insertions(+), 40 deletions(-) diff --git a/lib/regex_impl.h b/lib/regex_impl.h index 50342dae..b1f58faf 100644 --- a/lib/regex_impl.h +++ b/lib/regex_impl.h @@ -41,7 +41,7 @@ typedef confset_t::iterator confiter_t; typedef confset_t::const_iterator cconfiter_t; typedef confset_t::const_reverse_iterator rcconfiter_t; -template +template struct simctx_t { typedef libre2c::conf_t conf_t; @@ -50,7 +50,7 @@ struct simctx_t typedef confset_t::const_iterator cconfiter_t; typedef confset_t::reverse_iterator rconfiter_t; typedef confset_t::const_reverse_iterator rcconfiter_t; - typedef typename history_type_t::type history_t; + typedef history_type_t history_t; const nfa_t &nfa; const nfa_t *nfa0; @@ -94,10 +94,10 @@ struct simctx_t FORBID_COPY(simctx_t); }; -typedef simctx_t psimctx_t; -typedef simctx_t lsimctx_t; -typedef simctx_t pzsimctx_t; -typedef simctx_t lzsimctx_t; +typedef simctx_t psimctx_t; +typedef simctx_t lsimctx_t; +typedef simctx_t pzsimctx_t; +typedef simctx_t lzsimctx_t; int regexec_dfa(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags); int regexec_nfa_posix(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags); @@ -106,8 +106,8 @@ int regexec_nfa_posix_backward(const regex_t *preg, const char *string, size_t n int regexec_nfa_leftmost(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags); int regexec_nfa_leftmost_trie(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags); -template -simctx_t::simctx_t(const nfa_t &nfa, const nfa_t *nfa0, size_t re_nsub, int flags) +template +simctx_t::simctx_t(const nfa_t &nfa, const nfa_t *nfa0, size_t re_nsub, int flags) : nfa(nfa) , nfa0(nfa0) , nsub(2 * (re_nsub - 1)) @@ -170,8 +170,8 @@ simctx_t::simctx_t(const nfa_t &nfa, const nfa_t *nfa0, size_t re_ns } } -template -simctx_t::~simctx_t() +template +simctx_t::~simctx_t() { delete[] done; if (!(flags & REG_TRIE)) { @@ -192,8 +192,8 @@ simctx_t::~simctx_t() } } -template -void init(simctx_t &ctx, const char *string) +template +void init(simctx_t &ctx, const char *string) { ctx.reach.clear(); ctx.state.clear(); @@ -209,8 +209,8 @@ void init(simctx_t &ctx, const char *string) DASSERT(ctx.gtop_heap.empty()); } -template -int finalize(const simctx_t &ctx, const char *string, size_t nmatch, +template +int finalize(const simctx_t &ctx, const char *string, size_t nmatch, regmatch_t pmatch[]) { if (ctx.rule == Rule::NONE) { @@ -227,7 +227,7 @@ int finalize(const simctx_t &ctx, const char *string, size_t nmatch, memset(done, 0, ctx.nsub * sizeof(bool)); for (int32_t i = ctx.hidx; todo > 0 && i != HROOT; ) { - const typename simctx_t::history_t::node_t &n = ctx.history.node(i); + const typename history_t::node_t &n = ctx.history.node(i); const Tag &tag = tags[n.info.idx]; const size_t t = tag.ncap; if (!fictive(tag) && t < nmatch * 2 && !done[t]) { diff --git a/lib/regexec_nfa_leftmost.cc b/lib/regexec_nfa_leftmost.cc index b8a05540..a7ba89d6 100644 --- a/lib/regexec_nfa_leftmost.cc +++ b/lib/regexec_nfa_leftmost.cc @@ -115,7 +115,7 @@ void update_offsets(lsimctx_t &ctx, const conf_t &c, uint32_t id) memset(done, 0, nsub * sizeof(bool)); for (int32_t i = c.thist; i != HROOT; ) { - const lsimctx_t::history_t::node_t &n = ctx.history.node(i); + const lhistory_t::node_t &n = ctx.history.node(i); const size_t t = n.info.idx; if (!done[t]) { done[t] = true; diff --git a/lib/regexec_nfa_posix.cc b/lib/regexec_nfa_posix.cc index ada21def..64fb2dc8 100644 --- a/lib/regexec_nfa_posix.cc +++ b/lib/regexec_nfa_posix.cc @@ -183,7 +183,7 @@ void compute_prectbl_naive(psimctx_t &ctx) newtbl[i * newdim + i] = p0; for (uint32_t j = i + 1; j < newdim; ++j) { int32_t prec1, prec2; - int32_t prec = psimctx_t::history_t::precedence(ctx, state[i], state[j], prec1, prec2); + int32_t prec = phistory_t::precedence(ctx, state[i], state[j], prec1, prec2); newtbl[i * newdim + j] = pack(prec1, prec); newtbl[j * newdim + i] = pack(prec2, -prec); } diff --git a/src/dfa/determinization.cc b/src/dfa/determinization.cc index 2b9e919f..e59e7dc1 100644 --- a/src/dfa/determinization.cc +++ b/src/dfa/determinization.cc @@ -234,8 +234,8 @@ void warn_nondeterministic_tags(const ctx_t &ctx) } } -template -determ_context_t::determ_context_t(const opt_t *opts, Msg &msg +template +determ_context_t::determ_context_t(const opt_t *opts, Msg &msg , const std::string &condname, const nfa_t &nfa, dfa_t &dfa) : dc_opts(opts) , dc_msg(msg) @@ -252,7 +252,7 @@ determ_context_t::determ_context_t(const opt_t *opts, Msg &msg , dc_kernels() , dc_buffers(dc_allocator) , dc_hc_caches() - , dc_newvers(newver_cmp_t::history_t>(history, dc_hc_caches)) + , dc_newvers(newver_cmp_t(history, dc_hc_caches)) , dc_path1() , dc_path2() , dc_path3() @@ -287,7 +287,7 @@ determ_context_t::determ_context_t(const opt_t *opts, Msg &msg dc_path3.reserve(ntags); dc_tagcount.resize(ntags); - if (SEMA == POSIX) { + if (opts->posix_semantics) { newprectbl = new prectable_t[ncores * ncores]; histlevel = new histleaf_t[ncores]; sortcores.reserve(ncores); @@ -304,13 +304,11 @@ determ_context_t::determ_context_t(const opt_t *opts, Msg &msg } } -template -determ_context_t::~determ_context_t() +template +determ_context_t::~determ_context_t() { - if (SEMA == POSIX) { - delete[] newprectbl; - delete[] histlevel; - } + delete[] newprectbl; + delete[] histlevel; } } // namespace re2c diff --git a/src/dfa/determinization.h b/src/dfa/determinization.h index 7f86015f..42f37773 100644 --- a/src/dfa/determinization.h +++ b/src/dfa/determinization.h @@ -119,7 +119,7 @@ typedef lookup_t kernels_t; typedef std::priority_queue , cmp_gtop_t> gtop_heap_t; -template +template struct determ_context_t { typedef clos_t conf_t; @@ -128,7 +128,7 @@ struct determ_context_t typedef confset_t::const_iterator cconfiter_t; typedef confset_t::reverse_iterator rconfiter_t; typedef confset_t::const_reverse_iterator rcconfiter_t; - typedef typename history_type_t::type history_t; + typedef history_type_t history_t; typedef std::map > newvers_t; // determinization input @@ -184,8 +184,8 @@ struct determ_context_t FORBID_COPY(determ_context_t); }; -typedef determ_context_t pdetctx_t; -typedef determ_context_t ldetctx_t; +typedef determ_context_t pdetctx_t; +typedef determ_context_t ldetctx_t; template void tagged_epsilon_closure(ctx_t &ctx); template void find_state(ctx_t &ctx); diff --git a/src/dfa/tag_history.h b/src/dfa/tag_history.h index 497c88dd..a370fd11 100644 --- a/src/dfa/tag_history.h +++ b/src/dfa/tag_history.h @@ -21,9 +21,6 @@ const tag_info_t NOINFO = {0x3fffFFFF, 0}; static const uint32_t NONFIN = ~0u; static const uint32_t USED = NONFIN - 1; -enum sema_t {POSIX, LEFTMOST}; -enum eval_t {STRICT, LAZY}; - // tag history for POSIX semantics struct phistory_t { @@ -189,12 +186,6 @@ hidx_t zhistory_t::link(ctx_t &ctx, const typename ctx_t::conf_t &conf) return i; } -// history type selector -template struct history_type_t; -template<> struct history_type_t {typedef phistory_t type;}; -template<> struct history_type_t {typedef lhistory_t type;}; -template struct history_type_t {typedef zhistory_t type;}; - template tagver_t last(const history_t &h, hidx_t i, size_t t) { -- 2.40.0