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