Example #1
0
void branch_update_state_type(Branch* branch)
{
    if (branch_state_type_is_out_of_date(branch)) {

        // TODO: Handle the case where the stateType should go from non-NULL to NULL

        // Recreate the state type
        Type* type = create_compound_type();

        // TODO: give this new type a nice name

        for (int i=0; i < branch->length(); i++) {
            Term* term = branch->get(i);
            if (term == NULL)
                continue;

            if (term->function != FUNCS.unpack_state || FUNCS.unpack_state == NULL)
                continue;

            Term* identifyingTerm = term->input(1);

            compound_type_append_field(type, declared_type(term), unique_name(identifyingTerm));
        }

        branch->stateType = type;

        // Might need to update any existing pack_state calls.
        branch_update_existing_pack_state_calls(branch);
    }
}
Example #2
0
void block_update_state_type(Block* block)
{
    if (!block_state_type_is_out_of_date(block))
        return;

    // Recreate the state type
    Type* type = create_compound_type();

    // TODO: give this new type a nice name

    for (int i=0; i < block->length(); i++) {
        Term* term = block->get(i);
        if (term == NULL)
            continue;

        if (term->function != FUNCS.unpack_state || FUNCS.unpack_state == NULL)
            continue;

        Term* identifyingTerm = term->input(1);

        caValue* fieldName = get_unique_name(identifyingTerm);
        ca_assert(is_string(fieldName));
        ca_assert(!string_eq(fieldName, ""));

        compound_type_append_field(type, declared_type(term), as_cstring(fieldName));
    }

    block->stateType = type;
    block_remove_property(block, sym_DirtyStateType);

    // Might need to update any existing pack_state calls.
    block_update_pack_state_calls(block);
}