diff options
| author | Vexu <git@vexu.eu> | 2020-09-09 17:59:13 +0300 |
|---|---|---|
| committer | Vexu <git@vexu.eu> | 2020-09-30 16:59:09 +0300 |
| commit | e2cf2e015bf2afe816593458a3cad9e5baaab095 (patch) | |
| tree | cf9c4260ee35687362a4caae4d00ee9427505e0d /src/type.zig | |
| parent | 7d910b024bd47d005030f9f3351e4923b2e0edc0 (diff) | |
| download | zig-e2cf2e015bf2afe816593458a3cad9e5baaab095.tar.gz zig-e2cf2e015bf2afe816593458a3cad9e5baaab095.zip | |
stage2: struct type field access
Diffstat (limited to 'src/type.zig')
| -rw-r--r-- | src/type.zig | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/src/type.zig b/src/type.zig index bcce9d6edd..c22edaa561 100644 --- a/src/type.zig +++ b/src/type.zig @@ -441,7 +441,7 @@ pub const Type = extern union { }, .error_set => return self.copyPayloadShallow(allocator, Payload.ErrorSet), .error_set_single => return self.copyPayloadShallow(allocator, Payload.ErrorSetSingle), - .empty_struct => return self.copyPayloadShallow(allocator, Payload.EmptyStruct), + .empty_struct => return self.copyPayloadShallow(allocator, Payload.EmptyStruct), } } @@ -2789,6 +2789,80 @@ pub const Type = extern union { (self.isSinglePointer() and self.elemType().zigTypeTag() == .Array); } + /// Asserts that the type is a container. (note: ErrorSet is not a container). + pub fn getContainerScope(self: Type) *Module.Scope.Container { + return switch (self.tag()) { + .f16, + .f32, + .f64, + .f128, + .c_longdouble, + .comptime_int, + .comptime_float, + .u8, + .i8, + .u16, + .i16, + .u32, + .i32, + .u64, + .i64, + .usize, + .isize, + .c_short, + .c_ushort, + .c_int, + .c_uint, + .c_long, + .c_ulong, + .c_longlong, + .c_ulonglong, + .bool, + .type, + .anyerror, + .fn_noreturn_no_args, + .fn_void_no_args, + .fn_naked_noreturn_no_args, + .fn_ccc_void_no_args, + .function, + .single_const_pointer_to_comptime_int, + .const_slice_u8, + .c_void, + .void, + .noreturn, + .@"null", + .@"undefined", + .int_unsigned, + .int_signed, + .array, + .array_sentinel, + .array_u8, + .array_u8_sentinel_0, + .single_const_pointer, + .single_mut_pointer, + .many_const_pointer, + .many_mut_pointer, + .const_slice, + .mut_slice, + .optional, + .optional_single_mut_pointer, + .optional_single_const_pointer, + .enum_literal, + .error_union, + .@"anyframe", + .anyframe_T, + .anyerror_void_error_union, + .error_set, + .error_set_single, + .c_const_pointer, + .c_mut_pointer, + .pointer, + => unreachable, + + .empty_struct => self.cast(Type.Payload.EmptyStruct).?.scope, + }; + } + /// This enum does not directly correspond to `std.builtin.TypeId` because /// it has extra enum tags in it, as a way of using less memory. For example, /// even though Zig recognizes `*align(10) i32` and `*i32` both as Pointer types |
