Commit fd50696359

antlilja <liljaanton2001@gmail.com>
2020-06-23 15:18:28
Store else node in IrInstSrcCheckSwitchProngs * Remove have_else_prong (bool) * Add else_prong (AstNode*)
1 parent 5229f6e
Changed files (3)
src/all_types.hpp
@@ -4095,7 +4095,7 @@ struct IrInstSrcCheckSwitchProngs {
     IrInstSrc *target_value;
     IrInstSrcCheckSwitchProngsRange *ranges;
     size_t range_count;
-    bool have_else_prong;
+    AstNode* else_prong;
     bool have_underscore_prong;
 };
 
src/ir.cpp
@@ -4274,14 +4274,14 @@ static IrInstGen *ir_build_err_to_int_gen(IrAnalyze *ira, Scope *scope, AstNode
 
 static IrInstSrc *ir_build_check_switch_prongs(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
         IrInstSrc *target_value, IrInstSrcCheckSwitchProngsRange *ranges, size_t range_count,
-        bool have_else_prong, bool have_underscore_prong)
+        AstNode* else_prong, bool have_underscore_prong)
 {
     IrInstSrcCheckSwitchProngs *instruction = ir_build_instruction<IrInstSrcCheckSwitchProngs>(
             irb, scope, source_node);
     instruction->target_value = target_value;
     instruction->ranges = ranges;
     instruction->range_count = range_count;
-    instruction->have_else_prong = have_else_prong;
+    instruction->else_prong = else_prong;
     instruction->have_underscore_prong = have_underscore_prong;
 
     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
     }
 
     IrInstSrc *switch_prongs_void = ir_build_check_switch_prongs(irb, scope, node, target_value,
-            check_ranges.items, check_ranges.length, else_prong != nullptr, underscore_prong != nullptr);
+            check_ranges.items, check_ranges.length, else_prong, underscore_prong != nullptr);
 
     IrInstSrc *br_instruction;
     if (cases.length == 0) {
@@ -28685,7 +28685,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
                             buf_ptr(enum_field->name)));
                 }
             }
-        } else if (!instruction->have_else_prong) {
+        } else if (instruction->else_prong == nullptr) {
             if (switch_type->data.enumeration.non_exhaustive) {
                 ir_add_error(ira, &instruction->base.base,
                     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,
             }
             field_prev_uses[start_index] = start_value->base.source_node;
         }
-        if (!instruction->have_else_prong) {
+        if (instruction->else_prong == nullptr) {
             if (type_is_global_error_set(switch_type)) {
                 ir_add_error(ira, &instruction->base.base,
                     buf_sprintf("else prong required when switching on type 'anyerror'"));
@@ -28808,7 +28808,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
                 return ira->codegen->invalid_inst_gen;
             }
         }
-        if (!instruction->have_else_prong) {
+        if (instruction->else_prong == nullptr) {
             BigInt min_val;
             eval_min_max_value_int(ira->codegen, switch_type, &min_val, false);
             BigInt max_val;
@@ -28847,11 +28847,11 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
                 return ira->codegen->invalid_inst_gen;
             }
         }
-        if (((seenTrue < 1) || (seenFalse < 1)) && !instruction->have_else_prong) {
+        if (((seenTrue < 1) || (seenFalse < 1)) && instruction->else_prong == nullptr) {
             ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities"));
             return ira->codegen->invalid_inst_gen;
         }
-    } else if (!instruction->have_else_prong) {
+    } else if (instruction->else_prong == nullptr) {
         ir_add_error(ira, &instruction->base.base,
             buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name)));
         return ira->codegen->invalid_inst_gen;
src/ir_print.cpp
@@ -2177,7 +2177,7 @@ static void ir_print_check_switch_prongs(IrPrintSrc *irp, IrInstSrcCheckSwitchPr
         fprintf(irp->f, "...");
         ir_print_other_inst_src(irp, instruction->ranges[i].end);
     }
-    const char *have_else_str = instruction->have_else_prong ? "yes" : "no";
+    const char *have_else_str = instruction->else_prong != nullptr ? "yes" : "no";
     fprintf(irp->f, ")else:%s", have_else_str);
 }