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

Function extract_class_def

internal/cbm/extract_defs.c:7529–7827  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7527}
7528
7529static void extract_class_def(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec) {
7530 CBMArena *a = ctx->arena;
7531 const char *kind = ts_node_type(node);
7532
7533 if (extract_config_class_def(ctx, node, kind)) {
7534 return;
7535 }
7536 if (extract_sql_ddl_class_def(ctx, node, kind)) {
7537 return;
7538 }
7539 if (is_c_tag_reference(ctx->language, node, kind)) {
7540 return;
7541 }
7542 /* A C/C++ typedef carries no `name` field (the alias names live in its
7543 * declarators), so the generic path below always dropped it. */
7544 if (is_c_declarator_lang(ctx->language) && strcmp(kind, "type_definition") == 0) {
7545 extract_c_typedef(ctx, node, spec);
7546 return;
7547 }
7548 /* An anonymous C-family enum (`enum { A, B };`, also as a variable's or
7549 * member's type) has no Enum def to mint, but its enumerators are names of
7550 * the enclosing scope all the same. Inside a typedef, extract_c_typedef
7551 * names the enum and emits them. */
7552 if (c_enum_lang(ctx->language) && strcmp(kind, "enum_specifier") == 0 &&
7553 ts_node_is_null(ts_node_child_by_field_name(node, TS_FIELD("name")))) {
7554 if (!doc_kind_is(doc_parent(ctx, node), "type_definition")) {
7555 extract_enum_members(ctx, node, NULL);
7556 }
7557 return;
7558 }
7559
7560 TSNode name_node = ts_node_child_by_field_name(node, TS_FIELD("name"));
7561 // ObjC: class name is first identifier child
7562 if (ts_node_is_null(name_node) && ctx->language == CBM_LANG_OBJC) {
7563 name_node = cbm_find_child_by_kind(node, "identifier");
7564 }
7565 // ObjectScript UDL: class name is a `class_name` child (no "name" field).
7566 if (ts_node_is_null(name_node) && ctx->language == CBM_LANG_OBJECTSCRIPT_UDL) {
7567 name_node = cbm_find_child_by_kind(node, "class_name");
7568 }
7569 // Swift and newer tree-sitter-kotlin: class/object name is a type_identifier
7570 // child (no "name" field).
7571 if (ts_node_is_null(name_node) &&
7572 (ctx->language == CBM_LANG_SWIFT || ctx->language == CBM_LANG_KOTLIN)) {
7573 name_node = cbm_find_child_by_kind(node, "type_identifier");
7574 }
7575 // Protobuf: service_name / message_name / enum_name children
7576 if (ts_node_is_null(name_node) && ctx->language == CBM_LANG_PROTOBUF) {
7577 name_node = cbm_find_child_by_kind(node, "service_name");
7578 if (ts_node_is_null(name_node)) {
7579 name_node = cbm_find_child_by_kind(node, "message_name");
7580 }
7581 if (ts_node_is_null(name_node)) {
7582 name_node = cbm_find_child_by_kind(node, "enum_name");
7583 }
7584 }
7585 // Thrift / Smithy / Pony / PKL (no `name` field): class-type defs carry the
7586 // name on a plain `identifier` child (PKL `clazz` -> `(identifier) (classBody)`).

Callers 1

walk_defsFunction · 0.85

Calls 13

extract_config_class_defFunction · 0.85
is_c_tag_referenceFunction · 0.85
is_c_declarator_langFunction · 0.85
extract_c_typedefFunction · 0.85
c_enum_langFunction · 0.85
doc_kind_isFunction · 0.85
doc_parentFunction · 0.85
extract_enum_membersFunction · 0.85
cbm_find_child_by_kindFunction · 0.85
cbm_node_textFunction · 0.85

Tested by

no test coverage detected