]> granicus.if.org Git - re2c/commitdiff
Rule contexts are consecutive, so we only need to store bounds.
authorUlya Trofimovich <skvadrik@gmail.com>
Sat, 30 Apr 2016 15:47:06 +0000 (16:47 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Sat, 30 Apr 2016 16:01:28 +0000 (17:01 +0100)
re2c/src/codegen/emit_action.cc
re2c/src/ir/dfa/context_deduplication.cc
re2c/src/ir/nfa/nfa.cc
re2c/src/ir/rule.h

index 4384c11cc9d0ad3eb97754bcb48cb3331b8fce20..1708b3ec99ced4c55bbccc99dcc053ffcef15c4b 100644 (file)
@@ -233,8 +233,8 @@ static void subst_contexts(
        const Rule &rule,
        const std::vector<CtxVar> &contexts)
 {
-       for (size_t i = 0; i < rule.ctxvar.size(); ++i) {
-               const CtxVar &ctx = contexts[rule.ctxvar[i]];
+       for (size_t i = rule.ltag; i < rule.htag; ++i) {
+               const CtxVar &ctx = contexts[i];
                strrreplace(action, "@" + *ctx.codename,
                        opts->input_api.expr_ctx(ctx.expr()));
        }
index 96098857f30b67227fefadfcc370fae456e435ba..99a4f225c25312c067f046f954ba4bf27e8b7938 100644 (file)
@@ -32,7 +32,9 @@ static void calc_live(
 
                if (s->rule != Rule::NONE) {
                        const Rule &rule = dfa.rules[s->rule];
-                       live[i].insert(rule.ctxvar.begin(), rule.ctxvar.end());
+                       for (size_t j = rule.ltag; j < rule.htag; ++j) {
+                               live[i].insert(j);
+                       }
                        if (rule.trail.type == Trail::VAR) {
                                live[i].insert(rule.trail.pld.var);
                        }
@@ -55,7 +57,9 @@ size_t deduplicate_contexts(dfa_t &dfa,
        std::set<size_t> fbctxs;
        for (size_t i = 0; i < fallback.size(); ++i) {
                const Rule &rule = dfa.rules[dfa.states[fallback[i]]->rule];
-               fbctxs.insert(rule.ctxvar.begin(), rule.ctxvar.end());
+               for (size_t j = rule.ltag; j < rule.htag; ++j) {
+                       fbctxs.insert(j);
+               }
                if (rule.trail.type == Trail::VAR) {
                        fbctxs.insert(rule.trail.pld.var);
                }
index b464609468fb8e88554d6e1b1bfc3d90a4649f95..33f802e8180ecb167d22b4d48f766b9097fb609f 100644 (file)
@@ -156,7 +156,7 @@ static nfa_state_t *compile_rule(
        nfa_state_t *t = &nfa.states[nfa.size++];
        t->fin(nrule);
 
-       std::vector<size_t> &ctxvar = r.ctxvar;
+       r.ltag = nfa.contexts.size();
        std::vector<CtxFix> &ctxfix = r.ctxfix;
        Trail &trail = r.trail;
        // base2var is filled in right-to-left, this is crucial
@@ -168,9 +168,8 @@ static nfa_state_t *compile_rule(
                        const size_t idx = nfa.contexts.size();
                        base2var[i - 1] = idx;
                        nfa.contexts.push_back(CtxVar(name, nrule));
-                       if (name != NULL) {
-                               ctxvar.push_back(idx);
-                       } else {
+                       if (name == NULL) {
+                               ++r.ltag;
                                trail.make_var(idx);
                        }
                        nfa_state_t *q = &nfa.states[nfa.size++];
@@ -185,6 +184,7 @@ static nfa_state_t *compile_rule(
                        }
                }
        }
+       r.htag = nfa.contexts.size();
        t = compile(rs[0], nfa, t);
 
        bool null = nullable(rs[0]);
index 9fb7ff7e89ea1659eae7f56f6d12ee21075b0af9..f5500533142f3397197dcea302b9b27267485244 100644 (file)
@@ -35,7 +35,8 @@ struct Rule
 
        const RuleInfo *info;
 
-       std::vector<size_t> ctxvar;
+       size_t ltag;
+       size_t htag;
        std::vector<CtxFix> ctxfix;
        Trail trail;
        bool nullable;
@@ -45,7 +46,8 @@ struct Rule
 
        Rule()
                : info(NULL)
-               , ctxvar()
+               , ltag(0)
+               , htag(0)
                , ctxfix()
                , trail()
                , nullable(false)