fn nameStratExpr(
gz: *GenZir,
scope: *Scope,
ri: ResultInfo,
node: Ast.Node.Index,
name_strat: Zir.Inst.NameStrategy,
) InnerError!?Zir.Inst.Ref {
const astgen = gz.astgen;
const tree = astgen.tree;
switch (tree.nodeTag(node)) {
.container_decl,
.container_decl_trailing,
.container_decl_two,
.container_decl_two_trailing,
.container_decl_arg,
.container_decl_arg_trailing,
.tagged_union,
.tagged_union_trailing,
.tagged_union_two,
.tagged_union_two_trailing,
.tagged_union_enum_tag,
.tagged_union_enum_tag_trailing,
=> {
var buf: [2]Ast.Node.Index = undefined;
return try containerDecl(gz, scope, ri, node, tree.fullContainerDecl(&buf, node).?, name_strat);
},
.builtin_call_two,
.builtin_call_two_comma,
.builtin_call,
.builtin_call_comma,
=> {
const builtin_token = tree.nodeMainToken(node);
const builtin_name = tree.tokenSlice(builtin_token);
const info = BuiltinFn.list.get(builtin_name) orelse return null;
switch (info.tag) {
.Enum, .Struct, .Union => {
var buf: [2]Ast.Node.Index = undefined;
const params = tree.builtinCallParams(&buf, node).?;
return try builtinCall(gz, scope, ri, node, params, false, name_strat);
},
else => return null,
}
},
else => return null,
}
}
When a name strategy other than
.anonis available, for instance when analyzing the init expr of a variable declaration, try this function beforeexpr/comptimeExpr/etc, so that the name strategy can be applied if necessary. Ifnullis returned, thennodedoes not consume a name strategy, and a normal evaluation function likeexprshould be used instead. Otherwise,nodedoes consume a name strategy; the expression has been evaluated likeexpr, but using the given name strategy.