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

Function c_process_function

internal/cbm/lsp/c_lsp.c:5652–5885  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5650}
5651
5652static void c_process_function(CLSPContext *ctx, TSNode func_node) {
5653 if (ctx->eval_failure)
5654 return;
5655 if (c_process_configured_test_body(ctx, func_node))
5656 return;
5657 TSNode decl = ts_node_child_by_field_name(func_node, "declarator", 10);
5658 if (ts_node_is_null(decl))
5659 return;
5660
5661 // Extract function name from declarator chain
5662 char *func_name = NULL;
5663 const char *saved_class_qn = ctx->enclosing_class_qn;
5664 const char *saved_func_qn = ctx->enclosing_func_qn;
5665 TSNode params_node = (TSNode){0};
5666 TSNode macro_arg = (TSNode){0};
5667
5668 // Navigate declarator to find name and parameters
5669 TSNode cur = decl;
5670 // Set after stepping through a recovered `RetT::name` (see
5671 // cbm_c_qualifier_is_recovered): that path names the function with a
5672 // type_identifier, and the "scope" is the return type, not a class.
5673 bool recovered = false;
5674 for (int depth = 0; depth < 10 && !ts_node_is_null(cur); depth++) {
5675 const char *dk = ts_node_type(cur);
5676
5677 if (strcmp(dk, "function_declarator") == 0) {
5678 TSNode fdecl = ts_node_child_by_field_name(cur, "declarator", 10);
5679 params_node = ts_node_child_by_field_name(cur, "parameters", 10);
5680 // `API RetT name(...)`: the real name sits in an ERROR before the
5681 // parameters; the declarator identifier is the return type.
5682 TSNode real = cbm_c_recovered_func_name(cur);
5683 if (!ts_node_is_null(real)) {
5684 func_name = c_node_text(ctx, real);
5685 break;
5686 }
5687 /* #946: the nested declarator is a macro call. These parameters are
5688 * the real ones; step past the macro's own argument list to the
5689 * (possibly class-qualified) macro name, which still scopes it. */
5690 macro_arg = cbm_c_macro_wrapped_name_node(cur);
5691 if (!ts_node_is_null(macro_arg))
5692 fdecl = ts_node_child_by_field_name(fdecl, "declarator", 10);
5693 cur = fdecl;
5694 continue;
5695 }
5696 if (strcmp(dk, "pointer_declarator") == 0 || strcmp(dk, "reference_declarator") == 0 ||
5697 (recovered && strcmp(dk, "pointer_type_declarator") == 0)) {
5698 if (ts_node_named_child_count(cur) > 0)
5699 cur = ts_node_named_child(cur, ts_node_named_child_count(cur) - 1);
5700 else
5701 break;
5702 continue;
5703 }
5704 if (recovered && strcmp(dk, "type_identifier") == 0) {
5705 func_name = c_node_text(ctx, cur);
5706 break;
5707 }
5708 if ((strcmp(dk, "qualified_identifier") == 0 || strcmp(dk, "scoped_identifier") == 0) &&
5709 cbm_c_qualifier_is_recovered(cur)) {

Callers 2

c_process_body_childFunction · 0.85

Calls 15

c_node_textFunction · 0.85
c_build_qnFunction · 0.85
cbm_registry_lookup_typeFunction · 0.85
cbm_c_reserved_func_nameFunction · 0.85
cbm_scope_pushFunction · 0.85

Tested by

no test coverage detected