Recognise `$x = new Foo(...)` / `$x = Foo::create()` etc. and bind the LHS. */
| 1474 | |
| 1475 | /* Recognise `$x = new Foo(...)` / `$x = Foo::create()` etc. and bind the LHS. */ |
| 1476 | static void process_assignment(PHPLSPContext *ctx, TSNode node) { |
| 1477 | TSNode lhs = ts_node_child_by_field_name(node, "left", 4); |
| 1478 | TSNode rhs = ts_node_child_by_field_name(node, "right", 5); |
| 1479 | if (ts_node_is_null(lhs) || ts_node_is_null(rhs)) |
| 1480 | return; |
| 1481 | if (!node_is(lhs, "variable_name")) |
| 1482 | return; |
| 1483 | char *t = php_node_text(ctx, lhs); |
| 1484 | if (!t) |
| 1485 | return; |
| 1486 | const char *name = (t[0] == '$') ? t + 1 : t; |
| 1487 | if (strcmp(name, "this") == 0) |
| 1488 | return; |
| 1489 | const CBMType *rhs_type = php_eval_expr_type(ctx, rhs); |
| 1490 | if (rhs_type && rhs_type->kind != CBM_TYPE_UNKNOWN) { |
| 1491 | /* Don't override a more-specific (NAMED/TEMPLATE) binding with |
| 1492 | * a trivial null literal — preserves `@var T $x; $x = null;`. */ |
| 1493 | if (rhs_type->kind == CBM_TYPE_BUILTIN && rhs_type->data.builtin.name && |
| 1494 | strcmp(rhs_type->data.builtin.name, "null") == 0) { |
| 1495 | const CBMType *existing = cbm_scope_lookup(ctx->current_scope, name); |
| 1496 | if (existing && |
| 1497 | (existing->kind == CBM_TYPE_NAMED || existing->kind == CBM_TYPE_TEMPLATE)) { |
| 1498 | return; |
| 1499 | } |
| 1500 | } |
| 1501 | cbm_scope_bind(ctx->current_scope, name, rhs_type); |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | static void process_foreach(PHPLSPContext *ctx, TSNode node) { |
| 1506 | /* Try to extract the iterable expression's element type. tree-sitter-php |
no test coverage detected