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

Function apply_assert_narrowing

internal/cbm/lsp/php_lsp.c:2114–2146  ·  view source on GitHub ↗

`assert( )` narrows the current scope sequentially. */

Source from the content-addressed store, hash-verified

2112
2113/* `assert(<predicate>)` narrows the current scope sequentially. */
2114static void apply_assert_narrowing(PHPLSPContext *ctx, TSNode call) {
2115 TSNode fn = ts_node_child_by_field_name(call, "function", 8);
2116 if (ts_node_is_null(fn))
2117 return;
2118 char *name = php_node_text(ctx, fn);
2119 if (!name || strcmp(name, "assert") != 0)
2120 return;
2121 TSNode args = ts_node_child_by_field_name(call, "arguments", 9);
2122 if (ts_node_is_null(args))
2123 return;
2124 uint32_t anc = ts_node_child_count(args);
2125 for (uint32_t i = 0; i < anc; i++) {
2126 TSNode a = ts_node_child(args, i);
2127 if (ts_node_is_null(a) || !ts_node_is_named(a))
2128 continue;
2129 TSNode predicate = a;
2130 if (strcmp(ts_node_type(a), "argument") == 0) {
2131 uint32_t bnc = ts_node_child_count(a);
2132 for (uint32_t j = 0; j < bnc; j++) {
2133 TSNode b = ts_node_child(a, j);
2134 if (!ts_node_is_null(b) && ts_node_is_named(b)) {
2135 predicate = b;
2136 break;
2137 }
2138 }
2139 }
2140 php_narrowing_t nw = {0};
2141 if (parse_narrowing(ctx, predicate, &nw) && nw.var_name && nw.type) {
2142 cbm_scope_bind(ctx->current_scope, nw.var_name, nw.type);
2143 }
2144 return;
2145 }
2146}
2147
2148/* Walk a body subtree under a narrowed scope (with up to N bindings), then
2149 * restore. */

Callers 1

Calls 3

php_node_textFunction · 0.85
parse_narrowingFunction · 0.85
cbm_scope_bindFunction · 0.85

Tested by

no test coverage detected