authorgravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2020-06-23 15:18:28+02:00
committergravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2020-06-24 17:36:24+02:00
logfd50696359ec86abd238993930e979433a31db9a
tree6ed87ae39c4ca488ce5355b5d5f91d14f7bf309a
parent5229f6ec68708c3e66393a50ad9f9032ee7f4257

Store else node in IrInstSrcCheckSwitchProngs

* Remove have_else_prong (bool) * Add else_prong (AstNode*)

3 files changed, 10 insertions(+), 10 deletions(-)

src/all_types.hpp+1-1
...@@ -4095,7 +4095,7 @@ struct IrInstSrcCheckSwitchProngs {...@@ -4095,7 +4095,7 @@ struct IrInstSrcCheckSwitchProngs {
4095 IrInstSrc *target_value;4095 IrInstSrc *target_value;
4096 IrInstSrcCheckSwitchProngsRange *ranges;4096 IrInstSrcCheckSwitchProngsRange *ranges;
4097 size_t range_count;4097 size_t range_count;
4098 bool have_else_prong;4098 AstNode* else_prong;
4099 bool have_underscore_prong;4099 bool have_underscore_prong;
4100};4100};
41014101
src/ir.cpp+8-8
...@@ -4274,14 +4274,14 @@ static IrInstGen *ir_build_err_to_int_gen(IrAnalyze *ira, Scope *scope, AstNode...@@ -4274,14 +4274,14 @@ static IrInstGen *ir_build_err_to_int_gen(IrAnalyze *ira, Scope *scope, AstNode
42744274
4275static IrInstSrc *ir_build_check_switch_prongs(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,4275static IrInstSrc *ir_build_check_switch_prongs(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4276 IrInstSrc *target_value, IrInstSrcCheckSwitchProngsRange *ranges, size_t range_count,4276 IrInstSrc *target_value, IrInstSrcCheckSwitchProngsRange *ranges, size_t range_count,
4277 bool have_else_prong, bool have_underscore_prong)4277 AstNode* else_prong, bool have_underscore_prong)
4278{4278{
4279 IrInstSrcCheckSwitchProngs *instruction = ir_build_instruction<IrInstSrcCheckSwitchProngs>(4279 IrInstSrcCheckSwitchProngs *instruction = ir_build_instruction<IrInstSrcCheckSwitchProngs>(
4280 irb, scope, source_node);4280 irb, scope, source_node);
4281 instruction->target_value = target_value;4281 instruction->target_value = target_value;
4282 instruction->ranges = ranges;4282 instruction->ranges = ranges;
4283 instruction->range_count = range_count;4283 instruction->range_count = range_count;
4284 instruction->have_else_prong = have_else_prong;4284 instruction->else_prong = else_prong;
4285 instruction->have_underscore_prong = have_underscore_prong;4285 instruction->have_underscore_prong = have_underscore_prong;
42864286
4287 ir_ref_instruction(target_value, irb->current_basic_block);4287 ir_ref_instruction(target_value, irb->current_basic_block);
...@@ -9305,7 +9305,7 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n...@@ -9305,7 +9305,7 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
9305 }9305 }
93069306
9307 IrInstSrc *switch_prongs_void = ir_build_check_switch_prongs(irb, scope, node, target_value,9307 IrInstSrc *switch_prongs_void = ir_build_check_switch_prongs(irb, scope, node, target_value,
9308 check_ranges.items, check_ranges.length, else_prong != nullptr, underscore_prong != nullptr);9308 check_ranges.items, check_ranges.length, else_prong, underscore_prong != nullptr);
93099309
9310 IrInstSrc *br_instruction;9310 IrInstSrc *br_instruction;
9311 if (cases.length == 0) {9311 if (cases.length == 0) {
...@@ -28685,7 +28685,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -28685,7 +28685,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
28685 buf_ptr(enum_field->name)));28685 buf_ptr(enum_field->name)));
28686 }28686 }
28687 }28687 }
28688 } else if (!instruction->have_else_prong) {28688 } else if (instruction->else_prong == nullptr) {
28689 if (switch_type->data.enumeration.non_exhaustive) {28689 if (switch_type->data.enumeration.non_exhaustive) {
28690 ir_add_error(ira, &instruction->base.base,28690 ir_add_error(ira, &instruction->base.base,
28691 buf_sprintf("switch on non-exhaustive enum must include `else` or `_` prong"));28691 buf_sprintf("switch on non-exhaustive enum must include `else` or `_` prong"));
...@@ -28746,7 +28746,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -28746,7 +28746,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
28746 }28746 }
28747 field_prev_uses[start_index] = start_value->base.source_node;28747 field_prev_uses[start_index] = start_value->base.source_node;
28748 }28748 }
28749 if (!instruction->have_else_prong) {28749 if (instruction->else_prong == nullptr) {
28750 if (type_is_global_error_set(switch_type)) {28750 if (type_is_global_error_set(switch_type)) {
28751 ir_add_error(ira, &instruction->base.base,28751 ir_add_error(ira, &instruction->base.base,
28752 buf_sprintf("else prong required when switching on type 'anyerror'"));28752 buf_sprintf("else prong required when switching on type 'anyerror'"));
...@@ -28808,7 +28808,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -28808,7 +28808,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
28808 return ira->codegen->invalid_inst_gen;28808 return ira->codegen->invalid_inst_gen;
28809 }28809 }
28810 }28810 }
28811 if (!instruction->have_else_prong) {28811 if (instruction->else_prong == nullptr) {
28812 BigInt min_val;28812 BigInt min_val;
28813 eval_min_max_value_int(ira->codegen, switch_type, &min_val, false);28813 eval_min_max_value_int(ira->codegen, switch_type, &min_val, false);
28814 BigInt max_val;28814 BigInt max_val;
...@@ -28847,11 +28847,11 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -28847,11 +28847,11 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
28847 return ira->codegen->invalid_inst_gen;28847 return ira->codegen->invalid_inst_gen;
28848 }28848 }
28849 }28849 }
28850 if (((seenTrue < 1) || (seenFalse < 1)) && !instruction->have_else_prong) {28850 if (((seenTrue < 1) || (seenFalse < 1)) && instruction->else_prong == nullptr) {
28851 ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities"));28851 ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities"));
28852 return ira->codegen->invalid_inst_gen;28852 return ira->codegen->invalid_inst_gen;
28853 }28853 }
28854 } else if (!instruction->have_else_prong) {28854 } else if (instruction->else_prong == nullptr) {
28855 ir_add_error(ira, &instruction->base.base,28855 ir_add_error(ira, &instruction->base.base,
28856 buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name)));28856 buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name)));
28857 return ira->codegen->invalid_inst_gen;28857 return ira->codegen->invalid_inst_gen;
src/ir_print.cpp+1-1
...@@ -2177,7 +2177,7 @@ static void ir_print_check_switch_prongs(IrPrintSrc *irp, IrInstSrcCheckSwitchPr...@@ -2177,7 +2177,7 @@ static void ir_print_check_switch_prongs(IrPrintSrc *irp, IrInstSrcCheckSwitchPr
2177 fprintf(irp->f, "...");2177 fprintf(irp->f, "...");
2178 ir_print_other_inst_src(irp, instruction->ranges[i].end);2178 ir_print_other_inst_src(irp, instruction->ranges[i].end);
2179 }2179 }
2180 const char *have_else_str = instruction->have_else_prong ? "yes" : "no";2180 const char *have_else_str = instruction->else_prong != nullptr ? "yes" : "no";
2181 fprintf(irp->f, ")else:%s", have_else_str);2181 fprintf(irp->f, ")else:%s", have_else_str);
2182}2182}
21832183