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

Function extract_class_variables

internal/cbm/extract_defs.c:11098–11137  ·  view source on GitHub ↗

Extract class-level variables (field declarations inside class bodies). A declaration that extract_class_fields already made a Field (the defs from `fields_from` on) is not minted again: Java, C# and Solidity list the same kind as field and variable, and the second copy was a Variable with the module's qualified name (`demo.query.filters` for field Query.filters), which collided with package paths

Source from the content-addressed store, hash-verified

11096// module's qualified name (`demo.query.filters` for field Query.filters),
11097// which collided with package paths.
11098static void extract_class_variables(CBMExtractCtx *ctx, TSNode class_node, const char *class_qn,
11099 const CBMLangSpec *spec, int fields_from) {
11100 if (!spec->variable_node_types || !spec->variable_node_types[0]) {
11101 return;
11102 }
11103
11104 TSNode body = find_class_member_body(class_node, ctx->language);
11105 if (ts_node_is_null(body)) {
11106 return;
11107 }
11108
11109 /* the Fields of this body, in body order: walked alongside the children */
11110 int fields_to = ctx->result->defs.count;
11111 int fi = fields_from;
11112
11113 /* Record the declaring class on every variable minted from this body (see
11114 * push_var_def_qn); saved/restored so module-level minting stays bare. */
11115 const char *saved_parent = ctx->var_parent_class;
11116 ctx->var_parent_class = class_qn;
11117 member_iter_t it;
11118 member_iter_init(&it, body, ctx->language, true);
11119 TSNode child;
11120 while (member_iter_next(&it, &child)) {
11121 if (!cbm_kind_in_set(child, spec->variable_node_types)) {
11122 continue;
11123 }
11124 int line = (int)ts_node_start_point(child).row + TS_LINE_OFFSET;
11125 while (fi < fields_to && (strcmp(ctx->result->defs.items[fi].label, "Field") != 0 ||
11126 (int)ctx->result->defs.items[fi].start_line < line)) {
11127 fi++;
11128 }
11129 if (fi < fields_to && (int)ctx->result->defs.items[fi].start_line == line &&
11130 spec->field_node_types && cbm_kind_in_set(child, spec->field_node_types)) {
11131 continue; /* already a Field of this class */
11132 }
11133 extract_var_names(ctx, child, spec);
11134 }
11135 member_iter_done(&it);
11136 ctx->var_parent_class = saved_parent;
11137}
11138
11139// --- Module node + main walk ---
11140

Callers 1

emit_class_defFunction · 0.85

Calls 6

find_class_member_bodyFunction · 0.85
member_iter_initFunction · 0.85
member_iter_nextFunction · 0.85
cbm_kind_in_setFunction · 0.85
extract_var_namesFunction · 0.85
member_iter_doneFunction · 0.85

Tested by

no test coverage detected