From: Ulya Trofimovich Date: Fri, 3 Mar 2017 17:06:31 +0000 (+0000) Subject: Fixed code generation for '--skeleton' with '--posix-captures'. X-Git-Tag: 1.0~39^2~114 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=742f67921d2a08fed21176e95e26f8b5c7f5f4b9;p=re2c Fixed code generation for '--skeleton' with '--posix-captures'. --- diff --git a/re2c/src/codegen/emit.h b/re2c/src/codegen/emit.h index c60c048a..2dd9f938 100644 --- a/re2c/src/codegen/emit.h +++ b/re2c/src/codegen/emit.h @@ -15,6 +15,7 @@ void gen_goto_if(OutputFile &o, uint32_t ind, const State *to, const DFA &dfa, t void gen_settags(code_lines_t &code, const DFA &dfa, tcid_t tcid, const opt_t *opts); std::string vartag_name(tagver_t ver, const std::string &prefix); std::string vartag_expr(tagver_t ver, const std::string &prefix, const std::string &expression); +std::string tagname(const Tag &tag); inline std::string indent(uint32_t n, const std::string s) { diff --git a/re2c/src/codegen/emit_action.cc b/re2c/src/codegen/emit_action.cc index 0f5a18f6..153eb0ef 100644 --- a/re2c/src/codegen/emit_action.cc +++ b/re2c/src/codegen/emit_action.cc @@ -23,7 +23,6 @@ static void emit_accept (OutputFile &o, uint32_t ind, const DFA &dfa, con static void emit_rule (OutputFile &o, uint32_t ind, const DFA &dfa, size_t rule_idx); static void gen_fintags (OutputFile &o, uint32_t ind, const DFA &dfa, const Rule &rule); static void gen_goto (code_lines_t &code, const State *to, const DFA &dfa, tcid_t tcid, const opt_t *opts, bool skip); -static std::string tagname (const Tag &tag); static bool endstate (const State *s); void emit_action(OutputFile &o, uint32_t ind, const DFA &dfa, @@ -167,28 +166,26 @@ void emit_rule(OutputFile &o, uint32_t ind, const DFA &dfa, size_t rule_idx) if (opts->target == opt_t::SKELETON) { emit_action(o, ind, dfa, rule_idx); - return; - } - - if (!cond.empty() && dfa.cond != cond) { - strrreplace(s = opts->cond_set, opts->cond_set_arg, opts->condEnumPrefix + cond); - o.wind(ind).wstring(s); - if (!opts->cond_set_naked) { - o.ws("(").wstring(opts->condEnumPrefix).wstring(cond).ws(");"); + } else { + if (!cond.empty() && dfa.cond != cond) { + strrreplace(s = opts->cond_set, opts->cond_set_arg, opts->condEnumPrefix + cond); + o.wind(ind).wstring(s); + if (!opts->cond_set_naked) { + o.ws("(").wstring(opts->condEnumPrefix).wstring(cond).ws(");"); + } + o.ws("\n"); } - o.ws("\n"); - } - - if (!code->autogen) { - if (!dfa.setup.empty()) { - o.wind(ind).wstring(dfa.setup).ws("\n"); + if (!code->autogen) { + if (!dfa.setup.empty()) { + o.wind(ind).wstring(dfa.setup).ws("\n"); + } + o.wline_info(code->fline, code->fname.c_str()) + .wind(ind).wstring(code->text).ws("\n") + .wdelay_line_info(); + } else if (!cond.empty()) { + strrreplace(s = opts->condGoto, opts->condGotoParam, opts->condPrefix + cond); + o.wind(ind).wstring(s).ws("\n"); } - o.wline_info(code->fline, code->fname.c_str()) - .wind(ind).wstring(code->text).ws("\n") - .wdelay_line_info(); - } else if (!cond.empty()) { - strrreplace(s = opts->condGoto, opts->condGotoParam, opts->condPrefix + cond); - o.wind(ind).wstring(s).ws("\n"); } if (wrap) o.wind(--ind).ws("}\n"); diff --git a/re2c/src/ir/skeleton/generate_code.cc b/re2c/src/ir/skeleton/generate_code.cc index 32cfcfd0..7a308211 100644 --- a/re2c/src/ir/skeleton/generate_code.cc +++ b/re2c/src/ir/skeleton/generate_code.cc @@ -366,11 +366,12 @@ void emit_action(OutputFile &o, uint32_t ind, const DFA &dfa, size_t rid) .ws("(&i, keys, input, token, &cursor, ").wu64(rkey).ws(")"); for (size_t t = r.ltag; t < r.htag; ++t) { - if (t == r.ttag || fixed(dfa.tags[t])) continue; - const std::string &tag = *dfa.tags[t].name; + const Tag &tag = dfa.tags[t]; + if (t == r.ttag || fixed(tag)) continue; + const std::string tname = tagname(tag); o.ws("\n").wind(ind + 1).ws(" || check_tag_").wstring(name) - .ws("(&i, keys, ").wstring(tag).ws(", input, token, \"") - .wstring(tag).ws("\")"); + .ws("(&i, keys, ").wstring(tname).ws(", input, token, \"") + .wstring(tname).ws("\")"); } o.ws(";\n");