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

Function tdx_resolve

internal/cbm/extract_defs.c:5979–6015  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5977 const TDXRule *rule);
5978
5979static bool tdx_resolve(CBMExtractCtx *ctx, TSNode node, TSNode name_node, const char *macro,
5980 const char **name, TDXRule *rule) {
5981 *name = NULL;
5982 uint32_t line = ts_node_start_point(name_node).row + 1;
5983 if (!tdx_match(ctx, macro, strlen(macro), line, rule))
5984 return false;
5985 if (ctx->result->test_declarations_status == CBM_TEST_EXTRACT_OOM)
5986 return true;
5987 if (!tdx_observe(ctx, name_node, node, NULL, rule) || !rule->valid)
5988 return true;
5989 uint32_t end = ts_node_end_byte(name_node);
5990 size_t id_at = 0, id_length = 0, after = 0;
5991 if (!ctx->source || ctx->source_len < 0 || end > (uint32_t)ctx->source_len) {
5992 tdx_issue(ctx->result, CBM_TEST_EXTRACT_UNSUPPORTED_FORM, rule->declaration, line);
5993 return true;
5994 }
5995 if (!tdx_argument(ctx, end, rule->argument, &id_at, &id_length, &after, rule, line))
5996 return true;
5997 TSNode candidate_name, body;
5998 if (!cbm_test_definition_candidate(node, ctx->language, &candidate_name, &body) ||
5999 !ts_node_eq(candidate_name, name_node)) {
6000 tdx_issue(ctx->result, CBM_TEST_EXTRACT_UNSUPPORTED_FORM, rule->declaration, line);
6001 return true;
6002 }
6003 if (!tdx_trivia(ctx->source, (size_t)ctx->source_len, &after) ||
6004 after >= (size_t)ctx->source_len || ctx->source[after] != '{' || ts_node_is_null(body) ||
6005 ts_node_has_error(body) || ts_node_is_missing(body) || ts_node_start_byte(body) != after ||
6006 ts_node_end_byte(body) <= after || ts_node_end_byte(body) > (uint32_t)ctx->source_len ||
6007 ctx->source[ts_node_end_byte(body) - 1] != '}') {
6008 tdx_issue(ctx->result, CBM_TEST_EXTRACT_UNSUPPORTED_FORM, rule->declaration, line);
6009 return true;
6010 }
6011 *name = cbm_arena_sprintf(ctx->arena, "%s_%.*s", macro, (int)id_length, ctx->source + id_at);
6012 if (!*name)
6013 tdx_issue(ctx->result, CBM_TEST_EXTRACT_OOM, rule->declaration, line);
6014 return true;
6015}
6016
6017/* NULL qn records a recognized attempt, not a graph definition. A later
6018 * successful extraction fills its QN; the audit must not invent a second,

Callers 1

extract_func_defFunction · 0.85

Calls 7

tdx_matchFunction · 0.85
tdx_observeFunction · 0.85
tdx_issueFunction · 0.85
tdx_argumentFunction · 0.85
tdx_triviaFunction · 0.85
cbm_arena_sprintfFunction · 0.70

Tested by

no test coverage detected