| @@ -1578,13 +1578,14 @@ ST_FUNC void preprocess(int is_bof) · 1577 unmodified lines |
| 1578 | case TOK_INCLUDE: | 1578 | case TOK_INCLUDE: |
| 1579 | case TOK_INCLUDE_NEXT: | 1579 | case TOK_INCLUDE_NEXT: |
| 1580 | ch = file->buf_ptr[0]; | 1580 | ch = file->buf_ptr[0]; |
| 1581 | skip_spaces(); /* XXX: incorrect if comments : use next_nomacro with a special mode */ | 1581 | /* XXX: incorrect if comments : use next_nomacro with a special mode */ |
| 1582 | c = 0; | 1582 | skip_spaces(); |
| 1583 | if (ch == '<') | 1583 | if (ch == '<') { |
| 1584 | c = '>'; | 1584 | c = '>'; |
| 1585 | if (ch == '\"') | 1585 | goto read_name; |
| | 1586 | } else if (ch == '\"') { |
| 1586 | c = ch; | 1587 | c = ch; |
| 1587 | if (c) { | 1588 | read_name: |
| 1588 | inp(); | 1589 | inp(); |
| 1589 | q = buf; | 1590 | q = buf; |
| 1590 | while (ch != c && ch != '\n' && ch != CH_EOF) { | 1591 | while (ch != c && ch != '\n' && ch != CH_EOF) { |
| @@ -1598,6 +1599,12 @@ ST_FUNC void preprocess(int is_bof) · 7 unmodified lines |
| 1598 | } | 1599 | } |
| 1599 | *q = '\0'; | 1600 | *q = '\0'; |
| 1600 | minp(); | 1601 | minp(); |
| | 1602 | #if 0 |
| | 1603 | /* eat all spaces and comments after include */ |
| | 1604 | /* XXX: slightly incorrect */ |
| | 1605 | while (ch1 != '\n' && ch1 != CH_EOF) |
| | 1606 | inp(); |
| | 1607 | #endif |
| 1601 | } else { | 1608 | } else { |
| 1602 | /* computed #include : either we have only strings or | 1609 | /* computed #include : either we have only strings or |
| 1603 | we have anything enclosed in '<>' */ | 1610 | we have anything enclosed in '<>' */ |
| @@ -1631,25 +1638,22 @@ ST_FUNC void preprocess(int is_bof) · 27 unmodified lines |
| 1631 | | 1638 | |
| 1632 | if (s1->include_stack_ptr >= s1->include_stack + INCLUDE_STACK_SIZE) | 1639 | if (s1->include_stack_ptr >= s1->include_stack + INCLUDE_STACK_SIZE) |
| 1633 | tcc_error("#include recursion too deep"); | 1640 | tcc_error("#include recursion too deep"); |
| 1634 | | 1641 | /* store current file in stack, but increment stack later below */ |
| 1635 | i = -2; | 1642 | *s1->include_stack_ptr = file; |
| 1636 | if (tok == TOK_INCLUDE_NEXT) | 1643 | i = tok == TOK_INCLUDE_NEXT ? file->include_next_index : 0; |
| 1637 | i = file->inc_path_index + 1; | 1644 | n = 2 + s1->nb_include_paths + s1->nb_sysinclude_paths; |
| 1638 | | | |
| 1639 | n = s1->nb_include_paths + s1->nb_sysinclude_paths; | | |
| 1640 | for (; i < n; ++i) { | 1645 | for (; i < n; ++i) { |
| 1641 | char buf1[sizeof file->filename]; | 1646 | char buf1[sizeof file->filename]; |
| 1642 | CachedInclude *e; | 1647 | CachedInclude *e; |
| 1643 | const char *path; | 1648 | const char *path; |
| 1644 | | 1649 | |
| 1645 | if (i == -2) { | 1650 | if (i == 0) { |
| 1646 | /* check absolute include path */ | 1651 | /* check absolute include path */ |
| 1647 | if (!IS_ABSPATH(buf)) | 1652 | if (!IS_ABSPATH(buf)) |
| 1648 | continue; | 1653 | continue; |
| 1649 | buf1[0] = 0; | 1654 | buf1[0] = 0; |
| 1650 | i = n - 1; /* force end loop */ | | |
| 1651 | | 1655 | |
| 1652 | } else if (i == -1) { | 1656 | } else if (i == 1) { |
| 1653 | /* search in current dir if "header.h" */ | 1657 | /* search in current dir if "header.h" */ |
| 1654 | if (c != '\"') | 1658 | if (c != '\"') |
| 1655 | continue; | 1659 | continue; |
| @@ -1658,40 +1662,45 @@ ST_FUNC void preprocess(int is_bof) · 2 unmodified lines |
| 1658 | | 1662 | |
| 1659 | } else { | 1663 | } else { |
| 1660 | /* search in all the include paths */ | 1664 | /* search in all the include paths */ |
| 1661 | if (i < s1->nb_include_paths) | 1665 | int j = i - 2, k = j - s1->nb_include_paths; |
| 1662 | path = s1->include_paths[i]; | 1666 | path = k < 0 ? s1->include_paths[j] : s1->sysinclude_paths[k]; |
| 1663 | else | | |
| 1664 | path = s1->sysinclude_paths[i - s1->nb_include_paths]; | | |
| 1665 | if (path == 0) continue; | | |
| 1666 | pstrcpy(buf1, sizeof(buf1), path); | 1667 | pstrcpy(buf1, sizeof(buf1), path); |
| 1667 | pstrcat(buf1, sizeof(buf1), "/"); | 1668 | pstrcat(buf1, sizeof(buf1), "/"); |
| 1668 | } | 1669 | } |
| 1669 | | 1670 | |
| 1670 | pstrcat(buf1, sizeof(buf1), buf); | 1671 | pstrcat(buf1, sizeof(buf1), buf); |
| 1671 | e = search_cached_include(s1, buf1); | 1672 | e = search_cached_include(s1, buf1); |
| 1672 | if (e && (define_find(e->ifndef_macro) || e->ifndef_macro == TOK_once)) | 1673 | if (e && (define_find(e->ifndef_macro) || e->ifndef_macro == TOK_once)) { |
| 1673 | break; /* no need to parse the include */ | 1674 | /* no need to parse the include because the 'ifndef macro' |
| | 1675 | is defined */ |
| | 1676 | #ifdef INC_DEBUG |
| | 1677 | printf("%s: skipping cached %s\n", file->filename, buf1); |
| | 1678 | #endif |
| | 1679 | goto include_done; |
| | 1680 | } |
| 1674 | | 1681 | |
| 1675 | if (tcc_open(s1, buf1) < 0) | 1682 | if (tcc_open(s1, buf1) < 0) |
| 1676 | continue; | 1683 | continue; |
| 1677 | | 1684 | |
| 1678 | file->inc_path_index = i; | 1685 | file->include_next_index = i + 1; |
| 1679 | *(s1->include_stack_ptr++) = file->prev; | 1686 | #ifdef INC_DEBUG |
| 1680 | | 1687 | printf("%s: including %s\n", file->prev->filename, file->filename); |
| | 1688 | #endif |
| 1681 | /* update target deps */ | 1689 | /* update target deps */ |
| 1682 | dynarray_add((void ***)&s1->target_deps, &s1->nb_target_deps, | 1690 | dynarray_add((void ***)&s1->target_deps, &s1->nb_target_deps, |
| 1683 | tcc_strdup(buf1)); | 1691 | tcc_strdup(buf1)); |
| 1684 | | 1692 | /* push current file in stack */ |
| | 1693 | ++s1->include_stack_ptr; |
| 1685 | /* add include file debug info */ | 1694 | /* add include file debug info */ |
| 1686 | if (s1->do_debug) | 1695 | if (s1->do_debug) |
| 1687 | put_stabs(file->filename, N_BINCL, 0, 0, 0); | 1696 | put_stabs(file->filename, N_BINCL, 0, 0, 0); |
| 1688 | | | |
| 1689 | tok_flags |= TOK_FLAG_BOF | TOK_FLAG_BOL; | 1697 | tok_flags |= TOK_FLAG_BOF | TOK_FLAG_BOL; |
| 1690 | ch = file->buf_ptr[0]; | 1698 | ch = file->buf_ptr[0]; |
| 1691 | break; | 1699 | goto the_end; |
| 1692 | } | 1700 | } |
| 1693 | if (i >= n) tcc_error("include file '%s' not found", buf); | 1701 | tcc_error("include file '%s' not found", buf); |
| 1694 | goto the_end; | 1702 | include_done: |
| | 1703 | break; |
| 1695 | case TOK_IFNDEF: | 1704 | case TOK_IFNDEF: |
| 1696 | c = 1; | 1705 | c = 1; |
| 1697 | goto do_ifdef; | 1706 | goto do_ifdef; |
| @@ -1706,9 +1715,9 @@ ST_FUNC void preprocess(int is_bof) · 8 unmodified lines |
| 1706 | tcc_error("invalid argument for '#if%sdef'", c ? "n" : ""); | 1715 | tcc_error("invalid argument for '#if%sdef'", c ? "n" : ""); |
| 1707 | if (is_bof) { | 1716 | if (is_bof) { |
| 1708 | if (c) { | 1717 | if (c) { |
| 1709 | #ifdef INC_DEBUG | 1718 | #ifdef INC_DEBUG |
| 1710 | printf("#ifndef %s\n", get_tok_str(tok, NULL)); | 1719 | printf("#ifndef %s\n", get_tok_str(tok, NULL)); |
| 1711 | #endif | 1720 | #endif |
| 1712 | file->ifndef_macro = tok; | 1721 | file->ifndef_macro = tok; |
| 1713 | } | 1722 | } |
| 1714 | } | 1723 | } |
| @@ -2538,8 +2547,10 @@ maybe_newline: · 823 unmodified lines |
| 2538 | cstr_reset(&tokcstr); | 2547 | cstr_reset(&tokcstr); |
| 2539 | cstr_ccat(&tokcstr, '.'); | 2548 | cstr_ccat(&tokcstr, '.'); |
| 2540 | goto parse_num; | 2549 | goto parse_num; |
| 2541 | } else if ((c == '.') && (p[1] == '.')){ | 2550 | } else if (c == '.') { |
| 2542 | PEEKC(c, p); | 2551 | PEEKC(c, p); |
| | 2552 | if (c != '.') |
| | 2553 | expect("'.'"); |
| 2543 | PEEKC(c, p); | 2554 | PEEKC(c, p); |
| 2544 | tok = TOK_DOTS; | 2555 | tok = TOK_DOTS; |
| 2545 | } else { | 2556 | } else { |