Branch count per group. Returns the group count, or -1 on allocation failure.
| 99 | |
| 100 | // Branch count per group. Returns the group count, or -1 on allocation failure. |
| 101 | static int cpp_group_branches(CBMArena *a, const char *src, int len, int **out) { |
| 102 | int groups = 0; |
| 103 | for (int pos = 0; pos < len;) { |
| 104 | int end = cpp_line_end(src, pos, len); |
| 105 | groups += cpp_line_kind(src, pos, end) == CPP_LINE_START; |
| 106 | pos = end + 1; |
| 107 | } |
| 108 | *out = NULL; |
| 109 | if (groups == 0) { |
| 110 | return 0; |
| 111 | } |
| 112 | int *branches = cbm_arena_alloc(a, sizeof(int) * (size_t)groups); |
| 113 | if (!branches) { |
| 114 | return -1; |
| 115 | } |
| 116 | for (int g = 0; g < groups; g++) { |
| 117 | branches[g] = 1; |
| 118 | } |
| 119 | cpp_nest_t nest = {.depth = 0}; |
| 120 | for (int pos = 0; pos < len;) { |
| 121 | int end = cpp_line_end(src, pos, len); |
| 122 | cpp_frame_t *frame = cpp_nest_step(&nest, cpp_line_kind(src, pos, end), true); |
| 123 | if (frame) { |
| 124 | branches[frame->group] = frame->branch + 1; |
| 125 | } |
| 126 | pos = end + 1; |
| 127 | } |
| 128 | *out = branches; |
| 129 | return groups; |
| 130 | } |
| 131 | |
| 132 | int cbm_cpp_branch_view_count(CBMArena *a, const char *src, int len) { |
| 133 | int *branches = NULL; |
no test coverage detected