Set CBM_LINE_NO_CODE on every line of `src` that holds no construct. * One pass over the file. Carries block-comment state across lines so a line * in the middle of a comment counts as no-code too. */
| 1665 | * One pass over the file. Carries block-comment state across lines so a line |
| 1666 | * in the middle of a comment counts as no-code too. */ |
| 1667 | static void cbm_mark_no_code_lines(const char *src, int src_len, uint8_t *map, |
| 1668 | uint32_t line_count) { |
| 1669 | bool in_block = false; |
| 1670 | bool in_directive = false; |
| 1671 | uint32_t line = 1; |
| 1672 | int i = 0; |
| 1673 | while (i <= src_len && line <= line_count) { |
| 1674 | int end = i; |
| 1675 | while (end < src_len && src[end] != '\n') { |
| 1676 | end++; |
| 1677 | } |
| 1678 | bool has_code = false; |
| 1679 | bool line_starts_in_block = in_block; |
| 1680 | for (int j = i; j < end; j++) { |
| 1681 | if (in_block) { |
| 1682 | if (src[j] == '*' && j + 1 < end && src[j + 1] == '/') { |
| 1683 | in_block = false; |
| 1684 | j++; |
| 1685 | } |
| 1686 | continue; |
| 1687 | } |
| 1688 | if (src[j] == '/' && j + 1 < end && src[j + 1] == '*') { |
| 1689 | in_block = true; |
| 1690 | j++; |
| 1691 | continue; |
| 1692 | } |
| 1693 | if (src[j] == '/' && j + 1 < end && src[j + 1] == '/') { |
| 1694 | break; /* rest of the line is a comment */ |
| 1695 | } |
| 1696 | if (src[j] != ' ' && src[j] != '\t' && src[j] != '\r') { |
| 1697 | has_code = true; |
| 1698 | } |
| 1699 | } |
| 1700 | bool directive = |
| 1701 | !line_starts_in_block && (in_directive || cbm_is_directive_line(src + i, end - i)); |
| 1702 | if (!has_code || directive) { |
| 1703 | map[line] |= CBM_LINE_NO_CODE; |
| 1704 | } |
| 1705 | in_directive = directive && cbm_line_continues(src + i, end - i); |
| 1706 | line++; |
| 1707 | i = end + 1; |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | /* Paint CBM_LINE_PP_PARSED for every original line the preprocessed parse |
| 1712 | * covered without an error on it. |
no test coverage detected