| 3821 | } |
| 3822 | |
| 3823 | static void process_trait_use(PHPLSPContext *ctx, CBMTypeRegistry *reg, const char *class_qn, |
| 3824 | TSNode use_decl) { |
| 3825 | /* Collect the named traits and any `as` alias clauses. */ |
| 3826 | const char *trait_qns[16]; |
| 3827 | int trait_count = 0; |
| 3828 | |
| 3829 | uint32_t nc = ts_node_child_count(use_decl); |
| 3830 | for (uint32_t i = 0; i < nc && trait_count < 16; i++) { |
| 3831 | TSNode c = ts_node_child(use_decl, i); |
| 3832 | if (ts_node_is_null(c) || !ts_node_is_named(c)) |
| 3833 | continue; |
| 3834 | const char *k = ts_node_type(c); |
| 3835 | if (strcmp(k, "name") == 0 || strcmp(k, "qualified_name") == 0) { |
| 3836 | char *tn = php_node_text(ctx, c); |
| 3837 | if (tn) { |
| 3838 | const char *resolved = php_resolve_class_name(ctx, tn); |
| 3839 | if (resolved) |
| 3840 | trait_qns[trait_count++] = resolved; |
| 3841 | } |
| 3842 | } |
| 3843 | } |
| 3844 | |
| 3845 | /* First, do the default flatten for all traits. */ |
| 3846 | for (int i = 0; i < trait_count; i++) { |
| 3847 | flatten_trait_into_class(ctx, reg, class_qn, trait_qns[i], NULL, NULL); |
| 3848 | } |
| 3849 | |
| 3850 | /* Process `use_list` block for `as` / `insteadof` clauses. The block is |
| 3851 | * either named "body" or a sibling. */ |
| 3852 | for (uint32_t i = 0; i < nc; i++) { |
| 3853 | TSNode c = ts_node_child(use_decl, i); |
| 3854 | if (ts_node_is_null(c) || !ts_node_is_named(c)) |
| 3855 | continue; |
| 3856 | const char *k = ts_node_type(c); |
| 3857 | if (strcmp(k, "use_list") != 0 && strcmp(k, "use_clause") != 0) { |
| 3858 | uint32_t bnc = ts_node_child_count(c); |
| 3859 | for (uint32_t j = 0; j < bnc; j++) { |
| 3860 | TSNode cc = ts_node_child(c, j); |
| 3861 | if (ts_node_is_null(cc) || !ts_node_is_named(cc)) |
| 3862 | continue; |
| 3863 | const char *kk = ts_node_type(cc); |
| 3864 | if (strcmp(kk, "use_as_clause") == 0) { |
| 3865 | /* Trait::method as alias OR method as alias */ |
| 3866 | char *trait_text = NULL; |
| 3867 | char *method_text = NULL; |
| 3868 | char *alias_text = NULL; |
| 3869 | uint32_t anc = ts_node_child_count(cc); |
| 3870 | for (uint32_t a = 0; a < anc; a++) { |
| 3871 | TSNode ch = ts_node_child(cc, a); |
| 3872 | if (ts_node_is_null(ch) || !ts_node_is_named(ch)) |
| 3873 | continue; |
| 3874 | const char *ck = ts_node_type(ch); |
| 3875 | if (strcmp(ck, "class_constant_access_expression") == 0) { |
| 3876 | /* Trait::method */ |
| 3877 | uint32_t cc2 = ts_node_child_count(ch); |
| 3878 | for (uint32_t a2 = 0; a2 < cc2; a2++) { |
| 3879 | TSNode subch = ts_node_child(ch, a2); |
| 3880 | if (ts_node_is_null(subch) || !ts_node_is_named(subch)) |
no test coverage detected