authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-12 16:00:50-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-12 16:00:50-07:00
loga5aeb7381f22a42a8f11523267541243bab5964d
treedf3690a30be9cb0ac2cfa68b3bb6d2dad5f1bc82
parentb8a1cb299eccce24410454d36ebc755dfd0293cd

if statement children nodes know if they're compiled out


1 files changed, 23 insertions(+), 4 deletions(-)

src/analyze.cpp+23-4
...@@ -3491,7 +3491,7 @@ static TypeTableEntry *analyze_continue_expr(CodeGen *g, ImportTableEntry *impor...@@ -3491,7 +3491,7 @@ static TypeTableEntry *analyze_continue_expr(CodeGen *g, ImportTableEntry *impor
3491 return g->builtin_types.entry_unreachable;3491 return g->builtin_types.entry_unreachable;
3492}3492}
34933493
3494static TypeTableEntry *analyze_if(CodeGen *g, ImportTableEntry *import, BlockContext *context,3494static TypeTableEntry *analyze_if(CodeGen *g, ImportTableEntry *import, BlockContext *parent_context,
3495 TypeTableEntry *expected_type, AstNode *node,3495 TypeTableEntry *expected_type, AstNode *node,
3496 AstNode **then_node, AstNode **else_node, bool cond_is_const, bool cond_bool_val)3496 AstNode **then_node, AstNode **else_node, bool cond_is_const, bool cond_bool_val)
3497{3497{
...@@ -3500,8 +3500,27 @@ static TypeTableEntry *analyze_if(CodeGen *g, ImportTableEntry *import, BlockCon...@@ -3500,8 +3500,27 @@ static TypeTableEntry *analyze_if(CodeGen *g, ImportTableEntry *import, BlockCon
3500 normalize_parent_ptrs(node);3500 normalize_parent_ptrs(node);
3501 }3501 }
35023502
3503 TypeTableEntry *then_type = analyze_expression(g, import, context, expected_type, *then_node);3503 BlockContext *then_context;
3504 TypeTableEntry *else_type = analyze_expression(g, import, context, expected_type, *else_node);3504 BlockContext *else_context;
3505 if (cond_is_const) {
3506 if (cond_bool_val) {
3507 then_context = parent_context;
3508 else_context = new_block_context(node, parent_context);
3509
3510 else_context->codegen_excluded = true;
3511 } else {
3512 then_context = new_block_context(node, parent_context);
3513 else_context = parent_context;
3514
3515 then_context->codegen_excluded = true;
3516 }
3517 } else {
3518 then_context = parent_context;
3519 else_context = parent_context;
3520 }
3521
3522 TypeTableEntry *then_type = analyze_expression(g, import, then_context, expected_type, *then_node);
3523 TypeTableEntry *else_type = analyze_expression(g, import, else_context, expected_type, *else_node);
35053524
3506 if (then_type->id == TypeTableEntryIdInvalid || else_type->id == TypeTableEntryIdInvalid) {3525 if (then_type->id == TypeTableEntryIdInvalid || else_type->id == TypeTableEntryIdInvalid) {
3507 return g->builtin_types.entry_invalid;3526 return g->builtin_types.entry_invalid;
...@@ -3513,7 +3532,7 @@ static TypeTableEntry *analyze_if(CodeGen *g, ImportTableEntry *import, BlockCon...@@ -3513,7 +3532,7 @@ static TypeTableEntry *analyze_if(CodeGen *g, ImportTableEntry *import, BlockCon
3513 } else {3532 } else {
3514 AstNode *op_nodes[] = {*then_node, *else_node};3533 AstNode *op_nodes[] = {*then_node, *else_node};
3515 TypeTableEntry *op_types[] = {then_type, else_type};3534 TypeTableEntry *op_types[] = {then_type, else_type};
3516 result_type = resolve_peer_type_compatibility(g, import, context, node, op_nodes, op_types, 2);3535 result_type = resolve_peer_type_compatibility(g, import, parent_context, node, op_nodes, op_types, 2);
3517 }3536 }
35183537
3519 if (!cond_is_const) {3538 if (!cond_is_const) {