feature. See also
. The project being documented here (as the example) is the Zig library itself.
AstGen.fnProtoExpr
fn fnProtoExpr(
gz: *GenZir,
scope: *Scope,
ri: ResultInfo,
node: Ast.Node.Index,
fn_proto: Ast.full.FnProto,
) InnerError!Zir.Inst.Ref
File
Code
fn fnProtoExpr(
gz: *GenZir,
scope: *Scope,
ri: ResultInfo,
node: Ast.Node.Index,
fn_proto: Ast.full.FnProto,
) InnerError!Zir.Inst.Ref {
const astgen = gz.astgen;
const tree = astgen.tree;
if (fn_proto.name_token) |some| {
return astgen.failTok(some, "function type cannot have a name", .{});
}
if (fn_proto.ast.align_expr.unwrap()) |align_expr| {
return astgen.failNode(align_expr, "function type cannot have an alignment", .{});
}
if (fn_proto.ast.addrspace_expr.unwrap()) |addrspace_expr| {
return astgen.failNode(addrspace_expr, "function type cannot have an addrspace", .{});
}
if (fn_proto.ast.section_expr.unwrap()) |section_expr| {
return astgen.failNode(section_expr, "function type cannot have a linksection", .{});
}
const return_type = fn_proto.ast.return_type.unwrap().?;
const maybe_bang = tree.firstToken(return_type) - 1;
const is_inferred_error = tree.tokenTag(maybe_bang) == .bang;
if (is_inferred_error) {
return astgen.failTok(maybe_bang, "function type cannot have an inferred error set", .{});
}
const is_extern = blk: {
const maybe_extern_token = fn_proto.extern_export_inline_token orelse break :blk false;
break :blk tree.tokenTag(maybe_extern_token) == .keyword_extern;
};
assert(!is_extern);
return fnProtoExprInner(gz, scope, ri, node, fn_proto, false);
}