| 1773 | } |
| 1774 | |
| 1775 | static void emit_php_use_decl(CBMExtractCtx *ctx, TSNode decl) { |
| 1776 | CBMArena *a = ctx->arena; |
| 1777 | const CBMImportKind decl_kind = php_use_kind(decl); |
| 1778 | // Grouped form: namespace_use_group with a leading prefix qualified_name. |
| 1779 | TSNode group = decl; |
| 1780 | if (find_first_descendant_of(decl, "namespace_use_group", &group)) { |
| 1781 | // The prefix is the qualified_name sibling preceding the group within decl. |
| 1782 | char *prefix = NULL; |
| 1783 | uint32_t dc = ts_node_named_child_count(decl); |
| 1784 | for (uint32_t i = 0; i < dc; i++) { |
| 1785 | TSNode c = ts_node_named_child(decl, i); |
| 1786 | const char *ck = ts_node_type(c); |
| 1787 | if (strcmp(ck, "qualified_name") == 0 || strcmp(ck, "namespace_name") == 0 || |
| 1788 | strcmp(ck, "name") == 0) { |
| 1789 | prefix = cbm_node_text(a, c, ctx->source); |
| 1790 | break; |
| 1791 | } |
| 1792 | } |
| 1793 | uint32_t gc = ts_node_named_child_count(group); |
| 1794 | for (uint32_t i = 0; i < gc; i++) { |
| 1795 | TSNode clause = ts_node_named_child(group, i); |
| 1796 | const char *ck = ts_node_type(clause); |
| 1797 | if (strcmp(ck, "namespace_use_group_clause") == 0 || |
| 1798 | strcmp(ck, "namespace_use_clause") == 0) { |
| 1799 | emit_php_use_clause(ctx, clause, prefix, decl_kind); |
| 1800 | } |
| 1801 | } |
| 1802 | return; |
| 1803 | } |
| 1804 | // Flat form: one or more namespace_use_clause children. |
| 1805 | uint32_t dc = ts_node_named_child_count(decl); |
| 1806 | bool any = false; |
| 1807 | for (uint32_t i = 0; i < dc; i++) { |
| 1808 | TSNode clause = ts_node_named_child(decl, i); |
| 1809 | if (strcmp(ts_node_type(clause), "namespace_use_clause") == 0) { |
| 1810 | emit_php_use_clause(ctx, clause, NULL, decl_kind); |
| 1811 | any = true; |
| 1812 | } |
| 1813 | } |
| 1814 | if (!any) { |
| 1815 | // Some grammar versions inline the path directly under the declaration. |
| 1816 | emit_php_use_clause(ctx, decl, NULL, decl_kind); |
| 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | static void parse_php_imports(CBMExtractCtx *ctx) { |
| 1821 | TSTreeCursor cursor = ts_tree_cursor_new(ctx->root); |
no test coverage detected