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 -6
View File
@@ -9,15 +9,17 @@ namespace Carbon::Check {
auto HandleExprOpenParen(Context& context, Parse::ExprOpenParenId parse_node)
-> bool {
context.node_stack().Push(parse_node);
context.ParamOrArgStart();
context.param_and_arg_refs_stack().Push();
return true;
}
auto HandleParenExpr(Context& context, Parse::ParenExprId parse_node) -> bool {
auto value_id = context.node_stack().PopExpr();
// ParamOrArgStart was called for tuple handling; clean up the ParamOrArg
// support for non-tuple cases.
context.ParamOrArgEnd(Parse::NodeKind::ExprOpenParen);
// This always is always pushed at the open paren. It's only used for tuples,
// not paren exprs, but we still need to clean up.
context.param_and_arg_refs_stack().PopAndDiscard();
context.node_stack()
.PopAndDiscardSoloParseNode<Parse::NodeKind::ExprOpenParen>();
context.node_stack().Push(parse_node, value_id);
@@ -27,13 +29,14 @@ auto HandleParenExpr(Context& context, Parse::ParenExprId parse_node) -> bool {
auto HandleTupleLiteralComma(Context& context,
Parse::TupleLiteralCommaId /*parse_node*/)
-> bool {
context.ParamOrArgComma();
context.param_and_arg_refs_stack().ApplyComma();
return true;
}
auto HandleTupleLiteral(Context& context, Parse::TupleLiteralId parse_node)
-> bool {
auto refs_id = context.ParamOrArgEnd(Parse::NodeKind::ExprOpenParen);
auto refs_id = context.param_and_arg_refs_stack().EndAndPop(
Parse::NodeKind::ExprOpenParen);
context.node_stack()
.PopAndDiscardSoloParseNode<Parse::NodeKind::ExprOpenParen>();