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
34913491 return g->builtin_types.entry_unreachable;
34923492}
34933493
3494static TypeTableEntry *analyze_if(CodeGen *g, ImportTableEntry *import, BlockContext *context,
3494static TypeTableEntry *analyze_if(CodeGen *g, ImportTableEntry *import, BlockContext *parent_context,
34953495 TypeTableEntry *expected_type, AstNode *node,
34963496 AstNode **then_node, AstNode **else_node, bool cond_is_const, bool cond_bool_val)
34973497{
......@@ -3500,8 +3500,27 @@ static TypeTableEntry *analyze_if(CodeGen *g, ImportTableEntry *import, BlockCon
35003500 normalize_parent_ptrs(node);
35013501 }
35023502
3503 TypeTableEntry *then_type = analyze_expression(g, import, context, expected_type, *then_node);
3504 TypeTableEntry *else_type = analyze_expression(g, import, context, expected_type, *else_node);
3503 BlockContext *then_context;
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
35063525 if (then_type->id == TypeTableEntryIdInvalid || else_type->id == TypeTableEntryIdInvalid) {
35073526 return g->builtin_types.entry_invalid;
......@@ -3513,7 +3532,7 @@ static TypeTableEntry *analyze_if(CodeGen *g, ImportTableEntry *import, BlockCon
35133532 } else {
35143533 AstNode *op_nodes[] = {*then_node, *else_node};
35153534 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);
35173536 }
35183537
35193538 if (!cond_is_const) {