Skip to content

Commit d2737da

Browse files
committed
Avoid @ in macros in favor of explicit internal macros
1 parent 15646bf commit d2737da

File tree

13 files changed

+393
-362
lines changed

13 files changed

+393
-362
lines changed

crates/icrate/src/additions/Foundation/macros/ns_string.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,17 @@ macro_rules! __ns_string {
8686
macro_rules! __ns_string_inner {
8787
($inp:ident) => {{
8888
const X: &[u8] = $inp.as_bytes();
89-
$crate::__ns_string_inner!(@inner X);
89+
$crate::__ns_string_static!(X);
9090
// Return &'static NSString
9191
CFSTRING.as_nsstring()
9292
}};
93-
(@inner $inp:ident) => {
93+
}
94+
95+
#[doc(hidden)]
96+
#[cfg(all(feature = "apple", feature = "unstable-static-nsstring"))]
97+
#[macro_export]
98+
macro_rules! __ns_string_static {
99+
($inp:ident) => {
94100
// Note: We create both the ASCII + NUL and the UTF-16 + NUL versions
95101
// of the string, since we can't conditionally create a static.
96102
//

crates/icrate/src/macros.rs

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,13 @@ macro_rules! extern_enum {
7070
),* $(,)?
7171
}
7272
) => {
73-
extern_enum! {
74-
@__inner
75-
@($v)
76-
@($ty)
77-
@($(
73+
extern_enum_inner! {
74+
($v)
75+
($ty)
76+
$(
7877
$(#[$field_m])*
7978
$field = $value,
80-
)*)
79+
)*
8180
}
8281
};
8382
(
@@ -94,45 +93,42 @@ macro_rules! extern_enum {
9493
$(#[$m])*
9594
$v type $name = $ty;
9695

97-
extern_enum! {
98-
@__inner
99-
@($v)
100-
@($name)
101-
@($(
96+
extern_enum_inner! {
97+
($v)
98+
($name)
99+
$(
102100
$(#[$field_m])*
103101
$field = $value,
104-
)*)
102+
)*
105103
}
106104
};
105+
}
107106

108-
// tt-munch each field
107+
// tt-munch each enum field
108+
macro_rules! extern_enum_inner {
109+
// Base case
109110
(
110-
@__inner
111-
@($v:vis)
112-
@($ty:ty)
113-
@()
114-
) => {
115-
// Base case
116-
};
111+
($v:vis)
112+
($ty:ty)
113+
) => {};
114+
115+
// Parse each field
117116
(
118-
@__inner
119-
@($v:vis)
120-
@($ty:ty)
121-
@(
122-
$(#[$field_m:meta])*
123-
$field:ident = $value:expr,
117+
($v:vis)
118+
($ty:ty)
124119

125-
$($rest:tt)*
126-
)
120+
$(#[$field_m:meta])*
121+
$field:ident = $value:expr,
122+
123+
$($rest:tt)*
127124
) => {
128125
$(#[$field_m])*
129126
$v const $field: $ty = $value;
130127

131-
extern_enum! {
132-
@__inner
133-
@($v)
134-
@($ty)
135-
@($($rest)*)
128+
extern_enum_inner! {
129+
($v)
130+
($ty)
131+
$($rest)*
136132
}
137133
};
138134
}

crates/objc2/src/declare/mod.rs

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ pub trait MethodImplementation: private::Sealed + Sized {
166166
fn __imp(self) -> Imp;
167167
}
168168

169-
macro_rules! method_decl_impl {
170-
(@<$($l:lifetime),*> T: $t_bound:ident $(+ $t_bound2:ident)?, $r:ident, $f:ty, $($t:ident),*) => {
169+
macro_rules! method_impl_generic {
170+
(<$($l:lifetime),*> T: $t_bound:ident $(+ $t_bound2:ident)?, $r:ident, $f:ty, $($t:ident),*) => {
171171
impl<$($l,)* T, $r, $($t),*> private::Sealed for $f
172172
where
173173
T: ?Sized + $t_bound $(+ $t_bound2)?,
@@ -190,7 +190,10 @@ macro_rules! method_decl_impl {
190190
}
191191
}
192192
};
193-
(@<$($l:lifetime),*> $callee:ident, $r:ident, $f:ty, $($t:ident),*) => {
193+
}
194+
195+
macro_rules! method_impl_concrete {
196+
(<$($l:lifetime),*> $callee:ident, $r:ident, $f:ty, $($t:ident),*) => {
194197
impl<$($l,)* $r, $($t),*> private::Sealed for $f
195198
where
196199
$r: EncodeReturn,
@@ -211,7 +214,10 @@ macro_rules! method_decl_impl {
211214
}
212215
}
213216
};
214-
(@<> Allocated<T>, $f:ty, $($t:ident),*) => {
217+
}
218+
219+
macro_rules! method_impl_allocated {
220+
(<> Allocated<T>, $f:ty, $($t:ident),*) => {
215221
#[doc(hidden)]
216222
impl<T, $($t),*> private::Sealed for $f
217223
where
@@ -242,48 +248,54 @@ macro_rules! method_decl_impl {
242248
}
243249
}
244250
};
245-
(# $abi:literal; $($t:ident),*) => {
246-
method_decl_impl!(@<'a> T: Message, R, extern $abi fn(&'a T, Sel $(, $t)*) -> R, $($t),*);
247-
method_decl_impl!(@<'a> T: Message + IsMutable, R, extern $abi fn(&'a mut T, Sel $(, $t)*) -> R, $($t),*);
248-
method_decl_impl!(@<> T: Message, R, unsafe extern $abi fn(*const T, Sel $(, $t)*) -> R, $($t),*);
249-
method_decl_impl!(@<> T: Message, R, unsafe extern $abi fn(*mut T, Sel $(, $t)*) -> R, $($t),*);
250-
method_decl_impl!(@<'a> T: Message, R, unsafe extern $abi fn(&'a T, Sel $(, $t)*) -> R, $($t),*);
251-
method_decl_impl!(@<'a> T: Message + IsMutable, R, unsafe extern $abi fn(&'a mut T, Sel $(, $t)*) -> R, $($t),*);
252-
253-
method_decl_impl!(@<'a> AnyObject, R, extern $abi fn(&'a mut AnyObject, Sel $(, $t)*) -> R, $($t),*);
254-
method_decl_impl!(@<'a> AnyObject, R, unsafe extern $abi fn(&'a mut AnyObject, Sel $(, $t)*) -> R, $($t),*);
255-
256-
method_decl_impl!(@<'a> AnyClass, R, extern $abi fn(&'a AnyClass, Sel $(, $t)*) -> R, $($t),*);
257-
method_decl_impl!(@<> AnyClass, R, unsafe extern $abi fn(*const AnyClass, Sel $(, $t)*) -> R, $($t),*);
258-
method_decl_impl!(@<'a> AnyClass, R, unsafe extern $abi fn(&'a AnyClass, Sel $(, $t)*) -> R, $($t),*);
259-
260-
method_decl_impl!(@<> Allocated<T>, extern $abi fn(Allocated<T>, Sel $(, $t)*) -> __IdReturnValue, $($t),*);
261-
method_decl_impl!(@<> Allocated<T>, unsafe extern $abi fn(Allocated<T>, Sel $(, $t)*) -> __IdReturnValue, $($t),*);
251+
}
252+
253+
macro_rules! method_impl_abi {
254+
($abi:literal; $($t:ident),*) => {
255+
method_impl_generic!(<'a> T: Message, R, extern $abi fn(&'a T, Sel $(, $t)*) -> R, $($t),*);
256+
method_impl_generic!(<'a> T: Message + IsMutable, R, extern $abi fn(&'a mut T, Sel $(, $t)*) -> R, $($t),*);
257+
method_impl_generic!(<> T: Message, R, unsafe extern $abi fn(*const T, Sel $(, $t)*) -> R, $($t),*);
258+
method_impl_generic!(<> T: Message, R, unsafe extern $abi fn(*mut T, Sel $(, $t)*) -> R, $($t),*);
259+
method_impl_generic!(<'a> T: Message, R, unsafe extern $abi fn(&'a T, Sel $(, $t)*) -> R, $($t),*);
260+
method_impl_generic!(<'a> T: Message + IsMutable, R, unsafe extern $abi fn(&'a mut T, Sel $(, $t)*) -> R, $($t),*);
261+
262+
method_impl_concrete!(<'a> AnyObject, R, extern $abi fn(&'a mut AnyObject, Sel $(, $t)*) -> R, $($t),*);
263+
method_impl_concrete!(<'a> AnyObject, R, unsafe extern $abi fn(&'a mut AnyObject, Sel $(, $t)*) -> R, $($t),*);
264+
265+
method_impl_concrete!(<'a> AnyClass, R, extern $abi fn(&'a AnyClass, Sel $(, $t)*) -> R, $($t),*);
266+
method_impl_concrete!(<> AnyClass, R, unsafe extern $abi fn(*const AnyClass, Sel $(, $t)*) -> R, $($t),*);
267+
method_impl_concrete!(<'a> AnyClass, R, unsafe extern $abi fn(&'a AnyClass, Sel $(, $t)*) -> R, $($t),*);
268+
269+
method_impl_allocated!(<> Allocated<T>, extern $abi fn(Allocated<T>, Sel $(, $t)*) -> __IdReturnValue, $($t),*);
270+
method_impl_allocated!(<> Allocated<T>, unsafe extern $abi fn(Allocated<T>, Sel $(, $t)*) -> __IdReturnValue, $($t),*);
262271
};
272+
}
273+
274+
macro_rules! method_impl {
263275
($($t:ident),*) => {
264-
method_decl_impl!(# "C"; $($t),*);
276+
method_impl_abi!("C"; $($t),*);
265277
#[cfg(feature = "unstable-c-unwind")]
266-
method_decl_impl!(# "C-unwind"; $($t),*);
278+
method_impl_abi!("C-unwind"; $($t),*);
267279
};
268280
}
269281

270-
method_decl_impl!();
271-
method_decl_impl!(A);
272-
method_decl_impl!(A, B);
273-
method_decl_impl!(A, B, C);
274-
method_decl_impl!(A, B, C, D);
275-
method_decl_impl!(A, B, C, D, E);
276-
method_decl_impl!(A, B, C, D, E, F);
277-
method_decl_impl!(A, B, C, D, E, F, G);
278-
method_decl_impl!(A, B, C, D, E, F, G, H);
279-
method_decl_impl!(A, B, C, D, E, F, G, H, I);
280-
method_decl_impl!(A, B, C, D, E, F, G, H, I, J);
281-
method_decl_impl!(A, B, C, D, E, F, G, H, I, J, K);
282-
method_decl_impl!(A, B, C, D, E, F, G, H, I, J, K, L);
283-
method_decl_impl!(A, B, C, D, E, F, G, H, I, J, K, L, M);
284-
method_decl_impl!(A, B, C, D, E, F, G, H, I, J, K, L, M, N);
285-
method_decl_impl!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O);
286-
method_decl_impl!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P);
282+
method_impl!();
283+
method_impl!(A);
284+
method_impl!(A, B);
285+
method_impl!(A, B, C);
286+
method_impl!(A, B, C, D);
287+
method_impl!(A, B, C, D, E);
288+
method_impl!(A, B, C, D, E, F);
289+
method_impl!(A, B, C, D, E, F, G);
290+
method_impl!(A, B, C, D, E, F, G, H);
291+
method_impl!(A, B, C, D, E, F, G, H, I);
292+
method_impl!(A, B, C, D, E, F, G, H, I, J);
293+
method_impl!(A, B, C, D, E, F, G, H, I, J, K);
294+
method_impl!(A, B, C, D, E, F, G, H, I, J, K, L);
295+
method_impl!(A, B, C, D, E, F, G, H, I, J, K, L, M);
296+
method_impl!(A, B, C, D, E, F, G, H, I, J, K, L, M, N);
297+
method_impl!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O);
298+
method_impl!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P);
287299

