@@ -5440,6 +5440,20 @@ class AsyncConverter : private SourceEntityWalker {
5440
5440
return TopHandler.isValid ();
5441
5441
}
5442
5442
5443
+ // / Prints a tuple of elements, or a lone single element if only one is
5444
+ // / present, using the provided printing function.
5445
+ template <typename T, typename PrintFn>
5446
+ void addTupleOf (ArrayRef<T> Elements, llvm::raw_ostream &OS,
5447
+ PrintFn PrintElt) {
5448
+ if (Elements.size () == 1 ) {
5449
+ PrintElt (Elements[0 ]);
5450
+ return ;
5451
+ }
5452
+ OS << tok::l_paren;
5453
+ llvm::interleave (Elements, PrintElt, [&]() { OS << tok::comma << " " ; });
5454
+ OS << tok::r_paren;
5455
+ }
5456
+
5443
5457
5444
5458
// / Retrieves the location for the start of a comment attached to the token
5445
5459
// / at the provided location, or the location itself if there is no comment.
@@ -6083,16 +6097,9 @@ class AsyncConverter : private SourceEntityWalker {
6083
6097
}
6084
6098
OS << " " ;
6085
6099
}
6086
- if (SuccessParams.size () > 1 )
6087
- OS << tok::l_paren;
6088
- OS << newNameFor (SuccessParams.front ());
6089
- for (const auto Param : SuccessParams.drop_front ()) {
6090
- OS << tok::comma << " " ;
6091
- OS << newNameFor (Param);
6092
- }
6093
- if (SuccessParams.size () > 1 ) {
6094
- OS << tok::r_paren;
6095
- }
6100
+ // 'res =' or '(res1, res2, ...) ='
6101
+ addTupleOf (SuccessParams, OS,
6102
+ [&](auto &Param) { OS << newNameFor (Param); });
6096
6103
OS << " " << tok::equal << " " ;
6097
6104
}
6098
6105
@@ -6416,19 +6423,10 @@ class AsyncConverter : private SourceEntityWalker {
6416
6423
// / Adds the result type of a refactored async function that previously
6417
6424
// / returned results via a completion handler described by \p HandlerDesc.
6418
6425
void addAsyncFuncReturnType (const AsyncHandlerDesc &HandlerDesc) {
6426
+ // Type or (Type1, Type2, ...)
6419
6427
SmallVector<Type, 2 > Scratch;
6420
- auto ReturnTypes = HandlerDesc.getAsyncReturnTypes (Scratch);
6421
- if (ReturnTypes.size () > 1 ) {
6422
- OS << tok::l_paren;
6423
- }
6424
-
6425
- llvm::interleave (
6426
- ReturnTypes, [&](Type Ty) { Ty->print (OS); },
6427
- [&]() { OS << tok::comma << " " ; });
6428
-
6429
- if (ReturnTypes.size () > 1 ) {
6430
- OS << tok::r_paren;
6431
- }
6428
+ addTupleOf (HandlerDesc.getAsyncReturnTypes (Scratch), OS,
6429
+ [&](auto Ty) { Ty->print (OS); });
6432
6430
}
6433
6431
6434
6432
// / If \p FD is generic, adds a type annotation with the return type of the
0 commit comments