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

Function py_ns_statement

internal/cbm/extract_imports.c:739–789  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

737}
738
739static bool py_ns_statement(PyNamespaceBuilder *b, TSNode node) {
740 const char *kind = ts_node_type(node);
741 if (strcmp(kind, "comment") == 0 || strcmp(kind, "pass_statement") == 0)
742 return true;
743 if (strcmp(kind, "import_statement") == 0)
744 return py_ns_import(b, node, false);
745 if (strcmp(kind, "import_from_statement") == 0)
746 return py_ns_import(b, node, true);
747 bool decorated = strcmp(kind, "decorated_definition") == 0;
748 TSNode def = decorated ? ts_node_child_by_field_name(node, TS_FIELD("definition")) : node;
749 if (!ts_node_is_null(def)) {
750 const char *dk = ts_node_type(def);
751 bool function = strcmp(dk, "function_definition") == 0;
752 bool class_def = strcmp(dk, "class_definition") == 0;
753 if (function || class_def) {
754 const char *name =
755 py_ns_name(b, ts_node_child_by_field_name(def, TS_FIELD("name")), false);
756 if (!name)
757 return false;
758 bool proven = !decorated && (function || py_ns_class_safe(b, def));
759 if (!proven || (function && !py_ns_signature_safe(b, def))) {
760 if (!py_ns_unknown(b, CBM_PY_NS_REASON_EFFECT))
761 return false;
762 }
763 return py_ns_push(
764 b, proven ? (CBMPyNamespaceFact){.kind = CBM_PY_NS_OWN_DEF,
765 .local_name = name,
766 .def_kind = function ? CBM_PY_NS_DEF_FUNCTION
767 : CBM_PY_NS_DEF_CLASS}
768 : (CBMPyNamespaceFact){.kind = CBM_PY_NS_SHADOW,
769 .local_name = name,
770 .reason = decorated
771 ? CBM_PY_NS_REASON_DECORATED
772 : CBM_PY_NS_REASON_UNPROVEN_CLASS});
773 }
774 }
775 if (strcmp(kind, "delete_statement") == 0)
776 return py_ns_delete(b, node, 0);
777 if (strcmp(kind, "expression_statement") == 0 && ts_node_named_child_count(node) == 1) {
778 TSNode expr = ts_node_named_child(node, 0);
779 const char *ek = ts_node_type(expr);
780 if (strcmp(ek, "assignment") == 0 || strcmp(ek, "augmented_assignment") == 0)
781 return py_ns_assignment(b, expr);
782 return py_ns_safe_expr(b, expr, 0) || py_ns_unknown(b, CBM_PY_NS_REASON_EFFECT);
783 }
784 if (strcmp(kind, "if_statement") == 0 || strcmp(kind, "try_statement") == 0 ||
785 strcmp(kind, "for_statement") == 0 || strcmp(kind, "while_statement") == 0 ||
786 strcmp(kind, "with_statement") == 0 || strcmp(kind, "match_statement") == 0)
787 return py_ns_unknown(b, CBM_PY_NS_REASON_COMPOUND);
788 return false;
789}
790
791CBMPyNamespaceStatus cbm_extract_python_namespace_facts(CBMExtractCtx *ctx) {
792 if (!ctx || !ctx->result)

Callers 1

Calls 9

py_ns_importFunction · 0.85
py_ns_nameFunction · 0.85
py_ns_class_safeFunction · 0.85
py_ns_signature_safeFunction · 0.85
py_ns_unknownFunction · 0.85
py_ns_pushFunction · 0.85
py_ns_deleteFunction · 0.85
py_ns_assignmentFunction · 0.85
py_ns_safe_exprFunction · 0.85

Tested by

no test coverage detected