Append (field_name, field_type) to the registry slot for `class_qn`. * Used by populate_class_fields_from_ast so eval_field_access can resolve * `obj.field.method()` for arbitrary receivers, not just `this`. */
| 3565 | * Used by populate_class_fields_from_ast so eval_field_access can resolve |
| 3566 | * `obj.field.method()` for arbitrary receivers, not just `this`. */ |
| 3567 | static void append_field_to_class(CBMTypeRegistry *reg, CBMArena *a, const char *class_qn, |
| 3568 | const char *field_name, const CBMType *ftype) { |
| 3569 | CBMRegisteredType *slot = NULL; |
| 3570 | for (int ti = 0; ti < reg->type_count; ti++) { |
| 3571 | if (reg->types[ti].qualified_name && strcmp(reg->types[ti].qualified_name, class_qn) == 0) { |
| 3572 | slot = ®->types[ti]; |
| 3573 | break; |
| 3574 | } |
| 3575 | } |
| 3576 | if (!slot) |
| 3577 | return; |
| 3578 | |
| 3579 | int existing = 0; |
| 3580 | if (slot->field_names) { |
| 3581 | while (slot->field_names[existing]) |
| 3582 | existing++; |
| 3583 | } |
| 3584 | const char **new_names = |
| 3585 | (const char **)cbm_arena_alloc(a, (size_t)(existing + 2) * sizeof(*new_names)); |
| 3586 | const CBMType **new_types = |
| 3587 | (const CBMType **)cbm_arena_alloc(a, (size_t)(existing + 2) * sizeof(*new_types)); |
| 3588 | if (!new_names || !new_types) |
| 3589 | return; |
| 3590 | for (int j = 0; j < existing; j++) { |
| 3591 | new_names[j] = slot->field_names[j]; |
| 3592 | new_types[j] = slot->field_types[j]; |
| 3593 | } |
| 3594 | new_names[existing] = cbm_arena_strdup(a, field_name); |
| 3595 | new_types[existing] = ftype ? ftype : cbm_type_unknown(); |
| 3596 | new_names[existing + 1] = NULL; |
| 3597 | new_types[existing + 1] = NULL; |
| 3598 | slot->field_names = new_names; |
| 3599 | slot->field_types = new_types; |
| 3600 | } |
| 3601 | |
| 3602 | /* Walk a class_declaration / interface_declaration / enum_declaration body |
| 3603 | * and append each field_declaration to its containing class's registry |
no test coverage detected