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