Type* List__append_specializeType(Term* term) { Term* listInput = term->input(0); switch (list_get_parameter_type(&listInput->type->parameter)) { case sym_Untyped: return listInput->type; case sym_UniformListType: { Type* listElementType = list_get_repeated_type_from_type(listInput->type); Type* commonType = find_common_type(listElementType, term->input(1)->type); if (commonType == listElementType) return listInput->type; else return create_typed_unsized_list_type(commonType); } case sym_AnonStructType: case sym_StructType: { List elementTypes; copy(list_get_type_list_from_type(listInput->type), &elementTypes); set_type(elementTypes.append(), term->input(1)->type); return create_typed_unsized_list_type(find_common_type(&elementTypes)); } case sym_Invalid: default: return TYPES.any; } }
void compound_type_append_field(Type* type, Type* fieldType, const char* fieldName) { ca_assert(list_get_parameter_type(&type->parameter) == name_StructType); list_touch(&type->parameter); caValue* types = list_get(&type->parameter, 0); caValue* names = list_get(&type->parameter, 1); set_type(list_append(types), fieldType); set_string(list_append(names), fieldName); }
caValue* list_get_name_list_from_type(Type* type) { ca_assert(is_list_based_type(type)); caValue* parameter = &type->parameter; switch (list_get_parameter_type(parameter)) { case name_StructType: return list_get(parameter, 1); case name_AnonStructType: case name_Untyped: case name_UniformListType: case name_Invalid: return NULL; } ca_assert(false); return NULL; }
Type* infer_type_of_get_index(Term* input) { if (input == NULL) return &ANY_T; switch (list_get_parameter_type(&input->type->parameter)) { case LIST_UNTYPED: return &ANY_T; case LIST_TYPED_UNSIZED: return list_get_repeated_type_from_type(input->type); case LIST_TYPED_SIZED: case LIST_TYPED_SIZED_NAMED: return find_common_type(list_get_type_list_from_type(input->type)); case LIST_INVALID_PARAMETER: default: return &ANY_T; } }
Type* infer_type_of_get_index(Term* input) { if (input == NULL) return TYPES.any; switch (list_get_parameter_type(&input->type->parameter)) { case name_Untyped: return TYPES.any; case name_UniformListType: return list_get_repeated_type_from_type(input->type); case name_StructType: case name_AnonStructType: return find_common_type(list_get_type_list_from_type(input->type)); case name_Invalid: default: return TYPES.any; } }
bool is_compound_type(Type* type) { return list_get_parameter_type(&type->parameter) == name_StructType; }