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

Function doc_perl_module

internal/cbm/extract_defs.c:2732–2793  ·  view source on GitHub ↗

Perl's module doc, for the File node: the file's POD outside the sections a * sub's doc holds, so that no reference is read twice. Every POD block with * those sections cut out, each remaining run as it is in the source, in * document order and joined by a blank line (a sub's doc joins its sections * the same way); a run of only =cut / =pod / =over / =back lines is dropped. * Built after the

Source from the content-addressed store, hash-verified

2730 * Built after the definitions, which mark the sections they take. NULL when
2731 * nothing is left. */
2732static const char *doc_perl_module(CBMExtractCtx *ctx) {
2733 pod_index_t *ix = pod_index(ctx);
2734 if (!ix) {
2735 return NULL;
2736 }
2737 size_t total = 0;
2738 int blocks = 0;
2739 TSTreeCursor cur = ts_tree_cursor_new(ctx->root);
2740 if (ts_tree_cursor_goto_first_child(&cur)) {
2741 do {
2742 TSNode ch = ts_tree_cursor_current_node(&cur);
2743 if (strcmp(ts_node_type(ch), "pod") == 0) {
2744 total += ts_node_end_byte(ch) - ts_node_start_byte(ch);
2745 blocks++;
2746 }
2747 } while (ts_tree_cursor_goto_next_sibling(&cur));
2748 }
2749 if (blocks == 0) {
2750 ts_tree_cursor_delete(&cur);
2751 return NULL;
2752 }
2753 /* each block yields at most one run more than the sections it loses */
2754 size_t runs = (size_t)blocks + (size_t)ix->count;
2755 pod_module_t m = {.ctx = ctx};
2756 m.buf = (char *)cbm_arena_alloc(ctx->arena, total + (runs * PAIR_LEN) + SKIP_ONE);
2757 if (!m.buf) {
2758 ts_tree_cursor_delete(&cur);
2759 return NULL;
2760 }
2761 ts_tree_cursor_reset(&cur, ctx->root);
2762 if (ts_tree_cursor_goto_first_child(&cur)) {
2763 do {
2764 TSNode ch = ts_tree_cursor_current_node(&cur);
2765 if (strcmp(ts_node_type(ch), "pod") != 0) {
2766 continue;
2767 }
2768 m.block = ch;
2769 uint32_t pb = ts_node_start_byte(ch);
2770 uint32_t pe = ts_node_end_byte(ch);
2771 uint32_t at = pb;
2772 /* the index holds the blocks' sections in document order */
2773 for (; m.next_sec < ix->count && ix->items[m.next_sec].sb < pe; m.next_sec++) {
2774 const pod_sec_t *s = &ix->items[m.next_sec];
2775 if (!s->used || s->sb < pb) {
2776 continue;
2777 }
2778 if (s->sb > at) {
2779 pod_module_run(&m, at, s->sb);
2780 }
2781 at = s->eb > at ? s->eb : at;
2782 }
2783 pod_module_run(&m, at, pe);
2784 } while (ts_tree_cursor_goto_next_sibling(&cur));
2785 }
2786 ts_tree_cursor_delete(&cur);
2787 if (m.w == 0) {
2788 return NULL;
2789 }

Callers 1

cbm_extract_definitionsFunction · 0.85

Calls 4

pod_indexFunction · 0.85
pod_module_runFunction · 0.85
cbm_arena_allocFunction · 0.70

Tested by

no test coverage detected