Deep-copy a node into a binding (binding owns the strings) */
| 2603 | |
| 2604 | /* Deep-copy a node into a binding (binding owns the strings) */ |
| 2605 | static void binding_set(binding_t *b, const char *var, const cbm_node_t *node) { |
| 2606 | /* Check existing — free old fields first */ |
| 2607 | for (int i = 0; i < b->var_count; i++) { |
| 2608 | if (strcmp(b->var_names[i], var) == 0) { |
| 2609 | node_fields_free(&b->var_nodes[i]); |
| 2610 | node_deep_copy(&b->var_nodes[i], node); |
| 2611 | return; |
| 2612 | } |
| 2613 | } |
| 2614 | if (b->var_count >= CYP_MAX_VARS) { |
| 2615 | return; |
| 2616 | } |
| 2617 | b->var_names[b->var_count] = var; /* not owned — points to AST string */ |
| 2618 | node_deep_copy(&b->var_nodes[b->var_count], node); |
| 2619 | b->var_count++; |
| 2620 | } |
| 2621 | |
| 2622 | /* binding_set for a node the caller owns and is done with: the binding takes |
| 2623 | * its strings instead of copying them, and *node is left empty, so the |
no test coverage detected