| 4254 | } |
| 4255 | |
| 4256 | static const char **extract_base_classes(CBMArena *a, TSNode node, const char *source, |
| 4257 | CBMLanguage lang) { |
| 4258 | // ObjectScript: `Class X Extends (A, B)` — bases are class_name children of |
| 4259 | // the class_extends node. |
| 4260 | if (lang == CBM_LANG_OBJECTSCRIPT_UDL) { |
| 4261 | TSNode ext = cbm_find_child_by_kind(node, "class_extends"); |
| 4262 | if (!ts_node_is_null(ext)) { |
| 4263 | const char *bases[MAX_BASES]; |
| 4264 | int base_count = 0; |
| 4265 | uint32_t nc = ts_node_named_child_count(ext); |
| 4266 | for (uint32_t i = 0; i < nc && base_count < MAX_BASES_MINUS_1; i++) { |
| 4267 | TSNode ch = ts_node_named_child(ext, i); |
| 4268 | if (strcmp(ts_node_type(ch), "class_name") == 0) { |
| 4269 | char *base = cbm_node_text(a, ch, source); |
| 4270 | if (base && base[0]) { |
| 4271 | bases[base_count++] = base; |
| 4272 | } |
| 4273 | } |
| 4274 | } |
| 4275 | if (base_count > 0) { |
| 4276 | const char **result = |
| 4277 | (const char **)cbm_arena_alloc(a, (base_count + 1) * sizeof(const char *)); |
| 4278 | if (result) { |
| 4279 | for (int i = 0; i < base_count; i++) { |
| 4280 | result[i] = bases[i]; |
| 4281 | } |
| 4282 | result[base_count] = NULL; |
| 4283 | return result; |
| 4284 | } |
| 4285 | } |
| 4286 | } |
| 4287 | return NULL; |
| 4288 | } |
| 4289 | // Languages whose heritage is not exposed via a tree-sitter field need |
| 4290 | // dedicated walkers; the generic field/keyword path mis-captures them. |
| 4291 | if (lang == CBM_LANG_TYPESCRIPT || lang == CBM_LANG_TSX || lang == CBM_LANG_ARKTS) { |
| 4292 | const char **ts_result = extract_ts_bases(a, node, source); |
| 4293 | if (ts_result) { |
| 4294 | return ts_result; |
| 4295 | } |
| 4296 | } |
| 4297 | if (lang == CBM_LANG_PHP) { |
| 4298 | const char **php_result = extract_php_bases(a, node, source); |
| 4299 | if (php_result) { |
| 4300 | return php_result; |
| 4301 | } |
| 4302 | } |
| 4303 | if (lang == CBM_LANG_KOTLIN) { |
| 4304 | const char **kt_result = extract_kotlin_bases(a, node, source); |
| 4305 | if (kt_result) { |
| 4306 | return kt_result; |
| 4307 | } |
| 4308 | } |
| 4309 | // Squirrel: `class Dog extends Animal` — heritage is an `identifier` child |
| 4310 | // directly following the `extends` keyword (no field). Grab it. |
| 4311 | if (lang == CBM_LANG_SQUIRREL) { |
| 4312 | uint32_t sc = ts_node_child_count(node); |
| 4313 | bool seen_extends = false; |
no test coverage detected