]> granicus.if.org Git - re2c/commitdiff
Setup code for rules belongs in DFA scope, not the entire block scope.
authorUlya Trofimovich <skvadrik@gmail.com>
Fri, 23 Dec 2016 15:55:01 +0000 (15:55 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Fri, 23 Dec 2016 15:55:01 +0000 (15:55 +0000)
re2c/bootstrap/src/parse/lex.cc
re2c/bootstrap/src/parse/parser.cc
re2c/src/codegen/emit_action.cc
re2c/src/codegen/output.cc
re2c/src/codegen/output.h
re2c/src/ir/adfa/adfa.cc
re2c/src/ir/adfa/adfa.h
re2c/src/ir/compile.cc
re2c/src/ir/compile.h
re2c/src/parse/parser.ypp

index e1e3f6d1a495e8538b2f6791d29bb5890b0235ae..614eaf481cb9a5b39746b8bc443f6d4fe3a4a2fc 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.16 on Fri Dec 23 13:34:59 2016 */
+/* Generated by re2c 0.16 on Fri Dec 23 15:51:34 2016 */
 #line 1 "../src/parse/lex.re"
 #include "src/util/c99_stdint.h"
 #include <stddef.h>
index 77f187e0abbdadbbb478312db6db506a91be46a5..b2c88683a4fef33a7aff6e272f7601769e5a330c 100644 (file)
@@ -2151,7 +2151,8 @@ void parse(Scanner &in, Output & o)
 
                        for (it = context.specMap.begin(); it != context.specMap.end(); ++it) {
                                delay_default(it->second);
-                               dfa_map[it->first] = compile(it->second, o, it->first, opts->encoding.nCodeUnits ());
+                               const std::string &setup = find_setup_rule(context.ruleSetupMap, it->first);
+                               dfa_map[it->first] = compile(it->second, o, it->first, opts->encoding.nCodeUnits (), setup);
                        }
                }
 
@@ -2160,7 +2161,6 @@ void parse(Scanner &in, Output & o)
                        uint32_t ind = opts->topIndent;
                        size_t nCount = dfa_map.size();
                        for (dfa_map_t::const_iterator i = dfa_map.begin(); i != dfa_map.end(); ++i) {
-                               o.source.block().setup_rule = find_setup_rule(context.ruleSetupMap, i->first);
                                i->second->emit(o, ind, !--nCount, bPrologBrace);
                        }
                }
