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

Function ad_sections

internal/cbm/doc_adoc.c:289–336  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

287}
288
289static void ad_sections(ad_doc_t *d) {
290 CBMExtractCtx *ctx = d->ctx;
291 CBMArena *a = ctx->arena;
292 for (int h = 0; h < d->nheads; h++) {
293 const char *seg = ad_qn_segment(a, d->heads[h].title);
294 d->heads[h].qn = seg ? cbm_fqn_compute(a, ctx->project, ctx->rel_path, seg) : NULL;
295 if (!d->heads[h].qn) {
296 d->failed = true;
297 return;
298 }
299 }
300 if (d->nheads > 1) {
301 ad_head_t **by = (ad_head_t **)cbm_arena_alloc(d->scratch, (size_t)d->nheads * sizeof(*by));
302 if (!by) {
303 d->failed = true;
304 return;
305 }
306 for (int h = 0; h < d->nheads; h++) {
307 by[h] = &d->heads[h];
308 }
309 qsort(by, (size_t)d->nheads, sizeof(*by), ad_head_qn_cmp);
310 for (int h = 1; h < d->nheads; h++) {
311 if (strcmp(by[h]->qn, by[h - 1]->qn) == 0) {
312 by[h]->shared_qn = true;
313 by[h - 1]->shared_qn = true;
314 }
315 }
316 }
317 for (int h = 0; h < d->nheads; h++) {
318 const ad_head_t *hd = &d->heads[h];
319 int end = h + 1 < d->nheads ? d->heads[h + 1].line : d->n;
320 int last = end - 1;
321 while (last > hd->line && ad_rlen(&d->L[last]) == 0) {
322 last--;
323 }
324 CBMDefinition def;
325 memset(&def, 0, sizeof(def));
326 def.name = hd->title;
327 def.qualified_name = hd->qn;
328 def.label = "Section";
329 def.file_path = ctx->rel_path;
330 def.start_line = (uint32_t)hd->line + 1;
331 def.end_line = (uint32_t)last + 1;
332 def.is_exported = true;
333 def.docstring = ad_body(d, hd->line + 1, end);
334 cbm_defs_push(&ctx->result->defs, a, def);
335 }
336}
337
338/* ── Page attributes ─────────────────────────────────────────────── */
339

Callers 1

Calls 6

ad_qn_segmentFunction · 0.85
cbm_fqn_computeFunction · 0.85
ad_rlenFunction · 0.85
ad_bodyFunction · 0.85
cbm_defs_pushFunction · 0.85
cbm_arena_allocFunction · 0.70

Tested by

no test coverage detected