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

toAttribute

Public Function
std.zig.llvm.Builder.Attribute.Index.toAttribute
pub fn toAttribute(self: Index, builder: *const Builder) Attribute

Params

File

zig/llvm/Builder.zig:1861
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
        pub fn toAttribute(self: Index, builder: *const Builder) Attribute {
            @setEvalBranchQuota(2_000);
            const storage = self.toStorage(builder);
            if (storage.kind.toString()) |kind| return .{ .string = .{
                .kind = kind,
                .value = @fromBackingInt(storage.value),
            } } else return switch (storage.kind) {
                inline else => |kind| {
                    const field_name, const field_type = comptime blk: {
                        @setEvalBranchQuota(12_000);
                        const info = @typeInfo(Attribute).@"union";
                        for (info.field_names, info.field_types) |field_name, field_type| {
                            if (std.mem.eql(u8, field_name, @tagName(kind))) break :blk .{ field_name, field_type };
                        }
                        unreachable;
                    };
                    comptime assert(std.mem.eql(u8, @tagName(kind), field_name));
                    return @unionInit(Attribute, field_name, switch (field_type) {
                        void => {},
                        u32 => storage.value,
                        Alignment.Lazy, String, Type, UwTable => @fromBackingInt(storage.value),
                        AllocKind, AllocSize, Captures, FpClass, Memory, VScaleRange => @bitCast(storage.value),
                        else => @compileError("bad payload type: " ++ field_name ++ ": " ++
                            @typeName(field_type)),
                    });
                },
                .initializes,
                .dead_on_return,
                .range,
                => @panic("TODO"),
                .string, .none, _ => unreachable,
            };
        }