@@ -5432,6 +5432,20 @@ class AsyncConverter : private SourceEntityWalker {
5432
5432
return TopHandler.isValid ();
5433
5433
}
5434
5434
5435
+ // / Prints a tuple of elements, or a lone single element if only one is
5436
+ // / present, using the provided printing function.
5437
+ template <typename T, typename PrintFn>
5438
+ void addTupleOf (ArrayRef<T> Elements, llvm::raw_ostream &OS,
5439
+ PrintFn PrintElt) {
5440
+ if (Elements.size () == 1 ) {
5441
+ PrintElt (Elements[0 ]);
5442
+ return ;
5443
+ }
5444
+ OS << tok::l_paren;
5445
+ llvm::interleave (Elements, PrintElt, [&]() { OS << tok::comma << " " ; });
5446
+ OS << tok::r_paren;
5447
+ }
5448
+
5435
5449
5436
5450
// / Retrieves the location for the start of a comment attached to the token
5437
5451
// / at the provided location, or the location itself if there is no comment.
@@ -6075,16 +6089,9 @@ class AsyncConverter : private SourceEntityWalker {
6075
6089
}
6076
6090
OS << " " ;
6077
6091
}
6078
- if (SuccessParams.size () > 1 )
6079
- OS << tok::l_paren;
6080
- OS << newNameFor (SuccessParams.front ());
6081
- for (const auto Param : SuccessParams.drop_front ()) {
6082
- OS << tok::comma << " " ;
6083
- OS << newNameFor (Param);
6084
- }
6085
- if (SuccessParams.size () > 1 ) {
6086
- OS << tok::r_paren;
6087
- }
6092
+ // 'res =' or '(res1, res2, ...) ='
6093
+ addTupleOf (SuccessParams, OS,
6094
+ [&](auto &Param) { OS << newNameFor (Param); });
6088
6095
OS << " " << tok::equal << " " ;
6089
6096
}
6090
6097
@@ -6408,19 +6415,10 @@ class AsyncConverter : private SourceEntityWalker {
6408
6415
// / Adds the result type of a refactored async function that previously
6409
6416
// / returned results via a completion handler described by \p HandlerDesc.
6410
6417
void addAsyncFuncReturnType (const AsyncHandlerDesc &HandlerDesc) {
6418
+ // Type or (Type1, Type2, ...)
6411
6419
SmallVector<Type, 2 > Scratch;
6412
- auto ReturnTypes = HandlerDesc.getAsyncReturnTypes (Scratch);
6413
- if (ReturnTypes.size () > 1 ) {
6414
- OS << tok::l_paren;
6415
- }
6416
-
6417
- llvm::interleave (
6418
- ReturnTypes, [&](Type Ty) { Ty->print (OS); },
6419
- [&]() { OS << tok::comma << " " ; });
6420
-
6421
- if (ReturnTypes.size () > 1 ) {
6422
- OS << tok::r_paren;
6423
- }
6420
+ addTupleOf (HandlerDesc.getAsyncReturnTypes (Scratch), OS,
6421
+ [&](auto Ty) { Ty->print (OS); });
6424
6422
}
6425
6423
6426
6424
// / If \p FD is generic, adds a type annotation with the return type of the
0 commit comments