Factor param/arg ref logic to a class. (#3728)

Just segmenting out a chunk of logic while I'm thinking about function
parameters.
This commit is contained in:
Jon Ross-Perkins
2024-02-27 19:58:19 +00:00
committed by GitHub
parent 85ce06f854
commit 2fee4d072f
10 changed files with 138 additions and 95 deletions
+9 -9
View File
@@ -13,22 +13,22 @@ auto HandleCallExprStart(Context& context, Parse::CallExprStartId parse_node)
-> bool {
auto name_id = context.node_stack().PopExpr();
context.node_stack().Push(parse_node, name_id);
context.ParamOrArgStart();
context.param_and_arg_refs_stack().Push();
return true;
}
auto HandleCallExprComma(Context& context,
Parse::CallExprCommaId /*parse_node*/) -> bool {
context.ParamOrArgComma();
context.param_and_arg_refs_stack().ApplyComma();
return true;
}
auto HandleCallExpr(Context& context, Parse::CallExprId parse_node) -> bool {
// Process the final explicit call argument now, but leave the arguments
// block on the stack until the end of this function.
context.ParamOrArgEndNoPop(Parse::NodeKind::CallExprStart);
context.param_and_arg_refs_stack().EndNoPop(Parse::NodeKind::CallExprStart);
auto discard_args_block = llvm::make_scope_exit(
[&] { context.params_or_args_stack().PopAndDiscard(); });
[&] { context.param_and_arg_refs_stack().PopAndDiscard(); });
auto [call_expr_parse_node, callee_id] =
context.node_stack().PopWithParseNode<Parse::NodeKind::CallExprStart>();
@@ -87,11 +87,11 @@ auto HandleCallExpr(Context& context, Parse::CallExprId parse_node) -> bool {
}
// Convert the arguments to match the parameters.
auto converted_args_id =
ConvertCallArgs(context, call_expr_parse_node, self_id,
context.params_or_args_stack().PeekCurrentBlockContents(),
return_storage_id, function_decl_id.inst_id(),
callable.implicit_param_refs_id, callable.param_refs_id);
auto converted_args_id = ConvertCallArgs(
context, call_expr_parse_node, self_id,
context.param_and_arg_refs_stack().PeekCurrentBlockContents(),
return_storage_id, function_decl_id.inst_id(),
callable.implicit_param_refs_id, callable.param_refs_id);
auto call_inst_id =
context.AddInst({call_expr_parse_node,
SemIR::Call{type_id, callee_id, converted_args_id}});