Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Struct

SwitchBlock

Public Struct
std.zig.Zir.Inst.SwitchBlock
pub const SwitchBlock = struct

Trailing:

  1. multi_cases_len: u32, // If has_multi_cases is set.
  2. payload_capture_placeholder: Inst.Index, // If payload_capture_inst_is_placeholder is set. // Index of instruction prongs use to refer to their payload capture.
  3. tag_capture_placeholder: Inst.Index, // If tag_capture_inst_is_placeholder is set. // Index of instruction prongs use to refer to their tag capture.
  4. catch_or_if_src_node_offset: Ast.Node.Offset, // If inst is switch_block_err_union.
  5. non_err_info: ProngInfo.NonErr, // If inst is switch_block_err_union.
  6. else_info: ProngInfo.Else, // If has_else is set.
  7. scalar_prong_info: ProngInfo, // for every scalar_cases_len
  8. multi_prong_info: ProngInfo, // for every multi_cases_len
  9. multi_case_items_len: u32, // for every multi_cases_len
  10. multi_case_ranges_len: u32, // If has_ranges is set: for every multi_cases_len
  11. scalar_item_info: ItemInfo, // for every scalar_cases_len
  12. multi_items_info: { // for every multi_cases_len item_info: ItemInfo, // for each multi_case_items_len range_items_info: { // for each multi_case_ranges_len first_info: ItemInfo, last_info: ItemInfo, } }
  13. non_err_body { body_inst: Index // for every non_err_info.body_len }
  14. else_body: { // If has_else is set. body_inst: Inst.Index, // for every else_info.body_len }
  15. scalar_bodies: { // for every scalar_cases_len prong_body: { // for each body_len in scalar_prong_info body_inst: Inst.Index, // for every body_len } item_body: { // for each body_len in scalar_item_info body_inst: Inst.Index, // for every body_len } }
  16. multi_bodies: { // for each multi_items_info prong_body: { body_inst: Inst.Index, // for each multi_prong_info.body_len } item_body: { // for each item_info body_inst: Inst.Index, // for every item_info.body_len } range_bodies: { // for each .{first_info, last_info} in range_items_info first_body_inst: Inst.Index, // for every first_info.body_len last_body_inst: Inst.Index, // for every last_info.body_len } }

Fields

raw_operand: Ref

Either catch/if or switch operand.

bits: Bits

Structs

File

zig/Zir.zig:3372
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
    pub const SwitchBlock = struct {
        /// Either `catch`/`if` or `switch` operand.
        raw_operand: Ref,
        bits: Bits,

        pub const Bits = packed struct(u32) {
            /// If true, one or more prongs have multiple items.
            has_multi_cases: bool,
            /// If true, one or more prongs have ranges.
            /// Only valid if `has_multi_cases` is also set.
            any_ranges: bool,
            has_else: bool,
            has_under: bool,
            /// If true, at least one prong contains a `continue`.
            /// Only valid if `has_label` is set.
            has_continue: bool,
            // If true, at least one prong has a non-inline payload/tag capture.
            any_maybe_runtime_capture: bool,
            payload_capture_inst_is_placeholder: bool,
            tag_capture_inst_is_placeholder: bool,
            scalar_cases_len: ScalarCasesLen,

            // NOTE maybe don't steal any more bits from poor `scalar_cases_len`
            // and split `Bits` into two parts instead, `raw_operand` surely
            // wouldn't mind donating a couple of bits for that purpose...
            pub const ScalarCasesLen = u24;
        };

        pub const ProngInfo = packed struct(u32) {
            body_len: u27,
            capture: ProngInfo.Capture,
            is_inline: bool,
            has_tag_capture: bool,
            is_comptime_unreach: bool,

            pub const Capture = enum(u2) {
                none,
                by_val,
                by_ref,
            };

            pub const NonErr = packed struct(u32) {
                body_len: u29,
                capture: ProngInfo.Capture,
                operand_is_ref: bool,
            };

            pub const Else = packed struct(u32) {
                body_len: u27,
                capture: ProngInfo.Capture,
                is_inline: bool,
                has_tag_capture: bool,
                is_simple_noreturn: bool,
            };
        };

        pub const ItemInfo = packed struct(u32) {
            kind: ItemInfo.Kind,
            data: u30,

            pub const Kind = enum(u2) {
                enum_literal,
                error_value,
                body_len,
                under,
            };

            pub const Unwrapped = union(ItemInfo.Kind) {
                enum_literal: Zir.NullTerminatedString,
                error_value: Zir.NullTerminatedString,
                body_len: u32,
                under,
            };

            pub fn wrap(unwrapped: ItemInfo.Unwrapped) ItemInfo {
                const data_uncasted: u32 = switch (unwrapped) {
                    .enum_literal => |str_index| @backingInt(str_index),
                    .error_value => |str_index| @backingInt(str_index),
                    .body_len => |body_len| body_len,
                    .under => 0,
                };
                return .{ .kind = unwrapped, .data = @intCast(data_uncasted) };
            }

            pub fn unwrap(item_info: ItemInfo) ItemInfo.Unwrapped {
                return switch (item_info.kind) {
                    .enum_literal => .{ .enum_literal = @fromBackingInt(@intCast(item_info.data)) },
                    .error_value => .{ .error_value = @fromBackingInt(@intCast(item_info.data)) },
                    .body_len => .{ .body_len = item_info.data },
                    .under => .under,
                };
            }

            pub fn bodyLen(item_info: ItemInfo) ?u32 {
                return if (item_info.kind == .body_len) item_info.data else null;
            }
        };
    }