1
1
#[ doc( hidden) ]
2
2
#[ macro_export]
3
3
macro_rules! __inner_declare_class {
4
- { @rewrite_methods @$output_type : ident @$builder : ident } => { } ;
4
+ { @rewrite_methods @( $ ( $output : tt ) * ) } => { } ;
5
5
{
6
6
@rewrite_methods
7
- @$output_type: ident
8
- @$builder: ident
7
+ @( $( $output: tt) * )
9
8
10
9
$( #[ $( $m: tt) * ] ) *
11
10
fn $name: ident( $( $args: tt) * ) $( -> $ret: ty) ? $body: block
12
11
13
12
$( $rest: tt) *
14
13
} => {
15
14
$crate:: __inner_declare_class! {
16
- @rewrite_methods_inner
17
- @$output_type
18
- @$builder
19
- // Split args out so that we can match on `self`, while still use
20
- // it as a function argument
21
- ( $( $args) * )
15
+ @rewrite_self_arg
22
16
23
- $( #[ $( $m) * ] ) *
24
- fn $name( $( $args) * ) $( -> $ret) ? $body
17
+ // Duplicate args out so that we can match on `self`, while still
18
+ // use it as a function argument
19
+ @( $( $args) * )
20
+ // Split the function into parts, and send the arguments down to
21
+ // be used later on
22
+ @( $( $args) * )
23
+ @( $( #[ $( $m) * ] ) * )
24
+ @( $name)
25
+ @( $( $ret) ?)
26
+ @( $body)
27
+
28
+ #( $( $output) * )
25
29
}
26
30
27
31
$crate:: __inner_declare_class! {
28
32
@rewrite_methods
29
- @$output_type
30
- @$builder
33
+ @( $( $output) * )
31
34
32
35
$( $rest) *
33
36
}
34
37
} ;
35
38
36
39
// Instance method
37
40
{
38
- @rewrite_methods_inner
39
- @$output_type: ident
40
- @$builder: ident
41
- ( & mut self $( $__rest_args: tt) * )
42
-
43
- $( #[ $( $m: tt) * ] ) *
44
- fn $name: ident(
45
- & mut $self: ident
46
- $( , $( $rest_args: tt) * ) ?
47
- ) $( -> $ret: ty) ? $body: block
41
+ @rewrite_self_arg
42
+ @( & mut self $( $__rest_args: tt) * )
43
+ @( & mut $self: ident $( , $( $rest_args: tt) * ) ?)
44
+ $( $rest: tt) *
48
45
} => {
49
46
$crate:: __inner_declare_class! {
50
- @$output_type
51
- @instance_method
52
- @$name
53
- @$builder
54
- @( $( $( $rest_args) * ) ?)
55
-
56
- $( #[ $( $m) * ] ) *
57
- extern "C" fn $name(
58
- & mut $self,
47
+ @dispatch
48
+ @( instance_method)
49
+ @(
50
+ $self: & mut Self ,
59
51
_: $crate:: objc2:: runtime:: Sel ,
60
52
$( $( $rest_args) * ) ?
61
- ) $( -> $ret) ? $body
53
+ )
54
+ $( $rest) *
62
55
}
63
56
} ;
64
57
{
65
- @rewrite_methods_inner
66
- @$output_type: ident
67
- @$builder: ident
68
- ( & self $( $__rest_args: tt) * )
69
-
70
- $( #[ $( $m: tt) * ] ) *
71
- fn $name: ident(
72
- & $self: ident
73
- $( , $( $rest_args: tt) * ) ?
74
- ) $( -> $ret: ty) ? $body: block
58
+ @rewrite_self_arg
59
+ @( & self $( $__rest_args: tt) * )
60
+ @( & $self: ident $( , $( $rest_args: tt) * ) ?)
61
+ $( $rest: tt) *
75
62
} => {
76
63
$crate:: __inner_declare_class! {
77
- @$output_type
78
- @instance_method
79
- @$name
80
- @$builder
81
- @( $( $( $rest_args) * ) ?)
82
-
83
- $( #[ $( $m) * ] ) *
84
- extern "C" fn $name(
85
- & $self,
64
+ @dispatch
65
+ @( instance_method)
66
+ @(
67
+ $self: & Self ,
86
68
_: $crate:: objc2:: runtime:: Sel ,
87
69
$( $( $rest_args) * ) ?
88
- ) $( -> $ret) ? $body
70
+ )
71
+ $( $rest) *
89
72
}
90
73
} ;
91
74
{
92
- @rewrite_methods_inner
93
- @$output_type: ident
94
- @$builder: ident
95
- (
96
- mut self : $__self_ty: ty
97
- $( , $( $__rest_args: tt) * ) ?
98
- )
99
-
100
- $( #[ $( $m: tt) * ] ) *
101
- fn $name: ident(
102
- mut $self: ident: $self_ty: ty
103
- $( , $( $rest_args: tt) * ) ?
104
- ) $( -> $ret: ty) ? $body: block
75
+ @rewrite_self_arg
76
+ @( mut self : $__self_ty: ty $( , $( $__rest_args: tt) * ) ?)
77
+ @( mut $self: ident: $self_ty: ty $( , $( $rest_args: tt) * ) ?)
78
+ $( $rest: tt) *
105
79
} => {
106
80
$crate:: __inner_declare_class! {
107
- @$output_type
108
- @instance_method
109
- @$name
110
- @$builder
111
- @( $( $( $rest_args) * ) ?)
112
-
113
- $( #[ $( $m) * ] ) *
114
- extern "C" fn $name(
81
+ @dispatch
82
+ @( instance_method)
83
+ @(
115
84
mut $self: $self_ty,
116
85
_: $crate:: objc2:: runtime:: Sel ,
117
86
$( $( $rest_args) * ) ?
118
- ) $( -> $ret) ? $body
87
+ )
88
+ $( $rest) *
119
89
}
120
90
} ;
121
91
{
122
- @rewrite_methods_inner
123
- @$output_type: ident
124
- @$builder: ident
125
- (
126
- self : $__self_ty: ty
127
- $( , $( $__rest_args: tt) * ) ?
128
- )
129
-
130
- $( #[ $( $m: tt) * ] ) *
131
- fn $name: ident(
132
- $self: ident: $self_ty: ty
133
- $( , $( $rest_args: tt) * ) ?
134
- ) $( -> $ret: ty) ? $body: block
92
+ @rewrite_self_arg
93
+ @( self : $__self_ty: ty $( , $( $__rest_args: tt) * ) ?)
94
+ @( $self: ident: $self_ty: ty $( , $( $rest_args: tt) * ) ?)
95
+ $( $rest: tt) *
135
96
} => {
136
97
$crate:: __inner_declare_class! {
137
- @$output_type
138
- @instance_method
139
- @$name
140
- @$builder
141
- @( $( $( $rest_args) * ) ?)
142
-
143
- $( #[ $( $m) * ] ) *
144
- extern "C" fn $name(
98
+ @dispatch
99
+ @( instance_method)
100
+ @(
145
101
$self: $self_ty,
146
102
_: $crate:: objc2:: runtime:: Sel ,
147
103
$( $( $rest_args) * ) ?
148
- ) $( -> $ret) ? $body
104
+ )
105
+ $( $rest) *
149
106
}
150
107
} ;
151
-
152
108
// Class method
153
109
{
154
- @rewrite_methods_inner
155
- @$output_type: ident
156
- @$builder: ident
157
- ( $( $__args: tt) * )
158
-
159
- $( #[ $( $m: tt) * ] ) *
160
- fn $name: ident(
161
- $( $args: tt) *
162
- ) $( -> $ret: ty) ? $body: block
110
+ @rewrite_self_arg
111
+ @( $( $__args: tt) * )
112
+ @( $( $args: tt) * )
113
+ $( $rest: tt) *
163
114
} => {
164
115
$crate:: __inner_declare_class! {
165
- @$output_type
166
- @class_method
167
- @$name
168
- @$builder
169
- @( $( $args) * )
170
-
171
- $( #[ $( $m) * ] ) *
172
- extern "C" fn $name(
116
+ @dispatch
117
+ @( class_method)
118
+ @(
173
119
_: & $crate:: objc2:: runtime:: Class ,
174
120
_: $crate:: objc2:: runtime:: Sel ,
175
121
$( $args) *
176
- ) $( -> $ret) ? $body
122
+ )
123
+ $( $rest) *
177
124
}
178
125
} ;
179
126
180
127
{
181
- @method_out
182
- @$method_type: ident
183
- @$_name: ident
184
- @$builder: ident
185
- @( $( $builder_args: tt) * )
128
+ @dispatch
129
+ $(
130
+ @( $( $items: tt) * )
131
+ ) *
186
132
187
- $( #[ $( $m: tt) * ] ) *
188
- extern "C" fn $( $fn: tt) *
133
+ #( $( $output: tt) * )
134
+ } => {
135
+ $crate:: __inner_declare_class! {
136
+ @$( $output) *
137
+ $(
138
+ @( $( $items) * )
139
+ ) *
140
+ }
141
+ } ;
142
+
143
+ {
144
+ @method_out
145
+ @( $( $_kind: tt) * )
146
+ @( $( $args: tt) * )
147
+ @( $( #[ $( $m: tt) * ] ) * )
148
+ @( $name: ident)
149
+ @( $( $ret: ty) ?)
150
+ @( $( $body: tt) * )
151
+ $( $x: tt) *
189
152
} => {
190
153
$crate:: __attribute_helper! {
191
154
@strip_sel
192
155
$( @[ $( $m) * ] ) *
193
- ( extern "C" fn $( $fn ) * )
156
+ ( extern "C" fn $name ( $ ( $args ) * ) $ ( -> $ret ) ? $ ( $body ) * )
194
157
}
195
158
} ;
196
159
197
160
{
198
- @register_out
199
- @class_method
200
- @$name: ident
201
- @$builder: ident
202
- @( $( $builder_args: tt) * )
203
-
204
- $( #[ $( $m: tt) * ] ) *
205
- extern "C" fn $( $fn: tt) *
161
+ @register_out( $builder: ident)
162
+ @( class_method)
163
+ @( $( $args: tt) * )
164
+ @( $( #[ $( $m: tt) * ] ) * )
165
+ @( $name: ident)
166
+ @( $( $_ret: tt) * )
167
+ @( $( $_body: tt) * )
206
168
} => {
207
169
$builder. add_class_method(
208
170
$crate:: __attribute_helper! {
209
171
@extract_sel
210
172
$( #[ $( $m) * ] ) *
211
173
} ,
212
174
Self :: $name as $crate:: __extern_fn_ptr! {
213
- $( $builder_args ) *
175
+ $( $args ) *
214
176
} ,
215
177
) ;
216
178
} ;
217
179
{
218
- @register_out
219
- @instance_method
220
- @$name: ident
221
- @$builder: ident
222
- @( $( $builder_args: tt) * )
223
-
224
- $( #[ $( $m: tt) * ] ) *
225
- extern "C" fn $( $fn: tt) *
180
+ @register_out( $builder: ident)
181
+ @( instance_method)
182
+ @( $( $args: tt) * )
183
+ @( $( #[ $( $m: tt) * ] ) * )
184
+ @( $name: ident)
185
+ @( $( $_ret: tt) * )
186
+ @( $( $_body: tt) * )
226
187
} => {
227
188
$builder. add_method(
228
189
$crate:: __attribute_helper! {
229
190
@extract_sel
230
191
$( #[ $( $m) * ] ) *
231
192
} ,
232
193
Self :: $name as $crate:: __extern_fn_ptr! {
233
- $( $builder_args ) *
194
+ $( $args ) *
234
195
} ,
235
196
) ;
236
197
} ;
@@ -549,8 +510,7 @@ macro_rules! declare_class {
549
510
unsafe {
550
511
$crate:: __inner_declare_class! {
551
512
@rewrite_methods
552
- @register_out
553
- @builder
513
+ @( register_out( builder) )
554
514
555
515
$( $methods) *
556
516
}
@@ -570,8 +530,7 @@ macro_rules! declare_class {
570
530
impl $name {
571
531
$crate:: __inner_declare_class! {
572
532
@rewrite_methods
573
- @method_out
574
- @__builder
533
+ @( method_out)
575
534
576
535
$( $methods) *
577
536
}
0 commit comments