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

Function py_extract_init_fields

internal/cbm/extract_defs.c:7403–7438  ·  view source on GitHub ↗

Every `self.x` field assignment in one __init__ body, nested blocks * included; nested functions, lambdas and classes have their own `self`. */

Source from the content-addressed store, hash-verified

7401/* Every `self.x` field assignment in one __init__ body, nested blocks
7402 * included; nested functions, lambdas and classes have their own `self`. */
7403static void py_extract_init_fields(CBMExtractCtx *ctx, const char *class_qn, TSNode fn) {
7404 TSNode params = ts_node_child_by_field_name(fn, TS_FIELD("parameters"));
7405 TSNode body = ts_node_child_by_field_name(fn, TS_FIELD("body"));
7406 if (ts_node_is_null(params) || ts_node_is_null(body) ||
7407 ts_node_named_child_count(params) == 0) {
7408 return;
7409 }
7410 TSNode self_node = ts_node_named_child(params, 0);
7411 if (strcmp(ts_node_type(self_node), "identifier") != 0) {
7412 return;
7413 }
7414 char *self_name = cbm_node_text(ctx->arena, self_node, ctx->source);
7415 if (!self_name || !self_name[0]) {
7416 return;
7417 }
7418 TSNodeStack stack;
7419 ts_nstack_init(&stack, ctx, CBM_SZ_32);
7420 ts_nstack_push(&stack, body);
7421 while (stack.count > 0) {
7422 TSNode n = ts_nstack_pop(&stack);
7423 const char *k = ts_node_type(n);
7424 if (strcmp(k, "function_definition") == 0 || strcmp(k, "class_definition") == 0 ||
7425 strcmp(k, "lambda") == 0) {
7426 continue;
7427 }
7428 TSNode assign = py_statement_assignment(n);
7429 if (!ts_node_is_null(assign)) {
7430 py_init_field_assignment(ctx, class_qn, assign, params, self_name);
7431 continue;
7432 }
7433 /* Reverse push keeps source order on pop. */
7434 for (uint32_t i = ts_node_named_child_count(n); i > 0; i--) {
7435 ts_nstack_push(&stack, ts_node_named_child(n, i - 1));
7436 }
7437 }
7438}
7439
7440static void extract_py_field_types(CBMExtractCtx *ctx, TSNode class_node, const char *class_qn) {
7441 TSNode body = ts_node_child_by_field_name(class_node, TS_FIELD("body"));

Callers 1

extract_py_field_typesFunction · 0.85

Calls 6

cbm_node_textFunction · 0.85
ts_nstack_initFunction · 0.85
ts_nstack_pushFunction · 0.85
ts_nstack_popFunction · 0.85
py_statement_assignmentFunction · 0.85
py_init_field_assignmentFunction · 0.85

Tested by

no test coverage detected