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

Function c_process_statement

internal/cbm/lsp/c_lsp.c:2944–3609  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2942}
2943
2944void c_process_statement(CLSPContext *ctx, TSNode node) {
2945 if (ts_node_is_null(node))
2946 return;
2947 const char *kind = ts_node_type(node);
2948
2949 // declaration: Type var = expr; or Type var1, var2;
2950 if (strcmp(kind, "declaration") == 0) {
2951 const CBMType *base_type = c_parse_declaration_type(ctx, node);
2952 bool has_auto = false;
2953
2954 // Check if type is auto/decltype
2955 uint32_t nc = ts_node_named_child_count(node);
2956 for (uint32_t i = 0; i < nc; i++) {
2957 TSNode child = ts_node_named_child(node, i);
2958 const char *ck = ts_node_type(child);
2959 if (strcmp(ck, "placeholder_type_specifier") == 0 || strcmp(ck, "auto") == 0) {
2960 has_auto = true;
2961 break;
2962 }
2963 if (strcmp(ck, "decltype") == 0) {
2964 base_type = c_parse_type_node(ctx, child);
2965 break;
2966 }
2967 }
2968
2969 // Process each declarator
2970 for (uint32_t i = 0; i < nc; i++) {
2971 TSNode child = ts_node_named_child(node, i);
2972 const char *ck = ts_node_type(child);
2973
2974 if (strcmp(ck, "init_declarator") == 0) {
2975 TSNode decl = ts_node_child_by_field_name(child, "declarator", 10);
2976 TSNode value = ts_node_child_by_field_name(child, "value", 5);
2977
2978 const CBMType *var_type = base_type;
2979
2980 // For auto, infer from initializer
2981 if (has_auto && !ts_node_is_null(value)) {
2982 var_type = c_eval_expr_type(ctx, value);
2983 }
2984
2985 // Get variable name from declarator
2986 if (!ts_node_is_null(decl)) {
2987 const char *dk = ts_node_type(decl);
2988 char *var_name = NULL;
2989
2990 if (strcmp(dk, "identifier") == 0) {
2991 var_name = c_node_text(ctx, decl);
2992 } else if (strcmp(dk, "pointer_declarator") == 0) {
2993 // Count pointer depth and find identifier
2994 int ptr_depth = 0;
2995 TSNode inner = decl;
2996 while (!ts_node_is_null(inner) &&
2997 strcmp(ts_node_type(inner), "pointer_declarator") == 0) {
2998 ptr_depth++;
2999 uint32_t dnc = ts_node_named_child_count(inner);
3000 inner = dnc > 0 ? ts_node_named_child(inner, dnc - 1) : (TSNode){0};
3001 }

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