History

fixed comment parsing

bellard committed 23 years ago

Commit cab60181 parent 0c618f42 files · +48 −36Browse files

Unified · Split

2 files
  1. tcc.c +46 −35
  2. tccelf.c +2 −1
tcc.c+46−35
@@ -1772,22 +1772,40 @@ static void minp(void) · 1771 unmodified lines
1772}1772}
1773 1773
1774 1774
1775static void parse_line_comment(void)1775/* single line C++ comments */
1776static uint8_t *parse_line_comment(uint8_t *p)
1776{1777{
1777 /* single line C++ comments */1778 int c;
1778 /* XXX: accept '\\\n' ? */1779
1779 inp();1780 p++;
1780 while (ch != '\n' && ch != CH_EOF)1781 for(;;) {
1781 inp();1782 c = *p;
1783 if (c == '\n' || c == CH_EOF) {
1784 break;
1785 } else if (c == '\\') {
1786 PEEKC_EOB(c, p);
1787 if (c == '\n') {
1788 file->line_num++;
1789 PEEKC_EOB(c, p);
1790 } else if (c == '\r') {
1791 PEEKC_EOB(c, p);
1792 if (c == '\n') {
1793 file->line_num++;
1794 PEEKC_EOB(c, p);
1795 }
1796 }
1797 } else {
1798 p++;
1799 }
1800 }
1801 return p;
1782}1802}
1783 1803
1784static void parse_comment(void)1804/* C comments */
1805static uint8_t *parse_comment(uint8_t *p)
1785{1806{
1786 uint8_t *p;
1787 int c;1807 int c;
1788 1808
1789 /* C comments */
1790 p = file->buf_ptr;
1791 p++;1809 p++;
1792 for(;;) {1810 for(;;) {
1793 /* fast skip loop */1811 /* fast skip loop */
@@ -1816,32 +1834,30 @@ static void parse_comment(void) · 22 unmodified lines
1816 } else if (c == '\\') {1834 } else if (c == '\\') {
1817 file->buf_ptr = p;1835 file->buf_ptr = p;
1818 c = handle_eob();1836 c = handle_eob();
1837 p = file->buf_ptr;
1819 if (c == '\\') {1838 if (c == '\\') {
1820 /* skip '\\n', but if '\' followed but another1839 /* skip '\[\r]\n', otherwise just skip the stray */
1821 char, behave asif a stray was parsed */1840 while (c == '\\') {
1822 ch = file->buf_ptr[0];1841 PEEKC_EOB(c, p);
1823 while (ch == '\\') {1842 if (c == '\n') {
1824 inp();
1825 if (ch == '\n') {
1826 file->line_num++;1843 file->line_num++;
1827 inp();1844 PEEKC_EOB(c, p);
1828 } else if (ch == '\r') {1845 } else if (c == '\r') {
1829 inp();1846 PEEKC_EOB(c, p);
1830 if (ch == '\n') {1847 if (c == '\n') {
1831 file->line_num++;1848 file->line_num++;
1832 inp();1849 PEEKC_EOB(c, p);
1833 }1850 }
1834 } else {1851 } else {
1835 p = file->buf_ptr;1852 goto after_star;
1836 break;
1837 }1853 }
1838 }1854 }
1839 }1855 }
1840 p = file->buf_ptr;
1841 } else {1856 } else {
1842 break;1857 break;
1843 }1858 }
1844 }1859 }
1860 after_star: ;
1845 } else {1861 } else {
1846 /* stray, eob or eof */1862 /* stray, eob or eof */
1847 file->buf_ptr = p;1863 file->buf_ptr = p;
@@ -1856,8 +1872,7 @@ static void parse_comment(void) · 8 unmodified lines
1856 }1872 }
1857 end_of_comment:1873 end_of_comment:
1858 p++;1874 p++;
1859 file->buf_ptr = p;1875 return p;
1860 ch = *p;
1861}1876}
1862 1877
1863#define cinp minp1878#define cinp minp
@@ -1984,12 +1999,12 @@ void preprocess_skip(void) · 120 unmodified lines
1984 file->buf_ptr = p;1999 file->buf_ptr = p;
1985 ch = *p;2000 ch = *p;
1986 minp();2001 minp();
2002 p = file->buf_ptr;
1987 if (ch == '*') {2003 if (ch == '*') {
1988 parse_comment();2004 p = parse_comment(p);
1989 } else if (ch == '/') {2005 } else if (ch == '/') {
1990 parse_line_comment();2006 p = parse_line_comment(p);
1991 }2007 }
1992 p = file->buf_ptr;
1993 break;2008 break;
1994 2009
1995 case '#':2010 case '#':
@@ -3541,14 +3556,10 @@ static inline void next_nomacro1(void) · 1545 unmodified lines
3541 case '/':3556 case '/':
3542 PEEKC(c, p);3557 PEEKC(c, p);
3543 if (c == '*') {3558 if (c == '*') {
3544 file->buf_ptr = p;3559 p = parse_comment(p);
3545 parse_comment();
3546 p = file->buf_ptr;
3547 goto redo_no_start;3560 goto redo_no_start;
3548 } else if (c == '/') {3561 } else if (c == '/') {
3549 file->buf_ptr = p;3562 p = parse_line_comment(p);
3550 parse_line_comment();
3551 p = file->buf_ptr;
3552 goto redo_no_start;3563 goto redo_no_start;
3553 } else if (c == '=') {3564 } else if (c == '=') {
3554 p++;3565 p++;
tccelf.c+2−1
@@ -1868,7 +1868,8 @@ static int ld_next(TCCState *s1, char *name, int name_size) · 1867 unmodified lines
1868 case '/':1868 case '/':
1869 minp();1869 minp();
1870 if (ch == '*') {1870 if (ch == '*') {
1871 parse_comment();1871 file->buf_ptr = parse_comment(file->buf_ptr);
1872 ch = file->buf_ptr[0];
1872 goto redo;1873 goto redo;
1873 } else {1874 } else {
1874 q = name;1875 q = name;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t