mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 08:08:50 +00:00
Allow casting between a bit_field and its backing type
This commit is contained in:
@@ -210,6 +210,7 @@ gb_internal bool is_type_distinct(Ast *node) {
|
|||||||
case Ast_UnionType:
|
case Ast_UnionType:
|
||||||
case Ast_EnumType:
|
case Ast_EnumType:
|
||||||
case Ast_ProcType:
|
case Ast_ProcType:
|
||||||
|
case Ast_BitFieldType:
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case Ast_PointerType:
|
case Ast_PointerType:
|
||||||
|
|||||||
@@ -2908,6 +2908,13 @@ gb_internal bool check_is_castable_to(CheckerContext *c, Operand *operand, Type
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_type_bit_field(src)) {
|
||||||
|
return are_types_identical(core_type(src->BitField.backing_type), dst);
|
||||||
|
}
|
||||||
|
if (is_type_bit_field(dst)) {
|
||||||
|
return are_types_identical(src, core_type(dst->BitField.backing_type));
|
||||||
|
}
|
||||||
|
|
||||||
if (is_type_integer(src) && is_type_rune(dst)) {
|
if (is_type_integer(src) && is_type_rune(dst)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1946,6 +1946,24 @@ gb_internal lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bit_field <-> backing type
|
||||||
|
if (is_type_bit_field(src)) {
|
||||||
|
if (are_types_identical(src->BitField.backing_type, dst)) {
|
||||||
|
lbValue res = {};
|
||||||
|
res.type = t;
|
||||||
|
res.value = value.value;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is_type_bit_field(dst)) {
|
||||||
|
if (are_types_identical(src, dst->BitField.backing_type)) {
|
||||||
|
lbValue res = {};
|
||||||
|
res.type = t;
|
||||||
|
res.value = value.value;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Pointer <-> uintptr
|
// Pointer <-> uintptr
|
||||||
if (is_type_pointer(src) && is_type_uintptr(dst)) {
|
if (is_type_pointer(src) && is_type_uintptr(dst)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user