| ... | ... | @@ -2119,13 +2119,16 @@ fn transForLoop( |
| 2119 | 2119 | .parent = scope, |
| 2120 | 2120 | .id = .Loop, |
| 2121 | 2121 | }; |
| 2122 | | var block = false; |
| 2122 | |
| 2123 | 2123 | var block_scope: ?*Scope.Block = null; |
| 2124 | 2124 | if (ZigClangForStmt_getInit(stmt)) |init| { |
| 2125 | 2125 | block_scope = try Scope.Block.init(rp.c, scope, null); |
| 2126 | | block_scope.?.block_node = try transCreateNodeBlock(rp.c, null); |
| 2126 | const block = try transCreateNodeBlock(rp.c, null); |
| 2127 | block_scope.?.block_node = block; |
| 2127 | 2128 | loop_scope.parent = &block_scope.?.base; |
| 2128 | | _ = try transStmt(rp, &loop_scope, init, .unused, .r_value); |
| 2129 | const result = try transStmt(rp, &block_scope.?.base, init, .unused, .r_value); |
| 2130 | if (result != &block.base) |
| 2131 | try block.statements.push(result); |
| 2129 | 2132 | } |
| 2130 | 2133 | var cond_scope = Scope{ |
| 2131 | 2134 | .parent = scope, |
| ... | ... | @@ -4720,18 +4723,26 @@ fn parseCExpr(c: *Context, it: *ctok.TokenList.Iterator, source_loc: ZigClangSou |
| 4720 | 4723 | |
| 4721 | 4724 | fn parseCNumLit(c: *Context, tok: *CToken, source_loc: ZigClangSourceLocation) ParseError!*ast.Node { |
| 4722 | 4725 | if (tok.id == .NumLitInt) { |
| 4723 | | if (tok.num_lit_suffix == .None) { |
| 4724 | | if (tok.bytes.len > 2 and tok.bytes[0] == '0') { |
| 4725 | | switch (tok.bytes[1]) { |
| 4726 | | '0'...'7' => { |
| 4727 | | // octal |
| 4728 | | return transCreateNodeInt(c, try std.fmt.allocPrint(c.a(), "0o{}", .{tok.bytes})); |
| 4729 | | }, |
| 4730 | | else => {}, |
| 4731 | | } |
| 4726 | var lit_bytes = tok.bytes; |
| 4727 | |
| 4728 | if (tok.bytes.len > 2 and tok.bytes[0] == '0') { |
| 4729 | switch (tok.bytes[1]) { |
| 4730 | '0'...'7' => { |
| 4731 | // Octal |
| 4732 | lit_bytes = try std.fmt.allocPrint(c.a(), "0o{}", .{tok.bytes}); |
| 4733 | }, |
| 4734 | 'X' => { |
| 4735 | // Hexadecimal with capital X, valid in C but not in Zig |
| 4736 | lit_bytes = try std.fmt.allocPrint(c.a(), "0x{}", .{tok.bytes[2..]}); |
| 4737 | }, |
| 4738 | else => {}, |
| 4732 | 4739 | } |
| 4733 | | return transCreateNodeInt(c, tok.bytes); |
| 4734 | 4740 | } |
| 4741 | |
| 4742 | if (tok.num_lit_suffix == .None) { |
| 4743 | return transCreateNodeInt(c, lit_bytes); |
| 4744 | } |
| 4745 | |
| 4735 | 4746 | const cast_node = try transCreateNodeBuiltinFnCall(c, "@as"); |
| 4736 | 4747 | try cast_node.params.push(try transCreateNodeIdentifier(c, switch (tok.num_lit_suffix) { |
| 4737 | 4748 | .U => "c_uint", |
| ... | ... | @@ -4742,7 +4753,7 @@ fn parseCNumLit(c: *Context, tok: *CToken, source_loc: ZigClangSourceLocation) P |
| 4742 | 4753 | else => unreachable, |
| 4743 | 4754 | })); |
| 4744 | 4755 | _ = try appendToken(c, .Comma, ","); |
| 4745 | | try cast_node.params.push(try transCreateNodeInt(c, tok.bytes)); |
| 4756 | try cast_node.params.push(try transCreateNodeInt(c, lit_bytes)); |
| 4746 | 4757 | cast_node.rparen_token = try appendToken(c, .RParen, ")"); |
| 4747 | 4758 | return &cast_node.base; |
| 4748 | 4759 | } else if (tok.id == .NumLitFloat) { |