@@ -671,7 +671,8 @@ bool Parser::parseSpecializeAttributeArguments(
671
671
DeclNameFlag::AllowZeroArgCompoundNames |
672
672
DeclNameFlag::AllowKeywordsUsingSpecialNames |
673
673
DeclNameFlag::AllowOperators |
674
- DeclNameFlag::AllowLowercaseAndUppercaseSelf);
674
+ DeclNameFlag::AllowLowercaseAndUppercaseSelf,
675
+ ModuleSelectorReason::SiblingDeclName);
675
676
}
676
677
}
677
678
if (ParamLabel == " spiModule" ) {
@@ -687,7 +688,7 @@ bool Parser::parseSpecializeAttributeArguments(
687
688
consumeToken ();
688
689
return false ;
689
690
}
690
- diagnoseAndConsumeIfModuleSelector ( " SPI group " );
691
+ parseModuleSelector (ModuleSelectorReason::SPIGroup );
691
692
auto text = Tok.getText ();
692
693
spiGroups.push_back (Context.getIdentifier (text));
693
694
consumeToken ();
@@ -1117,7 +1118,8 @@ Parser::parseImplementsAttribute(SourceLoc AtLoc, SourceLoc Loc) {
1117
1118
MemberNameLoc, diag::attr_implements_expected_member_name,
1118
1119
DeclNameFlag::AllowZeroArgCompoundNames |
1119
1120
DeclNameFlag::AllowOperators |
1120
- DeclNameFlag::AllowLowercaseAndUppercaseSelf);
1121
+ DeclNameFlag::AllowLowercaseAndUppercaseSelf,
1122
+ ModuleSelectorReason::SiblingDeclName);
1121
1123
if (!MemberName) {
1122
1124
Status.setIsParseError ();
1123
1125
}
@@ -1588,8 +1590,7 @@ static bool parseQualifiedDeclName(Parser &P, Diag<> nameParseError,
1588
1590
Parser::DeclNameFlag::AllowZeroArgCompoundNames |
1589
1591
Parser::DeclNameFlag::AllowKeywordsUsingSpecialNames |
1590
1592
Parser::DeclNameFlag::AllowOperators |
1591
- Parser::DeclNameFlag::AllowLowercaseAndUppercaseSelf |
1592
- Parser::DeclNameFlag::AllowModuleSelector);
1593
+ Parser::DeclNameFlag::AllowLowercaseAndUppercaseSelf);
1593
1594
// The base type is optional, but the final unqualified declaration name is
1594
1595
// not. If name could not be parsed, return true for error.
1595
1596
if (!original.Name )
@@ -2498,8 +2499,7 @@ static std::optional<Identifier> parseSingleAttrOptionImpl(
2498
2499
P.consumeToken (tok::code_complete);
2499
2500
}
2500
2501
2501
- P.diagnoseAndConsumeIfModuleSelector (" keyword in attribute arguments" ,
2502
- /* IsDef=*/ true );
2502
+ P.parseModuleSelector (Parser::ModuleSelectorReason::AttrParameter);
2503
2503
2504
2504
StringRef parsedName = P.Tok .getText ();
2505
2505
if (!P.consumeIf (tok::identifier)) {
@@ -2975,7 +2975,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
2975
2975
return makeParserSuccess ();
2976
2976
}
2977
2977
2978
- diagnoseAndConsumeIfModuleSelector ( " SPI group " );
2978
+ parseModuleSelector (ModuleSelectorReason::SPIGroup );
2979
2979
2980
2980
auto text = Tok.getText ();
2981
2981
// An spi group name can be '_' as in @_spi(_), a specifier for implicit import of the SPI.
@@ -3540,8 +3540,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3540
3540
DeclNameFlag::AllowZeroArgCompoundNames |
3541
3541
DeclNameFlag::AllowKeywordsUsingSpecialNames |
3542
3542
DeclNameFlag::AllowOperators |
3543
- DeclNameFlag::AllowLowercaseAndUppercaseSelf |
3544
- DeclNameFlag::AllowModuleSelector);
3543
+ DeclNameFlag::AllowLowercaseAndUppercaseSelf);
3545
3544
}
3546
3545
3547
3546
// Parse the matching ')'.
@@ -4517,8 +4516,7 @@ bool Parser::parseConventionAttributeInternal(SourceLoc atLoc, SourceLoc attrLoc
4517
4516
DeclNameLoc unusedLoc;
4518
4517
witnessMethodProtocol = parseDeclNameRef (
4519
4518
unusedLoc, diag::convention_attribute_witness_method_expected_protocol,
4520
- DeclNameFlag::AllowLowercaseAndUppercaseSelf
4521
- | DeclNameFlag::AllowModuleSelector);
4519
+ DeclNameFlag::AllowLowercaseAndUppercaseSelf);
4522
4520
}
4523
4521
4524
4522
// Parse the ')'. We can't use parseMatchingToken if we're in
@@ -6695,27 +6693,11 @@ ParserStatus Parser::parseInheritance(
6695
6693
return Status;
6696
6694
}
6697
6695
6698
- bool Parser::diagnoseAndConsumeIfModuleSelector (StringRef KindName,
6699
- bool IsDefinition) {
6700
- if (!Context.LangOpts .hasFeature (Feature::ModuleSelector) ||
6701
- peekToken ().isNot (tok::colon_colon))
6702
- return false ;
6703
-
6704
- // Diagnose an error and consume the module selector so we can continue.
6705
- SourceLoc start = consumeToken ();
6706
- SourceLoc end = consumeToken (tok::colon_colon);
6707
- diagnose (end, diag::module_selector_not_allowed_in_decl, IsDefinition,
6708
- KindName)
6709
- .fixItRemove ({start, end});
6710
-
6711
- return true ;
6712
- }
6713
-
6714
6696
static ParserStatus
6715
6697
parseIdentifierDeclName (Parser &P, Identifier &Result, SourceLoc &Loc,
6716
6698
StringRef DeclKindName,
6717
6699
llvm::function_ref<bool (const Token &)> canRecover) {
6718
- P.diagnoseAndConsumeIfModuleSelector ( DeclKindName);
6700
+ P.parseModuleSelector (Parser::ModuleSelectorReason::NameInDecl, DeclKindName);
6719
6701
6720
6702
if (P.Tok .is (tok::identifier)) {
6721
6703
Loc = P.consumeIdentifier (Result, /* diagnoseDollarPrefix=*/ true );
@@ -7559,7 +7541,7 @@ static ParameterList *parseOptionalAccessorArgument(SourceLoc SpecifierLoc,
7559
7541
if (SpecifierLoc.isValid () && P.Tok .is (tok::l_paren)) {
7560
7542
StartLoc = P.consumeToken (tok::l_paren);
7561
7543
7562
- P.diagnoseAndConsumeIfModuleSelector ( " accessor parameter " );
7544
+ P.parseModuleSelector (Parser::ModuleSelectorReason::ParamDecl );
7563
7545
7564
7546
if (P.Tok .isNot (tok::identifier)) {
7565
7547
P.diagnose (P.Tok , diag::expected_accessor_parameter_name,
@@ -9174,8 +9156,6 @@ Parser::parseDeclEnumCase(ParseDeclOptions Flags,
9174
9156
break ;
9175
9157
}
9176
9158
9177
- diagnoseAndConsumeIfModuleSelector (" enum 'case'" );
9178
-
9179
9159
if (Tok.is (tok::identifier)) {
9180
9160
Status |= parseIdentifierDeclName (
9181
9161
*this , Name, NameLoc, " enum 'case'" , [](const Token &next) {
@@ -10142,11 +10122,9 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
10142
10122
10143
10123
// TODO: We could support module selectors for precedence groups if we
10144
10124
// implemented the lookup for it.
10145
- diagnoseAndConsumeIfModuleSelector (" precedence group specifier" ,
10146
- /* isDef=*/ false );
10147
10125
groupName = parseDeclNameRef (groupLoc,
10148
10126
diag::operator_decl_expected_precedencegroup,
10149
- {});
10127
+ {}, ModuleSelectorReason::PrecedenceGroup );
10150
10128
10151
10129
if (Context.TypeCheckerOpts .EnableOperatorDesignatedTypes ) {
10152
10130
// Designated types have been removed; consume the list (mainly for source
@@ -10241,7 +10219,7 @@ Parser::parseDeclPrecedenceGroup(ParseDeclOptions flags,
10241
10219
return nullptr ;
10242
10220
}
10243
10221
10244
- diagnoseAndConsumeIfModuleSelector ( " precedence group " );
10222
+ parseModuleSelector (ModuleSelectorReason::PrecedenceGroup );
10245
10223
10246
10224
Identifier name;
10247
10225
SourceLoc nameLoc;
@@ -10446,7 +10424,8 @@ Parser::parseDeclPrecedenceGroup(ParseDeclOptions flags,
10446
10424
auto name = parseDeclNameRef (nameLoc,
10447
10425
{ diag::expected_precedencegroup_relation,
10448
10426
attrName },
10449
- {});
10427
+ {},
10428
+ ModuleSelectorReason::PrecedenceGroup);
10450
10429
if (!name) {
10451
10430
return abortBody ();
10452
10431
}
0 commit comments