From 23d0e467828735f1844101e04876cd8a835eaa5e Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Thu, 14 May 2015 12:25:24 +0100 Subject: [PATCH] Simplified handling of named definitions in parser. Don't bother with named definitions in lexer, just pass them as strings to parser. Parser will recognize named definitions, insert them into symbol table and handle conflicts. Use simple 'std::map' instead 're2c::Symbol' class (that hides symbol table in class static member). Use 'std::string' instead of 're2c::Str'. Due to bison limitations we have to pass pointers to strings allocated on the heap and carefully destroy them. The whole thing is quite error prone, so maybe I'll make a small slab allocator for parser later on. --- re2c/Makefile.am | 2 - re2c/bootstrap/parser.cc | 117 +++++++++++++++++----------------- re2c/bootstrap/scanner_lex.cc | 15 ++--- re2c/bootstrap/y.tab.h | 5 +- re2c/src/parse/parser.h | 1 + re2c/src/parse/parser.ypp | 38 +++++------ re2c/src/parse/scanner.cc | 13 ++-- re2c/src/parse/scanner.h | 2 +- re2c/src/parse/scanner_lex.re | 13 ++-- re2c/src/parse/symbol.cc | 29 --------- re2c/src/parse/symbol.h | 42 ------------ re2c/src/parse/token.h | 6 +- 12 files changed, 107 insertions(+), 176 deletions(-) delete mode 100644 re2c/src/parse/symbol.cc delete mode 100644 re2c/src/parse/symbol.h diff --git a/re2c/Makefile.am b/re2c/Makefile.am index 14f2cabb..47134af8 100644 --- a/re2c/Makefile.am +++ b/re2c/Makefile.am @@ -55,7 +55,6 @@ SRC_HDR = \ $(srcdir)/src/parse/input.h \ $(srcdir)/src/parse/parser.h \ $(srcdir)/src/parse/scanner.h \ - $(srcdir)/src/parse/symbol.h \ $(srcdir)/src/parse/token.h \ $(srcdir)/src/util/allocate.h \ $(srcdir)/src/util/c99_stdint.h \ @@ -95,7 +94,6 @@ SRC = \ $(srcdir)/src/mbo_getopt.cc \ $(srcdir)/src/parse/input.cc \ $(srcdir)/src/parse/scanner.cc \ - $(srcdir)/src/parse/symbol.cc \ $(srcdir)/src/util/range.cc \ $(srcdir)/src/util/substr.cc # omit SRC_PARSER here; include it in EXTRA_DIST instead diff --git a/re2c/bootstrap/parser.cc b/re2c/bootstrap/parser.cc index bef481de..e865de25 100644 --- a/re2c/bootstrap/parser.cc +++ b/re2c/bootstrap/parser.cc @@ -84,7 +84,6 @@ #include "src/codegen/dfa_emit.h" // genTypes #include "src/globals.h" #include "src/parse/parser.h" -#include "src/parse/symbol.h" #include "src/util/c99_stdint.h" #include "src/util/smart_ptr.h" @@ -109,6 +108,7 @@ static SetupMap ruleSetupMap; static Token *ruleDefault = NULL; static DefaultMap ruleDefaultMap; static bool foundRules; +static symbol_table_t symbol_table; /* Bison version 1.875 emits a definition that is not working * with several g++ version. Hence we disable it here. @@ -150,7 +150,7 @@ void context_none(CondList *clist) in->fatal("no expression specified"); } -void context_rule(CondList *clist, RegExp *expr, RegExp *look, Str *newcond, Token *code) +void context_rule(CondList *clist, RegExp *expr, RegExp *look, const std::string * newcond, Token *code) { context_check(clist); const RegExp::InsAccess ins_access = clist->size() > 1 @@ -269,19 +269,18 @@ typedef union YYSTYPE /* Line 214 of yacc.c */ #line 151 "../src/parse/parser.ypp" - re2c::Symbol *symbol; re2c::RegExp *regexp; re2c::Token *token; char op; int number; re2c::ExtOp extop; - re2c::Str *str; + std::string *str; re2c::CondList *clist; /* Line 214 of yacc.c */ -#line 285 "./parser.cc" +#line 284 "./parser.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -293,7 +292,7 @@ typedef union YYSTYPE /* Line 264 of yacc.c */ -#line 297 "./parser.cc" +#line 296 "./parser.cc" #ifdef short # undef short @@ -600,12 +599,12 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 180, 180, 182, 186, 190, 199, 208, 212, 216, - 222, 230, 239, 248, 252, 257, 262, 268, 272, 280, - 288, 293, 299, 305, 317, 329, 335, 343, 346, 353, - 358, 367, 370, 378, 381, 388, 392, 399, 403, 414, - 418, 425, 429, 444, 451, 455, 459, 463, 470, 478, - 482, 486 + 0, 178, 178, 180, 184, 188, 197, 206, 210, 214, + 220, 228, 237, 246, 250, 255, 260, 266, 270, 278, + 286, 291, 297, 303, 315, 327, 333, 341, 344, 351, + 357, 367, 370, 378, 381, 388, 392, 399, 403, 414, + 418, 425, 429, 444, 451, 455, 459, 463, 470, 480, + 484, 488 }; #endif @@ -1574,7 +1573,7 @@ yyreduce: case 2: /* Line 1464 of yacc.c */ -#line 180 "../src/parse/parser.ypp" +#line 178 "../src/parse/parser.ypp" { ;} break; @@ -1582,7 +1581,7 @@ yyreduce: case 3: /* Line 1464 of yacc.c */ -#line 183 "../src/parse/parser.ypp" +#line 181 "../src/parse/parser.ypp" { foundRules = true; ;} @@ -1591,35 +1590,35 @@ yyreduce: case 5: /* Line 1464 of yacc.c */ -#line 191 "../src/parse/parser.ypp" +#line 189 "../src/parse/parser.ypp" { - if ((yyvsp[(1) - (4)].symbol)->re) + if (!symbol_table.insert (std::make_pair (* (yyvsp[(1) - (4)].str), (yyvsp[(3) - (4)].regexp))).second) { in->fatal("sym already defined"); } + delete (yyvsp[(1) - (4)].str); (yyvsp[(3) - (4)].regexp)->ins_access = RegExp::PRIVATE; - (yyvsp[(1) - (4)].symbol)->re = (yyvsp[(3) - (4)].regexp); ;} break; case 6: /* Line 1464 of yacc.c */ -#line 200 "../src/parse/parser.ypp" +#line 198 "../src/parse/parser.ypp" { - if ((yyvsp[(1) - (2)].symbol)->re) + if (!symbol_table.insert (std::make_pair (* (yyvsp[(1) - (2)].str), (yyvsp[(2) - (2)].regexp))).second) { in->fatal("sym already defined"); } + delete (yyvsp[(1) - (2)].str); (yyvsp[(2) - (2)].regexp)->ins_access = RegExp::PRIVATE; - (yyvsp[(1) - (2)].symbol)->re = (yyvsp[(2) - (2)].regexp); ;} break; case 7: /* Line 1464 of yacc.c */ -#line 209 "../src/parse/parser.ypp" +#line 207 "../src/parse/parser.ypp" { in->fatal("trailing contexts are not allowed in named definitions"); ;} @@ -1628,7 +1627,7 @@ yyreduce: case 8: /* Line 1464 of yacc.c */ -#line 213 "../src/parse/parser.ypp" +#line 211 "../src/parse/parser.ypp" { in->fatal("trailing contexts are not allowed in named definitions"); ;} @@ -1637,9 +1636,9 @@ yyreduce: case 9: /* Line 1464 of yacc.c */ -#line 217 "../src/parse/parser.ypp" +#line 215 "../src/parse/parser.ypp" { - in->config((yyvsp[(1) - (4)].str)->to_string (), *(yyvsp[(3) - (4)].str)); + in->config (* (yyvsp[(1) - (4)].str), * (yyvsp[(3) - (4)].str)); delete (yyvsp[(1) - (4)].str); delete (yyvsp[(3) - (4)].str); ;} @@ -1648,9 +1647,9 @@ yyreduce: case 10: /* Line 1464 of yacc.c */ -#line 223 "../src/parse/parser.ypp" +#line 221 "../src/parse/parser.ypp" { - in->config((yyvsp[(1) - (4)].str)->to_string (), (yyvsp[(3) - (4)].number)); + in->config (* (yyvsp[(1) - (4)].str), (yyvsp[(3) - (4)].number)); delete (yyvsp[(1) - (4)].str); ;} break; @@ -1658,7 +1657,7 @@ yyreduce: case 11: /* Line 1464 of yacc.c */ -#line 231 "../src/parse/parser.ypp" +#line 229 "../src/parse/parser.ypp" { if (cFlag) { @@ -1672,7 +1671,7 @@ yyreduce: case 12: /* Line 1464 of yacc.c */ -#line 240 "../src/parse/parser.ypp" +#line 238 "../src/parse/parser.ypp" { if (cFlag) in->fatal("condition or '<*>' required when using -c switch"); @@ -1686,7 +1685,7 @@ yyreduce: case 13: /* Line 1464 of yacc.c */ -#line 249 "../src/parse/parser.ypp" +#line 247 "../src/parse/parser.ypp" { context_rule((yyvsp[(2) - (7)].clist), (yyvsp[(4) - (7)].regexp), (yyvsp[(5) - (7)].regexp), (yyvsp[(6) - (7)].str), (yyvsp[(7) - (7)].token)); ;} @@ -1695,7 +1694,7 @@ yyreduce: case 14: /* Line 1464 of yacc.c */ -#line 253 "../src/parse/parser.ypp" +#line 251 "../src/parse/parser.ypp" { assert((yyvsp[(7) - (7)].str)); context_rule((yyvsp[(2) - (7)].clist), (yyvsp[(4) - (7)].regexp), (yyvsp[(5) - (7)].regexp), (yyvsp[(7) - (7)].str), NULL); @@ -1705,7 +1704,7 @@ yyreduce: case 15: /* Line 1464 of yacc.c */ -#line 258 "../src/parse/parser.ypp" +#line 256 "../src/parse/parser.ypp" { context_none((yyvsp[(2) - (6)].clist)); delete (yyvsp[(5) - (6)].str); @@ -1715,7 +1714,7 @@ yyreduce: case 16: /* Line 1464 of yacc.c */ -#line 263 "../src/parse/parser.ypp" +#line 261 "../src/parse/parser.ypp" { assert((yyvsp[(6) - (6)].str)); context_none((yyvsp[(2) - (6)].clist)); @@ -1726,7 +1725,7 @@ yyreduce: case 17: /* Line 1464 of yacc.c */ -#line 269 "../src/parse/parser.ypp" +#line 267 "../src/parse/parser.ypp" { default_rule((yyvsp[(2) - (5)].clist), (yyvsp[(5) - (5)].token)); ;} @@ -1735,7 +1734,7 @@ yyreduce: case 18: /* Line 1464 of yacc.c */ -#line 273 "../src/parse/parser.ypp" +#line 271 "../src/parse/parser.ypp" { context_check(NULL); Token *token = new Token((yyvsp[(7) - (7)].token), (yyvsp[(7) - (7)].token)->source, (yyvsp[(7) - (7)].token)->line, (yyvsp[(6) - (7)].str)); @@ -1748,7 +1747,7 @@ yyreduce: case 19: /* Line 1464 of yacc.c */ -#line 281 "../src/parse/parser.ypp" +#line 279 "../src/parse/parser.ypp" { assert((yyvsp[(7) - (7)].str)); context_check(NULL); @@ -1761,7 +1760,7 @@ yyreduce: case 20: /* Line 1464 of yacc.c */ -#line 289 "../src/parse/parser.ypp" +#line 287 "../src/parse/parser.ypp" { context_none(NULL); delete (yyvsp[(5) - (6)].str); @@ -1771,7 +1770,7 @@ yyreduce: case 21: /* Line 1464 of yacc.c */ -#line 294 "../src/parse/parser.ypp" +#line 292 "../src/parse/parser.ypp" { assert((yyvsp[(6) - (6)].str)); context_none(NULL); @@ -1782,7 +1781,7 @@ yyreduce: case 22: /* Line 1464 of yacc.c */ -#line 300 "../src/parse/parser.ypp" +#line 298 "../src/parse/parser.ypp" { CondList *clist = new CondList(); clist->insert("*"); @@ -1793,7 +1792,7 @@ yyreduce: case 23: /* Line 1464 of yacc.c */ -#line 306 "../src/parse/parser.ypp" +#line 304 "../src/parse/parser.ypp" { context_check(NULL); if (specNone) @@ -1810,7 +1809,7 @@ yyreduce: case 24: /* Line 1464 of yacc.c */ -#line 318 "../src/parse/parser.ypp" +#line 316 "../src/parse/parser.ypp" { assert((yyvsp[(3) - (3)].str)); context_check(NULL); @@ -1827,7 +1826,7 @@ yyreduce: case 25: /* Line 1464 of yacc.c */ -#line 330 "../src/parse/parser.ypp" +#line 328 "../src/parse/parser.ypp" { CondList *clist = new CondList(); clist->insert("*"); @@ -1838,7 +1837,7 @@ yyreduce: case 26: /* Line 1464 of yacc.c */ -#line 336 "../src/parse/parser.ypp" +#line 334 "../src/parse/parser.ypp" { setup_rule((yyvsp[(2) - (4)].clist), (yyvsp[(4) - (4)].token)); ;} @@ -1847,7 +1846,7 @@ yyreduce: case 27: /* Line 1464 of yacc.c */ -#line 343 "../src/parse/parser.ypp" +#line 341 "../src/parse/parser.ypp" { in->fatal("unnamed condition not supported"); ;} @@ -1856,7 +1855,7 @@ yyreduce: case 28: /* Line 1464 of yacc.c */ -#line 347 "../src/parse/parser.ypp" +#line 345 "../src/parse/parser.ypp" { (yyval.clist) = (yyvsp[(1) - (1)].clist); ;} @@ -1865,19 +1864,21 @@ yyreduce: case 29: /* Line 1464 of yacc.c */ -#line 354 "../src/parse/parser.ypp" +#line 352 "../src/parse/parser.ypp" { (yyval.clist) = new CondList(); - (yyval.clist)->insert((yyvsp[(1) - (1)].symbol)->GetName().to_string()); + (yyval.clist)->insert(* (yyvsp[(1) - (1)].str)); + delete (yyvsp[(1) - (1)].str); ;} break; case 30: /* Line 1464 of yacc.c */ -#line 359 "../src/parse/parser.ypp" +#line 358 "../src/parse/parser.ypp" { - (yyvsp[(1) - (3)].clist)->insert((yyvsp[(3) - (3)].symbol)->GetName().to_string()); + (yyvsp[(1) - (3)].clist)->insert(* (yyvsp[(3) - (3)].str)); + delete (yyvsp[(3) - (3)].str); (yyval.clist) = (yyvsp[(1) - (3)].clist); ;} break; @@ -1896,7 +1897,7 @@ yyreduce: /* Line 1464 of yacc.c */ #line 371 "../src/parse/parser.ypp" { - (yyval.str) = new Str((yyvsp[(3) - (3)].symbol)->GetName().to_string().c_str()); + (yyval.str) = (yyvsp[(3) - (3)].str); ;} break; @@ -2055,18 +2056,20 @@ yyreduce: /* Line 1464 of yacc.c */ #line 471 "../src/parse/parser.ypp" { - if(!(yyvsp[(1) - (1)].symbol)->re) + symbol_table_t::iterator i = symbol_table.find (* (yyvsp[(1) - (1)].str)); + delete (yyvsp[(1) - (1)].str); + if (i == symbol_table.end ()) { in->fatal("can't find symbol"); } - (yyval.regexp) = (yyvsp[(1) - (1)].symbol)->re; + (yyval.regexp) = i->second; ;} break; case 49: /* Line 1464 of yacc.c */ -#line 479 "../src/parse/parser.ypp" +#line 481 "../src/parse/parser.ypp" { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); ;} @@ -2075,7 +2078,7 @@ yyreduce: case 50: /* Line 1464 of yacc.c */ -#line 483 "../src/parse/parser.ypp" +#line 485 "../src/parse/parser.ypp" { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); ;} @@ -2084,7 +2087,7 @@ yyreduce: case 51: /* Line 1464 of yacc.c */ -#line 487 "../src/parse/parser.ypp" +#line 489 "../src/parse/parser.ypp" { (yyval.regexp) = (yyvsp[(2) - (3)].regexp); ;} @@ -2093,7 +2096,7 @@ yyreduce: /* Line 1464 of yacc.c */ -#line 2097 "./parser.cc" +#line 2100 "./parser.cc" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -2305,7 +2308,7 @@ yyreturn: /* Line 1684 of yacc.c */ -#line 492 "../src/parse/parser.ypp" +#line 494 "../src/parse/parser.ypp" extern "C" { @@ -2536,7 +2539,7 @@ void parse_cleanup() { RegExp::vFreeList.clear(); Range::vFreeList.clear(); - Symbol::ClearTable(); + symbol_table.clear (); specMap.clear(); specStar.clear(); specNone = NULL; diff --git a/re2c/bootstrap/scanner_lex.cc b/re2c/bootstrap/scanner_lex.cc index ffb66cb4..6535823e 100644 --- a/re2c/bootstrap/scanner_lex.cc +++ b/re2c/bootstrap/scanner_lex.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.14.1.dev on Wed May 13 17:17:35 2015*/ +/* Generated by re2c 0.14.1.dev on Wed May 13 23:05:53 2015*/ #include #include #include @@ -7,7 +7,6 @@ #include "src/dfa/dfa.h" #include "src/globals.h" #include "src/parse/parser.h" -#include "src/parse/symbol.h" #include "src/parse/scanner.h" #include "y.tab.h" @@ -891,7 +890,7 @@ yy149: fatal("curly braces for names only allowed with -F switch"); } cur = cursor; - yylval.symbol = Symbol::find(token(1, cur - tok - 2)); + yylval.str = new std::string (tok + 1, cur - tok - 2); return ID; } yy151: @@ -944,7 +943,7 @@ yy164: { if (!FFlag) { cur = cursor; - yylval.symbol = Symbol::find(token()); + yylval.str = new std::string (tok, cur - tok); return ID; } else { /* Add one char in front and one behind instead of 's or "s */ @@ -969,7 +968,7 @@ yy167: YYCURSOR = YYCTXMARKER; { cur = ptr > tok ? ptr - 1 : cursor; - yylval.symbol = Symbol::find(token()); + yylval.str = new std::string (tok, cur - tok); return ID; } yy168: @@ -1054,7 +1053,7 @@ yy176: cur = cursor; tok += 5; /* skip "re2c:" */ iscfg = 1; - yylval.str = new Str(token()); + yylval.str = new std::string (tok, cur - tok); return CONFIG; } yy177: @@ -1117,7 +1116,7 @@ yy181: YYCURSOR = YYCTXMARKER; { cur = ptr > tok ? ptr - 1 : cursor; - yylval.symbol = Symbol::find(token()); + yylval.str = new std::string (tok, cur - tok); return FFlag ? FID : ID; } yy183: @@ -2174,7 +2173,7 @@ value: yy350: { cur = cursor; - yylval.str = new Str(token()); + yylval.str = new std::string (tok, cur - tok); iscfg = 0; return VALUE; } diff --git a/re2c/bootstrap/y.tab.h b/re2c/bootstrap/y.tab.h index a62f7e9c..d8749dd0 100644 --- a/re2c/bootstrap/y.tab.h +++ b/re2c/bootstrap/y.tab.h @@ -63,19 +63,18 @@ typedef union YYSTYPE /* Line 1685 of yacc.c */ #line 151 "../src/parse/parser.ypp" - re2c::Symbol *symbol; re2c::RegExp *regexp; re2c::Token *token; char op; int number; re2c::ExtOp extop; - re2c::Str *str; + std::string *str; re2c::CondList *clist; /* Line 1685 of yacc.c */ -#line 79 "./y.tab.h" +#line 78 "./y.tab.h" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ diff --git a/re2c/src/parse/parser.h b/re2c/src/parse/parser.h index fba3fab6..70f32200 100644 --- a/re2c/src/parse/parser.h +++ b/re2c/src/parse/parser.h @@ -17,6 +17,7 @@ typedef std::set CondList; typedef std::list RuleOpList; typedef std::map > SetupMap; typedef std::map DefaultMap; +typedef std::map symbol_table_t; } // namespace re2c diff --git a/re2c/src/parse/parser.ypp b/re2c/src/parse/parser.ypp index 79a494d4..9febf956 100644 --- a/re2c/src/parse/parser.ypp +++ b/re2c/src/parse/parser.ypp @@ -14,7 +14,6 @@ #include "src/codegen/dfa_emit.h" // genTypes #include "src/globals.h" #include "src/parse/parser.h" -#include "src/parse/symbol.h" #include "src/util/c99_stdint.h" #include "src/util/smart_ptr.h" @@ -39,6 +38,7 @@ static SetupMap ruleSetupMap; static Token *ruleDefault = NULL; static DefaultMap ruleDefaultMap; static bool foundRules; +static symbol_table_t symbol_table; /* Bison version 1.875 emits a definition that is not working * with several g++ version. Hence we disable it here. @@ -80,7 +80,7 @@ void context_none(CondList *clist) in->fatal("no expression specified"); } -void context_rule(CondList *clist, RegExp *expr, RegExp *look, Str *newcond, Token *code) +void context_rule(CondList *clist, RegExp *expr, RegExp *look, const std::string * newcond, Token *code) { context_check(clist); const RegExp::InsAccess ins_access = clist->size() > 1 @@ -149,13 +149,12 @@ void default_rule(CondList *clist, Token *code) %start spec %union { - re2c::Symbol *symbol; re2c::RegExp *regexp; re2c::Token *token; char op; int number; re2c::ExtOp extop; - re2c::Str *str; + std::string *str; re2c::CondList *clist; }; @@ -165,11 +164,10 @@ void default_rule(CondList *clist, Token *code) %type CLOSE STAR SETUP %type close %type CLOSESIZE -%type ID FID %type CODE %type RANGE STRING %type rule look expr diff term factor primary -%type CONFIG VALUE newcond +%type CONFIG VALUE newcond ID FID %type cond clist %type NUMBER @@ -189,21 +187,21 @@ spec: decl: ID '=' expr ';' { - if ($1->re) + if (!symbol_table.insert (std::make_pair (* $1, $3)).second) { in->fatal("sym already defined"); } + delete $1; $3->ins_access = RegExp::PRIVATE; - $1->re = $3; } | FID expr { - if ($1->re) + if (!symbol_table.insert (std::make_pair (* $1, $2)).second) { in->fatal("sym already defined"); } + delete $1; $2->ins_access = RegExp::PRIVATE; - $1->re = $2; } | ID '=' expr '/' { @@ -215,13 +213,13 @@ decl: } | CONFIG '=' VALUE ';' { - in->config($1->to_string (), *$3); + in->config (* $1, * $3); delete $1; delete $3; } | CONFIG '=' NUMBER ';' { - in->config($1->to_string (), $3); + in->config (* $1, $3); delete $1; } ; @@ -353,11 +351,13 @@ clist: ID { $$ = new CondList(); - $$->insert($1->GetName().to_string()); + $$->insert(* $1); + delete $1; } | clist ',' ID { - $1->insert($3->GetName().to_string()); + $1->insert(* $3); + delete $3; $$ = $1; } ; @@ -369,7 +369,7 @@ newcond: } | '=' '>' ID { - $$ = new Str($3->GetName().to_string().c_str()); + $$ = $3; } ; @@ -469,11 +469,13 @@ close: primary: ID { - if(!$1->re) + symbol_table_t::iterator i = symbol_table.find (* $1); + delete $1; + if (i == symbol_table.end ()) { in->fatal("can't find symbol"); } - $$ = $1->re; + $$ = i->second; } | RANGE { @@ -719,7 +721,7 @@ void parse_cleanup() { RegExp::vFreeList.clear(); Range::vFreeList.clear(); - Symbol::ClearTable(); + symbol_table.clear (); specMap.clear(); specStar.clear(); specNone = NULL; diff --git a/re2c/src/parse/scanner.cc b/re2c/src/parse/scanner.cc index e119b33e..6393bce7 100644 --- a/re2c/src/parse/scanner.cc +++ b/re2c/src/parse/scanner.cc @@ -140,7 +140,7 @@ static std::set mapVariableKeys; static std::set mapDefineKeys; static std::set mapLabelKeys; -void Scanner::config(const std::string & cfg, const Str & val) +void Scanner::config(const std::string & cfg, const std::string & val) { if (mapDefineKeys.empty()) { @@ -175,15 +175,16 @@ void Scanner::config(const std::string & cfg, const Str & val) std::string strVal; - if (val.len >= 2 && val.str[0] == val.str[val.len-1] - && (val.str[0] == '"' || val.str[0] == '\'')) + const uint32_t val_len = val.size (); + if (val_len >= 2 && val[0] == val[val_len - 1] + && (val[0] == '"' || val[0] == '\'')) { - SubStr tmp(val.str + 1, val.len - 2); - unescape(tmp, strVal); + SubStr tmp (val.c_str () + 1, val_len - 2); + unescape (tmp, strVal); } else { - strVal = val.to_string(); + strVal = val; } if (cfg == "indent:string") diff --git a/re2c/src/parse/scanner.h b/re2c/src/parse/scanner.h index 76e078f7..d911a0ed 100644 --- a/re2c/src/parse/scanner.h +++ b/re2c/src/parse/scanner.h @@ -80,7 +80,7 @@ public: void fatal(uint32_t, const char*) const; void config(const std::string &, int); - void config(const std::string &, const Str &); + void config(const std::string &, const std::string &); void check_token_length(char *pos, uint32_t len) const; SubStr token() const; diff --git a/re2c/src/parse/scanner_lex.re b/re2c/src/parse/scanner_lex.re index 9017ee69..cfdbc3cb 100644 --- a/re2c/src/parse/scanner_lex.re +++ b/re2c/src/parse/scanner_lex.re @@ -6,7 +6,6 @@ #include "src/dfa/dfa.h" #include "src/globals.h" #include "src/parse/parser.h" -#include "src/parse/symbol.h" #include "src/parse/scanner.h" #include "y.tab.h" @@ -353,7 +352,7 @@ scan: fatal("curly braces for names only allowed with -F switch"); } cur = cursor; - yylval.symbol = Symbol::find(token(1, cur - tok - 2)); + yylval.str = new std::string (tok + 1, cur - tok - 2); return ID; } @@ -361,26 +360,26 @@ scan: cur = cursor; tok += 5; /* skip "re2c:" */ iscfg = 1; - yylval.str = new Str(token()); + yylval.str = new std::string (tok, cur - tok); return CONFIG; } name / (space+ [^=>,]) { cur = ptr > tok ? ptr - 1 : cursor; - yylval.symbol = Symbol::find(token()); + yylval.str = new std::string (tok, cur - tok); return FFlag ? FID : ID; } name / (space* [=>,]) { cur = ptr > tok ? ptr - 1 : cursor; - yylval.symbol = Symbol::find(token()); + yylval.str = new std::string (tok, cur - tok); return ID; } name / [^] { if (!FFlag) { cur = cursor; - yylval.symbol = Symbol::find(token()); + yylval.str = new std::string (tok, cur - tok); return ID; } else { /* Add one char in front and one behind instead of 's or "s */ @@ -587,7 +586,7 @@ value: } value { cur = cursor; - yylval.str = new Str(token()); + yylval.str = new std::string (tok, cur - tok); iscfg = 0; return VALUE; } diff --git a/re2c/src/parse/symbol.cc b/re2c/src/parse/symbol.cc deleted file mode 100644 index d3f2cbc0..00000000 --- a/re2c/src/parse/symbol.cc +++ /dev/null @@ -1,29 +0,0 @@ -#include "src/parse/symbol.h" - -namespace re2c -{ - -Symbol::SymbolTable Symbol::symbol_table; - -void Symbol::ClearTable () -{ - for (SymbolTable::iterator it = symbol_table.begin(); it != symbol_table.end(); ++it) - { - delete it->second; - } - symbol_table.clear (); -} - -Symbol * Symbol::find (const SubStr & str) -{ - const std::string ss (str.to_string ()); - SymbolTable::const_iterator it = symbol_table.find (ss); - if (it == symbol_table.end ()) - { - return (* symbol_table.insert (SymbolTable::value_type (ss, new Symbol (str))).first).second; - } - return (* it).second; -} - -} // namespace re2c - diff --git a/re2c/src/parse/symbol.h b/re2c/src/parse/symbol.h deleted file mode 100644 index 1a9af6ca..00000000 --- a/re2c/src/parse/symbol.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef __SYMBOL__ -#define __SYMBOL__ - -#include -#include - -#include "src/util/forbid_copy.h" -#include "src/util/substr.h" - -namespace re2c -{ - -class RegExp; - -class Symbol -{ - typedef std::map SymbolTable; - - static SymbolTable symbol_table; - Str name; - - Symbol(const SubStr & str) - : name (str) - , re (NULL) - {} - -public: - RegExp * re; - - static Symbol * find (const SubStr &); - static void ClearTable (); - const Str & GetName () const - { - return name; - } - - FORBID_COPY (Symbol); -}; - -} // namespace re2c - -#endif // __SYMBOL__ diff --git a/re2c/src/parse/token.h b/re2c/src/parse/token.h index f58f936e..5a15e474 100644 --- a/re2c/src/parse/token.h +++ b/re2c/src/parse/token.h @@ -18,7 +18,7 @@ public: public: Token(const SubStr&, const std::string&, uint32_t); - Token(const Token*, const std::string&, uint32_t, const Str*); + Token(const Token*, const std::string&, uint32_t, const std::string *); Token (const Token & t); ~Token(); @@ -36,9 +36,9 @@ inline Token::Token(const SubStr& t, const std::string& s, uint32_t l) ; } -inline Token::Token(const Token* t, const std::string& s, uint32_t l, const Str *c) +inline Token::Token(const Token* t, const std::string& s, uint32_t l, const std::string * c) : text(t ? t->text.to_string().c_str() : "") - , newcond(c ? c->to_string() : "") + , newcond(c ? * c : "") , source(t ? t->source : s) , line(t ? t->line : l) , autogen(t == NULL) -- 2.40.0