aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-01-11 16:20:32 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-01-11 16:25:21 -0700
commit29c9d5896c0f3349b37eff4cbce280fffa7e2924 (patch)
tree82aebe8095bc7dcafc6cca525b14ab82c5382278 /src/type.zig
parent5cc2e500e68a60cb99b48755af39856ff60198b6 (diff)
parentbace1181b2f6d63e51b6e511aa8318481e2eafee (diff)
downloadzig-29c9d5896c0f3349b37eff4cbce280fffa7e2924.tar.gz
zig-29c9d5896c0f3349b37eff4cbce280fffa7e2924.zip
Merge branch 'Stage2 begin implementing container types'
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig142
1 files changed, 140 insertions, 2 deletions
diff --git a/src/type.zig b/src/type.zig
index 9e2cd321f0..be61f57c1d 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -49,7 +49,7 @@ pub const Type = extern union {
.c_longdouble,
=> return .Float,
- .c_void => return .Opaque,
+ .c_void, .@"opaque" => return .Opaque,
.bool => return .Bool,
.void => return .Void,
.type => return .Type,
@@ -92,7 +92,9 @@ pub const Type = extern union {
.anyframe_T, .@"anyframe" => return .AnyFrame,
- .empty_struct => return .Struct,
+ .@"struct", .empty_struct => return .Struct,
+ .@"enum" => return .Enum,
+ .@"union" => return .Union,
}
}
@@ -470,6 +472,11 @@ pub const Type = extern union {
.error_set => return self.copyPayloadShallow(allocator, Payload.Decl),
.error_set_single => return self.copyPayloadShallow(allocator, Payload.Name),
.empty_struct => return self.copyPayloadShallow(allocator, Payload.ContainerScope),
+
+ .@"enum" => return self.copyPayloadShallow(allocator, Payload.Enum),
+ .@"struct" => return self.copyPayloadShallow(allocator, Payload.Struct),
+ .@"union" => return self.copyPayloadShallow(allocator, Payload.Union),
+ .@"opaque" => return self.copyPayloadShallow(allocator, Payload.Opaque),
}
}
@@ -695,6 +702,11 @@ pub const Type = extern union {
},
.inferred_alloc_const => return out_stream.writeAll("(inferred_alloc_const)"),
.inferred_alloc_mut => return out_stream.writeAll("(inferred_alloc_mut)"),
+ // TODO use declaration name
+ .@"enum" => return out_stream.writeAll("enum {}"),
+ .@"struct" => return out_stream.writeAll("struct {}"),
+ .@"union" => return out_stream.writeAll("union {}"),
+ .@"opaque" => return out_stream.writeAll("opaque {}"),
}
unreachable;
}
@@ -803,6 +815,10 @@ pub const Type = extern union {
return payload.error_set.hasCodeGenBits() or payload.payload.hasCodeGenBits();
},
+ .@"enum" => @panic("TODO"),
+ .@"struct" => @panic("TODO"),
+ .@"union" => @panic("TODO"),
+
.c_void,
.void,
.type,
@@ -813,6 +829,7 @@ pub const Type = extern union {
.@"undefined",
.enum_literal,
.empty_struct,
+ .@"opaque",
=> false,
.inferred_alloc_const => unreachable,
@@ -924,6 +941,10 @@ pub const Type = extern union {
@panic("TODO abiAlignment error union");
},
+ .@"enum" => self.cast(Payload.Enum).?.abiAlignment(target),
+ .@"struct" => @panic("TODO"),
+ .@"union" => @panic("TODO"),
+
.c_void,
.void,
.type,
@@ -936,6 +957,7 @@ pub const Type = extern union {
.empty_struct,
.inferred_alloc_const,
.inferred_alloc_mut,
+ .@"opaque",
=> unreachable,
};
}
@@ -961,6 +983,7 @@ pub const Type = extern union {
.empty_struct => unreachable,
.inferred_alloc_const => unreachable,
.inferred_alloc_mut => unreachable,
+ .@"opaque" => unreachable,
.u8,
.i8,
@@ -1067,6 +1090,10 @@ pub const Type = extern union {
}
@panic("TODO abiSize error union");
},
+
+ .@"enum" => @panic("TODO"),
+ .@"struct" => @panic("TODO"),
+ .@"union" => @panic("TODO"),
};
}
@@ -1134,6 +1161,10 @@ pub const Type = extern union {
.error_set,
.error_set_single,
.empty_struct,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> false,
.single_const_pointer,
@@ -1205,6 +1236,10 @@ pub const Type = extern union {
.error_set,
.error_set_single,
.empty_struct,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> unreachable,
.const_slice,
@@ -1297,6 +1332,10 @@ pub const Type = extern union {
.empty_struct,
.inferred_alloc_const,
.inferred_alloc_mut,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> false,
.const_slice,
@@ -1371,6 +1410,10 @@ pub const Type = extern union {
.empty_struct,
.inferred_alloc_const,
.inferred_alloc_mut,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> false,
.single_const_pointer,
@@ -1454,6 +1497,10 @@ pub const Type = extern union {
.empty_struct,
.inferred_alloc_const,
.inferred_alloc_mut,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> false,
.pointer => {
@@ -1532,6 +1579,10 @@ pub const Type = extern union {
.empty_struct,
.inferred_alloc_const,
.inferred_alloc_mut,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> false,
.pointer => {
@@ -1652,6 +1703,10 @@ pub const Type = extern union {
.empty_struct => unreachable,
.inferred_alloc_const => unreachable,
.inferred_alloc_mut => unreachable,
+ .@"enum" => unreachable,
+ .@"struct" => unreachable,
+ .@"union" => unreachable,
+ .@"opaque" => unreachable,
.array => self.castTag(.array).?.data.elem_type,
.array_sentinel => self.castTag(.array_sentinel).?.data.elem_type,
@@ -1775,6 +1830,10 @@ pub const Type = extern union {
.empty_struct,
.inferred_alloc_const,
.inferred_alloc_mut,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> unreachable,
.array => self.castTag(.array).?.data.len,
@@ -1843,6 +1902,10 @@ pub const Type = extern union {
.empty_struct,
.inferred_alloc_const,
.inferred_alloc_mut,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> unreachable,
.single_const_pointer,
@@ -1928,6 +1991,10 @@ pub const Type = extern union {
.empty_struct,
.inferred_alloc_const,
.inferred_alloc_mut,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> false,
.int_signed,
@@ -2005,6 +2072,10 @@ pub const Type = extern union {
.empty_struct,
.inferred_alloc_const,
.inferred_alloc_mut,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> false,
.int_unsigned,
@@ -2072,6 +2143,10 @@ pub const Type = extern union {
.empty_struct,
.inferred_alloc_const,
.inferred_alloc_mut,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> unreachable,
.int_unsigned => .{
@@ -2163,6 +2238,10 @@ pub const Type = extern union {
.empty_struct,
.inferred_alloc_const,
.inferred_alloc_mut,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> false,
.usize,
@@ -2277,6 +2356,10 @@ pub const Type = extern union {
.empty_struct,
.inferred_alloc_const,
.inferred_alloc_mut,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> unreachable,
};
}
@@ -2357,6 +2440,10 @@ pub const Type = extern union {
.empty_struct,
.inferred_alloc_const,
.inferred_alloc_mut,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> unreachable,
}
}
@@ -2436,6 +2523,10 @@ pub const Type = extern union {
.empty_struct,
.inferred_alloc_const,
.inferred_alloc_mut,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> unreachable,
}
}
@@ -2515,6 +2606,10 @@ pub const Type = extern union {
.empty_struct,
.inferred_alloc_const,
.inferred_alloc_mut,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> unreachable,
};
}
@@ -2591,6 +2686,10 @@ pub const Type = extern union {
.empty_struct,
.inferred_alloc_const,
.inferred_alloc_mut,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> unreachable,
};
}
@@ -2667,6 +2766,10 @@ pub const Type = extern union {
.empty_struct,
.inferred_alloc_const,
.inferred_alloc_mut,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> unreachable,
};
}
@@ -2743,6 +2846,10 @@ pub const Type = extern union {
.empty_struct,
.inferred_alloc_const,
.inferred_alloc_mut,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> false,
};
}
@@ -2800,8 +2907,13 @@ pub const Type = extern union {
.error_union,
.error_set,
.error_set_single,
+ .@"opaque",
=> return null,
+ .@"enum" => @panic("TODO onePossibleValue enum"),
+ .@"struct" => @panic("TODO onePossibleValue struct"),
+ .@"union" => @panic("TODO onePossibleValue union"),
+
.empty_struct => return Value.initTag(.empty_struct_value),
.void => return Value.initTag(.void_value),
.noreturn => return Value.initTag(.unreachable_value),
@@ -2907,6 +3019,10 @@ pub const Type = extern union {
.empty_struct,
.inferred_alloc_const,
.inferred_alloc_mut,
+ .@"enum",
+ .@"struct",
+ .@"union",
+ .@"opaque",
=> return false,
.c_const_pointer,
@@ -2997,6 +3113,10 @@ pub const Type = extern union {
=> unreachable,
.empty_struct => self.castTag(.empty_struct).?.data,
+ .@"enum" => &self.castTag(.@"enum").?.scope,
+ .@"struct" => &self.castTag(.@"struct").?.scope,
+ .@"union" => &self.castTag(.@"union").?.scope,
+ .@"opaque" => &self.castTag(.@"opaque").?.scope,
};
}
@@ -3137,6 +3257,10 @@ pub const Type = extern union {
error_set,
error_set_single,
empty_struct,
+ @"enum",
+ @"struct",
+ @"union",
+ @"opaque",
pub const last_no_payload_tag = Tag.inferred_alloc_const;
pub const no_payload_count = @enumToInt(last_no_payload_tag) + 1;
@@ -3219,6 +3343,10 @@ pub const Type = extern union {
.error_set => Payload.Decl,
.error_set_single => Payload.Name,
.empty_struct => Payload.ContainerScope,
+ .@"enum" => Payload.Enum,
+ .@"struct" => Payload.Struct,
+ .@"union" => Payload.Union,
+ .@"opaque" => Payload.Opaque,
};
}
@@ -3332,6 +3460,16 @@ pub const Type = extern union {
base: Payload,
data: *Module.Scope.Container,
};
+
+ pub const Opaque = struct {
+ base: Payload = .{ .tag = .@"opaque" },
+
+ scope: Module.Scope.Container,
+ };
+
+ pub const Enum = @import("type/Enum.zig");
+ pub const Struct = @import("type/Struct.zig");
+ pub const Union = @import("type/Union.zig");
};
};