288300
/// Helper type for implementing `MethodImplementation` with a receiver of
289301
/// `Allocated<T>`, without exposing that implementation to users.

crates/objc2/src/macros/__attribute_helpers.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,40 @@
99
macro_rules! __extract_and_apply_cfg_attributes {
1010
// Base case
1111
{
12-
@() // No attributes left to process
13-
@($($output:tt)*)
12+
() // No attributes left to process
13+
$($output:tt)*
1414
} => {
1515
$($output)*
1616
};
1717
// `cfg` attribute
1818
{
19-
@(
19+
(
2020
#[cfg $($args:tt)*]
2121
$($m_rest:tt)*
2222
)
23-
@($($output:tt)*)
23+
$($output:tt)*
2424
} => {
2525
// Apply the attribute and continue
2626
#[cfg $($args)*]
2727
{
2828
$crate::__extract_and_apply_cfg_attributes! {
29-
@($($m_rest)*)
30-
@($($output)*)
29+
($($m_rest)*)
30+
$($output)*
3131
}
3232
}
3333
};
3434
// Other attributes
3535
{
36-
@(
36+
(
3737
#[$($m_ignored:tt)*]
3838
$($m_rest:tt)*
3939
)
40-
@($($output:tt)*)
40+
$($output:tt)*
4141
} => {
4242
// Ignore the attribute, and continue parsing the rest
4343
$crate::__extract_and_apply_cfg_attributes! {
44-
@($($m_rest)*)
45-
@($($output)*)
44+
($($m_rest)*)
45+
$($output)*
4646
}
4747
};
4848
}

crates/objc2/src/macros/__method_msg_send.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ macro_rules! __method_msg_send {
1515
()
1616
) => {
1717
$crate::__msg_send_helper! {
18-
@(send_message)
19-
@($receiver)
20-
@($sel)
21-
@()
18+
($receiver)
19+
(send_message)
20+
($sel)
21+
()
2222
}
2323
};
2424

@@ -95,10 +95,10 @@ macro_rules! __method_msg_send {
9595
($($arg_parsed:tt)*)
9696
) => {
9797
$crate::__msg_send_helper! {
98-
@(send_message)
99-
@($receiver)
100-
@($($sel_parsed)*)
101-
@($($arg_parsed)*)
98+
($receiver)
99+
(send_message)
100+
($($sel_parsed)*)
101+
($($arg_parsed)*)
102102
}
103103
};
104104

@@ -113,11 +113,11 @@ macro_rules! __method_msg_send {
113113
($($arg_parsed:tt)*)
114114
) => {
115115
$crate::__msg_send_helper! {
116+
($receiver)
116117
// Use error method
117-
@(__send_message_error)
118-
@($receiver)
119-
@($($sel_parsed)* $sel :)
120-
@($($arg_parsed)*)
118+
(__send_message_error)
119+
($($sel_parsed)* $sel :)
120+
($($arg_parsed)*)
121121
}
122122
};
123123

@@ -165,11 +165,11 @@ macro_rules! __method_msg_send_id {
165165
($($retain_semantics:ident)?)
166166
) => {
167167
$crate::__msg_send_id_helper! {
168-
@(send_message_id)
169-
@($receiver)
170-
@($($retain_semantics)?)
171-
@($sel)
172-
@()
168+
($receiver)
169+
($($retain_semantics)?)
170+
(send_message_id)
171+
($sel)
172+
()
173173
}
174174
};
175175

@@ -253,11 +253,11 @@ macro_rules! __method_msg_send_id {
253253
($($retain_semantics:ident)?)
254254
) => {
255255
$crate::__msg_send_id_helper! {
256-
@(send_message_id)
257-
@($receiver)
258-
@($($retain_semantics)?)
259-
@($($sel_parsed)*)
260-
@($($arg_parsed)*)
256+
($receiver)
257+
($($retain_semantics)?)
258+
(send_message_id)
259+
($($sel_parsed)*)
260+
($($arg_parsed)*)
261261
}
262262
};
263263

@@ -273,12 +273,12 @@ macro_rules! __method_msg_send_id {
273273
($($retain_semantics:ident)?)
274274
) => {
275275
$crate::__msg_send_id_helper! {
276+
($receiver)
277+
($($retain_semantics)?)
276278
// Use error method
277-
@(send_message_id_error)
278-
@($receiver)
279-
@($($retain_semantics)?)
280-
@($($sel_parsed)* $sel :)
281-
@($($arg_parsed)*)
279+
(send_message_id_error)
280+
($($sel_parsed)* $sel :)
281+
($($arg_parsed)*)
282282
}
283283
};
284284

0 commit comments

Comments
 (0)