@@ -486,30 +486,34 @@ static void emitFixItIBActionRemoveAsync(ASTContext &ctx, const FuncDecl &FD) {
486
486
std::string replacement = " " ;
487
487
488
488
// attributes, function name and everything up to `async` (exclusive)
489
- replacement += CharSourceRange (ctx.SourceMgr ,
490
- FD.getSourceRangeIncludingAttrs ().Start ,
491
- FD.getAsyncLoc ()).str ();
492
-
493
- CharSourceRange returnType = Lexer::getCharSourceRangeFromSourceRange (ctx.SourceMgr ,
494
- FD.getResultTypeSourceRange ());
489
+ replacement +=
490
+ CharSourceRange (ctx.SourceMgr , FD.getSourceRangeIncludingAttrs ().Start ,
491
+ FD.getAsyncLoc ())
492
+ .str ();
495
493
494
+ CharSourceRange returnType = Lexer::getCharSourceRangeFromSourceRange (
495
+ ctx.SourceMgr , FD.getResultTypeSourceRange ());
496
496
497
497
// If we have a return type, include that here
498
498
if (returnType.isValid ()) {
499
- replacement += (llvm::Twine (" -> " ) + Lexer::getCharSourceRangeFromSourceRange (ctx.SourceMgr ,
500
- FD.getResultTypeSourceRange ()).str ()).str ();
499
+ replacement +=
500
+ (llvm::Twine (" -> " ) + Lexer::getCharSourceRangeFromSourceRange (
501
+ ctx.SourceMgr , FD.getResultTypeSourceRange ())
502
+ .str ())
503
+ .str ();
501
504
}
502
505
503
-
504
506
if (!FD.hasBody ()) {
505
507
// If we don't have any body, the sourcelocs won't work and will result in
506
508
// crashes, so just swap out what we can
507
509
508
- SourceLoc endLoc = returnType.isValid () ? returnType.getEnd () : FD.getAsyncLoc ();
509
- ctx.Diags .diagnose (FD.getAsyncLoc (), diag::remove_async_add_task,
510
- FD.getName ())
511
- .fixItReplace (SourceRange (FD.getSourceRangeIncludingAttrs ().Start , endLoc),
512
- replacement);
510
+ SourceLoc endLoc =
511
+ returnType.isValid () ? returnType.getEnd () : FD.getAsyncLoc ();
512
+ ctx.Diags
513
+ .diagnose (FD.getAsyncLoc (), diag::remove_async_add_task, FD.getName ())
514
+ .fixItReplace (
515
+ SourceRange (FD.getSourceRangeIncludingAttrs ().Start , endLoc),
516
+ replacement);
513
517
return ;
514
518
}
515
519
@@ -523,18 +527,21 @@ static void emitFixItIBActionRemoveAsync(ASTContext &ctx, const FuncDecl &FD) {
523
527
// location of the source range to come after the `End` of the range, and we
524
528
// will overflow. Dance around this by just appending the end of the fix to
525
529
// the replacement.
526
- if (FD.getBody ()->getLBraceLoc () != FD.getBody ()->getRBraceLoc ().getAdvancedLocOrInvalid (-1 )) {
530
+ if (FD.getBody ()->getLBraceLoc () !=
531
+ FD.getBody ()->getRBraceLoc ().getAdvancedLocOrInvalid (-1 )) {
527
532
// We actually have a body, so add that to the string
528
- CharSourceRange functionBody (ctx. SourceMgr ,
529
- FD.getBody ()->getLBraceLoc ().getAdvancedLocOrInvalid (1 ),
533
+ CharSourceRange functionBody (
534
+ ctx. SourceMgr , FD.getBody ()->getLBraceLoc ().getAdvancedLocOrInvalid (1 ),
530
535
FD.getBody ()->getRBraceLoc ().getAdvancedLocOrInvalid (-1 ));
531
536
replacement += functionBody.str ();
532
537
}
533
538
replacement += " }\n }" ;
534
539
535
- ctx.Diags .diagnose (FD.getAsyncLoc (), diag::remove_async_add_task, FD.getName ())
536
- .fixItReplace (SourceRange (FD.getSourceRangeIncludingAttrs ().Start ,
537
- FD.getBody ()->getRBraceLoc ()), replacement);
540
+ ctx.Diags
541
+ .diagnose (FD.getAsyncLoc (), diag::remove_async_add_task, FD.getName ())
542
+ .fixItReplace (SourceRange (FD.getSourceRangeIncludingAttrs ().Start ,
543
+ FD.getBody ()->getRBraceLoc ()),
544
+ replacement);
538
545
}
539
546
540
547
static bool
@@ -565,7 +572,7 @@ validateIBActionSignature(ASTContext &ctx, DeclAttribute *attr,
565
572
566
573
if (FD->isAsyncContext ()) {
567
574
ctx.Diags .diagnose (FD->getAsyncLoc (), diag::attr_decl_async,
568
- attr->getAttrName (), FD->getDescriptiveKind ());
575
+ attr->getAttrName (), FD->getDescriptiveKind ());
569
576
emitFixItIBActionRemoveAsync (ctx, *FD);
570
577
valid = false ;
571
578
}
0 commit comments