| ... | ... | @@ -89,7 +89,7 @@ const Scope = struct { |
| 89 | 89 | var proposed_name = name; |
| 90 | 90 | while (scope.contains(proposed_name)) { |
| 91 | 91 | scope.mangle_count += 1; |
| 92 | | proposed_name = try std.fmt.allocPrint(c.a(), "{}_{}", .{ name, scope.mangle_count }); |
| 92 | proposed_name = try std.fmtstream.allocPrint(c.a(), "{}_{}", .{ name, scope.mangle_count }); |
| 93 | 93 | } |
| 94 | 94 | try scope.variables.push(.{ .name = name, .alias = proposed_name }); |
| 95 | 95 | return proposed_name; |
| ... | ... | @@ -246,7 +246,7 @@ pub const Context = struct { |
| 246 | 246 | |
| 247 | 247 | const line = ZigClangSourceManager_getSpellingLineNumber(c.source_manager, spelling_loc); |
| 248 | 248 | const column = ZigClangSourceManager_getSpellingColumnNumber(c.source_manager, spelling_loc); |
| 249 | | return std.fmt.allocPrint(c.a(), "{}:{}:{}", .{ filename, line, column }); |
| 249 | return std.fmtstream.allocPrint(c.a(), "{}:{}:{}", .{ filename, line, column }); |
| 250 | 250 | } |
| 251 | 251 | }; |
| 252 | 252 | |
| ... | ... | @@ -516,7 +516,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 516 | 516 | |
| 517 | 517 | const arg_name = blk: { |
| 518 | 518 | const param_prefix = if (is_const) "" else "arg_"; |
| 519 | | const bare_arg_name = try std.fmt.allocPrint(c.a(), "{}{}", .{ param_prefix, mangled_param_name }); |
| 519 | const bare_arg_name = try std.fmtstream.allocPrint(c.a(), "{}{}", .{ param_prefix, mangled_param_name }); |
| 520 | 520 | break :blk try block_scope.makeMangledName(c, bare_arg_name); |
| 521 | 521 | }; |
| 522 | 522 | |
| ... | ... | @@ -560,7 +560,7 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl) Error!void { |
| 560 | 560 | |
| 561 | 561 | // TODO https://github.com/ziglang/zig/issues/3756 |
| 562 | 562 | // TODO https://github.com/ziglang/zig/issues/1802 |
| 563 | | const checked_name = if (isZigPrimitiveType(var_name)) try std.fmt.allocPrint(c.a(), "{}_{}", .{var_name, c.getMangle()}) else var_name; |
| 563 | const checked_name = if (isZigPrimitiveType(var_name)) try std.fmtstream.allocPrint(c.a(), "{}_{}", .{var_name, c.getMangle()}) else var_name; |
| 564 | 564 | const var_decl_loc = ZigClangVarDecl_getLocation(var_decl); |
| 565 | 565 | |
| 566 | 566 | const qual_type = ZigClangVarDecl_getTypeSourceInfo_getType(var_decl); |
| ... | ... | @@ -620,7 +620,7 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl) Error!void { |
| 620 | 620 | _ = try appendToken(rp.c, .LParen, "("); |
| 621 | 621 | const expr = try transCreateNodeStringLiteral( |
| 622 | 622 | rp.c, |
| 623 | | try std.fmt.allocPrint(rp.c.a(), "\"{}\"", .{str_ptr[0..str_len]}), |
| 623 | try std.fmtstream.allocPrint(rp.c.a(), "\"{}\"", .{str_ptr[0..str_len]}), |
| 624 | 624 | ); |
| 625 | 625 | _ = try appendToken(rp.c, .RParen, ")"); |
| 626 | 626 | |
| ... | ... | @@ -677,7 +677,7 @@ fn transTypeDef(c: *Context, typedef_decl: *const ZigClangTypedefNameDecl, top_l |
| 677 | 677 | |
| 678 | 678 | // TODO https://github.com/ziglang/zig/issues/3756 |
| 679 | 679 | // TODO https://github.com/ziglang/zig/issues/1802 |
| 680 | | const checked_name = if (isZigPrimitiveType(typedef_name)) try std.fmt.allocPrint(c.a(), "{}_{}", .{typedef_name, c.getMangle()}) else typedef_name; |
| 680 | const checked_name = if (isZigPrimitiveType(typedef_name)) try std.fmtstream.allocPrint(c.a(), "{}_{}", .{typedef_name, c.getMangle()}) else typedef_name; |
| 681 | 681 | |
| 682 | 682 | if (mem.eql(u8, checked_name, "uint8_t")) |
| 683 | 683 | return transTypeDefAsBuiltin(c, typedef_decl, "u8") |
| ... | ... | @@ -738,7 +738,7 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?* |
| 738 | 738 | // Record declarations such as `struct {...} x` have no name but they're not |
| 739 | 739 | // anonymous hence here isAnonymousStructOrUnion is not needed |
| 740 | 740 | if (bare_name.len == 0) { |
| 741 | | bare_name = try std.fmt.allocPrint(c.a(), "unnamed_{}", .{c.getMangle()}); |
| 741 | bare_name = try std.fmtstream.allocPrint(c.a(), "unnamed_{}", .{c.getMangle()}); |
| 742 | 742 | is_unnamed = true; |
| 743 | 743 | } |
| 744 | 744 | |
| ... | ... | @@ -755,7 +755,7 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?* |
| 755 | 755 | return null; |
| 756 | 756 | } |
| 757 | 757 | |
| 758 | | const name = try std.fmt.allocPrint(c.a(), "{}_{}", .{ container_kind_name, bare_name }); |
| 758 | const name = try std.fmtstream.allocPrint(c.a(), "{}_{}", .{ container_kind_name, bare_name }); |
| 759 | 759 | _ = try c.decl_table.put(@ptrToInt(ZigClangRecordDecl_getCanonicalDecl(record_decl)), name); |
| 760 | 760 | |
| 761 | 761 | const node = try transCreateNodeVarDecl(c, !is_unnamed, true, name); |
| ... | ... | @@ -812,7 +812,7 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?* |
| 812 | 812 | var is_anon = false; |
| 813 | 813 | var raw_name = try c.str(ZigClangNamedDecl_getName_bytes_begin(@ptrCast(*const ZigClangNamedDecl, field_decl))); |
| 814 | 814 | if (ZigClangFieldDecl_isAnonymousStructOrUnion(field_decl)) { |
| 815 | | raw_name = try std.fmt.allocPrint(c.a(), "unnamed_{}", .{c.getMangle()}); |
| 815 | raw_name = try std.fmtstream.allocPrint(c.a(), "unnamed_{}", .{c.getMangle()}); |
| 816 | 816 | is_anon = true; |
| 817 | 817 | } |
| 818 | 818 | const field_name = try appendIdentifier(c, raw_name); |
| ... | ... | @@ -882,11 +882,11 @@ fn transEnumDecl(c: *Context, enum_decl: *const ZigClangEnumDecl) Error!?*ast.No |
| 882 | 882 | var bare_name = try c.str(ZigClangNamedDecl_getName_bytes_begin(@ptrCast(*const ZigClangNamedDecl, enum_decl))); |
| 883 | 883 | var is_unnamed = false; |
| 884 | 884 | if (bare_name.len == 0) { |
| 885 | | bare_name = try std.fmt.allocPrint(c.a(), "unnamed_{}", .{c.getMangle()}); |
| 885 | bare_name = try std.fmtstream.allocPrint(c.a(), "unnamed_{}", .{c.getMangle()}); |
| 886 | 886 | is_unnamed = true; |
| 887 | 887 | } |
| 888 | 888 | |
| 889 | | const name = try std.fmt.allocPrint(c.a(), "enum_{}", .{bare_name}); |
| 889 | const name = try std.fmtstream.allocPrint(c.a(), "enum_{}", .{bare_name}); |
| 890 | 890 | _ = try c.decl_table.put(@ptrToInt(ZigClangEnumDecl_getCanonicalDecl(enum_decl)), name); |
| 891 | 891 | const node = try transCreateNodeVarDecl(c, !is_unnamed, true, name); |
| 892 | 892 | node.eq_token = try appendToken(c, .Equal, "="); |
| ... | ... | @@ -1754,9 +1754,9 @@ fn escapeChar(c: u8, char_buf: *[4]u8) []const u8 { |
| 1754 | 1754 | // Handle the remaining escapes Zig doesn't support by turning them |
| 1755 | 1755 | // into their respective hex representation |
| 1756 | 1756 | if (std.ascii.isCntrl(c)) |
| 1757 | | return std.fmt.bufPrint(char_buf[0..], "\\x{x:0<2}", .{c}) catch unreachable |
| 1757 | return std.fmtstream.bufPrint(char_buf[0..], "\\x{x:0<2}", .{c}) catch unreachable |
| 1758 | 1758 | else |
| 1759 | | return std.fmt.bufPrint(char_buf[0..], "{c}", .{c}) catch unreachable; |
| 1759 | return std.fmtstream.bufPrint(char_buf[0..], "{c}", .{c}) catch unreachable; |
| 1760 | 1760 | }, |
| 1761 | 1761 | }; |
| 1762 | 1762 | } |
| ... | ... | @@ -2436,7 +2436,7 @@ fn transCase( |
| 2436 | 2436 | ) TransError!*ast.Node { |
| 2437 | 2437 | const block_scope = scope.findBlockScope(rp.c) catch unreachable; |
| 2438 | 2438 | const switch_scope = scope.getSwitch(); |
| 2439 | | const label = try std.fmt.allocPrint(rp.c.a(), "__case_{}", .{switch_scope.cases.len - @boolToInt(switch_scope.has_default)}); |
| 2439 | const label = try std.fmtstream.allocPrint(rp.c.a(), "__case_{}", .{switch_scope.cases.len - @boolToInt(switch_scope.has_default)}); |
| 2440 | 2440 | _ = try appendToken(rp.c, .Semicolon, ";"); |
| 2441 | 2441 | |
| 2442 | 2442 | const expr = if (ZigClangCaseStmt_getRHS(stmt)) |rhs| blk: { |
| ... | ... | @@ -4607,7 +4607,7 @@ fn finishTransFnProto( |
| 4607 | 4607 | _ = try appendToken(rp.c, .LParen, "("); |
| 4608 | 4608 | const expr = try transCreateNodeStringLiteral( |
| 4609 | 4609 | rp.c, |
| 4610 | | try std.fmt.allocPrint(rp.c.a(), "\"{}\"", .{str_ptr[0..str_len]}), |
| 4610 | try std.fmtstream.allocPrint(rp.c.a(), "\"{}\"", .{str_ptr[0..str_len]}), |
| 4611 | 4611 | ); |
| 4612 | 4612 | _ = try appendToken(rp.c, .RParen, ")"); |
| 4613 | 4613 | |
| ... | ... | @@ -4752,15 +4752,10 @@ fn appendToken(c: *Context, token_id: Token.Id, bytes: []const u8) !ast.TokenInd |
| 4752 | 4752 | } |
| 4753 | 4753 | |
| 4754 | 4754 | fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, args: var) !ast.TokenIndex { |
| 4755 | | const S = struct { |
| 4756 | | fn callback(context: *Context, bytes: []const u8) error{OutOfMemory}!void { |
| 4757 | | return context.source_buffer.append(bytes); |
| 4758 | | } |
| 4759 | | }; |
| 4760 | 4755 | const start_index = c.source_buffer.len(); |
| 4761 | 4756 | errdefer c.source_buffer.shrink(start_index); |
| 4762 | 4757 | |
| 4763 | | try std.fmt.format(c, error{OutOfMemory}, S.callback, format, args); |
| 4758 | try c.source_buffer.print(format, args); |
| 4764 | 4759 | const end_index = c.source_buffer.len(); |
| 4765 | 4760 | const token_index = c.tree.tokens.len; |
| 4766 | 4761 | const new_token = try c.tree.tokens.addOne(); |
| ... | ... | @@ -4871,7 +4866,7 @@ fn transPreprocessorEntities(c: *Context, unit: *ZigClangASTUnit) Error!void { |
| 4871 | 4866 | const name = try c.str(raw_name); |
| 4872 | 4867 | // TODO https://github.com/ziglang/zig/issues/3756 |
| 4873 | 4868 | // TODO https://github.com/ziglang/zig/issues/1802 |
| 4874 | | const mangled_name = if (isZigPrimitiveType(name)) try std.fmt.allocPrint(c.a(), "{}_{}", .{name, c.getMangle()}) else name; |
| 4869 | const mangled_name = if (isZigPrimitiveType(name)) try std.fmtstream.allocPrint(c.a(), "{}_{}", .{name, c.getMangle()}) else name; |
| 4875 | 4870 | if (scope.containsNow(mangled_name)) { |
| 4876 | 4871 | continue; |
| 4877 | 4872 | } |
| ... | ... | @@ -5156,11 +5151,11 @@ fn parseCNumLit(c: *Context, tok: *CToken, source: []const u8, source_loc: ZigCl |
| 5156 | 5151 | switch (lit_bytes[1]) { |
| 5157 | 5152 | '0'...'7' => { |
| 5158 | 5153 | // Octal |
| 5159 | | lit_bytes = try std.fmt.allocPrint(c.a(), "0o{}", .{lit_bytes}); |
| 5154 | lit_bytes = try std.fmtstream.allocPrint(c.a(), "0o{}", .{lit_bytes}); |
| 5160 | 5155 | }, |
| 5161 | 5156 | 'X' => { |
| 5162 | 5157 | // Hexadecimal with capital X, valid in C but not in Zig |
| 5163 | | lit_bytes = try std.fmt.allocPrint(c.a(), "0x{}", .{lit_bytes[2..]}); |
| 5158 | lit_bytes = try std.fmtstream.allocPrint(c.a(), "0x{}", .{lit_bytes[2..]}); |
| 5164 | 5159 | }, |
| 5165 | 5160 | else => {}, |
| 5166 | 5161 | } |
| ... | ... | @@ -5191,7 +5186,7 @@ fn parseCNumLit(c: *Context, tok: *CToken, source: []const u8, source_loc: ZigCl |
| 5191 | 5186 | return &cast_node.base; |
| 5192 | 5187 | } else if (tok.id == .FloatLiteral) { |
| 5193 | 5188 | if (lit_bytes[0] == '.') |
| 5194 | | lit_bytes = try std.fmt.allocPrint(c.a(), "0{}", .{lit_bytes}); |
| 5189 | lit_bytes = try std.fmtstream.allocPrint(c.a(), "0{}", .{lit_bytes}); |
| 5195 | 5190 | if (tok.id.FloatLiteral == .None) { |
| 5196 | 5191 | return transCreateNodeFloat(c, lit_bytes); |
| 5197 | 5192 | } |
| ... | ... | @@ -5324,7 +5319,7 @@ fn zigifyEscapeSequences(ctx: *Context, source_bytes: []const u8, name: []const |
| 5324 | 5319 | num += c - 'A' + 10; |
| 5325 | 5320 | }, |
| 5326 | 5321 | else => { |
| 5327 | | i += std.fmt.formatIntBuf(bytes[i..], num, 16, false, std.fmt.FormatOptions{ .fill = '0', .width = 2 }); |
| 5322 | i += std.fmtstream.formatIntBuf(bytes[i..], num, 16, false, std.fmtstream.FormatOptions{ .fill = '0', .width = 2 }); |
| 5328 | 5323 | num = 0; |
| 5329 | 5324 | if (c == '\\') |
| 5330 | 5325 | state = .Escape |
| ... | ... | @@ -5350,7 +5345,7 @@ fn zigifyEscapeSequences(ctx: *Context, source_bytes: []const u8, name: []const |
| 5350 | 5345 | }; |
| 5351 | 5346 | num += c - '0'; |
| 5352 | 5347 | } else { |
| 5353 | | i += std.fmt.formatIntBuf(bytes[i..], num, 16, false, std.fmt.FormatOptions{ .fill = '0', .width = 2 }); |
| 5348 | i += std.fmtstream.formatIntBuf(bytes[i..], num, 16, false, std.fmtstream.FormatOptions{ .fill = '0', .width = 2 }); |
| 5354 | 5349 | num = 0; |
| 5355 | 5350 | count = 0; |
| 5356 | 5351 | if (c == '\\') |
| ... | ... | @@ -5364,7 +5359,7 @@ fn zigifyEscapeSequences(ctx: *Context, source_bytes: []const u8, name: []const |
| 5364 | 5359 | } |
| 5365 | 5360 | } |
| 5366 | 5361 | if (state == .Hex or state == .Octal) |
| 5367 | | i += std.fmt.formatIntBuf(bytes[i..], num, 16, false, std.fmt.FormatOptions{ .fill = '0', .width = 2 }); |
| 5362 | i += std.fmtstream.formatIntBuf(bytes[i..], num, 16, false, std.fmtstream.FormatOptions{ .fill = '0', .width = 2 }); |
| 5368 | 5363 | return bytes[0..i]; |
| 5369 | 5364 | } |
| 5370 | 5365 | |