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(
23462346 }
23472347
23482348 while (true) {
2349 assert(loc.line != 0);
2350 const newline_count = if (loc.line == 1) @as(u8, 1) else @as(u8, 2);
2349 // translate-c doesn't generate correct newlines
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);
23512353 try stream.writeByteNTimes('\n', newline_count);
23522354 try stream.writeByteNTimes(' ', indent);
23532355 try stream.writeAll(mem.trimRight(u8, tree.tokenSlicePtr(next_token), " "));
src-self-hosted/translate_c.zig+3-1
......@@ -3058,6 +3058,7 @@ fn transCreateCompoundAssign(
30583058 // common case
30593059 // c: lhs += rhs
30603060 // zig: lhs += rhs
3061
30613062 if ((is_mod or is_div) and is_signed) {
30623063 const op_token = try appendToken(rp.c, .Equal, "=");
30633064 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
47724773 const msg_tok = try appendTokenFmt(c, .StringLiteral, "\"" ++ format ++ "\"", args);
47734774 const rparen_tok = try appendToken(c, .RParen, ")");
47744775 const semi_tok = try appendToken(c, .Semicolon, ";");
4776 _ = try appendTokenFmt(c, .LineComment, "// {}", .{c.locStr(loc)});
47754777
47764778 const msg_node = try c.a().create(ast.Node.StringLiteral);
47774779 msg_node.* = ast.Node.StringLiteral{
......@@ -5440,7 +5442,7 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
54405442 };
54415443 return &node.base;
54425444 } 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]});
54445446 const node = try c.a().create(ast.Node.IntegerLiteral);
54455447 node.* = .{
54465448 .token = token,