From: Ulya Trofimovich Date: Wed, 23 Sep 2015 14:45:54 +0000 (+0100) Subject: Separated user config and effective config. X-Git-Tag: 0.15~47 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=70e15e0455a4f70ebdb2be6a028746cf9b9ca998;p=re2c Separated user config and effective config. --- diff --git a/re2c/bootstrap/src/conf/parse_opts.cc b/re2c/bootstrap/src/conf/parse_opts.cc index f5f5567a..b9daf36d 100644 --- a/re2c/bootstrap/src/conf/parse_opts.cc +++ b/re2c/bootstrap/src/conf/parse_opts.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.14.3 on Tue Sep 22 12:44:15 2015 */ +/* Generated by re2c 0.14.3 on Wed Sep 23 14:13:43 2015 */ #line 1 "../src/conf/parse_opts.re" #include @@ -1840,10 +1840,11 @@ yy621: end: - if (!opts.apply ()) + if (!opts.check ()) { return EXIT_FAIL; } + opts.sync (); if (!opts.source_file) { diff --git a/re2c/bootstrap/src/parse/parser.cc b/re2c/bootstrap/src/parse/parser.cc index 68dc33dc..d91340e4 100644 --- a/re2c/bootstrap/src/parse/parser.cc +++ b/re2c/bootstrap/src/parse/parser.cc @@ -123,7 +123,7 @@ static symbol_table_t symbol_table; void context_check(CondList *clist) { - if (!opts.cFlag) + if (!opts.cFlag ()) { delete clist; in->fatal("conditions are only allowed when using -c switch"); @@ -662,13 +662,13 @@ static const yytype_int8 yyrhs[] = static const yytype_uint16 yyrline[] = { 0, 242, 242, 244, 248, 252, 261, 270, 274, 278, - 287, 292, 297, 302, 307, 312, 317, 325, 329, 335, - 339, 343, 349, 353, 359, 372, 377, 385, 390, 394, - 399, 403, 407, 411, 417, 421, 425, 429, 436, 453, - 462, 466, 472, 477, 483, 487, 502, 519, 524, 530, - 536, 554, 574, 580, 588, 591, 598, 604, 614, 617, - 625, 628, 635, 639, 646, 650, 657, 661, 668, 672, - 687, 707, 711, 715, 719, 726, 736, 740 + 287, 292, 297, 302, 307, 312, 317, 325, 329, 334, + 338, 342, 347, 351, 356, 369, 374, 382, 387, 391, + 396, 400, 404, 408, 412, 416, 420, 424, 431, 448, + 457, 461, 467, 472, 478, 482, 497, 514, 519, 525, + 531, 549, 569, 575, 583, 586, 593, 599, 609, 612, + 620, 623, 630, 634, 641, 645, 652, 656, 663, 667, + 682, 702, 706, 710, 714, 721, 731, 735 }; #endif @@ -1759,7 +1759,7 @@ yyreduce: case 9: { - if (!opts.mapCodeName.insert (std::make_pair (*(yyvsp[(1) - (3)].str), *(yyvsp[(2) - (3)].str))).second) + if (!opts.sync_mapCodeName (*(yyvsp[(1) - (3)].str), *(yyvsp[(2) - (3)].str))) { in->fatalf ("configuration '%s' is already set and cannot be changed", (yyvsp[(1) - (3)].str)->c_str ()); } @@ -1771,7 +1771,7 @@ yyreduce: case 10: { - opts.condPrefix = *(yyvsp[(2) - (3)].str); + opts.sync_condPrefix (*(yyvsp[(2) - (3)].str)); delete (yyvsp[(2) - (3)].str); ;} break; @@ -1779,7 +1779,7 @@ yyreduce: case 11: { - opts.condEnumPrefix = *(yyvsp[(2) - (3)].str); + opts.sync_condEnumPrefix (*(yyvsp[(2) - (3)].str)); delete (yyvsp[(2) - (3)].str); ;} break; @@ -1787,7 +1787,7 @@ yyreduce: case 12: { - opts.condDivider = *(yyvsp[(2) - (3)].str); + opts.sync_condDivider (*(yyvsp[(2) - (3)].str)); delete (yyvsp[(2) - (3)].str); ;} break; @@ -1795,7 +1795,7 @@ yyreduce: case 13: { - opts.condDividerParam = *(yyvsp[(2) - (3)].str); + opts.sync_condDividerParam (*(yyvsp[(2) - (3)].str)); delete (yyvsp[(2) - (3)].str); ;} break; @@ -1803,7 +1803,7 @@ yyreduce: case 14: { - opts.condGoto = *(yyvsp[(2) - (3)].str); + opts.sync_condGoto (*(yyvsp[(2) - (3)].str)); delete (yyvsp[(2) - (3)].str); ;} break; @@ -1811,7 +1811,7 @@ yyreduce: case 15: { - opts.condGotoParam = *(yyvsp[(2) - (3)].str); + opts.sync_condGotoParam (*(yyvsp[(2) - (3)].str)); delete (yyvsp[(2) - (3)].str); ;} break; @@ -1823,22 +1823,21 @@ yyreduce: { in->fatal ("configuration 'cgoto:threshold' must be nonnegative"); } - opts.cGotoThreshold = static_cast ((yyvsp[(2) - (3)].num)); + opts.sync_cGotoThreshold (static_cast ((yyvsp[(2) - (3)].num))); ;} break; case 17: { - opts.bUseYYFillNaked = (yyvsp[(2) - (3)].num) != 0; + opts.sync_bUseYYFillNaked ((yyvsp[(2) - (3)].num) != 0); ;} break; case 18: { - opts.yyFillLength = *(yyvsp[(2) - (3)].str); - opts.bUseYYFillParam = false; + opts.sync_yyFillLength (*(yyvsp[(2) - (3)].str)); delete (yyvsp[(2) - (3)].str); ;} break; @@ -1846,22 +1845,21 @@ yyreduce: case 19: { - opts.bUseYYGetConditionNaked = (yyvsp[(2) - (3)].num) != 0; + opts.sync_bUseYYGetConditionNaked ((yyvsp[(2) - (3)].num) != 0); ;} break; case 20: { - opts.bUseYYGetStateNaked = (yyvsp[(2) - (3)].num) != 0; + opts.sync_bUseYYGetStateNaked ((yyvsp[(2) - (3)].num) != 0); ;} break; case 21: { - opts.yySetConditionParam = *(yyvsp[(2) - (3)].str); - opts.bUseYYSetConditionParam = false; + opts.sync_yySetConditionParam (*(yyvsp[(2) - (3)].str)); delete (yyvsp[(2) - (3)].str); ;} break; @@ -1869,15 +1867,14 @@ yyreduce: case 22: { - opts.bUseYYSetStateNaked = (yyvsp[(2) - (3)].num) != 0; + opts.sync_bUseYYSetStateNaked ((yyvsp[(2) - (3)].num) != 0); ;} break; case 23: { - opts.yySetStateParam = *(yyvsp[(2) - (3)].str); - opts.bUseYYSetStateParam = false; + opts.sync_yySetStateParam (*(yyvsp[(2) - (3)].str)); delete (yyvsp[(2) - (3)].str); ;} break; @@ -1887,13 +1884,13 @@ yyreduce: { if ((yyvsp[(2) - (3)].num) == 0) { - opts.encoding.unset ((yyvsp[(1) - (3)].enc)); + opts.sync_encoding_unset ((yyvsp[(1) - (3)].enc)); } - else if (!opts.encoding.set ((yyvsp[(1) - (3)].enc))) + else if (!opts.sync_encoding ((yyvsp[(1) - (3)].enc))) { in->fatalf ("Cannot set %s encoding: please reset %s encoding first" , Enc::name ((yyvsp[(1) - (3)].enc)) - , Enc::name (opts.encoding.type ())); + , Enc::name (opts.encoding ().type ())); } ;} break; @@ -1901,7 +1898,7 @@ yyreduce: case 25: { - opts.indString = *(yyvsp[(2) - (3)].str); + opts.sync_indString (*(yyvsp[(2) - (3)].str)); delete (yyvsp[(2) - (3)].str); ;} break; @@ -1913,14 +1910,14 @@ yyreduce: { in->fatal ("configuration 'indent:top' must be nonnegative"); } - opts.topIndent = static_cast ((yyvsp[(2) - (3)].num)); + opts.sync_topIndent (static_cast ((yyvsp[(2) - (3)].num))); ;} break; case 27: { - opts.labelPrefix = *(yyvsp[(2) - (3)].str); + opts.sync_labelPrefix (*(yyvsp[(2) - (3)].str)); delete (yyvsp[(2) - (3)].str); ;} break; @@ -1943,65 +1940,63 @@ yyreduce: case 30: { - opts.bUseStateAbort = (yyvsp[(2) - (3)].num) != 0; + opts.sync_bUseStateAbort ((yyvsp[(2) - (3)].num) != 0); ;} break; case 31: { - opts.bUseStateNext = (yyvsp[(2) - (3)].num) != 0; + opts.sync_bUseStateNext ((yyvsp[(2) - (3)].num) != 0); ;} break; case 32: { - opts.yybmHexTable = (yyvsp[(2) - (3)].num) != 0; + opts.sync_yybmHexTable ((yyvsp[(2) - (3)].num) != 0); ;} break; case 33: { - opts.yychConversion = (yyvsp[(2) - (3)].num) == 0 - ? "" - : "(" + opts.mapCodeName["YYCTYPE"] + ")"; + opts.sync_yychConversion ((yyvsp[(2) - (3)].num) != 0); ;} break; case 34: { - opts.bEmitYYCh = (yyvsp[(2) - (3)].num) != 0; + opts.sync_bEmitYYCh ((yyvsp[(2) - (3)].num) != 0); ;} break; case 35: { - opts.bUseYYFillCheck = (yyvsp[(2) - (3)].num) != 0; + opts.sync_bUseYYFillCheck ((yyvsp[(2) - (3)].num) != 0); ;} break; case 36: { - opts.bUseYYFill = (yyvsp[(2) - (3)].num) != 0; + opts.sync_bUseYYFill ((yyvsp[(2) - (3)].num) != 0); ;} break; case 37: { - opts.bUseYYFillParam = (yyvsp[(2) - (3)].num) != 0; + opts.sync_bUseYYFillParam ((yyvsp[(2) - (3)].num) != 0); ;} break; case 38: { - if (opts.cFlag) + if (opts.cFlag ()) { in->fatal("condition or '<*>' required when using -c switch"); } @@ -2021,7 +2016,7 @@ yyreduce: case 39: { - if (opts.cFlag) + if (opts.cFlag ()) in->fatal("condition or '<*>' required when using -c switch"); if (ruleDefault != NULL) in->fatal("code to default rule is already defined"); @@ -2633,12 +2628,12 @@ void parse(Scanner& i, Output & o) o.source.write_version_time (); o.source.write_line_info (in->get_cline (), in->get_fname ().c_str ()); - if (opts.flag_skeleton) + if (opts.flag_skeleton ()) { Skeleton::emit_prolog (o.source); } - Enc encodingOld = opts.encoding; + Enc encodingOld = opts.encoding (); while ((parseMode = i.echo()) != Scanner::Stop) { @@ -2649,7 +2644,7 @@ void parse(Scanner& i, Output & o) i.save_state(curr_state); foundRules = false; - if (opts.rFlag && parseMode == Scanner::Rules && dfa_map.size()) + if (opts.rFlag () && parseMode == Scanner::Rules && dfa_map.size()) { in->fatal("cannot have a second 'rules:re2c' block"); } @@ -2674,9 +2669,9 @@ void parse(Scanner& i, Output & o) in->set_in_parse(true); yyparse(); in->set_in_parse(false); - if (opts.rFlag && parseMode == Scanner::Reuse) + if (opts.rFlag () && parseMode == Scanner::Reuse) { - if (foundRules || opts.encoding != encodingOld) + if (foundRules || opts.encoding () != encodingOld) { // Re-parse rules parseMode = Scanner::Parse; @@ -2698,10 +2693,11 @@ void parse(Scanner& i, Output & o) yyparse(); in->set_in_parse(false); } - encodingOld = opts.encoding; + encodingOld = opts.encoding (); } o.source.set_block_line (in->get_cline ()); - if (opts.cFlag) + uint32_t ind = opts.topIndent (); + if (opts.cFlag ()) { RegExpMap::iterator it; SetupMap::const_iterator itRuleSetup; @@ -2783,11 +2779,11 @@ void parse(Scanner& i, Output & o) it->second = it->second ? mkAlt (def_rule, it->second) : def_rule; } - dfa_map[it->first] = genCode(it->second, o, it->first, opts.encoding.nCodeUnits ()); + dfa_map[it->first] = genCode(it->second, o, it->first, opts.encoding ().nCodeUnits ()); } if (parseMode != Scanner::Rules && dfa_map.find(it->first) != dfa_map.end()) { - dfa_map[it->first]->emit(o, opts.topIndent, !--nCount, bPrologBrace); + dfa_map[it->first]->emit(o, ind, !--nCount, bPrologBrace); } } } @@ -2810,20 +2806,20 @@ void parse(Scanner& i, Output & o) { if (parseMode != Scanner::Reuse) { - dfa_map[""] = genCode(spec, o, "", opts.encoding.nCodeUnits ()); + dfa_map[""] = genCode(spec, o, "", opts.encoding ().nCodeUnits ()); } if (parseMode != Scanner::Rules && dfa_map.find("") != dfa_map.end()) { - dfa_map[""]->emit(o, opts.topIndent, 0, bPrologBrace); + dfa_map[""]->emit(o, ind, 0, bPrologBrace); } } } o.source.write_line_info (in->get_cline (), in->get_fname ().c_str ()); /* restore original char handling mode*/ - opts.encoding = encodingOld; + opts.sync_reset_encoding (encodingOld); } - if (opts.cFlag) + if (opts.cFlag ()) { SetupMap::const_iterator itRuleSetup; for (itRuleSetup = ruleSetupMap.begin(); itRuleSetup != ruleSetupMap.end(); ++itRuleSetup) @@ -2845,7 +2841,7 @@ void parse(Scanner& i, Output & o) } } - if (opts.flag_skeleton) + if (opts.flag_skeleton ()) { Skeleton::emit_epilog (o.source, o.names); } diff --git a/re2c/bootstrap/src/parse/scanner_lex.cc b/re2c/bootstrap/src/parse/scanner_lex.cc index 9c7f09bd..06eb5b1e 100644 --- a/re2c/bootstrap/src/parse/scanner_lex.cc +++ b/re2c/bootstrap/src/parse/scanner_lex.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.14.3 on Mon Sep 21 22:04:43 2015 */ +/* Generated by re2c 0.14.3 on Wed Sep 23 13:14:09 2015 */ #line 1 "../src/parse/scanner_lex.re" #include #include @@ -109,7 +109,7 @@ echo: ++YYCURSOR; #line 199 "../src/parse/scanner_lex.re" { - if (!(ignore_eoc || opts.DFlag || opts.flag_skeleton)) + if (!(ignore_eoc || opts.DFlag () || opts.flag_skeleton ())) { out.write(tok, tok_len () - 1); // -1 so we don't write out the \0 @@ -142,7 +142,7 @@ yy7: { ignore_cnt++; } - else if (!(opts.DFlag || opts.flag_skeleton)) + else if (!(opts.DFlag () || opts.flag_skeleton ())) { out.write(tok, tok_len ()); } @@ -236,9 +236,9 @@ yy21: ++YYCURSOR; #line 87 "../src/parse/scanner_lex.re" { - if (opts.rFlag) + if (opts.rFlag ()) { - opts.mapCodeName.clear(); + opts.sync_reset_mapCodeName (); } else { @@ -255,11 +255,11 @@ yy32: ++YYCURSOR; #line 72 "../src/parse/scanner_lex.re" { - if (opts.rFlag) + if (opts.rFlag ()) { fatal("found standard 're2c' block while using -r flag"); } - if (!(opts.DFlag || opts.flag_skeleton)) + if (!(opts.DFlag () || opts.flag_skeleton ())) { const size_t lexeme_len = cur[-1] == '{' ? sizeof ("%{") - 1 @@ -286,12 +286,12 @@ yy34: ++YYCURSOR; #line 99 "../src/parse/scanner_lex.re" { - if (!opts.rFlag) + if (!opts.rFlag ()) { fatal("found 'use:re2c' block without -r flag"); } reuse(); - if (!(opts.DFlag || opts.flag_skeleton)) + if (!(opts.DFlag () || opts.flag_skeleton ())) { const size_t lexeme_len = sizeof ("/*!use:re2c") - 1; out.write(tok, tok_len () - lexeme_len); @@ -316,7 +316,7 @@ yy42: ++YYCURSOR; #line 113 "../src/parse/scanner_lex.re" { - if (!opts.DFlag) + if (!opts.DFlag ()) { out.insert_yymaxfill (); } @@ -352,7 +352,7 @@ yy50: #line 122 "../src/parse/scanner_lex.re" { tok = pos = cur; - out.insert_state_goto (opts.topIndent); + out.insert_state_goto (opts.topIndent ()); ignore_eoc = true; goto echo; } @@ -406,7 +406,7 @@ yy74: { tok = pos = cur; ignore_eoc = true; - if (!opts.DFlag) + if (!opts.DFlag ()) { out.insert_line_info (); out << "\n"; @@ -435,7 +435,7 @@ yy85: ignore_eoc = false; ignore_cnt = 0; } - else if (!(opts.DFlag || opts.flag_skeleton)) + else if (!(opts.DFlag () || opts.flag_skeleton ())) { out.write(tok, tok_len ()); } @@ -460,7 +460,7 @@ yy87: ignore_eoc = false; ignore_cnt = 0; } - else if (!(opts.DFlag || opts.flag_skeleton)) + else if (!(opts.DFlag () || opts.flag_skeleton ())) { out.write(tok, tok_len ()); } @@ -752,7 +752,7 @@ yy119: { std::vector cpoints; lex_cpoints ('"', cpoints); - yylval.regexp = cpoint_string (cpoints, opts.bCaseInsensitive || opts.bCaseInverted); + yylval.regexp = cpoint_string (cpoints, opts.bCaseInsensitive () || opts.bCaseInverted ()); return REGEXP; } #line 759 "src/parse/scanner_lex.cc" @@ -766,7 +766,7 @@ yy122: { std::vector cpoints; lex_cpoints ('\'', cpoints); - yylval.regexp = cpoint_string (cpoints, opts.bCaseInsensitive || !opts.bCaseInverted); + yylval.regexp = cpoint_string (cpoints, opts.bCaseInsensitive () || !opts.bCaseInverted ()); return REGEXP; } #line 773 "src/parse/scanner_lex.cc" @@ -920,7 +920,7 @@ yy148: ++YYCURSOR; #line 345 "../src/parse/scanner_lex.re" { - if (!opts.FFlag) { + if (!opts.FFlag ()) { fatal("curly braces for names only allowed with -F switch"); } yylval.str = new std::string (tok + 1, tok_len () - 2); // -2 to omit braces @@ -983,7 +983,7 @@ yy159: YYCURSOR = YYCTXMARKER; #line 373 "../src/parse/scanner_lex.re" { - if (!opts.FFlag) { + if (!opts.FFlag ()) { yylval.str = new std::string (tok, tok_len ()); return ID; } else { @@ -992,7 +992,7 @@ yy159: { cpoints.push_back (static_cast (*p)); } - yylval.regexp = cpoint_string (cpoints, opts.bCaseInsensitive || opts.bCaseInverted); + yylval.regexp = cpoint_string (cpoints, opts.bCaseInsensitive () || opts.bCaseInverted ()); return REGEXP; } } @@ -1063,7 +1063,7 @@ yy171: #line 355 "../src/parse/scanner_lex.re" { yylval.str = new std::string (tok, tok_len ()); - if (opts.FFlag) + if (opts.FFlag ()) { lexer_state = LEX_FLEX_NAME; return FID; diff --git a/re2c/src/codegen/bitmap.cc b/re2c/src/codegen/bitmap.cc index 4d5ccda6..71ce9f34 100644 --- a/re2c/src/codegen/bitmap.cc +++ b/re2c/src/codegen/bitmap.cc @@ -74,7 +74,7 @@ void BitMap::gen(OutputFile & o, uint32_t ind, uint32_t lb, uint32_t ub) { if (first && bUsedYYBitmap) { - o << indent(ind) << "static const unsigned char " << opts.mapCodeName["yybm"] << "[] = {"; + o << indent(ind) << "static const unsigned char " << opts.mapCodeName ()["yybm"] << "[] = {"; uint32_t c = 1, n = ub - lb; const BitMap *cb = first; @@ -110,7 +110,7 @@ void BitMap::gen(OutputFile & o, uint32_t ind, uint32_t lb, uint32_t ub) o << "\n" << indent(ind+1); } - if (opts.yybmHexTable) + if (opts.yybmHexTable ()) { o.write_hex (bm[j]); } diff --git a/re2c/src/codegen/code_names.cc b/re2c/src/codegen/code_names.cc index 2be7f281..1a02a79c 100644 --- a/re2c/src/codegen/code_names.cc +++ b/re2c/src/codegen/code_names.cc @@ -3,18 +3,12 @@ namespace re2c { -std::string& CodeNames::operator [] (const char * what) +std::string CodeNames::operator [] (const char * what) const { - CodeNames::iterator it = find(std::string(what)); - - if (it == end()) - { - return insert(std::make_pair(std::string(what), std::string(what))).first->second; - } - else - { - return it->second; - } + CodeNames::const_iterator it = find (what); + return it == end () + ? what + : it->second; } } // end namespace re2c diff --git a/re2c/src/codegen/code_names.h b/re2c/src/codegen/code_names.h index 75979a66..928ee7f0 100644 --- a/re2c/src/codegen/code_names.h +++ b/re2c/src/codegen/code_names.h @@ -10,7 +10,7 @@ namespace re2c class CodeNames: public std::map { public: - std::string& operator [] (const char * what); + std::string operator [] (const char * what) const; }; } // end namespace re2c diff --git a/re2c/src/codegen/emit_action.cc b/re2c/src/codegen/emit_action.cc index 1ee5fd21..029483a2 100644 --- a/re2c/src/codegen/emit_action.cc +++ b/re2c/src/codegen/emit_action.cc @@ -54,7 +54,7 @@ void emit_action void emit_match (OutputFile & o, uint32_t ind, bool & readCh, const State * const s) { - if (opts.DFlag) + if (opts.DFlag ()) { return; } @@ -64,17 +64,17 @@ void emit_match (OutputFile & o, uint32_t ind, bool & readCh, const State * cons && s->next->action.type != Action::RULE; if (s->link) { - o << opts.input_api.stmt_skip (ind); + o << opts.input_api ().stmt_skip (ind); } else if (!read_ahead) { /* do not read next char if match */ - o << opts.input_api.stmt_skip (ind); + o << opts.input_api ().stmt_skip (ind); readCh = true; } else { - o << opts.input_api.stmt_skip_peek (ind); + o << opts.input_api ().stmt_skip_peek (ind); readCh = false; } @@ -86,7 +86,7 @@ void emit_match (OutputFile & o, uint32_t ind, bool & readCh, const State * cons void emit_initial (OutputFile & o, uint32_t ind, bool & readCh, const State * const s, const Initial & initial, const std::set & used_labels) { - if (opts.DFlag) + if (opts.DFlag ()) { return; } @@ -95,22 +95,22 @@ void emit_initial (OutputFile & o, uint32_t ind, bool & readCh, const State * co { if (s->link) { - o << opts.input_api.stmt_skip (ind); + o << opts.input_api ().stmt_skip (ind); } else { - o << opts.input_api.stmt_skip_peek (ind); + o << opts.input_api ().stmt_skip_peek (ind); } } if (used_labels.count(initial.label)) { - o << opts.labelPrefix << initial.label << ":\n"; + o << opts.labelPrefix () << initial.label << ":\n"; } - if (opts.dFlag) + if (opts.dFlag ()) { - o << indent(ind) << opts.mapCodeName["YYDEBUG"] << "(" << initial.label << ", *" << opts.mapCodeName["YYCURSOR"] << ");" << "\n"; + o << indent(ind) << opts.mapCodeName ()["YYDEBUG"] << "(" << initial.label << ", *" << opts.mapCodeName ()["YYCURSOR"] << ");" << "\n"; } if (s->link) @@ -121,7 +121,7 @@ void emit_initial (OutputFile & o, uint32_t ind, bool & readCh, const State * co { if (initial.setMarker) { - o << opts.input_api.stmt_backup (ind); + o << opts.input_api ().stmt_backup (ind); } readCh = false; } @@ -129,24 +129,24 @@ void emit_initial (OutputFile & o, uint32_t ind, bool & readCh, const State * co void emit_save (OutputFile & o, uint32_t ind, bool & readCh, const State * const s, uint32_t save, bool save_yyaccept) { - if (opts.DFlag) + if (opts.DFlag ()) { return; } if (save_yyaccept) { - o << indent (ind) << opts.mapCodeName["yyaccept"] << " = " << save << ";\n"; + o << indent (ind) << opts.mapCodeName ()["yyaccept"] << " = " << save << ";\n"; } if (s->link) { - o << opts.input_api.stmt_skip_backup (ind); + o << opts.input_api ().stmt_skip_backup (ind); need(o, ind, readCh, s->depth, false); } else { - o << opts.input_api.stmt_skip_backup_peek (ind); + o << opts.input_api ().stmt_skip_backup_peek (ind); readCh = false; } } @@ -156,7 +156,7 @@ void emit_accept_binary (OutputFile & o, uint32_t ind, bool & readCh, const Stat if (l < r) { const uint32_t m = (l + r) >> 1; - o << indent(ind) << "if (" << opts.mapCodeName["yyaccept"] << (r == l+1 ? " == " : " <= ") << m << ") {\n"; + o << indent(ind) << "if (" << opts.mapCodeName ()["yyaccept"] << (r == l+1 ? " == " : " <= ") << m << ") {\n"; emit_accept_binary (o, ++ind, readCh, s, accepts, l, m); o << indent(--ind) << "} else {\n"; emit_accept_binary (o, ++ind, readCh, s, accepts, m + 1, r); @@ -173,36 +173,36 @@ void emit_accept (OutputFile & o, uint32_t ind, bool & readCh, const State * con const uint32_t accepts_size = static_cast (accepts.size ()); if (accepts_size > 0) { - if (!opts.DFlag) + if (!opts.DFlag ()) { - o << opts.input_api.stmt_restore (ind); + o << opts.input_api ().stmt_restore (ind); } if (readCh) // shouldn't be necessary, but might become at some point { - o << opts.input_api.stmt_peek (ind); + o << opts.input_api ().stmt_peek (ind); readCh = false; } if (accepts_size > 1) { - if (opts.gFlag && accepts_size >= opts.cGotoThreshold) + if (opts.gFlag () && accepts_size >= opts.cGotoThreshold ()) { o << indent(ind++) << "{\n"; - o << indent(ind++) << "static void *" << opts.mapCodeName["yytarget"] << "[" << accepts_size << "] = {\n"; + o << indent(ind++) << "static void *" << opts.mapCodeName ()["yytarget"] << "[" << accepts_size << "] = {\n"; for (uint32_t i = 0; i < accepts_size; ++i) { - o << indent(ind) << "&&" << opts.labelPrefix << accepts[i]->label << ",\n"; + o << indent(ind) << "&&" << opts.labelPrefix () << accepts[i]->label << ",\n"; } o << indent(--ind) << "};\n"; - o << indent(ind) << "goto *" << opts.mapCodeName["yytarget"] << "[" << opts.mapCodeName["yyaccept"] << "];\n"; + o << indent(ind) << "goto *" << opts.mapCodeName ()["yytarget"] << "[" << opts.mapCodeName ()["yyaccept"] << "];\n"; o << indent(--ind) << "}\n"; } - else if (opts.sFlag || (accepts_size == 2 && !opts.DFlag)) + else if (opts.sFlag () || (accepts_size == 2 && !opts.DFlag ())) { emit_accept_binary (o, ind, readCh, s, accepts, 0, accepts_size - 1); } - else if (opts.DFlag) + else if (opts.DFlag ()) { for (uint32_t i = 0; i < accepts_size; ++i) { @@ -212,7 +212,7 @@ void emit_accept (OutputFile & o, uint32_t ind, bool & readCh, const State * con } else { - o << indent(ind) << "switch (" << opts.mapCodeName["yyaccept"] << ") {\n"; + o << indent(ind) << "switch (" << opts.mapCodeName ()["yyaccept"] << ") {\n"; for (uint32_t i = 0; i < accepts_size - 1; ++i) { o << indent(ind) << "case " << i << ": \t"; @@ -233,7 +233,7 @@ void emit_accept (OutputFile & o, uint32_t ind, bool & readCh, const State * con void emit_rule (OutputFile & o, uint32_t ind, const State * const s, const RuleOp * const rule, const std::string & condName, const std::string & name) { - if (opts.DFlag) + if (opts.DFlag ()) { o << s->label; if (rule->code) @@ -245,12 +245,12 @@ void emit_rule (OutputFile & o, uint32_t ind, const State * const s, const RuleO } uint32_t back = rule->ctx->fixedLength(); - if (back != 0u && !opts.DFlag) + if (back != 0u && !opts.DFlag ()) { - o << opts.input_api.stmt_restorectx (ind); + o << opts.input_api ().stmt_restorectx (ind); } - if (opts.flag_skeleton) + if (opts.flag_skeleton ()) { Skeleton::emit_action (o, ind, rule->rank, name); } @@ -273,68 +273,68 @@ void emit_rule (OutputFile & o, uint32_t ind, const State * const s, const RuleO } else if (!rule->newcond.empty ()) { - o << indent (ind) << replaceParam(opts.condGoto, opts.condGotoParam, opts.condPrefix + rule->newcond) << "\n"; + o << indent (ind) << replaceParam(opts.condGoto (), opts.condGotoParam (), opts.condPrefix () + rule->newcond) << "\n"; } } } void need (OutputFile & o, uint32_t ind, bool & readCh, uint32_t n, bool bSetMarker) { - if (opts.DFlag) + if (opts.DFlag ()) { return; } uint32_t fillIndex = last_fill_index; - if (opts.fFlag) + if (opts.fFlag ()) { last_fill_index++; - if (opts.bUseYYSetStateParam) + if (opts.bUseYYSetStateParam ()) { - o << indent(ind) << opts.mapCodeName["YYSETSTATE"] << "(" << fillIndex << ");\n"; + o << indent(ind) << opts.mapCodeName ()["YYSETSTATE"] << "(" << fillIndex << ");\n"; } else { - o << indent(ind) << replaceParam(opts.mapCodeName["YYSETSTATE"], opts.yySetStateParam, fillIndex) << "\n"; + o << indent(ind) << replaceParam(opts.mapCodeName ()["YYSETSTATE"], opts.yySetStateParam (), fillIndex) << "\n"; } } - if (opts.bUseYYFill && n > 0) + if (opts.bUseYYFill () && n > 0) { o << indent(ind); if (n == 1) { - if (opts.bUseYYFillCheck) + if (opts.bUseYYFillCheck ()) { - o << "if (" << opts.input_api.expr_lessthan_one () << ") "; + o << "if (" << opts.input_api ().expr_lessthan_one () << ") "; } genYYFill(o, n); } else { - if (opts.bUseYYFillCheck) + if (opts.bUseYYFillCheck ()) { - o << "if (" << opts.input_api.expr_lessthan (n) << ") "; + o << "if (" << opts.input_api ().expr_lessthan (n) << ") "; } genYYFill(o, n); } } - if (opts.fFlag) + if (opts.fFlag ()) { - o << opts.mapCodeName["yyFillLabel"] << fillIndex << ":\n"; + o << opts.mapCodeName ()["yyFillLabel"] << fillIndex << ":\n"; } if (n > 0) { if (bSetMarker) { - o << opts.input_api.stmt_backup_peek (ind); + o << opts.input_api ().stmt_backup_peek (ind); } else { - o << opts.input_api.stmt_peek (ind); + o << opts.input_api ().stmt_peek (ind); } readCh = false; } @@ -342,10 +342,10 @@ void need (OutputFile & o, uint32_t ind, bool & readCh, uint32_t n, bool bSetMar void genYYFill(OutputFile & o, uint32_t need) { - if (opts.bUseYYFillParam) + if (opts.bUseYYFillParam ()) { - o << opts.mapCodeName["YYFILL"]; - if (!opts.bUseYYFillNaked) + o << opts.mapCodeName ()["YYFILL"]; + if (!opts.bUseYYFillNaked ()) { o << "(" << need << ");"; } @@ -353,8 +353,8 @@ void genYYFill(OutputFile & o, uint32_t need) } else { - o << replaceParam(opts.mapCodeName["YYFILL"], opts.yyFillLength, need); - if (!opts.bUseYYFillNaked) + o << replaceParam(opts.mapCodeName ()["YYFILL"], opts.yyFillLength (), need); + if (!opts.bUseYYFillNaked ()) { o << ";"; } @@ -364,13 +364,13 @@ void genYYFill(OutputFile & o, uint32_t need) void genSetCondition(OutputFile & o, uint32_t ind, const std::string& newcond) { - if (opts.bUseYYSetConditionParam) + if (opts.bUseYYSetConditionParam ()) { - o << indent(ind) << opts.mapCodeName["YYSETCONDITION"] << "(" << opts.condEnumPrefix << newcond << ");\n"; + o << indent(ind) << opts.mapCodeName ()["YYSETCONDITION"] << "(" << opts.condEnumPrefix () << newcond << ");\n"; } else { - o << indent(ind) << replaceParam(opts.mapCodeName["YYSETCONDITION"], opts.yySetConditionParam, opts.condEnumPrefix + newcond) << "\n"; + o << indent(ind) << replaceParam(opts.mapCodeName ()["YYSETCONDITION"], opts.yySetConditionParam (), opts.condEnumPrefix () + newcond) << "\n"; } } diff --git a/re2c/src/codegen/emit_dfa.cc b/re2c/src/codegen/emit_dfa.cc index 383e6638..96e43697 100644 --- a/re2c/src/codegen/emit_dfa.cc +++ b/re2c/src/codegen/emit_dfa.cc @@ -18,19 +18,19 @@ static void emit_state (OutputFile & o, uint32_t ind, const State * s, bool std::string genGetCondition() { - if (opts.bUseYYGetConditionNaked) + if (opts.bUseYYGetConditionNaked ()) { - return opts.mapCodeName["YYGETCONDITION"]; + return opts.mapCodeName ()["YYGETCONDITION"]; } else { - return opts.mapCodeName["YYGETCONDITION"] + "()"; + return opts.mapCodeName ()["YYGETCONDITION"] + "()"; } } void genGoTo(OutputFile & o, uint32_t ind, const State *from, const State *to, bool & readCh) { - if (opts.DFlag) + if (opts.DFlag ()) { o << from->label << " -> " << to->label << "\n"; return; @@ -38,28 +38,28 @@ void genGoTo(OutputFile & o, uint32_t ind, const State *from, const State *to, b if (readCh && from->next != to) { - o << opts.input_api.stmt_peek (ind); + o << opts.input_api ().stmt_peek (ind); readCh = false; } - o << indent(ind) << "goto " << opts.labelPrefix << to->label << ";\n"; + o << indent(ind) << "goto " << opts.labelPrefix () << to->label << ";\n"; } void emit_state (OutputFile & o, uint32_t ind, const State * s, bool used_label) { - if (!opts.DFlag) + if (!opts.DFlag ()) { if (used_label) { - o << opts.labelPrefix << s->label << ":\n"; + o << opts.labelPrefix () << s->label << ":\n"; } - if (opts.dFlag && (s->action.type != Action::INITIAL)) + if (opts.dFlag () && (s->action.type != Action::INITIAL)) { - o << indent(ind) << opts.mapCodeName["YYDEBUG"] << "(" << s->label << ", " << opts.input_api.expr_peek () << ");\n"; + o << indent(ind) << opts.mapCodeName ()["YYDEBUG"] << "(" << s->label << ", " << opts.input_api ().expr_peek () << ");\n"; } if (s->isPreCtxt) { - o << opts.input_api.stmt_backupctx (ind); + o << opts.input_api ().stmt_backupctx (ind); } } } @@ -67,7 +67,7 @@ void emit_state (OutputFile & o, uint32_t ind, const State * s, bool used_label) void DFA::count_used_labels (std::set & used, label_t start, label_t initial, bool force_start) const { // In '-f' mode, default state is always state 0 - if (opts.fFlag) + if (opts.fFlag ()) { used.insert (label_t::first ()); } @@ -106,7 +106,7 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra { OutputFile & o = output.source; - bool bProlog = (!opts.cFlag || !bWroteCondCheck); + bool bProlog = (!opts.cFlag () || !bWroteCondCheck); // start_label points to the beginning of current re2c block // (prior to condition dispatch in '-c' mode) @@ -114,7 +114,7 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra label_t start_label = o.label_counter.next (); // initial_label points to the beginning of DFA // in '-c' mode this is NOT equal to start_label - label_t initial_label = bProlog && opts.cFlag + label_t initial_label = bProlog && opts.cFlag () ? o.label_counter.next () : start_label; for (State * s = head; s; s = s->next) @@ -128,7 +128,7 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra skeleton->warn_undefined_control_flow (); - if (opts.flag_skeleton) + if (opts.flag_skeleton ()) { skeleton->emit_data (o.file_name); skeleton->emit_start (o, max_fill, need_backup, need_backupctx, need_accept); @@ -143,16 +143,16 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra { o << "\n"; o.insert_line_info (); - if (opts.DFlag) + if (opts.DFlag ()) { bPrologBrace = true; o << "digraph re2c {\n"; } - else if ((!opts.fFlag && o.get_used_yyaccept ()) - || (!opts.fFlag && opts.bEmitYYCh) - || (opts.bFlag && !opts.cFlag && BitMap::first) - || (opts.cFlag && !bWroteCondCheck && opts.gFlag) - || (opts.fFlag && !bWroteGetState && opts.gFlag) + else if ((!opts.fFlag () && o.get_used_yyaccept ()) + || (!opts.fFlag () && opts.bEmitYYCh ()) + || (opts.bFlag () && !opts.cFlag () && BitMap::first) + || (opts.cFlag () && !bWroteCondCheck && opts.gFlag ()) + || (opts.fFlag () && !bWroteGetState && opts.gFlag ()) ) { bPrologBrace = true; @@ -162,11 +162,11 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra { ind = 1; } - if (!opts.fFlag && !opts.DFlag) + if (!opts.fFlag () && !opts.DFlag ()) { - if (opts.bEmitYYCh) + if (opts.bEmitYYCh ()) { - o << indent(ind) << opts.mapCodeName["YYCTYPE"] << " " << opts.mapCodeName["yych"] << ";\n"; + o << indent(ind) << opts.mapCodeName ()["YYCTYPE"] << " " << opts.mapCodeName ()["yych"] << ";\n"; } o.insert_yyaccept_init (ind); } @@ -175,46 +175,46 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra o << "\n"; } } - if (opts.bFlag && !opts.cFlag && BitMap::first) + if (opts.bFlag () && !opts.cFlag () && BitMap::first) { BitMap::gen(o, ind, lbChar, ubChar <= 256 ? ubChar : 256); } if (bProlog) { - if (opts.cFlag && !bWroteCondCheck && opts.gFlag) + if (opts.cFlag () && !bWroteCondCheck && opts.gFlag ()) { genCondTable(o, ind, output.types); } o.insert_state_goto (ind); - if (opts.cFlag && !opts.DFlag) + if (opts.cFlag () && !opts.DFlag ()) { if (used_labels.count(start_label)) { - o << opts.labelPrefix << start_label << ":\n"; + o << opts.labelPrefix () << start_label << ":\n"; } } o.write_user_start_label (); - if (opts.cFlag && !bWroteCondCheck) + if (opts.cFlag () && !bWroteCondCheck) { genCondGoto(o, ind, output.types); } } - if (opts.cFlag && !cond.empty()) + if (opts.cFlag () && !cond.empty()) { - if (opts.condDivider.length()) + if (opts.condDivider ().length()) { - o << replaceParam(opts.condDivider, opts.condDividerParam, cond) << "\n"; + o << replaceParam(opts.condDivider (), opts.condDividerParam (), cond) << "\n"; } - if (opts.DFlag) + if (opts.DFlag ()) { o << cond << " -> " << head->label << "\n"; } else { - o << opts.condPrefix << cond << ":\n"; + o << opts.condPrefix () << cond << ":\n"; } } - if (opts.cFlag && opts.bFlag && BitMap::first) + if (opts.cFlag () && opts.bFlag () && BitMap::first) { o << indent(ind++) << "{\n"; BitMap::gen(o, ind, lbChar, ubChar <= 256 ? ubChar : 256); @@ -224,16 +224,16 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra // skip it when entering DFA. if (used_labels.count(head->label)) { - o << indent(ind) << "goto " << opts.labelPrefix << initial_label << ";\n"; + o << indent(ind) << "goto " << opts.labelPrefix () << initial_label << ";\n"; } // Generate code emit_body (o, ind, used_labels); - if (opts.cFlag && opts.bFlag && BitMap::first) + if (opts.cFlag () && opts.bFlag () && BitMap::first) { o << indent(--ind) << "}\n"; } // Generate epilog - if ((!opts.cFlag || isLastCond) && bPrologBrace) + if ((!opts.cFlag () || isLastCond) && bPrologBrace) { o << indent(--ind) << "}\n"; } @@ -250,10 +250,10 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra void genCondTable(OutputFile & o, uint32_t ind, const std::vector & condnames) { const size_t conds = condnames.size (); - o << indent(ind++) << "static void *" << opts.mapCodeName["yyctable"] << "[" << conds << "] = {\n"; + o << indent(ind++) << "static void *" << opts.mapCodeName ()["yyctable"] << "[" << conds << "] = {\n"; for (size_t i = 0; i < conds; ++i) { - o << indent(ind) << "&&" << opts.condPrefix << condnames[i] << ",\n"; + o << indent(ind) << "&&" << opts.condPrefix () << condnames[i] << ",\n"; } o << indent(--ind) << "};\n"; } @@ -262,7 +262,7 @@ void genCondGotoSub(OutputFile & o, uint32_t ind, const std::vector { if (cMin == cMax) { - o << indent(ind) << "goto " << opts.condPrefix << condnames[cMin] << ";\n"; + o << indent(ind) << "goto " << opts.condPrefix () << condnames[cMin] << ";\n"; } else { @@ -302,7 +302,7 @@ void genCondGotoSub(OutputFile & o, uint32_t ind, const std::vector void genCondGoto(OutputFile & o, uint32_t ind, const std::vector & condnames) { const size_t conds = condnames.size (); - if (opts.DFlag) + if (opts.DFlag ()) { o.warn_condition_order = false; // see note [condition order] for (size_t i = 0; i < conds; ++i) @@ -311,11 +311,11 @@ void genCondGoto(OutputFile & o, uint32_t ind, const std::vector & o << "0 -> " << cond << " [label=\"state=" << cond << "\"]\n"; } } - else if (opts.gFlag) + else if (opts.gFlag ()) { - o << indent(ind) << "goto *" << opts.mapCodeName["yyctable"] << "[" << genGetCondition() << "];\n"; + o << indent(ind) << "goto *" << opts.mapCodeName ()["yyctable"] << "[" << genGetCondition() << "];\n"; } - else if (opts.sFlag) + else if (opts.sFlag ()) { if (conds == 1) { @@ -330,7 +330,7 @@ void genCondGoto(OutputFile & o, uint32_t ind, const std::vector & for (size_t i = 0; i < conds; ++i) { const std::string & cond = condnames[i]; - o << indent(ind) << "case " << opts.condEnumPrefix << cond << ": goto " << opts.condPrefix << cond << ";\n"; + o << indent(ind) << "case " << opts.condEnumPrefix () << cond << ": goto " << opts.condPrefix () << cond << ";\n"; } o << indent(ind) << "}\n"; } diff --git a/re2c/src/codegen/go_construct.cc b/re2c/src/codegen/go_construct.cc index 7667dcd1..b2643ef6 100644 --- a/re2c/src/codegen/go_construct.cc +++ b/re2c/src/codegen/go_construct.cc @@ -113,7 +113,7 @@ SwitchIf::SwitchIf (const Span * sp, uint32_t nsp, const State * next) : type (IF) , info () { - if ((!opts.sFlag && nsp > 2) || (nsp > 8 && (sp[nsp - 2].ub - sp[0].ub <= 3 * (nsp - 2)))) + if ((!opts.sFlag () && nsp > 2) || (nsp > 8 && (sp[nsp - 2].ub - sp[0].ub <= 3 * (nsp - 2)))) { type = SWITCH; info.cases = new Cases (sp, nsp); @@ -216,17 +216,17 @@ void Go::init (const State * from) } const uint32_t dSpans = nSpans - hSpans - nBitmaps; - if (opts.DFlag) + if (opts.DFlag ()) { type = DOT; info.dot = new Dot (span, nSpans, from); } - else if (opts.gFlag && (dSpans >= opts.cGotoThreshold)) + else if (opts.gFlag () && (dSpans >= opts.cGotoThreshold ())) { type = CPGOTO; info.cpgoto = new Cpgoto (span, nSpans, hspan, hSpans, from->next); } - else if (opts.bFlag && (nBitmaps > 0)) + else if (opts.bFlag () && (nBitmaps > 0)) { type = BITMAP; info.bitmap = new GoBitmap (span, nSpans, hspan, hSpans, bitmap, bitmap_state, from->next); diff --git a/re2c/src/codegen/go_emit.cc b/re2c/src/codegen/go_emit.cc index 6e2fa3dc..3a6a0e76 100644 --- a/re2c/src/codegen/go_emit.cc +++ b/re2c/src/codegen/go_emit.cc @@ -17,11 +17,11 @@ std::string output_yych (bool & readCh) if (readCh) { readCh = false; - return "(" + opts.input_api.expr_peek_save () + ")"; + return "(" + opts.input_api ().expr_peek_save () + ")"; } else { - return opts.mapCodeName["yych"]; + return opts.mapCodeName ()["yych"]; } } @@ -36,10 +36,10 @@ void output_goto (OutputFile & o, uint32_t ind, bool & readCh, label_t to) { if (readCh) { - o << opts.input_api.stmt_peek (ind); + o << opts.input_api ().stmt_peek (ind); readCh = false; } - o << indent (ind) << "goto " << opts.labelPrefix << to << ";\n"; + o << indent (ind) << "goto " << opts.labelPrefix () << to << ";\n"; } std::string output_hgo (OutputFile & o, uint32_t ind, bool & readCh, SwitchIf * hgo) @@ -50,7 +50,7 @@ std::string output_hgo (OutputFile & o, uint32_t ind, bool & readCh, SwitchIf * o << indent (ind) << "if (" << yych <<" & ~0xFF) {\n"; hgo->emit (o, ind + 1, readCh); o << indent (ind) << "} else "; - yych = opts.mapCodeName["yych"]; + yych = opts.mapCodeName ()["yych"]; } else { @@ -68,9 +68,9 @@ void Case::emit (OutputFile & o, uint32_t ind) o << indent (ind) << "case "; o.write_char_hex (b); o << ":"; - if (opts.dFlag && opts.encoding.type () == Enc::EBCDIC) + if (opts.dFlag () && opts.encoding ().type () == Enc::EBCDIC) { - const uint32_t c = opts.encoding.decodeUnsafe (b); + const uint32_t c = opts.encoding ().decodeUnsafe (b); if (is_print (c)) o << " /* " << static_cast (c) << " */"; } @@ -154,8 +154,8 @@ void SwitchIf::emit (OutputFile & o, uint32_t ind, bool & readCh) void GoBitmap::emit (OutputFile & o, uint32_t ind, bool & readCh) { std::string yych = output_hgo (o, ind, readCh, hgo); - o << "if (" << opts.mapCodeName["yybm"] << "[" << bitmap->i << "+" << yych << "] & "; - if (opts.yybmHexTable) + o << "if (" << opts.mapCodeName ()["yybm"] << "[" << bitmap->i << "+" << yych << "] & "; + if (opts.yybmHexTable ()) { o.write_hex (bitmap->m); } @@ -187,12 +187,12 @@ label_t CpgotoTable::max_label () const void CpgotoTable::emit (OutputFile & o, uint32_t ind) { - o << indent (ind) << "static void *" << opts.mapCodeName["yytarget"] << "[256] = {\n"; + o << indent (ind) << "static void *" << opts.mapCodeName ()["yytarget"] << "[256] = {\n"; o << indent (++ind); const uint32_t max_digits = max_label ().width (); for (uint32_t i = 0; i < TABLE_SIZE; ++i) { - o << "&&" << opts.labelPrefix << table[i]->label; + o << "&&" << opts.labelPrefix () << table[i]->label; if (i == TABLE_SIZE - 1) { o << "\n"; @@ -215,7 +215,7 @@ void Cpgoto::emit (OutputFile & o, uint32_t ind, bool & readCh) std::string yych = output_hgo (o, ind, readCh, hgo); o << "{\n"; table->emit (o, ++ind); - o << indent(ind) << "goto *" << opts.mapCodeName["yytarget"] << "[" << yych << "];\n"; + o << indent(ind) << "goto *" << opts.mapCodeName ()["yytarget"] << "[" << yych << "];\n"; o << indent(--ind) << "}\n"; } diff --git a/re2c/src/codegen/indent.h b/re2c/src/codegen/indent.h index fde1faad..8f052556 100644 --- a/re2c/src/codegen/indent.h +++ b/re2c/src/codegen/indent.h @@ -12,9 +12,9 @@ inline std::string indent (uint32_t ind) { std::string str; - while (!opts.DFlag && ind-- > 0) + while (!opts.DFlag () && ind-- > 0) { - str += opts.indString; + str += opts.indString (); } return str; } diff --git a/re2c/src/codegen/input_api.cc b/re2c/src/codegen/input_api.cc index fb0d69af..2a844ca4 100644 --- a/re2c/src/codegen/input_api.cc +++ b/re2c/src/codegen/input_api.cc @@ -17,153 +17,153 @@ void InputAPI::set (type_t t) type_ = t; } -std::string InputAPI::expr_peek () +std::string InputAPI::expr_peek () const { std::string s; switch (type_) { case DEFAULT: - s = "*" + opts.mapCodeName["YYCURSOR"]; + s = "*" + opts.mapCodeName ()["YYCURSOR"]; break; case CUSTOM: - s = opts.mapCodeName["YYPEEK"] + " ()"; + s = opts.mapCodeName ()["YYPEEK"] + " ()"; break; } return s; } -std::string InputAPI::expr_peek_save () +std::string InputAPI::expr_peek_save () const { - return opts.mapCodeName["yych"] + " = " + opts.yychConversion + expr_peek (); + return opts.mapCodeName ()["yych"] + " = " + opts.yychConversion () + expr_peek (); } -std::string InputAPI::stmt_peek (uint32_t ind) +std::string InputAPI::stmt_peek (uint32_t ind) const { return indent (ind) + expr_peek_save () + ";\n"; } -std::string InputAPI::stmt_skip (uint32_t ind) +std::string InputAPI::stmt_skip (uint32_t ind) const { std::string s; switch (type_) { case DEFAULT: - s = "++" + opts.mapCodeName["YYCURSOR"]; + s = "++" + opts.mapCodeName ()["YYCURSOR"]; break; case CUSTOM: - s = opts.mapCodeName["YYSKIP"] + " ()"; + s = opts.mapCodeName ()["YYSKIP"] + " ()"; break; } return indent (ind) + s + ";\n"; } -std::string InputAPI::stmt_backup (uint32_t ind) +std::string InputAPI::stmt_backup (uint32_t ind) const { std::string s; switch (type_) { case DEFAULT: - s = opts.mapCodeName["YYMARKER"] + " = " + opts.mapCodeName["YYCURSOR"]; + s = opts.mapCodeName ()["YYMARKER"] + " = " + opts.mapCodeName ()["YYCURSOR"]; break; case CUSTOM: - s = opts.mapCodeName["YYBACKUP"] + " ()"; + s = opts.mapCodeName ()["YYBACKUP"] + " ()"; break; } return indent (ind) + s + ";\n"; } -std::string InputAPI::stmt_backupctx (uint32_t ind) +std::string InputAPI::stmt_backupctx (uint32_t ind) const { std::string s; switch (type_) { case DEFAULT: // backward compatibility: '+1' here instead of '++YYCURSOR;' in stmt_restorectx - s = opts.mapCodeName["YYCTXMARKER"] + " = " + opts.mapCodeName["YYCURSOR"] + " + 1"; + s = opts.mapCodeName ()["YYCTXMARKER"] + " = " + opts.mapCodeName ()["YYCURSOR"] + " + 1"; break; case CUSTOM: - s = opts.mapCodeName["YYBACKUPCTX"] + " ()"; + s = opts.mapCodeName ()["YYBACKUPCTX"] + " ()"; break; } return indent (ind) + s + ";\n"; } -std::string InputAPI::stmt_restore (uint32_t ind) +std::string InputAPI::stmt_restore (uint32_t ind) const { std::string s; switch (type_) { case DEFAULT: - s = opts.mapCodeName["YYCURSOR"] + " = " + opts.mapCodeName["YYMARKER"]; + s = opts.mapCodeName ()["YYCURSOR"] + " = " + opts.mapCodeName ()["YYMARKER"]; break; case CUSTOM: - s = opts.mapCodeName["YYRESTORE"] + " ()"; + s = opts.mapCodeName ()["YYRESTORE"] + " ()"; break; } return indent (ind) + s + ";\n"; } -std::string InputAPI::stmt_restorectx (uint32_t ind) +std::string InputAPI::stmt_restorectx (uint32_t ind) const { std::string s; switch (type_) { case DEFAULT: // backward compatibility: 'no ++YYCURSOR;' here; instead '+1' in stmt_backupctx - s = indent (ind) + opts.mapCodeName["YYCURSOR"] + " = " + opts.mapCodeName["YYCTXMARKER"] + ";\n"; + s = indent (ind) + opts.mapCodeName ()["YYCURSOR"] + " = " + opts.mapCodeName ()["YYCTXMARKER"] + ";\n"; break; case CUSTOM: - s = indent (ind) + opts.mapCodeName["YYRESTORECTX"] + " ();\n" + stmt_skip (ind); + s = indent (ind) + opts.mapCodeName ()["YYRESTORECTX"] + " ();\n" + stmt_skip (ind); break; } return s; } -std::string InputAPI::stmt_skip_peek (uint32_t ind) +std::string InputAPI::stmt_skip_peek (uint32_t ind) const { return type_ == DEFAULT - ? indent (ind) + opts.mapCodeName["yych"] + " = " + opts.yychConversion + "*++" + opts.mapCodeName["YYCURSOR"] + ";\n" + ? indent (ind) + opts.mapCodeName ()["yych"] + " = " + opts.yychConversion () + "*++" + opts.mapCodeName ()["YYCURSOR"] + ";\n" : stmt_skip (ind) + stmt_peek (ind); } -std::string InputAPI::stmt_skip_backup (uint32_t ind) +std::string InputAPI::stmt_skip_backup (uint32_t ind) const { return type_ == DEFAULT - ? indent (ind) + opts.mapCodeName["YYMARKER"] + " = ++" + opts.mapCodeName["YYCURSOR"] + ";\n" + ? indent (ind) + opts.mapCodeName ()["YYMARKER"] + " = ++" + opts.mapCodeName ()["YYCURSOR"] + ";\n" : stmt_skip (ind) + stmt_backup (ind); } -std::string InputAPI::stmt_backup_peek (uint32_t ind) +std::string InputAPI::stmt_backup_peek (uint32_t ind) const { return type_ == DEFAULT - ? indent (ind) + opts.mapCodeName["yych"] + " = " + opts.yychConversion + "*(" + opts.mapCodeName["YYMARKER"] + " = " + opts.mapCodeName["YYCURSOR"] + ");\n" + ? indent (ind) + opts.mapCodeName ()["yych"] + " = " + opts.yychConversion () + "*(" + opts.mapCodeName ()["YYMARKER"] + " = " + opts.mapCodeName ()["YYCURSOR"] + ");\n" : stmt_backup (ind) + stmt_peek (ind); } -std::string InputAPI::stmt_skip_backup_peek (uint32_t ind) +std::string InputAPI::stmt_skip_backup_peek (uint32_t ind) const { return type_ == DEFAULT - ? indent (ind) + opts.mapCodeName["yych"] + " = " + opts.yychConversion + "*(" + opts.mapCodeName["YYMARKER"] + " = ++" + opts.mapCodeName["YYCURSOR"] + ");\n" + ? indent (ind) + opts.mapCodeName ()["yych"] + " = " + opts.yychConversion () + "*(" + opts.mapCodeName ()["YYMARKER"] + " = ++" + opts.mapCodeName ()["YYCURSOR"] + ");\n" : stmt_skip (ind) + stmt_backup (ind) + stmt_peek (ind); } -std::string InputAPI::expr_lessthan_one () +std::string InputAPI::expr_lessthan_one () const { return type_ == DEFAULT - ? opts.mapCodeName["YYLIMIT"] + " <= " + opts.mapCodeName["YYCURSOR"] + ? opts.mapCodeName ()["YYLIMIT"] + " <= " + opts.mapCodeName ()["YYCURSOR"] : expr_lessthan (1); } -std::string InputAPI::expr_lessthan (uint32_t n) +std::string InputAPI::expr_lessthan (uint32_t n) const { std::ostringstream s; switch (type_) { case DEFAULT: - s << "(" << opts.mapCodeName["YYLIMIT"] << " - " << opts.mapCodeName["YYCURSOR"] << ") < " << n; + s << "(" << opts.mapCodeName ()["YYLIMIT"] << " - " << opts.mapCodeName ()["YYCURSOR"] << ") < " << n; break; case CUSTOM: - s << opts.mapCodeName["YYLESSTHAN"] << " (" << n << ")"; + s << opts.mapCodeName ()["YYLESSTHAN"] << " (" << n << ")"; break; } return s.str (); diff --git a/re2c/src/codegen/input_api.h b/re2c/src/codegen/input_api.h index 4018cc0c..6acf53c4 100644 --- a/re2c/src/codegen/input_api.h +++ b/re2c/src/codegen/input_api.h @@ -23,20 +23,20 @@ private: public: type_t type () const; void set (type_t t); - std::string expr_peek (); - std::string expr_peek_save (); - std::string stmt_peek (uint32_t ind); - std::string stmt_skip (uint32_t ind); - std::string stmt_backup (uint32_t ind); - std::string stmt_backupctx (uint32_t ind); - std::string stmt_restore (uint32_t ind); - std::string stmt_restorectx (uint32_t ind); - std::string stmt_skip_peek (uint32_t ind); - std::string stmt_skip_backup (uint32_t ind); - std::string stmt_backup_peek (uint32_t ind); - std::string stmt_skip_backup_peek (uint32_t ind); - std::string expr_lessthan_one (); - std::string expr_lessthan (uint32_t n); + std::string expr_peek () const; + std::string expr_peek_save () const; + std::string stmt_peek (uint32_t ind) const; + std::string stmt_skip (uint32_t ind) const; + std::string stmt_backup (uint32_t ind) const; + std::string stmt_backupctx (uint32_t ind) const; + std::string stmt_restore (uint32_t ind) const; + std::string stmt_restorectx (uint32_t ind) const; + std::string stmt_skip_peek (uint32_t ind) const; + std::string stmt_skip_backup (uint32_t ind) const; + std::string stmt_backup_peek (uint32_t ind) const; + std::string stmt_skip_backup_peek (uint32_t ind) const; + std::string expr_lessthan_one () const; + std::string expr_lessthan (uint32_t n) const; }; } // end namespace re2c diff --git a/re2c/src/codegen/output.cc b/re2c/src/codegen/output.cc index a9acf2d5..117bd2cb 100644 --- a/re2c/src/codegen/output.cc +++ b/re2c/src/codegen/output.cc @@ -55,7 +55,7 @@ OutputFile::OutputFile (const char * fn) , file (NULL) , blocks () , label_counter () - , warn_condition_order (!opts.tFlag) // see note [condition order] + , warn_condition_order (!opts.tFlag ()) // see note [condition order] { new_block (); } @@ -191,7 +191,7 @@ void OutputFile::insert_line_info () void OutputFile::insert_state_goto (uint32_t ind) { - if (opts.fFlag && !bWroteGetState) + if (opts.fFlag () && !bWroteGetState) { blocks.back ()->fragments.push_back (new OutputFragment (OutputFragment::STATE_GOTO, ind)); insert_code (); @@ -363,23 +363,23 @@ Output::~Output () void output_state_goto (std::ostream & o, uint32_t ind, uint32_t start_label) { o << indent(ind) << "switch (" << output_get_state() << ") {\n"; - if (opts.bUseStateAbort) + if (opts.bUseStateAbort ()) { o << indent(ind) << "default: abort();\n"; - o << indent(ind) << "case -1: goto " << opts.labelPrefix << start_label << ";\n"; + o << indent(ind) << "case -1: goto " << opts.labelPrefix () << start_label << ";\n"; } else { - o << indent(ind) << "default: goto " << opts.labelPrefix << start_label << ";\n"; + o << indent(ind) << "default: goto " << opts.labelPrefix () << start_label << ";\n"; } for (uint32_t i = 0; i < last_fill_index; ++i) { - o << indent(ind) << "case " << i << ": goto " << opts.mapCodeName["yyFillLabel"] << i << ";\n"; + o << indent(ind) << "case " << i << ": goto " << opts.mapCodeName ()["yyFillLabel"] << i << ";\n"; } o << indent(ind) << "}\n"; - if (opts.bUseStateNext) + if (opts.bUseStateNext ()) { - o << opts.mapCodeName["yyNext"] << ":\n"; + o << opts.mapCodeName ()["yyNext"] << ":\n"; } } @@ -387,7 +387,7 @@ void output_yyaccept_init (std::ostream & o, uint32_t ind, bool used_yyaccept) { if (used_yyaccept) { - o << indent (ind) << "unsigned int " << opts.mapCodeName["yyaccept"] << " = 0;\n"; + o << indent (ind) << "unsigned int " << opts.mapCodeName ()["yyaccept"] << " = 0;\n"; } } @@ -398,7 +398,7 @@ void output_yymaxfill (std::ostream & o, uint32_t max_fill) void output_line_info (std::ostream & o, uint32_t line_number, const char * file_name) { - if (!opts.iFlag) + if (!opts.iFlag ()) { o << "#line " << line_number << " \"" << file_name << "\"\n"; } @@ -406,10 +406,10 @@ void output_line_info (std::ostream & o, uint32_t line_number, const char * file void output_types (std::ostream & o, uint32_t ind, const std::vector & types) { - o << indent (ind++) << "enum " << opts.mapCodeName["YYCONDTYPE"] << " {\n"; + o << indent (ind++) << "enum " << opts.mapCodeName ()["YYCONDTYPE"] << " {\n"; for (unsigned int i = 0; i < types.size (); ++i) { - o << indent (ind) << opts.condEnumPrefix << types[i] << ",\n"; + o << indent (ind) << opts.condEnumPrefix () << types[i] << ",\n"; } o << indent (--ind) << "};\n"; } @@ -417,7 +417,7 @@ void output_types (std::ostream & o, uint32_t ind, const std::vectorisBase = true; split(s); - if (opts.bFlag) + if (opts.bFlag ()) { BitMap::find(&s->next->go, s); } diff --git a/re2c/src/codegen/print.cc b/re2c/src/codegen/print.cc index 88c83996..58f4c936 100644 --- a/re2c/src/codegen/print.cc +++ b/re2c/src/codegen/print.cc @@ -35,7 +35,7 @@ char hexCh(uint32_t c) void prtChOrHex(std::ostream& o, uint32_t c) { - if (opts.encoding.type () != Enc::EBCDIC + if (opts.encoding ().type () != Enc::EBCDIC && (is_print (c) || is_space (c))) { o << '\''; @@ -51,7 +51,7 @@ void prtChOrHex(std::ostream& o, uint32_t c) void prtHex(std::ostream& o, uint32_t c) { o << "0x"; - const uint32_t cunit_size = opts.encoding.szCodeUnit (); + const uint32_t cunit_size = opts.encoding ().szCodeUnit (); if (cunit_size >= 4) { o << hexCh (c >> 28u) @@ -73,39 +73,39 @@ void prtCh(std::ostream& o, uint32_t c) switch (c) { case '\'': - o << (opts.DFlag ? "'" : "\\'"); + o << (opts.DFlag () ? "'" : "\\'"); break; case '"': - o << (opts.DFlag ? "\\\"" : "\""); + o << (opts.DFlag () ? "\\\"" : "\""); break; case '\n': - o << (opts.DFlag ? "\\\\n" : "\\n"); + o << (opts.DFlag () ? "\\\\n" : "\\n"); break; case '\t': - o << (opts.DFlag ? "\\\\t" : "\\t"); + o << (opts.DFlag () ? "\\\\t" : "\\t"); break; case '\v': - o << (opts.DFlag ? "\\\\v" : "\\v"); + o << (opts.DFlag () ? "\\\\v" : "\\v"); break; case '\b': - o << (opts.DFlag ? "\\\\b" : "\\b"); + o << (opts.DFlag () ? "\\\\b" : "\\b"); break; case '\r': - o << (opts.DFlag ? "\\\\r" : "\\r"); + o << (opts.DFlag () ? "\\\\r" : "\\r"); break; case '\f': - o << (opts.DFlag ? "\\\\f" : "\\f"); + o << (opts.DFlag () ? "\\\\f" : "\\f"); break; case '\a': - o << (opts.DFlag ? "\\\\a" :"\\a"); + o << (opts.DFlag () ? "\\\\a" :"\\a"); break; case '\\': @@ -120,7 +120,7 @@ void prtCh(std::ostream& o, uint32_t c) void prtChOrHexForSpan(std::ostream& o, uint32_t c) { - if (opts.encoding.type () != Enc::EBCDIC + if (opts.encoding ().type () != Enc::EBCDIC && is_print (c) && (c != ']')) { diff --git a/re2c/src/codegen/skeleton/generate_code.cc b/re2c/src/codegen/skeleton/generate_code.cc index 0aeaa8d7..963d2510 100644 --- a/re2c/src/codegen/skeleton/generate_code.cc +++ b/re2c/src/codegen/skeleton/generate_code.cc @@ -32,7 +32,7 @@ static void exact_uint (OutputFile & o, size_t width) void Skeleton::emit_prolog (OutputFile & o) { - const std::string & ind = opts.indString; + const std::string & ind = opts.indString (); o << "\n" << "#include "; o << "\n" << "#include /* malloc, free */"; @@ -96,11 +96,11 @@ void Skeleton::emit_start , bool accept ) const { - const std::string & ind = opts.indString; + const std::string & ind = opts.indString (); const uint32_t default_rule = maxkey (); o << "\n" << "#define YYCTYPE "; - exact_uint (o, opts.encoding.szCodeUnit ()); + exact_uint (o, opts.encoding ().szCodeUnit ()); o << "\n" << "#define YYKEYTYPE "; exact_uint (o, sizeof_key); o << "\n" << "#define YYPEEK() *cursor"; @@ -221,9 +221,9 @@ void Skeleton::emit_start { o << "\n" << ind << ind << "unsigned int yyaccept = 0;"; } - if (opts.bFlag && BitMap::first) + if (opts.bFlag () && BitMap::first) { - BitMap::gen (o, 2, 0, std::min (0xFFu, opts.encoding.nCodeUnits ())); + BitMap::gen (o, 2, 0, std::min (0xFFu, opts.encoding ().nCodeUnits ())); } o << "\n"; } @@ -234,7 +234,7 @@ void Skeleton::emit_end , bool backupctx ) const { - const std::string & ind = opts.indString; + const std::string & ind = opts.indString (); o << "\n" << ind << "}"; o << "\n" << ind << "if (status == 0)"; @@ -285,10 +285,10 @@ void Skeleton::emit_epilog (OutputFile & o, const std::vector & nam const size_t names_count = names.size (); for (size_t i = 0; i < names_count; ++i) { - o << "\n" << opts.indString << "if (lex_" << names[i] << " () != 0) return 1;"; + o << "\n" << opts.indString () << "if (lex_" << names[i] << " () != 0) return 1;"; } - o << "\n" << opts.indString << "return 0;"; + o << "\n" << opts.indString () << "return 0;"; o << "\n" << "}"; o << "\n"; } diff --git a/re2c/src/codegen/skeleton/generate_data.cc b/re2c/src/codegen/skeleton/generate_data.cc index 014599d1..4d5a6a10 100644 --- a/re2c/src/codegen/skeleton/generate_data.cc +++ b/re2c/src/codegen/skeleton/generate_data.cc @@ -212,7 +212,7 @@ template void Skeleton::generate_paths (FILE * input, FILE * keys) { - switch (opts.encoding.szCodeUnit ()) + switch (opts.encoding ().szCodeUnit ()) { case 4: generate_paths_cunit (input, keys); break; case 2: generate_paths_cunit (input, keys); break; diff --git a/re2c/src/conf/opt.cc b/re2c/src/conf/opt.cc index 00dcdb87..0d3123e9 100644 --- a/re2c/src/conf/opt.cc +++ b/re2c/src/conf/opt.cc @@ -22,6 +22,7 @@ opt_t::opt_t () , flag_skeleton (false) , bNoGenerationDate (false) , bEmitYYCh (true) + , yychConversion (false) , bUseStateNext (false) , bUseYYFill (true) , bUseYYFillParam (true) @@ -46,7 +47,6 @@ opt_t::opt_t () , condDividerParam ("@@") , condGoto ("goto @@;") , condGotoParam ("@@") - , yychConversion ("") , yyFillLength ("@@") , yySetConditionParam ("@@") , yySetStateParam ("@@") @@ -72,6 +72,7 @@ opt_t::opt_t (const opt_t & opt) , flag_skeleton (opt.flag_skeleton) , bNoGenerationDate (opt.bNoGenerationDate) , bEmitYYCh (opt.bEmitYYCh) + , yychConversion (opt.yychConversion) , bUseStateNext (opt.bUseStateNext) , bUseYYFill (opt.bUseYYFill) , bUseYYFillParam (opt.bUseYYFillParam) @@ -96,7 +97,6 @@ opt_t::opt_t (const opt_t & opt) , condDividerParam (opt.condDividerParam) , condGoto (opt.condGoto) , condGotoParam (opt.condGotoParam) - , yychConversion (opt.yychConversion) , yyFillLength (opt.yyFillLength) , yySetConditionParam (opt.yySetConditionParam) , yySetStateParam (opt.yySetStateParam) @@ -112,110 +112,113 @@ opt_t & opt_t::operator = (const opt_t & opt) return *this; } -bool Opt::apply () +bool opt_t::check () { - *((opt_t *) this) = useropt; - // check groups of mutually exclusive options if (DFlag && flag_skeleton) { error ("incompatible options: '-D, --emit-dot' and '--skeleton'"); return false; } + return true; +} - // reset to default options that make no sense in current configuration +void opt_t::fix () +{ + // some options don't make sense in current configuration + // reset them to default if (DFlag) { - bFlag = baseopt.bFlag; - dFlag = baseopt.dFlag; - fFlag = baseopt.fFlag; - gFlag = baseopt.gFlag; - iFlag = baseopt.iFlag; - sFlag = baseopt.sFlag; - tFlag = baseopt.tFlag; - header_file = baseopt.header_file; - bEmitYYCh = baseopt.bEmitYYCh; - bUseStateNext = baseopt.bUseStateNext; - bUseYYFill = baseopt.bUseYYFill; - bUseYYFillParam = baseopt.bUseYYFillParam; - bUseYYFillCheck = baseopt.bUseYYFillCheck; - bUseYYFillNaked = baseopt.bUseYYFillNaked; - bUseYYSetConditionParam = baseopt.bUseYYSetConditionParam; - bUseYYGetConditionNaked = baseopt.bUseYYGetConditionNaked; - bUseYYSetStateParam = baseopt.bUseYYSetStateParam; - bUseYYSetStateNaked = baseopt.bUseYYSetStateNaked; - bUseYYGetStateNaked = baseopt.bUseYYGetStateNaked; - yybmHexTable = baseopt.yybmHexTable; - bUseStateAbort = baseopt.bUseStateAbort; - cGotoThreshold = baseopt.cGotoThreshold; - topIndent = baseopt.topIndent; - indString = baseopt.indString; - labelPrefix = baseopt.labelPrefix; - condPrefix = baseopt.condPrefix; - condEnumPrefix = baseopt.condEnumPrefix; - condDivider = baseopt.condDivider; - condDividerParam = baseopt.condDividerParam; - condGoto = baseopt.condGoto; - condGotoParam = baseopt.condGotoParam; - yychConversion = baseopt.yychConversion; - yyFillLength = baseopt.yyFillLength; - yySetConditionParam = baseopt.yySetConditionParam; - yySetStateParam = baseopt.yySetStateParam; - mapCodeName = baseopt.mapCodeName; - input_api = baseopt.input_api; + bFlag = Opt::baseopt.bFlag; + dFlag = Opt::baseopt.dFlag; + fFlag = Opt::baseopt.fFlag; + gFlag = Opt::baseopt.gFlag; + iFlag = Opt::baseopt.iFlag; + sFlag = Opt::baseopt.sFlag; + tFlag = Opt::baseopt.tFlag; + header_file = Opt::baseopt.header_file; + bEmitYYCh = Opt::baseopt.bEmitYYCh; + bUseStateNext = Opt::baseopt.bUseStateNext; + bUseYYFill = Opt::baseopt.bUseYYFill; + bUseYYFillParam = Opt::baseopt.bUseYYFillParam; + bUseYYFillCheck = Opt::baseopt.bUseYYFillCheck; + bUseYYFillNaked = Opt::baseopt.bUseYYFillNaked; + bUseYYSetConditionParam = Opt::baseopt.bUseYYSetConditionParam; + bUseYYGetConditionNaked = Opt::baseopt.bUseYYGetConditionNaked; + bUseYYSetStateParam = Opt::baseopt.bUseYYSetStateParam; + bUseYYSetStateNaked = Opt::baseopt.bUseYYSetStateNaked; + bUseYYGetStateNaked = Opt::baseopt.bUseYYGetStateNaked; + yybmHexTable = Opt::baseopt.yybmHexTable; + bUseStateAbort = Opt::baseopt.bUseStateAbort; + cGotoThreshold = Opt::baseopt.cGotoThreshold; + topIndent = Opt::baseopt.topIndent; + indString = Opt::baseopt.indString; + labelPrefix = Opt::baseopt.labelPrefix; + condPrefix = Opt::baseopt.condPrefix; + condEnumPrefix = Opt::baseopt.condEnumPrefix; + condDivider = Opt::baseopt.condDivider; + condDividerParam = Opt::baseopt.condDividerParam; + condGoto = Opt::baseopt.condGoto; + condGotoParam = Opt::baseopt.condGotoParam; + yychConversion = Opt::baseopt.yychConversion; + yyFillLength = Opt::baseopt.yyFillLength; + yySetConditionParam = Opt::baseopt.yySetConditionParam; + yySetStateParam = Opt::baseopt.yySetStateParam; + mapCodeName = Opt::baseopt.mapCodeName; + input_api = Opt::baseopt.input_api; } if (flag_skeleton) { - dFlag = baseopt.dFlag; - fFlag = baseopt.fFlag; - iFlag = baseopt.iFlag; - tFlag = baseopt.tFlag; - header_file = baseopt.header_file; - bEmitYYCh = baseopt.bEmitYYCh; - bUseStateNext = baseopt.bUseStateNext; - bUseYYFill = baseopt.bUseYYFill; - bUseYYFillParam = baseopt.bUseYYFillParam; - bUseYYFillCheck = baseopt.bUseYYFillCheck; - bUseYYFillNaked = baseopt.bUseYYFillNaked; - bUseYYSetConditionParam = baseopt.bUseYYSetConditionParam; - bUseYYGetConditionNaked = baseopt.bUseYYGetConditionNaked; - bUseYYSetStateParam = baseopt.bUseYYSetStateParam; - bUseYYSetStateNaked = baseopt.bUseYYSetStateNaked; - bUseYYGetStateNaked = baseopt.bUseYYGetStateNaked; - bUseStateAbort = baseopt.bUseStateAbort; - topIndent = baseopt.topIndent; - indString = baseopt.indString; - labelPrefix = baseopt.labelPrefix; - condPrefix = baseopt.condPrefix; - condEnumPrefix = baseopt.condEnumPrefix; - condDivider = baseopt.condDivider; - condDividerParam = baseopt.condDividerParam; - condGoto = baseopt.condGoto; - condGotoParam = baseopt.condGotoParam; - yychConversion = baseopt.yychConversion; - yyFillLength = baseopt.yyFillLength; - yySetConditionParam = baseopt.yySetConditionParam; - yySetStateParam = baseopt.yySetStateParam; - mapCodeName = baseopt.mapCodeName; - input_api = baseopt.input_api; + dFlag = Opt::baseopt.dFlag; + fFlag = Opt::baseopt.fFlag; + iFlag = Opt::baseopt.iFlag; + tFlag = Opt::baseopt.tFlag; + header_file = Opt::baseopt.header_file; + bEmitYYCh = Opt::baseopt.bEmitYYCh; + bUseStateNext = Opt::baseopt.bUseStateNext; + bUseYYFill = Opt::baseopt.bUseYYFill; + bUseYYFillParam = Opt::baseopt.bUseYYFillParam; + bUseYYFillCheck = Opt::baseopt.bUseYYFillCheck; + bUseYYFillNaked = Opt::baseopt.bUseYYFillNaked; + bUseYYSetConditionParam = Opt::baseopt.bUseYYSetConditionParam; + bUseYYGetConditionNaked = Opt::baseopt.bUseYYGetConditionNaked; + bUseYYSetStateParam = Opt::baseopt.bUseYYSetStateParam; + bUseYYSetStateNaked = Opt::baseopt.bUseYYSetStateNaked; + bUseYYGetStateNaked = Opt::baseopt.bUseYYGetStateNaked; + bUseStateAbort = Opt::baseopt.bUseStateAbort; + topIndent = Opt::baseopt.topIndent; + indString = Opt::baseopt.indString; + labelPrefix = Opt::baseopt.labelPrefix; + condPrefix = Opt::baseopt.condPrefix; + condEnumPrefix = Opt::baseopt.condEnumPrefix; + condDivider = Opt::baseopt.condDivider; + condDividerParam = Opt::baseopt.condDividerParam; + condGoto = Opt::baseopt.condGoto; + condGotoParam = Opt::baseopt.condGotoParam; + yychConversion = Opt::baseopt.yychConversion; + yyFillLength = Opt::baseopt.yyFillLength; + yySetConditionParam = Opt::baseopt.yySetConditionParam; + yySetStateParam = Opt::baseopt.yySetStateParam; + mapCodeName = Opt::baseopt.mapCodeName; + input_api = Opt::baseopt.input_api; } if (bCaseInsensitive) { - bCaseInverted = baseopt.bCaseInverted; + bCaseInverted = Opt::baseopt.bCaseInverted; } if (!cFlag) { - tFlag = baseopt.tFlag; - header_file = baseopt.header_file; - bUseYYSetConditionParam = baseopt.bUseYYSetConditionParam; - bUseYYGetConditionNaked = baseopt.bUseYYGetConditionNaked; - condPrefix = baseopt.condPrefix; - condEnumPrefix = baseopt.condEnumPrefix; - condDivider = baseopt.condDivider; - condDividerParam = baseopt.condDividerParam; - condGoto = baseopt.condGoto; - condGotoParam = baseopt.condGotoParam; - yySetConditionParam = baseopt.yySetConditionParam; + tFlag = Opt::baseopt.tFlag; + header_file = Opt::baseopt.header_file; + bUseYYSetConditionParam = Opt::baseopt.bUseYYSetConditionParam; + bUseYYGetConditionNaked = Opt::baseopt.bUseYYGetConditionNaked; + condPrefix = Opt::baseopt.condPrefix; + condEnumPrefix = Opt::baseopt.condEnumPrefix; + condDivider = Opt::baseopt.condDivider; + condDividerParam = Opt::baseopt.condDividerParam; + condGoto = Opt::baseopt.condGoto; + condGotoParam = Opt::baseopt.condGotoParam; + yySetConditionParam = Opt::baseopt.yySetConditionParam; mapCodeName.erase ("YYCONDTYPE"); mapCodeName.erase ("YYGETCONDITION"); mapCodeName.erase ("YYSETCONDITION"); @@ -223,12 +226,12 @@ bool Opt::apply () } if (!fFlag) { - bUseStateNext = baseopt.bUseStateNext; - bUseYYSetStateParam = baseopt.bUseYYSetStateParam; - bUseYYSetStateNaked = baseopt.bUseYYSetStateNaked; - bUseYYGetStateNaked = baseopt.bUseYYGetStateNaked; - bUseStateAbort = baseopt.bUseStateAbort; - yySetStateParam = baseopt.yySetStateParam; + bUseStateNext = Opt::baseopt.bUseStateNext; + bUseYYSetStateParam = Opt::baseopt.bUseYYSetStateParam; + bUseYYSetStateNaked = Opt::baseopt.bUseYYSetStateNaked; + bUseYYGetStateNaked = Opt::baseopt.bUseYYGetStateNaked; + bUseStateAbort = Opt::baseopt.bUseStateAbort; + yySetStateParam = Opt::baseopt.yySetStateParam; mapCodeName.erase ("YYGETSTATE"); mapCodeName.erase ("YYSETSTATE"); mapCodeName.erase ("yyaccept"); @@ -237,12 +240,12 @@ bool Opt::apply () } if (!bFlag) { - yybmHexTable = baseopt.yybmHexTable; + yybmHexTable = Opt::baseopt.yybmHexTable; mapCodeName.erase ("yybm"); } if (!gFlag) { - cGotoThreshold = baseopt.cGotoThreshold; + cGotoThreshold = Opt::baseopt.cGotoThreshold; mapCodeName.erase ("yytarget"); } if (input_api.type () != InputAPI::DEFAULT) @@ -300,8 +303,19 @@ bool Opt::apply () bFlag = true; sFlag = true; } +} - return true; +const opt_t Opt::baseopt; + +bool Opt::check () +{ + return useropt.check (); +} + +void Opt::sync () +{ + realopt = useropt; + realopt.fix (); } void Opt::bit_vectors () @@ -466,4 +480,195 @@ bool Opt::utf_8 () return useropt.encoding.set(Enc::UTF8); } +bool Opt::sync_mapCodeName (const std::string & key, const std::string & val) +{ + if (!useropt.mapCodeName.insert (std::make_pair (key, val)).second) + { + return false; + } + sync (); + return true; +} + +void Opt::sync_condPrefix (const std::string & s) +{ + useropt.condPrefix = s; + sync (); +} + +void Opt::sync_condEnumPrefix (const std::string & s) +{ + useropt.condEnumPrefix = s; + sync (); +} + +void Opt::sync_condDivider (const std::string & s) +{ + useropt.condDivider = s; + sync (); +} + +void Opt::sync_condDividerParam (const std::string & s) +{ + useropt.condDividerParam = s; + sync (); +} + +void Opt::sync_condGoto (const std::string & s) +{ + useropt.condGoto = s; + sync (); +} + +void Opt::sync_condGotoParam (const std::string & s) +{ + useropt.condGotoParam = s; + sync (); +} + +void Opt::sync_cGotoThreshold (uint32_t n) +{ + useropt.cGotoThreshold = n; + sync (); +} + +void Opt::sync_bUseYYFillNaked (bool b) +{ + useropt.bUseYYFillNaked = b; + sync (); +} + +void Opt::sync_yyFillLength (const std::string & s) +{ + useropt.yyFillLength = s; + useropt.bUseYYFillParam = false; + sync (); +} + +void Opt::sync_bUseYYGetConditionNaked (bool b) +{ + useropt.bUseYYGetConditionNaked = b; + sync (); +} + +void Opt::sync_bUseYYGetStateNaked (bool b) +{ + useropt.bUseYYGetStateNaked = b; + sync (); +} + +void Opt::sync_yySetConditionParam (const std::string & s) +{ + useropt.yySetConditionParam = s; + useropt.bUseYYSetConditionParam = false; + sync (); +} + +void Opt::sync_bUseYYSetStateNaked (bool b) +{ + useropt.bUseYYSetStateNaked = b; + sync (); +} + +void Opt::sync_yySetStateParam (const std::string & s) +{ + useropt.yySetStateParam = s; + useropt.bUseYYSetStateParam = false; + sync (); +} + +bool Opt::sync_encoding (Enc::type_t t) +{ + if (!useropt.encoding.set (t)) + { + return false; + } + sync (); + return true; +} + +void Opt::sync_encoding_unset (Enc::type_t t) +{ + useropt.encoding.unset (t); + sync (); +} + +void Opt::sync_indString (const std::string & s) +{ + useropt.indString = s; + sync (); +} + +void Opt::sync_topIndent (uint32_t n) +{ + useropt.topIndent = n; + sync (); +} + +void Opt::sync_labelPrefix (const std::string & s) +{ + useropt.labelPrefix = s; + sync (); +} + +void Opt::sync_bUseStateAbort (bool b) +{ + useropt.bUseStateAbort = b; + sync (); +} + +void Opt::sync_bUseStateNext (bool b) +{ + useropt.bUseStateNext = b; + sync (); +} + +void Opt::sync_yybmHexTable (bool b) +{ + useropt.yybmHexTable = b; + sync (); +} + +void Opt::sync_yychConversion (bool b) +{ + useropt.yychConversion = b; + sync (); +} + +void Opt::sync_bEmitYYCh (bool b) +{ + useropt.bEmitYYCh = b; + sync (); +} + +void Opt::sync_bUseYYFillCheck (bool b) +{ + useropt.bUseYYFillCheck = b; + sync (); +} + +void Opt::sync_bUseYYFill (bool b) +{ + useropt.bUseYYFill = b; + sync (); +} + +void Opt::sync_bUseYYFillParam (bool b) +{ + useropt.bUseYYFillParam = b; + sync (); +} + +void Opt::sync_reset_encoding (const Enc & enc) +{ + useropt.encoding = enc; + sync (); +} + +void Opt::sync_reset_mapCodeName () +{ + useropt.mapCodeName.clear (); + sync (); +} + } // namespace re2c diff --git a/re2c/src/conf/opt.h b/re2c/src/conf/opt.h index 7aa8bbd9..b9182e25 100644 --- a/re2c/src/conf/opt.h +++ b/re2c/src/conf/opt.h @@ -28,6 +28,7 @@ struct opt_t bool flag_skeleton; bool bNoGenerationDate; bool bEmitYYCh; + bool yychConversion; bool bUseStateNext; bool bUseYYFill; bool bUseYYFillParam; @@ -52,7 +53,6 @@ struct opt_t std::string condDividerParam; std::string condGoto; std::string condGotoParam; - std::string yychConversion; std::string yyFillLength; std::string yySetConditionParam; std::string yySetStateParam; @@ -64,27 +64,31 @@ struct opt_t opt_t (); opt_t (const opt_t & opt); opt_t & operator = (const opt_t & opt); + bool check (); + void fix (); }; -struct Opt : public opt_t +struct Opt { + static const opt_t baseopt; + const char * source_file; const char * output_file; private: - const opt_t baseopt; opt_t useropt; + opt_t realopt; public: Opt () - : opt_t () - , source_file (NULL) + : source_file (NULL) , output_file (NULL) - , baseopt () , useropt () + , realopt () {} - bool apply (); + bool check (); + void sync (); void bit_vectors (); void start_conditions (); @@ -112,6 +116,95 @@ public: bool utf_16 (); bool utf_8 (); + // Inplace configurations are applied immediately when parsed. + // This is very bad: first, re2c behaviour is changed in the middle + // of the block; second, we have to re-sync config every time. + bool sync_mapCodeName (const std::string & key, const std::string & val); + bool sync_encoding (Enc::type_t t); + void sync_encoding_unset (Enc::type_t t); + void sync_condPrefix (const std::string & s); + void sync_condEnumPrefix (const std::string & s); + void sync_condDivider (const std::string & s); + void sync_condDividerParam (const std::string & s); + void sync_condGoto (const std::string & s); + void sync_condGotoParam (const std::string & s); + void sync_cGotoThreshold (uint32_t n); + void sync_bUseYYFillNaked (bool b); + void sync_yyFillLength (const std::string & s); + void sync_bUseYYGetConditionNaked (bool b); + void sync_bUseYYGetStateNaked (bool b); + void sync_yySetConditionParam (const std::string & s); + void sync_bUseYYSetStateNaked (bool b); + void sync_yySetStateParam (const std::string & s); + void sync_indString (const std::string & s); + void sync_topIndent (uint32_t n); + void sync_labelPrefix (const std::string & s); + void sync_bUseStateAbort (bool b); + void sync_bUseStateNext (bool b); + void sync_yybmHexTable (bool b); + void sync_yychConversion (bool b); + void sync_bEmitYYCh (bool b); + void sync_bUseYYFillCheck (bool b); + void sync_bUseYYFill (bool b); + void sync_bUseYYFillParam (bool b); + // bad temporary hacks + // should be fixed by proper scoping in config (parts). + void sync_reset_encoding (const Enc & enc); + void sync_reset_mapCodeName (); + + bool bFlag () const { return realopt.bFlag; } + bool cFlag () const { return realopt.cFlag; } + bool dFlag () const { return realopt.dFlag; } + bool DFlag () const { return realopt.DFlag; } + bool fFlag () const { return realopt.fFlag; } + bool FFlag () const { return realopt.FFlag; } + bool gFlag () const { return realopt.gFlag; } + bool iFlag () const { return realopt.iFlag; } + bool rFlag () const { return realopt.rFlag; } + bool sFlag () const { return realopt.sFlag; } + bool tFlag () const { return realopt.tFlag; } + const char * header_file () const { return realopt.header_file; } + bool flag_skeleton () const { return realopt.flag_skeleton; } + bool bNoGenerationDate () const { return realopt.bNoGenerationDate; } + bool bEmitYYCh () const { return realopt.bEmitYYCh; } + std::string yychConversion () const + { + return realopt.yychConversion + ? "(" + realopt.mapCodeName["YYCTYPE"] + ")" + : ""; + } + bool bUseStateNext () const { return realopt.bUseStateNext; } + bool bUseYYFill () const { return realopt.bUseYYFill; } + bool bUseYYFillParam () const { return realopt.bUseYYFillParam; } + bool bUseYYFillCheck () const { return realopt.bUseYYFillCheck; } + bool bUseYYFillNaked () const { return realopt.bUseYYFillNaked; } + bool bUseYYSetConditionParam () const { return realopt.bUseYYSetConditionParam; } + bool bUseYYGetConditionNaked () const { return realopt.bUseYYGetConditionNaked; } + bool bUseYYSetStateParam () const { return realopt.bUseYYSetStateParam; } + bool bUseYYSetStateNaked () const { return realopt.bUseYYSetStateNaked; } + bool bUseYYGetStateNaked () const { return realopt.bUseYYGetStateNaked; } + bool yybmHexTable () const { return realopt.yybmHexTable; } + bool bUseStateAbort () const { return realopt.bUseStateAbort; } + bool bCaseInsensitive () const { return realopt.bCaseInsensitive; } + bool bCaseInverted () const { return realopt.bCaseInverted; } + uint32_t cGotoThreshold () const { return realopt.cGotoThreshold; } + uint32_t topIndent () const { return realopt.topIndent; } + const std::string & indString () const { return realopt.indString; } + const std::string & labelPrefix () const { return realopt.labelPrefix; } + const std::string & condPrefix () const { return realopt.condPrefix; } + const std::string & condEnumPrefix () const { return realopt.condEnumPrefix; } + const std::string & condDivider () const { return realopt.condDivider; } + const std::string & condDividerParam () const { return realopt.condDividerParam; } + const std::string & condGoto () const { return realopt.condGoto; } + const std::string & condGotoParam () const { return realopt.condGotoParam; } + const std::string & yyFillLength () const { return realopt.yyFillLength; } + const std::string & yySetConditionParam () const { return realopt.yySetConditionParam; } + const std::string & yySetStateParam () const { return realopt.yySetStateParam; } + const CodeNames & mapCodeName () const { return realopt.mapCodeName; } + const Enc & encoding () const { return realopt.encoding; } + const InputAPI & input_api () const { return realopt.input_api; } + empty_class_policy_t empty_class_policy () const { return realopt.empty_class_policy; } + FORBID_COPY (Opt); }; diff --git a/re2c/src/conf/parse_opts.re b/re2c/src/conf/parse_opts.re index c1f20231..60a5b4ef 100644 --- a/re2c/src/conf/parse_opts.re +++ b/re2c/src/conf/parse_opts.re @@ -225,10 +225,11 @@ opt_empty_class: */ end: - if (!opts.apply ()) + if (!opts.check ()) { return EXIT_FAIL; } + opts.sync (); if (!opts.source_file) { diff --git a/re2c/src/ir/regexp/regexp.cc b/re2c/src/ir/regexp/regexp.cc index 08e50815..a71bb13c 100644 --- a/re2c/src/ir/regexp/regexp.cc +++ b/re2c/src/ir/regexp/regexp.cc @@ -112,10 +112,10 @@ RegExp * doCat (RegExp * e1, RegExp * e2) RegExp * Scanner::matchSymbol(uint32_t c) const { - if (!opts.encoding.encode(c)) + if (!opts.encoding ().encode(c)) fatalf("Bad code point: '0x%X'", c); - switch (opts.encoding.type ()) + switch (opts.encoding ().type ()) { case Enc::UTF16: return UTF16Symbol(c); case Enc::UTF8: return UTF8Symbol(c); @@ -127,7 +127,7 @@ RegExp * Scanner::matchSymbolRange(Range * r) const { if (!r) { - switch (opts.empty_class_policy) + switch (opts.empty_class_policy ()) { case EMPTY_CLASS_MATCH_EMPTY: warn.empty_class (get_line ()); @@ -141,7 +141,7 @@ RegExp * Scanner::matchSymbolRange(Range * r) const } } - switch (opts.encoding.type ()) + switch (opts.encoding ().type ()) { case Enc::UTF16: return UTF16Range(r); case Enc::UTF8: return UTF8Range(r); @@ -185,7 +185,7 @@ RegExp * Scanner::cpoint_class (const std::vector & cs, bool neg) cons warn.swapped_range (get_line (), l, u); std::swap (l, u); } - Range * s = opts.encoding.encodeRange (l, u); + Range * s = opts.encoding ().encodeRange (l, u); if (!s) { fatalf ("Bad code point range: '0x%X - 0x%X'", l, u); @@ -194,7 +194,7 @@ RegExp * Scanner::cpoint_class (const std::vector & cs, bool neg) cons } if (neg) { - r = Range::sub (opts.encoding.fullRange (), r); + r = Range::sub (opts.encoding ().fullRange (), r); } return matchSymbolRange (r); } @@ -233,9 +233,9 @@ RegExp * Scanner::mkDiff (RegExp * e1, RegExp * e2) const RegExp * Scanner::mkDot() const { - Range * full = opts.encoding.fullRange(); + Range * full = opts.encoding ().fullRange(); uint32_t c = '\n'; - if (!opts.encoding.encode(c)) + if (!opts.encoding ().encode(c)) fatalf("Bad code point: '0x%X'", c); Range * ran = Range::sym (c); Range * inv = Range::sub (full, ran); @@ -255,7 +255,7 @@ RegExp * Scanner::mkDot() const */ RegExp * Scanner::mkDefault() const { - Range * def = Range::ran (0, opts.encoding.nCodeUnits()); + Range * def = Range::ran (0, opts.encoding ().nCodeUnits()); return new MatchOp(def); } diff --git a/re2c/src/main.cc b/re2c/src/main.cc index ea934da3..5606fd33 100644 --- a/re2c/src/main.cc +++ b/re2c/src/main.cc @@ -35,15 +35,15 @@ int main(int, char *argv[]) } // set up the output streams - re2c::Output output (opts.output_file, opts.header_file); + re2c::Output output (opts.output_file, opts.header_file ()); if (!output.source.open ()) { error ("cannot open output file: %s", opts.output_file); return 1; } - if (opts.tFlag && !output.header.open ()) + if (opts.tFlag () && !output.header.open ()) { - error ("cannot open header file: %s", opts.header_file); + error ("cannot open header file: %s", opts.header_file ()); return 1; } diff --git a/re2c/src/parse/parser.ypp b/re2c/src/parse/parser.ypp index 34297b0d..94bc39f7 100644 --- a/re2c/src/parse/parser.ypp +++ b/re2c/src/parse/parser.ypp @@ -55,7 +55,7 @@ static symbol_table_t symbol_table; void context_check(CondList *clist) { - if (!opts.cFlag) + if (!opts.cFlag ()) { delete clist; in->fatal("conditions are only allowed when using -c switch"); @@ -277,7 +277,7 @@ decl: } | CONF STRING ';' { - if (!opts.mapCodeName.insert (std::make_pair (*$1, *$2)).second) + if (!opts.sync_mapCodeName (*$1, *$2)) { in->fatalf ("configuration '%s' is already set and cannot be changed", $1->c_str ()); } @@ -286,32 +286,32 @@ decl: } | CONF_CONDPREFIX STRING ';' { - opts.condPrefix = *$2; + opts.sync_condPrefix (*$2); delete $2; } | CONF_CONDENUMPREFIX STRING ';' { - opts.condEnumPrefix = *$2; + opts.sync_condEnumPrefix (*$2); delete $2; } | CONF_COND_DIVIDER STRING ';' { - opts.condDivider = *$2; + opts.sync_condDivider (*$2); delete $2; } | CONF_COND_DIVIDER_COND STRING ';' { - opts.condDividerParam = *$2; + opts.sync_condDividerParam (*$2); delete $2; } | CONF_COND_GOTO STRING ';' { - opts.condGoto = *$2; + opts.sync_condGoto (*$2); delete $2; } | CONF_COND_GOTO_COND STRING ';' { - opts.condGotoParam = *$2; + opts.sync_condGotoParam (*$2); delete $2; } | CONF_CGOTO_THRESHOLD NUM ';' @@ -320,58 +320,55 @@ decl: { in->fatal ("configuration 'cgoto:threshold' must be nonnegative"); } - opts.cGotoThreshold = static_cast ($2); + opts.sync_cGotoThreshold (static_cast ($2)); } | CONF_DEFINE_YYFILL_NAKED NUM ';' { - opts.bUseYYFillNaked = $2 != 0; + opts.sync_bUseYYFillNaked ($2 != 0); } | CONF_DEFINE_YYFILL_LEN STRING ';' { - opts.yyFillLength = *$2; - opts.bUseYYFillParam = false; + opts.sync_yyFillLength (*$2); delete $2; } | CONF_DEFINE_YYGETCONDITION_NAKED NUM ';' { - opts.bUseYYGetConditionNaked = $2 != 0; + opts.sync_bUseYYGetConditionNaked ($2 != 0); } | CONF_DEFINE_YYGETSTATE_NAKED NUM ';' { - opts.bUseYYGetStateNaked = $2 != 0; + opts.sync_bUseYYGetStateNaked ($2 != 0); } | CONF_DEFINE_YYSETCONDITION_COND STRING ';' { - opts.yySetConditionParam = *$2; - opts.bUseYYSetConditionParam = false; + opts.sync_yySetConditionParam (*$2); delete $2; } | CONF_DEFINE_YYSETSTATE_NAKED NUM ';' { - opts.bUseYYSetStateNaked = $2 != 0; + opts.sync_bUseYYSetStateNaked ($2 != 0); } | CONF_DEFINE_YYSETSTATE_STATE STRING ';' { - opts.yySetStateParam = *$2; - opts.bUseYYSetStateParam = false; + opts.sync_yySetStateParam (*$2); delete $2; } | CONF_FLAGS NUM ';' { if ($2 == 0) { - opts.encoding.unset ($1); + opts.sync_encoding_unset ($1); } - else if (!opts.encoding.set ($1)) + else if (!opts.sync_encoding ($1)) { in->fatalf ("Cannot set %s encoding: please reset %s encoding first" , Enc::name ($1) - , Enc::name (opts.encoding.type ())); + , Enc::name (opts.encoding ().type ())); } } | CONF_INDENT_STRING STRING ';' { - opts.indString = *$2; + opts.sync_indString (*$2); delete $2; } | CONF_INDENT_TOP NUM ';' @@ -380,11 +377,11 @@ decl: { in->fatal ("configuration 'indent:top' must be nonnegative"); } - opts.topIndent = static_cast ($2); + opts.sync_topIndent (static_cast ($2)); } | CONF_LABELPREFIX STRING ';' { - opts.labelPrefix = *$2; + opts.sync_labelPrefix (*$2); delete $2; } | CONF_STARTLABEL NUM ';' @@ -398,44 +395,42 @@ decl: } | CONF_STATE_ABORT NUM ';' { - opts.bUseStateAbort = $2 != 0; + opts.sync_bUseStateAbort ($2 != 0); } | CONF_STATE_NEXTLABEL NUM ';' { - opts.bUseStateNext = $2 != 0; + opts.sync_bUseStateNext ($2 != 0); } | CONF_YYBM_HEX NUM ';' { - opts.yybmHexTable = $2 != 0; + opts.sync_yybmHexTable ($2 != 0); } | CONF_YYCH_CONVERSION NUM ';' { - opts.yychConversion = $2 == 0 - ? "" - : "(" + opts.mapCodeName["YYCTYPE"] + ")"; + opts.sync_yychConversion ($2 != 0); } | CONF_YYCH_EMIT NUM ';' { - opts.bEmitYYCh = $2 != 0; + opts.sync_bEmitYYCh ($2 != 0); } | CONF_YYFILL_CHECK NUM ';' { - opts.bUseYYFillCheck = $2 != 0; + opts.sync_bUseYYFillCheck ($2 != 0); } | CONF_YYFILL_ENABLE NUM ';' { - opts.bUseYYFill = $2 != 0; + opts.sync_bUseYYFill ($2 != 0); } | CONF_YYFILL_PARAMETER NUM ';' { - opts.bUseYYFillParam = $2 != 0; + opts.sync_bUseYYFillParam ($2 != 0); } ; rule: expr look CODE { - if (opts.cFlag) + if (opts.cFlag ()) { in->fatal("condition or '<*>' required when using -c switch"); } @@ -452,7 +447,7 @@ rule: } | STAR CODE /* default rule */ { - if (opts.cFlag) + if (opts.cFlag ()) in->fatal("condition or '<*>' required when using -c switch"); if (ruleDefault != NULL) in->fatal("code to default rule is already defined"); @@ -768,12 +763,12 @@ void parse(Scanner& i, Output & o) o.source.write_version_time (); o.source.write_line_info (in->get_cline (), in->get_fname ().c_str ()); - if (opts.flag_skeleton) + if (opts.flag_skeleton ()) { Skeleton::emit_prolog (o.source); } - Enc encodingOld = opts.encoding; + Enc encodingOld = opts.encoding (); while ((parseMode = i.echo()) != Scanner::Stop) { @@ -784,7 +779,7 @@ void parse(Scanner& i, Output & o) i.save_state(curr_state); foundRules = false; - if (opts.rFlag && parseMode == Scanner::Rules && dfa_map.size()) + if (opts.rFlag () && parseMode == Scanner::Rules && dfa_map.size()) { in->fatal("cannot have a second 'rules:re2c' block"); } @@ -809,9 +804,9 @@ void parse(Scanner& i, Output & o) in->set_in_parse(true); yyparse(); in->set_in_parse(false); - if (opts.rFlag && parseMode == Scanner::Reuse) + if (opts.rFlag () && parseMode == Scanner::Reuse) { - if (foundRules || opts.encoding != encodingOld) + if (foundRules || opts.encoding () != encodingOld) { // Re-parse rules parseMode = Scanner::Parse; @@ -833,10 +828,11 @@ void parse(Scanner& i, Output & o) yyparse(); in->set_in_parse(false); } - encodingOld = opts.encoding; + encodingOld = opts.encoding (); } o.source.set_block_line (in->get_cline ()); - if (opts.cFlag) + uint32_t ind = opts.topIndent (); + if (opts.cFlag ()) { RegExpMap::iterator it; SetupMap::const_iterator itRuleSetup; @@ -918,11 +914,11 @@ void parse(Scanner& i, Output & o) it->second = it->second ? mkAlt (def_rule, it->second) : def_rule; } - dfa_map[it->first] = genCode(it->second, o, it->first, opts.encoding.nCodeUnits ()); + dfa_map[it->first] = genCode(it->second, o, it->first, opts.encoding ().nCodeUnits ()); } if (parseMode != Scanner::Rules && dfa_map.find(it->first) != dfa_map.end()) { - dfa_map[it->first]->emit(o, opts.topIndent, !--nCount, bPrologBrace); + dfa_map[it->first]->emit(o, ind, !--nCount, bPrologBrace); } } } @@ -945,20 +941,20 @@ void parse(Scanner& i, Output & o) { if (parseMode != Scanner::Reuse) { - dfa_map[""] = genCode(spec, o, "", opts.encoding.nCodeUnits ()); + dfa_map[""] = genCode(spec, o, "", opts.encoding ().nCodeUnits ()); } if (parseMode != Scanner::Rules && dfa_map.find("") != dfa_map.end()) { - dfa_map[""]->emit(o, opts.topIndent, 0, bPrologBrace); + dfa_map[""]->emit(o, ind, 0, bPrologBrace); } } } o.source.write_line_info (in->get_cline (), in->get_fname ().c_str ()); /* restore original char handling mode*/ - opts.encoding = encodingOld; + opts.sync_reset_encoding (encodingOld); } - if (opts.cFlag) + if (opts.cFlag ()) { SetupMap::const_iterator itRuleSetup; for (itRuleSetup = ruleSetupMap.begin(); itRuleSetup != ruleSetupMap.end(); ++itRuleSetup) @@ -980,7 +976,7 @@ void parse(Scanner& i, Output & o) } } - if (opts.flag_skeleton) + if (opts.flag_skeleton ()) { Skeleton::emit_epilog (o.source, o.names); } diff --git a/re2c/src/parse/scanner.cc b/re2c/src/parse/scanner.cc index f8f1725d..7edd990b 100644 --- a/re2c/src/parse/scanner.cc +++ b/re2c/src/parse/scanner.cc @@ -66,7 +66,7 @@ void Scanner::fill (uint32_t need) { /* Do not get rid of anything when rFlag is active. Otherwise * get rid of everything that was already handedout. */ - if (!opts.rFlag) + if (!opts.rFlag ()) { const ptrdiff_t diff = tok - bot; if (diff > 0) @@ -178,7 +178,7 @@ void Scanner::reuse() last_fill_index = 0; bWroteGetState = false; bWroteCondCheck = false; - opts.mapCodeName.clear(); + opts.sync_reset_mapCodeName (); } void Scanner::restore_state(const ScannerState& state) diff --git a/re2c/src/parse/scanner_lex.re b/re2c/src/parse/scanner_lex.re index d785284f..c72decc4 100644 --- a/re2c/src/parse/scanner_lex.re +++ b/re2c/src/parse/scanner_lex.re @@ -70,11 +70,11 @@ echo: /*!re2c beginRE = "%{" | "/*!re2c"; beginRE { - if (opts.rFlag) + if (opts.rFlag ()) { fatal("found standard 're2c' block while using -r flag"); } - if (!(opts.DFlag || opts.flag_skeleton)) + if (!(opts.DFlag () || opts.flag_skeleton ())) { const size_t lexeme_len = cur[-1] == '{' ? sizeof ("%{") - 1 @@ -85,9 +85,9 @@ echo: return Parse; } "/*!rules:re2c" { - if (opts.rFlag) + if (opts.rFlag ()) { - opts.mapCodeName.clear(); + opts.sync_reset_mapCodeName (); } else { @@ -97,12 +97,12 @@ echo: return Rules; } "/*!use:re2c" { - if (!opts.rFlag) + if (!opts.rFlag ()) { fatal("found 'use:re2c' block without -r flag"); } reuse(); - if (!(opts.DFlag || opts.flag_skeleton)) + if (!(opts.DFlag () || opts.flag_skeleton ())) { const size_t lexeme_len = sizeof ("/*!use:re2c") - 1; out.write(tok, tok_len () - lexeme_len); @@ -111,7 +111,7 @@ echo: return Reuse; } "/*!max:re2c" { - if (!opts.DFlag) + if (!opts.DFlag ()) { out.insert_yymaxfill (); } @@ -121,7 +121,7 @@ echo: } "/*!getstate:re2c" { tok = pos = cur; - out.insert_state_goto (opts.topIndent); + out.insert_state_goto (opts.topIndent ()); ignore_eoc = true; goto echo; } @@ -133,7 +133,7 @@ echo: "/*!types:re2c" { tok = pos = cur; ignore_eoc = true; - if (!opts.DFlag) + if (!opts.DFlag ()) { out.insert_line_info (); out << "\n"; @@ -154,7 +154,7 @@ echo: ignore_eoc = false; ignore_cnt = 0; } - else if (!(opts.DFlag || opts.flag_skeleton)) + else if (!(opts.DFlag () || opts.flag_skeleton ())) { out.write(tok, tok_len ()); } @@ -172,7 +172,7 @@ echo: ignore_eoc = false; ignore_cnt = 0; } - else if (!(opts.DFlag || opts.flag_skeleton)) + else if (!(opts.DFlag () || opts.flag_skeleton ())) { out.write(tok, tok_len ()); } @@ -188,7 +188,7 @@ echo: { ignore_cnt++; } - else if (!(opts.DFlag || opts.flag_skeleton)) + else if (!(opts.DFlag () || opts.flag_skeleton ())) { out.write(tok, tok_len ()); } @@ -197,7 +197,7 @@ echo: goto echo; } zero { - if (!(ignore_eoc || opts.DFlag || opts.flag_skeleton)) + if (!(ignore_eoc || opts.DFlag () || opts.flag_skeleton ())) { out.write(tok, tok_len () - 1); // -1 so we don't write out the \0 @@ -263,14 +263,14 @@ start: { std::vector cpoints; lex_cpoints ('\'', cpoints); - yylval.regexp = cpoint_string (cpoints, opts.bCaseInsensitive || !opts.bCaseInverted); + yylval.regexp = cpoint_string (cpoints, opts.bCaseInsensitive () || !opts.bCaseInverted ()); return REGEXP; } "\"" { std::vector cpoints; lex_cpoints ('"', cpoints); - yylval.regexp = cpoint_string (cpoints, opts.bCaseInsensitive || opts.bCaseInverted); + yylval.regexp = cpoint_string (cpoints, opts.bCaseInsensitive () || opts.bCaseInverted ()); return REGEXP; } "[" @@ -343,7 +343,7 @@ start: } "{" name "}" { - if (!opts.FFlag) { + if (!opts.FFlag ()) { fatal("curly braces for names only allowed with -F switch"); } yylval.str = new std::string (tok + 1, tok_len () - 2); // -2 to omit braces @@ -354,7 +354,7 @@ start: name / (space+ [^=>,]) { yylval.str = new std::string (tok, tok_len ()); - if (opts.FFlag) + if (opts.FFlag ()) { lexer_state = LEX_FLEX_NAME; return FID; @@ -371,7 +371,7 @@ start: } name / [^] { - if (!opts.FFlag) { + if (!opts.FFlag ()) { yylval.str = new std::string (tok, tok_len ()); return ID; } else { @@ -380,7 +380,7 @@ start: { cpoints.push_back (static_cast (*p)); } - yylval.regexp = cpoint_string (cpoints, opts.bCaseInsensitive || opts.bCaseInverted); + yylval.regexp = cpoint_string (cpoints, opts.bCaseInsensitive () || opts.bCaseInverted ()); return REGEXP; } }