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,
53755375 const first_tok = it.list.at(0);
53765376 const token = try appendToken(c, .CharLiteral, try zigifyEscapeSequences(c, source[tok.start..tok.end], source[first_tok.start..first_tok.end], source_loc));
53775377 const node = try c.a().create(ast.Node.CharLiteral);
5378 node.* = ast.Node.CharLiteral{
5378 node.* = .{
53795379 .token = token,
53805380 };
53815381 return &node.base;
......@@ -5384,7 +5384,7 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
53845384 const first_tok = it.list.at(0);
53855385 const token = try appendToken(c, .StringLiteral, try zigifyEscapeSequences(c, source[tok.start..tok.end], source[first_tok.start..first_tok.end], source_loc));
53865386 const node = try c.a().create(ast.Node.StringLiteral);
5387 node.* = ast.Node.StringLiteral{
5387 node.* = .{
53885388 .token = token,
53895389 };
53905390 return &node.base;
......@@ -5793,12 +5793,13 @@ fn parseCSuffixOpExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
57935793 return node;
57945794 },
57955795 }
5796 const cast_fn = if (bool_op) macroIntToBool else macroBoolToInt;
5797 const lhs_node = try cast_fn(c, node);
57965798 const rhs_node = try parseCPrefixOpExpr(c, it, source, source_loc, scope);
57975799 const op_node = try c.a().create(ast.Node.InfixOp);
5798 const cast_fn = if (bool_op) macroIntToBool else macroBoolToInt;
57995800 op_node.* = .{
58005801 .op_token = op_token,
5801 .lhs = try cast_fn(c, node),
5802 .lhs = lhs_node,
58025803 .op = op_id,
58035804 .rhs = try cast_fn(c, rhs_node),
58045805 };
test/translate_c.zig+8
......@@ -3,6 +3,14 @@ const std = @import("std");
33const CrossTarget = std.zig.CrossTarget;
44
55pub 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
614 cases.add("c booleans are just ints",
715 \\#define FOO(x) ((x >= 0) + (x >= 0))
816 \\#define BAR 1 && 2 > 4