@@ -5695,9 +5695,7 @@ bool Parser::isStartOfFreestandingMacroExpansion() {
5695
5695
return false ;
5696
5696
}
5697
5697
5698
- void Parser::consumeDecl (ParserPosition BeginParserPosition,
5699
- ParseDeclOptions Flags,
5700
- bool IsTopLevel) {
5698
+ void Parser::consumeDecl (ParserPosition BeginParserPosition, bool IsTopLevel) {
5701
5699
SourceLoc CurrentLoc = Tok.getLoc ();
5702
5700
5703
5701
SourceLoc EndLoc = PreviousLoc;
@@ -5706,8 +5704,7 @@ void Parser::consumeDecl(ParserPosition BeginParserPosition,
5706
5704
5707
5705
State->setIDEInspectionDelayedDeclState (
5708
5706
SourceMgr, L->getBufferID (), IDEInspectionDelayedDeclKind::Decl,
5709
- Flags.toRaw (), CurDeclContext, {BeginLoc, EndLoc},
5710
- BeginParserPosition.PreviousLoc );
5707
+ CurDeclContext, {BeginLoc, EndLoc}, BeginParserPosition.PreviousLoc );
5711
5708
5712
5709
while (SourceMgr.isBeforeInBuffer (Tok.getLoc (), CurrentLoc))
5713
5710
consumeToken ();
@@ -5743,6 +5740,41 @@ setOriginalDeclarationForDifferentiableAttributes(DeclAttributes attrs,
5743
5740
const_cast <DerivativeAttr *>(attr)->setOriginalDeclaration (D);
5744
5741
}
5745
5742
5743
+ // / Determine the declaration parsing options to use when parsing the decl in
5744
+ // / the given context.
5745
+ static Parser::ParseDeclOptions getParseDeclOptions (DeclContext *DC) {
5746
+ using ParseDeclOptions = Parser::ParseDeclOptions;
5747
+
5748
+ if (DC->isModuleScopeContext ())
5749
+ return Parser::PD_AllowTopLevel;
5750
+
5751
+ if (DC->isLocalContext ())
5752
+ return Parser::PD_Default;
5753
+
5754
+ auto decl = DC->getAsDecl ();
5755
+ switch (decl->getKind ()) {
5756
+ case DeclKind::Extension:
5757
+ return ParseDeclOptions (Parser::PD_HasContainerType |
5758
+ Parser::PD_InExtension);
5759
+ case DeclKind::Enum:
5760
+ return ParseDeclOptions (Parser::PD_HasContainerType |
5761
+ Parser::PD_AllowEnumElement | Parser::PD_InEnum);
5762
+
5763
+ case DeclKind::Protocol:
5764
+ return ParseDeclOptions (Parser::PD_HasContainerType |
5765
+ Parser::PD_DisallowInit | Parser::PD_InProtocol);
5766
+
5767
+ case DeclKind::Class:
5768
+ return ParseDeclOptions (Parser::PD_HasContainerType | Parser::PD_InClass);
5769
+
5770
+ case DeclKind::Struct:
5771
+ return ParseDeclOptions (Parser::PD_HasContainerType | Parser::PD_InStruct);
5772
+
5773
+ default :
5774
+ llvm_unreachable (" Bad iterable decl context kinds." );
5775
+ }
5776
+ }
5777
+
5746
5778
// / Parse a single syntactic declaration and return a list of decl
5747
5779
// / ASTs. This can return multiple results for var decls that bind to multiple
5748
5780
// / values, structs that define a struct decl and a constructor, etc.
@@ -5760,11 +5792,10 @@ setOriginalDeclarationForDifferentiableAttributes(DeclAttributes attrs,
5760
5792
// / decl-import
5761
5793
// / decl-operator
5762
5794
// / \endverbatim
5763
- ParserResult<Decl>
5764
- Parser::parseDecl (ParseDeclOptions Flags,
5765
- bool IsAtStartOfLineOrPreviousHadSemi,
5766
- bool IfConfigsAreDeclAttrs,
5767
- llvm::function_ref<void (Decl*)> Handler) {
5795
+ ParserResult<Decl> Parser::parseDecl (bool IsAtStartOfLineOrPreviousHadSemi,
5796
+ bool IfConfigsAreDeclAttrs,
5797
+ llvm::function_ref<void (Decl *)> Handler) {
5798
+ ParseDeclOptions Flags = getParseDeclOptions (CurDeclContext);
5768
5799
ParserPosition BeginParserPosition;
5769
5800
if (isIDEInspectionFirstPass ())
5770
5801
BeginParserPosition = getParserPosition ();
@@ -5784,13 +5815,12 @@ Parser::parseDecl(ParseDeclOptions Flags,
5784
5815
skipUntilConditionalBlockClose ();
5785
5816
break ;
5786
5817
}
5787
- Status |= parseDeclItem (PreviousHadSemi, Flags,
5788
- [&](Decl *D) {Decls.emplace_back (D);});
5818
+ Status |= parseDeclItem (PreviousHadSemi,
5819
+ [&](Decl *D) { Decls.emplace_back (D); });
5789
5820
}
5790
5821
});
5791
5822
if (IfConfigResult.hasCodeCompletion () && isIDEInspectionFirstPass ()) {
5792
- consumeDecl (BeginParserPosition, Flags,
5793
- CurDeclContext->isModuleScopeContext ());
5823
+ consumeDecl (BeginParserPosition, CurDeclContext->isModuleScopeContext ());
5794
5824
return makeParserError ();
5795
5825
}
5796
5826
@@ -6131,7 +6161,7 @@ Parser::parseDecl(ParseDeclOptions Flags,
6131
6161
!isa<TopLevelCodeDecl>(CurDeclContext) &&
6132
6162
!isa<AbstractClosureExpr>(CurDeclContext)) {
6133
6163
// Only consume non-toplevel decls.
6134
- consumeDecl (BeginParserPosition, Flags, /* IsTopLevel=*/ false );
6164
+ consumeDecl (BeginParserPosition, /* IsTopLevel=*/ false );
6135
6165
6136
6166
return makeParserError ();
6137
6167
}
@@ -6165,38 +6195,6 @@ Parser::parseDecl(ParseDeclOptions Flags,
6165
6195
return DeclResult;
6166
6196
}
6167
6197
6168
- // / Determine the declaration parsing options to use when parsing the members
6169
- // / of the given context.
6170
- static Parser::ParseDeclOptions getMemberParseDeclOptions (
6171
- IterableDeclContext *idc) {
6172
- using ParseDeclOptions = Parser::ParseDeclOptions;
6173
-
6174
- auto decl = idc->getDecl ();
6175
- switch (decl->getKind ()) {
6176
- case DeclKind::Extension:
6177
- return ParseDeclOptions (
6178
- Parser::PD_HasContainerType | Parser::PD_InExtension);
6179
- case DeclKind::Enum:
6180
- return ParseDeclOptions (
6181
- Parser::PD_HasContainerType | Parser::PD_AllowEnumElement |
6182
- Parser::PD_InEnum);
6183
-
6184
- case DeclKind::Protocol:
6185
- return ParseDeclOptions (
6186
- Parser::PD_HasContainerType | Parser::PD_DisallowInit |
6187
- Parser::PD_InProtocol);
6188
-
6189
- case DeclKind::Class:
6190
- return ParseDeclOptions (Parser::PD_HasContainerType | Parser::PD_InClass);
6191
-
6192
- case DeclKind::Struct:
6193
- return ParseDeclOptions (Parser::PD_HasContainerType | Parser::PD_InStruct);
6194
-
6195
- default :
6196
- llvm_unreachable (" Bad iterable decl context kinds." );
6197
- }
6198
- }
6199
-
6200
6198
std::pair<std::vector<Decl *>, llvm::Optional<Fingerprint>>
6201
6199
Parser::parseDeclListDelayed (IterableDeclContext *IDC) {
6202
6200
Decl *D = const_cast <Decl*>(IDC->getDecl ());
@@ -6256,8 +6254,7 @@ Parser::parseDeclListDelayed(IterableDeclContext *IDC) {
6256
6254
llvm_unreachable (" Bad iterable decl context kinds." );
6257
6255
}
6258
6256
bool hadError = false ;
6259
- ParseDeclOptions Options = getMemberParseDeclOptions (IDC);
6260
- return parseDeclList (LBLoc, RBLoc, Id, Options, IDC, hadError);
6257
+ return parseDeclList (LBLoc, RBLoc, Id, hadError);
6261
6258
}
6262
6259
6263
6260
// / Parse an 'import' declaration, doing no token skipping on error.
@@ -6654,8 +6651,7 @@ void Parser::diagnoseConsecutiveIDs(StringRef First, SourceLoc FirstLoc,
6654
6651
6655
6652
// / Parse a Decl item in decl list.
6656
6653
ParserStatus Parser::parseDeclItem (bool &PreviousHadSemi,
6657
- ParseDeclOptions Options,
6658
- llvm::function_ref<void (Decl*)> handler) {
6654
+ llvm::function_ref<void (Decl *)> handler) {
6659
6655
if (Tok.is (tok::semi)) {
6660
6656
// Consume ';' without preceding decl.
6661
6657
diagnose (Tok, diag::unexpected_separator, " ;" )
@@ -6682,9 +6678,9 @@ ParserStatus Parser::parseDeclItem(bool &PreviousHadSemi,
6682
6678
return LineDirectiveStatus;
6683
6679
}
6684
6680
6685
- ParserResult<Decl> Result = parseDecl (
6686
- Options, IsAtStartOfLineOrPreviousHadSemi,
6687
- /* IfConfigsAreDeclAttrs=*/ false , handler);
6681
+ ParserResult<Decl> Result =
6682
+ parseDecl ( IsAtStartOfLineOrPreviousHadSemi,
6683
+ /* IfConfigsAreDeclAttrs=*/ false , handler);
6688
6684
if (Result.isParseErrorOrHasCompletion ())
6689
6685
skipUntilDeclRBrace (tok::semi, tok::pound_endif);
6690
6686
SourceLoc SemiLoc;
@@ -6727,9 +6723,7 @@ bool Parser::parseMemberDeclList(SourceLoc &LBLoc, SourceLoc &RBLoc,
6727
6723
// When forced to eagerly parse, do so and cache the results in the
6728
6724
// evaluator.
6729
6725
bool hadError = false ;
6730
- ParseDeclOptions Options = getMemberParseDeclOptions (IDC);
6731
- auto membersAndHash =
6732
- parseDeclList (LBLoc, RBLoc, RBraceDiag, Options, IDC, hadError);
6726
+ auto membersAndHash = parseDeclList (LBLoc, RBLoc, RBraceDiag, hadError);
6733
6727
IDC->setMaybeHasOperatorDeclarations ();
6734
6728
IDC->setMaybeHasNestedClassDeclarations ();
6735
6729
Context.evaluator .cacheOutput (
@@ -6752,7 +6746,6 @@ bool Parser::parseMemberDeclList(SourceLoc &LBLoc, SourceLoc &RBLoc,
6752
6746
// / \endverbatim
6753
6747
std::pair<std::vector<Decl *>, llvm::Optional<Fingerprint>>
6754
6748
Parser::parseDeclList (SourceLoc LBLoc, SourceLoc &RBLoc, Diag<> ErrorDiag,
6755
- ParseDeclOptions Options, IterableDeclContext *IDC,
6756
6749
bool &hadError) {
6757
6750
6758
6751
// Hash the type body separately.
@@ -6767,8 +6760,8 @@ Parser::parseDeclList(SourceLoc LBLoc, SourceLoc &RBLoc, Diag<> ErrorDiag,
6767
6760
bool PreviousHadSemi = true ;
6768
6761
{
6769
6762
while (Tok.isNot (tok::r_brace)) {
6770
- Status |= parseDeclItem (PreviousHadSemi, Options,
6771
- [&](Decl *D) { decls.push_back (D); });
6763
+ Status |=
6764
+ parseDeclItem (PreviousHadSemi, [&](Decl *D) { decls.push_back (D); });
6772
6765
if (Tok.isAny (tok::eof, tok::pound_endif, tok::pound_else,
6773
6766
tok::pound_elseif)) {
6774
6767
IsInputIncomplete = true ;
@@ -8048,9 +8041,7 @@ void Parser::parseExpandedMemberList(SmallVectorImpl<ASTNode> &items) {
8048
8041
8049
8042
SourceLoc startingLoc = Tok.getLoc ();
8050
8043
while (!Tok.is (tok::eof)) {
8051
- parseDeclItem (previousHadSemi,
8052
- getMemberParseDeclOptions (idc),
8053
- [&](Decl *d) { items.push_back (d); });
8044
+ parseDeclItem (previousHadSemi, [&](Decl *d) { items.push_back (d); });
8054
8045
8055
8046
if (Tok.getLoc () == startingLoc)
8056
8047
break ;
@@ -8908,7 +8899,7 @@ void Parser::parseAbstractFunctionBody(AbstractFunctionDecl *AFD) {
8908
8899
State->takeIDEInspectionDelayedDeclState ();
8909
8900
State->setIDEInspectionDelayedDeclState (
8910
8901
SourceMgr, L->getBufferID (), IDEInspectionDelayedDeclKind::FunctionBody,
8911
- PD_Default, AFD, BodyRange, BodyPreviousLoc);
8902
+ AFD, BodyRange, BodyPreviousLoc);
8912
8903
};
8913
8904
8914
8905
bool HasNestedTypeDeclarations;
0 commit comments