@@ -5740,6 +5740,7 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
5740
5740
}
5741
5741
}
5742
5742
5743
+ ParserStatus Status;
5743
5744
SourceLoc FuncLoc =
5744
5745
HasFuncKeyword ? consumeToken (tok::kw_func) : Tok.getLoc ();
5745
5746
@@ -5796,27 +5797,25 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
5796
5797
Optional<Scope> GenericsScope;
5797
5798
GenericsScope.emplace (this , ScopeKind::Generics);
5798
5799
GenericParamList *GenericParams;
5799
- bool SignatureHasCodeCompletion = false ;
5800
5800
auto GenericParamResult = maybeParseGenericParams ();
5801
5801
GenericParams = GenericParamResult.getPtrOrNull ();
5802
- SignatureHasCodeCompletion |= GenericParamResult.hasCodeCompletion ();
5803
- if (SignatureHasCodeCompletion && !CodeCompletion)
5804
- return makeParserCodeCompletionStatus ();
5802
+ if (GenericParamResult.hasCodeCompletion ()) {
5803
+ Status.setHasCodeCompletion ();
5804
+ if (!CodeCompletion)
5805
+ return Status;
5806
+ }
5805
5807
5806
5808
DefaultArgumentInfo DefaultArgs;
5807
5809
TypeRepr *FuncRetTy = nullptr ;
5808
5810
DeclName FullName;
5809
5811
ParameterList *BodyParams;
5810
5812
SourceLoc throwsLoc;
5811
5813
bool rethrows;
5812
- ParserStatus SignatureStatus =
5813
- parseFunctionSignature (SimpleName, FullName, BodyParams, DefaultArgs,
5814
- throwsLoc, rethrows, FuncRetTy);
5815
-
5816
- SignatureHasCodeCompletion |= SignatureStatus.hasCodeCompletion ();
5817
- if (SignatureStatus.hasCodeCompletion () && !CodeCompletion) {
5814
+ Status |= parseFunctionSignature (SimpleName, FullName, BodyParams,
5815
+ DefaultArgs, throwsLoc, rethrows, FuncRetTy);
5816
+ if (Status.hasCodeCompletion () && !CodeCompletion) {
5818
5817
// Trigger delayed parsing, no need to continue.
5819
- return SignatureStatus ;
5818
+ return Status ;
5820
5819
}
5821
5820
5822
5821
diagnoseWhereClauseInGenericParamList (GenericParams);
@@ -5841,11 +5840,10 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
5841
5840
if (Tok.is (tok::kw_where)) {
5842
5841
ContextChange CC (*this , FD);
5843
5842
5844
- auto whereStatus = parseFreestandingGenericWhereClause (GenericParams);
5845
- SignatureHasCodeCompletion |= whereStatus.hasCodeCompletion ();
5846
- if (whereStatus.hasCodeCompletion () && !CodeCompletion) {
5843
+ Status |= parseFreestandingGenericWhereClause (GenericParams);
5844
+ if (Status.hasCodeCompletion () && !CodeCompletion) {
5847
5845
// Trigger delayed parsing, no need to continue.
5848
- return whereStatus ;
5846
+ return Status ;
5849
5847
}
5850
5848
}
5851
5849
@@ -5866,8 +5864,10 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
5866
5864
FD->getAttrs () = Attributes;
5867
5865
5868
5866
// Pass the function signature to code completion.
5869
- if (SignatureHasCodeCompletion)
5867
+ if (Status.hasCodeCompletion ()) {
5868
+ assert (CodeCompletion && " must be code completion second pass" );
5870
5869
CodeCompletion->setParsedDecl (FD);
5870
+ }
5871
5871
5872
5872
DefaultArgs.setFunctionContext (FD, FD->getParameters ());
5873
5873
setLocalDiscriminator (FD);
@@ -5877,7 +5877,7 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
5877
5877
diagnose (Tok, diag::protocol_method_with_body);
5878
5878
skipSingle ();
5879
5879
}
5880
- } else {
5880
+ } else if (!Status. hasCodeCompletion ()) {
5881
5881
parseAbstractFunctionBody (FD);
5882
5882
}
5883
5883
@@ -6639,14 +6639,14 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
6639
6639
Optional<Scope> GenericsScope;
6640
6640
GenericsScope.emplace (this , ScopeKind::Generics);
6641
6641
GenericParamList *GenericParams;
6642
- bool SignatureHasCodeCompletion = false ;
6643
6642
6644
6643
auto Result = maybeParseGenericParams ();
6645
6644
GenericParams = Result.getPtrOrNull ();
6646
- SignatureHasCodeCompletion |= Result.hasCodeCompletion ();
6647
-
6648
- if (SignatureHasCodeCompletion && !CodeCompletion)
6649
- return makeParserCodeCompletionStatus ();
6645
+ if (Result.hasCodeCompletion ()) {
6646
+ Status.setHasCodeCompletion ();
6647
+ if (!CodeCompletion)
6648
+ return Status;
6649
+ }
6650
6650
6651
6651
// Parse the parameter list.
6652
6652
DefaultArgumentInfo DefaultArgs;
@@ -6655,10 +6655,8 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
6655
6655
= parseSingleParameterClause (ParameterContextKind::Subscript,
6656
6656
&argumentNames, &DefaultArgs);
6657
6657
Status |= Indices;
6658
-
6659
- SignatureHasCodeCompletion |= Indices.hasCodeCompletion ();
6660
- if (SignatureHasCodeCompletion && !CodeCompletion)
6661
- return makeParserCodeCompletionStatus ();
6658
+ if (Status.hasCodeCompletion () && !CodeCompletion)
6659
+ return Status;
6662
6660
6663
6661
SourceLoc ArrowLoc;
6664
6662
ParserResult<TypeRepr> ElementTy;
@@ -6682,10 +6680,9 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
6682
6680
// type
6683
6681
ElementTy = parseDeclResultType (diag::expected_type_subscript);
6684
6682
Status |= ElementTy;
6685
- SignatureHasCodeCompletion |= ElementTy.hasCodeCompletion ();
6686
- if (SignatureHasCodeCompletion && !CodeCompletion) {
6687
- return makeParserCodeCompletionStatus ();
6688
- }
6683
+ if (Status.hasCodeCompletion () && !CodeCompletion)
6684
+ return Status;
6685
+
6689
6686
if (ElementTy.isNull ()) {
6690
6687
// Always set an element type.
6691
6688
ElementTy = makeParserResult (ElementTy, new (Context) ErrorTypeRepr ());
@@ -6719,16 +6716,16 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
6719
6716
if (Tok.is (tok::kw_where)) {
6720
6717
ContextChange CC (*this , Subscript);
6721
6718
6722
- auto whereStatus = parseFreestandingGenericWhereClause (GenericParams);
6723
- SignatureHasCodeCompletion |= whereStatus.hasCodeCompletion ();
6724
- if (whereStatus.hasCodeCompletion () && !CodeCompletion) {
6719
+ Status |= parseFreestandingGenericWhereClause (GenericParams);
6720
+ if (Status.hasCodeCompletion () && !CodeCompletion) {
6725
6721
// Trigger delayed parsing, no need to continue.
6726
- return whereStatus ;
6722
+ return Status ;
6727
6723
}
6728
6724
}
6729
6725
6730
6726
// Pass the function signature to code completion.
6731
- if (SignatureHasCodeCompletion && CodeCompletion) {
6727
+ if (Status.hasCodeCompletion ()) {
6728
+ assert (CodeCompletion && " must be code completion second pass" );
6732
6729
CodeCompletion->setParsedDecl (Subscript);
6733
6730
}
6734
6731
@@ -6749,7 +6746,7 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
6749
6746
}
6750
6747
Status.setIsParseError ();
6751
6748
}
6752
- } else {
6749
+ } else if (!Status. hasCodeCompletion ()) {
6753
6750
Status |= parseGetSet (Flags, GenericParams, Indices.get (),
6754
6751
accessors, Subscript, StaticLoc);
6755
6752
}
@@ -6774,6 +6771,7 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
6774
6771
ParserResult<ConstructorDecl>
6775
6772
Parser::parseDeclInit (ParseDeclOptions Flags, DeclAttributes &Attributes) {
6776
6773
assert (Tok.is (tok::kw_init));
6774
+ ParserStatus Status;
6777
6775
SourceLoc ConstructorLoc = consumeToken ();
6778
6776
bool Failable = false , IUO = false ;
6779
6777
SourceLoc FailabilityLoc;
@@ -6808,21 +6806,22 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
6808
6806
Scope S (this , ScopeKind::Generics);
6809
6807
auto GPResult = maybeParseGenericParams ();
6810
6808
GenericParamList *GenericParams = GPResult.getPtrOrNull ();
6811
- if (GPResult.hasCodeCompletion ())
6812
- return makeParserCodeCompletionStatus ();
6809
+ if (GPResult.hasCodeCompletion ()) {
6810
+ Status.setHasCodeCompletion ();
6811
+ if (!CodeCompletion)
6812
+ return Status;
6813
+ }
6813
6814
6814
6815
// Parse the parameters.
6815
6816
DefaultArgumentInfo DefaultArgs;
6816
6817
llvm::SmallVector<Identifier, 4 > namePieces;
6817
- bool SignatureHasCodeCompletion = false ;
6818
6818
ParserResult<ParameterList> Params
6819
6819
= parseSingleParameterClause (ParameterContextKind::Initializer,
6820
6820
&namePieces, &DefaultArgs);
6821
-
6822
- SignatureHasCodeCompletion |= Params.hasCodeCompletion ();
6823
- if (Params.hasCodeCompletion () && !CodeCompletion) {
6821
+ Status |= Params;
6822
+ if (Status.hasCodeCompletion () && !CodeCompletion) {
6824
6823
// Trigger delayed parsing, no need to continue.
6825
- return makeParserCodeCompletionStatus () ;
6824
+ return Status ;
6826
6825
}
6827
6826
6828
6827
// Protocol initializer arguments may not have default values.
@@ -6854,11 +6853,10 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
6854
6853
if (Tok.is (tok::kw_where)) {
6855
6854
ContextChange (*this , CD);
6856
6855
6857
- auto whereStatus = parseFreestandingGenericWhereClause (GenericParams);
6858
- SignatureHasCodeCompletion |= whereStatus.hasCodeCompletion ();
6859
- if (whereStatus.hasCodeCompletion () && !CodeCompletion) {
6856
+ Status |= parseFreestandingGenericWhereClause (GenericParams);
6857
+ if (Status.hasCodeCompletion () && !CodeCompletion) {
6860
6858
// Trigger delayed parsing, no need to continue.
6861
- return whereStatus ;
6859
+ return Status ;
6862
6860
}
6863
6861
}
6864
6862
@@ -6867,8 +6865,10 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
6867
6865
DefaultArgs.setFunctionContext (CD, CD->getParameters ());
6868
6866
6869
6867
// Pass the function signature to code completion.
6870
- if (SignatureHasCodeCompletion)
6868
+ if (Status.hasCodeCompletion ()) {
6869
+ assert (CodeCompletion && " must be code completion second pass" );
6871
6870
CodeCompletion->setParsedDecl (CD);
6871
+ }
6872
6872
6873
6873
if (ConstructorsNotAllowed || Params.isParseError ()) {
6874
6874
// Tell the type checker not to touch this constructor.
@@ -6880,11 +6880,11 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
6880
6880
diagnose (Tok, diag::protocol_init_with_body);
6881
6881
skipSingle ();
6882
6882
}
6883
- } else {
6883
+ } else if (!Status. hasCodeCompletion ()) {
6884
6884
parseAbstractFunctionBody (CD);
6885
6885
}
6886
6886
6887
- return makeParserResult (CD);
6887
+ return makeParserResult (Status, CD);
6888
6888
}
6889
6889
6890
6890
ParserResult<DestructorDecl> Parser::
0 commit comments