@@ -6237,17 +6237,51 @@ bool AbstractFunctionDecl::argumentNameIsAPIByDefault() const {
6237
6237
return false ;
6238
6238
}
6239
6239
6240
+ BraceStmt *AbstractFunctionDecl::getBody (bool canSynthesize) const {
6241
+ switch (getBodyKind ()) {
6242
+ case BodyKind::Deserialized:
6243
+ case BodyKind::MemberwiseInitializer:
6244
+ case BodyKind::None:
6245
+ case BodyKind::Skipped:
6246
+ return nullptr ;
6247
+
6248
+ case BodyKind::Parsed:
6249
+ case BodyKind::TypeChecked:
6250
+ return Body;
6251
+
6252
+ case BodyKind::Unparsed:
6253
+ // FIXME: Go parse now!
6254
+ return nullptr ;
6255
+
6256
+ case BodyKind::Synthesize: {
6257
+ if (!canSynthesize)
6258
+ return nullptr ;
6259
+
6260
+ const_cast <AbstractFunctionDecl *>(this )->setBodyKind (BodyKind::None);
6261
+ BraceStmt *body;
6262
+ bool isTypeChecked;
6263
+
6264
+ auto mutableThis = const_cast <AbstractFunctionDecl *>(this );
6265
+ std::tie (body, isTypeChecked) = (Synthesizer.Fn )(
6266
+ mutableThis, Synthesizer.Context );
6267
+ mutableThis->setBody (
6268
+ body, isTypeChecked ? BodyKind::TypeChecked : BodyKind::Parsed);
6269
+ return body;
6270
+ }
6271
+ }
6272
+ }
6273
+
6240
6274
SourceRange AbstractFunctionDecl::getBodySourceRange () const {
6241
6275
switch (getBodyKind ()) {
6242
6276
case BodyKind::None:
6243
6277
case BodyKind::MemberwiseInitializer:
6244
6278
case BodyKind::Deserialized:
6279
+ case BodyKind::Synthesize:
6245
6280
return SourceRange ();
6246
6281
6247
6282
case BodyKind::Parsed:
6248
- case BodyKind::Synthesize:
6249
6283
case BodyKind::TypeChecked:
6250
- if (auto body = getBody ())
6284
+ if (auto body = getBody (/* canSynthesize= */ false ))
6251
6285
return body->getSourceRange ();
6252
6286
6253
6287
return SourceRange ();
@@ -6969,9 +7003,9 @@ SourceRange FuncDecl::getSourceRange() const {
6969
7003
getBodyKind () == BodyKind::Skipped)
6970
7004
return { StartLoc, BodyRange.End };
6971
7005
6972
- if ( auto *B = getBody ( /* canSynthesize= */ false )) {
6973
- if (!B-> isImplicit ())
6974
- return { StartLoc, B-> getEndLoc () };
7006
+ SourceLoc RBraceLoc = getBodySourceRange (). End ;
7007
+ if (RBraceLoc. isValid ()) {
7008
+ return { StartLoc, RBraceLoc };
6975
7009
}
6976
7010
6977
7011
if (isa<AccessorDecl>(this ))
@@ -7070,13 +7104,7 @@ SourceRange ConstructorDecl::getSourceRange() const {
7070
7104
if (isImplicit ())
7071
7105
return getConstructorLoc ();
7072
7106
7073
- if (getBodyKind () == BodyKind::Unparsed ||
7074
- getBodyKind () == BodyKind::Skipped)
7075
- return { getConstructorLoc (), BodyRange.End };
7076
-
7077
- SourceLoc End;
7078
- if (auto body = getBody ())
7079
- End = body->getEndLoc ();
7107
+ SourceLoc End = getBodySourceRange ().End ;
7080
7108
if (End.isInvalid ())
7081
7109
End = getGenericTrailingWhereClauseSourceRange ().End ;
7082
7110
if (End.isInvalid ())
@@ -7284,14 +7312,12 @@ ConstructorDecl::getDelegatingOrChainedInitKind(DiagnosticEngine *diags,
7284
7312
}
7285
7313
7286
7314
SourceRange DestructorDecl::getSourceRange () const {
7287
- if (getBodyKind () == BodyKind::Unparsed ||
7288
- getBodyKind () == BodyKind::Skipped)
7289
- return { getDestructorLoc (), BodyRange.End };
7290
-
7291
- if (getBodyKind () == BodyKind::None)
7292
- return getDestructorLoc ();
7315
+ SourceLoc End = getBodySourceRange ().End ;
7316
+ if (End.isInvalid ()) {
7317
+ End = getDestructorLoc ();
7318
+ }
7293
7319
7294
- return { getDestructorLoc (), getBody ()-> getEndLoc () };
7320
+ return { getDestructorLoc (), End };
7295
7321
}
7296
7322
7297
7323
StringRef swift::getAssociativitySpelling (Associativity value) {
0 commit comments