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 Function

getUnionDecl

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

Params

File

zig/Zir.zig:5421
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
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_column = extra.data.src_column,
        .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,
    };
}