| @@ -1118,11 +1118,13 @@ void test_lvalue(void) · 1117 unmodified lines |
| 1118 | 1118 | TokenSym *tok_alloc(const char *str, int len) |
| 1119 | 1119 | { |
| 1120 | 1120 | TokenSym *ts, **pts, **ptable; |
| 1121 | | − int h, i; |
| 1121 | + int i; |
| 1122 | + unsigned int h; |
| 1122 | 1123 | |
| 1123 | 1124 | h = 1; |
| 1124 | 1125 | for(i=0;i<len;i++) |
| 1125 | | − h = (h * 263 + ((unsigned char *)str)[i]) & (TOK_HASH_SIZE - 1); |
| 1126 | + h = h * 263 + ((unsigned char *)str)[i]; |
| 1127 | + h &= (TOK_HASH_SIZE - 1); |
| 1126 | 1128 | |
| 1127 | 1129 | pts = &hash_ident[h]; |
| 1128 | 1130 | while (1) { |
| @@ -1522,7 +1524,12 @@ static int tcc_peekc_slow(BufferedFile *bf) · 393 unmodified lines |
| 1522 | 1524 | /* only tries to read if really end of buffer */ |
| 1523 | 1525 | if (bf->buf_ptr >= bf->buf_end) { |
| 1524 | 1526 | if (bf->fd != -1) { |
| 1525 | | − len = read(bf->fd, bf->buffer, IO_BUF_SIZE); |
| 1527 | +#if defined(PARSE_DEBUG) |
| 1528 | + len = 8; |
| 1529 | +#else |
| 1530 | + len = IO_BUF_SIZE; |
| 1531 | +#endif |
| 1532 | + len = read(bf->fd, bf->buffer, len); |
| 1526 | 1533 | if (len < 0) |
| 1527 | 1534 | len = 0; |
| 1528 | 1535 | } else { |
| @@ -1541,13 +1548,11 @@ static int tcc_peekc_slow(BufferedFile *bf) · 12 unmodified lines |
| 1541 | 1548 | } |
| 1542 | 1549 | } |
| 1543 | 1550 | |
| 1544 | | −/* no need to put that inline */ |
| 1545 | | −void handle_eob(void) |
| 1551 | +/* return the current character, handling end of block if necessary |
| 1552 | + (but not stray) */ |
| 1553 | +static int handle_eob(void) |
| 1546 | 1554 | { |
| 1547 | | − /* no need to do anything if not at EOB */ |
| 1548 | | − if (file->buf_ptr < file->buf_end) |
| 1549 | | − return; |
| 1550 | | − ch = tcc_peekc_slow(file); |
| 1555 | + return tcc_peekc_slow(file); |
| 1551 | 1556 | } |
| 1552 | 1557 | |
| 1553 | 1558 | /* read next char from current input file and handle end of input buffer */ |
| @@ -1556,7 +1561,7 @@ static inline void inp(void) · 2 unmodified lines |
| 1556 | 1561 | ch = *(++(file->buf_ptr)); |
| 1557 | 1562 | /* end of buffer/file handling */ |
| 1558 | 1563 | if (ch == CH_EOB) |
| 1559 | | − handle_eob(); |
| 1564 | + ch = handle_eob(); |
| 1560 | 1565 | } |
| 1561 | 1566 | |
| 1562 | 1567 | /* handle '\[\r]\n' */ |
| @@ -1580,6 +1585,40 @@ static void handle_stray(void) · 17 unmodified lines |
| 1580 | 1585 | } |
| 1581 | 1586 | } |
| 1582 | 1587 | |
| 1588 | +/* skip the stray and handle the \\n case. Output an error if |
| 1589 | + incorrect char after the stray */ |
| 1590 | +static int handle_stray1(uint8_t *p) |
| 1591 | +{ |
| 1592 | + int c; |
| 1593 | + |
| 1594 | + if (p >= file->buf_end) { |
| 1595 | + file->buf_ptr = p; |
| 1596 | + c = handle_eob(); |
| 1597 | + p = file->buf_ptr; |
| 1598 | + if (c == '\\') |
| 1599 | + goto parse_stray; |
| 1600 | + } else { |
| 1601 | + parse_stray: |
| 1602 | + file->buf_ptr = p; |
| 1603 | + ch = *p; |
| 1604 | + handle_stray(); |
| 1605 | + p = file->buf_ptr; |
| 1606 | + c = *p; |
| 1607 | + } |
| 1608 | + return c; |
| 1609 | +} |
| 1610 | + |
| 1611 | +/* handle the complicated stray case */ |
| 1612 | +#define PEEKC(c, p)\ |
| 1613 | +{\ |
| 1614 | + p++;\ |
| 1615 | + c = *p;\ |
| 1616 | + if (c == '\\') {\ |
| 1617 | + c = handle_stray1(p);\ |
| 1618 | + p = file->buf_ptr;\ |
| 1619 | + }\ |
| 1620 | +} |
| 1621 | + |
| 1583 | 1622 | /* input with '\[\r]\n' handling. Note that this function cannot |
| 1584 | 1623 | handle other characters after '\', so you cannot call it inside |
| 1585 | 1624 | strings or comments */ |
| @@ -1606,8 +1645,8 @@ static void parse_comment(void) · 20 unmodified lines |
| 1606 | 1645 | int c; |
| 1607 | 1646 | |
| 1608 | 1647 | /* C comments */ |
| 1609 | | − minp(); |
| 1610 | 1648 | p = file->buf_ptr; |
| 1649 | + p++; |
| 1611 | 1650 | for(;;) { |
| 1612 | 1651 | /* fast skip loop */ |
| 1613 | 1652 | for(;;) { |
| @@ -1628,49 +1667,49 @@ static void parse_comment(void) · 14 unmodified lines |
| 1628 | 1667 | p++; |
| 1629 | 1668 | for(;;) { |
| 1630 | 1669 | c = *p; |
| 1631 | | − if (c == '/') { |
| 1670 | + if (c == '*') { |
| 1671 | + p++; |
| 1672 | + } else if (c == '/') { |
| 1632 | 1673 | goto end_of_comment; |
| 1633 | 1674 | } else if (c == '\\') { |
| 1634 | | − if (p >= file->buf_end) { |
| 1635 | | − file->buf_ptr = p; |
| 1636 | | − handle_eob(); |
| 1637 | | − p = file->buf_ptr; |
| 1638 | | − if (p >= file->buf_end) |
| 1639 | | − goto eof_found; |
| 1640 | | − continue; |
| 1641 | | − } |
| 1642 | | − p++; |
| 1643 | | − c = *p; |
| 1644 | | − if (c == '\n') { |
| 1645 | | − file->line_num++; |
| 1646 | | − p++; |
| 1647 | | − } else if (c == '\r') { |
| 1648 | | − p++; |
| 1649 | | − c = *p; |
| 1650 | | − if (c != '\n') |
| 1651 | | − break; |
| 1652 | | − file->line_num++; |
| 1653 | | − p++; |
| 1654 | | − } else { |
| 1655 | | − break; |
| 1675 | + file->buf_ptr = p; |
| 1676 | + c = handle_eob(); |
| 1677 | + if (c == '\\') { |
| 1678 | + /* skip '\\n', but if '\' followed but another |
| 1679 | + char, behave asif a stray was parsed */ |
| 1680 | + ch = file->buf_ptr[0]; |
| 1681 | + while (ch == '\\') { |
| 1682 | + inp(); |
| 1683 | + if (ch == '\n') { |
| 1684 | + file->line_num++; |
| 1685 | + inp(); |
| 1686 | + } else if (ch == '\r') { |
| 1687 | + inp(); |
| 1688 | + if (ch == '\n') { |
| 1689 | + file->line_num++; |
| 1690 | + inp(); |
| 1691 | + } |
| 1692 | + } else { |
| 1693 | + p = file->buf_ptr; |
| 1694 | + break; |
| 1695 | + } |
| 1696 | + } |
| 1656 | 1697 | } |
| 1657 | | − } else if (c == '*') { |
| 1658 | | − p++; |
| 1698 | + p = file->buf_ptr; |
| 1659 | 1699 | } else { |
| 1660 | 1700 | break; |
| 1661 | 1701 | } |
| 1662 | 1702 | } |
| 1663 | | − } else if (p >= file->buf_end) { |
| 1703 | + } else { |
| 1704 | + /* stray, eob or eof */ |
| 1664 | 1705 | file->buf_ptr = p; |
| 1665 | | − handle_eob(); |
| 1706 | + c = handle_eob(); |
| 1666 | 1707 | p = file->buf_ptr; |
| 1667 | | − if (p >= file->buf_end) { |
| 1668 | | − eof_found: |
| 1708 | + if (c == CH_EOF) { |
| 1669 | 1709 | error("unexpected end of file in comment"); |
| 1710 | + } else if (c == '\\') { |
| 1711 | + p++; |
| 1670 | 1712 | } |
| 1671 | | − } else { |
| 1672 | | − /* stray */ |
| 1673 | | − p++; |
| 1674 | 1713 | } |
| 1675 | 1714 | } |
| 1676 | 1715 | end_of_comment: |
| @@ -1697,63 +1736,98 @@ static inline void skip_spaces(void) · 20 unmodified lines |
| 1697 | 1736 | #if/#endif */ |
| 1698 | 1737 | void preprocess_skip(void) |
| 1699 | 1738 | { |
| 1700 | | − int a, start_of_line, sep; |
| 1701 | | − |
| 1739 | + int a, start_of_line, sep, c; |
| 1740 | + uint8_t *p; |
| 1741 | + |
| 1742 | + p = file->buf_ptr; |
| 1702 | 1743 | start_of_line = 1; |
| 1703 | 1744 | a = 0; |
| 1704 | 1745 | for(;;) { |
| 1705 | 1746 | redo_no_start: |
| 1706 | | − switch(ch) { |
| 1747 | + c = *p; |
| 1748 | + switch(c) { |
| 1707 | 1749 | case ' ': |
| 1708 | 1750 | case '\t': |
| 1709 | 1751 | case '\f': |
| 1710 | 1752 | case '\v': |
| 1711 | 1753 | case '\r': |
| 1712 | | − inp(); |
| 1754 | + p++; |
| 1713 | 1755 | goto redo_no_start; |
| 1714 | 1756 | case '\n': |
| 1715 | 1757 | start_of_line = 1; |
| 1716 | 1758 | file->line_num++; |
| 1717 | | − inp(); |
| 1759 | + p++; |
| 1718 | 1760 | goto redo_no_start; |
| 1719 | 1761 | case '\\': |
| 1720 | | − handle_stray(); |
| 1762 | + file->buf_ptr = p; |
| 1763 | + c = handle_eob(); |
| 1764 | + if (c == CH_EOF) { |
| 1765 | + expect("#endif"); |
| 1766 | + } else if (c == '\\') { |
| 1767 | + /* XXX: incorrect: should not give an error */ |
| 1768 | + ch = file->buf_ptr[0]; |
| 1769 | + handle_stray(); |
| 1770 | + } |
| 1771 | + p = file->buf_ptr; |
| 1721 | 1772 | goto redo_no_start; |
| 1722 | 1773 | /* skip strings */ |
| 1723 | 1774 | case '\"': |
| 1724 | 1775 | case '\'': |
| 1725 | | − sep = ch; |
| 1726 | | − inp(); |
| 1727 | | − while (ch != sep) { |
| 1728 | | − /* XXX: better error message */ |
| 1729 | | − if (ch == TOK_EOF) { |
| 1730 | | − error("unterminated string"); |
| 1731 | | − } else if (ch == '\n') { |
| 1776 | + sep = c; |
| 1777 | + p++; |
| 1778 | + for(;;) { |
| 1779 | + c = *p; |
| 1780 | + if (c == sep) { |
| 1781 | + break; |
| 1782 | + } else if (c == '\\') { |
| 1783 | + file->buf_ptr = p; |
| 1784 | + c = handle_eob(); |
| 1785 | + p = file->buf_ptr; |
| 1786 | + if (c == CH_EOF) { |
| 1787 | + /* XXX: better error message */ |
| 1788 | + error("unterminated string"); |
| 1789 | + } else if (c == '\\') { |
| 1790 | + /* ignore next char */ |
| 1791 | + p++; |
| 1792 | + c = *p; |
| 1793 | + if (c == '\\') { |
| 1794 | + file->buf_ptr = p; |
| 1795 | + c = handle_eob(); |
| 1796 | + p = file->buf_ptr; |
| 1797 | + } |
| 1798 | + if (c == '\n') |
| 1799 | + file->line_num++; |
| 1800 | + else if (c != CH_EOF) |
| 1801 | + p++; |
| 1802 | + } |
| 1803 | + } else if (c == '\n') { |
| 1732 | 1804 | file->line_num++; |
| 1733 | | − } else if (ch == '\\') { |
| 1734 | | − /* ignore next char */ |
| 1735 | | − inp(); |
| 1736 | | − if (ch == '\n') |
| 1737 | | − file->line_num++; |
| 1805 | + p++; |
| 1806 | + } else { |
| 1807 | + p++; |
| 1738 | 1808 | } |
| 1739 | | − inp(); |
| 1740 | 1809 | } |
| 1741 | | − minp(); |
| 1810 | + p++; |
| 1742 | 1811 | break; |
| 1743 | 1812 | /* skip comments */ |
| 1744 | 1813 | case '/': |
| 1814 | + file->buf_ptr = p; |
| 1815 | + ch = *p; |
| 1745 | 1816 | minp(); |
| 1746 | 1817 | if (ch == '*') { |
| 1747 | 1818 | parse_comment(); |
| 1748 | 1819 | } else if (ch == '/') { |
| 1749 | 1820 | parse_line_comment(); |
| 1750 | 1821 | } |
| 1822 | + p = file->buf_ptr; |
| 1751 | 1823 | break; |
| 1752 | 1824 | |
| 1753 | 1825 | case '#': |
| 1754 | | − minp(); |
| 1826 | + p++; |
| 1755 | 1827 | if (start_of_line) { |
| 1828 | + file->buf_ptr = p; |
| 1756 | 1829 | next_nomacro(); |
| 1830 | + p = file->buf_ptr; |
| 1757 | 1831 | if (a == 0 && |
| 1758 | 1832 | (tok == TOK_ELSE || tok == TOK_ELIF || tok == TOK_ENDIF)) |
| 1759 | 1833 | goto the_end; |
| @@ -1763,16 +1837,14 @@ void preprocess_skip(void) · 3 unmodified lines |
| 1763 | 1837 | a--; |
| 1764 | 1838 | } |
| 1765 | 1839 | break; |
| 1766 | | − case CH_EOF: |
| 1767 | | − expect("#endif"); |
| 1768 | | − break; |
| 1769 | 1840 | default: |
| 1770 | | − inp(); |
| 1841 | + p++; |
| 1771 | 1842 | break; |
| 1772 | 1843 | } |
| 1773 | 1844 | start_of_line = 0; |
| 1774 | 1845 | } |
| 1775 | 1846 | the_end: ; |
| 1847 | + file->buf_ptr = p; |
| 1776 | 1848 | } |
| 1777 | 1849 | |
| 1778 | 1850 | /* ParseState handling */ |
| @@ -2040,10 +2112,10 @@ void tok_print(int *str) · 261 unmodified lines |
| 2040 | 2112 | #endif |
| 2041 | 2113 | |
| 2042 | 2114 | /* parse after #define */ |
| 2043 | | −void parse_define(void) |
| 2115 | +static void parse_define(void) |
| 2044 | 2116 | { |
| 2045 | 2117 | Sym *s, *first, **ps; |
| 2046 | | − int v, t, varg, is_vaargs; |
| 2118 | + int v, t, varg, is_vaargs, c; |
| 2047 | 2119 | TokenString str; |
| 2048 | 2120 | |
| 2049 | 2121 | v = tok; |
| @@ -2053,7 +2125,10 @@ void parse_define(void) · 3 unmodified lines |
| 2053 | 2125 | first = NULL; |
| 2054 | 2126 | t = MACRO_OBJ; |
| 2055 | 2127 | /* '(' must be just after macro definition for MACRO_FUNC */ |
| 2056 | | − if (ch == '(') { |
| 2128 | + c = file->buf_ptr[0]; |
| 2129 | + if (c == '\\') |
| 2130 | + c = handle_stray1(file->buf_ptr); |
| 2131 | + if (c == '(') { |
| 2057 | 2132 | next_nomacro(); |
| 2058 | 2133 | next_nomacro(); |
| 2059 | 2134 | ps = &first; |
| @@ -2156,6 +2231,8 @@ static void preprocess(int is_bof) · 96 unmodified lines |
| 2156 | 2231 | define_undef(s); |
| 2157 | 2232 | break; |
| 2158 | 2233 | case TOK_INCLUDE: |
| 2234 | + ch = file->buf_ptr[0]; |
| 2235 | + /* XXX: incorrect if comments : use next_nomacro with a special mode */ |
| 2159 | 2236 | skip_spaces(); |
| 2160 | 2237 | if (ch == '<') { |
| 2161 | 2238 | c = '>'; |
| @@ -2781,32 +2858,55 @@ void parse_number(const char *p) · 619 unmodified lines |
| 2781 | 2858 | } |
| 2782 | 2859 | } |
| 2783 | 2860 | |
| 2861 | + |
| 2862 | +#define PARSE2(c1, tok1, c2, tok2) \ |
| 2863 | + case c1: \ |
| 2864 | + PEEKC(c, p); \ |
| 2865 | + if (c == c2) { \ |
| 2866 | + p++; \ |
| 2867 | + tok = tok2; \ |
| 2868 | + } else { \ |
| 2869 | + tok = tok1; \ |
| 2870 | + } \ |
| 2871 | + break; |
| 2872 | + |
| 2784 | 2873 | /* return next token without macro substitution */ |
| 2785 | 2874 | static inline void next_nomacro1(void) |
| 2786 | 2875 | { |
| 2787 | | − int b, t; |
| 2788 | | − char *q; |
| 2876 | + int b, t, c; |
| 2789 | 2877 | TokenSym *ts; |
| 2878 | + uint8_t *p, *p1; |
| 2790 | 2879 | |
| 2880 | + p = file->buf_ptr; |
| 2791 | 2881 | redo_no_start: |
| 2792 | | − switch(ch) { |
| 2882 | + c = *p; |
| 2883 | + switch(c) { |
| 2793 | 2884 | case ' ': |
| 2794 | 2885 | case '\t': |
| 2795 | 2886 | case '\f': |
| 2796 | 2887 | case '\v': |
| 2797 | 2888 | case '\r': |
| 2798 | | − inp(); |
| 2889 | + p++; |
| 2799 | 2890 | goto redo_no_start; |
| 2800 | 2891 | |
| 2801 | 2892 | case '\\': |
| 2802 | 2893 | /* first look if it is in fact an end of buffer */ |
| 2803 | | − handle_eob(); |
| 2804 | | − if (ch != '\\') |
| 2894 | + if (p >= file->buf_end) { |
| 2895 | + file->buf_ptr = p; |
| 2896 | + handle_eob(); |
| 2897 | + p = file->buf_ptr; |
| 2898 | + if (p >= file->buf_end) |
| 2899 | + goto parse_eof; |
| 2900 | + else |
| 2901 | + goto redo_no_start; |
| 2902 | + } else { |
| 2903 | + file->buf_ptr = p; |
| 2904 | + ch = *p; |
| 2905 | + handle_stray(); |
| 2906 | + p = file->buf_ptr; |
| 2805 | 2907 | goto redo_no_start; |
| 2806 | | − handle_stray(); |
| 2807 | | − goto redo_no_start; |
| 2808 | | − |
| 2809 | | − case CH_EOF: |
| 2908 | + } |
| 2909 | + parse_eof: |
| 2810 | 2910 | { |
| 2811 | 2911 | TCCState *s1 = tcc_state; |
| 2812 | 2912 | |
| @@ -2837,6 +2937,7 @@ static inline void next_nomacro1(void) · 24 unmodified lines |
| 2837 | 2937 | s1->include_stack_ptr--; |
| 2838 | 2938 | file = *s1->include_stack_ptr; |
| 2839 | 2939 | inp(); |
| 2940 | + p = file->buf_ptr; |
| 2840 | 2941 | goto redo_no_start; |
| 2841 | 2942 | } |
| 2842 | 2943 | } |
| @@ -2848,19 +2949,22 @@ static inline void next_nomacro1(void) · 5 unmodified lines |
| 2848 | 2949 | tok = TOK_LINEFEED; |
| 2849 | 2950 | } else { |
| 2850 | 2951 | tok_flags |= TOK_FLAG_BOL; |
| 2851 | | − inp(); |
| 2952 | + p++; |
| 2852 | 2953 | goto redo_no_start; |
| 2853 | 2954 | } |
| 2854 | 2955 | break; |
| 2855 | 2956 | |
| 2856 | 2957 | case '#': |
| 2857 | | − minp(); |
| 2958 | + /* XXX: simplify */ |
| 2959 | + PEEKC(c, p); |
| 2858 | 2960 | if (tok_flags & TOK_FLAG_BOL) { |
| 2961 | + file->buf_ptr = p; |
| 2859 | 2962 | preprocess(tok_flags & TOK_FLAG_BOF); |
| 2963 | + p = file->buf_ptr; |
| 2860 | 2964 | goto redo_no_start; |
| 2861 | 2965 | } else { |
| 2862 | | − if (ch == '#') { |
| 2863 | | − inp(); |
| 2966 | + if (c == '#') { |
| 2967 | + p++; |
| 2864 | 2968 | tok = TOK_TWOSHARPS; |
| 2865 | 2969 | } else { |
| 2866 | 2970 | tok = '#'; |
| @@ -2883,34 +2987,57 @@ static inline void next_nomacro1(void) · 16 unmodified lines |
| 2883 | 2987 | case 'U': case 'V': case 'W': case 'X': |
| 2884 | 2988 | case 'Y': case 'Z': |
| 2885 | 2989 | case '_': |
| 2886 | | − q = token_buf; |
| 2887 | | − *q++ = ch; |
| 2888 | | − cinp(); |
| 2889 | | − parse_ident: |
| 2890 | | − while (isid(ch) || isnum(ch)) { |
| 2891 | | − if (q >= token_buf + STRING_MAX_SIZE) |
| 2892 | | − error("ident too long"); |
| 2893 | | − *q++ = ch; |
| 2894 | | − cinp(); |
| 2990 | + parse_ident_fast: |
| 2991 | + p1 = p; |
| 2992 | + p++; |
| 2993 | + for(;;) { |
| 2994 | + c = *p; |
| 2995 | + if (!isid(c) && !isnum(c)) |
| 2996 | + break; |
| 2997 | + p++; |
| 2998 | + } |
| 2999 | + if (c != '\\') { |
| 3000 | + /* fast case : no stray found, so we have the full token */ |
| 3001 | + ts = tok_alloc(p1, p - p1); |
| 3002 | + } else { |
| 3003 | + /* slower case */ |
| 3004 | + cstr_reset(&tokcstr); |
| 3005 | + |
| 3006 | + while (p1 < p) { |
| 3007 | + cstr_ccat(&tokcstr, *p1); |
| 3008 | + p1++; |
| 3009 | + } |
| 3010 | + p--; |
| 3011 | + PEEKC(c, p); |
| 3012 | + parse_ident_slow: |
| 3013 | + while (isid(c) || isnum(c)) { |
| 3014 | + cstr_ccat(&tokcstr, c); |
| 3015 | + PEEKC(c, p); |
| 3016 | + } |
| 3017 | + ts = tok_alloc(tokcstr.data, tokcstr.size); |
| 2895 | 3018 | } |
| 2896 | | − *q = '\0'; |
| 2897 | | − ts = tok_alloc(token_buf, q - token_buf); |
| 2898 | 3019 | tok = ts->tok; |
| 2899 | 3020 | break; |
| 2900 | 3021 | case 'L': |
| 2901 | | − minp(); |
| 2902 | | − if (ch == '\'') { |
| 2903 | | − tok = TOK_LCHAR; |
| 2904 | | − goto char_const; |
| 2905 | | − } |
| 2906 | | − if (ch == '\"') { |
| 2907 | | − tok = TOK_LSTR; |
| 2908 | | − goto str_const; |
| 3022 | + c = p[1]; |
| 3023 | + if (c != '\\' && c != '\'' && c != '\"') { |
| 3024 | + /* fast case */ |
| 3025 | + goto parse_ident_fast; |
| 3026 | + } else { |
| 3027 | + PEEKC(c, p); |
| 3028 | + if (c == '\'') { |
| 3029 | + tok = TOK_LCHAR; |
| 3030 | + goto char_const; |
| 3031 | + } else if (c == '\"') { |
| 3032 | + tok = TOK_LSTR; |
| 3033 | + goto str_const; |
| 3034 | + } else { |
| 3035 | + cstr_reset(&tokcstr); |
| 3036 | + cstr_ccat(&tokcstr, 'L'); |
| 3037 | + goto parse_ident_slow; |
| 3038 | + } |
| 2909 | 3039 | } |
| 2910 | | − q = token_buf; |
| 2911 | | − *q++ = 'L'; |
| 2912 | | − goto parse_ident; |
| 2913 | | − |
| 3040 | + break; |
| 2914 | 3041 | case '0': case '1': case '2': case '3': |
| 2915 | 3042 | case '4': case '5': case '6': case '7': |
| 2916 | 3043 | case '8': case '9': |
| @@ -2920,11 +3047,11 @@ static inline void next_nomacro1(void) · 3 unmodified lines |
| 2920 | 3047 | prefixed by 'eEpP' */ |
| 2921 | 3048 | parse_num: |
| 2922 | 3049 | for(;;) { |
| 2923 | | − t = ch; |
| 2924 | | − cstr_ccat(&tokcstr, ch); |
| 2925 | | − cinp(); |
| 2926 | | − if (!(isnum(ch) || isid(ch) || ch == '.' || |
| 2927 | | − ((ch == '+' || ch == '-') && |
| 3050 | + t = c; |
| 3051 | + cstr_ccat(&tokcstr, c); |
| 3052 | + PEEKC(c, p); |
| 3053 | + if (!(isnum(c) || isid(c) || c == '.' || |
| 3054 | + ((c == '+' || c == '-') && |
| 2928 | 3055 | (t == 'e' || t == 'E' || t == 'p' || t == 'P')))) |
| 2929 | 3056 | break; |
| 2930 | 3057 | } |
| @@ -2935,17 +3062,16 @@ static inline void next_nomacro1(void) · 4 unmodified lines |
| 2935 | 3062 | break; |
| 2936 | 3063 | case '.': |
| 2937 | 3064 | /* special dot handling because it can also start a number */ |
| 2938 | | − cinp(); |
| 2939 | | − if (isnum(ch)) { |
| 3065 | + PEEKC(c, p); |
| 3066 | + if (isnum(c)) { |
| 2940 | 3067 | cstr_reset(&tokcstr); |
| 2941 | 3068 | cstr_ccat(&tokcstr, '.'); |
| 2942 | 3069 | goto parse_num; |
| 2943 | | − } |
| 2944 | | − if (ch == '.') { |
| 2945 | | − cinp(); |
| 2946 | | − if (ch != '.') |
| 3070 | + } else if (c == '.') { |
| 3071 | + PEEKC(c, p); |
| 3072 | + if (c != '.') |
| 2947 | 3073 | expect("'.'"); |
| 2948 | | − cinp(); |
| 3074 | + PEEKC(c, p); |
| 2949 | 3075 | tok = TOK_DOTS; |
| 2950 | 3076 | } else { |
| 2951 | 3077 | tok = '.'; |
| @@ -2954,6 +3080,7 @@ static inline void next_nomacro1(void) · 2 unmodified lines |
| 2954 | 3080 | case '\'': |
| 2955 | 3081 | tok = TOK_CCHAR; |
| 2956 | 3082 | char_const: |
| 3083 | + file->buf_ptr = p; |
| 2957 | 3084 | inp(); |
| 2958 | 3085 | b = getq(); |
| 2959 | 3086 | /* this cast is needed if >= 128 */ |
| @@ -2962,11 +3089,13 @@ static inline void next_nomacro1(void) · 2 unmodified lines |
| 2962 | 3089 | tokc.i = b; |
| 2963 | 3090 | if (ch != '\'') |
| 2964 | 3091 | error("unterminated character constant"); |
| 2965 | | − inp(); |
| 3092 | + p = file->buf_ptr; |
| 3093 | + p++; |
| 2966 | 3094 | break; |
| 2967 | 3095 | case '\"': |
| 2968 | 3096 | tok = TOK_STR; |
| 2969 | 3097 | str_const: |
| 3098 | + file->buf_ptr = p; |
| 2970 | 3099 | inp(); |
| 2971 | 3100 | cstr_reset(&tokcstr); |
| 2972 | 3101 | while (ch != '\"') { |
| @@ -2983,18 +3112,19 @@ static inline void next_nomacro1(void) · 10 unmodified lines |
| 2983 | 3112 | else |
| 2984 | 3113 | cstr_wccat(&tokcstr, '\0'); |
| 2985 | 3114 | tokc.cstr = &tokcstr; |
| 2986 | | − inp(); |
| 3115 | + p = file->buf_ptr; |
| 3116 | + p++; |
| 2987 | 3117 | break; |
| 2988 | 3118 | |
| 2989 | 3119 | case '<': |
| 2990 | | − cinp(); |
| 2991 | | − if (ch == '=') { |
| 2992 | | − cinp(); |
| 3120 | + PEEKC(c, p); |
| 3121 | + if (c == '=') { |
| 3122 | + p++; |
| 2993 | 3123 | tok = TOK_LE; |
| 2994 | | − } else if (ch == '<') { |
| 2995 | | − cinp(); |
| 2996 | | − if (ch == '=') { |
| 2997 | | − cinp(); |
| 3124 | + } else if (c == '<') { |
| 3125 | + PEEKC(c, p); |
| 3126 | + if (c == '=') { |
| 3127 | + p++; |
| 2998 | 3128 | tok = TOK_A_SHL; |
| 2999 | 3129 | } else { |
| 3000 | 3130 | tok = TOK_SHL; |
| @@ -3005,14 +3135,14 @@ static inline void next_nomacro1(void) · 4 unmodified lines |
| 3005 | 3135 | break; |
| 3006 | 3136 | |
| 3007 | 3137 | case '>': |
| 3008 | | − cinp(); |
| 3009 | | − if (ch == '=') { |
| 3010 | | − cinp(); |
| 3138 | + PEEKC(c, p); |
| 3139 | + if (c == '=') { |
| 3140 | + p++; |
| 3011 | 3141 | tok = TOK_GE; |
| 3012 | | − } else if (ch == '>') { |
| 3013 | | − cinp(); |
| 3014 | | − if (ch == '=') { |
| 3015 | | − cinp(); |
| 3142 | + } else if (c == '>') { |
| 3143 | + PEEKC(c, p); |
| 3144 | + if (c == '=') { |
| 3145 | + p++; |
| 3016 | 3146 | tok = TOK_A_SAR; |
| 3017 | 3147 | } else { |
| 3018 | 3148 | tok = TOK_SAR; |
| @@ -3022,113 +3152,82 @@ static inline void next_nomacro1(void) · 3 unmodified lines |
| 3022 | 3152 | } |
| 3023 | 3153 | break; |
| 3024 | 3154 | |
| 3025 | | − case '!': |
| 3026 | | − tok = ch; |
| 3027 | | − cinp(); |
| 3028 | | − if (ch == '=') { |
| 3029 | | − cinp(); |
| 3030 | | − tok = TOK_NE; |
| 3031 | | − } |
| 3032 | | − break; |
| 3033 | | − |
| 3034 | | − case '=': |
| 3035 | | − tok = ch; |
| 3036 | | − cinp(); |
| 3037 | | − if (ch == '=') { |
| 3038 | | − cinp(); |
| 3039 | | − tok = TOK_EQ; |
| 3040 | | − } |
| 3041 | | − break; |
| 3042 | | − |
| 3043 | 3155 | case '&': |
| 3044 | | − tok = ch; |
| 3045 | | − cinp(); |
| 3046 | | − if (ch == '&') { |
| 3047 | | − cinp(); |
| 3156 | + PEEKC(c, p); |
| 3157 | + if (c == '&') { |
| 3158 | + p++; |
| 3048 | 3159 | tok = TOK_LAND; |
| 3049 | | − } else if (ch == '=') { |
| 3050 | | − cinp(); |
| 3160 | + } else if (c == '=') { |
| 3161 | + p++; |
| 3051 | 3162 | tok = TOK_A_AND; |
| 3163 | + } else { |
| 3164 | + tok = '&'; |
| 3052 | 3165 | } |
| 3053 | 3166 | break; |
| 3054 | 3167 | |
| 3055 | 3168 | case '|': |
| 3056 | | − tok = ch; |
| 3057 | | − cinp(); |
| 3058 | | − if (ch == '|') { |
| 3059 | | − cinp(); |
| 3169 | + PEEKC(c, p); |
| 3170 | + if (c == '|') { |
| 3171 | + p++; |
| 3060 | 3172 | tok = TOK_LOR; |
| 3061 | | − } else if (ch == '=') { |
| 3062 | | − cinp(); |
| 3173 | + } else if (c == '=') { |
| 3174 | + p++; |
| 3063 | 3175 | tok = TOK_A_OR; |
| 3176 | + } else { |
| 3177 | + tok = '|'; |
| 3064 | 3178 | } |
| 3065 | 3179 | break; |
| 3066 | 3180 | |
| 3067 | 3181 | case '+': |
| 3068 | | − tok = ch; |
| 3069 | | − cinp(); |
| 3070 | | − if (ch == '+') { |
| 3071 | | − cinp(); |
| 3182 | + PEEKC(c, p); |
| 3183 | + if (c == '+') { |
| 3184 | + p++; |
| 3072 | 3185 | tok = TOK_INC; |
| 3073 | | − } else if (ch == '=') { |
| 3074 | | − cinp(); |
| 3186 | + } else if (c == '=') { |
| 3187 | + p++; |
| 3075 | 3188 | tok = TOK_A_ADD; |
| 3189 | + } else { |
| 3190 | + tok = '+'; |
| 3076 | 3191 | } |
| 3077 | 3192 | break; |
| 3078 | 3193 | |
| 3079 | 3194 | case '-': |
| 3080 | | − tok = ch; |
| 3081 | | − cinp(); |
| 3082 | | − if (ch == '-') { |
| 3083 | | − cinp(); |
| 3195 | + PEEKC(c, p); |
| 3196 | + if (c == '-') { |
| 3197 | + p++; |
| 3084 | 3198 | tok = TOK_DEC; |
| 3085 | | − } else if (ch == '=') { |
| 3086 | | − cinp(); |
| 3199 | + } else if (c == '=') { |
| 3200 | + p++; |
| 3087 | 3201 | tok = TOK_A_SUB; |
| 3088 | | − } else if (ch == '>') { |
| 3089 | | − cinp(); |
| 3202 | + } else if (c == '>') { |
| 3203 | + p++; |
| 3090 | 3204 | tok = TOK_ARROW; |
| 3205 | + } else { |
| 3206 | + tok = '-'; |
| 3091 | 3207 | } |
| 3092 | 3208 | break; |
| 3093 | 3209 | |
| 3094 | | − case '*': |
| 3095 | | − tok = ch; |
| 3096 | | − cinp(); |
| 3097 | | − if (ch == '=') { |
| 3098 | | − cinp(); |
| 3099 | | − tok = TOK_A_MUL; |
| 3100 | | − } |
| 3101 | | − break; |
| 3102 | | − |
| 3103 | | − case '%': |
| 3104 | | − tok = ch; |
| 3105 | | − cinp(); |
| 3106 | | − if (ch == '=') { |
| 3107 | | − cinp(); |
| 3108 | | − tok = TOK_A_MOD; |
| 3109 | | − } |
| 3110 | | − break; |
| 3210 | + PARSE2('!', '!', '=', TOK_NE) |
| 3211 | + PARSE2('=', '=', '=', TOK_EQ) |
| 3212 | + PARSE2('*', '*', '=', TOK_A_MUL) |
| 3213 | + PARSE2('%', '%', '=', TOK_A_MOD) |
| 3214 | + PARSE2('^', '^', '=', TOK_A_XOR) |
| 3111 | 3215 | |
| 3112 | | − case '^': |
| 3113 | | − tok = ch; |
| 3114 | | − cinp(); |
| 3115 | | − if (ch == '=') { |
| 3116 | | − cinp(); |
| 3117 | | − tok = TOK_A_XOR; |
| 3118 | | − } |
| 3119 | | − break; |
| 3120 | | − |
| 3121 | 3216 | /* comments or operator */ |
| 3122 | 3217 | case '/': |
| 3123 | | − minp(); |
| 3124 | | − if (ch == '*') { |
| 3218 | + PEEKC(c, p); |
| 3219 | + if (c == '*') { |
| 3220 | + file->buf_ptr = p; |
| 3125 | 3221 | parse_comment(); |
| 3222 | + p = file->buf_ptr; |
| 3126 | 3223 | goto redo_no_start; |
| 3127 | | − } else if (ch == '/') { |
| 3224 | + } else if (c == '/') { |
| 3225 | + file->buf_ptr = p; |
| 3128 | 3226 | parse_line_comment(); |
| 3227 | + p = file->buf_ptr; |
| 3129 | 3228 | goto redo_no_start; |
| 3130 | | − } else if (ch == '=') { |
| 3131 | | − cinp(); |
| 3229 | + } else if (c == '=') { |
| 3230 | + p++; |
| 3132 | 3231 | tok = TOK_A_DIV; |
| 3133 | 3232 | } else { |
| 3134 | 3233 | tok = '/'; |
| @@ -3147,13 +3246,14 @@ static inline void next_nomacro1(void) · 12 unmodified lines |
| 3147 | 3246 | case ':': |
| 3148 | 3247 | case '?': |
| 3149 | 3248 | case '~': |
| 3150 | | − tok = ch; |
| 3151 | | − cinp(); |
| 3249 | + tok = c; |
| 3250 | + p++; |
| 3152 | 3251 | break; |
| 3153 | 3252 | default: |
| 3154 | | − error("unrecognized character \\x%02x", ch); |
| 3253 | + error("unrecognized character \\x%02x", c); |
| 3155 | 3254 | break; |
| 3156 | 3255 | } |
| 3256 | + file->buf_ptr = p; |
| 3157 | 3257 | tok_flags = 0; |
| 3158 | 3258 | #if defined(PARSE_DEBUG) |
| 3159 | 3259 | printf("token = %s\n", get_tok_str(tok, &tokc)); |
| @@ -3427,6 +3527,7 @@ static int macro_subst_tok(TokenString *tok_str, · 267 unmodified lines |
| 3427 | 3527 | t = *macro_ptr; |
| 3428 | 3528 | } else { |
| 3429 | 3529 | /* XXX: incorrect with comments */ |
| 3530 | + ch = file->buf_ptr[0]; |
| 3430 | 3531 | while (is_space(ch) || ch == '\n') |
| 3431 | 3532 | cinp(); |
| 3432 | 3533 | t = ch; |