Merge pull request #4939 from SuperAuguste/master
translate-c: Properly translate C multicharacter literals
This commit is contained in:
commit
c5ced0d74a
|
@ -5433,12 +5433,21 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
|
||||||
switch (tok.id) {
|
switch (tok.id) {
|
||||||
.CharLiteral => {
|
.CharLiteral => {
|
||||||
const first_tok = it.list.at(0);
|
const first_tok = it.list.at(0);
|
||||||
const token = try appendToken(c, .CharLiteral, try zigifyEscapeSequences(c, source[tok.start..tok.end], source[first_tok.start..first_tok.end], source_loc));
|
if (source[tok.start] != '\'' or source[tok.start + 1] == '\\' or tok.end - tok.start == 3) {
|
||||||
const node = try c.a().create(ast.Node.CharLiteral);
|
const token = try appendToken(c, .CharLiteral, try zigifyEscapeSequences(c, source[tok.start..tok.end], source[first_tok.start..first_tok.end], source_loc));
|
||||||
node.* = .{
|
const node = try c.a().create(ast.Node.CharLiteral);
|
||||||
.token = token,
|
node.* = .{
|
||||||
};
|
.token = token,
|
||||||
return &node.base;
|
};
|
||||||
|
return &node.base;
|
||||||
|
} else {
|
||||||
|
const token = try appendTokenFmt(c, .IntegerLiteral, "0x{x}", .{source[tok.start+1..tok.end-1]});
|
||||||
|
const node = try c.a().create(ast.Node.IntegerLiteral);
|
||||||
|
node.* = .{
|
||||||
|
.token = token,
|
||||||
|
};
|
||||||
|
return &node.base;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
.StringLiteral => {
|
.StringLiteral => {
|
||||||
const first_tok = it.list.at(0);
|
const first_tok = it.list.at(0);
|
||||||
|
|
|
@ -2873,4 +2873,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
|
||||||
, &[_][]const u8{
|
, &[_][]const u8{
|
||||||
\\pub const FOO = "a" ++ ("b" ++ "c");
|
\\pub const FOO = "a" ++ ("b" ++ "c");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
cases.add("multibyte character literals",
|
||||||
|
\\#define FOO 'abcd'
|
||||||
|
, &[_][]const u8{
|
||||||
|
\\pub const FOO = 0x61626364;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user