From: helly Date: Mon, 21 Jan 2008 22:16:13 +0000 (+0000) Subject: - Update memory management, fixes code generation with condition support X-Git-Tag: 0.13.6~104 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dcb7a5a0a3198c2c95e6f3a0223898b54d0025bf;p=re2c - Update memory management, fixes code generation with condition support - Optimize detection whether a condition change is required, implements TODO --- diff --git a/re2c/bootstrap/parser.cc b/re2c/bootstrap/parser.cc index c5f41f2c..ec61cc73 100644 --- a/re2c/bootstrap/parser.cc +++ b/re2c/bootstrap/parser.cc @@ -174,12 +174,10 @@ void context_none(CondList *clist) void context_rule(CondList *clist, RegExp *expr, RegExp *look, Str *newcond, Token *code) { context_check(clist); - bool condchange = !newcond || clist->size() > 1 - || clist->find(newcond->to_string()) == clist->end(); for(CondList::const_iterator it = clist->begin(); it != clist->end(); ++it) { - Str *condcpy = newcond ? new Str(*newcond) : newcond; - Token *token = new Token(code, in->get_line(), condcpy, condchange); + //Str *condcpy = newcond ? new Str(*newcond) : newcond; + Token *token = new Token(code, in->get_line(), newcond);//condcpy); RuleOp *rule = new RuleOp(expr, look, token, accept++); RegExpMap::iterator itRE = specMap.find(*it); @@ -196,6 +194,7 @@ void context_rule(CondList *clist, RegExp *expr, RegExp *look, Str *newcond, Tok } delete clist; + delete newcond; delete code; } @@ -221,7 +220,7 @@ void context_rule(CondList *clist, RegExp *expr, RegExp *look, Str *newcond, Tok #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE -#line 107 "parser.y" +#line 106 "parser.y" { re2c::Symbol *symbol; re2c::RegExp *regexp; @@ -233,7 +232,7 @@ typedef union YYSTYPE re2c::CondList *clist; } /* Line 187 of yacc.c. */ -#line 237 "parser.cc" +#line 236 "parser.cc" YYSTYPE; # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 @@ -246,7 +245,7 @@ typedef union YYSTYPE /* Line 216 of yacc.c. */ -#line 250 "parser.cc" +#line 249 "parser.cc" #ifdef short # undef short @@ -548,11 +547,11 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 136, 136, 140, 141, 145, 153, 157, 163, 171, - 180, 184, 189, 193, 198, 204, 211, 215, 220, 230, - 245, 248, 255, 260, 269, 272, 280, 283, 290, 294, - 301, 305, 316, 320, 327, 331, 346, 353, 357, 361, - 365, 372, 380, 384, 388 + 0, 135, 135, 139, 140, 144, 152, 156, 162, 170, + 179, 183, 188, 193, 199, 207, 215, 220, 226, 238, + 254, 257, 264, 269, 278, 281, 289, 292, 299, 303, + 310, 314, 325, 329, 336, 340, 355, 362, 366, 370, + 374, 381, 389, 393, 397 }; #endif @@ -1504,7 +1503,7 @@ yyreduce: switch (yyn) { case 2: -#line 136 "parser.y" +#line 135 "parser.y" { accept = 0; spec = NULL; @@ -1512,7 +1511,7 @@ yyreduce: break; case 5: -#line 146 "parser.y" +#line 145 "parser.y" { if((yyvsp[(1) - (4)].symbol)->re) { @@ -1523,14 +1522,14 @@ yyreduce: break; case 6: -#line 154 "parser.y" +#line 153 "parser.y" { in->fatal("trailing contexts are not allowed in named definitions"); } break; case 7: -#line 158 "parser.y" +#line 157 "parser.y" { in->config(*(yyvsp[(1) - (4)].str), *(yyvsp[(3) - (4)].str)); delete (yyvsp[(1) - (4)].str); @@ -1539,7 +1538,7 @@ yyreduce: break; case 8: -#line 164 "parser.y" +#line 163 "parser.y" { in->config(*(yyvsp[(1) - (4)].str), (yyvsp[(3) - (4)].number)); delete (yyvsp[(1) - (4)].str); @@ -1547,7 +1546,7 @@ yyreduce: break; case 9: -#line 172 "parser.y" +#line 171 "parser.y" { if (cFlag) { @@ -1559,14 +1558,14 @@ yyreduce: break; case 10: -#line 181 "parser.y" +#line 180 "parser.y" { context_rule((yyvsp[(2) - (7)].clist), (yyvsp[(4) - (7)].regexp), (yyvsp[(5) - (7)].regexp), (yyvsp[(6) - (7)].str), (yyvsp[(7) - (7)].token)); } break; case 11: -#line 185 "parser.y" +#line 184 "parser.y" { assert((yyvsp[(7) - (7)].str)); context_rule((yyvsp[(2) - (7)].clist), (yyvsp[(4) - (7)].regexp), (yyvsp[(5) - (7)].regexp), (yyvsp[(7) - (7)].str), NULL); @@ -1574,9 +1573,10 @@ yyreduce: break; case 12: -#line 190 "parser.y" +#line 189 "parser.y" { context_none((yyvsp[(2) - (6)].clist)); + delete (yyvsp[(5) - (6)].str); } break; @@ -1585,58 +1585,66 @@ yyreduce: { assert((yyvsp[(6) - (6)].str)); context_none((yyvsp[(2) - (6)].clist)); + delete (yyvsp[(6) - (6)].str); } break; case 14: -#line 199 "parser.y" +#line 200 "parser.y" { context_check(NULL); - (yyvsp[(7) - (7)].token)->newcond = (yyvsp[(6) - (7)].str); - specStar.push_back(new RuleOp((yyvsp[(4) - (7)].regexp), (yyvsp[(5) - (7)].regexp), (yyvsp[(7) - (7)].token), accept++)); + Token *token = new Token((yyvsp[(7) - (7)].token), (yyvsp[(7) - (7)].token)->line, (yyvsp[(6) - (7)].str)); + delete (yyvsp[(7) - (7)].token); + delete (yyvsp[(6) - (7)].str); + specStar.push_back(new RuleOp((yyvsp[(4) - (7)].regexp), (yyvsp[(5) - (7)].regexp), token, accept++)); } break; case 15: -#line 205 "parser.y" +#line 208 "parser.y" { assert((yyvsp[(7) - (7)].str)); context_check(NULL); - Token *token = new Token(NULL, in->get_line(), (yyvsp[(7) - (7)].str), true); + Token *token = new Token(NULL, in->get_line(), (yyvsp[(7) - (7)].str)); + delete (yyvsp[(7) - (7)].str); specStar.push_back(new RuleOp((yyvsp[(4) - (7)].regexp), (yyvsp[(5) - (7)].regexp), token, accept++)); } break; case 16: -#line 212 "parser.y" +#line 216 "parser.y" { context_none(NULL); + delete (yyvsp[(5) - (6)].str); } break; case 17: -#line 216 "parser.y" +#line 221 "parser.y" { assert((yyvsp[(6) - (6)].str)); context_none(NULL); + delete (yyvsp[(6) - (6)].str); } break; case 18: -#line 221 "parser.y" +#line 227 "parser.y" { context_check(NULL); if (specNone) { in->fatal("code to handle illegal condition already defined"); } - (yyvsp[(3) - (3)].token)->newcond = (yyvsp[(2) - (3)].str); - (yyval.regexp) = specNone = new RuleOp(new NullOp(), new NullOp(), (yyvsp[(3) - (3)].token), accept++); + Token *token = new Token((yyvsp[(3) - (3)].token), (yyvsp[(3) - (3)].token)->line, (yyvsp[(2) - (3)].str)); + delete (yyvsp[(2) - (3)].str); + delete (yyvsp[(3) - (3)].token); + (yyval.regexp) = specNone = new RuleOp(new NullOp(), new NullOp(), token, accept++); } break; case 19: -#line 231 "parser.y" +#line 239 "parser.y" { assert((yyvsp[(3) - (3)].str)); context_check(NULL); @@ -1644,27 +1652,28 @@ yyreduce: { in->fatal("code to handle illegal condition already defined"); } - Token *token = new Token(NULL, in->get_line(), (yyvsp[(3) - (3)].str), true); + Token *token = new Token(NULL, in->get_line(), (yyvsp[(3) - (3)].str)); + delete (yyvsp[(3) - (3)].str); (yyval.regexp) = specNone = new RuleOp(new NullOp(), new NullOp(), token, accept++); } break; case 20: -#line 245 "parser.y" +#line 254 "parser.y" { in->fatal("unnamed condition not supported"); } break; case 21: -#line 249 "parser.y" +#line 258 "parser.y" { (yyval.clist) = (yyvsp[(1) - (1)].clist); } break; case 22: -#line 256 "parser.y" +#line 265 "parser.y" { (yyval.clist) = new CondList(); (yyval.clist)->insert((yyvsp[(1) - (1)].symbol)->GetName().to_string()); @@ -1672,7 +1681,7 @@ yyreduce: break; case 23: -#line 261 "parser.y" +#line 270 "parser.y" { (yyvsp[(1) - (3)].clist)->insert((yyvsp[(3) - (3)].symbol)->GetName().to_string()); (yyval.clist) = (yyvsp[(1) - (3)].clist); @@ -1680,56 +1689,56 @@ yyreduce: break; case 24: -#line 269 "parser.y" +#line 278 "parser.y" { (yyval.str) = NULL; } break; case 25: -#line 273 "parser.y" +#line 282 "parser.y" { (yyval.str) = new Str((yyvsp[(3) - (3)].symbol)->GetName().to_string().c_str()); } break; case 26: -#line 280 "parser.y" +#line 289 "parser.y" { (yyval.regexp) = new NullOp; } break; case 27: -#line 284 "parser.y" +#line 293 "parser.y" { (yyval.regexp) = (yyvsp[(2) - (2)].regexp); } break; case 28: -#line 291 "parser.y" +#line 300 "parser.y" { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); } break; case 29: -#line 295 "parser.y" +#line 304 "parser.y" { (yyval.regexp) = mkAlt((yyvsp[(1) - (3)].regexp), (yyvsp[(3) - (3)].regexp)); } break; case 30: -#line 302 "parser.y" +#line 311 "parser.y" { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); } break; case 31: -#line 306 "parser.y" +#line 315 "parser.y" { (yyval.regexp) = mkDiff((yyvsp[(1) - (3)].regexp), (yyvsp[(3) - (3)].regexp)); if(!(yyval.regexp)) @@ -1740,28 +1749,28 @@ yyreduce: break; case 32: -#line 317 "parser.y" +#line 326 "parser.y" { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); } break; case 33: -#line 321 "parser.y" +#line 330 "parser.y" { (yyval.regexp) = new CatOp((yyvsp[(1) - (2)].regexp), (yyvsp[(2) - (2)].regexp)); } break; case 34: -#line 328 "parser.y" +#line 337 "parser.y" { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); } break; case 35: -#line 332 "parser.y" +#line 341 "parser.y" { switch((yyvsp[(2) - (2)].op)) { @@ -1779,42 +1788,42 @@ yyreduce: break; case 36: -#line 347 "parser.y" +#line 356 "parser.y" { (yyval.regexp) = new CloseVOp((yyvsp[(1) - (2)].regexp), (yyvsp[(2) - (2)].extop).minsize, (yyvsp[(2) - (2)].extop).maxsize); } break; case 37: -#line 354 "parser.y" +#line 363 "parser.y" { (yyval.op) = (yyvsp[(1) - (1)].op); } break; case 38: -#line 358 "parser.y" +#line 367 "parser.y" { (yyval.op) = (yyvsp[(1) - (1)].op); } break; case 39: -#line 362 "parser.y" +#line 371 "parser.y" { (yyval.op) = ((yyvsp[(1) - (2)].op) == (yyvsp[(2) - (2)].op)) ? (yyvsp[(1) - (2)].op) : '*'; } break; case 40: -#line 366 "parser.y" +#line 375 "parser.y" { (yyval.op) = ((yyvsp[(1) - (2)].op) == (yyvsp[(2) - (2)].op)) ? (yyvsp[(1) - (2)].op) : '*'; } break; case 41: -#line 373 "parser.y" +#line 382 "parser.y" { if(!(yyvsp[(1) - (1)].symbol)->re) { @@ -1825,21 +1834,21 @@ yyreduce: break; case 42: -#line 381 "parser.y" +#line 390 "parser.y" { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); } break; case 43: -#line 385 "parser.y" +#line 394 "parser.y" { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); } break; case 44: -#line 389 "parser.y" +#line 398 "parser.y" { (yyval.regexp) = (yyvsp[(2) - (3)].regexp); } @@ -1847,7 +1856,7 @@ yyreduce: /* Line 1267 of yacc.c. */ -#line 1851 "parser.cc" +#line 1860 "parser.cc" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -2061,7 +2070,7 @@ yyreturn: } -#line 394 "parser.y" +#line 403 "parser.y" extern "C" { @@ -2121,7 +2130,7 @@ void parse(Scanner& i, std::ostream& o, std::ostream* h) } else { - // We reserved 0 for specNone but is isn't present, + // We reserved 0 for specNone but it is not present, // so we can decrease all specs. for(it = specMap.begin(); it != specMap.end(); ++it) { diff --git a/re2c/bootstrap/y.tab.h b/re2c/bootstrap/y.tab.h index cdafad0e..4d3b909a 100644 --- a/re2c/bootstrap/y.tab.h +++ b/re2c/bootstrap/y.tab.h @@ -70,7 +70,7 @@ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE -#line 107 "parser.y" +#line 106 "parser.y" { re2c::Symbol *symbol; re2c::RegExp *regexp; diff --git a/re2c/code.cc b/re2c/code.cc index 0e2b78de..7ebc9b88 100644 --- a/re2c/code.cc +++ b/re2c/code.cc @@ -440,7 +440,7 @@ static void need(std::ostream &o, uint ind, uint n, bool & readCh, bool bSetMark } } -void Match::emit(std::ostream &o, uint ind, bool &readCh) const +void Match::emit(std::ostream &o, uint ind, bool &readCh, const std::string&) const { if (state->link) { @@ -464,7 +464,7 @@ void Match::emit(std::ostream &o, uint ind, bool &readCh) const } } -void Enter::emit(std::ostream &o, uint ind, bool &readCh) const +void Enter::emit(std::ostream &o, uint ind, bool &readCh, const std::string&) const { if (state->link) { @@ -487,7 +487,7 @@ void Enter::emit(std::ostream &o, uint ind, bool &readCh) const } } -void Initial::emit(std::ostream &o, uint ind, bool &readCh) const +void Initial::emit(std::ostream &o, uint ind, bool &readCh, const std::string&) const { if (!cFlag && !startLabelName.empty()) { @@ -534,7 +534,7 @@ void Initial::emit(std::ostream &o, uint ind, bool &readCh) const } } -void Save::emit(std::ostream &o, uint ind, bool &readCh) const +void Save::emit(std::ostream &o, uint ind, bool &readCh, const std::string&) const { if (bUsedYYAccept) { @@ -568,7 +568,7 @@ Move::Move(State *s) : Action(s) ; } -void Move::emit(std::ostream &, uint, bool &) const +void Move::emit(std::ostream &, uint, bool &, const std::string&) const { ; } @@ -608,7 +608,7 @@ void Accept::emitBinary(std::ostream &o, uint ind, uint l, uint r, bool &readCh) } } -void Accept::emit(std::ostream &o, uint ind, bool &readCh) const +void Accept::emit(std::ostream &o, uint ind, bool &readCh, const std::string&) const { if (mapRules.size() > 0) { @@ -668,7 +668,7 @@ Rule::Rule(State *s, RuleOp *r) : Action(s), rule(r) ; } -void Rule::emit(std::ostream &o, uint ind, bool &) const +void Rule::emit(std::ostream &o, uint ind, bool &, const std::string& condName) const { uint back = rule->ctx->fixedLength(); @@ -677,11 +677,9 @@ void Rule::emit(std::ostream &o, uint ind, bool &) const o << indent(ind) << mapCodeName["YYCURSOR"] << " = " << mapCodeName["YYCTXMARKER"] << ";\n"; } - if (rule->code->newcond && rule->code->condchange) + if (rule->code->newcond.length() && condName != rule->code->newcond) { - // TODO: rather than using condchange we can do this by comparing the - // sourcecondition with the destination condition. - genSetCondition(o, ind, rule->code->newcond->to_string()); + genSetCondition(o, ind, rule->code->newcond); } RuleLine rl(*rule); @@ -690,9 +688,7 @@ void Rule::emit(std::ostream &o, uint ind, bool &) const o << indent(ind); if (rule->code->autogen) { - std::string condLabel(condPrefix); - condLabel += rule->code->newcond->to_string(); - o << replaceParam(condGoto, condGotoParam, condLabel); + o << replaceParam(condGoto, condGotoParam, condPrefix + rule->code->newcond); } else { @@ -1158,7 +1154,7 @@ void Go::genGoto(std::ostream &o, uint ind, const State *from, const State *next genBase(o, ind, from, next, readCh, 0); } -void State::emit(std::ostream &o, uint ind, bool &readCh) const +void State::emit(std::ostream &o, uint ind, bool &readCh, const std::string& condName) const { if (vUsedLabels.count(label)) { @@ -1172,7 +1168,7 @@ void State::emit(std::ostream &o, uint ind, bool &readCh) const { o << indent(ind) << mapCodeName["YYCTXMARKER"] << " = " << mapCodeName["YYCURSOR"] << " + 1;\n"; } - action->emit(o, ind, readCh); + action->emit(o, ind, readCh, condName); } uint merge(Span *x0, State *fg, State *bg) @@ -1649,7 +1645,7 @@ void DFA::emit(std::ostream &o, uint& ind, const RegExpMap* specMap, const std:: for (s = head; s; s = s->next) { bool readCh = false; - s->emit(null_dev, ind, readCh); + s->emit(null_dev, ind, readCh, condName); s->go.genGoto(null_dev, ind, s, s->next, readCh); } if (last_fill_index < next_fill_index) @@ -1740,7 +1736,7 @@ void DFA::emit(std::ostream &o, uint& ind, const RegExpMap* specMap, const std:: for (s = head; s; s = s->next) { bool readCh = false; - s->emit(o, ind, readCh); + s->emit(o, ind, readCh, condName); s->go.genGoto(o, ind, s, s->next, readCh); } diff --git a/re2c/dfa.h b/re2c/dfa.h index fb9a2e00..a4e26519 100644 --- a/re2c/dfa.h +++ b/re2c/dfa.h @@ -28,7 +28,7 @@ public: Action(State*); virtual ~Action(); - virtual void emit(std::ostream&, uint, bool&) const = 0; + virtual void emit(std::ostream&, uint, bool&, const std::string&) const = 0; virtual bool isRule() const; virtual bool isMatch() const; virtual bool isInitial() const; @@ -52,7 +52,7 @@ class Match: public Action { public: Match(State*); - void emit(std::ostream&, uint, bool&) const; + void emit(std::ostream&, uint, bool&, const std::string&) const; bool isMatch() const; }; @@ -63,7 +63,7 @@ public: public: Enter(State*, uint); - void emit(std::ostream&, uint, bool&) const; + void emit(std::ostream&, uint, bool&, const std::string&) const; }; class Initial: public Enter @@ -73,7 +73,7 @@ public: public: Initial(State*, uint, bool); - void emit(std::ostream&, uint, bool&) const; + void emit(std::ostream&, uint, bool&, const std::string&) const; bool isInitial() const; }; @@ -85,7 +85,7 @@ public: public: Save(State*, uint); - void emit(std::ostream&, uint, bool&) const; + void emit(std::ostream&, uint, bool&, const std::string&) const; bool isMatch() const; }; @@ -94,7 +94,7 @@ class Move: public Action public: Move(State*); - void emit(std::ostream&, uint, bool&) const; + void emit(std::ostream&, uint, bool&, const std::string&) const; }; class Accept: public Action @@ -110,7 +110,7 @@ public: public: Accept(State*, uint, uint*, State**); - void emit(std::ostream&, uint, bool&) const; + void emit(std::ostream&, uint, bool&, const std::string&) const; void emitBinary(std::ostream &o, uint ind, uint l, uint r, bool &readCh) const; void genRuleMap(); @@ -139,7 +139,7 @@ public: public: Rule(State*, RuleOp*); - void emit(std::ostream&, uint, bool&) const; + void emit(std::ostream&, uint, bool&, const std::string&) const; bool isRule() const; #ifdef PEDANTIC @@ -220,7 +220,7 @@ public: public: State(); ~State(); - void emit(std::ostream&, uint, bool&) const; + void emit(std::ostream&, uint, bool&, const std::string&) const; friend std::ostream& operator<<(std::ostream&, const State&); friend std::ostream& operator<<(std::ostream&, const State*); diff --git a/re2c/parser.y b/re2c/parser.y index 36a8bbab..fae174f7 100644 --- a/re2c/parser.y +++ b/re2c/parser.y @@ -75,12 +75,10 @@ void context_none(CondList *clist) void context_rule(CondList *clist, RegExp *expr, RegExp *look, Str *newcond, Token *code) { context_check(clist); - bool condchange = !newcond || clist->size() > 1 - || clist->find(newcond->to_string()) == clist->end(); for(CondList::const_iterator it = clist->begin(); it != clist->end(); ++it) { - Str *condcpy = newcond ? new Str(*newcond) : newcond; - Token *token = new Token(code, in->get_line(), condcpy, condchange); + //Str *condcpy = newcond ? new Str(*newcond) : newcond; + Token *token = new Token(code, in->get_line(), newcond);//condcpy); RuleOp *rule = new RuleOp(expr, look, token, accept++); RegExpMap::iterator itRE = specMap.find(*it); @@ -97,6 +95,7 @@ void context_rule(CondList *clist, RegExp *expr, RegExp *look, Str *newcond, Tok } delete clist; + delete newcond; delete code; } @@ -189,33 +188,40 @@ rule: | '<' cond '>' look newcond CODE { context_none($2); + delete $5; } | '<' cond '>' look ':' newcond { assert($6); context_none($2); + delete $6; } | '<' STAR '>' expr look newcond CODE { context_check(NULL); - $7->newcond = $6; - specStar.push_back(new RuleOp($4, $5, $7, accept++)); + Token *token = new Token($7, $7->line, $6); + delete $7; + delete $6; + specStar.push_back(new RuleOp($4, $5, token, accept++)); } | '<' STAR '>' expr look ':' newcond { assert($7); context_check(NULL); - Token *token = new Token(NULL, in->get_line(), $7, true); + Token *token = new Token(NULL, in->get_line(), $7); + delete $7; specStar.push_back(new RuleOp($4, $5, token, accept++)); } | '<' STAR '>' look newcond CODE { context_none(NULL); + delete $5; } | '<' STAR '>' look ':' newcond { assert($6); context_none(NULL); + delete $6; } | NOCOND newcond CODE { @@ -224,8 +230,10 @@ rule: { in->fatal("code to handle illegal condition already defined"); } - $3->newcond = $2; - $$ = specNone = new RuleOp(new NullOp(), new NullOp(), $3, accept++); + Token *token = new Token($3, $3->line, $2); + delete $2; + delete $3; + $$ = specNone = new RuleOp(new NullOp(), new NullOp(), token, accept++); } | NOCOND ':' newcond { @@ -235,7 +243,8 @@ rule: { in->fatal("code to handle illegal condition already defined"); } - Token *token = new Token(NULL, in->get_line(), $3, true); + Token *token = new Token(NULL, in->get_line(), $3); + delete $3; $$ = specNone = new RuleOp(new NullOp(), new NullOp(), token, accept++); } ; diff --git a/re2c/substr.h b/re2c/substr.h index a9ab432c..26fcb3be 100644 --- a/re2c/substr.h +++ b/re2c/substr.h @@ -74,7 +74,7 @@ inline SubStr::~SubStr() inline std::string SubStr::to_string() const { - return std::string(str, len); + return str && len ? std::string(str, len) : std::string(); } inline uint SubStr::ofs() const diff --git a/re2c/test/condition_11.cg.c b/re2c/test/condition_11.cg.c index eca563bb..e2d5dbb2 100755 --- a/re2c/test/condition_11.cg.c +++ b/re2c/test/condition_11.cg.c @@ -13,9 +13,10 @@ /* *********************************** */ yyc_0: + YYSETCONDITION(yycr1); #line 3 "condition_11.cg.re" { return NULL; } -#line 19 "" +#line 20 "" /* *********************************** */ yyc_r1: if(YYLIMIT == YYCURSOR) YYFILL(1); @@ -34,24 +35,24 @@ yy6: ++YYCURSOR; #line 5 "condition_11.cg.re" { return "2"; } -#line 38 "" +#line 39 "" yy8: ++YYCURSOR; #line 4 "condition_11.cg.re" { return "1"; } -#line 43 "" +#line 44 "" yy10: ++YYCURSOR; YYSETCONDITION(yycr2); #line 6 "condition_11.cg.re" { return "a"; } -#line 49 "" +#line 50 "" yy12: ++YYCURSOR; YYSETCONDITION(yycr2); #line 7 "condition_11.cg.re" { return "b"; } -#line 55 "" +#line 56 "" /* *********************************** */ yyc_r2: if(YYLIMIT == YYCURSOR) YYFILL(1); @@ -66,20 +67,21 @@ yyc_r2: yy16: yy17: ++YYCURSOR; + YYSETCONDITION(yycr1); #line 5 "condition_11.cg.re" { return "2"; } -#line 72 "" +#line 74 "" yy19: ++YYCURSOR; + YYSETCONDITION(yycr1); #line 4 "condition_11.cg.re" { return "1"; } -#line 77 "" +#line 80 "" yy21: ++YYCURSOR; - YYSETCONDITION(yyc); #line 7 "condition_11.cg.re" { return "b"; } -#line 83 "" +#line 85 "" } #line 9 "condition_11.cg.re" diff --git a/re2c/test/condition_13.cg.c b/re2c/test/condition_13.cg.c index 3b3ad1ee..c8a5c196 100755 --- a/re2c/test/condition_13.cg.c +++ b/re2c/test/condition_13.cg.c @@ -33,28 +33,26 @@ yyc_r1: yy5: yy6: ++YYCURSOR; - YYSETCONDITION(yycr1); #line 5 "condition_13.cg.re" goto yyc_r1; -#line 40 "" +#line 39 "" yy8: ++YYCURSOR; - YYSETCONDITION(yycr1); #line 4 "condition_13.cg.re" goto yyc_r1; -#line 46 "" +#line 44 "" yy10: ++YYCURSOR; YYSETCONDITION(yycr2); #line 6 "condition_13.cg.re" goto yyc_r2; -#line 52 "" +#line 50 "" yy12: ++YYCURSOR; YYSETCONDITION(yycr2); #line 7 "condition_13.cg.re" goto yyc_r2; -#line 58 "" +#line 56 "" /* *********************************** */ yyc_r2: if(YYLIMIT == YYCURSOR) YYFILL(1); @@ -72,19 +70,18 @@ yy17: YYSETCONDITION(yycr1); #line 5 "condition_13.cg.re" goto yyc_r1; -#line 76 "" +#line 74 "" yy19: ++YYCURSOR; YYSETCONDITION(yycr1); #line 4 "condition_13.cg.re" goto yyc_r1; -#line 82 "" +#line 80 "" yy21: ++YYCURSOR; - YYSETCONDITION(yyc); #line 7 "condition_13.cg.re" - goto yyc_; -#line 88 "" + goto yyc_r2; +#line 85 "" } #line 9 "condition_13.cg.re" diff --git a/re2c/token.h b/re2c/token.h index 10f2c1c4..cded2a60 100644 --- a/re2c/token.h +++ b/re2c/token.h @@ -10,52 +10,47 @@ namespace re2c class Token { public: - const Str text; - const Str* newcond; - const uint line; - const bool autogen; - const bool condchange; + const Str text; + const std::string newcond; + const uint line; + const bool autogen; public: Token(const SubStr&, uint); - Token(const Token*, uint, Str*, bool); + Token(const Token*, uint, const Str*); Token(const Token& oth); ~Token(); }; inline Token::Token(const SubStr& t, uint l) : text(t) - , newcond(NULL) + , newcond() , line(l) , autogen(false) - , condchange(false) { ; } -inline Token::Token(const Token* t, uint l, Str *c, bool chg) +inline Token::Token(const Token* t, uint l, const Str *c) : text(t ? t->text.to_string().c_str() : "") - , newcond(c) + , newcond(c ? c->to_string() : "") , line(t ? t->line : l) , autogen(t == NULL) - , condchange(chg) { ; } inline Token::Token(const Token& oth) : text(oth.text.to_string().c_str()) - , newcond(oth.newcond ? new Str(*oth.newcond) : NULL) + , newcond(oth.newcond) , line(oth.line) , autogen(oth.autogen) - , condchange(oth.autogen) { ; } inline Token::~Token() { - delete newcond; } } // end namespace re2c