8000 Odin/src/types.cpp at master · brian-hmn/Odin · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
8000
5311 lines (4675 loc) · 149 KB

types.cpp

File metadata and controls

5311 lines (4675 loc) · 149 KB
res.index.capacity = res.index.count;
return res;
}
gb_internal Selection trim_selection(Selection const &sel) {
Selection res = {};
res.index.data = sel.index.data;
res.index.count = gb_max(sel.index.count - 1, 0);
res.index.capacity = res.index.count;
return res;
}
gb_global Type basic_types[] = {
{Type_Basic, {Basic_Invalid, 0, 0, STR_LIT("invalid type")}},
{Type_Basic, {Basic_llvm_bool, BasicFlag_Boolean | BasicFlag_LLVM, 1, STR_LIT("llvm bool")}},
{Type_Basic, {Basic_bool, BasicFlag_Boolean, 1, STR_LIT("bool")}},
{Type_Basic, {Basic_b8, BasicFlag_Boolean, 1, STR_LIT("b8")}},
{Type_Basic, {Basic_b16, BasicFlag_Boolean, 2, STR_LIT("b16")}},
{Type_Basic, {Basic_b32, BasicFlag_Boolean, 4, STR_LIT("b32")}},
{Type_Basic, {Basic_b64, BasicFlag_Boolean, 8, STR_LIT("b64")}},
{Type_Basic, {Basic_i8, BasicFlag_Integer, 1, STR_LIT("i8")}},
{Type_Basic, {Basic_u8, BasicFlag_Integer | BasicFlag_Unsigned, 1, STR_LIT("u8")}},
{Type_Basic, {Basic_i16, BasicFlag_Integer, 2, STR_LIT("i16")}},
{Type_Basic, {Basic_u16, BasicFlag_Integer | BasicFlag_Unsigned, 2, STR_LIT("u16")}},
{Type_Basic, {Basic_i32, BasicFlag_Integer, 4, STR_LIT("i32")}},
{Type_Basic, {Basic_u32, BasicFlag_Integer | BasicFlag_Unsigned, 4, STR_LIT("u32")}},
{Type_Basic, {Basic_i64, BasicFlag_Integer, 8, STR_LIT("i64")}},
{Type_Basic, {Basic_u64, BasicFlag_Integer | BasicFlag_Unsigned, 8, STR_LIT("u64")}},
{Type_Basic, {Basic_i128, BasicFlag_Integer, 16, STR_LIT("i128")}},
{Type_Basic, {Basic_u128, BasicFlag_Integer | BasicFlag_Unsigned, 16, STR_LIT("u128")}},
{Type_Basic, {Basic_rune, BasicFlag_Integer | BasicFlag_Rune, 4, STR_LIT("rune")}},
{Type_Basic, {Basic_f16, BasicFlag_Float, 2, STR_LIT("f16")}},
{Type_Basic, {Basic_f32, BasicFlag_Float, 4, STR_LIT("f32")}},
{Type_Basic, {Basic_f64, BasicFlag_Float, 8, STR_LIT("f64")}},
{Type_Basic, {Basic_complex32, BasicFlag_Complex, 4, STR_LIT("complex32")}},
{Type_Basic, {Basic_complex64, BasicFlag_Complex, 8, STR_LIT("complex64")}},
{Type_Basic, {Basic_complex128, BasicFlag_Complex, 16, STR_LIT("complex128")}},
{Type_Basic, {Basic_quaternion64, BasicFlag_Quaternion, 8, STR_LIT("quaternion64")}},
{Type_Basic, {Basic_quaternion128, BasicFlag_Quaternion, 16, STR_LIT("quaternion128")}},
{Type_Basic, {Basic_quaternion256, BasicFlag_Quaternion, 32, STR_LIT("quaternion256")}},
{Type_Basic, {Basic_int, BasicFlag_Integer, -1, STR_LIT("int")}},
{Type_Basic, {Basic_uint, BasicFlag_Integer | BasicFlag_Unsigned, -1, STR_LIT("uint")}},
{Type_Basic, {Basic_uintptr, BasicFlag_Integer | BasicFlag_Unsigned, -1, STR_LIT("uintptr")}},
{Type_Basic, {Basic_rawptr, BasicFlag_Pointer, -1, STR_LIT("rawptr")}},
{Type_Basic, {Basic_string, BasicFlag_String, -1, STR_LIT("string")}},
{Type_Basic, {Basic_cstring, BasicFlag_String, -1, STR_LIT("cstring")}},
{Type_Basic, {Basic_string16, BasicFlag_String, -1, STR_LIT("string16")}},
{Type_Basic, {Basic_cstring16, BasicFlag_String, -1, STR_LIT("cstring16")}},
{Type_Basic, {Basic_any, 0, 16, STR_LIT("any")}},
{Type_Basic, {Basic_typeid, 0, 8, STR_LIT("typeid")}},
// Endian
{Type_Basic, {Basic_i16le, BasicFlag_Integer | BasicFlag_EndianLittle, 2, STR_LIT("i16le")}},
{Type_Basic, {Basic_u16le, BasicFlag_Integer | BasicFlag_Unsigned | BasicFlag_EndianLittle, 2, STR_LIT("u16le")}},
{Type_Basic, {Basic_i32le, BasicFlag_Integer | BasicFlag_EndianLittle, 4, STR_LIT("i32le")}},
{Type_Basic, {Basic_u32le, BasicFlag_Integer | BasicFlag_Unsigned | BasicFlag_EndianLittle, 4, STR_LIT("u32le")}},
{Type_Basic, {Basic_i64le, BasicFlag_Integer | BasicFlag_EndianLittle, 8, STR_LIT("i64le")}},
{Type_Basic, {Basic_u64le, BasicFlag_Integer | BasicFlag_Unsigned | BasicFlag_EndianLittle, 8, STR_LIT("u64le")}},
{Type_Basic, {Basic_i128le, BasicFlag_Integer | BasicFlag_EndianLittle, 16, STR_LIT("i128le")}},
{Type_Basic, {Basic_u128le, BasicFlag_Integer | BasicFlag_Unsigned | BasicFlag_EndianLittle, 16, STR_LIT("u128le")}},
{Type_Basic, {Basic_i16be, BasicFlag_Integer | BasicFlag_EndianBig, 2, STR_LIT("i16be")}},
{Type_Basic, {Basic_u16be, BasicFlag_Integer | BasicFlag_Unsigned | BasicFlag_EndianBig, 2, STR_LIT("u16be")}},
{Type_Basic, {Basic_i32be, BasicFlag_Integer | BasicFlag_EndianBig, 4, STR_LIT("i32be")}},
{Type_Basic, {Basic_u32be, BasicFlag_Integer | BasicFlag_Unsigned | BasicFlag_EndianBig, 4, STR_LIT("u32be")}},
{Type_Basic, {Basic_i64be, BasicFlag_Integer | BasicFlag_EndianBig, 8, STR_LIT("i64be")}},
{Type_Basic, {Basic_u64be, BasicFlag_Integer | BasicFlag_Unsigned | BasicFlag_EndianBig, 8, STR_LIT("u64be")}},
{Type_Basic, {Basic_i128be, BasicFlag_Integer | BasicFlag_EndianBig, 16, STR_LIT("i128be")}},
{Type_Basic, {Basic_u128be, BasicFlag_Integer | BasicFlag_Unsigned | BasicFlag_EndianBig, 16, STR_LIT("u128be")}},
{Type_Basic, {Basic_f16le, BasicFlag_Float | BasicFlag_EndianLittle, 2, STR_LIT("f16le")}},
{Type_Basic, {Basic_f32le, BasicFlag_Float | BasicFlag_EndianLittle, 4, STR_LIT("f32le")}},
{Type_Basic, {Basic_f64le, BasicFlag_Float | BasicFlag_EndianLittle, 8, STR_LIT("f64le")}},
{Type_Basic, {Basic_f16be, BasicFlag_Float | BasicFlag_EndianBig, 2, STR_LIT("f16be")}},
{Type_Basic, {Basic_f32be, BasicFlag_Float | BasicFlag_EndianBig, 4, STR_LIT("f32be")}},
{Type_Basic, {Basic_f64be, BasicFlag_Float | BasicFlag_EndianBig, 8, STR_LIT("f64be")}},
// Untyped types
{Type_Basic, {Basic_UntypedBool, BasicFlag_Boolean | BasicFlag_Untyped, 0, STR_LIT("untyped bool")}},
{Type_Basic, {Basic_UntypedInteger, BasicFlag_Integer | BasicFlag_Untyped, 0, STR_LIT("untyped integer")}},
{Type_Basic, {Basic_UntypedFloat, BasicFlag_Float | BasicFlag_Untyped, 0, STR_LIT("untyped float")}},
{Type_Basic, {Basic_UntypedComplex, BasicFlag_Complex | BasicFlag_Untyped, 0, STR_LIT("untyped complex")}},
{Type_Basic, {Basic_UntypedQuaternion, BasicFlag_Quaternion | BasicFlag_Untyped, 0, STR_LIT("untyped quaternion")}},
{Type_Basic, {Basic_UntypedString, BasicFlag_String | BasicFlag_Untyped, 0, STR_LIT("untyped string")}},
{Type_Basic, {Basic_UntypedRune, BasicFlag_Integer | BasicFlag_Untyped, 0, STR_LIT("untyped rune")}},
{Type_Basic, {Basic_UntypedNil, BasicFlag_Untyped, 0, STR_LIT("untyped nil")}},
{Type_Basic, {Basic_UntypedUninit, BasicFlag_Untyped, 0, STR_LIT("untyped uninitialized")}},
};
// gb_global Type basic_type_aliases[] = {
// // {Type_Basic, {Basic_byte, BasicFlag_Integer | BasicFlag_Unsigned, 1, STR_LIT("byte")}},
// // {Type_Basic, {Basic_rune, BasicFlag_Integer, 4, STR_LIT("rune")}},
// };
gb_global Type *t_invalid = &basic_types[Basic_Invalid];
gb_global Type *t_llvm_bool = &basic_types[Basic_llvm_bool];
gb_global Type *t_bool = &basic_types[Basic_bool];
gb_global Type *t_i8 = &basic_types[Basic_i8];
gb_global Type *t_u8 = &basic_types[Basic_u8];
gb_global Type *t_i16 = &basic_types[Basic_i16];
gb_global Type *t_u16 = &basic_types[Basic_u16];
gb_global Type *t_i32 = &basic_types[Basic_i32];
gb_global Type *t_u32 = &basic_types[Basic_u32];
gb_global Type *t_i64 = &basic_types[Basic_i64];
gb_global Type *t_u64 = &basic_types[Basic_u64];
gb_global Type *t_i128 = &basic_types[Basic_i128];
gb_global Type *t_u128 = &basic_types[Basic_u128];
gb_global Type *t_rune = &basic_types[Basic_rune];
gb_global Type *t_f16 = &basic_types[Basic_f16];
gb_global Type *t_f32 = &basic_types[Basic_f32];
gb_global Type *t_f64 = &basic_types[Basic_f64];
gb_global Type *t_f16be = &basic_types[Basic_f16be];
gb_global Type *t_f32be = &basic_types[Basic_f32be];
gb_global Type *t_f64be = &basic_types[Basic_f64be];
gb_global Type *t_f16le = &basic_types[Basic_f16le];
gb_global Type *t_f32le = &basic_types[Basic_f32le];
gb_global Type *t_f64le = &basic_types[Basic_f64le];
gb_global Type *t_complex32 = &basic_types[Basic_complex32];
gb_global Type *t_complex64 = &basic_types[Basic_complex64];
gb_global Type *t_complex128 = &basic_types[Basic_complex128];
gb_global Type *t_quaternion64 = &basic_types[Basic_quaternion64];
gb_global Type *t_quaternion128 = &basic_types[Basic_quaternion128];
gb_global Type *t_quaternion256 = &basic_types[Basic_quaternion256];
gb_global Type *t_int = &basic_types[Basic_int];
gb_global Type *t_uint = &basic_types[Basic_uint];
gb_global Type *t_uintptr = &basic_types[Basic_uintptr];
gb_global Type *t_rawptr = &basic_types[Basic_rawptr];
gb_global Type *t_string = &basic_types[Basic_string];
gb_global Type *t_cstring = &basic_types[Basic_cstring];
gb_global Type *t_string16 = &basic_types[Basic_string16];
gb_global Type *t_cstring16 = &basic_types[Basic_cstring16];
gb_global Type *t_any = &basic_types[Basic_any];
gb_global Type *t_typeid = &basic_types[Basic_typeid];
gb_global Type *t_i16le = &basic_types[Basic_i16le];
gb_global Type *t_u16le = &basic_types[Basic_u16le];
gb_global Type *t_i32le = &basic_types[Basic_i32le];
gb_global Type *t_u32le = &basic_types[Basic_u32le];
gb_global Type *t_i64le = &basic_types[Basic_i64le];
gb_global Type *t_u64le = &basic_types[Basic_u64le];
gb_global Type *t_i128le = &basic_types[Basic_i128le];
gb_global Type *t_u128le = &basic_types[Basic_u128le];
gb_global Type *t_i16be = &basic_types[Basic_i16be];
gb_global Type *t_u16be = &basic_types[Basic_u16be];
gb_global Type *t_i32be = &basic_types[Basic_i32be];
gb_global Type *t_u32be = &basic_types[Basic_u32be];
gb_global Type *t_i64be = &basic_types[Basic_i64be];
gb_global Type *t_u64be = &basic_types[Basic_u64be];
gb_global Type *t_i128be = &basic_types[Basic_i128be];
gb_global Type *t_u128be = &basic_types[Basic_u128be];
gb_global Type *t_untyped_bool = &basic_types[Basic_UntypedBool];
gb_global Type *t_untyped_integer = &basic_types[Basic_UntypedInteger];
gb_global Type *t_untyped_float = &basic_types[Basic_UntypedFloat];
gb_global Type *t_untyped_complex = &basic_types[Basic_UntypedComplex];
gb_global Type *t_untyped_quaternion = &basic_types[Basic_UntypedQuaternion];
gb_global Type *t_untyped_string = &basic_types[Basic_UntypedString];
gb_global Type *t_untyped_rune = &basic_types[Basic_UntypedRune];
gb_global Type *t_untyped_nil = &basic_types[Basic_UntypedNil];
gb_global Type *t_untyped_uninit = &basic_types[Basic_UntypedUninit];
gb_global Type *t_u8_ptr = nullptr;
gb_global Type *t_u8_multi_ptr = nullptr;
gb_global Type *t_u16_ptr = nullptr;
gb_global Type *t_u16_multi_ptr = nullptr;
gb_global Type *t_int_ptr = nullptr;
gb_global Type *t_i64_ptr = nullptr;
gb_global Type *t_f64_ptr = nullptr;
gb_global Type *t_u8_slice = nullptr;
gb_global Type *t_string_slice = nullptr;
// Type generated for the "preload" file
gb_global Type *t_type_info = nullptr;
gb_global Type *t_type_info_enum_value = nullptr;
gb_global Type *t_type_info_ptr = nullptr;
gb_global Type *t_type_info_enum_value_ptr = nullptr;
gb_global Type *t_type_info_string_encoding_kind = nullptr;
gb_global Type *t_type_info_named = nullptr;
gb_global Type *t_type_info_integer = nullptr;
gb_global Type *t_type_info_rune = nullptr;
gb_global Type *t_type_info_float = nullptr;
gb_global Type *t_type_info_complex = nullptr;
gb_global Type *t_type_info_quaternion = nullptr;
gb_global Type *t_type_info_any = nullptr;
gb_global Type *t_type_info_typeid = nullptr;
gb_global Type *t_type_info_string = nullptr;
gb_global Type *t_type_info_boolean = nullptr;
gb_global Type *t_type_info_pointer = nullptr;
gb_global Type *t_type_info_multi_pointer = nullptr;
gb_global Type *t_type_info_procedure = nullptr;
gb_global Type *t_type_info_array = nullptr;
gb_global Type *t_type_info_enumerated_array = nullptr;
gb_global Type *t_type_info_dynamic_array = nullptr;
gb_global Type *t_type_info_slice = nullptr;
gb_global Type *t_type_info_parameters = nullptr;
gb_global Type *t_type_info_struct = nullptr;
gb_global Type *t_type_info_union = nullptr;
gb_global Type *t_type_info_enum = nullptr;
gb_global Type *t_type_info_map = nullptr;
gb_global Type *t_type_info_bit_set = nullptr;
gb_global Type *t_type_info_simd_vector = nullptr;
gb_global Type *t_type_info_matrix = nullptr;
gb_global Type *t_type_info_soa_pointer 10BC8 = nullptr;
gb_global Type *t_type_info_bit_field = nullptr;
gb_global Type *t_type_info_named_ptr = nullptr;
gb_global Type *t_type_info_integer_ptr = nullptr;
gb_global Type *t_type_info_rune_ptr = nullptr;
gb_global Type *t_type_info_float_ptr = nullptr;
gb_global Type *t_type_info_complex_ptr = nullptr;
gb_global Type *t_type_info_quaternion_ptr = nullptr;
gb_global Type *t_type_info_any_ptr = nullptr;
gb_global Type *t_type_info_typeid_ptr = nullptr;
gb_global Type *t_type_info_string_ptr = nullptr;
gb_global Type *t_type_info_boolean_ptr = nullptr;
gb_global Type *t_type_info_pointer_ptr = nullptr;
gb_global Type *t_type_info_multi_pointer_ptr = nullptr;
gb_global Type *t_type_info_procedure_ptr = nullptr;
gb_global Type *t_type_info_array_ptr = nullptr;
gb_global Type *t_type_info_enumerated_array_ptr = nullptr;
gb_global Type *t_type_info_dynamic_array_ptr = nullptr;
gb_global Type *t_type_info_slice_ptr = nullptr;
gb_global Type *t_type_info_parameters_ptr = nullptr;
gb_global Type *t_type_info_struct_ptr = nullptr;
gb_global Type *t_type_info_union_ptr = nullptr;
gb_global Type *t_type_info_enum_ptr = nullptr;
gb_global Type *t_type_info_map_ptr = nullptr;
gb_global Type *t_type_info_bit_set_ptr = nullptr;
gb_global Type *t_type_info_simd_vector_ptr = nullptr;
gb_global Type *t_type_info_matrix_ptr = nullptr;
gb_global Type *t_type_info_soa_pointer_ptr = nullptr;
gb_global Type *t_type_info_bit_field_ptr = nullptr;
gb_global Type *t_allocator = nullptr;
gb_global Type *t_allocator_ptr = nullptr;
gb_global Type *t_context = nullptr;
gb_global Type *t_context_ptr = nullptr;
gb_global Type *t_allocator_error = nullptr;
gb_global Type *t_source_code_location = nullptr;
gb_global Type *t_source_code_location_ptr = nullptr;
gb_global Type *t_load_directory_file = nullptr;
gb_global Type *t_load_directory_file_ptr = nullptr;
gb_global Type *t_load_directory_file_slice = nullptr;
gb_global Type *t_map_info = nullptr;
gb_global Type *t_map_cell_info = nullptr;
gb_global Type *t_raw_map = nullptr;
gb_global Type *t_map_info_ptr = nullptr;
gb_global Type *t_map_cell_info_ptr = nullptr;
gb_global Type *t_raw_map_ptr = nullptr;
gb_global Type *t_equal_proc = nullptr;
gb_global Type *t_hasher_proc = nullptr;
gb_global Type *t_map_get_proc = nullptr;
gb_global Type *t_map_set_proc = nullptr;
gb_global Type *t_objc_object = nullptr;
gb_global Type *t_objc_selector = nullptr;
gb_global Type *t_objc_class = nullptr;
gb_global Type *t_objc_ivar = nullptr;
gb_global Type *t_objc_super = nullptr; // Struct used in lieu of the 'self' instance when calling objc_msgSendSuper.
gb_global Type *t_objc_super_ptr = nullptr;
gb_global Type *t_objc_id = nullptr;
gb_global Type *t_objc_SEL = nullptr;
gb_global Type *t_objc_Class = nullptr;
gb_global Type *t_objc_Ivar = nullptr;
gb_global Type *t_objc_instancetype = nullptr; // Special distinct variant of t_objc_id used mimic auto-typing of instancetype* in Objective-C
enum OdinAtomicMemoryOrder : i32 {
OdinAtomicMemoryOrder_relaxed = 0, // unordered
OdinAtomicMemoryOrder_consume = 1, // monotonic
OdinAtomicMemoryOrder_acquire = 2,
OdinAtomicMemoryOrder_release = 3,
OdinAtomicMemoryOrder_acq_rel = 4,
OdinAtomicMemoryOrder_seq_cst = 5,
OdinAtomicMemoryOrder_COUNT,
};
char const *OdinAtomicMemoryOrder_strings[OdinAtomicMemoryOrder_COUNT] = {
"Relaxed",
"Consume",
"Acquire",
"Release",
"Acq_Rel",
"Seq_Cst",
};
gb_global Type *t_atomic_memory_order = nullptr;
gb_global RecursiveMutex g_type_mutex;
struct TypePath;
gb_internal i64 type_size_of (Type *t);
gb_internal i64 type_align_of (Type *t);
gb_internal i64 type_offset_of (Type *t, i64 index, Type **field_type_=nullptr);
gb_internal gbString type_to_string (Type *type, bool shorthand=true);
gb_internal gbString type_to_string (Type *type, gbAllocator allocator, bool shorthand=true);
gb_internal i64 type_size_of_internal(Type *t, TypePath *path);
gb_internal i64 type_align_of_internal(Type *t, TypePath *path);
gb_internal Type * bit_set_to_int(Type *t);
gb_internal bool are_types_identical(Type *x, Type *y);
gb_internal bool is_type_pointer(Type *t);
gb_internal bool is_type_multi_pointer(Type *t);
gb_internal bool is_type_soa_pointer(Type *t);
gb_internal bool is_type_proc(Type *t);
gb_internal bool is_type_slice(Type *t);
gb_internal bool is_type_integer(Type *t);
gb_internal bool type_set_offsets(Type *t);
// IMPORTANT TODO(bill): SHould this TypePath code be removed since type cycle checking is handled much earlier on?
struct TypePath {
RecursiveMutex mutex;
Array<Entity *> path; // Entity_TypeName;
bool failure;
};
gb_internal void type_path_init(TypePath *tp) {
tp->path.allocator = heap_allocator();
}
gb_internal void type_path_free(TypePath *tp) {
mutex_lock(&tp->mutex);
array_free(&tp->path);
mutex_unlock(&tp->mutex);
}
gb_internal void type_path_print_illegal_cycle(TypePath *tp, isize start_index) {
GB_ASSERT(tp != nullptr);
GB_ASSERT(start_index < tp->path.count);
Entity *e = tp->path[start_index];
GB_ASSERT(e != nullptr);
error(e->token, "Illegal type declaration cycle of `%.*s`", LIT(e->token.string));
// NOTE(bill): Print cycle, if it's deep enough
for (isize j = start_index; j < tp->path.count; j++) {
Entity *e = tp->path[j];
error(e->token, "\t%.*s refers to", LIT(e->token.string));
}
// NOTE(bill): This will only print if the path count > 1
error(e->token, "\t%.*s", LIT(e->token.string));
tp->failure = true;
e->type->failure = true;
base_type(e->type)->failure = true;
}
gb_internal bool type_path_push(TypePath *tp, Type *t) {
GB_ASSERT(tp != nullptr);
if (t->kind != Type_Named) {
return false;
}
Entity *e = t->Named.type_name;
mutex_lock(&tp->mutex);
for (isize i = 0; i < tp->path.count; i++) {
Entity *p = tp->path[i];
if (p == e) {
type_path_print_illegal_cycle(tp, i);
}
}
array_add(&tp->path, e);
mutex_unlock(&tp->mutex);
return true;
}
gb_internal void type_path_pop(TypePath *tp) {
if (tp != nullptr) {
mutex_lock(&tp->mutex);
if (tp->path.count > 0) {
array_pop(&tp->path);
}
mutex_unlock(&tp->mutex);
}
}
#define FAILURE_SIZE 0
#define FAILURE_ALIGNMENT 0
gb_internal Type *base_type(Type *t) {
for (;;) {
if (t == nullptr) {
break;
}
if (t->kind != Type_Named) {
break;
}
if (t == t->Named.base) {
return t_invalid;
}
t = t->Named.base;
}
return t;
}
gb_internal Type *base_named_type(Type *t) {
if (t->kind != Type_Named) {
return t_invalid;
}
Type *prev_named = t;
t = t->Named.base;
for (;;) {
if (t == nullptr) {
break;
}
if (t->kind != Type_Named) {
break;
}
if (t == t->Named.base) {
return t_invalid;
}
prev_named = t;
t = t->Named.base;
}
return prev_named;
}
gb_internal Type *base_enum_type(Type *t) {
Type *bt = base_type(t);
if (bt != nullptr &&
bt->kind == Type_Enum) {
return bt->Enum.base_type;
}
return t;
}
gb_internal Type *core_type(Type *t) {
for (;;) {
if (t == nullptr) {
break;
}
switch (t->kind) {
case Type_Named:
if (t == t->Named.base) {
return t_invalid;
}
t = t->Named.base;
continue;
case Type_Enum:
t = t->Enum.base_type;
continue;
case Type_BitField:
t = t->BitField.backing_type;
continue;
}
break;
}
return t;
}
gb_internal void set_base_type(Type *t, Type *base) {
if (t && t->kind == Type_Named) {
t->Named.base = base;
}
}
gb_internal Type *alloc_type(TypeKind kind) {
// gbAllocator a = heap_allocator();
gbAllocator a = permanent_allocator();
Type *t = gb_alloc_item(a, Type);
gb_zero_item(t);
t->kind = kind;
t->cached_size = -1;
t->cached_align = -1;
return t;
}
gb_internal Type *alloc_type_generic(Scope *scope, i64 id, String name, Type *specialized) {
Type *t = alloc_type(Type_Generic);
t->Generic.id = id;
t->Generic.name = name;
t->Generic.specialized = specialized;
t->Generic.scope = scope;
return t;
}
gb_internal Type *alloc_type_pointer(Type *elem) {
Type *t = alloc_type(Type_Pointer);
t->Pointer.elem = elem;
return t;
}
gb_internal Type *alloc_type_multi_pointer(Type *elem) {
Type *t = alloc_type(Type_MultiPointer);
t->MultiPointer.elem = elem;
return t;
}
gb_internal Type *alloc_type_soa_pointer(Type *elem) {
Type *t = alloc_type(Type_SoaPointer);
0