From 7ec3c01eb4fa8251cb1481d39c6270bf589553a7 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Fri, 3 Mar 2017 01:21:53 +0000 Subject: [PATCH] Prepare default tags insertion for non-sequential tag enumeration. This will be needed when we add POSIX captures: opening and closing capture tags must have sequential numbers, but the tags may be located far from each other in the regexp tree (other tags are possible on the way from the opening tag to the closing tag). --- re2c/src/ir/re/default_tags.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/re2c/src/ir/re/default_tags.cc b/re2c/src/ir/re/default_tags.cc index 2253f030..ef98b396 100644 --- a/re2c/src/ir/re/default_tags.cc +++ b/re2c/src/ir/re/default_tags.cc @@ -2,22 +2,22 @@ namespace re2c { -static void insert_default_tags(RESpec &spec, RE *re, size_t &tidx) +static void insert_default_tags(RESpec &spec, RE *re, size_t *&tidx) { RE::alc_t &alc = spec.alc; switch (re->type) { case RE::NIL: break; case RE::SYM: break; case RE::ALT: { - size_t i = tidx; + size_t *i = tidx; RE *x = re_nil(alc), *y = re_nil(alc); insert_default_tags(spec, re->alt.re1, tidx); for (; i < tidx; ++i) { - x = re_cat(alc, x, re_tag(alc, i, true)); + x = re_cat(alc, x, re_tag(alc, *i, true)); } insert_default_tags(spec, re->alt.re2, tidx); for (; i < tidx; ++i) { - y = re_cat(alc, y, re_tag(alc, i, true)); + y = re_cat(alc, y, re_tag(alc, *i, true)); } re->alt.re1 = re_cat(alc, re->alt.re1, y); re->alt.re2 = re_cat(alc, re->alt.re2, x); @@ -31,21 +31,21 @@ static void insert_default_tags(RESpec &spec, RE *re, size_t &tidx) insert_default_tags(spec, re->iter.re, tidx); break; case RE::TAG: - assert(re->tag.idx == tidx); - ++tidx; + *tidx++ = re->tag.idx; break; } } void insert_default_tags(RESpec &spec) { - size_t tidx = 0; + size_t *tidx0 = new size_t[spec.tags.size()], *tidx = tidx0; std::vector::iterator i = spec.res.begin(), e = spec.res.end(); for (; i != e; ++i) { insert_default_tags(spec, *i, tidx); } + delete[] tidx0; } } // namespace re2c -- 2.40.0