aboutsummaryrefslogtreecommitdiff
path: root/src/type/Union.zig
diff options
context:
space:
mode:
authorVexu <git@vexu.eu>2020-11-15 13:03:48 +0200
committerVexu <git@vexu.eu>2020-11-15 13:03:48 +0200
commitf173d078c780c9946742c4ce686ccd0dccdb7e98 (patch)
tree47cf88dce1e9f9d4db80290aec4ff5234845defb /src/type/Union.zig
parent643f526cd121173b4102ce3a07ee9bb4a1582cc2 (diff)
downloadzig-f173d078c780c9946742c4ce686ccd0dccdb7e98.tar.gz
zig-f173d078c780c9946742c4ce686ccd0dccdb7e98.zip
stage2: outline container types
Diffstat (limited to 'src/type/Union.zig')
-rw-r--r--src/type/Union.zig57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/type/Union.zig b/src/type/Union.zig
new file mode 100644
index 0000000000..bb1fe56995
--- /dev/null
+++ b/src/type/Union.zig
@@ -0,0 +1,57 @@
+const std = @import("std");
+const Value = @import("../value.zig").Value;
+const Type = @import("../type.zig").Type;
+const Module = @import("../Module.zig");
+const Scope = Module.Scope;
+
+base: Type.Payload = .{ .tag = .@"struct" },
+
+analysis: union(enum) {
+ queued: Zir,
+ zero_bits_in_progress,
+ zero_bits: Zero,
+ in_progress,
+ alignment: Align,
+ resolved: Size,
+ failed,
+},
+scope: Scope.Container,
+
+pub const Field = struct {
+ value: Value,
+};
+
+pub const Zir = struct {
+ body: zir.Module.Body,
+ inst: *zir.Inst,
+ arena: std.heap.ArenaAllocator.State,
+};
+
+pub const Zero = struct {
+ is_zero_bits: bool,
+ fields: std.AutoArrayHashMap([]const u8, Field),
+};
+
+pub const Size = struct {
+ is_zero_bits: bool,
+ alignment: u32,
+ size: u32,
+ fields: std.AutoArrayHashMap([]const u8, Field),
+};
+
+pub fn resolveZeroBits(self: *Enum, mod: *Module, scope: *Scope) !void {
+ const zir = switch (self.analysis) {
+ .failed => return error.AnalysisFail,
+ .zero_bits_in_progress => {
+ return mod.fail(scope, src, "union '{}' depends on itself", .{});
+ },
+ .queued => |zir| zir,
+ else => return,
+ };
+
+ self.analysis = .zero_bits_in_progress;
+
+ // TODO
+}
+
+pub fn resolveSize(self: *Enum,) \ No newline at end of file