feature. See also
. The project being documented here (as the example) is the Zig library itself.
AstGen.arrayTypeSentinel
fn arrayTypeSentinel(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) !Zir.Inst.Ref
File
Code
fn arrayTypeSentinel(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) !Zir.Inst.Ref {
const astgen = gz.astgen;
const tree = astgen.tree;
const len_node, const extra_index = tree.nodeData(node).node_and_extra;
const extra = tree.extraData(extra_index, Ast.Node.ArrayTypeSentinel);
if (tree.nodeTag(len_node) == .identifier and
mem.eql(u8, tree.tokenSlice(tree.nodeMainToken(len_node)), "_"))
{
return astgen.failNode(len_node, "unable to infer array size", .{});
}
const len = try reachableExprComptime(gz, scope, .{ .rl = .{ .coerced_ty = .usize_type } }, len_node, node, .array_length);
const elem_type = try typeExpr(gz, scope, extra.elem_type);
const sentinel = try reachableExprComptime(gz, scope, .{ .rl = .{ .coerced_ty = elem_type } }, extra.sentinel, node, .array_sentinel);
const result = try gz.addPlNode(.array_type_sentinel, node, Zir.Inst.ArrayTypeSentinel{
.len = len,
.elem_type = elem_type,
.sentinel = sentinel,
});
return rvalue(gz, ri, result, node);
}