diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-05-05 16:32:38 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-06-10 20:42:28 -0700 |
| commit | 9ec0017f460854300004ab263bf585c2d376d1fb (patch) | |
| tree | df586141cc238241a5ce4d9898a119c217baf78c /src/type.zig | |
| parent | 70a4b76acaef8d4062f4d5317af398929ea6c9c4 (diff) | |
| download | zig-9ec0017f460854300004ab263bf585c2d376d1fb.tar.gz zig-9ec0017f460854300004ab263bf585c2d376d1fb.zip | |
stage2: migrate many pointer types to the InternPool
Diffstat (limited to 'src/type.zig')
| -rw-r--r-- | src/type.zig | 85 |
1 files changed, 62 insertions, 23 deletions
diff --git a/src/type.zig b/src/type.zig index 4840bca6e7..db8c116f70 100644 --- a/src/type.zig +++ b/src/type.zig @@ -193,7 +193,7 @@ pub const Type = struct { .Frame, => false, - .Pointer => !ty.isSlice(mod) and (is_equality_cmp or ty.isCPtr()), + .Pointer => !ty.isSlice(mod) and (is_equality_cmp or ty.isCPtr(mod)), .Optional => { if (!is_equality_cmp) return false; return ty.optionalChild(mod).isSelfComparable(mod, is_equality_cmp); @@ -3012,38 +3012,59 @@ pub const Type = struct { } } - pub fn isConstPtr(self: Type) bool { - return switch (self.tag()) { - .pointer => !self.castTag(.pointer).?.data.mutable, - else => false, + pub fn isConstPtr(ty: Type, mod: *const Module) bool { + return switch (ty.ip_index) { + .none => switch (ty.tag()) { + .pointer => !ty.castTag(.pointer).?.data.mutable, + else => false, + }, + else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { + .ptr_type => |ptr_type| ptr_type.is_const, + else => false, + }, }; } - pub fn isVolatilePtr(self: Type) bool { - return switch (self.tag()) { - .pointer => { - const payload = self.castTag(.pointer).?.data; - return payload.@"volatile"; + pub fn isVolatilePtr(ty: Type, mod: *const Module) bool { + return isVolatilePtrIp(ty, mod.intern_pool); + } + + pub fn isVolatilePtrIp(ty: Type, ip: InternPool) bool { + return switch (ty.ip_index) { + .none => switch (ty.tag()) { + .pointer => ty.castTag(.pointer).?.data.@"volatile", + else => false, + }, + else => switch (ip.indexToKey(ty.ip_index)) { + .ptr_type => |ptr_type| ptr_type.is_volatile, + else => false, }, - else => false, }; } - pub fn isAllowzeroPtr(self: Type, mod: *const Module) bool { - return switch (self.tag()) { - .pointer => { - const payload = self.castTag(.pointer).?.data; - return payload.@"allowzero"; + pub fn isAllowzeroPtr(ty: Type, mod: *const Module) bool { + return switch (ty.ip_index) { + .none => switch (ty.tag()) { + .pointer => ty.castTag(.pointer).?.data.@"allowzero", + else => ty.zigTypeTag(mod) == .Optional, + }, + else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { + .ptr_type => |ptr_type| ptr_type.is_allowzero, + else => false, }, - else => return self.zigTypeTag(mod) == .Optional, }; } - pub fn isCPtr(self: Type) bool { - return switch (self.tag()) { - .pointer => self.castTag(.pointer).?.data.size == .C, - - else => return false, + pub fn isCPtr(ty: Type, mod: *const Module) bool { + return switch (ty.ip_index) { + .none => switch (ty.tag()) { + .pointer => ty.castTag(.pointer).?.data.size == .C, + else => false, + }, + else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { + .ptr_type => |ptr_type| ptr_type.size == .C, + else => false, + }, }; } @@ -5063,7 +5084,7 @@ pub const Type = struct { return .{ .pointee_type = p.elem_type.toType(), .sentinel = if (p.sentinel != .none) p.sentinel.toValue() else null, - .@"align" = p.alignment, + .@"align" = @intCast(u32, p.alignment), .@"addrspace" = p.address_space, .bit_offset = p.bit_offset, .host_size = p.host_size, @@ -5248,6 +5269,24 @@ pub const Type = struct { } } + if (d.pointee_type.ip_index != .none and + (d.sentinel == null or d.sentinel.?.ip_index != .none)) + { + return mod.ptrType(.{ + .elem_type = d.pointee_type.ip_index, + .sentinel = if (d.sentinel) |s| s.ip_index else .none, + .alignment = d.@"align", + .host_size = d.host_size, + .bit_offset = d.bit_offset, + .vector_index = d.vector_index, + .size = d.size, + .is_const = !d.mutable, + .is_volatile = d.@"volatile", + .is_allowzero = d.@"allowzero", + .address_space = d.@"addrspace", + }); + } + return Type.Tag.pointer.create(arena, d); } |
