]> granicus.if.org Git - re2c/commitdiff
Pack tag index and sign into one 32-bit field.
authorUlya Trofimovich <skvadrik@gmail.com>
Mon, 6 Aug 2018 21:37:38 +0000 (22:37 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Mon, 6 Aug 2018 21:37:38 +0000 (22:37 +0100)
re2c/src/dfa/closure.cc
re2c/src/dfa/tagtree.cc
re2c/src/dfa/tagtree.h
re2c/src/nfa/dump.cc
re2c/src/nfa/nfa.h
re2c/src/nfa/re_to_nfa.cc
re2c/src/re/re.h
re2c/src/re/tag.h

index d0f21e14336469afdc0e7c1014d27287e50df0a8..df498f736f811908fc4bfe99a36ca4c35fb374bd 100644 (file)
@@ -159,8 +159,7 @@ static nfa_state_t *explore(nfa_state_t *q, closure_t &done,
                case nfa_state_t::TAG:
                        if (q->arcidx == 0) {
                                x.state = q->tag.out;
-                               x.tlook = tagpool.history.push(x.tlook, q->tag.info,
-                                       q->tag.bottom ? TAGVER_BOTTOM : TAGVER_CURSOR);
+                               x.tlook = tagpool.history.push(x.tlook, q->tag.info);
                                p = relax(x, done, shadow, tagpool, tags);
                                ++q->arcidx;
                        }
@@ -339,8 +338,7 @@ void closure_leftmost(const closure_t &init, closure_t &done,
                                break;
                        case nfa_state_t::TAG:
                                x.state = n->tag.out;
-                               x.tlook = tagpool.history.push(x.tlook, n->tag.info,
-                                       n->tag.bottom ? TAGVER_BOTTOM : TAGVER_CURSOR);
+                               x.tlook = tagpool.history.push(x.tlook, n->tag.info);
                                todo.push(x);
                                break;
                        case nfa_state_t::RAN:
index a5966a18201d70e4d97b061793decddff45e266f..caa86cb29667363f4a5b805836407cee4e861145 100644 (file)
@@ -10,15 +10,15 @@ static const tagver_t DELIM = TAGVER_CURSOR - 1;
 
 tagtree_t::tagtree_t(): nodes(), path1(), path2() {}
 
-tagver_t tagtree_t::elem(hidx_t i) const { return nodes[i].elem; }
+tagver_t tagtree_t::elem(hidx_t i) const { return nodes[i].info.neg ? TAGVER_BOTTOM : TAGVER_CURSOR; }
 
 hidx_t tagtree_t::pred(hidx_t i) const { return nodes[i].pred; }
 
-size_t tagtree_t::tag(hidx_t i) const { return nodes[i].tag; }
+size_t tagtree_t::tag(hidx_t i) const { return nodes[i].info.idx; }
 
-hidx_t tagtree_t::push(hidx_t i, size_t t, tagver_t v)
+hidx_t tagtree_t::push(hidx_t idx, tag_info_t info)
 {
-       node_t x = {i, v, t};
+       node_t x = {idx, info};
        nodes.push_back(x);
        return static_cast<hidx_t>(nodes.size() - 1);
 }
index 7f3bf4bb14eb2e07edc3d1d9c7422d27adf86414..66b0b16a41d1994cde91b3175be120a7a929d5fe 100644 (file)
@@ -22,8 +22,7 @@ struct tagtree_t
        // (a bunch of separate subtrees for each tag with common root)
        struct node_t {
                hidx_t pred;
-               tagver_t elem;
-               size_t tag;
+               tag_info_t info;
        };
        std::vector<node_t> nodes;
 
@@ -35,7 +34,7 @@ struct tagtree_t
        hidx_t pred(hidx_t i) const;
        tagver_t elem(hidx_t i) const;
        size_t tag(hidx_t i) const;
-       hidx_t push(hidx_t i, size_t t, tagver_t v);
+       hidx_t push(hidx_t idx, tag_info_t info);
        int32_t compare_plain(hidx_t x, hidx_t y, size_t t);
        int32_t compare_histories(hidx_t x, hidx_t y, tagver_t ox, tagver_t oy, size_t t);
        int32_t compare_last_subhistories(hidx_t x, hidx_t y, tagver_t ox, tagver_t oy, size_t t);
index 3af97d3f32d9c510f04886d3a0a8ef62078df5f7..8516b2fa153220db9ef77c8dbfe899f7ab645df7 100644 (file)
@@ -51,14 +51,14 @@ void dump_nfa(const nfa_t &nfa)
                                break;
                        }
                        case nfa_state_t::TAG: {
-                               const Tag &tag = nfa.tags[n->tag.info];
+                               const Tag &tag = nfa.tags[n->tag.info.idx];
                                fprintf(stderr, "  n%u -> n%u [label=\"/", i, index(nfa, n->tag.out));
                                if (capture(tag)) {
                                        fprintf(stderr, "%u", (uint32_t)tag.ncap);
                                } else if (!trailing(tag)) {
                                        fprintf(stderr, "%s", tag.name->c_str());
                                }
-                               if (n->tag.bottom) {
+                               if (n->tag.info.neg) {
                                        fprintf(stderr, "&darr;");
                                } else {
                                        fprintf(stderr, "&uarr;");
index 7951255b18f6e52828bf31727aac643be60440ab..880f32fbfde2fb0db722f1183b23419547ab0b3b 100644 (file)
@@ -40,8 +40,7 @@ struct nfa_state_t
                struct
                {
                        nfa_state_t *out;
-                       size_t info;
-                       bool bottom;
+                       tag_info_t info;
                } tag;
                struct
                {
@@ -81,12 +80,11 @@ struct nfa_state_t
                ran.ran = p;
                init(r);
        }
-       void make_tag(size_t r, nfa_state_t *s, size_t i, bool bottom)
+       void make_tag(size_t r, nfa_state_t *s, tag_info_t info)
        {
                type = TAG;
                tag.out = s;
-               tag.info = i;
-               tag.bottom = bottom;
+               tag.info = info;
                init(r);
        }
        void make_fin(size_t r)
index 0153a16bced1c014c0244e5163772f07ce611371..81e81726e3437c35cc34692d580114482fb5c35a 100644 (file)
@@ -81,7 +81,7 @@ static nfa_state_t *re_to_nfa(nfa_t &nfa, size_t nrule, const RE *re, nfa_state_
                                s = t;
                        } else {
                                s = &nfa.states[nfa.size++];
-                               s->make_tag(nrule, t, re->tag.idx, re->tag.bottom);
+                               s->make_tag(nrule, t, re->tag);
                        }
                        break;
                }
index 623f78f0e98b04e6e2a3684328061c6176abc283..c30cd0ffb02beb464f4cf8f7158a63991feddbd4 100644 (file)
@@ -32,10 +32,7 @@ struct RE
                        uint32_t min;
                        uint32_t max;
                } iter;
-               struct {
-                       size_t idx;
-                       bool bottom;
-               } tag;
+               tag_info_t tag;
        };
 };
 
@@ -110,12 +107,13 @@ inline RE *re_iter(RE::alc_t &alc, RE *x, uint32_t n, uint32_t m)
        return y;
 }
 
-inline RE *re_tag(RE::alc_t &alc, size_t i, bool b)
+inline RE *re_tag(RE::alc_t &alc, size_t idx, bool neg)
 {
        RE *x = alc.alloct<RE>(1);
        x->type = RE::TAG;
-       x->tag.idx = i;
-       x->tag.bottom = b;
+       x->tag.idx = idx & 0x7FFFffff;
+       assert(idx == x->tag.idx);
+       x->tag.neg = neg;
        return x;
 }
 
index 24b253052da29c1e9bfb9b7b3a79d5fe7c6a1640..b6482a73ecd5d102db714d1a984c90be69ede4db 100644 (file)
@@ -17,6 +17,13 @@ static const tagver_t TAGVER_ZERO = 0; // absense of tag
 static const tagver_t TAGVER_CURSOR = std::numeric_limits<tagver_t>::max(); // current position, highest priority
 
 
+struct tag_info_t
+{
+       uint32_t idx : 31;
+       uint32_t neg : 1;
+};
+
+
 struct Tag
 {
        static const size_t RIGHTMOST;