Skip to content

Commit 9fa4303

Browse files
committed
[NFC] Switch uses over to parseDeclNameRef()
1 parent c5747c3 commit 9fa4303

File tree

3 files changed

+35
-37
lines changed

3 files changed

+35
-37
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -768,11 +768,10 @@ Parser::parseImplementsAttribute(SourceLoc AtLoc, SourceLoc Loc) {
768768
}
769769

770770
if (!Status.shouldStopParsing()) {
771-
MemberName =
772-
parseUnqualifiedDeclName(/*afterDot=*/false, MemberNameLoc,
773-
diag::attr_implements_expected_member_name,
774-
/*allowOperators=*/true,
775-
/*allowZeroArgCompoundNames=*/true);
771+
MemberName = parseDeclNameRef(MemberNameLoc,
772+
diag::attr_implements_expected_member_name,
773+
DeclNameFlag::AllowZeroArgCompoundNames |
774+
DeclNameFlag::AllowOperators);
776775
if (!MemberName) {
777776
Status.setIsParseError();
778777
}
@@ -1022,10 +1021,8 @@ bool Parser::parseDifferentiableAttributeArguments(
10221021
SyntaxContext, SyntaxKind::FunctionDeclName);
10231022
Diagnostic funcDiag(diag::attr_differentiable_expected_function_name.ID,
10241023
{ label });
1025-
result.Name =
1026-
parseUnqualifiedDeclName(/*afterDot=*/false, result.Loc,
1027-
funcDiag, /*allowOperators=*/true,
1028-
/*allowZeroArgCompoundNames=*/true);
1024+
result.Name = parseDeclNameRef(result.Loc, funcDiag,
1025+
DeclNameFlag::AllowZeroArgCompoundNames | DeclNameFlag::AllowOperators);
10291026
// If no trailing comma or 'where' clause, terminate parsing arguments.
10301027
if (Tok.isNot(tok::comma, tok::kw_where))
10311028
terminateParsingArgs = true;
@@ -1129,10 +1126,11 @@ ParserResult<DerivativeAttr> Parser::parseDerivativeAttribute(SourceLoc atLoc,
11291126
SyntaxKind::FunctionDeclName);
11301127
// NOTE: Use `afterDot = true` and `allowDeinitAndSubscript = true` to
11311128
// enable, e.g. `@derivative(of: init)` and `@derivative(of: subscript)`.
1132-
original.Name = parseUnqualifiedDeclName(
1133-
/*afterDot*/ true, original.Loc,
1134-
diag::attr_derivative_expected_original_name, /*allowOperators*/ true,
1135-
/*allowZeroArgCompoundNames*/ true, /*allowDeinitAndSubscript*/ true);
1129+
original.Name = parseDeclNameRef(original.Loc,
1130+
diag::attr_derivative_expected_original_name,
1131+
DeclNameFlag::AllowZeroArgCompoundNames |
1132+
DeclNameFlag::AllowKeywords | DeclNameFlag::AllowOperators |
1133+
DeclNameFlag::UseSpecialNamesForDeinitAndSubscript);
11361134
}
11371135
if (consumeIfTrailingComma())
11381136
return makeParserError();
@@ -2060,10 +2058,11 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
20602058
SyntaxKind::DeclName);
20612059

20622060
DeclNameLoc loc;
2063-
replacedFunction = parseUnqualifiedDeclName(
2064-
true, loc, diag::attr_dynamic_replacement_expected_function,
2065-
/*allowOperators*/ true, /*allowZeroArgCompoundNames*/ true,
2066-
/*allowDeinitAndSubscript*/ true);
2061+
replacedFunction = parseDeclNameRef(loc,
2062+
diag::attr_dynamic_replacement_expected_function,
2063+
DeclNameFlag::AllowZeroArgCompoundNames |
2064+
DeclNameFlag::AllowKeywords | DeclNameFlag::AllowOperators |
2065+
DeclNameFlag::UseSpecialNamesForDeinitAndSubscript);
20672066
}
20682067
}
20692068

@@ -2572,11 +2571,9 @@ bool Parser::parseConventionAttributeInternal(
25722571
return true;
25732572
}
25742573

2575-
DeclNameLoc unusedWitnessMethodProtocolLoc;
2576-
convention.WitnessMethodProtocol = parseUnqualifiedDeclBaseName(
2577-
/*afterDot=*/false, unusedWitnessMethodProtocolLoc,
2578-
diag::convention_attribute_witness_method_expected_protocol
2579-
);
2574+
DeclNameLoc unusedLoc;
2575+
convention.WitnessMethodProtocol = parseDeclNameRef(unusedLoc,
2576+
diag::convention_attribute_witness_method_expected_protocol, {});
25802577
}
25812578

25822579
// Parse the ')'. We can't use parseMatchingToken if we're in

