]> granicus.if.org Git - re2c/commitdiff
Parameterize determinization/simulation context directly by history type.
authorUlya Trofimovich <skvadrik@gmail.com>
Mon, 25 Mar 2019 14:32:39 +0000 (14:32 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Mon, 25 Mar 2019 14:32:39 +0000 (14:32 +0000)
lib/regex_impl.h
lib/regexec_nfa_leftmost.cc
lib/regexec_nfa_posix.cc
src/dfa/determinization.cc
src/dfa/determinization.h
src/dfa/tag_history.h

index 50342daee1b78e36af1e6d86fc65d76897cfc261..b1f58faf28c022c51b264159043acf16b4daec9e 100644 (file)
@@ -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<sema_t SEMA, eval_t EVAL>
+template<typename history_type_t>
 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<SEMA, EVAL>::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<POSIX, STRICT> psimctx_t;
-typedef simctx_t<LEFTMOST, STRICT> lsimctx_t;
-typedef simctx_t<POSIX, LAZY> pzsimctx_t;
-typedef simctx_t<LEFTMOST, LAZY> lzsimctx_t;
+typedef simctx_t<phistory_t> psimctx_t;
+typedef simctx_t<lhistory_t> lsimctx_t;
+typedef simctx_t<zhistory_t> pzsimctx_t;
+typedef simctx_t<zhistory_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<sema_t SEMA, eval_t EVAL>
-simctx_t<SEMA, EVAL>::simctx_t(const nfa_t &nfa, const nfa_t *nfa0, size_t re_nsub, int flags)
+template<typename history_t>
+simctx_t<history_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<SEMA, EVAL>::simctx_t(const nfa_t &nfa, const nfa_t *nfa0, size_t re_ns
     }
 }
 
-template<sema_t SEMA, eval_t EVAL>
-simctx_t<SEMA, EVAL>::~simctx_t()
+template<typename history_t>
+simctx_t<history_t>::~simctx_t()
 {
     delete[] done;
     if (!(flags & REG_TRIE)) {
@@ -192,8 +192,8 @@ simctx_t<SEMA, EVAL>::~simctx_t()
     }
 }
 
-template<sema_t SEMA, eval_t EVAL>
-void init(simctx_t<SEMA, EVAL> &ctx, const char *string)
+template<typename history_t>
+void init(simctx_t<history_t> &ctx, const char *string)
 {
     ctx.reach.clear();
     ctx.state.clear();
@@ -209,8 +209,8 @@ void init(simctx_t<SEMA, EVAL> &ctx, const char *string)
     DASSERT(ctx.gtop_heap.empty());
 }
 
-template<sema_t SEMA>
-int finalize(const simctx_t<SEMA, LAZY> &ctx, const char *string, size_t nmatch,
+template<typename history_t>
+int finalize(const simctx_t<history_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<SEMA, LAZY> &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<SEMA, LAZY>::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]) {
index b8a05540c09b3bd99f15c98e75a9ba2e0678c51d..a7ba89d661a6edc92d4825a21058d0180417b1ce 100644 (file)
@@ -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;
index ada21def13dff785592bae50d6dcb0de740912bd..64fb2dc8d0cca3b05f562ddc4c06aef348c58311 100644 (file)
@@ -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);
         }
index 2b9e919f40452382f03da8990f980e645f9059ed..e59e7dc1eb179fa76bb0d8fe42c39cd5bbb87fc5 100644 (file)
@@ -234,8 +234,8 @@ void warn_nondeterministic_tags(const ctx_t &ctx)
     }
 }
 
-template<sema_t SEMA>
-determ_context_t<SEMA>::determ_context_t(const opt_t *opts, Msg &msg
+template<typename history_t>
+determ_context_t<history_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<SEMA>::determ_context_t(const opt_t *opts, Msg &msg
     , dc_kernels()
     , dc_buffers(dc_allocator)
     , dc_hc_caches()
-    , dc_newvers(newver_cmp_t<typename determ_context_t<SEMA>::history_t>(history, dc_hc_caches))
+    , dc_newvers(newver_cmp_t<history_t>(history, dc_hc_caches))
     , dc_path1()
     , dc_path2()
     , dc_path3()
@@ -287,7 +287,7 @@ determ_context_t<SEMA>::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<SEMA>::determ_context_t(const opt_t *opts, Msg &msg
     }
 }
 
-template<sema_t SEMA>
-determ_context_t<SEMA>::~determ_context_t()
+template<typename history_t>
+determ_context_t<history_t>::~determ_context_t()
 {
-    if (SEMA == POSIX) {
-        delete[] newprectbl;
-        delete[] histlevel;
-    }
+    delete[] newprectbl;
+    delete[] histlevel;
 }
 
 } // namespace re2c
index 7f86015fad6502b3432762dc4868790a693296d1..42f3777335b61edb798b89433bd21aed81dd5802 100644 (file)
@@ -119,7 +119,7 @@ typedef lookup_t<const kernel_t*> kernels_t;
 typedef std::priority_queue<nfa_state_t*, std::vector<nfa_state_t*>
     , cmp_gtop_t> gtop_heap_t;
 
-template<sema_t SEMA>
+template<typename history_type_t>
 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<SEMA, STRICT>::type history_t;
+    typedef history_type_t history_t;
     typedef std::map<newver_t, tagver_t, newver_cmp_t<history_t> > newvers_t;
 
     // determinization input
@@ -184,8 +184,8 @@ struct determ_context_t
     FORBID_COPY(determ_context_t);
 };
 
-typedef determ_context_t<POSIX> pdetctx_t;
-typedef determ_context_t<LEFTMOST> ldetctx_t;
+typedef determ_context_t<phistory_t> pdetctx_t;
+typedef determ_context_t<lhistory_t> ldetctx_t;
 
 template<typename ctx_t> void tagged_epsilon_closure(ctx_t &ctx);
 template<typename ctx_t> void find_state(ctx_t &ctx);
index 497c88dd1ba300897253ba0c5b8f96713bdff701..a370fd1193164f9174bb8eedf803dd5ef089e6ff 100644 (file)
@@ -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<sema_t SEMA, eval_t EVAL> struct history_type_t;
-template<> struct history_type_t<POSIX, STRICT> {typedef phistory_t type;};
-template<> struct history_type_t<LEFTMOST, STRICT> {typedef lhistory_t type;};
-template<sema_t SEMA> struct history_type_t<SEMA, LAZY> {typedef zhistory_t type;};
-
 template<typename history_t>
 tagver_t last(const history_t &h, hidx_t i, size_t t)
 {