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

Function build_import_map

src/pipeline/pass_semantic.c:84–168  ·  view source on GitHub ↗

Build per-file import map from cached extraction result or graph buffer edges. */

Source from the content-addressed store, hash-verified

82
83/* Build per-file import map from cached extraction result or graph buffer edges. */
84static int build_import_map(cbm_pipeline_ctx_t *ctx, const char *rel_path,
85 const CBMFileResult *result, const char ***out_keys,
86 const char ***out_vals, int *out_count) {
87 *out_keys = NULL;
88 *out_vals = NULL;
89 *out_count = 0;
90
91 /* Fast path: build from cached extraction result (no JSON parsing) */
92 if (result && result->imports.count > 0) {
93 const char **keys =
94 cbm_calloc(CBM_MEM_CLASS_SEMANTIC,
95 (size_t)((size_t)result->imports.count) * (sizeof(const char *)));
96 const char **vals =
97 cbm_calloc(CBM_MEM_CLASS_SEMANTIC,
98 (size_t)((size_t)result->imports.count) * (sizeof(const char *)));
99 int count = 0;
100
101 for (int i = 0; i < result->imports.count; i++) {
102 const CBMImport *imp = &result->imports.items[i];
103 if (!imp->local_name || !imp->local_name[0] || !imp->module_path) {
104 continue;
105 }
106 char *target_qn = cbm_pipeline_fqn_module(ctx->project_name, imp->module_path);
107 const cbm_gbuf_node_t *target = cbm_gbuf_find_by_qn(ctx->gbuf, target_qn);
108 free(target_qn);
109 if (!target) {
110 continue;
111 }
112 keys[count] = cbm_mem_strdup(CBM_MEM_CLASS_SEMANTIC, imp->local_name);
113 vals[count] = target->qualified_name;
114 count++;
115 }
116
117 *out_keys = keys;
118 *out_vals = vals;
119 *out_count = count;
120 return 0;
121 }
122
123 /* Slow path: scan graph buffer IMPORTS edges + parse JSON properties */
124 char *file_qn = cbm_pipeline_fqn_compute(ctx->project_name, rel_path, "__file__");
125 const cbm_gbuf_node_t *file_node = cbm_gbuf_find_by_qn(ctx->gbuf, file_qn);
126 free(file_qn);
127 if (!file_node) {
128 return 0;
129 }
130
131 const cbm_gbuf_edge_t **edges = NULL;
132 int edge_count = 0;
133 int rc = cbm_gbuf_find_edges_by_source_type(ctx->gbuf, file_node->id, "IMPORTS", &edges,
134 &edge_count);
135 if (rc != 0 || edge_count == 0) {
136 return 0;
137 }
138
139 const char **keys =
140 cbm_calloc(CBM_MEM_CLASS_SEMANTIC, (size_t)(edge_count) * (sizeof(const char *)));
141 const char **vals =

Callers 1

Calls 8

cbm_callocFunction · 0.85
cbm_pipeline_fqn_moduleFunction · 0.85
cbm_gbuf_find_by_qnFunction · 0.85
cbm_mem_strdupFunction · 0.85
cbm_pipeline_fqn_computeFunction · 0.85
cbm_gbuf_find_by_idFunction · 0.85
cbm_strndupFunction · 0.85

Tested by

no test coverage detected