From c66b48194ff83eb5b1774a1428461f5fc94dcd7d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 1 Apr 2021 19:27:17 -0700 Subject: stage2: AstGen and ZIR printing for struct decls --- src/type.zig | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'src/type.zig') diff --git a/src/type.zig b/src/type.zig index 333854296e..05d4a950c9 100644 --- a/src/type.zig +++ b/src/type.zig @@ -93,6 +93,7 @@ pub const Type = extern union { .anyerror_void_error_union, .error_union => return .ErrorUnion, .empty_struct => return .Struct, + .empty_struct_literal => return .Struct, .var_args_param => unreachable, // can be any type } @@ -530,6 +531,7 @@ pub const Type = extern union { .inferred_alloc_const, .inferred_alloc_mut, .var_args_param, + .empty_struct_literal, => unreachable, .array_u8, @@ -672,8 +674,7 @@ pub const Type = extern union { .@"null" => return out_stream.writeAll("@Type(.Null)"), .@"undefined" => return out_stream.writeAll("@Type(.Undefined)"), - // TODO this should print the structs name - .empty_struct => return out_stream.writeAll("struct {}"), + .empty_struct, .empty_struct_literal => return out_stream.writeAll("struct {}"), .anyerror_void_error_union => return out_stream.writeAll("anyerror!void"), .const_slice_u8 => return out_stream.writeAll("[]const u8"), .fn_noreturn_no_args => return out_stream.writeAll("fn() noreturn"), @@ -960,6 +961,7 @@ pub const Type = extern union { .@"undefined", .enum_literal, .empty_struct, + .empty_struct_literal, .@"opaque", => false, @@ -1108,6 +1110,7 @@ pub const Type = extern union { .@"undefined", .enum_literal, .empty_struct, + .empty_struct_literal, .inferred_alloc_const, .inferred_alloc_mut, .@"opaque", @@ -1135,6 +1138,7 @@ pub const Type = extern union { .enum_literal => unreachable, .single_const_pointer_to_comptime_int => unreachable, .empty_struct => unreachable, + .empty_struct_literal => unreachable, .inferred_alloc_const => unreachable, .inferred_alloc_mut => unreachable, .@"opaque" => unreachable, @@ -1313,6 +1317,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .@"opaque", .var_args_param, => false, @@ -1386,6 +1391,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .@"opaque", .var_args_param, => unreachable, @@ -1478,6 +1484,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .inferred_alloc_const, .inferred_alloc_mut, .@"opaque", @@ -1554,6 +1561,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .inferred_alloc_const, .inferred_alloc_mut, .@"opaque", @@ -1639,6 +1647,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .inferred_alloc_const, .inferred_alloc_mut, .@"opaque", @@ -1719,6 +1728,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .inferred_alloc_const, .inferred_alloc_mut, .@"opaque", @@ -1841,6 +1851,7 @@ pub const Type = extern union { .error_set => unreachable, .error_set_single => unreachable, .empty_struct => unreachable, + .empty_struct_literal => unreachable, .inferred_alloc_const => unreachable, .inferred_alloc_mut => unreachable, .@"opaque" => unreachable, @@ -1989,6 +2000,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .inferred_alloc_const, .inferred_alloc_mut, .@"opaque", @@ -2059,6 +2071,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .inferred_alloc_const, .inferred_alloc_mut, .@"opaque", @@ -2144,6 +2157,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .inferred_alloc_const, .inferred_alloc_mut, .@"opaque", @@ -2225,6 +2239,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .inferred_alloc_const, .inferred_alloc_mut, .@"opaque", @@ -2292,6 +2307,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .inferred_alloc_const, .inferred_alloc_mut, .@"opaque", @@ -2387,6 +2403,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .inferred_alloc_const, .inferred_alloc_mut, .@"opaque", @@ -2503,6 +2520,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .inferred_alloc_const, .inferred_alloc_mut, .@"opaque", @@ -2585,6 +2603,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .inferred_alloc_const, .inferred_alloc_mut, .@"opaque", @@ -2666,6 +2685,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .inferred_alloc_const, .inferred_alloc_mut, .@"opaque", @@ -2747,6 +2767,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .inferred_alloc_const, .inferred_alloc_mut, .@"opaque", @@ -2825,6 +2846,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .inferred_alloc_const, .inferred_alloc_mut, .@"opaque", @@ -2903,6 +2925,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .inferred_alloc_const, .inferred_alloc_mut, .@"opaque", @@ -2981,6 +3004,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .inferred_alloc_const, .inferred_alloc_mut, .@"opaque", @@ -3046,7 +3070,7 @@ pub const Type = extern union { .var_args_param, => return null, - .empty_struct => return Value.initTag(.empty_struct_value), + .empty_struct, .empty_struct_literal => return Value.initTag(.empty_struct_value), .void => return Value.initTag(.void_value), .noreturn => return Value.initTag(.unreachable_value), .@"null" => return Value.initTag(.null_value), @@ -3149,6 +3173,7 @@ pub const Type = extern union { .error_set, .error_set_single, .empty_struct, + .empty_struct_literal, .inferred_alloc_const, .inferred_alloc_mut, .@"opaque", @@ -3241,6 +3266,7 @@ pub const Type = extern union { .inferred_alloc_const, .inferred_alloc_mut, .var_args_param, + .empty_struct_literal, => unreachable, .empty_struct => self.castTag(.empty_struct).?.data, @@ -3361,6 +3387,8 @@ pub const Type = extern union { /// This is a special type for variadic parameters of a function call. /// Casts to it will validate that the type can be passed to a c calling convetion function. var_args_param, + /// Same as `empty_struct` except it has an empty namespace. + empty_struct_literal, /// This is a special value that tracks a set of types that have been stored /// to an inferred allocation. It does not support most of the normal type queries. /// However it does respond to `isConstPtr`, `ptrSize`, `zigTypeTag`, etc. @@ -3445,6 +3473,7 @@ pub const Type = extern union { .inferred_alloc_const, .inferred_alloc_mut, .var_args_param, + .empty_struct_literal, => @compileError("Type Tag " ++ @tagName(t) ++ " has no payload"), .array_u8, -- cgit v1.2.3