aboutsummaryrefslogtreecommitdiff
path: root/src/type/Struct.zig
blob: d6a591c95ea333361fcd63844273fd1648561d73 (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
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 Struct = @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: *Struct, mod: *Module, scope: *Scope) !void {
    const zir = switch (self.analysis) {
        .failed => return error.AnalysisFail,
        .zero_bits_in_progress => {
            return mod.fail(scope, src, "struct '{}' depends on itself", .{});
        },
        .queued => |zir| zir,
        else => return,
    };

    self.analysis = .zero_bits_in_progress;

    // TODO
}