| author | |
| committer | |
| log | ae5ba369e193ccf3f8103476efed34a6ff141a8d |
| tree | 5dfcbb3223248734413afc1899e3f5adfb1103c4 |
| parent | 70a4794c57425d75505583e03919df983c4d8ccd |
3 files changed, 16 insertions(+), 4 deletions(-)
lib/std/c/tokenizer.zig+9-3| ... | ... | @@ -1079,6 +1079,9 @@ pub const Tokenizer = struct { |
| 1079 | 1079 | 'x', 'X' => { |
| 1080 | 1080 | state = .IntegerLiteralHex; |
| 1081 | 1081 | }, |
| 1082 | '.' => { | |
| 1083 | state = .FloatFraction; | |
| 1084 | }, | |
| 1082 | 1085 | else => { |
| 1083 | 1086 | state = .IntegerSuffix; |
| 1084 | 1087 | self.index -= 1; |
| ... | ... | @@ -1261,13 +1264,16 @@ pub const Tokenizer = struct { |
| 1261 | 1264 | .UnicodeEscape, |
| 1262 | 1265 | .MultiLineComment, |
| 1263 | 1266 | .MultiLineCommentAsterisk, |
| 1264 | .FloatFraction, | |
| 1265 | .FloatFractionHex, | |
| 1266 | 1267 | .FloatExponent, |
| 1267 | .FloatExponentDigits, | |
| 1268 | 1268 | .MacroString, |
| 1269 | 1269 | => result.id = .Invalid, |
| 1270 | 1270 | |
| 1271 | .FloatExponentDigits => result.id = if (counter == 0) .Invalid else .{ .FloatLiteral = .None }, | |
| 1272 | ||
| 1273 | .FloatFraction, | |
| 1274 | .FloatFractionHex, | |
| 1275 | => result.id = .{ .FloatLiteral = .None }, | |
| 1276 | ||
| 1271 | 1277 | .IntegerLiteralOct, |
| 1272 | 1278 | .IntegerLiteralBinary, |
| 1273 | 1279 | .IntegerLiteralHex, |
src-self-hosted/translate_c.zig+3-1| ... | ... | @@ -5122,6 +5122,8 @@ fn parseCNumLit(c: *Context, tok: *CToken, source: []const u8, source_loc: ZigCl |
| 5122 | 5122 | cast_node.rparen_token = try appendToken(c, .RParen, ")"); |
| 5123 | 5123 | return &cast_node.base; |
| 5124 | 5124 | } else if (tok.id == .FloatLiteral) { |
| 5125 | if (lit_bytes[0] == '.') | |
| 5126 | lit_bytes = try std.fmt.allocPrint(c.a(), "0{}", .{lit_bytes}); | |
| 5125 | 5127 | if (tok.id.FloatLiteral == .None) { |
| 5126 | 5128 | return transCreateNodeFloat(c, lit_bytes); |
| 5127 | 5129 | } |
| ... | ... | @@ -5493,7 +5495,7 @@ fn parseCSuffixOpExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8, |
| 5493 | 5495 | // hack to get zig fmt to render a comma in builtin calls |
| 5494 | 5496 | _ = try appendToken(c, .Comma, ","); |
| 5495 | 5497 | |
| 5496 | const ptr_kind = blk:{ | |
| 5498 | const ptr_kind = blk: { | |
| 5497 | 5499 | // * token |
| 5498 | 5500 | _ = it.prev(); |
| 5499 | 5501 | // last token of `node` |
test/translate_c.zig+4| ... | ... | @@ -621,9 +621,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 621 | 621 | cases.add("float suffixes", |
| 622 | 622 | \\#define foo 3.14f |
| 623 | 623 | \\#define bar 16.e-2l |
| 624 | \\#define FOO 0.12345 | |
| 625 | \\#define BAR .12345 | |
| 624 | 626 | , &[_][]const u8{ |
| 625 | 627 | "pub const foo = @as(f32, 3.14);", |
| 626 | 628 | "pub const bar = @as(c_longdouble, 16.e-2);", |
| 629 | "pub const FOO = 0.12345;", | |
| 630 | "pub const BAR = 0.12345;", | |
| 627 | 631 | }); |
| 628 | 632 | |
| 629 | 633 | cases.add("comments", |