From: Ulya Trofimovich Date: Fri, 27 Nov 2015 13:41:42 +0000 (+0000) Subject: Don't use 'operator <<' overloads with integral types: resolution is platform-dependent. X-Git-Tag: 0.15.3~27 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=499537c8f356aee6c575eb5df374270db0e3c893;p=re2c Don't use 'operator <<' overloads with integral types: resolution is platform-dependent. See bug #122 "clang does not compile re2c 0.15.x". Example of error on Mac OS X: src/codegen/emit_dfa.cc:250:65: error: use of overloaded operator '<<' is ambiguous (with operand types 're2c::OutputFile' and 'const size_t' (aka 'const unsigned long')) o << indent(ind++) << "static void *" << opts->yyctable << "[" << conds << "] = {\n"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~ ./src/codegen/output.h:84:22: note: candidate function friend OutputFile & operator << (OutputFile & o, char c); ^ ./src/codegen/output.h:85:22: note: candidate function friend OutputFile & operator << (OutputFile & o, uint32_t n); ^ ./src/codegen/output.h:86:22: note: candidate function friend OutputFile & operator << (OutputFile & o, uint64_t n); ^ On OS X 'size_t' is neither 'uint32_t' nor 'uint64_t', resolution is therefore ambiguous. --- diff --git a/re2c/bootstrap/src/parse/lex.cc b/re2c/bootstrap/src/parse/lex.cc index 37a4cd14..224a4d49 100644 --- a/re2c/bootstrap/src/parse/lex.cc +++ b/re2c/bootstrap/src/parse/lex.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.14.3 on Mon Nov 23 21:19:03 2015 */ +/* Generated by re2c 0.15.2 on Fri Nov 27 12:31:17 2015*/ #line 1 "../src/parse/lex.re" #include #include @@ -87,7 +87,6 @@ echo: 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, }; - if ((YYLIMIT - YYCURSOR) < 16) YYFILL(16); yych = (YYCTYPE)*YYCURSOR; if (yych <= '%') { @@ -120,7 +119,7 @@ echo: return Stop; } } -#line 124 "src/parse/lex.cc" +#line 123 "src/parse/lex.cc" yy4: ++YYCURSOR; yy5: @@ -128,7 +127,7 @@ yy5: { goto echo; } -#line 132 "src/parse/lex.cc" +#line 131 "src/parse/lex.cc" yy6: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -151,7 +150,7 @@ yy7: cline++; goto echo; } -#line 155 "src/parse/lex.cc" +#line 154 "src/parse/lex.cc" yy8: yych = (YYCTYPE)*++YYCURSOR; if (yych == '{') goto yy32; @@ -248,7 +247,7 @@ yy21: tok = cur; return Rules; } -#line 252 "src/parse/lex.cc" +#line 251 "src/parse/lex.cc" yy31: yych = (YYCTYPE)*++YYCURSOR; if (yych != 'c') goto yy12; @@ -270,7 +269,7 @@ yy32: tok = cur; return Parse; } -#line 274 "src/parse/lex.cc" +#line 273 "src/parse/lex.cc" yy34: yych = (YYCTYPE)*++YYCURSOR; if (yych != 'e') goto yy12; @@ -300,7 +299,7 @@ yy34: tok = cur; return Reuse; } -#line 304 "src/parse/lex.cc" +#line 303 "src/parse/lex.cc" yy42: yych = (YYCTYPE)*++YYCURSOR; if (yych != 'x') goto yy12; @@ -325,7 +324,7 @@ yy42: ignore_eoc = true; goto echo; } -#line 329 "src/parse/lex.cc" +#line 328 "src/parse/lex.cc" yy50: yych = (YYCTYPE)*++YYCURSOR; if (yych != 't') goto yy12; @@ -357,7 +356,7 @@ yy50: ignore_eoc = true; goto echo; } -#line 361 "src/parse/lex.cc" +#line 360 "src/parse/lex.cc" yy63: yych = (YYCTYPE)*++YYCURSOR; if (yych != 'n') goto yy12; @@ -384,7 +383,7 @@ yy63: ignore_eoc = true; goto echo; } -#line 388 "src/parse/lex.cc" +#line 387 "src/parse/lex.cc" yy74: yych = (YYCTYPE)*++YYCURSOR; if (yych != 'p') goto yy12; @@ -410,14 +409,14 @@ yy74: if (opts->target != opt_t::DOT) { out.insert_line_info (); - out << "\n"; + out.ws("\n"); out.insert_types (); - out << "\n"; + out.ws("\n"); out.write_line_info (cline, get_fname ().c_str ()); } goto echo; } -#line 421 "src/parse/lex.cc" +#line 420 "src/parse/lex.cc" yy84: yyaccept = 2; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -430,7 +429,7 @@ yy85: { if (ignore_cnt) { - out << "\n"; + out.ws("\n"); out.write_line_info (cline, get_fname ().c_str ()); } ignore_eoc = false; @@ -443,7 +442,7 @@ yy85: tok = pos = cur; goto echo; } -#line 447 "src/parse/lex.cc" +#line 446 "src/parse/lex.cc" yy86: yych = (YYCTYPE)*++YYCURSOR; if (yych != '\n') goto yy12; @@ -468,7 +467,7 @@ yy87: tok = pos = cur; goto echo; } -#line 472 "src/parse/lex.cc" +#line 471 "src/parse/lex.cc" yy89: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -499,10 +498,10 @@ yy91: if (yych <= '9') goto yy12; goto yy98; yy97: - YYCTXMARKER = YYCURSOR + 1; ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = (YYCTYPE)*YYCURSOR; + YYCTXMARKER = YYCURSOR; yy98: if (yych <= 0x1F) { if (yych == '\t') goto yy97; @@ -548,7 +547,7 @@ yy103: set_sourceline (); goto echo; } -#line 552 "src/parse/lex.cc" +#line 551 "src/parse/lex.cc" yy105: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy103; @@ -593,7 +592,7 @@ scan: start: -#line 597 "src/parse/lex.cc" +#line 596 "src/parse/lex.cc" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -713,7 +712,7 @@ yy113: fatalf("unexpected character: '%c'", *tok); goto scan; } -#line 717 "src/parse/lex.cc" +#line 716 "src/parse/lex.cc" yy114: ++YYCURSOR; yych = (YYCTYPE)*YYCURSOR; @@ -723,7 +722,7 @@ yy115: { goto scan; } -#line 727 "src/parse/lex.cc" +#line 726 "src/parse/lex.cc" yy116: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -741,7 +740,7 @@ yy117: cline++; goto scan; } -#line 745 "src/parse/lex.cc" +#line 744 "src/parse/lex.cc" yy118: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy197; @@ -750,7 +749,7 @@ yy119: ++YYCURSOR; #line 259 "../src/parse/lex.re" { yylval.regexp = lex_str('"', opts->bCaseInsensitive || opts->bCaseInverted); return REGEXP; } -#line 754 "src/parse/lex.cc" +#line 753 "src/parse/lex.cc" yy121: yych = (YYCTYPE)*++YYCURSOR; if (yych == '}') goto yy195; @@ -759,7 +758,7 @@ yy122: ++YYCURSOR; #line 258 "../src/parse/lex.re" { yylval.regexp = lex_str('\'', opts->bCaseInsensitive || !opts->bCaseInverted); return REGEXP; } -#line 763 "src/parse/lex.cc" +#line 762 "src/parse/lex.cc" yy124: ++YYCURSOR; yy125: @@ -767,7 +766,7 @@ yy125: { return *tok; } -#line 771 "src/parse/lex.cc" +#line 770 "src/parse/lex.cc" yy126: ++YYCURSOR; if ((yych = (YYCTYPE)*YYCURSOR) == '/') goto yy195; @@ -776,7 +775,7 @@ yy126: yylval.op = *tok; return STAR; } -#line 780 "src/parse/lex.cc" +#line 779 "src/parse/lex.cc" yy128: ++YYCURSOR; #line 277 "../src/parse/lex.re" @@ -784,7 +783,7 @@ yy128: yylval.op = *tok; return CLOSE; } -#line 788 "src/parse/lex.cc" +#line 787 "src/parse/lex.cc" yy130: ++YYCURSOR; #line 361 "../src/parse/lex.re" @@ -792,19 +791,19 @@ yy130: yylval.regexp = mkDot(); return REGEXP; } -#line 796 "src/parse/lex.cc" +#line 795 "src/parse/lex.cc" yy132: yych = (YYCTYPE)*++YYCURSOR; if (yych == '*') goto yy191; if (yych == '/') goto yy193; goto yy125; yy133: - YYCTXMARKER = YYCURSOR + 1; yych = (YYCTYPE)*++YYCURSOR; + YYCTXMARKER = YYCURSOR; goto yy165; yy134: - YYCTXMARKER = YYCURSOR + 1; yych = (YYCTYPE)*++YYCURSOR; + YYCTXMARKER = YYCURSOR; if (yych == '=') goto yy187; goto yy113; yy135: @@ -818,10 +817,10 @@ yy136: if ((yych = (YYCTYPE)*YYCURSOR) == '^') goto yy176; #line 260 "../src/parse/lex.re" { yylval.regexp = lex_cls(false); return REGEXP; } -#line 822 "src/parse/lex.cc" +#line 821 "src/parse/lex.cc" yy138: - YYCTXMARKER = YYCURSOR + 1; yych = (YYCTYPE)*++YYCURSOR; + YYCTXMARKER = YYCURSOR; if (yych == 'e') goto yy166; goto yy165; yy139: @@ -847,7 +846,7 @@ yy140: depth = 1; goto code; } -#line 851 "src/parse/lex.cc" +#line 850 "src/parse/lex.cc" yy141: ++YYCURSOR; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); @@ -900,7 +899,7 @@ yy147: { fatal("illegal closure form, use '{n}', '{n,}', '{n,m}' where n and m are numbers"); } -#line 904 "src/parse/lex.cc" +#line 903 "src/parse/lex.cc" yy148: ++YYCURSOR; #line 317 "../src/parse/lex.re" @@ -911,7 +910,7 @@ yy148: yylval.str = new std::string (tok + 1, tok_len () - 2); // -2 to omit braces return ID; } -#line 915 "src/parse/lex.cc" +#line 914 "src/parse/lex.cc" yy150: ++YYCURSOR; #line 282 "../src/parse/lex.re" @@ -923,7 +922,7 @@ yy150: yylval.extop.max = yylval.extop.min; return CLOSESIZE; } -#line 927 "src/parse/lex.cc" +#line 926 "src/parse/lex.cc" yy152: yyaccept = 3; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -940,7 +939,7 @@ yy152: yylval.extop.max = UINT32_MAX; return CLOSESIZE; } -#line 944 "src/parse/lex.cc" +#line 943 "src/parse/lex.cc" yy155: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -962,7 +961,7 @@ yy155: } return CLOSESIZE; } -#line 966 "src/parse/lex.cc" +#line 965 "src/parse/lex.cc" yy159: ++YYCURSOR; YYCURSOR = YYCTXMARKER; @@ -982,7 +981,7 @@ yy159: return REGEXP; } } -#line 986 "src/parse/lex.cc" +#line 985 "src/parse/lex.cc" yy161: yych = (YYCTYPE)*++YYCURSOR; goto yy174; @@ -995,12 +994,12 @@ yy163: yylval.str = new std::string (tok, tok_len ()); return ID; } -#line 999 "src/parse/lex.cc" +#line 998 "src/parse/lex.cc" yy164: - YYCTXMARKER = YYCURSOR + 1; ++YYCURSOR; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = (YYCTYPE)*YYCURSOR; + YYCTXMARKER = YYCURSOR; yy165: if (yych <= '9') { if (yych <= ' ') { @@ -1030,19 +1029,19 @@ yy165: } } yy166: - YYCTXMARKER = YYCURSOR + 1; yych = (YYCTYPE)*++YYCURSOR; + YYCTXMARKER = YYCURSOR; if (yych != '2') goto yy165; - YYCTXMARKER = YYCURSOR + 1; yych = (YYCTYPE)*++YYCURSOR; + YYCTXMARKER = YYCURSOR; if (yych != 'c') goto yy165; - YYCTXMARKER = YYCURSOR + 1; yych = (YYCTYPE)*++YYCURSOR; + YYCTXMARKER = YYCURSOR; if (yych != ':') goto yy165; ++YYCURSOR; #line 325 "../src/parse/lex.re" { lex_conf (); return CONF; } -#line 1046 "src/parse/lex.cc" +#line 1045 "src/parse/lex.cc" yy171: ++YYCURSOR; YYCURSOR = YYCTXMARKER; @@ -1059,7 +1058,7 @@ yy171: return ID; } } -#line 1063 "src/parse/lex.cc" +#line 1062 "src/parse/lex.cc" yy173: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1078,17 +1077,17 @@ yy176: ++YYCURSOR; #line 261 "../src/parse/lex.re" { yylval.regexp = lex_cls(true); return REGEXP; } -#line 1082 "src/parse/lex.cc" +#line 1081 "src/parse/lex.cc" yy178: ++YYCURSOR; #line 266 "../src/parse/lex.re" { return SETUP; } -#line 1089 "src/parse/lex.cc" +#line 1088 "src/parse/lex.cc" yy180: - YYCTXMARKER = YYCURSOR + 1; yych = (YYCTYPE)*++YYCURSOR; + YYCTXMARKER = YYCURSOR; goto yy182; yy181: ++YYCURSOR; @@ -1119,7 +1118,7 @@ yy183: { return NOCOND; } -#line 1123 "src/parse/lex.cc" +#line 1122 "src/parse/lex.cc" yy185: yych = (YYCTYPE)*++YYCURSOR; if (yych == '>') goto yy183; @@ -1137,7 +1136,7 @@ yy187: depth = 0; goto code; } -#line 1141 "src/parse/lex.cc" +#line 1140 "src/parse/lex.cc" yy189: ++YYCURSOR; YYCURSOR = YYCTXMARKER; @@ -1145,7 +1144,7 @@ yy189: { return *tok; } -#line 1149 "src/parse/lex.cc" +#line 1148 "src/parse/lex.cc" yy191: ++YYCURSOR; #line 247 "../src/parse/lex.re" @@ -1153,14 +1152,14 @@ yy191: depth = 1; goto comment; } -#line 1157 "src/parse/lex.cc" +#line 1156 "src/parse/lex.cc" yy193: ++YYCURSOR; #line 244 "../src/parse/lex.re" { goto nextLine; } -#line 1164 "src/parse/lex.cc" +#line 1163 "src/parse/lex.cc" yy195: ++YYCURSOR; #line 253 "../src/parse/lex.re" @@ -1168,7 +1167,7 @@ yy195: tok = cur; return 0; } -#line 1172 "src/parse/lex.cc" +#line 1171 "src/parse/lex.cc" yy197: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -1212,10 +1211,10 @@ yy200: if (yych <= '9') goto yy143; goto yy207; yy206: - YYCTXMARKER = YYCURSOR + 1; ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = (YYCTYPE)*YYCURSOR; + YYCTXMARKER = YYCURSOR; yy207: if (yych <= 0x1F) { if (yych == '\t') goto yy206; @@ -1266,7 +1265,7 @@ yy212: set_sourceline (); goto scan; } -#line 1270 "src/parse/lex.cc" +#line 1269 "src/parse/lex.cc" yy214: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy212; @@ -1304,7 +1303,7 @@ yy220: flex_name: -#line 1308 "src/parse/lex.cc" +#line 1307 "src/parse/lex.cc" { YYCTYPE yych; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); @@ -1318,7 +1317,7 @@ yy224: YYCURSOR = tok; goto start; } -#line 1322 "src/parse/lex.cc" +#line 1321 "src/parse/lex.cc" yy225: ++YYCURSOR; yy226: @@ -1328,7 +1327,7 @@ yy226: lexer_state = LEX_NORMAL; return FID_END; } -#line 1332 "src/parse/lex.cc" +#line 1331 "src/parse/lex.cc" yy227: yych = (YYCTYPE)*++YYCURSOR; if (yych != '\n') goto yy224; @@ -1341,7 +1340,7 @@ yy227: code: -#line 1345 "src/parse/lex.cc" +#line 1344 "src/parse/lex.cc" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -1414,7 +1413,7 @@ yy231: } goto code; } -#line 1418 "src/parse/lex.cc" +#line 1417 "src/parse/lex.cc" yy233: ++YYCURSOR; yy234: @@ -1422,11 +1421,11 @@ yy234: { goto code; } -#line 1426 "src/parse/lex.cc" +#line 1425 "src/parse/lex.cc" yy235: - YYCTXMARKER = YYCURSOR + 1; yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); + YYCTXMARKER = YYCURSOR; if (yych <= '\r') { if (yych <= '\t') { if (yych >= '\t') goto yy252; @@ -1462,7 +1461,7 @@ yy236: cline++; goto code; } -#line 1466 "src/parse/lex.cc" +#line 1465 "src/parse/lex.cc" yy237: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -1487,7 +1486,7 @@ yy239: } goto code; } -#line 1491 "src/parse/lex.cc" +#line 1490 "src/parse/lex.cc" yy241: ++YYCURSOR; #line 405 "../src/parse/lex.re" @@ -1503,7 +1502,7 @@ yy241: } goto code; } -#line 1507 "src/parse/lex.cc" +#line 1506 "src/parse/lex.cc" yy243: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1538,7 +1537,7 @@ yy247: { goto code; } -#line 1542 "src/parse/lex.cc" +#line 1541 "src/parse/lex.cc" yy249: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1579,7 +1578,7 @@ yy253: cline++; goto code; } -#line 1583 "src/parse/lex.cc" +#line 1582 "src/parse/lex.cc" yy254: yych = (YYCTYPE)*++YYCURSOR; goto yy253; @@ -1602,10 +1601,10 @@ yy255: if (yych <= '9') goto yy245; goto yy262; yy261: - YYCTXMARKER = YYCURSOR + 1; ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = (YYCTYPE)*YYCURSOR; + YYCTXMARKER = YYCURSOR; yy262: if (yych <= 0x1F) { if (yych == '\t') goto yy261; @@ -1651,7 +1650,7 @@ yy267: set_sourceline (); goto code; } -#line 1655 "src/parse/lex.cc" +#line 1654 "src/parse/lex.cc" yy269: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy267; @@ -1695,7 +1694,7 @@ yy274: comment: -#line 1699 "src/parse/lex.cc" +#line 1698 "src/parse/lex.cc" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -1750,7 +1749,7 @@ yy279: } goto comment; } -#line 1754 "src/parse/lex.cc" +#line 1753 "src/parse/lex.cc" yy280: yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); if (yybm[0+yych] & 32) { @@ -1768,7 +1767,7 @@ yy281: cline++; goto comment; } -#line 1772 "src/parse/lex.cc" +#line 1771 "src/parse/lex.cc" yy282: yych = (YYCTYPE)*++YYCURSOR; if (yych == '/') goto yy286; @@ -1783,7 +1782,7 @@ yy283: fatal("ambiguous /* found"); goto comment; } -#line 1787 "src/parse/lex.cc" +#line 1786 "src/parse/lex.cc" yy286: ++YYCURSOR; #line 485 "../src/parse/lex.re" @@ -1797,7 +1796,7 @@ yy286: goto comment; } } -#line 1801 "src/parse/lex.cc" +#line 1800 "src/parse/lex.cc" yy288: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1831,10 +1830,10 @@ yy291: if (yych <= '9') goto yy290; goto yy298; yy297: - YYCTXMARKER = YYCURSOR + 1; ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = (YYCTYPE)*YYCURSOR; + YYCTXMARKER = YYCURSOR; yy298: if (yych <= 0x1F) { if (yych == '\t') goto yy297; @@ -1880,7 +1879,7 @@ yy303: set_sourceline (); goto comment; } -#line 1884 "src/parse/lex.cc" +#line 1883 "src/parse/lex.cc" yy305: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy303; @@ -1910,7 +1909,7 @@ yy309: nextLine: -#line 1914 "src/parse/lex.cc" +#line 1913 "src/parse/lex.cc" { YYCTYPE yych; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1923,7 +1922,7 @@ nextLine: } goto nextLine; } -#line 1927 "src/parse/lex.cc" +#line 1926 "src/parse/lex.cc" yy314: ++YYCURSOR; #line 524 "../src/parse/lex.re" @@ -1934,7 +1933,7 @@ yy314: cline++; goto scan; } -#line 1938 "src/parse/lex.cc" +#line 1937 "src/parse/lex.cc" } #line 536 "../src/parse/lex.re" @@ -1960,7 +1959,7 @@ RegExp *Scanner::lex_cls(bool neg) uint32_t u, l; fst: -#line 1964 "src/parse/lex.cc" +#line 1963 "src/parse/lex.cc" { YYCTYPE yych; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1968,18 +1967,18 @@ fst: if (yych == ']') goto yy319; #line 560 "../src/parse/lex.re" { l = lex_cls_chr(); goto snd; } -#line 1972 "src/parse/lex.cc" +#line 1971 "src/parse/lex.cc" yy319: ++YYCURSOR; #line 559 "../src/parse/lex.re" { goto end; } -#line 1977 "src/parse/lex.cc" +#line 1976 "src/parse/lex.cc" } #line 561 "../src/parse/lex.re" snd: -#line 1983 "src/parse/lex.cc" +#line 1982 "src/parse/lex.cc" { YYCTYPE yych; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); @@ -1988,10 +1987,10 @@ snd: yy323: #line 564 "../src/parse/lex.re" { u = l; goto add; } -#line 1992 "src/parse/lex.cc" +#line 1991 "src/parse/lex.cc" yy324: - YYCTXMARKER = YYCURSOR + 1; yych = (YYCTYPE)*++YYCURSOR; + YYCTXMARKER = YYCURSOR; if (yych != ']') goto yy326; YYCURSOR = YYMARKER; goto yy323; @@ -2007,7 +2006,7 @@ yy326: } goto add; } -#line 2011 "src/parse/lex.cc" +#line 2010 "src/parse/lex.cc" } #line 573 "../src/parse/lex.re" @@ -2028,7 +2027,7 @@ uint32_t Scanner::lex_cls_chr() { tok = cur; -#line 2032 "src/parse/lex.cc" +#line 2031 "src/parse/lex.cc" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -2039,12 +2038,12 @@ uint32_t Scanner::lex_cls_chr() ++YYCURSOR; #line 596 "../src/parse/lex.re" { return static_cast(tok[0]); } -#line 2043 "src/parse/lex.cc" +#line 2042 "src/parse/lex.cc" yy332: ++YYCURSOR; #line 591 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error"); } -#line 2048 "src/parse/lex.cc" +#line 2047 "src/parse/lex.cc" yy334: ++YYCURSOR; if ((yych = (YYCTYPE)*YYCURSOR) <= '`') { @@ -2095,7 +2094,7 @@ yy334: } #line 594 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error in escape sequence"); } -#line 2099 "src/parse/lex.cc" +#line 2098 "src/parse/lex.cc" yy336: ++YYCURSOR; #line 609 "../src/parse/lex.re" @@ -2103,12 +2102,12 @@ yy336: warn.useless_escape(tline, tok - pos, tok[1]); return static_cast(tok[1]); } -#line 2107 "src/parse/lex.cc" +#line 2106 "src/parse/lex.cc" yy338: ++YYCURSOR; #line 607 "../src/parse/lex.re" { return static_cast('-'); } -#line 2112 "src/parse/lex.cc" +#line 2111 "src/parse/lex.cc" yy340: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2117,7 +2116,7 @@ yy340: yy341: #line 593 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error in octal escape sequence"); } -#line 2121 "src/parse/lex.cc" +#line 2120 "src/parse/lex.cc" yy342: yych = (YYCTYPE)*++YYCURSOR; goto yy341; @@ -2135,7 +2134,7 @@ yy343: yy344: #line 592 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error in hexadecimal escape sequence"); } -#line 2139 "src/parse/lex.cc" +#line 2138 "src/parse/lex.cc" yy345: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2153,47 +2152,47 @@ yy346: ++YYCURSOR; #line 606 "../src/parse/lex.re" { return static_cast('\\'); } -#line 2157 "src/parse/lex.cc" +#line 2156 "src/parse/lex.cc" yy348: ++YYCURSOR; #line 608 "../src/parse/lex.re" { return static_cast(']'); } -#line 2162 "src/parse/lex.cc" +#line 2161 "src/parse/lex.cc" yy350: ++YYCURSOR; #line 599 "../src/parse/lex.re" { return static_cast('\a'); } -#line 2167 "src/parse/lex.cc" +#line 2166 "src/parse/lex.cc" yy352: ++YYCURSOR; #line 600 "../src/parse/lex.re" { return static_cast('\b'); } -#line 2172 "src/parse/lex.cc" +#line 2171 "src/parse/lex.cc" yy354: ++YYCURSOR; #line 601 "../src/parse/lex.re" { return static_cast('\f'); } -#line 2177 "src/parse/lex.cc" +#line 2176 "src/parse/lex.cc" yy356: ++YYCURSOR; #line 602 "../src/parse/lex.re" { return static_cast('\n'); } -#line 2182 "src/parse/lex.cc" +#line 2181 "src/parse/lex.cc" yy358: ++YYCURSOR; #line 603 "../src/parse/lex.re" { return static_cast('\r'); } -#line 2187 "src/parse/lex.cc" +#line 2186 "src/parse/lex.cc" yy360: ++YYCURSOR; #line 604 "../src/parse/lex.re" { return static_cast('\t'); } -#line 2192 "src/parse/lex.cc" +#line 2191 "src/parse/lex.cc" yy362: ++YYCURSOR; #line 605 "../src/parse/lex.re" { return static_cast('\v'); } -#line 2197 "src/parse/lex.cc" +#line 2196 "src/parse/lex.cc" yy364: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2226,7 +2225,7 @@ yy367: ++YYCURSOR; #line 597 "../src/parse/lex.re" { return unesc_hex(tok, cur); } -#line 2230 "src/parse/lex.cc" +#line 2229 "src/parse/lex.cc" yy369: yych = (YYCTYPE)*++YYCURSOR; if (yych <= '@') { @@ -2338,7 +2337,7 @@ yy379: ++YYCURSOR; #line 598 "../src/parse/lex.re" { return unesc_oct(tok, cur); } -#line 2342 "src/parse/lex.cc" +#line 2341 "src/parse/lex.cc" } #line 613 "../src/parse/lex.re" @@ -2349,7 +2348,7 @@ uint32_t Scanner::lex_str_chr(char quote, bool &end) end = false; tok = cur; -#line 2353 "src/parse/lex.cc" +#line 2352 "src/parse/lex.cc" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -2363,12 +2362,12 @@ uint32_t Scanner::lex_str_chr(char quote, bool &end) end = tok[0] == quote; return static_cast(tok[0]); } -#line 2367 "src/parse/lex.cc" +#line 2366 "src/parse/lex.cc" yy386: ++YYCURSOR; #line 621 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error"); } -#line 2372 "src/parse/lex.cc" +#line 2371 "src/parse/lex.cc" yy388: ++YYCURSOR; if ((yych = (YYCTYPE)*YYCURSOR) <= 'a') { @@ -2416,7 +2415,7 @@ yy388: } #line 624 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error in escape sequence"); } -#line 2420 "src/parse/lex.cc" +#line 2419 "src/parse/lex.cc" yy390: ++YYCURSOR; #line 640 "../src/parse/lex.re" @@ -2426,7 +2425,7 @@ yy390: } return static_cast(tok[1]); } -#line 2430 "src/parse/lex.cc" +#line 2429 "src/parse/lex.cc" yy392: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2435,7 +2434,7 @@ yy392: yy393: #line 623 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error in octal escape sequence"); } -#line 2439 "src/parse/lex.cc" +#line 2438 "src/parse/lex.cc" yy394: yych = (YYCTYPE)*++YYCURSOR; goto yy393; @@ -2453,7 +2452,7 @@ yy395: yy396: #line 622 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error in hexadecimal escape sequence"); } -#line 2457 "src/parse/lex.cc" +#line 2456 "src/parse/lex.cc" yy397: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2471,42 +2470,42 @@ yy398: ++YYCURSOR; #line 639 "../src/parse/lex.re" { return static_cast('\\'); } -#line 2475 "src/parse/lex.cc" +#line 2474 "src/parse/lex.cc" yy400: ++YYCURSOR; #line 632 "../src/parse/lex.re" { return static_cast('\a'); } -#line 2480 "src/parse/lex.cc" +#line 2479 "src/parse/lex.cc" yy402: ++YYCURSOR; #line 633 "../src/parse/lex.re" { return static_cast('\b'); } -#line 2485 "src/parse/lex.cc" +#line 2484 "src/parse/lex.cc" yy404: ++YYCURSOR; #line 634 "../src/parse/lex.re" { return static_cast('\f'); } -#line 2490 "src/parse/lex.cc" +#line 2489 "src/parse/lex.cc" yy406: ++YYCURSOR; #line 635 "../src/parse/lex.re" { return static_cast('\n'); } -#line 2495 "src/parse/lex.cc" +#line 2494 "src/parse/lex.cc" yy408: ++YYCURSOR; #line 636 "../src/parse/lex.re" { return static_cast('\r'); } -#line 2500 "src/parse/lex.cc" +#line 2499 "src/parse/lex.cc" yy410: ++YYCURSOR; #line 637 "../src/parse/lex.re" { return static_cast('\t'); } -#line 2505 "src/parse/lex.cc" +#line 2504 "src/parse/lex.cc" yy412: ++YYCURSOR; #line 638 "../src/parse/lex.re" { return static_cast('\v'); } -#line 2510 "src/parse/lex.cc" +#line 2509 "src/parse/lex.cc" yy414: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2539,7 +2538,7 @@ yy417: ++YYCURSOR; #line 630 "../src/parse/lex.re" { return unesc_hex(tok, cur); } -#line 2543 "src/parse/lex.cc" +#line 2542 "src/parse/lex.cc" yy419: yych = (YYCTYPE)*++YYCURSOR; if (yych <= '@') { @@ -2651,7 +2650,7 @@ yy429: ++YYCURSOR; #line 631 "../src/parse/lex.re" { return unesc_oct(tok, cur); } -#line 2655 "src/parse/lex.cc" +#line 2654 "src/parse/lex.cc" } #line 646 "../src/parse/lex.re" @@ -2674,7 +2673,7 @@ void Scanner::set_sourceline () sourceline: tok = cur; -#line 2678 "src/parse/lex.cc" +#line 2677 "src/parse/lex.cc" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -2727,7 +2726,7 @@ yy435: { goto sourceline; } -#line 2731 "src/parse/lex.cc" +#line 2730 "src/parse/lex.cc" yy436: ++YYCURSOR; #line 677 "../src/parse/lex.re" @@ -2743,7 +2742,7 @@ yy436: tok = cur; return; } -#line 2747 "src/parse/lex.cc" +#line 2746 "src/parse/lex.cc" yy438: yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); if (yych == '\n') goto yy435; @@ -2761,7 +2760,7 @@ yy440: } goto sourceline; } -#line 2765 "src/parse/lex.cc" +#line 2764 "src/parse/lex.cc" yy441: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -2798,7 +2797,7 @@ yy447: escape (in.file_name, std::string (tok + 1, tok_len () - 2)); // -2 to omit quotes goto sourceline; } -#line 2802 "src/parse/lex.cc" +#line 2801 "src/parse/lex.cc" } #line 692 "../src/parse/lex.re" diff --git a/re2c/src/codegen/bitmap.cc b/re2c/src/codegen/bitmap.cc index f2f3641c..210a70a3 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->yybm << "[] = {"; + o.wind(ind).ws("static const unsigned char ").wstring(opts->yybm).ws("[] = {"); uint32_t c = 1, n = ub - lb; const BitMap *cb = first; @@ -100,14 +100,14 @@ void BitMap::gen(OutputFile & o, uint32_t ind, uint32_t lb, uint32_t ub) if (c > 8) { - o << "\n" << indent(ind+1) << "/* table " << t << " .. " << std::min(c, t+7) << ": " << i << " */"; + o.ws("\n").wind(ind+1).ws("/* table ").wu32(t).ws(" .. ").wu32(std::min(c, t+7)).ws(": ").wu32(i).ws(" */"); } for (uint32_t j = 0; j < n; ++j) { if (j % 8 == 0) { - o << "\n" << indent(ind+1); + o.ws("\n").wind(ind+1); } if (opts->yybmHexTable) @@ -118,11 +118,11 @@ void BitMap::gen(OutputFile & o, uint32_t ind, uint32_t lb, uint32_t ub) { o.write_uint32_t_width (bm[j], 3); } - o << ", "; + o.ws(", "); } } - o << "\n" << indent(ind) << "};\n"; + o.ws("\n").wind(ind).ws("};\n"); delete[] bm; } diff --git a/re2c/src/codegen/emit_action.cc b/re2c/src/codegen/emit_action.cc index 4e2b6635..437e6870 100644 --- a/re2c/src/codegen/emit_action.cc +++ b/re2c/src/codegen/emit_action.cc @@ -12,7 +12,7 @@ static void need (OutputFile & o, uint32_t ind, bool & readCh, uin static void emit_match (OutputFile & o, uint32_t ind, bool & readCh, const State * const s); static void emit_initial (OutputFile & o, uint32_t ind, bool & readCh, const State * const s, const Initial & init, const std::set & used_labels); static void emit_save (OutputFile & o, uint32_t ind, bool & readCh, const State * const s, uint32_t save, bool save_yyaccept); -static void emit_accept_binary (OutputFile & o, uint32_t ind, bool & readCh, const State * const s, const accept_t & accept, uint32_t l, uint32_t r); +static void emit_accept_binary (OutputFile & o, uint32_t ind, bool & readCh, const State * const s, const accept_t & accept, size_t l, size_t r); static void emit_accept (OutputFile & o, uint32_t ind, bool & readCh, const State * const s, const accept_t & accept); static void emit_rule (OutputFile & o, uint32_t ind, const State * const s, const RuleOp * const rule, const std::string & condName, const Skeleton * skeleton); static void genYYFill (OutputFile & o, uint32_t need); @@ -53,7 +53,7 @@ void emit_action } if (s->isPreCtxt && opts->target != opt_t::DOT) { - o << opts->input_api.stmt_backupctx (ind); + o.wstring(opts->input_api.stmt_backupctx (ind)); } } @@ -69,17 +69,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.wstring(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.wstring(opts->input_api.stmt_skip (ind)); readCh = true; } else { - o << opts->input_api.stmt_skip_peek (ind); + o.wstring(opts->input_api.stmt_skip_peek (ind)); readCh = false; } @@ -100,22 +100,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.wstring(opts->input_api.stmt_skip (ind)); } else { - o << opts->input_api.stmt_skip_peek (ind); + o.wstring(opts->input_api.stmt_skip_peek (ind)); } } if (used_labels.count(initial.label)) { - o << opts->labelPrefix << initial.label << ":\n"; + o.wstring(opts->labelPrefix).wlabel(initial.label).ws(":\n"); } if (opts->dFlag) { - o << indent(ind) << opts->yydebug << "(" << initial.label << ", *" << opts->yycursor << ");" << "\n"; + o.wind(ind).wstring(opts->yydebug).ws("(").wlabel(initial.label).ws(", *").wstring(opts->yycursor).ws(");\n"); } if (s->link) @@ -126,7 +126,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.wstring(opts->input_api.stmt_backup (ind)); } readCh = false; } @@ -141,31 +141,31 @@ void emit_save (OutputFile & o, uint32_t ind, bool & readCh, const State * const if (save_yyaccept) { - o << indent (ind) << opts->yyaccept << " = " << save << ";\n"; + o.wind(ind).wstring(opts->yyaccept).ws(" = ").wu32(save).ws(";\n"); } if (s->link) { - o << opts->input_api.stmt_skip_backup (ind); + o.wstring(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.wstring(opts->input_api.stmt_skip_backup_peek (ind)); readCh = false; } } -void emit_accept_binary (OutputFile & o, uint32_t ind, bool & readCh, const State * const s, const accept_t & accepts, uint32_t l, uint32_t r) +void emit_accept_binary (OutputFile & o, uint32_t ind, bool & readCh, const State * const s, const accept_t & accepts, size_t l, size_t r) { if (l < r) { - const uint32_t m = (l + r) >> 1; - o << indent(ind) << "if (" << opts->yyaccept << (r == l+1 ? " == " : " <= ") << m << ") {\n"; + const size_t m = (l + r) >> 1; + o.wind(ind).ws("if (").wstring(opts->yyaccept).ws(r == l+1 ? " == " : " <= ").wu64(m).ws(") {\n"); emit_accept_binary (o, ++ind, readCh, s, accepts, l, m); - o << indent(--ind) << "} else {\n"; + o.wind(--ind).ws("} else {\n"); emit_accept_binary (o, ++ind, readCh, s, accepts, m + 1, r); - o << indent(--ind) << "}\n"; + o.wind(--ind).ws("}\n"); } else { @@ -175,17 +175,17 @@ void emit_accept_binary (OutputFile & o, uint32_t ind, bool & readCh, const Stat void emit_accept (OutputFile & o, uint32_t ind, bool & readCh, const State * const s, const accept_t & accepts) { - const uint32_t accepts_size = static_cast (accepts.size ()); + const size_t accepts_size = accepts.size (); if (accepts_size > 0) { if (opts->target != opt_t::DOT) { - o << opts->input_api.stmt_restore (ind); + o.wstring(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.wstring(opts->input_api.stmt_peek (ind)); readCh = false; } @@ -193,15 +193,15 @@ void emit_accept (OutputFile & o, uint32_t ind, bool & readCh, const State * con { if (opts->gFlag && accepts_size >= opts->cGotoThreshold) { - o << indent(ind++) << "{\n"; - o << indent(ind++) << "static void *" << opts->yytarget << "[" << accepts_size << "] = {\n"; + o.wind(ind++).ws("{\n"); + o.wind(ind++).ws("static void *").wstring(opts->yytarget).ws("[").wu64(accepts_size).ws("] = {\n"); for (uint32_t i = 0; i < accepts_size; ++i) { - o << indent(ind) << "&&" << opts->labelPrefix << accepts[i]->label << ",\n"; + o.wind(ind).ws("&&").wstring(opts->labelPrefix).wlabel(accepts[i]->label).ws(",\n"); } - o << indent(--ind) << "};\n"; - o << indent(ind) << "goto *" << opts->yytarget << "[" << opts->yyaccept << "];\n"; - o << indent(--ind) << "}\n"; + o.wind(--ind).ws("};\n"); + o.wind(ind).ws("goto *").wstring(opts->yytarget).ws("[").wstring(opts->yyaccept).ws("];\n"); + o.wind(--ind).ws("}\n"); } else if (opts->sFlag || (accepts_size == 2 && opts->target != opt_t::DOT)) { @@ -211,21 +211,21 @@ void emit_accept (OutputFile & o, uint32_t ind, bool & readCh, const State * con { for (uint32_t i = 0; i < accepts_size; ++i) { - o << s->label << " -> " << accepts[i]->label; - o << " [label=\"yyaccept=" << i << "\"]\n"; + o.wlabel(s->label).ws(" -> ").wlabel(accepts[i]->label); + o.ws(" [label=\"yyaccept=").wu32(i).ws("\"]\n"); } } else { - o << indent(ind) << "switch (" << opts->yyaccept << ") {\n"; + o.wind(ind).ws("switch (").wstring(opts->yyaccept).ws(") {\n"); for (uint32_t i = 0; i < accepts_size - 1; ++i) { - o << indent(ind) << "case " << i << ": \t"; + o.wind(ind).ws("case ").wu32(i).ws(": \t"); genGoTo(o, 0, s, accepts[i], readCh); } - o << indent(ind) << "default:\t"; + o.wind(ind).ws("default:\t"); genGoTo(o, 0, s, accepts[accepts_size - 1], readCh); - o << indent(ind) << "}\n"; + o.wind(ind).ws("}\n"); } } else @@ -240,19 +240,19 @@ void emit_rule (OutputFile & o, uint32_t ind, const State * const s, const RuleO { if (opts->target == opt_t::DOT) { - o << s->label; + o.wlabel(s->label); if (rule->code) { - o << " [label=\"" << rule->code->loc.filename << ":" << rule->code->loc.line << "\"]"; + o.ws(" [label=\"").wstring(rule->code->loc.filename).ws(":").wu32(rule->code->loc.line).ws("\"]"); } - o << "\n"; + o.ws("\n"); return; } uint32_t back = rule->ctx->fixedLength(); if (back != 0u && opts->target != opt_t::DOT) { - o << opts->input_api.stmt_restorectx (ind); + o.wstring(opts->input_api.stmt_restorectx (ind)); } if (opts->target == opt_t::SKELETON) @@ -270,15 +270,15 @@ void emit_rule (OutputFile & o, uint32_t ind, const State * const s, const RuleO { if (!yySetupRule.empty ()) { - o << indent(ind) << yySetupRule << "\n"; + o.wind(ind).wstring(yySetupRule).ws("\n"); } o.write_line_info (rule->code->loc.line, rule->code->loc.filename.c_str ()); - o << indent (ind) << rule->code->text << "\n"; + o.wind(ind).wstring(rule->code->text).ws("\n"); o.insert_line_info (); } else if (!rule->newcond.empty ()) { - o << indent (ind) << replaceParam(opts->condGoto, opts->condGotoParam, opts->condPrefix + rule->newcond) << "\n"; + o.wind(ind).wstring(replaceParam(opts->condGoto, opts->condGotoParam, opts->condPrefix + rule->newcond)).ws("\n"); } } } @@ -300,12 +300,12 @@ void need (OutputFile & o, uint32_t ind, bool & readCh, uint32_t n, bool bSetMar if (opts->fill_use && n > 0) { - o << indent(ind); + o.wind(ind); if (n == 1) { if (opts->fill_check) { - o << "if (" << opts->input_api.expr_lessthan_one () << ") "; + o.ws("if (").wstring(opts->input_api.expr_lessthan_one ()).ws(") "); } genYYFill(o, n); } @@ -313,7 +313,7 @@ void need (OutputFile & o, uint32_t ind, bool & readCh, uint32_t n, bool bSetMar { if (opts->fill_check) { - o << "if (" << opts->input_api.expr_lessthan (n) << ") "; + o.ws("if (").wstring(opts->input_api.expr_lessthan (n)).ws(") "); } genYYFill(o, n); } @@ -321,18 +321,18 @@ void need (OutputFile & o, uint32_t ind, bool & readCh, uint32_t n, bool bSetMar if (opts->fFlag) { - o << opts->yyfilllabel << fillIndex << ":\n"; + o.wstring(opts->yyfilllabel).wu32(fillIndex).ws(":\n"); } if (n > 0) { if (bSetMarker) { - o << opts->input_api.stmt_backup_peek (ind); + o.wstring(opts->input_api.stmt_backup_peek (ind)); } else { - o << opts->input_api.stmt_peek (ind); + o.wstring(opts->input_api.stmt_peek (ind)); } readCh = false; } @@ -340,36 +340,36 @@ void need (OutputFile & o, uint32_t ind, bool & readCh, uint32_t n, bool bSetMar void genYYFill (OutputFile & o, uint32_t need) { - o << replaceParam (opts->fill, opts->fill_arg, need); + o.wstring(replaceParam (opts->fill, opts->fill_arg, need)); if (!opts->fill_naked) { if (opts->fill_arg_use) { - o << "(" << need << ")"; + o.ws("(").wu32(need).ws(")"); } - o << ";"; + o.ws(";"); } - o << "\n"; + o.ws("\n"); } void genSetCondition(OutputFile & o, uint32_t ind, const std::string& newcond) { - o << indent(ind) << replaceParam (opts->cond_set, opts->cond_set_arg, opts->condEnumPrefix + newcond); + o.wind(ind).wstring(replaceParam (opts->cond_set, opts->cond_set_arg, opts->condEnumPrefix + newcond)); if (!opts->cond_set_naked) { - o << "(" << opts->condEnumPrefix << newcond << ");"; + o.ws("(").wstring(opts->condEnumPrefix).wstring(newcond).ws(");"); } - o << "\n"; + o.ws("\n"); } void genSetState(OutputFile & o, uint32_t ind, uint32_t fillIndex) { - o << indent(ind) << replaceParam (opts->state_set, opts->state_set_arg, fillIndex); + o.wind(ind).wstring(replaceParam (opts->state_set, opts->state_set_arg, fillIndex)); if (!opts->state_set_naked) { - o << "(" << fillIndex << ");"; + o.ws("(").wu32(fillIndex).ws(");"); } - o << "\n"; + o.ws("\n"); } } // namespace re2c diff --git a/re2c/src/codegen/emit_dfa.cc b/re2c/src/codegen/emit_dfa.cc index c150305c..c692ebbe 100644 --- a/re2c/src/codegen/emit_dfa.cc +++ b/re2c/src/codegen/emit_dfa.cc @@ -27,17 +27,17 @@ void genGoTo(OutputFile & o, uint32_t ind, const State *from, const State *to, b { if (opts->target == opt_t::DOT) { - o << from->label << " -> " << to->label << "\n"; + o.wlabel(from->label).ws(" -> ").wlabel(to->label).ws("\n"); return; } if (readCh && from->next != to) { - o << opts->input_api.stmt_peek (ind); + o.wstring(opts->input_api.stmt_peek (ind)); readCh = false; } - o << indent(ind) << "goto " << opts->labelPrefix << to->label << ";\n"; + o.wind(ind).ws("goto ").wstring(opts->labelPrefix).wlabel(to->label).ws(";\n"); } void emit_state (OutputFile & o, uint32_t ind, const State * s, bool used_label) @@ -46,11 +46,11 @@ void emit_state (OutputFile & o, uint32_t ind, const State * s, bool used_label) { if (used_label) { - o << opts->labelPrefix << s->label << ":\n"; + o.wstring(opts->labelPrefix).wlabel(s->label).ws(":\n"); } if (opts->dFlag && (s->action.type != Action::INITIAL)) { - o << indent(ind) << opts->yydebug << "(" << s->label << ", " << opts->input_api.expr_peek () << ");\n"; + o.wind(ind).wstring(opts->yydebug).ws("(").wlabel(s->label).ws(", ").wstring(opts->input_api.expr_peek ()).ws(");\n"); } } } @@ -88,7 +88,7 @@ void DFA::emit_body (OutputFile & o, uint32_t& ind, const std::set & us // skip it when entering DFA. if (used_labels.count(head->label)) { - o << indent(ind) << "goto " << opts->labelPrefix << initial << ";\n"; + o.wind(ind).ws("goto ").wstring(opts->labelPrefix).wlabel(initial).ws(";\n"); } const bool save_yyaccept = accepts.size () > 1; @@ -145,12 +145,12 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra // Generate prolog if (bProlog) { - o << "\n"; + o.ws("\n"); o.insert_line_info (); if (opts->target == opt_t::DOT) { bPrologBrace = true; - o << "digraph re2c {\n"; + o.ws("digraph re2c {\n"); } else if ((!opts->fFlag && o.get_used_yyaccept ()) || (!opts->fFlag && opts->bEmitYYCh) @@ -160,7 +160,7 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra ) { bPrologBrace = true; - o << indent(ind++) << "{\n"; + o.wind(ind++).ws("{\n"); } else if (ind == 0) { @@ -170,13 +170,13 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra { if (opts->bEmitYYCh) { - o << indent(ind) << opts->yyctype << " " << opts->yych << ";\n"; + o.wind(ind).wstring(opts->yyctype).ws(" ").wstring(opts->yych).ws(";\n"); } o.insert_yyaccept_init (ind); } else { - o << "\n"; + o.ws("\n"); } } if (opts->bFlag && !opts->cFlag && BitMap::first) @@ -194,7 +194,7 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra { if (used_labels.count(start_label)) { - o << opts->labelPrefix << start_label << ":\n"; + o.wstring(opts->labelPrefix).wlabel(start_label).ws(":\n"); } } o.write_user_start_label (); @@ -207,32 +207,32 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra { if (opts->condDivider.length()) { - o << replaceParam(opts->condDivider, opts->condDividerParam, cond) << "\n"; + o.wstring(replaceParam(opts->condDivider, opts->condDividerParam, cond)).ws("\n"); } if (opts->target == opt_t::DOT) { - o << cond << " -> " << head->label << "\n"; + o.wstring(cond).ws(" -> ").wlabel(head->label).ws("\n"); } else { - o << opts->condPrefix << cond << ":\n"; + o.wstring(opts->condPrefix).wstring(cond).ws(":\n"); } } if (opts->cFlag && opts->bFlag && BitMap::first) { - o << indent(ind++) << "{\n"; + o.wind(ind++).ws("{\n"); BitMap::gen(o, ind, lbChar, ubChar <= 256 ? ubChar : 256); } // Generate code emit_body (o, ind, used_labels, initial_label); if (opts->cFlag && opts->bFlag && BitMap::first) { - o << indent(--ind) << "}\n"; + o.wind(--ind).ws("}\n"); } // Generate epilog if ((!opts->cFlag || isLastCond) && bPrologBrace) { - o << indent(--ind) << "}\n"; + o.wind(--ind).ws("}\n"); } } @@ -247,29 +247,29 @@ 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->yyctable << "[" << conds << "] = {\n"; + o.wind(ind++).ws("static void *").wstring(opts->yyctable).ws("[").wu64(conds).ws("] = {\n"); for (size_t i = 0; i < conds; ++i) { - o << indent(ind) << "&&" << opts->condPrefix << condnames[i] << ",\n"; + o.wind(ind).ws("&&").wstring(opts->condPrefix).wstring(condnames[i]).ws(",\n"); } - o << indent(--ind) << "};\n"; + o.wind(--ind).ws("};\n"); } void genCondGotoSub(OutputFile & o, uint32_t ind, const std::vector & condnames, uint32_t cMin, uint32_t cMax) { if (cMin == cMax) { - o << indent(ind) << "goto " << opts->condPrefix << condnames[cMin] << ";\n"; + o.wind(ind).ws("goto ").wstring(opts->condPrefix).wstring(condnames[cMin]).ws(";\n"); } else { uint32_t cMid = cMin + ((cMax - cMin + 1) / 2); - o << indent(ind) << "if (" << genGetCondition() << " < " << cMid << ") {\n"; + o.wind(ind).ws("if (").wstring(genGetCondition()).ws(" < ").wu32(cMid).ws(") {\n"); genCondGotoSub(o, ind + 1, condnames, cMin, cMid - 1); - o << indent(ind) << "} else {\n"; + o.wind(ind).ws("} else {\n"); genCondGotoSub(o, ind + 1, condnames, cMid, cMax); - o << indent(ind) << "}\n"; + o.wind(ind).ws("}\n"); } } @@ -305,12 +305,12 @@ 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 << "0 -> " << cond << " [label=\"state=" << cond << "\"]\n"; + o.ws("0 -> ").wstring(cond).ws(" [label=\"state=").wstring(cond).ws("\"]\n"); } } else if (opts->gFlag) { - o << indent(ind) << "goto *" << opts->yyctable << "[" << genGetCondition() << "];\n"; + o.wind(ind).ws("goto *").wstring(opts->yyctable).ws("[").wstring(genGetCondition()).ws("];\n"); } else if (opts->sFlag) { @@ -323,13 +323,13 @@ void genCondGoto(OutputFile & o, uint32_t ind, const std::vector & else { o.warn_condition_order = false; // see note [condition order] - o << indent(ind) << "switch (" << genGetCondition() << ") {\n"; + o.wind(ind).ws("switch (").wstring(genGetCondition()).ws(") {\n"); 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.wind(ind).ws("case ").wstring(opts->condEnumPrefix).wstring(cond).ws(": goto ").wstring(opts->condPrefix).wstring(cond).ws(";\n"); } - o << indent(ind) << "}\n"; + o.wind(ind).ws("}\n"); } o.insert_warn_condition_order (); bWroteCondCheck = true; diff --git a/re2c/src/codegen/go_emit.cc b/re2c/src/codegen/go_emit.cc index ab957def..9ddf1197 100644 --- a/re2c/src/codegen/go_emit.cc +++ b/re2c/src/codegen/go_emit.cc @@ -27,19 +27,19 @@ std::string output_yych (bool & readCh) void output_if (OutputFile & o, uint32_t ind, bool & readCh, const std::string & compare, uint32_t value) { - o << indent(ind) << "if (" << output_yych (readCh) << " " << compare << " "; + o.wind(ind).ws("if (").wstring(output_yych (readCh)).ws(" ").wstring(compare).ws(" "); o.write_char_hex (value); - o << ") "; + o.ws(") "); } void output_goto (OutputFile & o, uint32_t ind, bool & readCh, label_t to) { if (readCh) { - o << opts->input_api.stmt_peek (ind); + o.wstring(opts->input_api.stmt_peek (ind)); readCh = false; } - o << indent (ind) << "goto " << opts->labelPrefix << to << ";\n"; + o.wind(ind).ws("goto ").wstring(opts->labelPrefix).wlabel(to).ws(";\n"); } std::string output_hgo (OutputFile & o, uint32_t ind, bool & readCh, SwitchIf * hgo) @@ -47,14 +47,14 @@ std::string output_hgo (OutputFile & o, uint32_t ind, bool & readCh, SwitchIf * std::string yych = output_yych (readCh); if (hgo != NULL) { - o << indent (ind) << "if (" << yych <<" & ~0xFF) {\n"; + o.wind(ind).ws("if (").wstring(yych).ws(" & ~0xFF) {\n"); hgo->emit (o, ind + 1, readCh); - o << indent (ind) << "} else "; + o.wind(ind).ws("} else "); yych = opts->yych; } else { - o << indent (ind); + o.wind(ind); } return yych; } @@ -65,19 +65,19 @@ void Case::emit (OutputFile & o, uint32_t ind) { for (uint32_t b = ranges[i].first; b < ranges[i].second; ++b) { - o << indent (ind) << "case "; + o.wind(ind).ws("case "); o.write_char_hex (b); - o << ":"; + o.ws(":"); if (opts->dFlag && opts->encoding.type () == Enc::EBCDIC) { const uint32_t c = opts->encoding.decodeUnsafe (b); if (is_print (c)) - o << " /* " << static_cast (c) << " */"; + o.ws(" /* ").wc(static_cast (c)).ws(" */"); } bool last_case = i == ranges.size () - 1 && b == ranges[i].second - 1; if (!last_case) { - o << "\n"; + o.ws("\n"); } } } @@ -85,7 +85,7 @@ void Case::emit (OutputFile & o, uint32_t ind) void Cases::emit (OutputFile & o, uint32_t ind, bool & readCh) { - o << indent(ind) << "switch (" << output_yych (readCh) << ") {\n"; + o.wind(ind).ws("switch (").wstring(output_yych (readCh)).ws(") {\n"); for (uint32_t i = 0; i < cases_size; ++i) { if (cases[i].to != def) @@ -94,19 +94,19 @@ void Cases::emit (OutputFile & o, uint32_t ind, bool & readCh) output_goto (o, 1, readCh, cases[i].to->label); } } - o << indent (ind) << "default:"; + o.wind(ind).ws("default:"); output_goto (o, 1, readCh, def->label); - o << indent (ind) << "}\n"; + o.wind(ind).ws("}\n"); } void Binary::emit (OutputFile & o, uint32_t ind, bool & readCh) { output_if (o, ind, readCh, cond->compare, cond->value); - o << "{\n"; + o.ws("{\n"); thn->emit (o, ind + 1, readCh); - o << indent (ind) << "} else {\n"; + o.wind(ind).ws("} else {\n"); els->emit (o, ind + 1, readCh); - o << indent (ind) << "}\n"; + o.wind(ind).ws("}\n"); } void Linear::emit (OutputFile & o, uint32_t ind, bool & readCh) @@ -154,18 +154,18 @@ 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->yybm << "[" << bitmap->i << "+" << yych << "] & "; + o.ws("if (").wstring(opts->yybm).ws("[").wu32(bitmap->i).ws("+").wstring(yych).ws("] & "); if (opts->yybmHexTable) { o.write_hex (bitmap->m); } else { - o << (uint32_t) bitmap->m; + o.wu32(bitmap->m); } - o << ") {\n"; + o.ws(") {\n"); output_goto (o, ind + 1, readCh, bitmap_state->label); - o << indent (ind) << "}\n"; + o.wind(ind).ws("}\n"); if (lgo != NULL) { lgo->emit (o, ind, readCh); @@ -187,36 +187,36 @@ label_t CpgotoTable::max_label () const void CpgotoTable::emit (OutputFile & o, uint32_t ind) { - o << indent (ind) << "static void *" << opts->yytarget << "[256] = {\n"; - o << indent (++ind); + o.wind(ind).ws("static void *").wstring(opts->yytarget).ws("[256] = {\n"); + o.wind(++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.ws("&&").wstring(opts->labelPrefix).wlabel(table[i]->label); if (i == TABLE_SIZE - 1) { - o << "\n"; + o.ws("\n"); } else if (i % 8 == 7) { - o << ",\n" << indent (ind); + o.ws(",\n").wind(ind); } else { const uint32_t padding = max_digits - table[i]->label.width () + 1; - o << "," << std::string (padding, ' '); + o.ws(",").wstring(std::string (padding, ' ')); } } - o << indent (--ind) << "};\n"; + o.wind(--ind).ws("};\n"); } void Cpgoto::emit (OutputFile & o, uint32_t ind, bool & readCh) { std::string yych = output_hgo (o, ind, readCh, hgo); - o << "{\n"; + o.ws("{\n"); table->emit (o, ++ind); - o << indent(ind) << "goto *" << opts->yytarget << "[" << yych << "];\n"; - o << indent(--ind) << "}\n"; + o.wind(ind).ws("goto *").wstring(opts->yytarget).ws("[").wstring(yych).ws("];\n"); + o.wind(--ind).ws("}\n"); } void Dot::emit (OutputFile & o) @@ -224,18 +224,18 @@ void Dot::emit (OutputFile & o) const uint32_t n = cases->cases_size; if (n == 1) { - o << from->label << " -> " << cases->cases[0].to->label << "\n"; + o.wlabel(from->label).ws(" -> ").wlabel(cases->cases[0].to->label).ws("\n"); } else { for (uint32_t i = 0; i < n; ++i) { - o << from->label << " -> " << cases->cases[i].to->label << " [label=\""; + 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 << "\"]\n"; + o.ws("\"]\n"); } } } diff --git a/re2c/src/codegen/output.cc b/re2c/src/codegen/output.cc index 79674918..0a954d13 100644 --- a/re2c/src/codegen/output.cc +++ b/re2c/src/codegen/output.cc @@ -132,50 +132,56 @@ void OutputFile::write_user_start_label () const std::string label = blocks.back ()->user_start_label; if (!label.empty ()) { - * this << label << ":\n"; + wstring(label).ws(":\n"); } } -OutputFile & operator << (OutputFile & u, char c) +OutputFile & OutputFile::wc (char c) { - u.stream () << c; - return u; + stream () << c; + return *this; } -OutputFile & operator << (OutputFile & u, uint32_t n) +OutputFile & OutputFile::wu32 (uint32_t n) { - u.stream () << n; - return u; + stream () << n; + return *this; +} + +OutputFile & OutputFile::wu64 (uint64_t n) +{ + stream () << n; + return *this; } -OutputFile & operator << (OutputFile & u, uint64_t n) +OutputFile & OutputFile::wstring (const std::string & s) { - u.stream () << n; - return u; + stream () << s; + return *this; } -OutputFile & operator << (OutputFile & u, const std::string & s) +OutputFile & OutputFile::ws (const char * s) { - u.stream () << s; - return u; + stream () << s; + return *this; } -OutputFile & operator << (OutputFile & u, const char * s) +OutputFile & OutputFile::wlabel (label_t l) { - u.stream () << s; - return u; + stream () << l; + return *this; } -OutputFile & operator << (OutputFile & u, label_t l) +OutputFile & OutputFile::wrank (rule_rank_t r) { - u.stream () << l; - return u; + stream () << r; + return *this; } -OutputFile & operator << (OutputFile & u, rule_rank_t r) +OutputFile & OutputFile::wind (uint32_t ind) { - u.stream () << r; - return u; + stream () << indent(ind); + return *this; } void OutputFile::insert_code () diff --git a/re2c/src/codegen/output.h b/re2c/src/codegen/output.h index 409b1943..cc07eb9e 100644 --- a/re2c/src/codegen/output.h +++ b/re2c/src/codegen/output.h @@ -81,13 +81,14 @@ public: void write_line_info (uint32_t l, const char * fn); void write_version_time (); void write_user_start_label (); - friend OutputFile & operator << (OutputFile & o, char c); - friend OutputFile & operator << (OutputFile & o, uint32_t n); - friend OutputFile & operator << (OutputFile & o, uint64_t n); - friend OutputFile & operator << (OutputFile & o, const std::string & s); - friend OutputFile & operator << (OutputFile & o, const char * s); - friend OutputFile & operator << (OutputFile & o, label_t l); - friend OutputFile & operator << (OutputFile & o, rule_rank_t l); + OutputFile & wc (char c); + OutputFile & wu32 (uint32_t n); + 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 & wind (uint32_t ind); void insert_line_info (); void insert_state_goto (uint32_t ind); diff --git a/re2c/src/codegen/skeleton/generate_code.cc b/re2c/src/codegen/skeleton/generate_code.cc index 13e6914d..a653d76d 100644 --- a/re2c/src/codegen/skeleton/generate_code.cc +++ b/re2c/src/codegen/skeleton/generate_code.cc @@ -9,78 +9,76 @@ static void exact_uint (OutputFile & o, size_t width) { if (width == sizeof (char)) { - o << "unsigned char"; + o.ws("unsigned char"); } else if (width == sizeof (short)) { - o << "unsigned short"; + o.ws("unsigned short"); } else if (width == sizeof (int)) { - o << "unsigned int"; + o.ws("unsigned int"); } else if (width == sizeof (long)) { - o << "unsigned long"; + o.ws("unsigned long"); } else { - o << "uint" << width * 8 << "_t"; + o.ws("uint").wu64 (width * 8).ws("_t"); } } void Skeleton::emit_prolog (OutputFile & o) { - const std::string & ind = opts->indString; - - o << "\n" << "#include "; - o << "\n" << "#include /* malloc, free */"; - o << "\n"; - o << "\n" << "static void *read_file"; - o << "\n" << ind << "( const char *fname"; - o << "\n" << ind << ", size_t unit"; - o << "\n" << ind << ", size_t padding"; - o << "\n" << ind << ", size_t *pfsize"; - o << "\n" << ind << ")"; - o << "\n" << "{"; - o << "\n" << ind << "void *buffer = NULL;"; - o << "\n" << ind << "size_t fsize = 0;"; - o << "\n"; - o << "\n" << ind << "/* open file */"; - o << "\n" << ind << "FILE *f = fopen(fname, \"rb\");"; - o << "\n" << ind << "if(f == NULL) {"; - o << "\n" << ind << ind << "goto error;"; - o << "\n" << ind << "}"; - o << "\n"; - o << "\n" << ind << "/* get file size */"; - o << "\n" << ind << "fseek(f, 0, SEEK_END);"; - o << "\n" << ind << "fsize = (size_t) ftell(f) / unit;"; - o << "\n" << ind << "fseek(f, 0, SEEK_SET);"; - o << "\n"; - o << "\n" << ind << "/* allocate memory for file and padding */"; - o << "\n" << ind << "buffer = malloc(unit * (fsize + padding));"; - o << "\n" << ind << "if (buffer == NULL) {"; - o << "\n" << ind << ind << "goto error;"; - o << "\n" << ind << "}"; - o << "\n"; - o << "\n" << ind << "/* read the whole file in memory */"; - o << "\n" << ind << "if (fread(buffer, unit, fsize, f) != fsize) {"; - o << "\n" << ind << ind << "goto error;"; - o << "\n" << ind << "}"; - o << "\n"; - o << "\n" << ind << "fclose(f);"; - o << "\n" << ind << "*pfsize = fsize;"; - o << "\n" << ind << "return buffer;"; - o << "\n"; - o << "\n" << "error:"; - o << "\n" << ind << "fprintf(stderr, \"error: cannot read file '%s'\\n\", fname);"; - o << "\n" << ind << "free(buffer);"; - o << "\n" << ind << "if (f != NULL) {"; - o << "\n" << ind << ind << "fclose(f);"; - o << "\n" << ind << "}"; - o << "\n" << ind << "return NULL;"; - o << "\n" << "}"; - o << "\n"; + o.ws("\n#include "); + o.ws("\n#include /* malloc, free */"); + o.ws("\n"); + o.ws("\nstatic void *read_file"); + o.ws("\n").wind(1).ws("( const char *fname"); + o.ws("\n").wind(1).ws(", size_t unit"); + o.ws("\n").wind(1).ws(", size_t padding"); + o.ws("\n").wind(1).ws(", size_t *pfsize"); + o.ws("\n").wind(1).ws(")"); + o.ws("\n{"); + o.ws("\n").wind(1).ws("void *buffer = NULL;"); + o.ws("\n").wind(1).ws("size_t fsize = 0;"); + o.ws("\n"); + o.ws("\n").wind(1).ws("/* open file */"); + o.ws("\n").wind(1).ws("FILE *f = fopen(fname, \"rb\");"); + o.ws("\n").wind(1).ws("if(f == NULL) {"); + o.ws("\n").wind(2).ws("goto error;"); + o.ws("\n").wind(1).ws("}"); + o.ws("\n"); + o.ws("\n").wind(1).ws("/* get file size */"); + o.ws("\n").wind(1).ws("fseek(f, 0, SEEK_END);"); + o.ws("\n").wind(1).ws("fsize = (size_t) ftell(f) / unit;"); + o.ws("\n").wind(1).ws("fseek(f, 0, SEEK_SET);"); + o.ws("\n"); + o.ws("\n").wind(1).ws("/* allocate memory for file and padding */"); + o.ws("\n").wind(1).ws("buffer = malloc(unit * (fsize + padding));"); + o.ws("\n").wind(1).ws("if (buffer == NULL) {"); + o.ws("\n").wind(2).ws("goto error;"); + o.ws("\n").wind(1).ws("}"); + o.ws("\n"); + o.ws("\n").wind(1).ws("/* read the whole file in memory */"); + o.ws("\n").wind(1).ws("if (fread(buffer, unit, fsize, f) != fsize) {"); + o.ws("\n").wind(2).ws("goto error;"); + o.ws("\n").wind(1).ws("}"); + o.ws("\n"); + o.ws("\n").wind(1).ws("fclose(f);"); + o.ws("\n").wind(1).ws("*pfsize = fsize;"); + o.ws("\n").wind(1).ws("return buffer;"); + o.ws("\n"); + o.ws("\nerror:"); + o.ws("\n").wind(1).ws("fprintf(stderr, \"error: cannot read file '%s'\\n\", fname);"); + o.ws("\n").wind(1).ws("free(buffer);"); + o.ws("\n").wind(1).ws("if (f != NULL) {"); + o.ws("\n").wind(2).ws("fclose(f);"); + o.ws("\n").wind(1).ws("}"); + o.ws("\n").wind(1).ws("return NULL;"); + o.ws("\n}"); + o.ws("\n"); } void Skeleton::emit_start @@ -91,131 +89,130 @@ void Skeleton::emit_start , bool accept ) const { - const std::string & ind = opts->indString; const uint32_t default_rule = rule2key (rule_rank_t::none ()); - o << "\n" << "#define YYCTYPE "; + o.ws("\n#define YYCTYPE "); exact_uint (o, opts->encoding.szCodeUnit ()); - o << "\n" << "#define YYKEYTYPE "; + o.ws("\n#define YYKEYTYPE "); exact_uint (o, sizeof_key); - o << "\n" << "#define YYPEEK() *cursor"; - o << "\n" << "#define YYSKIP() ++cursor"; + o.ws("\n#define YYPEEK() *cursor"); + o.ws("\n#define YYSKIP() ++cursor"); if (backup) { - o << "\n" << "#define YYBACKUP() marker = cursor"; - o << "\n" << "#define YYRESTORE() cursor = marker"; + o.ws("\n#define YYBACKUP() marker = cursor"); + o.ws("\n#define YYRESTORE() cursor = marker"); } if (backupctx) { - o << "\n" << "#define YYBACKUPCTX() ctxmarker = cursor"; - o << "\n" << "#define YYRESTORECTX() cursor = ctxmarker"; + o.ws("\n#define YYBACKUPCTX() ctxmarker = cursor"); + o.ws("\n#define YYRESTORECTX() cursor = ctxmarker"); } - o << "\n" << "#define YYLESSTHAN(n) (limit - cursor) < n"; - o << "\n" << "#define YYFILL(n) { break; }"; - o << "\n"; - o << "\n" << "static int action_" << name; - o << "\n" << ind << "( unsigned int i"; - o << "\n" << ind << ", const YYKEYTYPE *keys"; - o << "\n" << ind << ", const YYCTYPE *start"; - o << "\n" << ind << ", const YYCTYPE *token"; - o << "\n" << ind << ", const YYCTYPE **cursor"; - o << "\n" << ind << ", YYKEYTYPE rule_act"; - o << "\n" << ind << ")"; - o << "\n" << "{"; - o << "\n" << ind << "const long pos = token - start;"; - o << "\n" << ind << "const long len_act = *cursor - token;"; - o << "\n" << ind << "const long len_exp = (long) keys [3 * i + 1];"; - o << "\n" << ind << "const YYKEYTYPE rule_exp = keys [3 * i + 2];"; - o << "\n" << ind << "if (rule_exp == " << default_rule << ") {"; - o << "\n" << ind << ind << "fprintf"; - o << "\n" << ind << ind << ind << "( stderr"; - o << "\n" << ind << ind << ind << ", \"warning: lex_" << name << ": control flow is undefined for input\""; - o << "\n" << ind << ind << ind << ind << "\" at position %ld, rerun re2c with '-W'\\n\""; - o << "\n" << ind << ind << ind << ", pos"; - o << "\n" << ind << ind << ind << ");"; - o << "\n" << ind << "}"; - o << "\n" << ind << "if (len_act == len_exp && rule_act == rule_exp) {"; - o << "\n" << ind << ind << "const YYKEYTYPE offset = keys[3 * i];"; - o << "\n" << ind << ind << "*cursor = token + offset;"; - o << "\n" << ind << ind << "return 0;"; - o << "\n" << ind << "} else {"; - o << "\n" << ind << ind << "fprintf"; - o << "\n" << ind << ind << ind << "( stderr"; - o << "\n" << ind << ind << ind << ", \"error: lex_" << name << ": at position %ld (iteration %u):\\n\""; - o << "\n" << ind << ind << ind << ind << "\"\\texpected: match length %ld, rule %u\\n\""; - o << "\n" << ind << ind << ind << ind << "\"\\tactual: match length %ld, rule %u\\n\""; - o << "\n" << ind << ind << ind << ", pos"; - o << "\n" << ind << ind << ind << ", i"; - o << "\n" << ind << ind << ind << ", len_exp"; - o << "\n" << ind << ind << ind << ", rule_exp"; - o << "\n" << ind << ind << ind << ", len_act"; - o << "\n" << ind << ind << ind << ", rule_act"; - o << "\n" << ind << ind << ind << ");"; - o << "\n" << ind << ind << "return 1;"; - o << "\n" << ind << "}"; - o << "\n" << "}"; - o << "\n"; - o << "\n" << "int lex_" << name << "()"; - o << "\n" << "{"; - o << "\n" << ind << "const size_t padding = " << maxfill << "; /* YYMAXFILL */"; - o << "\n" << ind << "int status = 0;"; - o << "\n" << ind << "size_t input_len = 0;"; - o << "\n" << ind << "size_t keys_count = 0;"; - o << "\n" << ind << "YYCTYPE *input = NULL;"; - o << "\n" << ind << "YYKEYTYPE *keys = NULL;"; - o << "\n" << ind << "const YYCTYPE *cursor = NULL;"; - o << "\n" << ind << "const YYCTYPE *limit = NULL;"; - o << "\n" << ind << "const YYCTYPE *token = NULL;"; - o << "\n" << ind << "const YYCTYPE *eof = NULL;"; - o << "\n" << ind << "unsigned int i = 0;"; - o << "\n"; - o << "\n" << ind << "input = (YYCTYPE *) read_file"; - o << "\n" << ind << ind << "(\"" << o.file_name << "." << name << ".input\""; - o << "\n" << ind << ind << ", sizeof (YYCTYPE)"; - o << "\n" << ind << ind << ", padding"; - o << "\n" << ind << ind << ", &input_len"; - o << "\n" << ind << ind << ");"; - o << "\n" << ind << "if (input == NULL) {"; - o << "\n" << ind << ind << "status = 1;"; - o << "\n" << ind << ind << "goto end;"; - o << "\n" << ind << "}"; - o << "\n"; - o << "\n" << ind << "keys = (YYKEYTYPE *) read_file"; - o << "\n" << ind << ind << "(\"" << o.file_name << "." << name << ".keys\""; - o << "\n" << ind << ind << ", 3 * sizeof (YYKEYTYPE)"; - o << "\n" << ind << ind << ", 0"; - o << "\n" << ind << ind << ", &keys_count"; - o << "\n" << ind << ind << ");"; - o << "\n" << ind << "if (keys == NULL) {"; - o << "\n" << ind << ind << "status = 1;"; - o << "\n" << ind << ind << "goto end;"; - o << "\n" << ind << "}"; - o << "\n"; - o << "\n" << ind << "cursor = input;"; - o << "\n" << ind << "limit = input + input_len + padding;"; - o << "\n" << ind << "eof = input + input_len;"; - o << "\n"; - o << "\n" << ind << "for (i = 0; status == 0 && i < keys_count; ++i) {"; - o << "\n" << ind << ind << "token = cursor;"; + o.ws("\n#define YYLESSTHAN(n) (limit - cursor) < n"); + o.ws("\n#define YYFILL(n) { break; }"); + o.ws("\n"); + o.ws("\nstatic int action_").wstring(name); + o.ws("\n").wind(1).ws("( unsigned int i"); + o.ws("\n").wind(1).ws(", const YYKEYTYPE *keys"); + o.ws("\n").wind(1).ws(", const YYCTYPE *start"); + o.ws("\n").wind(1).ws(", const YYCTYPE *token"); + o.ws("\n").wind(1).ws(", const YYCTYPE **cursor"); + o.ws("\n").wind(1).ws(", YYKEYTYPE rule_act"); + o.ws("\n").wind(1).ws(")"); + o.ws("\n{"); + o.ws("\n").wind(1).ws("const long pos = token - start;"); + o.ws("\n").wind(1).ws("const long len_act = *cursor - token;"); + o.ws("\n").wind(1).ws("const long len_exp = (long) keys [3 * i + 1];"); + o.ws("\n").wind(1).ws("const YYKEYTYPE rule_exp = keys [3 * i + 2];"); + o.ws("\n").wind(1).ws("if (rule_exp == ").wu32(default_rule).ws(") {"); + o.ws("\n").wind(2).ws("fprintf"); + o.ws("\n").wind(3).ws("( stderr"); + o.ws("\n").wind(3).ws(", \"warning: lex_").wstring(name).ws(": control flow is undefined for input\""); + o.ws("\n").wind(4).ws("\" at position %ld, rerun re2c with '-W'\\n\""); + o.ws("\n").wind(3).ws(", pos"); + o.ws("\n").wind(3).ws(");"); + o.ws("\n").wind(1).ws("}"); + o.ws("\n").wind(1).ws("if (len_act == len_exp && rule_act == rule_exp) {"); + o.ws("\n").wind(2).ws("const YYKEYTYPE offset = keys[3 * i];"); + o.ws("\n").wind(2).ws("*cursor = token + offset;"); + o.ws("\n").wind(2).ws("return 0;"); + o.ws("\n").wind(1).ws("} else {"); + o.ws("\n").wind(2).ws("fprintf"); + o.ws("\n").wind(3).ws("( stderr"); + o.ws("\n").wind(3).ws(", \"error: lex_").wstring(name).ws(": at position %ld (iteration %u):\\n\""); + o.ws("\n").wind(4).ws("\"\\texpected: match length %ld, rule %u\\n\""); + o.ws("\n").wind(4).ws("\"\\tactual: match length %ld, rule %u\\n\""); + o.ws("\n").wind(3).ws(", pos"); + o.ws("\n").wind(3).ws(", i"); + o.ws("\n").wind(3).ws(", len_exp"); + o.ws("\n").wind(3).ws(", rule_exp"); + o.ws("\n").wind(3).ws(", len_act"); + o.ws("\n").wind(3).ws(", rule_act"); + o.ws("\n").wind(3).ws(");"); + o.ws("\n").wind(2).ws("return 1;"); + o.ws("\n").wind(1).ws("}"); + o.ws("\n}"); + o.ws("\n"); + o.ws("\nint lex_").wstring(name).ws("()"); + o.ws("\n{"); + o.ws("\n").wind(1).ws("const size_t padding = ").wu32(maxfill).ws("; /* YYMAXFILL */"); + o.ws("\n").wind(1).ws("int status = 0;"); + o.ws("\n").wind(1).ws("size_t input_len = 0;"); + o.ws("\n").wind(1).ws("size_t keys_count = 0;"); + o.ws("\n").wind(1).ws("YYCTYPE *input = NULL;"); + o.ws("\n").wind(1).ws("YYKEYTYPE *keys = NULL;"); + o.ws("\n").wind(1).ws("const YYCTYPE *cursor = NULL;"); + o.ws("\n").wind(1).ws("const YYCTYPE *limit = NULL;"); + o.ws("\n").wind(1).ws("const YYCTYPE *token = NULL;"); + o.ws("\n").wind(1).ws("const YYCTYPE *eof = NULL;"); + o.ws("\n").wind(1).ws("unsigned int i = 0;"); + o.ws("\n"); + o.ws("\n").wind(1).ws("input = (YYCTYPE *) read_file"); + o.ws("\n").wind(2).ws("(\"").wstring(o.file_name).ws(".").wstring(name).ws(".input\""); + o.ws("\n").wind(2).ws(", sizeof (YYCTYPE)"); + o.ws("\n").wind(2).ws(", padding"); + o.ws("\n").wind(2).ws(", &input_len"); + o.ws("\n").wind(2).ws(");"); + o.ws("\n").wind(1).ws("if (input == NULL) {"); + o.ws("\n").wind(2).ws("status = 1;"); + o.ws("\n").wind(2).ws("goto end;"); + o.ws("\n").wind(1).ws("}"); + o.ws("\n"); + o.ws("\n").wind(1).ws("keys = (YYKEYTYPE *) read_file"); + o.ws("\n").wind(2).ws("(\"").wstring(o.file_name).ws(".").wstring(name).ws(".keys\""); + o.ws("\n").wind(2).ws(", 3 * sizeof (YYKEYTYPE)"); + o.ws("\n").wind(2).ws(", 0"); + o.ws("\n").wind(2).ws(", &keys_count"); + o.ws("\n").wind(2).ws(");"); + o.ws("\n").wind(1).ws("if (keys == NULL) {"); + o.ws("\n").wind(2).ws("status = 1;"); + o.ws("\n").wind(2).ws("goto end;"); + o.ws("\n").wind(1).ws("}"); + o.ws("\n"); + o.ws("\n").wind(1).ws("cursor = input;"); + o.ws("\n").wind(1).ws("limit = input + input_len + padding;"); + o.ws("\n").wind(1).ws("eof = input + input_len;"); + o.ws("\n"); + o.ws("\n").wind(1).ws("for (i = 0; status == 0 && i < keys_count; ++i) {"); + o.ws("\n").wind(2).ws("token = cursor;"); if (backup) { - o << "\n" << ind << ind << "const YYCTYPE *marker = NULL;"; + o.ws("\n").wind(2).ws("const YYCTYPE *marker = NULL;"); } if (backupctx) { - o << "\n" << ind << ind << "const YYCTYPE *ctxmarker = NULL;"; + o.ws("\n").wind(2).ws("const YYCTYPE *ctxmarker = NULL;"); } - o << "\n" << ind << ind << "YYCTYPE yych;"; + o.ws("\n").wind(2).ws("YYCTYPE yych;"); if (accept) { - o << "\n" << ind << ind << "unsigned int yyaccept = 0;"; + o.ws("\n").wind(2).ws("unsigned int yyaccept = 0;"); } - o << "\n"; + o.ws("\n"); if (opts->bFlag && BitMap::first) { BitMap::gen (o, 2, 0, std::min (0x100u, opts->encoding.nCodeUnits ())); } - o << "\n"; + o.ws("\n"); } void Skeleton::emit_end @@ -224,68 +221,66 @@ void Skeleton::emit_end , bool backupctx ) const { - const std::string & ind = opts->indString; - - o << "\n" << ind << "}"; - o << "\n" << ind << "if (status == 0) {"; - o << "\n" << ind << ind << "if (cursor != eof) {"; - o << "\n" << ind << ind << ind << "status = 1;"; - o << "\n" << ind << ind << ind << "const long pos = token - input;"; - o << "\n" << ind << ind << ind << "fprintf(stderr, \"error: lex_" << name << ": unused input strings left at position %ld\\n\", pos);"; - o << "\n" << ind << ind << "}"; - o << "\n" << ind << ind << "if (i != keys_count) {"; - o << "\n" << ind << ind << ind << "status = 1;"; - o << "\n" << ind << ind << ind << "fprintf(stderr, \"error: lex_" << name << ": unused keys left after %u iterations\\n\", i);"; - o << "\n" << ind << ind << "}"; - o << "\n" << ind << "}"; - o << "\n"; - o << "\n" << "end:"; - o << "\n" << ind << "free(input);"; - o << "\n" << ind << "free(keys);"; - o << "\n"; - o << "\n" << ind << "return status;"; - o << "\n" << "}"; - o << "\n"; - o << "\n" << "#undef YYCTYPE"; - o << "\n" << "#undef YYKEYTYPE"; - o << "\n" << "#undef YYPEEK"; - o << "\n" << "#undef YYSKIP"; + o.ws("\n").wind(1).ws("}"); + o.ws("\n").wind(1).ws("if (status == 0) {"); + o.ws("\n").wind(2).ws("if (cursor != eof) {"); + o.ws("\n").wind(3).ws("status = 1;"); + o.ws("\n").wind(3).ws("const long pos = token - input;"); + o.ws("\n").wind(3).ws("fprintf(stderr, \"error: lex_").wstring(name).ws(": unused input strings left at position %ld\\n\", pos);"); + o.ws("\n").wind(2).ws("}"); + o.ws("\n").wind(2).ws("if (i != keys_count) {"); + o.ws("\n").wind(3).ws("status = 1;"); + o.ws("\n").wind(3).ws("fprintf(stderr, \"error: lex_").wstring(name).ws(": unused keys left after %u iterations\\n\", i);"); + o.ws("\n").wind(2).ws("}"); + o.ws("\n").wind(1).ws("}"); + o.ws("\n"); + o.ws("\nend:"); + o.ws("\n").wind(1).ws("free(input);"); + o.ws("\n").wind(1).ws("free(keys);"); + o.ws("\n"); + o.ws("\n").wind(1).ws("return status;"); + o.ws("\n}"); + o.ws("\n"); + o.ws("\n#undef YYCTYPE"); + o.ws("\n#undef YYKEYTYPE"); + o.ws("\n#undef YYPEEK"); + o.ws("\n#undef YYSKIP"); if (backup) { - o << "\n" << "#undef YYBACKUP"; - o << "\n" << "#undef YYRESTORE"; + o.ws("\n#undef YYBACKUP"); + o.ws("\n#undef YYRESTORE"); } if (backupctx) { - o << "\n" << "#undef YYBACKUPCTX"; - o << "\n" << "#undef YYRESTORECTX"; + o.ws("\n#undef YYBACKUPCTX"); + o.ws("\n#undef YYRESTORECTX"); } - o << "\n" << "#undef YYLESSTHAN"; - o << "\n" << "#undef YYFILL"; - o << "\n"; + o.ws("\n#undef YYLESSTHAN"); + o.ws("\n#undef YYFILL"); + o.ws("\n"); } void Skeleton::emit_epilog (OutputFile & o, const std::set & names) { - o << "\n" << "int main()"; - o << "\n" << "{"; + o.ws("\n").ws("int main()"); + o.ws("\n").ws("{"); for (std::set::const_iterator i = names.begin (); i != names.end (); ++i) { - o << "\n" << opts->indString << "if(lex_" << *i << "() != 0) {"; - o << "\n" << opts->indString << opts->indString << "return 1;"; - o << "\n" << opts->indString << "}"; + o.ws("\n").wind(1).ws("if(lex_").wstring(*i).ws("() != 0) {"); + o.ws("\n").wind(2).ws("return 1;"); + o.ws("\n").wind(1).ws("}"); } - o << "\n" << opts->indString << "return 0;"; - o << "\n" << "}"; - o << "\n"; + o.ws("\n").wind(1).ws("return 0;"); + o.ws("\n}"); + o.ws("\n"); } void Skeleton::emit_action (OutputFile & o, uint32_t ind, rule_rank_t rank) const { - o << indent (ind) << "status = action_" << name << "(i, keys, input, token, &cursor, " << rule2key (rank) << ");\n"; - o << indent (ind) << "continue;\n"; + o.wind(ind).ws("status = action_").wstring(name).ws("(i, keys, input, token, &cursor, ").wu32(rule2key (rank)).ws(");\n"); + o.wind(ind).ws("continue;\n"); } } // namespace re2c diff --git a/re2c/src/parse/lex.re b/re2c/src/parse/lex.re index c9e0dc93..ee8d8857 100644 --- a/re2c/src/parse/lex.re +++ b/re2c/src/parse/lex.re @@ -133,9 +133,9 @@ echo: if (opts->target != opt_t::DOT) { out.insert_line_info (); - out << "\n"; + out.ws("\n"); out.insert_types (); - out << "\n"; + out.ws("\n"); out.write_line_info (cline, get_fname ().c_str ()); } goto echo; @@ -163,7 +163,7 @@ echo: { if (ignore_cnt) { - out << "\n"; + out.ws("\n"); out.write_line_info (cline, get_fname ().c_str ()); } ignore_eoc = false;