Add PushState overload to combine Parse::State change with StateStackEntry (#3485)

Shortens a common `PushState` pattern
This commit is contained in:
josh11b
2023-12-08 23:58:30 +00:00
committed by GitHub
parent 6e65a30b5d
commit b7d129b88c
17 changed files with 47 additions and 87 deletions
+3 -6
View File
@@ -8,8 +8,7 @@ namespace Carbon::Parse {
auto HandleFunctionIntroducer(Context& context) -> void {
auto state = context.PopState();
state.state = State::FunctionAfterParams;
context.PushState(state);
context.PushState(state, State::FunctionAfterParams);
context.PushState(State::DeclNameAndParamsAsRequired, state.token);
}
@@ -17,8 +16,7 @@ auto HandleFunctionAfterParams(Context& context) -> void {
auto state = context.PopState();
// Regardless of whether there's a return type, we'll finish the signature.
state.state = State::FunctionSignatureFinish;
context.PushState(state);
context.PushState(state, State::FunctionSignatureFinish);
// If there is a return type, parse the expression before adding the return
// type node.
@@ -50,8 +48,7 @@ auto HandleFunctionSignatureFinish(Context& context) -> void {
state.subtree_start, state.has_error);
// Any error is recorded on the FunctionDefinitionStart.
state.has_error = false;
state.state = State::FunctionDefinitionFinish;
context.PushState(state);
context.PushState(state, State::FunctionDefinitionFinish);
context.PushState(State::StatementScopeLoop);
break;
}