@@ -5305,63 +5305,26 @@ Parser::parseDeclFunc(SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
5305
5305
if (rethrows) {
5306
5306
Attributes.add (new (Context) RethrowsAttr (throwsLoc));
5307
5307
}
5308
-
5309
- // Enter the arguments for the function into a new function-body scope. We
5310
- // need this even if there is no function body to detect argument name
5311
- // duplication.
5312
- {
5313
- Scope S (this , ScopeKind::FunctionBody);
5314
5308
5315
- diagnoseOperatorFixityAttributes (*this , Attributes, FD);
5316
-
5317
- // Add the attributes here so if we need them while parsing the body
5318
- // they are available.
5319
- FD->getAttrs () = Attributes;
5309
+ diagnoseOperatorFixityAttributes (*this , Attributes, FD);
5310
+ // Add the attributes here so if we need them while parsing the body
5311
+ // they are available.
5312
+ FD->getAttrs () = Attributes;
5320
5313
5321
- // Pass the function signature to code completion.
5322
- if (SignatureHasCodeCompletion)
5323
- CodeCompletion->setParsedDecl (FD);
5314
+ // Pass the function signature to code completion.
5315
+ if (SignatureHasCodeCompletion)
5316
+ CodeCompletion->setParsedDecl (FD);
5324
5317
5325
- DefaultArgs.setFunctionContext (FD, FD->getParameters ());
5326
- if (auto *P = FD->getImplicitSelfDecl ())
5327
- addToScope (P);
5328
- addParametersToScope (FD->getParameters ());
5329
- setLocalDiscriminator (FD);
5330
-
5331
- // Establish the new context.
5332
- ParseFunctionBody CC (*this , FD);
5333
- setLocalDiscriminatorToParamList (FD->getParameters ());
5318
+ DefaultArgs.setFunctionContext (FD, FD->getParameters ());
5319
+ setLocalDiscriminator (FD);
5334
5320
5335
- // Check to see if we have a "{" to start a brace statement.
5321
+ if (Flags. contains (PD_InProtocol)) {
5336
5322
if (Tok.is (tok::l_brace)) {
5337
- // Record the curly braces but nothing inside.
5338
- SF.recordInterfaceToken (" {" );
5339
- SF.recordInterfaceToken (" }" );
5340
- llvm::SaveAndRestore<bool > T (IsParsingInterfaceTokens, false );
5341
-
5342
- if (Flags.contains (PD_InProtocol)) {
5343
- diagnose (Tok, diag::protocol_method_with_body);
5344
- skipUntilDeclRBrace ();
5345
- } else if (!isDelayedParsingEnabled ()) {
5346
- if (Context.Stats )
5347
- Context.Stats ->getFrontendCounters ().NumFunctionsParsed ++;
5348
-
5349
- ParserResult<BraceStmt> Body =
5350
- parseBraceItemList (diag::func_decl_without_brace);
5351
- if (Body.isNull ()) {
5352
- // FIXME: Should do some sort of error recovery here?
5353
- } else if (SignatureStatus.hasCodeCompletion ()) {
5354
- // Code completion was inside the signature, don't attach the body.
5355
- FD->setBodySkipped (Body.get ()->getSourceRange ());
5356
- } else {
5357
- FD->setBody (Body.get ());
5358
- }
5359
- } else {
5360
- consumeAbstractFunctionBody (FD, Attributes);
5361
- }
5362
- } else {
5363
- checkForInputIncomplete ();
5323
+ diagnose (Tok, diag::protocol_method_with_body);
5324
+ skipSingle ();
5364
5325
}
5326
+ } else {
5327
+ parseAbstractFunctionBody (FD);
5365
5328
}
5366
5329
5367
5330
// Exit the scope introduced for the generic parameters.
@@ -5371,6 +5334,46 @@ Parser::parseDeclFunc(SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
5371
5334
return DCC.fixupParserResult (FD);
5372
5335
}
5373
5336
5337
+ // / Parse function body into \p AFD.
5338
+ void Parser::parseAbstractFunctionBody (AbstractFunctionDecl *AFD) {
5339
+ Scope S (this , ScopeKind::FunctionBody);
5340
+
5341
+ // Enter the arguments for the function into a new function-body scope. We
5342
+ // need this even if there is no function body to detect argument name
5343
+ // duplication.
5344
+ if (auto *P = AFD->getImplicitSelfDecl ())
5345
+ addToScope (P);
5346
+ addParametersToScope (AFD->getParameters ());
5347
+
5348
+ // Establish the new context.
5349
+ ParseFunctionBody CC (*this , AFD);
5350
+ setLocalDiscriminatorToParamList (AFD->getParameters ());
5351
+
5352
+ if (!Tok.is (tok::l_brace)) {
5353
+ checkForInputIncomplete ();
5354
+ return ;
5355
+ }
5356
+
5357
+ if (IsParsingInterfaceTokens) {
5358
+ // Record the curly braces but nothing inside.
5359
+ SF.recordInterfaceToken (" {" );
5360
+ SF.recordInterfaceToken (" }" );
5361
+ }
5362
+ llvm::SaveAndRestore<bool > T (IsParsingInterfaceTokens, false );
5363
+
5364
+ if (isDelayedParsingEnabled ()) {
5365
+ consumeAbstractFunctionBody (AFD, AFD->getAttrs ());
5366
+ return ;
5367
+ }
5368
+
5369
+ if (Context.Stats )
5370
+ Context.Stats ->getFrontendCounters ().NumFunctionsParsed ++;
5371
+
5372
+ ParserResult<BraceStmt> Body = parseBraceItemList (diag::invalid_diagnostic);
5373
+ if (!Body.isNull ())
5374
+ AFD->setBody (Body.get ());
5375
+ }
5376
+
5374
5377
bool Parser::parseAbstractFunctionBodyDelayed (AbstractFunctionDecl *AFD) {
5375
5378
assert (!AFD->getBody () && " function should not have a parsed body" );
5376
5379
assert (AFD->getBodyKind () == AbstractFunctionDecl::BodyKind::Unparsed &&
@@ -6225,7 +6228,6 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
6225
6228
6226
6229
CD->setGenericParams (GenericParams);
6227
6230
6228
- Scope S2 (this , ScopeKind::ConstructorBody);
6229
6231
CtorInitializerKind initKind = CtorInitializerKind::Designated;
6230
6232
if (Attributes.hasAttribute <ConvenienceAttr>())
6231
6233
initKind = CtorInitializerKind::Convenience;
@@ -6244,37 +6246,13 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
6244
6246
CD->setInvalid ();
6245
6247
}
6246
6248
6247
- addToScope (CD->getImplicitSelfDecl ());
6248
- addParametersToScope (Params.get ());
6249
-
6250
- // '{'
6251
- if (Tok.is (tok::l_brace)) {
6252
- // Record the curly braces but nothing inside.
6253
- SF.recordInterfaceToken (" {" );
6254
- SF.recordInterfaceToken (" }" );
6255
- llvm::SaveAndRestore<bool > T (IsParsingInterfaceTokens, false );
6256
-
6257
- if (Flags.contains (PD_InProtocol)) {
6249
+ if (Flags.contains (PD_InProtocol)) {
6250
+ if (Tok.is (tok::l_brace)) {
6258
6251
diagnose (Tok, diag::protocol_init_with_body);
6259
- skipUntilDeclRBrace ();
6260
- } else {
6261
- // Parse the body.
6262
- ParseFunctionBody CC (*this , CD);
6263
- setLocalDiscriminatorToParamList (CD->getParameters ());
6264
-
6265
- if (!isDelayedParsingEnabled ()) {
6266
- if (Context.Stats )
6267
- Context.Stats ->getFrontendCounters ().NumFunctionsParsed ++;
6268
-
6269
- ParserResult<BraceStmt> Body =
6270
- parseBraceItemList (diag::invalid_diagnostic);
6271
-
6272
- if (!Body.isNull ())
6273
- CD->setBody (Body.get ());
6274
- } else {
6275
- consumeAbstractFunctionBody (CD, Attributes);
6276
- }
6252
+ skipSingle ();
6277
6253
}
6254
+ } else {
6255
+ parseAbstractFunctionBody (CD);
6278
6256
}
6279
6257
6280
6258
CD->getAttrs () = Attributes;
@@ -6327,30 +6305,8 @@ parseDeclDeinit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
6327
6305
}
6328
6306
}
6329
6307
6330
- Scope S (this , ScopeKind::DestructorBody);
6331
6308
auto *DD = new (Context) DestructorDecl (DestructorLoc, CurDeclContext);
6332
-
6333
- // Parse the body.
6334
- if (Tok.is (tok::l_brace)) {
6335
- // Record the curly braces but nothing inside.
6336
- SF.recordInterfaceToken (" {" );
6337
- SF.recordInterfaceToken (" }" );
6338
- llvm::SaveAndRestore<bool > T (IsParsingInterfaceTokens, false );
6339
-
6340
- ParseFunctionBody CC (*this , DD);
6341
- if (!isDelayedParsingEnabled ()) {
6342
- if (Context.Stats )
6343
- Context.Stats ->getFrontendCounters ().NumFunctionsParsed ++;
6344
-
6345
- ParserResult<BraceStmt> Body =
6346
- parseBraceItemList (diag::invalid_diagnostic);
6347
-
6348
- if (!Body.isNull ())
6349
- DD->setBody (Body.get ());
6350
- } else {
6351
- consumeAbstractFunctionBody (DD, Attributes);
6352
- }
6353
- }
6309
+ parseAbstractFunctionBody (DD);
6354
6310
6355
6311
DD->getAttrs () = Attributes;
6356
6312
0 commit comments