| author | |
| committer | |
| log | d83c76eb5af687210e3cc856b3f808f7e5f5e68f |
| tree | 2013762f112f58f33af58cde7d7c710d9e46204b |
| parent | e05073b9e4a7a7a860779d3977a98ee6cd4b6391 |
17 files changed, 278 insertions(+), 196 deletions(-)
lib/compiler/aro/aro/Attribute.zig+1-6| ... | ... | @@ -792,12 +792,7 @@ pub fn normalize(name: []const u8) []const u8 { |
| 792 | 792 | } |
| 793 | 793 | |
| 794 | 794 | fn ignoredAttrErr(p: *Parser, tok: TokenIndex, attr: Attribute.Tag, context: []const u8) !void { |
| 795 | const strings_top = p.strings.items.len; | |
| 796 | defer p.strings.items.len = strings_top; | |
| 797 | ||
| 798 | try p.strings.print("attribute '{s}' ignored on {s}", .{ @tagName(attr), context }); | |
| 799 | const str = try p.comp.diagnostics.arena.allocator().dupe(u8, p.strings.items[strings_top..]); | |
| 800 | try p.errStr(.ignored_attribute, tok, str); | |
| 795 | try p.err(tok, .ignored_attribute, .{ @tagName(attr), context }); | |
| 801 | 796 | } |
| 802 | 797 | |
| 803 | 798 | pub fn applyParameterAttributes(p: *Parser, qt: QualType, attr_buf_start: usize, diagnostic: ?Parser.Diagnostic) !QualType { |
lib/compiler/aro/aro/Compilation.zig+45-12| ... | ... | @@ -132,6 +132,8 @@ sources: std.StringArrayHashMapUnmanaged(Source) = .empty, |
| 132 | 132 | /// Allocated into `gpa`, but keys are externally managed. |
| 133 | 133 | include_dirs: std.ArrayList([]const u8) = .empty, |
| 134 | 134 | /// Allocated into `gpa`, but keys are externally managed. |
| 135 | iquote_include_dirs: std.ArrayList([]const u8) = .empty, | |
| 136 | /// Allocated into `gpa`, but keys are externally managed. | |
| 135 | 137 | system_include_dirs: std.ArrayList([]const u8) = .empty, |
| 136 | 138 | /// Allocated into `gpa`, but keys are externally managed. |
| 137 | 139 | after_include_dirs: std.ArrayList([]const u8) = .empty, |
| ... | ... | @@ -192,6 +194,7 @@ pub fn deinit(comp: *Compilation) void { |
| 192 | 194 | } |
| 193 | 195 | comp.sources.deinit(gpa); |
| 194 | 196 | comp.include_dirs.deinit(gpa); |
| 197 | comp.iquote_include_dirs.deinit(gpa); | |
| 195 | 198 | comp.system_include_dirs.deinit(gpa); |
| 196 | 199 | comp.after_include_dirs.deinit(gpa); |
| 197 | 200 | comp.framework_dirs.deinit(gpa); |
| ... | ... | @@ -240,12 +243,26 @@ fn generateSystemDefines(comp: *Compilation, w: *std.Io.Writer) !void { |
| 240 | 243 | const ptr_width = comp.target.ptrBitWidth(); |
| 241 | 244 | const is_gnu = comp.langopts.standard.isGNU(); |
| 242 | 245 | |
| 243 | if (comp.langopts.gnuc_version > 0) { | |
| 244 | try w.print("#define __GNUC__ {d}\n", .{comp.langopts.gnuc_version / 10_000}); | |
| 245 | try w.print("#define __GNUC_MINOR__ {d}\n", .{comp.langopts.gnuc_version / 100 % 100}); | |
| 246 | try w.print("#define __GNUC_PATCHLEVEL__ {d}\n", .{comp.langopts.gnuc_version % 100}); | |
| 246 | const gnuc_version = comp.langopts.gnuc_version orelse comp.langopts.emulate.defaultGccVersion(); | |
| 247 | if (gnuc_version > 0) { | |
| 248 | try w.print("#define __GNUC__ {d}\n", .{gnuc_version / 10_000}); | |
| 249 | try w.print("#define __GNUC_MINOR__ {d}\n", .{gnuc_version / 100 % 100}); | |
| 250 | try w.print("#define __GNUC_PATCHLEVEL__ {d}\n", .{gnuc_version % 100}); | |
| 247 | 251 | } |
| 248 | 252 | |
| 253 | try w.writeAll( | |
| 254 | \\#define __ARO_EMULATE_CLANG__ 1 | |
| 255 | \\#define __ARO_EMULATE_GCC__ 2 | |
| 256 | \\#define __ARO_EMULATE_MSVC__ 3 | |
| 257 | \\ | |
| 258 | ); | |
| 259 | const emulated = switch (comp.langopts.emulate) { | |
| 260 | .clang => "__ARO_EMULATE_CLANG__", | |
| 261 | .gcc => "__ARO_EMULATE_GCC__", | |
| 262 | .msvc => "__ARO_EMULATE_MSVC__", | |
| 263 | }; | |
| 264 | try w.print("#define __ARO_EMULATE__ {s}\n", .{emulated}); | |
| 265 | ||
| 249 | 266 | if (comp.code_gen_options.optimization_level.hasAnyOptimizations()) { |
| 250 | 267 | try define(w, "__OPTIMIZE__"); |
| 251 | 268 | } |
| ... | ... | @@ -330,6 +347,8 @@ fn generateSystemDefines(comp: *Compilation, w: *std.Io.Writer) !void { |
| 330 | 347 | => try define(w, "__APPLE__"), |
| 331 | 348 | .wasi => try define(w, "__wasi__"), |
| 332 | 349 | .emscripten => try define(w, "__EMSCRIPTEN__"), |
| 350 | .@"3ds" => try define(w, "__3DS__"), | |
| 351 | .vita => try define(w, "__vita__"), | |
| 333 | 352 | else => {}, |
| 334 | 353 | } |
| 335 | 354 | |
| ... | ... | @@ -431,10 +450,13 @@ fn generateSystemDefines(comp: *Compilation, w: *std.Io.Writer) !void { |
| 431 | 450 | .{ .f16c, "__F16C__" }, |
| 432 | 451 | .{ .gfni, "__GFNI__" }, |
| 433 | 452 | .{ .evex512, "__EVEX512__" }, |
| 434 | .{ .avx10_1_256, "__AVX10_1__" }, | |
| 435 | .{ .avx10_1_512, "__AVX10_1_512__" }, | |
| 436 | .{ .avx10_2_256, "__AVX10_2__" }, | |
| 437 | .{ .avx10_2_512, "__AVX10_2_512__" }, | |
| 453 | ||
| 454 | .{ .avx10_1, "__AVX10_1__" }, | |
| 455 | .{ .avx10_1, "__AVX10_1_512__" }, | |
| 456 | ||
| 457 | .{ .avx10_2, "__AVX10_2__" }, | |
| 458 | .{ .avx10_2, "__AVX10_2_512__" }, | |
| 459 | ||
| 438 | 460 | .{ .avx512cd, "__AVX512CD__" }, |
| 439 | 461 | .{ .avx512vpopcntdq, "__AVX512VPOPCNTDQ__" }, |
| 440 | 462 | .{ .avx512vnni, "__AVX512VNNI__" }, |
| ... | ... | @@ -935,7 +957,7 @@ fn generateSystemDefines(comp: *Compilation, w: *std.Io.Writer) !void { |
| 935 | 957 | pub fn generateBuiltinMacros(comp: *Compilation, system_defines_mode: SystemDefinesMode) AddSourceError!Source { |
| 936 | 958 | try comp.type_store.initNamedTypes(comp); |
| 937 | 959 | |
| 938 | var allocating: std.io.Writer.Allocating = try .initCapacity(comp.gpa, 2 << 13); | |
| 960 | var allocating: std.Io.Writer.Allocating = try .initCapacity(comp.gpa, 2 << 13); | |
| 939 | 961 | defer allocating.deinit(); |
| 940 | 962 | |
| 941 | 963 | comp.writeBuiltinMacros(system_defines_mode, &allocating.writer) catch |err| switch (err) { |
| ... | ... | @@ -1297,6 +1319,11 @@ fn generateIntWidth(comp: *Compilation, w: *std.Io.Writer, name: []const u8, qt: |
| 1297 | 1319 | try w.print("#define __{s}_WIDTH__ {d}\n", .{ name, qt.sizeof(comp) * 8 }); |
| 1298 | 1320 | } |
| 1299 | 1321 | |
| 1322 | fn generateIntMaxAndWidth(comp: *Compilation, w: *std.Io.Writer, name: []const u8, qt: QualType) !void { | |
| 1323 | try comp.generateIntMax(w, name, qt); | |
| 1324 | try comp.generateIntWidth(w, name, qt); | |
| 1325 | } | |
| 1326 | ||
| 1300 | 1327 | fn generateSizeofType(comp: *Compilation, w: *std.Io.Writer, name: []const u8, qt: QualType) !void { |
| 1301 | 1328 | try w.print("#define {s} {d}\n", .{ name, qt.sizeof(comp) }); |
| 1302 | 1329 | } |
| ... | ... | @@ -1597,7 +1624,7 @@ pub fn hasInclude( |
| 1597 | 1624 | which: WhichInclude, |
| 1598 | 1625 | opt_dep_file: ?*DepFile, |
| 1599 | 1626 | ) Compilation.Error!bool { |
| 1600 | if (try FindInclude.run(comp, filename, switch (which) { | |
| 1627 | if (try FindInclude.run(comp, filename, include_type, switch (which) { | |
| 1601 | 1628 | .next => .{ .only_search_after_dir = comp.getSource(includer_token_source).path }, |
| 1602 | 1629 | .first => switch (include_type) { |
| 1603 | 1630 | .quotes => .{ .allow_same_dir = comp.getSource(includer_token_source).path }, |
| ... | ... | @@ -1629,6 +1656,7 @@ const FindInclude = struct { |
| 1629 | 1656 | fn run( |
| 1630 | 1657 | comp: *Compilation, |
| 1631 | 1658 | include_path: []const u8, |
| 1659 | include_type: IncludeType, | |
| 1632 | 1660 | search_strat: union(enum) { |
| 1633 | 1661 | allow_same_dir: []const u8, |
| 1634 | 1662 | only_search, |
| ... | ... | @@ -1663,7 +1691,12 @@ const FindInclude = struct { |
| 1663 | 1691 | find.wait_for = std.fs.path.dirname(other_file); |
| 1664 | 1692 | }, |
| 1665 | 1693 | } |
| 1666 | ||
| 1694 | switch (include_type) { | |
| 1695 | .quotes => for (comp.iquote_include_dirs.items) |dir| { | |
| 1696 | if (try find.checkIncludeDir(dir, .user)) |res| return res; | |
| 1697 | }, | |
| 1698 | .angle_brackets => {}, | |
| 1699 | } | |
| 1667 | 1700 | for (comp.include_dirs.items) |dir| { |
| 1668 | 1701 | if (try find.checkIncludeDir(dir, .user)) |res| return res; |
| 1669 | 1702 | } |
| ... | ... | @@ -1876,7 +1909,7 @@ pub fn findInclude( |
| 1876 | 1909 | /// include vs include_next |
| 1877 | 1910 | which: WhichInclude, |
| 1878 | 1911 | ) Compilation.Error!?Source { |
| 1879 | const found = try FindInclude.run(comp, filename, switch (which) { | |
| 1912 | const found = try FindInclude.run(comp, filename, include_type, switch (which) { | |
| 1880 | 1913 | .next => .{ .only_search_after_dir = comp.getSource(includer_token.source).path }, |
| 1881 | 1914 | .first => switch (include_type) { |
| 1882 | 1915 | .quotes => .{ .allow_same_dir = comp.getSource(includer_token.source).path }, |
lib/compiler/aro/aro/Diagnostics.zig+18-9| ... | ... | @@ -194,6 +194,7 @@ pub const Option = enum { |
| 194 | 194 | @"microsoft-anon-tag", |
| 195 | 195 | @"out-of-scope-function", |
| 196 | 196 | @"date-time", |
| 197 | @"variadic-macro-arguments-omitted", | |
| 197 | 198 | @"attribute-todo", |
| 198 | 199 | |
| 199 | 200 | /// GNU extensions |
| ... | ... | @@ -496,27 +497,35 @@ pub fn formatArgs(w: *std.Io.Writer, fmt: []const u8, args: anytype) std.Io.Writ |
| 496 | 497 | else => switch (@typeInfo(@TypeOf(arg))) { |
| 497 | 498 | .int, .comptime_int => try Diagnostics.formatInt(w, fmt[i..], arg), |
| 498 | 499 | .pointer => try Diagnostics.formatString(w, fmt[i..], arg), |
| 499 | else => unreachable, | |
| 500 | else => comptime unreachable, | |
| 500 | 501 | }, |
| 501 | 502 | }; |
| 502 | 503 | } |
| 503 | 504 | try w.writeAll(fmt[i..]); |
| 504 | 505 | } |
| 505 | 506 | |
| 506 | pub fn formatString(w: *std.Io.Writer, fmt: []const u8, str: []const u8) std.Io.Writer.Error!usize { | |
| 507 | const template = "{s}"; | |
| 508 | const i = std.mem.indexOf(u8, fmt, template).?; | |
| 507 | pub fn templateIndex(w: *std.Io.Writer, fmt: []const u8, template: []const u8) std.Io.Writer.Error!usize { | |
| 508 | const i = std.mem.indexOf(u8, fmt, template) orelse { | |
| 509 | if (@import("builtin").mode == .Debug) { | |
| 510 | std.debug.panic("template `{s}` not found in format string `{s}`", .{ template, fmt }); | |
| 511 | } | |
| 512 | try w.print("template `{s}` not found in format string `{s}` (this is a bug in arocc)", .{ template, fmt }); | |
| 513 | return 0; | |
| 514 | }; | |
| 509 | 515 | try w.writeAll(fmt[0..i]); |
| 510 | try w.writeAll(str); | |
| 511 | 516 | return i + template.len; |
| 512 | 517 | } |
| 513 | 518 | |
| 519 | pub fn formatString(w: *std.Io.Writer, fmt: []const u8, str: []const u8) std.Io.Writer.Error!usize { | |
| 520 | const i = templateIndex(w, fmt, "{s}"); | |
| 521 | try w.writeAll(str); | |
| 522 | return i; | |
| 523 | } | |
| 524 | ||
| 514 | 525 | pub fn formatInt(w: *std.Io.Writer, fmt: []const u8, int: anytype) std.Io.Writer.Error!usize { |
| 515 | const template = "{d}"; | |
| 516 | const i = std.mem.indexOf(u8, fmt, template).?; | |
| 517 | try w.writeAll(fmt[0..i]); | |
| 526 | const i = templateIndex(w, fmt, "{d}"); | |
| 518 | 527 | try w.printInt(int, 10, .lower, .{}); |
| 519 | return i + template.len; | |
| 528 | return i; | |
| 520 | 529 | } |
| 521 | 530 | |
| 522 | 531 | fn addMessage(d: *Diagnostics, msg: Message) Compilation.Error!void { |
lib/compiler/aro/aro/Driver.zig+20-6| ... | ... | @@ -203,6 +203,7 @@ pub const usage = |
| 203 | 203 | \\ -fuse-line-directives Use `#line <num>` linemarkers in preprocessed output |
| 204 | 204 | \\ -fno-use-line-directives |
| 205 | 205 | \\ Use `# <num>` linemarkers in preprocessed output |
| 206 | \\ -iquote <dir> Add directory to QUOTE include search path | |
| 206 | 207 | \\ -I <dir> Add directory to include search path |
| 207 | 208 | \\ -idirafter <dir> Add directory to AFTER include search path |
| 208 | 209 | \\ -isystem <dir> Add directory to SYSTEM include search path |
| ... | ... | @@ -275,7 +276,7 @@ pub fn parseArgs( |
| 275 | 276 | var i: usize = 1; |
| 276 | 277 | var comment_arg: []const u8 = ""; |
| 277 | 278 | var hosted: ?bool = null; |
| 278 | var gnuc_version: []const u8 = "4.2.1"; // default value set by clang | |
| 279 | var gnuc_version: ?[]const u8 = null; | |
| 279 | 280 | var pic_arg: []const u8 = ""; |
| 280 | 281 | var declspec_attrs: ?bool = null; |
| 281 | 282 | var ms_extensions: ?bool = null; |
| ... | ... | @@ -529,6 +530,17 @@ pub fn parseArgs( |
| 529 | 530 | path = args[i]; |
| 530 | 531 | } |
| 531 | 532 | try d.comp.system_include_dirs.append(d.comp.gpa, path); |
| 533 | } else if (mem.startsWith(u8, arg, "-iquote")) { | |
| 534 | var path = arg["-iquote".len..]; | |
| 535 | if (path.len == 0) { | |
| 536 | i += 1; | |
| 537 | if (i >= args.len) { | |
| 538 | try d.err("expected argument after -iquote", .{}); | |
| 539 | continue; | |
| 540 | } | |
| 541 | path = args[i]; | |
| 542 | } | |
| 543 | try d.comp.iquote_include_dirs.append(d.comp.gpa, path); | |
| 532 | 544 | } else if (mem.startsWith(u8, arg, "-F")) { |
| 533 | 545 | var path = arg["-F".len..]; |
| 534 | 546 | if (path.len == 0) { |
| ... | ... | @@ -784,11 +796,13 @@ pub fn parseArgs( |
| 784 | 796 | d.comp.target.os.tag = .freestanding; |
| 785 | 797 | } |
| 786 | 798 | } |
| 787 | const version = GCCVersion.parse(gnuc_version); | |
| 788 | if (version.major == -1) { | |
| 789 | return d.fatal("invalid value '{0s}' in '-fgnuc-version={0s}'", .{gnuc_version}); | |
| 799 | if (gnuc_version) |unwrapped| { | |
| 800 | const version = GCCVersion.parse(unwrapped); | |
| 801 | if (version.major == -1) { | |
| 802 | return d.fatal("invalid value '{s}' in '-fgnuc-version={s}'", .{ unwrapped, unwrapped }); | |
| 803 | } | |
| 804 | d.comp.langopts.gnuc_version = version.toUnsigned(); | |
| 790 | 805 | } |
| 791 | d.comp.langopts.gnuc_version = version.toUnsigned(); | |
| 792 | 806 | const pic_level, const is_pie = try d.getPICMode(pic_arg); |
| 793 | 807 | d.comp.code_gen_options.pic_level = pic_level; |
| 794 | 808 | d.comp.code_gen_options.is_pie = is_pie; |
| ... | ... | @@ -1039,7 +1053,7 @@ fn getRandomFilename(d: *Driver, buf: *[std.fs.max_name_bytes]u8, extension: []c |
| 1039 | 1053 | |
| 1040 | 1054 | const fmt_template = "/tmp/{s}{s}"; |
| 1041 | 1055 | const fmt_args = .{ |
| 1042 | random_name, | |
| 1056 | @as([]const u8, &random_name), | |
| 1043 | 1057 | extension, |
| 1044 | 1058 | }; |
| 1045 | 1059 | return std.fmt.bufPrint(buf, fmt_template, fmt_args) catch return d.fatal("Filename too long for filesystem: " ++ fmt_template, fmt_args); |
lib/compiler/aro/aro/Driver/GCCVersion.zig+1-1| ... | ... | @@ -57,7 +57,7 @@ pub fn parse(text: []const u8) GCCVersion { |
| 57 | 57 | var good = bad; |
| 58 | 58 | |
| 59 | 59 | var it = mem.splitScalar(u8, text, '.'); |
| 60 | const first = it.next().?; | |
| 60 | const first = it.first(); | |
| 61 | 61 | const second = it.next() orelse ""; |
| 62 | 62 | const rest = it.next() orelse ""; |
| 63 | 63 |
lib/compiler/aro/aro/LangOpts.zig+9-1| ... | ... | @@ -7,6 +7,14 @@ pub const Compiler = enum { |
| 7 | 7 | clang, |
| 8 | 8 | gcc, |
| 9 | 9 | msvc, |
| 10 | ||
| 11 | pub fn defaultGccVersion(self: Compiler) u32 { | |
| 12 | return switch (self) { | |
| 13 | .clang => 4 * 10_000 + 2 * 100 + 1, | |
| 14 | .gcc => 7 * 10_000 + 1 * 100 + 0, | |
| 15 | .msvc => 0, | |
| 16 | }; | |
| 17 | } | |
| 10 | 18 | }; |
| 11 | 19 | |
| 12 | 20 | /// The floating-point evaluation method for intermediate results within a single expression |
| ... | ... | @@ -139,7 +147,7 @@ preserve_comments_in_macros: bool = false, |
| 139 | 147 | /// Used ONLY for generating __GNUC__ and related macros. Does not control the presence/absence of any features |
| 140 | 148 | /// Encoded as major * 10,000 + minor * 100 + patch |
| 141 | 149 | /// e.g. 4.2.1 == 40201 |
| 142 | gnuc_version: u32 = 0, | |
| 150 | gnuc_version: ?u32 = null, | |
| 143 | 151 | |
| 144 | 152 | pub fn setStandard(self: *LangOpts, name: []const u8) error{InvalidStandard}!void { |
| 145 | 153 | self.standard = Standard.NameMap.get(name) orelse return error.InvalidStandard; |
lib/compiler/aro/aro/Parser.zig+40-36| ... | ... | @@ -469,7 +469,7 @@ fn formatArgs(p: *Parser, w: *std.Io.Writer, fmt: []const u8, args: anytype) !vo |
| 469 | 469 | else => switch (@typeInfo(@TypeOf(arg))) { |
| 470 | 470 | .int, .comptime_int => try Diagnostics.formatInt(w, fmt[i..], arg), |
| 471 | 471 | .pointer => try Diagnostics.formatString(w, fmt[i..], arg), |
| 472 | else => unreachable, | |
| 472 | else => comptime unreachable, | |
| 473 | 473 | }, |
| 474 | 474 | }; |
| 475 | 475 | } |
| ... | ... | @@ -477,22 +477,18 @@ fn formatArgs(p: *Parser, w: *std.Io.Writer, fmt: []const u8, args: anytype) !vo |
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | fn formatTokenId(w: *std.Io.Writer, fmt: []const u8, tok_id: Tree.Token.Id) !usize { |
| 480 | const template = "{tok_id}"; | |
| 481 | const i = std.mem.indexOf(u8, fmt, template).?; | |
| 482 | try w.writeAll(fmt[0..i]); | |
| 480 | const i = Diagnostics.templateIndex(w, fmt, "{tok_id}"); | |
| 483 | 481 | try w.writeAll(tok_id.symbol()); |
| 484 | return i + template.len; | |
| 482 | return i; | |
| 485 | 483 | } |
| 486 | 484 | |
| 487 | 485 | fn formatQualType(p: *Parser, w: *std.Io.Writer, fmt: []const u8, qt: QualType) !usize { |
| 488 | const template = "{qt}"; | |
| 489 | const i = std.mem.indexOf(u8, fmt, template).?; | |
| 490 | try w.writeAll(fmt[0..i]); | |
| 486 | const i = Diagnostics.templateIndex(w, fmt, "{qt}"); | |
| 491 | 487 | try w.writeByte('\''); |
| 492 | 488 | try qt.print(p.comp, w); |
| 493 | 489 | try w.writeByte('\''); |
| 494 | 490 | |
| 495 | if (qt.isC23Auto()) return i + template.len; | |
| 491 | if (qt.isC23Auto()) return i; | |
| 496 | 492 | if (qt.get(p.comp, .vector)) |vector_ty| { |
| 497 | 493 | try w.print(" (vector of {d} '", .{vector_ty.len}); |
| 498 | 494 | try vector_ty.elem.printDesugared(p.comp, w); |
| ... | ... | @@ -502,14 +498,11 @@ fn formatQualType(p: *Parser, w: *std.Io.Writer, fmt: []const u8, qt: QualType) |
| 502 | 498 | try qt.printDesugared(p.comp, w); |
| 503 | 499 | try w.writeAll("')"); |
| 504 | 500 | } |
| 505 | return i + template.len; | |
| 501 | return i; | |
| 506 | 502 | } |
| 507 | 503 | |
| 508 | 504 | fn formatResult(p: *Parser, w: *std.Io.Writer, fmt: []const u8, res: Result) !usize { |
| 509 | const template = "{value}"; | |
| 510 | const i = std.mem.indexOf(u8, fmt, template).?; | |
| 511 | try w.writeAll(fmt[0..i]); | |
| 512 | ||
| 505 | const i = Diagnostics.templateIndex(w, fmt, "{value}"); | |
| 513 | 506 | switch (res.val.opt_ref) { |
| 514 | 507 | .none => try w.writeAll("(none)"), |
| 515 | 508 | .null => try w.writeAll("nullptr_t"), |
| ... | ... | @@ -521,8 +514,7 @@ fn formatResult(p: *Parser, w: *std.Io.Writer, fmt: []const u8, res: Result) !us |
| 521 | 514 | }, |
| 522 | 515 | }, |
| 523 | 516 | } |
| 524 | ||
| 525 | return i + template.len; | |
| 517 | return i; | |
| 526 | 518 | } |
| 527 | 519 | |
| 528 | 520 | const Normalized = struct { |
| ... | ... | @@ -532,10 +524,8 @@ const Normalized = struct { |
| 532 | 524 | return .{ .str = str }; |
| 533 | 525 | } |
| 534 | 526 | |
| 535 | pub fn format(ctx: Normalized, w: *std.Io.Writer, fmt_str: []const u8) !usize { | |
| 536 | const template = "{normalized}"; | |
| 537 | const i = std.mem.indexOf(u8, fmt_str, template).?; | |
| 538 | try w.writeAll(fmt_str[0..i]); | |
| 527 | pub fn format(ctx: Normalized, w: *std.Io.Writer, fmt: []const u8) !usize { | |
| 528 | const i = Diagnostics.templateIndex(w, fmt, "{normalized}"); | |
| 539 | 529 | var it: std.unicode.Utf8Iterator = .{ |
| 540 | 530 | .bytes = ctx.str, |
| 541 | 531 | .i = 0, |
| ... | ... | @@ -557,7 +547,7 @@ const Normalized = struct { |
| 557 | 547 | }); |
| 558 | 548 | } |
| 559 | 549 | } |
| 560 | return i + template.len; | |
| 550 | return i; | |
| 561 | 551 | } |
| 562 | 552 | }; |
| 563 | 553 | |
| ... | ... | @@ -568,12 +558,10 @@ const Codepoint = struct { |
| 568 | 558 | return .{ .codepoint = codepoint }; |
| 569 | 559 | } |
| 570 | 560 | |
| 571 | pub fn format(ctx: Codepoint, w: *std.Io.Writer, fmt_str: []const u8) !usize { | |
| 572 | const template = "{codepoint}"; | |
| 573 | const i = std.mem.indexOf(u8, fmt_str, template).?; | |
| 574 | try w.writeAll(fmt_str[0..i]); | |
| 561 | pub fn format(ctx: Codepoint, w: *std.Io.Writer, fmt: []const u8) !usize { | |
| 562 | const i = Diagnostics.templateIndex(w, fmt, "{codepoint}"); | |
| 575 | 563 | try w.print("{X:0>4}", .{ctx.codepoint}); |
| 576 | return i + template.len; | |
| 564 | return i; | |
| 577 | 565 | } |
| 578 | 566 | }; |
| 579 | 567 | |
| ... | ... | @@ -584,12 +572,10 @@ const Escaped = struct { |
| 584 | 572 | return .{ .str = str }; |
| 585 | 573 | } |
| 586 | 574 | |
| 587 | pub fn format(ctx: Escaped, w: *std.Io.Writer, fmt_str: []const u8) !usize { | |
| 588 | const template = "{s}"; | |
| 589 | const i = std.mem.indexOf(u8, fmt_str, template).?; | |
| 590 | try w.writeAll(fmt_str[0..i]); | |
| 575 | pub fn format(ctx: Escaped, w: *std.Io.Writer, fmt: []const u8) !usize { | |
| 576 | const i = Diagnostics.templateIndex(w, fmt, "{s}"); | |
| 591 | 577 | try std.zig.stringEscape(ctx.str, w); |
| 592 | return i + template.len; | |
| 578 | return i; | |
| 593 | 579 | } |
| 594 | 580 | }; |
| 595 | 581 | |
| ... | ... | @@ -626,11 +612,11 @@ pub fn errValueChanged(p: *Parser, tok_i: TokenIndex, diagnostic: Diagnostic, re |
| 626 | 612 | fn checkDeprecatedUnavailable(p: *Parser, ty: QualType, usage_tok: TokenIndex, decl_tok: TokenIndex) !void { |
| 627 | 613 | if (ty.getAttribute(p.comp, .@"error")) |@"error"| { |
| 628 | 614 | const msg_str = p.comp.interner.get(@"error".msg.ref()).bytes; |
| 629 | try p.err(usage_tok, .error_attribute, .{ p.tokSlice(@"error".__name_tok), std.zig.fmtString(msg_str) }); | |
| 615 | try p.err(usage_tok, .error_attribute, .{ p.tokSlice(@"error".__name_tok), Escaped.init(msg_str) }); | |
| 630 | 616 | } |
| 631 | 617 | if (ty.getAttribute(p.comp, .warning)) |warning| { |
| 632 | 618 | const msg_str = p.comp.interner.get(warning.msg.ref()).bytes; |
| 633 | try p.err(usage_tok, .warning_attribute, .{ p.tokSlice(warning.__name_tok), std.zig.fmtString(msg_str) }); | |
| 619 | try p.err(usage_tok, .warning_attribute, .{ p.tokSlice(warning.__name_tok), Escaped.init(msg_str) }); | |
| 634 | 620 | } |
| 635 | 621 | if (ty.getAttribute(p.comp, .unavailable)) |unavailable| { |
| 636 | 622 | try p.errDeprecated(usage_tok, .unavailable, unavailable.msg); |
| ... | ... | @@ -4734,7 +4720,7 @@ fn asmOperand(p: *Parser, names: *std.ArrayList(?TokenIndex), constraints: *Node |
| 4734 | 4720 | try constraints.append(gpa, constraint.node); |
| 4735 | 4721 | |
| 4736 | 4722 | const l_paren = p.eatToken(.l_paren) orelse { |
| 4737 | try p.err(p.tok_i, .expected_token, .{ p.tok_ids[p.tok_i], .l_paren }); | |
| 4723 | try p.err(p.tok_i, .expected_token, .{ p.tok_ids[p.tok_i], Token.Id.l_paren }); | |
| 4738 | 4724 | return error.ParsingFailed; |
| 4739 | 4725 | }; |
| 4740 | 4726 | const maybe_res = try p.expr(); |
| ... | ... | @@ -10221,12 +10207,30 @@ test "Node locations" { |
| 10221 | 10207 | try std.testing.expectEqual(0, comp.diagnostics.total); |
| 10222 | 10208 | for (tree.root_decls.items[tree.root_decls.items.len - 3 ..], 0..) |node, i| { |
| 10223 | 10209 | const slice = tree.tokSlice(node.tok(&tree)); |
| 10224 | const expected = switch (i) { | |
| 10210 | const expected_slice = switch (i) { | |
| 10225 | 10211 | 0 => "foo", |
| 10226 | 10212 | 1 => "bar", |
| 10227 | 10213 | 2 => "main", |
| 10228 | 10214 | else => unreachable, |
| 10229 | 10215 | }; |
| 10230 | try std.testing.expectEqualStrings(expected, slice); | |
| 10216 | try std.testing.expectEqualStrings(expected_slice, slice); | |
| 10217 | ||
| 10218 | const loc = node.loc(&tree).expand(&comp); | |
| 10219 | const expected_col: u32 = switch (i) { | |
| 10220 | 0 => 5, | |
| 10221 | 1 => 5, | |
| 10222 | 2 => 5, | |
| 10223 | else => unreachable, | |
| 10224 | }; | |
| 10225 | try std.testing.expectEqual(expected_col, loc.col); | |
| 10226 | ||
| 10227 | const expected_line_no = i + 1; | |
| 10228 | try std.testing.expectEqual(expected_line_no, loc.line_no); | |
| 10229 | ||
| 10230 | const expected_source_path = "file.c"; | |
| 10231 | try std.testing.expectEqualStrings(expected_source_path, loc.path); | |
| 10232 | ||
| 10233 | const expected_source_kind = Source.Kind.user; | |
| 10234 | try std.testing.expectEqual(expected_source_kind, loc.kind); | |
| 10231 | 10235 | } |
| 10232 | 10236 | } |
lib/compiler/aro/aro/Preprocessor.zig+4-1| ... | ... | @@ -1703,7 +1703,10 @@ fn expandFuncMacro( |
| 1703 | 1703 | else |
| 1704 | 1704 | &[1]TokenWithExpansionLocs{tokFromRaw(raw_next)}, |
| 1705 | 1705 | .macro_param, .macro_param_no_expand => getPasteArgs(args.items[raw_next.end]), |
| 1706 | .keyword_va_args => variable_arguments.items, | |
| 1706 | .keyword_va_args => if (variable_arguments.items.len == 0) blk: { | |
| 1707 | try pp.err(raw_next, .no_argument_variadic_macro, .{}); | |
| 1708 | break :blk &[1]TokenWithExpansionLocs{.{ .id = .placemarker, .loc = .{ .id = .generated } }}; | |
| 1709 | } else variable_arguments.items, | |
| 1707 | 1710 | .keyword_va_opt => blk: { |
| 1708 | 1711 | try pp.expandVaOpt(&va_opt_buf, raw_next, variable_arguments.items.len != 0); |
| 1709 | 1712 | if (va_opt_buf.items.len == 0) break; |
lib/compiler/aro/aro/Preprocessor/Diagnostic.zig+7| ... | ... | @@ -449,3 +449,10 @@ pub const date_time: Diagnostic = .{ |
| 449 | 449 | .opt = .@"date-time", |
| 450 | 450 | .show_in_system_headers = true, |
| 451 | 451 | }; |
| 452 | ||
| 453 | pub const no_argument_variadic_macro: Diagnostic = .{ | |
| 454 | .fmt = "passing no argument for the '...' parameter of a variadic macro is incompatible with C standards before C23", | |
| 455 | .opt = .@"variadic-macro-arguments-omitted", | |
| 456 | .kind = .off, | |
| 457 | .extension = true, | |
| 458 | }; |
lib/compiler/aro/aro/Tree.zig+2-2| ... | ... | @@ -1699,9 +1699,9 @@ pub const Node = union(enum) { |
| 1699 | 1699 | return tree.nodes.items(.tok)[@intFromEnum(index)]; |
| 1700 | 1700 | } |
| 1701 | 1701 | |
| 1702 | pub fn loc(index: Index, tree: *const Tree) ?Source.Location { | |
| 1702 | pub fn loc(index: Index, tree: *const Tree) Source.Location { | |
| 1703 | 1703 | const tok_i = index.tok(tree); |
| 1704 | return tree.tokens.items(.loc)[@intFromEnum(tok_i)]; | |
| 1704 | return tree.tokens.items(.loc)[tok_i]; | |
| 1705 | 1705 | } |
| 1706 | 1706 | |
| 1707 | 1707 | pub fn qt(index: Index, tree: *const Tree) QualType { |
lib/compiler/aro/aro/target.zig+3-1| ... | ... | @@ -681,10 +681,12 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 { |
| 681 | 681 | .driverkit => "driverkit", |
| 682 | 682 | .visionos => "xros", |
| 683 | 683 | .serenity => "serenity", |
| 684 | .vulkan => "vulkan", | |
| 684 | 685 | .managarm => "managarm", |
| 686 | .@"3ds", | |
| 687 | .vita, | |
| 685 | 688 | .opencl, |
| 686 | 689 | .opengl, |
| 687 | .vulkan, | |
| 688 | 690 | .plan9, |
| 689 | 691 | .other, |
| 690 | 692 | => "unknown", |
lib/compiler/aro/aro/text_literal.zig+4-7| ... | ... | @@ -154,17 +154,14 @@ pub const Ascii = struct { |
| 154 | 154 | return .{ .val = @intCast(val) }; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | pub fn format(ctx: Ascii, w: *std.Io.Writer, fmt_str: []const u8) !usize { | |
| 158 | const template = "{c}"; | |
| 159 | const i = std.mem.indexOf(u8, fmt_str, template).?; | |
| 160 | try w.writeAll(fmt_str[0..i]); | |
| 161 | ||
| 157 | pub fn format(ctx: Ascii, w: *std.Io.Writer, fmt: []const u8) !usize { | |
| 158 | const i = Diagnostics.templateIndex(w, fmt, "{c}"); | |
| 162 | 159 | if (std.ascii.isPrint(ctx.val)) { |
| 163 | 160 | try w.writeByte(ctx.val); |
| 164 | 161 | } else { |
| 165 | 162 | try w.print("x{x:0>2}", .{ctx.val}); |
| 166 | 163 | } |
| 167 | return i + template.len; | |
| 164 | return i; | |
| 168 | 165 | } |
| 169 | 166 | }; |
| 170 | 167 | |
| ... | ... | @@ -345,7 +342,7 @@ pub const Parser = struct { |
| 345 | 342 | else => switch (@typeInfo(@TypeOf(arg))) { |
| 346 | 343 | .int, .comptime_int => try Diagnostics.formatInt(w, fmt[i..], arg), |
| 347 | 344 | .pointer => try Diagnostics.formatString(w, fmt[i..], arg), |
| 348 | else => unreachable, | |
| 345 | else => comptime unreachable, | |
| 349 | 346 | }, |
| 350 | 347 | }; |
| 351 | 348 | } |
lib/compiler/translate-c/MacroTranslator.zig+59-52| ... | ... | @@ -175,8 +175,10 @@ pub fn transMacro(mt: *MacroTranslator) ParseError!void { |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | fn createMacroFn(mt: *MacroTranslator, name: []const u8, ref: ZigNode, proto_alias: *ast.Payload.Func) !ZigNode { |
| 178 | var fn_params = std.array_list.Managed(ast.Payload.Param).init(mt.t.gpa); | |
| 179 | defer fn_params.deinit(); | |
| 178 | const gpa = mt.t.gpa; | |
| 179 | const arena = mt.t.arena; | |
| 180 | var fn_params: std.ArrayList(ast.Payload.Param) = .empty; | |
| 181 | defer fn_params.deinit(gpa); | |
| 180 | 182 | |
| 181 | 183 | var block_scope = try Scope.Block.init(mt.t, &mt.t.global_scope.base, false); |
| 182 | 184 | defer block_scope.deinit(); |
| ... | ... | @@ -184,7 +186,7 @@ fn createMacroFn(mt: *MacroTranslator, name: []const u8, ref: ZigNode, proto_ali |
| 184 | 186 | for (proto_alias.data.params) |param| { |
| 185 | 187 | const param_name = try block_scope.makeMangledName(param.name orelse "arg"); |
| 186 | 188 | |
| 187 | try fn_params.append(.{ | |
| 189 | try fn_params.append(gpa, .{ | |
| 188 | 190 | .name = param_name, |
| 189 | 191 | .type = param.type, |
| 190 | 192 | .is_noalias = param.is_noalias, |
| ... | ... | @@ -198,27 +200,28 @@ fn createMacroFn(mt: *MacroTranslator, name: []const u8, ref: ZigNode, proto_ali |
| 198 | 200 | else |
| 199 | 201 | unreachable; |
| 200 | 202 | |
| 201 | const unwrap_expr = try ZigTag.unwrap.create(mt.t.arena, init); | |
| 202 | const args = try mt.t.arena.alloc(ZigNode, fn_params.items.len); | |
| 203 | const unwrap_expr = try ZigTag.unwrap.create(arena, init); | |
| 204 | const args = try arena.alloc(ZigNode, fn_params.items.len); | |
| 203 | 205 | for (fn_params.items, 0..) |param, i| { |
| 204 | args[i] = try ZigTag.identifier.create(mt.t.arena, param.name.?); | |
| 206 | args[i] = try ZigTag.identifier.create(arena, param.name.?); | |
| 205 | 207 | } |
| 206 | const call_expr = try ZigTag.call.create(mt.t.arena, .{ | |
| 208 | const call_expr = try ZigTag.call.create(arena, .{ | |
| 207 | 209 | .lhs = unwrap_expr, |
| 208 | 210 | .args = args, |
| 209 | 211 | }); |
| 210 | const return_expr = try ZigTag.@"return".create(mt.t.arena, call_expr); | |
| 211 | const block = try ZigTag.block_single.create(mt.t.arena, return_expr); | |
| 212 | const return_expr = try ZigTag.@"return".create(arena, call_expr); | |
| 213 | const block = try ZigTag.block_single.create(arena, return_expr); | |
| 212 | 214 | |
| 213 | return ZigTag.pub_inline_fn.create(mt.t.arena, .{ | |
| 215 | return ZigTag.pub_inline_fn.create(arena, .{ | |
| 214 | 216 | .name = name, |
| 215 | .params = try mt.t.arena.dupe(ast.Payload.Param, fn_params.items), | |
| 217 | .params = try arena.dupe(ast.Payload.Param, fn_params.items), | |
| 216 | 218 | .return_type = proto_alias.data.return_type, |
| 217 | 219 | .body = block, |
| 218 | 220 | }); |
| 219 | 221 | } |
| 220 | 222 | |
| 221 | 223 | fn parseCExpr(mt: *MacroTranslator, scope: *Scope) ParseError!ZigNode { |
| 224 | const arena = mt.t.arena; | |
| 222 | 225 | // TODO parseCAssignExpr here |
| 223 | 226 | var block_scope = try Scope.Block.init(mt.t, scope, true); |
| 224 | 227 | defer block_scope.deinit(); |
| ... | ... | @@ -229,14 +232,14 @@ fn parseCExpr(mt: *MacroTranslator, scope: *Scope) ParseError!ZigNode { |
| 229 | 232 | var last = node; |
| 230 | 233 | while (true) { |
| 231 | 234 | // suppress result |
| 232 | const ignore = try ZigTag.discard.create(mt.t.arena, .{ .should_skip = false, .value = last }); | |
| 235 | const ignore = try ZigTag.discard.create(arena, .{ .should_skip = false, .value = last }); | |
| 233 | 236 | try block_scope.statements.append(mt.t.gpa, ignore); |
| 234 | 237 | |
| 235 | 238 | last = try mt.parseCCondExpr(&block_scope.base); |
| 236 | 239 | if (!mt.eat(.comma)) break; |
| 237 | 240 | } |
| 238 | 241 | |
| 239 | const break_node = try ZigTag.break_val.create(mt.t.arena, .{ | |
| 242 | const break_node = try ZigTag.break_val.create(arena, .{ | |
| 240 | 243 | .label = block_scope.label, |
| 241 | 244 | .val = last, |
| 242 | 245 | }); |
| ... | ... | @@ -245,10 +248,11 @@ fn parseCExpr(mt: *MacroTranslator, scope: *Scope) ParseError!ZigNode { |
| 245 | 248 | } |
| 246 | 249 | |
| 247 | 250 | fn parseCNumLit(mt: *MacroTranslator) ParseError!ZigNode { |
| 251 | const arena = mt.t.arena; | |
| 248 | 252 | const lit_bytes = mt.tokSlice(); |
| 249 | 253 | mt.i += 1; |
| 250 | 254 | |
| 251 | var bytes = try std.ArrayListUnmanaged(u8).initCapacity(mt.t.arena, lit_bytes.len + 3); | |
| 255 | var bytes = try std.ArrayListUnmanaged(u8).initCapacity(arena, lit_bytes.len + 3); | |
| 252 | 256 | |
| 253 | 257 | const prefix = aro.Tree.Token.NumberPrefix.fromString(lit_bytes); |
| 254 | 258 | switch (prefix) { |
| ... | ... | @@ -330,7 +334,7 @@ fn parseCNumLit(mt: *MacroTranslator) ParseError!ZigNode { |
| 330 | 334 | } |
| 331 | 335 | |
| 332 | 336 | if (is_float) { |
| 333 | const type_node = try ZigTag.type.create(mt.t.arena, switch (suffix) { | |
| 337 | const type_node = try ZigTag.type.create(arena, switch (suffix) { | |
| 334 | 338 | .F16 => "f16", |
| 335 | 339 | .F => "f32", |
| 336 | 340 | .None => "f64", |
| ... | ... | @@ -339,10 +343,10 @@ fn parseCNumLit(mt: *MacroTranslator) ParseError!ZigNode { |
| 339 | 343 | .Q, .F128 => "f128", |
| 340 | 344 | else => unreachable, |
| 341 | 345 | }); |
| 342 | const rhs = try ZigTag.float_literal.create(mt.t.arena, bytes.items); | |
| 343 | return ZigTag.as.create(mt.t.arena, .{ .lhs = type_node, .rhs = rhs }); | |
| 346 | const rhs = try ZigTag.float_literal.create(arena, bytes.items); | |
| 347 | return ZigTag.as.create(arena, .{ .lhs = type_node, .rhs = rhs }); | |
| 344 | 348 | } else { |
| 345 | const type_node = try ZigTag.type.create(mt.t.arena, switch (suffix) { | |
| 349 | const type_node = try ZigTag.type.create(arena, switch (suffix) { | |
| 346 | 350 | .None => "c_int", |
| 347 | 351 | .U => "c_uint", |
| 348 | 352 | .L => "c_long", |
| ... | ... | @@ -365,11 +369,11 @@ fn parseCNumLit(mt: *MacroTranslator) ParseError!ZigNode { |
| 365 | 369 | else => unreachable, |
| 366 | 370 | }; |
| 367 | 371 | |
| 368 | const literal_node = try ZigTag.integer_literal.create(mt.t.arena, bytes.items); | |
| 372 | const literal_node = try ZigTag.integer_literal.create(arena, bytes.items); | |
| 369 | 373 | if (guaranteed_to_fit) { |
| 370 | return ZigTag.as.create(mt.t.arena, .{ .lhs = type_node, .rhs = literal_node }); | |
| 374 | return ZigTag.as.create(arena, .{ .lhs = type_node, .rhs = literal_node }); | |
| 371 | 375 | } else { |
| 372 | return mt.t.createHelperCallNode(.promoteIntLiteral, &.{ type_node, literal_node, try ZigTag.enum_literal.create(mt.t.arena, @tagName(prefix)) }); | |
| 376 | return mt.t.createHelperCallNode(.promoteIntLiteral, &.{ type_node, literal_node, try ZigTag.enum_literal.create(arena, @tagName(prefix)) }); | |
| 373 | 377 | } |
| 374 | 378 | } |
| 375 | 379 | } |
| ... | ... | @@ -563,6 +567,7 @@ fn escapeUnprintables(mt: *MacroTranslator) ![]const u8 { |
| 563 | 567 | } |
| 564 | 568 | |
| 565 | 569 | fn parseCPrimaryExpr(mt: *MacroTranslator, scope: *Scope) ParseError!ZigNode { |
| 570 | const arena = mt.t.arena; | |
| 566 | 571 | const tok = mt.peek(); |
| 567 | 572 | switch (tok) { |
| 568 | 573 | .char_literal, |
| ... | ... | @@ -573,12 +578,12 @@ fn parseCPrimaryExpr(mt: *MacroTranslator, scope: *Scope) ParseError!ZigNode { |
| 573 | 578 | => { |
| 574 | 579 | const slice = mt.tokSlice(); |
| 575 | 580 | if (slice[0] != '\'' or slice[1] == '\\' or slice.len == 3) { |
| 576 | return ZigTag.char_literal.create(mt.t.arena, try mt.escapeUnprintables()); | |
| 581 | return ZigTag.char_literal.create(arena, try mt.escapeUnprintables()); | |
| 577 | 582 | } else { |
| 578 | 583 | mt.i += 1; |
| 579 | 584 | |
| 580 | const str = try std.fmt.allocPrint(mt.t.arena, "0x{x}", .{slice[1 .. slice.len - 1]}); | |
| 581 | return ZigTag.integer_literal.create(mt.t.arena, str); | |
| 585 | const str = try std.fmt.allocPrint(arena, "0x{x}", .{slice[1 .. slice.len - 1]}); | |
| 586 | return ZigTag.integer_literal.create(arena, str); | |
| 582 | 587 | } |
| 583 | 588 | }, |
| 584 | 589 | .string_literal, |
| ... | ... | @@ -586,7 +591,7 @@ fn parseCPrimaryExpr(mt: *MacroTranslator, scope: *Scope) ParseError!ZigNode { |
| 586 | 591 | .string_literal_utf_8, |
| 587 | 592 | .string_literal_utf_32, |
| 588 | 593 | .string_literal_wide, |
| 589 | => return ZigTag.string_literal.create(mt.t.arena, try mt.escapeUnprintables()), | |
| 594 | => return ZigTag.string_literal.create(arena, try mt.escapeUnprintables()), | |
| 590 | 595 | .pp_num => return mt.parseCNumLit(), |
| 591 | 596 | .l_paren => { |
| 592 | 597 | mt.i += 1; |
| ... | ... | @@ -600,7 +605,7 @@ fn parseCPrimaryExpr(mt: *MacroTranslator, scope: *Scope) ParseError!ZigNode { |
| 600 | 605 | mt.i += 1; |
| 601 | 606 | |
| 602 | 607 | const mangled_name = scope.getAlias(param) orelse param; |
| 603 | return try ZigTag.identifier.create(mt.t.arena, mangled_name); | |
| 608 | return try ZigTag.identifier.create(arena, mangled_name); | |
| 604 | 609 | }, |
| 605 | 610 | .identifier, .extended_identifier => { |
| 606 | 611 | const slice = mt.tokSlice(); |
| ... | ... | @@ -608,17 +613,17 @@ fn parseCPrimaryExpr(mt: *MacroTranslator, scope: *Scope) ParseError!ZigNode { |
| 608 | 613 | |
| 609 | 614 | const mangled_name = scope.getAlias(slice) orelse slice; |
| 610 | 615 | if (Translator.builtin_typedef_map.get(mangled_name)) |ty| { |
| 611 | return ZigTag.type.create(mt.t.arena, ty); | |
| 616 | return ZigTag.type.create(arena, ty); | |
| 612 | 617 | } |
| 613 | 618 | if (builtins.map.get(mangled_name)) |builtin| { |
| 614 | const builtin_identifier = try ZigTag.identifier.create(mt.t.arena, "__builtin"); | |
| 615 | return ZigTag.field_access.create(mt.t.arena, .{ | |
| 619 | const builtin_identifier = try ZigTag.identifier.create(arena, "__builtin"); | |
| 620 | return ZigTag.field_access.create(arena, .{ | |
| 616 | 621 | .lhs = builtin_identifier, |
| 617 | 622 | .field_name = builtin.name, |
| 618 | 623 | }); |
| 619 | 624 | } |
| 620 | 625 | |
| 621 | const identifier = try ZigTag.identifier.create(mt.t.arena, mangled_name); | |
| 626 | const identifier = try ZigTag.identifier.create(arena, mangled_name); | |
| 622 | 627 | scope.skipVariableDiscard(mangled_name); |
| 623 | 628 | refs_var: { |
| 624 | 629 | const ident_node = mt.t.global_scope.sym_table.get(slice) orelse break :refs_var; |
| ... | ... | @@ -1114,6 +1119,8 @@ fn parseCPostfixExpr(mt: *MacroTranslator, scope: *Scope, type_name: ?ZigNode) P |
| 1114 | 1119 | } |
| 1115 | 1120 | |
| 1116 | 1121 | fn parseCPostfixExprInner(mt: *MacroTranslator, scope: *Scope, type_name: ?ZigNode) ParseError!ZigNode { |
| 1122 | const gpa = mt.t.gpa; | |
| 1123 | const arena = mt.t.arena; | |
| 1117 | 1124 | var node = type_name orelse try mt.parseCPrimaryExpr(scope); |
| 1118 | 1125 | while (true) { |
| 1119 | 1126 | switch (mt.peek()) { |
| ... | ... | @@ -1122,39 +1129,39 @@ fn parseCPostfixExprInner(mt: *MacroTranslator, scope: *Scope, type_name: ?ZigNo |
| 1122 | 1129 | const field_name = mt.tokSlice(); |
| 1123 | 1130 | try mt.expect(.identifier); |
| 1124 | 1131 | |
| 1125 | node = try ZigTag.field_access.create(mt.t.arena, .{ .lhs = node, .field_name = field_name }); | |
| 1132 | node = try ZigTag.field_access.create(arena, .{ .lhs = node, .field_name = field_name }); | |
| 1126 | 1133 | }, |
| 1127 | 1134 | .arrow => { |
| 1128 | 1135 | mt.i += 1; |
| 1129 | 1136 | const field_name = mt.tokSlice(); |
| 1130 | 1137 | try mt.expect(.identifier); |
| 1131 | 1138 | |
| 1132 | const deref = try ZigTag.deref.create(mt.t.arena, node); | |
| 1133 | node = try ZigTag.field_access.create(mt.t.arena, .{ .lhs = deref, .field_name = field_name }); | |
| 1139 | const deref = try ZigTag.deref.create(arena, node); | |
| 1140 | node = try ZigTag.field_access.create(arena, .{ .lhs = deref, .field_name = field_name }); | |
| 1134 | 1141 | }, |
| 1135 | 1142 | .l_bracket => { |
| 1136 | 1143 | mt.i += 1; |
| 1137 | 1144 | |
| 1138 | 1145 | const index_val = try mt.macroIntFromBool(try mt.parseCExpr(scope)); |
| 1139 | const index = try ZigTag.as.create(mt.t.arena, .{ | |
| 1140 | .lhs = try ZigTag.type.create(mt.t.arena, "usize"), | |
| 1141 | .rhs = try ZigTag.int_cast.create(mt.t.arena, index_val), | |
| 1146 | const index = try ZigTag.as.create(arena, .{ | |
| 1147 | .lhs = try ZigTag.type.create(arena, "usize"), | |
| 1148 | .rhs = try ZigTag.int_cast.create(arena, index_val), | |
| 1142 | 1149 | }); |
| 1143 | node = try ZigTag.array_access.create(mt.t.arena, .{ .lhs = node, .rhs = index }); | |
| 1150 | node = try ZigTag.array_access.create(arena, .{ .lhs = node, .rhs = index }); | |
| 1144 | 1151 | try mt.expect(.r_bracket); |
| 1145 | 1152 | }, |
| 1146 | 1153 | .l_paren => { |
| 1147 | 1154 | mt.i += 1; |
| 1148 | 1155 | |
| 1149 | 1156 | if (mt.eat(.r_paren)) { |
| 1150 | node = try ZigTag.call.create(mt.t.arena, .{ .lhs = node, .args = &.{} }); | |
| 1157 | node = try ZigTag.call.create(arena, .{ .lhs = node, .args = &.{} }); | |
| 1151 | 1158 | } else { |
| 1152 | var args = std.array_list.Managed(ZigNode).init(mt.t.gpa); | |
| 1153 | defer args.deinit(); | |
| 1159 | var args: std.ArrayList(ZigNode) = .empty; | |
| 1160 | defer args.deinit(gpa); | |
| 1154 | 1161 | |
| 1155 | 1162 | while (true) { |
| 1156 | 1163 | const arg = try mt.parseCCondExpr(scope); |
| 1157 | try args.append(arg); | |
| 1164 | try args.append(gpa, arg); | |
| 1158 | 1165 | |
| 1159 | 1166 | const next_id = mt.peek(); |
| 1160 | 1167 | switch (next_id) { |
| ... | ... | @@ -1171,7 +1178,7 @@ fn parseCPostfixExprInner(mt: *MacroTranslator, scope: *Scope, type_name: ?ZigNo |
| 1171 | 1178 | }, |
| 1172 | 1179 | } |
| 1173 | 1180 | } |
| 1174 | node = try ZigTag.call.create(mt.t.arena, .{ .lhs = node, .args = try mt.t.arena.dupe(ZigNode, args.items) }); | |
| 1181 | node = try ZigTag.call.create(arena, .{ .lhs = node, .args = try arena.dupe(ZigNode, args.items) }); | |
| 1175 | 1182 | } |
| 1176 | 1183 | }, |
| 1177 | 1184 | .l_brace => { |
| ... | ... | @@ -1179,8 +1186,8 @@ fn parseCPostfixExprInner(mt: *MacroTranslator, scope: *Scope, type_name: ?ZigNo |
| 1179 | 1186 | |
| 1180 | 1187 | // Check for designated field initializers |
| 1181 | 1188 | if (mt.peek() == .period) { |
| 1182 | var init_vals = std.array_list.Managed(ast.Payload.ContainerInitDot.Initializer).init(mt.t.gpa); | |
| 1183 | defer init_vals.deinit(); | |
| 1189 | var init_vals: std.ArrayList(ast.Payload.ContainerInitDot.Initializer) = .empty; | |
| 1190 | defer init_vals.deinit(gpa); | |
| 1184 | 1191 | |
| 1185 | 1192 | while (true) { |
| 1186 | 1193 | try mt.expect(.period); |
| ... | ... | @@ -1189,7 +1196,7 @@ fn parseCPostfixExprInner(mt: *MacroTranslator, scope: *Scope, type_name: ?ZigNo |
| 1189 | 1196 | try mt.expect(.equal); |
| 1190 | 1197 | |
| 1191 | 1198 | const val = try mt.parseCCondExpr(scope); |
| 1192 | try init_vals.append(.{ .name = name, .value = val }); | |
| 1199 | try init_vals.append(gpa, .{ .name = name, .value = val }); | |
| 1193 | 1200 | |
| 1194 | 1201 | const next_id = mt.peek(); |
| 1195 | 1202 | switch (next_id) { |
| ... | ... | @@ -1206,17 +1213,17 @@ fn parseCPostfixExprInner(mt: *MacroTranslator, scope: *Scope, type_name: ?ZigNo |
| 1206 | 1213 | }, |
| 1207 | 1214 | } |
| 1208 | 1215 | } |
| 1209 | const tuple_node = try ZigTag.container_init_dot.create(mt.t.arena, try mt.t.arena.dupe(ast.Payload.ContainerInitDot.Initializer, init_vals.items)); | |
| 1210 | node = try ZigTag.std_mem_zeroinit.create(mt.t.arena, .{ .lhs = node, .rhs = tuple_node }); | |
| 1216 | const tuple_node = try ZigTag.container_init_dot.create(arena, try arena.dupe(ast.Payload.ContainerInitDot.Initializer, init_vals.items)); | |
| 1217 | node = try ZigTag.std_mem_zeroinit.create(arena, .{ .lhs = node, .rhs = tuple_node }); | |
| 1211 | 1218 | continue; |
| 1212 | 1219 | } |
| 1213 | 1220 | |
| 1214 | var init_vals = std.array_list.Managed(ZigNode).init(mt.t.gpa); | |
| 1215 | defer init_vals.deinit(); | |
| 1221 | var init_vals: std.ArrayList(ZigNode) = .empty; | |
| 1222 | defer init_vals.deinit(gpa); | |
| 1216 | 1223 | |
| 1217 | 1224 | while (true) { |
| 1218 | 1225 | const val = try mt.parseCCondExpr(scope); |
| 1219 | try init_vals.append(val); | |
| 1226 | try init_vals.append(gpa, val); | |
| 1220 | 1227 | |
| 1221 | 1228 | const next_id = mt.peek(); |
| 1222 | 1229 | switch (next_id) { |
| ... | ... | @@ -1233,8 +1240,8 @@ fn parseCPostfixExprInner(mt: *MacroTranslator, scope: *Scope, type_name: ?ZigNo |
| 1233 | 1240 | }, |
| 1234 | 1241 | } |
| 1235 | 1242 | } |
| 1236 | const tuple_node = try ZigTag.tuple.create(mt.t.arena, try mt.t.arena.dupe(ZigNode, init_vals.items)); | |
| 1237 | node = try ZigTag.std_mem_zeroinit.create(mt.t.arena, .{ .lhs = node, .rhs = tuple_node }); | |
| 1243 | const tuple_node = try ZigTag.tuple.create(arena, try arena.dupe(ZigNode, init_vals.items)); | |
| 1244 | node = try ZigTag.std_mem_zeroinit.create(arena, .{ .lhs = node, .rhs = tuple_node }); | |
| 1238 | 1245 | }, |
| 1239 | 1246 | .plus_plus, .minus_minus => { |
| 1240 | 1247 | try mt.fail("TODO postfix inc/dec expr", .{}); |
lib/compiler/translate-c/PatternList.zig+10-10| ... | ... | @@ -91,11 +91,11 @@ const Pattern = struct { |
| 91 | 91 | fn init(pl: *Pattern, allocator: mem.Allocator, template: Template) Error!void { |
| 92 | 92 | const source = template[0]; |
| 93 | 93 | const impl = template[1]; |
| 94 | var tok_list = std.array_list.Managed(CToken).init(allocator); | |
| 95 | defer tok_list.deinit(); | |
| 94 | var tok_list: std.ArrayList(CToken) = .empty; | |
| 95 | defer tok_list.deinit(allocator); | |
| 96 | 96 | |
| 97 | 97 | pl.* = .{ |
| 98 | .slicer = try tokenizeMacro(source, &tok_list), | |
| 98 | .slicer = try tokenizeMacro(allocator, source, &tok_list), | |
| 99 | 99 | .impl = impl, |
| 100 | 100 | }; |
| 101 | 101 | } |
| ... | ... | @@ -170,7 +170,7 @@ pub fn match(pl: PatternList, ms: MacroSlicer) Error!?Impl { |
| 170 | 170 | return null; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | fn tokenizeMacro(source: []const u8, tok_list: *std.array_list.Managed(CToken)) Error!MacroSlicer { | |
| 173 | fn tokenizeMacro(allocator: mem.Allocator, source: []const u8, tok_list: *std.ArrayList(CToken)) Error!MacroSlicer { | |
| 174 | 174 | var param_count: u32 = 0; |
| 175 | 175 | var param_buf: [8][]const u8 = undefined; |
| 176 | 176 | |
| ... | ... | @@ -207,7 +207,7 @@ fn tokenizeMacro(source: []const u8, tok_list: *std.array_list.Managed(CToken)) |
| 207 | 207 | const slice = source[tok.start..tok.end]; |
| 208 | 208 | for (param_buf[0..param_count], 0..) |param, i| { |
| 209 | 209 | if (std.mem.eql(u8, param, slice)) { |
| 210 | try tok_list.append(.{ | |
| 210 | try tok_list.append(allocator, .{ | |
| 211 | 211 | .id = .macro_param, |
| 212 | 212 | .source = .unused, |
| 213 | 213 | .end = @intCast(i), |
| ... | ... | @@ -224,12 +224,12 @@ fn tokenizeMacro(source: []const u8, tok_list: *std.array_list.Managed(CToken)) |
| 224 | 224 | .nl, .eof => break, |
| 225 | 225 | else => {}, |
| 226 | 226 | } |
| 227 | try tok_list.append(tok); | |
| 227 | try tok_list.append(allocator, tok); | |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | return .{ |
| 231 | 231 | .source = source, |
| 232 | .tokens = try tok_list.toOwnedSlice(), | |
| 232 | .tokens = try tok_list.toOwnedSlice(allocator), | |
| 233 | 233 | .params = param_count, |
| 234 | 234 | }; |
| 235 | 235 | } |
| ... | ... | @@ -243,9 +243,9 @@ test "Macro matching" { |
| 243 | 243 | source: []const u8, |
| 244 | 244 | comptime expected_match: ?Impl, |
| 245 | 245 | ) !void { |
| 246 | var tok_list = std.array_list.Managed(CToken).init(allocator); | |
| 247 | defer tok_list.deinit(); | |
| 248 | const ms = try tokenizeMacro(source, &tok_list); | |
| 246 | var tok_list: std.ArrayList(CToken) = .empty; | |
| 247 | defer tok_list.deinit(allocator); | |
| 248 | const ms = try tokenizeMacro(allocator, source, &tok_list); | |
| 249 | 249 | defer allocator.free(ms.tokens); |
| 250 | 250 | |
| 251 | 251 | const matched = try pattern_list.match(ms); |
lib/compiler/translate-c/Translator.zig+26-25| ... | ... | @@ -216,10 +216,10 @@ pub fn translate(options: Options) mem.Allocator.Error![]u8 { |
| 216 | 216 | |
| 217 | 217 | try translator.global_scope.processContainerMemberFns(); |
| 218 | 218 | |
| 219 | var aw: std.Io.Writer.Allocating = .init(gpa); | |
| 220 | defer aw.deinit(); | |
| 219 | var allocating: std.Io.Writer.Allocating = .init(gpa); | |
| 220 | defer allocating.deinit(); | |
| 221 | 221 | |
| 222 | aw.writer.writeAll( | |
| 222 | allocating.writer.writeAll( | |
| 223 | 223 | \\pub const __builtin = @import("std").zig.c_translation.builtins; |
| 224 | 224 | \\pub const __helpers = @import("std").zig.c_translation.helpers; |
| 225 | 225 | \\ |
| ... | ... | @@ -231,8 +231,8 @@ pub fn translate(options: Options) mem.Allocator.Error![]u8 { |
| 231 | 231 | gpa.free(zig_ast.source); |
| 232 | 232 | zig_ast.deinit(gpa); |
| 233 | 233 | } |
| 234 | zig_ast.render(gpa, &aw.writer, .{}) catch return error.OutOfMemory; | |
| 235 | return aw.toOwnedSlice(); | |
| 234 | zig_ast.render(gpa, &allocating.writer, .{}) catch return error.OutOfMemory; | |
| 235 | return allocating.toOwnedSlice(); | |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | fn prepopulateGlobalNameTable(t: *Translator) !void { |
| ... | ... | @@ -489,11 +489,12 @@ fn transRecordDecl(t: *Translator, scope: *Scope, record_qt: QualType) Error!voi |
| 489 | 489 | break :init ZigTag.opaque_literal.init(); |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | var fields = try std.array_list.Managed(ast.Payload.Container.Field).initCapacity(t.gpa, record_ty.fields.len); | |
| 493 | defer fields.deinit(); | |
| 492 | var fields: std.ArrayList(ast.Payload.Container.Field) = .empty; | |
| 493 | defer fields.deinit(t.gpa); | |
| 494 | try fields.ensureUnusedCapacity(t.gpa, record_ty.fields.len); | |
| 494 | 495 | |
| 495 | var functions = std.array_list.Managed(ZigNode).init(t.gpa); | |
| 496 | defer functions.deinit(); | |
| 496 | var functions: std.ArrayList(ZigNode) = .empty; | |
| 497 | defer functions.deinit(t.gpa); | |
| 497 | 498 | |
| 498 | 499 | var unnamed_field_count: u32 = 0; |
| 499 | 500 | |
| ... | ... | @@ -558,7 +559,7 @@ fn transRecordDecl(t: *Translator, scope: *Scope, record_qt: QualType) Error!voi |
| 558 | 559 | field_name = try std.fmt.allocPrint(t.arena, "_{s}", .{field_name}); |
| 559 | 560 | |
| 560 | 561 | const member = try t.createFlexibleMemberFn(member_name, field_name); |
| 561 | try functions.append(member); | |
| 562 | try functions.append(t.gpa, member); | |
| 562 | 563 | |
| 563 | 564 | break :field_type zero_array; |
| 564 | 565 | } |
| ... | ... | @@ -600,7 +601,7 @@ fn transRecordDecl(t: *Translator, scope: *Scope, record_qt: QualType) Error!voi |
| 600 | 601 | const padding_bits = record_ty.layout.?.size_bits; |
| 601 | 602 | const alignment_bits = record_ty.layout.?.field_alignment_bits; |
| 602 | 603 | |
| 603 | try fields.append(.{ | |
| 604 | try fields.append(t.gpa, .{ | |
| 604 | 605 | .name = "_padding", |
| 605 | 606 | .type = try ZigTag.type.create(t.arena, try std.fmt.allocPrint(t.arena, "u{d}", .{padding_bits})), |
| 606 | 607 | .alignment = @divExact(alignment_bits, 8), |
| ... | ... | @@ -1789,8 +1790,8 @@ fn transSwitch(t: *Translator, scope: *Scope, switch_stmt: Node.SwitchStmt) Tran |
| 1789 | 1790 | defer cond_scope.deinit(); |
| 1790 | 1791 | const switch_expr = try t.transExpr(&cond_scope.base, switch_stmt.cond, .used); |
| 1791 | 1792 | |
| 1792 | var cases = std.array_list.Managed(ZigNode).init(t.gpa); | |
| 1793 | defer cases.deinit(); | |
| 1793 | var cases: std.ArrayList(ZigNode) = .empty; | |
| 1794 | defer cases.deinit(t.gpa); | |
| 1794 | 1795 | var has_default = false; |
| 1795 | 1796 | |
| 1796 | 1797 | const body_node = switch_stmt.body.get(t.tree); |
| ... | ... | @@ -1803,21 +1804,21 @@ fn transSwitch(t: *Translator, scope: *Scope, switch_stmt: Node.SwitchStmt) Tran |
| 1803 | 1804 | for (body, 0..) |stmt, i| { |
| 1804 | 1805 | switch (stmt.get(t.tree)) { |
| 1805 | 1806 | .case_stmt => { |
| 1806 | var items = std.array_list.Managed(ZigNode).init(t.gpa); | |
| 1807 | defer items.deinit(); | |
| 1807 | var items: std.ArrayList(ZigNode) = .empty; | |
| 1808 | defer items.deinit(t.gpa); | |
| 1808 | 1809 | const sub = try t.transCaseStmt(base_scope, stmt, &items); |
| 1809 | 1810 | const res = try t.transSwitchProngStmt(base_scope, sub, body[i..]); |
| 1810 | 1811 | |
| 1811 | 1812 | if (items.items.len == 0) { |
| 1812 | 1813 | has_default = true; |
| 1813 | 1814 | const switch_else = try ZigTag.switch_else.create(t.arena, res); |
| 1814 | try cases.append(switch_else); | |
| 1815 | try cases.append(t.gpa, switch_else); | |
| 1815 | 1816 | } else { |
| 1816 | 1817 | const switch_prong = try ZigTag.switch_prong.create(t.arena, .{ |
| 1817 | 1818 | .cases = try t.arena.dupe(ZigNode, items.items), |
| 1818 | 1819 | .cond = res, |
| 1819 | 1820 | }); |
| 1820 | try cases.append(switch_prong); | |
| 1821 | try cases.append(t.gpa, switch_prong); | |
| 1821 | 1822 | } |
| 1822 | 1823 | }, |
| 1823 | 1824 | .default_stmt => |default_stmt| { |
| ... | ... | @@ -1833,7 +1834,7 @@ fn transSwitch(t: *Translator, scope: *Scope, switch_stmt: Node.SwitchStmt) Tran |
| 1833 | 1834 | const res = try t.transSwitchProngStmt(base_scope, sub, body[i..]); |
| 1834 | 1835 | |
| 1835 | 1836 | const switch_else = try ZigTag.switch_else.create(t.arena, res); |
| 1836 | try cases.append(switch_else); | |
| 1837 | try cases.append(t.gpa, switch_else); | |
| 1837 | 1838 | }, |
| 1838 | 1839 | else => {}, // collected in transSwitchProngStmt |
| 1839 | 1840 | } |
| ... | ... | @@ -1841,7 +1842,7 @@ fn transSwitch(t: *Translator, scope: *Scope, switch_stmt: Node.SwitchStmt) Tran |
| 1841 | 1842 | |
| 1842 | 1843 | if (!has_default) { |
| 1843 | 1844 | const else_prong = try ZigTag.switch_else.create(t.arena, ZigTag.empty_block.init()); |
| 1844 | try cases.append(else_prong); | |
| 1845 | try cases.append(t.gpa, else_prong); | |
| 1845 | 1846 | } |
| 1846 | 1847 | |
| 1847 | 1848 | const switch_node = try ZigTag.@"switch".create(t.arena, .{ |
| ... | ... | @@ -1861,7 +1862,7 @@ fn transCaseStmt( |
| 1861 | 1862 | t: *Translator, |
| 1862 | 1863 | scope: *Scope, |
| 1863 | 1864 | stmt: Node.Index, |
| 1864 | items: *std.array_list.Managed(ZigNode), | |
| 1865 | items: *std.ArrayList(ZigNode), | |
| 1865 | 1866 | ) TransError!Node.Index { |
| 1866 | 1867 | var sub = stmt; |
| 1867 | 1868 | var seen_default = false; |
| ... | ... | @@ -1886,7 +1887,7 @@ fn transCaseStmt( |
| 1886 | 1887 | break :blk try ZigTag.ellipsis3.create(t.arena, .{ .lhs = start_node, .rhs = end_node }); |
| 1887 | 1888 | } else try t.transExpr(scope, case_stmt.start, .used); |
| 1888 | 1889 | |
| 1889 | try items.append(expr); | |
| 1890 | try items.append(t.gpa, expr); | |
| 1890 | 1891 | sub = case_stmt.body; |
| 1891 | 1892 | }, |
| 1892 | 1893 | else => return sub, |
| ... | ... | @@ -3873,7 +3874,7 @@ fn createNumberNode(t: *Translator, num: anytype, num_kind: enum { int, float }) |
| 3873 | 3874 | |
| 3874 | 3875 | fn createCharLiteralNode(t: *Translator, narrow: bool, val: u32) TransError!ZigNode { |
| 3875 | 3876 | return ZigTag.char_literal.create(t.arena, if (narrow) |
| 3876 | try std.fmt.allocPrint(t.arena, "'{f}'", .{std.zig.fmtChar(@intCast(val))}) | |
| 3877 | try std.fmt.allocPrint(t.arena, "'{f}'", .{std.zig.fmtChar(@as(u8, @intCast(val)))}) | |
| 3877 | 3878 | else |
| 3878 | 3879 | try std.fmt.allocPrint(t.arena, "'\\u{{{x}}}'", .{val})); |
| 3879 | 3880 | } |
| ... | ... | @@ -3986,8 +3987,8 @@ fn createFlexibleMemberFn( |
| 3986 | 3987 | // ================= |
| 3987 | 3988 | |
| 3988 | 3989 | fn transMacros(t: *Translator) !void { |
| 3989 | var tok_list = std.array_list.Managed(CToken).init(t.gpa); | |
| 3990 | defer tok_list.deinit(); | |
| 3990 | var tok_list: std.ArrayList(CToken) = .empty; | |
| 3991 | defer tok_list.deinit(t.gpa); | |
| 3991 | 3992 | |
| 3992 | 3993 | var pattern_list = try PatternList.init(t.gpa); |
| 3993 | 3994 | defer pattern_list.deinit(t.gpa); |
| ... | ... | @@ -3999,7 +4000,7 @@ fn transMacros(t: *Translator) !void { |
| 3999 | 4000 | } |
| 4000 | 4001 | |
| 4001 | 4002 | tok_list.items.len = 0; |
| 4002 | try tok_list.ensureUnusedCapacity(macro.tokens.len); | |
| 4003 | try tok_list.ensureUnusedCapacity(t.gpa, macro.tokens.len); | |
| 4003 | 4004 | for (macro.tokens) |tok| { |
| 4004 | 4005 | switch (tok.id) { |
| 4005 | 4006 | .invalid => continue, |
lib/compiler/translate-c/ast.zig+23-23| ... | ... | @@ -798,9 +798,8 @@ pub const Payload = struct { |
| 798 | 798 | pub fn render(gpa: Allocator, nodes: []const Node) !std.zig.Ast { |
| 799 | 799 | var ctx: Context = .{ |
| 800 | 800 | .gpa = gpa, |
| 801 | .buf = std.array_list.Managed(u8).init(gpa), | |
| 802 | 801 | }; |
| 803 | defer ctx.buf.deinit(); | |
| 802 | defer ctx.buf.deinit(gpa); | |
| 804 | 803 | defer ctx.nodes.deinit(gpa); |
| 805 | 804 | defer ctx.extra_data.deinit(gpa); |
| 806 | 805 | defer ctx.tokens.deinit(gpa); |
| ... | ... | @@ -813,7 +812,7 @@ pub fn render(gpa: Allocator, nodes: []const Node) !std.zig.Ast { |
| 813 | 812 | try ctx.tokens.ensureTotalCapacity(gpa, estimated_tokens_count); |
| 814 | 813 | // Estimate that each each token is 3 bytes long. |
| 815 | 814 | const estimated_buf_len = estimated_tokens_count * 3; |
| 816 | try ctx.buf.ensureTotalCapacity(estimated_buf_len); | |
| 815 | try ctx.buf.ensureTotalCapacity(gpa, estimated_buf_len); | |
| 817 | 816 | |
| 818 | 817 | ctx.nodes.appendAssumeCapacity(.{ |
| 819 | 818 | .tag = .root, |
| ... | ... | @@ -822,12 +821,12 @@ pub fn render(gpa: Allocator, nodes: []const Node) !std.zig.Ast { |
| 822 | 821 | }); |
| 823 | 822 | |
| 824 | 823 | const root_members = blk: { |
| 825 | var result = std.array_list.Managed(NodeIndex).init(gpa); | |
| 826 | defer result.deinit(); | |
| 824 | var result: std.ArrayList(NodeIndex) = .empty; | |
| 825 | defer result.deinit(gpa); | |
| 827 | 826 | |
| 828 | 827 | for (nodes) |node| { |
| 829 | 828 | const res = (try renderNodeOpt(&ctx, node)) orelse continue; |
| 830 | try result.append(res); | |
| 829 | try result.append(gpa, res); | |
| 831 | 830 | } |
| 832 | 831 | break :blk try ctx.listToSpan(result.items); |
| 833 | 832 | }; |
| ... | ... | @@ -843,7 +842,7 @@ pub fn render(gpa: Allocator, nodes: []const Node) !std.zig.Ast { |
| 843 | 842 | }); |
| 844 | 843 | |
| 845 | 844 | return .{ |
| 846 | .source = try ctx.buf.toOwnedSliceSentinel(0), | |
| 845 | .source = try ctx.buf.toOwnedSliceSentinel(gpa, 0), | |
| 847 | 846 | .tokens = ctx.tokens.toOwnedSlice(), |
| 848 | 847 | .nodes = ctx.nodes.toOwnedSlice(), |
| 849 | 848 | .extra_data = try ctx.extra_data.toOwnedSlice(gpa), |
| ... | ... | @@ -859,14 +858,14 @@ const TokenTag = std.zig.Token.Tag; |
| 859 | 858 | |
| 860 | 859 | const Context = struct { |
| 861 | 860 | gpa: Allocator, |
| 862 | buf: std.array_list.Managed(u8), | |
| 863 | nodes: std.zig.Ast.NodeList = .{}, | |
| 861 | buf: std.ArrayList(u8) = .empty, | |
| 862 | nodes: std.zig.Ast.NodeList = .empty, | |
| 864 | 863 | extra_data: std.ArrayListUnmanaged(u32) = .empty, |
| 865 | tokens: std.zig.Ast.TokenList = .{}, | |
| 864 | tokens: std.zig.Ast.TokenList = .empty, | |
| 866 | 865 | |
| 867 | 866 | fn addTokenFmt(c: *Context, tag: TokenTag, comptime format: []const u8, args: anytype) Allocator.Error!TokenIndex { |
| 868 | 867 | const start_index = c.buf.items.len; |
| 869 | try c.buf.print(format ++ " ", args); | |
| 868 | try c.buf.print(c.gpa, format ++ " ", args); | |
| 870 | 869 | |
| 871 | 870 | try c.tokens.append(c.gpa, .{ |
| 872 | 871 | .tag = tag, |
| ... | ... | @@ -925,8 +924,8 @@ fn renderNodeOpt(c: *Context, node: Node) Allocator.Error!?NodeIndex { |
| 925 | 924 | switch (node.tag()) { |
| 926 | 925 | .warning => { |
| 927 | 926 | const payload = node.castTag(.warning).?.data; |
| 928 | try c.buf.appendSlice(payload); | |
| 929 | try c.buf.append('\n'); | |
| 927 | try c.buf.appendSlice(c.gpa, payload); | |
| 928 | try c.buf.append(c.gpa, '\n'); | |
| 930 | 929 | return null; |
| 931 | 930 | }, |
| 932 | 931 | .discard => { |
| ... | ... | @@ -1687,12 +1686,12 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { |
| 1687 | 1686 | } |
| 1688 | 1687 | const l_brace = try c.addToken(.l_brace, "{"); |
| 1689 | 1688 | |
| 1690 | var stmts = std.array_list.Managed(NodeIndex).init(c.gpa); | |
| 1691 | defer stmts.deinit(); | |
| 1689 | var stmts: std.ArrayList(NodeIndex) = .empty; | |
| 1690 | defer stmts.deinit(c.gpa); | |
| 1692 | 1691 | for (payload.stmts) |stmt| { |
| 1693 | 1692 | const res = (try renderNodeOpt(c, stmt)) orelse continue; |
| 1694 | 1693 | try addSemicolonIfNeeded(c, stmt); |
| 1695 | try stmts.append(res); | |
| 1694 | try stmts.append(c.gpa, res); | |
| 1696 | 1695 | } |
| 1697 | 1696 | const span = try c.listToSpan(stmts.items); |
| 1698 | 1697 | _ = try c.addToken(.r_brace, "}"); |
| ... | ... | @@ -2830,8 +2829,8 @@ fn renderFunc(c: *Context, node: Node) !NodeIndex { |
| 2830 | 2829 | const fn_token = try c.addToken(.keyword_fn, "fn"); |
| 2831 | 2830 | if (payload.name) |some| _ = try c.addIdentifier(some); |
| 2832 | 2831 | |
| 2833 | const params = try renderParams(c, payload.params, payload.is_var_args); | |
| 2834 | defer params.deinit(); | |
| 2832 | var params = try renderParams(c, payload.params, payload.is_var_args); | |
| 2833 | defer params.deinit(c.gpa); | |
| 2835 | 2834 | var span: NodeSubRange = undefined; |
| 2836 | 2835 | if (params.items.len > 1) span = try c.listToSpan(params.items); |
| 2837 | 2836 | |
| ... | ... | @@ -2998,8 +2997,8 @@ fn renderMacroFunc(c: *Context, node: Node) !NodeIndex { |
| 2998 | 2997 | const fn_token = try c.addToken(.keyword_fn, "fn"); |
| 2999 | 2998 | _ = try c.addIdentifier(payload.name); |
| 3000 | 2999 | |
| 3001 | const params = try renderParams(c, payload.params, false); | |
| 3002 | defer params.deinit(); | |
| 3000 | var params = try renderParams(c, payload.params, false); | |
| 3001 | defer params.deinit(c.gpa); | |
| 3003 | 3002 | var span: NodeSubRange = undefined; |
| 3004 | 3003 | if (params.items.len > 1) span = try c.listToSpan(params.items); |
| 3005 | 3004 | |
| ... | ... | @@ -3035,10 +3034,11 @@ fn renderMacroFunc(c: *Context, node: Node) !NodeIndex { |
| 3035 | 3034 | }); |
| 3036 | 3035 | } |
| 3037 | 3036 | |
| 3038 | fn renderParams(c: *Context, params: []Payload.Param, is_var_args: bool) !std.array_list.Managed(NodeIndex) { | |
| 3037 | fn renderParams(c: *Context, params: []Payload.Param, is_var_args: bool) !std.ArrayList(NodeIndex) { | |
| 3039 | 3038 | _ = try c.addToken(.l_paren, "("); |
| 3040 | var rendered = try std.array_list.Managed(NodeIndex).initCapacity(c.gpa, @max(params.len, 1)); | |
| 3041 | errdefer rendered.deinit(); | |
| 3039 | var rendered: std.ArrayList(NodeIndex) = .empty; | |
| 3040 | errdefer rendered.deinit(c.gpa); | |
| 3041 | try rendered.ensureUnusedCapacity(c.gpa, @max(params.len, 1)); | |
| 3042 | 3042 | |
| 3043 | 3043 | for (params, 0..) |param, i| { |
| 3044 | 3044 | if (i != 0) _ = try c.addToken(.comma, ","); |
lib/compiler/translate-c/main.zig+6-4| ... | ... | @@ -110,7 +110,7 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8) !void { |
| 110 | 110 | defer macro_buf.deinit(gpa); |
| 111 | 111 | |
| 112 | 112 | var discard_buf: [256]u8 = undefined; |
| 113 | var discarding: std.io.Writer.Discarding = .init(&discard_buf); | |
| 113 | var discarding: std.Io.Writer.Discarding = .init(&discard_buf); | |
| 114 | 114 | assert(!try d.parseArgs(&discarding.writer, &macro_buf, aro_args)); |
| 115 | 115 | if (macro_buf.items.len > std.math.maxInt(u32)) { |
| 116 | 116 | return d.fatal("user provided macro source exceeded max size", .{}); |
| ... | ... | @@ -206,9 +206,11 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8) !void { |
| 206 | 206 | out_file_path = path; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | var out_writer = out_file.writer(&.{}); | |
| 210 | out_writer.interface.writeAll(rendered_zig) catch | |
| 211 | return d.fatal("failed to write result to '{s}': {s}", .{ out_file_path, aro.Driver.errorDescription(out_writer.err.?) }); | |
| 209 | var out_writer = out_file.writer(&out_buf); | |
| 210 | out_writer.interface.writeAll(rendered_zig) catch {}; | |
| 211 | out_writer.interface.flush() catch {}; | |
| 212 | if (out_writer.err) |write_err| | |
| 213 | return d.fatal("failed to write result to '{s}': {s}", .{ out_file_path, aro.Driver.errorDescription(write_err) }); | |
| 212 | 214 | |
| 213 | 215 | if (fast_exit) process.exit(0); |
| 214 | 216 | } |