Zig 0.17.0-dev (Split by item)

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 library itself.

getUnionDecl

Zir.getUnionDecl
pub fn getUnionDecl(zir: *const Zir, union_decl: Inst.Index) UnwrappedUnionDecl

File

lib/std/zig/Zir.zig:5411

Code

pub fn getUnionDecl(zir: *const Zir, union_decl: Inst.Index) UnwrappedUnionDecl {
    const inst_data = zir.instructions.get(@backingInt(union_decl));
    assert(inst_data.tag == .extended);
    assert(inst_data.data.extended.opcode == .union_decl);
    const small: Inst.UnionDecl.Small = @bitCast(inst_data.data.extended.small);
    const extra = zir.extraData(Inst.UnionDecl, inst_data.data.extended.operand);
    var extra_index = extra.end;
    const captures_len: u32 = if (small.has_captures_len) blk: {
        const captures_len = zir.extra[extra_index];
        extra_index += 1;
        break :blk captures_len;
    } else 0;
    const decls_len: u32 = if (small.has_decls_len) blk: {
        const decls_len = zir.extra[extra_index];
        extra_index += 1;
        break :blk decls_len;
    } else 0;
    const fields_len: u32 = if (small.has_fields_len) blk: {
        const fields_len = zir.extra[extra_index];
        extra_index += 1;
        break :blk fields_len;
    } else 0;
    const arg_type_body_len: u32 = if (small.kind.hasArgType()) len: {
        const body_len = zir.extra[extra_index];
        extra_index += 1;
        break :len body_len;
    } else 0;
    const captures: []const Inst.Capture = @ptrCast(zir.extra[extra_index..][0..captures_len]);
    extra_index += captures_len;
    const capture_names: []const NullTerminatedString = @ptrCast(zir.extra[extra_index..][0..captures_len]);
    extra_index += captures_len;
    const decls: []const Inst.Index = @ptrCast(zir.extra[extra_index..][0..decls_len]);
    extra_index += decls_len;
    const field_names: []const NullTerminatedString = @ptrCast(zir.extra[extra_index..][0..fields_len]);
    extra_index += fields_len;
    const field_type_body_lens: []const u32 = @ptrCast(zir.extra[extra_index..][0..fields_len]);
    extra_index += fields_len;
    const field_align_body_lens: ?[]const u32 = if (small.any_field_aligns) lens: {
        const lens = zir.extra[extra_index..][0..fields_len];
        extra_index += fields_len;
        break :lens @ptrCast(lens);
    } else null;
    const field_value_body_lens: ?[]const u32 = if (small.any_field_values) lens: {
        const lens = zir.extra[extra_index..][0..fields_len];
        extra_index += fields_len;
        break :lens @ptrCast(lens);
    } else null;
    const arg_type_body: ?[]const Zir.Inst.Index = switch (arg_type_body_len) {
        0 => null,
        else => |n| zir.bodySlice(extra_index, n),
    };
    extra_index += arg_type_body_len;
    const field_bodies_overlong: []const Inst.Index = @ptrCast(zir.extra[extra_index..]);
    return .{
        .src_line = extra.data.src_line,
        .src_node = extra.data.src_node,
        .name_strategy = small.name_strategy,
        .captures = captures,
        .capture_names = capture_names,
        .decls = decls,
        .kind = small.kind,
        .arg_type_body = arg_type_body,
        .field_names = field_names,
        .field_type_body_lens = field_type_body_lens,
        .field_align_body_lens = field_align_body_lens,
        .field_value_body_lens = field_value_body_lens,
        .field_bodies_overlong = field_bodies_overlong,
    };
}