pub const UnwrappedSwitchBlock = struct main_operand: Inst.RefEither catch/if or switch operand.
switch_src_node_offset: Ast.Node.Offsetcatch_or_if_src_node_offset: Ast.Node.OptionalOffsetpayload_capture_placeholder: Inst.OptionalIndextag_capture_placeholder: Inst.OptionalIndexhas_continue: boolany_maybe_runtime_capture: boolnon_err_case: ?Case.NonErrelse_case: ?Case.Elsehas_under: boolprong_infos: []const Inst.SwitchBlock.ProngInfoRefer to doc comment and iterateCases to access everything below correctly.
multi_case_items_lens: []const u32multi_case_ranges_lens: ?[]const u32item_infos: []const Inst.SwitchBlock.ItemInfoend: usizepub fn anyRanges(unwrapped: *const UnwrappedSwitchBlock) boolpub fn scalarCasesLen(unwrapped: *const UnwrappedSwitchBlock) u32pub fn multiCasesLen(unwrapped: *const UnwrappedSwitchBlock) u32pub fn totalItemsLen(unwrapped: *const UnwrappedSwitchBlock) u32pub fn iterateCases(unwrapped: UnwrappedSwitchBlock) Case.Iterator5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213pub const UnwrappedSwitchBlock = struct {
/// Either `catch`/`if` or `switch` operand.
main_operand: Inst.Ref,
switch_src_node_offset: Ast.Node.Offset,
catch_or_if_src_node_offset: Ast.Node.OptionalOffset,
payload_capture_placeholder: Inst.OptionalIndex,
tag_capture_placeholder: Inst.OptionalIndex,
has_continue: bool,
any_maybe_runtime_capture: bool,
non_err_case: ?Case.NonErr,
else_case: ?Case.Else,
has_under: bool,
// Refer to doc comment and `iterateCases` to access everything below correctly.
prong_infos: []const Inst.SwitchBlock.ProngInfo,
multi_case_items_lens: []const u32,
multi_case_ranges_lens: ?[]const u32,
item_infos: []const Inst.SwitchBlock.ItemInfo,
end: usize,
pub fn anyRanges(unwrapped: *const UnwrappedSwitchBlock) bool {
return unwrapped.multi_case_ranges_lens != null;
}
pub fn scalarCasesLen(unwrapped: *const UnwrappedSwitchBlock) u32 {
return @intCast(unwrapped.prong_infos.len - unwrapped.multi_case_items_lens.len);
}
pub fn multiCasesLen(unwrapped: *const UnwrappedSwitchBlock) u32 {
return @intCast(unwrapped.multi_case_items_lens.len);
}
pub fn totalItemsLen(unwrapped: *const UnwrappedSwitchBlock) u32 {
var total_items_len: u32 = @intCast(unwrapped.item_infos.len);
if (unwrapped.multi_case_ranges_lens) |ranges_lens| {
for (ranges_lens) |len| total_items_len -= len;
}
return total_items_len;
}
pub const Case = struct {
index: Case.Index,
prong_info: Inst.SwitchBlock.ProngInfo,
item_infos: []const Inst.SwitchBlock.ItemInfo,
range_infos: []const [2]Inst.SwitchBlock.ItemInfo,
pub const Index = packed struct(u32) {
kind: enum(u1) { scalar, multi },
value: u31,
pub const @"else": Case.Index = .{
.kind = .scalar,
.value = std.math.maxInt(u31),
};
};
pub const NonErr = struct {
body: []const Inst.Index,
capture: Inst.SwitchBlock.ProngInfo.Capture,
operand_is_ref: bool,
};
pub const Else = struct {
index: Case.Index,
body: []const Inst.Index,
capture: Inst.SwitchBlock.ProngInfo.Capture,
is_inline: bool,
has_tag_capture: bool,
is_simple_noreturn: bool,
};
pub const Iterator = struct {
next_idx: u32,
prong_infos: []const Inst.SwitchBlock.ProngInfo,
multi_case_items_lens: []const u32,
multi_case_ranges_lens: ?[]const u32,
item_infos: []const Inst.SwitchBlock.ItemInfo,
pub fn next(it: *Iterator) ?Case {
const idx = it.next_idx;
if (idx == it.prong_infos.len) return null;
it.next_idx += 1;
const scalar_cases_len = it.prong_infos.len - it.multi_case_items_lens.len;
return if (idx < scalar_cases_len) .{
.index = .{
.kind = .scalar,
.value = @intCast(idx),
},
.prong_info = it.prong_infos[idx],
.item_infos = it.itemInfos(1),
.range_infos = &.{},
} else .{
.index = .{
.kind = .multi,
.value = @intCast(idx - scalar_cases_len),
},
.prong_info = it.prong_infos[idx],
.item_infos = it.itemInfos(it.multi_case_items_lens[idx - scalar_cases_len]),
.range_infos = if (it.multi_case_ranges_lens) |ranges_lens| b: {
break :b @ptrCast(it.itemInfos(2 * ranges_lens[idx - scalar_cases_len]));
} else &.{},
};
}
fn itemInfos(it: *Iterator, count: u32) []const Inst.SwitchBlock.ItemInfo {
const lens = it.item_infos[0..count];
it.item_infos = it.item_infos[count..];
return lens;
}
};
};
pub fn iterateCases(unwrapped: UnwrappedSwitchBlock) Case.Iterator {
return .{
.next_idx = 0,
.prong_infos = unwrapped.prong_infos,
.multi_case_items_lens = unwrapped.multi_case_items_lens,
.multi_case_ranges_lens = unwrapped.multi_case_ranges_lens,
.item_infos = unwrapped.item_infos,
};
}
}
Trailing (starting at
end):