@@ -24,53 +24,96 @@ namespace swift {
2424
2525// / A small structure describing the async convention of a foreign declaration.
2626class ForeignAsyncConvention {
27- // / The index of the completion handler parameters.
28- unsigned CompletionHandlerParamIndex;
29-
30- // / When non-zero, indicates which parameter to the completion handler is the
31- // / Error? parameter (minus one) that makes this async function also throwing.
32- unsigned CompletionHandlerErrorParamIndex;
3327public:
34- ForeignAsyncConvention ()
28+ struct Info {
29+ // / The index of the completion handler parameters.
30+ unsigned CompletionHandlerParamIndex;
31+
32+ // / When non-zero, indicates which parameter to the completion handler is
33+ // / the Error? parameter (minus one) that makes this async function also
34+ // / throwing.
35+ unsigned CompletionHandlerErrorParamIndex;
36+
37+ Info ()
3538 : CompletionHandlerParamIndex(0 ), CompletionHandlerErrorParamIndex(0 ) { }
3639
37- ForeignAsyncConvention (unsigned completionHandlerParamIndex,
38- Optional<unsigned > completionHandlerErrorParamIndex)
40+ Info (
41+ unsigned completionHandlerParamIndex,
42+ Optional<unsigned > completionHandlerErrorParamIndex)
3943 : CompletionHandlerParamIndex(completionHandlerParamIndex),
4044 CompletionHandlerErrorParamIndex (
41- completionHandlerErrorParamIndex
42- ? *completionHandlerErrorParamIndex + 1
43- : 0 ) {}
45+ completionHandlerErrorParamIndex
46+ ? *completionHandlerErrorParamIndex + 1
47+ : 0 ) {}
48+
49+ // / Retrieve the index of the \c Error? parameter in the completion handler's
50+ // / parameter list. When argument passed to this parameter is non-null, the
51+ // / provided error will be thrown by the async function.
52+ Optional<unsigned > completionHandlerErrorParamIndex () const {
53+ if (CompletionHandlerErrorParamIndex == 0 )
54+ return None;
55+
56+ return CompletionHandlerErrorParamIndex - 1 ;
57+ }
58+
59+ // / Whether the async function is throwing due to the completion handler
60+ // / having an \c Error? parameter.
61+ // /
62+ // / Equivalent to \c static_cast<bool>(completionHandlerErrorParamIndex()).
63+ bool isThrowing () const {
64+ return CompletionHandlerErrorParamIndex != 0 ;
65+ }
66+ };
67+
68+ // / The type of the completion handler parameter.
69+ CanType CompletionHandlerType;
70+
71+ // / Information about the async convention that can be determined from an
72+ // / Objective-C declaration by itself.
73+ Info TheInfo;
74+
75+ public:
76+ ForeignAsyncConvention () : TheInfo() { }
77+
78+ ForeignAsyncConvention (CanType completionHandlerType,
79+ unsigned completionHandlerParamIndex,
80+ Optional<unsigned > completionHandlerErrorParamIndex)
81+ : CompletionHandlerType(completionHandlerType),
82+ TheInfo(completionHandlerParamIndex, completionHandlerErrorParamIndex)
83+ { }
84+
85+ // / Retrieve the type of the completion handler parameter.
86+ CanType completionHandlerType () const { return CompletionHandlerType; }
4487
4588 // / Retrieve the index of the completion handler parameter, which will be
4689 // / erased from the Swift signature of the imported async function.
4790 unsigned completionHandlerParamIndex () const {
48- return CompletionHandlerParamIndex;
91+ return TheInfo. CompletionHandlerParamIndex ;
4992 }
5093
5194 // / Retrieve the index of the \c Error? parameter in the completion handler's
5295 // / parameter list. When argument passed to this parameter is non-null, the
5396 // / provided error will be thrown by the async function.
5497 Optional<unsigned > completionHandlerErrorParamIndex () const {
55- if (CompletionHandlerErrorParamIndex == 0 )
56- return None;
57-
58- return CompletionHandlerErrorParamIndex - 1 ;
98+ return TheInfo.completionHandlerErrorParamIndex ();
5999 }
60100
61101 // / Whether the async function is throwing due to the completion handler
62102 // / having an \c Error? parameter.
63103 // /
64104 // / Equivalent to \c static_cast<bool>(completionHandlerErrorParamIndex()).
65105 bool isThrowing () const {
66- return CompletionHandlerErrorParamIndex != 0 ;
106+ return TheInfo. isThrowing () ;
67107 }
68108
69109 bool operator ==(ForeignAsyncConvention other) const {
70- return CompletionHandlerParamIndex == other.CompletionHandlerParamIndex
71- && CompletionHandlerErrorParamIndex ==
72- other.CompletionHandlerErrorParamIndex ;
110+ return CompletionHandlerType == other.CompletionHandlerType
111+ && TheInfo.CompletionHandlerParamIndex ==
112+ other.TheInfo .CompletionHandlerParamIndex
113+ && TheInfo.CompletionHandlerErrorParamIndex ==
114+ other.TheInfo .CompletionHandlerErrorParamIndex ;
73115 }
116+
74117 bool operator !=(ForeignAsyncConvention other) const {
75118 return !(*this == other);
76119 }
0 commit comments