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

Function extract_elixir_call

internal/cbm/extract_defs.c:8843–8897  ·  view source on GitHub ↗

Process Elixir call nodes iteratively — handles defmodule/def/defp/defmacro without recursion between extract_elixir_call ↔ extract_elixir_module_def.

Source from the content-addressed store, hash-verified

8841// Process Elixir call nodes iteratively — handles defmodule/def/defp/defmacro
8842// without recursion between extract_elixir_call ↔ extract_elixir_module_def.
8843static void extract_elixir_call(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec) {
8844 (void)spec;
8845 TSNodeStack stack;
8846 ts_nstack_init(&stack, ctx, CBM_SZ_64);
8847 ts_nstack_push(&stack, node);
8848
8849 while (stack.count > 0) {
8850 TSNode cur = ts_nstack_pop(&stack);
8851 CBMArena *a = ctx->arena;
8852
8853 if (ts_node_child_count(cur) == 0) {
8854 continue;
8855 }
8856 TSNode callee = ts_node_child(cur, 0);
8857 if (ts_node_is_null(callee)) {
8858 continue;
8859 }
8860 char *macro = cbm_node_text(a, callee, ctx->source);
8861 if (!macro) {
8862 continue;
8863 }
8864
8865 if (strcmp(macro, "def") == 0 || strcmp(macro, "defp") == 0 ||
8866 strcmp(macro, "defmacro") == 0) {
8867 extract_elixir_func_def(ctx, cur, macro);
8868 } else if (strcmp(macro, "if") == 0 || strcmp(macro, "unless") == 0) {
8869 /* A compile-time if/unless in a module body defines functions
8870 * under a condition: its do and else branches hold variants of the
8871 * same definitions (graph_buffer.c, "Definition variants"). The
8872 * grammar nests the else_block inside the do_block. */
8873 TSNode branch = cbm_find_child_by_kind(cur, "do_block");
8874 for (int pass = 0; pass < 2 && !ts_node_is_null(branch); pass++) {
8875 uint32_t bc = ts_node_child_count(branch);
8876 for (int bi = (int)bc - SKIP_CHAR; bi >= 0; bi--) {
8877 TSNode bchild = ts_node_child(branch, (uint32_t)bi);
8878 if (!ts_node_is_null(bchild) && strcmp(ts_node_type(bchild), "call") == 0) {
8879 ts_nstack_push(&stack, bchild);
8880 }
8881 }
8882 branch = cbm_find_child_by_kind(branch, "else_block");
8883 }
8884 } else if (strcmp(macro, "defmodule") == 0) {
8885 TSNode do_block = emit_elixir_module_class(ctx, cur);
8886 if (!ts_node_is_null(do_block)) {
8887 uint32_t dbc = ts_node_child_count(do_block);
8888 for (int di = (int)dbc - SKIP_CHAR; di >= 0; di--) {
8889 TSNode dchild = ts_node_child(do_block, (uint32_t)di);
8890 if (!ts_node_is_null(dchild) && strcmp(ts_node_type(dchild), "call") == 0) {
8891 ts_nstack_push(&stack, dchild);
8892 }
8893 }
8894 }
8895 }
8896 }
8897}
8898
8899// --- Variable extraction ---
8900

Callers 1

walk_defsFunction · 0.85

Calls 7

ts_nstack_initFunction · 0.85
ts_nstack_pushFunction · 0.85
ts_nstack_popFunction · 0.85
cbm_node_textFunction · 0.85
extract_elixir_func_defFunction · 0.85
cbm_find_child_by_kindFunction · 0.85
emit_elixir_module_classFunction · 0.85

Tested by

no test coverage detected