feature. See also
. The project being documented here (as the example) is the Zig library itself.
Interner.get
pub fn get(i: *const Interner, ref: Ref) Key
File
Code
pub fn get(i: *const Interner, ref: Ref) Key {
switch (ref) {
.ptr => return .ptr_ty,
.func => return .func_ty,
.noreturn => return .noreturn_ty,
.void => return .void_ty,
.i1 => return .{ .int_ty = 1 },
.i8 => return .{ .int_ty = 8 },
.i16 => return .{ .int_ty = 16 },
.i32 => return .{ .int_ty = 32 },
.i64 => return .{ .int_ty = 64 },
.i128 => return .{ .int_ty = 128 },
.f16 => return .{ .float_ty = 16 },
.f32 => return .{ .float_ty = 32 },
.f64 => return .{ .float_ty = 64 },
.f80 => return .{ .float_ty = 80 },
.f128 => return .{ .float_ty = 128 },
.zero => return .{ .int = .{ .u64 = 0 } },
.one => return .{ .int = .{ .u64 = 1 } },
.null => return .null,
.cf16 => return .{ .complex_ty = 16 },
.cf32 => return .{ .complex_ty = 32 },
.cf64 => return .{ .complex_ty = 64 },
.cf80 => return .{ .complex_ty = 80 },
else => {},
}
const item = i.items.get(@backingInt(ref));
const data = item.data;
return switch (item.tag) {
.int_ty => .{ .int_ty = @intCast(data) },
.float_ty => .{ .float_ty = @intCast(data) },
.complex_ty => .{ .complex_ty = @intCast(data) },
.array_ty => {
const array_ty = i.extraData(Tag.Array, data);
return .{ .array_ty = .{
.len = array_ty.getLen(),
.child = array_ty.child,
} };
},
.vector_ty => {
const vector_ty = i.extraData(Tag.Vector, data);
return .{ .vector_ty = .{
.len = vector_ty.len,
.child = vector_ty.child,
} };
},
.pointer => {
const pointer = i.extraData(Tag.Pointer, data);
return .{ .pointer = .{
.node = pointer.node,
.offset = pointer.offset,
} };
},
.u32 => .{ .int = .{ .u64 = data } },
.i32 => .{ .int = .{ .i64 = @as(i32, @bitCast(data)) } },
.int_positive, .int_negative => {
const int_info = i.extraData(Tag.Int, data);
const limbs = i.limbs.items[int_info.limbs_index..][0..int_info.limbs_len];
return .{ .int = .{
.big_int = .{
.positive = item.tag == .int_positive,
.limbs = limbs,
},
} };
},
.f16 => .{ .float = .{ .f16 = @bitCast(@as(u16, @intCast(data))) } },
.f32 => .{ .float = .{ .f32 = @bitCast(data) } },
.f64 => {
const float = i.extraData(Tag.F64, data);
return .{ .float = .{ .f64 = float.get() } };
},
.f80 => {
const float = i.extraData(Tag.F80, data);
return .{ .float = .{ .f80 = float.get() } };
},
.f128 => {
const float = i.extraData(Tag.F128, data);
return .{ .float = .{ .f128 = float.get() } };
},
.cf16 => {
const components = i.extraData(Tag.CF16, data);
return .{ .complex = .{ .cf16 = components.get() } };
},
.cf32 => {
const components = i.extraData(Tag.CF32, data);
return .{ .complex = .{ .cf32 = components.get() } };
},
.cf64 => {
const components = i.extraData(Tag.CF64, data);
return .{ .complex = .{ .cf64 = components.get() } };
},
.cf80 => {
const components = i.extraData(Tag.CF80, data);
return .{ .complex = .{ .cf80 = components.get() } };
},
.cf128 => {
const components = i.extraData(Tag.CF128, data);
return .{ .complex = .{ .cf128 = components.get() } };
},
.bytes => {
const bytes = i.extraData(Tag.Bytes, data);
return .{ .bytes = i.strings.items[bytes.strings_index..][0..bytes.len] };
},
.record_ty => {
const extra = i.extraDataTrail(Tag.Record, data);
return .{
.record_ty = @ptrCast(i.extra.items[extra.end..][0..extra.data.elements_len]),
};
},
};
}