@@ -5646,6 +5646,7 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
5646
5646
}
5647
5647
}
5648
5648
5649
+ ParserStatus Status;
5649
5650
SourceLoc FuncLoc =
5650
5651
HasFuncKeyword ? consumeToken (tok::kw_func) : Tok.getLoc ();
5651
5652
@@ -5702,27 +5703,25 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
5702
5703
Optional<Scope> GenericsScope;
5703
5704
GenericsScope.emplace (this , ScopeKind::Generics);
5704
5705
GenericParamList *GenericParams;
5705
- bool SignatureHasCodeCompletion = false ;
5706
5706
auto GenericParamResult = maybeParseGenericParams ();
5707
5707
GenericParams = GenericParamResult.getPtrOrNull ();
5708
- SignatureHasCodeCompletion |= GenericParamResult.hasCodeCompletion ();
5709
- if (SignatureHasCodeCompletion && !CodeCompletion)
5710
- return makeParserCodeCompletionStatus ();
5708
+ if (GenericParamResult.hasCodeCompletion ()) {
5709
+ Status.setHasCodeCompletion ();
5710
+ if (!CodeCompletion)
5711
+ return Status;
5712
+ }
5711
5713
5712
5714
DefaultArgumentInfo DefaultArgs;
5713
5715
TypeRepr *FuncRetTy = nullptr ;
5714
5716
DeclName FullName;
5715
5717
ParameterList *BodyParams;
5716
5718
SourceLoc throwsLoc;
5717
5719
bool rethrows;
5718
- ParserStatus SignatureStatus =
5719
- parseFunctionSignature (SimpleName, FullName, BodyParams, DefaultArgs,
5720
- throwsLoc, rethrows, FuncRetTy);
5721
-
5722
- SignatureHasCodeCompletion |= SignatureStatus.hasCodeCompletion ();
5723
- if (SignatureStatus.hasCodeCompletion () && !CodeCompletion) {
5720
+ Status |= parseFunctionSignature (SimpleName, FullName, BodyParams,
5721
+ DefaultArgs, throwsLoc, rethrows, FuncRetTy);
5722
+ if (Status.hasCodeCompletion () && !CodeCompletion) {
5724
5723
// Trigger delayed parsing, no need to continue.
5725
- return SignatureStatus ;
5724
+ return Status ;
5726
5725
}
5727
5726
5728
5727
diagnoseWhereClauseInGenericParamList (GenericParams);
@@ -5747,11 +5746,10 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
5747
5746
if (Tok.is (tok::kw_where)) {
5748
5747
ContextChange CC (*this , FD);
5749
5748
5750
- auto whereStatus = parseFreestandingGenericWhereClause (GenericParams);
5751
- SignatureHasCodeCompletion |= whereStatus.hasCodeCompletion ();
5752
- if (whereStatus.hasCodeCompletion () && !CodeCompletion) {
5749
+ Status |= parseFreestandingGenericWhereClause (GenericParams);
5750
+ if (Status.hasCodeCompletion () && !CodeCompletion) {
5753
5751
// Trigger delayed parsing, no need to continue.
5754
- return whereStatus ;
5752
+ return Status ;
5755
5753
}
5756
5754
}
5757
5755
@@ -5772,8 +5770,10 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
5772
5770
FD->getAttrs () = Attributes;
5773
5771
5774
5772
// Pass the function signature to code completion.
5775
- if (SignatureHasCodeCompletion)
5773
+ if (Status.hasCodeCompletion ()) {
5774
+ assert (CodeCompletion && " must be code completion second pass" );
5776
5775
CodeCompletion->setParsedDecl (FD);
5776
+ }
5777
5777
5778
5778
DefaultArgs.setFunctionContext (FD, FD->getParameters ());
5779
5779
setLocalDiscriminator (FD);
@@ -5783,7 +5783,7 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
5783
5783
diagnose (Tok, diag::protocol_method_with_body);
5784
5784
skipSingle ();
5785
5785
}
5786
- } else {
5786
+ } else if (!Status. hasCodeCompletion ()) {
5787
5787
parseAbstractFunctionBody (FD);
5788
5788
}
5789
5789
@@ -6545,14 +6545,14 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
6545
6545
Optional<Scope> GenericsScope;
6546
6546
GenericsScope.emplace (this , ScopeKind::Generics);
6547
6547
GenericParamList *GenericParams;
6548
- bool SignatureHasCodeCompletion = false ;
6549
6548
6550
6549
auto Result = maybeParseGenericParams ();
6551
6550
GenericParams = Result.getPtrOrNull ();
6552
- SignatureHasCodeCompletion |= Result.hasCodeCompletion ();
6553
-
6554
- if (SignatureHasCodeCompletion && !CodeCompletion)
6555
- return makeParserCodeCompletionStatus ();
6551
+ if (Result.hasCodeCompletion ()) {
6552
+ Status.setHasCodeCompletion ();
6553
+ if (!CodeCompletion)
6554
+ return Status;
6555
+ }
6556
6556
6557
6557
// Parse the parameter list.
6558
6558
DefaultArgumentInfo DefaultArgs;
@@ -6561,10 +6561,8 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
6561
6561
= parseSingleParameterClause (ParameterContextKind::Subscript,
6562
6562
&argumentNames, &DefaultArgs);
6563
6563
Status |= Indices;
6564
-
6565
- SignatureHasCodeCompletion |= Indices.hasCodeCompletion ();
6566
- if (SignatureHasCodeCompletion && !CodeCompletion)
6567
- return makeParserCodeCompletionStatus ();
6564
+ if (Status.hasCodeCompletion () && !CodeCompletion)
6565
+ return Status;
6568
6566
6569
6567
SourceLoc ArrowLoc;
6570
6568
ParserResult<TypeRepr> ElementTy;
@@ -6588,10 +6586,9 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
6588
6586
// type
6589
6587
ElementTy = parseDeclResultType (diag::expected_type_subscript);
6590
6588
Status |= ElementTy;
6591
- SignatureHasCodeCompletion |= ElementTy.hasCodeCompletion ();
6592
- if (SignatureHasCodeCompletion && !CodeCompletion) {
6593
- return makeParserCodeCompletionStatus ();
6594
- }
6589
+ if (Status.hasCodeCompletion () && !CodeCompletion)
6590
+ return Status;
6591
+
6595
6592
if (ElementTy.isNull ()) {
6596
6593
// Always set an element type.
6597
6594
ElementTy = makeParserResult (ElementTy, new (Context) ErrorTypeRepr ());
@@ -6625,16 +6622,16 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
6625
6622
if (Tok.is (tok::kw_where)) {
6626
6623
ContextChange CC (*this , Subscript);
6627
6624
6628
- auto whereStatus = parseFreestandingGenericWhereClause (GenericParams);
6629
- SignatureHasCodeCompletion |= whereStatus.hasCodeCompletion ();
6630
- if (whereStatus.hasCodeCompletion () && !CodeCompletion) {
6625
+ Status |= parseFreestandingGenericWhereClause (GenericParams);
6626
+ if (Status.hasCodeCompletion () && !CodeCompletion) {
6631
6627
// Trigger delayed parsing, no need to continue.
6632
- return whereStatus ;
6628
+ return Status ;
6633
6629
}
6634
6630
}
6635
6631
6636
6632
// Pass the function signature to code completion.
6637
- if (SignatureHasCodeCompletion && CodeCompletion) {
6633
+ if (Status.hasCodeCompletion ()) {
6634
+ assert (CodeCompletion && " must be code completion second pass" );
6638
6635
CodeCompletion->setParsedDecl (Subscript);
6639
6636
}
6640
6637
@@ -6655,7 +6652,7 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
6655
6652
}
6656
6653
Status.setIsParseError ();
6657
6654
}
6658
- } else {
6655
+ } else if (!Status. hasCodeCompletion ()) {
6659
6656
Status |= parseGetSet (Flags, GenericParams, Indices.get (),
6660
6657
accessors, Subscript, StaticLoc);
6661
6658
}
@@ -6680,6 +6677,7 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
6680
6677
ParserResult<ConstructorDecl>
6681
6678
Parser::parseDeclInit (ParseDeclOptions Flags, DeclAttributes &Attributes) {
6682
6679
assert (Tok.is (tok::kw_init));
6680
+ ParserStatus Status;
6683
6681
SourceLoc ConstructorLoc = consumeToken ();
6684
6682
bool Failable = false , IUO = false ;
6685
6683
SourceLoc FailabilityLoc;
@@ -6714,21 +6712,22 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
6714
6712
Scope S (this , ScopeKind::Generics);
6715
6713
auto GPResult = maybeParseGenericParams ();
6716
6714
GenericParamList *GenericParams = GPResult.getPtrOrNull ();
6717
- if (GPResult.hasCodeCompletion ())
6718
- return makeParserCodeCompletionStatus ();
6715
+ if (GPResult.hasCodeCompletion ()) {
6716
+ Status.setHasCodeCompletion ();
6717
+ if (!CodeCompletion)
6718
+ return Status;
6719
+ }
6719
6720
6720
6721
// Parse the parameters.
6721
6722
DefaultArgumentInfo DefaultArgs;
6722
6723
llvm::SmallVector<Identifier, 4 > namePieces;
6723
- bool SignatureHasCodeCompletion = false ;
6724
6724
ParserResult<ParameterList> Params
6725
6725
= parseSingleParameterClause (ParameterContextKind::Initializer,
6726
6726
&namePieces, &DefaultArgs);
6727
-
6728
- SignatureHasCodeCompletion |= Params.hasCodeCompletion ();
6729
- if (Params.hasCodeCompletion () && !CodeCompletion) {
6727
+ Status |= Params;
6728
+ if (Status.hasCodeCompletion () && !CodeCompletion) {
6730
6729
// Trigger delayed parsing, no need to continue.
6731
- return makeParserCodeCompletionStatus () ;
6730
+ return Status ;
6732
6731
}
6733
6732
6734
6733
// Protocol initializer arguments may not have default values.
@@ -6760,11 +6759,10 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
6760
6759
if (Tok.is (tok::kw_where)) {
6761
6760
ContextChange (*this , CD);
6762
6761
6763
- auto whereStatus = parseFreestandingGenericWhereClause (GenericParams);
6764
- SignatureHasCodeCompletion |= whereStatus.hasCodeCompletion ();
6765
- if (whereStatus.hasCodeCompletion () && !CodeCompletion) {
6762
+ Status |= parseFreestandingGenericWhereClause (GenericParams);
6763
+ if (Status.hasCodeCompletion () && !CodeCompletion) {
6766
6764
// Trigger delayed parsing, no need to continue.
6767
- return whereStatus ;
6765
+ return Status ;
6768
6766
}
6769
6767
}
6770
6768
@@ -6773,8 +6771,10 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
6773
6771
DefaultArgs.setFunctionContext (CD, CD->getParameters ());
6774
6772
6775
6773
// Pass the function signature to code completion.
6776
- if (SignatureHasCodeCompletion)
6774
+ if (Status.hasCodeCompletion ()) {
6775
+ assert (CodeCompletion && " must be code completion second pass" );
6777
6776
CodeCompletion->setParsedDecl (CD);
6777
+ }
6778
6778
6779
6779
if (ConstructorsNotAllowed || Params.isParseError ()) {
6780
6780
// Tell the type checker not to touch this constructor.
@@ -6786,11 +6786,11 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
6786
6786
diagnose (Tok, diag::protocol_init_with_body);
6787
6787
skipSingle ();
6788
6788
}
6789
- } else {
6789
+ } else if (!Status. hasCodeCompletion ()) {
6790
6790
parseAbstractFunctionBody (CD);
6791
6791
}
6792
6792
6793
- return makeParserResult (CD);
6793
+ return makeParserResult (Status, CD);
6794
6794
}
6795
6795
6796
6796
ParserResult<DestructorDecl> Parser::
0 commit comments