Commit 1f49460dcb

Vexu <git@vexu.eu>
2020-02-05 07:35:30
fix regressions in comments and string prefixes
1 parent 35c40f0
Changed files (3)
lib
src-self-hosted
test
lib/std/c/tokenizer.zig
@@ -1049,7 +1049,6 @@ pub const Tokenizer = struct {
                 .LineComment => switch (c) {
                     '\n' => {
                         result.id = .LineComment;
-                        self.index += 1;
                         break;
                     },
                     else => {},
src-self-hosted/translate_c.zig
@@ -5129,7 +5129,14 @@ fn parseCNumLit(c: *Context, tok: *CToken, source: []const u8, source_loc: ZigCl
     } else unreachable;
 }
 
-fn zigifyEscapeSequences(ctx: *Context, source: []const u8, name: []const u8, source_loc: ZigClangSourceLocation) ![]const u8 {
+fn zigifyEscapeSequences(ctx: *Context, source_bytes: []const u8, name: []const u8, source_loc: ZigClangSourceLocation) ![]const u8 {
+    var source = source_bytes;
+    for (source) |c, i| {
+        if (c == '\"' or c == '\'') {
+            source = source[i..];
+            break;
+        }
+    }
     for (source) |c| {
         if (c == '\\') {
             break;
test/translate_c.zig
@@ -626,6 +626,20 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
         "pub const bar = @as(c_longdouble, 16.e-2);",
     });
 
+    cases.add("comments",
+        \\#define foo 1 //foo
+        \\#define bar /* bar */ 2
+    , &[_][]const u8{
+        "pub const foo = 1;",
+        "pub const bar = 2;",
+    });
+
+    cases.add("string prefix",
+        \\#define foo L"hello"
+    , &[_][]const u8{
+        "pub const foo = \"hello\";",
+    });
+
     cases.add("null statements",
         \\void foo(void) {
         \\    ;;;;;