@@ -1037,6 +1037,19 @@ bool Parser::parseDifferentiableAttributeArguments(
1037
1037
return false ;
1038
1038
}
1039
1039
1040
+ // Helper function that returns the accessorkind if a token is an accessor label.
1041
+ static Optional<AccessorKind> isAccessorLabel (const Token& token) {
1042
+ if (token.is (tok::identifier)) {
1043
+ StringRef tokText = token.getText ();
1044
+ for (auto accessor : allAccessorKinds ()) {
1045
+ if (tokText == getAccessorLabel (accessor)) {
1046
+ return accessor;
1047
+ }
1048
+ }
1049
+ }
1050
+ return None;
1051
+ }
1052
+
1040
1053
// / Helper function that parses 'type-identifier' for `parseQualifiedDeclName`.
1041
1054
// / Returns true on error. Sets `baseType` to the parsed base type if present,
1042
1055
// / or to `nullptr` if not. A missing base type is not considered an error.
@@ -1065,14 +1078,8 @@ static bool parseBaseTypeForQualifiedDeclName(Parser &P, TypeRepr *&baseType) {
1065
1078
// name like an accessor.
1066
1079
if (P.Tok .is (tok::period)) {
1067
1080
const Token &nextToken = P.peekToken ();
1068
- if (nextToken.is (tok::identifier)) {
1069
- StringRef tokText = nextToken.getText ();
1070
- for (auto accessor : allAccessorKinds ()) {
1071
- if (tokText == getAccessorLabel (accessor)) {
1072
- return false ;
1073
- }
1074
- }
1075
- }
1081
+ if (isAccessorLabel (nextToken) != None)
1082
+ return false ;
1076
1083
}
1077
1084
1078
1085
backtrack.cancelBacktrack ();
@@ -1115,24 +1122,20 @@ static bool parseQualifiedDeclName(Parser &P, Diag<> nameParseError,
1115
1122
if (!original.Name )
1116
1123
return true ;
1117
1124
}
1118
-
1119
- // Parse to see if this is an accessor and set it's type. This is an optional field.
1125
+
1126
+ // Parse to see if this is an accessor and set it's type. This is an optional field.
1120
1127
if (P.Tok .is (tok::period)) {
1121
1128
const Token &nextToken = P.peekToken ();
1122
- if (nextToken.is (tok::identifier)) {
1123
- StringRef tokText = nextToken.getText ();
1124
- for (auto accessor : allAccessorKinds ()) {
1125
- if (tokText == getAccessorLabel (accessor)) {
1126
- original.AccessorKind = accessor;
1127
- P.consumeIf (tok::period);
1128
- P.consumeIf (tok::identifier);
1129
- }
1130
- }
1129
+ Optional<AccessorKind> kind = isAccessorLabel (nextToken);
1130
+ if (kind != None) {
1131
+ original.AccessorKind = kind;
1132
+ P.consumeIf (tok::period);
1133
+ P.consumeIf (tok::identifier);
1131
1134
}
1132
1135
}
1133
1136
1134
1137
return false ;
1135
-
1138
+
1136
1139
}
1137
1140
1138
1141
// / Parse a `@derivative(of:)` attribute, returning true on error.
0 commit comments