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

Function c_process_class

internal/cbm/lsp/c_lsp.c:6112–6375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6110// ============================================================================
6111
6112static void c_process_class(CLSPContext *ctx, TSNode class_node) {
6113 const char *saved_class = ctx->enclosing_class_qn;
6114 const char **saved_tpn = ctx->template_param_names;
6115 const CBMType **saved_tpd = ctx->template_param_defaults;
6116 int saved_tpc = ctx->template_param_count;
6117
6118 char *class_name = NULL;
6119 TSNode name_node = ts_node_child_by_field_name(class_node, "name", 4);
6120 if (!ts_node_is_null(name_node)) {
6121 class_name = c_node_text(ctx, name_node);
6122 if (class_name) {
6123 const char *class_qn;
6124 if (ctx->current_namespace) {
6125 class_qn =
6126 cbm_arena_sprintf(ctx->arena, "%s.%s", ctx->current_namespace, class_name);
6127 } else if (ctx->module_qn) {
6128 class_qn = cbm_arena_sprintf(ctx->arena, "%s.%s", ctx->module_qn, class_name);
6129 } else {
6130 class_qn = class_name;
6131 }
6132 ctx->enclosing_class_qn = class_qn;
6133
6134 // Store template param names on the registered type (for substitution)
6135 if (ctx->in_template && ctx->template_param_names && ctx->template_param_count > 0) {
6136 CBMRegisteredType *rt = cbm_registry_type_for_update(ctx->registry_head, class_qn);
6137 if (rt && !rt->type_param_names) {
6138 const char **tpn = (const char **)cbm_arena_alloc(
6139 ctx->arena, (ctx->template_param_count + 1) * sizeof(const char *));
6140 for (int pi = 0; pi < ctx->template_param_count; pi++)
6141 tpn[pi] = ctx->template_param_names[pi];
6142 tpn[ctx->template_param_count] = NULL;
6143 rt->type_param_names = tpn;
6144 }
6145 }
6146 }
6147 }
6148
6149 // CRTP detection: class Derived : Base<Derived>
6150 // When a base class template argument matches the class name,
6151 // bind that template parameter to the derived class type.
6152 if (class_name && ctx->enclosing_class_qn) {
6153 // Walk base_class_clause children looking for template base classes
6154 uint32_t cnc = ts_node_named_child_count(class_node);
6155 for (uint32_t ci = 0; ci < cnc; ci++) {
6156 TSNode child = ts_node_named_child(class_node, ci);
6157 if (ts_node_is_null(child))
6158 continue;
6159 const char *ck = ts_node_type(child);
6160 if (strcmp(ck, "base_class_clause") != 0)
6161 continue;
6162 // Iterate base specifiers
6163 uint32_t bnc = ts_node_named_child_count(child);
6164 for (uint32_t bi = 0; bi < bnc; bi++) {
6165 TSNode base_spec = ts_node_named_child(child, bi);
6166 if (ts_node_is_null(base_spec))
6167 continue;
6168 // Look for template_type as base: Base<Derived>
6169 TSNode type_node = base_spec;

Callers 1

c_process_body_childFunction · 0.85

Calls 15

c_node_textFunction · 0.85
cbm_type_namedFunction · 0.85
cbm_lsp_collect_childrenFunction · 0.85
c_parse_declaration_typeFunction · 0.85
cbm_type_funcFunction · 0.85
cbm_registry_add_funcFunction · 0.85
cbm_type_referenceFunction · 0.85
cbm_type_pointerFunction · 0.85

Tested by

no test coverage detected