From 0c09cf94a6d3caca04c1b5c1414e391ff4c27ced Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Tue, 4 Aug 2015 10:29:47 +0100 Subject: [PATCH] New condition belongs to the whole rule rather than to rule's code. --- re2c/src/codegen/emit_action.cc | 6 +++--- re2c/src/ir/regexp/regexp_rule.h | 6 +++++- re2c/src/parse/parser.ypp | 30 +++++++++++++++--------------- re2c/src/parse/token.h | 8 ++------ 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/re2c/src/codegen/emit_action.cc b/re2c/src/codegen/emit_action.cc index e5d75afd..f5240532 100644 --- a/re2c/src/codegen/emit_action.cc +++ b/re2c/src/codegen/emit_action.cc @@ -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 { diff --git a/re2c/src/ir/regexp/regexp_rule.h b/re2c/src/ir/regexp/regexp_rule.h index b1c4cdf5..a85751ff 100644 --- a/re2c/src/ir/regexp/regexp_rule.h +++ b/re2c/src/ir/regexp/regexp_rule.h @@ -1,6 +1,8 @@ #ifndef _RE2C_IR_REGEXP_REGEXP_RULE_ #define _RE2C_IR_REGEXP_REGEXP_RULE_ +#include + #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; } diff --git a/re2c/src/parse/parser.ypp b/re2c/src/parse/parser.ypp index 4a5aafd6..b00a344a 100644 --- a/re2c/src/parse/parser.ypp +++ b/re2c/src/parse/parser.ypp @@ -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()) diff --git a/re2c/src/parse/token.h b/re2c/src/parse/token.h index 4d92685d..6f286335 100644 --- a/re2c/src/parse/token.h +++ b/re2c/src/parse/token.h @@ -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) -- 2.40.0