| author | |
| committer | |
| log | 5d7507214d5695842235cf0ad83849c5a2c97664 |
| tree | c3a95ca503e1dda902955447c4d7a757dd48b62b |
| parent | 2151b10a41aff2b81dbbadf8f823d21d7b80f43b |
9 files changed, 181 insertions(+), 103 deletions(-)
lib/compiler/aro/aro/Attribute.zig+1-1| ... | ... | @@ -780,7 +780,7 @@ fn ignoredAttrErr(p: *Parser, tok: TokenIndex, attr: Attribute.Tag, context: []c |
| 780 | 780 | const strings_top = p.strings.items.len; |
| 781 | 781 | defer p.strings.items.len = strings_top; |
| 782 | 782 | |
| 783 | try p.strings.writer().print("attribute '{s}' ignored on {s}", .{ @tagName(attr), context }); | |
| 783 | try p.strings.print("attribute '{s}' ignored on {s}", .{ @tagName(attr), context }); | |
| 784 | 784 | const str = try p.comp.diagnostics.arena.allocator().dupe(u8, p.strings.items[strings_top..]); |
| 785 | 785 | try p.errStr(.ignored_attribute, tok, str); |
| 786 | 786 | } |
lib/compiler/aro/aro/Builtins/Builtin.zig+2-3| ... | ... | @@ -119,8 +119,7 @@ pub fn nameFromUniqueIndex(index: u16, buf: []u8) []u8 { |
| 119 | 119 | |
| 120 | 120 | var node_index: u16 = 0; |
| 121 | 121 | var count: u16 = index; |
| 122 | var fbs = std.io.fixedBufferStream(buf); | |
| 123 | const w = fbs.writer(); | |
| 122 | var w: std.Io.Writer = .fixed(buf); | |
| 124 | 123 | |
| 125 | 124 | while (true) { |
| 126 | 125 | var sibling_index = dafsa[node_index].child_index; |
| ... | ... | @@ -142,7 +141,7 @@ pub fn nameFromUniqueIndex(index: u16, buf: []u8) []u8 { |
| 142 | 141 | if (count == 0) break; |
| 143 | 142 | } |
| 144 | 143 | |
| 145 | return fbs.getWritten(); | |
| 144 | return w.buffered(); | |
| 146 | 145 | } |
| 147 | 146 | |
| 148 | 147 | /// We're 1 bit shy of being able to fit this in a u32: |
lib/compiler/aro/aro/Compilation.zig+29-26| ... | ... | @@ -16,6 +16,7 @@ const Pragma = @import("Pragma.zig"); |
| 16 | 16 | const StrInt = @import("StringInterner.zig"); |
| 17 | 17 | const record_layout = @import("record_layout.zig"); |
| 18 | 18 | const target_util = @import("target.zig"); |
| 19 | const Writer = std.Io.Writer; | |
| 19 | 20 | |
| 20 | 21 | pub const Error = error{ |
| 21 | 22 | /// A fatal error has ocurred and compilation has stopped. |
| ... | ... | @@ -199,7 +200,7 @@ fn getTimestamp(comp: *Compilation) !u47 { |
| 199 | 200 | return @intCast(std.math.clamp(timestamp, 0, max_timestamp)); |
| 200 | 201 | } |
| 201 | 202 | |
| 202 | fn generateDateAndTime(w: anytype, timestamp: u47) !void { | |
| 203 | fn generateDateAndTime(w: *Writer, timestamp: u47) !void { | |
| 203 | 204 | const epoch_seconds = EpochSeconds{ .secs = timestamp }; |
| 204 | 205 | const epoch_day = epoch_seconds.getEpochDay(); |
| 205 | 206 | const day_seconds = epoch_seconds.getDaySeconds(); |
| ... | ... | @@ -242,7 +243,7 @@ pub const SystemDefinesMode = enum { |
| 242 | 243 | include_system_defines, |
| 243 | 244 | }; |
| 244 | 245 | |
| 245 | fn generateSystemDefines(comp: *Compilation, w: anytype) !void { | |
| 246 | fn generateSystemDefines(comp: *Compilation, w: *Writer) !void { | |
| 246 | 247 | const ptr_width = comp.target.ptrBitWidth(); |
| 247 | 248 | |
| 248 | 249 | if (comp.langopts.gnuc_version > 0) { |
| ... | ... | @@ -533,11 +534,13 @@ fn generateSystemDefines(comp: *Compilation, w: anytype) !void { |
| 533 | 534 | pub fn generateBuiltinMacros(comp: *Compilation, system_defines_mode: SystemDefinesMode) !Source { |
| 534 | 535 | try comp.generateBuiltinTypes(); |
| 535 | 536 | |
| 536 | var buf = std.array_list.Managed(u8).init(comp.gpa); | |
| 537 | defer buf.deinit(); | |
| 537 | var allocating: std.Io.Writer.Allocating = .init(comp.gpa); | |
| 538 | defer allocating.deinit(); | |
| 539 | ||
| 540 | const buf = &allocating.writer; | |
| 538 | 541 | |
| 539 | 542 | if (system_defines_mode == .include_system_defines) { |
| 540 | try buf.appendSlice( | |
| 543 | try buf.writeAll( | |
| 541 | 544 | \\#define __VERSION__ "Aro |
| 542 | 545 | ++ " " ++ @import("../backend.zig").version_str ++ "\"\n" ++ |
| 543 | 546 | \\#define __Aro__ |
| ... | ... | @@ -545,11 +548,11 @@ pub fn generateBuiltinMacros(comp: *Compilation, system_defines_mode: SystemDefi |
| 545 | 548 | ); |
| 546 | 549 | } |
| 547 | 550 | |
| 548 | try buf.appendSlice("#define __STDC__ 1\n"); | |
| 551 | try buf.writeAll("#define __STDC__ 1\n"); | |
| 549 | 552 | try buf.print("#define __STDC_HOSTED__ {d}\n", .{@intFromBool(comp.target.os.tag != .freestanding)}); |
| 550 | 553 | |
| 551 | 554 | // standard macros |
| 552 | try buf.appendSlice( | |
| 555 | try buf.writeAll( | |
| 553 | 556 | \\#define __STDC_NO_COMPLEX__ 1 |
| 554 | 557 | \\#define __STDC_NO_THREADS__ 1 |
| 555 | 558 | \\#define __STDC_NO_VLA__ 1 |
| ... | ... | @@ -561,23 +564,23 @@ pub fn generateBuiltinMacros(comp: *Compilation, system_defines_mode: SystemDefi |
| 561 | 564 | \\ |
| 562 | 565 | ); |
| 563 | 566 | if (comp.langopts.standard.StdCVersionMacro()) |stdc_version| { |
| 564 | try buf.appendSlice("#define __STDC_VERSION__ "); | |
| 565 | try buf.appendSlice(stdc_version); | |
| 566 | try buf.append('\n'); | |
| 567 | try buf.writeAll("#define __STDC_VERSION__ "); | |
| 568 | try buf.writeAll(stdc_version); | |
| 569 | try buf.writeByte('\n'); | |
| 567 | 570 | } |
| 568 | 571 | |
| 569 | 572 | // timestamps |
| 570 | 573 | const timestamp = try comp.getTimestamp(); |
| 571 | try generateDateAndTime(buf.writer(), timestamp); | |
| 574 | try generateDateAndTime(buf, timestamp); | |
| 572 | 575 | |
| 573 | 576 | if (system_defines_mode == .include_system_defines) { |
| 574 | try comp.generateSystemDefines(buf.writer()); | |
| 577 | try comp.generateSystemDefines(buf); | |
| 575 | 578 | } |
| 576 | 579 | |
| 577 | return comp.addSourceFromBuffer("<builtin>", buf.items); | |
| 580 | return comp.addSourceFromBuffer("<builtin>", allocating.written()); | |
| 578 | 581 | } |
| 579 | 582 | |
| 580 | fn generateFloatMacros(w: anytype, prefix: []const u8, semantics: target_util.FPSemantics, ext: []const u8) !void { | |
| 583 | fn generateFloatMacros(w: *Writer, prefix: []const u8, semantics: target_util.FPSemantics, ext: []const u8) !void { | |
| 581 | 584 | const denormMin = semantics.chooseValue( |
| 582 | 585 | []const u8, |
| 583 | 586 | .{ |
| ... | ... | @@ -656,7 +659,7 @@ fn generateFloatMacros(w: anytype, prefix: []const u8, semantics: target_util.FP |
| 656 | 659 | try w.print("#define {s}MIN__ {s}{s}\n", .{ prefix_slice, min, ext }); |
| 657 | 660 | } |
| 658 | 661 | |
| 659 | fn generateTypeMacro(w: anytype, mapper: StrInt.TypeMapper, name: []const u8, ty: Type, langopts: LangOpts) !void { | |
| 662 | fn generateTypeMacro(w: *Writer, mapper: StrInt.TypeMapper, name: []const u8, ty: Type, langopts: LangOpts) !void { | |
| 660 | 663 | try w.print("#define {s} ", .{name}); |
| 661 | 664 | try ty.print(mapper, langopts, w); |
| 662 | 665 | try w.writeByte('\n'); |
| ... | ... | @@ -762,7 +765,7 @@ fn generateFastOrLeastType( |
| 762 | 765 | bits: usize, |
| 763 | 766 | kind: enum { least, fast }, |
| 764 | 767 | signedness: std.builtin.Signedness, |
| 765 | w: anytype, | |
| 768 | w: *Writer, | |
| 766 | 769 | mapper: StrInt.TypeMapper, |
| 767 | 770 | ) !void { |
| 768 | 771 | const ty = comp.intLeastN(bits, signedness); // defining the fast types as the least types is permitted |
| ... | ... | @@ -793,7 +796,7 @@ fn generateFastOrLeastType( |
| 793 | 796 | try comp.generateFmt(prefix, w, ty); |
| 794 | 797 | } |
| 795 | 798 | |
| 796 | fn generateFastAndLeastWidthTypes(comp: *Compilation, w: anytype, mapper: StrInt.TypeMapper) !void { | |
| 799 | fn generateFastAndLeastWidthTypes(comp: *Compilation, w: *Writer, mapper: StrInt.TypeMapper) !void { | |
| 797 | 800 | const sizes = [_]usize{ 8, 16, 32, 64 }; |
| 798 | 801 | for (sizes) |size| { |
| 799 | 802 | try comp.generateFastOrLeastType(size, .least, .signed, w, mapper); |
| ... | ... | @@ -803,7 +806,7 @@ fn generateFastAndLeastWidthTypes(comp: *Compilation, w: anytype, mapper: StrInt |
| 803 | 806 | } |
| 804 | 807 | } |
| 805 | 808 | |
| 806 | fn generateExactWidthTypes(comp: *const Compilation, w: anytype, mapper: StrInt.TypeMapper) !void { | |
| 809 | fn generateExactWidthTypes(comp: *const Compilation, w: *Writer, mapper: StrInt.TypeMapper) !void { | |
| 807 | 810 | try comp.generateExactWidthType(w, mapper, .schar); |
| 808 | 811 | |
| 809 | 812 | if (comp.intSize(.short) > comp.intSize(.char)) { |
| ... | ... | @@ -851,7 +854,7 @@ fn generateExactWidthTypes(comp: *const Compilation, w: anytype, mapper: StrInt. |
| 851 | 854 | } |
| 852 | 855 | } |
| 853 | 856 | |
| 854 | fn generateFmt(comp: *const Compilation, prefix: []const u8, w: anytype, ty: Type) !void { | |
| 857 | fn generateFmt(comp: *const Compilation, prefix: []const u8, w: *Writer, ty: Type) !void { | |
| 855 | 858 | const unsigned = ty.isUnsignedInt(comp); |
| 856 | 859 | const modifier = ty.formatModifier(); |
| 857 | 860 | const formats = if (unsigned) "ouxX" else "di"; |
| ... | ... | @@ -860,7 +863,7 @@ fn generateFmt(comp: *const Compilation, prefix: []const u8, w: anytype, ty: Typ |
| 860 | 863 | } |
| 861 | 864 | } |
| 862 | 865 | |
| 863 | fn generateSuffixMacro(comp: *const Compilation, prefix: []const u8, w: anytype, ty: Type) !void { | |
| 866 | fn generateSuffixMacro(comp: *const Compilation, prefix: []const u8, w: *Writer, ty: Type) !void { | |
| 864 | 867 | return w.print("#define {s}_C_SUFFIX__ {s}\n", .{ prefix, ty.intValueSuffix(comp) }); |
| 865 | 868 | } |
| 866 | 869 | |
| ... | ... | @@ -868,7 +871,7 @@ fn generateSuffixMacro(comp: *const Compilation, prefix: []const u8, w: anytype, |
| 868 | 871 | /// Name macro (e.g. #define __UINT32_TYPE__ unsigned int) |
| 869 | 872 | /// Format strings (e.g. #define __UINT32_FMTu__ "u") |
| 870 | 873 | /// Suffix macro (e.g. #define __UINT32_C_SUFFIX__ U) |
| 871 | fn generateExactWidthType(comp: *const Compilation, w: anytype, mapper: StrInt.TypeMapper, specifier: Type.Specifier) !void { | |
| 874 | fn generateExactWidthType(comp: *const Compilation, w: *Writer, mapper: StrInt.TypeMapper, specifier: Type.Specifier) !void { | |
| 872 | 875 | var ty = Type{ .specifier = specifier }; |
| 873 | 876 | const width = 8 * ty.sizeof(comp).?; |
| 874 | 877 | const unsigned = ty.isUnsignedInt(comp); |
| ... | ... | @@ -998,7 +1001,7 @@ fn generateVaListType(comp: *Compilation) !Type { |
| 998 | 1001 | return ty; |
| 999 | 1002 | } |
| 1000 | 1003 | |
| 1001 | fn generateIntMax(comp: *const Compilation, w: anytype, name: []const u8, ty: Type) !void { | |
| 1004 | fn generateIntMax(comp: *const Compilation, w: *Writer, name: []const u8, ty: Type) !void { | |
| 1002 | 1005 | const bit_count: u8 = @intCast(ty.sizeof(comp).? * 8); |
| 1003 | 1006 | const unsigned = ty.isUnsignedInt(comp); |
| 1004 | 1007 | const max: u128 = switch (bit_count) { |
| ... | ... | @@ -1023,7 +1026,7 @@ pub fn wcharMax(comp: *const Compilation) u32 { |
| 1023 | 1026 | }; |
| 1024 | 1027 | } |
| 1025 | 1028 | |
| 1026 | fn generateExactWidthIntMax(comp: *const Compilation, w: anytype, specifier: Type.Specifier) !void { | |
| 1029 | fn generateExactWidthIntMax(comp: *const Compilation, w: *Writer, specifier: Type.Specifier) !void { | |
| 1027 | 1030 | var ty = Type{ .specifier = specifier }; |
| 1028 | 1031 | const bit_count: u8 = @intCast(ty.sizeof(comp).? * 8); |
| 1029 | 1032 | const unsigned = ty.isUnsignedInt(comp); |
| ... | ... | @@ -1040,16 +1043,16 @@ fn generateExactWidthIntMax(comp: *const Compilation, w: anytype, specifier: Typ |
| 1040 | 1043 | return comp.generateIntMax(w, name, ty); |
| 1041 | 1044 | } |
| 1042 | 1045 | |
| 1043 | fn generateIntWidth(comp: *Compilation, w: anytype, name: []const u8, ty: Type) !void { | |
| 1046 | fn generateIntWidth(comp: *Compilation, w: *Writer, name: []const u8, ty: Type) !void { | |
| 1044 | 1047 | try w.print("#define __{s}_WIDTH__ {d}\n", .{ name, 8 * ty.sizeof(comp).? }); |
| 1045 | 1048 | } |
| 1046 | 1049 | |
| 1047 | fn generateIntMaxAndWidth(comp: *Compilation, w: anytype, name: []const u8, ty: Type) !void { | |
| 1050 | fn generateIntMaxAndWidth(comp: *Compilation, w: *Writer, name: []const u8, ty: Type) !void { | |
| 1048 | 1051 | try comp.generateIntMax(w, name, ty); |
| 1049 | 1052 | try comp.generateIntWidth(w, name, ty); |
| 1050 | 1053 | } |
| 1051 | 1054 | |
| 1052 | fn generateSizeofType(comp: *Compilation, w: anytype, name: []const u8, ty: Type) !void { | |
| 1055 | fn generateSizeofType(comp: *Compilation, w: *Writer, name: []const u8, ty: Type) !void { | |
| 1053 | 1056 | try w.print("#define {s} {d}\n", .{ name, ty.sizeof(comp).? }); |
| 1054 | 1057 | } |
| 1055 | 1058 |
lib/compiler/aro/aro/Parser.zig+120-44| ... | ... | @@ -101,7 +101,7 @@ value_map: Tree.ValueMap, |
| 101 | 101 | |
| 102 | 102 | // buffers used during compilation |
| 103 | 103 | syms: SymbolStack = .{}, |
| 104 | strings: std.array_list.AlignedManaged(u8, .@"4"), | |
| 104 | strings: std.array_list.Managed(u8), | |
| 105 | 105 | labels: std.array_list.Managed(Label), |
| 106 | 106 | list_buf: NodeList, |
| 107 | 107 | decl_buf: NodeList, |
| ... | ... | @@ -447,7 +447,17 @@ pub fn typeStr(p: *Parser, ty: Type) ![]const u8 { |
| 447 | 447 | defer p.strings.items.len = strings_top; |
| 448 | 448 | |
| 449 | 449 | const mapper = p.comp.string_interner.getSlowTypeMapper(); |
| 450 | try ty.print(mapper, p.comp.langopts, p.strings.writer()); | |
| 450 | { | |
| 451 | var unmanaged = p.strings.moveToUnmanaged(); | |
| 452 | var allocating: std.Io.Writer.Allocating = .fromArrayList(p.comp.gpa, &unmanaged); | |
| 453 | defer { | |
| 454 | unmanaged = allocating.toArrayList(); | |
| 455 | p.strings = unmanaged.toManaged(p.comp.gpa); | |
| 456 | } | |
| 457 | ty.print(mapper, p.comp.langopts, &allocating.writer) catch |e| switch (e) { | |
| 458 | error.WriteFailed => return error.OutOfMemory, | |
| 459 | }; | |
| 460 | } | |
| 451 | 461 | return try p.comp.diagnostics.arena.allocator().dupe(u8, p.strings.items[strings_top..]); |
| 452 | 462 | } |
| 453 | 463 | |
| ... | ... | @@ -455,7 +465,7 @@ pub fn typePairStr(p: *Parser, a: Type, b: Type) ![]const u8 { |
| 455 | 465 | return p.typePairStrExtra(a, " and ", b); |
| 456 | 466 | } |
| 457 | 467 | |
| 458 | pub fn typePairStrExtra(p: *Parser, a: Type, msg: []const u8, b: Type) ![]const u8 { | |
| 468 | pub fn typePairStrExtra(p: *Parser, a: Type, msg: []const u8, b: Type) Error![]const u8 { | |
| 459 | 469 | if (@import("builtin").mode != .Debug) { |
| 460 | 470 | if (a.is(.invalid) or b.is(.invalid)) { |
| 461 | 471 | return "Tried to render invalid type - this is an aro bug."; |
| ... | ... | @@ -466,29 +476,60 @@ pub fn typePairStrExtra(p: *Parser, a: Type, msg: []const u8, b: Type) ![]const |
| 466 | 476 | |
| 467 | 477 | try p.strings.append('\''); |
| 468 | 478 | const mapper = p.comp.string_interner.getSlowTypeMapper(); |
| 469 | try a.print(mapper, p.comp.langopts, p.strings.writer()); | |
| 479 | { | |
| 480 | var unmanaged = p.strings.moveToUnmanaged(); | |
| 481 | var allocating: std.Io.Writer.Allocating = .fromArrayList(p.comp.gpa, &unmanaged); | |
| 482 | defer { | |
| 483 | unmanaged = allocating.toArrayList(); | |
| 484 | p.strings = unmanaged.toManaged(p.comp.gpa); | |
| 485 | } | |
| 486 | a.print(mapper, p.comp.langopts, &allocating.writer) catch |e| switch (e) { | |
| 487 | error.WriteFailed => return error.OutOfMemory, | |
| 488 | }; | |
| 489 | } | |
| 470 | 490 | try p.strings.append('\''); |
| 471 | 491 | try p.strings.appendSlice(msg); |
| 472 | 492 | try p.strings.append('\''); |
| 473 | try b.print(mapper, p.comp.langopts, p.strings.writer()); | |
| 493 | { | |
| 494 | var unmanaged = p.strings.moveToUnmanaged(); | |
| 495 | var allocating: std.Io.Writer.Allocating = .fromArrayList(p.comp.gpa, &unmanaged); | |
| 496 | defer { | |
| 497 | unmanaged = allocating.toArrayList(); | |
| 498 | p.strings = unmanaged.toManaged(p.comp.gpa); | |
| 499 | } | |
| 500 | b.print(mapper, p.comp.langopts, &allocating.writer) catch |e| switch (e) { | |
| 501 | error.WriteFailed => return error.OutOfMemory, | |
| 502 | }; | |
| 503 | } | |
| 474 | 504 | try p.strings.append('\''); |
| 475 | 505 | return try p.comp.diagnostics.arena.allocator().dupe(u8, p.strings.items[strings_top..]); |
| 476 | 506 | } |
| 477 | 507 | |
| 478 | pub fn valueChangedStr(p: *Parser, res: *Result, old_value: Value, int_ty: Type) ![]const u8 { | |
| 508 | pub fn valueChangedStr(p: *Parser, res: *Result, old_value: Value, int_ty: Type) Error![]const u8 { | |
| 479 | 509 | const strings_top = p.strings.items.len; |
| 480 | 510 | defer p.strings.items.len = strings_top; |
| 481 | 511 | |
| 482 | var w = p.strings.writer(); | |
| 483 | 512 | const type_pair_str = try p.typePairStrExtra(res.ty, " to ", int_ty); |
| 484 | try w.writeAll(type_pair_str); | |
| 513 | { | |
| 514 | var unmanaged = p.strings.moveToUnmanaged(); | |
| 515 | var allocating: std.Io.Writer.Allocating = .fromArrayList(p.comp.gpa, &unmanaged); | |
| 516 | defer { | |
| 517 | unmanaged = allocating.toArrayList(); | |
| 518 | p.strings = unmanaged.toManaged(p.comp.gpa); | |
| 519 | } | |
| 520 | allocating.writer.writeAll(type_pair_str) catch return error.OutOfMemory; | |
| 485 | 521 | |
| 486 | try w.writeAll(" changes "); | |
| 487 | if (res.val.isZero(p.comp)) try w.writeAll("non-zero "); | |
| 488 | try w.writeAll("value from "); | |
| 489 | try old_value.print(res.ty, p.comp, w); | |
| 490 | try w.writeAll(" to "); | |
| 491 | try res.val.print(int_ty, p.comp, w); | |
| 522 | allocating.writer.writeAll(" changes ") catch return error.OutOfMemory; | |
| 523 | if (res.val.isZero(p.comp)) allocating.writer.writeAll("non-zero ") catch return error.OutOfMemory; | |
| 524 | allocating.writer.writeAll("value from ") catch return error.OutOfMemory; | |
| 525 | old_value.print(res.ty, p.comp, &allocating.writer) catch |e| switch (e) { | |
| 526 | error.WriteFailed => return error.OutOfMemory, | |
| 527 | }; | |
| 528 | allocating.writer.writeAll(" to ") catch return error.OutOfMemory; | |
| 529 | res.val.print(int_ty, p.comp, &allocating.writer) catch |e| switch (e) { | |
| 530 | error.WriteFailed => return error.OutOfMemory, | |
| 531 | }; | |
| 532 | } | |
| 492 | 533 | |
| 493 | 534 | return try p.comp.diagnostics.arena.allocator().dupe(u8, p.strings.items[strings_top..]); |
| 494 | 535 | } |
| ... | ... | @@ -498,9 +539,8 @@ fn checkDeprecatedUnavailable(p: *Parser, ty: Type, usage_tok: TokenIndex, decl_ |
| 498 | 539 | const strings_top = p.strings.items.len; |
| 499 | 540 | defer p.strings.items.len = strings_top; |
| 500 | 541 | |
| 501 | const w = p.strings.writer(); | |
| 502 | 542 | const msg_str = p.comp.interner.get(@"error".msg.ref()).bytes; |
| 503 | try w.print("call to '{s}' declared with attribute error: {f}", .{ | |
| 543 | try p.strings.print("call to '{s}' declared with attribute error: {f}", .{ | |
| 504 | 544 | p.tokSlice(@"error".__name_tok), std.zig.fmtString(msg_str), |
| 505 | 545 | }); |
| 506 | 546 | const str = try p.comp.diagnostics.arena.allocator().dupe(u8, p.strings.items[strings_top..]); |
| ... | ... | @@ -510,9 +550,8 @@ fn checkDeprecatedUnavailable(p: *Parser, ty: Type, usage_tok: TokenIndex, decl_ |
| 510 | 550 | const strings_top = p.strings.items.len; |
| 511 | 551 | defer p.strings.items.len = strings_top; |
| 512 | 552 | |
| 513 | const w = p.strings.writer(); | |
| 514 | 553 | const msg_str = p.comp.interner.get(warning.msg.ref()).bytes; |
| 515 | try w.print("call to '{s}' declared with attribute warning: {f}", .{ | |
| 554 | try p.strings.print("call to '{s}' declared with attribute warning: {f}", .{ | |
| 516 | 555 | p.tokSlice(warning.__name_tok), std.zig.fmtString(msg_str), |
| 517 | 556 | }); |
| 518 | 557 | const str = try p.comp.diagnostics.arena.allocator().dupe(u8, p.strings.items[strings_top..]); |
| ... | ... | @@ -532,17 +571,16 @@ fn errDeprecated(p: *Parser, tag: Diagnostics.Tag, tok_i: TokenIndex, msg: ?Valu |
| 532 | 571 | const strings_top = p.strings.items.len; |
| 533 | 572 | defer p.strings.items.len = strings_top; |
| 534 | 573 | |
| 535 | const w = p.strings.writer(); | |
| 536 | try w.print("'{s}' is ", .{p.tokSlice(tok_i)}); | |
| 574 | try p.strings.print("'{s}' is ", .{p.tokSlice(tok_i)}); | |
| 537 | 575 | const reason: []const u8 = switch (tag) { |
| 538 | 576 | .unavailable => "unavailable", |
| 539 | 577 | .deprecated_declarations => "deprecated", |
| 540 | 578 | else => unreachable, |
| 541 | 579 | }; |
| 542 | try w.writeAll(reason); | |
| 580 | try p.strings.appendSlice(reason); | |
| 543 | 581 | if (msg) |m| { |
| 544 | 582 | const str = p.comp.interner.get(m.ref()).bytes; |
| 545 | try w.print(": {f}", .{std.zig.fmtString(str)}); | |
| 583 | try p.strings.print(": {f}", .{std.zig.fmtString(str)}); | |
| 546 | 584 | } |
| 547 | 585 | const str = try p.comp.diagnostics.arena.allocator().dupe(u8, p.strings.items[strings_top..]); |
| 548 | 586 | return p.errStr(tag, tok_i, str); |
| ... | ... | @@ -693,7 +731,7 @@ pub fn parse(pp: *Preprocessor) Compilation.Error!Tree { |
| 693 | 731 | .gpa = pp.comp.gpa, |
| 694 | 732 | .arena = arena.allocator(), |
| 695 | 733 | .tok_ids = pp.tokens.items(.id), |
| 696 | .strings = std.array_list.AlignedManaged(u8, .@"4").init(pp.comp.gpa), | |
| 734 | .strings = std.array_list.Managed(u8).init(pp.comp.gpa), | |
| 697 | 735 | .value_map = Tree.ValueMap.init(pp.comp.gpa), |
| 698 | 736 | .data = NodeList.init(pp.comp.gpa), |
| 699 | 737 | .labels = std.array_list.Managed(Label).init(pp.comp.gpa), |
| ... | ... | @@ -1218,38 +1256,46 @@ fn decl(p: *Parser) Error!bool { |
| 1218 | 1256 | return true; |
| 1219 | 1257 | } |
| 1220 | 1258 | |
| 1221 | fn staticAssertMessage(p: *Parser, cond_node: NodeIndex, message: Result) !?[]const u8 { | |
| 1259 | fn staticAssertMessage(p: *Parser, cond_node: NodeIndex, message: Result) Error!?[]const u8 { | |
| 1222 | 1260 | const cond_tag = p.nodes.items(.tag)[@intFromEnum(cond_node)]; |
| 1223 | 1261 | if (cond_tag != .builtin_types_compatible_p and message.node == .none) return null; |
| 1224 | 1262 | |
| 1225 | var buf = std.array_list.Managed(u8).init(p.gpa); | |
| 1226 | defer buf.deinit(); | |
| 1263 | var allocating: std.Io.Writer.Allocating = .init(p.gpa); | |
| 1264 | defer allocating.deinit(); | |
| 1265 | ||
| 1266 | const buf = &allocating.writer; | |
| 1227 | 1267 | |
| 1228 | 1268 | if (cond_tag == .builtin_types_compatible_p) { |
| 1229 | 1269 | const mapper = p.comp.string_interner.getSlowTypeMapper(); |
| 1230 | 1270 | const data = p.nodes.items(.data)[@intFromEnum(cond_node)].bin; |
| 1231 | 1271 | |
| 1232 | try buf.appendSlice("'__builtin_types_compatible_p("); | |
| 1272 | buf.writeAll("'__builtin_types_compatible_p(") catch return error.OutOfMemory; | |
| 1233 | 1273 | |
| 1234 | 1274 | const lhs_ty = p.nodes.items(.ty)[@intFromEnum(data.lhs)]; |
| 1235 | try lhs_ty.print(mapper, p.comp.langopts, buf.writer()); | |
| 1236 | try buf.appendSlice(", "); | |
| 1275 | lhs_ty.print(mapper, p.comp.langopts, buf) catch |e| switch (e) { | |
| 1276 | error.WriteFailed => return error.OutOfMemory, | |
| 1277 | }; | |
| 1278 | buf.writeAll(", ") catch return error.OutOfMemory; | |
| 1237 | 1279 | |
| 1238 | 1280 | const rhs_ty = p.nodes.items(.ty)[@intFromEnum(data.rhs)]; |
| 1239 | try rhs_ty.print(mapper, p.comp.langopts, buf.writer()); | |
| 1281 | rhs_ty.print(mapper, p.comp.langopts, buf) catch |e| switch (e) { | |
| 1282 | error.WriteFailed => return error.OutOfMemory, | |
| 1283 | }; | |
| 1240 | 1284 | |
| 1241 | try buf.appendSlice(")'"); | |
| 1285 | buf.writeAll(")'") catch return error.OutOfMemory; | |
| 1242 | 1286 | } |
| 1243 | 1287 | if (message.node != .none) { |
| 1244 | 1288 | assert(p.nodes.items(.tag)[@intFromEnum(message.node)] == .string_literal_expr); |
| 1245 | if (buf.items.len > 0) { | |
| 1246 | try buf.append(' '); | |
| 1289 | if (buf.buffered().len > 0) { | |
| 1290 | buf.writeByte(' ') catch return error.OutOfMemory; | |
| 1247 | 1291 | } |
| 1248 | 1292 | const bytes = p.comp.interner.get(message.val.ref()).bytes; |
| 1249 | try buf.ensureUnusedCapacity(bytes.len); | |
| 1250 | try Value.printString(bytes, message.ty, p.comp, buf.writer()); | |
| 1293 | try allocating.ensureUnusedCapacity(bytes.len); | |
| 1294 | Value.printString(bytes, message.ty, p.comp, buf) catch |e| switch (e) { | |
| 1295 | error.WriteFailed => return error.OutOfMemory, | |
| 1296 | }; | |
| 1251 | 1297 | } |
| 1252 | return try p.comp.diagnostics.arena.allocator().dupe(u8, buf.items); | |
| 1298 | return try p.comp.diagnostics.arena.allocator().dupe(u8, allocating.written()); | |
| 1253 | 1299 | } |
| 1254 | 1300 | |
| 1255 | 1301 | /// staticAssert |
| ... | ... | @@ -4981,7 +5027,7 @@ const CallExpr = union(enum) { |
| 4981 | 5027 | return true; |
| 4982 | 5028 | } |
| 4983 | 5029 | |
| 4984 | fn checkVarArg(self: CallExpr, p: *Parser, first_after: TokenIndex, param_tok: TokenIndex, arg: *Result, arg_idx: u32) !void { | |
| 5030 | fn checkVarArg(self: CallExpr, p: *Parser, first_after: TokenIndex, param_tok: TokenIndex, arg: *Result, arg_idx: u32) Error!void { | |
| 4985 | 5031 | if (self == .standard) return; |
| 4986 | 5032 | |
| 4987 | 5033 | const builtin_tok = p.nodes.items(.data)[@intFromEnum(self.builtin.node)].decl.name; |
| ... | ... | @@ -5183,7 +5229,17 @@ pub const Result = struct { |
| 5183 | 5229 | const strings_top = p.strings.items.len; |
| 5184 | 5230 | defer p.strings.items.len = strings_top; |
| 5185 | 5231 | |
| 5186 | try res.val.print(res.ty, p.comp, p.strings.writer()); | |
| 5232 | { | |
| 5233 | var unmanaged = p.strings.moveToUnmanaged(); | |
| 5234 | var allocating: std.Io.Writer.Allocating = .fromArrayList(p.comp.gpa, &unmanaged); | |
| 5235 | defer { | |
| 5236 | unmanaged = allocating.toArrayList(); | |
| 5237 | p.strings = unmanaged.toManaged(p.comp.gpa); | |
| 5238 | } | |
| 5239 | res.val.print(res.ty, p.comp, &allocating.writer) catch |e| switch (e) { | |
| 5240 | error.WriteFailed => return error.OutOfMemory, | |
| 5241 | }; | |
| 5242 | } | |
| 5187 | 5243 | return try p.comp.diagnostics.arena.allocator().dupe(u8, p.strings.items[strings_top..]); |
| 5188 | 5244 | } |
| 5189 | 5245 | |
| ... | ... | @@ -5347,7 +5403,7 @@ pub const Result = struct { |
| 5347 | 5403 | conditional, |
| 5348 | 5404 | add, |
| 5349 | 5405 | sub, |
| 5350 | }) !bool { | |
| 5406 | }) Error!bool { | |
| 5351 | 5407 | if (b.ty.specifier == .invalid) { |
| 5352 | 5408 | try a.saveValue(p); |
| 5353 | 5409 | a.ty = Type.invalid; |
| ... | ... | @@ -5643,7 +5699,7 @@ pub const Result = struct { |
| 5643 | 5699 | } |
| 5644 | 5700 | } |
| 5645 | 5701 | |
| 5646 | fn floatToIntWarning(res: *Result, p: *Parser, int_ty: Type, old_value: Value, change_kind: Value.FloatToIntChangeKind, tok: TokenIndex) !void { | |
| 5702 | fn floatToIntWarning(res: *Result, p: *Parser, int_ty: Type, old_value: Value, change_kind: Value.FloatToIntChangeKind, tok: TokenIndex) Error!void { | |
| 5647 | 5703 | switch (change_kind) { |
| 5648 | 5704 | .none => return p.errStr(.float_to_int, tok, try p.typePairStrExtra(res.ty, " to ", int_ty)), |
| 5649 | 5705 | .out_of_range => return p.errStr(.float_out_of_range, tok, try p.typePairStrExtra(res.ty, " to ", int_ty)), |
| ... | ... | @@ -5866,7 +5922,7 @@ pub const Result = struct { |
| 5866 | 5922 | res.val = .{}; |
| 5867 | 5923 | } |
| 5868 | 5924 | |
| 5869 | fn castType(res: *Result, p: *Parser, to: Type, operand_tok: TokenIndex, l_paren: TokenIndex) !void { | |
| 5925 | fn castType(res: *Result, p: *Parser, to: Type, operand_tok: TokenIndex, l_paren: TokenIndex) Error!void { | |
| 5870 | 5926 | var cast_kind: Tree.CastKind = undefined; |
| 5871 | 5927 | |
| 5872 | 5928 | if (to.is(.void)) { |
| ... | ... | @@ -7595,9 +7651,19 @@ fn validateFieldAccess(p: *Parser, record_ty: *const Type.Record, expr_ty: Type, |
| 7595 | 7651 | |
| 7596 | 7652 | p.strings.items.len = 0; |
| 7597 | 7653 | |
| 7598 | try p.strings.writer().print("'{s}' in '", .{p.tokSlice(field_name_tok)}); | |
| 7654 | try p.strings.print("'{s}' in '", .{p.tokSlice(field_name_tok)}); | |
| 7599 | 7655 | const mapper = p.comp.string_interner.getSlowTypeMapper(); |
| 7600 | try expr_ty.print(mapper, p.comp.langopts, p.strings.writer()); | |
| 7656 | { | |
| 7657 | var unmanaged = p.strings.moveToUnmanaged(); | |
| 7658 | var allocating: std.Io.Writer.Allocating = .fromArrayList(p.comp.gpa, &unmanaged); | |
| 7659 | defer { | |
| 7660 | unmanaged = allocating.toArrayList(); | |
| 7661 | p.strings = unmanaged.toManaged(p.comp.gpa); | |
| 7662 | } | |
| 7663 | expr_ty.print(mapper, p.comp.langopts, &allocating.writer) catch |e| switch (e) { | |
| 7664 | error.WriteFailed => return error.OutOfMemory, | |
| 7665 | }; | |
| 7666 | } | |
| 7601 | 7667 | try p.strings.append('\''); |
| 7602 | 7668 | |
| 7603 | 7669 | const duped = try p.comp.diagnostics.arena.allocator().dupe(u8, p.strings.items); |
| ... | ... | @@ -8016,7 +8082,17 @@ fn primaryExpr(p: *Parser) Error!Result { |
| 8016 | 8082 | defer p.strings.items.len = strings_top; |
| 8017 | 8083 | |
| 8018 | 8084 | const mapper = p.comp.string_interner.getSlowTypeMapper(); |
| 8019 | try Type.printNamed(func_ty, p.tokSlice(p.func.name), mapper, p.comp.langopts, p.strings.writer()); | |
| 8085 | { | |
| 8086 | var unmanaged = p.strings.moveToUnmanaged(); | |
| 8087 | var allocating: std.Io.Writer.Allocating = .fromArrayList(p.comp.gpa, &unmanaged); | |
| 8088 | defer { | |
| 8089 | unmanaged = allocating.toArrayList(); | |
| 8090 | p.strings = unmanaged.toManaged(p.comp.gpa); | |
| 8091 | } | |
| 8092 | Type.printNamed(func_ty, p.tokSlice(p.func.name), mapper, p.comp.langopts, &allocating.writer) catch |e| switch (e) { | |
| 8093 | error.WriteFailed => return error.OutOfMemory, | |
| 8094 | }; | |
| 8095 | } | |
| 8020 | 8096 | try p.strings.append(0); |
| 8021 | 8097 | const predef = try p.makePredefinedIdentifier(strings_top); |
| 8022 | 8098 | ty = predef.ty; |
lib/compiler/aro/aro/Preprocessor.zig+12-17| ... | ... | @@ -15,6 +15,7 @@ const TokenWithExpansionLocs = Tree.TokenWithExpansionLocs; |
| 15 | 15 | const Attribute = @import("Attribute.zig"); |
| 16 | 16 | const features = @import("features.zig"); |
| 17 | 17 | const Hideset = @import("Hideset.zig"); |
| 18 | const Writer = std.Io.Writer; | |
| 18 | 19 | |
| 19 | 20 | const DefineMap = std.StringHashMapUnmanaged(Macro); |
| 20 | 21 | const RawTokenList = std.array_list.Managed(RawToken); |
| ... | ... | @@ -982,7 +983,7 @@ fn expr(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!bool { |
| 982 | 983 | .tok_i = @intCast(token_state.tokens_len), |
| 983 | 984 | .arena = pp.arena.allocator(), |
| 984 | 985 | .in_macro = true, |
| 985 | .strings = std.array_list.AlignedManaged(u8, .@"4").init(pp.comp.gpa), | |
| 986 | .strings = std.array_list.Managed(u8).init(pp.comp.gpa), | |
| 986 | 987 | |
| 987 | 988 | .data = undefined, |
| 988 | 989 | .value_map = undefined, |
| ... | ... | @@ -1193,24 +1194,21 @@ fn expandObjMacro(pp: *Preprocessor, simple_macro: *const Macro) Error!ExpandBuf |
| 1193 | 1194 | .macro_file => { |
| 1194 | 1195 | const start = pp.comp.generated_buf.items.len; |
| 1195 | 1196 | const source = pp.comp.getSource(pp.expansion_source_loc.id); |
| 1196 | const w = pp.comp.generated_buf.writer(pp.gpa); | |
| 1197 | try w.print("\"{s}\"\n", .{source.path}); | |
| 1197 | try pp.comp.generated_buf.print(pp.gpa, "\"{s}\"\n", .{source.path}); | |
| 1198 | 1198 | |
| 1199 | 1199 | buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .string_literal, tok)); |
| 1200 | 1200 | }, |
| 1201 | 1201 | .macro_line => { |
| 1202 | 1202 | const start = pp.comp.generated_buf.items.len; |
| 1203 | 1203 | const source = pp.comp.getSource(pp.expansion_source_loc.id); |
| 1204 | const w = pp.comp.generated_buf.writer(pp.gpa); | |
| 1205 | try w.print("{d}\n", .{source.physicalLine(pp.expansion_source_loc)}); | |
| 1204 | try pp.comp.generated_buf.print(pp.gpa, "{d}\n", .{source.physicalLine(pp.expansion_source_loc)}); | |
| 1206 | 1205 | |
| 1207 | 1206 | buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .pp_num, tok)); |
| 1208 | 1207 | }, |
| 1209 | 1208 | .macro_counter => { |
| 1210 | 1209 | defer pp.counter += 1; |
| 1211 | 1210 | const start = pp.comp.generated_buf.items.len; |
| 1212 | const w = pp.comp.generated_buf.writer(pp.gpa); | |
| 1213 | try w.print("{d}\n", .{pp.counter}); | |
| 1211 | try pp.comp.generated_buf.print(pp.gpa, "{d}\n", .{pp.counter}); | |
| 1214 | 1212 | |
| 1215 | 1213 | buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .pp_num, tok)); |
| 1216 | 1214 | }, |
| ... | ... | @@ -1682,8 +1680,7 @@ fn expandFuncMacro( |
| 1682 | 1680 | break :blk false; |
| 1683 | 1681 | } else try pp.handleBuiltinMacro(raw.id, arg, macro_tok.loc); |
| 1684 | 1682 | const start = pp.comp.generated_buf.items.len; |
| 1685 | const w = pp.comp.generated_buf.writer(pp.gpa); | |
| 1686 | try w.print("{}\n", .{@intFromBool(result)}); | |
| 1683 | try pp.comp.generated_buf.print(pp.gpa, "{}\n", .{@intFromBool(result)}); | |
| 1687 | 1684 | try buf.append(try pp.makeGeneratedToken(start, .pp_num, tokFromRaw(raw))); |
| 1688 | 1685 | }, |
| 1689 | 1686 | .macro_param_has_c_attribute => { |
| ... | ... | @@ -2988,18 +2985,16 @@ fn embed(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!void { |
| 2988 | 2985 | // TODO: We currently only support systems with CHAR_BIT == 8 |
| 2989 | 2986 | // If the target's CHAR_BIT is not 8, we need to write out correctly-sized embed_bytes |
| 2990 | 2987 | // and correctly account for the target's endianness |
| 2991 | const writer = pp.comp.generated_buf.writer(pp.gpa); | |
| 2992 | ||
| 2993 | 2988 | { |
| 2994 | 2989 | const byte = embed_bytes[0]; |
| 2995 | 2990 | const start = pp.comp.generated_buf.items.len; |
| 2996 | try writer.print("{d}", .{byte}); | |
| 2991 | try pp.comp.generated_buf.print(pp.gpa, "{d}", .{byte}); | |
| 2997 | 2992 | pp.addTokenAssumeCapacity(try pp.makeGeneratedToken(start, .embed_byte, filename_tok)); |
| 2998 | 2993 | } |
| 2999 | 2994 | |
| 3000 | 2995 | for (embed_bytes[1..]) |byte| { |
| 3001 | 2996 | const start = pp.comp.generated_buf.items.len; |
| 3002 | try writer.print(",{d}", .{byte}); | |
| 2997 | try pp.comp.generated_buf.print(pp.gpa, ",{d}", .{byte}); | |
| 3003 | 2998 | pp.addTokenAssumeCapacity(.{ .id = .comma, .loc = .{ .id = .generated, .byte_offset = @intCast(start) } }); |
| 3004 | 2999 | pp.addTokenAssumeCapacity(try pp.makeGeneratedToken(start + 1, .embed_byte, filename_tok)); |
| 3005 | 3000 | } |
| ... | ... | @@ -3241,7 +3236,7 @@ fn findIncludeSource(pp: *Preprocessor, tokenizer: *Tokenizer, first: RawToken, |
| 3241 | 3236 | |
| 3242 | 3237 | fn printLinemarker( |
| 3243 | 3238 | pp: *Preprocessor, |
| 3244 | w: anytype, | |
| 3239 | w: *Writer, | |
| 3245 | 3240 | line_no: u32, |
| 3246 | 3241 | source: Source, |
| 3247 | 3242 | start_resume: enum(u8) { start, @"resume", none }, |
| ... | ... | @@ -3301,7 +3296,7 @@ pub const DumpMode = enum { |
| 3301 | 3296 | /// Pretty-print the macro define or undef at location `loc`. |
| 3302 | 3297 | /// We re-tokenize the directive because we are printing a macro that may have the same name as one in |
| 3303 | 3298 | /// `pp.defines` but a different definition (due to being #undef'ed and then redefined) |
| 3304 | fn prettyPrintMacro(pp: *Preprocessor, w: anytype, loc: Source.Location, parts: enum { name_only, name_and_body }) !void { | |
| 3299 | fn prettyPrintMacro(pp: *Preprocessor, w: *Writer, loc: Source.Location, parts: enum { name_only, name_and_body }) !void { | |
| 3305 | 3300 | const source = pp.comp.getSource(loc.id); |
| 3306 | 3301 | var tokenizer: Tokenizer = .{ |
| 3307 | 3302 | .buf = source.buf, |
| ... | ... | @@ -3339,7 +3334,7 @@ fn prettyPrintMacro(pp: *Preprocessor, w: anytype, loc: Source.Location, parts: |
| 3339 | 3334 | } |
| 3340 | 3335 | } |
| 3341 | 3336 | |
| 3342 | fn prettyPrintMacrosOnly(pp: *Preprocessor, w: anytype) !void { | |
| 3337 | fn prettyPrintMacrosOnly(pp: *Preprocessor, w: *Writer) !void { | |
| 3343 | 3338 | var it = pp.defines.valueIterator(); |
| 3344 | 3339 | while (it.next()) |macro| { |
| 3345 | 3340 | if (macro.is_builtin) continue; |
| ... | ... | @@ -3351,7 +3346,7 @@ fn prettyPrintMacrosOnly(pp: *Preprocessor, w: anytype) !void { |
| 3351 | 3346 | } |
| 3352 | 3347 | |
| 3353 | 3348 | /// Pretty print tokens and try to preserve whitespace. |
| 3354 | pub fn prettyPrintTokens(pp: *Preprocessor, w: anytype, macro_dump_mode: DumpMode) !void { | |
| 3349 | pub fn prettyPrintTokens(pp: *Preprocessor, w: *Writer, macro_dump_mode: DumpMode) !void { | |
| 3355 | 3350 | if (macro_dump_mode == .macros_only) { |
| 3356 | 3351 | return pp.prettyPrintMacrosOnly(w); |
| 3357 | 3352 | } |
lib/compiler/aro/aro/Type.zig+9-8| ... | ... | @@ -9,6 +9,7 @@ const StringInterner = @import("StringInterner.zig"); |
| 9 | 9 | const StringId = StringInterner.StringId; |
| 10 | 10 | const target_util = @import("target.zig"); |
| 11 | 11 | const LangOpts = @import("LangOpts.zig"); |
| 12 | const Writer = std.Io.Writer; | |
| 12 | 13 | |
| 13 | 14 | pub const Qualifiers = packed struct { |
| 14 | 15 | @"const": bool = false, |
| ... | ... | @@ -23,7 +24,7 @@ pub const Qualifiers = packed struct { |
| 23 | 24 | return quals.@"const" or quals.restrict or quals.@"volatile" or quals.atomic; |
| 24 | 25 | } |
| 25 | 26 | |
| 26 | pub fn dump(quals: Qualifiers, w: anytype) !void { | |
| 27 | pub fn dump(quals: Qualifiers, w: *Writer) !void { | |
| 27 | 28 | if (quals.@"const") try w.writeAll("const "); |
| 28 | 29 | if (quals.atomic) try w.writeAll("_Atomic "); |
| 29 | 30 | if (quals.@"volatile") try w.writeAll("volatile "); |
| ... | ... | @@ -2411,12 +2412,12 @@ pub fn intValueSuffix(ty: Type, comp: *const Compilation) []const u8 { |
| 2411 | 2412 | } |
| 2412 | 2413 | |
| 2413 | 2414 | /// Print type in C style |
| 2414 | pub fn print(ty: Type, mapper: StringInterner.TypeMapper, langopts: LangOpts, w: anytype) @TypeOf(w).Error!void { | |
| 2415 | pub fn print(ty: Type, mapper: StringInterner.TypeMapper, langopts: LangOpts, w: *Writer) Writer.Error!void { | |
| 2415 | 2416 | _ = try ty.printPrologue(mapper, langopts, w); |
| 2416 | 2417 | try ty.printEpilogue(mapper, langopts, w); |
| 2417 | 2418 | } |
| 2418 | 2419 | |
| 2419 | pub fn printNamed(ty: Type, name: []const u8, mapper: StringInterner.TypeMapper, langopts: LangOpts, w: anytype) @TypeOf(w).Error!void { | |
| 2420 | pub fn printNamed(ty: Type, name: []const u8, mapper: StringInterner.TypeMapper, langopts: LangOpts, w: *Writer) Writer.Error!void { | |
| 2420 | 2421 | const simple = try ty.printPrologue(mapper, langopts, w); |
| 2421 | 2422 | if (simple) try w.writeByte(' '); |
| 2422 | 2423 | try w.writeAll(name); |
| ... | ... | @@ -2426,7 +2427,7 @@ pub fn printNamed(ty: Type, name: []const u8, mapper: StringInterner.TypeMapper, |
| 2426 | 2427 | const StringGetter = fn (TokenIndex) []const u8; |
| 2427 | 2428 | |
| 2428 | 2429 | /// return true if `ty` is simple |
| 2429 | fn printPrologue(ty: Type, mapper: StringInterner.TypeMapper, langopts: LangOpts, w: anytype) @TypeOf(w).Error!bool { | |
| 2430 | fn printPrologue(ty: Type, mapper: StringInterner.TypeMapper, langopts: LangOpts, w: *Writer) Writer.Error!bool { | |
| 2430 | 2431 | if (ty.qual.atomic) { |
| 2431 | 2432 | var non_atomic_ty = ty; |
| 2432 | 2433 | non_atomic_ty.qual.atomic = false; |
| ... | ... | @@ -2497,7 +2498,7 @@ fn printPrologue(ty: Type, mapper: StringInterner.TypeMapper, langopts: LangOpts |
| 2497 | 2498 | return true; |
| 2498 | 2499 | } |
| 2499 | 2500 | |
| 2500 | fn printEpilogue(ty: Type, mapper: StringInterner.TypeMapper, langopts: LangOpts, w: anytype) @TypeOf(w).Error!void { | |
| 2501 | fn printEpilogue(ty: Type, mapper: StringInterner.TypeMapper, langopts: LangOpts, w: *Writer) Writer.Error!void { | |
| 2501 | 2502 | if (ty.qual.atomic) return; |
| 2502 | 2503 | if (ty.isPtr()) { |
| 2503 | 2504 | const elem_ty = ty.elemType(); |
| ... | ... | @@ -2564,7 +2565,7 @@ fn printEpilogue(ty: Type, mapper: StringInterner.TypeMapper, langopts: LangOpts |
| 2564 | 2565 | const dump_detailed_containers = false; |
| 2565 | 2566 | |
| 2566 | 2567 | // Print as Zig types since those are actually readable |
| 2567 | pub fn dump(ty: Type, mapper: StringInterner.TypeMapper, langopts: LangOpts, w: anytype) @TypeOf(w).Error!void { | |
| 2568 | pub fn dump(ty: Type, mapper: StringInterner.TypeMapper, langopts: LangOpts, w: *Writer) Writer.Error!void { | |
| 2568 | 2569 | try ty.qual.dump(w); |
| 2569 | 2570 | switch (ty.specifier) { |
| 2570 | 2571 | .invalid => try w.writeAll("invalid"), |
| ... | ... | @@ -2656,7 +2657,7 @@ pub fn dump(ty: Type, mapper: StringInterner.TypeMapper, langopts: LangOpts, w: |
| 2656 | 2657 | } |
| 2657 | 2658 | } |
| 2658 | 2659 | |
| 2659 | fn dumpEnum(@"enum": *Enum, mapper: StringInterner.TypeMapper, w: anytype) @TypeOf(w).Error!void { | |
| 2660 | fn dumpEnum(@"enum": *Enum, mapper: StringInterner.TypeMapper, w: *Writer) Writer.Error!void { | |
| 2660 | 2661 | try w.writeAll(" {"); |
| 2661 | 2662 | for (@"enum".fields) |field| { |
| 2662 | 2663 | try w.print(" {s} = {d},", .{ mapper.lookup(field.name), field.value }); |
| ... | ... | @@ -2664,7 +2665,7 @@ fn dumpEnum(@"enum": *Enum, mapper: StringInterner.TypeMapper, w: anytype) @Type |
| 2664 | 2665 | try w.writeAll(" }"); |
| 2665 | 2666 | } |
| 2666 | 2667 | |
| 2667 | fn dumpRecord(record: *Record, mapper: StringInterner.TypeMapper, langopts: LangOpts, w: anytype) @TypeOf(w).Error!void { | |
| 2668 | fn dumpRecord(record: *Record, mapper: StringInterner.TypeMapper, langopts: LangOpts, w: *Writer) Writer.Error!void { | |
| 2668 | 2669 | try w.writeAll(" {"); |
| 2669 | 2670 | for (record.fields) |field| { |
| 2670 | 2671 | try w.writeByte(' '); |
lib/compiler/aro/aro/Value.zig+3-2| ... | ... | @@ -9,6 +9,7 @@ const Compilation = @import("Compilation.zig"); |
| 9 | 9 | const Type = @import("Type.zig"); |
| 10 | 10 | const target_util = @import("target.zig"); |
| 11 | 11 | const annex_g = @import("annex_g.zig"); |
| 12 | const Writer = std.Io.Writer; | |
| 12 | 13 | |
| 13 | 14 | const Value = @This(); |
| 14 | 15 | |
| ... | ... | @@ -953,7 +954,7 @@ pub fn maxInt(ty: Type, comp: *Compilation) !Value { |
| 953 | 954 | return twosCompIntLimit(.max, ty, comp); |
| 954 | 955 | } |
| 955 | 956 | |
| 956 | pub fn print(v: Value, ty: Type, comp: *const Compilation, w: anytype) @TypeOf(w).Error!void { | |
| 957 | pub fn print(v: Value, ty: Type, comp: *const Compilation, w: *Writer) Writer.Error!void { | |
| 957 | 958 | if (ty.is(.bool)) { |
| 958 | 959 | return w.writeAll(if (v.isZero(comp)) "false" else "true"); |
| 959 | 960 | } |
| ... | ... | @@ -977,7 +978,7 @@ pub fn print(v: Value, ty: Type, comp: *const Compilation, w: anytype) @TypeOf(w |
| 977 | 978 | } |
| 978 | 979 | } |
| 979 | 980 | |
| 980 | pub fn printString(bytes: []const u8, ty: Type, comp: *const Compilation, w: anytype) @TypeOf(w).Error!void { | |
| 981 | pub fn printString(bytes: []const u8, ty: Type, comp: *const Compilation, w: *Writer) Writer.Error!void { | |
| 981 | 982 | const size: Compilation.CharUnitSize = @enumFromInt(ty.elemType().sizeof(comp).?); |
| 982 | 983 | const without_null = bytes[0 .. bytes.len - @intFromEnum(size)]; |
| 983 | 984 | try w.writeByte('"'); |
lib/compiler/aro_translate_c/ast.zig+1-1| ... | ... | @@ -832,7 +832,7 @@ const Context = struct { |
| 832 | 832 | |
| 833 | 833 | fn addTokenFmt(c: *Context, tag: TokenTag, comptime format: []const u8, args: anytype) Allocator.Error!TokenIndex { |
| 834 | 834 | const start_index = c.buf.items.len; |
| 835 | try c.buf.writer().print(format ++ " ", args); | |
| 835 | try c.buf.print(format ++ " ", args); | |
| 836 | 836 | |
| 837 | 837 | try c.tokens.append(c.gpa, .{ |
| 838 | 838 | .tag = tag, |
src/libs/mingw.zig+4-1| ... | ... | @@ -334,7 +334,10 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void { |
| 334 | 334 | // new scope to ensure definition file is written before passing the path to WriteImportLibrary |
| 335 | 335 | const def_final_file = try o_dir.createFile(final_def_basename, .{ .truncate = true }); |
| 336 | 336 | defer def_final_file.close(); |
| 337 | try pp.prettyPrintTokens(def_final_file.deprecatedWriter(), .result_only); | |
| 337 | var buffer: [1024]u8 = undefined; | |
| 338 | var def_final_file_writer = def_final_file.writer(&buffer); | |
| 339 | try pp.prettyPrintTokens(&def_final_file_writer.interface, .result_only); | |
| 340 | try def_final_file_writer.interface.flush(); | |
| 338 | 341 | } |
| 339 | 342 | |
| 340 | 343 | const lib_final_path = try std.fs.path.join(gpa, &.{ "o", &digest, final_lib_basename }); |