@@ -275,10 +275,8 @@ ParserResult<TypeRepr> Parser::parseSILBoxType(GenericParamList *generics,
275
275
return makeParserError ();
276
276
Fields.push_back ({VarOrLetLoc, Mutable, fieldTy.get ()});
277
277
278
- if (consumeIf (tok::comma))
279
- continue ;
280
-
281
- break ;
278
+ if (!consumeIf (tok::comma))
279
+ break ;
282
280
}
283
281
}
284
282
@@ -302,9 +300,8 @@ ParserResult<TypeRepr> Parser::parseSILBoxType(GenericParamList *generics,
302
300
if (!argTy.getPtrOrNull ())
303
301
return makeParserError ();
304
302
Args.push_back (argTy.get ());
305
- if (consumeIf (tok::comma))
306
- continue ;
307
- break ;
303
+ if (!consumeIf (tok::comma))
304
+ break ;
308
305
}
309
306
if (!startsWithGreater (Tok)) {
310
307
diagnose (Tok, diag::sil_box_expected_r_angle);
@@ -506,9 +503,8 @@ ParserResult<TypeRepr> Parser::parseType(Diag<> MessageID,
506
503
if (!argTy.getPtrOrNull ())
507
504
return false ;
508
505
SubsTypesVec.push_back (argTy.get ());
509
- if (consumeIf (tok::comma))
510
- continue ;
511
- break ;
506
+ if (!consumeIf (tok::comma))
507
+ break ;
512
508
}
513
509
if (!startsWithGreater (Tok)) {
514
510
diagnose (Tok, diag::sil_function_subst_expected_r_angle);
@@ -597,27 +593,31 @@ ParserResult<TypeRepr> Parser::parseDeclResultType(Diag<> MessageID) {
597
593
598
594
auto result = parseType (MessageID);
599
595
600
- if (!result.isParseErrorOrHasCompletion () && Tok.is (tok::r_square)) {
601
- auto diag = diagnose (Tok, diag::extra_rbracket);
602
- diag.fixItInsert (result.get ()->getStartLoc (), getTokenText (tok::l_square));
603
- consumeToken ();
604
- return makeParserErrorResult (new (Context)
605
- ErrorTypeRepr (getTypeErrorLoc ()));
606
- } else if (!result.isParseErrorOrHasCompletion () && Tok.is (tok::colon)) {
607
- auto colonTok = consumeToken ();
608
- auto secondType = parseType (diag::expected_dictionary_value_type);
609
-
610
- auto diag = diagnose (colonTok, diag::extra_colon);
611
- diag.fixItInsert (result.get ()->getStartLoc (), getTokenText (tok::l_square));
612
- if (!secondType.isParseErrorOrHasCompletion ()) {
613
- if (Tok.is (tok::r_square)) {
614
- consumeToken ();
615
- } else {
616
- diag.fixItInsertAfter (secondType.get ()->getEndLoc (), getTokenText (tok::r_square));
596
+ if (!result.isParseErrorOrHasCompletion ()) {
597
+ if (Tok.is (tok::r_square)) {
598
+ auto diag = diagnose (Tok, diag::extra_rbracket);
599
+ diag.fixItInsert (result.get ()->getStartLoc (), getTokenText (tok::l_square));
600
+ consumeToken ();
601
+ return makeParserErrorResult (new (Context)
602
+ ErrorTypeRepr (getTypeErrorLoc ()));
603
+ }
604
+
605
+ if (Tok.is (tok::colon)) {
606
+ auto colonTok = consumeToken ();
607
+ auto secondType = parseType (diag::expected_dictionary_value_type);
608
+
609
+ auto diag = diagnose (colonTok, diag::extra_colon);
610
+ diag.fixItInsert (result.get ()->getStartLoc (), getTokenText (tok::l_square));
611
+ if (!secondType.isParseErrorOrHasCompletion ()) {
612
+ if (Tok.is (tok::r_square)) {
613
+ consumeToken ();
614
+ } else {
615
+ diag.fixItInsertAfter (secondType.get ()->getEndLoc (), getTokenText (tok::r_square));
616
+ }
617
617
}
618
+ return makeParserErrorResult (new (Context)
619
+ ErrorTypeRepr (getTypeErrorLoc ()));
618
620
}
619
- return makeParserErrorResult (new (Context)
620
- ErrorTypeRepr (getTypeErrorLoc ()));
621
621
}
622
622
return result;
623
623
}
@@ -747,28 +747,26 @@ Parser::parseTypeIdentifier(bool isParsingQualifiedDeclBaseType) {
747
747
Status.setHasCodeCompletionAndIsError ();
748
748
break ;
749
749
}
750
- if (!peekToken ().isContextualKeyword (" Type" )
751
- && !peekToken ().isContextualKeyword (" Protocol" )) {
752
- // If parsing a qualified declaration name, break before parsing the
753
- // period before the final declaration name component.
754
- if (isParsingQualifiedDeclBaseType) {
755
- // If qualified name base type cannot be parsed from the current
756
- // point (i.e. the next type identifier is not followed by a '.'),
757
- // then the next identifier is the final declaration name component.
758
- BacktrackingScope backtrack (*this );
759
- consumeStartingCharacterOfCurrentToken (tok::period);
760
- if (!canParseBaseTypeForQualifiedDeclName ())
761
- break ;
762
- }
763
- // Consume the period.
764
- consumeToken ();
765
- continue ;
750
+ if (peekToken ().isContextualKeyword (" Type" ) ||
751
+ peekToken ().isContextualKeyword (" Protocol" ))
752
+ break ;
753
+ // If parsing a qualified declaration name, break before parsing the
754
+ // period before the final declaration name component.
755
+ if (isParsingQualifiedDeclBaseType) {
756
+ // If qualified name base type cannot be parsed from the current
757
+ // point (i.e. the next type identifier is not followed by a '.'),
758
+ // then the next identifier is the final declaration name component.
759
+ BacktrackingScope backtrack (*this );
760
+ consumeStartingCharacterOfCurrentToken (tok::period);
761
+ if (!canParseBaseTypeForQualifiedDeclName ())
762
+ break ;
766
763
}
767
- } else if (Tok.is (tok::code_complete)) {
768
- if (!Tok.isAtStartOfLine ())
769
- Status.setHasCodeCompletionAndIsError ();
770
- break ;
764
+ // Consume the period.
765
+ consumeToken ();
766
+ continue ;
771
767
}
768
+ if (Tok.is (tok::code_complete) && !Tok.isAtStartOfLine ())
769
+ Status.setHasCodeCompletionAndIsError ();
772
770
break ;
773
771
}
774
772
@@ -1322,13 +1320,14 @@ bool Parser::isOptionalToken(const Token &T) const {
1322
1320
// A postfix '?' by itself is obviously optional.
1323
1321
if (T.is (tok::question_postfix))
1324
1322
return true ;
1325
-
1326
1323
// A postfix or bound infix operator token that begins with '?' can be
1327
- // optional too. We'll munch off the '?', so long as it is left-bound with
1328
- // the type (i.e., parsed as a postfix or unspaced binary operator).
1329
- if ((T.is (tok::oper_postfix) || T.is (tok::oper_binary_unspaced)) &&
1330
- T.getText ().startswith (" ?" ))
1331
- return true ;
1324
+ // optional too.
1325
+ if (T.is (tok::oper_postfix) || T.is (tok::oper_binary_unspaced)) {
1326
+ // We'll munch off the '?', so long as it is left-bound with
1327
+ // the type (i.e., parsed as a postfix or unspaced binary operator).
1328
+ return T.getText ().startswith (" ?" );
1329
+ }
1330
+
1332
1331
return false ;
1333
1332
}
1334
1333
@@ -1338,12 +1337,13 @@ bool Parser::isImplicitlyUnwrappedOptionalToken(const Token &T) const {
1338
1337
if (T.is (tok::exclaim_postfix) || T.is (tok::sil_exclamation))
1339
1338
return true ;
1340
1339
// A postfix or bound infix operator token that begins with '!' can be
1341
- // implicitly unwrapped optional too. We'll munch off the '!', so long as it
1342
- // is left-bound with the type (i.e., parsed as a postfix or unspaced binary
1343
- // operator).
1344
- if ((T.is (tok::oper_postfix) || T.is (tok::oper_binary_unspaced)) &&
1345
- T.getText ().startswith (" !" ))
1346
- return true ;
1340
+ // implicitly unwrapped optional too.
1341
+ if (T.is (tok::oper_postfix) || T.is (tok::oper_binary_unspaced)) {
1342
+ // We'll munch off the '!', so long as it is left-bound with
1343
+ // the type (i.e., parsed as a postfix or unspaced binary operator).
1344
+ return T.getText ().startswith (" !" );
1345
+ }
1346
+
1347
1347
return false ;
1348
1348
}
1349
1349
@@ -1548,9 +1548,7 @@ bool Parser::canParseType() {
1548
1548
}
1549
1549
1550
1550
if (consumeIf (tok::arrow)) {
1551
- if (!canParseType ())
1552
- return false ;
1553
- return true ;
1551
+ return canParseType ();
1554
1552
}
1555
1553
1556
1554
return true ;
@@ -1580,9 +1578,8 @@ bool Parser::canParseSimpleTypeIdentifier() {
1580
1578
consumeToken ();
1581
1579
1582
1580
// Parse an optional generic argument list.
1583
- if (startsWithLess (Tok))
1584
- if (!canParseGenericArguments ())
1585
- return false ;
1581
+ if (startsWithLess (Tok) && !canParseGenericArguments ())
1582
+ return false ;
1586
1583
1587
1584
return true ;
1588
1585
}
0 commit comments