@@ -2077,12 +2077,12 @@ void Parser::parseOptionalArgumentLabel(Identifier &name, SourceLoc &loc) {
2077
2077
}
2078
2078
}
2079
2079
2080
- DeclName Parser::parseUnqualifiedDeclName ( bool afterDot,
2081
- DeclNameLoc &loc ,
2082
- const Diagnostic &diag ,
2083
- bool allowOperators ,
2084
- bool allowZeroArgCompoundNames ,
2085
- bool allowDeinitAndSubscript) {
2080
+ DeclBaseName Parser::parseUnqualifiedDeclBaseName (
2081
+ bool afterDot ,
2082
+ DeclNameLoc &loc ,
2083
+ const Diagnostic &diag ,
2084
+ bool allowOperators ,
2085
+ bool allowDeinitAndSubscript) {
2086
2086
// Consume the base name.
2087
2087
DeclBaseName baseName;
2088
2088
SourceLoc baseNameLoc;
@@ -2114,12 +2114,25 @@ DeclName Parser::parseUnqualifiedDeclName(bool afterDot,
2114
2114
return DeclName ();
2115
2115
}
2116
2116
2117
+ loc = DeclNameLoc (baseNameLoc);
2118
+ return baseName;
2119
+ }
2120
+
2121
+
2122
+ DeclName Parser::parseUnqualifiedDeclName (bool afterDot,
2123
+ DeclNameLoc &loc,
2124
+ const Diagnostic &diag,
2125
+ bool allowOperators,
2126
+ bool allowZeroArgCompoundNames,
2127
+ bool allowDeinitAndSubscript) {
2128
+ // Consume the base name.
2129
+ auto baseName = parseUnqualifiedDeclBaseName (afterDot, loc, diag,
2130
+ allowOperators,
2131
+ allowDeinitAndSubscript);
2132
+
2117
2133
// If the next token isn't a following '(', we don't have a compound name.
2118
- if (!Tok.isFollowingLParen ()) {
2119
- loc = DeclNameLoc (baseNameLoc);
2134
+ if (!baseName || !Tok.isFollowingLParen ())
2120
2135
return baseName;
2121
- }
2122
-
2123
2136
2124
2137
// If the next token is a ')' then we have a 0-arg compound name. This is
2125
2138
// explicitly differentiated from "simple" (non-compound) name in DeclName.
@@ -2133,7 +2146,6 @@ DeclName Parser::parseUnqualifiedDeclName(bool afterDot,
2133
2146
ParsedSyntaxRecorder::makeBlankDeclNameArgumentList (
2134
2147
leadingTriviaLoc (), *SyntaxContext));
2135
2148
consumeToken (tok::r_paren);
2136
- loc = DeclNameLoc (baseNameLoc);
2137
2149
SmallVector<Identifier, 2 > argumentLabels;
2138
2150
return DeclName (Context, baseName, argumentLabels);
2139
2151
}
@@ -2142,7 +2154,6 @@ DeclName Parser::parseUnqualifiedDeclName(bool afterDot,
2142
2154
// compound name.
2143
2155
if ((!peekToken ().canBeArgumentLabel () && !peekToken ().is (tok::colon)) ||
2144
2156
Identifier::isEditorPlaceholder (peekToken ().getText ())) {
2145
- loc = DeclNameLoc (baseNameLoc);
2146
2157
return baseName;
2147
2158
}
2148
2159
@@ -2176,7 +2187,6 @@ DeclName Parser::parseUnqualifiedDeclName(bool afterDot,
2176
2187
2177
2188
// This is not a compound name.
2178
2189
// FIXME: Could recover better if we "know" it's a compound name.
2179
- loc = DeclNameLoc (baseNameLoc);
2180
2190
ArgCtxt.setBackTracking ();
2181
2191
ArgsCtxt.setBackTracking ();
2182
2192
return baseName;
@@ -2190,7 +2200,7 @@ DeclName Parser::parseUnqualifiedDeclName(bool afterDot,
2190
2200
assert (!argumentLabels.empty () && " Logic above should prevent this" );
2191
2201
assert (argumentLabels.size () == argumentLabelLocs.size ());
2192
2202
2193
- loc = DeclNameLoc (Context, baseNameLoc , lparenLoc, argumentLabelLocs,
2203
+ loc = DeclNameLoc (Context, loc. getBaseNameLoc () , lparenLoc, argumentLabelLocs,
2194
2204
rparenLoc);
2195
2205
return DeclName (Context, baseName, argumentLabels);
2196
2206
}
@@ -3020,17 +3030,18 @@ ParserStatus Parser::parseExprList(tok leftTok, tok rightTok,
3020
3030
if (Tok.isBinaryOperator () && peekToken ().isAny (rightTok, tok::comma)) {
3021
3031
SyntaxParsingContext operatorContext (SyntaxContext,
3022
3032
SyntaxKind::IdentifierExpr);
3023
- SourceLoc Loc;
3024
- Identifier OperName;
3025
- if (parseAnyIdentifier (OperName, Loc, diag::expected_operator_ref)) {
3033
+ DeclNameLoc Loc;
3034
+ auto OperName = parseUnqualifiedDeclBaseName (/* afterDot=*/ false , Loc,
3035
+ diag::expected_operator_ref,
3036
+ /* allowOperators=*/ true );
3037
+ if (!OperName) {
3026
3038
return makeParserError ();
3027
3039
}
3028
3040
// Bypass local lookup. Use an 'Ordinary' reference kind so that the
3029
3041
// reference may resolve to any unary or binary operator based on
3030
3042
// context.
3031
3043
SubExpr = new (Context) UnresolvedDeclRefExpr (OperName,
3032
- DeclRefKind::Ordinary,
3033
- DeclNameLoc (Loc));
3044
+ DeclRefKind::Ordinary, Loc);
3034
3045
} else if (isPostfix && Tok.is (tok::code_complete)) {
3035
3046
// Handle call arguments specially because it may need argument labels.
3036
3047
auto CCExpr = new (Context) CodeCompletionExpr (Tok.getLoc ());
0 commit comments