@@ -670,7 +670,8 @@ bool Parser::parseSpecializeAttributeArguments(
670
670
targetFunctionLoc, diag::attr_specialize_expected_function,
671
671
DeclNameFlag::AllowZeroArgCompoundNames |
672
672
DeclNameFlag::AllowKeywordsUsingSpecialNames |
673
- DeclNameFlag::AllowOperators);
673
+ DeclNameFlag::AllowOperators,
674
+ ModuleSelectorReason::SiblingDeclName);
674
675
}
675
676
}
676
677
if (ParamLabel == " spiModule" ) {
@@ -686,7 +687,7 @@ bool Parser::parseSpecializeAttributeArguments(
686
687
consumeToken ();
687
688
return false ;
688
689
}
689
- diagnoseAndConsumeIfModuleSelector ( " SPI group " );
690
+ parseModuleSelector (ModuleSelectorReason::SPIGroup );
690
691
auto text = Tok.getText ();
691
692
spiGroups.push_back (Context.getIdentifier (text));
692
693
consumeToken ();
@@ -815,7 +816,8 @@ Parser::parseImplementsAttribute(SourceLoc AtLoc, SourceLoc Loc) {
815
816
MemberName = parseDeclNameRef (MemberNameLoc,
816
817
diag::attr_implements_expected_member_name,
817
818
DeclNameFlag::AllowZeroArgCompoundNames |
818
- DeclNameFlag::AllowOperators);
819
+ DeclNameFlag::AllowOperators,
820
+ ModuleSelectorReason::SiblingDeclName);
819
821
if (!MemberName) {
820
822
Status.setIsParseError ();
821
823
}
@@ -1193,8 +1195,7 @@ static bool parseQualifiedDeclName(Parser &P, Diag<> nameParseError,
1193
1195
original.Loc , nameParseError,
1194
1196
Parser::DeclNameFlag::AllowZeroArgCompoundNames |
1195
1197
Parser::DeclNameFlag::AllowKeywordsUsingSpecialNames |
1196
- Parser::DeclNameFlag::AllowOperators |
1197
- Parser::DeclNameFlag::AllowModuleSelector);
1198
+ Parser::DeclNameFlag::AllowOperators);
1198
1199
// The base type is optional, but the final unqualified declaration name is
1199
1200
// not. If name could not be parsed, return true for error.
1200
1201
if (!original.Name )
@@ -1862,7 +1863,7 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
1862
1863
return false ;
1863
1864
}
1864
1865
1865
- diagnoseAndConsumeIfModuleSelector ( " SPI group " );
1866
+ parseModuleSelector (ModuleSelectorReason::SPIGroup );
1866
1867
1867
1868
auto text = Tok.getText ();
1868
1869
spiGroups.push_back (Context.getIdentifier (text));
@@ -1974,10 +1975,7 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
1974
1975
return false ;
1975
1976
}
1976
1977
1977
- diagnoseAndConsumeIfModuleSelector (
1978
- " Objective-C class name in @_swift_native_objc_runtime_base" ,
1979
- /* IsDef=*/ true );
1980
-
1978
+ parseModuleSelector (ModuleSelectorReason::ObjCName);
1981
1979
if (Tok.isNot (tok::identifier)) {
1982
1980
diagnose (Loc, diag::swift_native_objc_runtime_base_must_be_identifier);
1983
1981
return false ;
@@ -2495,8 +2493,7 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
2495
2493
diag::attr_dynamic_replacement_expected_function,
2496
2494
DeclNameFlag::AllowZeroArgCompoundNames |
2497
2495
DeclNameFlag::AllowKeywordsUsingSpecialNames |
2498
- DeclNameFlag::AllowOperators |
2499
- DeclNameFlag::AllowModuleSelector);
2496
+ DeclNameFlag::AllowOperators);
2500
2497
}
2501
2498
2502
2499
// Parse the matching ')'.
@@ -2599,14 +2596,14 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
2599
2596
}
2600
2597
2601
2598
case DAK_ProjectedValueProperty: {
2602
- diagnoseAndConsumeIfModuleSelector (" @_projectedValueProperty attribute" );
2603
-
2604
2599
if (!consumeIf (tok::l_paren)) {
2605
2600
diagnose (Loc, diag::attr_expected_lparen, AttrName,
2606
2601
DeclAttribute::isDeclModifier (DK));
2607
2602
return false ;
2608
2603
}
2609
2604
2605
+ parseModuleSelector (ModuleSelectorReason::SiblingDeclName);
2606
+
2610
2607
if (Tok.isNot (tok::identifier)) {
2611
2608
diagnose (Loc, diag::projection_value_property_not_identifier);
2612
2609
return false ;
@@ -3142,8 +3139,7 @@ bool Parser::parseConventionAttributeInternal(
3142
3139
3143
3140
DeclNameLoc unusedLoc;
3144
3141
convention.WitnessMethodProtocol = parseDeclNameRef (unusedLoc,
3145
- diag::convention_attribute_witness_method_expected_protocol,
3146
- DeclNameFlag::AllowModuleSelector);
3142
+ diag::convention_attribute_witness_method_expected_protocol, {});
3147
3143
}
3148
3144
3149
3145
// Parse the ')'. We can't use parseMatchingToken if we're in
@@ -4822,27 +4818,11 @@ ParserStatus Parser::parseInheritance(
4822
4818
return Status;
4823
4819
}
4824
4820
4825
- bool Parser::diagnoseAndConsumeIfModuleSelector (StringRef KindName,
4826
- bool IsDefinition) {
4827
- if (!Context.LangOpts .EnableExperimentalModuleSelector ||
4828
- peekToken ().isNot (tok::colon_colon))
4829
- return false ;
4830
-
4831
- // Diagnose an error and consume the module selector so we can continue.
4832
- SourceLoc start = consumeToken ();
4833
- SourceLoc end = consumeToken (tok::colon_colon);
4834
- diagnose (end, diag::module_selector_not_allowed_in_decl, IsDefinition,
4835
- KindName)
4836
- .fixItRemove ({start, end});
4837
-
4838
- return true ;
4839
- }
4840
-
4841
4821
static ParserStatus
4842
4822
parseIdentifierDeclName (Parser &P, Identifier &Result, SourceLoc &Loc,
4843
4823
StringRef DeclKindName,
4844
4824
llvm::function_ref<bool (const Token &)> canRecover) {
4845
- P.diagnoseAndConsumeIfModuleSelector ( DeclKindName);
4825
+ P.parseModuleSelector (Parser::ModuleSelectorReason::NameInDecl, DeclKindName);
4846
4826
4847
4827
if (P.Tok .is (tok::identifier)) {
4848
4828
Loc = P.consumeIdentifier (Result, /* diagnoseDollarPrefix=*/ true );
@@ -5759,7 +5739,7 @@ static ParameterList *parseOptionalAccessorArgument(SourceLoc SpecifierLoc,
5759
5739
SyntaxParsingContext ParamCtx (P.SyntaxContext , SyntaxKind::AccessorParameter);
5760
5740
StartLoc = P.consumeToken (tok::l_paren);
5761
5741
5762
- P.diagnoseAndConsumeIfModuleSelector ( " accessor parameter " );
5742
+ P.parseModuleSelector (Parser::ModuleSelectorReason::ParamDecl );
5763
5743
5764
5744
if (P.Tok .isNot (tok::identifier)) {
5765
5745
P.diagnose (P.Tok , diag::expected_accessor_parameter_name,
@@ -7245,8 +7225,6 @@ Parser::parseDeclEnumCase(ParseDeclOptions Flags,
7245
7225
break ;
7246
7226
}
7247
7227
7248
- diagnoseAndConsumeIfModuleSelector (" enum 'case'" );
7249
-
7250
7228
if (Tok.is (tok::identifier)) {
7251
7229
Status |= parseIdentifierDeclName (
7252
7230
*this , Name, NameLoc, " enum 'case'" , [](const Token &next) {
@@ -8164,11 +8142,10 @@ parsePrecedenceGroupNameList(Parser &P, Fn takeGroupName) {
8164
8142
8165
8143
// TODO: We could support module selectors for precedence groups if we
8166
8144
// implemented the lookup for it.
8167
- P.diagnoseAndConsumeIfModuleSelector (" precedence group specifier" ,
8168
- /* isDef=*/ false );
8169
8145
DeclNameLoc nameLoc;
8170
8146
auto name = P.parseDeclNameRef (nameLoc,
8171
- diag::expected_group_name_in_precedencegroup_list, {});
8147
+ diag::expected_group_name_in_precedencegroup_list, {},
8148
+ Parser::ModuleSelectorReason::PrecedenceGroup);
8172
8149
if (!name)
8173
8150
return makeParserError ();
8174
8151
@@ -8307,7 +8284,7 @@ Parser::parseDeclPrecedenceGroup(ParseDeclOptions flags,
8307
8284
return nullptr ;
8308
8285
}
8309
8286
8310
- diagnoseAndConsumeIfModuleSelector ( " precedence group " );
8287
+ parseModuleSelector (ModuleSelectorReason::PrecedenceGroup );
8311
8288
8312
8289
Identifier name;
8313
8290
SourceLoc nameLoc;
0 commit comments