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

Function process_py_import_stmt

internal/cbm/extract_imports.c:200–229  ·  view source on GitHub ↗

Process a single Python import_statement node (import X, import X as Y).

Source from the content-addressed store, hash-verified

198
199// Process a single Python import_statement node (import X, import X as Y).
200static void process_py_import_stmt(CBMExtractCtx *ctx, TSNode node) {
201 CBMArena *a = ctx->arena;
202 TSNode name_node = ts_node_child_by_field_name(node, TS_FIELD("name"));
203 if (ts_node_is_null(name_node)) {
204 uint32_t nc = ts_node_child_count(node);
205 for (uint32_t j = 0; j < nc; j++) {
206 TSNode child = ts_node_child(node, j);
207 const char *ck = ts_node_type(child);
208 if (strcmp(ck, "dotted_name") == 0 || strcmp(ck, "identifier") == 0) {
209 char *mod = cbm_node_text(a, child, ctx->source);
210 if (mod && mod[0]) {
211 CBMImport imp = {.local_name = python_import_root(a, mod), .module_path = mod};
212 cbm_imports_push(&ctx->result->imports, a, imp);
213 }
214 } else if (strcmp(ck, "aliased_import") == 0) {
215 emit_py_aliased_import(ctx, child, NULL);
216 }
217 }
218 } else if (strcmp(ts_node_type(name_node), "aliased_import") == 0) {
219 /* `import util as u` — the import_statement's `name` field points at the
220 * aliased_import; extract its real module name (not "util as u"). */
221 emit_py_aliased_import(ctx, name_node, NULL);
222 } else {
223 char *mod = cbm_node_text(a, name_node, ctx->source);
224 if (mod && mod[0]) {
225 CBMImport imp = {.local_name = python_import_root(a, mod), .module_path = mod};
226 cbm_imports_push(&ctx->result->imports, a, imp);
227 }
228 }
229}
230
231// Resolve the module_name node for a Python import_from_statement.
232static TSNode resolve_py_module_node(TSNode node) {

Callers 1

parse_python_importsFunction · 0.85

Calls 4

cbm_node_textFunction · 0.85
python_import_rootFunction · 0.85
cbm_imports_pushFunction · 0.85
emit_py_aliased_importFunction · 0.85

Tested by

no test coverage detected