mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Fix using determination order
This commit is contained in:
+3
-3
@@ -3621,7 +3621,7 @@ break;
|
|||||||
isize variable_count = type->Struct.fields.count;
|
isize variable_count = type->Struct.fields.count;
|
||||||
array_init(&tuple->Tuple.variables, a, variable_count);
|
array_init(&tuple->Tuple.variables, a, variable_count);
|
||||||
// TODO(bill): Should I copy each of the entities or is this good enough?
|
// TODO(bill): Should I copy each of the entities or is this good enough?
|
||||||
gb_memcopy_array(tuple->Tuple.variables.data, type->Struct.fields_in_src_order.data, variable_count);
|
gb_memcopy_array(tuple->Tuple.variables.data, type->Struct.fields.data, variable_count);
|
||||||
|
|
||||||
operand->type = tuple;
|
operand->type = tuple;
|
||||||
operand->mode = Addressing_Value;
|
operand->mode = Addressing_Value;
|
||||||
@@ -5370,7 +5370,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
|||||||
isize field_count = t->Struct.fields.count;
|
isize field_count = t->Struct.fields.count;
|
||||||
isize min_field_count = t->Struct.fields.count;
|
isize min_field_count = t->Struct.fields.count;
|
||||||
for (isize i = min_field_count-1; i >= 0; i--) {
|
for (isize i = min_field_count-1; i >= 0; i--) {
|
||||||
Entity *e = t->Struct.fields_in_src_order[i];
|
Entity *e = t->Struct.fields[i];
|
||||||
GB_ASSERT(e->kind == Entity_Variable);
|
GB_ASSERT(e->kind == Entity_Variable);
|
||||||
if (e->Variable.default_is_nil) {
|
if (e->Variable.default_is_nil) {
|
||||||
min_field_count--;
|
min_field_count--;
|
||||||
@@ -5454,7 +5454,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (field == nullptr) {
|
if (field == nullptr) {
|
||||||
field = t->Struct.fields_in_src_order[index];
|
field = t->Struct.fields[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
check_expr_with_type_hint(c, o, elem, field->type);
|
check_expr_with_type_hint(c, o, elem, field->type);
|
||||||
|
|||||||
+10
-19
@@ -34,13 +34,12 @@ void populate_using_entity_map(Checker *c, AstNode *node, Type *t, Map<Entity *>
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns filled field_count
|
void check_struct_fields(Checker *c, AstNode *node, Array<Entity *> *fields, Array<AstNode *> params,
|
||||||
Array<Entity *> check_struct_fields(Checker *c, AstNode *node, Array<AstNode *> params,
|
isize init_field_capacity, Type *named_type, String context) {
|
||||||
isize init_field_capacity, Type *named_type, String context) {
|
|
||||||
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena);
|
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena);
|
||||||
defer (gb_temp_arena_memory_end(tmp));
|
defer (gb_temp_arena_memory_end(tmp));
|
||||||
|
|
||||||
auto fields = array_make<Entity *>(heap_allocator(), 0, init_field_capacity);
|
*fields = array_make<Entity *>(heap_allocator(), 0, init_field_capacity);
|
||||||
|
|
||||||
Map<Entity *> entity_map = {};
|
Map<Entity *> entity_map = {};
|
||||||
map_init(&entity_map, c->tmp_allocator, 2*init_field_capacity);
|
map_init(&entity_map, c->tmp_allocator, 2*init_field_capacity);
|
||||||
@@ -185,14 +184,14 @@ Array<Entity *> check_struct_fields(Checker *c, AstNode *node, Array<AstNode *>
|
|||||||
field->Variable.default_is_nil = default_is_nil;
|
field->Variable.default_is_nil = default_is_nil;
|
||||||
|
|
||||||
add_entity(c, c->context.scope, name, field);
|
add_entity(c, c->context.scope, name, field);
|
||||||
array_add(&fields, field);
|
array_add(fields, field);
|
||||||
|
|
||||||
field_src_index += 1;
|
field_src_index += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (is_using && p->names.count > 0) {
|
if (is_using && p->names.count > 0) {
|
||||||
Type *first_type = fields[fields.count-1]->type;
|
Type *first_type = (*fields)[fields->count-1]->type;
|
||||||
Type *t = base_type(type_deref(first_type));
|
Type *t = base_type(type_deref(first_type));
|
||||||
|
|
||||||
if (!is_type_struct(t) && !is_type_raw_union(t) && !is_type_bit_field(t) &&
|
if (!is_type_struct(t) && !is_type_raw_union(t) && !is_type_bit_field(t) &&
|
||||||
@@ -208,8 +207,6 @@ Array<Entity *> check_struct_fields(Checker *c, AstNode *node, Array<AstNode *>
|
|||||||
populate_using_entity_map(c, node, type, &entity_map);
|
populate_using_entity_map(c, node, type, &entity_map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fields;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -544,17 +541,13 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node, Array<Opera
|
|||||||
struct_type->Struct.is_polymorphic = is_polymorphic;
|
struct_type->Struct.is_polymorphic = is_polymorphic;
|
||||||
struct_type->Struct.is_poly_specialized = is_poly_specialized;
|
struct_type->Struct.is_poly_specialized = is_poly_specialized;
|
||||||
|
|
||||||
Array<Entity *> fields = {};
|
|
||||||
|
|
||||||
if (!is_polymorphic) {
|
if (!is_polymorphic) {
|
||||||
fields = check_struct_fields(c, node, st->fields, min_field_count, named_type, context);
|
check_struct_fields(c, node, &struct_type->Struct.fields, st->fields, min_field_count, named_type, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct_type->Struct.fields = fields;
|
for_array(i, struct_type->Struct.fields) {
|
||||||
struct_type->Struct.fields_in_src_order = fields;
|
Entity *f = struct_type->Struct.fields[i];
|
||||||
|
|
||||||
for_array(i, fields) {
|
|
||||||
Entity *f = fields[i];
|
|
||||||
if (f->kind == Entity_Variable) {
|
if (f->kind == Entity_Variable) {
|
||||||
if (f->Variable.default_value.kind == ExactValue_Procedure) {
|
if (f->Variable.default_value.kind == ExactValue_Procedure) {
|
||||||
struct_type->Struct.has_proc_default_values = true;
|
struct_type->Struct.has_proc_default_values = true;
|
||||||
@@ -1801,8 +1794,7 @@ void generate_map_entry_type(gbAllocator a, Type *type) {
|
|||||||
array_add(&fields, make_entity_field(a, s, make_token_ident(str_lit("value")), type->Map.value, false, 2));
|
array_add(&fields, make_entity_field(a, s, make_token_ident(str_lit("value")), type->Map.value, false, 2));
|
||||||
|
|
||||||
|
|
||||||
entry_type->Struct.fields = fields;
|
entry_type->Struct.fields = fields;
|
||||||
entry_type->Struct.fields_in_src_order = fields;
|
|
||||||
|
|
||||||
// type_set_offsets(a, entry_type);
|
// type_set_offsets(a, entry_type);
|
||||||
type->Map.entry_type = entry_type;
|
type->Map.entry_type = entry_type;
|
||||||
@@ -1839,8 +1831,7 @@ void generate_map_internal_types(gbAllocator a, Type *type) {
|
|||||||
array_add(&fields, make_entity_field(a, s, make_token_ident(str_lit("hashes")), hashes_type, false, 0));
|
array_add(&fields, make_entity_field(a, s, make_token_ident(str_lit("hashes")), hashes_type, false, 0));
|
||||||
array_add(&fields, make_entity_field(a, s, make_token_ident(str_lit("entries")), entries_type, false, 1));
|
array_add(&fields, make_entity_field(a, s, make_token_ident(str_lit("entries")), entries_type, false, 1));
|
||||||
|
|
||||||
generated_struct_type->Struct.fields = fields;
|
generated_struct_type->Struct.fields = fields;
|
||||||
generated_struct_type->Struct.fields_in_src_order = fields;
|
|
||||||
|
|
||||||
type_set_offsets(a, generated_struct_type);
|
type_set_offsets(a, generated_struct_type);
|
||||||
type->Map.generated_struct_type = generated_struct_type;
|
type->Map.generated_struct_type = generated_struct_type;
|
||||||
|
|||||||
+1
-1
@@ -1347,7 +1347,7 @@ void init_preload(Checker *c) {
|
|||||||
|
|
||||||
GB_ASSERT(tis->fields.count == 3);
|
GB_ASSERT(tis->fields.count == 3);
|
||||||
|
|
||||||
Entity *type_info_variant = tis->fields_in_src_order[2];
|
Entity *type_info_variant = tis->fields[2];
|
||||||
Type *tiv_type = type_info_variant->type;
|
Type *tiv_type = type_info_variant->type;
|
||||||
GB_ASSERT(is_type_union(tiv_type));
|
GB_ASSERT(is_type_union(tiv_type));
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -683,7 +683,7 @@ bool ir_type_has_default_values(Type *t) {
|
|||||||
case Type_Struct:
|
case Type_Struct:
|
||||||
if (t->Struct.is_raw_union) return false;
|
if (t->Struct.is_raw_union) return false;
|
||||||
for_array(i, t->Struct.fields) {
|
for_array(i, t->Struct.fields) {
|
||||||
Entity *f = t->Struct.fields_in_src_order[i];
|
Entity *f = t->Struct.fields[i];
|
||||||
if (f->kind != Entity_Variable) continue;
|
if (f->kind != Entity_Variable) continue;
|
||||||
if (f->Variable.default_is_nil) {
|
if (f->Variable.default_is_nil) {
|
||||||
// NOTE(bill): This is technically zero
|
// NOTE(bill): This is technically zero
|
||||||
@@ -4735,7 +4735,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
|||||||
|
|
||||||
irValue *tuple = ir_add_local_generated(proc, tv.type);
|
irValue *tuple = ir_add_local_generated(proc, tv.type);
|
||||||
for_array(src_index, t->Struct.fields) {
|
for_array(src_index, t->Struct.fields) {
|
||||||
Entity *field = t->Struct.fields_in_src_order[src_index];
|
Entity *field = t->Struct.fields[src_index];
|
||||||
i32 field_index = field->Variable.field_index;
|
i32 field_index = field->Variable.field_index;
|
||||||
irValue *f = ir_emit_struct_ev(proc, s, field_index);
|
irValue *f = ir_emit_struct_ev(proc, s, field_index);
|
||||||
irValue *ep = ir_emit_struct_ep(proc, tuple, cast(i32)src_index);
|
irValue *ep = ir_emit_struct_ep(proc, tuple, cast(i32)src_index);
|
||||||
@@ -5851,7 +5851,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
|||||||
} else {
|
} else {
|
||||||
TypeAndValue tav = type_and_value_of_expr(proc->module->info, elem);
|
TypeAndValue tav = type_and_value_of_expr(proc->module->info, elem);
|
||||||
Selection sel = lookup_field_from_index(proc->module->allocator, bt,
|
Selection sel = lookup_field_from_index(proc->module->allocator, bt,
|
||||||
st->fields_in_src_order[field_index]->Variable.field_src_index);
|
st->fields[field_index]->Variable.field_src_index);
|
||||||
index = sel.index[0];
|
index = sel.index[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8141,7 +8141,7 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
|
|||||||
type_set_offsets(a, t); // NOTE(bill): Just incase the offsets have not been set yet
|
type_set_offsets(a, t); // NOTE(bill): Just incase the offsets have not been set yet
|
||||||
for (isize source_index = 0; source_index < count; source_index++) {
|
for (isize source_index = 0; source_index < count; source_index++) {
|
||||||
// TODO(bill): Order fields in source order not layout order
|
// TODO(bill): Order fields in source order not layout order
|
||||||
Entity *f = t->Struct.fields_in_src_order[source_index];
|
Entity *f = t->Struct.fields[source_index];
|
||||||
irValue *tip = ir_get_type_info_ptr(proc, f->type);
|
irValue *tip = ir_get_type_info_ptr(proc, f->type);
|
||||||
i64 foffset = 0;
|
i64 foffset = 0;
|
||||||
if (!t->Struct.is_raw_union) {
|
if (!t->Struct.is_raw_union) {
|
||||||
|
|||||||
+1
-1
@@ -731,7 +731,7 @@ void ir_print_exact_value(irFileBuffer *f, irModule *m, ExactValue value, Type *
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for_array(i, cl->elems) {
|
for_array(i, cl->elems) {
|
||||||
Entity *f = type->Struct.fields_in_src_order[i];
|
Entity *f = type->Struct.fields[i];
|
||||||
TypeAndValue tav = type_and_value_of_expr(m->info, cl->elems[i]);
|
TypeAndValue tav = type_and_value_of_expr(m->info, cl->elems[i]);
|
||||||
ExactValue val = {};
|
ExactValue val = {};
|
||||||
if (tav.mode != Addressing_Invalid) {
|
if (tav.mode != Addressing_Invalid) {
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ struct BasicType {
|
|||||||
|
|
||||||
struct TypeStruct {
|
struct TypeStruct {
|
||||||
Array<Entity *> fields;
|
Array<Entity *> fields;
|
||||||
Array<Entity *> fields_in_src_order;
|
|
||||||
AstNode *node;
|
AstNode *node;
|
||||||
Scope * scope;
|
Scope * scope;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user