authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-03-12 17:14:01+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-03-12 17:14:01+02:00
log02c491e42affedf6dd33e75a456531bb60aff8a3
tree898603ef5147c1a643604f6c90d10e45cae360c9
parentdda711ba0d650b921108c6d13bd9b7d37c47a96e
signaturelock-open Commit is signed but in an unrecognized format.

translate-c fix order of tokens


2 files changed, 13 insertions(+), 4 deletions(-)

src-self-hosted/translate_c.zig+5-4
...@@ -5375,7 +5375,7 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,...@@ -5375,7 +5375,7 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
5375 const first_tok = it.list.at(0);5375 const first_tok = it.list.at(0);
5376 const token = try appendToken(c, .CharLiteral, try zigifyEscapeSequences(c, source[tok.start..tok.end], source[first_tok.start..first_tok.end], source_loc));5376 const token = try appendToken(c, .CharLiteral, try zigifyEscapeSequences(c, source[tok.start..tok.end], source[first_tok.start..first_tok.end], source_loc));
5377 const node = try c.a().create(ast.Node.CharLiteral);5377 const node = try c.a().create(ast.Node.CharLiteral);
5378 node.* = ast.Node.CharLiteral{5378 node.* = .{
5379 .token = token,5379 .token = token,
5380 };5380 };
5381 return &node.base;5381 return &node.base;
...@@ -5384,7 +5384,7 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,...@@ -5384,7 +5384,7 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
5384 const first_tok = it.list.at(0);5384 const first_tok = it.list.at(0);
5385 const token = try appendToken(c, .StringLiteral, try zigifyEscapeSequences(c, source[tok.start..tok.end], source[first_tok.start..first_tok.end], source_loc));5385 const token = try appendToken(c, .StringLiteral, try zigifyEscapeSequences(c, source[tok.start..tok.end], source[first_tok.start..first_tok.end], source_loc));
5386 const node = try c.a().create(ast.Node.StringLiteral);5386 const node = try c.a().create(ast.Node.StringLiteral);
5387 node.* = ast.Node.StringLiteral{5387 node.* = .{
5388 .token = token,5388 .token = token,
5389 };5389 };
5390 return &node.base;5390 return &node.base;
...@@ -5793,12 +5793,13 @@ fn parseCSuffixOpExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,...@@ -5793,12 +5793,13 @@ fn parseCSuffixOpExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
5793 return node;5793 return node;
5794 },5794 },
5795 }5795 }
5796 const cast_fn = if (bool_op) macroIntToBool else macroBoolToInt;
5797 const lhs_node = try cast_fn(c, node);
5796 const rhs_node = try parseCPrefixOpExpr(c, it, source, source_loc, scope);5798 const rhs_node = try parseCPrefixOpExpr(c, it, source, source_loc, scope);
5797 const op_node = try c.a().create(ast.Node.InfixOp);5799 const op_node = try c.a().create(ast.Node.InfixOp);
5798 const cast_fn = if (bool_op) macroIntToBool else macroBoolToInt;
5799 op_node.* = .{5800 op_node.* = .{
5800 .op_token = op_token,5801 .op_token = op_token,
5801 .lhs = try cast_fn(c, node),5802 .lhs = lhs_node,
5802 .op = op_id,5803 .op = op_id,
5803 .rhs = try cast_fn(c, rhs_node),5804 .rhs = try cast_fn(c, rhs_node),
5804 };5805 };
test/translate_c.zig+8
...@@ -3,6 +3,14 @@ const std = @import("std");...@@ -3,6 +3,14 @@ const std = @import("std");
3const CrossTarget = std.zig.CrossTarget;3const CrossTarget = std.zig.CrossTarget;
44
5pub fn addCases(cases: *tests.TranslateCContext) void {5pub fn addCases(cases: *tests.TranslateCContext) void {
6 cases.add("correct semicolon after infixop",
7 \\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0)
8 , &[_][]const u8{
9 \\pub inline fn __ferror_unlocked_body(_fp: var) @TypeOf(((_fp.*._flags) & _IO_ERR_SEEN) != 0) {
10 \\ return ((_fp.*._flags) & _IO_ERR_SEEN) != 0;
11 \\}
12 });
13
6 cases.add("c booleans are just ints",14 cases.add("c booleans are just ints",
7 \\#define FOO(x) ((x >= 0) + (x >= 0))15 \\#define FOO(x) ((x >= 0) + (x >= 0))
8 \\#define BAR 1 && 2 > 416 \\#define BAR 1 && 2 > 4