From 2a05ca1c9449fb26beaa948402e2742dee680137 Mon Sep 17 00:00:00 2001 From: Layne Gustafson Date: Sat, 28 Mar 2020 20:40:13 -0400 Subject: [PATCH 1/2] Conv macro string concat to ++ --- src-self-hosted/translate_c.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src-self-hosted/translate_c.zig b/src-self-hosted/translate_c.zig index 3235ac90c0b9451cebc116a89aa8c77b4a6e0cd0..1d8a2679f3696e874f2813277d8ede2bf97f352c 100644 --- a/src-self-hosted/translate_c.zig +++ b/src-self-hosted/translate_c.zig @@ -5782,6 +5782,18 @@ fn parseCSuffixOpExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8, op_id = .Mod; op_token = try appendToken(c, .Percent, "%"); }, + .StringLiteral => { + op_id = .ArrayCat; + op_token = try appendToken(c, .PlusPlus, "++"); + + _ = it.prev(); + }, + .Identifier => { + op_id = .ArrayCat; + op_token = try appendToken(c, .PlusPlus, "++"); + + _ = it.prev(); + }, else => { _ = it.prev(); return node; -- 2.54.0 From a55897106e34c55b02aeb5a5256e7da34f253de5 Mon Sep 17 00:00:00 2001 From: Layne Gustafson Date: Sat, 28 Mar 2020 20:40:26 -0400 Subject: [PATCH 2/2] Add macro string concat tests --- test/translate_c.zig | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/translate_c.zig b/test/translate_c.zig index 9890c4034e5b17aedfd30e78615d8c1b35db5107..8c84526a4914605e39a84e8070174271d2b7da63 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -2808,4 +2808,43 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ return if (x > y) x else y; \\} }); + + cases.add("string concatenation in macros", + \\#define FOO "hello" + \\#define BAR FOO " world" + \\#define BAZ "oh, " FOO + , &[_][]const u8{ + \\pub const FOO = "hello"; + , + \\pub const BAR = FOO ++ " world"; + , + \\pub const BAZ = "oh, " ++ FOO; + }); + + cases.add("string concatenation in macros: two defines", + \\#define FOO "hello" + \\#define BAZ " world" + \\#define BAR FOO BAZ + , &[_][]const u8{ + \\pub const FOO = "hello"; + , + \\pub const BAZ = " world"; + , + \\pub const BAR = FOO ++ BAZ; + }); + + cases.add("string concatenation in macros: two strings", + \\#define FOO "a" "b" + \\#define BAR FOO "c" + , &[_][]const u8{ + \\pub const FOO = "a" ++ "b"; + , + \\pub const BAR = FOO ++ "c"; + }); + + cases.add("string concatenation in macros: three strings", + \\#define FOO "a" "b" "c" + , &[_][]const u8{ + \\pub const FOO = "a" ++ ("b" ++ "c"); + }); } -- 2.54.0