Unify semantics of the built-in swizzle procedure with the selector expression semantics e.g. .xyz

This commit is contained in:
gingerBill
2021-08-09 19:37:58 +01:00
parent aebfa4b28e
commit 01f431b01f
6 changed files with 175 additions and 28 deletions

View File

@@ -778,12 +778,31 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
if (arg_count < max_count) {
operand->type = alloc_type_array(elem_type, arg_count);
}
operand->mode = Addressing_Value;
if (type_hint != nullptr && check_is_castable_to(c, operand, type_hint)) {
operand->type = type_hint;
if (type->kind == Type_Array) {
if (operand->mode == Addressing_Variable) {
operand->mode = Addressing_SwizzleVariable;
} else {
operand->mode = Addressing_SwizzleValue;
}
} else {
operand->mode = Addressing_Value;
}
Type *array_type = base_type(type_deref(operand->type));
GB_ASSERT(array_type->kind == Type_Array);
Type *swizzle_array_type = nullptr;
Type *bth = base_type(type_hint);
if (bth != nullptr && bth->kind == Type_Array &&
bth->Array.count == arg_count &&
are_types_identical(bth->Array.elem, array_type->Array.elem)) {
swizzle_array_type = type_hint;
} else {
swizzle_array_type = alloc_type_array(array_type->Array.elem, arg_count);
}
operand->type = swizzle_array_type;
break;
}