From 0122f2cff6fd44b08b17214e8535e8afba3d4985 Mon Sep 17 00:00:00 2001 From: Lachlan Easton Date: Tue, 14 Apr 2020 18:42:25 +1000 Subject: Translate C: Redo Add comment containing c source location for failed decls. --- src-self-hosted/translate_c.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src-self-hosted') diff --git a/src-self-hosted/translate_c.zig b/src-self-hosted/translate_c.zig index a88cc8e81b..508d781b7b 100644 --- a/src-self-hosted/translate_c.zig +++ b/src-self-hosted/translate_c.zig @@ -3058,6 +3058,7 @@ fn transCreateCompoundAssign( // common case // c: lhs += rhs // zig: lhs += rhs + if ((is_mod or is_div) and is_signed) { const op_token = try appendToken(rp.c, .Equal, "="); 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 const msg_tok = try appendTokenFmt(c, .StringLiteral, "\"" ++ format ++ "\"", args); const rparen_tok = try appendToken(c, .RParen, ")"); const semi_tok = try appendToken(c, .Semicolon, ";"); + _ = try appendTokenFmt(c, .LineComment, "// {}", .{c.locStr(loc)}); const msg_node = try c.a().create(ast.Node.StringLiteral); msg_node.* = ast.Node.StringLiteral{ @@ -5440,7 +5442,7 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8, }; return &node.base; } else { - const token = try appendTokenFmt(c, .IntegerLiteral, "0x{x}", .{source[tok.start + 1 .. tok.end - 1]}); + const token = try appendTokenFmt(c, .IntegerLiteral, "0x{x}", .{source[tok.start+1..tok.end-1]}); const node = try c.a().create(ast.Node.IntegerLiteral); node.* = .{ .token = token, -- cgit v1.2.3 From 3e375ee2b92db3ab4603c5f42f5a7fce8610ccab Mon Sep 17 00:00:00 2001 From: Vexu Date: Sat, 16 May 2020 14:17:50 +0300 Subject: translate-c use tagName for token id --- src-self-hosted/translate_c.zig | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src-self-hosted') diff --git a/src-self-hosted/translate_c.zig b/src-self-hosted/translate_c.zig index 508d781b7b..9037548d30 100644 --- a/src-self-hosted/translate_c.zig +++ b/src-self-hosted/translate_c.zig @@ -5013,8 +5013,8 @@ fn transMacroDefine(c: *Context, it: *CTokenList.Iterator, source: []const u8, n c, source_loc, name, - "unable to translate C expr: unexpected token {}", - .{last.id}, + "unable to translate C expr: unexpected token .{}", + .{@tagName(last.id)}, ); node.semicolon_token = try appendToken(c, .Semicolon, ";"); @@ -5123,8 +5123,8 @@ fn transMacroFnDefine(c: *Context, it: *CTokenList.Iterator, source: []const u8, c, source_loc, name, - "unable to translate C expr: unexpected token {}", - .{last.id}, + "unable to translate C expr: unexpected token .{}", + .{@tagName(last.id)}, ); _ = try appendToken(c, .Semicolon, ";"); const type_of_arg = if (expr.id != .Block) expr else blk: { @@ -5658,8 +5658,8 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8, c, source_loc, source[first_tok.start..first_tok.end], - "unable to translate C expr: unexpected token {}", - .{tok.id}, + "unable to translate C expr: unexpected token .{}", + .{@tagName(tok.id)}, ); return error.ParseError; }, -- cgit v1.2.3