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

Function extract_call_args

internal/cbm/extract_calls.c:2565–2636  ·  view source on GitHub ↗

Extract all arguments from a call expression into call->args[]. */

Source from the content-addressed store, hash-verified

2563
2564/* Extract all arguments from a call expression into call->args[]. */
2565static void extract_call_args(CBMExtractCtx *ctx, TSNode args, CBMCall *call) {
2566 uint32_t argc = ts_node_named_child_count(args);
2567 int positional_idx = 0;
2568 for (uint32_t ai = 0; ai < argc && call->arg_count < CBM_MAX_CALL_ARGS; ai++) {
2569 TSNode arg_node = ts_node_named_child(args, ai);
2570 const char *ak = ts_node_type(arg_node);
2571 /* tree-sitter lists a comment inside the argument list as a named
2572 * child (Java block_comment/line_comment, C-family comment). It is
2573 * not an argument: taken as one, a leading block comment became
2574 * args[0] and the Route pass read its text as a URL. */
2575 if (strcmp(ak, "comment") == 0 || strcmp(ak, "line_comment") == 0 ||
2576 strcmp(ak, "block_comment") == 0) {
2577 continue;
2578 }
2579 if (!call->args) {
2580 call->args = cbm_arena_calloc(ctx->arena, CBM_MAX_CALL_ARGS * sizeof(CBMCallArg));
2581 if (!call->args) {
2582 return;
2583 }
2584 }
2585 CBMCallArg *ca = &call->args[call->arg_count];
2586 memset(ca, 0, sizeof(*ca));
2587
2588 if (strcmp(ak, "keyword_argument") == 0 || strcmp(ak, "pair") == 0) {
2589 process_keyword_arg(ctx, arg_node, ca);
2590 ca->index = positional_idx++;
2591 call->arg_count++;
2592 } else if (strcmp(ak, "list_splat") == 0 || strcmp(ak, "dictionary_splat") == 0 ||
2593 strcmp(ak, "spread_element") == 0) {
2594 positional_idx++;
2595 } else {
2596 ca->expr = cbm_node_text(ctx->arena, arg_node, ctx->source);
2597 ca->index = positional_idx++;
2598 /* Python / JS / TS: a URL composed from module constants carries its
2599 * folded value, but only when nothing leading stayed unresolved
2600 * (#706, #1147); otherwise the long-standing handling below. */
2601 fold_call_arg(ctx, arg_node, ca);
2602 if (ca->value || is_folded_reference(ctx, ak)) {
2603 call->arg_count++;
2604 continue;
2605 }
2606 if (is_string_like(ak) && ca->expr) {
2607 ca->value = strip_quotes(ctx->arena, ca->expr);
2608 } else if (strcmp(ak, "template_string") == 0) {
2609 /* Flattened {} form so downstream url-arg detection joins the
2610 * canonical server route shape (issue #1006/#1009). */
2611 ca->value = cbm_template_string_text(ctx->arena, arg_node, ctx->source);
2612 } else if (strcmp(ak, "identifier") == 0 && ca->expr) {
2613 ca->value = lookup_string_constant(ctx, ca->expr);
2614 } else if (strcmp(ak, "object") == 0) {
2615 /* Request-config object: its `url` is what the arg-url
2616 * heuristic reads for a local fetch wrapper (#2235). */
2617 ca->value = js_config_object_url(ctx, arg_node, call->callee_name, false);
2618 const char *url = js_config_object_url(ctx, arg_node, call->callee_name, true);
2619 if (url && (!ca->value || strcmp(url, ca->value) != 0)) {
2620 ca->url_value = url;
2621 }
2622 } else if (strcmp(ak, "call_expression") == 0) {

Callers 1

handle_callsFunction · 0.85

Calls 11

cbm_arena_callocFunction · 0.85
process_keyword_argFunction · 0.85
cbm_node_textFunction · 0.85
fold_call_argFunction · 0.85
is_folded_referenceFunction · 0.85
is_string_likeFunction · 0.85
cbm_template_string_textFunction · 0.85
lookup_string_constantFunction · 0.85
js_config_object_urlFunction · 0.85
lookup_url_builderFunction · 0.85
strip_quotesFunction · 0.70

Tested by

no test coverage detected