types.c
// Go to the next element, staying at the same level if there are any left elements and
// going back up if the elements run out.
Go to the next element, staying at the same level if there are any left elements and
going back up if the elements run out.
Go to the next element staying at the same level if there are any left elements and going back up if the elements run out .
TypeIterator *type_iterator_next(TypeIterator *it) {
    if (type_iterator_done(it)) panic("Attempt to call next on a done type iterator");
    if (is_scalar_type(it->type)) {
        it->offset += get_type_size(it->type);
        return type_iterator_recurse_upwards(it);
    }
    else if (it->type->type == TYPE_ARRAY) {
        it->offset += get_type_size(it->type->target);
        it->index++;
        if (it->index == it->type->array_size)
            return type_iterator_recurse_upwards(it);
        return it;
    }
    else if (it->type->type == TYPE_STRUCT_OR_UNION) {
        it->index++;
        int is_union = it->type->struct_or_union_desc->is_union;
        if (is_union || !it->type->struct_or_union_desc->members[it->index]) {
            it->offset = it->start_offset + get_type_size(it->type);
            return type_iterator_recurse_upwards(it);
        }
        it->offset = it->start_offset + it->type->struct_or_union_desc->members[it->index]->offset;
        StructOrUnionMember *member = it->type->struct_or_union_desc->members[it->index];
        if (member->is_bit_field && !member->bit_field_size) return type_iterator_next(it);
        return it;
    }
    else
        panic("Unhandled type in type_iterator_next");
}
TypeIterator * type_iterator_next ( TypeIterator * it ) { if ( type_iterator_done ( it ) ) panic ( " " ) ; if ( is_scalar_type ( it -> type ) ) { it -> offset += get_type_size ( it -> type ) ; return type_iterator_recurse_upwards ( it ) ; } else if ( it -> type -> type == TYPE_ARRAY ) { it -> offset += get_type_size ( it -> type -> target ) ; it -> index ++ ; if ( it -> index == it -> type -> array_size ) return type_iterator_recurse_upwards ( it ) ; return it ; } else if ( it -> type -> type == TYPE_STRUCT_OR_UNION ) { it -> index ++ ; int is_union = it -> type -> struct_or_union_desc -> is_union ; if ( is_union || ! it -> type -> struct_or_union_desc -> members [ it -> index ] ) { it -> offset = it -> start_offset + get_type_size ( it -> type ) ; return type_iterator_recurse_upwards ( it ) ; } it -> offset = it -> start_offset + it -> type -> struct_or_union_desc -> members [ it -> index ] -> offset ; StructOrUnionMember * member = it -> type -> struct_or_union_desc -> members [ it -> index ] ; if ( member -> is_bit_field && ! member -> bit_field_size ) return type_iterator_next ( it ) ; return it ; } else panic ( " " ) ; }
Go to the next element, staying at the same level if there are any left elements and
going back up if the elements run out.
Go to the next element staying at the same level if there are any left elements and going back up if the elements run out .
// Skip over zero size bit fields