| ... | @@ -114,10 +114,10 @@ pub fn main() !void { | ... | @@ -114,10 +114,10 @@ pub fn main() !void { |
| 114 | interestingness_argv.appendAssumeCapacity(checker_path); | 114 | interestingness_argv.appendAssumeCapacity(checker_path); |
| 115 | interestingness_argv.appendSliceAssumeCapacity(argv); | 115 | interestingness_argv.appendSliceAssumeCapacity(argv); |
| 116 | | 116 | |
| 117 | var rendered = std.array_list.Managed(u8).init(gpa); | 117 | var rendered: std.Io.Writer.Allocating = .init(gpa); |
| 118 | defer rendered.deinit(); | 118 | defer rendered.deinit(); |
| 119 | | 119 | |
| 120 | var astgen_input = std.array_list.Managed(u8).init(gpa); | 120 | var astgen_input: std.Io.Writer.Allocating = .init(gpa); |
| 121 | defer astgen_input.deinit(); | 121 | defer astgen_input.deinit(); |
| 122 | | 122 | |
| 123 | var tree = try parse(gpa, root_source_file_path); | 123 | var tree = try parse(gpa, root_source_file_path); |
| ... | @@ -138,10 +138,10 @@ pub fn main() !void { | ... | @@ -138,10 +138,10 @@ pub fn main() !void { |
| 138 | } | 138 | } |
| 139 | } | 139 | } |
| 140 | | 140 | |
| 141 | var fixups: Ast.Fixups = .{}; | 141 | var fixups: Ast.Render.Fixups = .{}; |
| 142 | defer fixups.deinit(gpa); | 142 | defer fixups.deinit(gpa); |
| 143 | | 143 | |
| 144 | var more_fixups: Ast.Fixups = .{}; | 144 | var more_fixups: Ast.Render.Fixups = .{}; |
| 145 | defer more_fixups.deinit(gpa); | 145 | defer more_fixups.deinit(gpa); |
| 146 | | 146 | |
| 147 | var rng = std.Random.DefaultPrng.init(seed); | 147 | var rng = std.Random.DefaultPrng.init(seed); |
| ... | @@ -188,15 +188,14 @@ pub fn main() !void { | ... | @@ -188,15 +188,14 @@ pub fn main() !void { |
| 188 | try transformationsToFixups(gpa, arena, root_source_file_path, this_set, &fixups); | 188 | try transformationsToFixups(gpa, arena, root_source_file_path, this_set, &fixups); |
| 189 | | 189 | |
| 190 | rendered.clearRetainingCapacity(); | 190 | rendered.clearRetainingCapacity(); |
| 191 | try tree.renderToArrayList(&rendered, fixups); | 191 | try tree.render(gpa, &rendered.writer, fixups); |
| 192 | | 192 | |
| 193 | // The transformations we applied may have resulted in unused locals, | 193 | // The transformations we applied may have resulted in unused locals, |
| 194 | // in which case we would like to add the respective discards. | 194 | // in which case we would like to add the respective discards. |
| 195 | { | 195 | { |
| 196 | try astgen_input.resize(rendered.items.len); | 196 | try astgen_input.writer.writeAll(rendered.written()); |
| 197 | @memcpy(astgen_input.items, rendered.items); | 197 | try astgen_input.writer.writeByte(0); |
| 198 | try astgen_input.append(0); | 198 | const source_with_null = astgen_input.written()[0..(astgen_input.written().len - 1) :0]; |
| 199 | const source_with_null = astgen_input.items[0 .. astgen_input.items.len - 1 :0]; | | |
| 200 | var astgen_tree = try Ast.parse(gpa, source_with_null, .zig); | 199 | var astgen_tree = try Ast.parse(gpa, source_with_null, .zig); |
| 201 | defer astgen_tree.deinit(gpa); | 200 | defer astgen_tree.deinit(gpa); |
| 202 | if (astgen_tree.errors.len != 0) { | 201 | if (astgen_tree.errors.len != 0) { |
| ... | @@ -228,12 +227,12 @@ pub fn main() !void { | ... | @@ -228,12 +227,12 @@ pub fn main() !void { |
| 228 | } | 227 | } |
| 229 | if (more_fixups.count() != 0) { | 228 | if (more_fixups.count() != 0) { |
| 230 | rendered.clearRetainingCapacity(); | 229 | rendered.clearRetainingCapacity(); |
| 231 | try astgen_tree.renderToArrayList(&rendered, more_fixups); | 230 | try astgen_tree.render(gpa, &rendered.writer, more_fixups); |
| 232 | } | 231 | } |
| 233 | } | 232 | } |
| 234 | } | 233 | } |
| 235 | | 234 | |
| 236 | try std.fs.cwd().writeFile(.{ .sub_path = root_source_file_path, .data = rendered.items }); | 235 | try std.fs.cwd().writeFile(.{ .sub_path = root_source_file_path, .data = rendered.written() }); |
| 237 | // std.debug.print("trying this code:\n{s}\n", .{rendered.items}); | 236 | // std.debug.print("trying this code:\n{s}\n", .{rendered.items}); |
| 238 | | 237 | |
| 239 | const interestingness = try runCheck(arena, interestingness_argv.items); | 238 | const interestingness = try runCheck(arena, interestingness_argv.items); |
| ... | @@ -273,8 +272,8 @@ pub fn main() !void { | ... | @@ -273,8 +272,8 @@ pub fn main() !void { |
| 273 | // Revert the source back to not be transformed. | 272 | // Revert the source back to not be transformed. |
| 274 | fixups.clearRetainingCapacity(); | 273 | fixups.clearRetainingCapacity(); |
| 275 | rendered.clearRetainingCapacity(); | 274 | rendered.clearRetainingCapacity(); |
| 276 | try tree.renderToArrayList(&rendered, fixups); | 275 | try tree.render(gpa, &rendered.writer, fixups); |
| 277 | try std.fs.cwd().writeFile(.{ .sub_path = root_source_file_path, .data = rendered.items }); | 276 | try std.fs.cwd().writeFile(.{ .sub_path = root_source_file_path, .data = rendered.written() }); |
| 278 | | 277 | |
| 279 | return std.process.cleanExit(); | 278 | return std.process.cleanExit(); |
| 280 | } | 279 | } |
| ... | @@ -318,7 +317,7 @@ fn transformationsToFixups( | ... | @@ -318,7 +317,7 @@ fn transformationsToFixups( |
| 318 | arena: Allocator, | 317 | arena: Allocator, |
| 319 | root_source_file_path: []const u8, | 318 | root_source_file_path: []const u8, |
| 320 | transforms: []const Walk.Transformation, | 319 | transforms: []const Walk.Transformation, |
| 321 | fixups: *Ast.Fixups, | 320 | fixups: *Ast.Render.Fixups, |
| 322 | ) !void { | 321 | ) !void { |
| 323 | fixups.clearRetainingCapacity(); | 322 | fixups.clearRetainingCapacity(); |
| 324 | | 323 | |
| ... | @@ -359,7 +358,7 @@ fn transformationsToFixups( | ... | @@ -359,7 +358,7 @@ fn transformationsToFixups( |
| 359 | other_file_ast.deinit(gpa); | 358 | other_file_ast.deinit(gpa); |
| 360 | } | 359 | } |
| 361 | | 360 | |
| 362 | var inlined_fixups: Ast.Fixups = .{}; | 361 | var inlined_fixups: Ast.Render.Fixups = .{}; |
| 363 | defer inlined_fixups.deinit(gpa); | 362 | defer inlined_fixups.deinit(gpa); |
| 364 | if (std.fs.path.dirname(inline_imported_file.imported_string)) |dirname| { | 363 | if (std.fs.path.dirname(inline_imported_file.imported_string)) |dirname| { |
| 365 | inlined_fixups.rebase_imported_paths = dirname; | 364 | inlined_fixups.rebase_imported_paths = dirname; |
| ... | @@ -382,16 +381,16 @@ fn transformationsToFixups( | ... | @@ -382,16 +381,16 @@ fn transformationsToFixups( |
| 382 | } | 381 | } |
| 383 | } | 382 | } |
| 384 | | 383 | |
| 385 | var other_source = std.array_list.Managed(u8).init(gpa); | 384 | var other_source: std.io.Writer.Allocating = .init(gpa); |
| 386 | defer other_source.deinit(); | 385 | defer other_source.deinit(); |
| 387 | try other_source.appendSlice("struct {\n"); | 386 | try other_source.writer.writeAll("struct {\n"); |
| 388 | try other_file_ast.renderToArrayList(&other_source, inlined_fixups); | 387 | try other_file_ast.render(gpa, &other_source.writer, inlined_fixups); |
| 389 | try other_source.appendSlice("}"); | 388 | try other_source.writer.writeAll("}"); |
| 390 | | 389 | |
| 391 | try fixups.replace_nodes_with_string.put( | 390 | try fixups.replace_nodes_with_string.put( |
| 392 | gpa, | 391 | gpa, |
| 393 | inline_imported_file.builtin_call_node, | 392 | inline_imported_file.builtin_call_node, |
| 394 | try arena.dupe(u8, other_source.items), | 393 | try arena.dupe(u8, other_source.written()), |
| 395 | ); | 394 | ); |
| 396 | }, | 395 | }, |
| 397 | }; | 396 | }; |