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

Function c_process_statement

internal/cbm/lsp/c_lsp.c:2837–3483  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2835}
2836
2837void c_process_statement(CLSPContext *ctx, TSNode node) {
2838 if (ts_node_is_null(node))
2839 return;
2840 const char *kind = ts_node_type(node);
2841
2842 // declaration: Type var = expr; or Type var1, var2;
2843 if (strcmp(kind, "declaration") == 0) {
2844 const CBMType *base_type = c_parse_declaration_type(ctx, node);
2845 bool has_auto = false;
2846
2847 // Check if type is auto/decltype
2848 uint32_t nc = ts_node_named_child_count(node);
2849 for (uint32_t i = 0; i < nc; i++) {
2850 TSNode child = ts_node_named_child(node, i);
2851 const char *ck = ts_node_type(child);
2852 if (strcmp(ck, "placeholder_type_specifier") == 0 || strcmp(ck, "auto") == 0) {
2853 has_auto = true;
2854 break;
2855 }
2856 if (strcmp(ck, "decltype") == 0) {
2857 base_type = c_parse_type_node(ctx, child);
2858 break;
2859 }
2860 }
2861
2862 // Process each declarator
2863 for (uint32_t i = 0; i < nc; i++) {
2864 TSNode child = ts_node_named_child(node, i);
2865 const char *ck = ts_node_type(child);
2866
2867 if (strcmp(ck, "init_declarator") == 0) {
2868 TSNode decl = ts_node_child_by_field_name(child, "declarator", 10);
2869 TSNode value = ts_node_child_by_field_name(child, "value", 5);
2870
2871 const CBMType *var_type = base_type;
2872
2873 // For auto, infer from initializer
2874 if (has_auto && !ts_node_is_null(value)) {
2875 var_type = c_eval_expr_type(ctx, value);
2876 }
2877
2878 // Get variable name from declarator
2879 if (!ts_node_is_null(decl)) {
2880 const char *dk = ts_node_type(decl);
2881 char *var_name = NULL;
2882
2883 if (strcmp(dk, "identifier") == 0) {
2884 var_name = c_node_text(ctx, decl);
2885 } else if (strcmp(dk, "pointer_declarator") == 0) {
2886 // Count pointer depth and find identifier
2887 int ptr_depth = 0;
2888 TSNode inner = decl;
2889 while (!ts_node_is_null(inner) &&
2890 strcmp(ts_node_type(inner), "pointer_declarator") == 0) {
2891 ptr_depth++;
2892 uint32_t dnc = ts_node_named_child_count(inner);
2893 inner = dnc > 0 ? ts_node_named_child(inner, dnc - 1) : (TSNode){0};
2894 }

Callers 3

c_process_functionFunction · 0.85
c_lsp_process_fileFunction · 0.85

Calls 15

c_parse_declaration_typeFunction · 0.85
c_parse_type_nodeFunction · 0.85
c_eval_expr_typeFunction · 0.85
c_node_textFunction · 0.85
cbm_type_pointerFunction · 0.85
cbm_type_unknownFunction · 0.85
c_simplify_typeFunction · 0.85
cbm_type_is_unknownFunction · 0.85
type_to_qnFunction · 0.85
cbm_registry_lookup_typeFunction · 0.85
cbm_scope_bindFunction · 0.85
cbm_type_referenceFunction · 0.85

Tested by

no test coverage detected