| 1375 | } |
| 1376 | |
| 1377 | static const char *func_node_name(CBMArena *a, TSNode func_node, const char *source, |
| 1378 | CBMLanguage lang) { |
| 1379 | // Wolfram: set_delayed_top/set_top/set_delayed/set — LHS is apply(user_symbol("f"), ...) |
| 1380 | if (lang == CBM_LANG_WOLFRAM) { |
| 1381 | const char *nk = ts_node_type(func_node); |
| 1382 | if (strcmp(nk, "set_delayed_top") == 0 || strcmp(nk, "set_top") == 0 || |
| 1383 | strcmp(nk, "set_delayed") == 0 || strcmp(nk, "set") == 0) { |
| 1384 | if (ts_node_named_child_count(func_node) > 0) { |
| 1385 | TSNode lhs = ts_node_named_child(func_node, 0); |
| 1386 | if (strcmp(ts_node_type(lhs), "apply") == 0 && ts_node_named_child_count(lhs) > 0) { |
| 1387 | TSNode head = ts_node_named_child(lhs, 0); |
| 1388 | if (strcmp(ts_node_type(head), "user_symbol") == 0) { |
| 1389 | return cbm_node_text(a, head, source); |
| 1390 | } |
| 1391 | } |
| 1392 | } |
| 1393 | return NULL; |
| 1394 | } |
| 1395 | } |
| 1396 | |
| 1397 | TSNode name_node = ts_node_child_by_field_name(func_node, TS_FIELD("name")); |
| 1398 | if (!ts_node_is_null(name_node)) { |
| 1399 | return cbm_node_text(a, name_node, source); |
| 1400 | } |
| 1401 | // Arrow functions: check parent variable_declarator |
| 1402 | if (strcmp(ts_node_type(func_node), "arrow_function") == 0) { |
| 1403 | TSNode parent = ts_node_parent(func_node); |
| 1404 | if (!ts_node_is_null(parent) && strcmp(ts_node_type(parent), "variable_declarator") == 0) { |
| 1405 | TSNode vname = ts_node_child_by_field_name(parent, TS_FIELD("name")); |
| 1406 | if (!ts_node_is_null(vname)) { |
| 1407 | return cbm_node_text(a, vname, source); |
| 1408 | } |
| 1409 | } |
| 1410 | } |
| 1411 | // C/C++/CUDA/GLSL: function_definition carries its name in the declarator chain. |
| 1412 | if (strcmp(ts_node_type(func_node), "function_definition") == 0) { |
| 1413 | TSNode dn = cbm_resolve_c_declarator_name_node(func_node); |
| 1414 | if (!ts_node_is_null(dn)) { |
| 1415 | return cbm_func_name_node_text(a, dn, source, lang); |
| 1416 | } |
| 1417 | } |
| 1418 | return NULL; |
| 1419 | } |
| 1420 | |
| 1421 | const char *cbm_enclosing_func_qn(CBMArena *a, TSNode node, CBMLanguage lang, const char *source, |
| 1422 | const char *project, const char *rel_path, |
no test coverage detected