MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / extract_cpp_operator_call

Function extract_cpp_operator_call

internal/cbm/extract_calls.c:3440–3519  ·  view source on GitHub ↗

C++ operators represented by expression nodes are real invocations only when overload resolution finds a concrete function. Emit exact-occurrence raw candidates here; requires_lsp_resolution keeps primitive/pointer syntax from falling through to textual registry lookup and fabricating CALLS edges.

Source from the content-addressed store, hash-verified

3438// candidates here; requires_lsp_resolution keeps primitive/pointer syntax from
3439// falling through to textual registry lookup and fabricating CALLS edges.
3440static void extract_cpp_operator_call(CBMExtractCtx *ctx, TSNode node, const char *kind,
3441 const char *enclosing_func_qn) {
3442 if (strcmp(kind, "subscript_expression") == 0) {
3443 TSNode receiver = ts_node_child_by_field_name(node, TS_FIELD("argument"));
3444 TSNode index = ts_node_child_by_field_name(node, TS_FIELD("index"));
3445 if (ts_node_is_null(receiver) && ts_node_named_child_count(node) > 0) {
3446 receiver = ts_node_named_child(node, 0);
3447 }
3448 if (ts_node_is_null(index) && ts_node_named_child_count(node) > 1) {
3449 index = ts_node_named_child(node, 1);
3450 }
3451 if (!ts_node_is_null(receiver) && !ts_node_is_null(index)) {
3452 push_cpp_semantic_call_candidate(ctx, node, "operator[]", enclosing_func_qn);
3453 }
3454 return;
3455 }
3456
3457 if (strcmp(kind, "unary_expression") == 0 || strcmp(kind, "pointer_expression") == 0 ||
3458 strcmp(kind, "update_expression") == 0) {
3459 TSNode operand = ts_node_child_by_field_name(node, TS_FIELD("argument"));
3460 if (ts_node_is_null(operand)) {
3461 operand = ts_node_child_by_field_name(node, TS_FIELD("operand"));
3462 }
3463 if (ts_node_is_null(operand) && ts_node_named_child_count(node) > 0) {
3464 operand = ts_node_named_child(node, 0);
3465 }
3466 const char *token = cpp_operator_token(ctx, node);
3467 bool unary_token = token && (strcmp(token, "-") == 0 || strcmp(token, "*") == 0 ||
3468 strcmp(token, "!") == 0);
3469 bool update_token = token && (strcmp(token, "++") == 0 || strcmp(token, "--") == 0);
3470 /* `this` has the built-in pointer type in C++. Consequently `*this` is
3471 * always pointer dereference and can never dispatch an overloaded
3472 * operator*. Do not manufacture a semantic candidate for it. */
3473 if (!ts_node_is_null(operand) && token && strcmp(token, "*") == 0 &&
3474 strcmp(ts_node_type(operand), "this") == 0) {
3475 return;
3476 }
3477 if (!ts_node_is_null(operand) &&
3478 ((strcmp(kind, "update_expression") == 0 && update_token) ||
3479 (strcmp(kind, "update_expression") != 0 && unary_token))) {
3480 push_cpp_semantic_call_candidate(
3481 ctx, node, cbm_arena_sprintf(ctx->arena, "operator%s", token), enclosing_func_qn);
3482 }
3483 return;
3484 }
3485
3486 if (strcmp(kind, "field_expression") == 0) {
3487 TSNode receiver = ts_node_child_by_field_name(node, TS_FIELD("argument"));
3488 TSNode member = ts_node_child_by_field_name(node, TS_FIELD("field"));
3489 const char *token = cpp_operator_token(ctx, node);
3490 if (!ts_node_is_null(receiver) && !ts_node_is_null(member) && token &&
3491 strcmp(token, "->") == 0) {
3492 push_cpp_semantic_call_candidate(ctx, node, "operator->", enclosing_func_qn);
3493 }
3494 return;
3495 }
3496
3497 if (strcmp(kind, "assignment_expression") == 0) {

Callers 1

handle_callsFunction · 0.85

Calls 4

cpp_operator_tokenFunction · 0.85
cbm_arena_sprintfFunction · 0.70

Tested by

no test coverage detected