Moved start label configuration out of global scope.
authorUlya Trofimovich <skvadrik@gmail.com>
Wed, 27 May 2015 10:50:55 +0000 (11:50 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Wed, 27 May 2015 10:50:55 +0000 (11:50 +0100)
There are two configurations:
1. re2c:startlabel = <integer>;
2. re2c:startlabel = <string>;
The scope of these configurations is the scope of current re2c block.

re2c/src/codegen/emit_dfa.cc
re2c/src/codegen/output.cc
re2c/src/codegen/output.h
re2c/src/globals.h
re2c/src/main.cc
re2c/src/parse/scanner.cc

index 25b6bdb74755b0586305d6c01d303a59dd05c68c..37dfb89d605abc6170c09e4a0caf6d1ecd2409dc 100644 (file)
@@ -87,13 +87,6 @@ void DFA::emit(Output & output, uint32_t& ind, const RegExpMap* specMap, const s
 
        head->action.set_initial (start_label, bSaveOnHead);
 
-       if (bUseStartLabel)
-       {
-               if (startLabelName.empty())
-               {
-                       vUsedLabels.insert(prolog_label);
-               }
-       }
 
        State *s;
 
@@ -106,6 +99,10 @@ void DFA::emit(Output & output, uint32_t& ind, const RegExpMap* specMap, const s
        {
                vUsedLabels.insert(0);
        }
+       if (o.get_force_start_label ())
+       {
+               vUsedLabels.insert(prolog_label);
+       }
        for (s = head; s; s = s->next)
        {
                s->go.used_labels ();
@@ -169,10 +166,7 @@ void DFA::emit(Output & output, uint32_t& ind, const RegExpMap* specMap, const s
                                o << labelPrefix << prolog_label << ":\n";
                        }
                }
-               if (!startLabelName.empty())
-               {
-                       o << startLabelName << ":\n";
-               }
+               o.write_user_start_label ();
                genCondGoto(o, ind, *specMap);
        }
 
@@ -233,8 +227,6 @@ void DFA::emit(Output & output, uint32_t& ind, const RegExpMap* specMap, const s
                delete BitMap::first;
                BitMap::first = NULL;
        }
-
-       bUseStartLabel = false;
 }
 
 void genCondTable(OutputFile & o, uint32_t ind, const RegExpMap& specMap)
index 72a88c906911625ea212338bb869e3c7614985b1..c46ed0a397c86db2a8c5ef59ad71e0f9ae0d0c90 100644 (file)
@@ -35,6 +35,8 @@ uint32_t OutputFragment::count_lines ()
 OutputBlock::OutputBlock ()
        : fragments ()
        , used_yyaccept (false)
+       , force_start_label (false)
+       , user_start_label ()
 {
        fragments.push_back (new OutputFragment (OutputFragment::CODE, 0));
 }
@@ -120,6 +122,15 @@ void OutputFile::write_version_time ()
        output_version_time (stream ());
 }
 
+void OutputFile::write_user_start_label ()
+{
+       const std::string label = blocks.back ()->user_start_label;
+       if (!label.empty ())
+       {
+               * this << label << ":\n";
+       }
+}
+
 OutputFile & operator << (OutputFile & u, uint32_t n)
 {
        u.stream () << n;
@@ -195,6 +206,21 @@ bool OutputFile::get_used_yyaccept () const
        return blocks.back ()->used_yyaccept;
 }
 
+void OutputFile::set_force_start_label (bool force)
+{
+       blocks.back ()->force_start_label = force;
+}
+
+void OutputFile::set_user_start_label (const std::string & label)
+{
+       blocks.back ()->user_start_label = label;
+}
+
+bool OutputFile::get_force_start_label () const
+{
+       return blocks.back ()->force_start_label;
+}
+
 void OutputFile::new_block ()
 {
        blocks.push_back (new OutputBlock ());
index fae5dea47d1208e51655d60bb2e6888f93cf4125..43e54aebb77d8412256236cd0734a583d564b7ba 100644 (file)
@@ -43,6 +43,8 @@ struct OutputBlock
 {
        std::vector<OutputFragment *> fragments;
        bool used_yyaccept;
+       bool force_start_label;
+       std::string user_start_label;
 
        OutputBlock ();
        ~OutputBlock ();
@@ -64,6 +66,7 @@ struct OutputFile
        void write_uint32_t_width (uint32_t n, uint32_t w);
        void write_line_info (uint32_t l, const char * fn);
        void write_version_time ();
+       void write_user_start_label ();
        friend OutputFile & operator << (OutputFile & o, uint32_t n);
        friend OutputFile & operator << (OutputFile & o, const std::string & s);
        friend OutputFile & operator << (OutputFile & o, const char * s);
@@ -77,6 +80,9 @@ struct OutputFile
 
        void set_used_yyaccept ();
        bool get_used_yyaccept () const;
+       void set_force_start_label (bool force);
+       void set_user_start_label (const std::string & label);
+       bool get_force_start_label () const;
 
        void emit (const std::vector<std::string> & types, uint32_t max_fill);
 
index e467a2ca1d9e1b8f11f2af6e7d085345fcc2f713..b3676c5d86fe1f5fad723c2f73c380f181838ba3 100644 (file)
@@ -33,8 +33,6 @@ extern bool bNoGenerationDate;
 extern bool bUsedYYMarker;
 extern bool bUsedYYBitmap;
 
-extern bool bUseStartLabel;
-extern std::string startLabelName;
 extern std::string labelPrefix;
 extern std::string condPrefix;
 extern std::string condEnumPrefix;
index 11f1f6c0f81e3fee9f1690437147880f9870716e..258708cae52de6fc8694e69765fb3f5014696840 100644 (file)
@@ -32,7 +32,6 @@ bool bNoGenerationDate = false;
 bool bUsedYYBitmap  = false;
 bool bUsedYYMarker  = true;
 bool bEmitYYCh       = true;
-bool bUseStartLabel  = false;
 bool bUseStateNext   = false;
 bool bUseYYFill      = true;
 bool bUseYYFillParam = true;
@@ -44,7 +43,6 @@ bool bUseYYSetStateParam = true;
 bool bUseYYSetStateNaked = false;
 bool bUseYYGetStateNaked = false;
 
-std::string startLabelName;
 std::string labelPrefix("yy");
 std::string condPrefix("yyc_");
 std::string condEnumPrefix("yyc");
index e6dad63552a3bf2793c7d97dc22748af75d526fb..011f0e772dd7b9bcf1459f46cf0e13bc6cf44948 100644 (file)
@@ -26,8 +26,7 @@ void Scanner::config(const std::string & cfg, int num)
        }
        else if (cfg == "startlabel")
        {
-               bUseStartLabel = num != 0;
-               startLabelName = "";
+               out.set_force_start_label (num != 0);
        }
        else if (cfg == "state:abort")
        {
@@ -199,8 +198,7 @@ void Scanner::config(const std::string & cfg, const std::string & val)
        }
        else if (cfg == "startlabel")
        {
-               startLabelName = strVal;
-               bUseStartLabel = !startLabelName.empty();
+               out.set_user_start_label (strVal);
        }
        else if (cfg == "labelprefix")
        {