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

Function extract_composite_queue_field

internal/cbm/extract_calls.c:2700–2758  ·  view source on GitHub ↗

Recover a queue/topic identity from a Go composite-literal input struct, e.g. &sqs.SendMessageInput{QueueUrl: queueUrl, MessageBody: body} sns.PublishInput{TopicArn: "arn:aws:sns:..."} The dispatch target is carried by a struct field (QueueUrl/TopicArn/...), not a bare string arg, so the async edge would otherwise degrade to a plain CALLS. Returns the field's value: the string-literal content when

Source from the content-addressed store, hash-verified

2698// Returns the field's value: the string-literal content when present, else the
2699// referenced identifier text (which still names the queue/topic for edge formation).
2700static const char *extract_composite_queue_field(CBMExtractCtx *ctx, TSNode node) {
2701 // Unwrap a pointer-of-composite: `&Type{...}` is a unary_expression whose
2702 // operand is the composite_literal.
2703 if (strcmp(ts_node_type(node), "unary_expression") == 0) {
2704 TSNode operand = ts_node_child_by_field_name(node, TS_FIELD("operand"));
2705 if (ts_node_is_null(operand)) {
2706 return NULL;
2707 }
2708 node = operand;
2709 }
2710 if (strcmp(ts_node_type(node), "composite_literal") != 0) {
2711 return NULL;
2712 }
2713 TSNode body = ts_node_child_by_field_name(node, TS_FIELD("body"));
2714 if (ts_node_is_null(body)) {
2715 body = cbm_find_child_by_kind(node, "literal_value");
2716 }
2717 if (ts_node_is_null(body)) {
2718 return NULL;
2719 }
2720 uint32_t nc = ts_node_named_child_count(body);
2721 for (uint32_t i = 0; i < nc; i++) {
2722 TSNode el = ts_node_named_child(body, i);
2723 if (strcmp(ts_node_type(el), "keyed_element") != 0) {
2724 continue;
2725 }
2726 // keyed_element children: key then value. Each side may be wrapped in a
2727 // literal_element; unwrap to the underlying identifier/literal.
2728 uint32_t ec = ts_node_named_child_count(el);
2729 if (ec < PAIR_LEN) {
2730 continue;
2731 }
2732 TSNode key_n = ts_node_named_child(el, 0);
2733 TSNode val_n = ts_node_named_child(el, 1);
2734 if (strcmp(ts_node_type(key_n), "literal_element") == 0 &&
2735 ts_node_named_child_count(key_n) > 0) {
2736 key_n = ts_node_named_child(key_n, 0);
2737 }
2738 if (strcmp(ts_node_type(val_n), "literal_element") == 0 &&
2739 ts_node_named_child_count(val_n) > 0) {
2740 val_n = ts_node_named_child(val_n, 0);
2741 }
2742 char *key = cbm_node_text(ctx->arena, key_n, ctx->source);
2743 if (!is_queue_topic_field(key)) {
2744 continue;
2745 }
2746 const char *resolved = extract_string_value(ctx, val_n, false);
2747 if (resolved && resolved[0]) {
2748 return resolved;
2749 }
2750 // Value is a variable/expression (no constant value); use its source text
2751 // as the queue/topic identity so the async edge still forms.
2752 char *raw = cbm_node_text(ctx->arena, val_n, ctx->source);
2753 if (raw && raw[0]) {
2754 return raw;
2755 }
2756 }
2757 return NULL;

Callers 1

extract_url_or_topic_argFunction · 0.85

Calls 4

cbm_find_child_by_kindFunction · 0.85
cbm_node_textFunction · 0.85
is_queue_topic_fieldFunction · 0.85
extract_string_valueFunction · 0.85

Tested by

no test coverage detected