mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Merge branch 'master' into llvm-integration
This commit is contained in:
+6
-2
@@ -1155,10 +1155,12 @@ void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_reference = false;
|
||||||
|
|
||||||
if (is_ptr &&
|
if (is_ptr &&
|
||||||
cc->list.count == 1 &&
|
cc->list.count == 1 &&
|
||||||
case_type != nullptr) {
|
case_type != nullptr) {
|
||||||
case_type = alloc_type_pointer(case_type);
|
is_reference = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cc->list.count > 1) {
|
if (cc->list.count > 1) {
|
||||||
@@ -1173,7 +1175,9 @@ void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) {
|
|||||||
{
|
{
|
||||||
Entity *tag_var = alloc_entity_variable(ctx->scope, lhs->Ident.token, case_type, EntityState_Resolved);
|
Entity *tag_var = alloc_entity_variable(ctx->scope, lhs->Ident.token, case_type, EntityState_Resolved);
|
||||||
tag_var->flags |= EntityFlag_Used;
|
tag_var->flags |= EntityFlag_Used;
|
||||||
tag_var->flags |= EntityFlag_Value;
|
if (!is_reference) {
|
||||||
|
tag_var->flags |= EntityFlag_Value;
|
||||||
|
}
|
||||||
add_entity(ctx->checker, ctx->scope, lhs, tag_var);
|
add_entity(ctx->checker, ctx->scope, lhs, tag_var);
|
||||||
add_entity_use(ctx, lhs, tag_var);
|
add_entity_use(ctx, lhs, tag_var);
|
||||||
add_implicit_entity(ctx, stmt, tag_var);
|
add_implicit_entity(ctx, stmt, tag_var);
|
||||||
|
|||||||
+1
-1
@@ -32,7 +32,7 @@ String const entity_strings[] = {
|
|||||||
#undef ENTITY_KIND
|
#undef ENTITY_KIND
|
||||||
};
|
};
|
||||||
|
|
||||||
enum EntityFlag {
|
enum EntityFlag : u32 {
|
||||||
EntityFlag_Visited = 1<<0,
|
EntityFlag_Visited = 1<<0,
|
||||||
EntityFlag_Used = 1<<1,
|
EntityFlag_Used = 1<<1,
|
||||||
EntityFlag_Using = 1<<2,
|
EntityFlag_Using = 1<<2,
|
||||||
|
|||||||
+20
-15
@@ -9530,13 +9530,16 @@ void ir_build_range_tuple(irProcedure *proc, Ast *expr, Type *val0_type, Type *v
|
|||||||
void ir_store_type_case_implicit(irProcedure *proc, Ast *clause, irValue *value) {
|
void ir_store_type_case_implicit(irProcedure *proc, Ast *clause, irValue *value) {
|
||||||
Entity *e = implicit_entity_of_node(clause);
|
Entity *e = implicit_entity_of_node(clause);
|
||||||
GB_ASSERT(e != nullptr);
|
GB_ASSERT(e != nullptr);
|
||||||
#if 1
|
|
||||||
irValue *x = ir_add_local(proc, e, nullptr, false);
|
if (e->flags & EntityFlag_Value) {
|
||||||
ir_emit_store(proc, x, value);
|
// by value
|
||||||
#else
|
irValue *x = ir_add_local(proc, e, nullptr, false);
|
||||||
irValue *x = ir_address_from_load_or_generate_local(proc, value);
|
GB_ASSERT(are_types_identical(ir_type(value), e->type));
|
||||||
ir_module_add_value(proc->module, e, x);
|
ir_emit_store(proc, x, value);
|
||||||
#endif
|
} else {
|
||||||
|
// by reference
|
||||||
|
ir_module_add_value(proc->module, e, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ir_type_case_body(irProcedure *proc, Ast *label, Ast *clause, irBlock *body, irBlock *done) {
|
void ir_type_case_body(irProcedure *proc, Ast *label, Ast *clause, irBlock *body, irBlock *done) {
|
||||||
@@ -10477,14 +10480,8 @@ void ir_build_stmt_internal(irProcedure *proc, Ast *node) {
|
|||||||
ir_start_block(proc, body);
|
ir_start_block(proc, body);
|
||||||
|
|
||||||
// bool any_or_not_ptr = is_type_any(type_deref(parent_type)) || !is_parent_ptr;
|
// bool any_or_not_ptr = is_type_any(type_deref(parent_type)) || !is_parent_ptr;
|
||||||
bool any_or_not_ptr = !is_parent_ptr;
|
|
||||||
if (cc->list.count == 1) {
|
if (cc->list.count == 1) {
|
||||||
|
|
||||||
Type *ct = case_entity->type;
|
|
||||||
if (any_or_not_ptr) {
|
|
||||||
ct = alloc_type_pointer(ct);
|
|
||||||
}
|
|
||||||
GB_ASSERT_MSG(is_type_pointer(ct), "%s", type_to_string(ct));
|
|
||||||
irValue *data = nullptr;
|
irValue *data = nullptr;
|
||||||
if (switch_kind == TypeSwitch_Union) {
|
if (switch_kind == TypeSwitch_Union) {
|
||||||
data = union_data;
|
data = union_data;
|
||||||
@@ -10492,9 +10489,17 @@ void ir_build_stmt_internal(irProcedure *proc, Ast *node) {
|
|||||||
irValue *any_data = ir_emit_load(proc, ir_emit_struct_ep(proc, parent_ptr, 0));
|
irValue *any_data = ir_emit_load(proc, ir_emit_struct_ep(proc, parent_ptr, 0));
|
||||||
data = any_data;
|
data = any_data;
|
||||||
}
|
}
|
||||||
value = ir_emit_conv(proc, data, ct);
|
Type *ct = case_entity->type;
|
||||||
if (any_or_not_ptr) {
|
Type *ct_ptr = alloc_type_pointer(ct);
|
||||||
|
|
||||||
|
|
||||||
|
value = ir_emit_conv(proc, data, ct_ptr);
|
||||||
|
|
||||||
|
if (case_entity->flags & EntityFlag_Value) {
|
||||||
|
// by value
|
||||||
value = ir_emit_load(proc, value);
|
value = ir_emit_load(proc, value);
|
||||||
|
} else {
|
||||||
|
// by reference
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3490,4 +3490,3 @@ gbString type_to_string(Type *type) {
|
|||||||
return write_type_to_string(gb_string_make(heap_allocator(), ""), type);
|
return write_type_to_string(gb_string_make(heap_allocator(), ""), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user