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 {
10491049 .LineComment => switch (c) {
10501050 '\n' => {
10511051 result.id = .LineComment;
1052 self.index += 1;
10531052 break;
10541053 },
10551054 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
51295129 } else unreachable;
51305130}
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 }
51335140 for (source) |c| {
51345141 if (c == '\\') {
51355142 break;
test/translate_c.zig+14
......@@ -626,6 +626,20 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
626626 "pub const bar = @as(c_longdouble, 16.e-2);",
627627 });
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
629643 cases.add("null statements",
630644 \\void foo(void) {
631645 \\ ;;;;;