aboutsummaryrefslogtreecommitdiff
path: root/src/type/Union.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/Union.zig
parent5cc2e500e68a60cb99b48755af39856ff60198b6 (diff)
parentbace1181b2f6d63e51b6e511aa8318481e2eafee (diff)
downloadzig-29c9d5896c0f3349b37eff4cbce280fffa7e2924.tar.gz
zig-29c9d5896c0f3349b37eff4cbce280fffa7e2924.zip
Merge branch 'Stage2 begin implementing container types'
Diffstat (limited to 'src/type/Union.zig')
-rw-r--r--src/type/Union.zig56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/type/Union.zig b/src/type/Union.zig
new file mode 100644
index 0000000000..26cc1796c6
--- /dev/null
+++ b/src/type/Union.zig
@@ -0,0 +1,56 @@
+const std = @import("std");
+const zir = @import("../zir.zig");
+const Value = @import("../value.zig").Value;
+const Type = @import("../type.zig").Type;
+const Module = @import("../Module.zig");
+const Scope = Module.Scope;
+const Union = @This();
+
+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,
+};
+
+pub const Zero = struct {
+ is_zero_bits: bool,
+ fields: std.StringArrayHashMapUnmanaged(Field),
+};
+
+pub const Size = struct {
+ is_zero_bits: bool,
+ alignment: u32,
+ size: u32,
+ fields: std.StringArrayHashMapUnmanaged(Field),
+};
+
+pub fn resolveZeroBits(self: *Union, 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
+}