Skip to content

Commit 129b9c0

Browse files
committed
Format patches
1 parent 28572b3 commit 129b9c0

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -486,30 +486,34 @@ static void emitFixItIBActionRemoveAsync(ASTContext &ctx, const FuncDecl &FD) {
486486
std::string replacement = "";
487487

488488
// 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();
495493

494+
CharSourceRange returnType = Lexer::getCharSourceRangeFromSourceRange(
495+
ctx.SourceMgr, FD.getResultTypeSourceRange());
496496

497497
// If we have a return type, include that here
498498
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();
501504
}
502505

503-
504506
if (!FD.hasBody()) {
505507
// If we don't have any body, the sourcelocs won't work and will result in
506508
// crashes, so just swap out what we can
507509

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);
513517
return;
514518
}
515519

@@ -523,18 +527,21 @@ static void emitFixItIBActionRemoveAsync(ASTContext &ctx, const FuncDecl &FD) {
523527
// location of the source range to come after the `End` of the range, and we
524528
// will overflow. Dance around this by just appending the end of the fix to
525529
// the replacement.
526-
if (FD.getBody()->getLBraceLoc() != FD.getBody()->getRBraceLoc().getAdvancedLocOrInvalid(-1)) {
530+
if (FD.getBody()->getLBraceLoc() !=
531+
FD.getBody()->getRBraceLoc().getAdvancedLocOrInvalid(-1)) {
527532
// 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),
530535
FD.getBody()->getRBraceLoc().getAdvancedLocOrInvalid(-1));
531536
replacement += functionBody.str();
532537
}
533538
replacement += " }\n}";
534539

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);
538545
}
539546

540547
static bool
@@ -565,7 +572,7 @@ validateIBActionSignature(ASTContext &ctx, DeclAttribute *attr,
565572

566573
if (FD->isAsyncContext()) {
567574
ctx.Diags.diagnose(FD->getAsyncLoc(), diag::attr_decl_async,
568-
attr->getAttrName(), FD->getDescriptiveKind());
575+
attr->getAttrName(), FD->getDescriptiveKind());
569576
emitFixItIBActionRemoveAsync(ctx, *FD);
570577
valid = false;
571578
}

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,10 +2972,9 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
29722972
if (isRepresentableInObjC(FD, reason, asyncConvention, errorConvention)) {
29732973
if (FD->hasAsync()) {
29742974
FD->setForeignAsyncConvention(*asyncConvention);
2975-
getASTContext().Diags.diagnose(CDeclAttr->getLocation(),
2976-
diag::attr_decl_async,
2977-
CDeclAttr->getAttrName(),
2978-
FD->getDescriptiveKind());
2975+
getASTContext().Diags.diagnose(
2976+
CDeclAttr->getLocation(), diag::attr_decl_async,
2977+
CDeclAttr->getAttrName(), FD->getDescriptiveKind());
29792978
} else if (FD->hasThrows()) {
29802979
FD->setForeignErrorConvention(*errorConvention);
29812980
getASTContext().Diags.diagnose(CDeclAttr->getLocation(),

0 commit comments

Comments
 (0)