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

Function c_process_statement

internal/cbm/lsp/c_lsp.c:3467–4143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3465}
3466
3467void c_process_statement(CLSPContext *ctx, TSNode node) {
3468 if (ctx->eval_failure)
3469 return;
3470 if (ts_node_is_null(node))
3471 return;
3472 const char *kind = ts_node_type(node);
3473
3474 // declaration: Type var = expr; or Type var1, var2;
3475 if (strcmp(kind, "declaration") == 0) {
3476 const CBMType *base_type = c_parse_declaration_type(ctx, node);
3477 bool has_auto = false;
3478
3479 // Check if type is auto/decltype
3480 uint32_t nc = ts_node_named_child_count(node);
3481 for (uint32_t i = 0; i < nc; i++) {
3482 TSNode child = ts_node_named_child(node, i);
3483 const char *ck = ts_node_type(child);
3484 if (strcmp(ck, "placeholder_type_specifier") == 0 || strcmp(ck, "auto") == 0) {
3485 has_auto = true;
3486 break;
3487 }
3488 if (strcmp(ck, "decltype") == 0) {
3489 base_type = c_parse_type_node(ctx, child);
3490 break;
3491 }
3492 }
3493
3494 // Process each declarator
3495 for (uint32_t i = 0; i < nc; i++) {
3496 TSNode child = ts_node_named_child(node, i);
3497 const char *ck = ts_node_type(child);
3498
3499 if (strcmp(ck, "init_declarator") == 0) {
3500 TSNode decl = ts_node_child_by_field_name(child, "declarator", 10);
3501 TSNode value = ts_node_child_by_field_name(child, "value", 5);
3502
3503 const CBMType *var_type = base_type;
3504
3505 // For auto, infer from initializer
3506 if (has_auto && !ts_node_is_null(value)) {
3507 var_type = c_eval_expr_type(ctx, value);
3508 }
3509
3510 // Get variable name from declarator
3511 if (!ts_node_is_null(decl)) {
3512 const char *dk = ts_node_type(decl);
3513 char *var_name = NULL;
3514
3515 if (strcmp(dk, "identifier") == 0) {
3516 var_name = c_node_text(ctx, decl);
3517 } else if (strcmp(dk, "pointer_declarator") == 0) {
3518 // Count pointer depth and find identifier
3519 int ptr_depth = 0;
3520 TSNode inner = decl;
3521 while (!ts_node_is_null(inner) &&
3522 strcmp(ts_node_type(inner), "pointer_declarator") == 0) {
3523 ptr_depth++;
3524 uint32_t dnc = ts_node_named_child_count(inner);

Callers 3

c_process_functionFunction · 0.85
c_bind_file_scope_itemFunction · 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
c_struct_field_type_atFunction · 0.85
cbm_scope_bindFunction · 0.85

Tested by

no test coverage detected