authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-02-14 23:41:18+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-14 18:57:57-05:00
logb15958c557d3b29c8d4cee9951a8bfd30c215482
tree403355064937bdbeee0951074d89468184946ef2
parent9e1afdc23469e1dece4aea318eb8ad2f6c100a94

fix c tokenizer bug


2 files changed, 9 insertions(+), 0 deletions(-)

lib/std/c/tokenizer.zig+2
...@@ -616,6 +616,7 @@ pub const Tokenizer = struct {...@@ -616,6 +616,7 @@ pub const Tokenizer = struct {
616 },616 },
617 .BackSlash => switch (c) {617 .BackSlash => switch (c) {
618 '\n' => {618 '\n' => {
619 result.start = self.index + 1;
619 state = .Start;620 state = .Start;
620 },621 },
621 '\r' => {622 '\r' => {
...@@ -631,6 +632,7 @@ pub const Tokenizer = struct {...@@ -631,6 +632,7 @@ pub const Tokenizer = struct {
631 },632 },
632 .BackSlashCr => switch (c) {633 .BackSlashCr => switch (c) {
633 '\n' => {634 '\n' => {
635 result.start = self.index + 1;
634 state = .Start;636 state = .Start;
635 },637 },
636 else => {638 else => {
test/translate_c.zig+7
...@@ -3,6 +3,13 @@ const builtin = @import("builtin");...@@ -3,6 +3,13 @@ const builtin = @import("builtin");
3const Target = @import("std").Target;3const Target = @import("std").Target;
44
5pub fn addCases(cases: *tests.TranslateCContext) void {5pub fn addCases(cases: *tests.TranslateCContext) void {
6 cases.add("macro line continuation",
7 \\#define FOO -\
8 \\BAR
9 , &[_][]const u8{
10 \\pub const FOO = -BAR;
11 });
12
6 cases.add("function prototype translated as optional",13 cases.add("function prototype translated as optional",
7 \\typedef void (*fnptr_ty)(void);14 \\typedef void (*fnptr_ty)(void);
8 \\typedef __attribute__((cdecl)) void (*fnptr_attr_ty)(void);15 \\typedef __attribute__((cdecl)) void (*fnptr_attr_ty)(void);