| ... | ... | @@ -2808,16 +2808,18 @@ fn maybeBlockify(c: *Context, scope: *Scope, stmt: *const clang.Stmt) TransError |
| 2808 | 2808 | .NullStmtClass, |
| 2809 | 2809 | .WhileStmtClass, |
| 2810 | 2810 | => return transStmt(c, scope, stmt, .unused), |
| 2811 | | else => { |
| 2812 | | var block_scope = try Scope.Block.init(c, scope, false); |
| 2813 | | defer block_scope.deinit(); |
| 2814 | | const result = try transStmt(c, &block_scope.base, stmt, .unused); |
| 2815 | | try block_scope.statements.append(result); |
| 2816 | | return block_scope.complete(c); |
| 2817 | | }, |
| 2811 | else => return blockify(c, scope, stmt), |
| 2818 | 2812 | } |
| 2819 | 2813 | } |
| 2820 | 2814 | |
| 2815 | fn blockify(c: *Context, scope: *Scope, stmt: *const clang.Stmt) TransError!Node { |
| 2816 | var block_scope = try Scope.Block.init(c, scope, false); |
| 2817 | defer block_scope.deinit(); |
| 2818 | const result = try transStmt(c, &block_scope.base, stmt, .unused); |
| 2819 | try block_scope.statements.append(result); |
| 2820 | return block_scope.complete(c); |
| 2821 | } |
| 2822 | |
| 2821 | 2823 | fn transIfStmt( |
| 2822 | 2824 | c: *Context, |
| 2823 | 2825 | scope: *Scope, |
| ... | ... | @@ -2835,9 +2837,21 @@ fn transIfStmt( |
| 2835 | 2837 | const cond_expr = @ptrCast(*const clang.Expr, stmt.getCond()); |
| 2836 | 2838 | const cond = try transBoolExpr(c, &cond_scope.base, cond_expr, .used); |
| 2837 | 2839 | |
| 2838 | | const then_body = try maybeBlockify(c, scope, stmt.getThen()); |
| 2840 | const then_stmt = stmt.getThen(); |
| 2841 | const else_stmt = stmt.getElse(); |
| 2842 | const then_class = then_stmt.getStmtClass(); |
| 2843 | // block needed to keep else statement from attaching to inner while |
| 2844 | const must_blockify = (else_stmt != null) and switch (then_class) { |
| 2845 | .DoStmtClass, .ForStmtClass, .WhileStmtClass => true, |
| 2846 | else => false, |
| 2847 | }; |
| 2848 | |
| 2849 | const then_body = if (must_blockify) |
| 2850 | try blockify(c, scope, then_stmt) |
| 2851 | else |
| 2852 | try maybeBlockify(c, scope, then_stmt); |
| 2839 | 2853 | |
| 2840 | | const else_body = if (stmt.getElse()) |expr| |
| 2854 | const else_body = if (else_stmt) |expr| |
| 2841 | 2855 | try maybeBlockify(c, scope, expr) |
| 2842 | 2856 | else |
| 2843 | 2857 | null; |