| 1028 | } |
| 1029 | |
| 1030 | static const char *func_node_name(CBMArena *a, TSNode func_node, const char *source, |
| 1031 | CBMLanguage lang) { |
| 1032 | // Wolfram: set_delayed_top/set_top/set_delayed/set — LHS is apply(user_symbol("f"), ...) |
| 1033 | if (lang == CBM_LANG_WOLFRAM) { |
| 1034 | const char *nk = ts_node_type(func_node); |
| 1035 | if (strcmp(nk, "set_delayed_top") == 0 || strcmp(nk, "set_top") == 0 || |
| 1036 | strcmp(nk, "set_delayed") == 0 || strcmp(nk, "set") == 0) { |
| 1037 | if (ts_node_named_child_count(func_node) > 0) { |
| 1038 | TSNode lhs = ts_node_named_child(func_node, 0); |
| 1039 | if (strcmp(ts_node_type(lhs), "apply") == 0 && ts_node_named_child_count(lhs) > 0) { |
| 1040 | TSNode head = ts_node_named_child(lhs, 0); |
| 1041 | if (strcmp(ts_node_type(head), "user_symbol") == 0) { |
| 1042 | return cbm_node_text(a, head, source); |
| 1043 | } |
| 1044 | } |
| 1045 | } |
| 1046 | return NULL; |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | TSNode name_node = ts_node_child_by_field_name(func_node, TS_FIELD("name")); |
| 1051 | if (!ts_node_is_null(name_node)) { |
| 1052 | return cbm_node_text(a, name_node, source); |
| 1053 | } |
| 1054 | // Arrow functions: check parent variable_declarator |
| 1055 | if (strcmp(ts_node_type(func_node), "arrow_function") == 0) { |
| 1056 | TSNode parent = ts_node_parent(func_node); |
| 1057 | if (!ts_node_is_null(parent) && strcmp(ts_node_type(parent), "variable_declarator") == 0) { |
| 1058 | TSNode vname = ts_node_child_by_field_name(parent, TS_FIELD("name")); |
| 1059 | if (!ts_node_is_null(vname)) { |
| 1060 | return cbm_node_text(a, vname, source); |
| 1061 | } |
| 1062 | } |
| 1063 | } |
| 1064 | // C/C++/CUDA/GLSL: function_definition carries its name in the declarator chain. |
| 1065 | if (strcmp(ts_node_type(func_node), "function_definition") == 0) { |
| 1066 | TSNode dn = cbm_resolve_c_declarator_name_node(func_node); |
| 1067 | if (!ts_node_is_null(dn)) { |
| 1068 | return cbm_func_name_node_text(a, dn, source, lang); |
| 1069 | } |
| 1070 | } |
| 1071 | return NULL; |
| 1072 | } |
| 1073 | |
| 1074 | const char *cbm_enclosing_func_qn(CBMArena *a, TSNode node, CBMLanguage lang, const char *source, |
| 1075 | const char *project, const char *rel_path, |
no test coverage detected