Bladeren bron

Drop redundant parameter from ConsumeAndAddCloseSymbol (#6724)

Geoff Romer 2 maanden geleden
bovenliggende
commit
3719d200d6

+ 3 - 4
toolchain/parse/context.cpp

@@ -68,10 +68,9 @@ auto Context::ConsumeAndAddOpenParen(Lex::TokenIndex default_token,
   }
 }
 
-auto Context::ConsumeAndAddCloseSymbol(Lex::TokenIndex expected_open,
-                                       State state, NodeKind close_kind)
+auto Context::ConsumeAndAddCloseSymbol(State state, NodeKind close_kind)
     -> void {
-  Lex::TokenKind open_token_kind = tokens().GetKind(expected_open);
+  Lex::TokenKind open_token_kind = tokens().GetKind(state.token);
 
   if (!open_token_kind.is_opening_symbol()) {
     AddNode(close_kind, state.token, /*has_error=*/true);
@@ -85,7 +84,7 @@ auto Context::ConsumeAndAddCloseSymbol(Lex::TokenIndex expected_open,
     emitter_.Emit(*position_, ExpectedCloseSymbol,
                   open_token_kind.closing_symbol());
 
-    SkipTo(tokens().GetMatchedClosingToken(expected_open));
+    SkipTo(tokens().GetMatchedClosingToken(state.token));
     AddNode(close_kind, Consume(), /*has_error=*/true);
   }
 }

+ 6 - 7
toolchain/parse/context.h

@@ -196,13 +196,12 @@ class Context {
                               NodeKind start_kind)
       -> std::optional<Lex::TokenIndex>;
 
-  // Parses a closing symbol corresponding to the opening symbol
-  // `expected_open`, possibly skipping forward and diagnosing if necessary.
-  // Creates a parse node of the specified close kind. If `expected_open` is not
-  // an opening symbol, the parse node will be associated with `state.token`,
-  // no input will be consumed, and no diagnostic will be emitted.
-  auto ConsumeAndAddCloseSymbol(Lex::TokenIndex expected_open, State state,
-                                NodeKind close_kind) -> void;
+  // Parses a closing symbol corresponding to the opening symbol `state.token`,
+  // possibly skipping forward and diagnosing if necessary. Creates a parse node
+  // of the specified close kind. If `state.token` is not an opening symbol,
+  // no input will be consumed, and no diagnostic will be emitted, but the parse
+  // node will still be marked as having an error.
+  auto ConsumeAndAddCloseSymbol(State state, NodeKind close_kind) -> void;
 
   // Composes `ConsumeIf` and `AddLeafNode`, returning false when ConsumeIf
   // fails.

+ 1 - 2
toolchain/parse/handle_array_expr.cpp

@@ -41,8 +41,7 @@ auto HandleArrayExprComma(Context& context) -> void {
 
 auto HandleArrayExprFinish(Context& context) -> void {
   auto state = context.PopState();
-  context.ConsumeAndAddCloseSymbol(*(Lex::TokenIterator(state.token)), state,
-                                   NodeKind::ArrayExpr);
+  context.ConsumeAndAddCloseSymbol(state, NodeKind::ArrayExpr);
 }
 
 }  // namespace Carbon::Parse

+ 1 - 1
toolchain/parse/handle_form_literal.cpp

@@ -72,7 +72,7 @@ auto HandlePrimitiveFormFinish(Context& context) -> void {
 
 auto HandleFormLiteralFinish(Context& context) -> void {
   auto state = context.PopState();
-  context.ConsumeAndAddCloseSymbol(state.token, state, NodeKind::FormLiteral);
+  context.ConsumeAndAddCloseSymbol(state, NodeKind::FormLiteral);
 }
 
 }  // namespace Carbon::Parse

+ 1 - 1
toolchain/parse/handle_index_expr.cpp

@@ -20,7 +20,7 @@ auto HandleIndexExpr(Context& context) -> void {
 auto HandleIndexExprFinish(Context& context) -> void {
   auto state = context.PopState();
 
-  context.ConsumeAndAddCloseSymbol(state.token, state, NodeKind::IndexExpr);
+  context.ConsumeAndAddCloseSymbol(state, NodeKind::IndexExpr);
 }
 
 }  // namespace Carbon::Parse

+ 3 - 5
toolchain/parse/handle_paren_condition.cpp

@@ -49,21 +49,19 @@ auto HandleParenConditionAsMatch(Context& context) -> void {
 auto HandleParenConditionFinishAsIf(Context& context) -> void {
   auto state = context.PopState();
 
-  context.ConsumeAndAddCloseSymbol(state.token, state, NodeKind::IfCondition);
+  context.ConsumeAndAddCloseSymbol(state, NodeKind::IfCondition);
 }
 
 auto HandleParenConditionFinishAsWhile(Context& context) -> void {
   auto state = context.PopState();
 
-  context.ConsumeAndAddCloseSymbol(state.token, state,
-                                   NodeKind::WhileCondition);
+  context.ConsumeAndAddCloseSymbol(state, NodeKind::WhileCondition);
 }
 
 auto HandleParenConditionFinishAsMatch(Context& context) -> void {
   auto state = context.PopState();
 
-  context.ConsumeAndAddCloseSymbol(state.token, state,
-                                   NodeKind::MatchCondition);
+  context.ConsumeAndAddCloseSymbol(state, NodeKind::MatchCondition);
 }
 
 }  // namespace Carbon::Parse

+ 1 - 1
toolchain/parse/handle_statement.cpp

@@ -156,7 +156,7 @@ auto HandleStatementForHeaderIn(Context& context) -> void {
 auto HandleStatementForHeaderFinish(Context& context) -> void {
   auto state = context.PopState();
 
-  context.ConsumeAndAddCloseSymbol(state.token, state, NodeKind::ForHeader);
+  context.ConsumeAndAddCloseSymbol(state, NodeKind::ForHeader);
 
   context.PushState(StateKind::CodeBlock);
 }