Try to extract method name from a node, with language-specific fallbacks.
| 4029 | |
| 4030 | // Try to extract method name from a node, with language-specific fallbacks. |
| 4031 | static TSNode resolve_method_name(TSNode child, CBMLanguage lang) { |
| 4032 | TSNode name_node = func_name_node(child); |
| 4033 | if (!ts_node_is_null(name_node)) { |
| 4034 | return name_node; |
| 4035 | } |
| 4036 | |
| 4037 | const char *ck = ts_node_type(child); |
| 4038 | |
| 4039 | if ((lang == CBM_LANG_C || lang == CBM_LANG_CPP || lang == CBM_LANG_CUDA || |
| 4040 | lang == CBM_LANG_GLSL) && |
| 4041 | strcmp(ck, "function_definition") == 0) { |
| 4042 | return cbm_resolve_func_name(child, lang); |
| 4043 | } |
| 4044 | |
| 4045 | if (lang == CBM_LANG_GROOVY && strcmp(ck, "function_definition") == 0) { |
| 4046 | TSNode fn = ts_node_child_by_field_name(child, TS_FIELD("function")); |
| 4047 | if (!ts_node_is_null(fn)) { |
| 4048 | return fn; |
| 4049 | } |
| 4050 | return cbm_find_child_by_kind(child, "identifier"); |
| 4051 | } |
| 4052 | |
| 4053 | if (lang == CBM_LANG_DART) { |
| 4054 | return resolve_dart_method_name(child, ck); |
| 4055 | } |
| 4056 | |
| 4057 | if (lang == CBM_LANG_OBJC && strcmp(ck, "method_definition") == 0) { |
| 4058 | return cbm_find_child_by_kind(child, "identifier"); |
| 4059 | } |
| 4060 | |
| 4061 | // Pony: `fun`/`be`/`new` members are `method`/`constructor`/`ffi_method` |
| 4062 | // nodes with no `name` field; the name is the first plain `identifier` child |
| 4063 | // (mirrors the free-function case in cbm_resolve_func_name). |
| 4064 | if (lang == CBM_LANG_PONY && (strcmp(ck, "method") == 0 || strcmp(ck, "constructor") == 0 || |
| 4065 | strcmp(ck, "ffi_method") == 0)) { |
| 4066 | return cbm_find_child_by_kind(child, "identifier"); |
| 4067 | } |
| 4068 | |
| 4069 | if ((lang == CBM_LANG_SWIFT || lang == CBM_LANG_KOTLIN) && |
| 4070 | strcmp(ck, "function_declaration") == 0) { |
| 4071 | return cbm_find_child_by_kind(child, "simple_identifier"); |
| 4072 | } |
| 4073 | |
| 4074 | // Squirrel: function_declaration's name is a plain `identifier` child. |
| 4075 | if (lang == CBM_LANG_SQUIRREL && strcmp(ck, "function_declaration") == 0) { |
| 4076 | return cbm_find_child_by_kind(child, "identifier"); |
| 4077 | } |
| 4078 | |
| 4079 | if (strcmp(ck, "arrow_function") == 0) { |
| 4080 | return resolve_arrow_func_name(child); |
| 4081 | } |
| 4082 | |
| 4083 | TSNode null_node = {0}; |
| 4084 | return null_node; |
| 4085 | } |
| 4086 | |
| 4087 | // Push a single method definition |
| 4088 | static void push_method_def(CBMExtractCtx *ctx, TSNode child, TSNode class_node, |
no test coverage detected