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.

getEnumDecl

Zir.getEnumDecl
pub fn getEnumDecl(zir: *const Zir, enum_decl: Inst.Index) UnwrappedEnumDecl

File

lib/std/zig/Zir.zig:5545

Code

pub fn getEnumDecl(zir: *const Zir, enum_decl: Inst.Index) UnwrappedEnumDecl {
    const inst_data = zir.instructions.get(@backingInt(enum_decl));
    assert(inst_data.tag == .extended);
    assert(inst_data.data.extended.opcode == .enum_decl);
    const small: Inst.EnumDecl.Small = @bitCast(inst_data.data.extended.small);
    const extra = zir.extraData(Inst.EnumDecl, 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 tag_type_body_len: u32 = if (small.has_tag_type) 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_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 tag_type_body: ?[]const Zir.Inst.Index = switch (tag_type_body_len) {
        0 => null,
        else => |n| zir.bodySlice(extra_index, n),
    };
    extra_index += tag_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,
        .tag_type_body = tag_type_body,
        .nonexhaustive = small.nonexhaustive,
        .field_names = field_names,
        .field_value_body_lens = field_value_body_lens,
        .field_bodies_overlong = field_bodies_overlong,
    };
}