From bedb784318da8f77fba482ea51ac9a6f42121900 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Fri, 27 Nov 2015 14:29:16 +0000 Subject: [PATCH] Allowed chaining for all 'OutputFile' methods; renamed them in a uniform way. --- re2c/bootstrap/src/parse/lex.cc | 445 ++++++++++++++--------------- re2c/bootstrap/src/parse/parser.cc | 6 +- re2c/src/codegen/bitmap.cc | 4 +- re2c/src/codegen/emit_action.cc | 6 +- re2c/src/codegen/emit_dfa.cc | 11 +- re2c/src/codegen/go_emit.cc | 12 +- re2c/src/codegen/output.cc | 42 ++- re2c/src/codegen/output.h | 30 +- re2c/src/parse/lex.re | 29 +- re2c/src/parse/parser.ypp | 6 +- 10 files changed, 298 insertions(+), 293 deletions(-) diff --git a/re2c/bootstrap/src/parse/lex.cc b/re2c/bootstrap/src/parse/lex.cc index 2bf00301..f62533f2 100644 --- a/re2c/bootstrap/src/parse/lex.cc +++ b/re2c/bootstrap/src/parse/lex.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.15.2 on Fri Nov 27 13:55:12 2015*/ +/* Generated by re2c 0.15.2 on Fri Nov 27 14:24:13 2015*/ #line 1 "../src/parse/lex.re" #include #include @@ -107,11 +107,11 @@ echo: } } ++YYCURSOR; -#line 196 "../src/parse/lex.re" +#line 193 "../src/parse/lex.re" { if (!ignore_eoc && opts->target == opt_t::CODE) { - out.write(tok, tok_len () - 1); + out.wraw(tok, tok_len () - 1); // -1 so we don't write out the \0 } if(cur == eof) @@ -123,7 +123,7 @@ echo: yy4: ++YYCURSOR; yy5: -#line 207 "../src/parse/lex.re" +#line 204 "../src/parse/lex.re" { goto echo; } @@ -136,7 +136,7 @@ yy6: } if (yych == '#') goto yy91; yy7: -#line 183 "../src/parse/lex.re" +#line 180 "../src/parse/lex.re" { if (ignore_eoc) { @@ -144,7 +144,7 @@ yy7: } else if (opts->target == opt_t::CODE) { - out.write(tok, tok_len ()); + out.wraw(tok, tok_len ()); } tok = pos = cur; cline++; @@ -264,7 +264,7 @@ yy32: const size_t lexeme_len = cur[-1] == '{' ? sizeof ("%{") - 1 : sizeof ("/*!re2c") - 1; - out.write(tok, tok_len () - lexeme_len); + out.wraw(tok, tok_len () - lexeme_len); } tok = cur; return Parse; @@ -294,7 +294,7 @@ yy34: if (opts->target == opt_t::CODE) { const size_t lexeme_len = sizeof ("/*!use:re2c") - 1; - out.write(tok, tok_len () - lexeme_len); + out.wraw(tok, tok_len () - lexeme_len); } tok = cur; return Reuse; @@ -318,7 +318,7 @@ yy42: { if (opts->target != opt_t::DOT) { - out.insert_yymaxfill (); + out.wdelay_yymaxfill (); } tok = pos = cur; ignore_eoc = true; @@ -352,7 +352,7 @@ yy50: #line 119 "../src/parse/lex.re" { tok = pos = cur; - out.insert_state_goto (opts->topIndent); + out.wdelay_state_goto (opts->topIndent); ignore_eoc = true; goto echo; } @@ -408,66 +408,63 @@ yy74: ignore_eoc = true; if (opts->target != opt_t::DOT) { - out.insert_line_info (); - out.ws("\n"); - out.insert_types (); - out.ws("\n"); - out.write_line_info (cline, get_fname ().c_str ()); + out.wdelay_line_info ().ws("\n") + .wdelay_types ().ws("\n") + .wline_info (cline, get_fname ().c_str ()); } goto echo; } -#line 420 "src/parse/lex.cc" +#line 418 "src/parse/lex.cc" yy84: yyaccept = 2; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); if (yych == '\n') goto yy87; if (yych == '\r') goto yy86; yy85: -#line 161 "../src/parse/lex.re" +#line 159 "../src/parse/lex.re" { if (ignore_eoc) { if (ignore_cnt) { - out.ws("\n"); - out.write_line_info (cline, get_fname ().c_str ()); + out.ws("\n").wline_info (cline, get_fname ().c_str ()); } ignore_eoc = false; ignore_cnt = 0; } else if (opts->target == opt_t::CODE) { - out.write(tok, tok_len ()); + out.wraw(tok, tok_len ()); } tok = pos = cur; goto echo; } -#line 446 "src/parse/lex.cc" +#line 443 "src/parse/lex.cc" yy86: yych = (YYCTYPE)*++YYCURSOR; if (yych != '\n') goto yy12; yy87: ++YYCURSOR; -#line 143 "../src/parse/lex.re" +#line 141 "../src/parse/lex.re" { cline++; if (ignore_eoc) { if (ignore_cnt) { - out.write_line_info (cline, get_fname ().c_str ()); + out.wline_info (cline, get_fname ().c_str ()); } ignore_eoc = false; ignore_cnt = 0; } else if (opts->target == opt_t::CODE) { - out.write(tok, tok_len ()); + out.wraw(tok, tok_len ()); } tok = pos = cur; goto echo; } -#line 471 "src/parse/lex.cc" +#line 468 "src/parse/lex.cc" yy89: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -542,12 +539,12 @@ yy101: yy103: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 179 "../src/parse/lex.re" +#line 176 "../src/parse/lex.re" { set_sourceline (); goto echo; } -#line 551 "src/parse/lex.cc" +#line 548 "src/parse/lex.cc" yy105: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy103; @@ -572,7 +569,7 @@ yy109: if (yych == '\r') goto yy105; goto yy12; } -#line 210 "../src/parse/lex.re" +#line 207 "../src/parse/lex.re" } @@ -592,7 +589,7 @@ scan: start: -#line 596 "src/parse/lex.cc" +#line 593 "src/parse/lex.cc" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -707,22 +704,22 @@ start: yy112: ++YYCURSOR; yy113: -#line 382 "../src/parse/lex.re" +#line 379 "../src/parse/lex.re" { fatalf("unexpected character: '%c'", *tok); goto scan; } -#line 716 "src/parse/lex.cc" +#line 713 "src/parse/lex.cc" yy114: ++YYCURSOR; yych = (YYCTYPE)*YYCURSOR; goto yy220; yy115: -#line 366 "../src/parse/lex.re" +#line 363 "../src/parse/lex.re" { goto scan; } -#line 726 "src/parse/lex.cc" +#line 723 "src/parse/lex.cc" yy116: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -733,65 +730,65 @@ yy116: if (yych == '#') goto yy200; } yy117: -#line 375 "../src/parse/lex.re" +#line 372 "../src/parse/lex.re" { if (cur == eof) return 0; pos = cur; cline++; goto scan; } -#line 744 "src/parse/lex.cc" +#line 741 "src/parse/lex.cc" yy118: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy197; goto yy113; yy119: ++YYCURSOR; -#line 259 "../src/parse/lex.re" +#line 256 "../src/parse/lex.re" { yylval.regexp = lex_str('"', opts->bCaseInsensitive || opts->bCaseInverted); return REGEXP; } -#line 753 "src/parse/lex.cc" +#line 750 "src/parse/lex.cc" yy121: yych = (YYCTYPE)*++YYCURSOR; if (yych == '}') goto yy195; goto yy113; yy122: ++YYCURSOR; -#line 258 "../src/parse/lex.re" +#line 255 "../src/parse/lex.re" { yylval.regexp = lex_str('\'', opts->bCaseInsensitive || !opts->bCaseInverted); return REGEXP; } -#line 762 "src/parse/lex.cc" +#line 759 "src/parse/lex.cc" yy124: ++YYCURSOR; yy125: -#line 269 "../src/parse/lex.re" +#line 266 "../src/parse/lex.re" { return *tok; } -#line 770 "src/parse/lex.cc" +#line 767 "src/parse/lex.cc" yy126: ++YYCURSOR; if ((yych = (YYCTYPE)*YYCURSOR) == '/') goto yy195; -#line 273 "../src/parse/lex.re" +#line 270 "../src/parse/lex.re" { yylval.op = *tok; return STAR; } -#line 779 "src/parse/lex.cc" +#line 776 "src/parse/lex.cc" yy128: ++YYCURSOR; -#line 277 "../src/parse/lex.re" +#line 274 "../src/parse/lex.re" { yylval.op = *tok; return CLOSE; } -#line 787 "src/parse/lex.cc" +#line 784 "src/parse/lex.cc" yy130: ++YYCURSOR; -#line 361 "../src/parse/lex.re" +#line 358 "../src/parse/lex.re" { yylval.regexp = mkDot(); return REGEXP; } -#line 795 "src/parse/lex.cc" +#line 792 "src/parse/lex.cc" yy132: yych = (YYCTYPE)*++YYCURSOR; if (yych == '*') goto yy191; @@ -815,9 +812,9 @@ yy135: yy136: ++YYCURSOR; if ((yych = (YYCTYPE)*YYCURSOR) == '^') goto yy176; -#line 260 "../src/parse/lex.re" +#line 257 "../src/parse/lex.re" { yylval.regexp = lex_cls(false); return REGEXP; } -#line 821 "src/parse/lex.cc" +#line 818 "src/parse/lex.cc" yy138: yych = (YYCTYPE)*++YYCURSOR; YYCTXMARKER = YYCURSOR; @@ -841,12 +838,12 @@ yy139: } } yy140: -#line 229 "../src/parse/lex.re" +#line 226 "../src/parse/lex.re" { depth = 1; goto code; } -#line 850 "src/parse/lex.cc" +#line 847 "src/parse/lex.cc" yy141: ++YYCURSOR; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); @@ -895,14 +892,14 @@ yy144: yy146: ++YYCURSOR; yy147: -#line 313 "../src/parse/lex.re" +#line 310 "../src/parse/lex.re" { fatal("illegal closure form, use '{n}', '{n,}', '{n,m}' where n and m are numbers"); } -#line 903 "src/parse/lex.cc" +#line 900 "src/parse/lex.cc" yy148: ++YYCURSOR; -#line 317 "../src/parse/lex.re" +#line 314 "../src/parse/lex.re" { if (!opts->FFlag) { fatal("curly braces for names only allowed with -F switch"); @@ -910,10 +907,10 @@ yy148: yylval.str = new std::string (tok + 1, tok_len () - 2); // -2 to omit braces return ID; } -#line 914 "src/parse/lex.cc" +#line 911 "src/parse/lex.cc" yy150: ++YYCURSOR; -#line 282 "../src/parse/lex.re" +#line 279 "../src/parse/lex.re" { if (!s_to_u32_unsafe (tok + 1, cur - 1, yylval.extop.min)) { @@ -922,7 +919,7 @@ yy150: yylval.extop.max = yylval.extop.min; return CLOSESIZE; } -#line 926 "src/parse/lex.cc" +#line 923 "src/parse/lex.cc" yy152: yyaccept = 3; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -930,7 +927,7 @@ yy152: if (yych <= '9') goto yy155; if (yych != '}') goto yy147; ++YYCURSOR; -#line 304 "../src/parse/lex.re" +#line 301 "../src/parse/lex.re" { if (!s_to_u32_unsafe (tok + 1, cur - 2, yylval.extop.min)) { @@ -939,7 +936,7 @@ yy152: yylval.extop.max = UINT32_MAX; return CLOSESIZE; } -#line 943 "src/parse/lex.cc" +#line 940 "src/parse/lex.cc" yy155: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -948,7 +945,7 @@ yy155: if (yych <= '9') goto yy155; if (yych != '}') goto yy143; ++YYCURSOR; -#line 291 "../src/parse/lex.re" +#line 288 "../src/parse/lex.re" { const char * p = strchr (tok, ','); if (!s_to_u32_unsafe (tok + 1, p, yylval.extop.min)) @@ -961,11 +958,11 @@ yy155: } return CLOSESIZE; } -#line 965 "src/parse/lex.cc" +#line 962 "src/parse/lex.cc" yy159: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 345 "../src/parse/lex.re" +#line 342 "../src/parse/lex.re" { if (!opts->FFlag) { yylval.str = new std::string (tok, tok_len()); @@ -981,7 +978,7 @@ yy159: return REGEXP; } } -#line 985 "src/parse/lex.cc" +#line 982 "src/parse/lex.cc" yy161: yych = (YYCTYPE)*++YYCURSOR; goto yy174; @@ -989,12 +986,12 @@ yy162: ++YYCURSOR; yy163: YYCURSOR = YYCTXMARKER; -#line 340 "../src/parse/lex.re" +#line 337 "../src/parse/lex.re" { yylval.str = new std::string (tok, tok_len ()); return ID; } -#line 998 "src/parse/lex.cc" +#line 995 "src/parse/lex.cc" yy164: ++YYCURSOR; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); @@ -1039,13 +1036,13 @@ yy166: YYCTXMARKER = YYCURSOR; if (yych != ':') goto yy165; ++YYCURSOR; -#line 325 "../src/parse/lex.re" +#line 322 "../src/parse/lex.re" { lex_conf (); return CONF; } -#line 1045 "src/parse/lex.cc" +#line 1042 "src/parse/lex.cc" yy171: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 327 "../src/parse/lex.re" +#line 324 "../src/parse/lex.re" { yylval.str = new std::string (tok, tok_len ()); if (opts->FFlag) @@ -1058,7 +1055,7 @@ yy171: return ID; } } -#line 1062 "src/parse/lex.cc" +#line 1059 "src/parse/lex.cc" yy173: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1075,16 +1072,16 @@ yy175: goto yy163; yy176: ++YYCURSOR; -#line 261 "../src/parse/lex.re" +#line 258 "../src/parse/lex.re" { yylval.regexp = lex_cls(true); return REGEXP; } -#line 1081 "src/parse/lex.cc" +#line 1078 "src/parse/lex.cc" yy178: ++YYCURSOR; -#line 266 "../src/parse/lex.re" +#line 263 "../src/parse/lex.re" { return SETUP; } -#line 1088 "src/parse/lex.cc" +#line 1085 "src/parse/lex.cc" yy180: yych = (YYCTYPE)*++YYCURSOR; YYCTXMARKER = YYCURSOR; @@ -1114,11 +1111,11 @@ yy182: yy183: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 263 "../src/parse/lex.re" +#line 260 "../src/parse/lex.re" { return NOCOND; } -#line 1122 "src/parse/lex.cc" +#line 1119 "src/parse/lex.cc" yy185: yych = (YYCTYPE)*++YYCURSOR; if (yych == '>') goto yy183; @@ -1130,44 +1127,44 @@ yy186: yy187: ++YYCURSOR; if ((yych = (YYCTYPE)*YYCURSOR) == '>') goto yy189; -#line 238 "../src/parse/lex.re" +#line 235 "../src/parse/lex.re" { tok += 2; /* skip ":=" */ depth = 0; goto code; } -#line 1140 "src/parse/lex.cc" +#line 1137 "src/parse/lex.cc" yy189: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 234 "../src/parse/lex.re" +#line 231 "../src/parse/lex.re" { return *tok; } -#line 1148 "src/parse/lex.cc" +#line 1145 "src/parse/lex.cc" yy191: ++YYCURSOR; -#line 247 "../src/parse/lex.re" +#line 244 "../src/parse/lex.re" { depth = 1; goto comment; } -#line 1156 "src/parse/lex.cc" +#line 1153 "src/parse/lex.cc" yy193: ++YYCURSOR; -#line 244 "../src/parse/lex.re" +#line 241 "../src/parse/lex.re" { goto nextLine; } -#line 1163 "src/parse/lex.cc" +#line 1160 "src/parse/lex.cc" yy195: ++YYCURSOR; -#line 253 "../src/parse/lex.re" +#line 250 "../src/parse/lex.re" { tok = cur; return 0; } -#line 1171 "src/parse/lex.cc" +#line 1168 "src/parse/lex.cc" yy197: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -1260,12 +1257,12 @@ yy210: yy212: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 370 "../src/parse/lex.re" +#line 367 "../src/parse/lex.re" { set_sourceline (); goto scan; } -#line 1269 "src/parse/lex.cc" +#line 1266 "src/parse/lex.cc" yy214: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy212; @@ -1298,12 +1295,12 @@ yy220: if (yych == ' ') goto yy219; goto yy115; } -#line 386 "../src/parse/lex.re" +#line 383 "../src/parse/lex.re" flex_name: -#line 1307 "src/parse/lex.cc" +#line 1304 "src/parse/lex.cc" { YYCTYPE yych; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); @@ -1312,22 +1309,22 @@ flex_name: if (yych == '\r') goto yy227; ++YYCURSOR; yy224: -#line 397 "../src/parse/lex.re" +#line 394 "../src/parse/lex.re" { YYCURSOR = tok; goto start; } -#line 1321 "src/parse/lex.cc" +#line 1318 "src/parse/lex.cc" yy225: ++YYCURSOR; yy226: -#line 391 "../src/parse/lex.re" +#line 388 "../src/parse/lex.re" { YYCURSOR = tok; lexer_state = LEX_NORMAL; return FID_END; } -#line 1331 "src/parse/lex.cc" +#line 1328 "src/parse/lex.cc" yy227: yych = (YYCTYPE)*++YYCURSOR; if (yych != '\n') goto yy224; @@ -1335,12 +1332,12 @@ yy227: yych = (YYCTYPE)*YYCURSOR; goto yy226; } -#line 401 "../src/parse/lex.re" +#line 398 "../src/parse/lex.re" code: -#line 1344 "src/parse/lex.cc" +#line 1341 "src/parse/lex.cc" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -1401,7 +1398,7 @@ code: } yy231: ++YYCURSOR; -#line 464 "../src/parse/lex.re" +#line 461 "../src/parse/lex.re" { if (cur == eof) { @@ -1413,15 +1410,15 @@ yy231: } goto code; } -#line 1417 "src/parse/lex.cc" +#line 1414 "src/parse/lex.cc" yy233: ++YYCURSOR; yy234: -#line 478 "../src/parse/lex.re" +#line 475 "../src/parse/lex.re" { goto code; } -#line 1425 "src/parse/lex.cc" +#line 1422 "src/parse/lex.cc" yy235: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -1441,7 +1438,7 @@ yy235: } } yy236: -#line 445 "../src/parse/lex.re" +#line 442 "../src/parse/lex.re" { if (depth == 0) { @@ -1461,7 +1458,7 @@ yy236: cline++; goto code; } -#line 1465 "src/parse/lex.cc" +#line 1462 "src/parse/lex.cc" yy237: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -1474,7 +1471,7 @@ yy238: goto yy244; yy239: ++YYCURSOR; -#line 417 "../src/parse/lex.re" +#line 414 "../src/parse/lex.re" { if (depth == 0) { @@ -1486,10 +1483,10 @@ yy239: } goto code; } -#line 1490 "src/parse/lex.cc" +#line 1487 "src/parse/lex.cc" yy241: ++YYCURSOR; -#line 405 "../src/parse/lex.re" +#line 402 "../src/parse/lex.re" { if (depth == 0) { @@ -1502,7 +1499,7 @@ yy241: } goto code; } -#line 1506 "src/parse/lex.cc" +#line 1503 "src/parse/lex.cc" yy243: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1533,11 +1530,11 @@ yy246: goto yy243; yy247: ++YYCURSOR; -#line 475 "../src/parse/lex.re" +#line 472 "../src/parse/lex.re" { goto code; } -#line 1541 "src/parse/lex.cc" +#line 1538 "src/parse/lex.cc" yy249: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1564,7 +1561,7 @@ yy252: } yy253: YYCURSOR = YYCTXMARKER; -#line 432 "../src/parse/lex.re" +#line 429 "../src/parse/lex.re" { if (depth == 0) { @@ -1578,7 +1575,7 @@ yy253: cline++; goto code; } -#line 1582 "src/parse/lex.cc" +#line 1579 "src/parse/lex.cc" yy254: yych = (YYCTYPE)*++YYCURSOR; goto yy253; @@ -1645,12 +1642,12 @@ yy265: yy267: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 428 "../src/parse/lex.re" +#line 425 "../src/parse/lex.re" { set_sourceline (); goto code; } -#line 1654 "src/parse/lex.cc" +#line 1651 "src/parse/lex.cc" yy269: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy267; @@ -1689,12 +1686,12 @@ yy274: goto yy245; } } -#line 481 "../src/parse/lex.re" +#line 478 "../src/parse/lex.re" comment: -#line 1698 "src/parse/lex.cc" +#line 1695 "src/parse/lex.cc" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -1741,7 +1738,7 @@ comment: } ++YYCURSOR; yy279: -#line 513 "../src/parse/lex.re" +#line 510 "../src/parse/lex.re" { if (cur == eof) { @@ -1749,7 +1746,7 @@ yy279: } goto comment; } -#line 1753 "src/parse/lex.cc" +#line 1750 "src/parse/lex.cc" yy280: yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); if (yybm[0+yych] & 32) { @@ -1757,7 +1754,7 @@ yy280: } if (yych == '#') goto yy291; yy281: -#line 504 "../src/parse/lex.re" +#line 501 "../src/parse/lex.re" { if (cur == eof) { @@ -1767,7 +1764,7 @@ yy281: cline++; goto comment; } -#line 1771 "src/parse/lex.cc" +#line 1768 "src/parse/lex.cc" yy282: yych = (YYCTYPE)*++YYCURSOR; if (yych == '/') goto yy286; @@ -1776,16 +1773,16 @@ yy283: yych = (YYCTYPE)*++YYCURSOR; if (yych != '*') goto yy279; ++YYCURSOR; -#line 495 "../src/parse/lex.re" +#line 492 "../src/parse/lex.re" { ++depth; fatal("ambiguous /* found"); goto comment; } -#line 1786 "src/parse/lex.cc" +#line 1783 "src/parse/lex.cc" yy286: ++YYCURSOR; -#line 485 "../src/parse/lex.re" +#line 482 "../src/parse/lex.re" { if (--depth == 0) { @@ -1796,7 +1793,7 @@ yy286: goto comment; } } -#line 1800 "src/parse/lex.cc" +#line 1797 "src/parse/lex.cc" yy288: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1874,12 +1871,12 @@ yy301: yy303: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 500 "../src/parse/lex.re" +#line 497 "../src/parse/lex.re" { set_sourceline (); goto comment; } -#line 1883 "src/parse/lex.cc" +#line 1880 "src/parse/lex.cc" yy305: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy303; @@ -1904,28 +1901,28 @@ yy309: if (yych == '\r') goto yy305; goto yy290; } -#line 520 "../src/parse/lex.re" +#line 517 "../src/parse/lex.re" nextLine: -#line 1913 "src/parse/lex.cc" +#line 1910 "src/parse/lex.cc" { YYCTYPE yych; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = (YYCTYPE)*YYCURSOR; if (yych == '\n') goto yy314; ++YYCURSOR; -#line 531 "../src/parse/lex.re" +#line 528 "../src/parse/lex.re" { if(cur == eof) { return 0; } goto nextLine; } -#line 1926 "src/parse/lex.cc" +#line 1923 "src/parse/lex.cc" yy314: ++YYCURSOR; -#line 524 "../src/parse/lex.re" +#line 521 "../src/parse/lex.re" { if(cur == eof) { return 0; } @@ -1933,9 +1930,9 @@ yy314: cline++; goto scan; } -#line 1937 "src/parse/lex.cc" +#line 1934 "src/parse/lex.cc" } -#line 536 "../src/parse/lex.re" +#line 533 "../src/parse/lex.re" } @@ -1959,35 +1956,35 @@ RegExp *Scanner::lex_cls(bool neg) uint32_t u, l; fst: -#line 1963 "src/parse/lex.cc" +#line 1960 "src/parse/lex.cc" { YYCTYPE yych; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = (YYCTYPE)*YYCURSOR; if (yych == ']') goto yy319; -#line 560 "../src/parse/lex.re" +#line 557 "../src/parse/lex.re" { l = lex_cls_chr(); goto snd; } -#line 1971 "src/parse/lex.cc" +#line 1968 "src/parse/lex.cc" yy319: ++YYCURSOR; -#line 559 "../src/parse/lex.re" +#line 556 "../src/parse/lex.re" { goto end; } -#line 1976 "src/parse/lex.cc" +#line 1973 "src/parse/lex.cc" } -#line 561 "../src/parse/lex.re" +#line 558 "../src/parse/lex.re" snd: -#line 1982 "src/parse/lex.cc" +#line 1979 "src/parse/lex.cc" { YYCTYPE yych; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = (YYCTYPE)*(YYMARKER = YYCURSOR); if (yych == '-') goto yy324; yy323: -#line 564 "../src/parse/lex.re" +#line 561 "../src/parse/lex.re" { u = l; goto add; } -#line 1991 "src/parse/lex.cc" +#line 1988 "src/parse/lex.cc" yy324: yych = (YYCTYPE)*++YYCURSOR; YYCTXMARKER = YYCURSOR; @@ -1997,7 +1994,7 @@ yy324: yy326: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 565 "../src/parse/lex.re" +#line 562 "../src/parse/lex.re" { u = lex_cls_chr(); if (l > u) { @@ -2006,9 +2003,9 @@ yy326: } goto add; } -#line 2010 "src/parse/lex.cc" +#line 2007 "src/parse/lex.cc" } -#line 573 "../src/parse/lex.re" +#line 570 "../src/parse/lex.re" add: if (!(s = opts->encoding.encodeRange(l, u))) { @@ -2027,7 +2024,7 @@ uint32_t Scanner::lex_cls_chr() { tok = cur; -#line 2031 "src/parse/lex.cc" +#line 2028 "src/parse/lex.cc" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -2036,14 +2033,14 @@ uint32_t Scanner::lex_cls_chr() if (yych == '\n') goto yy332; if (yych == '\\') goto yy334; ++YYCURSOR; -#line 596 "../src/parse/lex.re" +#line 593 "../src/parse/lex.re" { return static_cast(tok[0]); } -#line 2042 "src/parse/lex.cc" +#line 2039 "src/parse/lex.cc" yy332: ++YYCURSOR; -#line 591 "../src/parse/lex.re" +#line 588 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error"); } -#line 2047 "src/parse/lex.cc" +#line 2044 "src/parse/lex.cc" yy334: ++YYCURSOR; if ((yych = (YYCTYPE)*YYCURSOR) <= '`') { @@ -2092,31 +2089,31 @@ yy334: } } } -#line 594 "../src/parse/lex.re" +#line 591 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error in escape sequence"); } -#line 2098 "src/parse/lex.cc" +#line 2095 "src/parse/lex.cc" yy336: ++YYCURSOR; -#line 609 "../src/parse/lex.re" +#line 606 "../src/parse/lex.re" { warn.useless_escape(tline, tok - pos, tok[1]); return static_cast(tok[1]); } -#line 2106 "src/parse/lex.cc" +#line 2103 "src/parse/lex.cc" yy338: ++YYCURSOR; -#line 607 "../src/parse/lex.re" +#line 604 "../src/parse/lex.re" { return static_cast('-'); } -#line 2111 "src/parse/lex.cc" +#line 2108 "src/parse/lex.cc" yy340: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); if (yych <= '/') goto yy341; if (yych <= '7') goto yy379; yy341: -#line 593 "../src/parse/lex.re" +#line 590 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error in octal escape sequence"); } -#line 2120 "src/parse/lex.cc" +#line 2117 "src/parse/lex.cc" yy342: yych = (YYCTYPE)*++YYCURSOR; goto yy341; @@ -2132,9 +2129,9 @@ yy343: if (yych <= 'f') goto yy372; } yy344: -#line 592 "../src/parse/lex.re" +#line 589 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error in hexadecimal escape sequence"); } -#line 2138 "src/parse/lex.cc" +#line 2135 "src/parse/lex.cc" yy345: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2150,49 +2147,49 @@ yy345: } yy346: ++YYCURSOR; -#line 606 "../src/parse/lex.re" +#line 603 "../src/parse/lex.re" { return static_cast('\\'); } -#line 2156 "src/parse/lex.cc" +#line 2153 "src/parse/lex.cc" yy348: ++YYCURSOR; -#line 608 "../src/parse/lex.re" +#line 605 "../src/parse/lex.re" { return static_cast(']'); } -#line 2161 "src/parse/lex.cc" +#line 2158 "src/parse/lex.cc" yy350: ++YYCURSOR; -#line 599 "../src/parse/lex.re" +#line 596 "../src/parse/lex.re" { return static_cast('\a'); } -#line 2166 "src/parse/lex.cc" +#line 2163 "src/parse/lex.cc" yy352: ++YYCURSOR; -#line 600 "../src/parse/lex.re" +#line 597 "../src/parse/lex.re" { return static_cast('\b'); } -#line 2171 "src/parse/lex.cc" +#line 2168 "src/parse/lex.cc" yy354: ++YYCURSOR; -#line 601 "../src/parse/lex.re" +#line 598 "../src/parse/lex.re" { return static_cast('\f'); } -#line 2176 "src/parse/lex.cc" +#line 2173 "src/parse/lex.cc" yy356: ++YYCURSOR; -#line 602 "../src/parse/lex.re" +#line 599 "../src/parse/lex.re" { return static_cast('\n'); } -#line 2181 "src/parse/lex.cc" +#line 2178 "src/parse/lex.cc" yy358: ++YYCURSOR; -#line 603 "../src/parse/lex.re" +#line 600 "../src/parse/lex.re" { return static_cast('\r'); } -#line 2186 "src/parse/lex.cc" +#line 2183 "src/parse/lex.cc" yy360: ++YYCURSOR; -#line 604 "../src/parse/lex.re" +#line 601 "../src/parse/lex.re" { return static_cast('\t'); } -#line 2191 "src/parse/lex.cc" +#line 2188 "src/parse/lex.cc" yy362: ++YYCURSOR; -#line 605 "../src/parse/lex.re" +#line 602 "../src/parse/lex.re" { return static_cast('\v'); } -#line 2196 "src/parse/lex.cc" +#line 2193 "src/parse/lex.cc" yy364: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2223,9 +2220,9 @@ yy366: } yy367: ++YYCURSOR; -#line 597 "../src/parse/lex.re" +#line 594 "../src/parse/lex.re" { return unesc_hex(tok, cur); } -#line 2229 "src/parse/lex.cc" +#line 2226 "src/parse/lex.cc" yy369: yych = (YYCTYPE)*++YYCURSOR; if (yych <= '@') { @@ -2335,11 +2332,11 @@ yy379: if (yych <= '/') goto yy366; if (yych >= '8') goto yy366; ++YYCURSOR; -#line 598 "../src/parse/lex.re" +#line 595 "../src/parse/lex.re" { return unesc_oct(tok, cur); } -#line 2341 "src/parse/lex.cc" +#line 2338 "src/parse/lex.cc" } -#line 613 "../src/parse/lex.re" +#line 610 "../src/parse/lex.re" } @@ -2348,7 +2345,7 @@ uint32_t Scanner::lex_str_chr(char quote, bool &end) end = false; tok = cur; -#line 2352 "src/parse/lex.cc" +#line 2349 "src/parse/lex.cc" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -2357,17 +2354,17 @@ uint32_t Scanner::lex_str_chr(char quote, bool &end) if (yych == '\n') goto yy386; if (yych == '\\') goto yy388; ++YYCURSOR; -#line 626 "../src/parse/lex.re" +#line 623 "../src/parse/lex.re" { end = tok[0] == quote; return static_cast(tok[0]); } -#line 2366 "src/parse/lex.cc" +#line 2363 "src/parse/lex.cc" yy386: ++YYCURSOR; -#line 621 "../src/parse/lex.re" +#line 618 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error"); } -#line 2371 "src/parse/lex.cc" +#line 2368 "src/parse/lex.cc" yy388: ++YYCURSOR; if ((yych = (YYCTYPE)*YYCURSOR) <= 'a') { @@ -2413,28 +2410,28 @@ yy388: } } } -#line 624 "../src/parse/lex.re" +#line 621 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error in escape sequence"); } -#line 2419 "src/parse/lex.cc" +#line 2416 "src/parse/lex.cc" yy390: ++YYCURSOR; -#line 640 "../src/parse/lex.re" +#line 637 "../src/parse/lex.re" { if (tok[1] != quote) { warn.useless_escape(tline, tok - pos, tok[1]); } return static_cast(tok[1]); } -#line 2429 "src/parse/lex.cc" +#line 2426 "src/parse/lex.cc" yy392: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); if (yych <= '/') goto yy393; if (yych <= '7') goto yy429; yy393: -#line 623 "../src/parse/lex.re" +#line 620 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error in octal escape sequence"); } -#line 2438 "src/parse/lex.cc" +#line 2435 "src/parse/lex.cc" yy394: yych = (YYCTYPE)*++YYCURSOR; goto yy393; @@ -2450,9 +2447,9 @@ yy395: if (yych <= 'f') goto yy422; } yy396: -#line 622 "../src/parse/lex.re" +#line 619 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error in hexadecimal escape sequence"); } -#line 2456 "src/parse/lex.cc" +#line 2453 "src/parse/lex.cc" yy397: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2468,44 +2465,44 @@ yy397: } yy398: ++YYCURSOR; -#line 639 "../src/parse/lex.re" +#line 636 "../src/parse/lex.re" { return static_cast('\\'); } -#line 2474 "src/parse/lex.cc" +#line 2471 "src/parse/lex.cc" yy400: ++YYCURSOR; -#line 632 "../src/parse/lex.re" +#line 629 "../src/parse/lex.re" { return static_cast('\a'); } -#line 2479 "src/parse/lex.cc" +#line 2476 "src/parse/lex.cc" yy402: ++YYCURSOR; -#line 633 "../src/parse/lex.re" +#line 630 "../src/parse/lex.re" { return static_cast('\b'); } -#line 2484 "src/parse/lex.cc" +#line 2481 "src/parse/lex.cc" yy404: ++YYCURSOR; -#line 634 "../src/parse/lex.re" +#line 631 "../src/parse/lex.re" { return static_cast('\f'); } -#line 2489 "src/parse/lex.cc" +#line 2486 "src/parse/lex.cc" yy406: ++YYCURSOR; -#line 635 "../src/parse/lex.re" +#line 632 "../src/parse/lex.re" { return static_cast('\n'); } -#line 2494 "src/parse/lex.cc" +#line 2491 "src/parse/lex.cc" yy408: ++YYCURSOR; -#line 636 "../src/parse/lex.re" +#line 633 "../src/parse/lex.re" { return static_cast('\r'); } -#line 2499 "src/parse/lex.cc" +#line 2496 "src/parse/lex.cc" yy410: ++YYCURSOR; -#line 637 "../src/parse/lex.re" +#line 634 "../src/parse/lex.re" { return static_cast('\t'); } -#line 2504 "src/parse/lex.cc" +#line 2501 "src/parse/lex.cc" yy412: ++YYCURSOR; -#line 638 "../src/parse/lex.re" +#line 635 "../src/parse/lex.re" { return static_cast('\v'); } -#line 2509 "src/parse/lex.cc" +#line 2506 "src/parse/lex.cc" yy414: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2536,9 +2533,9 @@ yy416: } yy417: ++YYCURSOR; -#line 630 "../src/parse/lex.re" +#line 627 "../src/parse/lex.re" { return unesc_hex(tok, cur); } -#line 2542 "src/parse/lex.cc" +#line 2539 "src/parse/lex.cc" yy419: yych = (YYCTYPE)*++YYCURSOR; if (yych <= '@') { @@ -2648,11 +2645,11 @@ yy429: if (yych <= '/') goto yy416; if (yych >= '8') goto yy416; ++YYCURSOR; -#line 631 "../src/parse/lex.re" +#line 628 "../src/parse/lex.re" { return unesc_oct(tok, cur); } -#line 2654 "src/parse/lex.cc" +#line 2651 "src/parse/lex.cc" } -#line 646 "../src/parse/lex.re" +#line 643 "../src/parse/lex.re" } @@ -2673,7 +2670,7 @@ void Scanner::set_sourceline () sourceline: tok = cur; -#line 2677 "src/parse/lex.cc" +#line 2674 "src/parse/lex.cc" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -2722,14 +2719,14 @@ sourceline: yy434: ++YYCURSOR; yy435: -#line 689 "../src/parse/lex.re" +#line 686 "../src/parse/lex.re" { goto sourceline; } -#line 2730 "src/parse/lex.cc" +#line 2727 "src/parse/lex.cc" yy436: ++YYCURSOR; -#line 677 "../src/parse/lex.re" +#line 674 "../src/parse/lex.re" { if (cur == eof) { @@ -2742,7 +2739,7 @@ yy436: tok = cur; return; } -#line 2746 "src/parse/lex.cc" +#line 2743 "src/parse/lex.cc" yy438: yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); if (yych == '\n') goto yy435; @@ -2752,7 +2749,7 @@ yy439: yych = (YYCTYPE)*YYCURSOR; goto yy442; yy440: -#line 666 "../src/parse/lex.re" +#line 663 "../src/parse/lex.re" { if (!s_to_u32_unsafe (tok, cur, cline)) { @@ -2760,7 +2757,7 @@ yy440: } goto sourceline; } -#line 2764 "src/parse/lex.cc" +#line 2761 "src/parse/lex.cc" yy441: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -2792,14 +2789,14 @@ yy446: goto yy443; yy447: ++YYCURSOR; -#line 673 "../src/parse/lex.re" +#line 670 "../src/parse/lex.re" { escape (in.file_name, std::string (tok + 1, tok_len () - 2)); // -2 to omit quotes goto sourceline; } -#line 2801 "src/parse/lex.cc" +#line 2798 "src/parse/lex.cc" } -#line 692 "../src/parse/lex.re" +#line 689 "../src/parse/lex.re" } diff --git a/re2c/bootstrap/src/parse/parser.cc b/re2c/bootstrap/src/parse/parser.cc index 700172ae..914f7951 100644 --- a/re2c/bootstrap/src/parse/parser.cc +++ b/re2c/bootstrap/src/parse/parser.cc @@ -2259,8 +2259,8 @@ void parse(Scanner& i, Output & o) in = &i; - o.source.write_version_time (); - o.source.write_line_info (in->get_cline (), in->get_fname ().c_str ()); + o.source.wversion_time () + .wline_info (in->get_cline (), in->get_fname ().c_str ()); if (opts->target == opt_t::SKELETON) { Skeleton::emit_prolog (o.source); @@ -2411,7 +2411,7 @@ void parse(Scanner& i, Output & o) } } } - o.source.write_line_info (in->get_cline (), in->get_fname ().c_str ()); + o.source.wline_info (in->get_cline (), in->get_fname ().c_str ()); /* restore original char handling mode*/ opts.reset_encoding (encodingOld); } diff --git a/re2c/src/codegen/bitmap.cc b/re2c/src/codegen/bitmap.cc index 210a70a3..5e74e2ce 100644 --- a/re2c/src/codegen/bitmap.cc +++ b/re2c/src/codegen/bitmap.cc @@ -112,11 +112,11 @@ void BitMap::gen(OutputFile & o, uint32_t ind, uint32_t lb, uint32_t ub) if (opts->yybmHexTable) { - o.write_hex (bm[j]); + o.wu32_hex(bm[j]); } else { - o.write_uint32_t_width (bm[j], 3); + o.wu32_width(bm[j], 3); } o.ws(", "); } diff --git a/re2c/src/codegen/emit_action.cc b/re2c/src/codegen/emit_action.cc index 437e6870..e0e5a4d0 100644 --- a/re2c/src/codegen/emit_action.cc +++ b/re2c/src/codegen/emit_action.cc @@ -272,9 +272,9 @@ void emit_rule (OutputFile & o, uint32_t ind, const State * const s, const RuleO { o.wind(ind).wstring(yySetupRule).ws("\n"); } - o.write_line_info (rule->code->loc.line, rule->code->loc.filename.c_str ()); - o.wind(ind).wstring(rule->code->text).ws("\n"); - o.insert_line_info (); + o.wline_info(rule->code->loc.line, rule->code->loc.filename.c_str ()) + .wind(ind).wstring(rule->code->text).ws("\n") + .wdelay_line_info (); } else if (!rule->newcond.empty ()) { diff --git a/re2c/src/codegen/emit_dfa.cc b/re2c/src/codegen/emit_dfa.cc index c692ebbe..c50d89a9 100644 --- a/re2c/src/codegen/emit_dfa.cc +++ b/re2c/src/codegen/emit_dfa.cc @@ -145,8 +145,7 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra // Generate prolog if (bProlog) { - o.ws("\n"); - o.insert_line_info (); + o.ws("\n").wdelay_line_info (); if (opts->target == opt_t::DOT) { bPrologBrace = true; @@ -172,7 +171,7 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra { o.wind(ind).wstring(opts->yyctype).ws(" ").wstring(opts->yych).ws(";\n"); } - o.insert_yyaccept_init (ind); + o.wdelay_yyaccept_init (ind); } else { @@ -189,7 +188,7 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra { genCondTable(o, ind, output.types); } - o.insert_state_goto (ind); + o.wdelay_state_goto (ind); if (opts->cFlag && opts->target != opt_t::DOT) { if (used_labels.count(start_label)) @@ -197,7 +196,7 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra o.wstring(opts->labelPrefix).wlabel(start_label).ws(":\n"); } } - o.write_user_start_label (); + o.wuser_start_label (); if (opts->cFlag && !bWroteCondCheck) { genCondGoto(o, ind, output.types); @@ -331,7 +330,7 @@ void genCondGoto(OutputFile & o, uint32_t ind, const std::vector & } o.wind(ind).ws("}\n"); } - o.insert_warn_condition_order (); + o.wdelay_warn_condition_order (); bWroteCondCheck = true; } diff --git a/re2c/src/codegen/go_emit.cc b/re2c/src/codegen/go_emit.cc index 9ddf1197..9a46b7ce 100644 --- a/re2c/src/codegen/go_emit.cc +++ b/re2c/src/codegen/go_emit.cc @@ -27,9 +27,7 @@ std::string output_yych (bool & readCh) void output_if (OutputFile & o, uint32_t ind, bool & readCh, const std::string & compare, uint32_t value) { - o.wind(ind).ws("if (").wstring(output_yych (readCh)).ws(" ").wstring(compare).ws(" "); - o.write_char_hex (value); - o.ws(") "); + o.wind(ind).ws("if (").wstring(output_yych (readCh)).ws(" ").wstring(compare).ws(" ").wc_hex (value).ws(") "); } void output_goto (OutputFile & o, uint32_t ind, bool & readCh, label_t to) @@ -65,9 +63,7 @@ void Case::emit (OutputFile & o, uint32_t ind) { for (uint32_t b = ranges[i].first; b < ranges[i].second; ++b) { - o.wind(ind).ws("case "); - o.write_char_hex (b); - o.ws(":"); + o.wind(ind).ws("case ").wc_hex (b).ws(":"); if (opts->dFlag && opts->encoding.type () == Enc::EBCDIC) { const uint32_t c = opts->encoding.decodeUnsafe (b); @@ -157,7 +153,7 @@ void GoBitmap::emit (OutputFile & o, uint32_t ind, bool & readCh) o.ws("if (").wstring(opts->yybm).ws("[").wu32(bitmap->i).ws("+").wstring(yych).ws("] & "); if (opts->yybmHexTable) { - o.write_hex (bitmap->m); + o.wu32_hex(bitmap->m); } else { @@ -233,7 +229,7 @@ void Dot::emit (OutputFile & o) o.wlabel(from->label).ws(" -> ").wlabel(cases->cases[i].to->label).ws(" [label=\""); for (uint32_t j = 0; j < cases->cases[i].ranges.size (); ++j) { - o.write_range (cases->cases[i].ranges[j].first, cases->cases[i].ranges[j].second); + o.wrange(cases->cases[i].ranges[j].first, cases->cases[i].ranges[j].second); } o.ws("\"]\n"); } diff --git a/re2c/src/codegen/output.cc b/re2c/src/codegen/output.cc index 0a954d13..b47c866e 100644 --- a/re2c/src/codegen/output.cc +++ b/re2c/src/codegen/output.cc @@ -91,49 +91,57 @@ std::ostream & OutputFile::stream () return blocks.back ()->fragments.back ()->stream; } -void OutputFile::write (const char * s, size_t n) +OutputFile & OutputFile::wraw (const char * s, size_t n) { stream ().write (s, static_cast (n)); + return *this; } -void OutputFile::write_hex (uint32_t n) +OutputFile & OutputFile::wu32_hex (uint32_t n) { prtHex (stream (), n); + return *this; } -void OutputFile::write_char_hex (uint32_t n) +OutputFile & OutputFile::wc_hex (uint32_t n) { prtChOrHex (stream (), n); + return *this; } -void OutputFile::write_range (uint32_t l, uint32_t u) +OutputFile & OutputFile::wrange (uint32_t l, uint32_t u) { printSpan (stream (), l, u); + return *this; } -void OutputFile::write_uint32_t_width (uint32_t n, int w) +OutputFile & OutputFile::wu32_width (uint32_t n, int w) { stream () << std::setw (w); stream () << n; + return *this; } -void OutputFile::write_line_info (uint32_t l, const char * fn) +OutputFile & OutputFile::wline_info (uint32_t l, const char * fn) { output_line_info (stream (), l, fn); + return *this; } -void OutputFile::write_version_time () +OutputFile & OutputFile::wversion_time () { output_version_time (stream ()); + return *this; } -void OutputFile::write_user_start_label () +OutputFile & OutputFile::wuser_start_label () { const std::string label = blocks.back ()->user_start_label; if (!label.empty ()) { wstring(label).ws(":\n"); } + return *this; } OutputFile & OutputFile::wc (char c) @@ -189,13 +197,14 @@ void OutputFile::insert_code () blocks.back ()->fragments.push_back (new OutputFragment (OutputFragment::CODE, 0)); } -void OutputFile::insert_line_info () +OutputFile & OutputFile::wdelay_line_info () { blocks.back ()->fragments.push_back (new OutputFragment (OutputFragment::LINE_INFO, 0)); insert_code (); + return *this; } -void OutputFile::insert_state_goto (uint32_t ind) +OutputFile & OutputFile::wdelay_state_goto (uint32_t ind) { if (opts->fFlag && !bWroteGetState) { @@ -203,31 +212,36 @@ void OutputFile::insert_state_goto (uint32_t ind) insert_code (); bWroteGetState = true; } + return *this; } -void OutputFile::insert_types () +OutputFile & OutputFile::wdelay_types () { warn_condition_order = false; // see note [condition order] blocks.back ()->fragments.push_back (new OutputFragment (OutputFragment::TYPES, 0)); insert_code (); + return *this; } -void OutputFile::insert_warn_condition_order () +OutputFile & OutputFile::wdelay_warn_condition_order () { blocks.back ()->fragments.push_back (new OutputFragment (OutputFragment::WARN_CONDITION_ORDER, 0)); insert_code (); + return *this; } -void OutputFile::insert_yyaccept_init (uint32_t ind) +OutputFile & OutputFile::wdelay_yyaccept_init (uint32_t ind) { blocks.back ()->fragments.push_back (new OutputFragment (OutputFragment::YYACCEPT_INIT, ind)); insert_code (); + return *this; } -void OutputFile::insert_yymaxfill () +OutputFile & OutputFile::wdelay_yymaxfill () { blocks.back ()->fragments.push_back (new OutputFragment (OutputFragment::YYMAXFILL, 0)); insert_code (); + return *this; } void OutputFile::set_used_yyaccept () diff --git a/re2c/src/codegen/output.h b/re2c/src/codegen/output.h index cc07eb9e..467a5a09 100644 --- a/re2c/src/codegen/output.h +++ b/re2c/src/codegen/output.h @@ -73,29 +73,31 @@ public: void new_block (); - void write (const char * s, size_t n); - void write_hex (uint32_t n); - void write_char_hex (uint32_t n); - void write_range (uint32_t u, uint32_t l); - void write_uint32_t_width (uint32_t n, int w); - void write_line_info (uint32_t l, const char * fn); - void write_version_time (); - void write_user_start_label (); + // immediate output + OutputFile & wraw (const char * s, size_t n); OutputFile & wc (char c); + OutputFile & wc_hex (uint32_t n); OutputFile & wu32 (uint32_t n); + OutputFile & wu32_hex (uint32_t n); + OutputFile & wu32_width (uint32_t n, int w); OutputFile & wu64 (uint64_t n); OutputFile & wstring (const std::string & s); OutputFile & ws (const char * s); OutputFile & wlabel (label_t l); OutputFile & wrank (rule_rank_t l); + OutputFile & wrange (uint32_t u, uint32_t l); + OutputFile & wline_info (uint32_t l, const char * fn); + OutputFile & wversion_time (); + OutputFile & wuser_start_label (); OutputFile & wind (uint32_t ind); - void insert_line_info (); - void insert_state_goto (uint32_t ind); - void insert_types (); - void insert_warn_condition_order (); - void insert_yyaccept_init (uint32_t ind); - void insert_yymaxfill (); + // delayed output + OutputFile & wdelay_line_info (); + OutputFile & wdelay_state_goto (uint32_t ind); + OutputFile & wdelay_types (); + OutputFile & wdelay_warn_condition_order (); + OutputFile & wdelay_yyaccept_init (uint32_t ind); + OutputFile & wdelay_yymaxfill (); void set_used_yyaccept (); bool get_used_yyaccept () const; diff --git a/re2c/src/parse/lex.re b/re2c/src/parse/lex.re index ee8d8857..cdb7a404 100644 --- a/re2c/src/parse/lex.re +++ b/re2c/src/parse/lex.re @@ -76,7 +76,7 @@ echo: const size_t lexeme_len = cur[-1] == '{' ? sizeof ("%{") - 1 : sizeof ("/*!re2c") - 1; - out.write(tok, tok_len () - lexeme_len); + out.wraw(tok, tok_len () - lexeme_len); } tok = cur; return Parse; @@ -102,7 +102,7 @@ echo: if (opts->target == opt_t::CODE) { const size_t lexeme_len = sizeof ("/*!use:re2c") - 1; - out.write(tok, tok_len () - lexeme_len); + out.wraw(tok, tok_len () - lexeme_len); } tok = cur; return Reuse; @@ -110,7 +110,7 @@ echo: "/*!max:re2c" { if (opts->target != opt_t::DOT) { - out.insert_yymaxfill (); + out.wdelay_yymaxfill (); } tok = pos = cur; ignore_eoc = true; @@ -118,7 +118,7 @@ echo: } "/*!getstate:re2c" { tok = pos = cur; - out.insert_state_goto (opts->topIndent); + out.wdelay_state_goto (opts->topIndent); ignore_eoc = true; goto echo; } @@ -132,11 +132,9 @@ echo: ignore_eoc = true; if (opts->target != opt_t::DOT) { - out.insert_line_info (); - out.ws("\n"); - out.insert_types (); - out.ws("\n"); - out.write_line_info (cline, get_fname ().c_str ()); + out.wdelay_line_info ().ws("\n") + .wdelay_types ().ws("\n") + .wline_info (cline, get_fname ().c_str ()); } goto echo; } @@ -146,14 +144,14 @@ echo: { if (ignore_cnt) { - out.write_line_info (cline, get_fname ().c_str ()); + out.wline_info (cline, get_fname ().c_str ()); } ignore_eoc = false; ignore_cnt = 0; } else if (opts->target == opt_t::CODE) { - out.write(tok, tok_len ()); + out.wraw(tok, tok_len ()); } tok = pos = cur; goto echo; @@ -163,15 +161,14 @@ echo: { if (ignore_cnt) { - out.ws("\n"); - out.write_line_info (cline, get_fname ().c_str ()); + out.ws("\n").wline_info (cline, get_fname ().c_str ()); } ignore_eoc = false; ignore_cnt = 0; } else if (opts->target == opt_t::CODE) { - out.write(tok, tok_len ()); + out.wraw(tok, tok_len ()); } tok = pos = cur; goto echo; @@ -187,7 +184,7 @@ echo: } else if (opts->target == opt_t::CODE) { - out.write(tok, tok_len ()); + out.wraw(tok, tok_len ()); } tok = pos = cur; cline++; @@ -196,7 +193,7 @@ echo: zero { if (!ignore_eoc && opts->target == opt_t::CODE) { - out.write(tok, tok_len () - 1); + out.wraw(tok, tok_len () - 1); // -1 so we don't write out the \0 } if(cur == eof) diff --git a/re2c/src/parse/parser.ypp b/re2c/src/parse/parser.ypp index 1c476953..b2b01087 100644 --- a/re2c/src/parse/parser.ypp +++ b/re2c/src/parse/parser.ypp @@ -572,8 +572,8 @@ void parse(Scanner& i, Output & o) in = &i; - o.source.write_version_time (); - o.source.write_line_info (in->get_cline (), in->get_fname ().c_str ()); + o.source.wversion_time () + .wline_info (in->get_cline (), in->get_fname ().c_str ()); if (opts->target == opt_t::SKELETON) { Skeleton::emit_prolog (o.source); @@ -724,7 +724,7 @@ void parse(Scanner& i, Output & o) } } } - o.source.write_line_info (in->get_cline (), in->get_fname ().c_str ()); + o.source.wline_info (in->get_cline (), in->get_fname ().c_str ()); /* restore original char handling mode*/ opts.reset_encoding (encodingOld); } -- 2.40.0