index a6b59b9b3077e0efbc61344e115251035cbe18b5..70f000b1fc0d0c199c8db4915a42db0500cf3870 100644 (file)
@@ -227,9 +227,8 @@ void emit_rule(OutputFile &o, uint32_t ind, const DFA &dfa, size_t rule_idx)
        }
 
        if (!code->autogen) {
-               const std::string setup = o.block().setup_rule;
-               if (!setup.empty()) {
-                       o.wind(ind).wstring(setup).ws("\n");
+               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")
index bd508df07ebe696c698e093fd3bc73ad6b4d460c..e3c34a541e1f62bc233aa15a81e6bf059450ab1b 100644 (file)
@@ -44,7 +44,6 @@ OutputBlock::OutputBlock ()
        , used_yyaccept (false)
        , force_start_label (false)
        , user_start_label ()
-       , setup_rule ()
        , line (0)
        , types ()
        , tags ()
index 34fcc0bd9d4fc03f265cfe7b1b9bc537a4cea115..231c81e85665c79399008023cce093e536eb4cdf 100644 (file)
@@ -62,7 +62,6 @@ struct OutputBlock
        bool used_yyaccept;
        bool force_start_label;
        std::string user_start_label;
-       std::string setup_rule;
        uint32_t line;
        std::vector<std::string> types;
        std::set<std::string> tags;
index 0056fdc5f77096fbce63d02f5aade6d36e9478c1..acdc0cb97249d080107b7f6af933f3cb5495bd7d 100644 (file)
@@ -24,6 +24,7 @@ DFA::DFA
        , const std::string &n
        , const std::string &c
        , uint32_t l
+       , const std::string &s
        )
        : accepts ()
        , name (n)
@@ -46,6 +47,7 @@ DFA::DFA
        , def_rule (def)
        , key_size (key)
        , bitmaps (std::min(ubChar, 256u))
+       , setup(s)
 {
        const size_t nstates = dfa.states.size();
        const size_t nchars = dfa.nchars;
index d5936bd5799701a6c7aa727ab752d173f6f52041..7a447604195af8d0934ba27b4b78908a5304ab00 100644 (file)
@@ -80,6 +80,7 @@ struct DFA
        const size_t def_rule;
        const size_t key_size;
        bitmaps_t bitmaps;
+       std::string setup;
 
        DFA     ( const dfa_t &dfa
                , const std::vector<size_t> &fill
@@ -89,6 +90,7 @@ struct DFA
                , const std::string &n
                , const std::string &c
                , uint32_t l
+               , const std::string &s
                );
        ~DFA ();
        void reorder();
index 7b1eb8dac4570b99276d0bec8dee11dd90151885..572210d22bc5ad6e7c8f74009553c27ed377fce5 100644 (file)
@@ -28,7 +28,7 @@ static std::string make_name(const std::string &cond, uint32_t line)
 }
 
 smart_ptr<DFA> compile(const Spec &rules, Output &output,
-       const std::string &cond, uint32_t cunits)
+       const std::string &cond, uint32_t cunits, const std::string &setup)
 {
        const size_t defrule = !rules.empty() && RegExpRule::is_def(*rules.rbegin())
                        ? rules.size() - 1 : Rule::NONE;
@@ -84,7 +84,8 @@ smart_ptr<DFA> compile(const Spec &rules, Output &output,
        fillpoints(dfa, fill);
 
        // ADFA stands for 'DFA with actions'
-       DFA *adfa = new DFA(dfa, fill, defrule, skeleton.sizeof_key, cs, name, cond, line);
+       DFA *adfa = new DFA(dfa, fill, defrule, skeleton.sizeof_key,
+               cs, name, cond, line, setup);
 
        // see note [reordering DFA states]
        adfa->reorder();
index be3e46c647212ef6eb49bf664b32a320c9f2b78b..c331cac4df2c0af1bf96898af00c84bad04a49fa 100644 (file)
@@ -14,7 +14,7 @@ class DFA;
 struct Output;
 
 smart_ptr<DFA> compile(const Spec &spec, Output &output,
-       const std::string &cond, uint32_t cunits);
+       const std::string &cond, uint32_t cunits, const std::string &setup);
 
 } // namespace re2c
 
index 7a1253259b15d1fb0677bb6e20635209a954e6a5..3014e7377c0b7a93ee5e6c3e51028fab46a77d6e 100644 (file)
@@ -510,7 +510,8 @@ void parse(Scanner &in, Output & o)
 
                        for (it = context.specMap.begin(); it != context.specMap.end(); ++it) {
                                delay_default(it->second);
-                               dfa_map[it->first] = compile(it->second, o, it->first, opts->encoding.nCodeUnits ());
+                               const std::string &setup = find_setup_rule(context.ruleSetupMap, it->first);
+                               dfa_map[it->first] = compile(it->second, o, it->first, opts->encoding.nCodeUnits (), setup);
                        }
                }
 
@@ -519,7 +520,6 @@ void parse(Scanner &in, Output & o)
                        uint32_t ind = opts->topIndent;
                        size_t nCount = dfa_map.size();
                        for (dfa_map_t::const_iterator i = dfa_map.begin(); i != dfa_map.end(); ++i) {
-                               o.source.block().setup_rule = find_setup_rule(context.ruleSetupMap, i->first);
                                i->second->emit(o, ind, !--nCount, bPrologBrace);
                        }
                }