From 1d1bfcde05cc5bbe86377b45c6d28a22f419ca4c Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Thu, 17 Sep 2015 10:53:35 +0100 Subject: [PATCH] Omit usseless 'yyaccept' variable in '--skeleton' programs. Normally re2c generates single 'yyaccept' variable for all conditions. With '--skeleton' re2c handles conditions separately, so each condition needs (or needs not) its own 'yyaccept'. Prior to this commit re2c used the same criterion to determine if 'yyaccept' is needed with '--skeleton' as it uses generally: whether 'yyaccept' was used in any of conditions. Now re2c looks if 'yyaccept' was used with this particular condition. --- re2c/src/codegen/emit_dfa.cc | 2 +- re2c/src/codegen/skeleton/generate_code.cc | 8 +++++--- re2c/src/codegen/skeleton/skeleton.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/re2c/src/codegen/emit_dfa.cc b/re2c/src/codegen/emit_dfa.cc index fd42e600..603927b0 100644 --- a/re2c/src/codegen/emit_dfa.cc +++ b/re2c/src/codegen/emit_dfa.cc @@ -131,7 +131,7 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra if (flag_skeleton) { skeleton->emit_data (o.file_name); - skeleton->emit_start (o, output.max_fill); + skeleton->emit_start (o, output.max_fill, accepts.size () > 1); uint32_t i = 2; emit_body (o, i, used_labels); skeleton->emit_end (o); diff --git a/re2c/src/codegen/skeleton/generate_code.cc b/re2c/src/codegen/skeleton/generate_code.cc index 584c2c98..21cfd621 100644 --- a/re2c/src/codegen/skeleton/generate_code.cc +++ b/re2c/src/codegen/skeleton/generate_code.cc @@ -86,7 +86,7 @@ void Skeleton::emit_prolog (OutputFile & o) o << "\n"; } -void Skeleton::emit_start (OutputFile & o, uint32_t maxfill) const +void Skeleton::emit_start (OutputFile & o, uint32_t maxfill, bool yyaccept) const { const uint32_t default_rule = maxkey (); @@ -198,8 +198,10 @@ void Skeleton::emit_start (OutputFile & o, uint32_t maxfill) const o << "\n" << indString << "{"; o << "\n" << indString << indString << "const YYCTYPE * token = cursor;"; o << "\n" << indString << indString << "YYCTYPE yych;"; - o.insert_yyaccept_init (2); - o << "\n"; + if (yyaccept) + { + o << "\n" << indString << indString << "unsigned int yyaccept = 0;"; + } if (bFlag && BitMap::first) { BitMap::gen (o, 2, 0, std::min (0xFFu, encoding.nCodeUnits ())); diff --git a/re2c/src/codegen/skeleton/skeleton.h b/re2c/src/codegen/skeleton/skeleton.h index 707d2f2c..147505c3 100644 --- a/re2c/src/codegen/skeleton/skeleton.h +++ b/re2c/src/codegen/skeleton/skeleton.h @@ -73,7 +73,7 @@ struct Skeleton void warn_undefined_control_flow (); void emit_data (const char * fname); static void emit_prolog (OutputFile & o); - void emit_start (OutputFile & o, uint32_t maxfill) const; + void emit_start (OutputFile & o, uint32_t maxfill, bool yyaccept) const; void emit_end (OutputFile & o) const; static void emit_epilog (OutputFile & o, const std::vector & names); static void emit_action (OutputFile & o, uint32_t ind, rule_rank_t rank, const std::string & name); -- 2.50.1