| 1744 | } |
| 1745 | |
| 1746 | static uint32_t python_nearest_namespace(const WalkState *state, uint32_t start_id) { |
| 1747 | uint32_t id = start_id; |
| 1748 | int remaining = state ? state->lexical_scope_count : 0; |
| 1749 | while (id != 0 && remaining-- > 0) { |
| 1750 | const CBMLexicalScope *scope = usage_lexical_scope(state, id); |
| 1751 | if (!scope) { |
| 1752 | return 0; |
| 1753 | } |
| 1754 | if (scope->kind == CBM_LEXICAL_SCOPE_FUNCTION || |
| 1755 | scope->kind == CBM_LEXICAL_SCOPE_COMPREHENSION || |
| 1756 | scope->kind == CBM_LEXICAL_SCOPE_CLASS || scope->kind == CBM_LEXICAL_SCOPE_MODULE) { |
| 1757 | return id; |
| 1758 | } |
| 1759 | id = scope->parent_id; |
| 1760 | } |
| 1761 | return 0; |
| 1762 | } |
| 1763 | |
| 1764 | static bool ensure_lexical_binding_capacity(WalkState *state) { |
| 1765 | if (!state->lexical_bindings) { |
no test coverage detected