| author | |
| committer | |
| log | dfbc063f79dc1358208216b466c1bf8c44baa430 |
| tree | 219c5f46a2e688fc1799117a1680102528691ce3 |
| parent | c90c256868a80cd35e9ba679ba082330592620c9 |
| signature | Commit is signed but in an unrecognized format. |
`std.mem.Allocator.createOne` is renamed to `std.mem.Allocator.create`.
The problem with the previous API is that even after copy elision,
the initalization value passed as a parameter would always be a copy.
With the new API, once copy elision is done, initialization
functions can directly initialize allocated memory in place.
Related:
* #1872
* #187323 files changed, 451 insertions(+), 312 deletions(-)
src-self-hosted/compilation.zig+43-29| ... | ... | @@ -83,10 +83,11 @@ pub const ZigCompiler = struct { |
| 83 | 83 | const context_ref = c.LLVMContextCreate() orelse return error.OutOfMemory; |
| 84 | 84 | errdefer c.LLVMContextDispose(context_ref); |
| 85 | 85 | |
| 86 | const node = try self.loop.allocator.create(std.atomic.Stack(llvm.ContextRef).Node{ | |
| 86 | const node = try self.loop.allocator.create(std.atomic.Stack(llvm.ContextRef).Node); | |
| 87 | node.* = std.atomic.Stack(llvm.ContextRef).Node{ | |
| 87 | 88 | .next = undefined, |
| 88 | 89 | .data = context_ref, |
| 89 | }); | |
| 90 | }; | |
| 90 | 91 | errdefer self.loop.allocator.destroy(node); |
| 91 | 92 | |
| 92 | 93 | return LlvmHandle{ .node = node }; |
| ... | ... | @@ -596,7 +597,8 @@ pub const Compilation = struct { |
| 596 | 597 | } |
| 597 | 598 | |
| 598 | 599 | fn initTypes(comp: *Compilation) !void { |
| 599 | comp.meta_type = try comp.arena().create(Type.MetaType{ | |
| 600 | comp.meta_type = try comp.arena().create(Type.MetaType); | |
| 601 | comp.meta_type.* = Type.MetaType{ | |
| 600 | 602 | .base = Type{ |
| 601 | 603 | .name = "type", |
| 602 | 604 | .base = Value{ |
| ... | ... | @@ -608,12 +610,13 @@ pub const Compilation = struct { |
| 608 | 610 | .abi_alignment = Type.AbiAlignment.init(comp.loop), |
| 609 | 611 | }, |
| 610 | 612 | .value = undefined, |
| 611 | }); | |
| 613 | }; | |
| 612 | 614 | comp.meta_type.value = &comp.meta_type.base; |
| 613 | 615 | comp.meta_type.base.base.typ = &comp.meta_type.base; |
| 614 | 616 | assert((try comp.primitive_type_table.put(comp.meta_type.base.name, &comp.meta_type.base)) == null); |
| 615 | 617 | |
| 616 | comp.void_type = try comp.arena().create(Type.Void{ | |
| 618 | comp.void_type = try comp.arena().create(Type.Void); | |
| 619 | comp.void_type.* = Type.Void{ | |
| 617 | 620 | .base = Type{ |
| 618 | 621 | .name = "void", |
| 619 | 622 | .base = Value{ |
| ... | ... | @@ -624,10 +627,11 @@ pub const Compilation = struct { |
| 624 | 627 | .id = builtin.TypeId.Void, |
| 625 | 628 | .abi_alignment = Type.AbiAlignment.init(comp.loop), |
| 626 | 629 | }, |
| 627 | }); | |
| 630 | }; | |
| 628 | 631 | assert((try comp.primitive_type_table.put(comp.void_type.base.name, &comp.void_type.base)) == null); |
| 629 | 632 | |
| 630 | comp.noreturn_type = try comp.arena().create(Type.NoReturn{ | |
| 633 | comp.noreturn_type = try comp.arena().create(Type.NoReturn); | |
| 634 | comp.noreturn_type.* = Type.NoReturn{ | |
| 631 | 635 | .base = Type{ |
| 632 | 636 | .name = "noreturn", |
| 633 | 637 | .base = Value{ |
| ... | ... | @@ -638,10 +642,11 @@ pub const Compilation = struct { |
| 638 | 642 | .id = builtin.TypeId.NoReturn, |
| 639 | 643 | .abi_alignment = Type.AbiAlignment.init(comp.loop), |
| 640 | 644 | }, |
| 641 | }); | |
| 645 | }; | |
| 642 | 646 | assert((try comp.primitive_type_table.put(comp.noreturn_type.base.name, &comp.noreturn_type.base)) == null); |
| 643 | 647 | |
| 644 | comp.comptime_int_type = try comp.arena().create(Type.ComptimeInt{ | |
| 648 | comp.comptime_int_type = try comp.arena().create(Type.ComptimeInt); | |
| 649 | comp.comptime_int_type.* = Type.ComptimeInt{ | |
| 645 | 650 | .base = Type{ |
| 646 | 651 | .name = "comptime_int", |
| 647 | 652 | .base = Value{ |
| ... | ... | @@ -652,10 +657,11 @@ pub const Compilation = struct { |
| 652 | 657 | .id = builtin.TypeId.ComptimeInt, |
| 653 | 658 | .abi_alignment = Type.AbiAlignment.init(comp.loop), |
| 654 | 659 | }, |
| 655 | }); | |
| 660 | }; | |
| 656 | 661 | assert((try comp.primitive_type_table.put(comp.comptime_int_type.base.name, &comp.comptime_int_type.base)) == null); |
| 657 | 662 | |
| 658 | comp.bool_type = try comp.arena().create(Type.Bool{ | |
| 663 | comp.bool_type = try comp.arena().create(Type.Bool); | |
| 664 | comp.bool_type.* = Type.Bool{ | |
| 659 | 665 | .base = Type{ |
| 660 | 666 | .name = "bool", |
| 661 | 667 | .base = Value{ |
| ... | ... | @@ -666,45 +672,50 @@ pub const Compilation = struct { |
| 666 | 672 | .id = builtin.TypeId.Bool, |
| 667 | 673 | .abi_alignment = Type.AbiAlignment.init(comp.loop), |
| 668 | 674 | }, |
| 669 | }); | |
| 675 | }; | |
| 670 | 676 | assert((try comp.primitive_type_table.put(comp.bool_type.base.name, &comp.bool_type.base)) == null); |
| 671 | 677 | |
| 672 | comp.void_value = try comp.arena().create(Value.Void{ | |
| 678 | comp.void_value = try comp.arena().create(Value.Void); | |
| 679 | comp.void_value.* = Value.Void{ | |
| 673 | 680 | .base = Value{ |
| 674 | 681 | .id = Value.Id.Void, |
| 675 | 682 | .typ = &Type.Void.get(comp).base, |
| 676 | 683 | .ref_count = std.atomic.Int(usize).init(1), |
| 677 | 684 | }, |
| 678 | }); | |
| 685 | }; | |
| 679 | 686 | |
| 680 | comp.true_value = try comp.arena().create(Value.Bool{ | |
| 687 | comp.true_value = try comp.arena().create(Value.Bool); | |
| 688 | comp.true_value.* = Value.Bool{ | |
| 681 | 689 | .base = Value{ |
| 682 | 690 | .id = Value.Id.Bool, |
| 683 | 691 | .typ = &Type.Bool.get(comp).base, |
| 684 | 692 | .ref_count = std.atomic.Int(usize).init(1), |
| 685 | 693 | }, |
| 686 | 694 | .x = true, |
| 687 | }); | |
| 695 | }; | |
| 688 | 696 | |
| 689 | comp.false_value = try comp.arena().create(Value.Bool{ | |
| 697 | comp.false_value = try comp.arena().create(Value.Bool); | |
| 698 | comp.false_value.* = Value.Bool{ | |
| 690 | 699 | .base = Value{ |
| 691 | 700 | .id = Value.Id.Bool, |
| 692 | 701 | .typ = &Type.Bool.get(comp).base, |
| 693 | 702 | .ref_count = std.atomic.Int(usize).init(1), |
| 694 | 703 | }, |
| 695 | 704 | .x = false, |
| 696 | }); | |
| 705 | }; | |
| 697 | 706 | |
| 698 | comp.noreturn_value = try comp.arena().create(Value.NoReturn{ | |
| 707 | comp.noreturn_value = try comp.arena().create(Value.NoReturn); | |
| 708 | comp.noreturn_value.* = Value.NoReturn{ | |
| 699 | 709 | .base = Value{ |
| 700 | 710 | .id = Value.Id.NoReturn, |
| 701 | 711 | .typ = &Type.NoReturn.get(comp).base, |
| 702 | 712 | .ref_count = std.atomic.Int(usize).init(1), |
| 703 | 713 | }, |
| 704 | }); | |
| 714 | }; | |
| 705 | 715 | |
| 706 | 716 | for (CInt.list) |cint, i| { |
| 707 | const c_int_type = try comp.arena().create(Type.Int{ | |
| 717 | const c_int_type = try comp.arena().create(Type.Int); | |
| 718 | c_int_type.* = Type.Int{ | |
| 708 | 719 | .base = Type{ |
| 709 | 720 | .name = cint.zig_name, |
| 710 | 721 | .base = Value{ |
| ... | ... | @@ -720,11 +731,12 @@ pub const Compilation = struct { |
| 720 | 731 | .bit_count = comp.target.cIntTypeSizeInBits(cint.id), |
| 721 | 732 | }, |
| 722 | 733 | .garbage_node = undefined, |
| 723 | }); | |
| 734 | }; | |
| 724 | 735 | comp.c_int_types[i] = c_int_type; |
| 725 | 736 | assert((try comp.primitive_type_table.put(cint.zig_name, &c_int_type.base)) == null); |
| 726 | 737 | } |
| 727 | comp.u8_type = try comp.arena().create(Type.Int{ | |
| 738 | comp.u8_type = try comp.arena().create(Type.Int); | |
| 739 | comp.u8_type.* = Type.Int{ | |
| 728 | 740 | .base = Type{ |
| 729 | 741 | .name = "u8", |
| 730 | 742 | .base = Value{ |
| ... | ... | @@ -740,7 +752,7 @@ pub const Compilation = struct { |
| 740 | 752 | .bit_count = 8, |
| 741 | 753 | }, |
| 742 | 754 | .garbage_node = undefined, |
| 743 | }); | |
| 755 | }; | |
| 744 | 756 | assert((try comp.primitive_type_table.put(comp.u8_type.base.name, &comp.u8_type.base)) == null); |
| 745 | 757 | } |
| 746 | 758 | |
| ... | ... | @@ -829,7 +841,7 @@ pub const Compilation = struct { |
| 829 | 841 | }; |
| 830 | 842 | errdefer self.gpa().free(source_code); |
| 831 | 843 | |
| 832 | const tree = try self.gpa().createOne(ast.Tree); | |
| 844 | const tree = try self.gpa().create(ast.Tree); | |
| 833 | 845 | tree.* = try std.zig.parse(self.gpa(), source_code); |
| 834 | 846 | errdefer { |
| 835 | 847 | tree.deinit(); |
| ... | ... | @@ -925,7 +937,8 @@ pub const Compilation = struct { |
| 925 | 937 | } |
| 926 | 938 | } else { |
| 927 | 939 | // add new decl |
| 928 | const fn_decl = try self.gpa().create(Decl.Fn{ | |
| 940 | const fn_decl = try self.gpa().create(Decl.Fn); | |
| 941 | fn_decl.* = Decl.Fn{ | |
| 929 | 942 | .base = Decl{ |
| 930 | 943 | .id = Decl.Id.Fn, |
| 931 | 944 | .name = name, |
| ... | ... | @@ -936,7 +949,7 @@ pub const Compilation = struct { |
| 936 | 949 | }, |
| 937 | 950 | .value = Decl.Fn.Val{ .Unresolved = {} }, |
| 938 | 951 | .fn_proto = fn_proto, |
| 939 | }); | |
| 952 | }; | |
| 940 | 953 | tree_scope.base.ref(); |
| 941 | 954 | errdefer self.gpa().destroy(fn_decl); |
| 942 | 955 | |
| ... | ... | @@ -1140,12 +1153,13 @@ pub const Compilation = struct { |
| 1140 | 1153 | } |
| 1141 | 1154 | } |
| 1142 | 1155 | |
| 1143 | const link_lib = try self.gpa().create(LinkLib{ | |
| 1156 | const link_lib = try self.gpa().create(LinkLib); | |
| 1157 | link_lib.* = LinkLib{ | |
| 1144 | 1158 | .name = name, |
| 1145 | 1159 | .path = null, |
| 1146 | 1160 | .provided_explicitly = provided_explicitly, |
| 1147 | 1161 | .symbols = ArrayList([]u8).init(self.gpa()), |
| 1148 | }); | |
| 1162 | }; | |
| 1149 | 1163 | try self.link_libs_list.append(link_lib); |
| 1150 | 1164 | if (is_libc) { |
| 1151 | 1165 | self.libc_link_lib = link_lib; |
src-self-hosted/errmsg.zig+12-8| ... | ... | @@ -118,7 +118,8 @@ pub const Msg = struct { |
| 118 | 118 | const realpath = try mem.dupe(comp.gpa(), u8, tree_scope.root().realpath); |
| 119 | 119 | errdefer comp.gpa().free(realpath); |
| 120 | 120 | |
| 121 | const msg = try comp.gpa().create(Msg{ | |
| 121 | const msg = try comp.gpa().create(Msg); | |
| 122 | msg.* = Msg{ | |
| 122 | 123 | .text = text, |
| 123 | 124 | .realpath = realpath, |
| 124 | 125 | .data = Data{ |
| ... | ... | @@ -128,7 +129,7 @@ pub const Msg = struct { |
| 128 | 129 | .span = span, |
| 129 | 130 | }, |
| 130 | 131 | }, |
| 131 | }); | |
| 132 | }; | |
| 132 | 133 | tree_scope.base.ref(); |
| 133 | 134 | return msg; |
| 134 | 135 | } |
| ... | ... | @@ -139,13 +140,14 @@ pub const Msg = struct { |
| 139 | 140 | const realpath_copy = try mem.dupe(comp.gpa(), u8, realpath); |
| 140 | 141 | errdefer comp.gpa().free(realpath_copy); |
| 141 | 142 | |
| 142 | const msg = try comp.gpa().create(Msg{ | |
| 143 | const msg = try comp.gpa().create(Msg); | |
| 144 | msg.* = Msg{ | |
| 143 | 145 | .text = text, |
| 144 | 146 | .realpath = realpath_copy, |
| 145 | 147 | .data = Data{ |
| 146 | 148 | .Cli = Cli{ .allocator = comp.gpa() }, |
| 147 | 149 | }, |
| 148 | }); | |
| 150 | }; | |
| 149 | 151 | return msg; |
| 150 | 152 | } |
| 151 | 153 | |
| ... | ... | @@ -164,7 +166,8 @@ pub const Msg = struct { |
| 164 | 166 | var out_stream = &std.io.BufferOutStream.init(&text_buf).stream; |
| 165 | 167 | try parse_error.render(&tree_scope.tree.tokens, out_stream); |
| 166 | 168 | |
| 167 | const msg = try comp.gpa().create(Msg{ | |
| 169 | const msg = try comp.gpa().create(Msg); | |
| 170 | msg.* = Msg{ | |
| 168 | 171 | .text = undefined, |
| 169 | 172 | .realpath = realpath_copy, |
| 170 | 173 | .data = Data{ |
| ... | ... | @@ -177,7 +180,7 @@ pub const Msg = struct { |
| 177 | 180 | }, |
| 178 | 181 | }, |
| 179 | 182 | }, |
| 180 | }); | |
| 183 | }; | |
| 181 | 184 | tree_scope.base.ref(); |
| 182 | 185 | msg.text = text_buf.toOwnedSlice(); |
| 183 | 186 | return msg; |
| ... | ... | @@ -203,7 +206,8 @@ pub const Msg = struct { |
| 203 | 206 | var out_stream = &std.io.BufferOutStream.init(&text_buf).stream; |
| 204 | 207 | try parse_error.render(&tree.tokens, out_stream); |
| 205 | 208 | |
| 206 | const msg = try allocator.create(Msg{ | |
| 209 | const msg = try allocator.create(Msg); | |
| 210 | msg.* = Msg{ | |
| 207 | 211 | .text = undefined, |
| 208 | 212 | .realpath = realpath_copy, |
| 209 | 213 | .data = Data{ |
| ... | ... | @@ -216,7 +220,7 @@ pub const Msg = struct { |
| 216 | 220 | }, |
| 217 | 221 | }, |
| 218 | 222 | }, |
| 219 | }); | |
| 223 | }; | |
| 220 | 224 | msg.text = text_buf.toOwnedSlice(); |
| 221 | 225 | errdefer allocator.destroy(msg); |
| 222 | 226 |
src-self-hosted/ir.zig+9-6| ... | ... | @@ -1021,12 +1021,13 @@ pub const Builder = struct { |
| 1021 | 1021 | pub const Error = Analyze.Error; |
| 1022 | 1022 | |
| 1023 | 1023 | pub fn init(comp: *Compilation, tree_scope: *Scope.AstTree, begin_scope: ?*Scope) !Builder { |
| 1024 | const code = try comp.gpa().create(Code{ | |
| 1024 | const code = try comp.gpa().create(Code); | |
| 1025 | code.* = Code{ | |
| 1025 | 1026 | .basic_block_list = undefined, |
| 1026 | 1027 | .arena = std.heap.ArenaAllocator.init(comp.gpa()), |
| 1027 | 1028 | .return_type = null, |
| 1028 | 1029 | .tree_scope = tree_scope, |
| 1029 | }); | |
| 1030 | }; | |
| 1030 | 1031 | code.basic_block_list = std.ArrayList(*BasicBlock).init(&code.arena.allocator); |
| 1031 | 1032 | errdefer code.destroy(comp.gpa()); |
| 1032 | 1033 | |
| ... | ... | @@ -1052,7 +1053,8 @@ pub const Builder = struct { |
| 1052 | 1053 | |
| 1053 | 1054 | /// No need to clean up resources thanks to the arena allocator. |
| 1054 | 1055 | pub fn createBasicBlock(self: *Builder, scope: *Scope, name_hint: [*]const u8) !*BasicBlock { |
| 1055 | const basic_block = try self.arena().create(BasicBlock{ | |
| 1056 | const basic_block = try self.arena().create(BasicBlock); | |
| 1057 | basic_block.* = BasicBlock{ | |
| 1056 | 1058 | .ref_count = 0, |
| 1057 | 1059 | .name_hint = name_hint, |
| 1058 | 1060 | .debug_id = self.next_debug_id, |
| ... | ... | @@ -1063,7 +1065,7 @@ pub const Builder = struct { |
| 1063 | 1065 | .ref_instruction = null, |
| 1064 | 1066 | .llvm_block = undefined, |
| 1065 | 1067 | .llvm_exit_block = undefined, |
| 1066 | }); | |
| 1068 | }; | |
| 1067 | 1069 | self.next_debug_id += 1; |
| 1068 | 1070 | return basic_block; |
| 1069 | 1071 | } |
| ... | ... | @@ -1774,7 +1776,8 @@ pub const Builder = struct { |
| 1774 | 1776 | params: I.Params, |
| 1775 | 1777 | is_generated: bool, |
| 1776 | 1778 | ) !*Inst { |
| 1777 | const inst = try self.arena().create(I{ | |
| 1779 | const inst = try self.arena().create(I); | |
| 1780 | inst.* = I{ | |
| 1778 | 1781 | .base = Inst{ |
| 1779 | 1782 | .id = Inst.typeToId(I), |
| 1780 | 1783 | .is_generated = is_generated, |
| ... | ... | @@ -1793,7 +1796,7 @@ pub const Builder = struct { |
| 1793 | 1796 | .owner_bb = self.current_basic_block, |
| 1794 | 1797 | }, |
| 1795 | 1798 | .params = params, |
| 1796 | }); | |
| 1799 | }; | |
| 1797 | 1800 | |
| 1798 | 1801 | // Look at the params and ref() other instructions |
| 1799 | 1802 | comptime var i = 0; |
src-self-hosted/main.zig+3-2| ... | ... | @@ -944,12 +944,13 @@ const CliPkg = struct { |
| 944 | 944 | parent: ?*CliPkg, |
| 945 | 945 | |
| 946 | 946 | pub fn init(allocator: *mem.Allocator, name: []const u8, path: []const u8, parent: ?*CliPkg) !*CliPkg { |
| 947 | var pkg = try allocator.create(CliPkg{ | |
| 947 | var pkg = try allocator.create(CliPkg); | |
| 948 | pkg.* = CliPkg{ | |
| 948 | 949 | .name = name, |
| 949 | 950 | .path = path, |
| 950 | 951 | .children = ArrayList(*CliPkg).init(allocator), |
| 951 | 952 | .parent = parent, |
| 952 | }); | |
| 953 | }; | |
| 953 | 954 | return pkg; |
| 954 | 955 | } |
| 955 | 956 |
src-self-hosted/package.zig+4-2| ... | ... | @@ -15,11 +15,13 @@ pub const Package = struct { |
| 15 | 15 | /// makes internal copies of root_src_dir and root_src_path |
| 16 | 16 | /// allocator should be an arena allocator because Package never frees anything |
| 17 | 17 | pub fn create(allocator: *mem.Allocator, root_src_dir: []const u8, root_src_path: []const u8) !*Package { |
| 18 | return allocator.create(Package{ | |
| 18 | const ptr = try allocator.create(Package); | |
| 19 | ptr.* = Package{ | |
| 19 | 20 | .root_src_dir = try Buffer.init(allocator, root_src_dir), |
| 20 | 21 | .root_src_path = try Buffer.init(allocator, root_src_path), |
| 21 | 22 | .table = Table.init(allocator), |
| 22 | }); | |
| 23 | }; | |
| 24 | return ptr; | |
| 23 | 25 | } |
| 24 | 26 | |
| 25 | 27 | pub fn add(self: *Package, name: []const u8, package: *Package) !void { |
src-self-hosted/scope.zig+9-9| ... | ... | @@ -120,7 +120,7 @@ pub const Scope = struct { |
| 120 | 120 | /// Creates a Root scope with 1 reference |
| 121 | 121 | /// Takes ownership of realpath |
| 122 | 122 | pub fn create(comp: *Compilation, realpath: []u8) !*Root { |
| 123 | const self = try comp.gpa().createOne(Root); | |
| 123 | const self = try comp.gpa().create(Root); | |
| 124 | 124 | self.* = Root{ |
| 125 | 125 | .base = Scope{ |
| 126 | 126 | .id = Id.Root, |
| ... | ... | @@ -150,7 +150,7 @@ pub const Scope = struct { |
| 150 | 150 | /// Creates a scope with 1 reference |
| 151 | 151 | /// Takes ownership of tree, will deinit and destroy when done. |
| 152 | 152 | pub fn create(comp: *Compilation, tree: *ast.Tree, root_scope: *Root) !*AstTree { |
| 153 | const self = try comp.gpa().createOne(AstTree); | |
| 153 | const self = try comp.gpa().create(AstTree); | |
| 154 | 154 | self.* = AstTree{ |
| 155 | 155 | .base = undefined, |
| 156 | 156 | .tree = tree, |
| ... | ... | @@ -182,7 +182,7 @@ pub const Scope = struct { |
| 182 | 182 | |
| 183 | 183 | /// Creates a Decls scope with 1 reference |
| 184 | 184 | pub fn create(comp: *Compilation, parent: *Scope) !*Decls { |
| 185 | const self = try comp.gpa().createOne(Decls); | |
| 185 | const self = try comp.gpa().create(Decls); | |
| 186 | 186 | self.* = Decls{ |
| 187 | 187 | .base = undefined, |
| 188 | 188 | .table = event.RwLocked(Decl.Table).init(comp.loop, Decl.Table.init(comp.gpa())), |
| ... | ... | @@ -235,7 +235,7 @@ pub const Scope = struct { |
| 235 | 235 | |
| 236 | 236 | /// Creates a Block scope with 1 reference |
| 237 | 237 | pub fn create(comp: *Compilation, parent: *Scope) !*Block { |
| 238 | const self = try comp.gpa().createOne(Block); | |
| 238 | const self = try comp.gpa().create(Block); | |
| 239 | 239 | self.* = Block{ |
| 240 | 240 | .base = undefined, |
| 241 | 241 | .incoming_values = undefined, |
| ... | ... | @@ -262,7 +262,7 @@ pub const Scope = struct { |
| 262 | 262 | /// Creates a FnDef scope with 1 reference |
| 263 | 263 | /// Must set the fn_val later |
| 264 | 264 | pub fn create(comp: *Compilation, parent: *Scope) !*FnDef { |
| 265 | const self = try comp.gpa().createOne(FnDef); | |
| 265 | const self = try comp.gpa().create(FnDef); | |
| 266 | 266 | self.* = FnDef{ |
| 267 | 267 | .base = undefined, |
| 268 | 268 | .fn_val = null, |
| ... | ... | @@ -281,7 +281,7 @@ pub const Scope = struct { |
| 281 | 281 | |
| 282 | 282 | /// Creates a CompTime scope with 1 reference |
| 283 | 283 | pub fn create(comp: *Compilation, parent: *Scope) !*CompTime { |
| 284 | const self = try comp.gpa().createOne(CompTime); | |
| 284 | const self = try comp.gpa().create(CompTime); | |
| 285 | 285 | self.* = CompTime{ .base = undefined }; |
| 286 | 286 | self.base.init(Id.CompTime, parent); |
| 287 | 287 | return self; |
| ... | ... | @@ -309,7 +309,7 @@ pub const Scope = struct { |
| 309 | 309 | kind: Kind, |
| 310 | 310 | defer_expr_scope: *DeferExpr, |
| 311 | 311 | ) !*Defer { |
| 312 | const self = try comp.gpa().createOne(Defer); | |
| 312 | const self = try comp.gpa().create(Defer); | |
| 313 | 313 | self.* = Defer{ |
| 314 | 314 | .base = undefined, |
| 315 | 315 | .defer_expr_scope = defer_expr_scope, |
| ... | ... | @@ -333,7 +333,7 @@ pub const Scope = struct { |
| 333 | 333 | |
| 334 | 334 | /// Creates a DeferExpr scope with 1 reference |
| 335 | 335 | pub fn create(comp: *Compilation, parent: *Scope, expr_node: *ast.Node) !*DeferExpr { |
| 336 | const self = try comp.gpa().createOne(DeferExpr); | |
| 336 | const self = try comp.gpa().create(DeferExpr); | |
| 337 | 337 | self.* = DeferExpr{ |
| 338 | 338 | .base = undefined, |
| 339 | 339 | .expr_node = expr_node, |
| ... | ... | @@ -398,7 +398,7 @@ pub const Scope = struct { |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | fn create(comp: *Compilation, parent: *Scope, name: []const u8, src_node: *ast.Node) !*Var { |
| 401 | const self = try comp.gpa().createOne(Var); | |
| 401 | const self = try comp.gpa().create(Var); | |
| 402 | 402 | self.* = Var{ |
| 403 | 403 | .base = undefined, |
| 404 | 404 | .name = name, |
src-self-hosted/type.zig+10-7| ... | ... | @@ -413,7 +413,7 @@ pub const Type = struct { |
| 413 | 413 | key.ref(); |
| 414 | 414 | errdefer key.deref(comp); |
| 415 | 415 | |
| 416 | const self = try comp.gpa().createOne(Fn); | |
| 416 | const self = try comp.gpa().create(Fn); | |
| 417 | 417 | self.* = Fn{ |
| 418 | 418 | .base = undefined, |
| 419 | 419 | .key = key, |
| ... | ... | @@ -615,11 +615,12 @@ pub const Type = struct { |
| 615 | 615 | } |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | const self = try comp.gpa().create(Int{ | |
| 618 | const self = try comp.gpa().create(Int); | |
| 619 | self.* = Int{ | |
| 619 | 620 | .base = undefined, |
| 620 | 621 | .key = key, |
| 621 | 622 | .garbage_node = undefined, |
| 622 | }); | |
| 623 | }; | |
| 623 | 624 | errdefer comp.gpa().destroy(self); |
| 624 | 625 | |
| 625 | 626 | const u_or_i = "ui"[@boolToInt(key.is_signed)]; |
| ... | ... | @@ -781,11 +782,12 @@ pub const Type = struct { |
| 781 | 782 | } |
| 782 | 783 | } |
| 783 | 784 | |
| 784 | const self = try comp.gpa().create(Pointer{ | |
| 785 | const self = try comp.gpa().create(Pointer); | |
| 786 | self.* = Pointer{ | |
| 785 | 787 | .base = undefined, |
| 786 | 788 | .key = normal_key, |
| 787 | 789 | .garbage_node = undefined, |
| 788 | }); | |
| 790 | }; | |
| 789 | 791 | errdefer comp.gpa().destroy(self); |
| 790 | 792 | |
| 791 | 793 | const size_str = switch (self.key.size) { |
| ... | ... | @@ -879,11 +881,12 @@ pub const Type = struct { |
| 879 | 881 | } |
| 880 | 882 | } |
| 881 | 883 | |
| 882 | const self = try comp.gpa().create(Array{ | |
| 884 | const self = try comp.gpa().create(Array); | |
| 885 | self.* = Array{ | |
| 883 | 886 | .base = undefined, |
| 884 | 887 | .key = key, |
| 885 | 888 | .garbage_node = undefined, |
| 886 | }); | |
| 889 | }; | |
| 887 | 890 | errdefer comp.gpa().destroy(self); |
| 888 | 891 | |
| 889 | 892 | const name = try std.fmt.allocPrint(comp.gpa(), "[{}]{}", key.len, key.elem_type.name); |
src-self-hosted/value.zig+21-14| ... | ... | @@ -135,14 +135,15 @@ pub const Value = struct { |
| 135 | 135 | symbol_name: Buffer, |
| 136 | 136 | |
| 137 | 137 | pub fn create(comp: *Compilation, fn_type: *Type.Fn, symbol_name: Buffer) !*FnProto { |
| 138 | const self = try comp.gpa().create(FnProto{ | |
| 138 | const self = try comp.gpa().create(FnProto); | |
| 139 | self.* = FnProto{ | |
| 139 | 140 | .base = Value{ |
| 140 | 141 | .id = Value.Id.FnProto, |
| 141 | 142 | .typ = &fn_type.base, |
| 142 | 143 | .ref_count = std.atomic.Int(usize).init(1), |
| 143 | 144 | }, |
| 144 | 145 | .symbol_name = symbol_name, |
| 145 | }); | |
| 146 | }; | |
| 146 | 147 | fn_type.base.base.ref(); |
| 147 | 148 | return self; |
| 148 | 149 | } |
| ... | ... | @@ -190,14 +191,16 @@ pub const Value = struct { |
| 190 | 191 | /// Creates a Fn value with 1 ref |
| 191 | 192 | /// Takes ownership of symbol_name |
| 192 | 193 | pub fn create(comp: *Compilation, fn_type: *Type.Fn, fndef_scope: *Scope.FnDef, symbol_name: Buffer) !*Fn { |
| 193 | const link_set_node = try comp.gpa().create(Compilation.FnLinkSet.Node{ | |
| 194 | const link_set_node = try comp.gpa().create(Compilation.FnLinkSet.Node); | |
| 195 | link_set_node.* = Compilation.FnLinkSet.Node{ | |
| 194 | 196 | .data = null, |
| 195 | 197 | .next = undefined, |
| 196 | 198 | .prev = undefined, |
| 197 | }); | |
| 199 | }; | |
| 198 | 200 | errdefer comp.gpa().destroy(link_set_node); |
| 199 | 201 | |
| 200 | const self = try comp.gpa().create(Fn{ | |
| 202 | const self = try comp.gpa().create(Fn); | |
| 203 | self.* = Fn{ | |
| 201 | 204 | .base = Value{ |
| 202 | 205 | .id = Value.Id.Fn, |
| 203 | 206 | .typ = &fn_type.base, |
| ... | ... | @@ -209,7 +212,7 @@ pub const Value = struct { |
| 209 | 212 | .symbol_name = symbol_name, |
| 210 | 213 | .containing_object = Buffer.initNull(comp.gpa()), |
| 211 | 214 | .link_set_node = link_set_node, |
| 212 | }); | |
| 215 | }; | |
| 213 | 216 | fn_type.base.base.ref(); |
| 214 | 217 | fndef_scope.fn_val = self; |
| 215 | 218 | fndef_scope.base.ref(); |
| ... | ... | @@ -353,7 +356,8 @@ pub const Value = struct { |
| 353 | 356 | var ptr_type_consumed = false; |
| 354 | 357 | errdefer if (!ptr_type_consumed) ptr_type.base.base.deref(comp); |
| 355 | 358 | |
| 356 | const self = try comp.gpa().create(Value.Ptr{ | |
| 359 | const self = try comp.gpa().create(Value.Ptr); | |
| 360 | self.* = Value.Ptr{ | |
| 357 | 361 | .base = Value{ |
| 358 | 362 | .id = Value.Id.Ptr, |
| 359 | 363 | .typ = &ptr_type.base, |
| ... | ... | @@ -366,7 +370,7 @@ pub const Value = struct { |
| 366 | 370 | }, |
| 367 | 371 | }, |
| 368 | 372 | .mut = Mut.CompTimeConst, |
| 369 | }); | |
| 373 | }; | |
| 370 | 374 | ptr_type_consumed = true; |
| 371 | 375 | errdefer comp.gpa().destroy(self); |
| 372 | 376 | |
| ... | ... | @@ -430,14 +434,15 @@ pub const Value = struct { |
| 430 | 434 | }) catch unreachable); |
| 431 | 435 | errdefer array_type.base.base.deref(comp); |
| 432 | 436 | |
| 433 | const self = try comp.gpa().create(Value.Array{ | |
| 437 | const self = try comp.gpa().create(Value.Array); | |
| 438 | self.* = Value.Array{ | |
| 434 | 439 | .base = Value{ |
| 435 | 440 | .id = Value.Id.Array, |
| 436 | 441 | .typ = &array_type.base, |
| 437 | 442 | .ref_count = std.atomic.Int(usize).init(1), |
| 438 | 443 | }, |
| 439 | 444 | .special = Special{ .OwnedBuffer = buffer }, |
| 440 | }); | |
| 445 | }; | |
| 441 | 446 | errdefer comp.gpa().destroy(self); |
| 442 | 447 | |
| 443 | 448 | return self; |
| ... | ... | @@ -509,14 +514,15 @@ pub const Value = struct { |
| 509 | 514 | big_int: std.math.big.Int, |
| 510 | 515 | |
| 511 | 516 | pub fn createFromString(comp: *Compilation, typ: *Type, base: u8, value: []const u8) !*Int { |
| 512 | const self = try comp.gpa().create(Value.Int{ | |
| 517 | const self = try comp.gpa().create(Value.Int); | |
| 518 | self.* = Value.Int{ | |
| 513 | 519 | .base = Value{ |
| 514 | 520 | .id = Value.Id.Int, |
| 515 | 521 | .typ = typ, |
| 516 | 522 | .ref_count = std.atomic.Int(usize).init(1), |
| 517 | 523 | }, |
| 518 | 524 | .big_int = undefined, |
| 519 | }); | |
| 525 | }; | |
| 520 | 526 | typ.base.ref(); |
| 521 | 527 | errdefer comp.gpa().destroy(self); |
| 522 | 528 | |
| ... | ... | @@ -557,14 +563,15 @@ pub const Value = struct { |
| 557 | 563 | old.base.typ.base.ref(); |
| 558 | 564 | errdefer old.base.typ.base.deref(comp); |
| 559 | 565 | |
| 560 | const new = try comp.gpa().create(Value.Int{ | |
| 566 | const new = try comp.gpa().create(Value.Int); | |
| 567 | new.* = Value.Int{ | |
| 561 | 568 | .base = Value{ |
| 562 | 569 | .id = Value.Id.Int, |
| 563 | 570 | .typ = old.base.typ, |
| 564 | 571 | .ref_count = std.atomic.Int(usize).init(1), |
| 565 | 572 | }, |
| 566 | 573 | .big_int = undefined, |
| 567 | }); | |
| 574 | }; | |
| 568 | 575 | errdefer comp.gpa().destroy(new); |
| 569 | 576 | |
| 570 | 577 | new.big_int = try old.big_int.clone(); |
std/atomic/queue.zig+3-2| ... | ... | @@ -221,11 +221,12 @@ fn startPuts(ctx: *Context) u8 { |
| 221 | 221 | while (put_count != 0) : (put_count -= 1) { |
| 222 | 222 | std.os.time.sleep(1); // let the os scheduler be our fuzz |
| 223 | 223 | const x = @bitCast(i32, r.random.scalar(u32)); |
| 224 | const node = ctx.allocator.create(Queue(i32).Node{ | |
| 224 | const node = ctx.allocator.create(Queue(i32).Node) catch unreachable; | |
| 225 | node.* = Queue(i32).Node{ | |
| 225 | 226 | .prev = undefined, |
| 226 | 227 | .next = undefined, |
| 227 | 228 | .data = x, |
| 228 | }) catch unreachable; | |
| 229 | }; | |
| 229 | 230 | ctx.queue.put(node); |
| 230 | 231 | _ = @atomicRmw(isize, &ctx.put_sum, builtin.AtomicRmwOp.Add, x, AtomicOrder.SeqCst); |
| 231 | 232 | } |
std/atomic/stack.zig+3-2| ... | ... | @@ -155,10 +155,11 @@ fn startPuts(ctx: *Context) u8 { |
| 155 | 155 | while (put_count != 0) : (put_count -= 1) { |
| 156 | 156 | std.os.time.sleep(1); // let the os scheduler be our fuzz |
| 157 | 157 | const x = @bitCast(i32, r.random.scalar(u32)); |
| 158 | const node = ctx.allocator.create(Stack(i32).Node{ | |
| 158 | const node = ctx.allocator.create(Stack(i32).Node) catch unreachable; | |
| 159 | node.* = Stack(i32).Node{ | |
| 159 | 160 | .next = undefined, |
| 160 | 161 | .data = x, |
| 161 | }) catch unreachable; | |
| 162 | }; | |
| 162 | 163 | ctx.stack.push(node); |
| 163 | 164 | _ = @atomicRmw(isize, &ctx.put_sum, builtin.AtomicRmwOp.Add, x, AtomicOrder.SeqCst); |
| 164 | 165 | } |
std/build.zig+36-20| ... | ... | @@ -89,7 +89,7 @@ pub const Builder = struct { |
| 89 | 89 | }; |
| 90 | 90 | |
| 91 | 91 | pub fn init(allocator: *Allocator, zig_exe: []const u8, build_root: []const u8, cache_root: []const u8) Builder { |
| 92 | const env_map = allocator.createOne(BufMap) catch unreachable; | |
| 92 | const env_map = allocator.create(BufMap) catch unreachable; | |
| 93 | 93 | env_map.* = os.getEnvMap(allocator) catch unreachable; |
| 94 | 94 | var self = Builder{ |
| 95 | 95 | .zig_exe = zig_exe, |
| ... | ... | @@ -170,7 +170,8 @@ pub const Builder = struct { |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | pub fn addTest(self: *Builder, root_src: []const u8) *TestStep { |
| 173 | const test_step = self.allocator.create(TestStep.init(self, root_src)) catch unreachable; | |
| 173 | const test_step = self.allocator.create(TestStep) catch unreachable; | |
| 174 | test_step.* = TestStep.init(self, root_src); | |
| 174 | 175 | return test_step; |
| 175 | 176 | } |
| 176 | 177 | |
| ... | ... | @@ -202,18 +203,21 @@ pub const Builder = struct { |
| 202 | 203 | } |
| 203 | 204 | |
| 204 | 205 | pub fn addWriteFile(self: *Builder, file_path: []const u8, data: []const u8) *WriteFileStep { |
| 205 | const write_file_step = self.allocator.create(WriteFileStep.init(self, file_path, data)) catch unreachable; | |
| 206 | const write_file_step = self.allocator.create(WriteFileStep) catch unreachable; | |
| 207 | write_file_step.* = WriteFileStep.init(self, file_path, data); | |
| 206 | 208 | return write_file_step; |
| 207 | 209 | } |
| 208 | 210 | |
| 209 | 211 | pub fn addLog(self: *Builder, comptime format: []const u8, args: ...) *LogStep { |
| 210 | 212 | const data = self.fmt(format, args); |
| 211 | const log_step = self.allocator.create(LogStep.init(self, data)) catch unreachable; | |
| 213 | const log_step = self.allocator.create(LogStep) catch unreachable; | |
| 214 | log_step.* = LogStep.init(self, data); | |
| 212 | 215 | return log_step; |
| 213 | 216 | } |
| 214 | 217 | |
| 215 | 218 | pub fn addRemoveDirTree(self: *Builder, dir_path: []const u8) *RemoveDirStep { |
| 216 | const remove_dir_step = self.allocator.create(RemoveDirStep.init(self, dir_path)) catch unreachable; | |
| 219 | const remove_dir_step = self.allocator.create(RemoveDirStep) catch unreachable; | |
| 220 | remove_dir_step.* = RemoveDirStep.init(self, dir_path); | |
| 217 | 221 | return remove_dir_step; |
| 218 | 222 | } |
| 219 | 223 | |
| ... | ... | @@ -414,10 +418,11 @@ pub const Builder = struct { |
| 414 | 418 | } |
| 415 | 419 | |
| 416 | 420 | pub fn step(self: *Builder, name: []const u8, description: []const u8) *Step { |
| 417 | const step_info = self.allocator.create(TopLevelStep{ | |
| 421 | const step_info = self.allocator.create(TopLevelStep) catch unreachable; | |
| 422 | step_info.* = TopLevelStep{ | |
| 418 | 423 | .step = Step.initNoOp(name, self.allocator), |
| 419 | 424 | .description = description, |
| 420 | }) catch unreachable; | |
| 425 | }; | |
| 421 | 426 | self.top_level_steps.append(step_info) catch unreachable; |
| 422 | 427 | return &step_info.step; |
| 423 | 428 | } |
| ... | ... | @@ -616,7 +621,8 @@ pub const Builder = struct { |
| 616 | 621 | const full_dest_path = os.path.resolve(self.allocator, self.prefix, dest_rel_path) catch unreachable; |
| 617 | 622 | self.pushInstalledFile(full_dest_path); |
| 618 | 623 | |
| 619 | const install_step = self.allocator.create(InstallFileStep.init(self, src_path, full_dest_path)) catch unreachable; | |
| 624 | const install_step = self.allocator.create(InstallFileStep) catch unreachable; | |
| 625 | install_step.* = InstallFileStep.init(self, src_path, full_dest_path); | |
| 620 | 626 | return install_step; |
| 621 | 627 | } |
| 622 | 628 | |
| ... | ... | @@ -865,43 +871,51 @@ pub const LibExeObjStep = struct { |
| 865 | 871 | }; |
| 866 | 872 | |
| 867 | 873 | pub fn createSharedLibrary(builder: *Builder, name: []const u8, root_src: ?[]const u8, ver: Version) *LibExeObjStep { |
| 868 | const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Lib, false, ver)) catch unreachable; | |
| 874 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 875 | self.* = initExtraArgs(builder, name, root_src, Kind.Lib, false, ver); | |
| 869 | 876 | return self; |
| 870 | 877 | } |
| 871 | 878 | |
| 872 | 879 | pub fn createCSharedLibrary(builder: *Builder, name: []const u8, version: Version) *LibExeObjStep { |
| 873 | const self = builder.allocator.create(initC(builder, name, Kind.Lib, version, false)) catch unreachable; | |
| 880 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 881 | self.* = initC(builder, name, Kind.Lib, version, false); | |
| 874 | 882 | return self; |
| 875 | 883 | } |
| 876 | 884 | |
| 877 | 885 | pub fn createStaticLibrary(builder: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep { |
| 878 | const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0))) catch unreachable; | |
| 886 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 887 | self.* = initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0)); | |
| 879 | 888 | return self; |
| 880 | 889 | } |
| 881 | 890 | |
| 882 | 891 | pub fn createCStaticLibrary(builder: *Builder, name: []const u8) *LibExeObjStep { |
| 883 | const self = builder.allocator.create(initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true)) catch unreachable; | |
| 892 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 893 | self.* = initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true); | |
| 884 | 894 | return self; |
| 885 | 895 | } |
| 886 | 896 | |
| 887 | 897 | pub fn createObject(builder: *Builder, name: []const u8, root_src: []const u8) *LibExeObjStep { |
| 888 | const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0))) catch unreachable; | |
| 898 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 899 | self.* = initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0)); | |
| 889 | 900 | return self; |
| 890 | 901 | } |
| 891 | 902 | |
| 892 | 903 | pub fn createCObject(builder: *Builder, name: []const u8, src: []const u8) *LibExeObjStep { |
| 893 | const self = builder.allocator.create(initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false)) catch unreachable; | |
| 904 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 905 | self.* = initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false); | |
| 894 | 906 | self.object_src = src; |
| 895 | 907 | return self; |
| 896 | 908 | } |
| 897 | 909 | |
| 898 | 910 | pub fn createExecutable(builder: *Builder, name: []const u8, root_src: ?[]const u8, static: bool) *LibExeObjStep { |
| 899 | const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Exe, static, builder.version(0, 0, 0))) catch unreachable; | |
| 911 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 912 | self.* = initExtraArgs(builder, name, root_src, Kind.Exe, static, builder.version(0, 0, 0)); | |
| 900 | 913 | return self; |
| 901 | 914 | } |
| 902 | 915 | |
| 903 | 916 | pub fn createCExecutable(builder: *Builder, name: []const u8) *LibExeObjStep { |
| 904 | const self = builder.allocator.create(initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false)) catch unreachable; | |
| 917 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 918 | self.* = initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false); | |
| 905 | 919 | return self; |
| 906 | 920 | } |
| 907 | 921 | |
| ... | ... | @@ -1914,13 +1928,14 @@ pub const CommandStep = struct { |
| 1914 | 1928 | |
| 1915 | 1929 | /// ::argv is copied. |
| 1916 | 1930 | pub fn create(builder: *Builder, cwd: ?[]const u8, env_map: *const BufMap, argv: []const []const u8) *CommandStep { |
| 1917 | const self = builder.allocator.create(CommandStep{ | |
| 1931 | const self = builder.allocator.create(CommandStep) catch unreachable; | |
| 1932 | self.* = CommandStep{ | |
| 1918 | 1933 | .builder = builder, |
| 1919 | 1934 | .step = Step.init(argv[0], builder.allocator, make), |
| 1920 | 1935 | .argv = builder.allocator.alloc([]u8, argv.len) catch unreachable, |
| 1921 | 1936 | .cwd = cwd, |
| 1922 | 1937 | .env_map = env_map, |
| 1923 | }) catch unreachable; | |
| 1938 | }; | |
| 1924 | 1939 | |
| 1925 | 1940 | mem.copy([]const u8, self.argv, argv); |
| 1926 | 1941 | self.step.name = self.argv[0]; |
| ... | ... | @@ -1949,12 +1964,13 @@ const InstallArtifactStep = struct { |
| 1949 | 1964 | LibExeObjStep.Kind.Exe => builder.exe_dir, |
| 1950 | 1965 | LibExeObjStep.Kind.Lib => builder.lib_dir, |
| 1951 | 1966 | }; |
| 1952 | const self = builder.allocator.create(Self{ | |
| 1967 | const self = builder.allocator.create(Self) catch unreachable; | |
| 1968 | self.* = Self{ | |
| 1953 | 1969 | .builder = builder, |
| 1954 | 1970 | .step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make), |
| 1955 | 1971 | .artifact = artifact, |
| 1956 | 1972 | .dest_file = os.path.join(builder.allocator, dest_dir, artifact.out_filename) catch unreachable, |
| 1957 | }) catch unreachable; | |
| 1973 | }; | |
| 1958 | 1974 | self.step.dependOn(&artifact.step); |
| 1959 | 1975 | builder.pushInstalledFile(self.dest_file); |
| 1960 | 1976 | if (self.artifact.kind == LibExeObjStep.Kind.Lib and !self.artifact.static) { |
std/debug/index.zig+4-3| ... | ... | @@ -751,7 +751,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo { |
| 751 | 751 | const self_file = try os.openSelfExe(); |
| 752 | 752 | defer self_file.close(); |
| 753 | 753 | |
| 754 | const coff_obj = try allocator.createOne(coff.Coff); | |
| 754 | const coff_obj = try allocator.create(coff.Coff); | |
| 755 | 755 | coff_obj.* = coff.Coff{ |
| 756 | 756 | .in_file = self_file, |
| 757 | 757 | .allocator = allocator, |
| ... | ... | @@ -1036,7 +1036,7 @@ fn openSelfDebugInfoMacOs(allocator: *mem.Allocator) !DebugInfo { |
| 1036 | 1036 | } |
| 1037 | 1037 | } |
| 1038 | 1038 | } |
| 1039 | const sentinel = try allocator.createOne(macho.nlist_64); | |
| 1039 | const sentinel = try allocator.create(macho.nlist_64); | |
| 1040 | 1040 | sentinel.* = macho.nlist_64{ |
| 1041 | 1041 | .n_strx = 0, |
| 1042 | 1042 | .n_type = 36, |
| ... | ... | @@ -1949,7 +1949,8 @@ fn scanAllCompileUnits(di: *DwarfInfo) !void { |
| 1949 | 1949 | |
| 1950 | 1950 | try di.dwarf_seekable_stream.seekTo(compile_unit_pos); |
| 1951 | 1951 | |
| 1952 | const compile_unit_die = try di.allocator().create(try parseDie(di, abbrev_table, is_64)); | |
| 1952 | const compile_unit_die = try di.allocator().create(Die); | |
| 1953 | compile_unit_die.* = try parseDie(di, abbrev_table, is_64); | |
| 1953 | 1954 | |
| 1954 | 1955 | if (compile_unit_die.tag_id != DW.TAG_compile_unit) return error.InvalidDebugInfo; |
| 1955 | 1956 |
std/event/channel.zig+3-2| ... | ... | @@ -54,7 +54,8 @@ pub fn Channel(comptime T: type) type { |
| 54 | 54 | const buffer_nodes = try loop.allocator.alloc(T, capacity); |
| 55 | 55 | errdefer loop.allocator.free(buffer_nodes); |
| 56 | 56 | |
| 57 | const self = try loop.allocator.create(SelfChannel{ | |
| 57 | const self = try loop.allocator.create(SelfChannel); | |
| 58 | self.* = SelfChannel{ | |
| 58 | 59 | .loop = loop, |
| 59 | 60 | .buffer_len = 0, |
| 60 | 61 | .buffer_nodes = buffer_nodes, |
| ... | ... | @@ -66,7 +67,7 @@ pub fn Channel(comptime T: type) type { |
| 66 | 67 | .or_null_queue = std.atomic.Queue(*std.atomic.Queue(GetNode).Node).init(), |
| 67 | 68 | .get_count = 0, |
| 68 | 69 | .put_count = 0, |
| 69 | }); | |
| 70 | }; | |
| 70 | 71 | errdefer loop.allocator.destroy(self); |
| 71 | 72 | |
| 72 | 73 | return self; |
std/event/fs.zig+4-4| ... | ... | @@ -495,7 +495,7 @@ pub const CloseOperation = struct { |
| 495 | 495 | }; |
| 496 | 496 | |
| 497 | 497 | pub fn start(loop: *Loop) (error{OutOfMemory}!*CloseOperation) { |
| 498 | const self = try loop.allocator.createOne(CloseOperation); | |
| 498 | const self = try loop.allocator.create(CloseOperation); | |
| 499 | 499 | self.* = CloseOperation{ |
| 500 | 500 | .loop = loop, |
| 501 | 501 | .os_data = switch (builtin.os) { |
| ... | ... | @@ -787,7 +787,7 @@ pub fn Watch(comptime V: type) type { |
| 787 | 787 | }, |
| 788 | 788 | |
| 789 | 789 | builtin.Os.windows => { |
| 790 | const self = try loop.allocator.createOne(Self); | |
| 790 | const self = try loop.allocator.create(Self); | |
| 791 | 791 | errdefer loop.allocator.destroy(self); |
| 792 | 792 | self.* = Self{ |
| 793 | 793 | .channel = channel, |
| ... | ... | @@ -802,7 +802,7 @@ pub fn Watch(comptime V: type) type { |
| 802 | 802 | }, |
| 803 | 803 | |
| 804 | 804 | builtin.Os.macosx, builtin.Os.freebsd => { |
| 805 | const self = try loop.allocator.createOne(Self); | |
| 805 | const self = try loop.allocator.create(Self); | |
| 806 | 806 | errdefer loop.allocator.destroy(self); |
| 807 | 807 | |
| 808 | 808 | self.* = Self{ |
| ... | ... | @@ -1068,7 +1068,7 @@ pub fn Watch(comptime V: type) type { |
| 1068 | 1068 | } |
| 1069 | 1069 | } else { |
| 1070 | 1070 | errdefer _ = self.os_data.dir_table.remove(dirname); |
| 1071 | const dir = try self.channel.loop.allocator.createOne(OsData.Dir); | |
| 1071 | const dir = try self.channel.loop.allocator.create(OsData.Dir); | |
| 1072 | 1072 | errdefer self.channel.loop.allocator.destroy(dir); |
| 1073 | 1073 | |
| 1074 | 1074 | dir.* = OsData.Dir{ |
std/event/group.zig+3-2| ... | ... | @@ -42,10 +42,11 @@ pub fn Group(comptime ReturnType: type) type { |
| 42 | 42 | |
| 43 | 43 | /// Add a promise to the group. Thread-safe. |
| 44 | 44 | pub fn add(self: *Self, handle: promise->ReturnType) (error{OutOfMemory}!void) { |
| 45 | const node = try self.lock.loop.allocator.create(Stack.Node{ | |
| 45 | const node = try self.lock.loop.allocator.create(Stack.Node); | |
| 46 | node.* = Stack.Node{ | |
| 46 | 47 | .next = undefined, |
| 47 | 48 | .data = handle, |
| 48 | }); | |
| 49 | }; | |
| 49 | 50 | self.alloc_stack.push(node); |
| 50 | 51 | } |
| 51 | 52 |
std/heap.zig+2-1| ... | ... | @@ -518,7 +518,8 @@ fn testAllocator(allocator: *mem.Allocator) !void { |
| 518 | 518 | var slice = try allocator.alloc(*i32, 100); |
| 519 | 519 | assert(slice.len == 100); |
| 520 | 520 | for (slice) |*item, i| { |
| 521 | item.* = try allocator.create(@intCast(i32, i)); | |
| 521 | item.* = try allocator.create(i32); | |
| 522 | item.*.* = @intCast(i32, i); | |
| 522 | 523 | } |
| 523 | 524 | |
| 524 | 525 | slice = try allocator.realloc(*i32, slice, 20000); |
std/io.zig+3-2| ... | ... | @@ -944,12 +944,13 @@ pub const BufferedAtomicFile = struct { |
| 944 | 944 | |
| 945 | 945 | pub fn create(allocator: *mem.Allocator, dest_path: []const u8) !*BufferedAtomicFile { |
| 946 | 946 | // TODO with well defined copy elision we don't need this allocation |
| 947 | var self = try allocator.create(BufferedAtomicFile{ | |
| 947 | var self = try allocator.create(BufferedAtomicFile); | |
| 948 | self.* = BufferedAtomicFile{ | |
| 948 | 949 | .atomic_file = undefined, |
| 949 | 950 | .file_stream = undefined, |
| 950 | 951 | .buffered_stream = undefined, |
| 951 | 952 | .allocator = allocator, |
| 952 | }); | |
| 953 | }; | |
| 953 | 954 | errdefer allocator.destroy(self); |
| 954 | 955 | |
| 955 | 956 | self.atomic_file = try os.AtomicFile.init(dest_path, os.File.default_mode); |
std/linked_list.zig+1-1| ... | ... | @@ -190,7 +190,7 @@ pub fn LinkedList(comptime T: type) type { |
| 190 | 190 | /// Returns: |
| 191 | 191 | /// A pointer to the new node. |
| 192 | 192 | pub fn allocateNode(list: *Self, allocator: *Allocator) !*Node { |
| 193 | return allocator.create(Node(undefined)); | |
| 193 | return allocator.create(Node); | |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /// Deallocate a node. |
std/mem.zig+1-12| ... | ... | @@ -36,20 +36,9 @@ pub const Allocator = struct { |
| 36 | 36 | /// Guaranteed: `old_mem.len` is the same as what was returned from `allocFn` or `reallocFn` |
| 37 | 37 | freeFn: fn (self: *Allocator, old_mem: []u8) void, |
| 38 | 38 | |
| 39 | /// Call `destroy` with the result | |
| 40 | /// TODO this is deprecated. use createOne instead | |
| 41 | pub fn create(self: *Allocator, init: var) Error!*@typeOf(init) { | |
| 42 | const T = @typeOf(init); | |
| 43 | if (@sizeOf(T) == 0) return &(T{}); | |
| 44 | const slice = try self.alloc(T, 1); | |
| 45 | const ptr = &slice[0]; | |
| 46 | ptr.* = init; | |
| 47 | return ptr; | |
| 48 | } | |
| 49 | ||
| 50 | 39 | /// Call `destroy` with the result. |
| 51 | 40 | /// Returns undefined memory. |
| 52 | pub fn createOne(self: *Allocator, comptime T: type) Error!*T { | |
| 41 | pub fn create(self: *Allocator, comptime T: type) Error!*T { | |
| 53 | 42 | if (@sizeOf(T) == 0) return &(T{}); |
| 54 | 43 | const slice = try self.alloc(T, 1); |
| 55 | 44 | return &slice[0]; |
std/os/child_process.zig+3-2| ... | ... | @@ -88,7 +88,8 @@ pub const ChildProcess = struct { |
| 88 | 88 | /// First argument in argv is the executable. |
| 89 | 89 | /// On success must call deinit. |
| 90 | 90 | pub fn init(argv: []const []const u8, allocator: *mem.Allocator) !*ChildProcess { |
| 91 | const child = try allocator.create(ChildProcess{ | |
| 91 | const child = try allocator.create(ChildProcess); | |
| 92 | child.* = ChildProcess{ | |
| 92 | 93 | .allocator = allocator, |
| 93 | 94 | .argv = argv, |
| 94 | 95 | .pid = undefined, |
| ... | ... | @@ -109,7 +110,7 @@ pub const ChildProcess = struct { |
| 109 | 110 | .stdin_behavior = StdIo.Inherit, |
| 110 | 111 | .stdout_behavior = StdIo.Inherit, |
| 111 | 112 | .stderr_behavior = StdIo.Inherit, |
| 112 | }); | |
| 113 | }; | |
| 113 | 114 | errdefer allocator.destroy(child); |
| 114 | 115 | return child; |
| 115 | 116 | } |
std/os/index.zig+3-2| ... | ... | @@ -3047,7 +3047,8 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread |
| 3047 | 3047 | const bytes_ptr = windows.HeapAlloc(heap_handle, 0, byte_count) orelse return SpawnThreadError.OutOfMemory; |
| 3048 | 3048 | errdefer assert(windows.HeapFree(heap_handle, 0, bytes_ptr) != 0); |
| 3049 | 3049 | const bytes = @ptrCast([*]u8, bytes_ptr)[0..byte_count]; |
| 3050 | const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext{ | |
| 3050 | const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext) catch unreachable; | |
| 3051 | outer_context.* = WinThread.OuterContext{ | |
| 3051 | 3052 | .thread = Thread{ |
| 3052 | 3053 | .data = Thread.Data{ |
| 3053 | 3054 | .heap_handle = heap_handle, |
| ... | ... | @@ -3056,7 +3057,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread |
| 3056 | 3057 | }, |
| 3057 | 3058 | }, |
| 3058 | 3059 | .inner = context, |
| 3059 | }) catch unreachable; | |
| 3060 | }; | |
| 3060 | 3061 | |
| 3061 | 3062 | const parameter = if (@sizeOf(Context) == 0) null else @ptrCast(*c_void, &outer_context.inner); |
| 3062 | 3063 | outer_context.thread.data.handle = windows.CreateThread(null, default_stack_size, WinThread.threadMain, parameter, 0, null) orelse { |
std/zig/parse.zig+226-150| ... | ... | @@ -17,14 +17,15 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 17 | 17 | defer stack.deinit(); |
| 18 | 18 | |
| 19 | 19 | const arena = &tree_arena.allocator; |
| 20 | const root_node = try arena.create(ast.Node.Root{ | |
| 20 | const root_node = try arena.create(ast.Node.Root); | |
| 21 | root_node.* = ast.Node.Root{ | |
| 21 | 22 | .base = ast.Node{ .id = ast.Node.Id.Root }, |
| 22 | 23 | .decls = ast.Node.Root.DeclList.init(arena), |
| 23 | 24 | .doc_comments = null, |
| 24 | 25 | .shebang = null, |
| 25 | 26 | // initialized when we get the eof token |
| 26 | 27 | .eof_token = undefined, |
| 27 | }); | |
| 28 | }; | |
| 28 | 29 | |
| 29 | 30 | var tree = ast.Tree{ |
| 30 | 31 | .source = source, |
| ... | ... | @@ -75,20 +76,22 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 75 | 76 | Token.Id.Keyword_test => { |
| 76 | 77 | stack.append(State.TopLevel) catch unreachable; |
| 77 | 78 | |
| 78 | const block = try arena.create(ast.Node.Block{ | |
| 79 | const block = try arena.create(ast.Node.Block); | |
| 80 | block.* = ast.Node.Block{ | |
| 79 | 81 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 80 | 82 | .label = null, |
| 81 | 83 | .lbrace = undefined, |
| 82 | 84 | .statements = ast.Node.Block.StatementList.init(arena), |
| 83 | 85 | .rbrace = undefined, |
| 84 | }); | |
| 85 | const test_node = try arena.create(ast.Node.TestDecl{ | |
| 86 | }; | |
| 87 | const test_node = try arena.create(ast.Node.TestDecl); | |
| 88 | test_node.* = ast.Node.TestDecl{ | |
| 86 | 89 | .base = ast.Node{ .id = ast.Node.Id.TestDecl }, |
| 87 | 90 | .doc_comments = comments, |
| 88 | 91 | .test_token = token_index, |
| 89 | 92 | .name = undefined, |
| 90 | 93 | .body_node = &block.base, |
| 91 | }); | |
| 94 | }; | |
| 92 | 95 | try root_node.decls.push(&test_node.base); |
| 93 | 96 | try stack.append(State{ .Block = block }); |
| 94 | 97 | try stack.append(State{ |
| ... | ... | @@ -119,19 +122,21 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 119 | 122 | continue; |
| 120 | 123 | }, |
| 121 | 124 | Token.Id.Keyword_comptime => { |
| 122 | const block = try arena.create(ast.Node.Block{ | |
| 125 | const block = try arena.create(ast.Node.Block); | |
| 126 | block.* = ast.Node.Block{ | |
| 123 | 127 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 124 | 128 | .label = null, |
| 125 | 129 | .lbrace = undefined, |
| 126 | 130 | .statements = ast.Node.Block.StatementList.init(arena), |
| 127 | 131 | .rbrace = undefined, |
| 128 | }); | |
| 129 | const node = try arena.create(ast.Node.Comptime{ | |
| 132 | }; | |
| 133 | const node = try arena.create(ast.Node.Comptime); | |
| 134 | node.* = ast.Node.Comptime{ | |
| 130 | 135 | .base = ast.Node{ .id = ast.Node.Id.Comptime }, |
| 131 | 136 | .comptime_token = token_index, |
| 132 | 137 | .expr = &block.base, |
| 133 | 138 | .doc_comments = comments, |
| 134 | }); | |
| 139 | }; | |
| 135 | 140 | try root_node.decls.push(&node.base); |
| 136 | 141 | |
| 137 | 142 | stack.append(State.TopLevel) catch unreachable; |
| ... | ... | @@ -235,14 +240,15 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 235 | 240 | return tree; |
| 236 | 241 | } |
| 237 | 242 | |
| 238 | const node = try arena.create(ast.Node.Use{ | |
| 243 | const node = try arena.create(ast.Node.Use); | |
| 244 | node.* = ast.Node.Use{ | |
| 239 | 245 | .base = ast.Node{ .id = ast.Node.Id.Use }, |
| 240 | 246 | .use_token = token_index, |
| 241 | 247 | .visib_token = ctx.visib_token, |
| 242 | 248 | .expr = undefined, |
| 243 | 249 | .semicolon_token = undefined, |
| 244 | 250 | .doc_comments = ctx.comments, |
| 245 | }); | |
| 251 | }; | |
| 246 | 252 | try ctx.decls.push(&node.base); |
| 247 | 253 | |
| 248 | 254 | stack.append(State{ |
| ... | ... | @@ -276,7 +282,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 276 | 282 | continue; |
| 277 | 283 | }, |
| 278 | 284 | Token.Id.Keyword_fn, Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc, Token.Id.Keyword_async => { |
| 279 | const fn_proto = try arena.create(ast.Node.FnProto{ | |
| 285 | const fn_proto = try arena.create(ast.Node.FnProto); | |
| 286 | fn_proto.* = ast.Node.FnProto{ | |
| 280 | 287 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, |
| 281 | 288 | .doc_comments = ctx.comments, |
| 282 | 289 | .visib_token = ctx.visib_token, |
| ... | ... | @@ -292,7 +299,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 292 | 299 | .lib_name = ctx.lib_name, |
| 293 | 300 | .align_expr = null, |
| 294 | 301 | .section_expr = null, |
| 295 | }); | |
| 302 | }; | |
| 296 | 303 | try ctx.decls.push(&fn_proto.base); |
| 297 | 304 | stack.append(State{ .FnDef = fn_proto }) catch unreachable; |
| 298 | 305 | try stack.append(State{ .FnProto = fn_proto }); |
| ... | ... | @@ -309,12 +316,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 309 | 316 | continue; |
| 310 | 317 | }, |
| 311 | 318 | Token.Id.Keyword_async => { |
| 312 | const async_node = try arena.create(ast.Node.AsyncAttribute{ | |
| 319 | const async_node = try arena.create(ast.Node.AsyncAttribute); | |
| 320 | async_node.* = ast.Node.AsyncAttribute{ | |
| 313 | 321 | .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute }, |
| 314 | 322 | .async_token = token_index, |
| 315 | 323 | .allocator_type = null, |
| 316 | 324 | .rangle_bracket = null, |
| 317 | }); | |
| 325 | }; | |
| 318 | 326 | fn_proto.async_attr = async_node; |
| 319 | 327 | |
| 320 | 328 | try stack.append(State{ |
| ... | ... | @@ -341,13 +349,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 341 | 349 | }, |
| 342 | 350 | State.TopLevelExternOrField => |ctx| { |
| 343 | 351 | if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |identifier| { |
| 344 | const node = try arena.create(ast.Node.StructField{ | |
| 352 | const node = try arena.create(ast.Node.StructField); | |
| 353 | node.* = ast.Node.StructField{ | |
| 345 | 354 | .base = ast.Node{ .id = ast.Node.Id.StructField }, |
| 346 | 355 | .doc_comments = ctx.comments, |
| 347 | 356 | .visib_token = ctx.visib_token, |
| 348 | 357 | .name_token = identifier, |
| 349 | 358 | .type_expr = undefined, |
| 350 | }); | |
| 359 | }; | |
| 351 | 360 | const node_ptr = try ctx.container_decl.fields_and_decls.addOne(); |
| 352 | 361 | node_ptr.* = &node.base; |
| 353 | 362 | |
| ... | ... | @@ -391,7 +400,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 391 | 400 | const token = nextToken(&tok_it, &tree); |
| 392 | 401 | const token_index = token.index; |
| 393 | 402 | const token_ptr = token.ptr; |
| 394 | const node = try arena.create(ast.Node.ContainerDecl{ | |
| 403 | const node = try arena.create(ast.Node.ContainerDecl); | |
| 404 | node.* = ast.Node.ContainerDecl{ | |
| 395 | 405 | .base = ast.Node{ .id = ast.Node.Id.ContainerDecl }, |
| 396 | 406 | .layout_token = ctx.layout_token, |
| 397 | 407 | .kind_token = switch (token_ptr.id) { |
| ... | ... | @@ -405,7 +415,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 405 | 415 | .fields_and_decls = ast.Node.ContainerDecl.DeclList.init(arena), |
| 406 | 416 | .lbrace_token = undefined, |
| 407 | 417 | .rbrace_token = undefined, |
| 408 | }); | |
| 418 | }; | |
| 409 | 419 | ctx.opt_ctx.store(&node.base); |
| 410 | 420 | |
| 411 | 421 | stack.append(State{ .ContainerDecl = node }) catch unreachable; |
| ... | ... | @@ -464,13 +474,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 464 | 474 | Token.Id.Identifier => { |
| 465 | 475 | switch (tree.tokens.at(container_decl.kind_token).id) { |
| 466 | 476 | Token.Id.Keyword_struct => { |
| 467 | const node = try arena.create(ast.Node.StructField{ | |
| 477 | const node = try arena.create(ast.Node.StructField); | |
| 478 | node.* = ast.Node.StructField{ | |
| 468 | 479 | .base = ast.Node{ .id = ast.Node.Id.StructField }, |
| 469 | 480 | .doc_comments = comments, |
| 470 | 481 | .visib_token = null, |
| 471 | 482 | .name_token = token_index, |
| 472 | 483 | .type_expr = undefined, |
| 473 | }); | |
| 484 | }; | |
| 474 | 485 | const node_ptr = try container_decl.fields_and_decls.addOne(); |
| 475 | 486 | node_ptr.* = &node.base; |
| 476 | 487 | |
| ... | ... | @@ -485,13 +496,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 485 | 496 | continue; |
| 486 | 497 | }, |
| 487 | 498 | Token.Id.Keyword_union => { |
| 488 | const node = try arena.create(ast.Node.UnionTag{ | |
| 499 | const node = try arena.create(ast.Node.UnionTag); | |
| 500 | node.* = ast.Node.UnionTag{ | |
| 489 | 501 | .base = ast.Node{ .id = ast.Node.Id.UnionTag }, |
| 490 | 502 | .name_token = token_index, |
| 491 | 503 | .type_expr = null, |
| 492 | 504 | .value_expr = null, |
| 493 | 505 | .doc_comments = comments, |
| 494 | }); | |
| 506 | }; | |
| 495 | 507 | try container_decl.fields_and_decls.push(&node.base); |
| 496 | 508 | |
| 497 | 509 | try stack.append(State{ |
| ... | ... | @@ -506,12 +518,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 506 | 518 | continue; |
| 507 | 519 | }, |
| 508 | 520 | Token.Id.Keyword_enum => { |
| 509 | const node = try arena.create(ast.Node.EnumTag{ | |
| 521 | const node = try arena.create(ast.Node.EnumTag); | |
| 522 | node.* = ast.Node.EnumTag{ | |
| 510 | 523 | .base = ast.Node{ .id = ast.Node.Id.EnumTag }, |
| 511 | 524 | .name_token = token_index, |
| 512 | 525 | .value = null, |
| 513 | 526 | .doc_comments = comments, |
| 514 | }); | |
| 527 | }; | |
| 515 | 528 | try container_decl.fields_and_decls.push(&node.base); |
| 516 | 529 | |
| 517 | 530 | try stack.append(State{ |
| ... | ... | @@ -593,7 +606,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 593 | 606 | }, |
| 594 | 607 | |
| 595 | 608 | State.VarDecl => |ctx| { |
| 596 | const var_decl = try arena.create(ast.Node.VarDecl{ | |
| 609 | const var_decl = try arena.create(ast.Node.VarDecl); | |
| 610 | var_decl.* = ast.Node.VarDecl{ | |
| 597 | 611 | .base = ast.Node{ .id = ast.Node.Id.VarDecl }, |
| 598 | 612 | .doc_comments = ctx.comments, |
| 599 | 613 | .visib_token = ctx.visib_token, |
| ... | ... | @@ -609,7 +623,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 609 | 623 | .name_token = undefined, |
| 610 | 624 | .eq_token = undefined, |
| 611 | 625 | .semicolon_token = undefined, |
| 612 | }); | |
| 626 | }; | |
| 613 | 627 | try ctx.list.push(&var_decl.base); |
| 614 | 628 | |
| 615 | 629 | try stack.append(State{ .VarDeclAlign = var_decl }); |
| ... | ... | @@ -708,13 +722,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 708 | 722 | const token_ptr = token.ptr; |
| 709 | 723 | switch (token_ptr.id) { |
| 710 | 724 | Token.Id.LBrace => { |
| 711 | const block = try arena.create(ast.Node.Block{ | |
| 725 | const block = try arena.create(ast.Node.Block); | |
| 726 | block.* = ast.Node.Block{ | |
| 712 | 727 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 713 | 728 | .label = null, |
| 714 | 729 | .lbrace = token_index, |
| 715 | 730 | .statements = ast.Node.Block.StatementList.init(arena), |
| 716 | 731 | .rbrace = undefined, |
| 717 | }); | |
| 732 | }; | |
| 718 | 733 | fn_proto.body_node = &block.base; |
| 719 | 734 | stack.append(State{ .Block = block }) catch unreachable; |
| 720 | 735 | continue; |
| ... | ... | @@ -770,10 +785,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 770 | 785 | // TODO: this is a special case. Remove this when #760 is fixed |
| 771 | 786 | if (token_ptr.id == Token.Id.Keyword_anyerror) { |
| 772 | 787 | if (tok_it.peek().?.id == Token.Id.LBrace) { |
| 773 | const error_type_node = try arena.create(ast.Node.ErrorType{ | |
| 788 | const error_type_node = try arena.create(ast.Node.ErrorType); | |
| 789 | error_type_node.* = ast.Node.ErrorType{ | |
| 774 | 790 | .base = ast.Node{ .id = ast.Node.Id.ErrorType }, |
| 775 | 791 | .token = token_index, |
| 776 | }); | |
| 792 | }; | |
| 777 | 793 | fn_proto.return_type = ast.Node.FnProto.ReturnType{ .Explicit = &error_type_node.base }; |
| 778 | 794 | continue; |
| 779 | 795 | } |
| ... | ... | @@ -791,14 +807,15 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 791 | 807 | if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| { |
| 792 | 808 | continue; |
| 793 | 809 | } |
| 794 | const param_decl = try arena.create(ast.Node.ParamDecl{ | |
| 810 | const param_decl = try arena.create(ast.Node.ParamDecl); | |
| 811 | param_decl.* = ast.Node.ParamDecl{ | |
| 795 | 812 | .base = ast.Node{ .id = ast.Node.Id.ParamDecl }, |
| 796 | 813 | .comptime_token = null, |
| 797 | 814 | .noalias_token = null, |
| 798 | 815 | .name_token = null, |
| 799 | 816 | .type_node = undefined, |
| 800 | 817 | .var_args_token = null, |
| 801 | }); | |
| 818 | }; | |
| 802 | 819 | try fn_proto.params.push(&param_decl.base); |
| 803 | 820 | |
| 804 | 821 | stack.append(State{ |
| ... | ... | @@ -877,13 +894,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 877 | 894 | const token_ptr = token.ptr; |
| 878 | 895 | switch (token_ptr.id) { |
| 879 | 896 | Token.Id.LBrace => { |
| 880 | const block = try arena.create(ast.Node.Block{ | |
| 897 | const block = try arena.create(ast.Node.Block); | |
| 898 | block.* = ast.Node.Block{ | |
| 881 | 899 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 882 | 900 | .label = ctx.label, |
| 883 | 901 | .lbrace = token_index, |
| 884 | 902 | .statements = ast.Node.Block.StatementList.init(arena), |
| 885 | 903 | .rbrace = undefined, |
| 886 | }); | |
| 904 | }; | |
| 887 | 905 | ctx.opt_ctx.store(&block.base); |
| 888 | 906 | stack.append(State{ .Block = block }) catch unreachable; |
| 889 | 907 | continue; |
| ... | ... | @@ -970,7 +988,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 970 | 988 | } |
| 971 | 989 | }, |
| 972 | 990 | State.While => |ctx| { |
| 973 | const node = try arena.create(ast.Node.While{ | |
| 991 | const node = try arena.create(ast.Node.While); | |
| 992 | node.* = ast.Node.While{ | |
| 974 | 993 | .base = ast.Node{ .id = ast.Node.Id.While }, |
| 975 | 994 | .label = ctx.label, |
| 976 | 995 | .inline_token = ctx.inline_token, |
| ... | ... | @@ -980,7 +999,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 980 | 999 | .continue_expr = null, |
| 981 | 1000 | .body = undefined, |
| 982 | 1001 | .@"else" = null, |
| 983 | }); | |
| 1002 | }; | |
| 984 | 1003 | ctx.opt_ctx.store(&node.base); |
| 985 | 1004 | stack.append(State{ .Else = &node.@"else" }) catch unreachable; |
| 986 | 1005 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.body } }); |
| ... | ... | @@ -999,7 +1018,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 999 | 1018 | continue; |
| 1000 | 1019 | }, |
| 1001 | 1020 | State.For => |ctx| { |
| 1002 | const node = try arena.create(ast.Node.For{ | |
| 1021 | const node = try arena.create(ast.Node.For); | |
| 1022 | node.* = ast.Node.For{ | |
| 1003 | 1023 | .base = ast.Node{ .id = ast.Node.Id.For }, |
| 1004 | 1024 | .label = ctx.label, |
| 1005 | 1025 | .inline_token = ctx.inline_token, |
| ... | ... | @@ -1008,7 +1028,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1008 | 1028 | .payload = null, |
| 1009 | 1029 | .body = undefined, |
| 1010 | 1030 | .@"else" = null, |
| 1011 | }); | |
| 1031 | }; | |
| 1012 | 1032 | ctx.opt_ctx.store(&node.base); |
| 1013 | 1033 | stack.append(State{ .Else = &node.@"else" }) catch unreachable; |
| 1014 | 1034 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.body } }); |
| ... | ... | @@ -1020,12 +1040,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1020 | 1040 | }, |
| 1021 | 1041 | State.Else => |dest| { |
| 1022 | 1042 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| { |
| 1023 | const node = try arena.create(ast.Node.Else{ | |
| 1043 | const node = try arena.create(ast.Node.Else); | |
| 1044 | node.* = ast.Node.Else{ | |
| 1024 | 1045 | .base = ast.Node{ .id = ast.Node.Id.Else }, |
| 1025 | 1046 | .else_token = else_token, |
| 1026 | 1047 | .payload = null, |
| 1027 | 1048 | .body = undefined, |
| 1028 | }); | |
| 1049 | }; | |
| 1029 | 1050 | dest.* = node; |
| 1030 | 1051 | |
| 1031 | 1052 | stack.append(State{ .Expression = OptionalCtx{ .Required = &node.body } }) catch unreachable; |
| ... | ... | @@ -1083,11 +1104,12 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1083 | 1104 | continue; |
| 1084 | 1105 | }, |
| 1085 | 1106 | Token.Id.Keyword_defer, Token.Id.Keyword_errdefer => { |
| 1086 | const node = try arena.create(ast.Node.Defer{ | |
| 1107 | const node = try arena.create(ast.Node.Defer); | |
| 1108 | node.* = ast.Node.Defer{ | |
| 1087 | 1109 | .base = ast.Node{ .id = ast.Node.Id.Defer }, |
| 1088 | 1110 | .defer_token = token_index, |
| 1089 | 1111 | .expr = undefined, |
| 1090 | }); | |
| 1112 | }; | |
| 1091 | 1113 | const node_ptr = try block.statements.addOne(); |
| 1092 | 1114 | node_ptr.* = &node.base; |
| 1093 | 1115 | |
| ... | ... | @@ -1096,13 +1118,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1096 | 1118 | continue; |
| 1097 | 1119 | }, |
| 1098 | 1120 | Token.Id.LBrace => { |
| 1099 | const inner_block = try arena.create(ast.Node.Block{ | |
| 1121 | const inner_block = try arena.create(ast.Node.Block); | |
| 1122 | inner_block.* = ast.Node.Block{ | |
| 1100 | 1123 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 1101 | 1124 | .label = null, |
| 1102 | 1125 | .lbrace = token_index, |
| 1103 | 1126 | .statements = ast.Node.Block.StatementList.init(arena), |
| 1104 | 1127 | .rbrace = undefined, |
| 1105 | }); | |
| 1128 | }; | |
| 1106 | 1129 | try block.statements.push(&inner_block.base); |
| 1107 | 1130 | |
| 1108 | 1131 | stack.append(State{ .Block = inner_block }) catch unreachable; |
| ... | ... | @@ -1164,14 +1187,15 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1164 | 1187 | continue; |
| 1165 | 1188 | } |
| 1166 | 1189 | |
| 1167 | const node = try arena.create(ast.Node.AsmOutput{ | |
| 1190 | const node = try arena.create(ast.Node.AsmOutput); | |
| 1191 | node.* = ast.Node.AsmOutput{ | |
| 1168 | 1192 | .base = ast.Node{ .id = ast.Node.Id.AsmOutput }, |
| 1169 | 1193 | .lbracket = lbracket_index, |
| 1170 | 1194 | .symbolic_name = undefined, |
| 1171 | 1195 | .constraint = undefined, |
| 1172 | 1196 | .kind = undefined, |
| 1173 | 1197 | .rparen = undefined, |
| 1174 | }); | |
| 1198 | }; | |
| 1175 | 1199 | try items.push(node); |
| 1176 | 1200 | |
| 1177 | 1201 | stack.append(State{ .AsmOutputItems = items }) catch unreachable; |
| ... | ... | @@ -1218,14 +1242,15 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1218 | 1242 | continue; |
| 1219 | 1243 | } |
| 1220 | 1244 | |
| 1221 | const node = try arena.create(ast.Node.AsmInput{ | |
| 1245 | const node = try arena.create(ast.Node.AsmInput); | |
| 1246 | node.* = ast.Node.AsmInput{ | |
| 1222 | 1247 | .base = ast.Node{ .id = ast.Node.Id.AsmInput }, |
| 1223 | 1248 | .lbracket = lbracket_index, |
| 1224 | 1249 | .symbolic_name = undefined, |
| 1225 | 1250 | .constraint = undefined, |
| 1226 | 1251 | .expr = undefined, |
| 1227 | 1252 | .rparen = undefined, |
| 1228 | }); | |
| 1253 | }; | |
| 1229 | 1254 | try items.push(node); |
| 1230 | 1255 | |
| 1231 | 1256 | stack.append(State{ .AsmInputItems = items }) catch unreachable; |
| ... | ... | @@ -1283,12 +1308,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1283 | 1308 | continue; |
| 1284 | 1309 | } |
| 1285 | 1310 | |
| 1286 | const node = try arena.create(ast.Node.FieldInitializer{ | |
| 1311 | const node = try arena.create(ast.Node.FieldInitializer); | |
| 1312 | node.* = ast.Node.FieldInitializer{ | |
| 1287 | 1313 | .base = ast.Node{ .id = ast.Node.Id.FieldInitializer }, |
| 1288 | 1314 | .period_token = undefined, |
| 1289 | 1315 | .name_token = undefined, |
| 1290 | 1316 | .expr = undefined, |
| 1291 | }); | |
| 1317 | }; | |
| 1292 | 1318 | try list_state.list.push(&node.base); |
| 1293 | 1319 | |
| 1294 | 1320 | stack.append(State{ .FieldInitListCommaOrEnd = list_state }) catch unreachable; |
| ... | ... | @@ -1390,13 +1416,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1390 | 1416 | } |
| 1391 | 1417 | |
| 1392 | 1418 | const comments = try eatDocComments(arena, &tok_it, &tree); |
| 1393 | const node = try arena.create(ast.Node.SwitchCase{ | |
| 1419 | const node = try arena.create(ast.Node.SwitchCase); | |
| 1420 | node.* = ast.Node.SwitchCase{ | |
| 1394 | 1421 | .base = ast.Node{ .id = ast.Node.Id.SwitchCase }, |
| 1395 | 1422 | .items = ast.Node.SwitchCase.ItemList.init(arena), |
| 1396 | 1423 | .payload = null, |
| 1397 | 1424 | .expr = undefined, |
| 1398 | 1425 | .arrow_token = undefined, |
| 1399 | }); | |
| 1426 | }; | |
| 1400 | 1427 | try list_state.list.push(&node.base); |
| 1401 | 1428 | try stack.append(State{ .SwitchCaseCommaOrEnd = list_state }); |
| 1402 | 1429 | try stack.append(State{ .AssignmentExpressionBegin = OptionalCtx{ .Required = &node.expr } }); |
| ... | ... | @@ -1427,10 +1454,11 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1427 | 1454 | const token_index = token.index; |
| 1428 | 1455 | const token_ptr = token.ptr; |
| 1429 | 1456 | if (token_ptr.id == Token.Id.Keyword_else) { |
| 1430 | const else_node = try arena.create(ast.Node.SwitchElse{ | |
| 1457 | const else_node = try arena.create(ast.Node.SwitchElse); | |
| 1458 | else_node.* = ast.Node.SwitchElse{ | |
| 1431 | 1459 | .base = ast.Node{ .id = ast.Node.Id.SwitchElse }, |
| 1432 | 1460 | .token = token_index, |
| 1433 | }); | |
| 1461 | }; | |
| 1434 | 1462 | try switch_case.items.push(&else_node.base); |
| 1435 | 1463 | |
| 1436 | 1464 | try stack.append(State{ |
| ... | ... | @@ -1537,7 +1565,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1537 | 1565 | |
| 1538 | 1566 | State.ExternType => |ctx| { |
| 1539 | 1567 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_fn)) |fn_token| { |
| 1540 | const fn_proto = try arena.create(ast.Node.FnProto{ | |
| 1568 | const fn_proto = try arena.create(ast.Node.FnProto); | |
| 1569 | fn_proto.* = ast.Node.FnProto{ | |
| 1541 | 1570 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, |
| 1542 | 1571 | .doc_comments = ctx.comments, |
| 1543 | 1572 | .visib_token = null, |
| ... | ... | @@ -1553,7 +1582,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1553 | 1582 | .lib_name = null, |
| 1554 | 1583 | .align_expr = null, |
| 1555 | 1584 | .section_expr = null, |
| 1556 | }); | |
| 1585 | }; | |
| 1557 | 1586 | ctx.opt_ctx.store(&fn_proto.base); |
| 1558 | 1587 | stack.append(State{ .FnProto = fn_proto }) catch unreachable; |
| 1559 | 1588 | continue; |
| ... | ... | @@ -1711,12 +1740,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1711 | 1740 | continue; |
| 1712 | 1741 | } |
| 1713 | 1742 | |
| 1714 | const node = try arena.create(ast.Node.Payload{ | |
| 1743 | const node = try arena.create(ast.Node.Payload); | |
| 1744 | node.* = ast.Node.Payload{ | |
| 1715 | 1745 | .base = ast.Node{ .id = ast.Node.Id.Payload }, |
| 1716 | 1746 | .lpipe = token_index, |
| 1717 | 1747 | .error_symbol = undefined, |
| 1718 | 1748 | .rpipe = undefined, |
| 1719 | }); | |
| 1749 | }; | |
| 1720 | 1750 | opt_ctx.store(&node.base); |
| 1721 | 1751 | |
| 1722 | 1752 | stack.append(State{ |
| ... | ... | @@ -1747,13 +1777,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1747 | 1777 | continue; |
| 1748 | 1778 | } |
| 1749 | 1779 | |
| 1750 | const node = try arena.create(ast.Node.PointerPayload{ | |
| 1780 | const node = try arena.create(ast.Node.PointerPayload); | |
| 1781 | node.* = ast.Node.PointerPayload{ | |
| 1751 | 1782 | .base = ast.Node{ .id = ast.Node.Id.PointerPayload }, |
| 1752 | 1783 | .lpipe = token_index, |
| 1753 | 1784 | .ptr_token = null, |
| 1754 | 1785 | .value_symbol = undefined, |
| 1755 | 1786 | .rpipe = undefined, |
| 1756 | }); | |
| 1787 | }; | |
| 1757 | 1788 | opt_ctx.store(&node.base); |
| 1758 | 1789 | |
| 1759 | 1790 | try stack.append(State{ |
| ... | ... | @@ -1790,14 +1821,15 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1790 | 1821 | continue; |
| 1791 | 1822 | } |
| 1792 | 1823 | |
| 1793 | const node = try arena.create(ast.Node.PointerIndexPayload{ | |
| 1824 | const node = try arena.create(ast.Node.PointerIndexPayload); | |
| 1825 | node.* = ast.Node.PointerIndexPayload{ | |
| 1794 | 1826 | .base = ast.Node{ .id = ast.Node.Id.PointerIndexPayload }, |
| 1795 | 1827 | .lpipe = token_index, |
| 1796 | 1828 | .ptr_token = null, |
| 1797 | 1829 | .value_symbol = undefined, |
| 1798 | 1830 | .index_symbol = null, |
| 1799 | 1831 | .rpipe = undefined, |
| 1800 | }); | |
| 1832 | }; | |
| 1801 | 1833 | opt_ctx.store(&node.base); |
| 1802 | 1834 | |
| 1803 | 1835 | stack.append(State{ |
| ... | ... | @@ -1824,12 +1856,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1824 | 1856 | const token_ptr = token.ptr; |
| 1825 | 1857 | switch (token_ptr.id) { |
| 1826 | 1858 | Token.Id.Keyword_return, Token.Id.Keyword_break, Token.Id.Keyword_continue => { |
| 1827 | const node = try arena.create(ast.Node.ControlFlowExpression{ | |
| 1859 | const node = try arena.create(ast.Node.ControlFlowExpression); | |
| 1860 | node.* = ast.Node.ControlFlowExpression{ | |
| 1828 | 1861 | .base = ast.Node{ .id = ast.Node.Id.ControlFlowExpression }, |
| 1829 | 1862 | .ltoken = token_index, |
| 1830 | 1863 | .kind = undefined, |
| 1831 | 1864 | .rhs = null, |
| 1832 | }); | |
| 1865 | }; | |
| 1833 | 1866 | opt_ctx.store(&node.base); |
| 1834 | 1867 | |
| 1835 | 1868 | stack.append(State{ .Expression = OptionalCtx{ .Optional = &node.rhs } }) catch unreachable; |
| ... | ... | @@ -1853,7 +1886,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1853 | 1886 | continue; |
| 1854 | 1887 | }, |
| 1855 | 1888 | Token.Id.Keyword_try, Token.Id.Keyword_cancel, Token.Id.Keyword_resume => { |
| 1856 | const node = try arena.create(ast.Node.PrefixOp{ | |
| 1889 | const node = try arena.create(ast.Node.PrefixOp); | |
| 1890 | node.* = ast.Node.PrefixOp{ | |
| 1857 | 1891 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, |
| 1858 | 1892 | .op_token = token_index, |
| 1859 | 1893 | .op = switch (token_ptr.id) { |
| ... | ... | @@ -1863,7 +1897,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1863 | 1897 | else => unreachable, |
| 1864 | 1898 | }, |
| 1865 | 1899 | .rhs = undefined, |
| 1866 | }); | |
| 1900 | }; | |
| 1867 | 1901 | opt_ctx.store(&node.base); |
| 1868 | 1902 | |
| 1869 | 1903 | stack.append(State{ .Expression = OptionalCtx{ .Required = &node.rhs } }) catch unreachable; |
| ... | ... | @@ -1887,13 +1921,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1887 | 1921 | const lhs = opt_ctx.get() orelse continue; |
| 1888 | 1922 | |
| 1889 | 1923 | if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| { |
| 1890 | const node = try arena.create(ast.Node.InfixOp{ | |
| 1924 | const node = try arena.create(ast.Node.InfixOp); | |
| 1925 | node.* = ast.Node.InfixOp{ | |
| 1891 | 1926 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1892 | 1927 | .lhs = lhs, |
| 1893 | 1928 | .op_token = ellipsis3, |
| 1894 | 1929 | .op = ast.Node.InfixOp.Op.Range, |
| 1895 | 1930 | .rhs = undefined, |
| 1896 | }); | |
| 1931 | }; | |
| 1897 | 1932 | opt_ctx.store(&node.base); |
| 1898 | 1933 | stack.append(State{ .Expression = OptionalCtx{ .Required = &node.rhs } }) catch unreachable; |
| 1899 | 1934 | continue; |
| ... | ... | @@ -1912,13 +1947,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1912 | 1947 | const token_index = token.index; |
| 1913 | 1948 | const token_ptr = token.ptr; |
| 1914 | 1949 | if (tokenIdToAssignment(token_ptr.id)) |ass_id| { |
| 1915 | const node = try arena.create(ast.Node.InfixOp{ | |
| 1950 | const node = try arena.create(ast.Node.InfixOp); | |
| 1951 | node.* = ast.Node.InfixOp{ | |
| 1916 | 1952 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1917 | 1953 | .lhs = lhs, |
| 1918 | 1954 | .op_token = token_index, |
| 1919 | 1955 | .op = ass_id, |
| 1920 | 1956 | .rhs = undefined, |
| 1921 | }); | |
| 1957 | }; | |
| 1922 | 1958 | opt_ctx.store(&node.base); |
| 1923 | 1959 | stack.append(State{ .AssignmentExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 1924 | 1960 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.rhs } }); |
| ... | ... | @@ -1942,13 +1978,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1942 | 1978 | const token_index = token.index; |
| 1943 | 1979 | const token_ptr = token.ptr; |
| 1944 | 1980 | if (tokenIdToUnwrapExpr(token_ptr.id)) |unwrap_id| { |
| 1945 | const node = try arena.create(ast.Node.InfixOp{ | |
| 1981 | const node = try arena.create(ast.Node.InfixOp); | |
| 1982 | node.* = ast.Node.InfixOp{ | |
| 1946 | 1983 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1947 | 1984 | .lhs = lhs, |
| 1948 | 1985 | .op_token = token_index, |
| 1949 | 1986 | .op = unwrap_id, |
| 1950 | 1987 | .rhs = undefined, |
| 1951 | }); | |
| 1988 | }; | |
| 1952 | 1989 | opt_ctx.store(&node.base); |
| 1953 | 1990 | |
| 1954 | 1991 | stack.append(State{ .UnwrapExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| ... | ... | @@ -1974,13 +2011,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1974 | 2011 | const lhs = opt_ctx.get() orelse continue; |
| 1975 | 2012 | |
| 1976 | 2013 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| { |
| 1977 | const node = try arena.create(ast.Node.InfixOp{ | |
| 2014 | const node = try arena.create(ast.Node.InfixOp); | |
| 2015 | node.* = ast.Node.InfixOp{ | |
| 1978 | 2016 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1979 | 2017 | .lhs = lhs, |
| 1980 | 2018 | .op_token = or_token, |
| 1981 | 2019 | .op = ast.Node.InfixOp.Op.BoolOr, |
| 1982 | 2020 | .rhs = undefined, |
| 1983 | }); | |
| 2021 | }; | |
| 1984 | 2022 | opt_ctx.store(&node.base); |
| 1985 | 2023 | stack.append(State{ .BoolOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 1986 | 2024 | try stack.append(State{ .BoolAndExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| ... | ... | @@ -1998,13 +2036,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1998 | 2036 | const lhs = opt_ctx.get() orelse continue; |
| 1999 | 2037 | |
| 2000 | 2038 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| { |
| 2001 | const node = try arena.create(ast.Node.InfixOp{ | |
| 2039 | const node = try arena.create(ast.Node.InfixOp); | |
| 2040 | node.* = ast.Node.InfixOp{ | |
| 2002 | 2041 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2003 | 2042 | .lhs = lhs, |
| 2004 | 2043 | .op_token = and_token, |
| 2005 | 2044 | .op = ast.Node.InfixOp.Op.BoolAnd, |
| 2006 | 2045 | .rhs = undefined, |
| 2007 | }); | |
| 2046 | }; | |
| 2008 | 2047 | opt_ctx.store(&node.base); |
| 2009 | 2048 | stack.append(State{ .BoolAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2010 | 2049 | try stack.append(State{ .ComparisonExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| ... | ... | @@ -2025,13 +2064,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2025 | 2064 | const token_index = token.index; |
| 2026 | 2065 | const token_ptr = token.ptr; |
| 2027 | 2066 | if (tokenIdToComparison(token_ptr.id)) |comp_id| { |
| 2028 | const node = try arena.create(ast.Node.InfixOp{ | |
| 2067 | const node = try arena.create(ast.Node.InfixOp); | |
| 2068 | node.* = ast.Node.InfixOp{ | |
| 2029 | 2069 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2030 | 2070 | .lhs = lhs, |
| 2031 | 2071 | .op_token = token_index, |
| 2032 | 2072 | .op = comp_id, |
| 2033 | 2073 | .rhs = undefined, |
| 2034 | }); | |
| 2074 | }; | |
| 2035 | 2075 | opt_ctx.store(&node.base); |
| 2036 | 2076 | stack.append(State{ .ComparisonExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2037 | 2077 | try stack.append(State{ .BinaryOrExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| ... | ... | @@ -2052,13 +2092,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2052 | 2092 | const lhs = opt_ctx.get() orelse continue; |
| 2053 | 2093 | |
| 2054 | 2094 | if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| { |
| 2055 | const node = try arena.create(ast.Node.InfixOp{ | |
| 2095 | const node = try arena.create(ast.Node.InfixOp); | |
| 2096 | node.* = ast.Node.InfixOp{ | |
| 2056 | 2097 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2057 | 2098 | .lhs = lhs, |
| 2058 | 2099 | .op_token = pipe, |
| 2059 | 2100 | .op = ast.Node.InfixOp.Op.BitOr, |
| 2060 | 2101 | .rhs = undefined, |
| 2061 | }); | |
| 2102 | }; | |
| 2062 | 2103 | opt_ctx.store(&node.base); |
| 2063 | 2104 | stack.append(State{ .BinaryOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2064 | 2105 | try stack.append(State{ .BinaryXorExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| ... | ... | @@ -2076,13 +2117,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2076 | 2117 | const lhs = opt_ctx.get() orelse continue; |
| 2077 | 2118 | |
| 2078 | 2119 | if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| { |
| 2079 | const node = try arena.create(ast.Node.InfixOp{ | |
| 2120 | const node = try arena.create(ast.Node.InfixOp); | |
| 2121 | node.* = ast.Node.InfixOp{ | |
| 2080 | 2122 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2081 | 2123 | .lhs = lhs, |
| 2082 | 2124 | .op_token = caret, |
| 2083 | 2125 | .op = ast.Node.InfixOp.Op.BitXor, |
| 2084 | 2126 | .rhs = undefined, |
| 2085 | }); | |
| 2127 | }; | |
| 2086 | 2128 | opt_ctx.store(&node.base); |
| 2087 | 2129 | stack.append(State{ .BinaryXorExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2088 | 2130 | try stack.append(State{ .BinaryAndExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| ... | ... | @@ -2100,13 +2142,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2100 | 2142 | const lhs = opt_ctx.get() orelse continue; |
| 2101 | 2143 | |
| 2102 | 2144 | if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| { |
| 2103 | const node = try arena.create(ast.Node.InfixOp{ | |
| 2145 | const node = try arena.create(ast.Node.InfixOp); | |
| 2146 | node.* = ast.Node.InfixOp{ | |
| 2104 | 2147 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2105 | 2148 | .lhs = lhs, |
| 2106 | 2149 | .op_token = ampersand, |
| 2107 | 2150 | .op = ast.Node.InfixOp.Op.BitAnd, |
| 2108 | 2151 | .rhs = undefined, |
| 2109 | }); | |
| 2152 | }; | |
| 2110 | 2153 | opt_ctx.store(&node.base); |
| 2111 | 2154 | stack.append(State{ .BinaryAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2112 | 2155 | try stack.append(State{ .BitShiftExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| ... | ... | @@ -2127,13 +2170,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2127 | 2170 | const token_index = token.index; |
| 2128 | 2171 | const token_ptr = token.ptr; |
| 2129 | 2172 | if (tokenIdToBitShift(token_ptr.id)) |bitshift_id| { |
| 2130 | const node = try arena.create(ast.Node.InfixOp{ | |
| 2173 | const node = try arena.create(ast.Node.InfixOp); | |
| 2174 | node.* = ast.Node.InfixOp{ | |
| 2131 | 2175 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2132 | 2176 | .lhs = lhs, |
| 2133 | 2177 | .op_token = token_index, |
| 2134 | 2178 | .op = bitshift_id, |
| 2135 | 2179 | .rhs = undefined, |
| 2136 | }); | |
| 2180 | }; | |
| 2137 | 2181 | opt_ctx.store(&node.base); |
| 2138 | 2182 | stack.append(State{ .BitShiftExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2139 | 2183 | try stack.append(State{ .AdditionExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| ... | ... | @@ -2157,13 +2201,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2157 | 2201 | const token_index = token.index; |
| 2158 | 2202 | const token_ptr = token.ptr; |
| 2159 | 2203 | if (tokenIdToAddition(token_ptr.id)) |add_id| { |
| 2160 | const node = try arena.create(ast.Node.InfixOp{ | |
| 2204 | const node = try arena.create(ast.Node.InfixOp); | |
| 2205 | node.* = ast.Node.InfixOp{ | |
| 2161 | 2206 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2162 | 2207 | .lhs = lhs, |
| 2163 | 2208 | .op_token = token_index, |
| 2164 | 2209 | .op = add_id, |
| 2165 | 2210 | .rhs = undefined, |
| 2166 | }); | |
| 2211 | }; | |
| 2167 | 2212 | opt_ctx.store(&node.base); |
| 2168 | 2213 | stack.append(State{ .AdditionExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2169 | 2214 | try stack.append(State{ .MultiplyExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| ... | ... | @@ -2187,13 +2232,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2187 | 2232 | const token_index = token.index; |
| 2188 | 2233 | const token_ptr = token.ptr; |
| 2189 | 2234 | if (tokenIdToMultiply(token_ptr.id)) |mult_id| { |
| 2190 | const node = try arena.create(ast.Node.InfixOp{ | |
| 2235 | const node = try arena.create(ast.Node.InfixOp); | |
| 2236 | node.* = ast.Node.InfixOp{ | |
| 2191 | 2237 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2192 | 2238 | .lhs = lhs, |
| 2193 | 2239 | .op_token = token_index, |
| 2194 | 2240 | .op = mult_id, |
| 2195 | 2241 | .rhs = undefined, |
| 2196 | }); | |
| 2242 | }; | |
| 2197 | 2243 | opt_ctx.store(&node.base); |
| 2198 | 2244 | stack.append(State{ .MultiplyExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2199 | 2245 | try stack.append(State{ .CurlySuffixExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| ... | ... | @@ -2215,12 +2261,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2215 | 2261 | const lhs = opt_ctx.get() orelse continue; |
| 2216 | 2262 | |
| 2217 | 2263 | if (tok_it.peek().?.id == Token.Id.Period) { |
| 2218 | const node = try arena.create(ast.Node.SuffixOp{ | |
| 2264 | const node = try arena.create(ast.Node.SuffixOp); | |
| 2265 | node.* = ast.Node.SuffixOp{ | |
| 2219 | 2266 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2220 | 2267 | .lhs = lhs, |
| 2221 | 2268 | .op = ast.Node.SuffixOp.Op{ .StructInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) }, |
| 2222 | 2269 | .rtoken = undefined, |
| 2223 | }); | |
| 2270 | }; | |
| 2224 | 2271 | opt_ctx.store(&node.base); |
| 2225 | 2272 | |
| 2226 | 2273 | stack.append(State{ .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| ... | ... | @@ -2234,12 +2281,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2234 | 2281 | continue; |
| 2235 | 2282 | } |
| 2236 | 2283 | |
| 2237 | const node = try arena.create(ast.Node.SuffixOp{ | |
| 2284 | const node = try arena.create(ast.Node.SuffixOp); | |
| 2285 | node.* = ast.Node.SuffixOp{ | |
| 2238 | 2286 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2239 | 2287 | .lhs = lhs, |
| 2240 | 2288 | .op = ast.Node.SuffixOp.Op{ .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) }, |
| 2241 | 2289 | .rtoken = undefined, |
| 2242 | }); | |
| 2290 | }; | |
| 2243 | 2291 | opt_ctx.store(&node.base); |
| 2244 | 2292 | stack.append(State{ .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2245 | 2293 | try stack.append(State{ .IfToken = Token.Id.LBrace }); |
| ... | ... | @@ -2263,13 +2311,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2263 | 2311 | const lhs = opt_ctx.get() orelse continue; |
| 2264 | 2312 | |
| 2265 | 2313 | if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| { |
| 2266 | const node = try arena.create(ast.Node.InfixOp{ | |
| 2314 | const node = try arena.create(ast.Node.InfixOp); | |
| 2315 | node.* = ast.Node.InfixOp{ | |
| 2267 | 2316 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2268 | 2317 | .lhs = lhs, |
| 2269 | 2318 | .op_token = bang, |
| 2270 | 2319 | .op = ast.Node.InfixOp.Op.ErrorUnion, |
| 2271 | 2320 | .rhs = undefined, |
| 2272 | }); | |
| 2321 | }; | |
| 2273 | 2322 | opt_ctx.store(&node.base); |
| 2274 | 2323 | stack.append(State{ .TypeExprEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2275 | 2324 | try stack.append(State{ .PrefixOpExpression = OptionalCtx{ .Required = &node.rhs } }); |
| ... | ... | @@ -2282,22 +2331,24 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2282 | 2331 | const token_index = token.index; |
| 2283 | 2332 | const token_ptr = token.ptr; |
| 2284 | 2333 | if (tokenIdToPrefixOp(token_ptr.id)) |prefix_id| { |
| 2285 | var node = try arena.create(ast.Node.PrefixOp{ | |
| 2334 | var node = try arena.create(ast.Node.PrefixOp); | |
| 2335 | node.* = ast.Node.PrefixOp{ | |
| 2286 | 2336 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, |
| 2287 | 2337 | .op_token = token_index, |
| 2288 | 2338 | .op = prefix_id, |
| 2289 | 2339 | .rhs = undefined, |
| 2290 | }); | |
| 2340 | }; | |
| 2291 | 2341 | opt_ctx.store(&node.base); |
| 2292 | 2342 | |
| 2293 | 2343 | // Treat '**' token as two pointer types |
| 2294 | 2344 | if (token_ptr.id == Token.Id.AsteriskAsterisk) { |
| 2295 | const child = try arena.create(ast.Node.PrefixOp{ | |
| 2345 | const child = try arena.create(ast.Node.PrefixOp); | |
| 2346 | child.* = ast.Node.PrefixOp{ | |
| 2296 | 2347 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, |
| 2297 | 2348 | .op_token = token_index, |
| 2298 | 2349 | .op = prefix_id, |
| 2299 | 2350 | .rhs = undefined, |
| 2300 | }); | |
| 2351 | }; | |
| 2301 | 2352 | node.rhs = &child.base; |
| 2302 | 2353 | node = child; |
| 2303 | 2354 | } |
| ... | ... | @@ -2316,12 +2367,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2316 | 2367 | |
| 2317 | 2368 | State.SuffixOpExpressionBegin => |opt_ctx| { |
| 2318 | 2369 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_async)) |async_token| { |
| 2319 | const async_node = try arena.create(ast.Node.AsyncAttribute{ | |
| 2370 | const async_node = try arena.create(ast.Node.AsyncAttribute); | |
| 2371 | async_node.* = ast.Node.AsyncAttribute{ | |
| 2320 | 2372 | .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute }, |
| 2321 | 2373 | .async_token = async_token, |
| 2322 | 2374 | .allocator_type = null, |
| 2323 | 2375 | .rangle_bracket = null, |
| 2324 | }); | |
| 2376 | }; | |
| 2325 | 2377 | stack.append(State{ |
| 2326 | 2378 | .AsyncEnd = AsyncEndCtx{ |
| 2327 | 2379 | .ctx = opt_ctx, |
| ... | ... | @@ -2347,7 +2399,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2347 | 2399 | const token_ptr = token.ptr; |
| 2348 | 2400 | switch (token_ptr.id) { |
| 2349 | 2401 | Token.Id.LParen => { |
| 2350 | const node = try arena.create(ast.Node.SuffixOp{ | |
| 2402 | const node = try arena.create(ast.Node.SuffixOp); | |
| 2403 | node.* = ast.Node.SuffixOp{ | |
| 2351 | 2404 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2352 | 2405 | .lhs = lhs, |
| 2353 | 2406 | .op = ast.Node.SuffixOp.Op{ |
| ... | ... | @@ -2357,7 +2410,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2357 | 2410 | }, |
| 2358 | 2411 | }, |
| 2359 | 2412 | .rtoken = undefined, |
| 2360 | }); | |
| 2413 | }; | |
| 2361 | 2414 | opt_ctx.store(&node.base); |
| 2362 | 2415 | |
| 2363 | 2416 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| ... | ... | @@ -2371,12 +2424,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2371 | 2424 | continue; |
| 2372 | 2425 | }, |
| 2373 | 2426 | Token.Id.LBracket => { |
| 2374 | const node = try arena.create(ast.Node.SuffixOp{ | |
| 2427 | const node = try arena.create(ast.Node.SuffixOp); | |
| 2428 | node.* = ast.Node.SuffixOp{ | |
| 2375 | 2429 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2376 | 2430 | .lhs = lhs, |
| 2377 | 2431 | .op = ast.Node.SuffixOp.Op{ .ArrayAccess = undefined }, |
| 2378 | 2432 | .rtoken = undefined, |
| 2379 | }); | |
| 2433 | }; | |
| 2380 | 2434 | opt_ctx.store(&node.base); |
| 2381 | 2435 | |
| 2382 | 2436 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| ... | ... | @@ -2386,34 +2440,37 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2386 | 2440 | }, |
| 2387 | 2441 | Token.Id.Period => { |
| 2388 | 2442 | if (eatToken(&tok_it, &tree, Token.Id.Asterisk)) |asterisk_token| { |
| 2389 | const node = try arena.create(ast.Node.SuffixOp{ | |
| 2443 | const node = try arena.create(ast.Node.SuffixOp); | |
| 2444 | node.* = ast.Node.SuffixOp{ | |
| 2390 | 2445 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2391 | 2446 | .lhs = lhs, |
| 2392 | 2447 | .op = ast.Node.SuffixOp.Op.Deref, |
| 2393 | 2448 | .rtoken = asterisk_token, |
| 2394 | }); | |
| 2449 | }; | |
| 2395 | 2450 | opt_ctx.store(&node.base); |
| 2396 | 2451 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2397 | 2452 | continue; |
| 2398 | 2453 | } |
| 2399 | 2454 | if (eatToken(&tok_it, &tree, Token.Id.QuestionMark)) |question_token| { |
| 2400 | const node = try arena.create(ast.Node.SuffixOp{ | |
| 2455 | const node = try arena.create(ast.Node.SuffixOp); | |
| 2456 | node.* = ast.Node.SuffixOp{ | |
| 2401 | 2457 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2402 | 2458 | .lhs = lhs, |
| 2403 | 2459 | .op = ast.Node.SuffixOp.Op.UnwrapOptional, |
| 2404 | 2460 | .rtoken = question_token, |
| 2405 | }); | |
| 2461 | }; | |
| 2406 | 2462 | opt_ctx.store(&node.base); |
| 2407 | 2463 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2408 | 2464 | continue; |
| 2409 | 2465 | } |
| 2410 | const node = try arena.create(ast.Node.InfixOp{ | |
| 2466 | const node = try arena.create(ast.Node.InfixOp); | |
| 2467 | node.* = ast.Node.InfixOp{ | |
| 2411 | 2468 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2412 | 2469 | .lhs = lhs, |
| 2413 | 2470 | .op_token = token_index, |
| 2414 | 2471 | .op = ast.Node.InfixOp.Op.Period, |
| 2415 | 2472 | .rhs = undefined, |
| 2416 | }); | |
| 2473 | }; | |
| 2417 | 2474 | opt_ctx.store(&node.base); |
| 2418 | 2475 | |
| 2419 | 2476 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| ... | ... | @@ -2467,11 +2524,12 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2467 | 2524 | continue; |
| 2468 | 2525 | }, |
| 2469 | 2526 | Token.Id.Keyword_promise => { |
| 2470 | const node = try arena.create(ast.Node.PromiseType{ | |
| 2527 | const node = try arena.create(ast.Node.PromiseType); | |
| 2528 | node.* = ast.Node.PromiseType{ | |
| 2471 | 2529 | .base = ast.Node{ .id = ast.Node.Id.PromiseType }, |
| 2472 | 2530 | .promise_token = token.index, |
| 2473 | 2531 | .result = null, |
| 2474 | }); | |
| 2532 | }; | |
| 2475 | 2533 | opt_ctx.store(&node.base); |
| 2476 | 2534 | const next_token = nextToken(&tok_it, &tree); |
| 2477 | 2535 | const next_token_index = next_token.index; |
| ... | ... | @@ -2493,12 +2551,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2493 | 2551 | continue; |
| 2494 | 2552 | }, |
| 2495 | 2553 | Token.Id.LParen => { |
| 2496 | const node = try arena.create(ast.Node.GroupedExpression{ | |
| 2554 | const node = try arena.create(ast.Node.GroupedExpression); | |
| 2555 | node.* = ast.Node.GroupedExpression{ | |
| 2497 | 2556 | .base = ast.Node{ .id = ast.Node.Id.GroupedExpression }, |
| 2498 | 2557 | .lparen = token.index, |
| 2499 | 2558 | .expr = undefined, |
| 2500 | 2559 | .rparen = undefined, |
| 2501 | }); | |
| 2560 | }; | |
| 2502 | 2561 | opt_ctx.store(&node.base); |
| 2503 | 2562 | |
| 2504 | 2563 | stack.append(State{ |
| ... | ... | @@ -2511,12 +2570,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2511 | 2570 | continue; |
| 2512 | 2571 | }, |
| 2513 | 2572 | Token.Id.Builtin => { |
| 2514 | const node = try arena.create(ast.Node.BuiltinCall{ | |
| 2573 | const node = try arena.create(ast.Node.BuiltinCall); | |
| 2574 | node.* = ast.Node.BuiltinCall{ | |
| 2515 | 2575 | .base = ast.Node{ .id = ast.Node.Id.BuiltinCall }, |
| 2516 | 2576 | .builtin_token = token.index, |
| 2517 | 2577 | .params = ast.Node.BuiltinCall.ParamList.init(arena), |
| 2518 | 2578 | .rparen_token = undefined, |
| 2519 | }); | |
| 2579 | }; | |
| 2520 | 2580 | opt_ctx.store(&node.base); |
| 2521 | 2581 | |
| 2522 | 2582 | stack.append(State{ |
| ... | ... | @@ -2530,12 +2590,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2530 | 2590 | continue; |
| 2531 | 2591 | }, |
| 2532 | 2592 | Token.Id.LBracket => { |
| 2533 | const node = try arena.create(ast.Node.PrefixOp{ | |
| 2593 | const node = try arena.create(ast.Node.PrefixOp); | |
| 2594 | node.* = ast.Node.PrefixOp{ | |
| 2534 | 2595 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, |
| 2535 | 2596 | .op_token = token.index, |
| 2536 | 2597 | .op = undefined, |
| 2537 | 2598 | .rhs = undefined, |
| 2538 | }); | |
| 2599 | }; | |
| 2539 | 2600 | opt_ctx.store(&node.base); |
| 2540 | 2601 | |
| 2541 | 2602 | stack.append(State{ .SliceOrArrayType = node }) catch unreachable; |
| ... | ... | @@ -2593,7 +2654,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2593 | 2654 | continue; |
| 2594 | 2655 | }, |
| 2595 | 2656 | Token.Id.Keyword_fn => { |
| 2596 | const fn_proto = try arena.create(ast.Node.FnProto{ | |
| 2657 | const fn_proto = try arena.create(ast.Node.FnProto); | |
| 2658 | fn_proto.* = ast.Node.FnProto{ | |
| 2597 | 2659 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, |
| 2598 | 2660 | .doc_comments = null, |
| 2599 | 2661 | .visib_token = null, |
| ... | ... | @@ -2609,13 +2671,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2609 | 2671 | .lib_name = null, |
| 2610 | 2672 | .align_expr = null, |
| 2611 | 2673 | .section_expr = null, |
| 2612 | }); | |
| 2674 | }; | |
| 2613 | 2675 | opt_ctx.store(&fn_proto.base); |
| 2614 | 2676 | stack.append(State{ .FnProto = fn_proto }) catch unreachable; |
| 2615 | 2677 | continue; |
| 2616 | 2678 | }, |
| 2617 | 2679 | Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc => { |
| 2618 | const fn_proto = try arena.create(ast.Node.FnProto{ | |
| 2680 | const fn_proto = try arena.create(ast.Node.FnProto); | |
| 2681 | fn_proto.* = ast.Node.FnProto{ | |
| 2619 | 2682 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, |
| 2620 | 2683 | .doc_comments = null, |
| 2621 | 2684 | .visib_token = null, |
| ... | ... | @@ -2631,7 +2694,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2631 | 2694 | .lib_name = null, |
| 2632 | 2695 | .align_expr = null, |
| 2633 | 2696 | .section_expr = null, |
| 2634 | }); | |
| 2697 | }; | |
| 2635 | 2698 | opt_ctx.store(&fn_proto.base); |
| 2636 | 2699 | stack.append(State{ .FnProto = fn_proto }) catch unreachable; |
| 2637 | 2700 | try stack.append(State{ |
| ... | ... | @@ -2643,7 +2706,8 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2643 | 2706 | continue; |
| 2644 | 2707 | }, |
| 2645 | 2708 | Token.Id.Keyword_asm => { |
| 2646 | const node = try arena.create(ast.Node.Asm{ | |
| 2709 | const node = try arena.create(ast.Node.Asm); | |
| 2710 | node.* = ast.Node.Asm{ | |
| 2647 | 2711 | .base = ast.Node{ .id = ast.Node.Id.Asm }, |
| 2648 | 2712 | .asm_token = token.index, |
| 2649 | 2713 | .volatile_token = null, |
| ... | ... | @@ -2652,7 +2716,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2652 | 2716 | .inputs = ast.Node.Asm.InputList.init(arena), |
| 2653 | 2717 | .clobbers = ast.Node.Asm.ClobberList.init(arena), |
| 2654 | 2718 | .rparen = undefined, |
| 2655 | }); | |
| 2719 | }; | |
| 2656 | 2720 | opt_ctx.store(&node.base); |
| 2657 | 2721 | |
| 2658 | 2722 | stack.append(State{ |
| ... | ... | @@ -2701,13 +2765,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2701 | 2765 | |
| 2702 | 2766 | State.ErrorTypeOrSetDecl => |ctx| { |
| 2703 | 2767 | if (eatToken(&tok_it, &tree, Token.Id.LBrace) == null) { |
| 2704 | const node = try arena.create(ast.Node.InfixOp{ | |
| 2768 | const node = try arena.create(ast.Node.InfixOp); | |
| 2769 | node.* = ast.Node.InfixOp{ | |
| 2705 | 2770 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2706 | 2771 | .lhs = &(try createLiteral(arena, ast.Node.ErrorType, ctx.error_token)).base, |
| 2707 | 2772 | .op_token = undefined, |
| 2708 | 2773 | .op = ast.Node.InfixOp.Op.Period, |
| 2709 | 2774 | .rhs = undefined, |
| 2710 | }); | |
| 2775 | }; | |
| 2711 | 2776 | ctx.opt_ctx.store(&node.base); |
| 2712 | 2777 | stack.append(State{ .Identifier = OptionalCtx{ .Required = &node.rhs } }) catch unreachable; |
| 2713 | 2778 | try stack.append(State{ |
| ... | ... | @@ -2719,12 +2784,13 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2719 | 2784 | continue; |
| 2720 | 2785 | } |
| 2721 | 2786 | |
| 2722 | const node = try arena.create(ast.Node.ErrorSetDecl{ | |
| 2787 | const node = try arena.create(ast.Node.ErrorSetDecl); | |
| 2788 | node.* = ast.Node.ErrorSetDecl{ | |
| 2723 | 2789 | .base = ast.Node{ .id = ast.Node.Id.ErrorSetDecl }, |
| 2724 | 2790 | .error_token = ctx.error_token, |
| 2725 | 2791 | .decls = ast.Node.ErrorSetDecl.DeclList.init(arena), |
| 2726 | 2792 | .rbrace_token = undefined, |
| 2727 | }); | |
| 2793 | }; | |
| 2728 | 2794 | ctx.opt_ctx.store(&node.base); |
| 2729 | 2795 | |
| 2730 | 2796 | stack.append(State{ |
| ... | ... | @@ -2785,11 +2851,12 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2785 | 2851 | return tree; |
| 2786 | 2852 | } |
| 2787 | 2853 | |
| 2788 | const node = try arena.create(ast.Node.ErrorTag{ | |
| 2854 | const node = try arena.create(ast.Node.ErrorTag); | |
| 2855 | node.* = ast.Node.ErrorTag{ | |
| 2789 | 2856 | .base = ast.Node{ .id = ast.Node.Id.ErrorTag }, |
| 2790 | 2857 | .doc_comments = comments, |
| 2791 | 2858 | .name_token = ident_token_index, |
| 2792 | }); | |
| 2859 | }; | |
| 2793 | 2860 | node_ptr.* = &node.base; |
| 2794 | 2861 | continue; |
| 2795 | 2862 | }, |
| ... | ... | @@ -3129,10 +3196,11 @@ fn pushDocComment(arena: *mem.Allocator, line_comment: TokenIndex, result: *?*as |
| 3129 | 3196 | if (result.*) |comment_node| { |
| 3130 | 3197 | break :blk comment_node; |
| 3131 | 3198 | } else { |
| 3132 | const comment_node = try arena.create(ast.Node.DocComment{ | |
| 3199 | const comment_node = try arena.create(ast.Node.DocComment); | |
| 3200 | comment_node.* = ast.Node.DocComment{ | |
| 3133 | 3201 | .base = ast.Node{ .id = ast.Node.Id.DocComment }, |
| 3134 | 3202 | .lines = ast.Node.DocComment.LineList.init(arena), |
| 3135 | }); | |
| 3203 | }; | |
| 3136 | 3204 | result.* = comment_node; |
| 3137 | 3205 | break :blk comment_node; |
| 3138 | 3206 | } |
| ... | ... | @@ -3158,10 +3226,11 @@ fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterato |
| 3158 | 3226 | return &(try createLiteral(arena, ast.Node.StringLiteral, token_index)).base; |
| 3159 | 3227 | }, |
| 3160 | 3228 | Token.Id.MultilineStringLiteralLine => { |
| 3161 | const node = try arena.create(ast.Node.MultilineStringLiteral{ | |
| 3229 | const node = try arena.create(ast.Node.MultilineStringLiteral); | |
| 3230 | node.* = ast.Node.MultilineStringLiteral{ | |
| 3162 | 3231 | .base = ast.Node{ .id = ast.Node.Id.MultilineStringLiteral }, |
| 3163 | 3232 | .lines = ast.Node.MultilineStringLiteral.LineList.init(arena), |
| 3164 | }); | |
| 3233 | }; | |
| 3165 | 3234 | try node.lines.push(token_index); |
| 3166 | 3235 | while (true) { |
| 3167 | 3236 | const multiline_str = nextToken(tok_it, tree); |
| ... | ... | @@ -3186,25 +3255,27 @@ fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterato |
| 3186 | 3255 | fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: OptionalCtx, token_ptr: Token, token_index: TokenIndex) !bool { |
| 3187 | 3256 | switch (token_ptr.id) { |
| 3188 | 3257 | Token.Id.Keyword_suspend => { |
| 3189 | const node = try arena.create(ast.Node.Suspend{ | |
| 3258 | const node = try arena.create(ast.Node.Suspend); | |
| 3259 | node.* = ast.Node.Suspend{ | |
| 3190 | 3260 | .base = ast.Node{ .id = ast.Node.Id.Suspend }, |
| 3191 | 3261 | .suspend_token = token_index, |
| 3192 | 3262 | .body = null, |
| 3193 | }); | |
| 3263 | }; | |
| 3194 | 3264 | ctx.store(&node.base); |
| 3195 | 3265 | |
| 3196 | 3266 | stack.append(State{ .SuspendBody = node }) catch unreachable; |
| 3197 | 3267 | return true; |
| 3198 | 3268 | }, |
| 3199 | 3269 | Token.Id.Keyword_if => { |
| 3200 | const node = try arena.create(ast.Node.If{ | |
| 3270 | const node = try arena.create(ast.Node.If); | |
| 3271 | node.* = ast.Node.If{ | |
| 3201 | 3272 | .base = ast.Node{ .id = ast.Node.Id.If }, |
| 3202 | 3273 | .if_token = token_index, |
| 3203 | 3274 | .condition = undefined, |
| 3204 | 3275 | .payload = null, |
| 3205 | 3276 | .body = undefined, |
| 3206 | 3277 | .@"else" = null, |
| 3207 | }); | |
| 3278 | }; | |
| 3208 | 3279 | ctx.store(&node.base); |
| 3209 | 3280 | |
| 3210 | 3281 | stack.append(State{ .Else = &node.@"else" }) catch unreachable; |
| ... | ... | @@ -3238,13 +3309,14 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: Opti |
| 3238 | 3309 | return true; |
| 3239 | 3310 | }, |
| 3240 | 3311 | Token.Id.Keyword_switch => { |
| 3241 | const node = try arena.create(ast.Node.Switch{ | |
| 3312 | const node = try arena.create(ast.Node.Switch); | |
| 3313 | node.* = ast.Node.Switch{ | |
| 3242 | 3314 | .base = ast.Node{ .id = ast.Node.Id.Switch }, |
| 3243 | 3315 | .switch_token = token_index, |
| 3244 | 3316 | .expr = undefined, |
| 3245 | 3317 | .cases = ast.Node.Switch.CaseList.init(arena), |
| 3246 | 3318 | .rbrace = undefined, |
| 3247 | }); | |
| 3319 | }; | |
| 3248 | 3320 | ctx.store(&node.base); |
| 3249 | 3321 | |
| 3250 | 3322 | stack.append(State{ |
| ... | ... | @@ -3260,25 +3332,27 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: Opti |
| 3260 | 3332 | return true; |
| 3261 | 3333 | }, |
| 3262 | 3334 | Token.Id.Keyword_comptime => { |
| 3263 | const node = try arena.create(ast.Node.Comptime{ | |
| 3335 | const node = try arena.create(ast.Node.Comptime); | |
| 3336 | node.* = ast.Node.Comptime{ | |
| 3264 | 3337 | .base = ast.Node{ .id = ast.Node.Id.Comptime }, |
| 3265 | 3338 | .comptime_token = token_index, |
| 3266 | 3339 | .expr = undefined, |
| 3267 | 3340 | .doc_comments = null, |
| 3268 | }); | |
| 3341 | }; | |
| 3269 | 3342 | ctx.store(&node.base); |
| 3270 | 3343 | |
| 3271 | 3344 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } }); |
| 3272 | 3345 | return true; |
| 3273 | 3346 | }, |
| 3274 | 3347 | Token.Id.LBrace => { |
| 3275 | const block = try arena.create(ast.Node.Block{ | |
| 3348 | const block = try arena.create(ast.Node.Block); | |
| 3349 | block.* = ast.Node.Block{ | |
| 3276 | 3350 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 3277 | 3351 | .label = null, |
| 3278 | 3352 | .lbrace = token_index, |
| 3279 | 3353 | .statements = ast.Node.Block.StatementList.init(arena), |
| 3280 | 3354 | .rbrace = undefined, |
| 3281 | }); | |
| 3355 | }; | |
| 3282 | 3356 | ctx.store(&block.base); |
| 3283 | 3357 | stack.append(State{ .Block = block }) catch unreachable; |
| 3284 | 3358 | return true; |
| ... | ... | @@ -3412,10 +3486,12 @@ fn tokenIdToPrefixOp(id: Token.Id) ?ast.Node.PrefixOp.Op { |
| 3412 | 3486 | } |
| 3413 | 3487 | |
| 3414 | 3488 | fn createLiteral(arena: *mem.Allocator, comptime T: type, token_index: TokenIndex) !*T { |
| 3415 | return arena.create(T{ | |
| 3489 | const result = try arena.create(T); | |
| 3490 | result.* = T{ | |
| 3416 | 3491 | .base = ast.Node{ .id = ast.Node.typeToId(T) }, |
| 3417 | 3492 | .token = token_index, |
| 3418 | }); | |
| 3493 | }; | |
| 3494 | return result; | |
| 3419 | 3495 | } |
| 3420 | 3496 | |
| 3421 | 3497 | fn createToCtxLiteral(arena: *mem.Allocator, opt_ctx: OptionalCtx, comptime T: type, token_index: TokenIndex) !*T { |
test/tests.zig+45-30| ... | ... | @@ -48,13 +48,14 @@ const test_targets = []TestTarget{ |
| 48 | 48 | const max_stdout_size = 1 * 1024 * 1024; // 1 MB |
| 49 | 49 | |
| 50 | 50 | pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step { |
| 51 | const cases = b.allocator.create(CompareOutputContext{ | |
| 51 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; | |
| 52 | cases.* = CompareOutputContext{ | |
| 52 | 53 | .b = b, |
| 53 | 54 | .step = b.step("test-compare-output", "Run the compare output tests"), |
| 54 | 55 | .test_index = 0, |
| 55 | 56 | .test_filter = test_filter, |
| 56 | 57 | .modes = modes, |
| 57 | }) catch unreachable; | |
| 58 | }; | |
| 58 | 59 | |
| 59 | 60 | compare_output.addCases(cases); |
| 60 | 61 | |
| ... | ... | @@ -62,13 +63,14 @@ pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8, modes: |
| 62 | 63 | } |
| 63 | 64 | |
| 64 | 65 | pub fn addRuntimeSafetyTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step { |
| 65 | const cases = b.allocator.create(CompareOutputContext{ | |
| 66 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; | |
| 67 | cases.* = CompareOutputContext{ | |
| 66 | 68 | .b = b, |
| 67 | 69 | .step = b.step("test-runtime-safety", "Run the runtime safety tests"), |
| 68 | 70 | .test_index = 0, |
| 69 | 71 | .test_filter = test_filter, |
| 70 | 72 | .modes = modes, |
| 71 | }) catch unreachable; | |
| 73 | }; | |
| 72 | 74 | |
| 73 | 75 | runtime_safety.addCases(cases); |
| 74 | 76 | |
| ... | ... | @@ -76,13 +78,14 @@ pub fn addRuntimeSafetyTests(b: *build.Builder, test_filter: ?[]const u8, modes: |
| 76 | 78 | } |
| 77 | 79 | |
| 78 | 80 | pub fn addCompileErrorTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step { |
| 79 | const cases = b.allocator.create(CompileErrorContext{ | |
| 81 | const cases = b.allocator.create(CompileErrorContext) catch unreachable; | |
| 82 | cases.* = CompileErrorContext{ | |
| 80 | 83 | .b = b, |
| 81 | 84 | .step = b.step("test-compile-errors", "Run the compile error tests"), |
| 82 | 85 | .test_index = 0, |
| 83 | 86 | .test_filter = test_filter, |
| 84 | 87 | .modes = modes, |
| 85 | }) catch unreachable; | |
| 88 | }; | |
| 86 | 89 | |
| 87 | 90 | compile_errors.addCases(cases); |
| 88 | 91 | |
| ... | ... | @@ -90,13 +93,14 @@ pub fn addCompileErrorTests(b: *build.Builder, test_filter: ?[]const u8, modes: |
| 90 | 93 | } |
| 91 | 94 | |
| 92 | 95 | pub fn addBuildExampleTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step { |
| 93 | const cases = b.allocator.create(BuildExamplesContext{ | |
| 96 | const cases = b.allocator.create(BuildExamplesContext) catch unreachable; | |
| 97 | cases.* = BuildExamplesContext{ | |
| 94 | 98 | .b = b, |
| 95 | 99 | .step = b.step("test-build-examples", "Build the examples"), |
| 96 | 100 | .test_index = 0, |
| 97 | 101 | .test_filter = test_filter, |
| 98 | 102 | .modes = modes, |
| 99 | }) catch unreachable; | |
| 103 | }; | |
| 100 | 104 | |
| 101 | 105 | build_examples.addCases(cases); |
| 102 | 106 | |
| ... | ... | @@ -119,13 +123,14 @@ pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const M |
| 119 | 123 | } |
| 120 | 124 | |
| 121 | 125 | pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step { |
| 122 | const cases = b.allocator.create(CompareOutputContext{ | |
| 126 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; | |
| 127 | cases.* = CompareOutputContext{ | |
| 123 | 128 | .b = b, |
| 124 | 129 | .step = b.step("test-asm-link", "Run the assemble and link tests"), |
| 125 | 130 | .test_index = 0, |
| 126 | 131 | .test_filter = test_filter, |
| 127 | 132 | .modes = modes, |
| 128 | }) catch unreachable; | |
| 133 | }; | |
| 129 | 134 | |
| 130 | 135 | assemble_and_link.addCases(cases); |
| 131 | 136 | |
| ... | ... | @@ -133,12 +138,13 @@ pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8, mode |
| 133 | 138 | } |
| 134 | 139 | |
| 135 | 140 | pub fn addTranslateCTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step { |
| 136 | const cases = b.allocator.create(TranslateCContext{ | |
| 141 | const cases = b.allocator.create(TranslateCContext) catch unreachable; | |
| 142 | cases.* = TranslateCContext{ | |
| 137 | 143 | .b = b, |
| 138 | 144 | .step = b.step("test-translate-c", "Run the C transation tests"), |
| 139 | 145 | .test_index = 0, |
| 140 | 146 | .test_filter = test_filter, |
| 141 | }) catch unreachable; | |
| 147 | }; | |
| 142 | 148 | |
| 143 | 149 | translate_c.addCases(cases); |
| 144 | 150 | |
| ... | ... | @@ -146,12 +152,13 @@ pub fn addTranslateCTests(b: *build.Builder, test_filter: ?[]const u8) *build.St |
| 146 | 152 | } |
| 147 | 153 | |
| 148 | 154 | pub fn addGenHTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step { |
| 149 | const cases = b.allocator.create(GenHContext{ | |
| 155 | const cases = b.allocator.create(GenHContext) catch unreachable; | |
| 156 | cases.* = GenHContext{ | |
| 150 | 157 | .b = b, |
| 151 | 158 | .step = b.step("test-gen-h", "Run the C header file generation tests"), |
| 152 | 159 | .test_index = 0, |
| 153 | 160 | .test_filter = test_filter, |
| 154 | }) catch unreachable; | |
| 161 | }; | |
| 155 | 162 | |
| 156 | 163 | gen_h.addCases(cases); |
| 157 | 164 | |
| ... | ... | @@ -244,7 +251,8 @@ pub const CompareOutputContext = struct { |
| 244 | 251 | |
| 245 | 252 | pub fn create(context: *CompareOutputContext, exe_path: []const u8, name: []const u8, expected_output: []const u8, cli_args: []const []const u8) *RunCompareOutputStep { |
| 246 | 253 | const allocator = context.b.allocator; |
| 247 | const ptr = allocator.create(RunCompareOutputStep{ | |
| 254 | const ptr = allocator.create(RunCompareOutputStep) catch unreachable; | |
| 255 | ptr.* = RunCompareOutputStep{ | |
| 248 | 256 | .context = context, |
| 249 | 257 | .exe_path = exe_path, |
| 250 | 258 | .name = name, |
| ... | ... | @@ -252,7 +260,7 @@ pub const CompareOutputContext = struct { |
| 252 | 260 | .test_index = context.test_index, |
| 253 | 261 | .step = build.Step.init("RunCompareOutput", allocator, make), |
| 254 | 262 | .cli_args = cli_args, |
| 255 | }) catch unreachable; | |
| 263 | }; | |
| 256 | 264 | context.test_index += 1; |
| 257 | 265 | return ptr; |
| 258 | 266 | } |
| ... | ... | @@ -331,13 +339,14 @@ pub const CompareOutputContext = struct { |
| 331 | 339 | |
| 332 | 340 | pub fn create(context: *CompareOutputContext, exe_path: []const u8, name: []const u8) *RuntimeSafetyRunStep { |
| 333 | 341 | const allocator = context.b.allocator; |
| 334 | const ptr = allocator.create(RuntimeSafetyRunStep{ | |
| 342 | const ptr = allocator.create(RuntimeSafetyRunStep) catch unreachable; | |
| 343 | ptr.* = RuntimeSafetyRunStep{ | |
| 335 | 344 | .context = context, |
| 336 | 345 | .exe_path = exe_path, |
| 337 | 346 | .name = name, |
| 338 | 347 | .test_index = context.test_index, |
| 339 | 348 | .step = build.Step.init("RuntimeSafetyRun", allocator, make), |
| 340 | }) catch unreachable; | |
| 349 | }; | |
| 341 | 350 | |
| 342 | 351 | context.test_index += 1; |
| 343 | 352 | return ptr; |
| ... | ... | @@ -542,14 +551,15 @@ pub const CompileErrorContext = struct { |
| 542 | 551 | |
| 543 | 552 | pub fn create(context: *CompileErrorContext, name: []const u8, case: *const TestCase, build_mode: Mode) *CompileCmpOutputStep { |
| 544 | 553 | const allocator = context.b.allocator; |
| 545 | const ptr = allocator.create(CompileCmpOutputStep{ | |
| 554 | const ptr = allocator.create(CompileCmpOutputStep) catch unreachable; | |
| 555 | ptr.* = CompileCmpOutputStep{ | |
| 546 | 556 | .step = build.Step.init("CompileCmpOutput", allocator, make), |
| 547 | 557 | .context = context, |
| 548 | 558 | .name = name, |
| 549 | 559 | .test_index = context.test_index, |
| 550 | 560 | .case = case, |
| 551 | 561 | .build_mode = build_mode, |
| 552 | }) catch unreachable; | |
| 562 | }; | |
| 553 | 563 | |
| 554 | 564 | context.test_index += 1; |
| 555 | 565 | return ptr; |
| ... | ... | @@ -661,13 +671,14 @@ pub const CompileErrorContext = struct { |
| 661 | 671 | } |
| 662 | 672 | |
| 663 | 673 | pub fn create(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) *TestCase { |
| 664 | const tc = self.b.allocator.create(TestCase{ | |
| 674 | const tc = self.b.allocator.create(TestCase) catch unreachable; | |
| 675 | tc.* = TestCase{ | |
| 665 | 676 | .name = name, |
| 666 | 677 | .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), |
| 667 | 678 | .expected_errors = ArrayList([]const u8).init(self.b.allocator), |
| 668 | 679 | .link_libc = false, |
| 669 | 680 | .is_exe = false, |
| 670 | }) catch unreachable; | |
| 681 | }; | |
| 671 | 682 | |
| 672 | 683 | tc.addSourceFile(".tmp_source.zig", source); |
| 673 | 684 | comptime var arg_i = 0; |
| ... | ... | @@ -821,13 +832,14 @@ pub const TranslateCContext = struct { |
| 821 | 832 | |
| 822 | 833 | pub fn create(context: *TranslateCContext, name: []const u8, case: *const TestCase) *TranslateCCmpOutputStep { |
| 823 | 834 | const allocator = context.b.allocator; |
| 824 | const ptr = allocator.create(TranslateCCmpOutputStep{ | |
| 835 | const ptr = allocator.create(TranslateCCmpOutputStep) catch unreachable; | |
| 836 | ptr.* = TranslateCCmpOutputStep{ | |
| 825 | 837 | .step = build.Step.init("ParseCCmpOutput", allocator, make), |
| 826 | 838 | .context = context, |
| 827 | 839 | .name = name, |
| 828 | 840 | .test_index = context.test_index, |
| 829 | 841 | .case = case, |
| 830 | }) catch unreachable; | |
| 842 | }; | |
| 831 | 843 | |
| 832 | 844 | context.test_index += 1; |
| 833 | 845 | return ptr; |
| ... | ... | @@ -928,12 +940,13 @@ pub const TranslateCContext = struct { |
| 928 | 940 | } |
| 929 | 941 | |
| 930 | 942 | pub fn create(self: *TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase { |
| 931 | const tc = self.b.allocator.create(TestCase{ | |
| 943 | const tc = self.b.allocator.create(TestCase) catch unreachable; | |
| 944 | tc.* = TestCase{ | |
| 932 | 945 | .name = name, |
| 933 | 946 | .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), |
| 934 | 947 | .expected_lines = ArrayList([]const u8).init(self.b.allocator), |
| 935 | 948 | .allow_warnings = allow_warnings, |
| 936 | }) catch unreachable; | |
| 949 | }; | |
| 937 | 950 | |
| 938 | 951 | tc.addSourceFile(filename, source); |
| 939 | 952 | comptime var arg_i = 0; |
| ... | ... | @@ -1015,14 +1028,15 @@ pub const GenHContext = struct { |
| 1015 | 1028 | |
| 1016 | 1029 | pub fn create(context: *GenHContext, h_path: []const u8, name: []const u8, case: *const TestCase) *GenHCmpOutputStep { |
| 1017 | 1030 | const allocator = context.b.allocator; |
| 1018 | const ptr = allocator.create(GenHCmpOutputStep{ | |
| 1031 | const ptr = allocator.create(GenHCmpOutputStep) catch unreachable; | |
| 1032 | ptr.* = GenHCmpOutputStep{ | |
| 1019 | 1033 | .step = build.Step.init("ParseCCmpOutput", allocator, make), |
| 1020 | 1034 | .context = context, |
| 1021 | 1035 | .h_path = h_path, |
| 1022 | 1036 | .name = name, |
| 1023 | 1037 | .test_index = context.test_index, |
| 1024 | 1038 | .case = case, |
| 1025 | }) catch unreachable; | |
| 1039 | }; | |
| 1026 | 1040 | |
| 1027 | 1041 | context.test_index += 1; |
| 1028 | 1042 | return ptr; |
| ... | ... | @@ -1062,11 +1076,12 @@ pub const GenHContext = struct { |
| 1062 | 1076 | } |
| 1063 | 1077 | |
| 1064 | 1078 | pub fn create(self: *GenHContext, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase { |
| 1065 | const tc = self.b.allocator.create(TestCase{ | |
| 1079 | const tc = self.b.allocator.create(TestCase) catch unreachable; | |
| 1080 | tc.* = TestCase{ | |
| 1066 | 1081 | .name = name, |
| 1067 | 1082 | .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), |
| 1068 | 1083 | .expected_lines = ArrayList([]const u8).init(self.b.allocator), |
| 1069 | }) catch unreachable; | |
| 1084 | }; | |
| 1070 | 1085 | |
| 1071 | 1086 | tc.addSourceFile(filename, source); |
| 1072 | 1087 | comptime var arg_i = 0; |