| author | |
| committer | |
| log | 4eca75c53b4679e7e31df1505d22a5b618a2d797 |
| tree | 1682c01aac310e445a68830545f670d121ac38ea |
| parent | 55193cb13bbc69350474f6a66728319b41149274 |
| parent | 85f928f8bff8c033f6ef0104d68b033669cb36e4 |
16 files changed, 191 insertions(+), 216 deletions(-)
src-self-hosted/errmsg.zig+1-1| ... | ... | @@ -35,7 +35,7 @@ pub fn createFromParseError( |
| 35 | 35 | var out_stream = &std.io.BufferOutStream.init(&text_buf).stream; |
| 36 | 36 | try parse_error.render(&tree.tokens, out_stream); |
| 37 | 37 | |
| 38 | const msg = try allocator.construct(Msg{ | |
| 38 | const msg = try allocator.create(Msg{ | |
| 39 | 39 | .tree = tree, |
| 40 | 40 | .path = path, |
| 41 | 41 | .text = text_buf.toOwnedSlice(), |
src-self-hosted/main.zig+1-1| ... | ... | @@ -707,7 +707,7 @@ const Fmt = struct { |
| 707 | 707 | |
| 708 | 708 | // file_path must outlive Fmt |
| 709 | 709 | fn addToQueue(self: *Fmt, file_path: []const u8) !void { |
| 710 | const new_node = try self.seen.allocator.construct(std.LinkedList([]const u8).Node{ | |
| 710 | const new_node = try self.seen.allocator.create(std.LinkedList([]const u8).Node{ | |
| 711 | 711 | .prev = undefined, |
| 712 | 712 | .next = undefined, |
| 713 | 713 | .data = file_path, |
src-self-hosted/module.zig+21-14| ... | ... | @@ -110,11 +110,12 @@ pub const Module = struct { |
| 110 | 110 | parent: ?*CliPkg, |
| 111 | 111 | |
| 112 | 112 | pub fn init(allocator: *mem.Allocator, name: []const u8, path: []const u8, parent: ?*CliPkg) !*CliPkg { |
| 113 | var pkg = try allocator.create(CliPkg); | |
| 114 | pkg.name = name; | |
| 115 | pkg.path = path; | |
| 116 | pkg.children = ArrayList(*CliPkg).init(allocator); | |
| 117 | pkg.parent = parent; | |
| 113 | var pkg = try allocator.create(CliPkg{ | |
| 114 | .name = name, | |
| 115 | .path = path, | |
| 116 | .children = ArrayList(*CliPkg).init(allocator), | |
| 117 | .parent = parent, | |
| 118 | }); | |
| 118 | 119 | return pkg; |
| 119 | 120 | } |
| 120 | 121 | |
| ... | ... | @@ -126,7 +127,16 @@ pub const Module = struct { |
| 126 | 127 | } |
| 127 | 128 | }; |
| 128 | 129 | |
| 129 | pub fn create(allocator: *mem.Allocator, name: []const u8, root_src_path: ?[]const u8, target: *const Target, kind: Kind, build_mode: builtin.Mode, zig_lib_dir: []const u8, cache_dir: []const u8) !*Module { | |
| 130 | pub fn create( | |
| 131 | allocator: *mem.Allocator, | |
| 132 | name: []const u8, | |
| 133 | root_src_path: ?[]const u8, | |
| 134 | target: *const Target, | |
| 135 | kind: Kind, | |
| 136 | build_mode: builtin.Mode, | |
| 137 | zig_lib_dir: []const u8, | |
| 138 | cache_dir: []const u8, | |
| 139 | ) !*Module { | |
| 130 | 140 | var name_buffer = try Buffer.init(allocator, name); |
| 131 | 141 | errdefer name_buffer.deinit(); |
| 132 | 142 | |
| ... | ... | @@ -139,10 +149,7 @@ pub const Module = struct { |
| 139 | 149 | const builder = c.LLVMCreateBuilderInContext(context) orelse return error.OutOfMemory; |
| 140 | 150 | errdefer c.LLVMDisposeBuilder(builder); |
| 141 | 151 | |
| 142 | const module_ptr = try allocator.create(Module); | |
| 143 | errdefer allocator.destroy(module_ptr); | |
| 144 | ||
| 145 | module_ptr.* = Module{ | |
| 152 | const module_ptr = try allocator.create(Module{ | |
| 146 | 153 | .allocator = allocator, |
| 147 | 154 | .name = name_buffer, |
| 148 | 155 | .root_src_path = root_src_path, |
| ... | ... | @@ -196,7 +203,8 @@ pub const Module = struct { |
| 196 | 203 | .test_filters = [][]const u8{}, |
| 197 | 204 | .test_name_prefix = null, |
| 198 | 205 | .emit_file_type = Emit.Binary, |
| 199 | }; | |
| 206 | }); | |
| 207 | errdefer allocator.destroy(module_ptr); | |
| 200 | 208 | return module_ptr; |
| 201 | 209 | } |
| 202 | 210 | |
| ... | ... | @@ -279,13 +287,12 @@ pub const Module = struct { |
| 279 | 287 | } |
| 280 | 288 | } |
| 281 | 289 | |
| 282 | const link_lib = try self.allocator.create(LinkLib); | |
| 283 | link_lib.* = LinkLib{ | |
| 290 | const link_lib = try self.allocator.create(LinkLib{ | |
| 284 | 291 | .name = name, |
| 285 | 292 | .path = null, |
| 286 | 293 | .provided_explicitly = provided_explicitly, |
| 287 | 294 | .symbols = ArrayList([]u8).init(self.allocator), |
| 288 | }; | |
| 295 | }); | |
| 289 | 296 | try self.link_libs_list.append(link_lib); |
| 290 | 297 | if (is_libc) { |
| 291 | 298 | self.libc_link_lib = link_lib; |
std/atomic/queue.zig+4-2| ... | ... | @@ -114,8 +114,10 @@ fn startPuts(ctx: *Context) u8 { |
| 114 | 114 | while (put_count != 0) : (put_count -= 1) { |
| 115 | 115 | std.os.time.sleep(0, 1); // let the os scheduler be our fuzz |
| 116 | 116 | const x = @bitCast(i32, r.random.scalar(u32)); |
| 117 | const node = ctx.allocator.create(Queue(i32).Node) catch unreachable; | |
| 118 | node.data = x; | |
| 117 | const node = ctx.allocator.create(Queue(i32).Node{ | |
| 118 | .next = undefined, | |
| 119 | .data = x, | |
| 120 | }) catch unreachable; | |
| 119 | 121 | ctx.queue.put(node); |
| 120 | 122 | _ = @atomicRmw(isize, &ctx.put_sum, builtin.AtomicRmwOp.Add, x, AtomicOrder.SeqCst); |
| 121 | 123 | } |
std/atomic/stack.zig+4-2| ... | ... | @@ -117,8 +117,10 @@ fn startPuts(ctx: *Context) u8 { |
| 117 | 117 | while (put_count != 0) : (put_count -= 1) { |
| 118 | 118 | std.os.time.sleep(0, 1); // let the os scheduler be our fuzz |
| 119 | 119 | const x = @bitCast(i32, r.random.scalar(u32)); |
| 120 | const node = ctx.allocator.create(Stack(i32).Node) catch unreachable; | |
| 121 | node.data = x; | |
| 120 | const node = ctx.allocator.create(Stack(i32).Node{ | |
| 121 | .next = undefined, | |
| 122 | .data = x, | |
| 123 | }) catch unreachable; | |
| 122 | 124 | ctx.stack.push(node); |
| 123 | 125 | _ = @atomicRmw(isize, &ctx.put_sum, builtin.AtomicRmwOp.Add, x, AtomicOrder.SeqCst); |
| 124 | 126 | } |
std/build.zig+20-35| ... | ... | @@ -158,8 +158,7 @@ pub const Builder = struct { |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | pub fn addTest(self: *Builder, root_src: []const u8) *TestStep { |
| 161 | const test_step = self.allocator.create(TestStep) catch unreachable; | |
| 162 | test_step.* = TestStep.init(self, root_src); | |
| 161 | const test_step = self.allocator.create(TestStep.init(self, root_src)) catch unreachable; | |
| 163 | 162 | return test_step; |
| 164 | 163 | } |
| 165 | 164 | |
| ... | ... | @@ -191,21 +190,18 @@ pub const Builder = struct { |
| 191 | 190 | } |
| 192 | 191 | |
| 193 | 192 | pub fn addWriteFile(self: *Builder, file_path: []const u8, data: []const u8) *WriteFileStep { |
| 194 | const write_file_step = self.allocator.create(WriteFileStep) catch unreachable; | |
| 195 | write_file_step.* = WriteFileStep.init(self, file_path, data); | |
| 193 | const write_file_step = self.allocator.create(WriteFileStep.init(self, file_path, data)) catch unreachable; | |
| 196 | 194 | return write_file_step; |
| 197 | 195 | } |
| 198 | 196 | |
| 199 | 197 | pub fn addLog(self: *Builder, comptime format: []const u8, args: ...) *LogStep { |
| 200 | 198 | const data = self.fmt(format, args); |
| 201 | const log_step = self.allocator.create(LogStep) catch unreachable; | |
| 202 | log_step.* = LogStep.init(self, data); | |
| 199 | const log_step = self.allocator.create(LogStep.init(self, data)) catch unreachable; | |
| 203 | 200 | return log_step; |
| 204 | 201 | } |
| 205 | 202 | |
| 206 | 203 | pub fn addRemoveDirTree(self: *Builder, dir_path: []const u8) *RemoveDirStep { |
| 207 | const remove_dir_step = self.allocator.create(RemoveDirStep) catch unreachable; | |
| 208 | remove_dir_step.* = RemoveDirStep.init(self, dir_path); | |
| 204 | const remove_dir_step = self.allocator.create(RemoveDirStep.init(self, dir_path)) catch unreachable; | |
| 209 | 205 | return remove_dir_step; |
| 210 | 206 | } |
| 211 | 207 | |
| ... | ... | @@ -404,11 +400,10 @@ pub const Builder = struct { |
| 404 | 400 | } |
| 405 | 401 | |
| 406 | 402 | pub fn step(self: *Builder, name: []const u8, description: []const u8) *Step { |
| 407 | const step_info = self.allocator.create(TopLevelStep) catch unreachable; | |
| 408 | step_info.* = TopLevelStep{ | |
| 403 | const step_info = self.allocator.create(TopLevelStep{ | |
| 409 | 404 | .step = Step.initNoOp(name, self.allocator), |
| 410 | 405 | .description = description, |
| 411 | }; | |
| 406 | }) catch unreachable; | |
| 412 | 407 | self.top_level_steps.append(step_info) catch unreachable; |
| 413 | 408 | return &step_info.step; |
| 414 | 409 | } |
| ... | ... | @@ -598,8 +593,7 @@ pub const Builder = struct { |
| 598 | 593 | const full_dest_path = os.path.resolve(self.allocator, self.prefix, dest_rel_path) catch unreachable; |
| 599 | 594 | self.pushInstalledFile(full_dest_path); |
| 600 | 595 | |
| 601 | const install_step = self.allocator.create(InstallFileStep) catch unreachable; | |
| 602 | install_step.* = InstallFileStep.init(self, src_path, full_dest_path); | |
| 596 | const install_step = self.allocator.create(InstallFileStep.init(self, src_path, full_dest_path)) catch unreachable; | |
| 603 | 597 | return install_step; |
| 604 | 598 | } |
| 605 | 599 | |
| ... | ... | @@ -837,51 +831,43 @@ pub const LibExeObjStep = struct { |
| 837 | 831 | }; |
| 838 | 832 | |
| 839 | 833 | pub fn createSharedLibrary(builder: *Builder, name: []const u8, root_src: ?[]const u8, ver: *const Version) *LibExeObjStep { |
| 840 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 841 | self.* = initExtraArgs(builder, name, root_src, Kind.Lib, false, ver); | |
| 834 | const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Lib, false, ver)) catch unreachable; | |
| 842 | 835 | return self; |
| 843 | 836 | } |
| 844 | 837 | |
| 845 | 838 | pub fn createCSharedLibrary(builder: *Builder, name: []const u8, version: *const Version) *LibExeObjStep { |
| 846 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 847 | self.* = initC(builder, name, Kind.Lib, version, false); | |
| 839 | const self = builder.allocator.create(initC(builder, name, Kind.Lib, version, false)) catch unreachable; | |
| 848 | 840 | return self; |
| 849 | 841 | } |
| 850 | 842 | |
| 851 | 843 | pub fn createStaticLibrary(builder: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep { |
| 852 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 853 | self.* = initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0)); | |
| 844 | const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0))) catch unreachable; | |
| 854 | 845 | return self; |
| 855 | 846 | } |
| 856 | 847 | |
| 857 | 848 | pub fn createCStaticLibrary(builder: *Builder, name: []const u8) *LibExeObjStep { |
| 858 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 859 | self.* = initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true); | |
| 849 | const self = builder.allocator.create(initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true)) catch unreachable; | |
| 860 | 850 | return self; |
| 861 | 851 | } |
| 862 | 852 | |
| 863 | 853 | pub fn createObject(builder: *Builder, name: []const u8, root_src: []const u8) *LibExeObjStep { |
| 864 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 865 | self.* = initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0)); | |
| 854 | const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0))) catch unreachable; | |
| 866 | 855 | return self; |
| 867 | 856 | } |
| 868 | 857 | |
| 869 | 858 | pub fn createCObject(builder: *Builder, name: []const u8, src: []const u8) *LibExeObjStep { |
| 870 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 871 | self.* = initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false); | |
| 859 | const self = builder.allocator.create(initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false)) catch unreachable; | |
| 872 | 860 | self.object_src = src; |
| 873 | 861 | return self; |
| 874 | 862 | } |
| 875 | 863 | |
| 876 | 864 | pub fn createExecutable(builder: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep { |
| 877 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 878 | self.* = initExtraArgs(builder, name, root_src, Kind.Exe, false, builder.version(0, 0, 0)); | |
| 865 | const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Exe, false, builder.version(0, 0, 0))) catch unreachable; | |
| 879 | 866 | return self; |
| 880 | 867 | } |
| 881 | 868 | |
| 882 | 869 | pub fn createCExecutable(builder: *Builder, name: []const u8) *LibExeObjStep { |
| 883 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 884 | self.* = initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false); | |
| 870 | const self = builder.allocator.create(initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false)) catch unreachable; | |
| 885 | 871 | return self; |
| 886 | 872 | } |
| 887 | 873 | |
| ... | ... | @@ -1748,14 +1734,14 @@ pub const CommandStep = struct { |
| 1748 | 1734 | |
| 1749 | 1735 | /// ::argv is copied. |
| 1750 | 1736 | pub fn create(builder: *Builder, cwd: ?[]const u8, env_map: *const BufMap, argv: []const []const u8) *CommandStep { |
| 1751 | const self = builder.allocator.create(CommandStep) catch unreachable; | |
| 1752 | self.* = CommandStep{ | |
| 1737 | const self = builder.allocator.create(CommandStep{ | |
| 1753 | 1738 | .builder = builder, |
| 1754 | 1739 | .step = Step.init(argv[0], builder.allocator, make), |
| 1755 | 1740 | .argv = builder.allocator.alloc([]u8, argv.len) catch unreachable, |
| 1756 | 1741 | .cwd = cwd, |
| 1757 | 1742 | .env_map = env_map, |
| 1758 | }; | |
| 1743 | }) catch unreachable; | |
| 1744 | ||
| 1759 | 1745 | mem.copy([]const u8, self.argv, argv); |
| 1760 | 1746 | self.step.name = self.argv[0]; |
| 1761 | 1747 | return self; |
| ... | ... | @@ -1778,18 +1764,17 @@ const InstallArtifactStep = struct { |
| 1778 | 1764 | const Self = this; |
| 1779 | 1765 | |
| 1780 | 1766 | pub fn create(builder: *Builder, artifact: *LibExeObjStep) *Self { |
| 1781 | const self = builder.allocator.create(Self) catch unreachable; | |
| 1782 | 1767 | const dest_dir = switch (artifact.kind) { |
| 1783 | 1768 | LibExeObjStep.Kind.Obj => unreachable, |
| 1784 | 1769 | LibExeObjStep.Kind.Exe => builder.exe_dir, |
| 1785 | 1770 | LibExeObjStep.Kind.Lib => builder.lib_dir, |
| 1786 | 1771 | }; |
| 1787 | self.* = Self{ | |
| 1772 | const self = builder.allocator.create(Self{ | |
| 1788 | 1773 | .builder = builder, |
| 1789 | 1774 | .step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make), |
| 1790 | 1775 | .artifact = artifact, |
| 1791 | 1776 | .dest_file = os.path.join(builder.allocator, dest_dir, artifact.out_filename) catch unreachable, |
| 1792 | }; | |
| 1777 | }) catch unreachable; | |
| 1793 | 1778 | self.step.dependOn(&artifact.step); |
| 1794 | 1779 | builder.pushInstalledFile(self.dest_file); |
| 1795 | 1780 | if (self.artifact.kind == LibExeObjStep.Kind.Lib and !self.artifact.static) { |
std/debug/index.zig+5-10| ... | ... | @@ -249,9 +249,7 @@ fn printSourceAtAddress(debug_info: *ElfStackTrace, out_stream: var, address: us |
| 249 | 249 | pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace { |
| 250 | 250 | switch (builtin.object_format) { |
| 251 | 251 | builtin.ObjectFormat.elf => { |
| 252 | const st = try allocator.create(ElfStackTrace); | |
| 253 | errdefer allocator.destroy(st); | |
| 254 | st.* = ElfStackTrace{ | |
| 252 | const st = try allocator.create(ElfStackTrace{ | |
| 255 | 253 | .self_exe_file = undefined, |
| 256 | 254 | .elf = undefined, |
| 257 | 255 | .debug_info = undefined, |
| ... | ... | @@ -261,7 +259,8 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace { |
| 261 | 259 | .debug_ranges = null, |
| 262 | 260 | .abbrev_table_list = ArrayList(AbbrevTableHeader).init(allocator), |
| 263 | 261 | .compile_unit_list = ArrayList(CompileUnit).init(allocator), |
| 264 | }; | |
| 262 | }); | |
| 263 | errdefer allocator.destroy(st); | |
| 265 | 264 | st.self_exe_file = try os.openSelfExe(); |
| 266 | 265 | errdefer st.self_exe_file.close(); |
| 267 | 266 | |
| ... | ... | @@ -280,11 +279,8 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace { |
| 280 | 279 | var exe_file = try os.openSelfExe(); |
| 281 | 280 | defer exe_file.close(); |
| 282 | 281 | |
| 283 | const st = try allocator.create(ElfStackTrace); | |
| 282 | const st = try allocator.create(ElfStackTrace{ .symbol_table = try macho.loadSymbols(allocator, &io.FileInStream.init(&exe_file)) }); | |
| 284 | 283 | errdefer allocator.destroy(st); |
| 285 | ||
| 286 | st.* = ElfStackTrace{ .symbol_table = try macho.loadSymbols(allocator, &io.FileInStream.init(&exe_file)) }; | |
| 287 | ||
| 288 | 284 | return st; |
| 289 | 285 | }, |
| 290 | 286 | builtin.ObjectFormat.coff => { |
| ... | ... | @@ -974,8 +970,7 @@ fn scanAllCompileUnits(st: *ElfStackTrace) !void { |
| 974 | 970 | |
| 975 | 971 | try st.self_exe_file.seekTo(compile_unit_pos); |
| 976 | 972 | |
| 977 | const compile_unit_die = try st.allocator().create(Die); | |
| 978 | compile_unit_die.* = try parseDie(st, abbrev_table, is_64); | |
| 973 | const compile_unit_die = try st.allocator().create(try parseDie(st, abbrev_table, is_64)); | |
| 979 | 974 | |
| 980 | 975 | if (compile_unit_die.tag_id != DW.TAG_compile_unit) return error.InvalidDebugInfo; |
| 981 | 976 |
std/heap.zig+1-2| ... | ... | @@ -407,8 +407,7 @@ fn testAllocator(allocator: *mem.Allocator) !void { |
| 407 | 407 | var slice = try allocator.alloc(*i32, 100); |
| 408 | 408 | |
| 409 | 409 | for (slice) |*item, i| { |
| 410 | item.* = try allocator.create(i32); | |
| 411 | item.*.* = @intCast(i32, i); | |
| 410 | item.* = try allocator.create(@intCast(i32, i)); | |
| 412 | 411 | } |
| 413 | 412 | |
| 414 | 413 | for (slice) |item, i| { |
std/io.zig+3-5| ... | ... | @@ -414,14 +414,12 @@ pub const BufferedAtomicFile = struct { |
| 414 | 414 | |
| 415 | 415 | pub fn create(allocator: *mem.Allocator, dest_path: []const u8) !*BufferedAtomicFile { |
| 416 | 416 | // TODO with well defined copy elision we don't need this allocation |
| 417 | var self = try allocator.create(BufferedAtomicFile); | |
| 418 | errdefer allocator.destroy(self); | |
| 419 | ||
| 420 | self.* = BufferedAtomicFile{ | |
| 417 | var self = try allocator.create(BufferedAtomicFile{ | |
| 421 | 418 | .atomic_file = undefined, |
| 422 | 419 | .file_stream = undefined, |
| 423 | 420 | .buffered_stream = undefined, |
| 424 | }; | |
| 421 | }); | |
| 422 | errdefer allocator.destroy(self); | |
| 425 | 423 | |
| 426 | 424 | self.atomic_file = try os.AtomicFile.init(allocator, dest_path, os.default_file_mode); |
| 427 | 425 | errdefer self.atomic_file.deinit(); |
std/linked_list.zig+1-1| ... | ... | @@ -193,7 +193,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na |
| 193 | 193 | /// A pointer to the new node. |
| 194 | 194 | pub fn allocateNode(list: *Self, allocator: *Allocator) !*Node { |
| 195 | 195 | comptime assert(!isIntrusive()); |
| 196 | return allocator.create(Node); | |
| 196 | return allocator.create(Node(undefined)); | |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /// Deallocate a node. |
std/mem.zig+3-11| ... | ... | @@ -31,16 +31,8 @@ pub const Allocator = struct { |
| 31 | 31 | /// Guaranteed: `old_mem.len` is the same as what was returned from `allocFn` or `reallocFn` |
| 32 | 32 | freeFn: fn (self: *Allocator, old_mem: []u8) void, |
| 33 | 33 | |
| 34 | /// Call destroy with the result | |
| 35 | pub fn create(self: *Allocator, comptime T: type) !*T { | |
| 36 | if (@sizeOf(T) == 0) return *{}; | |
| 37 | const slice = try self.alloc(T, 1); | |
| 38 | return &slice[0]; | |
| 39 | } | |
| 40 | ||
| 41 | /// Call destroy with the result | |
| 42 | /// TODO once #733 is solved, this will replace create | |
| 43 | pub fn construct(self: *Allocator, init: var) Error!*@typeOf(init) { | |
| 34 | /// Call `destroy` with the result | |
| 35 | pub fn create(self: *Allocator, init: var) Error!*@typeOf(init) { | |
| 44 | 36 | const T = @typeOf(init); |
| 45 | 37 | if (@sizeOf(T) == 0) return &{}; |
| 46 | 38 | const slice = try self.alloc(T, 1); |
| ... | ... | @@ -49,7 +41,7 @@ pub const Allocator = struct { |
| 49 | 41 | return ptr; |
| 50 | 42 | } |
| 51 | 43 | |
| 52 | /// `ptr` should be the return value of `construct` or `create` | |
| 44 | /// `ptr` should be the return value of `create` | |
| 53 | 45 | pub fn destroy(self: *Allocator, ptr: var) void { |
| 54 | 46 | const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr)); |
| 55 | 47 | self.freeFn(self, non_const_ptr[0..@sizeOf(@typeOf(ptr).Child)]); |
std/os/child_process.zig+3-6| ... | ... | @@ -85,10 +85,7 @@ pub const ChildProcess = struct { |
| 85 | 85 | /// First argument in argv is the executable. |
| 86 | 86 | /// On success must call deinit. |
| 87 | 87 | pub fn init(argv: []const []const u8, allocator: *mem.Allocator) !*ChildProcess { |
| 88 | const child = try allocator.create(ChildProcess); | |
| 89 | errdefer allocator.destroy(child); | |
| 90 | ||
| 91 | child.* = ChildProcess{ | |
| 88 | const child = try allocator.create(ChildProcess{ | |
| 92 | 89 | .allocator = allocator, |
| 93 | 90 | .argv = argv, |
| 94 | 91 | .pid = undefined, |
| ... | ... | @@ -109,8 +106,8 @@ pub const ChildProcess = struct { |
| 109 | 106 | .stdin_behavior = StdIo.Inherit, |
| 110 | 107 | .stdout_behavior = StdIo.Inherit, |
| 111 | 108 | .stderr_behavior = StdIo.Inherit, |
| 112 | }; | |
| 113 | ||
| 109 | }); | |
| 110 | errdefer allocator.destroy(child); | |
| 114 | 111 | return child; |
| 115 | 112 | } |
| 116 | 113 |
std/os/index.zig+11-5| ... | ... | @@ -2468,7 +2468,7 @@ pub const Thread = struct { |
| 2468 | 2468 | data: Data, |
| 2469 | 2469 | |
| 2470 | 2470 | pub const use_pthreads = is_posix and builtin.link_libc; |
| 2471 | const Data = if (use_pthreads) | |
| 2471 | pub const Data = if (use_pthreads) | |
| 2472 | 2472 | struct { |
| 2473 | 2473 | handle: c.pthread_t, |
| 2474 | 2474 | stack_addr: usize, |
| ... | ... | @@ -2582,10 +2582,16 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread |
| 2582 | 2582 | const bytes_ptr = windows.HeapAlloc(heap_handle, 0, byte_count) orelse return SpawnThreadError.OutOfMemory; |
| 2583 | 2583 | errdefer assert(windows.HeapFree(heap_handle, 0, bytes_ptr) != 0); |
| 2584 | 2584 | const bytes = @ptrCast([*]u8, bytes_ptr)[0..byte_count]; |
| 2585 | const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext) catch unreachable; | |
| 2586 | outer_context.inner = context; | |
| 2587 | outer_context.thread.data.heap_handle = heap_handle; | |
| 2588 | outer_context.thread.data.alloc_start = bytes_ptr; | |
| 2585 | const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext{ | |
| 2586 | .thread = Thread{ | |
| 2587 | .data = Thread.Data{ | |
| 2588 | .heap_handle = heap_handle, | |
| 2589 | .alloc_start = bytes_ptr, | |
| 2590 | .handle = undefined, | |
| 2591 | }, | |
| 2592 | }, | |
| 2593 | .inner = context, | |
| 2594 | }) catch unreachable; | |
| 2589 | 2595 | |
| 2590 | 2596 | const parameter = if (@sizeOf(Context) == 0) null else @ptrCast(*c_void, &outer_context.inner); |
| 2591 | 2597 | outer_context.thread.data.handle = windows.CreateThread(null, default_stack_size, WinThread.threadMain, parameter, 0, null) orelse { |
std/zig/parse.zig+75-75| ... | ... | @@ -17,7 +17,7 @@ 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.construct(ast.Node.Root{ | |
| 20 | const root_node = try arena.create(ast.Node.Root{ | |
| 21 | 21 | .base = ast.Node{ .id = ast.Node.Id.Root }, |
| 22 | 22 | .decls = ast.Node.Root.DeclList.init(arena), |
| 23 | 23 | .doc_comments = null, |
| ... | ... | @@ -65,14 +65,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 65 | 65 | Token.Id.Keyword_test => { |
| 66 | 66 | stack.append(State.TopLevel) catch unreachable; |
| 67 | 67 | |
| 68 | const block = try arena.construct(ast.Node.Block{ | |
| 68 | const block = try arena.create(ast.Node.Block{ | |
| 69 | 69 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 70 | 70 | .label = null, |
| 71 | 71 | .lbrace = undefined, |
| 72 | 72 | .statements = ast.Node.Block.StatementList.init(arena), |
| 73 | 73 | .rbrace = undefined, |
| 74 | 74 | }); |
| 75 | const test_node = try arena.construct(ast.Node.TestDecl{ | |
| 75 | const test_node = try arena.create(ast.Node.TestDecl{ | |
| 76 | 76 | .base = ast.Node{ .id = ast.Node.Id.TestDecl }, |
| 77 | 77 | .doc_comments = comments, |
| 78 | 78 | .test_token = token_index, |
| ... | ... | @@ -109,14 +109,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 109 | 109 | continue; |
| 110 | 110 | }, |
| 111 | 111 | Token.Id.Keyword_comptime => { |
| 112 | const block = try arena.construct(ast.Node.Block{ | |
| 112 | const block = try arena.create(ast.Node.Block{ | |
| 113 | 113 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 114 | 114 | .label = null, |
| 115 | 115 | .lbrace = undefined, |
| 116 | 116 | .statements = ast.Node.Block.StatementList.init(arena), |
| 117 | 117 | .rbrace = undefined, |
| 118 | 118 | }); |
| 119 | const node = try arena.construct(ast.Node.Comptime{ | |
| 119 | const node = try arena.create(ast.Node.Comptime{ | |
| 120 | 120 | .base = ast.Node{ .id = ast.Node.Id.Comptime }, |
| 121 | 121 | .comptime_token = token_index, |
| 122 | 122 | .expr = &block.base, |
| ... | ... | @@ -225,7 +225,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 225 | 225 | return tree; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | const node = try arena.construct(ast.Node.Use{ | |
| 228 | const node = try arena.create(ast.Node.Use{ | |
| 229 | 229 | .base = ast.Node{ .id = ast.Node.Id.Use }, |
| 230 | 230 | .use_token = token_index, |
| 231 | 231 | .visib_token = ctx.visib_token, |
| ... | ... | @@ -266,7 +266,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 266 | 266 | continue; |
| 267 | 267 | }, |
| 268 | 268 | Token.Id.Keyword_fn, Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc, Token.Id.Keyword_async => { |
| 269 | const fn_proto = try arena.construct(ast.Node.FnProto{ | |
| 269 | const fn_proto = try arena.create(ast.Node.FnProto{ | |
| 270 | 270 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, |
| 271 | 271 | .doc_comments = ctx.comments, |
| 272 | 272 | .visib_token = ctx.visib_token, |
| ... | ... | @@ -298,7 +298,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 298 | 298 | continue; |
| 299 | 299 | }, |
| 300 | 300 | Token.Id.Keyword_async => { |
| 301 | const async_node = try arena.construct(ast.Node.AsyncAttribute{ | |
| 301 | const async_node = try arena.create(ast.Node.AsyncAttribute{ | |
| 302 | 302 | .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute }, |
| 303 | 303 | .async_token = token_index, |
| 304 | 304 | .allocator_type = null, |
| ... | ... | @@ -330,7 +330,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 330 | 330 | }, |
| 331 | 331 | State.TopLevelExternOrField => |ctx| { |
| 332 | 332 | if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |identifier| { |
| 333 | const node = try arena.construct(ast.Node.StructField{ | |
| 333 | const node = try arena.create(ast.Node.StructField{ | |
| 334 | 334 | .base = ast.Node{ .id = ast.Node.Id.StructField }, |
| 335 | 335 | .doc_comments = ctx.comments, |
| 336 | 336 | .visib_token = ctx.visib_token, |
| ... | ... | @@ -375,7 +375,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 375 | 375 | const token = nextToken(&tok_it, &tree); |
| 376 | 376 | const token_index = token.index; |
| 377 | 377 | const token_ptr = token.ptr; |
| 378 | const node = try arena.construct(ast.Node.ContainerDecl{ | |
| 378 | const node = try arena.create(ast.Node.ContainerDecl{ | |
| 379 | 379 | .base = ast.Node{ .id = ast.Node.Id.ContainerDecl }, |
| 380 | 380 | .layout_token = ctx.layout_token, |
| 381 | 381 | .kind_token = switch (token_ptr.id) { |
| ... | ... | @@ -448,7 +448,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 448 | 448 | Token.Id.Identifier => { |
| 449 | 449 | switch (tree.tokens.at(container_decl.kind_token).id) { |
| 450 | 450 | Token.Id.Keyword_struct => { |
| 451 | const node = try arena.construct(ast.Node.StructField{ | |
| 451 | const node = try arena.create(ast.Node.StructField{ | |
| 452 | 452 | .base = ast.Node{ .id = ast.Node.Id.StructField }, |
| 453 | 453 | .doc_comments = comments, |
| 454 | 454 | .visib_token = null, |
| ... | ... | @@ -464,7 +464,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 464 | 464 | continue; |
| 465 | 465 | }, |
| 466 | 466 | Token.Id.Keyword_union => { |
| 467 | const node = try arena.construct(ast.Node.UnionTag{ | |
| 467 | const node = try arena.create(ast.Node.UnionTag{ | |
| 468 | 468 | .base = ast.Node{ .id = ast.Node.Id.UnionTag }, |
| 469 | 469 | .name_token = token_index, |
| 470 | 470 | .type_expr = null, |
| ... | ... | @@ -480,7 +480,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 480 | 480 | continue; |
| 481 | 481 | }, |
| 482 | 482 | Token.Id.Keyword_enum => { |
| 483 | const node = try arena.construct(ast.Node.EnumTag{ | |
| 483 | const node = try arena.create(ast.Node.EnumTag{ | |
| 484 | 484 | .base = ast.Node{ .id = ast.Node.Id.EnumTag }, |
| 485 | 485 | .name_token = token_index, |
| 486 | 486 | .value = null, |
| ... | ... | @@ -562,7 +562,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 562 | 562 | }, |
| 563 | 563 | |
| 564 | 564 | State.VarDecl => |ctx| { |
| 565 | const var_decl = try arena.construct(ast.Node.VarDecl{ | |
| 565 | const var_decl = try arena.create(ast.Node.VarDecl{ | |
| 566 | 566 | .base = ast.Node{ .id = ast.Node.Id.VarDecl }, |
| 567 | 567 | .doc_comments = ctx.comments, |
| 568 | 568 | .visib_token = ctx.visib_token, |
| ... | ... | @@ -660,7 +660,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 660 | 660 | const token_ptr = token.ptr; |
| 661 | 661 | switch (token_ptr.id) { |
| 662 | 662 | Token.Id.LBrace => { |
| 663 | const block = try arena.construct(ast.Node.Block{ | |
| 663 | const block = try arena.create(ast.Node.Block{ | |
| 664 | 664 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 665 | 665 | .label = null, |
| 666 | 666 | .lbrace = token_index, |
| ... | ... | @@ -712,7 +712,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 712 | 712 | // TODO: this is a special case. Remove this when #760 is fixed |
| 713 | 713 | if (token_ptr.id == Token.Id.Keyword_error) { |
| 714 | 714 | if (tok_it.peek().?.id == Token.Id.LBrace) { |
| 715 | const error_type_node = try arena.construct(ast.Node.ErrorType{ | |
| 715 | const error_type_node = try arena.create(ast.Node.ErrorType{ | |
| 716 | 716 | .base = ast.Node{ .id = ast.Node.Id.ErrorType }, |
| 717 | 717 | .token = token_index, |
| 718 | 718 | }); |
| ... | ... | @@ -733,7 +733,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 733 | 733 | if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| { |
| 734 | 734 | continue; |
| 735 | 735 | } |
| 736 | const param_decl = try arena.construct(ast.Node.ParamDecl{ | |
| 736 | const param_decl = try arena.create(ast.Node.ParamDecl{ | |
| 737 | 737 | .base = ast.Node{ .id = ast.Node.Id.ParamDecl }, |
| 738 | 738 | .comptime_token = null, |
| 739 | 739 | .noalias_token = null, |
| ... | ... | @@ -819,7 +819,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 819 | 819 | const token_ptr = token.ptr; |
| 820 | 820 | switch (token_ptr.id) { |
| 821 | 821 | Token.Id.LBrace => { |
| 822 | const block = try arena.construct(ast.Node.Block{ | |
| 822 | const block = try arena.create(ast.Node.Block{ | |
| 823 | 823 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 824 | 824 | .label = ctx.label, |
| 825 | 825 | .lbrace = token_index, |
| ... | ... | @@ -853,7 +853,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 853 | 853 | continue; |
| 854 | 854 | }, |
| 855 | 855 | Token.Id.Keyword_suspend => { |
| 856 | const node = try arena.construct(ast.Node.Suspend{ | |
| 856 | const node = try arena.create(ast.Node.Suspend{ | |
| 857 | 857 | .base = ast.Node{ .id = ast.Node.Id.Suspend }, |
| 858 | 858 | .label = ctx.label, |
| 859 | 859 | .suspend_token = token_index, |
| ... | ... | @@ -925,7 +925,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 925 | 925 | } |
| 926 | 926 | }, |
| 927 | 927 | State.While => |ctx| { |
| 928 | const node = try arena.construct(ast.Node.While{ | |
| 928 | const node = try arena.create(ast.Node.While{ | |
| 929 | 929 | .base = ast.Node{ .id = ast.Node.Id.While }, |
| 930 | 930 | .label = ctx.label, |
| 931 | 931 | .inline_token = ctx.inline_token, |
| ... | ... | @@ -954,7 +954,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 954 | 954 | continue; |
| 955 | 955 | }, |
| 956 | 956 | State.For => |ctx| { |
| 957 | const node = try arena.construct(ast.Node.For{ | |
| 957 | const node = try arena.create(ast.Node.For{ | |
| 958 | 958 | .base = ast.Node{ .id = ast.Node.Id.For }, |
| 959 | 959 | .label = ctx.label, |
| 960 | 960 | .inline_token = ctx.inline_token, |
| ... | ... | @@ -975,7 +975,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 975 | 975 | }, |
| 976 | 976 | State.Else => |dest| { |
| 977 | 977 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| { |
| 978 | const node = try arena.construct(ast.Node.Else{ | |
| 978 | const node = try arena.create(ast.Node.Else{ | |
| 979 | 979 | .base = ast.Node{ .id = ast.Node.Id.Else }, |
| 980 | 980 | .else_token = else_token, |
| 981 | 981 | .payload = null, |
| ... | ... | @@ -1038,7 +1038,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1038 | 1038 | continue; |
| 1039 | 1039 | }, |
| 1040 | 1040 | Token.Id.Keyword_defer, Token.Id.Keyword_errdefer => { |
| 1041 | const node = try arena.construct(ast.Node.Defer{ | |
| 1041 | const node = try arena.create(ast.Node.Defer{ | |
| 1042 | 1042 | .base = ast.Node{ .id = ast.Node.Id.Defer }, |
| 1043 | 1043 | .defer_token = token_index, |
| 1044 | 1044 | .kind = switch (token_ptr.id) { |
| ... | ... | @@ -1056,7 +1056,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1056 | 1056 | continue; |
| 1057 | 1057 | }, |
| 1058 | 1058 | Token.Id.LBrace => { |
| 1059 | const inner_block = try arena.construct(ast.Node.Block{ | |
| 1059 | const inner_block = try arena.create(ast.Node.Block{ | |
| 1060 | 1060 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 1061 | 1061 | .label = null, |
| 1062 | 1062 | .lbrace = token_index, |
| ... | ... | @@ -1124,7 +1124,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1124 | 1124 | continue; |
| 1125 | 1125 | } |
| 1126 | 1126 | |
| 1127 | const node = try arena.construct(ast.Node.AsmOutput{ | |
| 1127 | const node = try arena.create(ast.Node.AsmOutput{ | |
| 1128 | 1128 | .base = ast.Node{ .id = ast.Node.Id.AsmOutput }, |
| 1129 | 1129 | .lbracket = lbracket_index, |
| 1130 | 1130 | .symbolic_name = undefined, |
| ... | ... | @@ -1178,7 +1178,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1178 | 1178 | continue; |
| 1179 | 1179 | } |
| 1180 | 1180 | |
| 1181 | const node = try arena.construct(ast.Node.AsmInput{ | |
| 1181 | const node = try arena.create(ast.Node.AsmInput{ | |
| 1182 | 1182 | .base = ast.Node{ .id = ast.Node.Id.AsmInput }, |
| 1183 | 1183 | .lbracket = lbracket_index, |
| 1184 | 1184 | .symbolic_name = undefined, |
| ... | ... | @@ -1243,7 +1243,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1243 | 1243 | continue; |
| 1244 | 1244 | } |
| 1245 | 1245 | |
| 1246 | const node = try arena.construct(ast.Node.FieldInitializer{ | |
| 1246 | const node = try arena.create(ast.Node.FieldInitializer{ | |
| 1247 | 1247 | .base = ast.Node{ .id = ast.Node.Id.FieldInitializer }, |
| 1248 | 1248 | .period_token = undefined, |
| 1249 | 1249 | .name_token = undefined, |
| ... | ... | @@ -1332,7 +1332,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1332 | 1332 | } |
| 1333 | 1333 | |
| 1334 | 1334 | const comments = try eatDocComments(arena, &tok_it, &tree); |
| 1335 | const node = try arena.construct(ast.Node.SwitchCase{ | |
| 1335 | const node = try arena.create(ast.Node.SwitchCase{ | |
| 1336 | 1336 | .base = ast.Node{ .id = ast.Node.Id.SwitchCase }, |
| 1337 | 1337 | .items = ast.Node.SwitchCase.ItemList.init(arena), |
| 1338 | 1338 | .payload = null, |
| ... | ... | @@ -1369,7 +1369,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1369 | 1369 | const token_index = token.index; |
| 1370 | 1370 | const token_ptr = token.ptr; |
| 1371 | 1371 | if (token_ptr.id == Token.Id.Keyword_else) { |
| 1372 | const else_node = try arena.construct(ast.Node.SwitchElse{ | |
| 1372 | const else_node = try arena.create(ast.Node.SwitchElse{ | |
| 1373 | 1373 | .base = ast.Node{ .id = ast.Node.Id.SwitchElse }, |
| 1374 | 1374 | .token = token_index, |
| 1375 | 1375 | }); |
| ... | ... | @@ -1468,7 +1468,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1468 | 1468 | |
| 1469 | 1469 | State.ExternType => |ctx| { |
| 1470 | 1470 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_fn)) |fn_token| { |
| 1471 | const fn_proto = try arena.construct(ast.Node.FnProto{ | |
| 1471 | const fn_proto = try arena.create(ast.Node.FnProto{ | |
| 1472 | 1472 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, |
| 1473 | 1473 | .doc_comments = ctx.comments, |
| 1474 | 1474 | .visib_token = null, |
| ... | ... | @@ -1641,7 +1641,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1641 | 1641 | continue; |
| 1642 | 1642 | } |
| 1643 | 1643 | |
| 1644 | const node = try arena.construct(ast.Node.Payload{ | |
| 1644 | const node = try arena.create(ast.Node.Payload{ | |
| 1645 | 1645 | .base = ast.Node{ .id = ast.Node.Id.Payload }, |
| 1646 | 1646 | .lpipe = token_index, |
| 1647 | 1647 | .error_symbol = undefined, |
| ... | ... | @@ -1677,7 +1677,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1677 | 1677 | continue; |
| 1678 | 1678 | } |
| 1679 | 1679 | |
| 1680 | const node = try arena.construct(ast.Node.PointerPayload{ | |
| 1680 | const node = try arena.create(ast.Node.PointerPayload{ | |
| 1681 | 1681 | .base = ast.Node{ .id = ast.Node.Id.PointerPayload }, |
| 1682 | 1682 | .lpipe = token_index, |
| 1683 | 1683 | .ptr_token = null, |
| ... | ... | @@ -1720,7 +1720,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1720 | 1720 | continue; |
| 1721 | 1721 | } |
| 1722 | 1722 | |
| 1723 | const node = try arena.construct(ast.Node.PointerIndexPayload{ | |
| 1723 | const node = try arena.create(ast.Node.PointerIndexPayload{ | |
| 1724 | 1724 | .base = ast.Node{ .id = ast.Node.Id.PointerIndexPayload }, |
| 1725 | 1725 | .lpipe = token_index, |
| 1726 | 1726 | .ptr_token = null, |
| ... | ... | @@ -1754,7 +1754,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1754 | 1754 | const token_ptr = token.ptr; |
| 1755 | 1755 | switch (token_ptr.id) { |
| 1756 | 1756 | Token.Id.Keyword_return, Token.Id.Keyword_break, Token.Id.Keyword_continue => { |
| 1757 | const node = try arena.construct(ast.Node.ControlFlowExpression{ | |
| 1757 | const node = try arena.create(ast.Node.ControlFlowExpression{ | |
| 1758 | 1758 | .base = ast.Node{ .id = ast.Node.Id.ControlFlowExpression }, |
| 1759 | 1759 | .ltoken = token_index, |
| 1760 | 1760 | .kind = undefined, |
| ... | ... | @@ -1783,7 +1783,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1783 | 1783 | continue; |
| 1784 | 1784 | }, |
| 1785 | 1785 | Token.Id.Keyword_try, Token.Id.Keyword_cancel, Token.Id.Keyword_resume => { |
| 1786 | const node = try arena.construct(ast.Node.PrefixOp{ | |
| 1786 | const node = try arena.create(ast.Node.PrefixOp{ | |
| 1787 | 1787 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, |
| 1788 | 1788 | .op_token = token_index, |
| 1789 | 1789 | .op = switch (token_ptr.id) { |
| ... | ... | @@ -1817,7 +1817,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1817 | 1817 | const lhs = opt_ctx.get() orelse continue; |
| 1818 | 1818 | |
| 1819 | 1819 | if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| { |
| 1820 | const node = try arena.construct(ast.Node.InfixOp{ | |
| 1820 | const node = try arena.create(ast.Node.InfixOp{ | |
| 1821 | 1821 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1822 | 1822 | .lhs = lhs, |
| 1823 | 1823 | .op_token = ellipsis3, |
| ... | ... | @@ -1842,7 +1842,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1842 | 1842 | const token_index = token.index; |
| 1843 | 1843 | const token_ptr = token.ptr; |
| 1844 | 1844 | if (tokenIdToAssignment(token_ptr.id)) |ass_id| { |
| 1845 | const node = try arena.construct(ast.Node.InfixOp{ | |
| 1845 | const node = try arena.create(ast.Node.InfixOp{ | |
| 1846 | 1846 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1847 | 1847 | .lhs = lhs, |
| 1848 | 1848 | .op_token = token_index, |
| ... | ... | @@ -1872,7 +1872,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1872 | 1872 | const token_index = token.index; |
| 1873 | 1873 | const token_ptr = token.ptr; |
| 1874 | 1874 | if (tokenIdToUnwrapExpr(token_ptr.id)) |unwrap_id| { |
| 1875 | const node = try arena.construct(ast.Node.InfixOp{ | |
| 1875 | const node = try arena.create(ast.Node.InfixOp{ | |
| 1876 | 1876 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1877 | 1877 | .lhs = lhs, |
| 1878 | 1878 | .op_token = token_index, |
| ... | ... | @@ -1904,7 +1904,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1904 | 1904 | const lhs = opt_ctx.get() orelse continue; |
| 1905 | 1905 | |
| 1906 | 1906 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| { |
| 1907 | const node = try arena.construct(ast.Node.InfixOp{ | |
| 1907 | const node = try arena.create(ast.Node.InfixOp{ | |
| 1908 | 1908 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1909 | 1909 | .lhs = lhs, |
| 1910 | 1910 | .op_token = or_token, |
| ... | ... | @@ -1928,7 +1928,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1928 | 1928 | const lhs = opt_ctx.get() orelse continue; |
| 1929 | 1929 | |
| 1930 | 1930 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| { |
| 1931 | const node = try arena.construct(ast.Node.InfixOp{ | |
| 1931 | const node = try arena.create(ast.Node.InfixOp{ | |
| 1932 | 1932 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1933 | 1933 | .lhs = lhs, |
| 1934 | 1934 | .op_token = and_token, |
| ... | ... | @@ -1955,7 +1955,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1955 | 1955 | const token_index = token.index; |
| 1956 | 1956 | const token_ptr = token.ptr; |
| 1957 | 1957 | if (tokenIdToComparison(token_ptr.id)) |comp_id| { |
| 1958 | const node = try arena.construct(ast.Node.InfixOp{ | |
| 1958 | const node = try arena.create(ast.Node.InfixOp{ | |
| 1959 | 1959 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1960 | 1960 | .lhs = lhs, |
| 1961 | 1961 | .op_token = token_index, |
| ... | ... | @@ -1982,7 +1982,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1982 | 1982 | const lhs = opt_ctx.get() orelse continue; |
| 1983 | 1983 | |
| 1984 | 1984 | if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| { |
| 1985 | const node = try arena.construct(ast.Node.InfixOp{ | |
| 1985 | const node = try arena.create(ast.Node.InfixOp{ | |
| 1986 | 1986 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1987 | 1987 | .lhs = lhs, |
| 1988 | 1988 | .op_token = pipe, |
| ... | ... | @@ -2006,7 +2006,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2006 | 2006 | const lhs = opt_ctx.get() orelse continue; |
| 2007 | 2007 | |
| 2008 | 2008 | if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| { |
| 2009 | const node = try arena.construct(ast.Node.InfixOp{ | |
| 2009 | const node = try arena.create(ast.Node.InfixOp{ | |
| 2010 | 2010 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2011 | 2011 | .lhs = lhs, |
| 2012 | 2012 | .op_token = caret, |
| ... | ... | @@ -2030,7 +2030,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2030 | 2030 | const lhs = opt_ctx.get() orelse continue; |
| 2031 | 2031 | |
| 2032 | 2032 | if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| { |
| 2033 | const node = try arena.construct(ast.Node.InfixOp{ | |
| 2033 | const node = try arena.create(ast.Node.InfixOp{ | |
| 2034 | 2034 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2035 | 2035 | .lhs = lhs, |
| 2036 | 2036 | .op_token = ampersand, |
| ... | ... | @@ -2057,7 +2057,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2057 | 2057 | const token_index = token.index; |
| 2058 | 2058 | const token_ptr = token.ptr; |
| 2059 | 2059 | if (tokenIdToBitShift(token_ptr.id)) |bitshift_id| { |
| 2060 | const node = try arena.construct(ast.Node.InfixOp{ | |
| 2060 | const node = try arena.create(ast.Node.InfixOp{ | |
| 2061 | 2061 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2062 | 2062 | .lhs = lhs, |
| 2063 | 2063 | .op_token = token_index, |
| ... | ... | @@ -2087,7 +2087,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2087 | 2087 | const token_index = token.index; |
| 2088 | 2088 | const token_ptr = token.ptr; |
| 2089 | 2089 | if (tokenIdToAddition(token_ptr.id)) |add_id| { |
| 2090 | const node = try arena.construct(ast.Node.InfixOp{ | |
| 2090 | const node = try arena.create(ast.Node.InfixOp{ | |
| 2091 | 2091 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2092 | 2092 | .lhs = lhs, |
| 2093 | 2093 | .op_token = token_index, |
| ... | ... | @@ -2117,7 +2117,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2117 | 2117 | const token_index = token.index; |
| 2118 | 2118 | const token_ptr = token.ptr; |
| 2119 | 2119 | if (tokenIdToMultiply(token_ptr.id)) |mult_id| { |
| 2120 | const node = try arena.construct(ast.Node.InfixOp{ | |
| 2120 | const node = try arena.create(ast.Node.InfixOp{ | |
| 2121 | 2121 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2122 | 2122 | .lhs = lhs, |
| 2123 | 2123 | .op_token = token_index, |
| ... | ... | @@ -2145,7 +2145,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2145 | 2145 | const lhs = opt_ctx.get() orelse continue; |
| 2146 | 2146 | |
| 2147 | 2147 | if (tok_it.peek().?.id == Token.Id.Period) { |
| 2148 | const node = try arena.construct(ast.Node.SuffixOp{ | |
| 2148 | const node = try arena.create(ast.Node.SuffixOp{ | |
| 2149 | 2149 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2150 | 2150 | .lhs = lhs, |
| 2151 | 2151 | .op = ast.Node.SuffixOp.Op{ .StructInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) }, |
| ... | ... | @@ -2164,7 +2164,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2164 | 2164 | continue; |
| 2165 | 2165 | } |
| 2166 | 2166 | |
| 2167 | const node = try arena.construct(ast.Node.SuffixOp{ | |
| 2167 | const node = try arena.create(ast.Node.SuffixOp{ | |
| 2168 | 2168 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2169 | 2169 | .lhs = lhs, |
| 2170 | 2170 | .op = ast.Node.SuffixOp.Op{ .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) }, |
| ... | ... | @@ -2193,7 +2193,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2193 | 2193 | const lhs = opt_ctx.get() orelse continue; |
| 2194 | 2194 | |
| 2195 | 2195 | if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| { |
| 2196 | const node = try arena.construct(ast.Node.InfixOp{ | |
| 2196 | const node = try arena.create(ast.Node.InfixOp{ | |
| 2197 | 2197 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2198 | 2198 | .lhs = lhs, |
| 2199 | 2199 | .op_token = bang, |
| ... | ... | @@ -2212,7 +2212,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2212 | 2212 | const token_index = token.index; |
| 2213 | 2213 | const token_ptr = token.ptr; |
| 2214 | 2214 | if (tokenIdToPrefixOp(token_ptr.id)) |prefix_id| { |
| 2215 | var node = try arena.construct(ast.Node.PrefixOp{ | |
| 2215 | var node = try arena.create(ast.Node.PrefixOp{ | |
| 2216 | 2216 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, |
| 2217 | 2217 | .op_token = token_index, |
| 2218 | 2218 | .op = prefix_id, |
| ... | ... | @@ -2222,7 +2222,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2222 | 2222 | |
| 2223 | 2223 | // Treat '**' token as two pointer types |
| 2224 | 2224 | if (token_ptr.id == Token.Id.AsteriskAsterisk) { |
| 2225 | const child = try arena.construct(ast.Node.PrefixOp{ | |
| 2225 | const child = try arena.create(ast.Node.PrefixOp{ | |
| 2226 | 2226 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, |
| 2227 | 2227 | .op_token = token_index, |
| 2228 | 2228 | .op = prefix_id, |
| ... | ... | @@ -2246,7 +2246,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2246 | 2246 | |
| 2247 | 2247 | State.SuffixOpExpressionBegin => |opt_ctx| { |
| 2248 | 2248 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_async)) |async_token| { |
| 2249 | const async_node = try arena.construct(ast.Node.AsyncAttribute{ | |
| 2249 | const async_node = try arena.create(ast.Node.AsyncAttribute{ | |
| 2250 | 2250 | .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute }, |
| 2251 | 2251 | .async_token = async_token, |
| 2252 | 2252 | .allocator_type = null, |
| ... | ... | @@ -2277,7 +2277,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2277 | 2277 | const token_ptr = token.ptr; |
| 2278 | 2278 | switch (token_ptr.id) { |
| 2279 | 2279 | Token.Id.LParen => { |
| 2280 | const node = try arena.construct(ast.Node.SuffixOp{ | |
| 2280 | const node = try arena.create(ast.Node.SuffixOp{ | |
| 2281 | 2281 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2282 | 2282 | .lhs = lhs, |
| 2283 | 2283 | .op = ast.Node.SuffixOp.Op{ |
| ... | ... | @@ -2301,7 +2301,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2301 | 2301 | continue; |
| 2302 | 2302 | }, |
| 2303 | 2303 | Token.Id.LBracket => { |
| 2304 | const node = try arena.construct(ast.Node.SuffixOp{ | |
| 2304 | const node = try arena.create(ast.Node.SuffixOp{ | |
| 2305 | 2305 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2306 | 2306 | .lhs = lhs, |
| 2307 | 2307 | .op = ast.Node.SuffixOp.Op{ .ArrayAccess = undefined }, |
| ... | ... | @@ -2316,7 +2316,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2316 | 2316 | }, |
| 2317 | 2317 | Token.Id.Period => { |
| 2318 | 2318 | if (eatToken(&tok_it, &tree, Token.Id.Asterisk)) |asterisk_token| { |
| 2319 | const node = try arena.construct(ast.Node.SuffixOp{ | |
| 2319 | const node = try arena.create(ast.Node.SuffixOp{ | |
| 2320 | 2320 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2321 | 2321 | .lhs = lhs, |
| 2322 | 2322 | .op = ast.Node.SuffixOp.Op.Deref, |
| ... | ... | @@ -2327,7 +2327,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2327 | 2327 | continue; |
| 2328 | 2328 | } |
| 2329 | 2329 | if (eatToken(&tok_it, &tree, Token.Id.QuestionMark)) |question_token| { |
| 2330 | const node = try arena.construct(ast.Node.SuffixOp{ | |
| 2330 | const node = try arena.create(ast.Node.SuffixOp{ | |
| 2331 | 2331 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2332 | 2332 | .lhs = lhs, |
| 2333 | 2333 | .op = ast.Node.SuffixOp.Op.UnwrapOptional, |
| ... | ... | @@ -2337,7 +2337,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2337 | 2337 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2338 | 2338 | continue; |
| 2339 | 2339 | } |
| 2340 | const node = try arena.construct(ast.Node.InfixOp{ | |
| 2340 | const node = try arena.create(ast.Node.InfixOp{ | |
| 2341 | 2341 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2342 | 2342 | .lhs = lhs, |
| 2343 | 2343 | .op_token = token_index, |
| ... | ... | @@ -2397,7 +2397,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2397 | 2397 | continue; |
| 2398 | 2398 | }, |
| 2399 | 2399 | Token.Id.Keyword_promise => { |
| 2400 | const node = try arena.construct(ast.Node.PromiseType{ | |
| 2400 | const node = try arena.create(ast.Node.PromiseType{ | |
| 2401 | 2401 | .base = ast.Node{ .id = ast.Node.Id.PromiseType }, |
| 2402 | 2402 | .promise_token = token.index, |
| 2403 | 2403 | .result = null, |
| ... | ... | @@ -2423,7 +2423,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2423 | 2423 | continue; |
| 2424 | 2424 | }, |
| 2425 | 2425 | Token.Id.LParen => { |
| 2426 | const node = try arena.construct(ast.Node.GroupedExpression{ | |
| 2426 | const node = try arena.create(ast.Node.GroupedExpression{ | |
| 2427 | 2427 | .base = ast.Node{ .id = ast.Node.Id.GroupedExpression }, |
| 2428 | 2428 | .lparen = token.index, |
| 2429 | 2429 | .expr = undefined, |
| ... | ... | @@ -2441,7 +2441,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2441 | 2441 | continue; |
| 2442 | 2442 | }, |
| 2443 | 2443 | Token.Id.Builtin => { |
| 2444 | const node = try arena.construct(ast.Node.BuiltinCall{ | |
| 2444 | const node = try arena.create(ast.Node.BuiltinCall{ | |
| 2445 | 2445 | .base = ast.Node{ .id = ast.Node.Id.BuiltinCall }, |
| 2446 | 2446 | .builtin_token = token.index, |
| 2447 | 2447 | .params = ast.Node.BuiltinCall.ParamList.init(arena), |
| ... | ... | @@ -2460,7 +2460,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2460 | 2460 | continue; |
| 2461 | 2461 | }, |
| 2462 | 2462 | Token.Id.LBracket => { |
| 2463 | const node = try arena.construct(ast.Node.PrefixOp{ | |
| 2463 | const node = try arena.create(ast.Node.PrefixOp{ | |
| 2464 | 2464 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, |
| 2465 | 2465 | .op_token = token.index, |
| 2466 | 2466 | .op = undefined, |
| ... | ... | @@ -2519,7 +2519,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2519 | 2519 | continue; |
| 2520 | 2520 | }, |
| 2521 | 2521 | Token.Id.Keyword_fn => { |
| 2522 | const fn_proto = try arena.construct(ast.Node.FnProto{ | |
| 2522 | const fn_proto = try arena.create(ast.Node.FnProto{ | |
| 2523 | 2523 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, |
| 2524 | 2524 | .doc_comments = null, |
| 2525 | 2525 | .visib_token = null, |
| ... | ... | @@ -2540,7 +2540,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2540 | 2540 | continue; |
| 2541 | 2541 | }, |
| 2542 | 2542 | Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc => { |
| 2543 | const fn_proto = try arena.construct(ast.Node.FnProto{ | |
| 2543 | const fn_proto = try arena.create(ast.Node.FnProto{ | |
| 2544 | 2544 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, |
| 2545 | 2545 | .doc_comments = null, |
| 2546 | 2546 | .visib_token = null, |
| ... | ... | @@ -2567,7 +2567,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2567 | 2567 | continue; |
| 2568 | 2568 | }, |
| 2569 | 2569 | Token.Id.Keyword_asm => { |
| 2570 | const node = try arena.construct(ast.Node.Asm{ | |
| 2570 | const node = try arena.create(ast.Node.Asm{ | |
| 2571 | 2571 | .base = ast.Node{ .id = ast.Node.Id.Asm }, |
| 2572 | 2572 | .asm_token = token.index, |
| 2573 | 2573 | .volatile_token = null, |
| ... | ... | @@ -2629,7 +2629,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2629 | 2629 | continue; |
| 2630 | 2630 | } |
| 2631 | 2631 | |
| 2632 | const node = try arena.construct(ast.Node.ErrorSetDecl{ | |
| 2632 | const node = try arena.create(ast.Node.ErrorSetDecl{ | |
| 2633 | 2633 | .base = ast.Node{ .id = ast.Node.Id.ErrorSetDecl }, |
| 2634 | 2634 | .error_token = ctx.error_token, |
| 2635 | 2635 | .decls = ast.Node.ErrorSetDecl.DeclList.init(arena), |
| ... | ... | @@ -2695,7 +2695,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2695 | 2695 | return tree; |
| 2696 | 2696 | } |
| 2697 | 2697 | |
| 2698 | const node = try arena.construct(ast.Node.ErrorTag{ | |
| 2698 | const node = try arena.create(ast.Node.ErrorTag{ | |
| 2699 | 2699 | .base = ast.Node{ .id = ast.Node.Id.ErrorTag }, |
| 2700 | 2700 | .doc_comments = comments, |
| 2701 | 2701 | .name_token = ident_token_index, |
| ... | ... | @@ -3032,7 +3032,7 @@ fn pushDocComment(arena: *mem.Allocator, line_comment: TokenIndex, result: *?*as |
| 3032 | 3032 | if (result.*) |comment_node| { |
| 3033 | 3033 | break :blk comment_node; |
| 3034 | 3034 | } else { |
| 3035 | const comment_node = try arena.construct(ast.Node.DocComment{ | |
| 3035 | const comment_node = try arena.create(ast.Node.DocComment{ | |
| 3036 | 3036 | .base = ast.Node{ .id = ast.Node.Id.DocComment }, |
| 3037 | 3037 | .lines = ast.Node.DocComment.LineList.init(arena), |
| 3038 | 3038 | }); |
| ... | ... | @@ -3061,7 +3061,7 @@ fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterato |
| 3061 | 3061 | return &(try createLiteral(arena, ast.Node.StringLiteral, token_index)).base; |
| 3062 | 3062 | }, |
| 3063 | 3063 | Token.Id.MultilineStringLiteralLine => { |
| 3064 | const node = try arena.construct(ast.Node.MultilineStringLiteral{ | |
| 3064 | const node = try arena.create(ast.Node.MultilineStringLiteral{ | |
| 3065 | 3065 | .base = ast.Node{ .id = ast.Node.Id.MultilineStringLiteral }, |
| 3066 | 3066 | .lines = ast.Node.MultilineStringLiteral.LineList.init(arena), |
| 3067 | 3067 | }); |
| ... | ... | @@ -3089,7 +3089,7 @@ fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterato |
| 3089 | 3089 | fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *const OptionalCtx, token_ptr: *const Token, token_index: TokenIndex) !bool { |
| 3090 | 3090 | switch (token_ptr.id) { |
| 3091 | 3091 | Token.Id.Keyword_suspend => { |
| 3092 | const node = try arena.construct(ast.Node.Suspend{ | |
| 3092 | const node = try arena.create(ast.Node.Suspend{ | |
| 3093 | 3093 | .base = ast.Node{ .id = ast.Node.Id.Suspend }, |
| 3094 | 3094 | .label = null, |
| 3095 | 3095 | .suspend_token = token_index, |
| ... | ... | @@ -3103,7 +3103,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con |
| 3103 | 3103 | return true; |
| 3104 | 3104 | }, |
| 3105 | 3105 | Token.Id.Keyword_if => { |
| 3106 | const node = try arena.construct(ast.Node.If{ | |
| 3106 | const node = try arena.create(ast.Node.If{ | |
| 3107 | 3107 | .base = ast.Node{ .id = ast.Node.Id.If }, |
| 3108 | 3108 | .if_token = token_index, |
| 3109 | 3109 | .condition = undefined, |
| ... | ... | @@ -3144,7 +3144,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con |
| 3144 | 3144 | return true; |
| 3145 | 3145 | }, |
| 3146 | 3146 | Token.Id.Keyword_switch => { |
| 3147 | const node = try arena.construct(ast.Node.Switch{ | |
| 3147 | const node = try arena.create(ast.Node.Switch{ | |
| 3148 | 3148 | .base = ast.Node{ .id = ast.Node.Id.Switch }, |
| 3149 | 3149 | .switch_token = token_index, |
| 3150 | 3150 | .expr = undefined, |
| ... | ... | @@ -3166,7 +3166,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con |
| 3166 | 3166 | return true; |
| 3167 | 3167 | }, |
| 3168 | 3168 | Token.Id.Keyword_comptime => { |
| 3169 | const node = try arena.construct(ast.Node.Comptime{ | |
| 3169 | const node = try arena.create(ast.Node.Comptime{ | |
| 3170 | 3170 | .base = ast.Node{ .id = ast.Node.Id.Comptime }, |
| 3171 | 3171 | .comptime_token = token_index, |
| 3172 | 3172 | .expr = undefined, |
| ... | ... | @@ -3178,7 +3178,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con |
| 3178 | 3178 | return true; |
| 3179 | 3179 | }, |
| 3180 | 3180 | Token.Id.LBrace => { |
| 3181 | const block = try arena.construct(ast.Node.Block{ | |
| 3181 | const block = try arena.create(ast.Node.Block{ | |
| 3182 | 3182 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 3183 | 3183 | .label = null, |
| 3184 | 3184 | .lbrace = token_index, |
| ... | ... | @@ -3318,7 +3318,7 @@ fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op { |
| 3318 | 3318 | } |
| 3319 | 3319 | |
| 3320 | 3320 | fn createLiteral(arena: *mem.Allocator, comptime T: type, token_index: TokenIndex) !*T { |
| 3321 | return arena.construct(T{ | |
| 3321 | return arena.create(T{ | |
| 3322 | 3322 | .base = ast.Node{ .id = ast.Node.typeToId(T) }, |
| 3323 | 3323 | .token = token_index, |
| 3324 | 3324 | }); |
test/cases/null.zig+1-1| ... | ... | @@ -146,7 +146,7 @@ test "null with default unwrap" { |
| 146 | 146 | |
| 147 | 147 | test "optional types" { |
| 148 | 148 | comptime { |
| 149 | const opt_type_struct = StructWithOptionalType { .t=u8, }; | |
| 149 | const opt_type_struct = StructWithOptionalType{ .t = u8 }; | |
| 150 | 150 | assert(opt_type_struct.t != null and opt_type_struct.t.? == u8); |
| 151 | 151 | } |
| 152 | 152 | } |
test/tests.zig+37-45| ... | ... | @@ -48,13 +48,12 @@ 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) *build.Step { |
| 51 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; | |
| 52 | cases.* = CompareOutputContext{ | |
| 51 | const cases = b.allocator.create(CompareOutputContext{ | |
| 53 | 52 | .b = b, |
| 54 | 53 | .step = b.step("test-compare-output", "Run the compare output tests"), |
| 55 | 54 | .test_index = 0, |
| 56 | 55 | .test_filter = test_filter, |
| 57 | }; | |
| 56 | }) catch unreachable; | |
| 58 | 57 | |
| 59 | 58 | compare_output.addCases(cases); |
| 60 | 59 | |
| ... | ... | @@ -62,13 +61,12 @@ pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8) *build |
| 62 | 61 | } |
| 63 | 62 | |
| 64 | 63 | pub fn addRuntimeSafetyTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step { |
| 65 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; | |
| 66 | cases.* = CompareOutputContext{ | |
| 64 | const cases = b.allocator.create(CompareOutputContext{ | |
| 67 | 65 | .b = b, |
| 68 | 66 | .step = b.step("test-runtime-safety", "Run the runtime safety tests"), |
| 69 | 67 | .test_index = 0, |
| 70 | 68 | .test_filter = test_filter, |
| 71 | }; | |
| 69 | }) catch unreachable; | |
| 72 | 70 | |
| 73 | 71 | runtime_safety.addCases(cases); |
| 74 | 72 | |
| ... | ... | @@ -76,13 +74,12 @@ pub fn addRuntimeSafetyTests(b: *build.Builder, test_filter: ?[]const u8) *build |
| 76 | 74 | } |
| 77 | 75 | |
| 78 | 76 | pub fn addCompileErrorTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step { |
| 79 | const cases = b.allocator.create(CompileErrorContext) catch unreachable; | |
| 80 | cases.* = CompileErrorContext{ | |
| 77 | const cases = b.allocator.create(CompileErrorContext{ | |
| 81 | 78 | .b = b, |
| 82 | 79 | .step = b.step("test-compile-errors", "Run the compile error tests"), |
| 83 | 80 | .test_index = 0, |
| 84 | 81 | .test_filter = test_filter, |
| 85 | }; | |
| 82 | }) catch unreachable; | |
| 86 | 83 | |
| 87 | 84 | compile_errors.addCases(cases); |
| 88 | 85 | |
| ... | ... | @@ -90,13 +87,12 @@ pub fn addCompileErrorTests(b: *build.Builder, test_filter: ?[]const u8) *build. |
| 90 | 87 | } |
| 91 | 88 | |
| 92 | 89 | pub fn addBuildExampleTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step { |
| 93 | const cases = b.allocator.create(BuildExamplesContext) catch unreachable; | |
| 94 | cases.* = BuildExamplesContext{ | |
| 90 | const cases = b.allocator.create(BuildExamplesContext{ | |
| 95 | 91 | .b = b, |
| 96 | 92 | .step = b.step("test-build-examples", "Build the examples"), |
| 97 | 93 | .test_index = 0, |
| 98 | 94 | .test_filter = test_filter, |
| 99 | }; | |
| 95 | }) catch unreachable; | |
| 100 | 96 | |
| 101 | 97 | build_examples.addCases(cases); |
| 102 | 98 | |
| ... | ... | @@ -104,13 +100,12 @@ pub fn addBuildExampleTests(b: *build.Builder, test_filter: ?[]const u8) *build. |
| 104 | 100 | } |
| 105 | 101 | |
| 106 | 102 | pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step { |
| 107 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; | |
| 108 | cases.* = CompareOutputContext{ | |
| 103 | const cases = b.allocator.create(CompareOutputContext{ | |
| 109 | 104 | .b = b, |
| 110 | 105 | .step = b.step("test-asm-link", "Run the assemble and link tests"), |
| 111 | 106 | .test_index = 0, |
| 112 | 107 | .test_filter = test_filter, |
| 113 | }; | |
| 108 | }) catch unreachable; | |
| 114 | 109 | |
| 115 | 110 | assemble_and_link.addCases(cases); |
| 116 | 111 | |
| ... | ... | @@ -118,13 +113,12 @@ pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8) *bui |
| 118 | 113 | } |
| 119 | 114 | |
| 120 | 115 | pub fn addTranslateCTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step { |
| 121 | const cases = b.allocator.create(TranslateCContext) catch unreachable; | |
| 122 | cases.* = TranslateCContext{ | |
| 116 | const cases = b.allocator.create(TranslateCContext{ | |
| 123 | 117 | .b = b, |
| 124 | 118 | .step = b.step("test-translate-c", "Run the C transation tests"), |
| 125 | 119 | .test_index = 0, |
| 126 | 120 | .test_filter = test_filter, |
| 127 | }; | |
| 121 | }) catch unreachable; | |
| 128 | 122 | |
| 129 | 123 | translate_c.addCases(cases); |
| 130 | 124 | |
| ... | ... | @@ -132,13 +126,12 @@ pub fn addTranslateCTests(b: *build.Builder, test_filter: ?[]const u8) *build.St |
| 132 | 126 | } |
| 133 | 127 | |
| 134 | 128 | pub fn addGenHTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step { |
| 135 | const cases = b.allocator.create(GenHContext) catch unreachable; | |
| 136 | cases.* = GenHContext{ | |
| 129 | const cases = b.allocator.create(GenHContext{ | |
| 137 | 130 | .b = b, |
| 138 | 131 | .step = b.step("test-gen-h", "Run the C header file generation tests"), |
| 139 | 132 | .test_index = 0, |
| 140 | 133 | .test_filter = test_filter, |
| 141 | }; | |
| 134 | }) catch unreachable; | |
| 142 | 135 | |
| 143 | 136 | gen_h.addCases(cases); |
| 144 | 137 | |
| ... | ... | @@ -240,8 +233,7 @@ pub const CompareOutputContext = struct { |
| 240 | 233 | |
| 241 | 234 | pub fn create(context: *CompareOutputContext, exe_path: []const u8, name: []const u8, expected_output: []const u8, cli_args: []const []const u8) *RunCompareOutputStep { |
| 242 | 235 | const allocator = context.b.allocator; |
| 243 | const ptr = allocator.create(RunCompareOutputStep) catch unreachable; | |
| 244 | ptr.* = RunCompareOutputStep{ | |
| 236 | const ptr = allocator.create(RunCompareOutputStep{ | |
| 245 | 237 | .context = context, |
| 246 | 238 | .exe_path = exe_path, |
| 247 | 239 | .name = name, |
| ... | ... | @@ -249,7 +241,7 @@ pub const CompareOutputContext = struct { |
| 249 | 241 | .test_index = context.test_index, |
| 250 | 242 | .step = build.Step.init("RunCompareOutput", allocator, make), |
| 251 | 243 | .cli_args = cli_args, |
| 252 | }; | |
| 244 | }) catch unreachable; | |
| 253 | 245 | context.test_index += 1; |
| 254 | 246 | return ptr; |
| 255 | 247 | } |
| ... | ... | @@ -328,14 +320,14 @@ pub const CompareOutputContext = struct { |
| 328 | 320 | |
| 329 | 321 | pub fn create(context: *CompareOutputContext, exe_path: []const u8, name: []const u8) *RuntimeSafetyRunStep { |
| 330 | 322 | const allocator = context.b.allocator; |
| 331 | const ptr = allocator.create(RuntimeSafetyRunStep) catch unreachable; | |
| 332 | ptr.* = RuntimeSafetyRunStep{ | |
| 323 | const ptr = allocator.create(RuntimeSafetyRunStep{ | |
| 333 | 324 | .context = context, |
| 334 | 325 | .exe_path = exe_path, |
| 335 | 326 | .name = name, |
| 336 | 327 | .test_index = context.test_index, |
| 337 | 328 | .step = build.Step.init("RuntimeSafetyRun", allocator, make), |
| 338 | }; | |
| 329 | }) catch unreachable; | |
| 330 | ||
| 339 | 331 | context.test_index += 1; |
| 340 | 332 | return ptr; |
| 341 | 333 | } |
| ... | ... | @@ -543,15 +535,15 @@ pub const CompileErrorContext = struct { |
| 543 | 535 | |
| 544 | 536 | pub fn create(context: *CompileErrorContext, name: []const u8, case: *const TestCase, build_mode: Mode) *CompileCmpOutputStep { |
| 545 | 537 | const allocator = context.b.allocator; |
| 546 | const ptr = allocator.create(CompileCmpOutputStep) catch unreachable; | |
| 547 | ptr.* = CompileCmpOutputStep{ | |
| 538 | const ptr = allocator.create(CompileCmpOutputStep{ | |
| 548 | 539 | .step = build.Step.init("CompileCmpOutput", allocator, make), |
| 549 | 540 | .context = context, |
| 550 | 541 | .name = name, |
| 551 | 542 | .test_index = context.test_index, |
| 552 | 543 | .case = case, |
| 553 | 544 | .build_mode = build_mode, |
| 554 | }; | |
| 545 | }) catch unreachable; | |
| 546 | ||
| 555 | 547 | context.test_index += 1; |
| 556 | 548 | return ptr; |
| 557 | 549 | } |
| ... | ... | @@ -662,14 +654,14 @@ pub const CompileErrorContext = struct { |
| 662 | 654 | } |
| 663 | 655 | |
| 664 | 656 | pub fn create(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) *TestCase { |
| 665 | const tc = self.b.allocator.create(TestCase) catch unreachable; | |
| 666 | tc.* = TestCase{ | |
| 657 | const tc = self.b.allocator.create(TestCase{ | |
| 667 | 658 | .name = name, |
| 668 | 659 | .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), |
| 669 | 660 | .expected_errors = ArrayList([]const u8).init(self.b.allocator), |
| 670 | 661 | .link_libc = false, |
| 671 | 662 | .is_exe = false, |
| 672 | }; | |
| 663 | }) catch unreachable; | |
| 664 | ||
| 673 | 665 | tc.addSourceFile(".tmp_source.zig", source); |
| 674 | 666 | comptime var arg_i = 0; |
| 675 | 667 | inline while (arg_i < expected_lines.len) : (arg_i += 1) { |
| ... | ... | @@ -829,14 +821,14 @@ pub const TranslateCContext = struct { |
| 829 | 821 | |
| 830 | 822 | pub fn create(context: *TranslateCContext, name: []const u8, case: *const TestCase) *TranslateCCmpOutputStep { |
| 831 | 823 | const allocator = context.b.allocator; |
| 832 | const ptr = allocator.create(TranslateCCmpOutputStep) catch unreachable; | |
| 833 | ptr.* = TranslateCCmpOutputStep{ | |
| 824 | const ptr = allocator.create(TranslateCCmpOutputStep{ | |
| 834 | 825 | .step = build.Step.init("ParseCCmpOutput", allocator, make), |
| 835 | 826 | .context = context, |
| 836 | 827 | .name = name, |
| 837 | 828 | .test_index = context.test_index, |
| 838 | 829 | .case = case, |
| 839 | }; | |
| 830 | }) catch unreachable; | |
| 831 | ||
| 840 | 832 | context.test_index += 1; |
| 841 | 833 | return ptr; |
| 842 | 834 | } |
| ... | ... | @@ -936,13 +928,13 @@ pub const TranslateCContext = struct { |
| 936 | 928 | } |
| 937 | 929 | |
| 938 | 930 | pub fn create(self: *TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase { |
| 939 | const tc = self.b.allocator.create(TestCase) catch unreachable; | |
| 940 | tc.* = TestCase{ | |
| 931 | const tc = self.b.allocator.create(TestCase{ | |
| 941 | 932 | .name = name, |
| 942 | 933 | .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), |
| 943 | 934 | .expected_lines = ArrayList([]const u8).init(self.b.allocator), |
| 944 | 935 | .allow_warnings = allow_warnings, |
| 945 | }; | |
| 936 | }) catch unreachable; | |
| 937 | ||
| 946 | 938 | tc.addSourceFile(filename, source); |
| 947 | 939 | comptime var arg_i = 0; |
| 948 | 940 | inline while (arg_i < expected_lines.len) : (arg_i += 1) { |
| ... | ... | @@ -1023,15 +1015,15 @@ pub const GenHContext = struct { |
| 1023 | 1015 | |
| 1024 | 1016 | pub fn create(context: *GenHContext, h_path: []const u8, name: []const u8, case: *const TestCase) *GenHCmpOutputStep { |
| 1025 | 1017 | const allocator = context.b.allocator; |
| 1026 | const ptr = allocator.create(GenHCmpOutputStep) catch unreachable; | |
| 1027 | ptr.* = GenHCmpOutputStep{ | |
| 1018 | const ptr = allocator.create(GenHCmpOutputStep{ | |
| 1028 | 1019 | .step = build.Step.init("ParseCCmpOutput", allocator, make), |
| 1029 | 1020 | .context = context, |
| 1030 | 1021 | .h_path = h_path, |
| 1031 | 1022 | .name = name, |
| 1032 | 1023 | .test_index = context.test_index, |
| 1033 | 1024 | .case = case, |
| 1034 | }; | |
| 1025 | }) catch unreachable; | |
| 1026 | ||
| 1035 | 1027 | context.test_index += 1; |
| 1036 | 1028 | return ptr; |
| 1037 | 1029 | } |
| ... | ... | @@ -1070,12 +1062,12 @@ pub const GenHContext = struct { |
| 1070 | 1062 | } |
| 1071 | 1063 | |
| 1072 | 1064 | pub fn create(self: *GenHContext, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase { |
| 1073 | const tc = self.b.allocator.create(TestCase) catch unreachable; | |
| 1074 | tc.* = TestCase{ | |
| 1065 | const tc = self.b.allocator.create(TestCase{ | |
| 1075 | 1066 | .name = name, |
| 1076 | 1067 | .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), |
| 1077 | 1068 | .expected_lines = ArrayList([]const u8).init(self.b.allocator), |
| 1078 | }; | |
| 1069 | }) catch unreachable; | |
| 1070 | ||
| 1079 | 1071 | tc.addSourceFile(filename, source); |
| 1080 | 1072 | comptime var arg_i = 0; |
| 1081 | 1073 | inline while (arg_i < expected_lines.len) : (arg_i += 1) { |