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