| 671 | } |
| 672 | |
| 673 | static bool py_ns_assignment(PyNamespaceBuilder *b, TSNode node) { |
| 674 | TSNode left = ts_node_child_by_field_name(node, TS_FIELD("left")); |
| 675 | TSNode right = ts_node_child_by_field_name(node, TS_FIELD("right")); |
| 676 | TSNode annotation = ts_node_child_by_field_name(node, TS_FIELD("type")); |
| 677 | const char *name = py_ns_name(b, left, false); |
| 678 | if (!name) |
| 679 | return false; |
| 680 | if (!py_ns_safe_expr(b, right, 0) || !py_ns_safe_expr(b, annotation, 0)) { |
| 681 | if (!py_ns_unknown(b, CBM_PY_NS_REASON_EFFECT)) |
| 682 | return false; |
| 683 | } |
| 684 | if (ts_node_is_null(right)) |
| 685 | return true; /* annotation alone does not bind the target */ |
| 686 | bool augmented = strcmp(ts_node_type(node), "augmented_assignment") == 0; |
| 687 | if (strcmp(name, "__all__") != 0) { |
| 688 | if (augmented) |
| 689 | return py_ns_unknown(b, CBM_PY_NS_REASON_UNSUPPORTED); |
| 690 | return py_ns_push(b, (CBMPyNamespaceFact){.kind = CBM_PY_NS_SHADOW, |
| 691 | .local_name = name, |
| 692 | .reason = CBM_PY_NS_REASON_VALUE}); |
| 693 | } |
| 694 | CBMPyNamespaceFact fact = {.kind = augmented ? CBM_PY_NS_ALL_APPEND : CBM_PY_NS_ALL_SET}; |
| 695 | bool plus = true; |
| 696 | if (augmented) { |
| 697 | const char *op = NULL; |
| 698 | size_t len = 0; |
| 699 | plus = py_ns_slice(b, ts_node_child_by_field_name(node, TS_FIELD("operator")), &op, &len) && |
| 700 | len == 2 && memcmp(op, "+=", 2) == 0; |
| 701 | } |
| 702 | if (plus && py_ns_all_literal(b, right, &fact)) |
| 703 | return py_ns_push(b, fact); |
| 704 | return py_ns_push( |
| 705 | b, (CBMPyNamespaceFact){.kind = CBM_PY_NS_ALL_UNKNOWN, .reason = CBM_PY_NS_REASON_VALUE}); |
| 706 | } |
| 707 | |
| 708 | static bool py_ns_delete(PyNamespaceBuilder *b, TSNode node, int depth) { |
| 709 | if (depth > 2) |
no test coverage detected