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

Function emit_php_use_decl

internal/cbm/extract_imports.c:1775–1818  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1773}
1774
1775static 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
1820static void parse_php_imports(CBMExtractCtx *ctx) {
1821 TSTreeCursor cursor = ts_tree_cursor_new(ctx->root);

Callers 1

parse_php_importsFunction · 0.85

Calls 4

find_first_descendant_ofFunction · 0.85
cbm_node_textFunction · 0.85
emit_php_use_clauseFunction · 0.85
php_use_kindFunction · 0.70

Tested by

no test coverage detected