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

Function py_process_statement

internal/cbm/lsp/py_lsp.c:2478–2783  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2476/* ── statement processing: bind from assignments, for-loops, with-as ──── */
2477
2478static void py_process_statement(PyLSPContext *ctx, TSNode node) {
2479 if (!ctx || ctx->eval_failure || ts_node_is_null(node))
2480 return;
2481 const char *k = ts_node_type(node);
2482
2483 if (strcmp(k, "assignment") == 0) {
2484 TSNode left = ts_node_child_by_field_name(node, "left", 4);
2485 TSNode right = ts_node_child_by_field_name(node, "right", 5);
2486 TSNode ann = ts_node_child_by_field_name(node, "type", 4);
2487
2488 const CBMType *rhs_type =
2489 ts_node_is_null(right) ? cbm_type_unknown() : py_eval_expr_type(ctx, right);
2490 bool rhs_lexical_alias = false;
2491 const char *rhs_callable =
2492 ts_node_is_null(right)
2493 ? NULL
2494 : py_exact_callable_target_ex(ctx, right, NULL, &rhs_lexical_alias);
2495 /* A proven callable value on the right of an assignment is a reference
2496 * to that callable, exactly as it would be as a call argument -- the
2497 * policy is proven exact value => CALL_REFERENCE, and `cb = handler`
2498 * proves it or the alias binding below could not be created. Bare
2499 * identifier RHS only, in lockstep with the usage-carrier rule in
2500 * extract_usages.c; the strategy distinction mirrors the argument path
2501 * so a shadowed source name still satisfies the local-shadow guard. */
2502 if (rhs_callable && strcmp(ts_node_type(right), "identifier") == 0) {
2503 char *rhs_name = py_node_text(ctx, right);
2504 py_emit_resolved_reference(ctx, rhs_callable, rhs_name, right,
2505 rhs_lexical_alias ? "lsp_callable_alias"
2506 : "lsp_callable_value_reference");
2507 }
2508
2509 // Annotated assignment: x: T = expr — annotation wins.
2510 bool has_annotation = !ts_node_is_null(ann);
2511 if (has_annotation) {
2512 char *ann_text = py_node_text(ctx, ann);
2513 if (ann_text && ann_text[0]) {
2514 rhs_type = py_resolve_annotation(ctx, ann_text);
2515 }
2516 }
2517
2518 if (ts_node_is_null(left))
2519 return;
2520 const char *lk = ts_node_type(left);
2521 // Tuple/list pattern unpacking: a, b = f() / [a, b] = f() /
2522 // (a, b) = f(). Each LHS element binds to the corresponding
2523 // element of the RHS tuple. *rest binds the remaining elements
2524 // as a list (best-effort: list of element type).
2525 if (strcmp(lk, "pattern_list") == 0 || strcmp(lk, "tuple_pattern") == 0 ||
2526 strcmp(lk, "list_pattern") == 0 || strcmp(lk, "expression_list") == 0) {
2527 uint32_t lc = ts_node_named_child_count(left);
2528 // Collect RHS element types.
2529 const CBMType *const *rhs_elems = NULL;
2530 int rhs_count = 0;
2531 if (rhs_type) {
2532 if (rhs_type->kind == CBM_TYPE_TUPLE) {
2533 rhs_elems = rhs_type->data.tuple.elems;
2534 rhs_count = rhs_type->data.tuple.count;
2535 } else if (rhs_type->kind == CBM_TYPE_TEMPLATE &&

Callers 1

Calls 15

cbm_type_unknownFunction · 0.85
py_eval_expr_typeFunction · 0.85
py_node_textFunction · 0.85
py_resolve_annotationFunction · 0.85
py_iterable_element_typeFunction · 0.85
cbm_type_templateFunction · 0.85
py_scope_bindFunction · 0.85
py_scope_bind_callableFunction · 0.85
py_register_lambdaFunction · 0.85
py_register_dict_literalFunction · 0.85

Tested by

no test coverage detected