@@ -2469,13 +2469,14 @@ Parser::parseMacroRoleAttribute(
2469
2469
// / \c Identifier() ; if false, diagnose a missing argument list as an error.
2470
2470
// / \param nonIdentifierDiagnostic The diagnostic to emit if something other than a
2471
2471
// / \c tok::identifier is used as an argument.
2472
+ // / \param PDK Specific kind of the parameterized attribute being passed. Used when invoking code completion callbacks.
2472
2473
// /
2473
2474
// / \returns \c None if an error was diagnosed; \c Identifier() if the argument list was permissibly
2474
2475
// / omitted; the identifier written by the user otherwise.
2475
2476
static std::optional<Identifier> parseSingleAttrOptionImpl (
2476
- Parser &P, SourceLoc Loc, SourceRange &AttrRange, StringRef AttrName, DeclAttrKind DK,
2477
- ParserStatus &Status , bool allowOmitted, DiagRef nonIdentifierDiagnostic,
2478
- llvm::function_ref< void ()> codeCompletionCallback = {} ) {
2477
+ Parser &P, SourceLoc Loc, SourceRange &AttrRange, StringRef AttrName,
2478
+ DeclAttrKind DK , bool allowOmitted, DiagRef nonIdentifierDiagnostic,
2479
+ std::optional<ParameterizedDeclAttributeKind> PDK = std::nullopt ) {
2479
2480
SWIFT_DEFER {
2480
2481
AttrRange = SourceRange (Loc, P.PreviousLoc );
2481
2482
};
@@ -2484,28 +2485,25 @@ static std::optional<Identifier> parseSingleAttrOptionImpl(
2484
2485
if (!P.Tok .is (tok::l_paren)) {
2485
2486
if (allowOmitted)
2486
2487
return Identifier ();
2487
-
2488
- Status.setIsParseError ();
2488
+
2489
2489
P.diagnose (Loc, diag::attr_expected_lparen, AttrName, isDeclModifier);
2490
2490
return std::nullopt;
2491
2491
}
2492
2492
2493
2493
P.consumeAttributeLParen ();
2494
2494
2495
- if (P.Tok .is (tok::code_complete)) {
2496
- Status. setHasCodeCompletion ( );
2497
- codeCompletionCallback ( );
2495
+ if (P.Tok .is (tok::code_complete) && P. CodeCompletionCallbacks && PDK ) {
2496
+ P. CodeCompletionCallbacks -> completeDeclAttrParam (*PDK, 0 , /* HasLabel= */ false );
2497
+ P. consumeToken (tok::code_complete );
2498
2498
}
2499
2499
2500
2500
StringRef parsedName = P.Tok .getText ();
2501
2501
if (!P.consumeIf (tok::identifier)) {
2502
- Status.setIsParseError ();
2503
2502
P.diagnose (Loc, nonIdentifierDiagnostic);
2504
2503
return std::nullopt;
2505
2504
}
2506
2505
2507
2506
if (!P.consumeIf (tok::r_paren)) {
2508
- Status.setIsParseError ();
2509
2507
P.diagnose (Loc, diag::attr_expected_rparen, AttrName, isDeclModifier);
2510
2508
return std::nullopt;
2511
2509
}
@@ -2599,11 +2597,11 @@ ParserResult<LifetimeAttr> Parser::parseLifetimeAttribute(SourceLoc atLoc,
2599
2597
// / \returns \c None if an error was diagnosed; \c Identifier() if the argument list was permissibly
2600
2598
// / omitted; the identifier written by the user otherwise.
2601
2599
static std::optional<Identifier>
2602
- parseSingleAttrOptionIdentifier (Parser &P, SourceLoc Loc, ParserStatus &Status ,
2603
- SourceRange &AttrRange, StringRef AttrName ,
2604
- DeclAttrKind DK, bool allowOmitted = false ) {
2600
+ parseSingleAttrOptionIdentifier (Parser &P, SourceLoc Loc, SourceRange &AttrRange ,
2601
+ StringRef AttrName, DeclAttrKind DK ,
2602
+ bool allowOmitted = false ) {
2605
2603
return parseSingleAttrOptionImpl (
2606
- P, Loc, AttrRange, AttrName, DK, Status, allowOmitted,
2604
+ P, Loc, AttrRange, AttrName, DK, allowOmitted,
2607
2605
{diag::attr_expected_option_identifier, {AttrName}});
2608
2606
}
2609
2607
@@ -2618,23 +2616,22 @@ parseSingleAttrOptionIdentifier(Parser &P, SourceLoc Loc, ParserStatus &Status,
2618
2616
// / \param options The set of permitted keywords and their corresponding values.
2619
2617
// / \param valueIfOmitted If present, treat a missing argument list as permitted and return
2620
2618
// / the provided value; if absent, diagnose a missing argument list as an error.
2619
+ // / \param PDK Specific kind of the parameterized attribute being passed. Used when invoking code completion callbacks.
2621
2620
// /
2622
2621
// / \returns \c None if an error was diagnosed; the value corresponding to the identifier written by the
2623
2622
// / user otherwise.
2624
2623
template <typename R>
2625
2624
static std::optional<R>
2626
2625
parseSingleAttrOption (Parser &P, SourceLoc Loc, SourceRange &AttrRange,
2627
2626
StringRef AttrName, DeclAttrKind DK,
2628
- ParserStatus& Status,
2629
2627
ArrayRef<std::pair<Identifier, R>> options,
2630
2628
std::optional<R> valueIfOmitted = std::nullopt,
2631
- llvm::function_ref< void ()> codeCompletionCallback = {} ) {
2629
+ std::optional<ParameterizedDeclAttributeKind> PDK = std::nullopt ) {
2632
2630
auto parsedIdentifier = parseSingleAttrOptionImpl (
2633
- P, Loc, AttrRange, AttrName, DK, Status,
2631
+ P, Loc, AttrRange, AttrName, DK,
2634
2632
/* allowOmitted=*/ valueIfOmitted.has_value (),
2635
2633
{diag::attr_expected_option_such_as,
2636
- {AttrName, options.front ().first .str ()}},
2637
- codeCompletionCallback);
2634
+ {AttrName, options.front ().first .str ()}}, PDK);
2638
2635
2639
2636
if (!parsedIdentifier)
2640
2637
return std::nullopt;
@@ -2768,9 +2765,8 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
2768
2765
}
2769
2766
2770
2767
case DeclAttrKind::Inline: {
2771
- ParserStatus optionStatus;
2772
2768
auto kind = parseSingleAttrOption<InlineKind>(
2773
- *this , Loc, AttrRange, AttrName, DK, optionStatus, {
2769
+ *this , Loc, AttrRange, AttrName, DK, {
2774
2770
{ Context.Id_never , InlineKind::Never },
2775
2771
{ Context.Id__always , InlineKind::Always }
2776
2772
});
@@ -2784,9 +2780,8 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
2784
2780
}
2785
2781
2786
2782
case DeclAttrKind::Optimize: {
2787
- ParserStatus optionStatus;
2788
2783
auto optMode = parseSingleAttrOption<OptimizationMode>(
2789
- *this , Loc, AttrRange, AttrName, DK, optionStatus, {
2784
+ *this , Loc, AttrRange, AttrName, DK, {
2790
2785
{ Context.Id_speed , OptimizationMode::ForSpeed },
2791
2786
{ Context.Id_size , OptimizationMode::ForSize },
2792
2787
{ Context.Id_none , OptimizationMode::NoOptimization }
@@ -2801,9 +2796,8 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
2801
2796
}
2802
2797
2803
2798
case DeclAttrKind::Exclusivity: {
2804
- ParserStatus optionStatus;
2805
2799
auto mode = parseSingleAttrOption<ExclusivityAttr::Mode>(
2806
- *this , Loc, AttrRange, AttrName, DK, optionStatus, {
2800
+ *this , Loc, AttrRange, AttrName, DK, {
2807
2801
{ Context.Id_checked , ExclusivityAttr::Mode::Checked },
2808
2802
{ Context.Id_unchecked , ExclusivityAttr::Mode::Unchecked }
2809
2803
});
@@ -2823,19 +2817,12 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
2823
2817
2824
2818
if (Kind == ReferenceOwnership::Unowned) {
2825
2819
// Parse an optional specifier after unowned.
2826
- ParserStatus optionStatus;
2827
2820
Kind = parseSingleAttrOption<ReferenceOwnership>(
2828
- *this , Loc, AttrRange, AttrName, DK, optionStatus, {
2821
+ *this , Loc, AttrRange, AttrName, DK, {
2829
2822
{ Context.Id_unsafe , ReferenceOwnership::Unmanaged },
2830
2823
{ Context.Id_safe , ReferenceOwnership::Unowned }
2831
2824
}, ReferenceOwnership::Unowned,
2832
- [&] () {
2833
- if (CodeCompletionCallbacks) {
2834
- CodeCompletionCallbacks->completeDeclAttrParam (
2835
- ParameterizedDeclAttributeKind::Unowned, 0 , /* HasLabel=*/ false );
2836
- consumeToken (tok::code_complete);
2837
- }
2838
- })
2825
+ ParameterizedDeclAttributeKind::Unowned)
2839
2826
// Recover from errors by going back to Unowned.
2840
2827
.value_or (ReferenceOwnership::Unowned);
2841
2828
}
@@ -2851,9 +2838,8 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
2851
2838
}
2852
2839
2853
2840
case DeclAttrKind::NonSendable: {
2854
- ParserStatus optionStatus;
2855
2841
auto kind = parseSingleAttrOption<NonSendableKind>(
2856
- *this , Loc, AttrRange, AttrName, DK, optionStatus, {
2842
+ *this , Loc, AttrRange, AttrName, DK, {
2857
2843
{ Context.Id_assumed , NonSendableKind::Assumed }
2858
2844
}, NonSendableKind::Specific);
2859
2845
if (!kind)
@@ -3190,8 +3176,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3190
3176
3191
3177
case DeclAttrKind::SwiftNativeObjCRuntimeBase: {
3192
3178
SourceRange range;
3193
- ParserStatus optionStatus;
3194
- auto name = parseSingleAttrOptionIdentifier (*this , Loc, optionStatus, range,
3179
+ auto name = parseSingleAttrOptionIdentifier (*this , Loc, range,
3195
3180
AttrName, DK);
3196
3181
if (!name)
3197
3182
return makeParserSuccess ();
@@ -3484,8 +3469,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3484
3469
}
3485
3470
case DeclAttrKind::ObjCImplementation: {
3486
3471
SourceRange range;
3487
- ParserStatus optionStatus;
3488
- auto name = parseSingleAttrOptionIdentifier (*this , Loc, optionStatus, range, AttrName, DK,
3472
+ auto name = parseSingleAttrOptionIdentifier (*this , Loc, range, AttrName, DK,
3489
3473
/* allowOmitted=*/ true );
3490
3474
if (!name)
3491
3475
return makeParserSuccess ();
@@ -3497,9 +3481,8 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3497
3481
}
3498
3482
case DeclAttrKind::ObjCRuntimeName: {
3499
3483
SourceRange range;
3500
- ParserStatus optionStatus;
3501
3484
auto name =
3502
- parseSingleAttrOptionIdentifier (*this , Loc, optionStatus, range, AttrName, DK);
3485
+ parseSingleAttrOptionIdentifier (*this , Loc, range, AttrName, DK);
3503
3486
if (!name)
3504
3487
return makeParserSuccess ();
3505
3488
@@ -3656,9 +3639,8 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3656
3639
3657
3640
case DeclAttrKind::ProjectedValueProperty: {
3658
3641
SourceRange range;
3659
- ParserStatus optionStatus;
3660
3642
auto name =
3661
- parseSingleAttrOptionIdentifier (*this , Loc, optionStatus, range, AttrName, DK);
3643
+ parseSingleAttrOptionIdentifier (*this , Loc, range, AttrName, DK);
3662
3644
if (!name)
3663
3645
return makeParserSuccess ();
3664
3646
@@ -3758,17 +3740,10 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3758
3740
case DeclAttrKind::Nonisolated: {
3759
3741
std::optional<bool > isUnsafe (false );
3760
3742
if (EnableParameterizedNonisolated) {
3761
- ParserStatus optionStatus;
3762
3743
isUnsafe =
3763
3744
parseSingleAttrOption<bool >(*this , Loc, AttrRange, AttrName, DK,
3764
- optionStatus, {{Context.Id_unsafe , true }},
3765
- *isUnsafe, [&] () {
3766
- if (CodeCompletionCallbacks) {
3767
- CodeCompletionCallbacks->completeDeclAttrParam (
3768
- ParameterizedDeclAttributeKind::Nonisolated, 0 , /* HasLabel=*/ false );
3769
- consumeToken (tok::code_complete);
3770
- }
3771
- });
3745
+ {{Context.Id_unsafe , true }}, *isUnsafe,
3746
+ ParameterizedDeclAttributeKind::Nonisolated);
3772
3747
if (!isUnsafe) {
3773
3748
return makeParserSuccess ();
3774
3749
}
@@ -3967,9 +3942,8 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3967
3942
}
3968
3943
3969
3944
case DeclAttrKind::Execution: {
3970
- ParserStatus optionStatus;
3971
3945
auto behavior = parseSingleAttrOption<ExecutionKind>(
3972
- *this , Loc, AttrRange, AttrName, DK, optionStatus,
3946
+ *this , Loc, AttrRange, AttrName, DK,
3973
3947
{{Context.Id_concurrent , ExecutionKind::Concurrent},
3974
3948
{Context.Id_caller , ExecutionKind::Caller}});
3975
3949
if (!behavior)
@@ -5674,7 +5648,6 @@ consumeIfParenthesizedModifier(Parser &P, StringRef name,
5674
5648
P.consumeToken (tok::identifier);
5675
5649
P.consumeToken (tok::l_paren);
5676
5650
5677
- const Token &Tok2 = P.peekToken ();
5678
5651
if (P.consumeIf (tok::code_complete)) {
5679
5652
// If a code complete token is present, recover from missing/incorrect argument and missing '('
5680
5653
P.consumeIf (tok::identifier);
@@ -5683,19 +5656,6 @@ consumeIfParenthesizedModifier(Parser &P, StringRef name,
5683
5656
return true ;
5684
5657
}
5685
5658
5686
- if (P.Tok .is (tok::identifier) && !P.Tok .isContextualDeclKeyword () && Tok2.is (tok::code_complete)) {
5687
- P.consumeToken (tok::identifier);
5688
- P.consumeToken (tok::code_complete);
5689
-
5690
- // If a code complete is present with a non-keyword token before it, recover from missing/incorrect argument and missing '('
5691
- if (!P.Tok .isContextualDeclKeyword ()) {
5692
- P.consumeIf (tok::identifier);
5693
- }
5694
- P.consumeIf (tok::r_paren);
5695
- backtrack.cancelBacktrack ();
5696
- return true ;
5697
- }
5698
-
5699
5659
const bool argumentIsAllowed =
5700
5660
std::find (allowedArguments.begin (), allowedArguments.end (),
5701
5661
P.Tok .getText ()) != allowedArguments.end ();
0 commit comments