]> granicus.if.org Git - re2c/commitdiff
New condition belongs to the whole rule rather than to rule's code.
authorUlya Trofimovich <skvadrik@gmail.com>
Tue, 4 Aug 2015 09:29:47 +0000 (10:29 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Tue, 4 Aug 2015 09:29:47 +0000 (10:29 +0100)
re2c/src/codegen/emit_action.cc
re2c/src/ir/regexp/regexp_rule.h
re2c/src/parse/parser.ypp
re2c/src/parse/token.h

index e5d75afd1324480efea78c2ae8f43559e8f05292..f52405320cb0cbf22627035694bdc43930079988 100644 (file)
@@ -243,9 +243,9 @@ void emit_rule (OutputFile & o, uint32_t ind, const State * const s, const RuleO
                o << input_api.stmt_restorectx (ind);
        }
 
-       if (rule->code->newcond.length() && condName != rule->code->newcond)
+       if (rule->newcond.length() && condName != rule->newcond)
        {
-               genSetCondition(o, ind, rule->code->newcond);
+               genSetCondition(o, ind, rule->newcond);
        }
 
        if (!yySetupRule.empty() && !rule->code->autogen)
@@ -266,7 +266,7 @@ void emit_rule (OutputFile & o, uint32_t ind, const State * const s, const RuleO
        }
        else if (rule->code->autogen)
        {
-               o << replaceParam(condGoto, condGotoParam, condPrefix + rule->code->newcond);
+               o << replaceParam(condGoto, condGotoParam, condPrefix + rule->newcond);
        }
        else
        {
index b1c4cdf5b30fa69b159ad637a9b3f4d24b8d2180..a85751ffdf5d67c0d8f2cd6b042ca7b8bf6a5349 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef _RE2C_IR_REGEXP_REGEXP_RULE_
 #define _RE2C_IR_REGEXP_REGEXP_RULE_
 
+#include <string>
+
 #include "src/ir/regexp/regexp.h"
 #include "src/ir/rule_rank.h"
 #include "src/parse/token.h"
@@ -17,13 +19,15 @@ public:
        Ins * ins;
        rule_rank_t rank;
        Token * code;
+       const std::string newcond;
 
-       inline RuleOp (RegExp * e, RegExp * c, Token * t, rule_rank_t r, InsAccess access)
+       inline RuleOp (RegExp * e, RegExp * c, Token * t, rule_rank_t r, InsAccess access, const std::string * n)
                : exp (e)
                , ctx (c)
                , ins (NULL)
                , rank (r)
                , code (t)
+               , newcond (n ? *n : "")
        {
                ins_access = access;
        }
index 4a5aafd65a5311c238aca0b5e6cc82174f1b0019..b00a344a454c6094a72f1a283d03aff7a6bcc5b1 100644 (file)
@@ -74,8 +74,8 @@ void context_rule(CondList *clist, RegExp *expr, RegExp *look, const std::string
                : RegExp::SHARED;
        for(CondList::const_iterator it = clist->begin(); it != clist->end(); ++it)
        {
-               Token *token = new Token(code, in->get_fname (), in->get_cline (), newcond);//condcpy);
-               RuleOp *rule = new RuleOp(expr, look, token, rank_counter.next (), ins_access);
+               Token *token = new Token(code, in->get_fname (), in->get_cline ());
+               RuleOp *rule = new RuleOp(expr, look, token, rank_counter.next (), ins_access, newcond);
 
                RegExpMap::iterator itRE = specMap.find(*it);
 
@@ -216,7 +216,7 @@ rule:
                        {
                                in->fatal("condition or '<*>' required when using -c switch");
                        }
-                       $$ = new RuleOp($1, $2, $3, rank_counter.next (), RegExp::SHARED);
+                       $$ = new RuleOp($1, $2, $3, rank_counter.next (), RegExp::SHARED, NULL);
                        spec = spec? mkAlt(spec, $$) : $$;
                }
        |       STAR CODE /* default rule */
@@ -255,18 +255,18 @@ rule:
        |       '<' STAR '>' expr look newcond CODE
                {
                        context_check(NULL);
-                       Token *token = new Token($7, $7->source, $7->line, $6);
+                       Token *token = new Token($7, $7->source, $7->line);
                        delete $7;
+                       specStar.push_back(new RuleOp($4, $5, token, rank_counter.next (), RegExp::PRIVATE, $6));
                        delete $6;
-                       specStar.push_back(new RuleOp($4, $5, token, rank_counter.next (), RegExp::PRIVATE));
                }
        |       '<' STAR '>' expr look ':' newcond
                {
                        assert($7);
                        context_check(NULL);
-                       Token *token = new Token(NULL, in->get_fname (), in->get_cline (), $7);
+                       Token *token = new Token(NULL, in->get_fname (), in->get_cline ());
+                       specStar.push_back(new RuleOp($4, $5, token, rank_counter.next (), RegExp::PRIVATE, $7));
                        delete $7;
-                       specStar.push_back(new RuleOp($4, $5, token, rank_counter.next (), RegExp::PRIVATE));
                }
        |       '<' STAR '>' look newcond CODE
                {
@@ -292,10 +292,10 @@ rule:
                        {
                                in->fatal("code to handle illegal condition already defined");
                        }
-                       Token *token = new Token($3, $3->source, $3->line, $2);
-                       delete $2;
+                       Token *token = new Token($3, $3->source, $3->line);
                        delete $3;
-                       $$ = specNone = new RuleOp(new NullOp(), new NullOp(), token, rank_counter.next (), RegExp::SHARED);
+                       $$ = specNone = new RuleOp(new NullOp(), new NullOp(), token, rank_counter.next (), RegExp::SHARED, $2);
+                       delete $2;
                }
        |       NOCOND ':' newcond
                {
@@ -305,9 +305,9 @@ rule:
                        {
                                in->fatal("code to handle illegal condition already defined");
                        }
-                       Token *token = new Token(NULL, in->get_fname (), in->get_cline (), $3);
+                       Token *token = new Token(NULL, in->get_fname (), in->get_cline ());
+                       $$ = specNone = new RuleOp(new NullOp(), new NullOp(), token, rank_counter.next (), RegExp::SHARED, $3);
                        delete $3;
-                       $$ = specNone = new RuleOp(new NullOp(), new NullOp(), token, rank_counter.next (), RegExp::SHARED);
                }
        |       SETUP STAR '>' CODE
                {
@@ -636,7 +636,7 @@ void parse(Scanner& i, Output & o)
                                        itRuleDefault = ruleDefaultMap.find(it->first);
                                        if (itRuleDefault != ruleDefaultMap.end())
                                        {
-                                               RuleOp * def = new RuleOp(in->mkDefault(), new NullOp(), itRuleDefault->second, rank_counter.next (), RegExp::SHARED);
+                                               RuleOp * def = new RuleOp(in->mkDefault(), new NullOp(), itRuleDefault->second, rank_counter.next (), RegExp::SHARED, NULL);
                                                it->second.second = it->second.second ? mkAlt(def, it->second.second) : def;
                                        }
                                        else
@@ -644,7 +644,7 @@ void parse(Scanner& i, Output & o)
                                                itRuleDefault = ruleDefaultMap.find("*");
                                                if (itRuleDefault != ruleDefaultMap.end())
                                                {
-                                                       RuleOp * def = new RuleOp(in->mkDefault(), new NullOp(), itRuleDefault->second, rank_counter.next (), RegExp::SHARED);
+                                                       RuleOp * def = new RuleOp(in->mkDefault(), new NullOp(), itRuleDefault->second, rank_counter.next (), RegExp::SHARED, NULL);
                                                        it->second.second = it->second.second ? mkAlt(def, it->second.second) : def;
                                                }
                                        }
@@ -662,7 +662,7 @@ void parse(Scanner& i, Output & o)
                {
                        if (ruleDefault != NULL && parseMode != Scanner::Reuse)
                        {
-                               RuleOp * def = new RuleOp(in->mkDefault(), new NullOp(), ruleDefault, rank_counter.next (), RegExp::SHARED);
+                               RuleOp * def = new RuleOp(in->mkDefault(), new NullOp(), ruleDefault, rank_counter.next (), RegExp::SHARED, NULL);
                                spec = spec ? mkAlt(def, spec) : def;
                        }
                        if (spec || !dfa_map.empty())
index 4d92685d3abbfbf4db819d087145daa6a0adb0a9..6f286335bbd009df0863595feb652ad57b8c8584 100644 (file)
@@ -11,28 +11,25 @@ class Token
 {
 public:
        const std::string text;
-       const std::string newcond;
        const std::string source;
        uint32_t line;
        const bool autogen;
 
        Token (const char *, uint32_t, const std::string &, uint32_t);
-       Token (const Token *, const std::string &, uint32_t, const std::string *);
+       Token (const Token *, const std::string &, uint32_t);
 
        FORBID_COPY (Token);
 };
 
 inline Token::Token (const char * t, uint32_t t_len, const std::string & s, uint32_t l)
        : text (t, t_len)
-       , newcond ()
        , source (s)
        , line (l)
        , autogen (false)
 {}
 
-inline Token::Token (const Token * t, const std::string & s, uint32_t l, const std::string * c)
+inline Token::Token (const Token * t, const std::string & s, uint32_t l)
        : text (t ? t->text : "")
-       , newcond (c ? * c : "")
        , source (t ? t->source : s)
        , line (t ? t->line : l)
        , autogen (t == NULL)
@@ -40,7 +37,6 @@ inline Token::Token (const Token * t, const std::string & s, uint32_t l, const s
 
 inline Token::Token (const Token & t)
        : text (t.text)
-       , newcond (t.newcond)
        , source (t.source)
        , line (t.line)
        , autogen (t.autogen)