| @@ -43,7 +43,8 @@ · 42 unmodified lines |
| 43 | 43 | |
| 44 | 44 | #include "libtcc.h" |
| 45 | 45 | |
| 46 | | −//#define DEBUG |
| 46 | +/* parser debug */ |
| 47 | +//#define PARSE_DEBUG |
| 47 | 48 | /* preprocessor debug */ |
| 48 | 49 | //#define PP_DEBUG |
| 49 | 50 | /* include file debug */ |
| @@ -249,7 +250,7 @@ typedef struct CachedInclude { · 199 unmodified lines |
| 249 | 250 | |
| 250 | 251 | /* parser */ |
| 251 | 252 | struct BufferedFile *file; |
| 252 | | −int ch, ch1, tok, tok1; |
| 253 | +int ch, tok, tok1; |
| 253 | 254 | CValue tokc, tok1c; |
| 254 | 255 | CString tokcstr; /* current parsed string, if any */ |
| 255 | 256 | /* if true, line feed is returned as a token. line feed is also |
| @@ -1481,7 +1482,7 @@ BufferedFile *tcc_open(TCCState *s1, const char *filename) · 1225 unmodified lines |
| 1481 | 1482 | bf->buf_end = bf->buffer; |
| 1482 | 1483 | bf->buffer[0] = CH_EOB; /* put eob symbol */ |
| 1483 | 1484 | pstrcpy(bf->filename, sizeof(bf->filename), filename); |
| 1484 | | − bf->line_num = 1; |
| 1485 | + bf->line_num = 0; |
| 1485 | 1486 | bf->ifndef_macro = 0; |
| 1486 | 1487 | bf->ifdef_stack_ptr = s1->ifdef_stack_ptr; |
| 1487 | 1488 | // printf("opening '%s'\n", filename); |
| @@ -1495,9 +1496,6 @@ void tcc_close(BufferedFile *bf) · 7 unmodified lines |
| 1495 | 1496 | tcc_free(bf); |
| 1496 | 1497 | } |
| 1497 | 1498 | |
| 1498 | | −/* read one char. MUST call tcc_fillbuf if CH_EOB is read */ |
| 1499 | | −#define TCC_GETC(bf) (*(bf)->buf_ptr++) |
| 1500 | | − |
| 1501 | 1499 | /* fill input buffer and return next char */ |
| 1502 | 1500 | int tcc_getc_slow(BufferedFile *bf) |
| 1503 | 1501 | { |
| @@ -1534,12 +1532,12 @@ void handle_eob(void) · 30 unmodified lines |
| 1534 | 1532 | return; |
| 1535 | 1533 | |
| 1536 | 1534 | for(;;) { |
| 1537 | | − ch1 = tcc_getc_slow(file); |
| 1538 | | − if (ch1 != CH_EOF) |
| 1535 | + ch = tcc_getc_slow(file); |
| 1536 | + if (ch != CH_EOF) |
| 1539 | 1537 | return; |
| 1540 | 1538 | eof_seen = 1; |
| 1541 | 1539 | if (return_linefeed) { |
| 1542 | | − ch1 = '\n'; |
| 1540 | + ch = '\n'; |
| 1543 | 1541 | return; |
| 1544 | 1542 | } |
| 1545 | 1543 | if (s1->include_stack_ptr == s1->include_stack) |
| @@ -1555,81 +1553,101 @@ void handle_eob(void) · 9 unmodified lines |
| 1555 | 1553 | } |
| 1556 | 1554 | } |
| 1557 | 1555 | |
| 1558 | | −/* read next char from current input file */ |
| 1556 | +/* read next char from current input file and handle end of input buffer */ |
| 1559 | 1557 | static inline void inp(void) |
| 1560 | 1558 | { |
| 1561 | | − ch1 = TCC_GETC(file); |
| 1559 | + ch = *(file->buf_ptr++); |
| 1562 | 1560 | /* end of buffer/file handling */ |
| 1563 | | − if (ch1 == CH_EOB) |
| 1561 | + if (ch == CH_EOB) |
| 1564 | 1562 | handle_eob(); |
| 1565 | | − if (ch1 == '\n') |
| 1566 | | − file->line_num++; |
| 1567 | | − // printf("ch1=%c 0x%x\n", ch1, ch1); |
| 1568 | 1563 | } |
| 1569 | 1564 | |
| 1570 | | −/* handle '\\n' and '\\r\n' */ |
| 1565 | +/* handle '\[\r]\n' */ |
| 1571 | 1566 | static void handle_stray(void) |
| 1572 | 1567 | { |
| 1573 | | − do { |
| 1574 | | − if (ch1 == '\n') { |
| 1568 | + while (ch == '\\') { |
| 1569 | + inp(); |
| 1570 | + if (ch == '\n') { |
| 1571 | + file->line_num++; |
| 1575 | 1572 | inp(); |
| 1576 | | − } else if (ch1 == '\r') { |
| 1573 | + } else if (ch == '\r') { |
| 1577 | 1574 | inp(); |
| 1578 | | − if (ch1 != '\n') |
| 1579 | | − error("invalid character after '\\'"); |
| 1575 | + if (ch != '\n') |
| 1576 | + goto fail; |
| 1577 | + file->line_num++; |
| 1580 | 1578 | inp(); |
| 1581 | 1579 | } else { |
| 1582 | | − break; |
| 1580 | + fail: |
| 1581 | + error("stray '\\' in program"); |
| 1583 | 1582 | } |
| 1584 | | − ch = ch1; |
| 1585 | | − inp(); |
| 1586 | | − } while (ch == '\\'); |
| 1583 | + } |
| 1587 | 1584 | } |
| 1588 | 1585 | |
| 1589 | | −/* input with '\\n' handling. Also supports '\\r\n' for horrible MSDOS |
| 1590 | | − case */ |
| 1591 | | −static inline void minp(void) |
| 1586 | +/* input with '\[\r]\n' handling. Note that this function cannot |
| 1587 | + handle other characters after '\', so you cannot call it inside |
| 1588 | + strings or comments */ |
| 1589 | +static void minp(void) |
| 1592 | 1590 | { |
| 1593 | | − ch = ch1; |
| 1594 | 1591 | inp(); |
| 1595 | 1592 | if (ch == '\\') |
| 1596 | 1593 | handle_stray(); |
| 1597 | 1594 | } |
| 1598 | 1595 | |
| 1599 | 1596 | |
| 1600 | | −/* same as minp, but also skip comments */ |
| 1601 | | −static void cinp(void) |
| 1597 | +static void parse_line_comment(void) |
| 1602 | 1598 | { |
| 1603 | | − int c; |
| 1604 | | − |
| 1605 | | − if (ch1 == '/') { |
| 1599 | + /* single line C++ comments */ |
| 1600 | + /* XXX: accept '\\\n' ? */ |
| 1601 | + inp(); |
| 1602 | + while (ch != '\n' && ch != TOK_EOF) |
| 1606 | 1603 | inp(); |
| 1607 | | − if (ch1 == '/') { |
| 1608 | | − /* single line C++ comments */ |
| 1604 | +} |
| 1605 | + |
| 1606 | +static void parse_comment(void) |
| 1607 | +{ |
| 1608 | + /* C comments */ |
| 1609 | + minp(); |
| 1610 | + for(;;) { |
| 1611 | + /* fast skip loop */ |
| 1612 | + while (ch != '\n' && ch != '*' && ch != TOK_EOF) |
| 1609 | 1613 | inp(); |
| 1610 | | − while (ch1 != '\n' && ch1 != CH_EOF) |
| 1611 | | − inp(); |
| 1612 | | − ch = ' '; /* return space */ |
| 1613 | | − } else if (ch1 == '*') { |
| 1614 | | − /* C comments */ |
| 1614 | + /* now we can handle all the cases */ |
| 1615 | + if (ch == '\n') { |
| 1616 | + file->line_num++; |
| 1615 | 1617 | inp(); |
| 1616 | | − while (ch1 != CH_EOF) { |
| 1617 | | − c = ch1; |
| 1618 | | − inp(); |
| 1619 | | − if (c == '*' && ch1 == '/') { |
| 1618 | + } else if (ch == '*') { |
| 1619 | + for(;;) { |
| 1620 | 1620 | inp(); |
| 1621 | | − ch = ' '; /* return space */ |
| 1622 | | − break; |
| 1623 | | − } |
| 1621 | + if (ch == '/') { |
| 1622 | + goto end_of_comment; |
| 1623 | + } else if (ch == '\\') { |
| 1624 | + inp(); |
| 1625 | + if (ch == '\n') { |
| 1626 | + file->line_num++; |
| 1627 | + inp(); |
| 1628 | + } else if (ch == '\r') { |
| 1629 | + inp(); |
| 1630 | + if (ch != '\n') |
| 1631 | + break; |
| 1632 | + file->line_num++; |
| 1633 | + inp(); |
| 1634 | + } else { |
| 1635 | + break; |
| 1636 | + } |
| 1637 | + } else if (ch != '*') { |
| 1638 | + break; |
| 1639 | + } |
| 1624 | 1640 | } |
| 1625 | 1641 | } else { |
| 1626 | | − ch = '/'; |
| 1642 | + error("unexpected end of file in comment"); |
| 1627 | 1643 | } |
| 1628 | | − } else { |
| 1629 | | − minp(); |
| 1630 | 1644 | } |
| 1645 | + end_of_comment: |
| 1646 | + inp(); |
| 1631 | 1647 | } |
| 1632 | 1648 | |
| 1649 | +#define cinp minp |
| 1650 | + |
| 1633 | 1651 | /* space exlcuding newline */ |
| 1634 | 1652 | static inline int is_space(int ch) |
| 1635 | 1653 | { |
| @@ -1646,28 +1664,85 @@ static inline void skip_spaces(void) · 10 unmodified lines |
| 1646 | 1664 | #if/#endif */ |
| 1647 | 1665 | void preprocess_skip(void) |
| 1648 | 1666 | { |
| 1649 | | − int a; |
| 1667 | + int a, start_of_line, sep; |
| 1668 | + |
| 1669 | + start_of_line = 1; |
| 1650 | 1670 | a = 0; |
| 1651 | 1671 | while (1) { |
| 1652 | | − while (ch != '\n') { |
| 1653 | | − if (ch == CH_EOF) |
| 1654 | | − expect("#endif"); |
| 1655 | | − cinp(); |
| 1656 | | − } |
| 1657 | | − cinp(); |
| 1658 | | − skip_spaces(); |
| 1659 | | − if (ch == '#') { |
| 1660 | | − cinp(); |
| 1661 | | − next_nomacro(); |
| 1662 | | − if (a == 0 && |
| 1663 | | − (tok == TOK_ELSE || tok == TOK_ELIF || tok == TOK_ENDIF)) |
| 1664 | | − break; |
| 1665 | | − if (tok == TOK_IF || tok == TOK_IFDEF || tok == TOK_IFNDEF) |
| 1666 | | − a++; |
| 1667 | | − else if (tok == TOK_ENDIF) |
| 1668 | | − a--; |
| 1672 | + switch(ch) { |
| 1673 | + case ' ': |
| 1674 | + case '\t': |
| 1675 | + case '\f': |
| 1676 | + case '\v': |
| 1677 | + case '\r': |
| 1678 | + inp(); |
| 1679 | + break; |
| 1680 | + case '\n': |
| 1681 | + start_of_line = 1; |
| 1682 | + file->line_num++; |
| 1683 | + inp(); |
| 1684 | + break; |
| 1685 | + case '\\': |
| 1686 | + handle_stray(); |
| 1687 | + break; |
| 1688 | + /* skip strings */ |
| 1689 | + case '\"': |
| 1690 | + case '\'': |
| 1691 | + start_of_line = 0; |
| 1692 | + sep = ch; |
| 1693 | + inp(); |
| 1694 | + while (ch != sep) { |
| 1695 | + /* XXX: better error message */ |
| 1696 | + if (ch == TOK_EOF) { |
| 1697 | + error("unterminated string"); |
| 1698 | + } else if (ch == '\n') { |
| 1699 | + file->line_num++; |
| 1700 | + } else if (ch == '\\') { |
| 1701 | + /* ignore next char */ |
| 1702 | + inp(); |
| 1703 | + if (ch == '\n') |
| 1704 | + file->line_num++; |
| 1705 | + } |
| 1706 | + inp(); |
| 1707 | + } |
| 1708 | + minp(); |
| 1709 | + break; |
| 1710 | + /* skip comments */ |
| 1711 | + case '/': |
| 1712 | + minp(); |
| 1713 | + if (ch == '*') { |
| 1714 | + parse_comment(); |
| 1715 | + } else if (ch == '/') { |
| 1716 | + parse_line_comment(); |
| 1717 | + } else { |
| 1718 | + start_of_line = 0; |
| 1719 | + } |
| 1720 | + break; |
| 1721 | + |
| 1722 | + case '#': |
| 1723 | + minp(); |
| 1724 | + if (start_of_line) { |
| 1725 | + next_nomacro(); |
| 1726 | + if (a == 0 && |
| 1727 | + (tok == TOK_ELSE || tok == TOK_ELIF || tok == TOK_ENDIF)) |
| 1728 | + goto the_end; |
| 1729 | + if (tok == TOK_IF || tok == TOK_IFDEF || tok == TOK_IFNDEF) |
| 1730 | + a++; |
| 1731 | + else if (tok == TOK_ENDIF) |
| 1732 | + a--; |
| 1733 | + } |
| 1734 | + start_of_line = 0; |
| 1735 | + break; |
| 1736 | + case CH_EOF: |
| 1737 | + expect("#endif"); |
| 1738 | + break; |
| 1739 | + default: |
| 1740 | + inp(); |
| 1741 | + start_of_line = 0; |
| 1742 | + break; |
| 1669 | 1743 | } |
| 1670 | 1744 | } |
| 1745 | + the_end: ; |
| 1671 | 1746 | } |
| 1672 | 1747 | |
| 1673 | 1748 | /* ParseState handling */ |
| @@ -1927,7 +2002,7 @@ int expr_preprocess(void) · 253 unmodified lines |
| 1927 | 2002 | return c != 0; |
| 1928 | 2003 | } |
| 1929 | 2004 | |
| 1930 | | −#if defined(DEBUG) || defined(PP_DEBUG) |
| 2005 | +#if defined(PARSE_DEBUG) || defined(PP_DEBUG) |
| 1931 | 2006 | void tok_print(int *str) |
| 1932 | 2007 | { |
| 1933 | 2008 | int t; |
| @@ -2054,7 +2129,6 @@ void preprocess(void) · 120 unmodified lines |
| 2054 | 2129 | state = INCLUDE_STATE_NONE; |
| 2055 | 2130 | eof_seen = 0; |
| 2056 | 2131 | redo1: |
| 2057 | | − cinp(); |
| 2058 | 2132 | next_nomacro(); |
| 2059 | 2133 | redo: |
| 2060 | 2134 | switch(tok) { |
| @@ -2085,10 +2159,12 @@ void preprocess(void) · 24 unmodified lines |
| 2085 | 2159 | minp(); |
| 2086 | 2160 | } |
| 2087 | 2161 | *q = '\0'; |
| 2162 | +#if 0 |
| 2088 | 2163 | /* eat all spaces and comments after include */ |
| 2089 | 2164 | /* XXX: slightly incorrect */ |
| 2090 | 2165 | while (ch1 != '\n' && ch1 != CH_EOF) |
| 2091 | 2166 | inp(); |
| 2167 | +#endif |
| 2092 | 2168 | } else { |
| 2093 | 2169 | /* computed #include : either we have only strings or |
| 2094 | 2170 | we have anything enclosed in '<>' */ |
| @@ -2185,6 +2261,7 @@ void preprocess(void) · 90 unmodified lines |
| 2185 | 2261 | if (ch != '#') |
| 2186 | 2262 | goto the_end; |
| 2187 | 2263 | state = INCLUDE_STATE_SEEK_IFNDEF; |
| 2264 | + cinp(); |
| 2188 | 2265 | goto redo1; |
| 2189 | 2266 | } |
| 2190 | 2267 | break; |
| @@ -2324,7 +2401,7 @@ static int getn(int b) · 133 unmodified lines |
| 2324 | 2401 | if (t < 0 || t >= b) |
| 2325 | 2402 | break; |
| 2326 | 2403 | n = n * b + t; |
| 2327 | | − cinp(); |
| 2404 | + inp(); |
| 2328 | 2405 | } |
| 2329 | 2406 | return n; |
| 2330 | 2407 | } |
| @@ -2334,50 +2411,76 @@ static int getq(void) · 3 unmodified lines |
| 2334 | 2411 | { |
| 2335 | 2412 | int c; |
| 2336 | 2413 | |
| 2414 | + redo: |
| 2337 | 2415 | c = ch; |
| 2338 | | − minp(); |
| 2416 | + inp(); |
| 2339 | 2417 | if (c == '\\') { |
| 2340 | | − if (isoct(ch)) { |
| 2418 | + switch(ch) { |
| 2419 | + case '0': case '1': case '2': case '3': |
| 2420 | + case '4': case '5': case '6': case '7': |
| 2341 | 2421 | /* at most three octal digits */ |
| 2342 | 2422 | c = ch - '0'; |
| 2343 | | − minp(); |
| 2423 | + inp(); |
| 2344 | 2424 | if (isoct(ch)) { |
| 2345 | 2425 | c = c * 8 + ch - '0'; |
| 2346 | | − minp(); |
| 2426 | + inp(); |
| 2347 | 2427 | if (isoct(ch)) { |
| 2348 | 2428 | c = c * 8 + ch - '0'; |
| 2349 | | − minp(); |
| 2429 | + inp(); |
| 2350 | 2430 | } |
| 2351 | 2431 | } |
| 2352 | 2432 | return c; |
| 2353 | | − } else if (ch == 'x') { |
| 2354 | | − minp(); |
| 2433 | + case 'x': |
| 2434 | + inp(); |
| 2355 | 2435 | return getn(16); |
| 2356 | | − } else { |
| 2357 | | − if (ch == 'a') |
| 2358 | | − c = '\a'; |
| 2359 | | − else if (ch == 'b') |
| 2360 | | − c = '\b'; |
| 2361 | | − else if (ch == 'f') |
| 2362 | | − c = '\f'; |
| 2363 | | − else if (ch == 'n') |
| 2364 | | − c = '\n'; |
| 2365 | | − else if (ch == 'r') |
| 2366 | | − c = '\r'; |
| 2367 | | − else if (ch == 't') |
| 2368 | | − c = '\t'; |
| 2369 | | − else if (ch == 'v') |
| 2370 | | − c = '\v'; |
| 2371 | | − else if (ch == 'e' && gnu_ext) |
| 2372 | | − c = 27; |
| 2373 | | − else if (ch == '\'' || ch == '\"' || ch == '\\' || ch == '?') |
| 2374 | | − c = ch; |
| 2375 | | − else |
| 2376 | | − error("invalid escaped char"); |
| 2377 | | − minp(); |
| 2436 | + case 'a': |
| 2437 | + c = '\a'; |
| 2438 | + break; |
| 2439 | + case 'b': |
| 2440 | + c = '\b'; |
| 2441 | + break; |
| 2442 | + case 'f': |
| 2443 | + c = '\f'; |
| 2444 | + break; |
| 2445 | + case 'n': |
| 2446 | + c = '\n'; |
| 2447 | + break; |
| 2448 | + case 'r': |
| 2449 | + c = '\r'; |
| 2450 | + break; |
| 2451 | + case 't': |
| 2452 | + c = '\t'; |
| 2453 | + break; |
| 2454 | + case 'v': |
| 2455 | + c = '\v'; |
| 2456 | + break; |
| 2457 | + case 'e': |
| 2458 | + if (!gnu_ext) |
| 2459 | + goto invalid_escape; |
| 2460 | + c = 27; |
| 2461 | + break; |
| 2462 | + case '\'': |
| 2463 | + case '\"': |
| 2464 | + case '\\': |
| 2465 | + case '?': |
| 2466 | + c = ch; |
| 2467 | + break; |
| 2468 | + case '\n': |
| 2469 | + inp(); |
| 2470 | + goto redo; |
| 2471 | + case '\r': |
| 2472 | + inp(); |
| 2473 | + if (ch != '\n') |
| 2474 | + goto invalid_escape; |
| 2475 | + inp(); |
| 2476 | + goto redo; |
| 2477 | + default: |
| 2478 | + invalid_escape: |
| 2479 | + error("invalid escaped char"); |
| 2378 | 2480 | } |
| 2481 | + inp(); |
| 2379 | 2482 | } else if (c == '\r' && ch == '\n') { |
| 2380 | | − minp(); |
| 2483 | + inp(); |
| 2381 | 2484 | c = '\n'; |
| 2382 | 2485 | } |
| 2383 | 2486 | return c; |
| @@ -2677,10 +2780,11 @@ void parse_number(const char *p) · 293 unmodified lines |
| 2677 | 2780 | /* return next token without macro substitution */ |
| 2678 | 2781 | static inline void next_nomacro1(void) |
| 2679 | 2782 | { |
| 2680 | | − int b, t; |
| 2783 | + int b, t, start_of_line; |
| 2681 | 2784 | char *q; |
| 2682 | 2785 | TokenSym *ts; |
| 2683 | 2786 | |
| 2787 | + start_of_line = 0; |
| 2684 | 2788 | redo_no_start: |
| 2685 | 2789 | switch(ch) { |
| 2686 | 2790 | case ' ': |
| @@ -2688,38 +2792,36 @@ static inline void next_nomacro1(void) · 1 unmodified line |
| 2688 | 2792 | case '\f': |
| 2689 | 2793 | case '\v': |
| 2690 | 2794 | case '\r': |
| 2691 | | − cinp(); |
| 2795 | + inp(); |
| 2692 | 2796 | goto redo_no_start; |
| 2693 | 2797 | |
| 2798 | + case '\\': |
| 2799 | + handle_stray(); |
| 2800 | + goto redo_no_start; |
| 2801 | + |
| 2694 | 2802 | case '\n': |
| 2803 | + file->line_num++; |
| 2695 | 2804 | if (return_linefeed) { |
| 2696 | 2805 | /* XXX: should eat token ? */ |
| 2697 | 2806 | tok = TOK_LINEFEED; |
| 2698 | 2807 | } else { |
| 2699 | | − cinp(); |
| 2700 | | − skip_spaces(); |
| 2701 | | − if (ch == '#') { |
| 2702 | | − /* preprocessor command if # at start of line after |
| 2703 | | − spaces */ |
| 2704 | | − preprocess(); |
| 2705 | | − } |
| 2808 | + start_of_line = 1; |
| 2809 | + inp(); |
| 2706 | 2810 | goto redo_no_start; |
| 2707 | 2811 | } |
| 2708 | 2812 | break; |
| 2709 | 2813 | |
| 2710 | 2814 | case '#': |
| 2711 | | − tok = ch; |
| 2712 | | − cinp(); |
| 2713 | | −#if 0 |
| 2815 | + minp(); |
| 2714 | 2816 | if (start_of_line) { |
| 2715 | 2817 | preprocess(); |
| 2716 | 2818 | goto redo_no_start; |
| 2717 | | − } else |
| 2718 | | −#endif |
| 2719 | | − { |
| 2819 | + } else { |
| 2720 | 2820 | if (ch == '#') { |
| 2721 | | − cinp(); |
| 2821 | + inp(); |
| 2722 | 2822 | tok = TOK_TWOSHARPS; |
| 2823 | + } else { |
| 2824 | + tok = '#'; |
| 2723 | 2825 | } |
| 2724 | 2826 | } |
| 2725 | 2827 | break; |
| @@ -2754,7 +2856,7 @@ static inline void next_nomacro1(void) · 28 unmodified lines |
| 2754 | 2856 | tok = ts->tok; |
| 2755 | 2857 | break; |
| 2756 | 2858 | case 'L': |
| 2757 | | − cinp(); |
| 2859 | + minp(); |
| 2758 | 2860 | if (ch == '\'') { |
| 2759 | 2861 | tok = TOK_LCHAR; |
| 2760 | 2862 | goto char_const; |
| @@ -2810,7 +2912,7 @@ static inline void next_nomacro1(void) · 49 unmodified lines |
| 2810 | 2912 | case '\'': |
| 2811 | 2913 | tok = TOK_CCHAR; |
| 2812 | 2914 | char_const: |
| 2813 | | − minp(); |
| 2915 | + inp(); |
| 2814 | 2916 | b = getq(); |
| 2815 | 2917 | /* this cast is needed if >= 128 */ |
| 2816 | 2918 | if (tok == TOK_CCHAR) |
| @@ -2818,12 +2920,12 @@ static inline void next_nomacro1(void) · 1 unmodified line |
| 2818 | 2920 | tokc.i = b; |
| 2819 | 2921 | if (ch != '\'') |
| 2820 | 2922 | error("unterminated character constant"); |
| 2821 | | − minp(); |
| 2923 | + inp(); |
| 2822 | 2924 | break; |
| 2823 | 2925 | case '\"': |
| 2824 | 2926 | tok = TOK_STR; |
| 2825 | 2927 | str_const: |
| 2826 | | − minp(); |
| 2928 | + inp(); |
| 2827 | 2929 | cstr_reset(&tokcstr); |
| 2828 | 2930 | while (ch != '\"') { |
| 2829 | 2931 | b = getq(); |
| @@ -2839,7 +2941,7 @@ static inline void next_nomacro1(void) · 9 unmodified lines |
| 2839 | 2941 | else |
| 2840 | 2942 | cstr_wccat(&tokcstr, '\0'); |
| 2841 | 2943 | tokc.cstr = &tokcstr; |
| 2842 | | − minp(); |
| 2944 | + inp(); |
| 2843 | 2945 | break; |
| 2844 | 2946 | |
| 2845 | 2947 | case '<': |
| @@ -2976,18 +3078,19 @@ static inline void next_nomacro1(void) · 130 unmodified lines |
| 2976 | 3078 | |
| 2977 | 3079 | /* comments or operator */ |
| 2978 | 3080 | case '/': |
| 2979 | | − tok = ch; |
| 2980 | | − cinp(); |
| 2981 | | − if (ch == '=') { |
| 3081 | + minp(); |
| 3082 | + if (ch == '*') { |
| 3083 | + parse_comment(); |
| 3084 | + goto redo_no_start; |
| 3085 | + } else if (ch == '/') { |
| 3086 | + parse_line_comment(); |
| 3087 | + goto redo_no_start; |
| 3088 | + } else if (ch == '=') { |
| 2982 | 3089 | cinp(); |
| 2983 | 3090 | tok = TOK_A_DIV; |
| 2984 | | − } |
| 2985 | | −#if 0 |
| 2986 | | − else if (ch == '/' || ch == '*') { |
| 2987 | | − parse_comments(); |
| 2988 | | − goto redo_no_start; |
| 3091 | + } else { |
| 3092 | + tok = '/'; |
| 2989 | 3093 | } |
| 2990 | | −#endif |
| 2991 | 3094 | break; |
| 2992 | 3095 | |
| 2993 | 3096 | /* simple tokens */ |
| @@ -3012,6 +3115,9 @@ static inline void next_nomacro1(void) · 18 unmodified lines |
| 3012 | 3115 | error("unrecognized character \\x%02x", ch); |
| 3013 | 3116 | break; |
| 3014 | 3117 | } |
| 3118 | +#if defined(PARSE_DEBUG) |
| 3119 | + printf("token = %s\n", get_tok_str(tok, &tokc)); |
| 3120 | +#endif |
| 3015 | 3121 | } |
| 3016 | 3122 | |
| 3017 | 3123 | /* return next token without macro substitution. Can read input from |
| @@ -3437,9 +3543,6 @@ static void next(void) · 419 unmodified lines |
| 3437 | 3543 | parse_number((char *)tokc.cstr->data); |
| 3438 | 3544 | } |
| 3439 | 3545 | } |
| 3440 | | −#if defined(DEBUG) |
| 3441 | | − printf("token = %s\n", get_tok_str(tok, &tokc)); |
| 3442 | | −#endif |
| 3443 | 3546 | } |
| 3444 | 3547 | |
| 3445 | 3548 | void swap(int *p, int *q) |
| @@ -7539,7 +7642,6 @@ static int tcc_compile(TCCState *s1) · 4093 unmodified lines |
| 7539 | 7642 | s1->nb_errors = 0; |
| 7540 | 7643 | s1->error_set_jmp_enabled = 1; |
| 7541 | 7644 | |
| 7542 | | − inp(); |
| 7543 | 7645 | ch = '\n'; /* needed to parse correctly first preprocessor command */ |
| 7544 | 7646 | next(); |
| 7545 | 7647 | decl(VT_CONST); |
| @@ -7617,7 +7719,6 @@ void tcc_define_symbol(TCCState *s1, const char *sym, const char *value) · 71 unmodified lines |
| 7617 | 7719 | s1->include_stack_ptr = s1->include_stack; |
| 7618 | 7720 | |
| 7619 | 7721 | /* parse with define parser */ |
| 7620 | | − inp(); |
| 7621 | 7722 | ch = '\n'; /* needed to parse correctly first preprocessor command */ |
| 7622 | 7723 | next_nomacro(); |
| 7623 | 7724 | parse_define(); |