| ... | ... | @@ -607,8 +607,16 @@ pub const Type = union(enum) { |
| 607 | 607 | |
| 608 | 608 | /// The type of the sentinel is the element type of the pointer, which is |
| 609 | 609 | /// the value of the `child` field in this struct. However there is no way |
| 610 | | /// to refer to that type here, so we use pointer to `anyopaque`. |
| 611 | | sentinel: ?*const anyopaque, |
| 610 | /// to refer to that type here, so we use `*const anyopaque`. |
| 611 | /// See also: `sentinel` |
| 612 | sentinel_ptr: ?*const anyopaque, |
| 613 | |
| 614 | /// Loads the pointer type's sentinel value from `sentinel_ptr`. |
| 615 | /// Returns `null` if the pointer type has no sentinel. |
| 616 | pub inline fn sentinel(comptime ptr: Pointer) ?ptr.child { |
| 617 | const sp: *const ptr.child = @ptrCast(@alignCast(ptr.sentinel_ptr orelse return null)); |
| 618 | return sp.*; |
| 619 | } |
| 612 | 620 | |
| 613 | 621 | /// This data structure is used by the Zig language code generation and |
| 614 | 622 | /// therefore must be kept in sync with the compiler implementation. |
| ... | ... | @@ -628,8 +636,16 @@ pub const Type = union(enum) { |
| 628 | 636 | |
| 629 | 637 | /// The type of the sentinel is the element type of the array, which is |
| 630 | 638 | /// the value of the `child` field in this struct. However there is no way |
| 631 | | /// to refer to that type here, so we use pointer to `anyopaque`. |
| 632 | | sentinel: ?*const anyopaque, |
| 639 | /// to refer to that type here, so we use `*const anyopaque`. |
| 640 | /// See also: `sentinel`. |
| 641 | sentinel_ptr: ?*const anyopaque, |
| 642 | |
| 643 | /// Loads the array type's sentinel value from `sentinel_ptr`. |
| 644 | /// Returns `null` if the array type has no sentinel. |
| 645 | pub inline fn sentinel(comptime arr: Array) ?arr.child { |
| 646 | const sp: *const arr.child = @ptrCast(@alignCast(arr.sentinel_ptr orelse return null)); |
| 647 | return sp.*; |
| 648 | } |
| 633 | 649 | }; |
| 634 | 650 | |
| 635 | 651 | /// This data structure is used by the Zig language code generation and |
| ... | ... | @@ -645,9 +661,20 @@ pub const Type = union(enum) { |
| 645 | 661 | pub const StructField = struct { |
| 646 | 662 | name: [:0]const u8, |
| 647 | 663 | type: type, |
| 648 | | default_value: ?*const anyopaque, |
| 664 | /// The type of the default value is the type of this struct field, which |
| 665 | /// is the value of the `type` field in this struct. However there is no |
| 666 | /// way to refer to that type here, so we use `*const anyopaque`. |
| 667 | /// See also: `defaultValue`. |
| 668 | default_value_ptr: ?*const anyopaque, |
| 649 | 669 | is_comptime: bool, |
| 650 | 670 | alignment: comptime_int, |
| 671 | |
| 672 | /// Loads the field's default value from `default_value_ptr`. |
| 673 | /// Returns `null` if the field has no default value. |
| 674 | pub inline fn defaultValue(comptime sf: StructField) ?sf.type { |
| 675 | const dp: *const sf.type = @ptrCast(@alignCast(sf.default_value_ptr orelse return null)); |
| 676 | return dp.*; |
| 677 | } |
| 651 | 678 | }; |
| 652 | 679 | |
| 653 | 680 | /// This data structure is used by the Zig language code generation and |