authorgravatar for lachlan@lakebythewoods.xyzLachlan Easton <lachlan@lakebythewoods.xyz> 2020-04-14 18:42:25+10:00
committergravatar for lachlan@lakebythewoods.xyzLachlan Easton <lachlan@lakebythewoods.xyz> 2020-04-14 22:13:43+10:00
log0122f2cff6fd44b08b17214e8535e8afba3d4985
treea866be9d8e678876d5baabf53d37a55a28c31ce5
parent448f8c2eb8335e1c8fc0dd76c3ed728b80487a63

Translate C: Redo Add comment containing c source location for failed decls.


2 files changed, 7 insertions(+), 3 deletions(-)

lib/std/zig/render.zig+4-2
...@@ -2346,8 +2346,10 @@ fn renderTokenOffset(...@@ -2346,8 +2346,10 @@ fn renderTokenOffset(
2346 }2346 }
23472347
2348 while (true) {2348 while (true) {
2349 assert(loc.line != 0);2349 // translate-c doesn't generate correct newlines
2350 const newline_count = if (loc.line == 1) @as(u8, 1) else @as(u8, 2);2350 // in generated code (loc.line == 0) so treat that case
2351 // as though there was meant to be a newline between the tokens
2352 const newline_count = if (loc.line <= 1) @as(u8, 1) else @as(u8, 2);
2351 try stream.writeByteNTimes('\n', newline_count);2353 try stream.writeByteNTimes('\n', newline_count);
2352 try stream.writeByteNTimes(' ', indent);2354 try stream.writeByteNTimes(' ', indent);
2353 try stream.writeAll(mem.trimRight(u8, tree.tokenSlicePtr(next_token), " "));2355 try stream.writeAll(mem.trimRight(u8, tree.tokenSlicePtr(next_token), " "));
src-self-hosted/translate_c.zig+3-1
...@@ -3058,6 +3058,7 @@ fn transCreateCompoundAssign(...@@ -3058,6 +3058,7 @@ fn transCreateCompoundAssign(
3058 // common case3058 // common case
3059 // c: lhs += rhs3059 // c: lhs += rhs
3060 // zig: lhs += rhs3060 // zig: lhs += rhs
3061
3061 if ((is_mod or is_div) and is_signed) {3062 if ((is_mod or is_div) and is_signed) {
3062 const op_token = try appendToken(rp.c, .Equal, "=");3063 const op_token = try appendToken(rp.c, .Equal, "=");
3063 const op_node = try rp.c.a().create(ast.Node.InfixOp);3064 const op_node = try rp.c.a().create(ast.Node.InfixOp);
...@@ -4772,6 +4773,7 @@ pub fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comp...@@ -4772,6 +4773,7 @@ pub fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comp
4772 const msg_tok = try appendTokenFmt(c, .StringLiteral, "\"" ++ format ++ "\"", args);4773 const msg_tok = try appendTokenFmt(c, .StringLiteral, "\"" ++ format ++ "\"", args);
4773 const rparen_tok = try appendToken(c, .RParen, ")");4774 const rparen_tok = try appendToken(c, .RParen, ")");
4774 const semi_tok = try appendToken(c, .Semicolon, ";");4775 const semi_tok = try appendToken(c, .Semicolon, ";");
4776 _ = try appendTokenFmt(c, .LineComment, "// {}", .{c.locStr(loc)});
47754777
4776 const msg_node = try c.a().create(ast.Node.StringLiteral);4778 const msg_node = try c.a().create(ast.Node.StringLiteral);
4777 msg_node.* = ast.Node.StringLiteral{4779 msg_node.* = ast.Node.StringLiteral{
...@@ -5440,7 +5442,7 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,...@@ -5440,7 +5442,7 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
5440 };5442 };
5441 return &node.base;5443 return &node.base;
5442 } else {5444 } else {
5443 const token = try appendTokenFmt(c, .IntegerLiteral, "0x{x}", .{source[tok.start + 1 .. tok.end - 1]});5445 const token = try appendTokenFmt(c, .IntegerLiteral, "0x{x}", .{source[tok.start+1..tok.end-1]});
5444 const node = try c.a().create(ast.Node.IntegerLiteral);5446 const node = try c.a().create(ast.Node.IntegerLiteral);
5445 node.* = .{5447 node.* = .{
5446 .token = token,5448 .token = token,