| 6511 | } |
| 6512 | |
| 6513 | static void extract_func_def(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec) { |
| 6514 | CBMArena *a = ctx->arena; |
| 6515 | |
| 6516 | TSNode name_node = cbm_resolve_func_name(node, ctx->language); |
| 6517 | if (ctx->language == CBM_LANG_C && ctx->test_declarations && |
| 6518 | ctx->test_declarations_raw_source) { |
| 6519 | TSNode candidate_name, candidate_body; |
| 6520 | if (cbm_test_definition_candidate(node, ctx->language, &candidate_name, &candidate_body)) { |
| 6521 | uint32_t begin = ts_node_start_byte(candidate_name); |
| 6522 | uint32_t end = ts_node_end_byte(candidate_name); |
| 6523 | TDXRule rule; |
| 6524 | if (end > begin && end <= (uint32_t)ctx->source_len && |
| 6525 | tdx_match(ctx, ctx->source + begin, end - begin, |
| 6526 | ts_node_start_point(candidate_name).row + 1, &rule)) |
| 6527 | name_node = candidate_name; |
| 6528 | } |
| 6529 | } |
| 6530 | if (ts_node_is_null(name_node)) { |
| 6531 | return; |
| 6532 | } |
| 6533 | |
| 6534 | char *name = cbm_func_name_node_text(a, name_node, ctx->source, ctx->language); |
| 6535 | if (!name || !name[0] || strcmp(name, "function") == 0) { |
| 6536 | return; |
| 6537 | } |
| 6538 | |
| 6539 | // Makefile special targets (.PHONY, .DEFAULT, .SUFFIXES, …) are directives, |
| 6540 | // not build-rule defs. Their leading '.' would also make cbm_fqn_compute |
| 6541 | // emit a "..PHONY" segment (a "double dot") and thus a malformed QN. Skip |
| 6542 | // any dot-prefixed Make target. |
| 6543 | if (ctx->language == CBM_LANG_MAKEFILE && name[0] == '.') { |
| 6544 | return; |
| 6545 | } |
| 6546 | // `targets: [export] VAR := value` sets a variable for those targets: |
| 6547 | // no rule, so no def (else a target only ever configured there is a |
| 6548 | // phantom, and a real rule of it gains the line as a variant). |
| 6549 | if (ctx->language == CBM_LANG_MAKEFILE && make_rule_sets_variable(node, ctx->source)) { |
| 6550 | return; |
| 6551 | } |
| 6552 | |
| 6553 | /* C++/CUDA: GoogleTest macros (TEST, TEST_F, TEST_P, ...) parse as |
| 6554 | * function definitions whose name resolves to the bare macro identifier. |
| 6555 | * Multiple test cases per file collide on qualified name; derive a unique |
| 6556 | * name from the macro arguments so each gets its own graph node (#1266). */ |
| 6557 | bool is_gtest = false; |
| 6558 | const char *configured_name = NULL; |
| 6559 | TDXRule configured_rule; |
| 6560 | bool configured = tdx_resolve(ctx, node, name_node, name, &configured_name, &configured_rule); |
| 6561 | if (configured) { |
| 6562 | if (!configured_name) |
| 6563 | return; |
| 6564 | name = (char *)configured_name; |
| 6565 | } |
| 6566 | if (!configured && tdx_preset(ctx, CBM_TEST_PRESET_GTEST) && |
| 6567 | (ctx->language == CBM_LANG_CPP || ctx->language == CBM_LANG_CUDA) && |
| 6568 | is_cpp_test_macro(name)) { |
| 6569 | char *gtest_name = resolve_cpp_test_macro_name(a, name, node, ctx->source); |
| 6570 | if (gtest_name) { |
no test coverage detected