From: Ulya Trofimovich Date: Sun, 23 Dec 2018 19:32:29 +0000 (+0000) Subject: Preparations to support #include: keep input files in a stack. X-Git-Tag: 1.2~284 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1edd26a35457c5835afd58b8fa8330d33e7a1192;p=re2c Preparations to support #include: keep input files in a stack. --- diff --git a/re2c/bootstrap/src/ast/lex.cc b/re2c/bootstrap/src/ast/lex.cc index bbaeee18..c06bbee5 100644 --- a/re2c/bootstrap/src/ast/lex.cc +++ b/re2c/bootstrap/src/ast/lex.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 1.1.1 on Sat Dec 22 19:57:50 2018 */ +/* Generated by re2c 1.1.1 on Sun Dec 23 19:24:34 2018 */ #line 1 "../src/ast/lex.re" #include "src/util/c99_stdint.h" #include @@ -33,7 +33,7 @@ namespace re2c { #line 55 "../src/ast/lex.re" -#line 112 "../src/ast/lex.re" +#line 113 "../src/ast/lex.re" Scanner::ParseMode Scanner::echo(Output &out) @@ -103,7 +103,7 @@ echo: } } ++YYCURSOR; -#line 202 "../src/ast/lex.re" +#line 203 "../src/ast/lex.re" { if (!is_eof()) goto echo; out.wraw(tok, ptr); @@ -113,7 +113,7 @@ echo: yy4: ++YYCURSOR; yy5: -#line 220 "../src/ast/lex.re" +#line 221 "../src/ast/lex.re" { goto echo; } #line 119 "src/ast/lex.cc" yy6: @@ -124,7 +124,7 @@ yy6: } if (yych == '#') goto yy14; yy7: -#line 214 "../src/ast/lex.re" +#line 215 "../src/ast/lex.re" { cline++; pos = cur; @@ -173,7 +173,7 @@ yy14: } yy16: ++YYCURSOR; -#line 123 "../src/ast/lex.re" +#line 124 "../src/ast/lex.re" { out.wraw(tok, ptr); return Parse; @@ -457,7 +457,7 @@ yy76: yy78: ++YYCURSOR; YYCURSOR = yyt1; -#line 208 "../src/ast/lex.re" +#line 209 "../src/ast/lex.re" { out.wraw(tok, ptr + 1); set_sourceline(); @@ -584,7 +584,7 @@ yy107: goto yy13; yy108: ++YYCURSOR; -#line 144 "../src/ast/lex.re" +#line 145 "../src/ast/lex.re" { out.wraw(tok, ptr); out.wdelay_yymaxfill(); @@ -614,7 +614,7 @@ yy114: goto yy13; yy115: ++YYCURSOR; -#line 133 "../src/ast/lex.re" +#line 134 "../src/ast/lex.re" { out.wraw(tok, ptr); return Reuse; @@ -670,7 +670,7 @@ yy128: goto yy13; yy129: ++YYCURSOR; -#line 180 "../src/ast/lex.re" +#line 181 "../src/ast/lex.re" { out.wraw(tok, ptr); lex_tags(out, true); @@ -679,7 +679,7 @@ yy129: #line 680 "src/ast/lex.cc" yy131: ++YYCURSOR; -#line 128 "../src/ast/lex.re" +#line 129 "../src/ast/lex.re" { out.wraw(tok, ptr); return Rules; @@ -687,7 +687,7 @@ yy131: #line 688 "src/ast/lex.cc" yy133: ++YYCURSOR; -#line 174 "../src/ast/lex.re" +#line 175 "../src/ast/lex.re" { out.wraw(tok, ptr); lex_tags(out, false); @@ -696,7 +696,7 @@ yy133: #line 697 "src/ast/lex.cc" yy135: ++YYCURSOR; -#line 165 "../src/ast/lex.re" +#line 166 "../src/ast/lex.re" { out.wraw(tok, ptr); out.wdelay_line_info_output(); @@ -716,7 +716,7 @@ yy138: goto yy13; yy139: ++YYCURSOR; -#line 138 "../src/ast/lex.re" +#line 139 "../src/ast/lex.re" { out.wraw(tok, ptr); lex_end_of_comment(out); @@ -741,7 +741,7 @@ yy144: goto yy13; yy145: ++YYCURSOR; -#line 158 "../src/ast/lex.re" +#line 159 "../src/ast/lex.re" { out.wraw(tok, ptr); out.wdelay_state_goto(0); @@ -764,7 +764,7 @@ yy149: goto yy13; yy150: ++YYCURSOR; -#line 186 "../src/ast/lex.re" +#line 187 "../src/ast/lex.re" { out.wraw(tok, ptr); out.header_mode(true); @@ -775,7 +775,7 @@ yy150: #line 776 "src/ast/lex.cc" yy152: ++YYCURSOR; -#line 151 "../src/ast/lex.re" +#line 152 "../src/ast/lex.re" { out.wraw(tok, ptr); out.wdelay_yymaxnmatch(); @@ -785,7 +785,7 @@ yy152: #line 786 "src/ast/lex.cc" yy154: ++YYCURSOR; -#line 194 "../src/ast/lex.re" +#line 195 "../src/ast/lex.re" { out.wraw(tok, ptr); out.header_mode(false); @@ -795,7 +795,7 @@ yy154: } #line 797 "src/ast/lex.cc" } -#line 221 "../src/ast/lex.re" +#line 222 "../src/ast/lex.re" } @@ -819,18 +819,18 @@ void Scanner::lex_end_of_comment(Output &out) } yy158: ++YYCURSOR; -#line 228 "../src/ast/lex.re" +#line 229 "../src/ast/lex.re" { fatal_lc(get_cline(), get_column(), "expected end of block"); } #line 825 "src/ast/lex.cc" yy160: ++YYCURSOR; yy161: -#line 230 "../src/ast/lex.re" +#line 231 "../src/ast/lex.re" { continue; } #line 831 "src/ast/lex.cc" yy162: ++YYCURSOR; -#line 231 "../src/ast/lex.re" +#line 232 "../src/ast/lex.re" { ++ignored; continue; } #line 836 "src/ast/lex.cc" yy164: @@ -841,7 +841,7 @@ yy165: yych = (YYCTYPE)*++YYCURSOR; if (yych != '/') goto yy161; ++YYCURSOR; -#line 232 "../src/ast/lex.re" +#line 233 "../src/ast/lex.re" { if (ignored > 0) { cline += ignored; @@ -852,7 +852,7 @@ yy165: } #line 854 "src/ast/lex.cc" } -#line 240 "../src/ast/lex.re" +#line 241 "../src/ast/lex.re" } } @@ -918,7 +918,7 @@ void Scanner::lex_tags(Output &out, bool mtags) } ++YYCURSOR; yy171: -#line 247 "../src/ast/lex.re" +#line 248 "../src/ast/lex.re" { fatal_lc(get_cline(), get_column(), "unrecognized configuration"); } #line 924 "src/ast/lex.cc" yy172: @@ -928,12 +928,12 @@ yy172: if (yybm[0+yych] & 128) { goto yy172; } -#line 252 "../src/ast/lex.re" +#line 253 "../src/ast/lex.re" { continue; } #line 934 "src/ast/lex.cc" yy175: ++YYCURSOR; -#line 253 "../src/ast/lex.re" +#line 254 "../src/ast/lex.re" { ++cline; continue; } #line 939 "src/ast/lex.cc" yy177: @@ -954,7 +954,7 @@ yy180: goto yy171; yy181: ++YYCURSOR; -#line 254 "../src/ast/lex.re" +#line 255 "../src/ast/lex.re" { out.wdelay_tags(new ConfTags(fmt, sep), mtags); tok = pos = cur; @@ -997,7 +997,7 @@ yy191: goto yy184; yy192: ++YYCURSOR; -#line 249 "../src/ast/lex.re" +#line 250 "../src/ast/lex.re" { fmt = lex_conf_string(); continue; } #line 1003 "src/ast/lex.cc" yy194: @@ -1008,11 +1008,11 @@ yy194: yych = (YYCTYPE)*++YYCURSOR; if (yych != 'r') goto yy184; ++YYCURSOR; -#line 250 "../src/ast/lex.re" +#line 251 "../src/ast/lex.re" { sep = lex_conf_string(); continue; } #line 1014 "src/ast/lex.cc" } -#line 259 "../src/ast/lex.re" +#line 260 "../src/ast/lex.re" } } @@ -1133,7 +1133,7 @@ scan: yy201: ++YYCURSOR; yy202: -#line 386 "../src/ast/lex.re" +#line 387 "../src/ast/lex.re" { fatal_lc(get_cline(), get_column(), "unexpected character: '%c'", *tok); goto scan; @@ -1146,7 +1146,7 @@ yy203: if (yybm[0+yych] & 16) { goto yy203; } -#line 367 "../src/ast/lex.re" +#line 368 "../src/ast/lex.re" { goto scan; } #line 1152 "src/ast/lex.cc" yy206: @@ -1159,7 +1159,7 @@ yy206: if (yych == '#') goto yy236; } yy207: -#line 374 "../src/ast/lex.re" +#line 375 "../src/ast/lex.re" { pos = cur; cline++; @@ -1178,7 +1178,7 @@ yy208: goto yy202; yy209: ++YYCURSOR; -#line 285 "../src/ast/lex.re" +#line 286 "../src/ast/lex.re" { yylval.regexp = lex_str('"'); return TOKEN_REGEXP; } #line 1184 "src/ast/lex.cc" yy211: @@ -1195,7 +1195,7 @@ yy211: yy212: ++YYCURSOR; yy213: -#line 295 "../src/ast/lex.re" +#line 296 "../src/ast/lex.re" { return *tok; } #line 1201 "src/ast/lex.cc" yy214: @@ -1204,7 +1204,7 @@ yy214: goto yy202; yy215: ++YYCURSOR; -#line 284 "../src/ast/lex.re" +#line 285 "../src/ast/lex.re" { yylval.regexp = lex_str('\''); return TOKEN_REGEXP; } #line 1210 "src/ast/lex.cc" yy217: @@ -1213,7 +1213,7 @@ yy217: goto yy213; yy218: ++YYCURSOR; -#line 362 "../src/ast/lex.re" +#line 363 "../src/ast/lex.re" { yylval.regexp = ast_dot(cline, get_column()); return TOKEN_REGEXP; @@ -1230,7 +1230,7 @@ yy221: goto yy202; yy222: ++YYCURSOR; -#line 277 "../src/ast/lex.re" +#line 278 "../src/ast/lex.re" { return lex_clist(); } #line 1236 "src/ast/lex.cc" yy224: @@ -1246,7 +1246,7 @@ yy226: if (yybm[0+yych] & 32) { goto yy225; } -#line 339 "../src/ast/lex.re" +#line 340 "../src/ast/lex.re" { if (!globopts->FFlag || lex_namedef_context_re2c()) { yylval.str = new std::string (tok, tok_len()); @@ -1273,7 +1273,7 @@ yy226: yy228: yych = (YYCTYPE)*++YYCURSOR; if (yych == '^') goto yy251; -#line 286 "../src/ast/lex.re" +#line 287 "../src/ast/lex.re" { yylval.regexp = lex_cls(false); return TOKEN_REGEXP; } #line 1279 "src/ast/lex.cc" yy230: @@ -1298,7 +1298,7 @@ yy231: } } yy232: -#line 269 "../src/ast/lex.re" +#line 270 "../src/ast/lex.re" { lex_code_in_braces(); return TOKEN_CODE; } #line 1304 "src/ast/lex.cc" yy233: @@ -1359,7 +1359,7 @@ yy238: } } yy240: -#line 289 "../src/ast/lex.re" +#line 290 "../src/ast/lex.re" { const std::string *name = new std::string(tok + 1, tok_len() - 1); yylval.regexp = ast_tag(cline, get_column(), name, tok[0] == '#'); @@ -1368,17 +1368,17 @@ yy240: #line 1369 "src/ast/lex.cc" yy241: ++YYCURSOR; -#line 282 "../src/ast/lex.re" +#line 283 "../src/ast/lex.re" { tok = cur; return 0; } #line 1374 "src/ast/lex.cc" yy243: ++YYCURSOR; -#line 280 "../src/ast/lex.re" +#line 281 "../src/ast/lex.re" { lex_c_comment(); goto scan; } #line 1379 "src/ast/lex.cc" yy245: ++YYCURSOR; -#line 279 "../src/ast/lex.re" +#line 280 "../src/ast/lex.re" { lex_cpp_comment(); goto scan; } #line 1384 "src/ast/lex.cc" yy247: @@ -1386,7 +1386,7 @@ yy247: yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); if (yych == '>') goto yy249; yy248: -#line 270 "../src/ast/lex.re" +#line 271 "../src/ast/lex.re" { lex_code_indented(); return TOKEN_CODE; } #line 1392 "src/ast/lex.cc" yy249: @@ -1421,7 +1421,7 @@ yy249: } yy251: ++YYCURSOR; -#line 287 "../src/ast/lex.re" +#line 288 "../src/ast/lex.re" { yylval.regexp = lex_cls(true); return TOKEN_REGEXP; } #line 1427 "src/ast/lex.cc" yy253: @@ -1431,7 +1431,7 @@ yy253: yy254: ++YYCURSOR; yy255: -#line 323 "../src/ast/lex.re" +#line 324 "../src/ast/lex.re" { fatal_lc(get_cline(), get_column(), "illegal closure form, use '{n}', '{n,}', '{n,m}' where n and m are numbers"); @@ -1494,7 +1494,7 @@ yy261: } yy263: p = yyt1; -#line 272 "../src/ast/lex.re" +#line 273 "../src/ast/lex.re" { yylval.str = new std::string(p, static_cast(cur - p)); return tok[0] == ':' ? TOKEN_CJUMP : TOKEN_CNEXT; @@ -1513,7 +1513,7 @@ yy265: goto yy255; yy266: ++YYCURSOR; -#line 297 "../src/ast/lex.re" +#line 298 "../src/ast/lex.re" { if (!s_to_u32_unsafe (tok + 1, cur - 1, yylval.bounds.min)) { fatal_lc(get_cline(), get_column(), "repetition count overflow"); @@ -1524,7 +1524,7 @@ yy266: #line 1525 "src/ast/lex.cc" yy268: ++YYCURSOR; -#line 328 "../src/ast/lex.re" +#line 329 "../src/ast/lex.re" { if (!globopts->FFlag) { fatal_lc(get_cline(), get_column(), @@ -1552,7 +1552,7 @@ yy272: goto yy235; yy274: ++YYCURSOR; -#line 315 "../src/ast/lex.re" +#line 316 "../src/ast/lex.re" { if (!s_to_u32_unsafe (tok + 1, cur - 2, yylval.bounds.min)) { fatal_lc(get_cline(), get_column(), "repetition lower bound overflow"); @@ -1567,13 +1567,13 @@ yy276: goto yy235; yy277: ++YYCURSOR; -#line 337 "../src/ast/lex.re" +#line 338 "../src/ast/lex.re" { return TOKEN_CONF; } #line 1573 "src/ast/lex.cc" yy279: ++YYCURSOR; p = yyt1; -#line 305 "../src/ast/lex.re" +#line 306 "../src/ast/lex.re" { if (!s_to_u32_unsafe (tok + 1, p, yylval.bounds.min)) { fatal_lc(get_cline(), get_column(), "repetition lower bound overflow"); @@ -1639,7 +1639,7 @@ yy286: yy288: ++YYCURSOR; YYCURSOR = yyt1; -#line 369 "../src/ast/lex.re" +#line 370 "../src/ast/lex.re" { set_sourceline (); return TOKEN_LINE_INFO; @@ -1670,7 +1670,7 @@ yy294: if (yych == '\n') goto yy235; goto yy291; } -#line 390 "../src/ast/lex.re" +#line 391 "../src/ast/lex.re" } @@ -1732,7 +1732,7 @@ bool Scanner::lex_namedef_context_re2c() } } yy297: -#line 397 "../src/ast/lex.re" +#line 398 "../src/ast/lex.re" { return false; } #line 1738 "src/ast/lex.cc" yy298: @@ -1751,11 +1751,11 @@ yy301: if (yych == '>') goto yy300; ++YYCURSOR; YYCURSOR = yyt1; -#line 396 "../src/ast/lex.re" +#line 397 "../src/ast/lex.re" { return true; } #line 1757 "src/ast/lex.cc" } -#line 398 "../src/ast/lex.re" +#line 399 "../src/ast/lex.re" } @@ -1809,7 +1809,7 @@ bool Scanner::lex_namedef_context_flex() yyt1 = YYCURSOR; goto yy307; } -#line 406 "../src/ast/lex.re" +#line 407 "../src/ast/lex.re" { return false; } #line 1815 "src/ast/lex.cc" yy307: @@ -1826,17 +1826,17 @@ yy307: if (yych == '{') goto yy310; } YYCURSOR = yyt1; -#line 405 "../src/ast/lex.re" +#line 406 "../src/ast/lex.re" { return true; } #line 1832 "src/ast/lex.cc" yy310: ++YYCURSOR; YYCURSOR = yyt1; -#line 404 "../src/ast/lex.re" +#line 405 "../src/ast/lex.re" { return false; } #line 1838 "src/ast/lex.cc" } -#line 407 "../src/ast/lex.re" +#line 408 "../src/ast/lex.re" } @@ -1895,7 +1895,7 @@ yy312: if (yych <= '!') goto yy316; if (yych == '>') goto yy319; yy315: -#line 417 "../src/ast/lex.re" +#line 418 "../src/ast/lex.re" { goto cond; } #line 1901 "src/ast/lex.cc" yy316: @@ -1904,16 +1904,16 @@ yy316: yych = (YYCTYPE)*YYCURSOR; if (yych == '\t') goto yy316; if (yych == ' ') goto yy316; -#line 415 "../src/ast/lex.re" +#line 416 "../src/ast/lex.re" { kind = TOKEN_CSETUP; goto cond; } #line 1910 "src/ast/lex.cc" yy319: ++YYCURSOR; -#line 416 "../src/ast/lex.re" +#line 417 "../src/ast/lex.re" { kind = TOKEN_CZERO; goto end; } #line 1915 "src/ast/lex.cc" } -#line 418 "../src/ast/lex.re" +#line 419 "../src/ast/lex.re" cond: tok = cur; @@ -1970,12 +1970,12 @@ cond: } yy323: ++YYCURSOR; -#line 424 "../src/ast/lex.re" +#line 425 "../src/ast/lex.re" { goto error; } #line 1976 "src/ast/lex.cc" yy325: ++YYCURSOR; -#line 423 "../src/ast/lex.re" +#line 424 "../src/ast/lex.re" { if (!cl->empty()) goto error; cl->insert("*"); goto next; } #line 1981 "src/ast/lex.cc" yy327: @@ -1985,11 +1985,11 @@ yy327: if (yybm[0+yych] & 128) { goto yy327; } -#line 422 "../src/ast/lex.re" +#line 423 "../src/ast/lex.re" { cl->insert(std::string(tok, tok_len())); goto next; } #line 1991 "src/ast/lex.cc" } -#line 425 "../src/ast/lex.re" +#line 426 "../src/ast/lex.re" next: @@ -2044,7 +2044,7 @@ next: } ++YYCURSOR; yy333: -#line 430 "../src/ast/lex.re" +#line 431 "../src/ast/lex.re" { goto error; } #line 2050 "src/ast/lex.cc" yy334: @@ -2068,12 +2068,12 @@ yy335: if (yybm[0+yych] & 128) { goto yy335; } -#line 428 "../src/ast/lex.re" +#line 429 "../src/ast/lex.re" { goto cond; } #line 2074 "src/ast/lex.cc" yy338: ++YYCURSOR; -#line 429 "../src/ast/lex.re" +#line 430 "../src/ast/lex.re" { goto end; } #line 2079 "src/ast/lex.cc" yy340: @@ -2093,7 +2093,7 @@ yy340: YYCURSOR = YYMARKER; goto yy333; } -#line 431 "../src/ast/lex.re" +#line 432 "../src/ast/lex.re" end: yylval.clist = cl; @@ -2137,13 +2137,13 @@ code: } yy345: ++YYCURSOR; -#line 454 "../src/ast/lex.re" +#line 455 "../src/ast/lex.re" { fail_if_eof(); goto code; } #line 2143 "src/ast/lex.cc" yy347: ++YYCURSOR; yy348: -#line 459 "../src/ast/lex.re" +#line 460 "../src/ast/lex.re" { goto code; } #line 2149 "src/ast/lex.cc" yy349: @@ -2156,7 +2156,7 @@ yy349: if (yych == ' ') goto yy357; } yy350: -#line 447 "../src/ast/lex.re" +#line 448 "../src/ast/lex.re" { while (isspace(tok[0])) ++tok; while (cur > tok && isspace(cur[-1])) --cur; @@ -2170,7 +2170,7 @@ yy351: goto yy348; yy352: ++YYCURSOR; -#line 458 "../src/ast/lex.re" +#line 459 "../src/ast/lex.re" { lex_string(cur[-1]); goto code; } #line 2176 "src/ast/lex.cc" yy354: @@ -2180,27 +2180,27 @@ yy354: goto yy348; yy355: ++YYCURSOR; -#line 455 "../src/ast/lex.re" +#line 456 "../src/ast/lex.re" { fatal_l(get_cline(), "Curly braces are not allowed after ':='"); } #line 2186 "src/ast/lex.cc" yy357: ++YYCURSOR; YYCURSOR -= 1; -#line 446 "../src/ast/lex.re" +#line 447 "../src/ast/lex.re" { goto code; } #line 2192 "src/ast/lex.cc" yy359: ++YYCURSOR; -#line 456 "../src/ast/lex.re" +#line 457 "../src/ast/lex.re" { lex_c_comment(); goto code; } #line 2197 "src/ast/lex.cc" yy361: ++YYCURSOR; -#line 457 "../src/ast/lex.re" +#line 458 "../src/ast/lex.re" { lex_cpp_comment(); goto code; } #line 2202 "src/ast/lex.cc" } -#line 460 "../src/ast/lex.re" +#line 461 "../src/ast/lex.re" } @@ -2272,13 +2272,13 @@ code: } yy365: ++YYCURSOR; -#line 480 "../src/ast/lex.re" +#line 481 "../src/ast/lex.re" { fail_if_eof(); goto code; } #line 2278 "src/ast/lex.cc" yy367: ++YYCURSOR; yy368: -#line 484 "../src/ast/lex.re" +#line 485 "../src/ast/lex.re" { goto code; } #line 2284 "src/ast/lex.cc" yy369: @@ -2288,7 +2288,7 @@ yy369: } if (yych == '#') goto yy382; yy370: -#line 479 "../src/ast/lex.re" +#line 480 "../src/ast/lex.re" { pos = cur; cline++; goto code; } #line 2294 "src/ast/lex.cc" yy371: @@ -2297,7 +2297,7 @@ yy371: goto yy368; yy372: ++YYCURSOR; -#line 483 "../src/ast/lex.re" +#line 484 "../src/ast/lex.re" { lex_string(cur[-1]); goto code; } #line 2303 "src/ast/lex.cc" yy374: @@ -2307,12 +2307,12 @@ yy374: goto yy368; yy375: ++YYCURSOR; -#line 477 "../src/ast/lex.re" +#line 478 "../src/ast/lex.re" { ++depth; goto code; } #line 2313 "src/ast/lex.cc" yy377: ++YYCURSOR; -#line 469 "../src/ast/lex.re" +#line 470 "../src/ast/lex.re" { if (--depth == 0) { yylval.code = new Code(get_fname (), line, tok, tok_len ()); @@ -2346,12 +2346,12 @@ yy382: } yy384: ++YYCURSOR; -#line 481 "../src/ast/lex.re" +#line 482 "../src/ast/lex.re" { lex_c_comment(); goto code; } #line 2352 "src/ast/lex.cc" yy386: ++YYCURSOR; -#line 482 "../src/ast/lex.re" +#line 483 "../src/ast/lex.re" { lex_cpp_comment(); goto code; } #line 2357 "src/ast/lex.cc" yy388: @@ -2410,7 +2410,7 @@ yy396: yy398: ++YYCURSOR; YYCURSOR = yyt1; -#line 478 "../src/ast/lex.re" +#line 479 "../src/ast/lex.re" { set_sourceline (); goto code; } #line 2416 "src/ast/lex.cc" yy400: @@ -2438,7 +2438,7 @@ yy404: if (yych == '\n') goto yy381; goto yy401; } -#line 485 "../src/ast/lex.re" +#line 486 "../src/ast/lex.re" } @@ -2472,18 +2472,18 @@ loop: } yy407: ++YYCURSOR; -#line 495 "../src/ast/lex.re" +#line 496 "../src/ast/lex.re" { fail_if_eof(); goto loop; } #line 2478 "src/ast/lex.cc" yy409: ++YYCURSOR; yy410: -#line 496 "../src/ast/lex.re" +#line 497 "../src/ast/lex.re" { goto loop; } #line 2484 "src/ast/lex.cc" yy411: ++YYCURSOR; -#line 494 "../src/ast/lex.re" +#line 495 "../src/ast/lex.re" { pos = cur; ++cline; goto loop; } #line 2489 "src/ast/lex.cc" yy413: @@ -2492,7 +2492,7 @@ yy413: goto yy410; yy414: ++YYCURSOR; -#line 492 "../src/ast/lex.re" +#line 493 "../src/ast/lex.re" { if (cur[-1] == delim) return; else goto loop; } #line 2498 "src/ast/lex.cc" yy416: @@ -2505,11 +2505,11 @@ yy416: } yy417: ++YYCURSOR; -#line 493 "../src/ast/lex.re" +#line 494 "../src/ast/lex.re" { goto loop; } #line 2511 "src/ast/lex.cc" } -#line 497 "../src/ast/lex.re" +#line 498 "../src/ast/lex.re" } @@ -2533,18 +2533,18 @@ loop: } yy421: ++YYCURSOR; -#line 506 "../src/ast/lex.re" +#line 507 "../src/ast/lex.re" { fail_if_eof(); goto loop; } #line 2539 "src/ast/lex.cc" yy423: ++YYCURSOR; yy424: -#line 507 "../src/ast/lex.re" +#line 508 "../src/ast/lex.re" { goto loop; } #line 2545 "src/ast/lex.cc" yy425: ++YYCURSOR; -#line 505 "../src/ast/lex.re" +#line 506 "../src/ast/lex.re" { pos = cur; ++cline; goto loop; } #line 2550 "src/ast/lex.cc" yy427: @@ -2555,11 +2555,11 @@ yy428: yych = (YYCTYPE)*++YYCURSOR; if (yych != '/') goto yy424; ++YYCURSOR; -#line 504 "../src/ast/lex.re" +#line 505 "../src/ast/lex.re" { return; } #line 2561 "src/ast/lex.cc" } -#line 508 "../src/ast/lex.re" +#line 509 "../src/ast/lex.re" } @@ -2582,18 +2582,18 @@ loop: } yy433: ++YYCURSOR; -#line 516 "../src/ast/lex.re" +#line 517 "../src/ast/lex.re" { fail_if_eof(); goto loop; } #line 2588 "src/ast/lex.cc" yy435: ++YYCURSOR; yy436: -#line 517 "../src/ast/lex.re" +#line 518 "../src/ast/lex.re" { goto loop; } #line 2594 "src/ast/lex.cc" yy437: ++YYCURSOR; -#line 515 "../src/ast/lex.re" +#line 516 "../src/ast/lex.re" { pos = cur; ++cline; return; } #line 2599 "src/ast/lex.cc" yy439: @@ -2601,7 +2601,7 @@ yy439: if (yych == '\n') goto yy437; goto yy436; } -#line 518 "../src/ast/lex.re" +#line 519 "../src/ast/lex.re" } @@ -2619,16 +2619,16 @@ fst: if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = (YYCTYPE)*YYCURSOR; if (yych == ']') goto yy443; -#line 530 "../src/ast/lex.re" +#line 531 "../src/ast/lex.re" { l = lex_cls_chr(); goto snd; } #line 2625 "src/ast/lex.cc" yy443: ++YYCURSOR; -#line 529 "../src/ast/lex.re" +#line 530 "../src/ast/lex.re" { return ast_cls(cline, c0, cls, neg); } #line 2630 "src/ast/lex.cc" } -#line 531 "../src/ast/lex.re" +#line 532 "../src/ast/lex.re" snd: @@ -2639,7 +2639,7 @@ snd: yych = (YYCTYPE)*(YYMARKER = YYCURSOR); if (yych == '-') goto yy448; yy447: -#line 534 "../src/ast/lex.re" +#line 535 "../src/ast/lex.re" { u = l; goto add; } #line 2645 "src/ast/lex.cc" yy448: @@ -2650,7 +2650,7 @@ yy448: yy450: ++YYCURSOR; YYCURSOR -= 1; -#line 535 "../src/ast/lex.re" +#line 536 "../src/ast/lex.re" { u = lex_cls_chr(); if (l > u) { @@ -2661,7 +2661,7 @@ yy450: } #line 2663 "src/ast/lex.cc" } -#line 543 "../src/ast/lex.re" +#line 544 "../src/ast/lex.re" add: cls->push_back(ASTRange(l, u, c)); @@ -2690,18 +2690,18 @@ uint32_t Scanner::lex_cls_chr() } yy454: ++YYCURSOR; -#line 555 "../src/ast/lex.re" +#line 556 "../src/ast/lex.re" { fail_if_eof(); return 0; } #line 2696 "src/ast/lex.cc" yy456: ++YYCURSOR; yy457: -#line 561 "../src/ast/lex.re" +#line 562 "../src/ast/lex.re" { return static_cast(tok[0]); } #line 2702 "src/ast/lex.cc" yy458: ++YYCURSOR; -#line 556 "../src/ast/lex.re" +#line 557 "../src/ast/lex.re" { fatal_lc(l, c, "newline in character class"); } #line 2707 "src/ast/lex.cc" yy460: @@ -2762,13 +2762,13 @@ yy461: } } yy462: -#line 559 "../src/ast/lex.re" +#line 560 "../src/ast/lex.re" { fatal_lc(l, c, "syntax error in escape sequence"); } #line 2768 "src/ast/lex.cc" yy463: ++YYCURSOR; yy464: -#line 574 "../src/ast/lex.re" +#line 575 "../src/ast/lex.re" { warn.useless_escape(cline, get_column(), tok[1]); return static_cast(tok[1]); @@ -2780,7 +2780,7 @@ yy465: goto yy464; yy466: ++YYCURSOR; -#line 572 "../src/ast/lex.re" +#line 573 "../src/ast/lex.re" { return static_cast('-'); } #line 2786 "src/ast/lex.cc" yy468: @@ -2789,7 +2789,7 @@ yy468: if (yych <= '/') goto yy469; if (yych <= '7') goto yy493; yy469: -#line 558 "../src/ast/lex.re" +#line 559 "../src/ast/lex.re" { fatal_lc(l, c, "syntax error in octal escape sequence"); } #line 2795 "src/ast/lex.cc" yy470: @@ -2807,7 +2807,7 @@ yy471: if (yych <= 'f') goto yy495; } yy472: -#line 557 "../src/ast/lex.re" +#line 558 "../src/ast/lex.re" { fatal_lc(l, c, "syntax error in hexadecimal escape sequence"); } #line 2813 "src/ast/lex.cc" yy473: @@ -2825,47 +2825,47 @@ yy473: } yy474: ++YYCURSOR; -#line 571 "../src/ast/lex.re" +#line 572 "../src/ast/lex.re" { return static_cast('\\'); } #line 2831 "src/ast/lex.cc" yy476: ++YYCURSOR; -#line 573 "../src/ast/lex.re" +#line 574 "../src/ast/lex.re" { return static_cast(']'); } #line 2836 "src/ast/lex.cc" yy478: ++YYCURSOR; -#line 564 "../src/ast/lex.re" +#line 565 "../src/ast/lex.re" { return static_cast('\a'); } #line 2841 "src/ast/lex.cc" yy480: ++YYCURSOR; -#line 565 "../src/ast/lex.re" +#line 566 "../src/ast/lex.re" { return static_cast('\b'); } #line 2846 "src/ast/lex.cc" yy482: ++YYCURSOR; -#line 566 "../src/ast/lex.re" +#line 567 "../src/ast/lex.re" { return static_cast('\f'); } #line 2851 "src/ast/lex.cc" yy484: ++YYCURSOR; -#line 567 "../src/ast/lex.re" +#line 568 "../src/ast/lex.re" { return static_cast('\n'); } #line 2856 "src/ast/lex.cc" yy486: ++YYCURSOR; -#line 568 "../src/ast/lex.re" +#line 569 "../src/ast/lex.re" { return static_cast('\r'); } #line 2861 "src/ast/lex.cc" yy488: ++YYCURSOR; -#line 569 "../src/ast/lex.re" +#line 570 "../src/ast/lex.re" { return static_cast('\t'); } #line 2866 "src/ast/lex.cc" yy490: ++YYCURSOR; -#line 570 "../src/ast/lex.re" +#line 571 "../src/ast/lex.re" { return static_cast('\v'); } #line 2871 "src/ast/lex.cc" yy492: @@ -2930,7 +2930,7 @@ yy497: } yy498: ++YYCURSOR; -#line 563 "../src/ast/lex.re" +#line 564 "../src/ast/lex.re" { return unesc_oct(tok, cur); } #line 2936 "src/ast/lex.cc" yy500: @@ -2959,7 +2959,7 @@ yy501: } yy502: ++YYCURSOR; -#line 562 "../src/ast/lex.re" +#line 563 "../src/ast/lex.re" { return unesc_hex(tok, cur); } #line 2965 "src/ast/lex.cc" yy504: @@ -2985,7 +2985,7 @@ yy505: goto yy494; } } -#line 578 "../src/ast/lex.re" +#line 579 "../src/ast/lex.re" } @@ -3012,13 +3012,13 @@ uint32_t Scanner::lex_str_chr(char quote, bool &end) } yy508: ++YYCURSOR; -#line 588 "../src/ast/lex.re" +#line 589 "../src/ast/lex.re" { fail_if_eof(); return 0; } #line 3018 "src/ast/lex.cc" yy510: ++YYCURSOR; yy511: -#line 594 "../src/ast/lex.re" +#line 595 "../src/ast/lex.re" { end = tok[0] == quote; return static_cast(tok[0]); @@ -3026,7 +3026,7 @@ yy511: #line 3027 "src/ast/lex.cc" yy512: ++YYCURSOR; -#line 589 "../src/ast/lex.re" +#line 590 "../src/ast/lex.re" { fatal_lc(l, c, "newline in character string"); } #line 3032 "src/ast/lex.cc" yy514: @@ -3082,13 +3082,13 @@ yy515: } } yy516: -#line 592 "../src/ast/lex.re" +#line 593 "../src/ast/lex.re" { fatal_lc(l, c, "syntax error in escape sequence"); } #line 3088 "src/ast/lex.cc" yy517: ++YYCURSOR; yy518: -#line 608 "../src/ast/lex.re" +#line 609 "../src/ast/lex.re" { if (tok[1] != quote) { warn.useless_escape(cline, get_column(), tok[1]); @@ -3106,7 +3106,7 @@ yy520: if (yych <= '/') goto yy521; if (yych <= '7') goto yy543; yy521: -#line 591 "../src/ast/lex.re" +#line 592 "../src/ast/lex.re" { fatal_lc(l, c, "syntax error in octal escape sequence"); } #line 3112 "src/ast/lex.cc" yy522: @@ -3124,7 +3124,7 @@ yy523: if (yych <= 'f') goto yy545; } yy524: -#line 590 "../src/ast/lex.re" +#line 591 "../src/ast/lex.re" { fatal_lc(l, c, "syntax error in hexadecimal escape sequence"); } #line 3130 "src/ast/lex.cc" yy525: @@ -3142,42 +3142,42 @@ yy525: } yy526: ++YYCURSOR; -#line 607 "../src/ast/lex.re" +#line 608 "../src/ast/lex.re" { return static_cast('\\'); } #line 3148 "src/ast/lex.cc" yy528: ++YYCURSOR; -#line 600 "../src/ast/lex.re" +#line 601 "../src/ast/lex.re" { return static_cast('\a'); } #line 3153 "src/ast/lex.cc" yy530: ++YYCURSOR; -#line 601 "../src/ast/lex.re" +#line 602 "../src/ast/lex.re" { return static_cast('\b'); } #line 3158 "src/ast/lex.cc" yy532: ++YYCURSOR; -#line 602 "../src/ast/lex.re" +#line 603 "../src/ast/lex.re" { return static_cast('\f'); } #line 3163 "src/ast/lex.cc" yy534: ++YYCURSOR; -#line 603 "../src/ast/lex.re" +#line 604 "../src/ast/lex.re" { return static_cast('\n'); } #line 3168 "src/ast/lex.cc" yy536: ++YYCURSOR; -#line 604 "../src/ast/lex.re" +#line 605 "../src/ast/lex.re" { return static_cast('\r'); } #line 3173 "src/ast/lex.cc" yy538: ++YYCURSOR; -#line 605 "../src/ast/lex.re" +#line 606 "../src/ast/lex.re" { return static_cast('\t'); } #line 3178 "src/ast/lex.cc" yy540: ++YYCURSOR; -#line 606 "../src/ast/lex.re" +#line 607 "../src/ast/lex.re" { return static_cast('\v'); } #line 3183 "src/ast/lex.cc" yy542: @@ -3242,7 +3242,7 @@ yy547: } yy548: ++YYCURSOR; -#line 599 "../src/ast/lex.re" +#line 600 "../src/ast/lex.re" { return unesc_oct(tok, cur); } #line 3248 "src/ast/lex.cc" yy550: @@ -3271,7 +3271,7 @@ yy551: } yy552: ++YYCURSOR; -#line 598 "../src/ast/lex.re" +#line 599 "../src/ast/lex.re" { return unesc_hex(tok, cur); } #line 3277 "src/ast/lex.cc" yy554: @@ -3297,7 +3297,7 @@ yy555: goto yy544; } } -#line 614 "../src/ast/lex.re" +#line 615 "../src/ast/lex.re" } @@ -3375,18 +3375,18 @@ sourceline: } } ++YYCURSOR; -#line 647 "../src/ast/lex.re" +#line 649 "../src/ast/lex.re" { --cur; return; } #line 3381 "src/ast/lex.cc" yy560: ++YYCURSOR; yy561: -#line 648 "../src/ast/lex.re" +#line 650 "../src/ast/lex.re" { goto sourceline; } #line 3387 "src/ast/lex.cc" yy562: ++YYCURSOR; -#line 646 "../src/ast/lex.re" +#line 648 "../src/ast/lex.re" { tok = cur; return; } #line 3392 "src/ast/lex.cc" yy564: @@ -3405,7 +3405,7 @@ yy566: if (yybm[0+yych] & 64) { goto yy566; } -#line 633 "../src/ast/lex.re" +#line 634 "../src/ast/lex.re" { if (!s_to_u32_unsafe (tok, cur, cline)) { fatal_lc(get_cline(), get_column(), "line number overflow"); @@ -3429,13 +3429,14 @@ yy571: goto yy561; yy572: ++YYCURSOR; -#line 640 "../src/ast/lex.re" +#line 641 "../src/ast/lex.re" { - in.escaped_file_name = std::string (tok + 1, tok_len () - 2); // strip quotes - strrreplace (in.escaped_file_name, "\\", "\\\\"); + std::string &name = files.top()->escaped_name; + name = std::string(tok + 1, tok_len () - 2); // strip quotes + strrreplace(name, "\\", "\\\\"); goto sourceline; } -#line 3439 "src/ast/lex.cc" +#line 3440 "src/ast/lex.cc" yy574: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -3444,7 +3445,7 @@ yy574: if (yych == '\n') goto yy571; goto yy569; } -#line 649 "../src/ast/lex.re" +#line 651 "../src/ast/lex.re" } diff --git a/re2c/bootstrap/src/ast/lex.h b/re2c/bootstrap/src/ast/lex.h index f83447c0..762da47f 100644 --- a/re2c/bootstrap/src/ast/lex.h +++ b/re2c/bootstrap/src/ast/lex.h @@ -1,6 +1,7 @@ -/* Generated by re2c 1.1.1 on Sat Dec 22 19:57:50 2018 */ +/* Generated by re2c 1.1.1 on Sun Dec 23 19:24:34 2018 */ #include +#include "src/util/forbid_copy.h" namespace re2c { diff --git a/re2c/src/ast/input.cc b/re2c/src/ast/input.cc index b7073ec8..64853b1e 100644 --- a/re2c/src/ast/input.cc +++ b/re2c/src/ast/input.cc @@ -1,33 +1,28 @@ #include "src/ast/input.h" +#include "src/conf/msg.h" #include "src/util/string_utils.h" namespace re2c { -Input::Input (const char * fn) - : file (NULL) - , file_name (fn) - , escaped_file_name (fn) -{ - strrreplace (escaped_file_name, "\\", "\\\\"); -} +Input::Input(): file(NULL), name(), escaped_name() {} -bool Input::open () +bool Input::open(const char *filename) { - if (file_name == "") - { - file = stdin; - } - else - { - file = fopen (file_name.c_str (), "rb"); + name = escaped_name = filename; + strrreplace(escaped_name, "\\", "\\\\"); + + file = name == "" ? stdin : fopen(name.c_str(), "rb"); + if (!file) { + error("cannot open source file: %s", name.c_str()); + return false; } - return file != NULL; + + return true; } -Input::~Input () +Input::~Input() { - if (file != NULL && file != stdin) - { + if (file != NULL && file != stdin) { fclose (file); } } diff --git a/re2c/src/ast/input.h b/re2c/src/ast/input.h index 1da3dfc8..7c7131fc 100644 --- a/re2c/src/ast/input.h +++ b/re2c/src/ast/input.h @@ -3,22 +3,21 @@ #include #include - #include "src/util/forbid_copy.h" namespace re2c { struct Input { - FILE * file; - const std::string file_name; - std::string escaped_file_name; + FILE *file; + std::string name; + std::string escaped_name; - explicit Input (const char * fn); - ~Input (); - bool open (); + Input(); + ~Input(); + bool open(const char *filename); - FORBID_COPY (Input); + FORBID_COPY(Input); }; } // namespace re2c diff --git a/re2c/src/ast/lex.re b/re2c/src/ast/lex.re index 3d433f08..5021783a 100644 --- a/re2c/src/ast/lex.re +++ b/re2c/src/ast/lex.re @@ -56,6 +56,7 @@ namespace re2c { /*!header:re2c:on*/ #include +#include "src/util/forbid_copy.h" namespace re2c { @@ -638,8 +639,9 @@ sourceline: } dstring { - in.escaped_file_name = std::string (tok + 1, tok_len () - 2); // strip quotes - strrreplace (in.escaped_file_name, "\\", "\\\\"); + std::string &name = files.top()->escaped_name; + name = std::string(tok + 1, tok_len () - 2); // strip quotes + strrreplace(name, "\\", "\\\\"); goto sourceline; } diff --git a/re2c/src/ast/scanner.cc b/re2c/src/ast/scanner.cc index b50383c4..b128880d 100644 --- a/re2c/src/ast/scanner.cc +++ b/re2c/src/ast/scanner.cc @@ -9,7 +9,55 @@ namespace re2c { class Warn; -Scanner::Scanner(Input &i, Warn &w): ScannerState(), in(i), warn(w) {} +Scanner::Scanner(Warn &w) + : ScannerState() + , files() + , warn(w) +{} + +Scanner::~Scanner() +{ + for (; !files.empty(); ) { + delete files.top(); + files.pop(); + } +} + +bool Scanner::push_file(const char *filename) +{ + // push buffer tail back to file - we'll return to it later + if (!files.empty()) { + int err = fseek(files.top()->file, lim - cur, SEEK_CUR); + if (err != 0) return false; + } + + // open new file and place place at the top of stack + Input *f = new Input; + files.push(f); + if (!f->open(filename)) return false; + + // refill buffer + return fill(BSIZE); +} + +bool Scanner::read(size_t want) +{ + const char *stop = lim + want; + assert(!files.empty()); + for (;;) { + Input *f = files.top(); + lim += fread(lim, 1, want, f->file); + + // buffer filled + if (lim == stop) return true; + + // the first file must remain at the bottom of the stack + if (files.size() == 1) break; + delete f; + files.pop(); + } + return false; +} bool Scanner::fill(size_t need) { @@ -36,8 +84,7 @@ bool Scanner::fill(size_t need) free = BSIZE - copy; } - lim += fread(lim, 1, free, in.file); - if (lim < bot + BSIZE) { + if (!read(free)) { eof = lim; memset(lim, 0, YYMAXFILL); lim += YYMAXFILL; diff --git a/re2c/src/ast/scanner.h b/re2c/src/ast/scanner.h index 1b746fb8..bfe39c07 100644 --- a/re2c/src/ast/scanner.h +++ b/re2c/src/ast/scanner.h @@ -4,6 +4,7 @@ #include #include "src/util/c99_stdint.h" #include +#include #include #include "src/ast/input.h" @@ -26,9 +27,26 @@ struct AST; class Scanner: private ScannerState { - Input & in; +public: + enum ParseMode {Stop, Parse, Reuse, Rules}; + +private: + std::stack files; Warn &warn; +public: + explicit Scanner(Warn &w); + ~Scanner(); + bool push_file(const char *filename); + ParseMode echo(Output &out); + int scan(const conopt_t *globopts); + void lex_conf(Opt &opts); + uint32_t get_cline() const; + uint32_t get_column() const; + const std::string & get_fname () const; + +private: + bool read(size_t want); bool fill(size_t need); void lex_end_of_comment(Output &out); void lex_code_indented(); @@ -59,16 +77,6 @@ class Scanner: private ScannerState bool is_eof() const; void fail_if_eof() const; -public: - enum ParseMode {Stop, Parse, Reuse, Rules}; - - Scanner(Input&, Warn &w); - ParseMode echo(Output &out); - int scan(const conopt_t *globopts); - void lex_conf(Opt &opts); - uint32_t get_cline() const; - uint32_t get_column() const; - const std::string & get_fname () const; FORBID_COPY (Scanner); }; @@ -80,7 +88,7 @@ inline size_t Scanner::tok_len () const inline const std::string & Scanner::get_fname () const { - return in.escaped_file_name; + return files.top()->escaped_name; } inline uint32_t Scanner::get_cline() const diff --git a/re2c/src/main.cc b/re2c/src/main.cc index 999ffed7..ffeb569a 100644 --- a/re2c/src/main.cc +++ b/re2c/src/main.cc @@ -2,7 +2,6 @@ #include "src/ast/scanner.h" #include "src/code/output.h" #include "src/compile.h" -#include "src/conf/msg.h" #include "src/conf/opt.h" #include "src/conf/warn.h" @@ -20,12 +19,9 @@ int main(int, char *argv[]) case EXIT_FAIL: return 1; } - re2c::Input input(opts.source_file); - if (!input.open()) { - error("cannot open source file: %s", opts.source_file); - return 1; - } - Scanner scanner(input, warn); + Scanner scanner(warn); + if (!scanner.push_file(opts.source_file)) return 1; + Output output(warn); compile(scanner, output, opts);