| ... | @@ -74,6 +74,7 @@ pub const Type = extern union { | ... | @@ -74,6 +74,7 @@ pub const Type = extern union { |
| 74 | .many_mut_pointer, | 74 | .many_mut_pointer, |
| 75 | .c_const_pointer, | 75 | .c_const_pointer, |
| 76 | .c_mut_pointer, | 76 | .c_mut_pointer, |
| | 77 | .pointer, |
| 77 | => return .Pointer, | 78 | => return .Pointer, |
| 78 | | 79 | |
| 79 | .optional, | 80 | .optional, |
| ... | @@ -390,6 +391,25 @@ pub const Type = extern union { | ... | @@ -390,6 +391,25 @@ pub const Type = extern union { |
| 390 | .optional_single_mut_pointer, | 391 | .optional_single_mut_pointer, |
| 391 | .optional_single_const_pointer, | 392 | .optional_single_const_pointer, |
| 392 | => return self.copyPayloadSingleField(allocator, Payload.PointerSimple, "pointee_type"), | 393 | => return self.copyPayloadSingleField(allocator, Payload.PointerSimple, "pointee_type"), |
| | 394 | |
| | 395 | .pointer => { |
| | 396 | const payload = @fieldParentPtr(Payload.Pointer, "base", self.ptr_otherwise); |
| | 397 | const new_payload = try allocator.create(Payload.Pointer); |
| | 398 | new_payload.* = .{ |
| | 399 | .base = payload.base, |
| | 400 | |
| | 401 | .pointee_type = try payload.pointee_type.copy(allocator), |
| | 402 | .sentinel = if (payload.sentinel) |some| try some.copy(allocator) else null, |
| | 403 | .@"align" = payload.@"align", |
| | 404 | .bit_offset = payload.bit_offset, |
| | 405 | .host_size = payload.host_size, |
| | 406 | .@"allowzero" = payload.@"allowzero", |
| | 407 | .mutable = payload.mutable, |
| | 408 | .@"volatile" = payload.@"volatile", |
| | 409 | .size = payload.size, |
| | 410 | }; |
| | 411 | return Type{ .ptr_otherwise = &new_payload.base }; |
| | 412 | }, |
| 393 | } | 413 | } |
| 394 | } | 414 | } |
| 395 | | 415 | |
| ... | @@ -556,6 +576,34 @@ pub const Type = extern union { | ... | @@ -556,6 +576,34 @@ pub const Type = extern union { |
| 556 | ty = payload.pointee_type; | 576 | ty = payload.pointee_type; |
| 557 | continue; | 577 | continue; |
| 558 | }, | 578 | }, |
| | 579 | |
| | 580 | .pointer => { |
| | 581 | const payload = @fieldParentPtr(Payload.Pointer, "base", ty.ptr_otherwise); |
| | 582 | if (payload.sentinel) |some| switch (payload.size) { |
| | 583 | .One, .C => unreachable, |
| | 584 | .Many => try out_stream.writeAll("[*:{}]"), |
| | 585 | .Slice => try out_stream.writeAll("[:{}]"), |
| | 586 | } else switch (payload.size) { |
| | 587 | .One => try out_stream.writeAll("*"), |
| | 588 | .Many => try out_stream.writeAll("[*]"), |
| | 589 | .C => try out_stream.writeAll("[*c]"), |
| | 590 | .Slice => try out_stream.writeAll("[]"), |
| | 591 | } |
| | 592 | if (payload.@"align" != 0) { |
| | 593 | try out_stream.print("align({}", .{payload.@"align"}); |
| | 594 | |
| | 595 | if (payload.bit_offset != 0) { |
| | 596 | try out_stream.print(":{}:{}", .{ payload.bit_offset, payload.host_size }); |
| | 597 | } |
| | 598 | try out_stream.writeAll(") "); |
| | 599 | } |
| | 600 | if (!payload.mutable) try out_stream.writeAll("const "); |
| | 601 | if (payload.@"volatile") try out_stream.writeAll("volatile "); |
| | 602 | if (payload.@"allowzero") try out_stream.writeAll("allowzero "); |
| | 603 | |
| | 604 | ty = payload.pointee_type; |
| | 605 | continue; |
| | 606 | }, |
| 559 | } | 607 | } |
| 560 | unreachable; | 608 | unreachable; |
| 561 | } | 609 | } |
| ... | @@ -660,6 +708,7 @@ pub const Type = extern union { | ... | @@ -660,6 +708,7 @@ pub const Type = extern union { |
| 660 | .many_mut_pointer => self.elemType().hasCodeGenBits(), | 708 | .many_mut_pointer => self.elemType().hasCodeGenBits(), |
| 661 | .c_const_pointer => self.elemType().hasCodeGenBits(), | 709 | .c_const_pointer => self.elemType().hasCodeGenBits(), |
| 662 | .c_mut_pointer => self.elemType().hasCodeGenBits(), | 710 | .c_mut_pointer => self.elemType().hasCodeGenBits(), |
| | 711 | .pointer => self.elemType().hasCodeGenBits(), |
| 663 | .int_signed => self.cast(Payload.IntSigned).?.bits == 0, | 712 | .int_signed => self.cast(Payload.IntSigned).?.bits == 0, |
| 664 | .int_unsigned => self.cast(Payload.IntUnsigned).?.bits == 0, | 713 | .int_unsigned => self.cast(Payload.IntUnsigned).?.bits == 0, |
| 665 | | 714 | |
| ... | @@ -718,6 +767,13 @@ pub const Type = extern union { | ... | @@ -718,6 +767,13 @@ pub const Type = extern union { |
| 718 | .optional_single_mut_pointer, | 767 | .optional_single_mut_pointer, |
| 719 | => return @divExact(target.cpu.arch.ptrBitWidth(), 8), | 768 | => return @divExact(target.cpu.arch.ptrBitWidth(), 8), |
| 720 | | 769 | |
| | 770 | .pointer => { |
| | 771 | const payload = @fieldParentPtr(Payload.Pointer, "base", self.ptr_otherwise); |
| | 772 | |
| | 773 | if (payload.@"align" != 0) return payload.@"align"; |
| | 774 | return @divExact(target.cpu.arch.ptrBitWidth(), 8); |
| | 775 | }, |
| | 776 | |
| 721 | .c_short => return @divExact(CType.short.sizeInBits(target), 8), | 777 | .c_short => return @divExact(CType.short.sizeInBits(target), 8), |
| 722 | .c_ushort => return @divExact(CType.ushort.sizeInBits(target), 8), | 778 | .c_ushort => return @divExact(CType.ushort.sizeInBits(target), 8), |
| 723 | .c_int => return @divExact(CType.int.sizeInBits(target), 8), | 779 | .c_int => return @divExact(CType.int.sizeInBits(target), 8), |
| ... | @@ -789,6 +845,7 @@ pub const Type = extern union { | ... | @@ -789,6 +845,7 @@ pub const Type = extern union { |
| 789 | .@"null" => unreachable, | 845 | .@"null" => unreachable, |
| 790 | .@"undefined" => unreachable, | 846 | .@"undefined" => unreachable, |
| 791 | .enum_literal => unreachable, | 847 | .enum_literal => unreachable, |
| | 848 | .single_const_pointer_to_comptime_int => unreachable, |
| 792 | | 849 | |
| 793 | .u8, | 850 | .u8, |
| 794 | .i8, | 851 | .i8, |
| ... | @@ -812,18 +869,28 @@ pub const Type = extern union { | ... | @@ -812,18 +869,28 @@ pub const Type = extern union { |
| 812 | .i64, .u64 => return 8, | 869 | .i64, .u64 => return 8, |
| 813 | | 870 | |
| 814 | .isize, | 871 | .isize, |
| 815 | .usize, | 872 | .usize |
| 816 | .single_const_pointer_to_comptime_int, | 873 | => return @divExact(target.cpu.arch.ptrBitWidth(), 8), |
| 817 | .const_slice_u8, | 874 | .const_slice_u8 => return @divExact(target.cpu.arch.ptrBitWidth(), 8) * 2, |
| | 875 | |
| | 876 | .optional_single_const_pointer, |
| | 877 | .optional_single_mut_pointer, |
| | 878 | => { |
| | 879 | if (self.elemType().hasCodeGenBits()) return 1; |
| | 880 | return @divExact(target.cpu.arch.ptrBitWidth(), 8); |
| | 881 | }, |
| | 882 | |
| 818 | .single_const_pointer, | 883 | .single_const_pointer, |
| 819 | .single_mut_pointer, | 884 | .single_mut_pointer, |
| 820 | .many_const_pointer, | 885 | .many_const_pointer, |
| 821 | .many_mut_pointer, | 886 | .many_mut_pointer, |
| 822 | .c_const_pointer, | 887 | .c_const_pointer, |
| 823 | .c_mut_pointer, | 888 | .c_mut_pointer, |
| 824 | .optional_single_const_pointer, | 889 | .pointer, |
| 825 | .optional_single_mut_pointer, | 890 | => { |
| 826 | => return @divExact(target.cpu.arch.ptrBitWidth(), 8), | 891 | if (self.elemType().hasCodeGenBits()) return 0; |
| | 892 | return @divExact(target.cpu.arch.ptrBitWidth(), 8); |
| | 893 | }, |
| 827 | | 894 | |
| 828 | .c_short => return @divExact(CType.short.sizeInBits(target), 8), | 895 | .c_short => return @divExact(CType.short.sizeInBits(target), 8), |
| 829 | .c_ushort => return @divExact(CType.ushort.sizeInBits(target), 8), | 896 | .c_ushort => return @divExact(CType.ushort.sizeInBits(target), 8), |
| ... | @@ -931,6 +998,8 @@ pub const Type = extern union { | ... | @@ -931,6 +998,8 @@ pub const Type = extern union { |
| 931 | .single_mut_pointer, | 998 | .single_mut_pointer, |
| 932 | .single_const_pointer_to_comptime_int, | 999 | .single_const_pointer_to_comptime_int, |
| 933 | => true, | 1000 | => true, |
| | 1001 | |
| | 1002 | .pointer => self.cast(Payload.Pointer).?.size == .One, |
| 934 | }; | 1003 | }; |
| 935 | } | 1004 | } |
| 936 | | 1005 | |
| ... | @@ -994,6 +1063,8 @@ pub const Type = extern union { | ... | @@ -994,6 +1063,8 @@ pub const Type = extern union { |
| 994 | => false, | 1063 | => false, |
| 995 | | 1064 | |
| 996 | .const_slice_u8 => true, | 1065 | .const_slice_u8 => true, |
| | 1066 | |
| | 1067 | .pointer => self.cast(Payload.Pointer).?.size == .Slice, |
| 997 | }; | 1068 | }; |
| 998 | } | 1069 | } |
| 999 | | 1070 | |
| ... | @@ -1058,6 +1129,8 @@ pub const Type = extern union { | ... | @@ -1058,6 +1129,8 @@ pub const Type = extern union { |
| 1058 | .single_const_pointer_to_comptime_int, | 1129 | .single_const_pointer_to_comptime_int, |
| 1059 | .const_slice_u8, | 1130 | .const_slice_u8, |
| 1060 | => true, | 1131 | => true, |
| | 1132 | |
| | 1133 | .pointer => !self.cast(Payload.Pointer).?.mutable, |
| 1061 | }; | 1134 | }; |
| 1062 | } | 1135 | } |
| 1063 | | 1136 | |
| ... | @@ -1120,6 +1193,11 @@ pub const Type = extern union { | ... | @@ -1120,6 +1193,11 @@ pub const Type = extern union { |
| 1120 | .optional_single_const_pointer, | 1193 | .optional_single_const_pointer, |
| 1121 | .enum_literal, | 1194 | .enum_literal, |
| 1122 | => false, | 1195 | => false, |
| | 1196 | |
| | 1197 | .pointer => { |
| | 1198 | const payload = @fieldParentPtr(Payload.Pointer, "base", self.ptr_otherwise); |
| | 1199 | return payload.@"volatile"; |
| | 1200 | }, |
| 1123 | }; | 1201 | }; |
| 1124 | } | 1202 | } |
| 1125 | | 1203 | |
| ... | @@ -1237,6 +1315,7 @@ pub const Type = extern union { | ... | @@ -1237,6 +1315,7 @@ pub const Type = extern union { |
| 1237 | .c_mut_pointer => self.castPointer().?.pointee_type, | 1315 | .c_mut_pointer => self.castPointer().?.pointee_type, |
| 1238 | .array_u8, .array_u8_sentinel_0, .const_slice_u8 => Type.initTag(.u8), | 1316 | .array_u8, .array_u8_sentinel_0, .const_slice_u8 => Type.initTag(.u8), |
| 1239 | .single_const_pointer_to_comptime_int => Type.initTag(.comptime_int), | 1317 | .single_const_pointer_to_comptime_int => Type.initTag(.comptime_int), |
| | 1318 | .pointer => self.cast(Payload.Pointer).?.pointee_type, |
| 1240 | }; | 1319 | }; |
| 1241 | } | 1320 | } |
| 1242 | | 1321 | |
| ... | @@ -1325,6 +1404,7 @@ pub const Type = extern union { | ... | @@ -1325,6 +1404,7 @@ pub const Type = extern union { |
| 1325 | .fn_naked_noreturn_no_args, | 1404 | .fn_naked_noreturn_no_args, |
| 1326 | .fn_ccc_void_no_args, | 1405 | .fn_ccc_void_no_args, |
| 1327 | .function, | 1406 | .function, |
| | 1407 | .pointer, |
| 1328 | .single_const_pointer, | 1408 | .single_const_pointer, |
| 1329 | .single_mut_pointer, | 1409 | .single_mut_pointer, |
| 1330 | .many_const_pointer, | 1410 | .many_const_pointer, |
| ... | @@ -1389,6 +1469,7 @@ pub const Type = extern union { | ... | @@ -1389,6 +1469,7 @@ pub const Type = extern union { |
| 1389 | .fn_naked_noreturn_no_args, | 1469 | .fn_naked_noreturn_no_args, |
| 1390 | .fn_ccc_void_no_args, | 1470 | .fn_ccc_void_no_args, |
| 1391 | .function, | 1471 | .function, |
| | 1472 | .pointer, |
| 1392 | .single_const_pointer, | 1473 | .single_const_pointer, |
| 1393 | .single_mut_pointer, | 1474 | .single_mut_pointer, |
| 1394 | .many_const_pointer, | 1475 | .many_const_pointer, |
| ... | @@ -1443,6 +1524,7 @@ pub const Type = extern union { | ... | @@ -1443,6 +1524,7 @@ pub const Type = extern union { |
| 1443 | .array_sentinel, | 1524 | .array_sentinel, |
| 1444 | .array_u8, | 1525 | .array_u8, |
| 1445 | .array_u8_sentinel_0, | 1526 | .array_u8_sentinel_0, |
| | 1527 | .pointer, |
| 1446 | .single_const_pointer, | 1528 | .single_const_pointer, |
| 1447 | .single_mut_pointer, | 1529 | .single_mut_pointer, |
| 1448 | .many_const_pointer, | 1530 | .many_const_pointer, |
| ... | @@ -1508,6 +1590,7 @@ pub const Type = extern union { | ... | @@ -1508,6 +1590,7 @@ pub const Type = extern union { |
| 1508 | .array_sentinel, | 1590 | .array_sentinel, |
| 1509 | .array_u8, | 1591 | .array_u8, |
| 1510 | .array_u8_sentinel_0, | 1592 | .array_u8_sentinel_0, |
| | 1593 | .pointer, |
| 1511 | .single_const_pointer, | 1594 | .single_const_pointer, |
| 1512 | .single_mut_pointer, | 1595 | .single_mut_pointer, |
| 1513 | .many_const_pointer, | 1596 | .many_const_pointer, |
| ... | @@ -1573,6 +1656,7 @@ pub const Type = extern union { | ... | @@ -1573,6 +1656,7 @@ pub const Type = extern union { |
| 1573 | .array_sentinel, | 1656 | .array_sentinel, |
| 1574 | .array_u8, | 1657 | .array_u8, |
| 1575 | .array_u8_sentinel_0, | 1658 | .array_u8_sentinel_0, |
| | 1659 | .pointer, |
| 1576 | .single_const_pointer, | 1660 | .single_const_pointer, |
| 1577 | .single_mut_pointer, | 1661 | .single_mut_pointer, |
| 1578 | .many_const_pointer, | 1662 | .many_const_pointer, |
| ... | @@ -1636,6 +1720,7 @@ pub const Type = extern union { | ... | @@ -1636,6 +1720,7 @@ pub const Type = extern union { |
| 1636 | .array_sentinel, | 1720 | .array_sentinel, |
| 1637 | .array_u8, | 1721 | .array_u8, |
| 1638 | .array_u8_sentinel_0, | 1722 | .array_u8_sentinel_0, |
| | 1723 | .pointer, |
| 1639 | .single_const_pointer, | 1724 | .single_const_pointer, |
| 1640 | .single_mut_pointer, | 1725 | .single_mut_pointer, |
| 1641 | .many_const_pointer, | 1726 | .many_const_pointer, |
| ... | @@ -1728,6 +1813,7 @@ pub const Type = extern union { | ... | @@ -1728,6 +1813,7 @@ pub const Type = extern union { |
| 1728 | .array_sentinel, | 1813 | .array_sentinel, |
| 1729 | .array_u8, | 1814 | .array_u8, |
| 1730 | .array_u8_sentinel_0, | 1815 | .array_u8_sentinel_0, |
| | 1816 | .pointer, |
| 1731 | .single_const_pointer, | 1817 | .single_const_pointer, |
| 1732 | .single_mut_pointer, | 1818 | .single_mut_pointer, |
| 1733 | .many_const_pointer, | 1819 | .many_const_pointer, |
| ... | @@ -1796,6 +1882,7 @@ pub const Type = extern union { | ... | @@ -1796,6 +1882,7 @@ pub const Type = extern union { |
| 1796 | .array_sentinel, | 1882 | .array_sentinel, |
| 1797 | .array_u8, | 1883 | .array_u8, |
| 1798 | .array_u8_sentinel_0, | 1884 | .array_u8_sentinel_0, |
| | 1885 | .pointer, |
| 1799 | .single_const_pointer, | 1886 | .single_const_pointer, |
| 1800 | .single_mut_pointer, | 1887 | .single_mut_pointer, |
| 1801 | .many_const_pointer, | 1888 | .many_const_pointer, |
| ... | @@ -1863,6 +1950,7 @@ pub const Type = extern union { | ... | @@ -1863,6 +1950,7 @@ pub const Type = extern union { |
| 1863 | .array_sentinel, | 1950 | .array_sentinel, |
| 1864 | .array_u8, | 1951 | .array_u8, |
| 1865 | .array_u8_sentinel_0, | 1952 | .array_u8_sentinel_0, |
| | 1953 | .pointer, |
| 1866 | .single_const_pointer, | 1954 | .single_const_pointer, |
| 1867 | .single_mut_pointer, | 1955 | .single_mut_pointer, |
| 1868 | .many_const_pointer, | 1956 | .many_const_pointer, |
| ... | @@ -1930,6 +2018,7 @@ pub const Type = extern union { | ... | @@ -1930,6 +2018,7 @@ pub const Type = extern union { |
| 1930 | .array_sentinel, | 2018 | .array_sentinel, |
| 1931 | .array_u8, | 2019 | .array_u8, |
| 1932 | .array_u8_sentinel_0, | 2020 | .array_u8_sentinel_0, |
| | 2021 | .pointer, |
| 1933 | .single_const_pointer, | 2022 | .single_const_pointer, |
| 1934 | .single_mut_pointer, | 2023 | .single_mut_pointer, |
| 1935 | .many_const_pointer, | 2024 | .many_const_pointer, |
| ... | @@ -1994,6 +2083,7 @@ pub const Type = extern union { | ... | @@ -1994,6 +2083,7 @@ pub const Type = extern union { |
| 1994 | .array_sentinel, | 2083 | .array_sentinel, |
| 1995 | .array_u8, | 2084 | .array_u8, |
| 1996 | .array_u8_sentinel_0, | 2085 | .array_u8_sentinel_0, |
| | 2086 | .pointer, |
| 1997 | .single_const_pointer, | 2087 | .single_const_pointer, |
| 1998 | .single_mut_pointer, | 2088 | .single_mut_pointer, |
| 1999 | .many_const_pointer, | 2089 | .many_const_pointer, |
| ... | @@ -2058,6 +2148,7 @@ pub const Type = extern union { | ... | @@ -2058,6 +2148,7 @@ pub const Type = extern union { |
| 2058 | .array_sentinel, | 2148 | .array_sentinel, |
| 2059 | .array_u8, | 2149 | .array_u8, |
| 2060 | .array_u8_sentinel_0, | 2150 | .array_u8_sentinel_0, |
| | 2151 | .pointer, |
| 2061 | .single_const_pointer, | 2152 | .single_const_pointer, |
| 2062 | .single_mut_pointer, | 2153 | .single_mut_pointer, |
| 2063 | .many_const_pointer, | 2154 | .many_const_pointer, |
| ... | @@ -2142,6 +2233,7 @@ pub const Type = extern union { | ... | @@ -2142,6 +2233,7 @@ pub const Type = extern union { |
| 2142 | .array_sentinel, | 2233 | .array_sentinel, |
| 2143 | .array_u8, | 2234 | .array_u8, |
| 2144 | .array_u8_sentinel_0, | 2235 | .array_u8_sentinel_0, |
| | 2236 | .pointer, |
| 2145 | .single_const_pointer, | 2237 | .single_const_pointer, |
| 2146 | .single_mut_pointer, | 2238 | .single_mut_pointer, |
| 2147 | .many_const_pointer, | 2239 | .many_const_pointer, |
| ... | @@ -2241,6 +2333,10 @@ pub const Type = extern union { | ... | @@ -2241,6 +2333,10 @@ pub const Type = extern union { |
| 2241 | ty = ptr.pointee_type; | 2333 | ty = ptr.pointee_type; |
| 2242 | continue; | 2334 | continue; |
| 2243 | }, | 2335 | }, |
| | 2336 | .pointer => { |
| | 2337 | ty = ty.cast(Payload.Pointer).?.pointee_type; |
| | 2338 | continue; |
| | 2339 | }, |
| 2244 | }; | 2340 | }; |
| 2245 | } | 2341 | } |
| 2246 | | 2342 | |
| ... | @@ -2305,6 +2401,8 @@ pub const Type = extern union { | ... | @@ -2305,6 +2401,8 @@ pub const Type = extern union { |
| 2305 | .c_const_pointer, | 2401 | .c_const_pointer, |
| 2306 | .c_mut_pointer, | 2402 | .c_mut_pointer, |
| 2307 | => return true, | 2403 | => return true, |
| | 2404 | |
| | 2405 | .pointer => self.cast(Payload.Pointer).?.size == .C, |
| 2308 | }; | 2406 | }; |
| 2309 | } | 2407 | } |
| 2310 | | 2408 | |
| ... | @@ -2362,6 +2460,7 @@ pub const Type = extern union { | ... | @@ -2362,6 +2460,7 @@ pub const Type = extern union { |
| 2362 | array_u8_sentinel_0, | 2460 | array_u8_sentinel_0, |
| 2363 | array, | 2461 | array, |
| 2364 | array_sentinel, | 2462 | array_sentinel, |
| | 2463 | pointer, |
| 2365 | single_const_pointer, | 2464 | single_const_pointer, |
| 2366 | single_mut_pointer, | 2465 | single_mut_pointer, |
| 2367 | many_const_pointer, | 2466 | many_const_pointer, |
| ... | @@ -2440,6 +2539,21 @@ pub const Type = extern union { | ... | @@ -2440,6 +2539,21 @@ pub const Type = extern union { |
| 2440 | | 2539 | |
| 2441 | child_type: Type, | 2540 | child_type: Type, |
| 2442 | }; | 2541 | }; |
| | 2542 | |
| | 2543 | pub const Pointer = struct { |
| | 2544 | base: Payload = .{ .tag = .pointer }, |
| | 2545 | |
| | 2546 | pointee_type: Type, |
| | 2547 | sentinel: ?Value, |
| | 2548 | /// If zero use pointee_type.AbiAlign() |
| | 2549 | @"align": u32, |
| | 2550 | bit_offset: u16, |
| | 2551 | host_size: u16, |
| | 2552 | @"allowzero": bool, |
| | 2553 | mutable: bool, |
| | 2554 | @"volatile": bool, |
| | 2555 | size: std.builtin.TypeInfo.Pointer.Size, |
| | 2556 | }; |
| 2443 | }; | 2557 | }; |
| 2444 | }; | 2558 | }; |
| 2445 | | 2559 | |