lib/Parse/ParseExpr.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ ParserResult<Expr> Parser::parseExprKeyPathObjC() {
644644
// Parse the sequence of unqualified-names.
645645
ParserStatus status;
646646
SourceLoc LastDotLoc;
647+
DeclNameOptions flags = DeclNameFlag::AllowCompoundNames;
647648
while (true) {
648649
SyntaxParsingContext NamePieceCtx(SyntaxContext, SyntaxKind::ObjcNamePiece);
649650
// Handle code completion.
@@ -652,10 +653,8 @@ ParserResult<Expr> Parser::parseExprKeyPathObjC() {
652653

653654
// Parse the next name.
654655
DeclNameLoc nameLoc;
655-
bool afterDot = !components.empty();
656-
auto name = parseUnqualifiedDeclName(
657-
afterDot, nameLoc,
658-
diag::expr_keypath_expected_property_or_type);
656+
DeclNameRef name = parseDeclNameRef(nameLoc,
657+
diag::expr_keypath_expected_property_or_type, flags);
659658
if (!name) {
660659
status.setIsParseError();
661660
break;
@@ -666,6 +665,9 @@ ParserResult<Expr> Parser::parseExprKeyPathObjC() {
666665
nameLoc.getBaseNameLoc());
667666
components.push_back(component);
668667

668+
// After the first component, we can start parsing keywords.
669+
flags |= DeclNameFlag::AllowKeywords;
670+
669671
// Handle code completion.
670672
if (Tok.is(tok::code_complete))
671673
return handleCodeCompletion(SourceLoc());
@@ -1130,7 +1132,8 @@ Parser::parseExprPostfixSuffix(ParserResult<Expr> Result, bool isExprBasic,
11301132
Diag<> D = isa<SuperRefExpr>(Result.get())
11311133
? diag::expected_identifier_after_super_dot_expr
11321134
: diag::expected_member_name;
1133-
DeclNameRef Name = parseUnqualifiedDeclName(/*afterDot=*/true, NameLoc, D);
1135+
auto Name = parseDeclNameRef(NameLoc, D,
1136+
DeclNameFlag::AllowKeywords | DeclNameFlag::AllowCompoundNames);
11341137
if (!Name)
11351138
return nullptr;
11361139
SyntaxContext->createNodeInPlace(SyntaxKind::MemberAccessExpr);
@@ -1580,8 +1583,8 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
15801583
return Result;
15811584
}
15821585

1583-
Name = parseUnqualifiedDeclName(/*afterDot=*/true, NameLoc,
1584-
diag::expected_identifier_after_dot_expr);
1586+
Name = parseDeclNameRef(NameLoc, diag::expected_identifier_after_dot_expr,
1587+
DeclNameFlag::AllowKeywords | DeclNameFlag::AllowCompoundNames);
15851588
if (!Name) return nullptr;
15861589
SyntaxContext->createNodeInPlace(SyntaxKind::MemberAccessExpr);
15871590

@@ -2267,8 +2270,8 @@ Expr *Parser::parseExprIdentifier() {
22672270

22682271
// Parse the unqualified-decl-name.
22692272
DeclNameLoc loc;
2270-
DeclNameRef name = parseUnqualifiedDeclName(/*afterDot=*/false, loc,
2271-
diag::expected_expr);
2273+
DeclNameRef name = parseDeclNameRef(loc, diag::expected_expr,
2274+
DeclNameFlag::AllowCompoundNames);
22722275

22732276
SmallVector<TypeRepr*, 8> args;
22742277
SourceLoc LAngleLoc, RAngleLoc;
@@ -3082,9 +3085,8 @@ ParserStatus Parser::parseExprList(tok leftTok, tok rightTok,
30823085
SyntaxParsingContext operatorContext(SyntaxContext,
30833086
SyntaxKind::IdentifierExpr);
30843087
DeclNameLoc Loc;
3085-
auto OperName = parseUnqualifiedDeclBaseName(/*afterDot=*/false, Loc,
3086-
diag::expected_operator_ref,
3087-
/*allowOperators=*/true);
3088+
auto OperName = parseDeclNameRef(Loc, diag::expected_operator_ref,
3089+
DeclNameFlag::AllowOperators);
30883090
if (!OperName) {
30893091
return makeParserError();
30903092
}

lib/Parse/ParseType.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,9 +667,8 @@ ParserResult<TypeRepr> Parser::parseTypeIdentifier() {
667667
SourceLoc EndLoc;
668668
while (true) {
669669
DeclNameLoc Loc;
670-
DeclNameRef Name = parseUnqualifiedDeclBaseName(
671-
/*afterDot=*/false, Loc,
672-
diag::expected_identifier_in_dotted_type);
670+
DeclNameRef Name =
671+
parseDeclNameRef(Loc, diag::expected_identifier_in_dotted_type, {});
673672
if (!Name)
674673
Status.setIsParseError();
675674

0 commit comments

Comments
 (0)