aboutsummaryrefslogtreecommitdiff
path: root/src/type/Enum.zig
blob: 4dfd5f6e44fe160660ed3555f8b7c1bf19ff81fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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 Enum = @This();

base: Type.Payload = .{ .tag = .@"enum" },

analysis: union(enum) {
    queued: Zir,
    in_progress,
    resolved: Size,
    failed,
},
scope: Scope.Container,

pub const Field = struct {
    value: Value,
};

pub const Zir = struct {
    body: zir.Body,
    inst: *zir.Inst,
};

pub const Size = struct {
    tag_type: Type,
    fields: std.StringArrayHashMapUnmanaged(Field),
};

pub fn resolve(self: *Enum, mod: *Module, scope: *Scope) !void {
    const zir = switch (self.analysis) {
        .failed => return error.AnalysisFail,
        .resolved => return,
        .in_progress => {
            return mod.fail(scope, src, "enum '{}' depends on itself", .{enum_name});
        },
        .queued => |zir| zir,
    };
    self.analysis = .in_progress;

    // TODO
}

// TODO should this resolve the type or assert that it has already been resolved?
pub fn abiAlignment(self: *Enum, target: std.Target) u32 {
    switch (self.analysis) {
        .queued => unreachable, // alignment has not been resolved
        .in_progress => unreachable, // alignment has not been resolved
        .failed => unreachable, // type resolution failed
        .resolved => |r| return r.tag_type.abiAlignment(target),
    }
}