From a5f3e7ae3a27259353e903d2a60ec7cb9faf3640 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Sat, 30 Apr 2016 16:47:06 +0100 Subject: [PATCH] Rule contexts are consecutive, so we only need to store bounds. --- re2c/src/codegen/emit_action.cc | 4 ++-- re2c/src/ir/dfa/context_deduplication.cc | 8 ++++++-- re2c/src/ir/nfa/nfa.cc | 8 ++++---- re2c/src/ir/rule.h | 6 ++++-- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/re2c/src/codegen/emit_action.cc b/re2c/src/codegen/emit_action.cc index 4384c11c..1708b3ec 100644 --- a/re2c/src/codegen/emit_action.cc +++ b/re2c/src/codegen/emit_action.cc @@ -233,8 +233,8 @@ static void subst_contexts( const Rule &rule, const std::vector &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())); } diff --git a/re2c/src/ir/dfa/context_deduplication.cc b/re2c/src/ir/dfa/context_deduplication.cc index 96098857..99a4f225 100644 --- a/re2c/src/ir/dfa/context_deduplication.cc +++ b/re2c/src/ir/dfa/context_deduplication.cc @@ -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 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); } diff --git a/re2c/src/ir/nfa/nfa.cc b/re2c/src/ir/nfa/nfa.cc index b4646094..33f802e8 100644 --- a/re2c/src/ir/nfa/nfa.cc +++ b/re2c/src/ir/nfa/nfa.cc @@ -156,7 +156,7 @@ static nfa_state_t *compile_rule( nfa_state_t *t = &nfa.states[nfa.size++]; t->fin(nrule); - std::vector &ctxvar = r.ctxvar; + r.ltag = nfa.contexts.size(); std::vector &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]); diff --git a/re2c/src/ir/rule.h b/re2c/src/ir/rule.h index 9fb7ff7e..f5500533 100644 --- a/re2c/src/ir/rule.h +++ b/re2c/src/ir/rule.h @@ -35,7 +35,8 @@ struct Rule const RuleInfo *info; - std::vector ctxvar; + size_t ltag; + size_t htag; std::vector ctxfix; Trail trail; bool nullable; @@ -45,7 +46,8 @@ struct Rule Rule() : info(NULL) - , ctxvar() + , ltag(0) + , htag(0) , ctxfix() , trail() , nullable(false) -- 2.40.0