MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cpp_group_branches

Function cpp_group_branches

internal/cbm/cpp_branch_views.c:101–130  ·  view source on GitHub ↗

Branch count per group. Returns the group count, or -1 on allocation failure.

Source from the content-addressed store, hash-verified

99
100// Branch count per group. Returns the group count, or -1 on allocation failure.
101static 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
132int cbm_cpp_branch_view_count(CBMArena *a, const char *src, int len) {
133 int *branches = NULL;

Callers 2

cbm_cpp_branch_viewFunction · 0.85

Calls 4

cpp_line_endFunction · 0.85
cpp_line_kindFunction · 0.85
cpp_nest_stepFunction · 0.85
cbm_arena_allocFunction · 0.70

Tested by

no test coverage detected