@@ -24,53 +24,96 @@ namespace swift {
24
24
25
25
// / A small structure describing the async convention of a foreign declaration.
26
26
class 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;
33
27
public:
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 ()
35
38
: CompletionHandlerParamIndex(0 ), CompletionHandlerErrorParamIndex(0 ) { }
36
39
37
- ForeignAsyncConvention (unsigned completionHandlerParamIndex,
38
- Optional<unsigned > completionHandlerErrorParamIndex)
40
+ Info (
41
+ unsigned completionHandlerParamIndex,
42
+ Optional<unsigned > completionHandlerErrorParamIndex)
39
43
: CompletionHandlerParamIndex(completionHandlerParamIndex),
40
44
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; }
44
87
45
88
// / Retrieve the index of the completion handler parameter, which will be
46
89
// / erased from the Swift signature of the imported async function.
47
90
unsigned completionHandlerParamIndex () const {
48
- return CompletionHandlerParamIndex;
91
+ return TheInfo. CompletionHandlerParamIndex ;
49
92
}
50
93
51
94
// / Retrieve the index of the \c Error? parameter in the completion handler's
52
95
// / parameter list. When argument passed to this parameter is non-null, the
53
96
// / provided error will be thrown by the async function.
54
97
Optional<unsigned > completionHandlerErrorParamIndex () const {
55
- if (CompletionHandlerErrorParamIndex == 0 )
56
- return None;
57
-
58
- return CompletionHandlerErrorParamIndex - 1 ;
98
+ return TheInfo.completionHandlerErrorParamIndex ();
59
99
}
60
100
61
101
// / Whether the async function is throwing due to the completion handler
62
102
// / having an \c Error? parameter.
63
103
// /
64
104
// / Equivalent to \c static_cast<bool>(completionHandlerErrorParamIndex()).
65
105
bool isThrowing () const {
66
- return CompletionHandlerErrorParamIndex != 0 ;
106
+ return TheInfo. isThrowing () ;
67
107
}
68
108
69
109
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 ;
73
115
}
116
+
74
117
bool operator !=(ForeignAsyncConvention other) const {
75
118
return !(*this == other);
76
119
}
0 commit comments