fix regressions in comments and string prefixes

This commit is contained in:
Vexu 2020-02-05 08:35:30 +02:00
parent 35c40f0a70
commit 1f49460dcb
No known key found for this signature in database
GPG Key ID: 59AEB8936E16A6AC
3 changed files with 22 additions and 2 deletions

View File

@ -1049,7 +1049,6 @@ pub const Tokenizer = struct {
.LineComment => switch (c) {
'\n' => {
result.id = .LineComment;
self.index += 1;
break;
},
else => {},

View File

@ -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;

View File

@ -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) {
\\ ;;;;;