src/dfa/determinization.h \
src/dfa/dfa.h \
src/dfa/dump.h \
- src/dfa/tagpool.h \
- src/dfa/tagtree.h \
+ src/dfa/tag_history.h \
+ src/dfa/tagver_table.h \
src/dfa/tcmd.h \
src/nfa/nfa.h \
src/re/encoding/case.h \
src/dfa/fillpoints.cc \
src/dfa/find_state.cc \
src/dfa/minimization.cc \
- src/dfa/tagpool.cc \
- src/dfa/tagtree.cc \
+ src/dfa/tag_history.cc \
+ src/dfa/tagver_table.cc \
src/dfa/tcmd.cc \
src/re/encoding/enc.cc \
src/re/encoding/range_suffix.cc \
#include "src/conf/opt.h"
#include "src/dfa/determinization.h"
#include "src/dfa/dfa.h"
-#include "src/dfa/tagpool.h"
#include "src/dfa/tcmd.h"
#include "src/nfa/nfa.h"
#include "src/re/rule.h"
case nfa_state_t::TAG:
if (q->arcidx == 0) {
x.state = q->tag.out;
- x.tlook = ctx.dc_tagtrie.push(x.tlook, q->tag.info);
+ x.tlook = ctx.dc_taghistory.push(x.tlook, q->tag.info);
p = relax(ctx, x);
++q->arcidx;
}
break;
case nfa_state_t::TAG:
x.state = n->tag.out;
- x.tlook = ctx.dc_tagtrie.push(x.tlook, n->tag.info);
+ x.tlook = ctx.dc_taghistory.push(x.tlook, n->tag.info);
todo.push(x);
break;
case nfa_state_t::RAN:
const std::vector<Tag> &tags = dfa.tags;
const size_t ntag = tags.size();
tagver_t &maxver = dfa.maxtagver;
- Tagpool &tagpool = ctx.dc_tagpool;
- tagver_t *vers = tagpool.buffer;
+ tagver_table_t &tvtbl = ctx.dc_tagvertbl;
+ tagver_t *vers = tvtbl.buffer;
closure_t &clos = ctx.dc_closure;
- tagtree_t &tagtree = ctx.dc_tagtrie;
+ tag_history_t &thist = ctx.dc_taghistory;
newvers_t &newvers = ctx.dc_newvers;
clositer_t b = clos.begin(), e = clos.end(), c;
- newver_cmp_t cmp(tagtree);
+ newver_cmp_t cmp(thist);
newvers_t newacts(cmp);
tcmd_t *cmd = NULL;
const hidx_t l = c->tlook, h = c->ttran;
if (h == HROOT) continue;
- const tagver_t *vs = tagpool[c->tvers];
+ const tagver_t *vs = tvtbl[c->tvers];
for (size_t t = 0; t < ntag; ++t) {
const Tag &tag = tags[t];
const tagver_t
- h0 = tagtree.last(h, t),
- l0 = tagtree.last(l, t);
+ h0 = thist.last(h, t),
+ l0 = thist.last(l, t);
if (h0 == TAGVER_ZERO) continue;
const hidx_t h = i->first.history;
const size_t t = i->first.tag;
if (history(tags[t])) {
- cmd = dfa.tcpool.make_add(cmd, abs(m), abs(v), tagtree, h, t);
+ cmd = dfa.tcpool.make_add(cmd, abs(m), abs(v), thist, h, t);
} else {
- cmd = dfa.tcpool.make_set(cmd, abs(m), tagtree.last(h, t));
+ cmd = dfa.tcpool.make_set(cmd, abs(m), thist.last(h, t));
}
}
// mark tags with history
for (newvers_t::iterator j = newvers.begin(); j != newvers.end(); ++j) {
- if (history(tags[j->first.tag])) dfa.mtagvers.insert(abs(j->second));
+ if (history(tags[j->first.tag])) {
+ dfa.mtagvers.insert(abs(j->second));
+ }
}
// update tag versions in closure
const hidx_t h = c->ttran;
if (h == HROOT) continue;
- const tagver_t *vs = tagpool[c->tvers];
+ const tagver_t *vs = tvtbl[c->tvers];
for (size_t t = 0; t < ntag; ++t) {
const tagver_t
v0 = vs[t],
- h0 = tagtree.last(h, t),
+ h0 = thist.last(h, t),
v = history(tags[t]) ? v0 : TAGVER_ZERO;
if (h0 == TAGVER_ZERO) {
vers[t] = v0;
vers[t] = newvers[x];
}
}
- c->tvers = tagpool.insert(vers);
+ c->tvers = tvtbl.insert(vers);
}
ctx.dc_actions = cmd;
#include "src/dfa/dfa.h"
#include "src/dfa/determinization.h"
#include "src/dfa/dump.h"
-#include "src/dfa/tagpool.h"
-#include "src/dfa/tagtree.h"
#include "src/dfa/tcmd.h"
#include "src/nfa/nfa.h"
#include "src/re/rule.h"
const size_t ntags = dfa.tags.size();
// all-zero tag configuration must have static number zero
- assert(ZERO_TAGS == ctx.dc_tagpool.insert_const(TAGVER_ZERO));
+ assert(ZERO_TAGS == ctx.dc_tagvertbl.insert_const(TAGVER_ZERO));
// initial tag versions: [1 .. N]
- const uint32_t INITIAL_TAGS = ctx.dc_tagpool.insert_succ(1);
+ const uint32_t INITIAL_TAGS = ctx.dc_tagvertbl.insert_succ(1);
// other versions: [ .. -(N + 1)] and [N + 1 .. ]
dfa.maxtagver = static_cast<tagver_t>(ntags);
for (size_t t = rule.ltag; t < rule.htag; ++t) {
uniq.clear();
for (size_t m = l; m < u; ++m) {
- uniq.insert(ctx.dc_tagpool[v[m]][t]);
+ uniq.insert(ctx.dc_tagvertbl[v[m]][t]);
}
maxv[t] = std::max(maxv[t], uniq.size());
}
, dc_reached()
, dc_closure()
, dc_prectbl(NULL)
- , dc_tagpool(nfa.tags.size())
- , dc_tagtrie()
+ , dc_tagvertbl(nfa.tags.size())
+ , dc_taghistory()
, dc_kernels()
, dc_buffers(dc_allocator)
- , dc_newvers(newver_cmp_t(dc_tagtrie))
+ , dc_newvers(newver_cmp_t(dc_taghistory))
, dc_stack_topsort()
, dc_stack_linear()
, dc_stack_dfs()
#include "src/nfa/nfa.h"
#include "src/dfa/dump.h"
-#include "src/dfa/tagpool.h"
-#include "src/dfa/tagtree.h"
+#include "src/dfa/tagver_table.h"
+#include "src/dfa/tag_history.h"
#include "src/util/forbid_copy.h"
#include "src/util/lookup.h"
#include "src/util/slab_allocator.h"
struct newver_cmp_t
{
- tagtree_t &history;
+ tag_history_t &history;
- explicit newver_cmp_t(tagtree_t &h) : history(h) {}
+ explicit newver_cmp_t(tag_history_t &h) : history(h) {}
bool operator()(const newver_t &, const newver_t &) const;
};
struct determ_context_t
{
// determinization input
- const opt_t *dc_opts; // options
- Warn &dc_warn; // warnings
- const std::string &dc_condname; // the name of current condition (with -c)
- const nfa_t &dc_nfa; // TNFA
+ const opt_t *dc_opts; // options
+ Warn &dc_warn; // warnings
+ const std::string &dc_condname; // the name of current condition (with -c)
+ const nfa_t &dc_nfa; // TNFA
// determinization output
- dfa_t &dc_dfa; // resulting TDFA
+ dfa_t &dc_dfa; // resulting TDFA
// temporary structures used by determinization
allocator_t dc_allocator;
- uint32_t dc_origin; // from-state of the current transition
- uint32_t dc_target; // to-state of the current transition
- uint32_t dc_symbol; // alphabet symbol of the current transition
- tcmd_t *dc_actions; // tag actions of the current transition
+ uint32_t dc_origin; // from-state of the current transition
+ uint32_t dc_target; // to-state of the current transition
+ uint32_t dc_symbol; // alphabet symbol of the current transition
+ tcmd_t *dc_actions; // tag actions of the current transition
closure_t dc_reached;
closure_t dc_closure;
- prectable_t *dc_prectbl; // precedence table for Okui POSIX disambiguation
- Tagpool dc_tagpool;
- tagtree_t dc_tagtrie; // prefix trie of tag histories
- kernels_t dc_kernels; // TDFA states under construction
+ prectable_t *dc_prectbl; // precedence table for Okui POSIX disambiguation
+ tagver_table_t dc_tagvertbl;
+ tag_history_t dc_taghistory; // prefix trie of tag histories
+ kernels_t dc_kernels; // TDFA states under construction
kernel_buffers_t dc_buffers;
newvers_t dc_newvers;
std::stack<nfa_state_t*> dc_stack_topsort;
struct nfa_t;
struct opt_t;
-struct Tagpool;
struct dfa_state_t
{
#include "src/dfa/dfa.h"
#include "src/dfa/determinization.h"
#include "src/dfa/dump.h"
-#include "src/dfa/tagpool.h"
-#include "src/dfa/tagtree.h"
+#include "src/dfa/tag_history.h"
+#include "src/dfa/tagver_table.h"
#include "src/dfa/tcmd.h"
#include "src/nfa/nfa.h"
#include "src/re/rule.h"
static void dump_tcmd_or_tcid(tcmd_t *const *, const tcid_t *, size_t, const tcpool_t &);
static const char *tagname(const Tag &);
-static void dump_tags(const Tagpool &, const tagtree_t &, hidx_t, uint32_t);
+static void dump_tags(const tagver_table_t &, const tag_history_t &, hidx_t, uint32_t);
dump_dfa_t::dump_dfa_t(const opt_t *opts)
}
-static void dump_history(const dfa_t &dfa, const tagtree_t &h, hidx_t i)
+static void dump_history(const dfa_t &dfa, const tag_history_t &h, hidx_t i)
{
if (i == HROOT) {
fprintf(stderr, " /");
const uint32_t target = ctx.dc_target;
const uint32_t symbol = ctx.dc_symbol;
const dfa_t &dfa = ctx.dc_dfa;
- const Tagpool &tagpool = ctx.dc_tagpool;
+ const tagver_table_t &tvtbl = ctx.dc_tagvertbl;
+ const tag_history_t &thist = ctx.dc_taghistory;
uint32_t i;
if (target == dfa_t::NIL) return;
i, style, static_cast<uint32_t>(c->state - ctx.dc_nfa.states));
if (c->tvers != ZERO_TAGS) {
- const tagver_t *vers = tagpool[c->tvers];
+ const tagver_t *vers = tvtbl[c->tvers];
const size_t ntag = dfa.tags.size();
for (size_t t = 0; t < ntag; ++t) {
}
if (c->tlook != HROOT) {
- dump_history(dfa, ctx.dc_tagtrie, c->tlook);
+ dump_history(dfa, thist, c->tlook);
}
}
uint32_t i = 0;
for (c = b; c != e; ++c, ++i) {
fprintf(stderr, " void -> 0:%u:w [style=dotted label=\"", i);
- dump_tags(tagpool, ctx.dc_tagtrie, c->ttran, c->tvers);
+ dump_tags(tvtbl, thist, c->ttran, c->tvers);
fprintf(stderr, "\"]\n");
}
}
fprintf(stderr,
" %u:%u:e -> %s%u:%u:w [label=\"%u",
origin, c->origin, prefix, state, i, symbol);
- dump_tags(tagpool, ctx.dc_tagtrie, c->ttran, c->tvers);
+ dump_tags(tvtbl, thist, c->ttran, c->tvers);
fprintf(stderr, "\"]\n");
}
}
}
-void dump_tags(const Tagpool &tagpool, const tagtree_t &tagtrie,
+void dump_tags(const tagver_table_t &tagvertbl, const tag_history_t &taghistory,
hidx_t ttran, uint32_t tvers)
{
if (ttran == HROOT) return;
fprintf(stderr, "/");
- const tagver_t *vers = tagpool[tvers];
- for (size_t i = 0; i < tagpool.ntags; ++i) {
+ const tagver_t *vers = tagvertbl[tvers];
+ for (size_t i = 0; i < tagvertbl.ntags; ++i) {
- if (tagtrie.last(ttran, i) == TAGVER_ZERO) {
+ if (taghistory.last(ttran, i) == TAGVER_ZERO) {
continue;
}
fprintf(stderr, "%d", abs(vers[i]));
- for (hidx_t t = ttran; t != HROOT; t = tagtrie.pred(t)) {
- if (tagtrie.tag(t) != i) {
+ for (hidx_t t = ttran; t != HROOT; t = taghistory.pred(t)) {
+ if (taghistory.tag(t) != i) {
continue;
}
- else if (tagtrie.elem(t) < TAGVER_ZERO) {
+ else if (taghistory.elem(t) < TAGVER_ZERO) {
fprintf(stderr, "↓");
}
else if (t > TAGVER_ZERO) {
#include "src/dfa/determinization.h"
#include "src/dfa/dfa.h"
#include "src/dfa/dump.h"
-#include "src/dfa/tagpool.h"
#include "src/dfa/tcmd.h"
#include "src/nfa/nfa.h"
#include "src/re/rule.h"
return true;
}
- const tagtree_t &trie = ctx.dc_tagtrie;
- const Tagpool &tagpool = ctx.dc_tagpool;
+ const tag_history_t &thist = ctx.dc_taghistory;
+ const tagver_table_t &tvtbl = ctx.dc_tagvertbl;
const std::vector<Tag> &tags = ctx.dc_dfa.tags;
for (size_t i = 0; i < x->size; ++i) {
const hidx_t xl = x->tlook[i], yl = y->tlook[i];
- for (size_t t = 0; t < tagpool.ntags; ++t) {
+ for (size_t t = 0; t < tvtbl.ntags; ++t) {
if (history(tags[t])) {
// compare full tag sequences
- if (trie.compare_reversed(xl, yl, t) != 0) return false;
+ if (thist.compare_reversed(xl, yl, t) != 0) return false;
} else {
// compare only the last pair of tags
- if (trie.last(xl, t) != trie.last(yl, t)) return false;
+ if (thist.last(xl, t) != thist.last(yl, t)) return false;
}
}
}
std::fill(y2x - max, y2x + max, TAGVER_ZERO);
for (size_t i = 0; i < n; ++i) {
const tagver_t
- *xvs = ctx.dc_tagpool[x->tvers[i]],
- *yvs = ctx.dc_tagpool[y->tvers[i]];
+ *xvs = ctx.dc_tagvertbl[x->tvers[i]],
+ *yvs = ctx.dc_tagvertbl[y->tvers[i]];
const hidx_t xl = x->tlook[i];
for (size_t t = 0; t < ntag; ++t) {
// see note [mapping ignores items with lookahead tags]
- if (ctx.dc_tagtrie.last(xl, t) != TAGVER_ZERO
+ if (ctx.dc_taghistory.last(xl, t) != TAGVER_ZERO
&& !history(tags[t])) continue;
const tagver_t xv = xvs[t], yv = yvs[t];
{
dfa_t &dfa = ctx.dc_dfa;
const Rule &rule = dfa.rules[fin.state->rule];
- const tagver_t *vers = ctx.dc_tagpool[fin.tvers];
+ const tagver_t *vers = ctx.dc_tagvertbl[fin.tvers];
const hidx_t look = fin.tlook;
- const tagtree_t &hist = ctx.dc_tagtrie;
+ const tag_history_t &thist = ctx.dc_taghistory;
tcpool_t &tcpool = dfa.tcpool;
tcmd_t *copy = NULL, *save = NULL, **p;
const Tag &tag = dfa.tags[t];
if (fixed(tag)) continue;
- const tagver_t v = abs(vers[t]), l = hist.last(look, t);
+ const tagver_t v = abs(vers[t]), l = thist.last(look, t);
tagver_t &f = dfa.finvers[t];
if (l == TAGVER_ZERO) {
copy = tcpool.make_copy(copy, f, v);
} else if (history(tag)) {
- save = tcpool.make_add(save, f, v, hist, look, t);
+ save = tcpool.make_add(save, f, v, thist, look, t);
} else {
save = tcpool.make_set(save, f, l);
}
#include <stdlib.h>
#include "src/dfa/determinization.h"
-#include "src/dfa/tagtree.h"
+#include "src/dfa/tag_history.h"
namespace re2c
static const tagver_t DELIM = TAGVER_CURSOR - 1;
-tagtree_t::tagtree_t(): nodes(), path1(), path2() {}
+tag_history_t::tag_history_t(): nodes(), path1(), path2() {}
-hidx_t tagtree_t::pred(hidx_t i) const { return nodes[i].pred; }
+hidx_t tag_history_t::pred(hidx_t i) const { return nodes[i].pred; }
-tag_info_t tagtree_t::info(hidx_t i) const { return nodes[i].info; }
+tag_info_t tag_history_t::info(hidx_t i) const { return nodes[i].info; }
-tagver_t tagtree_t::elem(hidx_t i) const { return nodes[i].info.neg ? TAGVER_BOTTOM : TAGVER_CURSOR; }
+tagver_t tag_history_t::elem(hidx_t i) const { return nodes[i].info.neg ? TAGVER_BOTTOM : TAGVER_CURSOR; }
-size_t tagtree_t::tag(hidx_t i) const { return nodes[i].info.idx; }
+size_t tag_history_t::tag(hidx_t i) const { return nodes[i].info.idx; }
-hidx_t tagtree_t::push(hidx_t idx, tag_info_t info)
+hidx_t tag_history_t::push(hidx_t idx, tag_info_t info)
{
node_t x = {idx, info};
nodes.push_back(x);
}
-tagver_t tagtree_t::last(hidx_t i, size_t t) const
+tagver_t tag_history_t::last(hidx_t i, size_t t) const
{
for (; i != HROOT; i = pred(i)) {
if (tag(i) == t) return elem(i);
}
-int32_t tagtree_t::compare_reversed(hidx_t x, hidx_t y, size_t t) const
+int32_t tag_history_t::compare_reversed(hidx_t x, hidx_t y, size_t t) const
{
// compare in reverse, from tail to head: direction makes
// no difference when comparing for exact coincidence
}
-static void reconstruct_history(const tagtree_t &history,
+static void reconstruct_history(const tag_history_t &history,
tag_path_t &path, hidx_t idx)
{
path.clear();
return 0;
}
- tagtree_t &trie = ctx.dc_tagtrie;
- tag_path_t &p1 = trie.path1, &p2 = trie.path2;
- reconstruct_history(trie, p1, xl);
- reconstruct_history(trie, p2, yl);
+ tag_history_t &thist = ctx.dc_taghistory;
+ tag_path_t &p1 = thist.path1, &p2 = thist.path2;
+ reconstruct_history(thist, p1, xl);
+ reconstruct_history(thist, p2, yl);
tag_path_t::const_reverse_iterator
i1 = p1.rbegin(), e1 = p1.rend(), j1 = i1, g1,
i2 = p2.rbegin(), e2 = p2.rend(), j2 = i2, g2;
-#ifndef _RE2C_DFA_TAGTREE_
-#define _RE2C_DFA_TAGTREE_
+#ifndef _RE2C_DFA_TAG_HISTORY_
+#define _RE2C_DFA_TAG_HISTORY_
#include <stddef.h>
#include "src/util/c99_stdint.h"
typedef std::vector<tag_info_t> tag_path_t;
-struct tagtree_t
+struct tag_history_t
{
// the whole tree of tags found by the epsilon-closure
// (a bunch of separate subtrees for each tag with common root)
tag_path_t path1;
tag_path_t path2;
- tagtree_t();
+ tag_history_t();
hidx_t pred(hidx_t i) const;
tag_info_t info(hidx_t i) const;
tagver_t elem(hidx_t i) const;
tagver_t last(hidx_t i, size_t t) const;
int32_t compare_reversed(hidx_t x, hidx_t y, size_t t) const;
- FORBID_COPY(tagtree_t);
+ FORBID_COPY(tag_history_t);
};
} // namespace re2c
-#endif // _RE2C_DFA_TAGTREE_
+#endif // _RE2C_DFA_TAG_HISTORY_
#include <string.h> // memcpy, memcmp
#include <algorithm>
-#include "src/dfa/tagpool.h"
+#include "src/dfa/tagver_table.h"
#include "src/util/hash32.h"
namespace re2c
};
-Tagpool::Tagpool(size_t n)
+tagver_table_t::tagver_table_t(size_t n)
: lookup()
, ntags(n)
, buffer(new tagver_t[n])
{}
-Tagpool::~Tagpool()
+tagver_table_t::~tagver_table_t()
{
delete[] buffer;
const size_t n = lookup.size();
}
-uint32_t Tagpool::insert_const(tagver_t ver)
+uint32_t tagver_table_t::insert_const(tagver_t ver)
{
std::fill(buffer, buffer + ntags, ver);
return insert(buffer);
}
-uint32_t Tagpool::insert_succ(tagver_t fst)
+uint32_t tagver_table_t::insert_succ(tagver_t fst)
{
for (uint32_t i = 0; i < ntags; ++i) {
buffer[i] = fst++;
}
-uint32_t Tagpool::insert(const tagver_t *tags)
+uint32_t tagver_table_t::insert(const tagver_t *tags)
{
const size_t size = ntags * sizeof(tagver_t);
const uint32_t hash = hash32(0, tags, size);
}
-const tagver_t *Tagpool::operator[](uint32_t idx) const
+const tagver_t *tagver_table_t::operator[](uint32_t idx) const
{
return lookup[idx];
}
-#ifndef _RE2C_DFA_TAGPOOL_
-#define _RE2C_DFA_TAGPOOL_
+#ifndef _RE2C_DFA_TAGVER_TABLE_
+#define _RE2C_DFA_TAGVER_TABLE_
#include <stddef.h>
#include "src/util/c99_stdint.h"
static const size_t ZERO_TAGS = 0;
-struct Tagpool
+struct tagver_table_t
{
private:
typedef lookup_t<const tagver_t*> taglookup_t;
const size_t ntags;
tagver_t *buffer;
- explicit Tagpool(size_t n);
- ~Tagpool();
+ explicit tagver_table_t(size_t n);
+ ~tagver_table_t();
uint32_t insert_const(tagver_t ver);
uint32_t insert_succ(tagver_t fst);
uint32_t insert(const tagver_t *tags);
const tagver_t *operator[](uint32_t idx) const;
- FORBID_COPY(Tagpool);
+ FORBID_COPY(tagver_table_t);
};
} // namespace re2c
-#endif // _RE2C_DFA_TAGPOOL_
+#endif // _RE2C_DFA_TAGVER_TABLE_
tcmd_t *tcpool_t::make_add(tcmd_t *next, tagver_t lhs, tagver_t rhs,
- const tagtree_t &history, hidx_t hidx, size_t tag)
+ const tag_history_t &history, hidx_t hidx, size_t tag)
{
size_t hlen = 0;
for (hidx_t i = hidx; i != HROOT; i = history.pred(i)) {
#include <stddef.h>
#include "src/util/c99_stdint.h"
-#include "src/dfa/tagtree.h"
+#include "src/dfa/tag_history.h"
#include "src/re/tag.h"
#include "src/util/lookup.h"
#include "src/util/slab_allocator.h"
tcpool_t();
tcmd_t *make_copy(tcmd_t *next, tagver_t lhs, tagver_t rhs);
tcmd_t *make_set(tcmd_t *next, tagver_t lhs, tagver_t set);
- tcmd_t *make_add(tcmd_t *next, tagver_t lhs, tagver_t rhs, const tagtree_t &history, hidx_t hidx, size_t tag);
+ tcmd_t *make_add(tcmd_t *next, tagver_t lhs, tagver_t rhs, const tag_history_t &history, hidx_t hidx, size_t tag);
tcmd_t *copy_add(tcmd_t *next, tagver_t lhs, tagver_t rhs, const tagver_t *history);
tcid_t insert(const tcmd_t *tcmd);
const tcmd_t *operator[](tcid_t id) const;