authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-02-05 08:35:30+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-02-05 08:35:30+02:00
log1f49460dcb532a146022ef5e9f037477b4c13314
tree5fde7fef27d44dd3bcfc00f4e42772ee2bd61042
parent35c40f0a700636b0ac09bb9282d2c7c5b905c21b
signaturelock-open Commit is signed but in an unrecognized format.

fix regressions in comments and string prefixes


3 files changed, 22 insertions(+), 2 deletions(-)

lib/std/c/tokenizer.zig-1
...@@ -1049,7 +1049,6 @@ pub const Tokenizer = struct {...@@ -1049,7 +1049,6 @@ pub const Tokenizer = struct {
1049 .LineComment => switch (c) {1049 .LineComment => switch (c) {
1050 '\n' => {1050 '\n' => {
1051 result.id = .LineComment;1051 result.id = .LineComment;
1052 self.index += 1;
1053 break;1052 break;
1054 },1053 },
1055 else => {},1054 else => {},
src-self-hosted/translate_c.zig+8-1
...@@ -5129,7 +5129,14 @@ fn parseCNumLit(c: *Context, tok: *CToken, source: []const u8, source_loc: ZigCl...@@ -5129,7 +5129,14 @@ fn parseCNumLit(c: *Context, tok: *CToken, source: []const u8, source_loc: ZigCl
5129 } else unreachable;5129 } else unreachable;
5130}5130}
51315131
5132fn zigifyEscapeSequences(ctx: *Context, source: []const u8, name: []const u8, source_loc: ZigClangSourceLocation) ![]const u8 {5132fn zigifyEscapeSequences(ctx: *Context, source_bytes: []const u8, name: []const u8, source_loc: ZigClangSourceLocation) ![]const u8 {
5133 var source = source_bytes;
5134 for (source) |c, i| {
5135 if (c == '\"' or c == '\'') {
5136 source = source[i..];
5137 break;
5138 }
5139 }
5133 for (source) |c| {5140 for (source) |c| {
5134 if (c == '\\') {5141 if (c == '\\') {
5135 break;5142 break;
test/translate_c.zig+14
...@@ -626,6 +626,20 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -626,6 +626,20 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
626 "pub const bar = @as(c_longdouble, 16.e-2);",626 "pub const bar = @as(c_longdouble, 16.e-2);",
627 });627 });
628628
629 cases.add("comments",
630 \\#define foo 1 //foo
631 \\#define bar /* bar */ 2
632 , &[_][]const u8{
633 "pub const foo = 1;",
634 "pub const bar = 2;",
635 });
636
637 cases.add("string prefix",
638 \\#define foo L"hello"
639 , &[_][]const u8{
640 "pub const foo = \"hello\";",
641 });
642
629 cases.add("null statements",643 cases.add("null statements",
630 \\void foo(void) {644 \\void foo(void) {
631 \\ ;;;;;645 \\ ;;;;;