Push a single method definition
| 4653 | |
| 4654 | // Push a single method definition |
| 4655 | static void push_method_def(CBMExtractCtx *ctx, TSNode child, TSNode class_node, |
| 4656 | const char *class_qn, const CBMLangSpec *spec, TSNode name_node) { |
| 4657 | CBMArena *a = ctx->arena; |
| 4658 | |
| 4659 | char *name = cbm_func_name_node_text(a, name_node, ctx->source, ctx->language); |
| 4660 | if (!name || !name[0]) { |
| 4661 | return; |
| 4662 | } |
| 4663 | |
| 4664 | const char *method_qn = cbm_arena_sprintf(a, "%s.%s", class_qn, name); |
| 4665 | |
| 4666 | CBMDefinition def; |
| 4667 | memset(&def, 0, sizeof(def)); |
| 4668 | def.name = name; |
| 4669 | def.qualified_name = method_qn; |
| 4670 | def.label = "Method"; |
| 4671 | def.file_path = ctx->rel_path; |
| 4672 | def.parent_class = class_qn; |
| 4673 | def.start_line = ts_node_start_point(child).row + TS_LINE_OFFSET; |
| 4674 | def.end_line = ts_node_end_point(child).row + TS_LINE_OFFSET; |
| 4675 | def.lines = (int)(def.end_line - def.start_line + TS_LINE_OFFSET); |
| 4676 | def.is_exported = cbm_is_exported(name, ctx->language); |
| 4677 | if (ctx->language == CBM_LANG_RUST && |
| 4678 | strcmp(ts_node_type(child), "function_signature_item") == 0) { |
| 4679 | def.is_abstract = true; |
| 4680 | } |
| 4681 | |
| 4682 | TSNode params = find_function_params(child, ctx->language); |
| 4683 | if (!ts_node_is_null(params)) { |
| 4684 | def.signature = cbm_node_text(a, params, ctx->source); |
| 4685 | def.param_types = extract_param_types(a, params, ctx->source, ctx->language); |
| 4686 | def.signature_param_types = extract_signature_param_types( |
| 4687 | a, params, ctx->source, ctx->language, true, &def.signature_param_count); |
| 4688 | } |
| 4689 | |
| 4690 | // Return type (same fields as extract_func_def) |
| 4691 | { |
| 4692 | static const char *rt_fields[] = {"result", "return_type", "type", NULL}; |
| 4693 | for (const char **f = rt_fields; *f; f++) { |
| 4694 | TSNode rt = ts_node_child_by_field_name(child, *f, (uint32_t)strlen(*f)); |
| 4695 | if (!ts_node_is_null(rt)) { |
| 4696 | def.return_type = cbm_node_text(a, rt, ctx->source); |
| 4697 | break; |
| 4698 | } |
| 4699 | } |
| 4700 | } |
| 4701 | |
| 4702 | // ObjectScript: return type is method_definition -> return_type -> typename. |
| 4703 | if (!def.return_type && (ctx->language == CBM_LANG_OBJECTSCRIPT_UDL || |
| 4704 | ctx->language == CBM_LANG_OBJECTSCRIPT_ROUTINE)) { |
| 4705 | TSNode mdef = cbm_find_child_by_kind(child, "method_definition"); |
| 4706 | if (ts_node_is_null(mdef)) { |
| 4707 | mdef = child; |
| 4708 | } |
| 4709 | TSNode rt_node = cbm_find_child_by_kind(mdef, "return_type"); |
| 4710 | if (!ts_node_is_null(rt_node)) { |
| 4711 | TSNode tname = cbm_find_child_by_kind(rt_node, "typename"); |
| 4712 | if (!ts_node_is_null(tname)) { |
no test coverage detected