authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-21 15:05:28-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-09-24 20:01:19-07:00
log8cba6b1df813279735bf831018489a9e03788413
tree4e1e9d16bc6216dbfbd65b2d393f308157b93635
parent01132e0cf87a4e9ee5639b4b6b4b39606feab6a9

aro: update

This is f5fb720a5399ee98e45f36337b2f68a4d23a783c plus ehaas's nonnull attribute pull request currently at 4b26cb3ac610a0a070fc43e43da8b4cdf0e9101b with zig patches intact.

31 files changed, 1483 insertions(+), 1240 deletions(-)

lib/compiler/aro/aro/Attribute.zig+59-44
...@@ -345,6 +345,7 @@ fn diagnoseField(...@@ -345,6 +345,7 @@ fn diagnoseField(
345345
346pub fn diagnose(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Parser.Result, arg_start: TokenIndex, node: Tree.Node, p: *Parser) !bool {346pub fn diagnose(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Parser.Result, arg_start: TokenIndex, node: Tree.Node, p: *Parser) !bool {
347 switch (attr) {347 switch (attr) {
348 .nonnull => return false,
348 inline else => |tag| {349 inline else => |tag| {
349 const decl = @typeInfo(attributes).@"struct".decls[@intFromEnum(tag)];350 const decl = @typeInfo(attributes).@"struct".decls[@intFromEnum(tag)];
350 const max_arg_count = comptime maxArgCount(tag);351 const max_arg_count = comptime maxArgCount(tag);
...@@ -532,10 +533,7 @@ const attributes = struct {...@@ -532,10 +533,7 @@ const attributes = struct {
532 pub const @"noinline" = struct {};533 pub const @"noinline" = struct {};
533 pub const noipa = struct {};534 pub const noipa = struct {};
534 // TODO: arbitrary number of arguments535 // TODO: arbitrary number of arguments
535 // const nonnull = struct {536 pub const nonnull = struct {};
536 // // arg_index: []const u32,
537 // };
538 // };
539 pub const nonstring = struct {};537 pub const nonstring = struct {};
540 pub const noplt = struct {};538 pub const noplt = struct {};
541 pub const @"noreturn" = struct {};539 pub const @"noreturn" = struct {};
...@@ -802,8 +800,16 @@ fn ignoredAttrErr(p: *Parser, tok: TokenIndex, attr: Attribute.Tag, context: []c...@@ -802,8 +800,16 @@ fn ignoredAttrErr(p: *Parser, tok: TokenIndex, attr: Attribute.Tag, context: []c
802 try p.errStr(.ignored_attribute, tok, str);800 try p.errStr(.ignored_attribute, tok, str);
803}801}
804802
805pub const applyParameterAttributes = applyVariableAttributes;803pub fn applyParameterAttributes(p: *Parser, qt: QualType, attr_buf_start: usize, diagnostic: ?Parser.Diagnostic) !QualType {
804 return applyVariableOrParameterAttributes(p, qt, attr_buf_start, diagnostic, .parameter);
805}
806
806pub fn applyVariableAttributes(p: *Parser, qt: QualType, attr_buf_start: usize, diagnostic: ?Parser.Diagnostic) !QualType {807pub fn applyVariableAttributes(p: *Parser, qt: QualType, attr_buf_start: usize, diagnostic: ?Parser.Diagnostic) !QualType {
808 return applyVariableOrParameterAttributes(p, qt, attr_buf_start, diagnostic, .variable);
809}
810
811fn applyVariableOrParameterAttributes(p: *Parser, qt: QualType, attr_buf_start: usize, diagnostic: ?Parser.Diagnostic, context: enum { parameter, variable }) !QualType {
812 const gpa = p.comp.gpa;
807 const attrs = p.attr_buf.items(.attr)[attr_buf_start..];813 const attrs = p.attr_buf.items(.attr)[attr_buf_start..];
808 const toks = p.attr_buf.items(.tok)[attr_buf_start..];814 const toks = p.attr_buf.items(.tok)[attr_buf_start..];
809 p.attr_application_buf.items.len = 0;815 p.attr_application_buf.items.len = 0;
...@@ -814,27 +820,33 @@ pub fn applyVariableAttributes(p: *Parser, qt: QualType, attr_buf_start: usize,...@@ -814,27 +820,33 @@ pub fn applyVariableAttributes(p: *Parser, qt: QualType, attr_buf_start: usize,
814 // zig fmt: off820 // zig fmt: off
815 .alias, .may_alias, .deprecated, .unavailable, .unused, .warn_if_not_aligned, .weak, .used,821 .alias, .may_alias, .deprecated, .unavailable, .unused, .warn_if_not_aligned, .weak, .used,
816 .noinit, .retain, .persistent, .section, .mode, .asm_label, .nullability, .unaligned,822 .noinit, .retain, .persistent, .section, .mode, .asm_label, .nullability, .unaligned,
817 => try p.attr_application_buf.append(p.gpa, attr),823 => try p.attr_application_buf.append(gpa, attr),
818 // zig fmt: on824 // zig fmt: on
819 .common => if (nocommon) {825 .common => if (nocommon) {
820 try p.err(tok, .ignore_common, .{});826 try p.err(tok, .ignore_common, .{});
821 } else {827 } else {
822 try p.attr_application_buf.append(p.gpa, attr);828 try p.attr_application_buf.append(gpa, attr);
823 common = true;829 common = true;
824 },830 },
825 .nocommon => if (common) {831 .nocommon => if (common) {
826 try p.err(tok, .ignore_nocommon, .{});832 try p.err(tok, .ignore_nocommon, .{});
827 } else {833 } else {
828 try p.attr_application_buf.append(p.gpa, attr);834 try p.attr_application_buf.append(gpa, attr);
829 nocommon = true;835 nocommon = true;
830 },836 },
831 .vector_size => try attr.applyVectorSize(p, tok, &base_qt),837 .vector_size => try attr.applyVectorSize(p, tok, &base_qt),
832 .aligned => try attr.applyAligned(p, base_qt, diagnostic),838 .aligned => try attr.applyAligned(p, base_qt, diagnostic),
839 .nonnull => {
840 switch (context) {
841 .parameter => try p.err(tok, .attribute_todo, .{ "nonnull", "parameters" }),
842 .variable => try p.err(tok, .nonnull_not_applicable, .{}),
843 }
844 },
833 .nonstring => {845 .nonstring => {
834 if (base_qt.get(p.comp, .array)) |array_ty| {846 if (base_qt.get(p.comp, .array)) |array_ty| {
835 if (array_ty.elem.get(p.comp, .int)) |int_ty| switch (int_ty) {847 if (array_ty.elem.get(p.comp, .int)) |int_ty| switch (int_ty) {
836 .char, .uchar, .schar => {848 .char, .uchar, .schar => {
837 try p.attr_application_buf.append(p.gpa, attr);849 try p.attr_application_buf.append(gpa, attr);
838 continue;850 continue;
839 },851 },
840 else => {},852 else => {},
...@@ -845,12 +857,12 @@ pub fn applyVariableAttributes(p: *Parser, qt: QualType, attr_buf_start: usize,...@@ -845,12 +857,12 @@ pub fn applyVariableAttributes(p: *Parser, qt: QualType, attr_buf_start: usize,
845 .uninitialized => if (p.func.qt == null) {857 .uninitialized => if (p.func.qt == null) {
846 try p.err(tok, .local_variable_attribute, .{"uninitialized"});858 try p.err(tok, .local_variable_attribute, .{"uninitialized"});
847 } else {859 } else {
848 try p.attr_application_buf.append(p.gpa, attr);860 try p.attr_application_buf.append(gpa, attr);
849 },861 },
850 .cleanup => if (p.func.qt == null) {862 .cleanup => if (p.func.qt == null) {
851 try p.err(tok, .local_variable_attribute, .{"cleanup"});863 try p.err(tok, .local_variable_attribute, .{"cleanup"});
852 } else {864 } else {
853 try p.attr_application_buf.append(p.gpa, attr);865 try p.attr_application_buf.append(gpa, attr);
854 },866 },
855 .calling_convention => try applyCallingConvention(attr, p, tok, base_qt),867 .calling_convention => try applyCallingConvention(attr, p, tok, base_qt),
856 .alloc_size,868 .alloc_size,
...@@ -873,7 +885,7 @@ pub fn applyFieldAttributes(p: *Parser, field_qt: *QualType, attr_buf_start: usi...@@ -873,7 +885,7 @@ pub fn applyFieldAttributes(p: *Parser, field_qt: *QualType, attr_buf_start: usi
873 // zig fmt: off885 // zig fmt: off
874 .@"packed", .may_alias, .deprecated, .unavailable, .unused, .warn_if_not_aligned,886 .@"packed", .may_alias, .deprecated, .unavailable, .unused, .warn_if_not_aligned,
875 .mode, .warn_unused_result, .nodiscard, .nullability, .unaligned,887 .mode, .warn_unused_result, .nodiscard, .nullability, .unaligned,
876 => try p.attr_application_buf.append(p.gpa, attr),888 => try p.attr_application_buf.append(p.comp.gpa, attr),
877 // zig fmt: on889 // zig fmt: on
878 .vector_size => try attr.applyVectorSize(p, tok, field_qt),890 .vector_size => try attr.applyVectorSize(p, tok, field_qt),
879 .aligned => try attr.applyAligned(p, field_qt.*, null),891 .aligned => try attr.applyAligned(p, field_qt.*, null),
...@@ -884,6 +896,7 @@ pub fn applyFieldAttributes(p: *Parser, field_qt: *QualType, attr_buf_start: usi...@@ -884,6 +896,7 @@ pub fn applyFieldAttributes(p: *Parser, field_qt: *QualType, attr_buf_start: usi
884}896}
885897
886pub fn applyTypeAttributes(p: *Parser, qt: QualType, attr_buf_start: usize, diagnostic: ?Parser.Diagnostic) !QualType {898pub fn applyTypeAttributes(p: *Parser, qt: QualType, attr_buf_start: usize, diagnostic: ?Parser.Diagnostic) !QualType {
899 const gpa = p.comp.gpa;
887 const attrs = p.attr_buf.items(.attr)[attr_buf_start..];900 const attrs = p.attr_buf.items(.attr)[attr_buf_start..];
888 const toks = p.attr_buf.items(.tok)[attr_buf_start..];901 const toks = p.attr_buf.items(.tok)[attr_buf_start..];
889 p.attr_application_buf.items.len = 0;902 p.attr_application_buf.items.len = 0;
...@@ -891,13 +904,13 @@ pub fn applyTypeAttributes(p: *Parser, qt: QualType, attr_buf_start: usize, diag...@@ -891,13 +904,13 @@ pub fn applyTypeAttributes(p: *Parser, qt: QualType, attr_buf_start: usize, diag
891 for (attrs, toks) |attr, tok| switch (attr.tag) {904 for (attrs, toks) |attr, tok| switch (attr.tag) {
892 // zig fmt: off905 // zig fmt: off
893 .@"packed", .may_alias, .deprecated, .unavailable, .unused, .warn_if_not_aligned, .mode, .nullability, .unaligned,906 .@"packed", .may_alias, .deprecated, .unavailable, .unused, .warn_if_not_aligned, .mode, .nullability, .unaligned,
894 => try p.attr_application_buf.append(p.gpa, attr),907 => try p.attr_application_buf.append(gpa, attr),
895 // zig fmt: on908 // zig fmt: on
896 .transparent_union => try attr.applyTransparentUnion(p, tok, base_qt),909 .transparent_union => try attr.applyTransparentUnion(p, tok, base_qt),
897 .vector_size => try attr.applyVectorSize(p, tok, &base_qt),910 .vector_size => try attr.applyVectorSize(p, tok, &base_qt),
898 .aligned => try attr.applyAligned(p, base_qt, diagnostic),911 .aligned => try attr.applyAligned(p, base_qt, diagnostic),
899 .designated_init => if (base_qt.is(p.comp, .@"struct")) {912 .designated_init => if (base_qt.is(p.comp, .@"struct")) {
900 try p.attr_application_buf.append(p.gpa, attr);913 try p.attr_application_buf.append(gpa, attr);
901 } else {914 } else {
902 try p.err(tok, .designated_init_invalid, .{});915 try p.err(tok, .designated_init_invalid, .{});
903 },916 },
...@@ -913,6 +926,7 @@ pub fn applyTypeAttributes(p: *Parser, qt: QualType, attr_buf_start: usize, diag...@@ -913,6 +926,7 @@ pub fn applyTypeAttributes(p: *Parser, qt: QualType, attr_buf_start: usize, diag
913}926}
914927
915pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize) !QualType {928pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize) !QualType {
929 const gpa = p.comp.gpa;
916 const attrs = p.attr_buf.items(.attr)[attr_buf_start..];930 const attrs = p.attr_buf.items(.attr)[attr_buf_start..];
917 const toks = p.attr_buf.items(.tok)[attr_buf_start..];931 const toks = p.attr_buf.items(.tok)[attr_buf_start..];
918 p.attr_application_buf.items.len = 0;932 p.attr_application_buf.items.len = 0;
...@@ -927,37 +941,37 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)...@@ -927,37 +941,37 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)
927 .@"const", .warn_unused_result, .section, .returns_nonnull, .returns_twice, .@"error",941 .@"const", .warn_unused_result, .section, .returns_nonnull, .returns_twice, .@"error",
928 .externally_visible, .retain, .flatten, .gnu_inline, .alias, .asm_label, .nodiscard,942 .externally_visible, .retain, .flatten, .gnu_inline, .alias, .asm_label, .nodiscard,
929 .reproducible, .unsequenced, .nothrow, .nullability, .unaligned,943 .reproducible, .unsequenced, .nothrow, .nullability, .unaligned,
930 => try p.attr_application_buf.append(p.gpa, attr),944 => try p.attr_application_buf.append(gpa, attr),
931 // zig fmt: on945 // zig fmt: on
932 .hot => if (cold) {946 .hot => if (cold) {
933 try p.err(tok, .ignore_hot, .{});947 try p.err(tok, .ignore_hot, .{});
934 } else {948 } else {
935 try p.attr_application_buf.append(p.gpa, attr);949 try p.attr_application_buf.append(gpa, attr);
936 hot = true;950 hot = true;
937 },951 },
938 .cold => if (hot) {952 .cold => if (hot) {
939 try p.err(tok, .ignore_cold, .{});953 try p.err(tok, .ignore_cold, .{});
940 } else {954 } else {
941 try p.attr_application_buf.append(p.gpa, attr);955 try p.attr_application_buf.append(gpa, attr);
942 cold = true;956 cold = true;
943 },957 },
944 .always_inline => if (@"noinline") {958 .always_inline => if (@"noinline") {
945 try p.err(tok, .ignore_always_inline, .{});959 try p.err(tok, .ignore_always_inline, .{});
946 } else {960 } else {
947 try p.attr_application_buf.append(p.gpa, attr);961 try p.attr_application_buf.append(gpa, attr);
948 always_inline = true;962 always_inline = true;
949 },963 },
950 .@"noinline" => if (always_inline) {964 .@"noinline" => if (always_inline) {
951 try p.err(tok, .ignore_noinline, .{});965 try p.err(tok, .ignore_noinline, .{});
952 } else {966 } else {
953 try p.attr_application_buf.append(p.gpa, attr);967 try p.attr_application_buf.append(gpa, attr);
954 @"noinline" = true;968 @"noinline" = true;
955 },969 },
956 .aligned => try attr.applyAligned(p, base_qt, null),970 .aligned => try attr.applyAligned(p, base_qt, null),
957 .format => try attr.applyFormat(p, base_qt),971 .format => try attr.applyFormat(p, base_qt),
958 .calling_convention => try applyCallingConvention(attr, p, tok, base_qt),972 .calling_convention => try applyCallingConvention(attr, p, tok, base_qt),
959 .fastcall => if (p.comp.target.cpu.arch == .x86) {973 .fastcall => if (p.comp.target.cpu.arch == .x86) {
960 try p.attr_application_buf.append(p.gpa, .{974 try p.attr_application_buf.append(gpa, .{
961 .tag = .calling_convention,975 .tag = .calling_convention,
962 .args = .{ .calling_convention = .{ .cc = .fastcall } },976 .args = .{ .calling_convention = .{ .cc = .fastcall } },
963 .syntax = attr.syntax,977 .syntax = attr.syntax,
...@@ -966,7 +980,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)...@@ -966,7 +980,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)
966 try p.err(tok, .callconv_not_supported, .{"fastcall"});980 try p.err(tok, .callconv_not_supported, .{"fastcall"});
967 },981 },
968 .stdcall => if (p.comp.target.cpu.arch == .x86) {982 .stdcall => if (p.comp.target.cpu.arch == .x86) {
969 try p.attr_application_buf.append(p.gpa, .{983 try p.attr_application_buf.append(gpa, .{
970 .tag = .calling_convention,984 .tag = .calling_convention,
971 .args = .{ .calling_convention = .{ .cc = .stdcall } },985 .args = .{ .calling_convention = .{ .cc = .stdcall } },
972 .syntax = attr.syntax,986 .syntax = attr.syntax,
...@@ -975,7 +989,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)...@@ -975,7 +989,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)
975 try p.err(tok, .callconv_not_supported, .{"stdcall"});989 try p.err(tok, .callconv_not_supported, .{"stdcall"});
976 },990 },
977 .thiscall => if (p.comp.target.cpu.arch == .x86) {991 .thiscall => if (p.comp.target.cpu.arch == .x86) {
978 try p.attr_application_buf.append(p.gpa, .{992 try p.attr_application_buf.append(gpa, .{
979 .tag = .calling_convention,993 .tag = .calling_convention,
980 .args = .{ .calling_convention = .{ .cc = .thiscall } },994 .args = .{ .calling_convention = .{ .cc = .thiscall } },
981 .syntax = attr.syntax,995 .syntax = attr.syntax,
...@@ -984,7 +998,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)...@@ -984,7 +998,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)
984 try p.err(tok, .callconv_not_supported, .{"thiscall"});998 try p.err(tok, .callconv_not_supported, .{"thiscall"});
985 },999 },
986 .vectorcall => if (p.comp.target.cpu.arch == .x86 or p.comp.target.cpu.arch.isAARCH64()) {1000 .vectorcall => if (p.comp.target.cpu.arch == .x86 or p.comp.target.cpu.arch.isAARCH64()) {
987 try p.attr_application_buf.append(p.gpa, .{1001 try p.attr_application_buf.append(gpa, .{
988 .tag = .calling_convention,1002 .tag = .calling_convention,
989 .args = .{ .calling_convention = .{ .cc = .vectorcall } },1003 .args = .{ .calling_convention = .{ .cc = .vectorcall } },
990 .syntax = attr.syntax,1004 .syntax = attr.syntax,
...@@ -994,7 +1008,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)...@@ -994,7 +1008,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)
994 },1008 },
995 .cdecl => {},1009 .cdecl => {},
996 .pcs => if (p.comp.target.cpu.arch.isArm()) {1010 .pcs => if (p.comp.target.cpu.arch.isArm()) {
997 try p.attr_application_buf.append(p.gpa, .{1011 try p.attr_application_buf.append(gpa, .{
998 .tag = .calling_convention,1012 .tag = .calling_convention,
999 .args = .{ .calling_convention = .{ .cc = switch (attr.args.pcs.kind) {1013 .args = .{ .calling_convention = .{ .cc = switch (attr.args.pcs.kind) {
1000 .aapcs => .arm_aapcs,1014 .aapcs => .arm_aapcs,
...@@ -1006,7 +1020,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)...@@ -1006,7 +1020,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)
1006 try p.err(tok, .callconv_not_supported, .{"pcs"});1020 try p.err(tok, .callconv_not_supported, .{"pcs"});
1007 },1021 },
1008 .riscv_vector_cc => if (p.comp.target.cpu.arch.isRISCV()) {1022 .riscv_vector_cc => if (p.comp.target.cpu.arch.isRISCV()) {
1009 try p.attr_application_buf.append(p.gpa, .{1023 try p.attr_application_buf.append(gpa, .{
1010 .tag = .calling_convention,1024 .tag = .calling_convention,
1011 .args = .{ .calling_convention = .{ .cc = .riscv_vector } },1025 .args = .{ .calling_convention = .{ .cc = .riscv_vector } },
1012 .syntax = attr.syntax,1026 .syntax = attr.syntax,
...@@ -1015,7 +1029,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)...@@ -1015,7 +1029,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)
1015 try p.err(tok, .callconv_not_supported, .{"pcs"});1029 try p.err(tok, .callconv_not_supported, .{"pcs"});
1016 },1030 },
1017 .aarch64_sve_pcs => if (p.comp.target.cpu.arch.isAARCH64()) {1031 .aarch64_sve_pcs => if (p.comp.target.cpu.arch.isAARCH64()) {
1018 try p.attr_application_buf.append(p.gpa, .{1032 try p.attr_application_buf.append(gpa, .{
1019 .tag = .calling_convention,1033 .tag = .calling_convention,
1020 .args = .{ .calling_convention = .{ .cc = .aarch64_sve_pcs } },1034 .args = .{ .calling_convention = .{ .cc = .aarch64_sve_pcs } },
1021 .syntax = attr.syntax,1035 .syntax = attr.syntax,
...@@ -1024,7 +1038,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)...@@ -1024,7 +1038,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)
1024 try p.err(tok, .callconv_not_supported, .{"pcs"});1038 try p.err(tok, .callconv_not_supported, .{"pcs"});
1025 },1039 },
1026 .aarch64_vector_pcs => if (p.comp.target.cpu.arch.isAARCH64()) {1040 .aarch64_vector_pcs => if (p.comp.target.cpu.arch.isAARCH64()) {
1027 try p.attr_application_buf.append(p.gpa, .{1041 try p.attr_application_buf.append(gpa, .{
1028 .tag = .calling_convention,1042 .tag = .calling_convention,
1029 .args = .{ .calling_convention = .{ .cc = .aarch64_vector_pcs } },1043 .args = .{ .calling_convention = .{ .cc = .aarch64_vector_pcs } },
1030 .syntax = attr.syntax,1044 .syntax = attr.syntax,
...@@ -1033,14 +1047,14 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)...@@ -1033,14 +1047,14 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)
1033 try p.err(tok, .callconv_not_supported, .{"pcs"});1047 try p.err(tok, .callconv_not_supported, .{"pcs"});
1034 },1048 },
1035 .sysv_abi => if (p.comp.target.cpu.arch == .x86_64 and p.comp.target.os.tag == .windows) {1049 .sysv_abi => if (p.comp.target.cpu.arch == .x86_64 and p.comp.target.os.tag == .windows) {
1036 try p.attr_application_buf.append(p.gpa, .{1050 try p.attr_application_buf.append(gpa, .{
1037 .tag = .calling_convention,1051 .tag = .calling_convention,
1038 .args = .{ .calling_convention = .{ .cc = .x86_64_sysv } },1052 .args = .{ .calling_convention = .{ .cc = .x86_64_sysv } },
1039 .syntax = attr.syntax,1053 .syntax = attr.syntax,
1040 });1054 });
1041 },1055 },
1042 .ms_abi => if (p.comp.target.cpu.arch == .x86_64 and p.comp.target.os.tag != .windows) {1056 .ms_abi => if (p.comp.target.cpu.arch == .x86_64 and p.comp.target.os.tag != .windows) {
1043 try p.attr_application_buf.append(p.gpa, .{1057 try p.attr_application_buf.append(gpa, .{
1044 .tag = .calling_convention,1058 .tag = .calling_convention,
1045 .args = .{ .calling_convention = .{ .cc = .x86_64_win } },1059 .args = .{ .calling_convention = .{ .cc = .x86_64_win } },
1046 .syntax = attr.syntax,1060 .syntax = attr.syntax,
...@@ -1048,7 +1062,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)...@@ -1048,7 +1062,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)
1048 },1062 },
1049 .malloc => {1063 .malloc => {
1050 if (base_qt.get(p.comp, .func).?.return_type.isPointer(p.comp)) {1064 if (base_qt.get(p.comp, .func).?.return_type.isPointer(p.comp)) {
1051 try p.attr_application_buf.append(p.gpa, attr);1065 try p.attr_application_buf.append(gpa, attr);
1052 } else {1066 } else {
1053 try ignoredAttrErr(p, tok, attr.tag, "functions that do not return pointers");1067 try ignoredAttrErr(p, tok, attr.tag, "functions that do not return pointers");
1054 }1068 }
...@@ -1065,7 +1079,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)...@@ -1065,7 +1079,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)
1065 if (!arg_sk.isInt() or !arg_sk.isReal()) {1079 if (!arg_sk.isInt() or !arg_sk.isReal()) {
1066 try p.err(tok, .alloc_align_required_int_param, .{});1080 try p.err(tok, .alloc_align_required_int_param, .{});
1067 } else {1081 } else {
1068 try p.attr_application_buf.append(p.gpa, attr);1082 try p.attr_application_buf.append(gpa, attr);
1069 }1083 }
1070 }1084 }
1071 } else {1085 } else {
...@@ -1098,7 +1112,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)...@@ -1098,7 +1112,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)
1098 .no_stack_protector,1112 .no_stack_protector,
1099 .noclone,1113 .noclone,
1100 .noipa,1114 .noipa,
1101 // .nonnull,1115 .nonnull,
1102 .noplt,1116 .noplt,
1103 // .optimize,1117 // .optimize,
1104 .patchable_function_entry,1118 .patchable_function_entry,
...@@ -1118,23 +1132,24 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)...@@ -1118,23 +1132,24 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)
1118}1132}
11191133
1120pub fn applyLabelAttributes(p: *Parser, attr_buf_start: usize) !QualType {1134pub fn applyLabelAttributes(p: *Parser, attr_buf_start: usize) !QualType {
1135 const gpa = p.comp.gpa;
1121 const attrs = p.attr_buf.items(.attr)[attr_buf_start..];1136 const attrs = p.attr_buf.items(.attr)[attr_buf_start..];
1122 const toks = p.attr_buf.items(.tok)[attr_buf_start..];1137 const toks = p.attr_buf.items(.tok)[attr_buf_start..];
1123 p.attr_application_buf.items.len = 0;1138 p.attr_application_buf.items.len = 0;
1124 var hot = false;1139 var hot = false;
1125 var cold = false;1140 var cold = false;
1126 for (attrs, toks) |attr, tok| switch (attr.tag) {1141 for (attrs, toks) |attr, tok| switch (attr.tag) {
1127 .unused => try p.attr_application_buf.append(p.gpa, attr),1142 .unused => try p.attr_application_buf.append(gpa, attr),
1128 .hot => if (cold) {1143 .hot => if (cold) {
1129 try p.err(tok, .ignore_hot, .{});1144 try p.err(tok, .ignore_hot, .{});
1130 } else {1145 } else {
1131 try p.attr_application_buf.append(p.gpa, attr);1146 try p.attr_application_buf.append(gpa, attr);
1132 hot = true;1147 hot = true;
1133 },1148 },
1134 .cold => if (hot) {1149 .cold => if (hot) {
1135 try p.err(tok, .ignore_cold, .{});1150 try p.err(tok, .ignore_cold, .{});
1136 } else {1151 } else {
1137 try p.attr_application_buf.append(p.gpa, attr);1152 try p.attr_application_buf.append(gpa, attr);
1138 cold = true;1153 cold = true;
1139 },1154 },
1140 else => try ignoredAttrErr(p, tok, attr.tag, "labels"),1155 else => try ignoredAttrErr(p, tok, attr.tag, "labels"),
...@@ -1151,7 +1166,7 @@ pub fn applyStatementAttributes(p: *Parser, expr_start: TokenIndex, attr_buf_sta...@@ -1151,7 +1166,7 @@ pub fn applyStatementAttributes(p: *Parser, expr_start: TokenIndex, attr_buf_sta
1151 for (p.tok_ids[p.tok_i..]) |tok_id| {1166 for (p.tok_ids[p.tok_i..]) |tok_id| {
1152 switch (tok_id) {1167 switch (tok_id) {
1153 .keyword_case, .keyword_default, .eof => {1168 .keyword_case, .keyword_default, .eof => {
1154 try p.attr_application_buf.append(p.gpa, attr);1169 try p.attr_application_buf.append(p.comp.gpa, attr);
1155 break;1170 break;
1156 },1171 },
1157 .r_brace => {},1172 .r_brace => {},
...@@ -1172,7 +1187,7 @@ pub fn applyEnumeratorAttributes(p: *Parser, qt: QualType, attr_buf_start: usize...@@ -1172,7 +1187,7 @@ pub fn applyEnumeratorAttributes(p: *Parser, qt: QualType, attr_buf_start: usize
1172 const toks = p.attr_buf.items(.tok)[attr_buf_start..];1187 const toks = p.attr_buf.items(.tok)[attr_buf_start..];
1173 p.attr_application_buf.items.len = 0;1188 p.attr_application_buf.items.len = 0;
1174 for (attrs, toks) |attr, tok| switch (attr.tag) {1189 for (attrs, toks) |attr, tok| switch (attr.tag) {
1175 .deprecated, .unavailable => try p.attr_application_buf.append(p.gpa, attr),1190 .deprecated, .unavailable => try p.attr_application_buf.append(p.comp.gpa, attr),
1176 else => try ignoredAttrErr(p, tok, attr.tag, "enums"),1191 else => try ignoredAttrErr(p, tok, attr.tag, "enums"),
1177 };1192 };
1178 return applySelected(qt, p);1193 return applySelected(qt, p);
...@@ -1193,7 +1208,7 @@ fn applyAligned(attr: Attribute, p: *Parser, qt: QualType, diagnostic: ?Parser.D...@@ -1193,7 +1208,7 @@ fn applyAligned(attr: Attribute, p: *Parser, qt: QualType, diagnostic: ?Parser.D
1193 try p.err(align_tok, .minimum_alignment, .{default_align});1208 try p.err(align_tok, .minimum_alignment, .{default_align});
1194 }1209 }
1195 }1210 }
1196 try p.attr_application_buf.append(p.gpa, attr);1211 try p.attr_application_buf.append(p.comp.gpa, attr);
1197}1212}
11981213
1199fn applyTransparentUnion(attr: Attribute, p: *Parser, tok: TokenIndex, qt: QualType) !void {1214fn applyTransparentUnion(attr: Attribute, p: *Parser, tok: TokenIndex, qt: QualType) !void {
...@@ -1214,7 +1229,7 @@ fn applyTransparentUnion(attr: Attribute, p: *Parser, tok: TokenIndex, qt: QualT...@@ -1214,7 +1229,7 @@ fn applyTransparentUnion(attr: Attribute, p: *Parser, tok: TokenIndex, qt: QualT
1214 return p.err(union_ty.fields[0].name_tok, .transparent_union_size_note, .{first_field_size});1229 return p.err(union_ty.fields[0].name_tok, .transparent_union_size_note, .{first_field_size});
1215 }1230 }
12161231
1217 try p.attr_application_buf.append(p.gpa, attr);1232 try p.attr_application_buf.append(p.comp.gpa, attr);
1218}1233}
12191234
1220fn applyVectorSize(attr: Attribute, p: *Parser, tok: TokenIndex, qt: *QualType) !void {1235fn applyVectorSize(attr: Attribute, p: *Parser, tok: TokenIndex, qt: *QualType) !void {
...@@ -1245,7 +1260,7 @@ fn applyVectorSize(attr: Attribute, p: *Parser, tok: TokenIndex, qt: *QualType)...@@ -1245,7 +1260,7 @@ fn applyVectorSize(attr: Attribute, p: *Parser, tok: TokenIndex, qt: *QualType)
1245 return p.err(tok, .vec_size_not_multiple, .{});1260 return p.err(tok, .vec_size_not_multiple, .{});
1246 }1261 }
12471262
1248 qt.* = try p.comp.type_store.put(p.gpa, .{ .vector = .{1263 qt.* = try p.comp.type_store.put(p.comp.gpa, .{ .vector = .{
1249 .elem = qt.*,1264 .elem = qt.*,
1250 .len = @intCast(vec_bytes / elem_size),1265 .len = @intCast(vec_bytes / elem_size),
1251 } });1266 } });
...@@ -1254,7 +1269,7 @@ fn applyVectorSize(attr: Attribute, p: *Parser, tok: TokenIndex, qt: *QualType)...@@ -1254,7 +1269,7 @@ fn applyVectorSize(attr: Attribute, p: *Parser, tok: TokenIndex, qt: *QualType)
1254fn applyFormat(attr: Attribute, p: *Parser, qt: QualType) !void {1269fn applyFormat(attr: Attribute, p: *Parser, qt: QualType) !void {
1255 // TODO validate1270 // TODO validate
1256 _ = qt;1271 _ = qt;
1257 try p.attr_application_buf.append(p.gpa, attr);1272 try p.attr_application_buf.append(p.comp.gpa, attr);
1258}1273}
12591274
1260fn applyCallingConvention(attr: Attribute, p: *Parser, tok: TokenIndex, qt: QualType) !void {1275fn applyCallingConvention(attr: Attribute, p: *Parser, tok: TokenIndex, qt: QualType) !void {
...@@ -1264,11 +1279,11 @@ fn applyCallingConvention(attr: Attribute, p: *Parser, tok: TokenIndex, qt: Qual...@@ -1264,11 +1279,11 @@ fn applyCallingConvention(attr: Attribute, p: *Parser, tok: TokenIndex, qt: Qual
1264 switch (attr.args.calling_convention.cc) {1279 switch (attr.args.calling_convention.cc) {
1265 .c => {},1280 .c => {},
1266 .stdcall, .thiscall, .fastcall, .regcall => switch (p.comp.target.cpu.arch) {1281 .stdcall, .thiscall, .fastcall, .regcall => switch (p.comp.target.cpu.arch) {
1267 .x86 => try p.attr_application_buf.append(p.gpa, attr),1282 .x86 => try p.attr_application_buf.append(p.comp.gpa, attr),
1268 else => try p.err(tok, .callconv_not_supported, .{p.tok_ids[tok].symbol()}),1283 else => try p.err(tok, .callconv_not_supported, .{p.tok_ids[tok].symbol()}),
1269 },1284 },
1270 .vectorcall => switch (p.comp.target.cpu.arch) {1285 .vectorcall => switch (p.comp.target.cpu.arch) {
1271 .x86, .aarch64, .aarch64_be => try p.attr_application_buf.append(p.gpa, attr),1286 .x86, .aarch64, .aarch64_be => try p.attr_application_buf.append(p.comp.gpa, attr),
1272 else => try p.err(tok, .callconv_not_supported, .{p.tok_ids[tok].symbol()}),1287 else => try p.err(tok, .callconv_not_supported, .{p.tok_ids[tok].symbol()}),
1273 },1288 },
1274 .riscv_vector,1289 .riscv_vector,
...@@ -1285,7 +1300,7 @@ fn applyCallingConvention(attr: Attribute, p: *Parser, tok: TokenIndex, qt: Qual...@@ -1285,7 +1300,7 @@ fn applyCallingConvention(attr: Attribute, p: *Parser, tok: TokenIndex, qt: Qual
1285fn applySelected(qt: QualType, p: *Parser) !QualType {1300fn applySelected(qt: QualType, p: *Parser) !QualType {
1286 if (p.attr_application_buf.items.len == 0) return qt;1301 if (p.attr_application_buf.items.len == 0) return qt;
1287 if (qt.isInvalid()) return qt;1302 if (qt.isInvalid()) return qt;
1288 return (try p.comp.type_store.put(p.gpa, .{ .attributed = .{1303 return (try p.comp.type_store.put(p.comp.gpa, .{ .attributed = .{
1289 .base = qt,1304 .base = qt,
1290 .attributes = p.attr_application_buf.items,1305 .attributes = p.attr_application_buf.items,
1291 } })).withQualifiers(qt);1306 } })).withQualifiers(qt);
lib/compiler/aro/aro/Attribute/names.zig+498-495
...@@ -78,6 +78,7 @@ pub const Tag = enum(u16) { aarch64_sve_pcs,...@@ -78,6 +78,7 @@ pub const Tag = enum(u16) { aarch64_sve_pcs,
78 noinit,78 noinit,
79 @"noinline",79 @"noinline",
80 noipa,80 noipa,
81 nonnull,
81 nonstring,82 nonstring,
82 noplt,83 noplt,
83 @"noreturn",84 @"noreturn",
...@@ -184,7 +185,7 @@ pub const longest_name = 30;...@@ -184,7 +185,7 @@ pub const longest_name = 30;
184/// If found, returns the index of the node within the `dafsa` array.185/// If found, returns the index of the node within the `dafsa` array.
185/// Otherwise, returns `null`.186/// Otherwise, returns `null`.
186pub fn findInList(first_child_index: u16, char: u8) ?u16 {187pub fn findInList(first_child_index: u16, char: u8) ?u16 {
187 @setEvalBranchQuota(230);188 @setEvalBranchQuota(232);
188 var index = first_child_index;189 var index = first_child_index;
189 while (true) {190 while (true) {
190 if (dafsa[index].char == char) return index;191 if (dafsa[index].char == char) return index;
...@@ -290,7 +291,7 @@ const dafsa = [_]Node{...@@ -290,7 +291,7 @@ const dafsa = [_]Node{
290 .{ .char = 'j', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 41 },291 .{ .char = 'j', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 41 },
291 .{ .char = 'l', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 42 },292 .{ .char = 'l', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 42 },
292 .{ .char = 'm', .end_of_word = false, .end_of_list = false, .number = 5, .child_index = 43 },293 .{ .char = 'm', .end_of_word = false, .end_of_list = false, .number = 5, .child_index = 43 },
293 .{ .char = 'n', .end_of_word = false, .end_of_list = false, .number = 25, .child_index = 46 },294 .{ .char = 'n', .end_of_word = false, .end_of_list = false, .number = 26, .child_index = 46 },
294 .{ .char = 'p', .end_of_word = false, .end_of_list = false, .number = 6, .child_index = 48 },295 .{ .char = 'p', .end_of_word = false, .end_of_list = false, .number = 6, .child_index = 48 },
295 .{ .char = 'r', .end_of_word = false, .end_of_list = false, .number = 6, .child_index = 53 },296 .{ .char = 'r', .end_of_word = false, .end_of_list = false, .number = 6, .child_index = 53 },
296 .{ .char = 's', .end_of_word = false, .end_of_list = false, .number = 11, .child_index = 55 },297 .{ .char = 's', .end_of_word = false, .end_of_list = false, .number = 11, .child_index = 55 },
...@@ -325,7 +326,7 @@ const dafsa = [_]Node{...@@ -325,7 +326,7 @@ const dafsa = [_]Node{
325 .{ .char = 'o', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 106 },326 .{ .char = 'o', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 106 },
326 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 107 },327 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 107 },
327 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 108 },328 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 108 },
328 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 24, .child_index = 109 },329 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 25, .child_index = 109 },
329 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 2, .child_index = 118 },330 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 2, .child_index = 118 },
330 .{ .char = 'c', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 120 },331 .{ .char = 'c', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 120 },
331 .{ .char = 'e', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 121 },332 .{ .char = 'e', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 121 },
...@@ -392,574 +393,575 @@ const dafsa = [_]Node{...@@ -392,574 +393,575 @@ const dafsa = [_]Node{
392 .{ .char = 'c', .end_of_word = false, .end_of_list = false, .number = 2, .child_index = 198 },393 .{ .char = 'c', .end_of_word = false, .end_of_list = false, .number = 2, .child_index = 198 },
393 .{ .char = 'd', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 200 },394 .{ .char = 'd', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 200 },
394 .{ .char = 'i', .end_of_word = false, .end_of_list = false, .number = 3, .child_index = 201 },395 .{ .char = 'i', .end_of_word = false, .end_of_list = false, .number = 3, .child_index = 201 },
395 .{ .char = 'n', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 203 },396 .{ .char = 'n', .end_of_word = false, .end_of_list = false, .number = 2, .child_index = 203 },
396 .{ .char = 'p', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 204 },397 .{ .char = 'p', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 205 },
397 .{ .char = 'r', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 205 },398 .{ .char = 'r', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 206 },
398 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 206 },
399 .{ .char = 'c', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 108 },
400 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 207 },399 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 207 },
400 .{ .char = 'c', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 108 },
401 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 208 },
401 .{ .char = 's', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },402 .{ .char = 's', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
402 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 208 },403 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 209 },
403 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 75 },404 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 75 },
404 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 190 },405 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 190 },
405 .{ .char = 'p', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 209 },406 .{ .char = 'p', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 210 },
406 .{ .char = 's', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 210 },407 .{ .char = 's', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 211 },
407 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 3, .child_index = 211 },408 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 3, .child_index = 212 },
408 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 213 },409 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 214 },
409 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 214 },410 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 215 },
410 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 215 },411 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 216 },
411 .{ .char = 'c', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 216 },412 .{ .char = 'c', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 217 },
412 .{ .char = 'l', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 217 },413 .{ .char = 'l', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 218 },
413 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 218 },414 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 219 },
414 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 167 },415 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 167 },
415 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 219 },416 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 220 },
416 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 220 },417 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 221 },
417 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 221 },418 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 222 },
418 .{ .char = 'm', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 222 },419 .{ .char = 'm', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 223 },
419 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 223 },420 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 224 },
420 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 224 },421 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 225 },
421 .{ .char = 'i', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 225 },422 .{ .char = 'i', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 226 },
422 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 226 },423 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 227 },
423 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 227 },424 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 228 },
424 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 228 },425 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 229 },
425 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 229 },426 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 230 },
426 .{ .char = 'i', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 230 },427 .{ .char = 'i', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 231 },
427 .{ .char = 's', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 231 },428 .{ .char = 's', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 232 },
428 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 232 },429 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 233 },
429 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 167 },430 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 167 },
430 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 167 },431 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 167 },
431 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 233 },432 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 234 },
432 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 234 },433 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 235 },
433 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 3, .child_index = 235 },434 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 3, .child_index = 236 },
434 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 236 },435 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 237 },
435 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 237 },436 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 238 },
436 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 238 },437 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 239 },
437 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 239 },438 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 240 },
438 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 120 },439 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 120 },
439 .{ .char = 'g', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 240 },440 .{ .char = 'g', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 241 },
440 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 4, .child_index = 241 },441 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 4, .child_index = 242 },
441 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 242 },442 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 243 },
442 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 243 },443 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 244 },
443 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 244 },444 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 245 },
444 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 245 },445 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 246 },
445 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 246 },446 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 247 },
446 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 247 },447 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 248 },
447 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 248 },448 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 249 },
448 .{ .char = 'd', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },449 .{ .char = 'd', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
449 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 249 },450 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 250 },
450 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 250 },451 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 251 },
451 .{ .char = 'y', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },452 .{ .char = 'y', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
452 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 251 },453 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 252 },
453 .{ .char = 'i', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 252 },454 .{ .char = 'i', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 253 },
454 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 253 },455 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 254 },
455 .{ .char = 'e', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 254 },456 .{ .char = 'e', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 255 },
456 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 255 },457 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 256 },
457 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 256 },458 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 257 },
458 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 257 },459 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 258 },
459 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 258 },460 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 259 },
460 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 221 },461 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 222 },
461 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 259 },462 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 260 },
462 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 260 },463 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 261 },
463 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 261 },464 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 262 },
464 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 262 },465 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 263 },
465 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 263 },466 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 264 },
466 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 264 },467 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 265 },
467 .{ .char = 'f', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },468 .{ .char = 'f', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
468 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 265 },469 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 266 },
469 .{ .char = '_', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 266 },470 .{ .char = '_', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 267 },
470 .{ .char = 'b', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 267 },471 .{ .char = 'b', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 268 },
471 .{ .char = 'e', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },472 .{ .char = 'e', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
472 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 268 },473 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 269 },
473 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 269 },474 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 270 },
474 .{ .char = 'i', .end_of_word = false, .end_of_list = false, .number = 2, .child_index = 270 },475 .{ .char = 'i', .end_of_word = false, .end_of_list = false, .number = 2, .child_index = 271 },
475 .{ .char = 'p', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 272 },476 .{ .char = 'p', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 273 },
476 .{ .char = 'r', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 273 },477 .{ .char = 'r', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 274 },
477 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 8, .child_index = 274 },478 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 8, .child_index = 275 },
478 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 277 },479 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 278 },
479 .{ .char = 'l', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 278 },480 .{ .char = 'l', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 279 },
480 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 279 },481 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 280 },
481 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 280 },482 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 281 },
482 .{ .char = 'n', .end_of_word = false, .end_of_list = false, .number = 2, .child_index = 281 },483 .{ .char = 'n', .end_of_word = false, .end_of_list = false, .number = 2, .child_index = 282 },
483 .{ .char = 'p', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 283 },484 .{ .char = 'p', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 284 },
484 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 284 },485 .{ .char = 'n', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 285 },
486 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 286 },
485 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 99 },487 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 99 },
486 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 285 },488 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 287 },
487 .{ .char = 'h', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 286 },489 .{ .char = 'h', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 288 },
488 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 287 },490 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 289 },
489 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 288 },491 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 290 },
490 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 289 },492 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 291 },
491 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 290 },493 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 292 },
492 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 291 },494 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 293 },
493 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 292 },495 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 294 },
494 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 293 },496 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 295 },
495 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 294 },497 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 296 },
496 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 295 },498 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 297 },
497 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 296 },
498 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 297 },
499 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 298 },499 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 298 },
500 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 299 },500 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 299 },
501 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 300 },501 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 300 },
502 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 301 },502 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 301 },
503 .{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 302 },503 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 302 },
504 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 303 },
505 .{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 304 },
504 .{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 107 },506 .{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 107 },
505 .{ .char = 'g', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 303 },507 .{ .char = 'g', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 305 },
506 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 221 },508 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 222 },
507 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 304 },509 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 306 },
508 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 305 },510 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 307 },
509 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 306 },
510 .{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 307 },
511 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 308 },511 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 308 },
512 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 309 },512 .{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 309 },
513 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 310 },
514 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 311 },
513 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 148 },515 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 148 },
514 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 310 },516 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 312 },
515 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 311 },517 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 313 },
516 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 3, .child_index = 312 },518 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 3, .child_index = 314 },
517 .{ .char = 'k', .end_of_word = true, .end_of_list = true, .number = 2, .child_index = 314 },519 .{ .char = 'k', .end_of_word = true, .end_of_list = true, .number = 2, .child_index = 316 },
518 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 315 },520 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 317 },
519 .{ .char = 'h', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 316 },521 .{ .char = 'h', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 318 },
520 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 120 },522 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 120 },
521 .{ .char = 'n', .end_of_word = true, .end_of_list = true, .number = 2, .child_index = 317 },523 .{ .char = 'n', .end_of_word = true, .end_of_list = true, .number = 2, .child_index = 319 },
522 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 4, .child_index = 318 },524 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 4, .child_index = 320 },
523 .{ .char = 'y', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 320 },525 .{ .char = 'y', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 322 },
524 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 321 },526 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 323 },
525 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 322 },527 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 324 },
526 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 323 },528 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 325 },
527 .{ .char = 'l', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },529 .{ .char = 'l', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
528 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 324 },530 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 326 },
529 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 325 },531 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 327 },
530 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 326 },532 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 328 },
531 .{ .char = 't', .end_of_word = true, .end_of_list = true, .number = 2, .child_index = 327 },533 .{ .char = 't', .end_of_word = true, .end_of_list = true, .number = 2, .child_index = 329 },
532 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 328 },534 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 330 },
533 .{ .char = 'g', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 329 },535 .{ .char = 'g', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 331 },
534 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 330 },
535 .{ .char = 'x', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 331 },
536 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 331 },
537 .{ .char = 'r', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
538 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 332 },536 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 332 },
539 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 333 },537 .{ .char = 'x', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 333 },
540 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 334 },538 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 333 },
541 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 335 },539 .{ .char = 'r', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
542 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 336 },540 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 334 },
541 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 335 },
542 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 336 },
543 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 337 },
544 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 338 },
543 .{ .char = 'c', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },545 .{ .char = 'c', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
544 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 337 },546 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 339 },
545 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 338 },547 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 340 },
546 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 262 },548 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 263 },
547 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 197 },549 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 197 },
548 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 339 },550 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 341 },
549 .{ .char = 'b', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 340 },551 .{ .char = 'b', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 342 },
550 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 341 },552 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 343 },
551 .{ .char = 'c', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 186 },553 .{ .char = 'c', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 186 },
552 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 342 },554 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 344 },
553 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 343 },555 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 345 },
554 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 344 },556 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 346 },
555 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 5, .child_index = 345 },557 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 5, .child_index = 347 },
556 .{ .char = 'p', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 346 },558 .{ .char = 'p', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 348 },
557 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 347 },559 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 349 },
558 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 348 },560 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 350 },
559 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 349 },561 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 351 },
560 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 168 },562 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 168 },
561 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 350 },563 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 352 },
562 .{ .char = 'i', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 99 },564 .{ .char = 'i', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 99 },
563 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 351 },565 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 353 },
564 .{ .char = 'a', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },566 .{ .char = 'a', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
565 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 352 },567 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 354 },
566 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 353 },568 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 355 },
567 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 354 },569 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 356 },
568 .{ .char = 'h', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 355 },570 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 357 },
569 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 356 },571 .{ .char = 'h', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 358 },
570 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 357 },572 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 359 },
571 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 358 },573 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 360 },
572 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 326 },574 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 361 },
573 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 359 },575 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 328 },
574 .{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 360 },576 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 362 },
575 .{ .char = 'b', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 361 },577 .{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 363 },
576 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 362 },578 .{ .char = 'b', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 364 },
577 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 249 },579 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 365 },
578 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 363 },580 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 250 },
579 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 364 },581 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 366 },
582 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 367 },
580 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 123 },583 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 123 },
581 .{ .char = 'k', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 365 },584 .{ .char = 'k', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 368 },
582 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 366 },585 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 354 },
583 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 256 },586 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 257 },
584 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 367 },587 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 369 },
585 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 167 },588 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 167 },
586 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 368 },589 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 370 },
587 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 369 },590 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 371 },
588 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 370 },591 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 372 },
589 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 371 },592 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 373 },
590 .{ .char = 'q', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 372 },593 .{ .char = 'q', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 374 },
591 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 373 },594 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 375 },
592 .{ .char = 'b', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 374 },595 .{ .char = 'b', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 376 },
593 .{ .char = '_', .end_of_word = false, .end_of_list = false, .number = 2, .child_index = 375 },596 .{ .char = '_', .end_of_word = false, .end_of_list = false, .number = 2, .child_index = 377 },
594 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 377 },597 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 379 },
595 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 378 },598 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 380 },
596 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 379 },599 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 381 },
597 .{ .char = '6', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 380 },600 .{ .char = '6', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 382 },
598 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 167 },601 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 167 },
599 .{ .char = '_', .end_of_word = false, .end_of_list = false, .number = 2, .child_index = 381 },602 .{ .char = '_', .end_of_word = false, .end_of_list = false, .number = 2, .child_index = 383 },
600 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 383 },603 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 385 },
601 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 182 },604 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 182 },
602 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 384 },605 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 386 },
603 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 385 },606 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 387 },
604 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 386 },607 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 388 },
605 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 387 },608 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 389 },
606 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 388 },609 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 390 },
607 .{ .char = 'n', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },610 .{ .char = 'n', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
608 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 330 },611 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 332 },
609 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 389 },612 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 391 },
610 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 390 },613 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 392 },
611 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 391 },614 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 393 },
612 .{ .char = 'p', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 392 },615 .{ .char = 'p', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 394 },
613 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 393 },616 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 395 },
614 .{ .char = 'h', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 394 },617 .{ .char = 'h', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 396 },
615 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 326 },618 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 328 },
616 .{ .char = 't', .end_of_word = true, .end_of_list = true, .number = 2, .child_index = 395 },619 .{ .char = 't', .end_of_word = true, .end_of_list = true, .number = 2, .child_index = 397 },
617 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 396 },620 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 398 },
618 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 397 },621 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 399 },
619 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 398 },622 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 400 },
620 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 399 },623 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 401 },
621 .{ .char = 'i', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },624 .{ .char = 'i', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
622 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 400 },625 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 402 },
623 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 401 },626 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 403 },
624 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 402 },627 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 404 },
625 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 403 },628 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 405 },
626 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 5, .child_index = 404 },629 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 5, .child_index = 406 },
627 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 405 },630 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 407 },
628 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 406 },631 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 408 },
629 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 120 },632 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 120 },
630 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 190 },633 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 190 },
631 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 407 },634 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 409 },
632 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 349 },635 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 351 },
633 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 408 },636 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 247 },
634 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 409 },637 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 410 },
635 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 410 },638 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 411 },
636 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 411 },639 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 412 },
637 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 412 },640 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 413 },
638 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 413 },641 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 414 },
639 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 414 },642 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 415 },
640 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 415 },643 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 416 },
641 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 416 },644 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 417 },
642 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 417 },645 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 418 },
643 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 418 },646 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 419 },
644 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 419 },647 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 420 },
645 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 420 },648 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 421 },
646 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 421 },649 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 422 },
647 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 246 },650 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 423 },
648 .{ .char = 't', .end_of_word = true, .end_of_list = true, .number = 2, .child_index = 422 },651 .{ .char = 't', .end_of_word = true, .end_of_list = true, .number = 2, .child_index = 424 },
649 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 423 },652 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 425 },
650 .{ .char = 'p', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 424 },653 .{ .char = 'p', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 426 },
651 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 425 },654 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 427 },
652 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 426 },655 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 428 },
653 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 427 },656 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 429 },
654 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 428 },657 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 430 },
655 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 430 },658 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 432 },
656 .{ .char = 'i', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 431 },659 .{ .char = 'i', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 433 },
657 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 432 },660 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 434 },
658 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 433 },661 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 435 },
659 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 186 },662 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 186 },
660 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 434 },663 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 436 },
661 .{ .char = '4', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 435 },664 .{ .char = '4', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 437 },
662 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 436 },665 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 438 },
663 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 437 },666 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 439 },
664 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 438 },667 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 440 },
665 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 291 },668 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 293 },
666 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 440 },669 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 442 },
667 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 441 },670 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 443 },
668 .{ .char = 'p', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },671 .{ .char = 'p', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
669 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 433 },672 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 435 },
670 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 442 },673 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 444 },
671 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 443 },674 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 445 },
672 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 444 },675 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 446 },
673 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 445 },676 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 447 },
674 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 446 },677 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 448 },
675 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 447 },678 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 449 },
676 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 448 },679 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 450 },
677 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 351 },680 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 353 },
678 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 449 },681 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 451 },
679 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 450 },
680 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 451 },
681 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 452 },682 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 452 },
682 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 453 },683 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 453 },
683 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 454 },684 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 454 },
684 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 455 },685 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 455 },
685 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 5, .child_index = 456 },686 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 456 },
686 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 457 },687 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 457 },
687 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 458 },688 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 5, .child_index = 458 },
688 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 459 },689 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 459 },
689 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 377 },690 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 460 },
690 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 326 },691 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 461 },
692 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 379 },
693 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 328 },
691 .{ .char = 'w', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },694 .{ .char = 'w', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
692 .{ .char = 'b', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 460 },695 .{ .char = 'b', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 462 },
693 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 461 },696 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 463 },
694 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 462 },697 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 464 },
695 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 99 },698 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 99 },
696 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 463 },699 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 465 },
697 .{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 464 },700 .{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 466 },
698 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 465 },701 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 467 },
699 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 466 },702 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 468 },
700 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 467 },703 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 469 },
701 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 246 },704 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 247 },
702 .{ .char = 'p', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 468 },705 .{ .char = 'p', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 470 },
703 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 469 },706 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 471 },
704 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 420 },707 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 422 },
705 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 470 },708 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 472 },
706 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 471 },709 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 473 },
707 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 472 },710 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 474 },
708 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 473 },711 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 475 },
709 .{ .char = '_', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 474 },712 .{ .char = '_', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 476 },
710 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 301 },713 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 303 },
711 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 475 },714 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 477 },
712 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 476 },715 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 478 },
713 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 477 },716 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 479 },
714 .{ .char = 'g', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },717 .{ .char = 'g', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
715 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 478 },718 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 480 },
716 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 479 },719 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 481 },
717 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 481 },720 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 483 },
718 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 482 },721 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 484 },
719 .{ .char = 'e', .end_of_word = true, .end_of_list = false, .number = 1, .child_index = 0 },722 .{ .char = 'e', .end_of_word = true, .end_of_list = false, .number = 1, .child_index = 0 },
720 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 256 },723 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 257 },
721 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 483 },724 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 485 },
722 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 484 },725 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 486 },
723 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 148 },726 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 148 },
724 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 485 },727 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 487 },
725 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 176 },728 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 176 },
726 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 99 },729 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 99 },
727 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 486 },730 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 488 },
728 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 487 },731 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 489 },
729 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 488 },732 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 490 },
730 .{ .char = 'p', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 489 },733 .{ .char = 'p', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 491 },
731 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 490 },734 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 492 },
732 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 491 },735 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 493 },
733 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 492 },736 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 494 },
734 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 493 },737 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 495 },
735 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 494 },738 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 496 },
736 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 302 },739 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 304 },
737 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 5, .child_index = 495 },740 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 5, .child_index = 497 },
738 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 496 },741 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 498 },
739 .{ .char = 'k', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 497 },742 .{ .char = 'k', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 499 },
740 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 167 },743 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 167 },
741 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 498 },744 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 500 },
742 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 499 },745 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 501 },
743 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 500 },746 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 502 },
744 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 501 },747 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 503 },
745 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 503 },748 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 505 },
746 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 504 },749 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 506 },
747 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 505 },750 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 507 },
748 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 170 },751 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 170 },
749 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 506 },
750 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 507 },
751 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 508 },752 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 508 },
752 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 509 },753 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 509 },
753 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 510 },754 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 510 },
754 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 511 },755 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 511 },
755 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 437 },756 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 512 },
756 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 512 },757 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 513 },
757 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 513 },758 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 439 },
758 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 514 },759 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 514 },
759 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 515 },760 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 515 },
760 .{ .char = 's', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 516 },761 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 516 },
761 .{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 517 },762 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 517 },
762 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 518 },763 .{ .char = 's', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 518 },
764 .{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 519 },
765 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 520 },
763 .{ .char = 'z', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 190 },766 .{ .char = 'z', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 190 },
764 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 246 },767 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 247 },
765 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 519 },
766 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 520 },
767 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 521 },768 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 521 },
768 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 522 },769 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 522 },
769 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 433 },770 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 523 },
770 .{ .char = 't', .end_of_word = true, .end_of_list = true, .number = 2, .child_index = 523 },771 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 524 },
771 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 524 },772 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 435 },
772 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 232 },773 .{ .char = 't', .end_of_word = true, .end_of_list = true, .number = 2, .child_index = 525 },
773 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 525 },774 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 526 },
774 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 526 },775 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 233 },
775 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 527 },776 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 527 },
776 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 5, .child_index = 528 },777 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 528 },
777 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 529 },778 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 529 },
778 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 530 },779 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 5, .child_index = 530 },
779 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 532 },780 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 531 },
781 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 2, .child_index = 532 },
782 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 534 },
780 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 99 },783 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 99 },
781 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 509 },784 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 511 },
782 .{ .char = 'n', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 533 },785 .{ .char = 'n', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 535 },
783 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 534 },786 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 536 },
784 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 535 },787 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 537 },
785 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 536 },788 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 538 },
786 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 537 },789 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 539 },
787 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 538 },790 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 540 },
788 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 539 },791 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 541 },
789 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 540 },792 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 542 },
790 .{ .char = 'b', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 541 },793 .{ .char = 'b', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 543 },
791 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 542 },794 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 544 },
792 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 148 },795 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 148 },
793 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 170 },796 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 170 },
794 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 543 },797 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 545 },
795 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 544 },798 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 546 },
796 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 545 },799 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 547 },
797 .{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 546 },800 .{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 548 },
798 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 547 },801 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 549 },
799 .{ .char = 'g', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 326 },802 .{ .char = 'g', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 328 },
800 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 548 },803 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 550 },
801 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 549 },804 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 551 },
802 .{ .char = 'y', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 550 },805 .{ .char = 'y', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 552 },
803 .{ .char = 'g', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 551 },806 .{ .char = 'g', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 553 },
804 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 552 },807 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 554 },
805 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 553 },808 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 555 },
806 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 554 },809 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 556 },
807 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 555 },810 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 557 },
808 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 556 },811 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 558 },
809 .{ .char = 'z', .end_of_word = false, .end_of_list = true, .number = 5, .child_index = 557 },812 .{ .char = 'z', .end_of_word = false, .end_of_list = true, .number = 5, .child_index = 559 },
810 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 558 },813 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 560 },
811 .{ .char = 'l', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 559 },814 .{ .char = 'l', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 561 },
812 .{ .char = 'p', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 560 },815 .{ .char = 'p', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 562 },
813 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 561 },816 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 563 },
814 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 562 },817 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 564 },
815 .{ .char = 'w', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 563 },818 .{ .char = 'w', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 565 },
816 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 564 },
817 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 120 },
818 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 565 },
819 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 566 },819 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 566 },
820 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 120 },
820 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 567 },821 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 567 },
821 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 568 },822 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 568 },
823 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 569 },
824 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 570 },
822 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 190 },825 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 190 },
823 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 569 },826 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 571 },
824 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 570 },827 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 572 },
825 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 571 },
826 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 572 },
827 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 573 },828 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 573 },
828 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 574 },829 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 574 },
829 .{ .char = 'g', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 575 },830 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 575 },
830 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 576 },831 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 576 },
831 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 577 },832 .{ .char = 'g', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 577 },
832 .{ .char = 'h', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },833 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 578 },
833 .{ .char = 'h', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 578 },
834 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 262 },
835 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 579 },834 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 579 },
836 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 580 },835 .{ .char = 'h', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
836 .{ .char = 'h', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 580 },
837 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 263 },
837 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 581 },838 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 581 },
838 .{ .char = 'e', .end_of_word = true, .end_of_list = true, .number = 5, .child_index = 582 },839 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 582 },
839 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 583 },840 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 583 },
840 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 584 },841 .{ .char = 'e', .end_of_word = true, .end_of_list = true, .number = 5, .child_index = 584 },
841 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 585 },842 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 585 },
842 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 586 },843 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 586 },
843 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 587 },844 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 587 },
844 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 588 },845 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 588 },
845 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 589 },846 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 589 },
846 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 590 },847 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 590 },
847 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 414 },848 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 591 },
848 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 591 },849 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 592 },
849 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 592 },850 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 416 },
851 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 593 },
852 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 594 },
850 .{ .char = 'z', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 148 },853 .{ .char = 'z', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 148 },
851 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 386 },854 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 388 },
852 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 593 },855 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 595 },
853 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 594 },856 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 596 },
854 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 595 },857 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 597 },
855 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 596 },858 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 598 },
856 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 148 },859 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 148 },
857 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 597 },860 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 599 },
858 .{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 598 },861 .{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 600 },
859 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 599 },862 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 601 },
860 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 600 },863 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 602 },
861 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 601 },864 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 603 },
862 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 602 },865 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 604 },
863 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 4, .child_index = 603 },866 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 4, .child_index = 605 },
864 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 607 },867 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 609 },
865 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 608 },868 .{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 610 },
866 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 609 },869 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 611 },
867 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 610 },870 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 612 },
868 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 611 },871 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 285 },
869 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 190 },872 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 190 },
870 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 612 },873 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 613 },
871 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 613 },874 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 614 },
872 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 120 },875 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 120 },
873 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 614 },
874 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 615 },876 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 615 },
875 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 616 },877 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 616 },
876 .{ .char = 'p', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 617 },878 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 617 },
877 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 618 },879 .{ .char = 'p', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 618 },
878 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 608 },880 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 619 },
879 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 619 },881 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 610 },
880 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 620 },882 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 620 },
881 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 621 },883 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 621 },
882 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 622 },884 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 622 },
883 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 342 },885 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 623 },
884 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 623 },886 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 344 },
885 .{ .char = 'c', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 624 },887 .{ .char = 'a', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 624 },
886 .{ .char = 't', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 625 },888 .{ .char = 'c', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 625 },
887 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 626 },889 .{ .char = 't', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 626 },
888 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 627 },890 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 627 },
891 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 628 },
889 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 99 },892 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 99 },
890 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 628 },893 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 629 },
891 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 629 },894 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 630 },
892 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 366 },895 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 631 },
893 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 630 },896 .{ .char = 'g', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 632 },
894 .{ .char = 'g', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 631 },897 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 633 },
895 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 632 },898 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 634 },
896 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 633 },899 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 635 },
897 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 634 },
898 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 120 },900 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 120 },
899 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 573 },901 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 575 },
900 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 500 },902 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 502 },
901 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 635 },903 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 636 },
902 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 636 },904 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 637 },
903 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 637 },905 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 638 },
904 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 638 },906 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 639 },
905 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 639 },907 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 640 },
906 .{ .char = 'h', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 640 },908 .{ .char = 'h', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 641 },
907 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 641 },909 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 642 },
908 .{ .char = 'k', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },910 .{ .char = 'k', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
909 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 391 },911 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 393 },
910 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 642 },912 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 643 },
911 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 262 },913 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 263 },
912 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 643 },
913 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 296 },
914 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 644 },914 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 644 },
915 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 645 },915 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 298 },
916 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 302 },916 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 645 },
917 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 646 },917 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 646 },
918 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 647 },918 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 304 },
919 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 648 },919 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 647 },
920 .{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 649 },920 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 648 },
921 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 226 },921 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 649 },
922 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 650 },922 .{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 650 },
923 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 651 },923 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 227 },
924 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 344 },924 .{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 651 },
925 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 652 },925 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 652 },
926 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 653 },926 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 346 },
927 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 654 },927 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 653 },
928 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 655 },928 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 654 },
929 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 655 },
930 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 656 },
929 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 156 },931 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 156 },
930 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 656 },
931 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 657 },932 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 657 },
932 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 658 },933 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 658 },
933 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 204 },934 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 659 },
934 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 659 },935 .{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 205 },
935 .{ .char = 'y', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 660 },936 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 660 },
936 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 661 },937 .{ .char = 'y', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 661 },
937 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 662 },938 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 662 },
938 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 663 },939 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 663 },
939 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 664 },940 .{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 664 },
940 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 665 },941 .{ .char = 'o', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 665 },
941 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 666 },942 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 666 },
942 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 216 },943 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 667 },
943 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 667 },944 .{ .char = 'c', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 217 },
944 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 575 },945 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 668 },
945 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 668 },946 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 577 },
947 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 669 },
946 .{ .char = 'g', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 120 },948 .{ .char = 'g', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 120 },
947 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 669 },949 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 670 },
948 .{ .char = 'g', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 190 },950 .{ .char = 'g', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 190 },
949 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 670 },951 .{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 671 },
950 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 671 },952 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 672 },
951 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 672 },953 .{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 673 },
952 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 673 },954 .{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 674 },
953 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 674 },955 .{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 675 },
954 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 675 },956 .{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 676 },
955 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 676 },957 .{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 677 },
956 .{ .char = 'y', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 677 },958 .{ .char = 'y', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 678 },
957 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 170 },959 .{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 170 },
958 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 678 },960 .{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 679 },
959 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 120 },961 .{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 120 },
960};962};
961pub const data = blk: {963pub const data = blk: {
962 @setEvalBranchQuota(805);964 @setEvalBranchQuota(812);
963 break :blk [_]@This(){965 break :blk [_]@This(){
964 .{ .tag = .aarch64_sve_pcs, .properties = .{ .tag = .aarch64_sve_pcs, .gnu = true } },966 .{ .tag = .aarch64_sve_pcs, .properties = .{ .tag = .aarch64_sve_pcs, .gnu = true } },
965 .{ .tag = .aarch64_vector_pcs, .properties = .{ .tag = .aarch64_vector_pcs, .gnu = true } },967 .{ .tag = .aarch64_vector_pcs, .properties = .{ .tag = .aarch64_vector_pcs, .gnu = true } },
...@@ -1028,6 +1030,7 @@ pub const data = blk: {...@@ -1028,6 +1030,7 @@ pub const data = blk: {
1028 .{ .tag = .noinit, .properties = .{ .tag = .noinit, .gnu = true } },1030 .{ .tag = .noinit, .properties = .{ .tag = .noinit, .gnu = true } },
1029 .{ .tag = .@"noinline", .properties = .{ .tag = .@"noinline", .gnu = true, .declspec = true } },1031 .{ .tag = .@"noinline", .properties = .{ .tag = .@"noinline", .gnu = true, .declspec = true } },
1030 .{ .tag = .noipa, .properties = .{ .tag = .noipa, .gnu = true } },1032 .{ .tag = .noipa, .properties = .{ .tag = .noipa, .gnu = true } },
1033 .{ .tag = .nonnull, .properties = .{ .tag = .nonnull, .gnu = true } },
1031 .{ .tag = .nonstring, .properties = .{ .tag = .nonstring, .gnu = true } },1034 .{ .tag = .nonstring, .properties = .{ .tag = .nonstring, .gnu = true } },
1032 .{ .tag = .noplt, .properties = .{ .tag = .noplt, .gnu = true } },1035 .{ .tag = .noplt, .properties = .{ .tag = .noplt, .gnu = true } },
1033 .{ .tag = .@"noreturn", .properties = .{ .tag = .@"noreturn", .c23 = true, .gnu = true, .declspec = true } },1036 .{ .tag = .@"noreturn", .properties = .{ .tag = .@"noreturn", .c23 = true, .gnu = true, .declspec = true } },
lib/compiler/aro/aro/Builtins.zig+5-4
...@@ -312,12 +312,13 @@ pub const Iterator = struct {...@@ -312,12 +312,13 @@ pub const Iterator = struct {
312};312};
313313
314test Iterator {314test Iterator {
315 const gpa = std.testing.allocator;
315 var it = Iterator{};316 var it = Iterator{};
316317
317 var seen = std.StringHashMap(Builtin).init(std.testing.allocator);318 var seen: std.StringHashMapUnmanaged(Builtin) = .empty;
318 defer seen.deinit();319 defer seen.deinit(gpa);
319320
320 var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);321 var arena_state = std.heap.ArenaAllocator.init(gpa);
321 defer arena_state.deinit();322 defer arena_state.deinit();
322 const arena = arena_state.allocator();323 const arena = arena_state.allocator();
323324
...@@ -333,7 +334,7 @@ test Iterator {...@@ -333,7 +334,7 @@ test Iterator {
333 std.debug.print("previous data: {}\n", .{seen.get(entry.name).?});334 std.debug.print("previous data: {}\n", .{seen.get(entry.name).?});
334 return error.TestExpectedUniqueEntries;335 return error.TestExpectedUniqueEntries;
335 }336 }
336 try seen.put(try arena.dupe(u8, entry.name), entry.builtin);337 try seen.put(gpa, try arena.dupe(u8, entry.name), entry.builtin);
337 }338 }
338 try std.testing.expectEqual(@as(usize, Builtin.data.len), seen.count());339 try std.testing.expectEqual(@as(usize, Builtin.data.len), seen.count());
339}340}
lib/compiler/aro/aro/CodeGen.zig+9-8
...@@ -40,11 +40,11 @@ tree: *const Tree,...@@ -40,11 +40,11 @@ tree: *const Tree,
40comp: *Compilation,40comp: *Compilation,
41builder: Builder,41builder: Builder,
42wip_switch: *WipSwitch = undefined,42wip_switch: *WipSwitch = undefined,
43symbols: std.ArrayListUnmanaged(Symbol) = .{},43symbols: std.ArrayList(Symbol) = .empty,
44ret_nodes: std.ArrayListUnmanaged(Ir.Inst.Phi.Input) = .{},44ret_nodes: std.ArrayList(Ir.Inst.Phi.Input) = .empty,
45phi_nodes: std.ArrayListUnmanaged(Ir.Inst.Phi.Input) = .{},45phi_nodes: std.ArrayList(Ir.Inst.Phi.Input) = .empty,
46record_elem_buf: std.ArrayListUnmanaged(Interner.Ref) = .{},46record_elem_buf: std.ArrayList(Interner.Ref) = .empty,
47record_cache: std.AutoHashMapUnmanaged(QualType, Interner.Ref) = .{},47record_cache: std.AutoHashMapUnmanaged(QualType, Interner.Ref) = .empty,
48cond_dummy_ty: ?Interner.Ref = null,48cond_dummy_ty: ?Interner.Ref = null,
49bool_invert: bool = false,49bool_invert: bool = false,
50bool_end_label: Ir.Ref = .none,50bool_end_label: Ir.Ref = .none,
...@@ -56,10 +56,11 @@ compound_assign_dummy: ?Ir.Ref = null,...@@ -56,10 +56,11 @@ compound_assign_dummy: ?Ir.Ref = null,
5656
57fn fail(c: *CodeGen, comptime fmt: []const u8, args: anytype) error{ FatalError, OutOfMemory } {57fn fail(c: *CodeGen, comptime fmt: []const u8, args: anytype) error{ FatalError, OutOfMemory } {
58 var sf = std.heap.stackFallback(1024, c.comp.gpa);58 var sf = std.heap.stackFallback(1024, c.comp.gpa);
59 var buf = std.ArrayList(u8).init(sf.get());59 const allocator = sf.get();
60 defer buf.deinit();60 var buf: std.ArrayList(u8) = .empty;
61 defer buf.deinit(allocator);
6162
62 try buf.print(fmt, args);63 try buf.print(allocator, fmt, args);
63 try c.comp.diagnostics.add(.{ .text = buf.items, .kind = .@"fatal error", .location = null });64 try c.comp.diagnostics.add(.{ .text = buf.items, .kind = .@"fatal error", .location = null });
64 return error.FatalError;65 return error.FatalError;
65}66}
lib/compiler/aro/aro/Compilation.zig+68-47
...@@ -4,8 +4,9 @@ const EpochSeconds = std.time.epoch.EpochSeconds;...@@ -4,8 +4,9 @@ const EpochSeconds = std.time.epoch.EpochSeconds;
4const mem = std.mem;4const mem = std.mem;
5const Allocator = mem.Allocator;5const Allocator = mem.Allocator;
66
7const Interner = @import("../backend.zig").Interner;7const backend = @import("../backend.zig");
8const CodeGenOptions = @import("../backend.zig").CodeGenOptions;8const Interner = backend.Interner;
9const CodeGenOptions = backend.CodeGenOptions;
910
10const Builtins = @import("Builtins.zig");11const Builtins = @import("Builtins.zig");
11const Builtin = Builtins.Builtin;12const Builtin = Builtins.Builtin;
...@@ -127,24 +128,24 @@ diagnostics: *Diagnostics,...@@ -127,24 +128,24 @@ diagnostics: *Diagnostics,
127128
128code_gen_options: CodeGenOptions = .default,129code_gen_options: CodeGenOptions = .default,
129environment: Environment = .{},130environment: Environment = .{},
130sources: std.StringArrayHashMapUnmanaged(Source) = .{},131sources: std.StringArrayHashMapUnmanaged(Source) = .empty,
131/// Allocated into `gpa`, but keys are externally managed.132/// Allocated into `gpa`, but keys are externally managed.
132include_dirs: std.ArrayListUnmanaged([]const u8) = .empty,133include_dirs: std.ArrayList([]const u8) = .empty,
133/// Allocated into `gpa`, but keys are externally managed.134/// Allocated into `gpa`, but keys are externally managed.
134system_include_dirs: std.ArrayListUnmanaged([]const u8) = .empty,135system_include_dirs: std.ArrayList([]const u8) = .empty,
135/// Allocated into `gpa`, but keys are externally managed.136/// Allocated into `gpa`, but keys are externally managed.
136after_include_dirs: std.ArrayListUnmanaged([]const u8) = .empty,137after_include_dirs: std.ArrayList([]const u8) = .empty,
137/// Allocated into `gpa`, but keys are externally managed.138/// Allocated into `gpa`, but keys are externally managed.
138framework_dirs: std.ArrayListUnmanaged([]const u8) = .empty,139framework_dirs: std.ArrayList([]const u8) = .empty,
139/// Allocated into `gpa`, but keys are externally managed.140/// Allocated into `gpa`, but keys are externally managed.
140system_framework_dirs: std.ArrayListUnmanaged([]const u8) = .empty,141system_framework_dirs: std.ArrayList([]const u8) = .empty,
141/// Allocated into `gpa`, but keys are externally managed.142/// Allocated into `gpa`, but keys are externally managed.
142embed_dirs: std.ArrayListUnmanaged([]const u8) = .empty,143embed_dirs: std.ArrayList([]const u8) = .empty,
143target: std.Target = @import("builtin").target,144target: std.Target = @import("builtin").target,
144cmodel: std.builtin.CodeModel = .default,145cmodel: std.builtin.CodeModel = .default,
145pragma_handlers: std.StringArrayHashMapUnmanaged(*Pragma) = .{},146pragma_handlers: std.StringArrayHashMapUnmanaged(*Pragma) = .empty,
146langopts: LangOpts = .{},147langopts: LangOpts = .{},
147generated_buf: std.ArrayListUnmanaged(u8) = .{},148generated_buf: std.ArrayList(u8) = .empty,
148builtins: Builtins = .{},149builtins: Builtins = .{},
149string_interner: StringInterner = .{},150string_interner: StringInterner = .{},
150interner: Interner = .{},151interner: Interner = .{},
...@@ -245,6 +246,13 @@ fn generateSystemDefines(comp: *Compilation, w: *std.Io.Writer) !void {...@@ -245,6 +246,13 @@ fn generateSystemDefines(comp: *Compilation, w: *std.Io.Writer) !void {
245 try w.print("#define __GNUC_PATCHLEVEL__ {d}\n", .{comp.langopts.gnuc_version % 100});246 try w.print("#define __GNUC_PATCHLEVEL__ {d}\n", .{comp.langopts.gnuc_version % 100});
246 }247 }
247248
249 if (comp.code_gen_options.optimization_level.hasAnyOptimizations()) {
250 try define(w, "__OPTIMIZE__");
251 }
252 if (comp.code_gen_options.optimization_level.isSizeOptimized()) {
253 try define(w, "__OPTIMIZE_SIZE__");
254 }
255
248 // os macros256 // os macros
249 switch (comp.target.os.tag) {257 switch (comp.target.os.tag) {
250 .linux => try defineStd(w, "linux", is_gnu),258 .linux => try defineStd(w, "linux", is_gnu),
...@@ -1379,8 +1387,8 @@ pub fn addSourceFromOwnedBuffer(comp: *Compilation, path: []const u8, buf: []u8,...@@ -1379,8 +1387,8 @@ pub fn addSourceFromOwnedBuffer(comp: *Compilation, path: []const u8, buf: []u8,
1379 const duped_path = try comp.gpa.dupe(u8, path);1387 const duped_path = try comp.gpa.dupe(u8, path);
1380 errdefer comp.gpa.free(duped_path);1388 errdefer comp.gpa.free(duped_path);
13811389
1382 var splice_list = std.array_list.Managed(u32).init(comp.gpa);1390 var splice_list: std.ArrayList(u32) = .empty;
1383 defer splice_list.deinit();1391 defer splice_list.deinit(comp.gpa);
13841392
1385 const source_id: Source.Id = @enumFromInt(comp.sources.count() + 2);1393 const source_id: Source.Id = @enumFromInt(comp.sources.count() + 2);
13861394
...@@ -1413,9 +1421,9 @@ pub fn addSourceFromOwnedBuffer(comp: *Compilation, path: []const u8, buf: []u8,...@@ -1413,9 +1421,9 @@ pub fn addSourceFromOwnedBuffer(comp: *Compilation, path: []const u8, buf: []u8,
1413 },1421 },
1414 .back_slash, .trailing_ws, .back_slash_cr => {1422 .back_slash, .trailing_ws, .back_slash_cr => {
1415 i = backslash_loc;1423 i = backslash_loc;
1416 try splice_list.append(i);1424 try splice_list.append(comp.gpa, i);
1417 if (state == .trailing_ws) {1425 if (state == .trailing_ws) {
1418 try comp.addNewlineEscapeError(path, buf, splice_list.items, i, line);1426 try comp.addNewlineEscapeError(path, buf, splice_list.items, i, line, kind);
1419 }1427 }
1420 state = if (state == .back_slash_cr) .cr else .back_slash_cr;1428 state = if (state == .back_slash_cr) .cr else .back_slash_cr;
1421 },1429 },
...@@ -1433,10 +1441,10 @@ pub fn addSourceFromOwnedBuffer(comp: *Compilation, path: []const u8, buf: []u8,...@@ -1433,10 +1441,10 @@ pub fn addSourceFromOwnedBuffer(comp: *Compilation, path: []const u8, buf: []u8,
1433 .back_slash, .trailing_ws => {1441 .back_slash, .trailing_ws => {
1434 i = backslash_loc;1442 i = backslash_loc;
1435 if (state == .back_slash or state == .trailing_ws) {1443 if (state == .back_slash or state == .trailing_ws) {
1436 try splice_list.append(i);1444 try splice_list.append(comp.gpa, i);
1437 }1445 }
1438 if (state == .trailing_ws) {1446 if (state == .trailing_ws) {
1439 try comp.addNewlineEscapeError(path, buf, splice_list.items, i, line);1447 try comp.addNewlineEscapeError(path, buf, splice_list.items, i, line, kind);
1440 }1448 }
1441 },1449 },
1442 .bom1, .bom2 => break,1450 .bom1, .bom2 => break,
...@@ -1486,11 +1494,11 @@ pub fn addSourceFromOwnedBuffer(comp: *Compilation, path: []const u8, buf: []u8,...@@ -1486,11 +1494,11 @@ pub fn addSourceFromOwnedBuffer(comp: *Compilation, path: []const u8, buf: []u8,
1486 }1494 }
1487 }1495 }
14881496
1489 const splice_locs = try splice_list.toOwnedSlice();1497 const splice_locs = try splice_list.toOwnedSlice(comp.gpa);
1490 errdefer comp.gpa.free(splice_locs);1498 errdefer comp.gpa.free(splice_locs);
14911499
1492 if (i != contents.len) {1500 if (i != contents.len) {
1493 var list: std.ArrayListUnmanaged(u8) = .{1501 var list: std.ArrayList(u8) = .{
1494 .items = contents[0..i],1502 .items = contents[0..i],
1495 .capacity = contents.len,1503 .capacity = contents.len,
1496 };1504 };
...@@ -1510,13 +1518,21 @@ pub fn addSourceFromOwnedBuffer(comp: *Compilation, path: []const u8, buf: []u8,...@@ -1510,13 +1518,21 @@ pub fn addSourceFromOwnedBuffer(comp: *Compilation, path: []const u8, buf: []u8,
1510 return source;1518 return source;
1511}1519}
15121520
1513fn addNewlineEscapeError(comp: *Compilation, path: []const u8, buf: []const u8, splice_locs: []const u32, byte_offset: u32, line: u32) !void {1521fn addNewlineEscapeError(
1522 comp: *Compilation,
1523 path: []const u8,
1524 buf: []const u8,
1525 splice_locs: []const u32,
1526 byte_offset: u32,
1527 line: u32,
1528 kind: Source.Kind,
1529) !void {
1514 // Temporary source for getting the location for errors.1530 // Temporary source for getting the location for errors.
1515 var tmp_source: Source = .{1531 var tmp_source: Source = .{
1516 .path = path,1532 .path = path,
1517 .buf = buf,1533 .buf = buf,
1518 .id = undefined,1534 .id = undefined,
1519 .kind = undefined,1535 .kind = kind,
1520 .splice_locs = splice_locs,1536 .splice_locs = splice_locs,
1521 };1537 };
15221538
...@@ -1566,17 +1582,7 @@ fn addSourceFromPathExtra(comp: *Compilation, path: []const u8, kind: Source.Kin...@@ -1566,17 +1582,7 @@ fn addSourceFromPathExtra(comp: *Compilation, path: []const u8, kind: Source.Kin
1566}1582}
15671583
1568pub fn addSourceFromFile(comp: *Compilation, file: std.fs.File, path: []const u8, kind: Source.Kind) !Source {1584pub fn addSourceFromFile(comp: *Compilation, file: std.fs.File, path: []const u8, kind: Source.Kind) !Source {
1569 var file_buf: [4096]u8 = undefined;1585 const contents = try comp.getFileContents(file, .unlimited);
1570 var file_reader = file.reader(&file_buf);
1571 if (try file_reader.getSize() > std.math.maxInt(u32)) return error.FileTooBig;
1572
1573 var allocating: std.Io.Writer.Allocating = .init(comp.gpa);
1574 _ = allocating.writer.sendFileAll(&file_reader, .limited(std.math.maxInt(u32))) catch |e| switch (e) {
1575 error.WriteFailed => return error.OutOfMemory,
1576 error.ReadFailed => return file_reader.err.?,
1577 };
1578
1579 const contents = try allocating.toOwnedSlice();
1580 errdefer comp.gpa.free(contents);1586 errdefer comp.gpa.free(contents);
1581 return comp.addSourceFromOwnedBuffer(path, contents, kind);1587 return comp.addSourceFromOwnedBuffer(path, contents, kind);
1582}1588}
...@@ -1671,7 +1677,7 @@ const FindInclude = struct {...@@ -1671,7 +1677,7 @@ const FindInclude = struct {
1671 if (try find.checkFrameworkDir(dir, .system)) |res| return res;1677 if (try find.checkFrameworkDir(dir, .system)) |res| return res;
1672 }1678 }
1673 for (comp.after_include_dirs.items) |dir| {1679 for (comp.after_include_dirs.items) |dir| {
1674 if (try find.checkIncludeDir(dir, .user)) |res| return res;1680 if (try find.checkIncludeDir(dir, .system)) |res| return res;
1675 }1681 }
1676 if (comp.ms_cwd_source_id) |source_id| {1682 if (comp.ms_cwd_source_id) |source_id| {
1677 if (try find.checkMsCwdIncludeDir(source_id)) |res| return res;1683 if (try find.checkMsCwdIncludeDir(source_id)) |res| return res;
...@@ -1766,26 +1772,38 @@ pub const IncludeType = enum {...@@ -1766,26 +1772,38 @@ pub const IncludeType = enum {
1766 angle_brackets,1772 angle_brackets,
1767};1773};
17681774
1769fn getFileContents(comp: *Compilation, path: []const u8, limit: std.Io.Limit) ![]const u8 {1775fn getPathContents(comp: *Compilation, path: []const u8, limit: std.Io.Limit) ![]u8 {
1770 if (mem.indexOfScalar(u8, path, 0) != null) {1776 if (mem.indexOfScalar(u8, path, 0) != null) {
1771 return error.FileNotFound;1777 return error.FileNotFound;
1772 }1778 }
17731779
1774 const file = try comp.cwd.openFile(path, .{});1780 const file = try comp.cwd.openFile(path, .{});
1775 defer file.close();1781 defer file.close();
1782 return comp.getFileContents(file, limit);
1783}
17761784
1777 var allocating: std.Io.Writer.Allocating = .init(comp.gpa);1785fn getFileContents(comp: *Compilation, file: std.fs.File, limit: std.Io.Limit) ![]u8 {
1778 defer allocating.deinit();
1779
1780 var file_buf: [4096]u8 = undefined;1786 var file_buf: [4096]u8 = undefined;
1781 var file_reader = file.reader(&file_buf);1787 var file_reader = file.reader(&file_buf);
1782 if (limit.minInt64(try file_reader.getSize()) > std.math.maxInt(u32)) return error.FileTooBig;
1783
1784 _ = allocating.writer.sendFileAll(&file_reader, limit) catch |err| switch (err) {
1785 error.WriteFailed => return error.OutOfMemory,
1786 error.ReadFailed => return file_reader.err.?,
1787 };
17881788
1789 var allocating: std.Io.Writer.Allocating = .init(comp.gpa);
1790 defer allocating.deinit();
1791 if (file_reader.getSize()) |size| {
1792 const limited_size = limit.minInt64(size);
1793 if (limited_size > std.math.maxInt(u32)) return error.FileTooBig;
1794 try allocating.ensureUnusedCapacity(limited_size);
1795 } else |_| {}
1796
1797 var remaining = limit.min(.limited(std.math.maxInt(u32)));
1798 while (remaining.nonzero()) {
1799 const n = file_reader.interface.stream(&allocating.writer, remaining) catch |err| switch (err) {
1800 error.EndOfStream => return allocating.toOwnedSlice(),
1801 error.WriteFailed => return error.OutOfMemory,
1802 error.ReadFailed => return file_reader.err.?,
1803 };
1804 remaining = remaining.subtract(n).?;
1805 }
1806 if (limit == .unlimited) return error.FileTooBig;
1789 return allocating.toOwnedSlice();1807 return allocating.toOwnedSlice();
1790}1808}
17911809
...@@ -1797,9 +1815,10 @@ pub fn findEmbed(...@@ -1797,9 +1815,10 @@ pub fn findEmbed(
1797 include_type: IncludeType,1815 include_type: IncludeType,
1798 limit: std.Io.Limit,1816 limit: std.Io.Limit,
1799 opt_dep_file: ?*DepFile,1817 opt_dep_file: ?*DepFile,
1800) !?[]const u8 {1818) !?[]u8 {
1801 if (std.fs.path.isAbsolute(filename)) {1819 if (std.fs.path.isAbsolute(filename)) {
1802 if (comp.getFileContents(filename, limit)) |some| {1820 if (comp.getPathContents(filename, limit)) |some| {
1821 errdefer comp.gpa.free(some);
1803 if (opt_dep_file) |dep_file| try dep_file.addDependencyDupe(comp.gpa, comp.arena, filename);1822 if (opt_dep_file) |dep_file| try dep_file.addDependencyDupe(comp.gpa, comp.arena, filename);
1804 return some;1823 return some;
1805 } else |err| switch (err) {1824 } else |err| switch (err) {
...@@ -1819,7 +1838,8 @@ pub fn findEmbed(...@@ -1819,7 +1838,8 @@ pub fn findEmbed(
1819 if (comp.langopts.ms_extensions) {1838 if (comp.langopts.ms_extensions) {
1820 std.mem.replaceScalar(u8, path, '\\', '/');1839 std.mem.replaceScalar(u8, path, '\\', '/');
1821 }1840 }
1822 if (comp.getFileContents(path, limit)) |some| {1841 if (comp.getPathContents(path, limit)) |some| {
1842 errdefer comp.gpa.free(some);
1823 if (opt_dep_file) |dep_file| try dep_file.addDependencyDupe(comp.gpa, comp.arena, filename);1843 if (opt_dep_file) |dep_file| try dep_file.addDependencyDupe(comp.gpa, comp.arena, filename);
1824 return some;1844 return some;
1825 } else |err| switch (err) {1845 } else |err| switch (err) {
...@@ -1835,7 +1855,8 @@ pub fn findEmbed(...@@ -1835,7 +1855,8 @@ pub fn findEmbed(
1835 if (comp.langopts.ms_extensions) {1855 if (comp.langopts.ms_extensions) {
1836 std.mem.replaceScalar(u8, path, '\\', '/');1856 std.mem.replaceScalar(u8, path, '\\', '/');
1837 }1857 }
1838 if (comp.getFileContents(path, limit)) |some| {1858 if (comp.getPathContents(path, limit)) |some| {
1859 errdefer comp.gpa.free(some);
1839 if (opt_dep_file) |dep_file| try dep_file.addDependencyDupe(comp.gpa, comp.arena, filename);1860 if (opt_dep_file) |dep_file| try dep_file.addDependencyDupe(comp.gpa, comp.arena, filename);
1840 return some;1861 return some;
1841 } else |err| switch (err) {1862 } else |err| switch (err) {
lib/compiler/aro/aro/DepFile.zig+33-12
...@@ -28,7 +28,7 @@ pub fn write(d: *const DepFile, w: *std.Io.Writer) std.Io.Writer.Error!void {...@@ -28,7 +28,7 @@ pub fn write(d: *const DepFile, w: *std.Io.Writer) std.Io.Writer.Error!void {
28 const max_columns = 75;28 const max_columns = 75;
29 var columns: usize = 0;29 var columns: usize = 0;
3030
31 try w.writeAll(d.target);31 try writeTarget(d.target, w);
32 columns += d.target.len;32 columns += d.target.len;
33 try w.writeByte(':');33 try w.writeByte(':');
34 columns += 1;34 columns += 1;
...@@ -48,6 +48,26 @@ pub fn write(d: *const DepFile, w: *std.Io.Writer) std.Io.Writer.Error!void {...@@ -48,6 +48,26 @@ pub fn write(d: *const DepFile, w: *std.Io.Writer) std.Io.Writer.Error!void {
48 try w.flush();48 try w.flush();
49}49}
5050
51fn writeTarget(path: []const u8, w: *std.Io.Writer) !void {
52 for (path, 0..) |c, i| {
53 switch (c) {
54 ' ', '\t' => {
55 try w.writeByte('\\');
56 var j = i;
57 while (j != 0) {
58 j -= 1;
59 if (path[j] != '\\') break;
60 try w.writeByte('\\');
61 }
62 },
63 '$' => try w.writeByte('$'),
64 '#' => try w.writeByte('\\'),
65 else => {},
66 }
67 try w.writeByte(c);
68 }
69}
70
51fn writePath(d: *const DepFile, path: []const u8, w: *std.Io.Writer) !void {71fn writePath(d: *const DepFile, path: []const u8, w: *std.Io.Writer) !void {
52 switch (d.format) {72 switch (d.format) {
53 .nmake => {73 .nmake => {
...@@ -58,18 +78,19 @@ fn writePath(d: *const DepFile, path: []const u8, w: *std.Io.Writer) !void {...@@ -58,18 +78,19 @@ fn writePath(d: *const DepFile, path: []const u8, w: *std.Io.Writer) !void {
58 },78 },
59 .make => {79 .make => {
60 for (path, 0..) |c, i| {80 for (path, 0..) |c, i| {
61 if (c == '#') {81 switch (c) {
62 try w.writeByte('\\');82 ' ' => {
63 } else if (c == '$') {
64 try w.writeByte('$');
65 } else if (c == ' ') {
66 try w.writeByte('\\');
67 var j = i;
68 while (j != 0) {
69 j -= 1;
70 if (path[j] != '\\') break;
71 try w.writeByte('\\');83 try w.writeByte('\\');
72 }84 var j = i;
85 while (j != 0) {
86 j -= 1;
87 if (path[j] != '\\') break;
88 try w.writeByte('\\');
89 }
90 },
91 '$' => try w.writeByte('$'),
92 '#' => try w.writeByte('\\'),
93 else => {},
73 }94 }
74 try w.writeByte(c);95 try w.writeByte(c);
75 }96 }
lib/compiler/aro/aro/Diagnostics.zig+17-3
...@@ -193,6 +193,8 @@ pub const Option = enum {...@@ -193,6 +193,8 @@ pub const Option = enum {
193 @"microsoft-flexible-array",193 @"microsoft-flexible-array",
194 @"microsoft-anon-tag",194 @"microsoft-anon-tag",
195 @"out-of-scope-function",195 @"out-of-scope-function",
196 @"date-time",
197 @"attribute-todo",
196198
197 /// GNU extensions199 /// GNU extensions
198 pub const gnu = [_]Option{200 pub const gnu = [_]Option{
...@@ -278,6 +280,8 @@ pub const State = struct {...@@ -278,6 +280,8 @@ pub const State = struct {
278 extensions: Message.Kind = .off,280 extensions: Message.Kind = .off,
279 /// How to treat individual options, set by -W<name>281 /// How to treat individual options, set by -W<name>
280 options: std.EnumMap(Option, Message.Kind) = .{},282 options: std.EnumMap(Option, Message.Kind) = .{},
283 /// Should warnings be suppressed in system headers, set by -Wsystem-headers
284 suppress_system_headers: bool = true,
281};285};
282286
283const Diagnostics = @This();287const Diagnostics = @This();
...@@ -288,7 +292,7 @@ output: union(enum) {...@@ -288,7 +292,7 @@ output: union(enum) {
288 color: std.Io.tty.Config,292 color: std.Io.tty.Config,
289 },293 },
290 to_list: struct {294 to_list: struct {
291 messages: std.ArrayListUnmanaged(Message) = .empty,295 messages: std.ArrayList(Message) = .empty,
292 arena: std.heap.ArenaAllocator,296 arena: std.heap.ArenaAllocator,
293 },297 },
294 ignore,298 ignore,
...@@ -373,6 +377,16 @@ pub fn effectiveKind(d: *Diagnostics, message: anytype) Message.Kind {...@@ -373,6 +377,16 @@ pub fn effectiveKind(d: *Diagnostics, message: anytype) Message.Kind {
373 return .off;377 return .off;
374 }378 }
375379
380 if (@hasField(@TypeOf(message), "location")) {
381 if (message.location) |location| {
382 if (location.kind != .user and d.state.suppress_system_headers and
383 (message.kind == .warning or message.kind == .off))
384 {
385 return .off;
386 }
387 }
388 }
389
376 var kind = message.kind;390 var kind = message.kind;
377391
378 // Get explicit kind set by -W<name>=392 // Get explicit kind set by -W<name>=
...@@ -418,9 +432,9 @@ pub fn addWithLocation(...@@ -418,9 +432,9 @@ pub fn addWithLocation(
418 note_msg_loc: bool,432 note_msg_loc: bool,
419) Compilation.Error!void {433) Compilation.Error!void {
420 var copy = msg;434 var copy = msg;
421 copy.effective_kind = d.effectiveKind(msg);
422 if (copy.effective_kind == .off) return;
423 if (expansion_locs.len != 0) copy.location = expansion_locs[expansion_locs.len - 1].expand(comp);435 if (expansion_locs.len != 0) copy.location = expansion_locs[expansion_locs.len - 1].expand(comp);
436 copy.effective_kind = d.effectiveKind(copy);
437 if (copy.effective_kind == .off) return;
424 try d.addMessage(copy);438 try d.addMessage(copy);
425439
426 if (expansion_locs.len != 0) {440 if (expansion_locs.len != 0) {
lib/compiler/aro/aro/Driver.zig+19-25
...@@ -45,8 +45,8 @@ const Driver = @This();...@@ -45,8 +45,8 @@ const Driver = @This();
45comp: *Compilation,45comp: *Compilation,
46diagnostics: *Diagnostics,46diagnostics: *Diagnostics,
4747
48inputs: std.ArrayListUnmanaged(Source) = .{},48inputs: std.ArrayList(Source) = .empty,
49link_objects: std.ArrayListUnmanaged([]const u8) = .{},49link_objects: std.ArrayList([]const u8) = .empty,
50output_name: ?[]const u8 = null,50output_name: ?[]const u8 = null,
51sysroot: ?[]const u8 = null,51sysroot: ?[]const u8 = null,
52resource_dir: ?[]const u8 = null,52resource_dir: ?[]const u8 = null,
...@@ -107,7 +107,6 @@ raw_cpu: ?[]const u8 = null,...@@ -107,7 +107,6 @@ raw_cpu: ?[]const u8 = null,
107use_assembly_backend: bool = false,107use_assembly_backend: bool = false,
108108
109// linker options109// linker options
110use_linker: ?[]const u8 = null,
111linker_path: ?[]const u8 = null,110linker_path: ?[]const u8 = null,
112nodefaultlibs: bool = false,111nodefaultlibs: bool = false,
113nolibc: bool = false,112nolibc: bool = false,
...@@ -270,7 +269,7 @@ pub const usage =...@@ -270,7 +269,7 @@ pub const usage =
270pub fn parseArgs(269pub fn parseArgs(
271 d: *Driver,270 d: *Driver,
272 stdout: *std.Io.Writer,271 stdout: *std.Io.Writer,
273 macro_buf: *std.ArrayListUnmanaged(u8),272 macro_buf: *std.ArrayList(u8),
274 args: []const []const u8,273 args: []const []const u8,
275) (Compilation.Error || std.Io.Writer.Error)!bool {274) (Compilation.Error || std.Io.Writer.Error)!bool {
276 var i: usize = 1;275 var i: usize = 1;
...@@ -322,7 +321,7 @@ pub fn parseArgs(...@@ -322,7 +321,7 @@ pub fn parseArgs(
322 }321 }
323 try macro_buf.print(d.comp.gpa, "#undef {s}\n", .{macro});322 try macro_buf.print(d.comp.gpa, "#undef {s}\n", .{macro});
324 } else if (mem.eql(u8, arg, "-O")) {323 } else if (mem.eql(u8, arg, "-O")) {
325 d.comp.code_gen_options.optimization_level = .@"0";324 d.comp.code_gen_options.optimization_level = .@"1";
326 } else if (mem.startsWith(u8, arg, "-O")) {325 } else if (mem.startsWith(u8, arg, "-O")) {
327 d.comp.code_gen_options.optimization_level = backend.CodeGenOptions.OptimizationLevel.fromString(arg["-O".len..]) orelse {326 d.comp.code_gen_options.optimization_level = backend.CodeGenOptions.OptimizationLevel.fromString(arg["-O".len..]) orelse {
328 try d.err("invalid optimization level '{s}'", .{arg});327 try d.err("invalid optimization level '{s}'", .{arg});
...@@ -600,6 +599,10 @@ pub fn parseArgs(...@@ -600,6 +599,10 @@ pub fn parseArgs(
600 d.diagnostics.state.enable_all_warnings = false;599 d.diagnostics.state.enable_all_warnings = false;
601 } else if (mem.eql(u8, arg, "-Weverything")) {600 } else if (mem.eql(u8, arg, "-Weverything")) {
602 d.diagnostics.state.enable_all_warnings = true;601 d.diagnostics.state.enable_all_warnings = true;
602 } else if (mem.eql(u8, arg, "-Wno-system-headers")) {
603 d.diagnostics.state.suppress_system_headers = true;
604 } else if (mem.eql(u8, arg, "-Wsystem-headers")) {
605 d.diagnostics.state.suppress_system_headers = false;
603 } else if (mem.eql(u8, arg, "-Werror")) {606 } else if (mem.eql(u8, arg, "-Werror")) {
604 d.diagnostics.state.error_warnings = true;607 d.diagnostics.state.error_warnings = true;
605 } else if (mem.eql(u8, arg, "-Wno-error")) {608 } else if (mem.eql(u8, arg, "-Wno-error")) {
...@@ -644,10 +647,6 @@ pub fn parseArgs(...@@ -644,10 +647,6 @@ pub fn parseArgs(
644 d.comp.langopts.preserve_comments = true;647 d.comp.langopts.preserve_comments = true;
645 d.comp.langopts.preserve_comments_in_macros = true;648 d.comp.langopts.preserve_comments_in_macros = true;
646 comment_arg = arg;649 comment_arg = arg;
647 } else if (option(arg, "-fuse-ld=")) |linker_name| {
648 d.use_linker = linker_name;
649 } else if (mem.eql(u8, arg, "-fuse-ld=")) {
650 d.use_linker = null;
651 } else if (option(arg, "--ld-path=")) |linker_path| {650 } else if (option(arg, "--ld-path=")) |linker_path| {
652 d.linker_path = linker_path;651 d.linker_path = linker_path;
653 } else if (mem.eql(u8, arg, "-r")) {652 } else if (mem.eql(u8, arg, "-r")) {
...@@ -917,13 +916,11 @@ pub fn errorDescription(e: anyerror) []const u8 {...@@ -917,13 +916,11 @@ pub fn errorDescription(e: anyerror) []const u8 {
917 };916 };
918}917}
919918
920var stdout_buffer: [4096]u8 = undefined;
921
922/// The entry point of the Aro compiler.919/// The entry point of the Aro compiler.
923/// **MAY call `exit` if `fast_exit` is set.**920/// **MAY call `exit` if `fast_exit` is set.**
924pub fn main(d: *Driver, tc: *Toolchain, args: []const []const u8, comptime fast_exit: bool, asm_gen_fn: ?AsmCodeGenFn) Compilation.Error!void {921pub fn main(d: *Driver, tc: *Toolchain, args: []const []const u8, comptime fast_exit: bool, asm_gen_fn: ?AsmCodeGenFn) Compilation.Error!void {
925 const user_macros = macros: {922 const user_macros = macros: {
926 var macro_buf: std.ArrayListUnmanaged(u8) = .empty;923 var macro_buf: std.ArrayList(u8) = .empty;
927 defer macro_buf.deinit(d.comp.gpa);924 defer macro_buf.deinit(d.comp.gpa);
928925
929 var stdout_buf: [256]u8 = undefined;926 var stdout_buf: [256]u8 = undefined;
...@@ -1107,7 +1104,7 @@ fn processSource(...@@ -1107,7 +1104,7 @@ fn processSource(
11071104
1108 var name_buf: [std.fs.max_name_bytes]u8 = undefined;1105 var name_buf: [std.fs.max_name_bytes]u8 = undefined;
1109 var opt_dep_file = try d.initDepFile(source, &name_buf, false);1106 var opt_dep_file = try d.initDepFile(source, &name_buf, false);
1110 defer if (opt_dep_file) |*dep_file| dep_file.deinit(pp.gpa);1107 defer if (opt_dep_file) |*dep_file| dep_file.deinit(d.comp.gpa);
11111108
1112 if (opt_dep_file) |*dep_file| pp.dep_file = dep_file;1109 if (opt_dep_file) |*dep_file| pp.dep_file = dep_file;
11131110
...@@ -1164,14 +1161,11 @@ fn processSource(...@@ -1164,14 +1161,11 @@ fn processSource(
1164 else1161 else
1165 std.fs.File.stdout();1162 std.fs.File.stdout();
1166 defer if (d.output_name != null) file.close();1163 defer if (d.output_name != null) file.close();
1167 var file_buffer: [1024]u8 = undefined;
1168 var file_writer = file.writer(&file_buffer);
11691164
1170 pp.prettyPrintTokens(&file_writer.interface, dump_mode) catch |er|1165 var file_writer = file.writer(&writer_buf);
1171 return d.fatal("unable to write result: {s}", .{errorDescription(er)});1166 pp.prettyPrintTokens(&file_writer.interface, dump_mode) catch
1167 return d.fatal("unable to write result: {s}", .{errorDescription(file_writer.err.?)});
11721168
1173 file_writer.interface.flush() catch |er|
1174 return d.fatal("unable to write result: {s}", .{errorDescription(er)});
1175 if (fast_exit) std.process.exit(0); // Not linking, no need for cleanup.1169 if (fast_exit) std.process.exit(0); // Not linking, no need for cleanup.
1176 return;1170 return;
1177 }1171 }
...@@ -1180,9 +1174,8 @@ fn processSource(...@@ -1180,9 +1174,8 @@ fn processSource(
1180 defer tree.deinit();1174 defer tree.deinit();
11811175
1182 if (d.verbose_ast) {1176 if (d.verbose_ast) {
1183 var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);1177 var stdout = std.fs.File.stdout().writer(&writer_buf);
1184 tree.dump(d.detectConfig(.stdout()), &stdout_writer.interface) catch {};1178 tree.dump(d.detectConfig(stdout.file), &stdout.interface) catch {};
1185 stdout_writer.interface.flush() catch {};
1186 }1179 }
11871180
1188 d.printDiagnosticsStats();1181 d.printDiagnosticsStats();
...@@ -1299,12 +1292,13 @@ fn dumpLinkerArgs(w: *std.Io.Writer, items: []const []const u8) !void {...@@ -1299,12 +1292,13 @@ fn dumpLinkerArgs(w: *std.Io.Writer, items: []const []const u8) !void {
1299/// The entry point of the Aro compiler.1292/// The entry point of the Aro compiler.
1300/// **MAY call `exit` if `fast_exit` is set.**1293/// **MAY call `exit` if `fast_exit` is set.**
1301pub fn invokeLinker(d: *Driver, tc: *Toolchain, comptime fast_exit: bool) Compilation.Error!void {1294pub fn invokeLinker(d: *Driver, tc: *Toolchain, comptime fast_exit: bool) Compilation.Error!void {
1302 var argv = std.array_list.Managed([]const u8).init(d.comp.gpa);1295 const gpa = d.comp.gpa;
1303 defer argv.deinit();1296 var argv: std.ArrayList([]const u8) = .empty;
1297 defer argv.deinit(gpa);
13041298
1305 var linker_path_buf: [std.fs.max_path_bytes]u8 = undefined;1299 var linker_path_buf: [std.fs.max_path_bytes]u8 = undefined;
1306 const linker_path = try tc.getLinkerPath(&linker_path_buf);1300 const linker_path = try tc.getLinkerPath(&linker_path_buf);
1307 try argv.append(linker_path);1301 try argv.append(gpa, linker_path);
13081302
1309 try tc.buildLinkerArgs(&argv);1303 try tc.buildLinkerArgs(&argv);
13101304
lib/compiler/aro/aro/Driver/Multilib.zig+32-23
...@@ -1,47 +1,50 @@...@@ -1,47 +1,50 @@
1const std = @import("std");1const std = @import("std");
2const Filesystem = @import("Filesystem.zig").Filesystem;2const Filesystem = @import("Filesystem.zig").Filesystem;
33
4pub const Flags = std.ArrayListUnmanaged([]const u8);
5
6/// Large enough for GCCDetector for Linux; may need to be increased to support other toolchains.4/// Large enough for GCCDetector for Linux; may need to be increased to support other toolchains.
7const max_multilibs = 4;5const max_multilibs = 4;
86
9const MultilibArray = std.ArrayListUnmanaged(Multilib);
10
11pub const Detected = struct {7pub const Detected = struct {
12 multilibs: MultilibArray = .{},8 multilib_buf: [max_multilibs]Multilib = undefined,
9 multilib_count: u8 = 0,
13 selected: Multilib = .{},10 selected: Multilib = .{},
14 biarch_sibling: ?Multilib = null,11 biarch_sibling: ?Multilib = null,
1512
16 pub fn filter(self: *Detected, multilib_filter: Filter, fs: Filesystem) void {13 pub fn filter(d: *Detected, multilib_filter: Filter, fs: Filesystem) void {
17 var found_count: usize = 0;14 var found_count: u8 = 0;
18 for (self.multilibs.items) |multilib| {15 for (d.multilibs()) |multilib| {
19 if (multilib_filter.exists(multilib, fs)) {16 if (multilib_filter.exists(multilib, fs)) {
20 self.multilibs.items[found_count] = multilib;17 d.multilib_buf[found_count] = multilib;
21 found_count += 1;18 found_count += 1;
22 }19 }
23 }20 }
24 self.multilibs.resize(found_count) catch unreachable;21 d.multilib_count = found_count;
25 }22 }
2623
27 pub fn select(self: *Detected, flags: []const []const Flags) !bool {24 pub fn select(d: *Detected, check_flags: []const []const u8) !bool {
28 var filtered: MultilibArray = .{};25 var selected: ?Multilib = null;
29 for (self.multilibs.items) |multilib| {26
30 for (flags) |multilib_flag| {27 for (d.multilibs()) |multilib| {
31 const matched = for (flags) |arg_flag| {28 for (multilib.flags()) |multilib_flag| {
29 const matched = for (check_flags) |arg_flag| {
32 if (std.mem.eql(u8, arg_flag[1..], multilib_flag[1..])) break arg_flag;30 if (std.mem.eql(u8, arg_flag[1..], multilib_flag[1..])) break arg_flag;
33 } else multilib_flag;31 } else multilib_flag;
34 if (matched[0] != multilib_flag[0]) break;32 if (matched[0] != multilib_flag[0]) break;
33 } else if (selected != null) {
34 return error.TooManyMultilibs;
35 } else {35 } else {
36 filtered.appendAssumeCapacity(multilib);36 selected = multilib;
37 }37 }
38 }38 }
39 if (filtered.len == 0) return false;39 if (selected) |multilib| {
40 if (filtered.len == 1) {40 d.selected = multilib;
41 self.selected = filtered.get(0);
42 return true;41 return true;
43 }42 }
44 return error.TooManyMultilibs;43 return false;
44 }
45
46 pub fn multilibs(d: *const Detected) []const Multilib {
47 return d.multilib_buf[0..d.multilib_count];
45 }48 }
46};49};
4750
...@@ -58,14 +61,20 @@ const Multilib = @This();...@@ -58,14 +61,20 @@ const Multilib = @This();
58gcc_suffix: []const u8 = "",61gcc_suffix: []const u8 = "",
59os_suffix: []const u8 = "",62os_suffix: []const u8 = "",
60include_suffix: []const u8 = "",63include_suffix: []const u8 = "",
61flags: Flags = .{},64flag_buf: [6][]const u8 = undefined,
65flag_count: u8 = 0,
62priority: u32 = 0,66priority: u32 = 0,
6367
64pub fn init(gcc_suffix: []const u8, os_suffix: []const u8, flags: []const []const u8) Multilib {68pub fn init(gcc_suffix: []const u8, os_suffix: []const u8, init_flags: []const []const u8) Multilib {
65 var self: Multilib = .{69 var self: Multilib = .{
66 .gcc_suffix = gcc_suffix,70 .gcc_suffix = gcc_suffix,
67 .os_suffix = os_suffix,71 .os_suffix = os_suffix,
72 .flag_count = @intCast(init_flags.len),
68 };73 };
69 self.flags.appendSliceAssumeCapacity(flags);74 @memcpy(self.flag_buf[0..init_flags.len], init_flags);
70 return self;75 return self;
71}76}
77
78pub fn flags(m: *const Multilib) []const []const u8 {
79 return m.flag_buf[0..m.flag_count];
80}
lib/compiler/aro/aro/InitList.zig+1-1
...@@ -22,7 +22,7 @@ const Item = struct {...@@ -22,7 +22,7 @@ const Item = struct {
2222
23const InitList = @This();23const InitList = @This();
2424
25list: std.ArrayListUnmanaged(Item) = .empty,25list: std.ArrayList(Item) = .empty,
26node: Node.OptIndex = .null,26node: Node.OptIndex = .null,
27tok: TokenIndex = 0,27tok: TokenIndex = 0,
2828
lib/compiler/aro/aro/Parser.zig+296-216
...@@ -32,12 +32,12 @@ const Type = TypeStore.Type;...@@ -32,12 +32,12 @@ const Type = TypeStore.Type;
32const QualType = TypeStore.QualType;32const QualType = TypeStore.QualType;
33const Value = @import("Value.zig");33const Value = @import("Value.zig");
3434
35const NodeList = std.array_list.Managed(Node.Index);35const NodeList = std.ArrayList(Node.Index);
36const Switch = struct {36const Switch = struct {
37 default: ?TokenIndex = null,37 default: ?TokenIndex = null,
38 ranges: std.array_list.Managed(Range),38 ranges: std.ArrayList(Range) = .empty,
39 qt: QualType,39 qt: QualType,
40 comp: *Compilation,40 comp: *const Compilation,
4141
42 const Range = struct {42 const Range = struct {
43 first: Value,43 first: Value,
...@@ -45,13 +45,13 @@ const Switch = struct {...@@ -45,13 +45,13 @@ const Switch = struct {
45 tok: TokenIndex,45 tok: TokenIndex,
46 };46 };
4747
48 fn add(self: *Switch, first: Value, last: Value, tok: TokenIndex) !?Range {48 fn add(s: *Switch, first: Value, last: Value, tok: TokenIndex) !?Range {
49 for (self.ranges.items) |range| {49 for (s.ranges.items) |range| {
50 if (last.compare(.gte, range.first, self.comp) and first.compare(.lte, range.last, self.comp)) {50 if (last.compare(.gte, range.first, s.comp) and first.compare(.lte, range.last, s.comp)) {
51 return range; // They overlap.51 return range; // They overlap.
52 }52 }
53 }53 }
54 try self.ranges.append(.{54 try s.ranges.append(s.comp.gpa, .{
55 .first = first,55 .first = first,
56 .last = last,56 .last = last,
57 .tok = tok,57 .tok = tok,
...@@ -101,7 +101,6 @@ const Parser = @This();...@@ -101,7 +101,6 @@ const Parser = @This();
101pp: *Preprocessor,101pp: *Preprocessor,
102comp: *Compilation,102comp: *Compilation,
103diagnostics: *Diagnostics,103diagnostics: *Diagnostics,
104gpa: mem.Allocator,
105tok_ids: []const Token.Id,104tok_ids: []const Token.Id,
106tok_i: TokenIndex = 0,105tok_i: TokenIndex = 0,
107106
...@@ -110,21 +109,21 @@ tree: Tree,...@@ -110,21 +109,21 @@ tree: Tree,
110109
111// buffers used during compilation110// buffers used during compilation
112syms: SymbolStack = .{},111syms: SymbolStack = .{},
113strings: std.array_list.Managed(u8),112strings: std.array_list.Aligned(u8, .@"4") = .empty,
114labels: std.array_list.Managed(Label),113labels: std.ArrayList(Label) = .empty,
115list_buf: NodeList,114list_buf: NodeList = .empty,
116decl_buf: NodeList,115decl_buf: NodeList = .empty,
117/// Function type parameters, also used for generic selection association116/// Function type parameters, also used for generic selection association
118/// duplicate checking.117/// duplicate checking.
119param_buf: std.array_list.Managed(Type.Func.Param),118param_buf: std.ArrayList(Type.Func.Param) = .empty,
120/// Enum type fields.119/// Enum type fields.
121enum_buf: std.array_list.Managed(Type.Enum.Field),120enum_buf: std.ArrayList(Type.Enum.Field) = .empty,
122/// Record type fields.121/// Record type fields.
123record_buf: std.array_list.Managed(Type.Record.Field),122record_buf: std.ArrayList(Type.Record.Field) = .empty,
124/// Attributes that have been parsed but not yet validated or applied.123/// Attributes that have been parsed but not yet validated or applied.
125attr_buf: std.MultiArrayList(TentativeAttribute) = .empty,124attr_buf: std.MultiArrayList(TentativeAttribute) = .empty,
126/// Used to store validated attributes before they are applied to types.125/// Used to store validated attributes before they are applied to types.
127attr_application_buf: std.ArrayListUnmanaged(Attribute) = .empty,126attr_application_buf: std.ArrayList(Attribute) = .empty,
128/// type name -> variable name location for tentative definitions (top-level defs with thus-far-incomplete types)127/// type name -> variable name location for tentative definitions (top-level defs with thus-far-incomplete types)
129/// e.g. `struct Foo bar;` where `struct Foo` is not defined yet.128/// e.g. `struct Foo bar;` where `struct Foo` is not defined yet.
130/// The key is the StringId of `Foo` and the value is the TokenIndex of `bar`129/// The key is the StringId of `Foo` and the value is the TokenIndex of `bar`
...@@ -177,7 +176,7 @@ record: struct {...@@ -177,7 +176,7 @@ record: struct {
177 break;176 break;
178 }177 }
179 }178 }
180 try p.record_members.append(p.gpa, .{ .name = name, .tok = tok });179 try p.record_members.append(p.comp.gpa, .{ .name = name, .tok = tok });
181 }180 }
182181
183 fn addFieldsFromAnonymous(r: @This(), p: *Parser, record_ty: Type.Record) Error!void {182 fn addFieldsFromAnonymous(r: @This(), p: *Parser, record_ty: Type.Record) Error!void {
...@@ -192,7 +191,7 @@ record: struct {...@@ -192,7 +191,7 @@ record: struct {
192 }191 }
193 }192 }
194} = .{},193} = .{},
195record_members: std.ArrayListUnmanaged(struct { tok: TokenIndex, name: StringId }) = .{},194record_members: std.ArrayList(struct { tok: TokenIndex, name: StringId }) = .empty,
196195
197@"switch": ?*Switch = null,196@"switch": ?*Switch = null,
198in_loop: bool = false,197in_loop: bool = false,
...@@ -212,7 +211,7 @@ fn checkIdentifierCodepointWarnings(p: *Parser, codepoint: u21, loc: Source.Loca...@@ -212,7 +211,7 @@ fn checkIdentifierCodepointWarnings(p: *Parser, codepoint: u21, loc: Source.Loca
212 assert(codepoint >= 0x80);211 assert(codepoint >= 0x80);
213212
214 const prev_total = p.diagnostics.total;213 const prev_total = p.diagnostics.total;
215 var sf = std.heap.stackFallback(1024, p.gpa);214 var sf = std.heap.stackFallback(1024, p.comp.gpa);
216 var allocating: std.Io.Writer.Allocating = .init(sf.get());215 var allocating: std.Io.Writer.Allocating = .init(sf.get());
217 defer allocating.deinit();216 defer allocating.deinit();
218217
...@@ -425,7 +424,7 @@ pub fn err(p: *Parser, tok_i: TokenIndex, diagnostic: Diagnostic, args: anytype)...@@ -425,7 +424,7 @@ pub fn err(p: *Parser, tok_i: TokenIndex, diagnostic: Diagnostic, args: anytype)
425 if (diagnostic.suppress_unless_version) |some| if (!p.comp.langopts.standard.atLeast(some)) return;424 if (diagnostic.suppress_unless_version) |some| if (!p.comp.langopts.standard.atLeast(some)) return;
426 if (p.diagnostics.effectiveKind(diagnostic) == .off) return;425 if (p.diagnostics.effectiveKind(diagnostic) == .off) return;
427426
428 var sf = std.heap.stackFallback(1024, p.gpa);427 var sf = std.heap.stackFallback(1024, p.comp.gpa);
429 var allocating: std.Io.Writer.Allocating = .init(sf.get());428 var allocating: std.Io.Writer.Allocating = .init(sf.get());
430 defer allocating.deinit();429 defer allocating.deinit();
431430
...@@ -604,7 +603,7 @@ pub fn removeNull(p: *Parser, str: Value) !Value {...@@ -604,7 +603,7 @@ pub fn removeNull(p: *Parser, str: Value) !Value {
604 defer p.strings.items.len = strings_top;603 defer p.strings.items.len = strings_top;
605 {604 {
606 const bytes = p.comp.interner.get(str.ref()).bytes;605 const bytes = p.comp.interner.get(str.ref()).bytes;
607 try p.strings.appendSlice(bytes[0 .. bytes.len - 1]);606 try p.strings.appendSlice(p.comp.gpa, bytes[0 .. bytes.len - 1]);
608 }607 }
609 return Value.intern(p.comp, .{ .bytes = p.strings.items[strings_top..] });608 return Value.intern(p.comp, .{ .bytes = p.strings.items[strings_top..] });
610}609}
...@@ -799,30 +798,23 @@ fn diagnoseIncompleteDefinitions(p: *Parser) !void {...@@ -799,30 +798,23 @@ fn diagnoseIncompleteDefinitions(p: *Parser) !void {
799}798}
800799
801/// root : (decl | assembly ';' | staticAssert)*800/// root : (decl | assembly ';' | staticAssert)*
802pub fn parse(pp: *Preprocessor) Error!Tree {801pub fn parse(pp: *Preprocessor) Compilation.Error!Tree {
802 const gpa = pp.comp.gpa;
803 assert(pp.linemarkers == .none);803 assert(pp.linemarkers == .none);
804 pp.comp.pragmaEvent(.before_parse);804 pp.comp.pragmaEvent(.before_parse);
805805
806 const expected_implicit_typedef_max = 7;806 const expected_implicit_typedef_max = 7;
807 try pp.tokens.ensureUnusedCapacity(pp.gpa, expected_implicit_typedef_max);807 try pp.tokens.ensureUnusedCapacity(gpa, expected_implicit_typedef_max);
808808
809 var p: Parser = .{809 var p: Parser = .{
810 .pp = pp,810 .pp = pp,
811 .comp = pp.comp,811 .comp = pp.comp,
812 .diagnostics = pp.diagnostics,812 .diagnostics = pp.diagnostics,
813 .gpa = pp.comp.gpa,
814 .tree = .{813 .tree = .{
815 .comp = pp.comp,814 .comp = pp.comp,
816 .tokens = undefined, // Set after implicit typedefs815 .tokens = undefined, // Set after implicit typedefs
817 },816 },
818 .tok_ids = pp.tokens.items(.id),817 .tok_ids = pp.tokens.items(.id),
819 .strings = .init(pp.comp.gpa),
820 .labels = .init(pp.comp.gpa),
821 .list_buf = .init(pp.comp.gpa),
822 .decl_buf = .init(pp.comp.gpa),
823 .param_buf = .init(pp.comp.gpa),
824 .enum_buf = .init(pp.comp.gpa),
825 .record_buf = .init(pp.comp.gpa),
826 .string_ids = .{818 .string_ids = .{
827 .declspec_id = try pp.comp.internString("__declspec"),819 .declspec_id = try pp.comp.internString("__declspec"),
828 .main_id = try pp.comp.internString("main"),820 .main_id = try pp.comp.internString("main"),
...@@ -834,18 +826,18 @@ pub fn parse(pp: *Preprocessor) Error!Tree {...@@ -834,18 +826,18 @@ pub fn parse(pp: *Preprocessor) Error!Tree {
834 };826 };
835 errdefer p.tree.deinit();827 errdefer p.tree.deinit();
836 defer {828 defer {
837 p.labels.deinit();829 p.labels.deinit(gpa);
838 p.strings.deinit();830 p.strings.deinit(gpa);
839 p.syms.deinit(pp.comp.gpa);831 p.syms.deinit(gpa);
840 p.list_buf.deinit();832 p.list_buf.deinit(gpa);
841 p.decl_buf.deinit();833 p.decl_buf.deinit(gpa);
842 p.param_buf.deinit();834 p.param_buf.deinit(gpa);
843 p.enum_buf.deinit();835 p.enum_buf.deinit(gpa);
844 p.record_buf.deinit();836 p.record_buf.deinit(gpa);
845 p.record_members.deinit(pp.comp.gpa);837 p.record_members.deinit(gpa);
846 p.attr_buf.deinit(pp.comp.gpa);838 p.attr_buf.deinit(gpa);
847 p.attr_application_buf.deinit(pp.comp.gpa);839 p.attr_application_buf.deinit(gpa);
848 p.tentative_defs.deinit(pp.comp.gpa);840 p.tentative_defs.deinit(gpa);
849 }841 }
850842
851 try p.syms.pushScope(&p);843 try p.syms.pushScope(&p);
...@@ -907,7 +899,7 @@ pub fn parse(pp: *Preprocessor) Error!Tree {...@@ -907,7 +899,7 @@ pub fn parse(pp: *Preprocessor) Error!Tree {
907 },899 },
908 else => |e| return e,900 else => |e| return e,
909 }) |node| {901 }) |node| {
910 try p.decl_buf.append(node);902 try p.decl_buf.append(gpa, node);
911 continue;903 continue;
912 }904 }
913 if (p.eatToken(.semicolon)) |tok| {905 if (p.eatToken(.semicolon)) |tok| {
...@@ -915,7 +907,7 @@ pub fn parse(pp: *Preprocessor) Error!Tree {...@@ -915,7 +907,7 @@ pub fn parse(pp: *Preprocessor) Error!Tree {
915 const empty = try p.tree.addNode(.{ .empty_decl = .{907 const empty = try p.tree.addNode(.{ .empty_decl = .{
916 .semicolon = tok,908 .semicolon = tok,
917 } });909 } });
918 try p.decl_buf.append(empty);910 try p.decl_buf.append(gpa, empty);
919 continue;911 continue;
920 }912 }
921 try p.err(p.tok_i, .expected_external_decl, .{});913 try p.err(p.tok_i, .expected_external_decl, .{});
...@@ -925,7 +917,9 @@ pub fn parse(pp: *Preprocessor) Error!Tree {...@@ -925,7 +917,9 @@ pub fn parse(pp: *Preprocessor) Error!Tree {
925 try p.diagnoseIncompleteDefinitions();917 try p.diagnoseIncompleteDefinitions();
926 }918 }
927919
928 p.tree.root_decls = p.decl_buf.moveToUnmanaged();920 p.tree.root_decls = p.decl_buf;
921 p.decl_buf = .empty;
922
929 if (p.tree.root_decls.items.len == implicit_typedef_count) {923 if (p.tree.root_decls.items.len == implicit_typedef_count) {
930 try p.err(p.tok_i - 1, .empty_translation_unit, .{});924 try p.err(p.tok_i - 1, .empty_translation_unit, .{});
931 }925 }
...@@ -937,9 +931,11 @@ pub fn parse(pp: *Preprocessor) Error!Tree {...@@ -937,9 +931,11 @@ pub fn parse(pp: *Preprocessor) Error!Tree {
937}931}
938932
939fn addImplicitTypedef(p: *Parser, name: []const u8, qt: QualType) !void {933fn addImplicitTypedef(p: *Parser, name: []const u8, qt: QualType) !void {
934 const gpa = p.comp.gpa;
940 const start = p.comp.generated_buf.items.len;935 const start = p.comp.generated_buf.items.len;
941 try p.comp.generated_buf.appendSlice(p.comp.gpa, name);936 try p.comp.generated_buf.ensureUnusedCapacity(gpa, name.len + 1);
942 try p.comp.generated_buf.append(p.comp.gpa, '\n');937 p.comp.generated_buf.appendSliceAssumeCapacity(name);
938 p.comp.generated_buf.appendAssumeCapacity('\n');
943939
944 const name_tok: u32 = @intCast(p.pp.tokens.len);940 const name_tok: u32 = @intCast(p.pp.tokens.len);
945 p.pp.tokens.appendAssumeCapacity(.{ .id = .identifier, .loc = .{941 p.pp.tokens.appendAssumeCapacity(.{ .id = .identifier, .loc = .{
...@@ -958,13 +954,13 @@ fn addImplicitTypedef(p: *Parser, name: []const u8, qt: QualType) !void {...@@ -958,13 +954,13 @@ fn addImplicitTypedef(p: *Parser, name: []const u8, qt: QualType) !void {
958 });954 });
959955
960 const interned_name = try p.comp.internString(name);956 const interned_name = try p.comp.internString(name);
961 const typedef_qt = (try p.comp.type_store.put(p.gpa, .{ .typedef = .{957 const typedef_qt = (try p.comp.type_store.put(gpa, .{ .typedef = .{
962 .base = qt,958 .base = qt,
963 .name = interned_name,959 .name = interned_name,
964 .decl_node = node,960 .decl_node = node,
965 } })).withQualifiers(qt);961 } })).withQualifiers(qt);
966 try p.syms.defineTypedef(p, interned_name, typedef_qt, name_tok, node);962 try p.syms.defineTypedef(p, interned_name, typedef_qt, name_tok, node);
967 try p.decl_buf.append(node);963 try p.decl_buf.append(gpa, node);
968}964}
969965
970fn skipToPragmaSentinel(p: *Parser) void {966fn skipToPragmaSentinel(p: *Parser) void {
...@@ -1082,6 +1078,7 @@ fn typedefDefined(p: *Parser, name: StringId, ty: QualType) void {...@@ -1082,6 +1078,7 @@ fn typedefDefined(p: *Parser, name: StringId, ty: QualType) void {
1082/// : declSpec (initDeclarator ( ',' initDeclarator)*)? ';'1078/// : declSpec (initDeclarator ( ',' initDeclarator)*)? ';'
1083/// | declSpec declarator decl* compoundStmt1079/// | declSpec declarator decl* compoundStmt
1084fn decl(p: *Parser) Error!bool {1080fn decl(p: *Parser) Error!bool {
1081 const gpa = p.comp.gpa;
1085 _ = try p.pragma();1082 _ = try p.pragma();
1086 const first_tok = p.tok_i;1083 const first_tok = p.tok_i;
1087 const attr_buf_top = p.attr_buf.len;1084 const attr_buf_top = p.attr_buf.len;
...@@ -1116,7 +1113,7 @@ fn decl(p: *Parser) Error!bool {...@@ -1116,7 +1113,7 @@ fn decl(p: *Parser) Error!bool {
1116 };1113 };
1117 if (decl_spec.noreturn) |tok| {1114 if (decl_spec.noreturn) |tok| {
1118 const attr = Attribute{ .tag = .noreturn, .args = .{ .noreturn = .{} }, .syntax = .keyword };1115 const attr = Attribute{ .tag = .noreturn, .args = .{ .noreturn = .{} }, .syntax = .keyword };
1119 try p.attr_buf.append(p.gpa, .{ .attr = attr, .tok = tok });1116 try p.attr_buf.append(gpa, .{ .attr = attr, .tok = tok });
1120 }1117 }
11211118
1122 var decl_node = try p.tree.addNode(.{ .empty_decl = .{1119 var decl_node = try p.tree.addNode(.{ .empty_decl = .{
...@@ -1194,7 +1191,7 @@ fn decl(p: *Parser) Error!bool {...@@ -1194,7 +1191,7 @@ fn decl(p: *Parser) Error!bool {
1194 const func_qt = init_d.d.qt.base(p.comp).qt;1191 const func_qt = init_d.d.qt.base(p.comp).qt;
1195 const params_len = func_qt.get(p.comp, .func).?.params.len;1192 const params_len = func_qt.get(p.comp, .func).?.params.len;
11961193
1197 const new_params = try p.param_buf.addManyAsSlice(params_len);1194 const new_params = try p.param_buf.addManyAsSlice(gpa, params_len);
1198 for (new_params) |*new_param| {1195 for (new_params) |*new_param| {
1199 new_param.name = .empty;1196 new_param.name = .empty;
1200 }1197 }
...@@ -1280,7 +1277,7 @@ fn decl(p: *Parser) Error!bool {...@@ -1280,7 +1277,7 @@ fn decl(p: *Parser) Error!bool {
1280 }1277 }
1281 }1278 }
1282 // Update the functio type to contain the declared parameters.1279 // Update the functio type to contain the declared parameters.
1283 p.func.qt = try p.comp.type_store.put(p.gpa, .{ .func = .{1280 p.func.qt = try p.comp.type_store.put(gpa, .{ .func = .{
1284 .kind = .normal,1281 .kind = .normal,
1285 .params = new_params,1282 .params = new_params,
1286 .return_type = func_ty.return_type,1283 .return_type = func_ty.return_type,
...@@ -1293,7 +1290,7 @@ fn decl(p: *Parser) Error!bool {...@@ -1293,7 +1290,7 @@ fn decl(p: *Parser) Error!bool {
1293 }1290 }
12941291
1295 // bypass redefinition check to avoid duplicate errors1292 // bypass redefinition check to avoid duplicate errors
1296 try p.syms.define(p.gpa, .{1293 try p.syms.define(gpa, .{
1297 .kind = .def,1294 .kind = .def,
1298 .name = param.name,1295 .name = param.name,
1299 .tok = param.name_tok,1296 .tok = param.name_tok,
...@@ -1334,7 +1331,7 @@ fn decl(p: *Parser) Error!bool {...@@ -1334,7 +1331,7 @@ fn decl(p: *Parser) Error!bool {
1334 .definition = null,1331 .definition = null,
1335 } }, @intFromEnum(decl_node));1332 } }, @intFromEnum(decl_node));
13361333
1337 try p.decl_buf.append(decl_node);1334 try p.decl_buf.append(gpa, decl_node);
13381335
1339 // check gotos1336 // check gotos
1340 if (func.qt == null) {1337 if (func.qt == null) {
...@@ -1382,7 +1379,7 @@ fn decl(p: *Parser) Error!bool {...@@ -1382,7 +1379,7 @@ fn decl(p: *Parser) Error!bool {
1382 if (node_qt.get(p.comp, .array)) |array_ty| {1379 if (node_qt.get(p.comp, .array)) |array_ty| {
1383 if (array_ty.len == .incomplete) {1380 if (array_ty.len == .incomplete) {
1384 // Create tentative array node with fixed type.1381 // Create tentative array node with fixed type.
1385 node_qt = try p.comp.type_store.put(p.gpa, .{ .array = .{1382 node_qt = try p.comp.type_store.put(gpa, .{ .array = .{
1386 .elem = array_ty.elem,1383 .elem = array_ty.elem,
1387 .len = .{ .fixed = 1 },1384 .len = .{ .fixed = 1 },
1388 } });1385 } });
...@@ -1408,14 +1405,14 @@ fn decl(p: *Parser) Error!bool {...@@ -1408,14 +1405,14 @@ fn decl(p: *Parser) Error!bool {
1408 },1405 },
1409 }, @intFromEnum(decl_node));1406 }, @intFromEnum(decl_node));
1410 }1407 }
1411 try p.decl_buf.append(decl_node);1408 try p.decl_buf.append(gpa, decl_node);
14121409
1413 const interned_name = try p.comp.internString(p.tokSlice(init_d.d.name));1410 const interned_name = try p.comp.internString(p.tokSlice(init_d.d.name));
1414 if (decl_spec.storage_class == .typedef) {1411 if (decl_spec.storage_class == .typedef) {
1415 const typedef_qt = if (init_d.d.qt.isInvalid())1412 const typedef_qt = if (init_d.d.qt.isInvalid())
1416 init_d.d.qt1413 init_d.d.qt
1417 else1414 else
1418 (try p.comp.type_store.put(p.gpa, .{ .typedef = .{1415 (try p.comp.type_store.put(gpa, .{ .typedef = .{
1419 .base = init_d.d.qt,1416 .base = init_d.d.qt,
1420 .name = interned_name,1417 .name = interned_name,
1421 .decl_node = decl_node,1418 .decl_node = decl_node,
...@@ -1500,6 +1497,7 @@ fn staticAssertMessage(p: *Parser, cond_node: Node.Index, maybe_message: ?Result...@@ -1500,6 +1497,7 @@ fn staticAssertMessage(p: *Parser, cond_node: Node.Index, maybe_message: ?Result
1500/// : keyword_static_assert '(' integerConstExpr (',' STRING_LITERAL)? ')' ';'1497/// : keyword_static_assert '(' integerConstExpr (',' STRING_LITERAL)? ')' ';'
1501/// | keyword_c23_static_assert '(' integerConstExpr (',' STRING_LITERAL)? ')' ';'1498/// | keyword_c23_static_assert '(' integerConstExpr (',' STRING_LITERAL)? ')' ';'
1502fn staticAssert(p: *Parser) Error!bool {1499fn staticAssert(p: *Parser) Error!bool {
1500 const gpa = p.comp.gpa;
1503 const static_assert = p.eatToken(.keyword_static_assert) orelse p.eatToken(.keyword_c23_static_assert) orelse return false;1501 const static_assert = p.eatToken(.keyword_static_assert) orelse p.eatToken(.keyword_c23_static_assert) orelse return false;
1504 const l_paren = try p.expectToken(.l_paren);1502 const l_paren = try p.expectToken(.l_paren);
1505 const res_token = p.tok_i;1503 const res_token = p.tok_i;
...@@ -1539,7 +1537,7 @@ fn staticAssert(p: *Parser) Error!bool {...@@ -1539,7 +1537,7 @@ fn staticAssert(p: *Parser) Error!bool {
1539 }1537 }
1540 } else {1538 } else {
1541 if (!res.val.toBool(p.comp)) {1539 if (!res.val.toBool(p.comp)) {
1542 var sf = std.heap.stackFallback(1024, p.gpa);1540 var sf = std.heap.stackFallback(1024, gpa);
1543 var allocating: std.Io.Writer.Allocating = .init(sf.get());1541 var allocating: std.Io.Writer.Allocating = .init(sf.get());
1544 defer allocating.deinit();1542 defer allocating.deinit();
15451543
...@@ -1558,7 +1556,7 @@ fn staticAssert(p: *Parser) Error!bool {...@@ -1558,7 +1556,7 @@ fn staticAssert(p: *Parser) Error!bool {
1558 .message = if (str) |some| some.node else null,1556 .message = if (str) |some| some.node else null,
1559 },1557 },
1560 });1558 });
1561 try p.decl_buf.append(node);1559 try p.decl_buf.append(gpa, node);
1562 return true;1560 return true;
1563}1561}
15641562
...@@ -1632,6 +1630,7 @@ pub const DeclSpec = struct {...@@ -1632,6 +1630,7 @@ pub const DeclSpec = struct {
1632/// : keyword_typeof '(' typeName ')'1630/// : keyword_typeof '(' typeName ')'
1633/// | keyword_typeof '(' expr ')'1631/// | keyword_typeof '(' expr ')'
1634fn typeof(p: *Parser) Error!?QualType {1632fn typeof(p: *Parser) Error!?QualType {
1633 const gpa = p.comp.gpa;
1635 var unqual = false;1634 var unqual = false;
1636 switch (p.tok_ids[p.tok_i]) {1635 switch (p.tok_ids[p.tok_i]) {
1637 .keyword_typeof, .keyword_typeof1, .keyword_typeof2 => p.tok_i += 1,1636 .keyword_typeof, .keyword_typeof1, .keyword_typeof2 => p.tok_i += 1,
...@@ -1646,7 +1645,7 @@ fn typeof(p: *Parser) Error!?QualType {...@@ -1646,7 +1645,7 @@ fn typeof(p: *Parser) Error!?QualType {
1646 try p.expectClosing(l_paren, .r_paren);1645 try p.expectClosing(l_paren, .r_paren);
1647 if (qt.isInvalid()) return null;1646 if (qt.isInvalid()) return null;
16481647
1649 return (try p.comp.type_store.put(p.gpa, .{ .typeof = .{1648 return (try p.comp.type_store.put(gpa, .{ .typeof = .{
1650 .base = qt,1649 .base = qt,
1651 .expr = null,1650 .expr = null,
1652 } })).withQualifiers(qt);1651 } })).withQualifiers(qt);
...@@ -1655,7 +1654,7 @@ fn typeof(p: *Parser) Error!?QualType {...@@ -1655,7 +1654,7 @@ fn typeof(p: *Parser) Error!?QualType {
1655 try p.expectClosing(l_paren, .r_paren);1654 try p.expectClosing(l_paren, .r_paren);
1656 if (typeof_expr.qt.isInvalid()) return null;1655 if (typeof_expr.qt.isInvalid()) return null;
16571656
1658 const typeof_qt = try p.comp.type_store.put(p.gpa, .{ .typeof = .{1657 const typeof_qt = try p.comp.type_store.put(gpa, .{ .typeof = .{
1659 .base = typeof_expr.qt,1658 .base = typeof_expr.qt,
1660 .expr = typeof_expr.node,1659 .expr = typeof_expr.node,
1661 } });1660 } });
...@@ -1704,7 +1703,7 @@ fn declSpec(p: *Parser) Error!?DeclSpec {...@@ -1704,7 +1703,7 @@ fn declSpec(p: *Parser) Error!?DeclSpec {
1704 continue;1703 continue;
1705 },1704 },
1706 .keyword_forceinline, .keyword_forceinline2 => {1705 .keyword_forceinline, .keyword_forceinline2 => {
1707 try p.attr_buf.append(p.gpa, .{1706 try p.attr_buf.append(p.comp.gpa, .{
1708 .attr = .{ .tag = .always_inline, .args = .{ .always_inline = .{} }, .syntax = .keyword },1707 .attr = .{ .tag = .always_inline, .args = .{ .always_inline = .{} }, .syntax = .keyword },
1709 .tok = p.tok_i,1708 .tok = p.tok_i,
1710 });1709 });
...@@ -1883,11 +1882,12 @@ fn diagnose(p: *Parser, attr: Attribute.Tag, arguments: *Attribute.Arguments, ar...@@ -1883,11 +1882,12 @@ fn diagnose(p: *Parser, attr: Attribute.Tag, arguments: *Attribute.Arguments, ar
1883/// attributeList : (attribute (',' attribute)*)?1882/// attributeList : (attribute (',' attribute)*)?
1884fn gnuAttributeList(p: *Parser) Error!void {1883fn gnuAttributeList(p: *Parser) Error!void {
1885 if (p.tok_ids[p.tok_i] == .r_paren) return;1884 if (p.tok_ids[p.tok_i] == .r_paren) return;
1885 const gpa = p.comp.gpa;
18861886
1887 if (try p.attribute(.gnu, null)) |attr| try p.attr_buf.append(p.gpa, attr);1887 if (try p.attribute(.gnu, null)) |attr| try p.attr_buf.append(gpa, attr);
1888 while (p.tok_ids[p.tok_i] != .r_paren) {1888 while (p.tok_ids[p.tok_i] != .r_paren) {
1889 _ = try p.expectToken(.comma);1889 _ = try p.expectToken(.comma);
1890 if (try p.attribute(.gnu, null)) |attr| try p.attr_buf.append(p.gpa, attr);1890 if (try p.attribute(.gnu, null)) |attr| try p.attr_buf.append(gpa, attr);
1891 }1891 }
1892}1892}
18931893
...@@ -1900,14 +1900,14 @@ fn c23AttributeList(p: *Parser) Error!void {...@@ -1900,14 +1900,14 @@ fn c23AttributeList(p: *Parser) Error!void {
1900 } else {1900 } else {
1901 p.tok_i -= 1;1901 p.tok_i -= 1;
1902 }1902 }
1903 if (try p.attribute(.c23, namespace)) |attr| try p.attr_buf.append(p.gpa, attr);1903 if (try p.attribute(.c23, namespace)) |attr| try p.attr_buf.append(p.comp.gpa, attr);
1904 _ = p.eatToken(.comma);1904 _ = p.eatToken(.comma);
1905 }1905 }
1906}1906}
19071907
1908fn msvcAttributeList(p: *Parser) Error!void {1908fn msvcAttributeList(p: *Parser) Error!void {
1909 while (p.tok_ids[p.tok_i] != .r_paren) {1909 while (p.tok_ids[p.tok_i] != .r_paren) {
1910 if (try p.attribute(.declspec, null)) |attr| try p.attr_buf.append(p.gpa, attr);1910 if (try p.attribute(.declspec, null)) |attr| try p.attr_buf.append(p.comp.gpa, attr);
1911 _ = p.eatToken(.comma);1911 _ = p.eatToken(.comma);
1912 }1912 }
1913}1913}
...@@ -1979,6 +1979,7 @@ fn attributeSpecifierExtra(p: *Parser, declarator_name: ?TokenIndex) Error!void...@@ -1979,6 +1979,7 @@ fn attributeSpecifierExtra(p: *Parser, declarator_name: ?TokenIndex) Error!void
1979fn initDeclarator(p: *Parser, decl_spec: *DeclSpec, attr_buf_top: usize, decl_node: Node.Index) Error!?InitDeclarator {1979fn initDeclarator(p: *Parser, decl_spec: *DeclSpec, attr_buf_top: usize, decl_node: Node.Index) Error!?InitDeclarator {
1980 const this_attr_buf_top = p.attr_buf.len;1980 const this_attr_buf_top = p.attr_buf.len;
1981 defer p.attr_buf.len = this_attr_buf_top;1981 defer p.attr_buf.len = this_attr_buf_top;
1982 const gpa = p.comp.gpa;
19821983
1983 var init_d = InitDeclarator{1984 var init_d = InitDeclarator{
1984 .d = (try p.declarator(decl_spec.qt, .normal)) orelse return null,1985 .d = (try p.declarator(decl_spec.qt, .normal)) orelse return null,
...@@ -2081,7 +2082,7 @@ fn initDeclarator(p: *Parser, decl_spec: *DeclSpec, attr_buf_top: usize, decl_no...@@ -2081,7 +2082,7 @@ fn initDeclarator(p: *Parser, decl_spec: *DeclSpec, attr_buf_top: usize, decl_no
2081 if (base_array_ty.len == .incomplete) if (init_list_expr.qt.get(p.comp, .array)) |init_array_ty| {2082 if (base_array_ty.len == .incomplete) if (init_list_expr.qt.get(p.comp, .array)) |init_array_ty| {
2082 switch (init_array_ty.len) {2083 switch (init_array_ty.len) {
2083 .fixed, .static => |len| {2084 .fixed, .static => |len| {
2084 init_d.d.qt = (try p.comp.type_store.put(p.gpa, .{ .array = .{2085 init_d.d.qt = (try p.comp.type_store.put(gpa, .{ .array = .{
2085 .elem = base_array_ty.elem,2086 .elem = base_array_ty.elem,
2086 .len = .{ .fixed = len },2087 .len = .{ .fixed = len },
2087 } })).withQualifiers(init_d.d.qt);2088 } })).withQualifiers(init_d.d.qt);
...@@ -2132,11 +2133,11 @@ fn initDeclarator(p: *Parser, decl_spec: *DeclSpec, attr_buf_top: usize, decl_no...@@ -2132,11 +2133,11 @@ fn initDeclarator(p: *Parser, decl_spec: *DeclSpec, attr_buf_top: usize, decl_no
2132 break :incomplete;2133 break :incomplete;
2133 },2134 },
2134 .@"struct", .@"union" => |record_ty| {2135 .@"struct", .@"union" => |record_ty| {
2135 _ = try p.tentative_defs.getOrPutValue(p.gpa, record_ty.name, init_d.d.name);2136 _ = try p.tentative_defs.getOrPutValue(gpa, record_ty.name, init_d.d.name);
2136 break :incomplete;2137 break :incomplete;
2137 },2138 },
2138 .@"enum" => |enum_ty| {2139 .@"enum" => |enum_ty| {
2139 _ = try p.tentative_defs.getOrPutValue(p.gpa, enum_ty.name, init_d.d.name);2140 _ = try p.tentative_defs.getOrPutValue(gpa, enum_ty.name, init_d.d.name);
2140 break :incomplete;2141 break :incomplete;
2141 },2142 },
2142 else => {},2143 else => {},
...@@ -2234,6 +2235,7 @@ fn typeSpec(p: *Parser, builder: *TypeStore.Builder) Error!bool {...@@ -2234,6 +2235,7 @@ fn typeSpec(p: *Parser, builder: *TypeStore.Builder) Error!bool {
2234 => {2235 => {
2235 const align_tok = p.tok_i;2236 const align_tok = p.tok_i;
2236 p.tok_i += 1;2237 p.tok_i += 1;
2238 const gpa = p.comp.gpa;
2237 const l_paren = try p.expectToken(.l_paren);2239 const l_paren = try p.expectToken(.l_paren);
2238 const typename_start = p.tok_i;2240 const typename_start = p.tok_i;
2239 if (try p.typeName()) |inner_qt| {2241 if (try p.typeName()) |inner_qt| {
...@@ -2241,7 +2243,7 @@ fn typeSpec(p: *Parser, builder: *TypeStore.Builder) Error!bool {...@@ -2241,7 +2243,7 @@ fn typeSpec(p: *Parser, builder: *TypeStore.Builder) Error!bool {
2241 try p.err(typename_start, .invalid_alignof, .{inner_qt});2243 try p.err(typename_start, .invalid_alignof, .{inner_qt});
2242 }2244 }
2243 const alignment = Attribute.Alignment{ .requested = inner_qt.alignof(p.comp) };2245 const alignment = Attribute.Alignment{ .requested = inner_qt.alignof(p.comp) };
2244 try p.attr_buf.append(p.gpa, .{2246 try p.attr_buf.append(gpa, .{
2245 .attr = .{ .tag = .aligned, .args = .{2247 .attr = .{ .tag = .aligned, .args = .{
2246 .aligned = .{ .alignment = alignment, .__name_tok = align_tok },2248 .aligned = .{ .alignment = alignment, .__name_tok = align_tok },
2247 }, .syntax = .keyword },2249 }, .syntax = .keyword },
...@@ -2257,7 +2259,7 @@ fn typeSpec(p: *Parser, builder: *TypeStore.Builder) Error!bool {...@@ -2257,7 +2259,7 @@ fn typeSpec(p: *Parser, builder: *TypeStore.Builder) Error!bool {
2257 return error.ParsingFailed;2259 return error.ParsingFailed;
2258 }2260 }
2259 args.aligned.alignment.?.node = .pack(res.node);2261 args.aligned.alignment.?.node = .pack(res.node);
2260 try p.attr_buf.append(p.gpa, .{2262 try p.attr_buf.append(gpa, .{
2261 .attr = .{ .tag = .aligned, .args = args, .syntax = .keyword },2263 .attr = .{ .tag = .aligned, .args = args, .syntax = .keyword },
2262 .tok = align_tok,2264 .tok = align_tok,
2263 });2265 });
...@@ -2336,7 +2338,7 @@ fn getAnonymousName(p: *Parser, kind_tok: TokenIndex) !StringId {...@@ -2336,7 +2338,7 @@ fn getAnonymousName(p: *Parser, kind_tok: TokenIndex) !StringId {
2336 else => "record field",2338 else => "record field",
2337 };2339 };
23382340
2339 var arena = p.comp.type_store.anon_name_arena.promote(p.gpa);2341 var arena = p.comp.type_store.anon_name_arena.promote(p.comp.gpa);
2340 defer p.comp.type_store.anon_name_arena = arena.state;2342 defer p.comp.type_store.anon_name_arena = arena.state;
2341 const str = try std.fmt.allocPrint(2343 const str = try std.fmt.allocPrint(
2342 arena.allocator(),2344 arena.allocator(),
...@@ -2350,6 +2352,7 @@ fn getAnonymousName(p: *Parser, kind_tok: TokenIndex) !StringId {...@@ -2350,6 +2352,7 @@ fn getAnonymousName(p: *Parser, kind_tok: TokenIndex) !StringId {
2350/// : (keyword_struct | keyword_union) IDENTIFIER? { recordDecls }2352/// : (keyword_struct | keyword_union) IDENTIFIER? { recordDecls }
2351/// | (keyword_struct | keyword_union) IDENTIFIER2353/// | (keyword_struct | keyword_union) IDENTIFIER
2352fn recordSpec(p: *Parser) Error!QualType {2354fn recordSpec(p: *Parser) Error!QualType {
2355 const gpa = p.comp.gpa;
2353 const starting_pragma_pack = p.pragma_pack;2356 const starting_pragma_pack = p.pragma_pack;
2354 const kind_tok = p.tok_i;2357 const kind_tok = p.tok_i;
2355 const is_struct = p.tok_ids[kind_tok] == .keyword_struct;2358 const is_struct = p.tok_ids[kind_tok] == .keyword_struct;
...@@ -2358,7 +2361,7 @@ fn recordSpec(p: *Parser) Error!QualType {...@@ -2358,7 +2361,7 @@ fn recordSpec(p: *Parser) Error!QualType {
2358 defer p.attr_buf.len = attr_buf_top;2361 defer p.attr_buf.len = attr_buf_top;
2359 try p.attributeSpecifier();2362 try p.attributeSpecifier();
23602363
2361 const reserved_index = try p.tree.nodes.addOne(p.gpa);2364 const reserved_index = try p.tree.nodes.addOne(gpa);
23622365
2363 const maybe_ident = try p.eatIdentifier();2366 const maybe_ident = try p.eatIdentifier();
2364 const l_brace = p.eatToken(.l_brace) orelse {2367 const l_brace = p.eatToken(.l_brace) orelse {
...@@ -2378,13 +2381,13 @@ fn recordSpec(p: *Parser) Error!QualType {...@@ -2378,13 +2381,13 @@ fn recordSpec(p: *Parser) Error!QualType {
2378 .decl_node = @enumFromInt(reserved_index),2381 .decl_node = @enumFromInt(reserved_index),
2379 .fields = &.{},2382 .fields = &.{},
2380 };2383 };
2381 const record_qt = try p.comp.type_store.put(p.gpa, if (is_struct)2384 const record_qt = try p.comp.type_store.put(gpa, if (is_struct)
2382 .{ .@"struct" = record_ty }2385 .{ .@"struct" = record_ty }
2383 else2386 else
2384 .{ .@"union" = record_ty });2387 .{ .@"union" = record_ty });
23852388
2386 const attributed_qt = try Attribute.applyTypeAttributes(p, record_qt, attr_buf_top, null);2389 const attributed_qt = try Attribute.applyTypeAttributes(p, record_qt, attr_buf_top, null);
2387 try p.syms.define(p.gpa, .{2390 try p.syms.define(gpa, .{
2388 .kind = if (is_struct) .@"struct" else .@"union",2391 .kind = if (is_struct) .@"struct" else .@"union",
2389 .name = interned_name,2392 .name = interned_name,
2390 .tok = ident,2393 .tok = ident,
...@@ -2401,7 +2404,7 @@ fn recordSpec(p: *Parser) Error!QualType {...@@ -2401,7 +2404,7 @@ fn recordSpec(p: *Parser) Error!QualType {
2401 .{ .struct_forward_decl = fw }2404 .{ .struct_forward_decl = fw }
2402 else2405 else
2403 .{ .union_forward_decl = fw }, reserved_index);2406 .{ .union_forward_decl = fw }, reserved_index);
2404 try p.decl_buf.append(@enumFromInt(reserved_index));2407 try p.decl_buf.append(gpa, @enumFromInt(reserved_index));
2405 return attributed_qt;2408 return attributed_qt;
2406 }2409 }
2407 };2410 };
...@@ -2435,7 +2438,7 @@ fn recordSpec(p: *Parser) Error!QualType {...@@ -2435,7 +2438,7 @@ fn recordSpec(p: *Parser) Error!QualType {
2435 .layout = null,2438 .layout = null,
2436 .fields = &.{},2439 .fields = &.{},
2437 };2440 };
2438 const record_qt = try p.comp.type_store.put(p.gpa, if (is_struct)2441 const record_qt = try p.comp.type_store.put(gpa, if (is_struct)
2439 .{ .@"struct" = record_ty }2442 .{ .@"struct" = record_ty }
2440 else2443 else
2441 .{ .@"union" = record_ty });2444 .{ .@"union" = record_ty });
...@@ -2443,7 +2446,7 @@ fn recordSpec(p: *Parser) Error!QualType {...@@ -2443,7 +2446,7 @@ fn recordSpec(p: *Parser) Error!QualType {
2443 // declare a symbol for the type2446 // declare a symbol for the type
2444 // We need to replace the symbol's type if it has attributes2447 // We need to replace the symbol's type if it has attributes
2445 if (maybe_ident != null) {2448 if (maybe_ident != null) {
2446 try p.syms.define(p.gpa, .{2449 try p.syms.define(gpa, .{
2447 .kind = if (is_struct) .@"struct" else .@"union",2450 .kind = if (is_struct) .@"struct" else .@"union",
2448 .name = record_ty.name,2451 .name = record_ty.name,
2449 .tok = maybe_ident.?,2452 .tok = maybe_ident.?,
...@@ -2455,7 +2458,7 @@ fn recordSpec(p: *Parser) Error!QualType {...@@ -2455,7 +2458,7 @@ fn recordSpec(p: *Parser) Error!QualType {
2455 break :blk .{ record_ty, record_qt };2458 break :blk .{ record_ty, record_qt };
2456 };2459 };
24572460
2458 try p.decl_buf.append(@enumFromInt(reserved_index));2461 try p.decl_buf.append(gpa, @enumFromInt(reserved_index));
2459 const decl_buf_top = p.decl_buf.items.len;2462 const decl_buf_top = p.decl_buf.items.len;
2460 const record_buf_top = p.record_buf.items.len;2463 const record_buf_top = p.record_buf.items.len;
2461 errdefer p.decl_buf.items.len = decl_buf_top - 1;2464 errdefer p.decl_buf.items.len = decl_buf_top - 1;
...@@ -2512,10 +2515,10 @@ fn recordSpec(p: *Parser) Error!QualType {...@@ -2512,10 +2515,10 @@ fn recordSpec(p: *Parser) Error!QualType {
2512 const base_type = qt.base(p.comp);2515 const base_type = qt.base(p.comp);
2513 if (is_struct) {2516 if (is_struct) {
2514 std.debug.assert(base_type.type.@"struct".name == record_ty.name);2517 std.debug.assert(base_type.type.@"struct".name == record_ty.name);
2515 try p.comp.type_store.set(p.gpa, .{ .@"struct" = record_ty }, @intFromEnum(base_type.qt._index));2518 try p.comp.type_store.set(gpa, .{ .@"struct" = record_ty }, @intFromEnum(base_type.qt._index));
2516 } else {2519 } else {
2517 std.debug.assert(base_type.type.@"union".name == record_ty.name);2520 std.debug.assert(base_type.type.@"union".name == record_ty.name);
2518 try p.comp.type_store.set(p.gpa, .{ .@"union" = record_ty }, @intFromEnum(base_type.qt._index));2521 try p.comp.type_store.set(gpa, .{ .@"union" = record_ty }, @intFromEnum(base_type.qt._index));
2519 }2522 }
2520 break :blk false;2523 break :blk false;
2521 };2524 };
...@@ -2603,6 +2606,7 @@ fn recordDecls(p: *Parser) Error!void {...@@ -2603,6 +2606,7 @@ fn recordDecls(p: *Parser) Error!void {
2603/// recordDecl : typeSpec+ (recordDeclarator (',' recordDeclarator)*)?2606/// recordDecl : typeSpec+ (recordDeclarator (',' recordDeclarator)*)?
2604/// recordDeclarator : declarator (':' integerConstExpr)?2607/// recordDeclarator : declarator (':' integerConstExpr)?
2605fn recordDecl(p: *Parser) Error!bool {2608fn recordDecl(p: *Parser) Error!bool {
2609 const gpa = p.comp.gpa;
2606 const attr_buf_top = p.attr_buf.len;2610 const attr_buf_top = p.attr_buf.len;
2607 defer p.attr_buf.len = attr_buf_top;2611 defer p.attr_buf.len = attr_buf_top;
26082612
...@@ -2698,7 +2702,7 @@ fn recordDecl(p: *Parser) Error!bool {...@@ -2698,7 +2702,7 @@ fn recordDecl(p: *Parser) Error!bool {
26982702
2699 const attr_index: u32 = @intCast(p.comp.type_store.attributes.items.len);2703 const attr_index: u32 = @intCast(p.comp.type_store.attributes.items.len);
2700 const attr_len: u32 = @intCast(to_append.len);2704 const attr_len: u32 = @intCast(to_append.len);
2701 try p.comp.type_store.attributes.appendSlice(p.gpa, to_append);2705 try p.comp.type_store.attributes.appendSlice(gpa, to_append);
27022706
2703 if (name_tok == 0 and bits == null) unnamed: {2707 if (name_tok == 0 and bits == null) unnamed: {
2704 var is_typedef = false;2708 var is_typedef = false;
...@@ -2717,7 +2721,7 @@ fn recordDecl(p: *Parser) Error!bool {...@@ -2717,7 +2721,7 @@ fn recordDecl(p: *Parser) Error!bool {
2717 try p.err(first_tok, .anonymous_struct, .{});2721 try p.err(first_tok, .anonymous_struct, .{});
2718 }2722 }
2719 // An anonymous record appears as indirect fields on the parent2723 // An anonymous record appears as indirect fields on the parent
2720 try p.record_buf.append(.{2724 try p.record_buf.append(gpa, .{
2721 .name = try p.getAnonymousName(first_tok),2725 .name = try p.getAnonymousName(first_tok),
2722 .qt = qt,2726 .qt = qt,
2723 ._attr_index = attr_index,2727 ._attr_index = attr_index,
...@@ -2731,7 +2735,7 @@ fn recordDecl(p: *Parser) Error!bool {...@@ -2731,7 +2735,7 @@ fn recordDecl(p: *Parser) Error!bool {
2731 .bit_width = null,2735 .bit_width = null,
2732 },2736 },
2733 });2737 });
2734 try p.decl_buf.append(node);2738 try p.decl_buf.append(gpa, node);
2735 try p.record.addFieldsFromAnonymous(p, record_ty);2739 try p.record.addFieldsFromAnonymous(p, record_ty);
2736 break; // must be followed by a semicolon2740 break; // must be followed by a semicolon
2737 },2741 },
...@@ -2746,7 +2750,7 @@ fn recordDecl(p: *Parser) Error!bool {...@@ -2746,7 +2750,7 @@ fn recordDecl(p: *Parser) Error!bool {
2746 continue;2750 continue;
2747 } else {2751 } else {
2748 const interned_name = if (name_tok != 0) try p.comp.internString(p.tokSlice(name_tok)) else try p.getAnonymousName(first_tok);2752 const interned_name = if (name_tok != 0) try p.comp.internString(p.tokSlice(name_tok)) else try p.getAnonymousName(first_tok);
2749 try p.record_buf.append(.{2753 try p.record_buf.append(gpa, .{
2750 .name = interned_name,2754 .name = interned_name,
2751 .qt = qt,2755 .qt = qt,
2752 .name_tok = name_tok,2756 .name_tok = name_tok,
...@@ -2762,7 +2766,7 @@ fn recordDecl(p: *Parser) Error!bool {...@@ -2762,7 +2766,7 @@ fn recordDecl(p: *Parser) Error!bool {
2762 .bit_width = bits_node,2766 .bit_width = bits_node,
2763 },2767 },
2764 });2768 });
2765 try p.decl_buf.append(node);2769 try p.decl_buf.append(gpa, node);
2766 }2770 }
27672771
2768 if (!qt.isInvalid()) {2772 if (!qt.isInvalid()) {
...@@ -2834,6 +2838,7 @@ fn specQual(p: *Parser) Error!?QualType {...@@ -2834,6 +2838,7 @@ fn specQual(p: *Parser) Error!?QualType {
2834/// : keyword_enum IDENTIFIER? (: typeName)? { enumerator (',' enumerator)? ',') }2838/// : keyword_enum IDENTIFIER? (: typeName)? { enumerator (',' enumerator)? ',') }
2835/// | keyword_enum IDENTIFIER (: typeName)?2839/// | keyword_enum IDENTIFIER (: typeName)?
2836fn enumSpec(p: *Parser) Error!QualType {2840fn enumSpec(p: *Parser) Error!QualType {
2841 const gpa = p.comp.gpa;
2837 const enum_tok = p.tok_i;2842 const enum_tok = p.tok_i;
2838 p.tok_i += 1;2843 p.tok_i += 1;
2839 const attr_buf_top = p.attr_buf.len;2844 const attr_buf_top = p.attr_buf.len;
...@@ -2864,7 +2869,7 @@ fn enumSpec(p: *Parser) Error!QualType {...@@ -2864,7 +2869,7 @@ fn enumSpec(p: *Parser) Error!QualType {
2864 break :fixed fixed;2869 break :fixed fixed;
2865 } else null;2870 } else null;
28662871
2867 const reserved_index = try p.tree.nodes.addOne(p.gpa);2872 const reserved_index = try p.tree.nodes.addOne(gpa);
28682873
2869 const l_brace = p.eatToken(.l_brace) orelse {2874 const l_brace = p.eatToken(.l_brace) orelse {
2870 const ident = maybe_ident orelse {2875 const ident = maybe_ident orelse {
...@@ -2879,7 +2884,7 @@ fn enumSpec(p: *Parser) Error!QualType {...@@ -2879,7 +2884,7 @@ fn enumSpec(p: *Parser) Error!QualType {
2879 try p.checkEnumFixedTy(fixed_qt, ident, prev);2884 try p.checkEnumFixedTy(fixed_qt, ident, prev);
2880 return prev.qt;2885 return prev.qt;
2881 } else {2886 } else {
2882 const enum_qt = try p.comp.type_store.put(p.gpa, .{ .@"enum" = .{2887 const enum_qt = try p.comp.type_store.put(gpa, .{ .@"enum" = .{
2883 .name = interned_name,2888 .name = interned_name,
2884 .tag = fixed_qt,2889 .tag = fixed_qt,
2885 .fixed = fixed_qt != null,2890 .fixed = fixed_qt != null,
...@@ -2889,7 +2894,7 @@ fn enumSpec(p: *Parser) Error!QualType {...@@ -2889,7 +2894,7 @@ fn enumSpec(p: *Parser) Error!QualType {
2889 } });2894 } });
28902895
2891 const attributed_qt = try Attribute.applyTypeAttributes(p, enum_qt, attr_buf_top, null);2896 const attributed_qt = try Attribute.applyTypeAttributes(p, enum_qt, attr_buf_top, null);
2892 try p.syms.define(p.gpa, .{2897 try p.syms.define(gpa, .{
2893 .kind = .@"enum",2898 .kind = .@"enum",
2894 .name = interned_name,2899 .name = interned_name,
2895 .tok = ident,2900 .tok = ident,
...@@ -2897,7 +2902,7 @@ fn enumSpec(p: *Parser) Error!QualType {...@@ -2897,7 +2902,7 @@ fn enumSpec(p: *Parser) Error!QualType {
2897 .val = .{},2902 .val = .{},
2898 });2903 });
28992904
2900 try p.decl_buf.append(try p.addNode(.{ .enum_forward_decl = .{2905 try p.decl_buf.append(gpa, try p.addNode(.{ .enum_forward_decl = .{
2901 .name_or_kind_tok = ident,2906 .name_or_kind_tok = ident,
2902 .container_qt = attributed_qt,2907 .container_qt = attributed_qt,
2903 .definition = null,2908 .definition = null,
...@@ -2940,12 +2945,12 @@ fn enumSpec(p: *Parser) Error!QualType {...@@ -2940,12 +2945,12 @@ fn enumSpec(p: *Parser) Error!QualType {
2940 .fixed = fixed_qt != null,2945 .fixed = fixed_qt != null,
2941 .fields = &.{},2946 .fields = &.{},
2942 };2947 };
2943 const enum_qt = try p.comp.type_store.put(p.gpa, .{ .@"enum" = enum_ty });2948 const enum_qt = try p.comp.type_store.put(gpa, .{ .@"enum" = enum_ty });
2944 break :blk .{ enum_ty, enum_qt };2949 break :blk .{ enum_ty, enum_qt };
2945 };2950 };
29462951
2947 // reserve space for this enum2952 // reserve space for this enum
2948 try p.decl_buf.append(@enumFromInt(reserved_index));2953 try p.decl_buf.append(gpa, @enumFromInt(reserved_index));
2949 const decl_buf_top = p.decl_buf.items.len;2954 const decl_buf_top = p.decl_buf.items.len;
2950 const list_buf_top = p.list_buf.items.len;2955 const list_buf_top = p.list_buf.items.len;
2951 const enum_buf_top = p.enum_buf.items.len;2956 const enum_buf_top = p.enum_buf.items.len;
...@@ -2958,8 +2963,8 @@ fn enumSpec(p: *Parser) Error!QualType {...@@ -2958,8 +2963,8 @@ fn enumSpec(p: *Parser) Error!QualType {
29582963
2959 var e = Enumerator.init(fixed_qt);2964 var e = Enumerator.init(fixed_qt);
2960 while (try p.enumerator(&e)) |field_and_node| {2965 while (try p.enumerator(&e)) |field_and_node| {
2961 try p.enum_buf.append(field_and_node.field);2966 try p.enum_buf.append(gpa, field_and_node.field);
2962 try p.list_buf.append(field_and_node.node);2967 try p.list_buf.append(gpa, field_and_node.node);
2963 if (p.eatToken(.comma) == null) break;2968 if (p.eatToken(.comma) == null) break;
2964 }2969 }
29652970
...@@ -2996,7 +3001,7 @@ fn enumSpec(p: *Parser) Error!QualType {...@@ -2996,7 +3001,7 @@ fn enumSpec(p: *Parser) Error!QualType {
29963001
2997 const symbol = p.syms.getPtr(field.name, .vars);3002 const symbol = p.syms.getPtr(field.name, .vars);
2998 _ = try symbol.val.intCast(dest_ty, p.comp);3003 _ = try symbol.val.intCast(dest_ty, p.comp);
2999 try p.tree.value_map.put(p.gpa, field_node, symbol.val);3004 try p.tree.value_map.put(gpa, field_node, symbol.val);
30003005
3001 symbol.qt = dest_ty;3006 symbol.qt = dest_ty;
3002 field.qt = dest_ty;3007 field.qt = dest_ty;
...@@ -3022,12 +3027,12 @@ fn enumSpec(p: *Parser) Error!QualType {...@@ -3022,12 +3027,12 @@ fn enumSpec(p: *Parser) Error!QualType {
3022 enum_ty.decl_node = @enumFromInt(reserved_index);3027 enum_ty.decl_node = @enumFromInt(reserved_index);
3023 const base_type = attributed_qt.base(p.comp);3028 const base_type = attributed_qt.base(p.comp);
3024 std.debug.assert(base_type.type.@"enum".name == enum_ty.name);3029 std.debug.assert(base_type.type.@"enum".name == enum_ty.name);
3025 try p.comp.type_store.set(p.gpa, .{ .@"enum" = enum_ty }, @intFromEnum(base_type.qt._index));3030 try p.comp.type_store.set(gpa, .{ .@"enum" = enum_ty }, @intFromEnum(base_type.qt._index));
3026 }3031 }
30273032
3028 // declare a symbol for the type3033 // declare a symbol for the type
3029 if (maybe_ident != null and !defined) {3034 if (maybe_ident != null and !defined) {
3030 try p.syms.define(p.gpa, .{3035 try p.syms.define(gpa, .{
3031 .kind = .@"enum",3036 .kind = .@"enum",
3032 .name = enum_ty.name,3037 .name = enum_ty.name,
3033 .qt = attributed_qt,3038 .qt = attributed_qt,
...@@ -3231,7 +3236,7 @@ fn enumerator(p: *Parser, e: *Enumerator) Error!?EnumFieldAndNode {...@@ -3231,7 +3236,7 @@ fn enumerator(p: *Parser, e: *Enumerator) Error!?EnumFieldAndNode {
3231 .init = field_init,3236 .init = field_init,
3232 },3237 },
3233 });3238 });
3234 try p.tree.value_map.put(p.gpa, node, e.val);3239 try p.tree.value_map.put(p.comp.gpa, node, e.val);
32353240
3236 const interned_name = try p.comp.internString(p.tokSlice(name_tok));3241 const interned_name = try p.comp.internString(p.tokSlice(name_tok));
3237 try p.syms.defineEnumeration(p, interned_name, attributed_qt, name_tok, e.val, node);3242 try p.syms.defineEnumeration(p, interned_name, attributed_qt, name_tok, e.val, node);
...@@ -3297,7 +3302,7 @@ fn typeQual(p: *Parser, b: *TypeStore.Builder, allow_attr: bool) Error!bool {...@@ -3297,7 +3302,7 @@ fn typeQual(p: *Parser, b: *TypeStore.Builder, allow_attr: bool) Error!bool {
3297 } else switch (b.nullability) {3302 } else switch (b.nullability) {
3298 .none => {3303 .none => {
3299 b.nullability = new;3304 b.nullability = new;
3300 try p.attr_buf.append(p.gpa, .{3305 try p.attr_buf.append(p.comp.gpa, .{
3301 .attr = .{ .tag = .nullability, .args = .{3306 .attr = .{ .tag = .nullability, .args = .{
3302 .nullability = .{ .kind = switch (tok_id) {3307 .nullability = .{ .kind = switch (tok_id) {
3303 .keyword_nonnull => .nonnull,3308 .keyword_nonnull => .nonnull,
...@@ -3341,7 +3346,7 @@ fn msTypeAttribute(p: *Parser) !bool {...@@ -3341,7 +3346,7 @@ fn msTypeAttribute(p: *Parser) !bool {
3341 .keyword_cdecl,3346 .keyword_cdecl,
3342 .keyword_cdecl2,3347 .keyword_cdecl2,
3343 => {3348 => {
3344 try p.attr_buf.append(p.gpa, .{3349 try p.attr_buf.append(p.comp.gpa, .{
3345 .attr = .{ .tag = .calling_convention, .args = .{3350 .attr = .{ .tag = .calling_convention, .args = .{
3346 .calling_convention = .{ .cc = switch (p.tok_ids[p.tok_i]) {3351 .calling_convention = .{ .cc = switch (p.tok_ids[p.tok_i]) {
3347 .keyword_stdcall,3352 .keyword_stdcall,
...@@ -3496,7 +3501,7 @@ fn declarator(...@@ -3496,7 +3501,7 @@ fn declarator(
3496 var builder: TypeStore.Builder = .{ .parser = p };3501 var builder: TypeStore.Builder = .{ .parser = p };
3497 _ = try p.typeQual(&builder, true);3502 _ = try p.typeQual(&builder, true);
34983503
3499 const pointer_qt = try p.comp.type_store.put(p.gpa, .{ .pointer = .{3504 const pointer_qt = try p.comp.type_store.put(p.comp.gpa, .{ .pointer = .{
3500 .child = d.qt,3505 .child = d.qt,
3501 .decayed = null,3506 .decayed = null,
3502 } });3507 } });
...@@ -3611,6 +3616,7 @@ fn directDeclarator(...@@ -3611,6 +3616,7 @@ fn directDeclarator(
3611 base_declarator: *Declarator,3616 base_declarator: *Declarator,
3612 kind: Declarator.Kind,3617 kind: Declarator.Kind,
3613) Error!QualType {3618) Error!QualType {
3619 const gpa = p.comp.gpa;
3614 if (p.eatToken(.l_bracket)) |l_bracket| {3620 if (p.eatToken(.l_bracket)) |l_bracket| {
3615 // Check for C23 attribute3621 // Check for C23 attribute
3616 if (p.tok_ids[p.tok_i] == .l_bracket) {3622 if (p.tok_ids[p.tok_i] == .l_bracket) {
...@@ -3674,7 +3680,7 @@ fn directDeclarator(...@@ -3674,7 +3680,7 @@ fn directDeclarator(
3674 try p.err(base_declarator.name, .variable_len_array_file_scope, .{});3680 try p.err(base_declarator.name, .variable_len_array_file_scope, .{});
3675 }3681 }
36763682
3677 const array_qt = try p.comp.type_store.put(p.gpa, .{ .array = .{3683 const array_qt = try p.comp.type_store.put(gpa, .{ .array = .{
3678 .elem = outer,3684 .elem = outer,
3679 .len = .{ .variable = size.node },3685 .len = .{ .variable = size.node },
3680 } });3686 } });
...@@ -3690,7 +3696,7 @@ fn directDeclarator(...@@ -3690,7 +3696,7 @@ fn directDeclarator(
3690 }3696 }
36913697
3692 const len = size.val.toInt(u64, p.comp) orelse std.math.maxInt(u64);3698 const len = size.val.toInt(u64, p.comp) orelse std.math.maxInt(u64);
3693 const array_qt = try p.comp.type_store.put(p.gpa, .{ .array = .{3699 const array_qt = try p.comp.type_store.put(gpa, .{ .array = .{
3694 .elem = outer,3700 .elem = outer,
3695 .len = if (static != null)3701 .len = if (static != null)
3696 .{ .static = len }3702 .{ .static = len }
...@@ -3700,13 +3706,13 @@ fn directDeclarator(...@@ -3700,13 +3706,13 @@ fn directDeclarator(
3700 return builder.finishQuals(array_qt);3706 return builder.finishQuals(array_qt);
3701 }3707 }
3702 } else if (star) |_| {3708 } else if (star) |_| {
3703 const array_qt = try p.comp.type_store.put(p.gpa, .{ .array = .{3709 const array_qt = try p.comp.type_store.put(gpa, .{ .array = .{
3704 .elem = outer,3710 .elem = outer,
3705 .len = .unspecified_variable,3711 .len = .unspecified_variable,
3706 } });3712 } });
3707 return builder.finishQuals(array_qt);3713 return builder.finishQuals(array_qt);
3708 } else {3714 } else {
3709 const array_qt = try p.comp.type_store.put(p.gpa, .{ .array = .{3715 const array_qt = try p.comp.type_store.put(gpa, .{ .array = .{
3710 .elem = outer,3716 .elem = outer,
3711 .len = .incomplete,3717 .len = .incomplete,
3712 } });3718 } });
...@@ -3729,7 +3735,7 @@ fn directDeclarator(...@@ -3729,7 +3735,7 @@ fn directDeclarator(
3729 // Set after call to `directDeclarator` since we will return3735 // Set after call to `directDeclarator` since we will return
3730 // a function type from here.3736 // a function type from here.
3731 base_declarator.declarator_type = .func;3737 base_declarator.declarator_type = .func;
3732 return p.comp.type_store.put(p.gpa, .{ .func = func_ty });3738 return p.comp.type_store.put(gpa, .{ .func = func_ty });
3733 }3739 }
37343740
3735 // Set here so the call to directDeclarator for the return type3741 // Set here so the call to directDeclarator for the return type
...@@ -3756,7 +3762,7 @@ fn directDeclarator(...@@ -3756,7 +3762,7 @@ fn directDeclarator(
3756 const name_tok = try p.expectIdentifier();3762 const name_tok = try p.expectIdentifier();
3757 const interned_name = try p.comp.internString(p.tokSlice(name_tok));3763 const interned_name = try p.comp.internString(p.tokSlice(name_tok));
3758 try p.syms.defineParam(p, interned_name, undefined, name_tok, null);3764 try p.syms.defineParam(p, interned_name, undefined, name_tok, null);
3759 try p.param_buf.append(.{3765 try p.param_buf.append(gpa, .{
3760 .name = interned_name,3766 .name = interned_name,
3761 .name_tok = name_tok,3767 .name_tok = name_tok,
3762 .qt = .int,3768 .qt = .int,
...@@ -3776,7 +3782,7 @@ fn directDeclarator(...@@ -3776,7 +3782,7 @@ fn directDeclarator(
3776 // a function type from here.3782 // a function type from here.
3777 base_declarator.declarator_type = .func;3783 base_declarator.declarator_type = .func;
37783784
3779 return p.comp.type_store.put(p.gpa, .{ .func = func_ty });3785 return p.comp.type_store.put(gpa, .{ .func = func_ty });
3780 } else return base_declarator.qt;3786 } else return base_declarator.qt;
3781}3787}
37823788
...@@ -3789,6 +3795,7 @@ fn paramDecls(p: *Parser) Error!?[]Type.Func.Param {...@@ -3789,6 +3795,7 @@ fn paramDecls(p: *Parser) Error!?[]Type.Func.Param {
37893795
3790 // Clearing the param buf is handled in directDeclarator.3796 // Clearing the param buf is handled in directDeclarator.
3791 const param_buf_top = p.param_buf.items.len;3797 const param_buf_top = p.param_buf.items.len;
3798 const gpa = p.comp.gpa;
37923799
3793 while (true) {3800 while (true) {
3794 const attr_buf_top = p.attr_buf.len;3801 const attr_buf_top = p.attr_buf.len;
...@@ -3802,7 +3809,7 @@ fn paramDecls(p: *Parser) Error!?[]Type.Func.Param {...@@ -3802,7 +3809,7 @@ fn paramDecls(p: *Parser) Error!?[]Type.Func.Param {
3802 const identifier = try p.expectIdentifier();3809 const identifier = try p.expectIdentifier();
3803 try p.err(identifier, .unknown_type_name, .{p.tokSlice(identifier)});3810 try p.err(identifier, .unknown_type_name, .{p.tokSlice(identifier)});
38043811
3805 try p.param_buf.append(.{3812 try p.param_buf.append(gpa, .{
3806 .name = try p.comp.internString(p.tokSlice(identifier)),3813 .name = try p.comp.internString(p.tokSlice(identifier)),
3807 .name_tok = identifier,3814 .name_tok = identifier,
3808 .qt = .int,3815 .qt = .int,
...@@ -3882,7 +3889,7 @@ fn paramDecls(p: *Parser) Error!?[]Type.Func.Param {...@@ -3882,7 +3889,7 @@ fn paramDecls(p: *Parser) Error!?[]Type.Func.Param {
3882 try p.syms.defineParam(p, interned_name, param_qt, name_tok, node);3889 try p.syms.defineParam(p, interned_name, param_qt, name_tok, node);
3883 }3890 }
38843891
3885 try p.param_buf.append(.{3892 try p.param_buf.append(gpa, .{
3886 .name = interned_name,3893 .name = interned_name,
3887 .name_tok = if (name_tok == 0) first_tok else name_tok,3894 .name_tok = if (name_tok == 0) first_tok else name_tok,
3888 .qt = param_qt,3895 .qt = param_qt,
...@@ -3932,7 +3939,7 @@ fn initializer(p: *Parser, init_qt: QualType) Error!Result {...@@ -3932,7 +3939,7 @@ fn initializer(p: *Parser, init_qt: QualType) Error!Result {
3932 }3939 }
39333940
3934 var il: InitList = .{};3941 var il: InitList = .{};
3935 defer il.deinit(p.gpa);3942 defer il.deinit(p.comp.gpa);
39363943
3937 try p.initializerItem(&il, final_init_qt, l_brace);3944 try p.initializerItem(&il, final_init_qt, l_brace);
39383945
...@@ -3944,10 +3951,11 @@ fn initializer(p: *Parser, init_qt: QualType) Error!Result {...@@ -3944,10 +3951,11 @@ fn initializer(p: *Parser, init_qt: QualType) Error!Result {
3944 };3951 };
3945}3952}
39463953
3947const IndexList = std.ArrayListUnmanaged(u64);3954const IndexList = std.ArrayList(u64);
39483955
3949/// initializerItems : designation? initializer (',' designation? initializer)* ','?3956/// initializerItems : designation? initializer (',' designation? initializer)* ','?
3950fn initializerItem(p: *Parser, il: *InitList, init_qt: QualType, l_brace: TokenIndex) Error!void {3957fn initializerItem(p: *Parser, il: *InitList, init_qt: QualType, l_brace: TokenIndex) Error!void {
3958 const gpa = p.comp.gpa;
3951 const is_scalar = !init_qt.isInvalid() and init_qt.scalarKind(p.comp) != .none;3959 const is_scalar = !init_qt.isInvalid() and init_qt.scalarKind(p.comp) != .none;
39523960
3953 if (p.eatToken(.r_brace)) |_| {3961 if (p.eatToken(.r_brace)) |_| {
...@@ -3962,7 +3970,7 @@ fn initializerItem(p: *Parser, il: *InitList, init_qt: QualType, l_brace: TokenI...@@ -3962,7 +3970,7 @@ fn initializerItem(p: *Parser, il: *InitList, init_qt: QualType, l_brace: TokenI
3962 }3970 }
39633971
3964 var index_list: IndexList = .empty;3972 var index_list: IndexList = .empty;
3965 defer index_list.deinit(p.gpa);3973 defer index_list.deinit(gpa);
39663974
3967 var seen_any = false;3975 var seen_any = false;
3968 var warned_excess = init_qt.isInvalid();3976 var warned_excess = init_qt.isInvalid();
...@@ -3980,14 +3988,14 @@ fn initializerItem(p: *Parser, il: *InitList, init_qt: QualType, l_brace: TokenI...@@ -3980,14 +3988,14 @@ fn initializerItem(p: *Parser, il: *InitList, init_qt: QualType, l_brace: TokenI
3980 if (item.il.tok != 0 and !init_qt.isInvalid()) {3988 if (item.il.tok != 0 and !init_qt.isInvalid()) {
3981 try p.err(first_tok, .initializer_overrides, .{});3989 try p.err(first_tok, .initializer_overrides, .{});
3982 try p.err(item.il.tok, .previous_initializer, .{});3990 try p.err(item.il.tok, .previous_initializer, .{});
3983 item.il.deinit(p.gpa);3991 item.il.deinit(gpa);
3984 item.il.* = .{};3992 item.il.* = .{};
3985 }3993 }
3986 try p.initializerItem(item.il, item.qt, inner_l_brace);3994 try p.initializerItem(item.il, item.qt, inner_l_brace);
3987 } else {3995 } else {
3988 // discard further values3996 // discard further values
3989 var tmp_il: InitList = .{};3997 var tmp_il: InitList = .{};
3990 defer tmp_il.deinit(p.gpa);3998 defer tmp_il.deinit(gpa);
3991 try p.initializerItem(&tmp_il, .invalid, inner_l_brace);3999 try p.initializerItem(&tmp_il, .invalid, inner_l_brace);
3992 if (!warned_excess) try p.err(first_tok, switch (init_qt.base(p.comp).type) {4000 if (!warned_excess) try p.err(first_tok, switch (init_qt.base(p.comp).type) {
3993 .array => if (il.node != .null and p.isStringInit(init_qt, il.node.unpack().?))4001 .array => if (il.node != .null and p.isStringInit(init_qt, il.node.unpack().?))
...@@ -4042,6 +4050,7 @@ fn designation(p: *Parser, il: *InitList, init_qt: QualType, index_list: *IndexL...@@ -4042,6 +4050,7 @@ fn designation(p: *Parser, il: *InitList, init_qt: QualType, index_list: *IndexL
4042 .l_bracket, .period => index_list.items.len = 0,4050 .l_bracket, .period => index_list.items.len = 0,
4043 else => return false,4051 else => return false,
4044 }4052 }
4053 const gpa = p.comp.gpa;
40454054
4046 var cur_qt = init_qt;4055 var cur_qt = init_qt;
4047 var cur_il = il;4056 var cur_il = il;
...@@ -4074,8 +4083,8 @@ fn designation(p: *Parser, il: *InitList, init_qt: QualType, index_list: *IndexL...@@ -4074,8 +4083,8 @@ fn designation(p: *Parser, il: *InitList, init_qt: QualType, index_list: *IndexL
4074 return error.ParsingFailed;4083 return error.ParsingFailed;
4075 }4084 }
40764085
4077 try index_list.append(p.gpa, index_int);4086 try index_list.append(gpa, index_int);
4078 cur_il = try cur_il.find(p.gpa, index_int);4087 cur_il = try cur_il.find(gpa, index_int);
4079 cur_qt = array_ty.elem;4088 cur_qt = array_ty.elem;
4080 } else if (p.eatToken(.period)) |period| {4089 } else if (p.eatToken(.period)) |period| {
4081 const field_tok = try p.expectIdentifier();4090 const field_tok = try p.expectIdentifier();
...@@ -4094,16 +4103,16 @@ fn designation(p: *Parser, il: *InitList, init_qt: QualType, index_list: *IndexL...@@ -4094,16 +4103,16 @@ fn designation(p: *Parser, il: *InitList, init_qt: QualType, index_list: *IndexL
4094 if (field.name_tok == 0) if (field.qt.getRecord(p.comp)) |field_record_ty| {4103 if (field.name_tok == 0) if (field.qt.getRecord(p.comp)) |field_record_ty| {
4095 // Recurse into anonymous field if it has a field by the name.4104 // Recurse into anonymous field if it has a field by the name.
4096 if (!field_record_ty.hasField(p.comp, target_name)) continue;4105 if (!field_record_ty.hasField(p.comp, target_name)) continue;
4097 try index_list.append(p.gpa, field_index);4106 try index_list.append(gpa, field_index);
4098 cur_il = try il.find(p.gpa, field_index);4107 cur_il = try il.find(gpa, field_index);
4099 record_ty = field_record_ty;4108 record_ty = field_record_ty;
4100 field_index = 0;4109 field_index = 0;
4101 continue;4110 continue;
4102 };4111 };
4103 if (field.name == target_name) {4112 if (field.name == target_name) {
4104 cur_qt = field.qt;4113 cur_qt = field.qt;
4105 try index_list.append(p.gpa, field_index);4114 try index_list.append(gpa, field_index);
4106 cur_il = try cur_il.find(p.gpa, field_index);4115 cur_il = try cur_il.find(gpa, field_index);
4107 break;4116 break;
4108 }4117 }
4109 field_index += 1;4118 field_index += 1;
...@@ -4132,7 +4141,8 @@ fn findScalarInitializer(...@@ -4132,7 +4141,8 @@ fn findScalarInitializer(
4132 index_list_top: u32,4141 index_list_top: u32,
4133) Error!bool {4142) Error!bool {
4134 if (qt.isInvalid()) return false;4143 if (qt.isInvalid()) return false;
4135 if (index_list.items.len <= index_list_top) try index_list.append(p.gpa, 0);4144 const gpa = p.comp.gpa;
4145 if (index_list.items.len <= index_list_top) try index_list.append(gpa, 0);
4136 const index = index_list.items[index_list_top];4146 const index = index_list.items[index_list_top];
41374147
4138 switch (qt.base(p.comp).type) {4148 switch (qt.base(p.comp).type) {
...@@ -4147,7 +4157,7 @@ fn findScalarInitializer(...@@ -4147,7 +4157,7 @@ fn findScalarInitializer(
4147 return true;4157 return true;
4148 }4158 }
41494159
4150 const elem_il = try il.find(p.gpa, index);4160 const elem_il = try il.find(gpa, index);
4151 if (try p.setInitializerIfEqual(elem_il, complex_ty, first_tok, res) or4161 if (try p.setInitializerIfEqual(elem_il, complex_ty, first_tok, res) or
4152 try p.findScalarInitializer(4162 try p.findScalarInitializer(
4153 elem_il,4163 elem_il,
...@@ -4180,7 +4190,7 @@ fn findScalarInitializer(...@@ -4180,7 +4190,7 @@ fn findScalarInitializer(
4180 return true;4190 return true;
4181 }4191 }
41824192
4183 const elem_il = try il.find(p.gpa, index);4193 const elem_il = try il.find(gpa, index);
4184 if (try p.setInitializerIfEqual(elem_il, vector_ty.elem, first_tok, res) or4194 if (try p.setInitializerIfEqual(elem_il, vector_ty.elem, first_tok, res) or
4185 try p.findScalarInitializer(4195 try p.findScalarInitializer(
4186 elem_il,4196 elem_il,
...@@ -4229,7 +4239,7 @@ fn findScalarInitializer(...@@ -4229,7 +4239,7 @@ fn findScalarInitializer(
4229 return true;4239 return true;
4230 }4240 }
42314241
4232 const elem_il = try il.find(p.gpa, index);4242 const elem_il = try il.find(gpa, index);
4233 if (try p.setInitializerIfEqual(elem_il, array_ty.elem, first_tok, res) or4243 if (try p.setInitializerIfEqual(elem_il, array_ty.elem, first_tok, res) or
4234 try p.findScalarInitializer(4244 try p.findScalarInitializer(
4235 elem_il,4245 elem_il,
...@@ -4262,7 +4272,7 @@ fn findScalarInitializer(...@@ -4262,7 +4272,7 @@ fn findScalarInitializer(
4262 }4272 }
42634273
4264 const field = struct_ty.fields[@intCast(index)];4274 const field = struct_ty.fields[@intCast(index)];
4265 const field_il = try il.find(p.gpa, index);4275 const field_il = try il.find(gpa, index);
4266 if (try p.setInitializerIfEqual(field_il, field.qt, first_tok, res) or4276 if (try p.setInitializerIfEqual(field_il, field.qt, first_tok, res) or
4267 try p.findScalarInitializer(4277 try p.findScalarInitializer(
4268 field_il,4278 field_il,
...@@ -4297,7 +4307,7 @@ fn findScalarInitializer(...@@ -4297,7 +4307,7 @@ fn findScalarInitializer(
4297 }4307 }
42984308
4299 const field = union_ty.fields[@intCast(index)];4309 const field = union_ty.fields[@intCast(index)];
4300 const field_il = try il.find(p.gpa, index);4310 const field_il = try il.find(gpa, index);
4301 if (try p.setInitializerIfEqual(field_il, field.qt, first_tok, res) or4311 if (try p.setInitializerIfEqual(field_il, field.qt, first_tok, res) or
4302 try p.findScalarInitializer(4312 try p.findScalarInitializer(
4303 field_il,4313 field_il,
...@@ -4342,7 +4352,8 @@ fn findBracedInitializer(...@@ -4342,7 +4352,8 @@ fn findBracedInitializer(
4342 if (il.node != .null) return .{ .il = il, .qt = qt };4352 if (il.node != .null) return .{ .il = il, .qt = qt };
4343 return null;4353 return null;
4344 }4354 }
4345 if (index_list.items.len == 0) try index_list.append(p.gpa, 0);4355 const gpa = p.comp.gpa;
4356 if (index_list.items.len == 0) try index_list.append(gpa, 0);
4346 const index = index_list.items[0];4357 const index = index_list.items[0];
43474358
4348 switch (qt.base(p.comp).type) {4359 switch (qt.base(p.comp).type) {
...@@ -4352,7 +4363,7 @@ fn findBracedInitializer(...@@ -4352,7 +4363,7 @@ fn findBracedInitializer(
4352 if (index < 2) {4363 if (index < 2) {
4353 index_list.items[0] = index + 1;4364 index_list.items[0] = index + 1;
4354 index_list.items.len = 1;4365 index_list.items.len = 1;
4355 return .{ .il = try il.find(p.gpa, index), .qt = complex_ty };4366 return .{ .il = try il.find(gpa, index), .qt = complex_ty };
4356 }4367 }
4357 },4368 },
4358 .vector => |vector_ty| {4369 .vector => |vector_ty| {
...@@ -4361,7 +4372,7 @@ fn findBracedInitializer(...@@ -4361,7 +4372,7 @@ fn findBracedInitializer(
4361 if (index < vector_ty.len) {4372 if (index < vector_ty.len) {
4362 index_list.items[0] = index + 1;4373 index_list.items[0] = index + 1;
4363 index_list.items.len = 1;4374 index_list.items.len = 1;
4364 return .{ .il = try il.find(p.gpa, index), .qt = vector_ty.elem };4375 return .{ .il = try il.find(gpa, index), .qt = vector_ty.elem };
4365 }4376 }
4366 },4377 },
4367 .array => |array_ty| {4378 .array => |array_ty| {
...@@ -4374,7 +4385,7 @@ fn findBracedInitializer(...@@ -4374,7 +4385,7 @@ fn findBracedInitializer(
4374 if (index < max_len) {4385 if (index < max_len) {
4375 index_list.items[0] = index + 1;4386 index_list.items[0] = index + 1;
4376 index_list.items.len = 1;4387 index_list.items.len = 1;
4377 return .{ .il = try il.find(p.gpa, index), .qt = array_ty.elem };4388 return .{ .il = try il.find(gpa, index), .qt = array_ty.elem };
4378 }4389 }
4379 },4390 },
4380 .@"struct" => |struct_ty| {4391 .@"struct" => |struct_ty| {
...@@ -4384,7 +4395,7 @@ fn findBracedInitializer(...@@ -4384,7 +4395,7 @@ fn findBracedInitializer(
4384 index_list.items[0] = index + 1;4395 index_list.items[0] = index + 1;
4385 index_list.items.len = 1;4396 index_list.items.len = 1;
4386 const field_qt = struct_ty.fields[@intCast(index)].qt;4397 const field_qt = struct_ty.fields[@intCast(index)].qt;
4387 return .{ .il = try il.find(p.gpa, index), .qt = field_qt };4398 return .{ .il = try il.find(gpa, index), .qt = field_qt };
4388 }4399 }
4389 },4400 },
4390 .@"union" => |union_ty| {4401 .@"union" => |union_ty| {
...@@ -4395,7 +4406,7 @@ fn findBracedInitializer(...@@ -4395,7 +4406,7 @@ fn findBracedInitializer(
4395 index_list.items[0] = index + 1;4406 index_list.items[0] = index + 1;
4396 index_list.items.len = 1;4407 index_list.items.len = 1;
4397 const field_qt = union_ty.fields[@intCast(index)].qt;4408 const field_qt = union_ty.fields[@intCast(index)].qt;
4398 return .{ .il = try il.find(p.gpa, index), .qt = field_qt };4409 return .{ .il = try il.find(gpa, index), .qt = field_qt };
4399 }4410 }
4400 },4411 },
4401 else => {4412 else => {
...@@ -4495,6 +4506,7 @@ fn convertInitList(p: *Parser, il: InitList, init_qt: QualType) Error!Node.Index...@@ -4495,6 +4506,7 @@ fn convertInitList(p: *Parser, il: InitList, init_qt: QualType) Error!Node.Index
44954506
4496 if (il.node.unpack()) |some| return some;4507 if (il.node.unpack()) |some| return some;
44974508
4509 const gpa = p.comp.gpa;
4498 switch (init_qt.base(p.comp).type) {4510 switch (init_qt.base(p.comp).type) {
4499 .complex => |complex_ty| {4511 .complex => |complex_ty| {
4500 if (il.list.items.len == 0) {4512 if (il.list.items.len == 0) {
...@@ -4535,7 +4547,7 @@ fn convertInitList(p: *Parser, il: InitList, init_qt: QualType) Error!Node.Index...@@ -4535,7 +4547,7 @@ fn convertInitList(p: *Parser, il: InitList, init_qt: QualType) Error!Node.Index
4535 128 => .{ .complex = .{ .cf128 = .{ first_val.toFloat(f128, p.comp), second_val.toFloat(f128, p.comp) } } },4547 128 => .{ .complex = .{ .cf128 = .{ first_val.toFloat(f128, p.comp), second_val.toFloat(f128, p.comp) } } },
4536 else => unreachable,4548 else => unreachable,
4537 });4549 });
4538 try p.tree.value_map.put(p.gpa, node, complex_val);4550 try p.tree.value_map.put(gpa, node, complex_val);
4539 return node;4551 return node;
4540 },4552 },
4541 .vector => |vector_ty| {4553 .vector => |vector_ty| {
...@@ -4555,12 +4567,12 @@ fn convertInitList(p: *Parser, il: InitList, init_qt: QualType) Error!Node.Index...@@ -4555,12 +4567,12 @@ fn convertInitList(p: *Parser, il: InitList, init_qt: QualType) Error!Node.Index
4555 .qt = elem_ty,4567 .qt = elem_ty,
4556 },4568 },
4557 });4569 });
4558 try p.list_buf.append(elem);4570 try p.list_buf.append(gpa, elem);
4559 }4571 }
4560 start = init.index + 1;4572 start = init.index + 1;
45614573
4562 const elem = try p.convertInitList(init.list, elem_ty);4574 const elem = try p.convertInitList(init.list, elem_ty);
4563 try p.list_buf.append(elem);4575 try p.list_buf.append(gpa, elem);
4564 }4576 }
45654577
4566 if (start < max_len) {4578 if (start < max_len) {
...@@ -4571,7 +4583,7 @@ fn convertInitList(p: *Parser, il: InitList, init_qt: QualType) Error!Node.Index...@@ -4571,7 +4583,7 @@ fn convertInitList(p: *Parser, il: InitList, init_qt: QualType) Error!Node.Index
4571 .qt = elem_ty,4583 .qt = elem_ty,
4572 },4584 },
4573 });4585 });
4574 try p.list_buf.append(elem);4586 try p.list_buf.append(gpa, elem);
4575 }4587 }
45764588
4577 return p.addNode(.{ .array_init_expr = .{4589 return p.addNode(.{ .array_init_expr = .{
...@@ -4605,12 +4617,12 @@ fn convertInitList(p: *Parser, il: InitList, init_qt: QualType) Error!Node.Index...@@ -4605,12 +4617,12 @@ fn convertInitList(p: *Parser, il: InitList, init_qt: QualType) Error!Node.Index
4605 .qt = elem_ty,4617 .qt = elem_ty,
4606 },4618 },
4607 });4619 });
4608 try p.list_buf.append(elem);4620 try p.list_buf.append(gpa, elem);
4609 }4621 }
4610 start = init.index + 1;4622 start = init.index + 1;
46114623
4612 const elem = try p.convertInitList(init.list, elem_ty);4624 const elem = try p.convertInitList(init.list, elem_ty);
4613 try p.list_buf.append(elem);4625 try p.list_buf.append(gpa, elem);
4614 }4626 }
46154627
4616 const max_elems = p.comp.maxArrayBytes() / (@max(1, elem_ty.sizeofOrNull(p.comp) orelse 1));4628 const max_elems = p.comp.maxArrayBytes() / (@max(1, elem_ty.sizeofOrNull(p.comp) orelse 1));
...@@ -4621,7 +4633,7 @@ fn convertInitList(p: *Parser, il: InitList, init_qt: QualType) Error!Node.Index...@@ -4621,7 +4633,7 @@ fn convertInitList(p: *Parser, il: InitList, init_qt: QualType) Error!Node.Index
46214633
4622 var arr_init_qt = init_qt;4634 var arr_init_qt = init_qt;
4623 if (array_ty.len == .incomplete) {4635 if (array_ty.len == .incomplete) {
4624 arr_init_qt = try p.comp.type_store.put(p.gpa, .{ .array = .{4636 arr_init_qt = try p.comp.type_store.put(gpa, .{ .array = .{
4625 .elem = array_ty.elem,4637 .elem = array_ty.elem,
4626 .len = .{ .fixed = start },4638 .len = .{ .fixed = start },
4627 } });4639 } });
...@@ -4633,7 +4645,7 @@ fn convertInitList(p: *Parser, il: InitList, init_qt: QualType) Error!Node.Index...@@ -4633,7 +4645,7 @@ fn convertInitList(p: *Parser, il: InitList, init_qt: QualType) Error!Node.Index
4633 .qt = elem_ty,4645 .qt = elem_ty,
4634 },4646 },
4635 });4647 });
4636 try p.list_buf.append(elem);4648 try p.list_buf.append(gpa, elem);
4637 }4649 }
46384650
4639 return p.addNode(.{ .array_init_expr = .{4651 return p.addNode(.{ .array_init_expr = .{
...@@ -4651,7 +4663,7 @@ fn convertInitList(p: *Parser, il: InitList, init_qt: QualType) Error!Node.Index...@@ -4651,7 +4663,7 @@ fn convertInitList(p: *Parser, il: InitList, init_qt: QualType) Error!Node.Index
4651 for (struct_ty.fields, 0..) |field, i| {4663 for (struct_ty.fields, 0..) |field, i| {
4652 if (init_index < il.list.items.len and il.list.items[init_index].index == i) {4664 if (init_index < il.list.items.len and il.list.items[init_index].index == i) {
4653 const item = try p.convertInitList(il.list.items[init_index].list, field.qt);4665 const item = try p.convertInitList(il.list.items[init_index].list, field.qt);
4654 try p.list_buf.append(item);4666 try p.list_buf.append(gpa, item);
4655 init_index += 1;4667 init_index += 1;
4656 } else {4668 } else {
4657 const item = try p.addNode(.{4669 const item = try p.addNode(.{
...@@ -4660,7 +4672,7 @@ fn convertInitList(p: *Parser, il: InitList, init_qt: QualType) Error!Node.Index...@@ -4660,7 +4672,7 @@ fn convertInitList(p: *Parser, il: InitList, init_qt: QualType) Error!Node.Index
4660 .qt = field.qt,4672 .qt = field.qt,
4661 },4673 },
4662 });4674 });
4663 try p.list_buf.append(item);4675 try p.list_buf.append(gpa, item);
4664 }4676 }
4665 }4677 }
46664678
...@@ -4706,19 +4718,20 @@ fn msvcAsmStmt(p: *Parser) Error!?Node.Index {...@@ -4706,19 +4718,20 @@ fn msvcAsmStmt(p: *Parser) Error!?Node.Index {
4706}4718}
47074719
4708/// asmOperand : ('[' IDENTIFIER ']')? asmStr '(' expr ')'4720/// asmOperand : ('[' IDENTIFIER ']')? asmStr '(' expr ')'
4709fn asmOperand(p: *Parser, names: *std.array_list.Managed(?TokenIndex), constraints: *NodeList, exprs: *NodeList) Error!void {4721fn asmOperand(p: *Parser, names: *std.ArrayList(?TokenIndex), constraints: *NodeList, exprs: *NodeList) Error!void {
4722 const gpa = p.comp.gpa;
4710 if (p.eatToken(.l_bracket)) |l_bracket| {4723 if (p.eatToken(.l_bracket)) |l_bracket| {
4711 const ident = (try p.eatIdentifier()) orelse {4724 const ident = (try p.eatIdentifier()) orelse {
4712 try p.err(p.tok_i, .expected_identifier, .{});4725 try p.err(p.tok_i, .expected_identifier, .{});
4713 return error.ParsingFailed;4726 return error.ParsingFailed;
4714 };4727 };
4715 try names.append(ident);4728 try names.append(gpa, ident);
4716 try p.expectClosing(l_bracket, .r_bracket);4729 try p.expectClosing(l_bracket, .r_bracket);
4717 } else {4730 } else {
4718 try names.append(null);4731 try names.append(gpa, null);
4719 }4732 }
4720 const constraint = try p.asmStr();4733 const constraint = try p.asmStr();
4721 try constraints.append(constraint.node);4734 try constraints.append(gpa, constraint.node);
47224735
4723 const l_paren = p.eatToken(.l_paren) orelse {4736 const l_paren = p.eatToken(.l_paren) orelse {
4724 try p.err(p.tok_i, .expected_token, .{ p.tok_ids[p.tok_i], .l_paren });4737 try p.err(p.tok_i, .expected_token, .{ p.tok_ids[p.tok_i], .l_paren });
...@@ -4727,7 +4740,7 @@ fn asmOperand(p: *Parser, names: *std.array_list.Managed(?TokenIndex), constrain...@@ -4727,7 +4740,7 @@ fn asmOperand(p: *Parser, names: *std.array_list.Managed(?TokenIndex), constrain
4727 const maybe_res = try p.expr();4740 const maybe_res = try p.expr();
4728 try p.expectClosing(l_paren, .r_paren);4741 try p.expectClosing(l_paren, .r_paren);
4729 const res = try p.expectResult(maybe_res);4742 const res = try p.expectResult(maybe_res);
4730 try exprs.append(res.node);4743 try exprs.append(gpa, res.node);
4731}4744}
47324745
4733/// gnuAsmStmt4746/// gnuAsmStmt
...@@ -4737,6 +4750,7 @@ fn asmOperand(p: *Parser, names: *std.array_list.Managed(?TokenIndex), constrain...@@ -4737,6 +4750,7 @@ fn asmOperand(p: *Parser, names: *std.array_list.Managed(?TokenIndex), constrain
4737/// | asmStr ':' asmOperand* ':' asmOperand* : asmStr? (',' asmStr)*4750/// | asmStr ':' asmOperand* ':' asmOperand* : asmStr? (',' asmStr)*
4738/// | asmStr ':' asmOperand* ':' asmOperand* : asmStr? (',' asmStr)* : IDENTIFIER (',' IDENTIFIER)*4751/// | asmStr ':' asmOperand* ':' asmOperand* : asmStr? (',' asmStr)* : IDENTIFIER (',' IDENTIFIER)*
4739fn gnuAsmStmt(p: *Parser, quals: Tree.GNUAssemblyQualifiers, asm_tok: TokenIndex, l_paren: TokenIndex) Error!Node.Index {4752fn gnuAsmStmt(p: *Parser, quals: Tree.GNUAssemblyQualifiers, asm_tok: TokenIndex, l_paren: TokenIndex) Error!Node.Index {
4753 const gpa = p.comp.gpa;
4740 const asm_str = try p.asmStr();4754 const asm_str = try p.asmStr();
4741 try p.checkAsmStr(asm_str.val, l_paren);4755 try p.checkAsmStr(asm_str.val, l_paren);
47424756
...@@ -4752,18 +4766,22 @@ fn gnuAsmStmt(p: *Parser, quals: Tree.GNUAssemblyQualifiers, asm_tok: TokenIndex...@@ -4752,18 +4766,22 @@ fn gnuAsmStmt(p: *Parser, quals: Tree.GNUAssemblyQualifiers, asm_tok: TokenIndex
4752 const expected_items = 8; // arbitrarily chosen, most assembly will have fewer than 8 inputs/outputs/constraints/names4766 const expected_items = 8; // arbitrarily chosen, most assembly will have fewer than 8 inputs/outputs/constraints/names
4753 const bytes_needed = expected_items * @sizeOf(?TokenIndex) + expected_items * 3 * @sizeOf(Node.Index);4767 const bytes_needed = expected_items * @sizeOf(?TokenIndex) + expected_items * 3 * @sizeOf(Node.Index);
47544768
4755 var stack_fallback = std.heap.stackFallback(bytes_needed, p.gpa);4769 var stack_fallback = std.heap.stackFallback(bytes_needed, gpa);
4756 const allocator = stack_fallback.get();4770 const allocator = stack_fallback.get();
47574771
4758 // TODO: Consider using a TokenIndex of 0 instead of null if we need to store the names in the tree4772 // TODO: Consider using a TokenIndex of 0 instead of null if we need to store the names in the tree
4759 var names = std.array_list.Managed(?TokenIndex).initCapacity(allocator, expected_items) catch unreachable; // stack allocation already succeeded4773 var names: std.ArrayList(?TokenIndex) = .empty;
4760 defer names.deinit();4774 defer names.deinit(allocator);
4761 var constraints = NodeList.initCapacity(allocator, expected_items) catch unreachable; // stack allocation already succeeded4775 names.ensureUnusedCapacity(allocator, expected_items) catch unreachable; // stack allocation already succeeded
4762 defer constraints.deinit();4776 var constraints: NodeList = .empty;
4763 var exprs = NodeList.initCapacity(allocator, expected_items) catch unreachable; //stack allocation already succeeded4777 defer constraints.deinit(allocator);
4764 defer exprs.deinit();4778 constraints.ensureUnusedCapacity(allocator, expected_items) catch unreachable; // stack allocation already succeeded
4765 var clobbers = NodeList.initCapacity(allocator, expected_items) catch unreachable; //stack allocation already succeeded4779 var exprs: NodeList = .empty;
4766 defer clobbers.deinit();4780 defer exprs.deinit(allocator);
4781 exprs.ensureUnusedCapacity(allocator, expected_items) catch unreachable; //stack allocation already succeeded
4782 var clobbers: NodeList = .empty;
4783 defer clobbers.deinit(allocator);
4784 clobbers.ensureUnusedCapacity(allocator, expected_items) catch unreachable; //stack allocation already succeeded
47674785
4768 // Outputs4786 // Outputs
4769 var ate_extra_colon = false;4787 var ate_extra_colon = false;
...@@ -4813,7 +4831,7 @@ fn gnuAsmStmt(p: *Parser, quals: Tree.GNUAssemblyQualifiers, asm_tok: TokenIndex...@@ -4813,7 +4831,7 @@ fn gnuAsmStmt(p: *Parser, quals: Tree.GNUAssemblyQualifiers, asm_tok: TokenIndex
4813 if (!ate_extra_colon and p.tok_ids[p.tok_i].isStringLiteral()) {4831 if (!ate_extra_colon and p.tok_ids[p.tok_i].isStringLiteral()) {
4814 while (true) {4832 while (true) {
4815 const clobber = try p.asmStr();4833 const clobber = try p.asmStr();
4816 try clobbers.append(clobber.node);4834 try clobbers.append(allocator, clobber.node);
4817 if (p.eatToken(.comma) == null) break;4835 if (p.eatToken(.comma) == null) break;
4818 }4836 }
4819 }4837 }
...@@ -4837,10 +4855,10 @@ fn gnuAsmStmt(p: *Parser, quals: Tree.GNUAssemblyQualifiers, asm_tok: TokenIndex...@@ -4837,10 +4855,10 @@ fn gnuAsmStmt(p: *Parser, quals: Tree.GNUAssemblyQualifiers, asm_tok: TokenIndex
4837 };4855 };
4838 const ident_str = p.tokSlice(ident);4856 const ident_str = p.tokSlice(ident);
4839 const label = p.findLabel(ident_str) orelse blk: {4857 const label = p.findLabel(ident_str) orelse blk: {
4840 try p.labels.append(.{ .unresolved_goto = ident });4858 try p.labels.append(gpa, .{ .unresolved_goto = ident });
4841 break :blk ident;4859 break :blk ident;
4842 };4860 };
4843 try names.append(ident);4861 try names.append(allocator, ident);
48444862
4845 const label_addr_node = try p.addNode(.{4863 const label_addr_node = try p.addNode(.{
4846 .addr_of_label = .{4864 .addr_of_label = .{
...@@ -4848,7 +4866,7 @@ fn gnuAsmStmt(p: *Parser, quals: Tree.GNUAssemblyQualifiers, asm_tok: TokenIndex...@@ -4848,7 +4866,7 @@ fn gnuAsmStmt(p: *Parser, quals: Tree.GNUAssemblyQualifiers, asm_tok: TokenIndex
4848 .qt = .void_pointer,4866 .qt = .void_pointer,
4849 },4867 },
4850 });4868 });
4851 try exprs.append(label_addr_node);4869 try exprs.append(allocator, label_addr_node);
48524870
4853 num_labels += 1;4871 num_labels += 1;
4854 if (p.eatToken(.comma) == null) break;4872 if (p.eatToken(.comma) == null) break;
...@@ -4922,7 +4940,7 @@ fn assembly(p: *Parser, kind: enum { global, decl_label, stmt }) Error!?Node.Ind...@@ -4922,7 +4940,7 @@ fn assembly(p: *Parser, kind: enum { global, decl_label, stmt }) Error!?Node.Ind
4922 const str = try p.removeNull(asm_str.val);4940 const str = try p.removeNull(asm_str.val);
49234941
4924 const attr = Attribute{ .tag = .asm_label, .args = .{ .asm_label = .{ .name = str } }, .syntax = .keyword };4942 const attr = Attribute{ .tag = .asm_label, .args = .{ .asm_label = .{ .name = str } }, .syntax = .keyword };
4925 try p.attr_buf.append(p.gpa, .{ .attr = attr, .tok = asm_tok });4943 try p.attr_buf.append(p.comp.gpa, .{ .attr = attr, .tok = asm_tok });
4926 },4944 },
4927 .global => {4945 .global => {
4928 const asm_str = try p.asmStr();4946 const asm_str = try p.asmStr();
...@@ -4985,6 +5003,7 @@ fn asmStr(p: *Parser) Error!Result {...@@ -4985,6 +5003,7 @@ fn asmStr(p: *Parser) Error!Result {
4985fn stmt(p: *Parser) Error!Node.Index {5003fn stmt(p: *Parser) Error!Node.Index {
4986 if (try p.labeledStmt()) |some| return some;5004 if (try p.labeledStmt()) |some| return some;
4987 if (try p.compoundStmt(false, null)) |some| return some;5005 if (try p.compoundStmt(false, null)) |some| return some;
5006 const gpa = p.comp.gpa;
4988 if (p.eatToken(.keyword_if)) |kw_if| {5007 if (p.eatToken(.keyword_if)) |kw_if| {
4989 const l_paren = try p.expectToken(.l_paren);5008 const l_paren = try p.expectToken(.l_paren);
49905009
...@@ -5035,14 +5054,13 @@ fn stmt(p: *Parser) Error!Node.Index {...@@ -5035,14 +5054,13 @@ fn stmt(p: *Parser) Error!Node.Index {
5035 try p.expectClosing(l_paren, .r_paren);5054 try p.expectClosing(l_paren, .r_paren);
50365055
5037 const old_switch = p.@"switch";5056 const old_switch = p.@"switch";
5038 var @"switch" = Switch{5057 var @"switch": Switch = .{
5039 .ranges = std.array_list.Managed(Switch.Range).init(p.gpa),
5040 .qt = cond.qt,5058 .qt = cond.qt,
5041 .comp = p.comp,5059 .comp = p.comp,
5042 };5060 };
5043 p.@"switch" = &@"switch";5061 p.@"switch" = &@"switch";
5044 defer {5062 defer {
5045 @"switch".ranges.deinit();5063 @"switch".ranges.deinit(gpa);
5046 p.@"switch" = old_switch;5064 p.@"switch" = old_switch;
5047 }5065 }
50485066
...@@ -5183,7 +5201,7 @@ fn stmt(p: *Parser) Error!Node.Index {...@@ -5183,7 +5201,7 @@ fn stmt(p: *Parser) Error!Node.Index {
5183 p.computed_goto_tok = p.computed_goto_tok orelse goto_tok;5201 p.computed_goto_tok = p.computed_goto_tok orelse goto_tok;
51845202
5185 if (!goto_expr.qt.isInvalid() and !goto_expr.qt.isPointer(p.comp)) {5203 if (!goto_expr.qt.isInvalid() and !goto_expr.qt.isPointer(p.comp)) {
5186 const result_qt = try p.comp.type_store.put(p.gpa, .{ .pointer = .{5204 const result_qt = try p.comp.type_store.put(gpa, .{ .pointer = .{
5187 .child = .{ .@"const" = true, ._index = .void },5205 .child = .{ .@"const" = true, ._index = .void },
5188 .decayed = null,5206 .decayed = null,
5189 } });5207 } });
...@@ -5204,7 +5222,7 @@ fn stmt(p: *Parser) Error!Node.Index {...@@ -5204,7 +5222,7 @@ fn stmt(p: *Parser) Error!Node.Index {
5204 const name_tok = try p.expectIdentifier();5222 const name_tok = try p.expectIdentifier();
5205 const str = p.tokSlice(name_tok);5223 const str = p.tokSlice(name_tok);
5206 if (p.findLabel(str) == null) {5224 if (p.findLabel(str) == null) {
5207 try p.labels.append(.{ .unresolved_goto = name_tok });5225 try p.labels.append(gpa, .{ .unresolved_goto = name_tok });
5208 }5226 }
5209 _ = try p.expectToken(.semicolon);5227 _ = try p.expectToken(.semicolon);
5210 return p.addNode(.{ .goto_stmt = .{ .label_tok = name_tok } });5228 return p.addNode(.{ .goto_stmt = .{ .label_tok = name_tok } });
...@@ -5259,7 +5277,7 @@ fn labeledStmt(p: *Parser) Error!?Node.Index {...@@ -5259,7 +5277,7 @@ fn labeledStmt(p: *Parser) Error!?Node.Index {
5259 try p.err(some, .previous_label, .{str});5277 try p.err(some, .previous_label, .{str});
5260 } else {5278 } else {
5261 p.label_count += 1;5279 p.label_count += 1;
5262 try p.labels.append(.{ .label = name_tok });5280 try p.labels.append(p.comp.gpa, .{ .label = name_tok });
5263 var i: usize = 0;5281 var i: usize = 0;
5264 while (i < p.labels.items.len) {5282 while (i < p.labels.items.len) {
5265 if (p.labels.items[i] == .unresolved_goto and5283 if (p.labels.items[i] == .unresolved_goto and
...@@ -5370,6 +5388,7 @@ const StmtExprState = struct {...@@ -5370,6 +5388,7 @@ const StmtExprState = struct {
5370fn compoundStmt(p: *Parser, is_fn_body: bool, stmt_expr_state: ?*StmtExprState) Error!?Node.Index {5388fn compoundStmt(p: *Parser, is_fn_body: bool, stmt_expr_state: ?*StmtExprState) Error!?Node.Index {
5371 const l_brace = p.eatToken(.l_brace) orelse return null;5389 const l_brace = p.eatToken(.l_brace) orelse return null;
53725390
5391 const gpa = p.comp.gpa;
5373 const decl_buf_top = p.decl_buf.items.len;5392 const decl_buf_top = p.decl_buf.items.len;
5374 defer p.decl_buf.items.len = decl_buf_top;5393 defer p.decl_buf.items.len = decl_buf_top;
53755394
...@@ -5406,7 +5425,7 @@ fn compoundStmt(p: *Parser, is_fn_body: bool, stmt_expr_state: ?*StmtExprState)...@@ -5406,7 +5425,7 @@ fn compoundStmt(p: *Parser, is_fn_body: bool, stmt_expr_state: ?*StmtExprState)
5406 .last_expr_qt = s.qt(&p.tree),5425 .last_expr_qt = s.qt(&p.tree),
5407 };5426 };
5408 }5427 }
5409 try p.decl_buf.append(s);5428 try p.decl_buf.append(gpa, s);
54105429
5411 if (noreturn_index == null and p.nodeIsNoreturn(s) == .yes) {5430 if (noreturn_index == null and p.nodeIsNoreturn(s) == .yes) {
5412 noreturn_index = p.tok_i;5431 noreturn_index = p.tok_i;
...@@ -5456,10 +5475,10 @@ fn compoundStmt(p: *Parser, is_fn_body: bool, stmt_expr_state: ?*StmtExprState)...@@ -5456,10 +5475,10 @@ fn compoundStmt(p: *Parser, is_fn_body: bool, stmt_expr_state: ?*StmtExprState)
5456 .return_qt = ret_qt,5475 .return_qt = ret_qt,
5457 .operand = .{ .implicit = return_zero },5476 .operand = .{ .implicit = return_zero },
5458 } });5477 } });
5459 try p.decl_buf.append(implicit_ret);5478 try p.decl_buf.append(gpa, implicit_ret);
5460 }5479 }
5461 if (p.func.ident) |some| try p.decl_buf.insert(decl_buf_top, some.node);5480 if (p.func.ident) |some| try p.decl_buf.insert(gpa, decl_buf_top, some.node);
5462 if (p.func.pretty_ident) |some| try p.decl_buf.insert(decl_buf_top, some.node);5481 if (p.func.pretty_ident) |some| try p.decl_buf.insert(gpa, decl_buf_top, some.node);
5463 }5482 }
54645483
5465 return try p.addNode(.{ .compound_stmt = .{5484 return try p.addNode(.{ .compound_stmt = .{
...@@ -5988,6 +6007,7 @@ pub const Result = struct {...@@ -5988,6 +6007,7 @@ pub const Result = struct {
59886007
5989 fn adjustCondExprPtrs(a: *Result, tok: TokenIndex, b: *Result, p: *Parser) !bool {6008 fn adjustCondExprPtrs(a: *Result, tok: TokenIndex, b: *Result, p: *Parser) !bool {
5990 assert(a.qt.isPointer(p.comp) and b.qt.isPointer(p.comp));6009 assert(a.qt.isPointer(p.comp) and b.qt.isPointer(p.comp));
6010 const gpa = p.comp.gpa;
59916011
5992 const a_elem = a.qt.childType(p.comp);6012 const a_elem = a.qt.childType(p.comp);
5993 const b_elem = b.qt.childType(p.comp);6013 const b_elem = b.qt.childType(p.comp);
...@@ -6014,14 +6034,14 @@ pub const Result = struct {...@@ -6014,14 +6034,14 @@ pub const Result = struct {
6014 }6034 }
60156035
6016 if (!adjusted_elem_qt.eqlQualified(a_elem, p.comp)) {6036 if (!adjusted_elem_qt.eqlQualified(a_elem, p.comp)) {
6017 a.qt = try p.comp.type_store.put(p.gpa, .{ .pointer = .{6037 a.qt = try p.comp.type_store.put(gpa, .{ .pointer = .{
6018 .child = adjusted_elem_qt,6038 .child = adjusted_elem_qt,
6019 .decayed = null,6039 .decayed = null,
6020 } });6040 } });
6021 try a.implicitCast(p, .bitcast, tok);6041 try a.implicitCast(p, .bitcast, tok);
6022 }6042 }
6023 if (!adjusted_elem_qt.eqlQualified(b_elem, p.comp)) {6043 if (!adjusted_elem_qt.eqlQualified(b_elem, p.comp)) {
6024 b.qt = try p.comp.type_store.put(p.gpa, .{ .pointer = .{6044 b.qt = try p.comp.type_store.put(gpa, .{ .pointer = .{
6025 .child = adjusted_elem_qt,6045 .child = adjusted_elem_qt,
6026 .decayed = null,6046 .decayed = null,
6027 } });6047 } });
...@@ -6659,7 +6679,7 @@ pub const Result = struct {...@@ -6659,7 +6679,7 @@ pub const Result = struct {
6659 /// Saves value without altering the result.6679 /// Saves value without altering the result.
6660 fn putValue(res: *const Result, p: *Parser) !void {6680 fn putValue(res: *const Result, p: *Parser) !void {
6661 if (res.val.opt_ref == .none or res.val.opt_ref == .null) return;6681 if (res.val.opt_ref == .none or res.val.opt_ref == .null) return;
6662 if (!p.in_macro) try p.tree.value_map.put(p.gpa, res.node, res.val);6682 if (!p.in_macro) try p.tree.value_map.put(p.comp.gpa, res.node, res.val);
6663 }6683 }
66646684
6665 fn castType(res: *Result, p: *Parser, dest_qt: QualType, operand_tok: TokenIndex, l_paren: TokenIndex) !void {6685 fn castType(res: *Result, p: *Parser, dest_qt: QualType, operand_tok: TokenIndex, l_paren: TokenIndex) !void {
...@@ -7085,9 +7105,13 @@ pub const Result = struct {...@@ -7085,9 +7105,13 @@ pub const Result = struct {
7085 return; // ok7105 return; // ok
7086 }7106 }
7087 } else {7107 } else {
7088 if (c == .assign and (dest_unqual.is(p.comp, .array) or dest_unqual.is(p.comp, .func))) {7108 if (c == .assign) {
7089 try p.err(tok, .not_assignable, .{});7109 const base_type = dest_unqual.base(p.comp);
7090 return;7110 switch (base_type.type) {
7111 .array => return p.err(tok, .array_not_assignable, .{base_type.qt}),
7112 .func => return p.err(tok, .non_object_not_assignable, .{base_type.qt}),
7113 else => {},
7114 }
7091 } else if (c == .test_coerce) {7115 } else if (c == .test_coerce) {
7092 return error.CoercionFailed;7116 return error.CoercionFailed;
7093 }7117 }
...@@ -7186,6 +7210,47 @@ fn nonAssignExpr(assign_node: std.meta.Tag(Node)) std.meta.Tag(Node) {...@@ -7186,6 +7210,47 @@ fn nonAssignExpr(assign_node: std.meta.Tag(Node)) std.meta.Tag(Node) {
7186 };7210 };
7187}7211}
71887212
7213fn unwrapNestedOperation(p: *Parser, node_idx: Node.Index) ?Node.DeclRef {
7214 return loop: switch (node_idx.get(&p.tree)) {
7215 inline .array_access_expr,
7216 .member_access_ptr_expr,
7217 .member_access_expr,
7218 => |memb_or_arr_access| continue :loop memb_or_arr_access.base.get(&p.tree),
7219 inline .cast,
7220 .paren_expr,
7221 .pre_inc_expr,
7222 .post_inc_expr,
7223 .pre_dec_expr,
7224 .post_dec_expr,
7225 => |cast_or_unary| continue :loop cast_or_unary.operand.get(&p.tree),
7226 .sub_expr,
7227 .add_expr,
7228 => |bin| continue :loop bin.lhs.get(&p.tree),
7229 .call_expr => |call| continue :loop call.callee.get(&p.tree),
7230 .decl_ref_expr => |decl_ref| decl_ref,
7231 else => null,
7232 };
7233}
7234
7235fn issueDeclaredConstHereNote(p: *Parser, decl_ref: Tree.Node.DeclRef, var_name: []const u8) Compilation.Error!void {
7236 const location = switch (decl_ref.decl.get(&p.tree)) {
7237 .variable => |variable| variable.name_tok,
7238 .param => |param| param.name_tok,
7239 else => return,
7240 };
7241 try p.err(location, .declared_const_here, .{var_name});
7242}
7243
7244fn issueConstAssignmetDiagnostics(p: *Parser, node_idx: Node.Index, tok: TokenIndex) Compilation.Error!void {
7245 if (p.unwrapNestedOperation(node_idx)) |unwrapped| {
7246 const name = p.tokSlice(unwrapped.name_tok);
7247 try p.err(tok, .const_var_assignment, .{ name, unwrapped.qt });
7248 try p.issueDeclaredConstHereNote(unwrapped, name);
7249 } else {
7250 try p.err(tok, .not_assignable, .{});
7251 }
7252}
7253
7189/// assignExpr7254/// assignExpr
7190/// : condExpr7255/// : condExpr
7191/// | unExpr ('=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '&=' | '^=' | '|=') assignExpr7256/// | unExpr ('=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '&=' | '^=' | '|=') assignExpr
...@@ -7209,7 +7274,7 @@ fn assignExpr(p: *Parser) Error!?Result {...@@ -7209,7 +7274,7 @@ fn assignExpr(p: *Parser) Error!?Result {
72097274
7210 var is_const: bool = undefined;7275 var is_const: bool = undefined;
7211 if (!p.tree.isLvalExtra(lhs.node, &is_const) or is_const) {7276 if (!p.tree.isLvalExtra(lhs.node, &is_const) or is_const) {
7212 try p.err(tok, .not_assignable, .{});7277 try p.issueConstAssignmetDiagnostics(lhs.node, tok);
7213 lhs.qt = .invalid;7278 lhs.qt = .invalid;
7214 }7279 }
72157280
...@@ -7702,12 +7767,13 @@ fn shufflevector(p: *Parser, builtin_tok: TokenIndex) Error!Result {...@@ -7702,12 +7767,13 @@ fn shufflevector(p: *Parser, builtin_tok: TokenIndex) Error!Result {
7702 };7767 };
7703 const negative_one = try Value.intern(p.comp, .{ .int = .{ .i64 = -1 } });7768 const negative_one = try Value.intern(p.comp, .{ .int = .{ .i64 = -1 } });
77047769
7770 const gpa = p.comp.gpa;
7705 const list_buf_top = p.list_buf.items.len;7771 const list_buf_top = p.list_buf.items.len;
7706 defer p.list_buf.items.len = list_buf_top;7772 defer p.list_buf.items.len = list_buf_top;
7707 while (p.eatToken(.comma)) |_| {7773 while (p.eatToken(.comma)) |_| {
7708 const index_tok = p.tok_i;7774 const index_tok = p.tok_i;
7709 const index = try p.integerConstExpr(.gnu_folding_extension);7775 const index = try p.integerConstExpr(.gnu_folding_extension);
7710 try p.list_buf.append(index.node);7776 try p.list_buf.append(gpa, index.node);
7711 if (index.val.compare(.lt, negative_one, p.comp)) {7777 if (index.val.compare(.lt, negative_one, p.comp)) {
7712 try p.err(index_tok, .shufflevector_negative_index, .{});7778 try p.err(index_tok, .shufflevector_negative_index, .{});
7713 } else if (max_index != null and index.val.compare(.gte, max_index.?, p.comp)) {7779 } else if (max_index != null and index.val.compare(.gte, max_index.?, p.comp)) {
...@@ -7727,7 +7793,7 @@ fn shufflevector(p: *Parser, builtin_tok: TokenIndex) Error!Result {...@@ -7727,7 +7793,7 @@ fn shufflevector(p: *Parser, builtin_tok: TokenIndex) Error!Result {
7727 } else if (p.list_buf.items.len == list_buf_top) {7793 } else if (p.list_buf.items.len == list_buf_top) {
7728 res_qt = lhs.qt;7794 res_qt = lhs.qt;
7729 } else {7795 } else {
7730 res_qt = try p.comp.type_store.put(p.gpa, .{ .vector = .{7796 res_qt = try p.comp.type_store.put(gpa, .{ .vector = .{
7731 .elem = lhs.qt.childType(p.comp),7797 .elem = lhs.qt.childType(p.comp),
7732 .len = @intCast(p.list_buf.items.len - list_buf_top),7798 .len = @intCast(p.list_buf.items.len - list_buf_top),
7733 } });7799 } });
...@@ -8086,6 +8152,7 @@ fn computeOffset(p: *Parser, res: Result) !Value {...@@ -8086,6 +8152,7 @@ fn computeOffset(p: *Parser, res: Result) !Value {
8086/// | keyword_alignof '(' typeName ')'8152/// | keyword_alignof '(' typeName ')'
8087/// | keyword_c23_alignof '(' typeName ')'8153/// | keyword_c23_alignof '(' typeName ')'
8088fn unExpr(p: *Parser) Error!?Result {8154fn unExpr(p: *Parser) Error!?Result {
8155 const gpa = p.comp.gpa;
8089 const tok = p.tok_i;8156 const tok = p.tok_i;
8090 switch (p.tok_ids[tok]) {8157 switch (p.tok_ids[tok]) {
8091 .ampersand_ampersand => {8158 .ampersand_ampersand => {
...@@ -8097,7 +8164,7 @@ fn unExpr(p: *Parser) Error!?Result {...@@ -8097,7 +8164,7 @@ fn unExpr(p: *Parser) Error!?Result {
80978164
8098 const str = p.tokSlice(name_tok);8165 const str = p.tokSlice(name_tok);
8099 if (p.findLabel(str) == null) {8166 if (p.findLabel(str) == null) {
8100 try p.labels.append(.{ .unresolved_goto = name_tok });8167 try p.labels.append(gpa, .{ .unresolved_goto = name_tok });
8101 }8168 }
81028169
8103 return .{8170 return .{
...@@ -8139,7 +8206,7 @@ fn unExpr(p: *Parser) Error!?Result {...@@ -8139,7 +8206,7 @@ fn unExpr(p: *Parser) Error!?Result {
8139 }8206 }
8140 addr_val = try p.computeOffset(operand);8207 addr_val = try p.computeOffset(operand);
81418208
8142 operand.qt = try p.comp.type_store.put(p.gpa, .{ .pointer = .{8209 operand.qt = try p.comp.type_store.put(gpa, .{ .pointer = .{
8143 .child = operand.qt,8210 .child = operand.qt,
8144 .decayed = null,8211 .decayed = null,
8145 } });8212 } });
...@@ -8845,6 +8912,7 @@ fn checkComplexArg(p: *Parser, builtin_tok: TokenIndex, first_after: TokenIndex,...@@ -8845,6 +8912,7 @@ fn checkComplexArg(p: *Parser, builtin_tok: TokenIndex, first_after: TokenIndex,
8845}8912}
88468913
8847fn callExpr(p: *Parser, lhs: Result) Error!Result {8914fn callExpr(p: *Parser, lhs: Result) Error!Result {
8915 const gpa = p.comp.gpa;
8848 const l_paren = p.tok_i;8916 const l_paren = p.tok_i;
8849 p.tok_i += 1;8917 p.tok_i += 1;
88508918
...@@ -8892,7 +8960,7 @@ fn callExpr(p: *Parser, lhs: Result) Error!Result {...@@ -8892,7 +8960,7 @@ fn callExpr(p: *Parser, lhs: Result) Error!Result {
88928960
8893 try call_expr.checkVarArg(p, first_after, param_tok, &arg, arg_count);8961 try call_expr.checkVarArg(p, first_after, param_tok, &arg, arg_count);
8894 try arg.saveValue(p);8962 try arg.saveValue(p);
8895 try p.list_buf.append(arg.node);8963 try p.list_buf.append(gpa, arg.node);
8896 arg_count += 1;8964 arg_count += 1;
88978965
8898 _ = p.eatToken(.comma) orelse {8966 _ = p.eatToken(.comma) orelse {
...@@ -8927,7 +8995,7 @@ fn callExpr(p: *Parser, lhs: Result) Error!Result {...@@ -8927,7 +8995,7 @@ fn callExpr(p: *Parser, lhs: Result) Error!Result {
8927 }8995 }
8928 }8996 }
8929 try arg.saveValue(p);8997 try arg.saveValue(p);
8930 try p.list_buf.append(arg.node);8998 try p.list_buf.append(gpa, arg.node);
8931 arg_count += 1;8999 arg_count += 1;
89329000
8933 _ = p.eatToken(.comma) orelse {9001 _ = p.eatToken(.comma) orelse {
...@@ -9024,6 +9092,7 @@ fn primaryExpr(p: *Parser) Error!?Result {...@@ -9024,6 +9092,7 @@ fn primaryExpr(p: *Parser) Error!?Result {
9024 return grouped_expr;9092 return grouped_expr;
9025 }9093 }
90269094
9095 const gpa = p.comp.gpa;
9027 switch (p.tok_ids[p.tok_i]) {9096 switch (p.tok_ids[p.tok_i]) {
9028 .identifier, .extended_identifier => {9097 .identifier, .extended_identifier => {
9029 const name_tok = try p.expectIdentifier();9098 const name_tok = try p.expectIdentifier();
...@@ -9134,7 +9203,7 @@ fn primaryExpr(p: *Parser) Error!?Result {...@@ -9134,7 +9203,7 @@ fn primaryExpr(p: *Parser) Error!?Result {
9134 else9203 else
9135 try p.err(name_tok, .implicit_func_decl, .{name});9204 try p.err(name_tok, .implicit_func_decl, .{name});
91369205
9137 const func_qt = try p.comp.type_store.put(p.gpa, .{ .func = .{9206 const func_qt = try p.comp.type_store.put(gpa, .{ .func = .{
9138 .return_type = .int,9207 .return_type = .int,
9139 .kind = .old_style,9208 .kind = .old_style,
9140 .params = &.{},9209 .params = &.{},
...@@ -9150,7 +9219,7 @@ fn primaryExpr(p: *Parser) Error!?Result {...@@ -9150,7 +9219,7 @@ fn primaryExpr(p: *Parser) Error!?Result {
9150 },9219 },
9151 });9220 });
91529221
9153 try p.decl_buf.append(node);9222 try p.decl_buf.append(gpa, node);
9154 try p.syms.declareSymbol(p, interned_name, func_qt, name_tok, node);9223 try p.syms.declareSymbol(p, interned_name, func_qt, name_tok, node);
91559224
9156 return .{9225 return .{
...@@ -9211,8 +9280,11 @@ fn primaryExpr(p: *Parser) Error!?Result {...@@ -9211,8 +9280,11 @@ fn primaryExpr(p: *Parser) Error!?Result {
9211 const strings_top = p.strings.items.len;9280 const strings_top = p.strings.items.len;
9212 defer p.strings.items.len = strings_top;9281 defer p.strings.items.len = strings_top;
92139282
9214 try p.strings.appendSlice(p.tokSlice(p.func.name));9283 const name = p.tokSlice(p.func.name);
9215 try p.strings.append(0);9284 try p.strings.ensureUnusedCapacity(gpa, name.len + 1);
9285
9286 p.strings.appendSliceAssumeCapacity(name);
9287 p.strings.appendAssumeCapacity(0);
9216 const predef = try p.makePredefinedIdentifier(p.strings.items[strings_top..]);9288 const predef = try p.makePredefinedIdentifier(p.strings.items[strings_top..]);
9217 ty = predef.qt;9289 ty = predef.qt;
9218 p.func.ident = predef;9290 p.func.ident = predef;
...@@ -9220,7 +9292,7 @@ fn primaryExpr(p: *Parser) Error!?Result {...@@ -9220,7 +9292,7 @@ fn primaryExpr(p: *Parser) Error!?Result {
9220 const predef = try p.makePredefinedIdentifier("\x00");9292 const predef = try p.makePredefinedIdentifier("\x00");
9221 ty = predef.qt;9293 ty = predef.qt;
9222 p.func.ident = predef;9294 p.func.ident = predef;
9223 try p.decl_buf.append(predef.node);9295 try p.decl_buf.append(gpa, predef.node);
9224 }9296 }
9225 if (p.func.qt == null) try p.err(p.tok_i, .predefined_top_level, .{});9297 if (p.func.qt == null) try p.err(p.tok_i, .predefined_top_level, .{});
92269298
...@@ -9241,7 +9313,7 @@ fn primaryExpr(p: *Parser) Error!?Result {...@@ -9241,7 +9313,7 @@ fn primaryExpr(p: *Parser) Error!?Result {
9241 if (p.func.pretty_ident) |some| {9313 if (p.func.pretty_ident) |some| {
9242 qt = some.qt;9314 qt = some.qt;
9243 } else if (p.func.qt) |func_qt| {9315 } else if (p.func.qt) |func_qt| {
9244 var sf = std.heap.stackFallback(1024, p.gpa);9316 var sf = std.heap.stackFallback(1024, gpa);
9245 var allocating: std.Io.Writer.Allocating = .init(sf.get());9317 var allocating: std.Io.Writer.Allocating = .init(sf.get());
9246 defer allocating.deinit();9318 defer allocating.deinit();
92479319
...@@ -9255,7 +9327,7 @@ fn primaryExpr(p: *Parser) Error!?Result {...@@ -9255,7 +9327,7 @@ fn primaryExpr(p: *Parser) Error!?Result {
9255 const predef = try p.makePredefinedIdentifier("top level\x00");9327 const predef = try p.makePredefinedIdentifier("top level\x00");
9256 qt = predef.qt;9328 qt = predef.qt;
9257 p.func.pretty_ident = predef;9329 p.func.pretty_ident = predef;
9258 try p.decl_buf.append(predef.node);9330 try p.decl_buf.append(gpa, predef.node);
9259 }9331 }
9260 if (p.func.qt == null) try p.err(p.tok_i, .predefined_top_level, .{});9332 if (p.func.qt == null) try p.err(p.tok_i, .predefined_top_level, .{});
9261 return .{9333 return .{
...@@ -9332,7 +9404,8 @@ fn primaryExpr(p: *Parser) Error!?Result {...@@ -9332,7 +9404,8 @@ fn primaryExpr(p: *Parser) Error!?Result {
9332}9404}
93339405
9334fn makePredefinedIdentifier(p: *Parser, slice: []const u8) !Result {9406fn makePredefinedIdentifier(p: *Parser, slice: []const u8) !Result {
9335 const array_qt = try p.comp.type_store.put(p.gpa, .{ .array = .{9407 const gpa = p.comp.gpa;
9408 const array_qt = try p.comp.type_store.put(gpa, .{ .array = .{
9336 .elem = .{ .@"const" = true, ._index = .int_char },9409 .elem = .{ .@"const" = true, ._index = .int_char },
9337 .len = .{ .fixed = slice.len },9410 .len = .{ .fixed = slice.len },
9338 } });9411 } });
...@@ -9340,7 +9413,7 @@ fn makePredefinedIdentifier(p: *Parser, slice: []const u8) !Result {...@@ -9340,7 +9413,7 @@ fn makePredefinedIdentifier(p: *Parser, slice: []const u8) !Result {
9340 const val = try Value.intern(p.comp, .{ .bytes = slice });9413 const val = try Value.intern(p.comp, .{ .bytes = slice });
93419414
9342 const str_lit = try p.addNode(.{ .string_literal_expr = .{ .qt = array_qt, .literal_tok = p.tok_i, .kind = .ascii } });9415 const str_lit = try p.addNode(.{ .string_literal_expr = .{ .qt = array_qt, .literal_tok = p.tok_i, .kind = .ascii } });
9343 if (!p.in_macro) try p.tree.value_map.put(p.gpa, str_lit, val);9416 if (!p.in_macro) try p.tree.value_map.put(gpa, str_lit, val);
93449417
9345 return .{ .qt = array_qt, .node = try p.addNode(.{9418 return .{ .qt = array_qt, .node = try p.addNode(.{
9346 .variable = .{9419 .variable = .{
...@@ -9356,6 +9429,7 @@ fn makePredefinedIdentifier(p: *Parser, slice: []const u8) !Result {...@@ -9356,6 +9429,7 @@ fn makePredefinedIdentifier(p: *Parser, slice: []const u8) !Result {
9356}9429}
93579430
9358fn stringLiteral(p: *Parser) Error!Result {9431fn stringLiteral(p: *Parser) Error!Result {
9432 const gpa = p.comp.gpa;
9359 const string_start = p.tok_i;9433 const string_start = p.tok_i;
9360 var string_end = p.tok_i;9434 var string_end = p.tok_i;
9361 var string_kind: text_literal.Kind = .char;9435 var string_kind: text_literal.Kind = .char;
...@@ -9380,7 +9454,7 @@ fn stringLiteral(p: *Parser) Error!Result {...@@ -9380,7 +9454,7 @@ fn stringLiteral(p: *Parser) Error!Result {
9380 defer p.strings.items.len = strings_top;9454 defer p.strings.items.len = strings_top;
93819455
9382 const literal_start = mem.alignForward(usize, strings_top, @intFromEnum(char_width));9456 const literal_start = mem.alignForward(usize, strings_top, @intFromEnum(char_width));
9383 try p.strings.resize(literal_start);9457 try p.strings.resize(gpa, literal_start);
93849458
9385 while (p.tok_i < string_end) : (p.tok_i += 1) {9459 while (p.tok_i < string_end) : (p.tok_i += 1) {
9386 const this_kind = text_literal.Kind.classify(p.tok_ids[p.tok_i], .string_literal).?;9460 const this_kind = text_literal.Kind.classify(p.tok_ids[p.tok_i], .string_literal).?;
...@@ -9395,7 +9469,7 @@ fn stringLiteral(p: *Parser) Error!Result {...@@ -9395,7 +9469,7 @@ fn stringLiteral(p: *Parser) Error!Result {
9395 .incorrect_encoding_is_error = count > 1,9469 .incorrect_encoding_is_error = count > 1,
9396 };9470 };
93979471
9398 try p.strings.ensureUnusedCapacity((slice.len + 1) * @intFromEnum(char_width)); // +1 for null terminator9472 try p.strings.ensureUnusedCapacity(gpa, (slice.len + 1) * @intFromEnum(char_width)); // +1 for null terminator
9399 while (try char_literal_parser.next()) |item| switch (item) {9473 while (try char_literal_parser.next()) |item| switch (item) {
9400 .value => |v| {9474 .value => |v| {
9401 switch (char_width) {9475 switch (char_width) {
...@@ -9443,7 +9517,7 @@ fn stringLiteral(p: *Parser) Error!Result {...@@ -9443,7 +9517,7 @@ fn stringLiteral(p: *Parser) Error!Result {
9443 const dest_len = std.mem.alignBackward(usize, capacity_slice.len, 2);9517 const dest_len = std.mem.alignBackward(usize, capacity_slice.len, 2);
9444 const dest = std.mem.bytesAsSlice(u16, capacity_slice[0..dest_len]);9518 const dest = std.mem.bytesAsSlice(u16, capacity_slice[0..dest_len]);
9445 const words_written = std.unicode.utf8ToUtf16Le(dest, view.bytes) catch unreachable;9519 const words_written = std.unicode.utf8ToUtf16Le(dest, view.bytes) catch unreachable;
9446 p.strings.resize(p.strings.items.len + words_written * 2) catch unreachable;9520 p.strings.resize(gpa, p.strings.items.len + words_written * 2) catch unreachable;
9447 },9521 },
9448 .@"4" => {9522 .@"4" => {
9449 var it = view.iterator();9523 var it = view.iterator();
...@@ -9465,11 +9539,11 @@ fn stringLiteral(p: *Parser) Error!Result {...@@ -9465,11 +9539,11 @@ fn stringLiteral(p: *Parser) Error!Result {
9465 p.comp.interner.strings.items.len,9539 p.comp.interner.strings.items.len,
9466 string_kind.internalStorageAlignment(p.comp),9540 string_kind.internalStorageAlignment(p.comp),
9467 );9541 );
9468 try p.comp.interner.strings.resize(p.gpa, interned_align);9542 try p.comp.interner.strings.resize(gpa, interned_align);
94699543
9470 const val = try Value.intern(p.comp, .{ .bytes = slice });9544 const val = try Value.intern(p.comp, .{ .bytes = slice });
94719545
9472 const array_qt = try p.comp.type_store.put(p.gpa, .{ .array = .{9546 const array_qt = try p.comp.type_store.put(gpa, .{ .array = .{
9473 .elem = string_kind.elementType(p.comp),9547 .elem = string_kind.elementType(p.comp),
9474 .len = .{ .fixed = @divExact(slice.len, @intFromEnum(char_width)) },9548 .len = .{ .fixed = @divExact(slice.len, @intFromEnum(char_width)) },
9475 } });9549 } });
...@@ -9510,6 +9584,7 @@ fn charLiteral(p: *Parser) Error!?Result {...@@ -9510,6 +9584,7 @@ fn charLiteral(p: *Parser) Error!?Result {
9510 if (char_kind == .utf_8) try p.err(p.tok_i, .u8_char_lit, .{});9584 if (char_kind == .utf_8) try p.err(p.tok_i, .u8_char_lit, .{});
9511 var val: u32 = 0;9585 var val: u32 = 0;
95129586
9587 const gpa = p.comp.gpa;
9513 const slice = char_kind.contentSlice(p.tokSlice(p.tok_i));9588 const slice = char_kind.contentSlice(p.tokSlice(p.tok_i));
95149589
9515 var is_multichar = false;9590 var is_multichar = false;
...@@ -9528,21 +9603,24 @@ fn charLiteral(p: *Parser) Error!?Result {...@@ -9528,21 +9603,24 @@ fn charLiteral(p: *Parser) Error!?Result {
9528 };9603 };
95299604
9530 const max_chars_expected = 4;9605 const max_chars_expected = 4;
9531 var stack_fallback = std.heap.stackFallback(max_chars_expected * @sizeOf(u32), p.comp.gpa);9606 var sf = std.heap.stackFallback(max_chars_expected * @sizeOf(u32), gpa);
9532 var chars = std.array_list.Managed(u32).initCapacity(stack_fallback.get(), max_chars_expected) catch unreachable; // stack allocation already succeeded9607 const allocator = sf.get();
9533 defer chars.deinit();9608 var chars: std.ArrayList(u32) = .empty;
9609 defer chars.deinit(allocator);
9610
9611 chars.ensureUnusedCapacity(allocator, max_chars_expected) catch unreachable; // stack allocation already succeeded
95349612
9535 while (try char_literal_parser.next()) |item| switch (item) {9613 while (try char_literal_parser.next()) |item| switch (item) {
9536 .value => |v| try chars.append(v),9614 .value => |v| try chars.append(allocator, v),
9537 .codepoint => |c| try chars.append(c),9615 .codepoint => |c| try chars.append(allocator, c),
9538 .improperly_encoded => |s| {9616 .improperly_encoded => |s| {
9539 try chars.ensureUnusedCapacity(s.len);9617 try chars.ensureUnusedCapacity(allocator, s.len);
9540 for (s) |c| chars.appendAssumeCapacity(c);9618 for (s) |c| chars.appendAssumeCapacity(c);
9541 },9619 },
9542 .utf8_text => |view| {9620 .utf8_text => |view| {
9543 var it = view.iterator();9621 var it = view.iterator();
9544 var max_codepoint_seen: u21 = 0;9622 var max_codepoint_seen: u21 = 0;
9545 try chars.ensureUnusedCapacity(view.bytes.len);9623 try chars.ensureUnusedCapacity(allocator, view.bytes.len);
9546 while (it.nextCodepoint()) |c| {9624 while (it.nextCodepoint()) |c| {
9547 max_codepoint_seen = @max(max_codepoint_seen, c);9625 max_codepoint_seen = @max(max_codepoint_seen, c);
9548 chars.appendAssumeCapacity(c);9626 chars.appendAssumeCapacity(c);
...@@ -9603,7 +9681,7 @@ fn charLiteral(p: *Parser) Error!?Result {...@@ -9603,7 +9681,7 @@ fn charLiteral(p: *Parser) Error!?Result {
9603 _ = try value.intCast(.char, p.comp);9681 _ = try value.intCast(.char, p.comp);
9604 }9682 }
96059683
9606 const res = Result{9684 const res: Result = .{
9607 .qt = if (p.in_macro) macro_qt else char_literal_qt,9685 .qt = if (p.in_macro) macro_qt else char_literal_qt,
9608 .val = value,9686 .val = value,
9609 .node = try p.addNode(.{ .char_literal = .{9687 .node = try p.addNode(.{ .char_literal = .{
...@@ -9618,7 +9696,7 @@ fn charLiteral(p: *Parser) Error!?Result {...@@ -9618,7 +9696,7 @@ fn charLiteral(p: *Parser) Error!?Result {
9618 },9696 },
9619 } }),9697 } }),
9620 };9698 };
9621 if (!p.in_macro) try p.tree.value_map.put(p.gpa, res.node, res.val);9699 if (!p.in_macro) try p.tree.value_map.put(gpa, res.node, res.val);
9622 return res;9700 return res;
9623}9701}
96249702
...@@ -9633,7 +9711,7 @@ fn parseFloat(p: *Parser, buf: []const u8, suffix: NumberSuffix, tok_i: TokenInd...@@ -9633,7 +9711,7 @@ fn parseFloat(p: *Parser, buf: []const u8, suffix: NumberSuffix, tok_i: TokenInd
9633 else => unreachable,9711 else => unreachable,
9634 };9712 };
9635 const val = try Value.intern(p.comp, key: {9713 const val = try Value.intern(p.comp, key: {
9636 try p.strings.ensureUnusedCapacity(buf.len);9714 try p.strings.ensureUnusedCapacity(p.comp.gpa, buf.len);
96379715
9638 const strings_top = p.strings.items.len;9716 const strings_top = p.strings.items.len;
9639 defer p.strings.items.len = strings_top;9717 defer p.strings.items.len = strings_top;
...@@ -9821,14 +9899,15 @@ fn parseInt(p: *Parser, prefix: NumberPrefix, buf: []const u8, suffix: NumberSuf...@@ -9821,14 +9899,15 @@ fn parseInt(p: *Parser, prefix: NumberPrefix, buf: []const u8, suffix: NumberSuf
9821}9899}
98229900
9823fn bitInt(p: *Parser, base: u8, buf: []const u8, suffix: NumberSuffix, tok_i: TokenIndex) Error!Result {9901fn bitInt(p: *Parser, base: u8, buf: []const u8, suffix: NumberSuffix, tok_i: TokenIndex) Error!Result {
9902 const gpa = p.comp.gpa;
9824 try p.err(tok_i, .pre_c23_compat, .{"'_BitInt' suffix for literals"});9903 try p.err(tok_i, .pre_c23_compat, .{"'_BitInt' suffix for literals"});
9825 try p.err(tok_i, .bitint_suffix, .{});9904 try p.err(tok_i, .bitint_suffix, .{});
98269905
9827 var managed = try big.int.Managed.init(p.gpa);9906 var managed = try big.int.Managed.init(gpa);
9828 defer managed.deinit();9907 defer managed.deinit();
98299908
9830 {9909 {
9831 try p.strings.ensureUnusedCapacity(buf.len);9910 try p.strings.ensureUnusedCapacity(gpa, buf.len);
98329911
9833 const strings_top = p.strings.items.len;9912 const strings_top = p.strings.items.len;
9834 defer p.strings.items.len = strings_top;9913 defer p.strings.items.len = strings_top;
...@@ -9853,7 +9932,7 @@ fn bitInt(p: *Parser, base: u8, buf: []const u8, suffix: NumberSuffix, tok_i: To...@@ -9853,7 +9932,7 @@ fn bitInt(p: *Parser, base: u8, buf: []const u8, suffix: NumberSuffix, tok_i: To
9853 break :blk @intCast(bits_needed);9932 break :blk @intCast(bits_needed);
9854 };9933 };
98559934
9856 const int_qt = try p.comp.type_store.put(p.gpa, .{ .bit_int = .{9935 const int_qt = try p.comp.type_store.put(gpa, .{ .bit_int = .{
9857 .bits = bits_needed,9936 .bits = bits_needed,
9858 .signedness = suffix.signedness(),9937 .signedness = suffix.signedness(),
9859 } });9938 } });
...@@ -9986,6 +10065,7 @@ fn parseNoEval(p: *Parser, comptime func: fn (*Parser) Error!?Result) Error!Resu...@@ -9986,6 +10065,7 @@ fn parseNoEval(p: *Parser, comptime func: fn (*Parser) Error!?Result) Error!Resu
9986/// : typeName ':' assignExpr10065/// : typeName ':' assignExpr
9987/// | keyword_default ':' assignExpr10066/// | keyword_default ':' assignExpr
9988fn genericSelection(p: *Parser) Error!?Result {10067fn genericSelection(p: *Parser) Error!?Result {
10068 const gpa = p.comp.gpa;
9989 const kw_generic = p.tok_i;10069 const kw_generic = p.tok_i;
9990 p.tok_i += 1;10070 p.tok_i += 1;
9991 const l_paren = try p.expectToken(.l_paren);10071 const l_paren = try p.expectToken(.l_paren);
...@@ -10030,8 +10110,8 @@ fn genericSelection(p: *Parser) Error!?Result {...@@ -10030,8 +10110,8 @@ fn genericSelection(p: *Parser) Error!?Result {
10030 .expr = res.node,10110 .expr = res.node,
10031 },10111 },
10032 });10112 });
10033 try p.list_buf.append(res.node);10113 try p.list_buf.append(gpa, res.node);
10034 try p.param_buf.append(.{ .name = undefined, .qt = qt, .name_tok = start, .node = .null });10114 try p.param_buf.append(gpa, .{ .name = undefined, .qt = qt, .name_tok = start, .node = .null });
1003510115
10036 if (qt.eql(controlling_qt, p.comp)) {10116 if (qt.eql(controlling_qt, p.comp)) {
10037 if (chosen_tok == null) {10117 if (chosen_tok == null) {
...@@ -10083,7 +10163,7 @@ fn genericSelection(p: *Parser) Error!?Result {...@@ -10083,7 +10163,7 @@ fn genericSelection(p: *Parser) Error!?Result {
10083 return error.ParsingFailed;10163 return error.ParsingFailed;
10084 }10164 }
10085 } else if (default_tok != null) {10165 } else if (default_tok != null) {
10086 try p.list_buf.append(default.node);10166 try p.list_buf.append(gpa, default.node);
10087 }10167 }
1008810168
10089 for (p.list_buf.items[list_buf_top..], list_buf_top..) |item, i| {10169 for (p.list_buf.items[list_buf_top..], list_buf_top..) |item, i| {
lib/compiler/aro/aro/Parser/Diagnostic.zig+27
...@@ -2304,6 +2304,7 @@ pub const overflow_result_requires_ptr: Diagnostic = .{...@@ -2304,6 +2304,7 @@ pub const overflow_result_requires_ptr: Diagnostic = .{
2304pub const attribute_todo: Diagnostic = .{2304pub const attribute_todo: Diagnostic = .{
2305 .fmt = "TODO: implement '{s}' attribute for {s}",2305 .fmt = "TODO: implement '{s}' attribute for {s}",
2306 .kind = .warning,2306 .kind = .warning,
2307 .opt = .@"attribute-todo",
2307};2308};
23082309
2309pub const invalid_type_underlying_enum: Diagnostic = .{2310pub const invalid_type_underlying_enum: Diagnostic = .{
...@@ -2395,3 +2396,29 @@ pub const invalid_nullability: Diagnostic = .{...@@ -2395,3 +2396,29 @@ pub const invalid_nullability: Diagnostic = .{
2395 .fmt = "nullability specifier cannot be applied to non-pointer type {qt}",2396 .fmt = "nullability specifier cannot be applied to non-pointer type {qt}",
2396 .kind = .@"error",2397 .kind = .@"error",
2397};2398};
2399
2400pub const array_not_assignable: Diagnostic = .{
2401 .fmt = "array type {qt} is not assignable",
2402 .kind = .@"error",
2403};
2404
2405pub const non_object_not_assignable: Diagnostic = .{
2406 .fmt = "non-object type {qt} is not assignable",
2407 .kind = .@"error",
2408};
2409
2410pub const const_var_assignment: Diagnostic = .{
2411 .fmt = "cannot assign to variable '{s}' with const-qualified type {qt}",
2412 .kind = .@"error",
2413};
2414
2415pub const declared_const_here: Diagnostic = .{
2416 .fmt = "variable '{s}' declared const here",
2417 .kind = .note,
2418};
2419
2420pub const nonnull_not_applicable: Diagnostic = .{
2421 .fmt = "'nonnull' attribute only applies to functions, methods, and parameters",
2422 .kind = .warning,
2423 .opt = .@"ignored-attributes",
2424};
lib/compiler/aro/aro/Pragma.zig+2-2
...@@ -60,7 +60,7 @@ pub fn pasteTokens(pp: *Preprocessor, start_idx: TokenIndex) ![]const u8 {...@@ -60,7 +60,7 @@ pub fn pasteTokens(pp: *Preprocessor, start_idx: TokenIndex) ![]const u8 {
60 .string_literal => {60 .string_literal => {
61 if (rparen_count != 0) return error.ExpectedStringLiteral;61 if (rparen_count != 0) return error.ExpectedStringLiteral;
62 const str = pp.expandedSlice(tok);62 const str = pp.expandedSlice(tok);
63 try pp.char_buf.appendSlice(str[1 .. str.len - 1]);63 try pp.char_buf.appendSlice(pp.comp.gpa, str[1 .. str.len - 1]);
64 },64 },
65 else => return error.ExpectedStringLiteral,65 else => return error.ExpectedStringLiteral,
66 }66 }
...@@ -194,7 +194,7 @@ pub const Diagnostic = struct {...@@ -194,7 +194,7 @@ pub const Diagnostic = struct {
194};194};
195195
196pub fn err(pp: *Preprocessor, tok_i: TokenIndex, diagnostic: Diagnostic, args: anytype) Compilation.Error!void {196pub fn err(pp: *Preprocessor, tok_i: TokenIndex, diagnostic: Diagnostic, args: anytype) Compilation.Error!void {
197 var sf = std.heap.stackFallback(1024, pp.gpa);197 var sf = std.heap.stackFallback(1024, pp.comp.gpa);
198 var allocating: std.Io.Writer.Allocating = .init(sf.get());198 var allocating: std.Io.Writer.Allocating = .init(sf.get());
199 defer allocating.deinit();199 defer allocating.deinit();
200200
lib/compiler/aro/aro/Preprocessor.zig+275-245
...@@ -21,7 +21,7 @@ const Token = Tree.Token;...@@ -21,7 +21,7 @@ const Token = Tree.Token;
21const TokenWithExpansionLocs = Tree.TokenWithExpansionLocs;21const TokenWithExpansionLocs = Tree.TokenWithExpansionLocs;
2222
23const DefineMap = std.StringArrayHashMapUnmanaged(Macro);23const DefineMap = std.StringArrayHashMapUnmanaged(Macro);
24const RawTokenList = std.array_list.Managed(RawToken);24const RawTokenList = std.ArrayList(RawToken);
25const max_include_depth = 200;25const max_include_depth = 200;
2626
27/// Errors that can be returned when expanding a macro.27/// Errors that can be returned when expanding a macro.
...@@ -115,16 +115,15 @@ const TokenState = struct {...@@ -115,16 +115,15 @@ const TokenState = struct {
115115
116comp: *Compilation,116comp: *Compilation,
117diagnostics: *Diagnostics,117diagnostics: *Diagnostics,
118gpa: mem.Allocator,
119118
120arena: std.heap.ArenaAllocator,119arena: std.heap.ArenaAllocator,
121defines: DefineMap = .{},120defines: DefineMap = .empty,
122/// Do not directly mutate this; use addToken / addTokenAssumeCapacity / ensureTotalTokenCapacity / ensureUnusedTokenCapacity121/// Do not directly mutate this; use addToken / addTokenAssumeCapacity / ensureTotalTokenCapacity / ensureUnusedTokenCapacity
123tokens: Token.List = .{},122tokens: Token.List = .empty,
124/// Do not directly mutate this; must be kept in sync with `tokens`123/// Do not directly mutate this; must be kept in sync with `tokens`
125expansion_entries: std.MultiArrayList(ExpansionEntry) = .{},124expansion_entries: std.MultiArrayList(ExpansionEntry) = .empty,
126token_buf: RawTokenList,125token_buf: RawTokenList = .empty,
127char_buf: std.array_list.Managed(u8),126char_buf: std.ArrayList(u8) = .empty,
128/// Counter that is incremented each time preprocess() is called127/// Counter that is incremented each time preprocess() is called
129/// Can be used to distinguish multiple preprocessings of the same file128/// Can be used to distinguish multiple preprocessings of the same file
130preprocess_count: u32 = 0,129preprocess_count: u32 = 0,
...@@ -133,9 +132,9 @@ add_expansion_nl: u32 = 0,...@@ -133,9 +132,9 @@ add_expansion_nl: u32 = 0,
133include_depth: u8 = 0,132include_depth: u8 = 0,
134counter: u32 = 0,133counter: u32 = 0,
135expansion_source_loc: Source.Location = undefined,134expansion_source_loc: Source.Location = undefined,
136poisoned_identifiers: std.StringHashMap(void),135poisoned_identifiers: std.StringHashMapUnmanaged(void) = .empty,
137/// Map from Source.Id to macro name in the `#ifndef` condition which guards the source, if any136/// Map from Source.Id to macro name in the `#ifndef` condition which guards the source, if any
138include_guards: std.AutoHashMapUnmanaged(Source.Id, []const u8) = .{},137include_guards: std.AutoHashMapUnmanaged(Source.Id, []const u8) = .empty,
139138
140/// Store `keyword_define` and `keyword_undef` tokens.139/// Store `keyword_define` and `keyword_undef` tokens.
141/// Used to implement preprocessor debug dump options140/// Used to implement preprocessor debug dump options
...@@ -143,7 +142,7 @@ include_guards: std.AutoHashMapUnmanaged(Source.Id, []const u8) = .{},...@@ -143,7 +142,7 @@ include_guards: std.AutoHashMapUnmanaged(Source.Id, []const u8) = .{},
143store_macro_tokens: bool = false,142store_macro_tokens: bool = false,
144143
145/// Memory is retained to avoid allocation on every single token.144/// Memory is retained to avoid allocation on every single token.
146top_expansion_buf: ExpandBuf,145top_expansion_buf: ExpandBuf = .empty,
147146
148/// Dump current state to stderr.147/// Dump current state to stderr.
149verbose: bool = false,148verbose: bool = false,
...@@ -156,7 +155,7 @@ hideset: Hideset,...@@ -156,7 +155,7 @@ hideset: Hideset,
156155
157/// Epoch used for __DATE__, __TIME__, and possibly __TIMESTAMP__156/// Epoch used for __DATE__, __TIME__, and possibly __TIMESTAMP__
158source_epoch: SourceEpoch,157source_epoch: SourceEpoch,
159m_times: std.AutoHashMapUnmanaged(Source.Id, u64) = .{},158m_times: std.AutoHashMapUnmanaged(Source.Id, u64) = .empty,
160159
161/// The dependency file tracking all includes and embeds.160/// The dependency file tracking all includes and embeds.
162dep_file: ?*DepFile = null,161dep_file: ?*DepFile = null,
...@@ -176,12 +175,7 @@ pub fn init(comp: *Compilation, source_epoch: SourceEpoch) Preprocessor {...@@ -176,12 +175,7 @@ pub fn init(comp: *Compilation, source_epoch: SourceEpoch) Preprocessor {
176 const pp: Preprocessor = .{175 const pp: Preprocessor = .{
177 .comp = comp,176 .comp = comp,
178 .diagnostics = comp.diagnostics,177 .diagnostics = comp.diagnostics,
179 .gpa = comp.gpa,178 .arena = .init(comp.gpa),
180 .arena = std.heap.ArenaAllocator.init(comp.gpa),
181 .token_buf = RawTokenList.init(comp.gpa),
182 .char_buf = std.array_list.Managed(u8).init(comp.gpa),
183 .poisoned_identifiers = std.StringHashMap(void).init(comp.gpa),
184 .top_expansion_buf = ExpandBuf.init(comp.gpa),
185 .hideset = .{ .comp = comp },179 .hideset = .{ .comp = comp },
186 .source_epoch = source_epoch,180 .source_epoch = source_epoch,
187 };181 };
...@@ -207,7 +201,7 @@ pub fn initDefault(comp: *Compilation) !Preprocessor {...@@ -207,7 +201,7 @@ pub fn initDefault(comp: *Compilation) !Preprocessor {
207201
208// `param_tok_id` is comptime so that the generated `tokens` list is unique for every macro.202// `param_tok_id` is comptime so that the generated `tokens` list is unique for every macro.
209fn addBuiltinMacro(pp: *Preprocessor, name: []const u8, is_func: bool, comptime param_tok_id: Token.Id) !void {203fn addBuiltinMacro(pp: *Preprocessor, name: []const u8, is_func: bool, comptime param_tok_id: Token.Id) !void {
210 try pp.defines.putNoClobber(pp.gpa, name, .{204 try pp.defines.putNoClobber(pp.comp.gpa, name, .{
211 .params = &[1][]const u8{"X"},205 .params = &[1][]const u8{"X"},
212 .tokens = &[1]RawToken{.{206 .tokens = &[1]RawToken{.{
213 .id = param_tok_id,207 .id = param_tok_id,
...@@ -248,30 +242,33 @@ pub fn addBuiltinMacros(pp: *Preprocessor) !void {...@@ -248,30 +242,33 @@ pub fn addBuiltinMacros(pp: *Preprocessor) !void {
248}242}
249243
250pub fn deinit(pp: *Preprocessor) void {244pub fn deinit(pp: *Preprocessor) void {
251 pp.defines.deinit(pp.gpa);245 const gpa = pp.comp.gpa;
252 pp.tokens.deinit(pp.gpa);246 pp.defines.deinit(gpa);
247 pp.tokens.deinit(gpa);
253 pp.arena.deinit();248 pp.arena.deinit();
254 pp.token_buf.deinit();249 pp.token_buf.deinit(gpa);
255 pp.char_buf.deinit();250 pp.char_buf.deinit(gpa);
256 pp.poisoned_identifiers.deinit();251 pp.poisoned_identifiers.deinit(gpa);
257 pp.include_guards.deinit(pp.gpa);252 pp.include_guards.deinit(gpa);
258 pp.top_expansion_buf.deinit();253 pp.top_expansion_buf.deinit(gpa);
259 pp.hideset.deinit();254 pp.hideset.deinit();
260 for (pp.expansion_entries.items(.locs)) |locs| TokenWithExpansionLocs.free(locs, pp.gpa);255 for (pp.expansion_entries.items(.locs)) |locs| TokenWithExpansionLocs.free(locs, gpa);
261 pp.expansion_entries.deinit(pp.gpa);256 pp.expansion_entries.deinit(gpa);
262 pp.m_times.deinit(pp.gpa);257 pp.m_times.deinit(gpa);
258 pp.* = undefined;
263}259}
264260
265/// Free buffers that are not needed after preprocessing261/// Free buffers that are not needed after preprocessing
266fn clearBuffers(pp: *Preprocessor) void {262fn clearBuffers(pp: *Preprocessor) void {
267 pp.token_buf.clearAndFree();263 const gpa = pp.comp.gpa;
268 pp.char_buf.clearAndFree();264 pp.token_buf.clearAndFree(gpa);
269 pp.top_expansion_buf.clearAndFree();265 pp.char_buf.clearAndFree(gpa);
266 pp.top_expansion_buf.clearAndFree(gpa);
270 pp.hideset.clearAndFree();267 pp.hideset.clearAndFree();
271}268}
272269
273fn mTime(pp: *Preprocessor, source_id: Source.Id) !u64 {270fn mTime(pp: *Preprocessor, source_id: Source.Id) !u64 {
274 const gop = try pp.m_times.getOrPut(pp.gpa, source_id);271 const gop = try pp.m_times.getOrPut(pp.comp.gpa, source_id);
275 if (!gop.found_existing) {272 if (!gop.found_existing) {
276 gop.value_ptr.* = pp.comp.getSourceMTimeUncached(source_id) orelse 0;273 gop.value_ptr.* = pp.comp.getSourceMTimeUncached(source_id) orelse 0;
277 }274 }
...@@ -385,6 +382,7 @@ fn findIncludeGuard(pp: *Preprocessor, source: Source) ?[]const u8 {...@@ -385,6 +382,7 @@ fn findIncludeGuard(pp: *Preprocessor, source: Source) ?[]const u8 {
385}382}
386383
387fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpansionLocs {384fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpansionLocs {
385 const gpa = pp.comp.gpa;
388 var guard_name = pp.findIncludeGuard(source);386 var guard_name = pp.findIncludeGuard(source);
389387
390 pp.preprocess_count += 1;388 pp.preprocess_count += 1;
...@@ -418,7 +416,7 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans...@@ -418,7 +416,7 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
418 tok = tokenizer.next();416 tok = tokenizer.next();
419 if (tok.id == .nl or tok.id == .eof) break;417 if (tok.id == .nl or tok.id == .eof) break;
420 if (tok.id == .whitespace) tok.id = .macro_ws;418 if (tok.id == .whitespace) tok.id = .macro_ws;
421 try pp.top_expansion_buf.append(tokFromRaw(tok));419 try pp.top_expansion_buf.append(gpa, tokFromRaw(tok));
422 }420 }
423 try pp.stringify(pp.top_expansion_buf.items);421 try pp.stringify(pp.top_expansion_buf.items);
424 const slice = pp.char_buf.items[char_top + 1 .. pp.char_buf.items.len - 2];422 const slice = pp.char_buf.items[char_top + 1 .. pp.char_buf.items.len - 2];
...@@ -713,7 +711,7 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans...@@ -713,7 +711,7 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
713 try pp.err(tok, .newline_eof, .{});711 try pp.err(tok, .newline_eof, .{});
714 }712 }
715 if (guard_name) |name| {713 if (guard_name) |name| {
716 if (try pp.include_guards.fetchPut(pp.gpa, source.id, name)) |prev| {714 if (try pp.include_guards.fetchPut(pp.comp.gpa, source.id, name)) |prev| {
717 assert(mem.eql(u8, name, prev.value));715 assert(mem.eql(u8, name, prev.value));
718 }716 }
719 }717 }
...@@ -761,8 +759,11 @@ pub const Diagnostic = @import("Preprocessor/Diagnostic.zig");...@@ -761,8 +759,11 @@ pub const Diagnostic = @import("Preprocessor/Diagnostic.zig");
761759
762fn err(pp: *Preprocessor, loc: anytype, diagnostic: Diagnostic, args: anytype) Compilation.Error!void {760fn err(pp: *Preprocessor, loc: anytype, diagnostic: Diagnostic, args: anytype) Compilation.Error!void {
763 if (pp.diagnostics.effectiveKind(diagnostic) == .off) return;761 if (pp.diagnostics.effectiveKind(diagnostic) == .off) return;
762 const old_suppress_system = pp.diagnostics.state.suppress_system_headers;
763 defer pp.diagnostics.state.suppress_system_headers = old_suppress_system;
764 if (diagnostic.show_in_system_headers) pp.diagnostics.state.suppress_system_headers = false;
764765
765 var sf = std.heap.stackFallback(1024, pp.gpa);766 var sf = std.heap.stackFallback(1024, pp.comp.gpa);
766 var allocating: std.Io.Writer.Allocating = .init(sf.get());767 var allocating: std.Io.Writer.Allocating = .init(sf.get());
767 defer allocating.deinit();768 defer allocating.deinit();
768769
...@@ -791,7 +792,7 @@ fn err(pp: *Preprocessor, loc: anytype, diagnostic: Diagnostic, args: anytype) C...@@ -791,7 +792,7 @@ fn err(pp: *Preprocessor, loc: anytype, diagnostic: Diagnostic, args: anytype) C
791}792}
792793
793fn fatal(pp: *Preprocessor, raw: RawToken, comptime fmt: []const u8, args: anytype) Compilation.Error {794fn fatal(pp: *Preprocessor, raw: RawToken, comptime fmt: []const u8, args: anytype) Compilation.Error {
794 var sf = std.heap.stackFallback(1024, pp.gpa);795 var sf = std.heap.stackFallback(1024, pp.comp.gpa);
795 var allocating: std.Io.Writer.Allocating = .init(sf.get());796 var allocating: std.Io.Writer.Allocating = .init(sf.get());
796 defer allocating.deinit();797 defer allocating.deinit();
797798
...@@ -813,11 +814,12 @@ fn fatalNotFound(pp: *Preprocessor, tok: TokenWithExpansionLocs, filename: []con...@@ -813,11 +814,12 @@ fn fatalNotFound(pp: *Preprocessor, tok: TokenWithExpansionLocs, filename: []con
813 pp.diagnostics.state.fatal_errors = true;814 pp.diagnostics.state.fatal_errors = true;
814 defer pp.diagnostics.state.fatal_errors = old;815 defer pp.diagnostics.state.fatal_errors = old;
815816
816 var sf = std.heap.stackFallback(1024, pp.gpa);817 var sf = std.heap.stackFallback(1024, pp.comp.gpa);
817 var buf = std.array_list.Managed(u8).init(sf.get());818 const allocator = sf.get();
818 defer buf.deinit();819 var buf: std.ArrayList(u8) = .empty;
820 defer buf.deinit(allocator);
819821
820 try buf.print("'{s}' not found", .{filename});822 try buf.print(allocator, "'{s}' not found", .{filename});
821 try pp.diagnostics.addWithLocation(pp.comp, .{823 try pp.diagnostics.addWithLocation(pp.comp, .{
822 .kind = .@"fatal error",824 .kind = .@"fatal error",
823 .text = buf.items,825 .text = buf.items,
...@@ -831,14 +833,16 @@ fn verboseLog(pp: *Preprocessor, raw: RawToken, comptime fmt: []const u8, args:...@@ -831,14 +833,16 @@ fn verboseLog(pp: *Preprocessor, raw: RawToken, comptime fmt: []const u8, args:
831 const source = pp.comp.getSource(raw.source);833 const source = pp.comp.getSource(raw.source);
832 const line_col = source.lineCol(.{ .id = raw.source, .line = raw.line, .byte_offset = raw.start });834 const line_col = source.lineCol(.{ .id = raw.source, .line = raw.line, .byte_offset = raw.start });
833835
834 var stderr_buffer: [64]u8 = undefined;836 var stderr_buf: [4096]u8 = undefined;
835 var writer = std.debug.lockStderrWriter(&stderr_buffer);837 var stderr = std.fs.File.stderr().writer(&stderr_buf);
836 defer std.debug.unlockStderrWriter();838 const w = &stderr.interface;
837 writer.print("{s}:{d}:{d}: ", .{ source.path, line_col.line_no, line_col.col }) catch return;839
838 writer.print(fmt, args) catch return;840 w.print("{s}:{d}:{d}: ", .{ source.path, line_col.line_no, line_col.col }) catch return;
839 writer.writeByte('\n') catch return;841 w.print(fmt, args) catch return;
840 writer.writeAll(line_col.line) catch return;842 w.writeByte('\n') catch return;
841 writer.writeByte('\n') catch return;843 w.writeAll(line_col.line) catch return;
844 w.writeByte('\n') catch return;
845 w.flush() catch return;
842}846}
843847
844/// Consume next token, error if it is not an identifier.848/// Consume next token, error if it is not an identifier.
...@@ -880,9 +884,10 @@ fn restoreTokenState(pp: *Preprocessor, state: TokenState) void {...@@ -880,9 +884,10 @@ fn restoreTokenState(pp: *Preprocessor, state: TokenState) void {
880884
881/// Consume all tokens until a newline and parse the result into a boolean.885/// Consume all tokens until a newline and parse the result into a boolean.
882fn expr(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!bool {886fn expr(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!bool {
887 const gpa = pp.comp.gpa;
883 const token_state = pp.getTokenState();888 const token_state = pp.getTokenState();
884 defer {889 defer {
885 for (pp.top_expansion_buf.items) |tok| TokenWithExpansionLocs.free(tok.expansion_locs, pp.gpa);890 for (pp.top_expansion_buf.items) |tok| TokenWithExpansionLocs.free(tok.expansion_locs, gpa);
886 pp.restoreTokenState(token_state);891 pp.restoreTokenState(token_state);
887 }892 }
888893
...@@ -894,7 +899,7 @@ fn expr(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!bool {...@@ -894,7 +899,7 @@ fn expr(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!bool {
894 .whitespace => if (pp.top_expansion_buf.items.len == 0) continue,899 .whitespace => if (pp.top_expansion_buf.items.len == 0) continue,
895 else => {},900 else => {},
896 }901 }
897 try pp.top_expansion_buf.append(tokFromRaw(tok));902 try pp.top_expansion_buf.append(gpa, tokFromRaw(tok));
898 } else unreachable;903 } else unreachable;
899 if (pp.top_expansion_buf.items.len != 0) {904 if (pp.top_expansion_buf.items.len != 0) {
900 pp.expansion_source_loc = pp.top_expansion_buf.items[0].loc;905 pp.expansion_source_loc = pp.top_expansion_buf.items[0].loc;
...@@ -989,11 +994,9 @@ fn expr(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!bool {...@@ -989,11 +994,9 @@ fn expr(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!bool {
989 .pp = pp,994 .pp = pp,
990 .comp = pp.comp,995 .comp = pp.comp,
991 .diagnostics = pp.diagnostics,996 .diagnostics = pp.diagnostics,
992 .gpa = pp.gpa,
993 .tok_ids = pp.tokens.items(.id),997 .tok_ids = pp.tokens.items(.id),
994 .tok_i = @intCast(token_state.tokens_len),998 .tok_i = @intCast(token_state.tokens_len),
995 .in_macro = true,999 .in_macro = true,
996 .strings = std.array_list.Managed(u8).init(pp.comp.gpa),
9971000
998 .tree = undefined,1001 .tree = undefined,
999 .labels = undefined,1002 .labels = undefined,
...@@ -1005,7 +1008,7 @@ fn expr(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!bool {...@@ -1005,7 +1008,7 @@ fn expr(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!bool {
1005 .attr_buf = undefined,1008 .attr_buf = undefined,
1006 .string_ids = undefined,1009 .string_ids = undefined,
1007 };1010 };
1008 defer parser.strings.deinit();1011 defer parser.strings.deinit(gpa);
1009 return parser.macroExpr();1012 return parser.macroExpr();
1010}1013}
10111014
...@@ -1140,34 +1143,35 @@ fn skipToNl(tokenizer: *Tokenizer) void {...@@ -1140,34 +1143,35 @@ fn skipToNl(tokenizer: *Tokenizer) void {
1140 }1143 }
1141}1144}
11421145
1143const ExpandBuf = std.array_list.Managed(TokenWithExpansionLocs);1146const ExpandBuf = std.ArrayList(TokenWithExpansionLocs);
1144fn removePlacemarkers(buf: *ExpandBuf) void {1147fn removePlacemarkers(gpa: Allocator, buf: *ExpandBuf) void {
1145 var i: usize = buf.items.len -% 1;1148 var i: usize = buf.items.len -% 1;
1146 while (i < buf.items.len) : (i -%= 1) {1149 while (i < buf.items.len) : (i -%= 1) {
1147 if (buf.items[i].id == .placemarker) {1150 if (buf.items[i].id == .placemarker) {
1148 const placemarker = buf.orderedRemove(i);1151 const placemarker = buf.orderedRemove(i);
1149 TokenWithExpansionLocs.free(placemarker.expansion_locs, buf.allocator);1152 TokenWithExpansionLocs.free(placemarker.expansion_locs, gpa);
1150 }1153 }
1151 }1154 }
1152}1155}
11531156
1154const MacroArguments = std.array_list.Managed([]const TokenWithExpansionLocs);1157const MacroArguments = std.ArrayList([]const TokenWithExpansionLocs);
1155fn deinitMacroArguments(allocator: Allocator, args: *const MacroArguments) void {1158fn deinitMacroArguments(gpa: Allocator, args: *MacroArguments) void {
1156 for (args.items) |item| {1159 for (args.items) |item| {
1157 for (item) |tok| TokenWithExpansionLocs.free(tok.expansion_locs, allocator);1160 for (item) |tok| TokenWithExpansionLocs.free(tok.expansion_locs, gpa);
1158 allocator.free(item);1161 gpa.free(item);
1159 }1162 }
1160 args.deinit();1163 args.deinit(gpa);
1161}1164}
11621165
1163fn expandObjMacro(pp: *Preprocessor, simple_macro: *const Macro) Error!ExpandBuf {1166fn expandObjMacro(pp: *Preprocessor, simple_macro: *const Macro) Error!ExpandBuf {
1164 var buf = ExpandBuf.init(pp.gpa);1167 const gpa = pp.comp.gpa;
1165 errdefer buf.deinit();1168 var buf: ExpandBuf = .empty;
1169 errdefer buf.deinit(gpa);
1166 if (simple_macro.tokens.len == 0) {1170 if (simple_macro.tokens.len == 0) {
1167 try buf.append(.{ .id = .placemarker, .loc = .{ .id = .generated } });1171 try buf.append(gpa, .{ .id = .placemarker, .loc = .{ .id = .generated } });
1168 return buf;1172 return buf;
1169 }1173 }
1170 try buf.ensureTotalCapacity(simple_macro.tokens.len);1174 try buf.ensureTotalCapacity(gpa, simple_macro.tokens.len);
11711175
1172 // Add all of the simple_macros tokens to the new buffer handling any concats.1176 // Add all of the simple_macros tokens to the new buffer handling any concats.
1173 var i: usize = 0;1177 var i: usize = 0;
...@@ -1193,25 +1197,26 @@ fn expandObjMacro(pp: *Preprocessor, simple_macro: *const Macro) Error!ExpandBuf...@@ -1193,25 +1197,26 @@ fn expandObjMacro(pp: *Preprocessor, simple_macro: *const Macro) Error!ExpandBuf
1193 .macro_file => {1197 .macro_file => {
1194 const start = pp.comp.generated_buf.items.len;1198 const start = pp.comp.generated_buf.items.len;
1195 const source = pp.comp.getSource(pp.expansion_source_loc.id);1199 const source = pp.comp.getSource(pp.expansion_source_loc.id);
1196 try pp.comp.generated_buf.print(pp.gpa, "\"{f}\"\n", .{fmtEscapes(source.path)});1200 try pp.comp.generated_buf.print(gpa, "\"{f}\"\n", .{fmtEscapes(source.path)});
11971201
1198 buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .string_literal, tok));1202 buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .string_literal, tok));
1199 },1203 },
1200 .macro_line => {1204 .macro_line => {
1201 const start = pp.comp.generated_buf.items.len;1205 const start = pp.comp.generated_buf.items.len;
1202 const source = pp.comp.getSource(pp.expansion_source_loc.id);1206 const source = pp.comp.getSource(pp.expansion_source_loc.id);
1203 try pp.comp.generated_buf.print(pp.gpa, "{d}\n", .{source.physicalLine(pp.expansion_source_loc)});1207 try pp.comp.generated_buf.print(gpa, "{d}\n", .{source.physicalLine(pp.expansion_source_loc)});
12041208
1205 buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .pp_num, tok));1209 buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .pp_num, tok));
1206 },1210 },
1207 .macro_counter => {1211 .macro_counter => {
1208 defer pp.counter += 1;1212 defer pp.counter += 1;
1209 const start = pp.comp.generated_buf.items.len;1213 const start = pp.comp.generated_buf.items.len;
1210 try pp.comp.generated_buf.print(pp.gpa, "{d}\n", .{pp.counter});1214 try pp.comp.generated_buf.print(gpa, "{d}\n", .{pp.counter});
12111215
1212 buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .pp_num, tok));1216 buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .pp_num, tok));
1213 },1217 },
1214 .macro_date, .macro_time => {1218 .macro_date, .macro_time => {
1219 try pp.err(pp.expansion_source_loc, .date_time, .{});
1215 const start = pp.comp.generated_buf.items.len;1220 const start = pp.comp.generated_buf.items.len;
1216 const timestamp = switch (pp.source_epoch) {1221 const timestamp = switch (pp.source_epoch) {
1217 .system, .provided => |ts| ts,1222 .system, .provided => |ts| ts,
...@@ -1220,6 +1225,7 @@ fn expandObjMacro(pp: *Preprocessor, simple_macro: *const Macro) Error!ExpandBuf...@@ -1220,6 +1225,7 @@ fn expandObjMacro(pp: *Preprocessor, simple_macro: *const Macro) Error!ExpandBuf
1220 buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .string_literal, tok));1225 buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .string_literal, tok));
1221 },1226 },
1222 .macro_timestamp => {1227 .macro_timestamp => {
1228 try pp.err(pp.expansion_source_loc, .date_time, .{});
1223 const start = pp.comp.generated_buf.items.len;1229 const start = pp.comp.generated_buf.items.len;
1224 const timestamp = switch (pp.source_epoch) {1230 const timestamp = switch (pp.source_epoch) {
1225 .provided => |ts| ts,1231 .provided => |ts| ts,
...@@ -1251,8 +1257,9 @@ const DateTimeStampKind = enum {...@@ -1251,8 +1257,9 @@ const DateTimeStampKind = enum {
1251 }1257 }
1252};1258};
12531259
1254fn writeDateTimeStamp(pp: *Preprocessor, kind: DateTimeStampKind, timestamp: u64) !void {1260fn writeDateTimeStamp(pp: *const Preprocessor, kind: DateTimeStampKind, timestamp: u64) !void {
1255 std.debug.assert(std.time.epoch.Month.jan.numeric() == 1);1261 std.debug.assert(std.time.epoch.Month.jan.numeric() == 1);
1262 const gpa = pp.comp.gpa;
12561263
1257 const epoch_seconds = std.time.epoch.EpochSeconds{ .secs = timestamp };1264 const epoch_seconds = std.time.epoch.EpochSeconds{ .secs = timestamp };
1258 const epoch_day = epoch_seconds.getEpochDay();1265 const epoch_day = epoch_seconds.getEpochDay();
...@@ -1267,21 +1274,21 @@ fn writeDateTimeStamp(pp: *Preprocessor, kind: DateTimeStampKind, timestamp: u64...@@ -1267,21 +1274,21 @@ fn writeDateTimeStamp(pp: *Preprocessor, kind: DateTimeStampKind, timestamp: u64
12671274
1268 switch (kind) {1275 switch (kind) {
1269 .date => {1276 .date => {
1270 try pp.comp.generated_buf.print(pp.gpa, "\"{s} {d: >2} {d}\"", .{1277 try pp.comp.generated_buf.print(gpa, "\"{s} {d: >2} {d}\"", .{
1271 month_name,1278 month_name,
1272 month_day.day_index + 1,1279 month_day.day_index + 1,
1273 year_day.year,1280 year_day.year,
1274 });1281 });
1275 },1282 },
1276 .time => {1283 .time => {
1277 try pp.comp.generated_buf.print(pp.gpa, "\"{d:0>2}:{d:0>2}:{d:0>2}\"", .{1284 try pp.comp.generated_buf.print(gpa, "\"{d:0>2}:{d:0>2}:{d:0>2}\"", .{
1278 day_seconds.getHoursIntoDay(),1285 day_seconds.getHoursIntoDay(),
1279 day_seconds.getMinutesIntoHour(),1286 day_seconds.getMinutesIntoHour(),
1280 day_seconds.getSecondsIntoMinute(),1287 day_seconds.getSecondsIntoMinute(),
1281 });1288 });
1282 },1289 },
1283 .timestamp => {1290 .timestamp => {
1284 try pp.comp.generated_buf.print(pp.gpa, "\"{s} {s} {d: >2} {d:0>2}:{d:0>2}:{d:0>2} {d}\"", .{1291 try pp.comp.generated_buf.print(gpa, "\"{s} {s} {d: >2} {d:0>2}:{d:0>2}:{d:0>2} {d}\"", .{
1285 day_name,1292 day_name,
1286 month_name,1293 month_name,
1287 month_day.day_index + 1,1294 month_day.day_index + 1,
...@@ -1312,7 +1319,7 @@ fn pasteStringsUnsafe(pp: *Preprocessor, toks: []const TokenWithExpansionLocs) !...@@ -1312,7 +1319,7 @@ fn pasteStringsUnsafe(pp: *Preprocessor, toks: []const TokenWithExpansionLocs) !
1312 if (tok.id == .macro_ws) continue;1319 if (tok.id == .macro_ws) continue;
1313 if (tok.id != .string_literal) return error.ExpectedStringLiteral;1320 if (tok.id != .string_literal) return error.ExpectedStringLiteral;
1314 const str = pp.expandedSlice(tok);1321 const str = pp.expandedSlice(tok);
1315 try pp.char_buf.appendSlice(str[1 .. str.len - 1]);1322 try pp.char_buf.appendSlice(pp.comp.gpa, str[1 .. str.len - 1]);
1316 }1323 }
1317 return pp.char_buf.items[char_top..];1324 return pp.char_buf.items[char_top..];
1318}1325}
...@@ -1322,16 +1329,17 @@ fn pragmaOperator(pp: *Preprocessor, arg_tok: TokenWithExpansionLocs, operator_l...@@ -1322,16 +1329,17 @@ fn pragmaOperator(pp: *Preprocessor, arg_tok: TokenWithExpansionLocs, operator_l
1322 const arg_slice = pp.expandedSlice(arg_tok);1329 const arg_slice = pp.expandedSlice(arg_tok);
1323 const content = arg_slice[1 .. arg_slice.len - 1];1330 const content = arg_slice[1 .. arg_slice.len - 1];
1324 const directive = "#pragma ";1331 const directive = "#pragma ";
1332 const gpa = pp.comp.gpa;
13251333
1326 pp.char_buf.clearRetainingCapacity();1334 pp.char_buf.clearRetainingCapacity();
1327 const total_len = directive.len + content.len + 1; // destringify can never grow the string, + 1 for newline1335 const total_len = directive.len + content.len + 1; // destringify can never grow the string, + 1 for newline
1328 try pp.char_buf.ensureUnusedCapacity(total_len);1336 try pp.char_buf.ensureUnusedCapacity(gpa, total_len);
1329 pp.char_buf.appendSliceAssumeCapacity(directive);1337 pp.char_buf.appendSliceAssumeCapacity(directive);
1330 pp.destringify(content);1338 pp.destringify(content);
1331 pp.char_buf.appendAssumeCapacity('\n');1339 pp.char_buf.appendAssumeCapacity('\n');
13321340
1333 const start = pp.comp.generated_buf.items.len;1341 const start = pp.comp.generated_buf.items.len;
1334 try pp.comp.generated_buf.appendSlice(pp.gpa, pp.char_buf.items);1342 try pp.comp.generated_buf.appendSlice(gpa, pp.char_buf.items);
1335 var tmp_tokenizer = Tokenizer{1343 var tmp_tokenizer = Tokenizer{
1336 .buf = pp.comp.generated_buf.items,1344 .buf = pp.comp.generated_buf.items,
1337 .langopts = pp.comp.langopts,1345 .langopts = pp.comp.langopts,
...@@ -1353,9 +1361,10 @@ fn msPragmaOperator(pp: *Preprocessor, pragma_tok: TokenWithExpansionLocs, args:...@@ -1353,9 +1361,10 @@ fn msPragmaOperator(pp: *Preprocessor, pragma_tok: TokenWithExpansionLocs, args:
1353 try pp.err(pragma_tok, .unknown_pragma, .{});1361 try pp.err(pragma_tok, .unknown_pragma, .{});
1354 return;1362 return;
1355 }1363 }
1364 const gpa = pp.comp.gpa;
13561365
1357 {1366 {
1358 var copy = try pragma_tok.dupe(pp.gpa);1367 var copy = try pragma_tok.dupe(gpa);
1359 copy.id = .keyword_pragma;1368 copy.id = .keyword_pragma;
1360 try pp.addToken(copy);1369 try pp.addToken(copy);
1361 }1370 }
...@@ -1364,7 +1373,7 @@ fn msPragmaOperator(pp: *Preprocessor, pragma_tok: TokenWithExpansionLocs, args:...@@ -1364,7 +1373,7 @@ fn msPragmaOperator(pp: *Preprocessor, pragma_tok: TokenWithExpansionLocs, args:
1364 for (args) |tok| {1373 for (args) |tok| {
1365 switch (tok.id) {1374 switch (tok.id) {
1366 .macro_ws, .comment => continue,1375 .macro_ws, .comment => continue,
1367 else => try pp.addToken(try tok.dupe(pp.gpa)),1376 else => try pp.addToken(try tok.dupe(gpa)),
1368 }1377 }
1369 }1378 }
1370 try pp.addToken(.{ .id = .nl, .loc = .{ .id = .generated } });1379 try pp.addToken(.{ .id = .nl, .loc = .{ .id = .generated } });
...@@ -1406,7 +1415,8 @@ fn destringify(pp: *Preprocessor, str: []const u8) void {...@@ -1406,7 +1415,8 @@ fn destringify(pp: *Preprocessor, str: []const u8) void {
1406/// Stringify `tokens` into pp.char_buf.1415/// Stringify `tokens` into pp.char_buf.
1407/// See https://gcc.gnu.org/onlinedocs/gcc-11.2.0/cpp/Stringizing.html#Stringizing1416/// See https://gcc.gnu.org/onlinedocs/gcc-11.2.0/cpp/Stringizing.html#Stringizing
1408fn stringify(pp: *Preprocessor, tokens: []const TokenWithExpansionLocs) !void {1417fn stringify(pp: *Preprocessor, tokens: []const TokenWithExpansionLocs) !void {
1409 try pp.char_buf.append('"');1418 const gpa = pp.comp.gpa;
1419 try pp.char_buf.append(gpa, '"');
1410 var ws_state: enum { start, need, not_needed } = .start;1420 var ws_state: enum { start, need, not_needed } = .start;
1411 for (tokens) |tok| {1421 for (tokens) |tok| {
1412 if (tok.id == .macro_ws) {1422 if (tok.id == .macro_ws) {
...@@ -1414,7 +1424,7 @@ fn stringify(pp: *Preprocessor, tokens: []const TokenWithExpansionLocs) !void {...@@ -1414,7 +1424,7 @@ fn stringify(pp: *Preprocessor, tokens: []const TokenWithExpansionLocs) !void {
1414 ws_state = .need;1424 ws_state = .need;
1415 continue;1425 continue;
1416 }1426 }
1417 if (ws_state == .need) try pp.char_buf.append(' ');1427 if (ws_state == .need) try pp.char_buf.append(gpa, ' ');
1418 ws_state = .not_needed;1428 ws_state = .not_needed;
14191429
1420 // backslashes not inside strings are not escaped1430 // backslashes not inside strings are not escaped
...@@ -1434,14 +1444,14 @@ fn stringify(pp: *Preprocessor, tokens: []const TokenWithExpansionLocs) !void {...@@ -1434,14 +1444,14 @@ fn stringify(pp: *Preprocessor, tokens: []const TokenWithExpansionLocs) !void {
14341444
1435 for (pp.expandedSlice(tok)) |c| {1445 for (pp.expandedSlice(tok)) |c| {
1436 if (c == '"')1446 if (c == '"')
1437 try pp.char_buf.appendSlice("\\\"")1447 try pp.char_buf.appendSlice(gpa, "\\\"")
1438 else if (c == '\\' and is_str)1448 else if (c == '\\' and is_str)
1439 try pp.char_buf.appendSlice("\\\\")1449 try pp.char_buf.appendSlice(gpa, "\\\\")
1440 else1450 else
1441 try pp.char_buf.append(c);1451 try pp.char_buf.append(gpa, c);
1442 }1452 }
1443 }1453 }
1444 try pp.char_buf.ensureUnusedCapacity(2);1454 try pp.char_buf.ensureUnusedCapacity(gpa, 2);
1445 if (pp.char_buf.items[pp.char_buf.items.len - 1] != '\\') {1455 if (pp.char_buf.items[pp.char_buf.items.len - 1] != '\\') {
1446 pp.char_buf.appendSliceAssumeCapacity("\"\n");1456 pp.char_buf.appendSliceAssumeCapacity("\"\n");
1447 return;1457 return;
...@@ -1492,7 +1502,7 @@ fn reconstructIncludeString(pp: *Preprocessor, param_toks: []const TokenWithExpa...@@ -1492,7 +1502,7 @@ fn reconstructIncludeString(pp: *Preprocessor, param_toks: []const TokenWithExpa
14921502
1493 for (params, 0..) |tok, i| {1503 for (params, 0..) |tok, i| {
1494 const str = pp.expandedSliceExtra(tok, .preserve_macro_ws);1504 const str = pp.expandedSliceExtra(tok, .preserve_macro_ws);
1495 try pp.char_buf.appendSlice(str);1505 try pp.char_buf.appendSlice(pp.comp.gpa, str);
1496 if (embed_args) |some| {1506 if (embed_args) |some| {
1497 if ((i == 0 and tok.id == .string_literal) or tok.id == .angle_bracket_right) {1507 if ((i == 0 and tok.id == .string_literal) or tok.id == .angle_bracket_right) {
1498 some.* = params[i + 1 ..];1508 some.* = params[i + 1 ..];
...@@ -1649,25 +1659,26 @@ fn expandFuncMacro(...@@ -1649,25 +1659,26 @@ fn expandFuncMacro(
1649 expanded_args: *const MacroArguments,1659 expanded_args: *const MacroArguments,
1650 hideset_arg: Hideset.Index,1660 hideset_arg: Hideset.Index,
1651) MacroError!ExpandBuf {1661) MacroError!ExpandBuf {
1662 const gpa = pp.comp.gpa;
1652 var hideset = hideset_arg;1663 var hideset = hideset_arg;
1653 var buf = ExpandBuf.init(pp.gpa);1664 var buf: ExpandBuf = .empty;
1654 try buf.ensureTotalCapacity(func_macro.tokens.len);1665 errdefer buf.deinit(gpa);
1655 errdefer buf.deinit();1666 try buf.ensureTotalCapacity(gpa, func_macro.tokens.len);
16561667
1657 var expanded_variable_arguments = ExpandBuf.init(pp.gpa);1668 var expanded_variable_arguments: ExpandBuf = .empty;
1658 defer expanded_variable_arguments.deinit();1669 defer expanded_variable_arguments.deinit(gpa);
1659 var variable_arguments = ExpandBuf.init(pp.gpa);1670 var variable_arguments: ExpandBuf = .empty;
1660 defer variable_arguments.deinit();1671 defer variable_arguments.deinit(gpa);
16611672
1662 if (func_macro.var_args) {1673 if (func_macro.var_args) {
1663 var i: usize = func_macro.params.len;1674 var i: usize = func_macro.params.len;
1664 while (i < expanded_args.items.len) : (i += 1) {1675 while (i < expanded_args.items.len) : (i += 1) {
1665 try variable_arguments.appendSlice(args.items[i]);1676 try variable_arguments.appendSlice(gpa, args.items[i]);
1666 try expanded_variable_arguments.appendSlice(expanded_args.items[i]);1677 try expanded_variable_arguments.appendSlice(gpa, expanded_args.items[i]);
1667 if (i != expanded_args.items.len - 1) {1678 if (i != expanded_args.items.len - 1) {
1668 const comma = TokenWithExpansionLocs{ .id = .comma, .loc = .{ .id = .generated } };1679 const comma: TokenWithExpansionLocs = .{ .id = .comma, .loc = .{ .id = .generated } };
1669 try variable_arguments.append(comma);1680 try variable_arguments.append(gpa, comma);
1670 try expanded_variable_arguments.append(comma);1681 try expanded_variable_arguments.append(gpa, comma);
1671 }1682 }
1672 }1683 }
1673 }1684 }
...@@ -1681,8 +1692,8 @@ fn expandFuncMacro(...@@ -1681,8 +1692,8 @@ fn expandFuncMacro(
1681 const raw_next = func_macro.tokens[tok_i + 1];1692 const raw_next = func_macro.tokens[tok_i + 1];
1682 tok_i += 1;1693 tok_i += 1;
16831694
1684 var va_opt_buf = ExpandBuf.init(pp.gpa);1695 var va_opt_buf: ExpandBuf = .empty;
1685 defer va_opt_buf.deinit();1696 defer va_opt_buf.deinit(gpa);
16861697
1687 const next = switch (raw_next.id) {1698 const next = switch (raw_next.id) {
1688 .macro_ws => continue,1699 .macro_ws => continue,
...@@ -1709,7 +1720,7 @@ fn expandFuncMacro(...@@ -1709,7 +1720,7 @@ fn expandFuncMacro(
1709 }1720 }
1710 const slice = getPasteArgs(args.items[raw.end]);1721 const slice = getPasteArgs(args.items[raw.end]);
1711 const raw_loc = Source.Location{ .id = raw.source, .byte_offset = raw.start, .line = raw.line };1722 const raw_loc = Source.Location{ .id = raw.source, .byte_offset = raw.start, .line = raw.line };
1712 try bufCopyTokens(&buf, slice, &.{raw_loc});1723 try bufCopyTokens(gpa, &buf, slice, &.{raw_loc});
1713 },1724 },
1714 .macro_param => {1725 .macro_param => {
1715 if (tok_i + 1 < func_macro.tokens.len and func_macro.tokens[tok_i + 1].id == .hash_hash) {1726 if (tok_i + 1 < func_macro.tokens.len and func_macro.tokens[tok_i + 1].id == .hash_hash) {
...@@ -1717,11 +1728,11 @@ fn expandFuncMacro(...@@ -1717,11 +1728,11 @@ fn expandFuncMacro(
1717 }1728 }
1718 const arg = expanded_args.items[raw.end];1729 const arg = expanded_args.items[raw.end];
1719 const raw_loc = Source.Location{ .id = raw.source, .byte_offset = raw.start, .line = raw.line };1730 const raw_loc = Source.Location{ .id = raw.source, .byte_offset = raw.start, .line = raw.line };
1720 try bufCopyTokens(&buf, arg, &.{raw_loc});1731 try bufCopyTokens(gpa, &buf, arg, &.{raw_loc});
1721 },1732 },
1722 .keyword_va_args => {1733 .keyword_va_args => {
1723 const raw_loc = Source.Location{ .id = raw.source, .byte_offset = raw.start, .line = raw.line };1734 const raw_loc = Source.Location{ .id = raw.source, .byte_offset = raw.start, .line = raw.line };
1724 try bufCopyTokens(&buf, expanded_variable_arguments.items, &.{raw_loc});1735 try bufCopyTokens(gpa, &buf, expanded_variable_arguments.items, &.{raw_loc});
1725 },1736 },
1726 .keyword_va_opt => {1737 .keyword_va_opt => {
1727 try pp.expandVaOpt(&buf, raw, variable_arguments.items.len != 0);1738 try pp.expandVaOpt(&buf, raw, variable_arguments.items.len != 0);
...@@ -1736,9 +1747,9 @@ fn expandFuncMacro(...@@ -1736,9 +1747,9 @@ fn expandFuncMacro(
1736 try pp.stringify(arg);1747 try pp.stringify(arg);
17371748
1738 const start = pp.comp.generated_buf.items.len;1749 const start = pp.comp.generated_buf.items.len;
1739 try pp.comp.generated_buf.appendSlice(pp.gpa, pp.char_buf.items);1750 try pp.comp.generated_buf.appendSlice(gpa, pp.char_buf.items);
17401751
1741 try buf.append(try pp.makeGeneratedToken(start, .string_literal, tokFromRaw(raw)));1752 try buf.append(gpa, try pp.makeGeneratedToken(start, .string_literal, tokFromRaw(raw)));
1742 },1753 },
1743 .macro_param_has_attribute,1754 .macro_param_has_attribute,
1744 .macro_param_has_declspec_attribute,1755 .macro_param_has_declspec_attribute,
...@@ -1757,8 +1768,8 @@ fn expandFuncMacro(...@@ -1757,8 +1768,8 @@ fn expandFuncMacro(
1757 } else try pp.handleBuiltinMacro(raw.id, arg, macro_tok.loc);1768 } else try pp.handleBuiltinMacro(raw.id, arg, macro_tok.loc);
1758 const start = pp.comp.generated_buf.items.len;1769 const start = pp.comp.generated_buf.items.len;
17591770
1760 try pp.comp.generated_buf.print(pp.gpa, "{}\n", .{@intFromBool(result)});1771 try pp.comp.generated_buf.print(gpa, "{}\n", .{@intFromBool(result)});
1761 try buf.append(try pp.makeGeneratedToken(start, .pp_num, tokFromRaw(raw)));1772 try buf.append(gpa, try pp.makeGeneratedToken(start, .pp_num, tokFromRaw(raw)));
1762 },1773 },
1763 .macro_param_has_c_attribute => {1774 .macro_param_has_c_attribute => {
1764 const arg = expanded_args.items[0];1775 const arg = expanded_args.items[0];
...@@ -1808,8 +1819,8 @@ fn expandFuncMacro(...@@ -1808,8 +1819,8 @@ fn expandFuncMacro(
1808 const exists = Attribute.fromString(.gnu, vendor_str, attr_str) != null;1819 const exists = Attribute.fromString(.gnu, vendor_str, attr_str) != null;
18091820
1810 const start = pp.comp.generated_buf.items.len;1821 const start = pp.comp.generated_buf.items.len;
1811 try pp.comp.generated_buf.appendSlice(pp.gpa, if (exists) "1\n" else "0\n");1822 try pp.comp.generated_buf.appendSlice(gpa, if (exists) "1\n" else "0\n");
1812 try buf.append(try pp.makeGeneratedToken(start, .pp_num, tokFromRaw(raw)));1823 try buf.append(gpa, try pp.makeGeneratedToken(start, .pp_num, tokFromRaw(raw)));
1813 continue;1824 continue;
1814 }1825 }
1815 if (!pp.comp.langopts.standard.atLeast(.c23)) break :res not_found;1826 if (!pp.comp.langopts.standard.atLeast(.c23)) break :res not_found;
...@@ -1829,8 +1840,8 @@ fn expandFuncMacro(...@@ -1829,8 +1840,8 @@ fn expandFuncMacro(
1829 break :res attrs.get(attr_str) orelse not_found;1840 break :res attrs.get(attr_str) orelse not_found;
1830 };1841 };
1831 const start = pp.comp.generated_buf.items.len;1842 const start = pp.comp.generated_buf.items.len;
1832 try pp.comp.generated_buf.appendSlice(pp.gpa, result);1843 try pp.comp.generated_buf.appendSlice(gpa, result);
1833 try buf.append(try pp.makeGeneratedToken(start, .pp_num, tokFromRaw(raw)));1844 try buf.append(gpa, try pp.makeGeneratedToken(start, .pp_num, tokFromRaw(raw)));
1834 },1845 },
1835 .macro_param_has_embed => {1846 .macro_param_has_embed => {
1836 const arg = expanded_args.items[0];1847 const arg = expanded_args.items[0];
...@@ -1936,12 +1947,12 @@ fn expandFuncMacro(...@@ -1936,12 +1947,12 @@ fn expandFuncMacro(
1936 const contents = (try pp.comp.findEmbed(filename, arg[0].loc.id, include_type, .limited(1), pp.dep_file)) orelse1947 const contents = (try pp.comp.findEmbed(filename, arg[0].loc.id, include_type, .limited(1), pp.dep_file)) orelse
1937 break :res not_found;1948 break :res not_found;
19381949
1939 defer pp.comp.gpa.free(contents);1950 defer gpa.free(contents);
1940 break :res if (contents.len != 0) "1\n" else "2\n";1951 break :res if (contents.len != 0) "1\n" else "2\n";
1941 };1952 };
1942 const start = pp.comp.generated_buf.items.len;1953 const start = pp.comp.generated_buf.items.len;
1943 try pp.comp.generated_buf.appendSlice(pp.comp.gpa, result);1954 try pp.comp.generated_buf.appendSlice(gpa, result);
1944 try buf.append(try pp.makeGeneratedToken(start, .pp_num, tokFromRaw(raw)));1955 try buf.append(gpa, try pp.makeGeneratedToken(start, .pp_num, tokFromRaw(raw)));
1945 },1956 },
1946 .macro_param_pragma_operator => {1957 .macro_param_pragma_operator => {
1947 // Clang and GCC require exactly one token (so, no parentheses or string pasting)1958 // Clang and GCC require exactly one token (so, no parentheses or string pasting)
...@@ -1993,7 +2004,7 @@ fn expandFuncMacro(...@@ -1993,7 +2004,7 @@ fn expandFuncMacro(
1993 }2004 }
1994 if (ident) |*some| {2005 if (ident) |*some| {
1995 some.id = .identifier;2006 some.id = .identifier;
1996 try buf.append(some.*);2007 try buf.append(gpa, some.*);
1997 } else {2008 } else {
1998 try pp.err(macro_tok, .expected_identifier, .{});2009 try pp.err(macro_tok, .expected_identifier, .{});
1999 }2010 }
...@@ -2023,10 +2034,10 @@ fn expandFuncMacro(...@@ -2023,10 +2034,10 @@ fn expandFuncMacro(
2023 try pp.err(hash_hash, .comma_deletion_va_args, .{});2034 try pp.err(hash_hash, .comma_deletion_va_args, .{});
2024 } else {2035 } else {
2025 // C standard, retain the comma2036 // C standard, retain the comma
2026 try buf.append(tokFromRaw(raw));2037 try buf.append(gpa, tokFromRaw(raw));
2027 }2038 }
2028 } else {2039 } else {
2029 try buf.append(tokFromRaw(raw));2040 try buf.append(gpa, tokFromRaw(raw));
2030 if (expanded_variable_arguments.items.len > 0 or variable_arguments.items.len == func_macro.params.len) {2041 if (expanded_variable_arguments.items.len > 0 or variable_arguments.items.len == func_macro.params.len) {
2031 try pp.err(hash_hash, .comma_deletion_va_args, .{});2042 try pp.err(hash_hash, .comma_deletion_va_args, .{});
2032 }2043 }
...@@ -2035,23 +2046,23 @@ fn expandFuncMacro(...@@ -2035,23 +2046,23 @@ fn expandFuncMacro(
2035 .byte_offset = maybe_va_args.start,2046 .byte_offset = maybe_va_args.start,
2036 .line = maybe_va_args.line,2047 .line = maybe_va_args.line,
2037 };2048 };
2038 try bufCopyTokens(&buf, expanded_variable_arguments.items, &.{raw_loc});2049 try bufCopyTokens(gpa, &buf, expanded_variable_arguments.items, &.{raw_loc});
2039 }2050 }
2040 continue;2051 continue;
2041 }2052 }
2042 }2053 }
2043 // Regular comma, no token pasting with __VA_ARGS__2054 // Regular comma, no token pasting with __VA_ARGS__
2044 try buf.append(tokFromRaw(raw));2055 try buf.append(gpa, tokFromRaw(raw));
2045 },2056 },
2046 else => try buf.append(tokFromRaw(raw)),2057 else => try buf.append(gpa, tokFromRaw(raw)),
2047 }2058 }
2048 }2059 }
2049 removePlacemarkers(&buf);2060 removePlacemarkers(gpa, &buf);
20502061
2051 const macro_expansion_locs = macro_tok.expansionSlice();2062 const macro_expansion_locs = macro_tok.expansionSlice();
2052 for (buf.items) |*tok| {2063 for (buf.items) |*tok| {
2053 try tok.addExpansionLocation(pp.gpa, &.{macro_tok.loc});2064 try tok.addExpansionLocation(gpa, &.{macro_tok.loc});
2054 try tok.addExpansionLocation(pp.gpa, macro_expansion_locs);2065 try tok.addExpansionLocation(gpa, macro_expansion_locs);
2055 const tok_hidelist = pp.hideset.get(tok.loc);2066 const tok_hidelist = pp.hideset.get(tok.loc);
2056 const new_hidelist = try pp.hideset.@"union"(tok_hidelist, hideset);2067 const new_hidelist = try pp.hideset.@"union"(tok_hidelist, hideset);
2057 try pp.hideset.put(tok.loc, new_hidelist);2068 try pp.hideset.put(tok.loc, new_hidelist);
...@@ -2078,16 +2089,16 @@ fn expandVaOpt(...@@ -2078,16 +2089,16 @@ fn expandVaOpt(
2078 };2089 };
2079 while (tokenizer.index < raw.end) {2090 while (tokenizer.index < raw.end) {
2080 const tok = tokenizer.next();2091 const tok = tokenizer.next();
2081 try buf.append(tokFromRaw(tok));2092 try buf.append(pp.comp.gpa, tokFromRaw(tok));
2082 }2093 }
2083}2094}
20842095
2085fn bufCopyTokens(buf: *ExpandBuf, tokens: []const TokenWithExpansionLocs, src: []const Source.Location) !void {2096fn bufCopyTokens(gpa: Allocator, buf: *ExpandBuf, tokens: []const TokenWithExpansionLocs, src: []const Source.Location) !void {
2086 try buf.ensureUnusedCapacity(tokens.len);2097 try buf.ensureUnusedCapacity(gpa, tokens.len);
2087 for (tokens) |tok| {2098 for (tokens) |tok| {
2088 var copy = try tok.dupe(buf.allocator);2099 var copy = try tok.dupe(gpa);
2089 errdefer TokenWithExpansionLocs.free(copy.expansion_locs, buf.allocator);2100 errdefer TokenWithExpansionLocs.free(copy.expansion_locs, gpa);
2090 try copy.addExpansionLocation(buf.allocator, src);2101 try copy.addExpansionLocation(gpa, src);
2091 buf.appendAssumeCapacity(copy);2102 buf.appendAssumeCapacity(copy);
2092 }2103 }
2093}2104}
...@@ -2112,10 +2123,10 @@ fn nextBufToken(...@@ -2112,10 +2123,10 @@ fn nextBufToken(
21122123
2113 const new_tok = tokFromRaw(raw_tok);2124 const new_tok = tokFromRaw(raw_tok);
2114 end_idx.* += 1;2125 end_idx.* += 1;
2115 try buf.append(new_tok);2126 try buf.append(pp.comp.gpa, new_tok);
2116 return new_tok;2127 return new_tok;
2117 } else {2128 } else {
2118 return TokenWithExpansionLocs{ .id = .eof, .loc = .{ .id = .generated } };2129 return .{ .id = .eof, .loc = .{ .id = .generated } };
2119 }2130 }
2120 } else {2131 } else {
2121 return buf.items[start_idx.*];2132 return buf.items[start_idx.*];
...@@ -2132,6 +2143,7 @@ fn collectMacroFuncArguments(...@@ -2132,6 +2143,7 @@ fn collectMacroFuncArguments(
2132 is_builtin: bool,2143 is_builtin: bool,
2133 r_paren: *TokenWithExpansionLocs,2144 r_paren: *TokenWithExpansionLocs,
2134) !MacroArguments {2145) !MacroArguments {
2146 const gpa = pp.comp.gpa;
2135 const name_tok = buf.items[start_idx.*];2147 const name_tok = buf.items[start_idx.*];
2136 const saved_tokenizer = tokenizer.*;2148 const saved_tokenizer = tokenizer.*;
2137 const old_end = end_idx.*;2149 const old_end = end_idx.*;
...@@ -2155,62 +2167,62 @@ fn collectMacroFuncArguments(...@@ -2155,62 +2167,62 @@ fn collectMacroFuncArguments(
21552167
2156 // collect the arguments.2168 // collect the arguments.
2157 var parens: u32 = 0;2169 var parens: u32 = 0;
2158 var args = MacroArguments.init(pp.gpa);2170 var args: MacroArguments = .empty;
2159 errdefer deinitMacroArguments(pp.gpa, &args);2171 errdefer deinitMacroArguments(gpa, &args);
2160 var curArgument = std.array_list.Managed(TokenWithExpansionLocs).init(pp.gpa);2172 var cur_argument: std.ArrayList(TokenWithExpansionLocs) = .empty;
2161 defer curArgument.deinit();2173 defer cur_argument.deinit(gpa);
2162 while (true) {2174 while (true) {
2163 var tok = try nextBufToken(pp, tokenizer, buf, start_idx, end_idx, extend_buf);2175 var tok = try nextBufToken(pp, tokenizer, buf, start_idx, end_idx, extend_buf);
2164 tok.flags.is_macro_arg = true;2176 tok.flags.is_macro_arg = true;
2165 switch (tok.id) {2177 switch (tok.id) {
2166 .comma => {2178 .comma => {
2167 if (parens == 0) {2179 if (parens == 0) {
2168 const owned = try curArgument.toOwnedSlice();2180 const owned = try cur_argument.toOwnedSlice(gpa);
2169 errdefer pp.gpa.free(owned);2181 errdefer gpa.free(owned);
2170 try args.append(owned);2182 try args.append(gpa, owned);
2171 } else {2183 } else {
2172 const duped = try tok.dupe(pp.gpa);2184 const duped = try tok.dupe(gpa);
2173 errdefer TokenWithExpansionLocs.free(duped.expansion_locs, pp.gpa);2185 errdefer TokenWithExpansionLocs.free(duped.expansion_locs, gpa);
2174 try curArgument.append(duped);2186 try cur_argument.append(gpa, duped);
2175 }2187 }
2176 },2188 },
2177 .l_paren => {2189 .l_paren => {
2178 const duped = try tok.dupe(pp.gpa);2190 const duped = try tok.dupe(gpa);
2179 errdefer TokenWithExpansionLocs.free(duped.expansion_locs, pp.gpa);2191 errdefer TokenWithExpansionLocs.free(duped.expansion_locs, gpa);
2180 try curArgument.append(duped);2192 try cur_argument.append(gpa, duped);
2181 parens += 1;2193 parens += 1;
2182 },2194 },
2183 .r_paren => {2195 .r_paren => {
2184 if (parens == 0) {2196 if (parens == 0) {
2185 const owned = try curArgument.toOwnedSlice();2197 const owned = try cur_argument.toOwnedSlice(gpa);
2186 errdefer pp.gpa.free(owned);2198 errdefer gpa.free(owned);
2187 try args.append(owned);2199 try args.append(gpa, owned);
2188 r_paren.* = tok;2200 r_paren.* = tok;
2189 break;2201 break;
2190 } else {2202 } else {
2191 const duped = try tok.dupe(pp.gpa);2203 const duped = try tok.dupe(gpa);
2192 errdefer TokenWithExpansionLocs.free(duped.expansion_locs, pp.gpa);2204 errdefer TokenWithExpansionLocs.free(duped.expansion_locs, gpa);
2193 try curArgument.append(duped);2205 try cur_argument.append(gpa, duped);
2194 parens -= 1;2206 parens -= 1;
2195 }2207 }
2196 },2208 },
2197 .eof => {2209 .eof => {
2198 {2210 {
2199 const owned = try curArgument.toOwnedSlice();2211 const owned = try cur_argument.toOwnedSlice(gpa);
2200 errdefer pp.gpa.free(owned);2212 errdefer gpa.free(owned);
2201 try args.append(owned);2213 try args.append(gpa, owned);
2202 }2214 }
2203 tokenizer.* = saved_tokenizer;2215 tokenizer.* = saved_tokenizer;
2204 try pp.err(name_tok, .unterminated_macro_arg_list, .{});2216 try pp.err(name_tok, .unterminated_macro_arg_list, .{});
2205 return error.Unterminated;2217 return error.Unterminated;
2206 },2218 },
2207 .nl, .whitespace => {2219 .nl, .whitespace => {
2208 try curArgument.append(.{ .id = .macro_ws, .loc = tok.loc });2220 try cur_argument.append(gpa, .{ .id = .macro_ws, .loc = tok.loc });
2209 },2221 },
2210 else => {2222 else => {
2211 const duped = try tok.dupe(pp.gpa);2223 const duped = try tok.dupe(gpa);
2212 errdefer TokenWithExpansionLocs.free(duped.expansion_locs, pp.gpa);2224 errdefer TokenWithExpansionLocs.free(duped.expansion_locs, gpa);
2213 try curArgument.append(duped);2225 try cur_argument.append(gpa, duped);
2214 },2226 },
2215 }2227 }
2216 }2228 }
...@@ -2219,8 +2231,9 @@ fn collectMacroFuncArguments(...@@ -2219,8 +2231,9 @@ fn collectMacroFuncArguments(
2219}2231}
22202232
2221fn removeExpandedTokens(pp: *Preprocessor, buf: *ExpandBuf, start: usize, len: usize, moving_end_idx: *usize) !void {2233fn removeExpandedTokens(pp: *Preprocessor, buf: *ExpandBuf, start: usize, len: usize, moving_end_idx: *usize) !void {
2222 for (buf.items[start .. start + len]) |tok| TokenWithExpansionLocs.free(tok.expansion_locs, pp.gpa);2234 const gpa = pp.comp.gpa;
2223 try buf.replaceRange(start, len, &.{});2235 for (buf.items[start .. start + len]) |tok| TokenWithExpansionLocs.free(tok.expansion_locs, gpa);
2236 try buf.replaceRange(gpa, start, len, &.{});
2224 moving_end_idx.* -|= len;2237 moving_end_idx.* -|= len;
2225}2238}
22262239
...@@ -2263,6 +2276,7 @@ fn expandMacroExhaustive(...@@ -2263,6 +2276,7 @@ fn expandMacroExhaustive(
2263 extend_buf: bool,2276 extend_buf: bool,
2264 eval_ctx: EvalContext,2277 eval_ctx: EvalContext,
2265) MacroError!void {2278) MacroError!void {
2279 const gpa = pp.comp.gpa;
2266 var moving_end_idx = end_idx;2280 var moving_end_idx = end_idx;
2267 var advance_index: usize = 0;2281 var advance_index: usize = 0;
2268 // rescan loop2282 // rescan loop
...@@ -2309,7 +2323,7 @@ fn expandMacroExhaustive(...@@ -2309,7 +2323,7 @@ fn expandMacroExhaustive(
2309 var r_paren: TokenWithExpansionLocs = undefined;2323 var r_paren: TokenWithExpansionLocs = undefined;
2310 var macro_scan_idx = idx;2324 var macro_scan_idx = idx;
2311 // to be saved in case this doesn't turn out to be a call2325 // to be saved in case this doesn't turn out to be a call
2312 const args = pp.collectMacroFuncArguments(2326 var args = pp.collectMacroFuncArguments(
2313 tokenizer,2327 tokenizer,
2314 buf,2328 buf,
2315 &macro_scan_idx,2329 &macro_scan_idx,
...@@ -2334,10 +2348,10 @@ fn expandMacroExhaustive(...@@ -2334,10 +2348,10 @@ fn expandMacroExhaustive(
2334 var free_arg_expansion_locs = false;2348 var free_arg_expansion_locs = false;
2335 defer {2349 defer {
2336 for (args.items) |item| {2350 for (args.items) |item| {
2337 if (free_arg_expansion_locs) for (item) |tok| TokenWithExpansionLocs.free(tok.expansion_locs, pp.gpa);2351 if (free_arg_expansion_locs) for (item) |tok| TokenWithExpansionLocs.free(tok.expansion_locs, gpa);
2338 pp.gpa.free(item);2352 gpa.free(item);
2339 }2353 }
2340 args.deinit();2354 args.deinit(gpa);
2341 }2355 }
2342 const r_paren_hidelist = pp.hideset.get(r_paren.loc);2356 const r_paren_hidelist = pp.hideset.get(r_paren.loc);
2343 var hs = try pp.hideset.intersection(macro_hidelist, r_paren_hidelist);2357 var hs = try pp.hideset.intersection(macro_hidelist, r_paren_hidelist);
...@@ -2370,25 +2384,25 @@ fn expandMacroExhaustive(...@@ -2370,25 +2384,25 @@ fn expandMacroExhaustive(
2370 try pp.removeExpandedTokens(buf, idx, macro_scan_idx - idx + 1, &moving_end_idx);2384 try pp.removeExpandedTokens(buf, idx, macro_scan_idx - idx + 1, &moving_end_idx);
2371 continue;2385 continue;
2372 }2386 }
2373 var expanded_args = MacroArguments.init(pp.gpa);2387 var expanded_args: MacroArguments = .empty;
2374 defer deinitMacroArguments(pp.gpa, &expanded_args);2388 defer deinitMacroArguments(gpa, &expanded_args);
2375 try expanded_args.ensureTotalCapacity(args.items.len);2389 try expanded_args.ensureTotalCapacity(gpa, args.items.len);
2376 for (args.items) |arg| {2390 for (args.items) |arg| {
2377 var expand_buf = ExpandBuf.init(pp.gpa);2391 var expand_buf: ExpandBuf = .empty;
2378 errdefer expand_buf.deinit();2392 errdefer expand_buf.deinit(gpa);
2379 try expand_buf.appendSlice(arg);2393 try expand_buf.appendSlice(gpa, arg);
23802394
2381 try pp.expandMacroExhaustive(tokenizer, &expand_buf, 0, expand_buf.items.len, false, eval_ctx);2395 try pp.expandMacroExhaustive(tokenizer, &expand_buf, 0, expand_buf.items.len, false, eval_ctx);
23822396
2383 expanded_args.appendAssumeCapacity(try expand_buf.toOwnedSlice());2397 expanded_args.appendAssumeCapacity(try expand_buf.toOwnedSlice(gpa));
2384 }2398 }
23852399
2386 var res = try pp.expandFuncMacro(macro_tok, macro, &args, &expanded_args, hs);2400 var res = try pp.expandFuncMacro(macro_tok, macro, &args, &expanded_args, hs);
2387 defer res.deinit();2401 defer res.deinit(gpa);
2388 const tokens_added = res.items.len;2402 const tokens_added = res.items.len;
2389 const tokens_removed = macro_scan_idx - idx + 1;2403 const tokens_removed = macro_scan_idx - idx + 1;
2390 for (buf.items[idx .. idx + tokens_removed]) |tok| TokenWithExpansionLocs.free(tok.expansion_locs, pp.gpa);2404 for (buf.items[idx .. idx + tokens_removed]) |tok| TokenWithExpansionLocs.free(tok.expansion_locs, gpa);
2391 try buf.replaceRange(idx, tokens_removed, res.items);2405 try buf.replaceRange(gpa, idx, tokens_removed, res.items);
23922406
2393 moving_end_idx += tokens_added;2407 moving_end_idx += tokens_added;
2394 // Overflow here means that we encountered an unterminated argument list2408 // Overflow here means that we encountered an unterminated argument list
...@@ -2397,8 +2411,8 @@ fn expandMacroExhaustive(...@@ -2397,8 +2411,8 @@ fn expandMacroExhaustive(
2397 idx += tokens_added;2411 idx += tokens_added;
2398 do_rescan = true;2412 do_rescan = true;
2399 } else {2413 } else {
2400 const res = try pp.expandObjMacro(macro);2414 var res = try pp.expandObjMacro(macro);
2401 defer res.deinit();2415 defer res.deinit(gpa);
24022416
2403 const hs = try pp.hideset.prepend(macro_tok.loc, macro_hidelist);2417 const hs = try pp.hideset.prepend(macro_tok.loc, macro_hidelist);
24042418
...@@ -2406,8 +2420,8 @@ fn expandMacroExhaustive(...@@ -2406,8 +2420,8 @@ fn expandMacroExhaustive(
2406 var increment_idx_by = res.items.len;2420 var increment_idx_by = res.items.len;
2407 for (res.items, 0..) |*tok, i| {2421 for (res.items, 0..) |*tok, i| {
2408 tok.flags.is_macro_arg = macro_tok.flags.is_macro_arg;2422 tok.flags.is_macro_arg = macro_tok.flags.is_macro_arg;
2409 try tok.addExpansionLocation(pp.gpa, &.{macro_tok.loc});2423 try tok.addExpansionLocation(gpa, &.{macro_tok.loc});
2410 try tok.addExpansionLocation(pp.gpa, macro_expansion_locs);2424 try tok.addExpansionLocation(gpa, macro_expansion_locs);
24112425
2412 const tok_hidelist = pp.hideset.get(tok.loc);2426 const tok_hidelist = pp.hideset.get(tok.loc);
2413 const new_hidelist = try pp.hideset.@"union"(tok_hidelist, hs);2427 const new_hidelist = try pp.hideset.@"union"(tok_hidelist, hs);
...@@ -2426,8 +2440,8 @@ fn expandMacroExhaustive(...@@ -2426,8 +2440,8 @@ fn expandMacroExhaustive(
2426 }2440 }
2427 }2441 }
24282442
2429 TokenWithExpansionLocs.free(buf.items[idx].expansion_locs, pp.gpa);2443 TokenWithExpansionLocs.free(buf.items[idx].expansion_locs, gpa);
2430 try buf.replaceRange(idx, 1, res.items);2444 try buf.replaceRange(gpa, idx, 1, res.items);
2431 idx += increment_idx_by;2445 idx += increment_idx_by;
2432 moving_end_idx = moving_end_idx + res.items.len - 1;2446 moving_end_idx = moving_end_idx + res.items.len - 1;
2433 do_rescan = true;2447 do_rescan = true;
...@@ -2442,7 +2456,7 @@ fn expandMacroExhaustive(...@@ -2442,7 +2456,7 @@ fn expandMacroExhaustive(
24422456
2443 // trim excess buffer2457 // trim excess buffer
2444 for (buf.items[moving_end_idx..]) |item| {2458 for (buf.items[moving_end_idx..]) |item| {
2445 TokenWithExpansionLocs.free(item.expansion_locs, pp.gpa);2459 TokenWithExpansionLocs.free(item.expansion_locs, gpa);
2446 }2460 }
2447 buf.items.len = moving_end_idx;2461 buf.items.len = moving_end_idx;
2448}2462}
...@@ -2456,10 +2470,11 @@ fn unescapeUcn(pp: *Preprocessor, tok: TokenWithExpansionLocs) !TokenWithExpansi...@@ -2456,10 +2470,11 @@ fn unescapeUcn(pp: *Preprocessor, tok: TokenWithExpansionLocs) !TokenWithExpansi
2456 .extended_identifier => {2470 .extended_identifier => {
2457 @branchHint(.cold);2471 @branchHint(.cold);
2458 const identifier = pp.expandedSlice(tok);2472 const identifier = pp.expandedSlice(tok);
2473 const gpa = pp.comp.gpa;
2459 if (mem.indexOfScalar(u8, identifier, '\\') != null) {2474 if (mem.indexOfScalar(u8, identifier, '\\') != null) {
2460 @branchHint(.cold);2475 @branchHint(.cold);
2461 const start = pp.comp.generated_buf.items.len;2476 const start = pp.comp.generated_buf.items.len;
2462 try pp.comp.generated_buf.ensureUnusedCapacity(pp.gpa, identifier.len + 1);2477 try pp.comp.generated_buf.ensureUnusedCapacity(gpa, identifier.len + 1);
2463 var identifier_parser: text_literal.Parser = .{2478 var identifier_parser: text_literal.Parser = .{
2464 .comp = pp.comp,2479 .comp = pp.comp,
2465 .literal = pp.expandedSlice(tok), // re-expand since previous line may have caused a reallocation, invalidating `identifier`2480 .literal = pp.expandedSlice(tok), // re-expand since previous line may have caused a reallocation, invalidating `identifier`
...@@ -2486,7 +2501,7 @@ fn unescapeUcn(pp: *Preprocessor, tok: TokenWithExpansionLocs) !TokenWithExpansi...@@ -2486,7 +2501,7 @@ fn unescapeUcn(pp: *Preprocessor, tok: TokenWithExpansionLocs) !TokenWithExpansi
2486 }2501 }
2487 }2502 }
2488 pp.comp.generated_buf.appendAssumeCapacity('\n');2503 pp.comp.generated_buf.appendAssumeCapacity('\n');
2489 defer TokenWithExpansionLocs.free(tok.expansion_locs, pp.gpa);2504 defer TokenWithExpansionLocs.free(tok.expansion_locs, gpa);
2490 return pp.makeGeneratedToken(start, .extended_identifier, tok);2505 return pp.makeGeneratedToken(start, .extended_identifier, tok);
2491 }2506 }
2492 },2507 },
...@@ -2503,8 +2518,9 @@ fn expandMacro(pp: *Preprocessor, tokenizer: *Tokenizer, raw: RawToken) MacroErr...@@ -2503,8 +2518,9 @@ fn expandMacro(pp: *Preprocessor, tokenizer: *Tokenizer, raw: RawToken) MacroErr
2503 source_tok.id.simplifyMacroKeyword();2518 source_tok.id.simplifyMacroKeyword();
2504 return pp.addToken(source_tok);2519 return pp.addToken(source_tok);
2505 }2520 }
2521 const gpa = pp.comp.gpa;
2506 pp.top_expansion_buf.items.len = 0;2522 pp.top_expansion_buf.items.len = 0;
2507 try pp.top_expansion_buf.append(source_tok);2523 try pp.top_expansion_buf.append(gpa, source_tok);
2508 pp.expansion_source_loc = source_tok.loc;2524 pp.expansion_source_loc = source_tok.loc;
25092525
2510 pp.hideset.clearRetainingCapacity();2526 pp.hideset.clearRetainingCapacity();
...@@ -2512,15 +2528,15 @@ fn expandMacro(pp: *Preprocessor, tokenizer: *Tokenizer, raw: RawToken) MacroErr...@@ -2512,15 +2528,15 @@ fn expandMacro(pp: *Preprocessor, tokenizer: *Tokenizer, raw: RawToken) MacroErr
2512 try pp.ensureUnusedTokenCapacity(pp.top_expansion_buf.items.len);2528 try pp.ensureUnusedTokenCapacity(pp.top_expansion_buf.items.len);
2513 for (pp.top_expansion_buf.items) |*tok| {2529 for (pp.top_expansion_buf.items) |*tok| {
2514 if (tok.id == .macro_ws and !pp.preserve_whitespace) {2530 if (tok.id == .macro_ws and !pp.preserve_whitespace) {
2515 TokenWithExpansionLocs.free(tok.expansion_locs, pp.gpa);2531 TokenWithExpansionLocs.free(tok.expansion_locs, gpa);
2516 continue;2532 continue;
2517 }2533 }
2518 if (tok.id == .comment and !pp.comp.langopts.preserve_comments_in_macros) {2534 if (tok.id == .comment and !pp.comp.langopts.preserve_comments_in_macros) {
2519 TokenWithExpansionLocs.free(tok.expansion_locs, pp.gpa);2535 TokenWithExpansionLocs.free(tok.expansion_locs, gpa);
2520 continue;2536 continue;
2521 }2537 }
2522 if (tok.id == .placemarker) {2538 if (tok.id == .placemarker) {
2523 TokenWithExpansionLocs.free(tok.expansion_locs, pp.gpa);2539 TokenWithExpansionLocs.free(tok.expansion_locs, gpa);
2524 continue;2540 continue;
2525 }2541 }
2526 tok.id.simplifyMacroKeywordExtra(true);2542 tok.id.simplifyMacroKeywordExtra(true);
...@@ -2564,14 +2580,15 @@ pub fn expandedSlice(pp: *const Preprocessor, tok: anytype) []const u8 {...@@ -2564,14 +2580,15 @@ pub fn expandedSlice(pp: *const Preprocessor, tok: anytype) []const u8 {
25642580
2565/// Concat two tokens and add the result to pp.generated2581/// Concat two tokens and add the result to pp.generated
2566fn pasteTokens(pp: *Preprocessor, lhs_toks: *ExpandBuf, rhs_toks: []const TokenWithExpansionLocs) Error!void {2582fn pasteTokens(pp: *Preprocessor, lhs_toks: *ExpandBuf, rhs_toks: []const TokenWithExpansionLocs) Error!void {
2583 const gpa = pp.comp.gpa;
2567 const lhs = while (lhs_toks.pop()) |lhs| {2584 const lhs = while (lhs_toks.pop()) |lhs| {
2568 if ((pp.comp.langopts.preserve_comments_in_macros and lhs.id == .comment) or2585 if ((pp.comp.langopts.preserve_comments_in_macros and lhs.id == .comment) or
2569 (lhs.id != .macro_ws and lhs.id != .comment))2586 (lhs.id != .macro_ws and lhs.id != .comment))
2570 break lhs;2587 break lhs;
25712588
2572 TokenWithExpansionLocs.free(lhs.expansion_locs, pp.gpa);2589 TokenWithExpansionLocs.free(lhs.expansion_locs, gpa);
2573 } else {2590 } else {
2574 return bufCopyTokens(lhs_toks, rhs_toks, &.{});2591 return bufCopyTokens(gpa, lhs_toks, rhs_toks, &.{});
2575 };2592 };
25762593
2577 var rhs_rest: u32 = 1;2594 var rhs_rest: u32 = 1;
...@@ -2584,11 +2601,11 @@ fn pasteTokens(pp: *Preprocessor, lhs_toks: *ExpandBuf, rhs_toks: []const TokenW...@@ -2584,11 +2601,11 @@ fn pasteTokens(pp: *Preprocessor, lhs_toks: *ExpandBuf, rhs_toks: []const TokenW
2584 } else {2601 } else {
2585 return lhs_toks.appendAssumeCapacity(lhs);2602 return lhs_toks.appendAssumeCapacity(lhs);
2586 };2603 };
2587 defer TokenWithExpansionLocs.free(lhs.expansion_locs, pp.gpa);2604 defer TokenWithExpansionLocs.free(lhs.expansion_locs, gpa);
25882605
2589 const start = pp.comp.generated_buf.items.len;2606 const start = pp.comp.generated_buf.items.len;
2590 const end = start + pp.expandedSlice(lhs).len + pp.expandedSlice(rhs).len;2607 const end = start + pp.expandedSlice(lhs).len + pp.expandedSlice(rhs).len;
2591 try pp.comp.generated_buf.ensureTotalCapacity(pp.gpa, end + 1); // +1 for a newline2608 try pp.comp.generated_buf.ensureTotalCapacity(gpa, end + 1); // +1 for a newline
2592 // We cannot use the same slices here since they might be invalidated by `ensureCapacity`2609 // We cannot use the same slices here since they might be invalidated by `ensureCapacity`
2593 pp.comp.generated_buf.appendSliceAssumeCapacity(pp.expandedSlice(lhs));2610 pp.comp.generated_buf.appendSliceAssumeCapacity(pp.expandedSlice(lhs));
2594 pp.comp.generated_buf.appendSliceAssumeCapacity(pp.expandedSlice(rhs));2611 pp.comp.generated_buf.appendSliceAssumeCapacity(pp.expandedSlice(rhs));
...@@ -2607,32 +2624,33 @@ fn pasteTokens(pp: *Preprocessor, lhs_toks: *ExpandBuf, rhs_toks: []const TokenW...@@ -2607,32 +2624,33 @@ fn pasteTokens(pp: *Preprocessor, lhs_toks: *ExpandBuf, rhs_toks: []const TokenW
2607 .placemarker2624 .placemarker
2608 else2625 else
2609 pasted_token.id;2626 pasted_token.id;
2610 try lhs_toks.append(try pp.makeGeneratedToken(start, pasted_id, lhs));2627 try lhs_toks.append(gpa, try pp.makeGeneratedToken(start, pasted_id, lhs));
26112628
2612 if (next.id != .nl and next.id != .eof) {2629 if (next.id != .nl and next.id != .eof) {
2613 try pp.err(lhs, .pasting_formed_invalid, .{pp.comp.generated_buf.items[start..end]});2630 try pp.err(lhs, .pasting_formed_invalid, .{pp.comp.generated_buf.items[start..end]});
2614 try lhs_toks.append(tokFromRaw(next));2631 try lhs_toks.append(gpa, tokFromRaw(next));
2615 }2632 }
26162633
2617 try bufCopyTokens(lhs_toks, rhs_toks[rhs_rest..], &.{});2634 try bufCopyTokens(gpa, lhs_toks, rhs_toks[rhs_rest..], &.{});
2618}2635}
26192636
2620fn makeGeneratedToken(pp: *Preprocessor, start: usize, id: Token.Id, source: TokenWithExpansionLocs) !TokenWithExpansionLocs {2637fn makeGeneratedToken(pp: *Preprocessor, start: usize, id: Token.Id, source: TokenWithExpansionLocs) !TokenWithExpansionLocs {
2638 const gpa = pp.comp.gpa;
2621 var pasted_token = TokenWithExpansionLocs{ .id = id, .loc = .{2639 var pasted_token = TokenWithExpansionLocs{ .id = id, .loc = .{
2622 .id = .generated,2640 .id = .generated,
2623 .byte_offset = @intCast(start),2641 .byte_offset = @intCast(start),
2624 .line = pp.generated_line,2642 .line = pp.generated_line,
2625 } };2643 } };
2626 pp.generated_line += 1;2644 pp.generated_line += 1;
2627 try pasted_token.addExpansionLocation(pp.gpa, &.{source.loc});2645 try pasted_token.addExpansionLocation(gpa, &.{source.loc});
2628 try pasted_token.addExpansionLocation(pp.gpa, source.expansionSlice());2646 try pasted_token.addExpansionLocation(gpa, source.expansionSlice());
2629 return pasted_token;2647 return pasted_token;
2630}2648}
26312649
2632/// Defines a new macro and warns if it is a duplicate2650/// Defines a new macro and warns if it is a duplicate
2633fn defineMacro(pp: *Preprocessor, define_tok: RawToken, name_tok: TokenWithExpansionLocs, macro: Macro) Error!void {2651fn defineMacro(pp: *Preprocessor, define_tok: RawToken, name_tok: TokenWithExpansionLocs, macro: Macro) Error!void {
2634 const name_str = pp.expandedSlice(name_tok);2652 const name_str = pp.expandedSlice(name_tok);
2635 const gop = try pp.defines.getOrPut(pp.gpa, name_str);2653 const gop = try pp.defines.getOrPut(pp.comp.gpa, name_str);
2636 if (gop.found_existing and !gop.value_ptr.eql(macro, pp)) {2654 if (gop.found_existing and !gop.value_ptr.eql(macro, pp)) {
2637 const loc = name_tok.loc;2655 const loc = name_tok.loc;
2638 const prev_total = pp.diagnostics.total;2656 const prev_total = pp.diagnostics.total;
...@@ -2668,8 +2686,9 @@ fn define(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken) Error!...@@ -2668,8 +2686,9 @@ fn define(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken) Error!
2668 try pp.err(escaped_macro_name, .macro_name_must_be_identifier, .{});2686 try pp.err(escaped_macro_name, .macro_name_must_be_identifier, .{});
2669 return skipToNl(tokenizer);2687 return skipToNl(tokenizer);
2670 }2688 }
2689 const gpa = pp.comp.gpa;
2671 const macro_name = try pp.unescapeUcn(tokFromRaw(escaped_macro_name));2690 const macro_name = try pp.unescapeUcn(tokFromRaw(escaped_macro_name));
2672 defer TokenWithExpansionLocs.free(macro_name.expansion_locs, pp.gpa);2691 defer TokenWithExpansionLocs.free(macro_name.expansion_locs, gpa);
26732692
2674 var macro_name_token_id = macro_name.id;2693 var macro_name_token_id = macro_name.id;
2675 macro_name_token_id.simplifyMacroKeyword();2694 macro_name_token_id.simplifyMacroKeyword();
...@@ -2724,21 +2743,21 @@ fn define(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken) Error!...@@ -2724,21 +2743,21 @@ fn define(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken) Error!
2724 },2743 },
2725 else => {},2744 else => {},
2726 }2745 }
2727 try pp.token_buf.append(tok);2746 try pp.token_buf.append(gpa, tok);
2728 try pp.token_buf.append(next);2747 try pp.token_buf.append(gpa, next);
2729 },2748 },
2730 .nl, .eof => break,2749 .nl, .eof => break,
2731 .comment => if (pp.comp.langopts.preserve_comments_in_macros) {2750 .comment => if (pp.comp.langopts.preserve_comments_in_macros) {
2732 if (need_ws) {2751 if (need_ws) {
2733 need_ws = false;2752 need_ws = false;
2734 try pp.token_buf.append(.{ .id = .macro_ws, .source = .generated });2753 try pp.token_buf.append(gpa, .{ .id = .macro_ws, .source = .generated });
2735 }2754 }
2736 try pp.token_buf.append(tok);2755 try pp.token_buf.append(gpa, tok);
2737 },2756 },
2738 .whitespace => need_ws = true,2757 .whitespace => need_ws = true,
2739 .unterminated_string_literal, .unterminated_char_literal, .empty_char_literal => |tag| {2758 .unterminated_string_literal, .unterminated_char_literal, .empty_char_literal => |tag| {
2740 try pp.err(tok, invalidTokenDiagnostic(tag), .{});2759 try pp.err(tok, invalidTokenDiagnostic(tag), .{});
2741 try pp.token_buf.append(tok);2760 try pp.token_buf.append(gpa, tok);
2742 },2761 },
2743 .unterminated_comment => try pp.err(tok, .unterminated_comment, .{}),2762 .unterminated_comment => try pp.err(tok, .unterminated_comment, .{}),
2744 else => {2763 else => {
...@@ -2748,9 +2767,9 @@ fn define(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken) Error!...@@ -2748,9 +2767,9 @@ fn define(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken) Error!
2748 }2767 }
2749 if (tok.id != .whitespace and need_ws) {2768 if (tok.id != .whitespace and need_ws) {
2750 need_ws = false;2769 need_ws = false;
2751 try pp.token_buf.append(.{ .id = .macro_ws, .source = .generated });2770 try pp.token_buf.append(gpa, .{ .id = .macro_ws, .source = .generated });
2752 }2771 }
2753 try pp.token_buf.append(tok);2772 try pp.token_buf.append(gpa, tok);
2754 },2773 },
2755 }2774 }
2756 tok = tokenizer.next();2775 tok = tokenizer.next();
...@@ -2769,8 +2788,9 @@ fn define(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken) Error!...@@ -2769,8 +2788,9 @@ fn define(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken) Error!
2769/// Handle a function like #define directive.2788/// Handle a function like #define directive.
2770fn defineFn(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken, macro_name: TokenWithExpansionLocs, l_paren: RawToken) Error!void {2789fn defineFn(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken, macro_name: TokenWithExpansionLocs, l_paren: RawToken) Error!void {
2771 assert(macro_name.id.isMacroIdentifier());2790 assert(macro_name.id.isMacroIdentifier());
2772 var params = std.array_list.Managed([]const u8).init(pp.gpa);2791 const gpa = pp.comp.gpa;
2773 defer params.deinit();2792 var params: std.ArrayList([]const u8) = .empty;
2793 defer params.deinit(gpa);
27742794
2775 // Parse the parameter list.2795 // Parse the parameter list.
2776 var gnu_var_args: []const u8 = "";2796 var gnu_var_args: []const u8 = "";
...@@ -2794,7 +2814,7 @@ fn defineFn(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken, macr...@@ -2794,7 +2814,7 @@ fn defineFn(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken, macr
2794 return skipToNl(tokenizer);2814 return skipToNl(tokenizer);
2795 }2815 }
27962816
2797 try params.append(pp.tokSlice(tok));2817 try params.append(gpa, pp.tokSlice(tok));
27982818
2799 tok = tokenizer.nextNoWS();2819 tok = tokenizer.nextNoWS();
2800 if (tok.id == .ellipsis) {2820 if (tok.id == .ellipsis) {
...@@ -2826,34 +2846,34 @@ fn defineFn(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken, macr...@@ -2826,34 +2846,34 @@ fn defineFn(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken, macr
2826 .comment => if (!pp.comp.langopts.preserve_comments_in_macros) continue else {2846 .comment => if (!pp.comp.langopts.preserve_comments_in_macros) continue else {
2827 if (need_ws) {2847 if (need_ws) {
2828 need_ws = false;2848 need_ws = false;
2829 try pp.token_buf.append(.{ .id = .macro_ws, .source = .generated });2849 try pp.token_buf.append(gpa, .{ .id = .macro_ws, .source = .generated });
2830 }2850 }
2831 try pp.token_buf.append(tok);2851 try pp.token_buf.append(gpa, tok);
2832 },2852 },
2833 .hash => {2853 .hash => {
2834 if (tok.id != .whitespace and need_ws) {2854 if (tok.id != .whitespace and need_ws) {
2835 need_ws = false;2855 need_ws = false;
2836 try pp.token_buf.append(.{ .id = .macro_ws, .source = .generated });2856 try pp.token_buf.append(gpa, .{ .id = .macro_ws, .source = .generated });
2837 }2857 }
2838 const param = tokenizer.nextNoWS();2858 const param = tokenizer.nextNoWS();
2839 blk: {2859 blk: {
2840 if (var_args and param.id == .keyword_va_args) {2860 if (var_args and param.id == .keyword_va_args) {
2841 tok.id = .stringify_va_args;2861 tok.id = .stringify_va_args;
2842 try pp.token_buf.append(tok);2862 try pp.token_buf.append(gpa, tok);
2843 continue :tok_loop;2863 continue :tok_loop;
2844 }2864 }
2845 if (!param.id.isMacroIdentifier()) break :blk;2865 if (!param.id.isMacroIdentifier()) break :blk;
2846 const s = pp.tokSlice(param);2866 const s = pp.tokSlice(param);
2847 if (mem.eql(u8, s, gnu_var_args)) {2867 if (mem.eql(u8, s, gnu_var_args)) {
2848 tok.id = .stringify_va_args;2868 tok.id = .stringify_va_args;
2849 try pp.token_buf.append(tok);2869 try pp.token_buf.append(gpa, tok);
2850 continue :tok_loop;2870 continue :tok_loop;
2851 }2871 }
2852 for (params.items, 0..) |p, i| {2872 for (params.items, 0..) |p, i| {
2853 if (mem.eql(u8, p, s)) {2873 if (mem.eql(u8, p, s)) {
2854 tok.id = .stringify_param;2874 tok.id = .stringify_param;
2855 tok.end = @intCast(i);2875 tok.end = @intCast(i);
2856 try pp.token_buf.append(tok);2876 try pp.token_buf.append(gpa, tok);
2857 continue :tok_loop;2877 continue :tok_loop;
2858 }2878 }
2859 }2879 }
...@@ -2880,17 +2900,17 @@ fn defineFn(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken, macr...@@ -2880,17 +2900,17 @@ fn defineFn(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken, macr
2880 if (pp.token_buf.items[pp.token_buf.items.len - 1].id == .macro_param) {2900 if (pp.token_buf.items[pp.token_buf.items.len - 1].id == .macro_param) {
2881 pp.token_buf.items[pp.token_buf.items.len - 1].id = .macro_param_no_expand;2901 pp.token_buf.items[pp.token_buf.items.len - 1].id = .macro_param_no_expand;
2882 }2902 }
2883 try pp.token_buf.append(tok);2903 try pp.token_buf.append(gpa, tok);
2884 },2904 },
2885 .unterminated_string_literal, .unterminated_char_literal, .empty_char_literal => |tag| {2905 .unterminated_string_literal, .unterminated_char_literal, .empty_char_literal => |tag| {
2886 try pp.err(tok, invalidTokenDiagnostic(tag), .{});2906 try pp.err(tok, invalidTokenDiagnostic(tag), .{});
2887 try pp.token_buf.append(tok);2907 try pp.token_buf.append(gpa, tok);
2888 },2908 },
2889 .unterminated_comment => try pp.err(tok, .unterminated_comment, .{}),2909 .unterminated_comment => try pp.err(tok, .unterminated_comment, .{}),
2890 else => {2910 else => {
2891 if (tok.id != .whitespace and need_ws) {2911 if (tok.id != .whitespace and need_ws) {
2892 need_ws = false;2912 need_ws = false;
2893 try pp.token_buf.append(.{ .id = .macro_ws, .source = .generated });2913 try pp.token_buf.append(gpa, .{ .id = .macro_ws, .source = .generated });
2894 }2914 }
2895 if (var_args and tok.id == .keyword_va_args) {2915 if (var_args and tok.id == .keyword_va_args) {
2896 // do nothing2916 // do nothing
...@@ -2937,7 +2957,7 @@ fn defineFn(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken, macr...@@ -2937,7 +2957,7 @@ fn defineFn(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken, macr
2937 }2957 }
2938 }2958 }
2939 }2959 }
2940 try pp.token_buf.append(tok);2960 try pp.token_buf.append(gpa, tok);
2941 },2961 },
2942 }2962 }
2943 }2963 }
...@@ -2957,12 +2977,13 @@ fn defineFn(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken, macr...@@ -2957,12 +2977,13 @@ fn defineFn(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken, macr
2957/// embedDirective : ("FILENAME" | <FILENAME>) embedParam*2977/// embedDirective : ("FILENAME" | <FILENAME>) embedParam*
2958/// embedParam : IDENTIFIER (:: IDENTIFIER)? '(' <tokens> ')'2978/// embedParam : IDENTIFIER (:: IDENTIFIER)? '(' <tokens> ')'
2959fn embed(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!void {2979fn embed(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!void {
2980 const gpa = pp.comp.gpa;
2960 const first = tokenizer.nextNoWS();2981 const first = tokenizer.nextNoWS();
2961 const filename_tok = pp.findIncludeFilenameToken(first, tokenizer, .ignore_trailing_tokens) catch |er| switch (er) {2982 const filename_tok = pp.findIncludeFilenameToken(first, tokenizer, .ignore_trailing_tokens) catch |er| switch (er) {
2962 error.InvalidInclude => return,2983 error.InvalidInclude => return,
2963 else => |e| return e,2984 else => |e| return e,
2964 };2985 };
2965 defer TokenWithExpansionLocs.free(filename_tok.expansion_locs, pp.gpa);2986 defer TokenWithExpansionLocs.free(filename_tok.expansion_locs, gpa);
29662987
2967 // Check for empty filename.2988 // Check for empty filename.
2968 const tok_slice = pp.expandedSliceExtra(filename_tok, .single_macro_ws);2989 const tok_slice = pp.expandedSliceExtra(filename_tok, .single_macro_ws);
...@@ -3024,9 +3045,12 @@ fn embed(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!void {...@@ -3024,9 +3045,12 @@ fn embed(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!void {
3024 try pp.err(l_paren, .malformed_embed_param, .{});3045 try pp.err(l_paren, .malformed_embed_param, .{});
3025 continue;3046 continue;
3026 }3047 }
3027 try pp.char_buf.appendSlice(Attribute.normalize(pp.tokSlice(param_first)));3048 const vendor = Attribute.normalize(pp.tokSlice(param_first));
3028 try pp.char_buf.appendSlice("::");3049 const param_name = Attribute.normalize(pp.tokSlice(param));
3029 try pp.char_buf.appendSlice(Attribute.normalize(pp.tokSlice(param)));3050 try pp.char_buf.ensureUnusedCapacity(gpa, vendor.len + 2 + param_name.len);
3051 pp.char_buf.appendSliceAssumeCapacity(vendor);
3052 pp.char_buf.appendSliceAssumeCapacity("::");
3053 pp.char_buf.appendSliceAssumeCapacity(param_name);
3030 break :blk pp.char_buf.items;3054 break :blk pp.char_buf.items;
3031 },3055 },
3032 .l_paren => Attribute.normalize(pp.tokSlice(param_first)),3056 .l_paren => Attribute.normalize(pp.tokSlice(param_first)),
...@@ -3044,7 +3068,7 @@ fn embed(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!void {...@@ -3044,7 +3068,7 @@ fn embed(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!void {
3044 try pp.err(maybe_colon, .malformed_embed_param, .{});3068 try pp.err(maybe_colon, .malformed_embed_param, .{});
3045 break;3069 break;
3046 }3070 }
3047 try pp.token_buf.append(next);3071 try pp.token_buf.append(gpa, next);
3048 }3072 }
3049 const end: u32 = @intCast(pp.token_buf.items.len);3073 const end: u32 = @intCast(pp.token_buf.items.len);
30503074
...@@ -3093,7 +3117,7 @@ fn embed(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!void {...@@ -3093,7 +3117,7 @@ fn embed(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!void {
30933117
3094 const embed_bytes = (try pp.comp.findEmbed(filename, first.source, include_type, limit orelse .unlimited, pp.dep_file)) orelse3118 const embed_bytes = (try pp.comp.findEmbed(filename, first.source, include_type, limit orelse .unlimited, pp.dep_file)) orelse
3095 return pp.fatalNotFound(filename_tok, filename);3119 return pp.fatalNotFound(filename_tok, filename);
3096 defer pp.comp.gpa.free(embed_bytes);3120 defer gpa.free(embed_bytes);
30973121
3098 try Range.expand(prefix, pp, tokenizer);3122 try Range.expand(prefix, pp, tokenizer);
30993123
...@@ -3111,17 +3135,17 @@ fn embed(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!void {...@@ -3111,17 +3135,17 @@ fn embed(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!void {
3111 {3135 {
3112 const byte = embed_bytes[0];3136 const byte = embed_bytes[0];
3113 const start = pp.comp.generated_buf.items.len;3137 const start = pp.comp.generated_buf.items.len;
3114 try pp.comp.generated_buf.print(pp.gpa, "{d}", .{byte});3138 try pp.comp.generated_buf.print(gpa, "{d}", .{byte});
3115 pp.addTokenAssumeCapacity(try pp.makeGeneratedToken(start, .embed_byte, filename_tok));3139 pp.addTokenAssumeCapacity(try pp.makeGeneratedToken(start, .embed_byte, filename_tok));
3116 }3140 }
31173141
3118 for (embed_bytes[1..]) |byte| {3142 for (embed_bytes[1..]) |byte| {
3119 const start = pp.comp.generated_buf.items.len;3143 const start = pp.comp.generated_buf.items.len;
3120 try pp.comp.generated_buf.print(pp.gpa, ",{d}", .{byte});3144 try pp.comp.generated_buf.print(gpa, ",{d}", .{byte});
3121 pp.addTokenAssumeCapacity(.{ .id = .comma, .loc = .{ .id = .generated, .byte_offset = @intCast(start) } });3145 pp.addTokenAssumeCapacity(.{ .id = .comma, .loc = .{ .id = .generated, .byte_offset = @intCast(start) } });
3122 pp.addTokenAssumeCapacity(try pp.makeGeneratedToken(start + 1, .embed_byte, filename_tok));3146 pp.addTokenAssumeCapacity(try pp.makeGeneratedToken(start + 1, .embed_byte, filename_tok));
3123 }3147 }
3124 try pp.comp.generated_buf.append(pp.gpa, '\n');3148 try pp.comp.generated_buf.append(gpa, '\n');
31253149
3126 try Range.expand(suffix, pp, tokenizer);3150 try Range.expand(suffix, pp, tokenizer);
3127}3151}
...@@ -3133,6 +3157,7 @@ fn include(pp: *Preprocessor, tokenizer: *Tokenizer, which: Compilation.WhichInc...@@ -3133,6 +3157,7 @@ fn include(pp: *Preprocessor, tokenizer: *Tokenizer, which: Compilation.WhichInc
3133 error.InvalidInclude => return,3157 error.InvalidInclude => return,
3134 else => |e| return e,3158 else => |e| return e,
3135 };3159 };
3160 const gpa = pp.comp.gpa;
31363161
3137 // Prevent stack overflow3162 // Prevent stack overflow
3138 pp.include_depth += 1;3163 pp.include_depth += 1;
...@@ -3147,7 +3172,7 @@ fn include(pp: *Preprocessor, tokenizer: *Tokenizer, which: Compilation.WhichInc...@@ -3147,7 +3172,7 @@ fn include(pp: *Preprocessor, tokenizer: *Tokenizer, which: Compilation.WhichInc
3147 if (pp.defines.contains(guard)) return;3172 if (pp.defines.contains(guard)) return;
3148 }3173 }
31493174
3150 if (pp.dep_file) |dep| try dep.addDependency(pp.gpa, new_source.path);3175 if (pp.dep_file) |dep| try dep.addDependency(gpa, new_source.path);
3151 if (pp.verbose) {3176 if (pp.verbose) {
3152 pp.verboseLog(first, "include file {s}", .{new_source.path});3177 pp.verboseLog(first, "include file {s}", .{new_source.path});
3153 }3178 }
...@@ -3156,7 +3181,7 @@ fn include(pp: *Preprocessor, tokenizer: *Tokenizer, which: Compilation.WhichInc...@@ -3156,7 +3181,7 @@ fn include(pp: *Preprocessor, tokenizer: *Tokenizer, which: Compilation.WhichInc
3156 try pp.addIncludeStart(new_source);3181 try pp.addIncludeStart(new_source);
3157 const eof = pp.preprocessExtra(new_source) catch |er| switch (er) {3182 const eof = pp.preprocessExtra(new_source) catch |er| switch (er) {
3158 error.StopPreprocessing => {3183 error.StopPreprocessing => {
3159 for (pp.expansion_entries.items(.locs)[token_state.expansion_entries_len..]) |loc| TokenWithExpansionLocs.free(loc, pp.gpa);3184 for (pp.expansion_entries.items(.locs)[token_state.expansion_entries_len..]) |loc| TokenWithExpansionLocs.free(loc, gpa);
3160 pp.restoreTokenState(token_state);3185 pp.restoreTokenState(token_state);
3161 return;3186 return;
3162 },3187 },
...@@ -3187,20 +3212,22 @@ fn include(pp: *Preprocessor, tokenizer: *Tokenizer, which: Compilation.WhichInc...@@ -3187,20 +3212,22 @@ fn include(pp: *Preprocessor, tokenizer: *Tokenizer, which: Compilation.WhichInc
3187/// operator_loc: Location of `_Pragma`; null if this is from #pragma3212/// operator_loc: Location of `_Pragma`; null if this is from #pragma
3188/// arg_locs: expansion locations of the argument to _Pragma. empty if #pragma or a raw string literal was used3213/// arg_locs: expansion locations of the argument to _Pragma. empty if #pragma or a raw string literal was used
3189fn makePragmaToken(pp: *Preprocessor, raw: RawToken, operator_loc: ?Source.Location, arg_locs: []const Source.Location) !TokenWithExpansionLocs {3214fn makePragmaToken(pp: *Preprocessor, raw: RawToken, operator_loc: ?Source.Location, arg_locs: []const Source.Location) !TokenWithExpansionLocs {
3215 const gpa = pp.comp.gpa;
3190 var tok = tokFromRaw(raw);3216 var tok = tokFromRaw(raw);
3191 if (operator_loc) |loc| {3217 if (operator_loc) |loc| {
3192 try tok.addExpansionLocation(pp.gpa, &.{loc});3218 try tok.addExpansionLocation(gpa, &.{loc});
3193 }3219 }
3194 try tok.addExpansionLocation(pp.gpa, arg_locs);3220 try tok.addExpansionLocation(gpa, arg_locs);
3195 return tok;3221 return tok;
3196}3222}
31973223
3198pub fn addToken(pp: *Preprocessor, tok_arg: TokenWithExpansionLocs) !void {3224pub fn addToken(pp: *Preprocessor, tok_arg: TokenWithExpansionLocs) !void {
3225 const gpa = pp.comp.gpa;
3199 const tok = try pp.unescapeUcn(tok_arg);3226 const tok = try pp.unescapeUcn(tok_arg);
3200 if (tok.expansion_locs) |expansion_locs| {3227 if (tok.expansion_locs) |expansion_locs| {
3201 try pp.expansion_entries.append(pp.gpa, .{ .idx = @intCast(pp.tokens.len), .locs = expansion_locs });3228 try pp.expansion_entries.append(gpa, .{ .idx = @intCast(pp.tokens.len), .locs = expansion_locs });
3202 }3229 }
3203 try pp.tokens.append(pp.gpa, .{ .id = tok.id, .loc = tok.loc });3230 try pp.tokens.append(gpa, .{ .id = tok.id, .loc = tok.loc });
3204}3231}
32053232
3206pub fn addTokenAssumeCapacity(pp: *Preprocessor, tok: TokenWithExpansionLocs) void {3233pub fn addTokenAssumeCapacity(pp: *Preprocessor, tok: TokenWithExpansionLocs) void {
...@@ -3211,13 +3238,15 @@ pub fn addTokenAssumeCapacity(pp: *Preprocessor, tok: TokenWithExpansionLocs) vo...@@ -3211,13 +3238,15 @@ pub fn addTokenAssumeCapacity(pp: *Preprocessor, tok: TokenWithExpansionLocs) vo
3211}3238}
32123239
3213pub fn ensureTotalTokenCapacity(pp: *Preprocessor, capacity: usize) !void {3240pub fn ensureTotalTokenCapacity(pp: *Preprocessor, capacity: usize) !void {
3214 try pp.tokens.ensureTotalCapacity(pp.gpa, capacity);3241 const gpa = pp.comp.gpa;
3215 try pp.expansion_entries.ensureTotalCapacity(pp.gpa, capacity);3242 try pp.tokens.ensureTotalCapacity(gpa, capacity);
3243 try pp.expansion_entries.ensureTotalCapacity(gpa, capacity);
3216}3244}
32173245
3218pub fn ensureUnusedTokenCapacity(pp: *Preprocessor, capacity: usize) !void {3246pub fn ensureUnusedTokenCapacity(pp: *Preprocessor, capacity: usize) !void {
3219 try pp.tokens.ensureUnusedCapacity(pp.gpa, capacity);3247 const gpa = pp.comp.gpa;
3220 try pp.expansion_entries.ensureUnusedCapacity(pp.gpa, capacity);3248 try pp.tokens.ensureUnusedCapacity(gpa, capacity);
3249 try pp.expansion_entries.ensureUnusedCapacity(gpa, capacity);
3221}3250}
32223251
3223/// Handle a pragma directive3252/// Handle a pragma directive
...@@ -3285,10 +3314,11 @@ fn findIncludeFilenameToken(...@@ -3285,10 +3314,11 @@ fn findIncludeFilenameToken(
3285 const filename_tok, const expanded_trailing = switch (source_tok.id) {3314 const filename_tok, const expanded_trailing = switch (source_tok.id) {
3286 .string_literal, .macro_string => .{ source_tok, false },3315 .string_literal, .macro_string => .{ source_tok, false },
3287 else => expanded: {3316 else => expanded: {
3317 const gpa = pp.comp.gpa;
3288 // Try to expand if the argument is a macro.3318 // Try to expand if the argument is a macro.
3289 pp.top_expansion_buf.items.len = 0;3319 pp.top_expansion_buf.items.len = 0;
3290 defer for (pp.top_expansion_buf.items) |tok| TokenWithExpansionLocs.free(tok.expansion_locs, pp.gpa);3320 defer for (pp.top_expansion_buf.items) |tok| TokenWithExpansionLocs.free(tok.expansion_locs, gpa);
3291 try pp.top_expansion_buf.append(source_tok);3321 try pp.top_expansion_buf.append(gpa, source_tok);
3292 pp.expansion_source_loc = source_tok.loc;3322 pp.expansion_source_loc = source_tok.loc;
32933323
3294 try pp.expandMacroExhaustive(tokenizer, &pp.top_expansion_buf, 0, 1, true, .non_expr);3324 try pp.expandMacroExhaustive(tokenizer, &pp.top_expansion_buf, 0, 1, true, .non_expr);
...@@ -3298,7 +3328,7 @@ fn findIncludeFilenameToken(...@@ -3298,7 +3328,7 @@ fn findIncludeFilenameToken(
3298 return error.InvalidInclude;3328 return error.InvalidInclude;
3299 };3329 };
3300 const start = pp.comp.generated_buf.items.len;3330 const start = pp.comp.generated_buf.items.len;
3301 try pp.comp.generated_buf.appendSlice(pp.gpa, include_str);3331 try pp.comp.generated_buf.appendSlice(gpa, include_str);
33023332
3303 break :expanded .{ try pp.makeGeneratedToken(start, switch (include_str[0]) {3333 break :expanded .{ try pp.makeGeneratedToken(start, switch (include_str[0]) {
3304 '"' => .string_literal,3334 '"' => .string_literal,
...@@ -3326,7 +3356,7 @@ fn findIncludeFilenameToken(...@@ -3326,7 +3356,7 @@ fn findIncludeFilenameToken(
33263356
3327fn findIncludeSource(pp: *Preprocessor, tokenizer: *Tokenizer, first: RawToken, which: Compilation.WhichInclude) !Source {3357fn findIncludeSource(pp: *Preprocessor, tokenizer: *Tokenizer, first: RawToken, which: Compilation.WhichInclude) !Source {
3328 const filename_tok = try pp.findIncludeFilenameToken(first, tokenizer, .expect_nl_eof);3358 const filename_tok = try pp.findIncludeFilenameToken(first, tokenizer, .expect_nl_eof);
3329 defer TokenWithExpansionLocs.free(filename_tok.expansion_locs, pp.gpa);3359 defer TokenWithExpansionLocs.free(filename_tok.expansion_locs, pp.comp.gpa);
33303360
3331 // Check for empty filename.3361 // Check for empty filename.
3332 const tok_slice = pp.expandedSliceExtra(filename_tok, .single_macro_ws);3362 const tok_slice = pp.expandedSliceExtra(filename_tok, .single_macro_ws);
...@@ -3650,7 +3680,7 @@ test "destringify" {...@@ -3650,7 +3680,7 @@ test "destringify" {
3650 const Test = struct {3680 const Test = struct {
3651 fn testDestringify(pp: *Preprocessor, stringified: []const u8, destringified: []const u8) !void {3681 fn testDestringify(pp: *Preprocessor, stringified: []const u8, destringified: []const u8) !void {
3652 pp.char_buf.clearRetainingCapacity();3682 pp.char_buf.clearRetainingCapacity();
3653 try pp.char_buf.ensureUnusedCapacity(stringified.len);3683 try pp.char_buf.ensureUnusedCapacity(gpa, stringified.len);
3654 pp.destringify(stringified);3684 pp.destringify(stringified);
3655 try std.testing.expectEqualStrings(destringified, pp.char_buf.items);3685 try std.testing.expectEqualStrings(destringified, pp.char_buf.items);
3656 }3686 }
...@@ -3730,18 +3760,18 @@ test "Include guards" {...@@ -3730,18 +3760,18 @@ test "Include guards" {
37303760
3731 _ = try comp.addSourceFromBuffer(path, "int bar = 5;\n");3761 _ = try comp.addSourceFromBuffer(path, "int bar = 5;\n");
37323762
3733 var buf = std.array_list.Managed(u8).init(gpa);3763 var buf: std.ArrayList(u8) = .empty;
3734 defer buf.deinit();3764 defer buf.deinit(gpa);
37353765
3736 switch (tok_id) {3766 switch (tok_id) {
3737 .keyword_include, .keyword_include_next => try buf.print(template, .{ tok_id.lexeme().?, " \"bar.h\"" }),3767 .keyword_include, .keyword_include_next => try buf.print(gpa, template, .{ tok_id.lexeme().?, " \"bar.h\"" }),
3738 .keyword_define, .keyword_undef => try buf.print(template, .{ tok_id.lexeme().?, " BAR" }),3768 .keyword_define, .keyword_undef => try buf.print(gpa, template, .{ tok_id.lexeme().?, " BAR" }),
3739 .keyword_ifndef,3769 .keyword_ifndef,
3740 .keyword_ifdef,3770 .keyword_ifdef,
3741 .keyword_elifdef,3771 .keyword_elifdef,
3742 .keyword_elifndef,3772 .keyword_elifndef,
3743 => try buf.print(template, .{ tok_id.lexeme().?, " BAR\n#endif" }),3773 => try buf.print(gpa, template, .{ tok_id.lexeme().?, " BAR\n#endif" }),
3744 else => try buf.print(template, .{ tok_id.lexeme().?, "" }),3774 else => try buf.print(gpa, template, .{ tok_id.lexeme().?, "" }),
3745 }3775 }
3746 const source = try comp.addSourceFromBuffer("test.h", buf.items);3776 const source = try comp.addSourceFromBuffer("test.h", buf.items);
3747 _ = try pp.preprocess(source);3777 _ = try pp.preprocess(source);
lib/compiler/aro/aro/Preprocessor/Diagnostic.zig+9
...@@ -10,6 +10,7 @@ fmt: []const u8,...@@ -10,6 +10,7 @@ fmt: []const u8,
10kind: Diagnostics.Message.Kind,10kind: Diagnostics.Message.Kind,
11opt: ?Diagnostics.Option = null,11opt: ?Diagnostics.Option = null,
12extension: bool = false,12extension: bool = false,
13show_in_system_headers: bool = false,
1314
14pub const elif_without_if: Diagnostic = .{15pub const elif_without_if: Diagnostic = .{
15 .fmt = "#elif without #if",16 .fmt = "#elif without #if",
...@@ -91,6 +92,7 @@ pub const warning_directive: Diagnostic = .{...@@ -91,6 +92,7 @@ pub const warning_directive: Diagnostic = .{
91 .fmt = "{s}",92 .fmt = "{s}",
92 .opt = .@"#warnings",93 .opt = .@"#warnings",
93 .kind = .warning,94 .kind = .warning,
95 .show_in_system_headers = true,
94};96};
9597
96pub const macro_name_missing: Diagnostic = .{98pub const macro_name_missing: Diagnostic = .{
...@@ -440,3 +442,10 @@ pub const invalid_source_epoch: Diagnostic = .{...@@ -440,3 +442,10 @@ pub const invalid_source_epoch: Diagnostic = .{
440 .fmt = "environment variable SOURCE_DATE_EPOCH must expand to a non-negative integer less than or equal to 253402300799",442 .fmt = "environment variable SOURCE_DATE_EPOCH must expand to a non-negative integer less than or equal to 253402300799",
441 .kind = .@"error",443 .kind = .@"error",
442};444};
445
446pub const date_time: Diagnostic = .{
447 .fmt = "expansion of date or time macro is not reproducible",
448 .kind = .off,
449 .opt = .@"date-time",
450 .show_in_system_headers = true,
451};
lib/compiler/aro/aro/Source.zig+2
...@@ -38,6 +38,7 @@ pub const ExpandedLocation = struct {...@@ -38,6 +38,7 @@ pub const ExpandedLocation = struct {
38 col: u32,38 col: u32,
39 width: u32,39 width: u32,
40 end_with_splice: bool,40 end_with_splice: bool,
41 kind: Kind,
41};42};
4243
43const Source = @This();44const Source = @This();
...@@ -120,6 +121,7 @@ pub fn lineCol(source: Source, loc: Location) ExpandedLocation {...@@ -120,6 +121,7 @@ pub fn lineCol(source: Source, loc: Location) ExpandedLocation {
120 .col = col,121 .col = col,
121 .width = width,122 .width = width,
122 .end_with_splice = end_with_splice,123 .end_with_splice = end_with_splice,
124 .kind = source.kind,
123 };125 };
124}126}
125127
lib/compiler/aro/aro/SymbolStack.zig+10-10
...@@ -35,14 +35,14 @@ pub const Kind = enum {...@@ -35,14 +35,14 @@ pub const Kind = enum {
35 constexpr,35 constexpr,
36};36};
3737
38scopes: std.ArrayListUnmanaged(Scope) = .{},38scopes: std.ArrayList(Scope) = .empty,
39/// allocations from nested scopes are retained after popping; `active_len` is the number39/// allocations from nested scopes are retained after popping; `active_len` is the number
40/// of currently-active items in `scopes`.40/// of currently-active items in `scopes`.
41active_len: usize = 0,41active_len: usize = 0,
4242
43const Scope = struct {43const Scope = struct {
44 vars: std.AutoHashMapUnmanaged(StringId, Symbol) = .{},44 vars: std.AutoHashMapUnmanaged(StringId, Symbol) = .empty,
45 tags: std.AutoHashMapUnmanaged(StringId, Symbol) = .{},45 tags: std.AutoHashMapUnmanaged(StringId, Symbol) = .empty,
4646
47 fn deinit(self: *Scope, allocator: Allocator) void {47 fn deinit(self: *Scope, allocator: Allocator) void {
48 self.vars.deinit(allocator);48 self.vars.deinit(allocator);
...@@ -66,7 +66,7 @@ pub fn deinit(s: *SymbolStack, gpa: Allocator) void {...@@ -66,7 +66,7 @@ pub fn deinit(s: *SymbolStack, gpa: Allocator) void {
6666
67pub fn pushScope(s: *SymbolStack, p: *Parser) !void {67pub fn pushScope(s: *SymbolStack, p: *Parser) !void {
68 if (s.active_len + 1 > s.scopes.items.len) {68 if (s.active_len + 1 > s.scopes.items.len) {
69 try s.scopes.append(p.gpa, .{});69 try s.scopes.append(p.comp.gpa, .{});
70 s.active_len = s.scopes.items.len;70 s.active_len = s.scopes.items.len;
71 } else {71 } else {
72 s.scopes.items[s.active_len].clearRetainingCapacity();72 s.scopes.items[s.active_len].clearRetainingCapacity();
...@@ -195,7 +195,7 @@ pub fn defineTypedef(...@@ -195,7 +195,7 @@ pub fn defineTypedef(
195 else => unreachable,195 else => unreachable,
196 }196 }
197 }197 }
198 try s.define(p.gpa, .{198 try s.define(p.comp.gpa, .{
199 .kind = .typedef,199 .kind = .typedef,
200 .name = name,200 .name = name,
201 .tok = tok,201 .tok = tok,
...@@ -245,7 +245,7 @@ pub fn defineSymbol(...@@ -245,7 +245,7 @@ pub fn defineSymbol(
245 }245 }
246 }246 }
247247
248 try s.define(p.gpa, .{248 try s.define(p.comp.gpa, .{
249 .kind = if (constexpr) .constexpr else .def,249 .kind = if (constexpr) .constexpr else .def,
250 .name = name,250 .name = name,
251 .tok = tok,251 .tok = tok,
...@@ -306,7 +306,7 @@ pub fn declareSymbol(...@@ -306,7 +306,7 @@ pub fn declareSymbol(
306 else => unreachable,306 else => unreachable,
307 }307 }
308 }308 }
309 try s.define(p.gpa, .{309 try s.define(p.comp.gpa, .{
310 .kind = .decl,310 .kind = .decl,
311 .name = name,311 .name = name,
312 .tok = tok,312 .tok = tok,
...@@ -317,7 +317,7 @@ pub fn declareSymbol(...@@ -317,7 +317,7 @@ pub fn declareSymbol(
317317
318 // Declare out of scope symbol for functions declared in functions.318 // Declare out of scope symbol for functions declared in functions.
319 if (s.active_len > 1 and !p.comp.langopts.standard.atLeast(.c23) and qt.is(p.comp, .func)) {319 if (s.active_len > 1 and !p.comp.langopts.standard.atLeast(.c23) and qt.is(p.comp, .func)) {
320 try s.scopes.items[0].vars.put(p.gpa, name, .{320 try s.scopes.items[0].vars.put(p.comp.gpa, name, .{
321 .kind = .decl,321 .kind = .decl,
322 .name = name,322 .name = name,
323 .tok = tok,323 .tok = tok,
...@@ -352,7 +352,7 @@ pub fn defineParam(...@@ -352,7 +352,7 @@ pub fn defineParam(
352 else => unreachable,352 else => unreachable,
353 }353 }
354 }354 }
355 try s.define(p.gpa, .{355 try s.define(p.comp.gpa, .{
356 .kind = .def,356 .kind = .def,
357 .name = name,357 .name = name,
358 .tok = tok,358 .tok = tok,
...@@ -424,7 +424,7 @@ pub fn defineEnumeration(...@@ -424,7 +424,7 @@ pub fn defineEnumeration(
424 else => unreachable,424 else => unreachable,
425 }425 }
426 }426 }
427 try s.define(p.gpa, .{427 try s.define(p.comp.gpa, .{
428 .kind = .enumeration,428 .kind = .enumeration,
429 .name = name,429 .name = name,
430 .tok = tok,430 .tok = tok,
lib/compiler/aro/aro/Toolchain.zig+40-38
...@@ -9,7 +9,7 @@ const Filesystem = @import("Driver/Filesystem.zig").Filesystem;...@@ -9,7 +9,7 @@ const Filesystem = @import("Driver/Filesystem.zig").Filesystem;
9const Multilib = @import("Driver/Multilib.zig");9const Multilib = @import("Driver/Multilib.zig");
10const target_util = @import("target.zig");10const target_util = @import("target.zig");
1111
12pub const PathList = std.ArrayListUnmanaged([]const u8);12pub const PathList = std.ArrayList([]const u8);
1313
14pub const RuntimeLibKind = enum {14pub const RuntimeLibKind = enum {
15 compiler_rt,15 compiler_rt,
...@@ -64,7 +64,6 @@ pub fn getTarget(tc: *const Toolchain) std.Target {...@@ -64,7 +64,6 @@ pub fn getTarget(tc: *const Toolchain) std.Target {
64fn getDefaultLinker(tc: *const Toolchain) []const u8 {64fn getDefaultLinker(tc: *const Toolchain) []const u8 {
65 return switch (tc.inner) {65 return switch (tc.inner) {
66 .uninitialized => unreachable,66 .uninitialized => unreachable,
67 .linux => |linux| linux.getDefaultLinker(tc.getTarget()),
68 .unknown => "ld",67 .unknown => "ld",
69 };68 };
70}69}
...@@ -72,6 +71,7 @@ fn getDefaultLinker(tc: *const Toolchain) []const u8 {...@@ -72,6 +71,7 @@ fn getDefaultLinker(tc: *const Toolchain) []const u8 {
72/// Call this after driver has finished parsing command line arguments to find the toolchain71/// Call this after driver has finished parsing command line arguments to find the toolchain
73pub fn discover(tc: *Toolchain) !void {72pub fn discover(tc: *Toolchain) !void {
74 if (tc.inner != .uninitialized) return;73 if (tc.inner != .uninitialized) return;
74
75 tc.inner = .unknown;75 tc.inner = .unknown;
76 return switch (tc.inner) {76 return switch (tc.inner) {
77 .uninitialized => unreachable,77 .uninitialized => unreachable,
...@@ -143,8 +143,11 @@ pub fn getLinkerPath(tc: *const Toolchain, buf: []u8) ![]const u8 {...@@ -143,8 +143,11 @@ pub fn getLinkerPath(tc: *const Toolchain, buf: []u8) ![]const u8 {
143 return use_linker;143 return use_linker;
144 }144 }
145 } else {145 } else {
146 var linker_name = try std.array_list.Managed(u8).initCapacity(tc.driver.comp.gpa, 5 + use_linker.len); // "ld64." ++ use_linker146 const gpa = tc.driver.comp.gpa;
147 defer linker_name.deinit();147 var linker_name: std.ArrayList(u8) = .empty;
148 defer linker_name.deinit(gpa);
149 try linker_name.ensureUnusedCapacity(tc.driver.comp.gpa, 5 + use_linker.len); // "ld64." ++ use_linker
150
148 if (tc.getTarget().os.tag.isDarwin()) {151 if (tc.getTarget().os.tag.isDarwin()) {
149 linker_name.appendSliceAssumeCapacity("ld64.");152 linker_name.appendSliceAssumeCapacity("ld64.");
150 } else {153 } else {
...@@ -171,20 +174,27 @@ pub fn getLinkerPath(tc: *const Toolchain, buf: []u8) ![]const u8 {...@@ -171,20 +174,27 @@ pub fn getLinkerPath(tc: *const Toolchain, buf: []u8) ![]const u8 {
171/// TODO: this isn't exactly right since our target names don't necessarily match up174/// TODO: this isn't exactly right since our target names don't necessarily match up
172/// with GCC's.175/// with GCC's.
173/// For example the Zig target `arm-freestanding-eabi` would need the `arm-none-eabi` tools176/// For example the Zig target `arm-freestanding-eabi` would need the `arm-none-eabi` tools
174fn possibleProgramNames(raw_triple: ?[]const u8, name: []const u8, buf: *[64]u8, possible_names: *std.ArrayListUnmanaged([]const u8)) void {177fn possibleProgramNames(
178 raw_triple: ?[]const u8,
179 name: []const u8,
180 buf: *[64]u8,
181 possible_name_buf: *[2][]const u8,
182) []const []const u8 {
183 var i: u32 = 0;
175 if (raw_triple) |triple| {184 if (raw_triple) |triple| {
176 if (std.fmt.bufPrint(buf, "{s}-{s}", .{ triple, name })) |res| {185 if (std.fmt.bufPrint(buf, "{s}-{s}", .{ triple, name })) |res| {
177 possible_names.appendAssumeCapacity(res);186 possible_name_buf[i] = res;
187 i += 1;
178 } else |_| {}188 } else |_| {}
179 }189 }
180 possible_names.appendAssumeCapacity(name);190 possible_name_buf[i] = name;
181191
182 return possible_names;192 return possible_name_buf[0..i];
183}193}
184194
185/// Add toolchain `file_paths` to argv as `-L` arguments195/// Add toolchain `file_paths` to argv as `-L` arguments
186pub fn addFilePathLibArgs(tc: *const Toolchain, argv: *std.array_list.Managed([]const u8)) !void {196pub fn addFilePathLibArgs(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !void {
187 try argv.ensureUnusedCapacity(tc.file_paths.items.len);197 try argv.ensureUnusedCapacity(tc.driver.comp.gpa, tc.file_paths.items.len);
188198
189 var bytes_needed: usize = 0;199 var bytes_needed: usize = 0;
190 for (tc.file_paths.items) |path| {200 for (tc.file_paths.items) |path| {
...@@ -208,11 +218,10 @@ fn getProgramPath(tc: *const Toolchain, name: []const u8, buf: []u8) []const u8...@@ -208,11 +218,10 @@ fn getProgramPath(tc: *const Toolchain, name: []const u8, buf: []u8) []const u8
208 var fib = std.heap.FixedBufferAllocator.init(&path_buf);218 var fib = std.heap.FixedBufferAllocator.init(&path_buf);
209219
210 var tool_specific_buf: [64]u8 = undefined;220 var tool_specific_buf: [64]u8 = undefined;
211 var possible_names_buffer: [2][]const u8 = undefined;221 var possible_name_buf: [2][]const u8 = undefined;
212 var possible_names = std.ArrayListUnmanaged.initBuffer(&possible_names_buffer);222 const possible_names = possibleProgramNames(tc.driver.raw_target_triple, name, &tool_specific_buf, &possible_name_buf);
213 possibleProgramNames(tc.driver.raw_target_triple, name, &tool_specific_buf, &possible_names);
214223
215 for (possible_names.items) |tool_name| {224 for (possible_names) |tool_name| {
216 for (tc.program_paths.items) |program_path| {225 for (tc.program_paths.items) |program_path| {
217 defer fib.reset();226 defer fib.reset();
218227
...@@ -318,16 +327,6 @@ pub fn addPathFromComponents(tc: *Toolchain, components: []const []const u8, des...@@ -318,16 +327,6 @@ pub fn addPathFromComponents(tc: *Toolchain, components: []const []const u8, des
318 try dest.append(tc.driver.comp.gpa, full_path);327 try dest.append(tc.driver.comp.gpa, full_path);
319}328}
320329
321/// Add linker args to `argv`. Does not add path to linker executable as first item; that must be handled separately
322/// Items added to `argv` will be string literals or owned by `tc.driver.comp.arena` so they must not be individually freed
323pub fn buildLinkerArgs(tc: *Toolchain, argv: *std.array_list.Managed([]const u8)) !void {
324 return switch (tc.inner) {
325 .uninitialized => unreachable,
326 .linux => |*linux| linux.buildLinkerArgs(tc, argv),
327 .unknown => @panic("This toolchain does not support linking yet"),
328 };
329}
330
331fn getDefaultRuntimeLibKind(tc: *const Toolchain) RuntimeLibKind {330fn getDefaultRuntimeLibKind(tc: *const Toolchain) RuntimeLibKind {
332 if (tc.getTarget().abi.isAndroid()) {331 if (tc.getTarget().abi.isAndroid()) {
333 return .compiler_rt;332 return .compiler_rt;
...@@ -400,7 +399,7 @@ fn getAsNeededOption(is_solaris: bool, needed: bool) []const u8 {...@@ -400,7 +399,7 @@ fn getAsNeededOption(is_solaris: bool, needed: bool) []const u8 {
400 }399 }
401}400}
402401
403fn addUnwindLibrary(tc: *const Toolchain, argv: *std.array_list.Managed([]const u8)) !void {402fn addUnwindLibrary(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !void {
404 const unw = try tc.getUnwindLibKind();403 const unw = try tc.getUnwindLibKind();
405 const target = tc.getTarget();404 const target = tc.getTarget();
406 if ((target.abi.isAndroid() and unw == .libgcc) or405 if ((target.abi.isAndroid() and unw == .libgcc) or
...@@ -410,46 +409,49 @@ fn addUnwindLibrary(tc: *const Toolchain, argv: *std.array_list.Managed([]const...@@ -410,46 +409,49 @@ fn addUnwindLibrary(tc: *const Toolchain, argv: *std.array_list.Managed([]const
410409
411 const lgk = tc.getLibGCCKind();410 const lgk = tc.getLibGCCKind();
412 const as_needed = lgk == .unspecified and !target.abi.isAndroid() and !target_util.isCygwinMinGW(target) and target.os.tag != .aix;411 const as_needed = lgk == .unspecified and !target.abi.isAndroid() and !target_util.isCygwinMinGW(target) and target.os.tag != .aix;
412
413 try argv.ensureUnusedCapacity(tc.driver.comp.gpa, 3);
413 if (as_needed) {414 if (as_needed) {
414 try argv.append(getAsNeededOption(target.os.tag == .solaris, true));415 argv.appendAssumeCapacity(getAsNeededOption(target.os.tag == .solaris, true));
415 }416 }
416 switch (unw) {417 switch (unw) {
417 .none => return,418 .none => return,
418 .libgcc => if (lgk == .static) try argv.append("-lgcc_eh") else try argv.append("-lgcc_s"),419 .libgcc => argv.appendAssumeCapacity(if (lgk == .static) "-lgcc_eh" else "-lgcc_s"),
419 .compiler_rt => if (target.os.tag == .aix) {420 .compiler_rt => if (target.os.tag == .aix) {
420 if (lgk != .static) {421 if (lgk != .static) {
421 try argv.append("-lunwind");422 argv.appendAssumeCapacity("-lunwind");
422 }423 }
423 } else if (lgk == .static) {424 } else if (lgk == .static) {
424 try argv.append("-l:libunwind.a");425 argv.appendAssumeCapacity("-l:libunwind.a");
425 } else if (lgk == .shared) {426 } else if (lgk == .shared) {
426 if (target_util.isCygwinMinGW(target)) {427 if (target_util.isCygwinMinGW(target)) {
427 try argv.append("-l:libunwind.dll.a");428 argv.appendAssumeCapacity("-l:libunwind.dll.a");
428 } else {429 } else {
429 try argv.append("-l:libunwind.so");430 argv.appendAssumeCapacity("-l:libunwind.so");
430 }431 }
431 } else {432 } else {
432 try argv.append("-lunwind");433 argv.appendAssumeCapacity("-lunwind");
433 },434 },
434 }435 }
435436
436 if (as_needed) {437 if (as_needed) {
437 try argv.append(getAsNeededOption(target.os.tag == .solaris, false));438 argv.appendAssumeCapacity(getAsNeededOption(target.os.tag == .solaris, false));
438 }439 }
439}440}
440441
441fn addLibGCC(tc: *const Toolchain, argv: *std.array_list.Managed([]const u8)) !void {442fn addLibGCC(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !void {
443 const gpa = tc.driver.comp.gpa;
442 const libgcc_kind = tc.getLibGCCKind();444 const libgcc_kind = tc.getLibGCCKind();
443 if (libgcc_kind == .static or libgcc_kind == .unspecified) {445 if (libgcc_kind == .static or libgcc_kind == .unspecified) {
444 try argv.append("-lgcc");446 try argv.append(gpa, "-lgcc");
445 }447 }
446 try tc.addUnwindLibrary(argv);448 try tc.addUnwindLibrary(argv);
447 if (libgcc_kind == .shared) {449 if (libgcc_kind == .shared) {
448 try argv.append("-lgcc");450 try argv.append(gpa, "-lgcc");
449 }451 }
450}452}
451453
452pub fn addRuntimeLibs(tc: *const Toolchain, argv: *std.array_list.Managed([]const u8)) !void {454pub fn addRuntimeLibs(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !void {
453 const target = tc.getTarget();455 const target = tc.getTarget();
454 const rlt = tc.getRuntimeLibKind();456 const rlt = tc.getRuntimeLibKind();
455 switch (rlt) {457 switch (rlt) {
...@@ -469,7 +471,7 @@ pub fn addRuntimeLibs(tc: *const Toolchain, argv: *std.array_list.Managed([]cons...@@ -469,7 +471,7 @@ pub fn addRuntimeLibs(tc: *const Toolchain, argv: *std.array_list.Managed([]cons
469 }471 }
470472
471 if (target.abi.isAndroid() and !tc.driver.static and !tc.driver.static_pie) {473 if (target.abi.isAndroid() and !tc.driver.static and !tc.driver.static_pie) {
472 try argv.append("-ldl");474 try argv.append(tc.driver.comp.gpa, "-ldl");
473 }475 }
474}476}
475477
lib/compiler/aro/aro/Tree.zig+4-4
...@@ -42,7 +42,7 @@ pub const TokenWithExpansionLocs = struct {...@@ -42,7 +42,7 @@ pub const TokenWithExpansionLocs = struct {
4242
43 pub fn addExpansionLocation(tok: *TokenWithExpansionLocs, gpa: std.mem.Allocator, new: []const Source.Location) !void {43 pub fn addExpansionLocation(tok: *TokenWithExpansionLocs, gpa: std.mem.Allocator, new: []const Source.Location) !void {
44 if (new.len == 0 or tok.id == .whitespace or tok.id == .macro_ws or tok.id == .placemarker) return;44 if (new.len == 0 or tok.id == .whitespace or tok.id == .macro_ws or tok.id == .placemarker) return;
45 var list = std.array_list.Managed(Source.Location).init(gpa);45 var list: std.ArrayList(Source.Location) = .empty;
46 defer {46 defer {
47 @memset(list.items.ptr[list.items.len..list.capacity], .{});47 @memset(list.items.ptr[list.items.len..list.capacity], .{});
48 // Add a sentinel to indicate the end of the list since48 // Add a sentinel to indicate the end of the list since
...@@ -65,7 +65,7 @@ pub const TokenWithExpansionLocs = struct {...@@ -65,7 +65,7 @@ pub const TokenWithExpansionLocs = struct {
65 const min_len = @max(list.items.len + new.len + 1, 4);65 const min_len = @max(list.items.len + new.len + 1, 4);
66 const wanted_len = std.math.ceilPowerOfTwo(usize, min_len) catch66 const wanted_len = std.math.ceilPowerOfTwo(usize, min_len) catch
67 return error.OutOfMemory;67 return error.OutOfMemory;
68 try list.ensureTotalCapacity(wanted_len);68 try list.ensureTotalCapacity(gpa, wanted_len);
6969
70 for (new) |new_loc| {70 for (new) |new_loc| {
71 if (new_loc.id == .generated) continue;71 if (new_loc.id == .generated) continue;
...@@ -119,8 +119,8 @@ tokens: Token.List.Slice,...@@ -119,8 +119,8 @@ tokens: Token.List.Slice,
119119
120// Values owned by this Tree120// Values owned by this Tree
121nodes: std.MultiArrayList(Node.Repr) = .empty,121nodes: std.MultiArrayList(Node.Repr) = .empty,
122extra: std.ArrayListUnmanaged(u32) = .empty,122extra: std.ArrayList(u32) = .empty,
123root_decls: std.ArrayListUnmanaged(Node.Index) = .empty,123root_decls: std.ArrayList(Node.Index) = .empty,
124value_map: ValueMap = .empty,124value_map: ValueMap = .empty,
125125
126pub const genIr = CodeGen.genIr;126pub const genIr = CodeGen.genIr;
lib/compiler/aro/aro/TypeStore.zig+13-13
...@@ -1216,6 +1216,13 @@ pub const QualType = packed struct(u32) {...@@ -1216,6 +1216,13 @@ pub const QualType = packed struct(u32) {
1216 return false;1216 return false;
1217 },1217 },
1218 .array => |array| {1218 .array => |array| {
1219 if (qt.@"const") {
1220 try w.writeAll("const ");
1221 }
1222 if (qt.@"volatile") {
1223 try w.writeAll("volatile");
1224 }
1225
1219 const simple = try array.elem.printPrologue(comp, desugar, w);1226 const simple = try array.elem.printPrologue(comp, desugar, w);
1220 if (simple) try w.writeByte(' ');1227 if (simple) try w.writeByte(' ');
1221 return false;1228 return false;
...@@ -1341,14 +1348,6 @@ pub const QualType = packed struct(u32) {...@@ -1341,14 +1348,6 @@ pub const QualType = packed struct(u32) {
13411348
1342 const static = array.len == .static;1349 const static = array.len == .static;
1343 if (static) try w.writeAll("static");1350 if (static) try w.writeAll("static");
1344 if (qt.@"const") {
1345 if (static) try w.writeByte(' ');
1346 try w.writeAll("const");
1347 }
1348 if (qt.@"volatile") {
1349 if (static or qt.@"const") try w.writeByte(' ');
1350 try w.writeAll("volatile");
1351 }
1352 if (qt.restrict) {1351 if (qt.restrict) {
1353 if (static or qt.@"const" or qt.@"volatile") try w.writeByte(' ');1352 if (static or qt.@"const" or qt.@"volatile") try w.writeByte(' ');
1354 try w.writeAll("restrict");1353 try w.writeAll("restrict");
...@@ -1694,8 +1693,8 @@ pub const Type = union(enum) {...@@ -1694,8 +1693,8 @@ pub const Type = union(enum) {
1694};1693};
16951694
1696types: std.MultiArrayList(Repr) = .empty,1695types: std.MultiArrayList(Repr) = .empty,
1697extra: std.ArrayListUnmanaged(u32) = .empty,1696extra: std.ArrayList(u32) = .empty,
1698attributes: std.ArrayListUnmanaged(Attribute) = .empty,1697attributes: std.ArrayList(Attribute) = .empty,
1699anon_name_arena: std.heap.ArenaAllocator.State = .{},1698anon_name_arena: std.heap.ArenaAllocator.State = .{},
17001699
1701wchar: QualType = .invalid,1700wchar: QualType = .invalid,
...@@ -2435,7 +2434,7 @@ pub const Builder = struct {...@@ -2435,7 +2434,7 @@ pub const Builder = struct {
2435 }2434 }
2436 if (b.complex_tok) |tok| try b.parser.err(tok, .complex_int, .{});2435 if (b.complex_tok) |tok| try b.parser.err(tok, .complex_int, .{});
24372436
2438 const qt = try b.parser.comp.type_store.put(b.parser.gpa, .{ .bit_int = .{2437 const qt = try b.parser.comp.type_store.put(b.parser.comp.gpa, .{ .bit_int = .{
2439 .signedness = if (unsigned) .unsigned else .signed,2438 .signedness = if (unsigned) .unsigned else .signed,
2440 .bits = @intCast(bits),2439 .bits = @intCast(bits),
2441 } });2440 } });
...@@ -2476,6 +2475,7 @@ pub const Builder = struct {...@@ -2476,6 +2475,7 @@ pub const Builder = struct {
24762475
2477 pub fn finishQuals(b: Builder, qt: QualType) !QualType {2476 pub fn finishQuals(b: Builder, qt: QualType) !QualType {
2478 if (qt.isInvalid()) return .invalid;2477 if (qt.isInvalid()) return .invalid;
2478 const gpa = b.parser.comp.gpa;
2479 var result_qt = qt;2479 var result_qt = qt;
2480 if (b.atomic_type orelse b.atomic) |atomic_tok| {2480 if (b.atomic_type orelse b.atomic) |atomic_tok| {
2481 if (result_qt.isAutoType()) return b.parser.todo("_Atomic __auto_type");2481 if (result_qt.isAutoType()) return b.parser.todo("_Atomic __auto_type");
...@@ -2505,7 +2505,7 @@ pub const Builder = struct {...@@ -2505,7 +2505,7 @@ pub const Builder = struct {
2505 return .invalid;2505 return .invalid;
2506 },2506 },
2507 else => {2507 else => {
2508 result_qt = try b.parser.comp.type_store.put(b.parser.gpa, .{ .atomic = result_qt });2508 result_qt = try b.parser.comp.type_store.put(gpa, .{ .atomic = result_qt });
2509 },2509 },
2510 }2510 }
2511 }2511 }
...@@ -2514,7 +2514,7 @@ pub const Builder = struct {...@@ -2514,7 +2514,7 @@ pub const Builder = struct {
2514 const is_pointer = qt.isAutoType() or qt.isC23Auto() or qt.base(b.parser.comp).type == .pointer;2514 const is_pointer = qt.isAutoType() or qt.isC23Auto() or qt.base(b.parser.comp).type == .pointer;
25152515
2516 if (b.unaligned != null and !is_pointer) {2516 if (b.unaligned != null and !is_pointer) {
2517 result_qt = (try b.parser.comp.type_store.put(b.parser.gpa, .{ .attributed = .{2517 result_qt = (try b.parser.comp.type_store.put(gpa, .{ .attributed = .{
2518 .base = result_qt,2518 .base = result_qt,
2519 .attributes = &.{.{ .tag = .unaligned, .args = .{ .unaligned = .{} }, .syntax = .keyword }},2519 .attributes = &.{.{ .tag = .unaligned, .args = .{ .unaligned = .{} }, .syntax = .keyword }},
2520 } })).withQualifiers(result_qt);2520 } })).withQualifiers(result_qt);
lib/compiler/aro/aro/pragmas/gcc.zig+2-2
...@@ -20,7 +20,7 @@ pragma: Pragma = .{...@@ -20,7 +20,7 @@ pragma: Pragma = .{
20 .preserveTokens = preserveTokens,20 .preserveTokens = preserveTokens,
21},21},
22original_state: Diagnostics.State = .{},22original_state: Diagnostics.State = .{},
23state_stack: std.ArrayListUnmanaged(Diagnostics.State) = .{},23state_stack: std.ArrayList(Diagnostics.State) = .empty,
2424
25const Directive = enum {25const Directive = enum {
26 warning,26 warning,
...@@ -138,7 +138,7 @@ fn preprocessorHandler(pragma: *Pragma, pp: *Preprocessor, start_idx: TokenIndex...@@ -138,7 +138,7 @@ fn preprocessorHandler(pragma: *Pragma, pp: *Preprocessor, start_idx: TokenIndex
138 if (pp.defines.get(str) != null) {138 if (pp.defines.get(str) != null) {
139 try Pragma.err(pp, start_idx + i, .pragma_poison_macro, .{});139 try Pragma.err(pp, start_idx + i, .pragma_poison_macro, .{});
140 }140 }
141 try pp.poisoned_identifiers.put(str, {});141 try pp.poisoned_identifiers.put(pp.comp.gpa, str, {});
142 }142 }
143 return;143 return;
144 },144 },
lib/compiler/aro/aro/pragmas/message.zig+1-1
...@@ -44,7 +44,7 @@ fn preprocessorHandler(_: *Pragma, pp: *Preprocessor, start_idx: TokenIndex) Pra...@@ -44,7 +44,7 @@ fn preprocessorHandler(_: *Pragma, pp: *Preprocessor, start_idx: TokenIndex) Pra
4444
45 const diagnostic: Pragma.Diagnostic = .pragma_message;45 const diagnostic: Pragma.Diagnostic = .pragma_message;
4646
47 var sf = std.heap.stackFallback(1024, pp.gpa);47 var sf = std.heap.stackFallback(1024, pp.comp.gpa);
48 var allocating: std.Io.Writer.Allocating = .init(sf.get());48 var allocating: std.Io.Writer.Allocating = .init(sf.get());
49 defer allocating.deinit();49 defer allocating.deinit();
5050
lib/compiler/aro/aro/pragmas/once.zig+5-6
...@@ -17,14 +17,12 @@ pragma: Pragma = .{...@@ -17,14 +17,12 @@ pragma: Pragma = .{
17 .preprocessorHandler = preprocessorHandler,17 .preprocessorHandler = preprocessorHandler,
18 .preserveTokens = preserveTokens,18 .preserveTokens = preserveTokens,
19},19},
20pragma_once: std.AutoHashMap(Source.Id, void),20pragma_once: std.AutoHashMapUnmanaged(Source.Id, void) = .empty,
21preprocess_count: u32 = 0,21preprocess_count: u32 = 0,
2222
23pub fn init(allocator: mem.Allocator) !*Pragma {23pub fn init(allocator: mem.Allocator) !*Pragma {
24 var once = try allocator.create(Once);24 var once = try allocator.create(Once);
25 once.* = .{25 once.* = .{};
26 .pragma_once = std.AutoHashMap(Source.Id, void).init(allocator),
27 };
28 return &once.pragma;26 return &once.pragma;
29}27}
3028
...@@ -35,8 +33,9 @@ fn afterParse(pragma: *Pragma, _: *Compilation) void {...@@ -35,8 +33,9 @@ fn afterParse(pragma: *Pragma, _: *Compilation) void {
3533
36fn deinit(pragma: *Pragma, comp: *Compilation) void {34fn deinit(pragma: *Pragma, comp: *Compilation) void {
37 var self: *Once = @fieldParentPtr("pragma", pragma);35 var self: *Once = @fieldParentPtr("pragma", pragma);
38 self.pragma_once.deinit();36 self.pragma_once.deinit(comp.gpa);
39 comp.gpa.destroy(self);37 comp.gpa.destroy(self);
38 pragma.* = undefined;
40}39}
4140
42fn preprocessorHandler(pragma: *Pragma, pp: *Preprocessor, start_idx: TokenIndex) Pragma.Error!void {41fn preprocessorHandler(pragma: *Pragma, pp: *Preprocessor, start_idx: TokenIndex) Pragma.Error!void {
...@@ -53,7 +52,7 @@ fn preprocessorHandler(pragma: *Pragma, pp: *Preprocessor, start_idx: TokenIndex...@@ -53,7 +52,7 @@ fn preprocessorHandler(pragma: *Pragma, pp: *Preprocessor, start_idx: TokenIndex
53 }, pp.expansionSlice(start_idx + 1), true);52 }, pp.expansionSlice(start_idx + 1), true);
54 }53 }
55 const seen = self.preprocess_count == pp.preprocess_count;54 const seen = self.preprocess_count == pp.preprocess_count;
56 const prev = try self.pragma_once.fetchPut(name_tok.loc.id, {});55 const prev = try self.pragma_once.fetchPut(pp.comp.gpa, name_tok.loc.id, {});
57 if (prev != null and !seen) {56 if (prev != null and !seen) {
58 return error.StopPreprocessing;57 return error.StopPreprocessing;
59 }58 }
lib/compiler/aro/aro/pragmas/pack.zig+2-2
...@@ -15,7 +15,7 @@ pragma: Pragma = .{...@@ -15,7 +15,7 @@ pragma: Pragma = .{
15 .deinit = deinit,15 .deinit = deinit,
16 .parserHandler = parserHandler,16 .parserHandler = parserHandler,
17},17},
18stack: std.ArrayListUnmanaged(struct { label: []const u8, val: u8 }) = .{},18stack: std.ArrayList(struct { label: []const u8, val: u8 }) = .empty,
1919
20pub fn init(allocator: mem.Allocator) !*Pragma {20pub fn init(allocator: mem.Allocator) !*Pragma {
21 var pack = try allocator.create(Pack);21 var pack = try allocator.create(Pack);
...@@ -82,7 +82,7 @@ fn parserHandler(pragma: *Pragma, p: *Parser, start_idx: TokenIndex) Compilation...@@ -82,7 +82,7 @@ fn parserHandler(pragma: *Pragma, p: *Parser, start_idx: TokenIndex) Compilation
82 }82 }
83 }83 }
84 if (action == .push) {84 if (action == .push) {
85 try pack.stack.append(p.gpa, .{ .label = label orelse "", .val = p.pragma_pack orelse 8 });85 try pack.stack.append(p.comp.gpa, .{ .label = label orelse "", .val = p.pragma_pack orelse 8 });
86 } else {86 } else {
87 pack.pop(p, label);87 pack.pop(p, label);
88 if (new_val != null) {88 if (new_val != null) {
lib/compiler/aro/assembly_backend/x86_64.zig+5-4
...@@ -70,10 +70,11 @@ pub fn todo(c: *AsmCodeGen, msg: []const u8, tok: Tree.TokenIndex) Error {...@@ -70,10 +70,11 @@ pub fn todo(c: *AsmCodeGen, msg: []const u8, tok: Tree.TokenIndex) Error {
70 const loc: Source.Location = c.tree.tokens.items(.loc)[tok];70 const loc: Source.Location = c.tree.tokens.items(.loc)[tok];
7171
72 var sf = std.heap.stackFallback(1024, c.comp.gpa);72 var sf = std.heap.stackFallback(1024, c.comp.gpa);
73 var buf = std.ArrayList(u8).init(sf.get());73 const allocator = sf.get();
74 defer buf.deinit();74 var buf: std.ArrayList(u8) = .empty;
75 defer buf.deinit(allocator);
7576
76 try buf.print("TODO: {s}", .{msg});77 try buf.print(allocator, "TODO: {s}", .{msg});
77 try c.comp.diagnostics.add(.{78 try c.comp.diagnostics.add(.{
78 .text = buf.items,79 .text = buf.items,
79 .kind = .@"error",80 .kind = .@"error",
...@@ -163,7 +164,7 @@ pub fn genAsm(tree: *const Tree) Error!Assembly {...@@ -163,7 +164,7 @@ pub fn genAsm(tree: *const Tree) Error!Assembly {
163}164}
164165
165fn genDecls(c: *AsmCodeGen) !void {166fn genDecls(c: *AsmCodeGen) !void {
166 if (c.tree.comp.code_gen_options.debug) {167 if (c.tree.comp.code_gen_options.debug != .strip) {
167 const sources = c.tree.comp.sources.values();168 const sources = c.tree.comp.sources.values();
168 for (sources) |source| {169 for (sources) |source| {
169 try c.data.print(" .file {d} \"{s}\"\n", .{ @intFromEnum(source.id) - 1, source.path });170 try c.data.print(" .file {d} \"{s}\"\n", .{ @intFromEnum(source.id) - 1, source.path });
lib/compiler/aro/backend/CodeGenOptions.zig+14
...@@ -66,6 +66,20 @@ pub const OptimizationLevel = enum {...@@ -66,6 +66,20 @@ pub const OptimizationLevel = enum {
66 pub fn fromString(str: []const u8) ?OptimizationLevel {66 pub fn fromString(str: []const u8) ?OptimizationLevel {
67 return level_map.get(str);67 return level_map.get(str);
68 }68 }
69
70 pub fn isSizeOptimized(self: OptimizationLevel) bool {
71 return switch (self) {
72 .s, .z => true,
73 .@"0", .@"1", .@"2", .@"3", .fast, .g => false,
74 };
75 }
76
77 pub fn hasAnyOptimizations(self: OptimizationLevel) bool {
78 return switch (self) {
79 .@"0" => false,
80 .@"1", .@"2", .@"3", .s, .fast, .g, .z => true,
81 };
82 }
69};83};
7084
71pub const default: @This() = .{85pub const default: @This() = .{
lib/compiler/aro/backend/Interner.zig+5-5
...@@ -8,14 +8,14 @@ const Limb = std.math.big.Limb;...@@ -8,14 +8,14 @@ const Limb = std.math.big.Limb;
88
9const Interner = @This();9const Interner = @This();
1010
11map: std.AutoArrayHashMapUnmanaged(void, void) = .{},11map: std.AutoArrayHashMapUnmanaged(void, void) = .empty,
12items: std.MultiArrayList(struct {12items: std.MultiArrayList(struct {
13 tag: Tag,13 tag: Tag,
14 data: u32,14 data: u32,
15}) = .{},15}) = .empty,
16extra: std.ArrayListUnmanaged(u32) = .{},16extra: std.ArrayList(u32) = .empty,
17limbs: std.ArrayListUnmanaged(Limb) = .{},17limbs: std.ArrayList(Limb) = .empty,
18strings: std.ArrayListUnmanaged(u8) = .{},18strings: std.ArrayList(u8) = .empty,
1919
20const KeyAdapter = struct {20const KeyAdapter = struct {
21 interner: *const Interner,21 interner: *const Interner,
lib/compiler/aro/backend/Ir.zig+20-20
...@@ -11,7 +11,7 @@ decls: std.StringArrayHashMapUnmanaged(Decl),...@@ -11,7 +11,7 @@ decls: std.StringArrayHashMapUnmanaged(Decl),
1111
12pub const Decl = struct {12pub const Decl = struct {
13 instructions: std.MultiArrayList(Inst),13 instructions: std.MultiArrayList(Inst),
14 body: std.ArrayListUnmanaged(Ref),14 body: std.ArrayList(Ref),
15 arena: std.heap.ArenaAllocator.State,15 arena: std.heap.ArenaAllocator.State,
1616
17 pub fn deinit(decl: *Decl, gpa: Allocator) void {17 pub fn deinit(decl: *Decl, gpa: Allocator) void {
...@@ -26,9 +26,9 @@ pub const Builder = struct {...@@ -26,9 +26,9 @@ pub const Builder = struct {
26 arena: std.heap.ArenaAllocator,26 arena: std.heap.ArenaAllocator,
27 interner: *Interner,27 interner: *Interner,
2828
29 decls: std.StringArrayHashMapUnmanaged(Decl) = .{},29 decls: std.StringArrayHashMapUnmanaged(Decl) = .empty,
30 instructions: std.MultiArrayList(Ir.Inst) = .{},30 instructions: std.MultiArrayList(Ir.Inst) = .empty,
31 body: std.ArrayListUnmanaged(Ref) = .{},31 body: std.ArrayList(Ref) = .empty,
32 alloc_count: u32 = 0,32 alloc_count: u32 = 0,
33 arg_count: u32 = 0,33 arg_count: u32 = 0,
34 current_label: Ref = undefined,34 current_label: Ref = undefined,
...@@ -380,7 +380,7 @@ const REF = std.Io.tty.Color.bright_blue;...@@ -380,7 +380,7 @@ const REF = std.Io.tty.Color.bright_blue;
380const LITERAL = std.Io.tty.Color.bright_green;380const LITERAL = std.Io.tty.Color.bright_green;
381const ATTRIBUTE = std.Io.tty.Color.bright_yellow;381const ATTRIBUTE = std.Io.tty.Color.bright_yellow;
382382
383const RefMap = std.AutoArrayHashMap(Ref, void);383const RefMap = std.AutoArrayHashMapUnmanaged(Ref, void);
384384
385pub fn dump(ir: *const Ir, gpa: Allocator, config: std.Io.tty.Config, w: *std.Io.Writer) !void {385pub fn dump(ir: *const Ir, gpa: Allocator, config: std.Io.tty.Config, w: *std.Io.Writer) !void {
386 for (ir.decls.keys(), ir.decls.values()) |name, *decl| {386 for (ir.decls.keys(), ir.decls.values()) |name, *decl| {
...@@ -393,11 +393,11 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,...@@ -393,11 +393,11 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,
393 const tags = decl.instructions.items(.tag);393 const tags = decl.instructions.items(.tag);
394 const data = decl.instructions.items(.data);394 const data = decl.instructions.items(.data);
395395
396 var ref_map = RefMap.init(gpa);396 var ref_map: RefMap = .empty;
397 defer ref_map.deinit();397 defer ref_map.deinit(gpa);
398398
399 var label_map = RefMap.init(gpa);399 var label_map: RefMap = .empty;
400 defer label_map.deinit();400 defer label_map.deinit(gpa);
401401
402 const ret_inst = decl.body.items[decl.body.items.len - 1];402 const ret_inst = decl.body.items[decl.body.items.len - 1];
403 const ret_operand = data[@intFromEnum(ret_inst)].un;403 const ret_operand = data[@intFromEnum(ret_inst)].un;
...@@ -413,14 +413,14 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,...@@ -413,14 +413,14 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,
413 const ref = decl.body.items[arg_count];413 const ref = decl.body.items[arg_count];
414 if (tags[@intFromEnum(ref)] != .arg) break;414 if (tags[@intFromEnum(ref)] != .arg) break;
415 if (arg_count != 0) try w.writeAll(", ");415 if (arg_count != 0) try w.writeAll(", ");
416 try ref_map.put(ref, {});416 try ref_map.put(gpa, ref, {});
417 try ir.writeRef(decl, &ref_map, ref, config, w);417 try ir.writeRef(decl, &ref_map, ref, config, w);
418 try config.setColor(w, .reset);418 try config.setColor(w, .reset);
419 }419 }
420 try w.writeAll(") {\n");420 try w.writeAll(") {\n");
421 for (decl.body.items[arg_count..]) |ref| {421 for (decl.body.items[arg_count..]) |ref| {
422 switch (tags[@intFromEnum(ref)]) {422 switch (tags[@intFromEnum(ref)]) {
423 .label => try label_map.put(ref, {}),423 .label => try label_map.put(gpa, ref, {}),
424 else => {},424 else => {},
425 }425 }
426 }426 }
...@@ -461,7 +461,7 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,...@@ -461,7 +461,7 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,
461 },461 },
462 .select => {462 .select => {
463 const br = data[i].branch;463 const br = data[i].branch;
464 try ir.writeNewRef(decl, &ref_map, ref, config, w);464 try ir.writeNewRef(gpa, decl, &ref_map, ref, config, w);
465 try w.writeAll("select ");465 try w.writeAll("select ");
466 try ir.writeRef(decl, &ref_map, br.cond, config, w);466 try ir.writeRef(decl, &ref_map, br.cond, config, w);
467 try config.setColor(w, .reset);467 try config.setColor(w, .reset);
...@@ -501,7 +501,7 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,...@@ -501,7 +501,7 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,
501 },501 },
502 .call => {502 .call => {
503 const call = data[i].call;503 const call = data[i].call;
504 try ir.writeNewRef(decl, &ref_map, ref, config, w);504 try ir.writeNewRef(gpa, decl, &ref_map, ref, config, w);
505 try w.writeAll("call ");505 try w.writeAll("call ");
506 try ir.writeRef(decl, &ref_map, call.func, config, w);506 try ir.writeRef(decl, &ref_map, call.func, config, w);
507 try config.setColor(w, .reset);507 try config.setColor(w, .reset);
...@@ -515,7 +515,7 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,...@@ -515,7 +515,7 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,
515 },515 },
516 .alloc => {516 .alloc => {
517 const alloc = data[i].alloc;517 const alloc = data[i].alloc;
518 try ir.writeNewRef(decl, &ref_map, ref, config, w);518 try ir.writeNewRef(gpa, decl, &ref_map, ref, config, w);
519 try w.writeAll("alloc ");519 try w.writeAll("alloc ");
520 try config.setColor(w, ATTRIBUTE);520 try config.setColor(w, ATTRIBUTE);
521 try w.writeAll("size ");521 try w.writeAll("size ");
...@@ -528,7 +528,7 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,...@@ -528,7 +528,7 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,
528 try w.writeByte('\n');528 try w.writeByte('\n');
529 },529 },
530 .phi => {530 .phi => {
531 try ir.writeNewRef(decl, &ref_map, ref, config, w);531 try ir.writeNewRef(gpa, decl, &ref_map, ref, config, w);
532 try w.writeAll("phi");532 try w.writeAll("phi");
533 try config.setColor(w, .reset);533 try config.setColor(w, .reset);
534 try w.writeAll(" {");534 try w.writeAll(" {");
...@@ -560,7 +560,7 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,...@@ -560,7 +560,7 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,
560 try w.writeByte('\n');560 try w.writeByte('\n');
561 },561 },
562 .load => {562 .load => {
563 try ir.writeNewRef(decl, &ref_map, ref, config, w);563 try ir.writeNewRef(gpa, decl, &ref_map, ref, config, w);
564 try w.writeAll("load ");564 try w.writeAll("load ");
565 try ir.writeRef(decl, &ref_map, data[i].un, config, w);565 try ir.writeRef(decl, &ref_map, data[i].un, config, w);
566 try w.writeByte('\n');566 try w.writeByte('\n');
...@@ -583,7 +583,7 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,...@@ -583,7 +583,7 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,
583 .mod,583 .mod,
584 => {584 => {
585 const bin = data[i].bin;585 const bin = data[i].bin;
586 try ir.writeNewRef(decl, &ref_map, ref, config, w);586 try ir.writeNewRef(gpa, decl, &ref_map, ref, config, w);
587 try w.print("{s} ", .{@tagName(tag)});587 try w.print("{s} ", .{@tagName(tag)});
588 try ir.writeRef(decl, &ref_map, bin.lhs, config, w);588 try ir.writeRef(decl, &ref_map, bin.lhs, config, w);
589 try config.setColor(w, .reset);589 try config.setColor(w, .reset);
...@@ -598,7 +598,7 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,...@@ -598,7 +598,7 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,
598 .sext,598 .sext,
599 => {599 => {
600 const un = data[i].un;600 const un = data[i].un;
601 try ir.writeNewRef(decl, &ref_map, ref, config, w);601 try ir.writeNewRef(gpa, decl, &ref_map, ref, config, w);
602 try w.print("{s} ", .{@tagName(tag)});602 try w.print("{s} ", .{@tagName(tag)});
603 try ir.writeRef(decl, &ref_map, un, config, w);603 try ir.writeRef(decl, &ref_map, un, config, w);
604 try w.writeByte('\n');604 try w.writeByte('\n');
...@@ -679,8 +679,8 @@ fn writeRef(ir: Ir, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: std.I...@@ -679,8 +679,8 @@ fn writeRef(ir: Ir, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: std.I
679 try w.print(" %{d}", .{ref_index});679 try w.print(" %{d}", .{ref_index});
680}680}
681681
682fn writeNewRef(ir: Ir, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: std.Io.tty.Config, w: *std.Io.Writer) !void {682fn writeNewRef(ir: Ir, gpa: Allocator, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: std.Io.tty.Config, w: *std.Io.Writer) !void {
683 try ref_map.put(ref, {});683 try ref_map.put(gpa, ref, {});
684 try w.writeAll(" ");684 try w.writeAll(" ");
685 try ir.writeRef(decl, ref_map, ref, config, w);685 try ir.writeRef(decl, ref_map, ref, config, w);
686 try config.setColor(w, .reset);686 try config.setColor(w, .reset);
lib/compiler/aro/backend/Object.zig+1-1
...@@ -30,7 +30,7 @@ pub const Section = union(enum) {...@@ -30,7 +30,7 @@ pub const Section = union(enum) {
30 custom: []const u8,30 custom: []const u8,
31};31};
3232
33pub fn getSection(obj: *Object, section: Section) !*std.array_list.Managed(u8) {33pub fn getSection(obj: *Object, section: Section) !*std.ArrayList(u8) {
34 switch (obj.format) {34 switch (obj.format) {
35 .elf => return @as(*Elf, @alignCast(@fieldParentPtr("obj", obj))).getSection(section),35 .elf => return @as(*Elf, @alignCast(@fieldParentPtr("obj", obj))).getSection(section),
36 else => unreachable,36 else => unreachable,
lib/compiler/aro/backend/Object/Elf.zig+8-8
...@@ -4,8 +4,8 @@ const Target = std.Target;...@@ -4,8 +4,8 @@ const Target = std.Target;
4const Object = @import("../Object.zig");4const Object = @import("../Object.zig");
55
6const Section = struct {6const Section = struct {
7 data: std.array_list.Managed(u8),7 data: std.ArrayList(u8) = .empty,
8 relocations: std.ArrayListUnmanaged(Relocation) = .{},8 relocations: std.ArrayList(Relocation) = .empty,
9 flags: u64,9 flags: u64,
10 type: u32,10 type: u32,
11 index: u16 = undefined,11 index: u16 = undefined,
...@@ -37,9 +37,9 @@ const Elf = @This();...@@ -37,9 +37,9 @@ const Elf = @This();
3737
38obj: Object,38obj: Object,
39/// The keys are owned by the Codegen.tree39/// The keys are owned by the Codegen.tree
40sections: std.StringHashMapUnmanaged(*Section) = .{},40sections: std.StringHashMapUnmanaged(*Section) = .empty,
41local_symbols: std.StringHashMapUnmanaged(*Symbol) = .{},41local_symbols: std.StringHashMapUnmanaged(*Symbol) = .empty,
42global_symbols: std.StringHashMapUnmanaged(*Symbol) = .{},42global_symbols: std.StringHashMapUnmanaged(*Symbol) = .empty,
43unnamed_symbol_mangle: u32 = 0,43unnamed_symbol_mangle: u32 = 0,
44strtab_len: u64 = strtab_default.len,44strtab_len: u64 = strtab_default.len,
45arena: std.heap.ArenaAllocator,45arena: std.heap.ArenaAllocator,
...@@ -58,7 +58,7 @@ pub fn deinit(elf: *Elf) void {...@@ -58,7 +58,7 @@ pub fn deinit(elf: *Elf) void {
58 {58 {
59 var it = elf.sections.valueIterator();59 var it = elf.sections.valueIterator();
60 while (it.next()) |sect| {60 while (it.next()) |sect| {
61 sect.*.data.deinit();61 sect.*.data.deinit(gpa);
62 sect.*.relocations.deinit(gpa);62 sect.*.relocations.deinit(gpa);
63 }63 }
64 }64 }
...@@ -80,12 +80,12 @@ fn sectionString(sec: Object.Section) []const u8 {...@@ -80,12 +80,12 @@ fn sectionString(sec: Object.Section) []const u8 {
80 };80 };
81}81}
8282
83pub fn getSection(elf: *Elf, section_kind: Object.Section) !*std.array_list.Managed(u8) {83pub fn getSection(elf: *Elf, section_kind: Object.Section) !*std.ArrayList(u8) {
84 const section_name = sectionString(section_kind);84 const section_name = sectionString(section_kind);
85 const section = elf.sections.get(section_name) orelse blk: {85 const section = elf.sections.get(section_name) orelse blk: {
86 const section = try elf.arena.allocator().create(Section);86 const section = try elf.arena.allocator().create(Section);
87 section.* = .{87 section.* = .{
88 .data = std.array_list.Managed(u8).init(elf.arena.child_allocator),88 .data = std.ArrayList(u8).init(elf.arena.child_allocator),
89 .type = std.elf.SHT_PROGBITS,89 .type = std.elf.SHT_PROGBITS,
90 .flags = switch (section_kind) {90 .flags = switch (section_kind) {
91 .func, .custom => std.elf.SHF_ALLOC + std.elf.SHF_EXECINSTR,91 .func, .custom => std.elf.SHF_ALLOC + std.elf.SHF_EXECINSTR,
lib/compiler/translate-c/main.zig+1-1
...@@ -150,7 +150,7 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8) !void {...@@ -150,7 +150,7 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8) !void {
150 // be written to a tmp file then renamed into place, meaning the path will be150 // be written to a tmp file then renamed into place, meaning the path will be
151 // wrong as soon as the work is done.151 // wrong as soon as the work is done.
152 var opt_dep_file = try d.initDepFile(source, &name_buf, true);152 var opt_dep_file = try d.initDepFile(source, &name_buf, true);
153 defer if (opt_dep_file) |*dep_file| dep_file.deinit(pp.gpa);153 defer if (opt_dep_file) |*dep_file| dep_file.deinit(gpa);
154154
155 if (opt_dep_file) |*dep_file| pp.dep_file = dep_file;155 if (opt_dep_file) |*dep_file| pp.dep_file = dep_file;
156156