]> granicus.if.org Git - re2c/commitdiff
Omit usseless 'yyaccept' variable in '--skeleton' programs.
authorUlya Trofimovich <skvadrik@gmail.com>
Thu, 17 Sep 2015 09:53:35 +0000 (10:53 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Thu, 17 Sep 2015 09:53:35 +0000 (10:53 +0100)
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
re2c/src/codegen/skeleton/generate_code.cc
re2c/src/codegen/skeleton/skeleton.h

index fd42e60048d2e2a89f36283c01c78ef289a00157..603927b0f9b952fbbdb11e68ab7e564a97144374 100644 (file)
@@ -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);
index 584c2c9897863bc27037e2d371a1dddb5cf30450..21cfd62110eaf3564d57b6763d435f6e48c9e252 100644 (file)
@@ -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 ()));
index 707d2f2c06cec74776218869de6388c65a381336..147505c3f59e5c8224dd74b3886154af8648a814 100644 (file)
@@ -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<std::string> & names);
        static void emit_action (OutputFile & o, uint32_t ind, rule_rank_t rank, const std::string & name);