Add a @phpstan-type alias to ctx (idempotent — keeps first definition). */
| 610 | |
| 611 | /* Add a @phpstan-type alias to ctx (idempotent — keeps first definition). */ |
| 612 | static void php_add_phpstan_alias(PHPLSPContext *ctx, const char *name, const CBMType *type) { |
| 613 | if (!ctx || !name || !type) |
| 614 | return; |
| 615 | for (int i = 0; i < ctx->phpstan_alias_count; i++) { |
| 616 | if (strcmp(ctx->phpstan_alias_names[i], name) == 0) |
| 617 | return; |
| 618 | } |
| 619 | if (ctx->phpstan_alias_count >= ctx->phpstan_alias_cap) { |
| 620 | int new_cap = ctx->phpstan_alias_cap ? ctx->phpstan_alias_cap * 2 : 8; |
| 621 | const char **nn = |
| 622 | (const char **)cbm_arena_alloc(ctx->arena, (size_t)(new_cap + 1) * sizeof(*nn)); |
| 623 | const CBMType **nt = |
| 624 | (const CBMType **)cbm_arena_alloc(ctx->arena, (size_t)(new_cap + 1) * sizeof(*nt)); |
| 625 | if (!nn || !nt) |
| 626 | return; |
| 627 | for (int i = 0; i < ctx->phpstan_alias_count; i++) { |
| 628 | nn[i] = ctx->phpstan_alias_names[i]; |
| 629 | nt[i] = ctx->phpstan_alias_types[i]; |
| 630 | } |
| 631 | ctx->phpstan_alias_names = nn; |
| 632 | ctx->phpstan_alias_types = nt; |
| 633 | ctx->phpstan_alias_cap = new_cap; |
| 634 | } |
| 635 | ctx->phpstan_alias_names[ctx->phpstan_alias_count] = cbm_arena_strdup(ctx->arena, name); |
| 636 | ctx->phpstan_alias_types[ctx->phpstan_alias_count] = type; |
| 637 | ctx->phpstan_alias_count++; |
| 638 | } |
| 639 | |
| 640 | static const CBMType *php_lookup_phpstan_alias(PHPLSPContext *ctx, const char *name) { |
| 641 | if (!ctx || !name) |
no test coverage detected