| 1650 | } |
| 1651 | |
| 1652 | static void rst_sections(rst_doc_t *d) { |
| 1653 | CBMExtractCtx *ctx = d->ctx; |
| 1654 | CBMArena *a = ctx->arena; |
| 1655 | for (int t = 0; t < d->ntitles; t++) { |
| 1656 | rst_title_t *ti = &d->titles[t]; |
| 1657 | const char *seg = rst_qn_segment(a, ti->text); |
| 1658 | ti->qn = seg ? cbm_fqn_compute(a, ctx->project, ctx->rel_path, seg) : NULL; |
| 1659 | if (!ti->qn) { |
| 1660 | d->failed = true; |
| 1661 | return; |
| 1662 | } |
| 1663 | } |
| 1664 | if (d->ntitles > 1) { |
| 1665 | rst_title_t **by_qn = |
| 1666 | (rst_title_t **)cbm_arena_alloc(d->scratch, (size_t)d->ntitles * sizeof(*by_qn)); |
| 1667 | if (!by_qn) { |
| 1668 | d->failed = true; |
| 1669 | return; |
| 1670 | } |
| 1671 | for (int t = 0; t < d->ntitles; t++) { |
| 1672 | by_qn[t] = &d->titles[t]; |
| 1673 | } |
| 1674 | qsort(by_qn, (size_t)d->ntitles, sizeof(*by_qn), rst_title_qn_cmp); |
| 1675 | for (int t = 1; t < d->ntitles; t++) { |
| 1676 | if (strcmp(by_qn[t]->qn, by_qn[t - 1]->qn) == 0) { |
| 1677 | by_qn[t]->shared_qn = true; |
| 1678 | by_qn[t - 1]->shared_qn = true; |
| 1679 | } |
| 1680 | } |
| 1681 | } |
| 1682 | for (int t = 0; t < d->ntitles; t++) { |
| 1683 | const rst_title_t *ti = &d->titles[t]; |
| 1684 | int end = t + 1 < d->ntitles ? d->titles[t + 1].first : d->n; |
| 1685 | int last = end - 1; |
| 1686 | while (last > ti->idx && d->L[last].blank) { |
| 1687 | last--; |
| 1688 | } |
| 1689 | char *name = cbm_arena_strdup(a, ti->text); |
| 1690 | if (!name) { |
| 1691 | d->failed = true; |
| 1692 | return; |
| 1693 | } |
| 1694 | CBMDefinition def; |
| 1695 | memset(&def, 0, sizeof(def)); |
| 1696 | def.name = name; |
| 1697 | def.qualified_name = ti->qn; |
| 1698 | def.label = "Section"; |
| 1699 | def.file_path = ctx->rel_path; |
| 1700 | def.start_line = (uint32_t)ti->idx + 1; |
| 1701 | def.end_line = (uint32_t)last + 1; |
| 1702 | def.is_exported = true; |
| 1703 | def.docstring = rst_body(d, ti->next, end); |
| 1704 | cbm_defs_push(&ctx->result->defs, a, def); |
| 1705 | } |
| 1706 | } |
| 1707 | |
| 1708 | /* ── Driver ──────────────────────────────────────────────────────── */ |
| 1709 |
no test coverage detected