objc2/macros/
__msg_send_parse.rs

1#[doc(hidden)]
2#[macro_export]
3macro_rules! __msg_send_parse {
4    // No arguments
5    {
6        // Intentionally empty
7        ()
8        ()
9        ($selector:ident $(,)?)
10
11        ($($error_data:tt)*)
12        ($($data:tt)*)
13
14        ($out_macro:path)
15        $($macro_args:tt)*
16    } => {
17        $crate::__msg_send_parse! {
18            ($selector)
19            ()
20            ()
21
22            ($($error_data)*)
23            ($($data)*)
24
25            ($out_macro)
26            $($macro_args)*
27        }
28    };
29
30    // tt-munch remaining `selector: argument` pairs, looking for a pattern
31    // that ends with `sel: _`.
32    {
33        ($($selector_output:tt)*)
34        ($($argument_output:tt)*)
35        ()
36
37        ($($error_data:tt)*)
38        ($($data:tt)*)
39
40        ($out_macro:path)
41        $($macro_args:tt)*
42    } => ({
43        $out_macro! {
44            $($macro_args)*
45
46            ($($data)*)
47            ($($selector_output)*)
48            ($($argument_output)*)
49        }
50    });
51    {
52        ($($selector_output:tt)*)
53        ($($argument_output:tt)*)
54        ($selector:ident: _ $(,)?)
55
56        ($($error_data:tt)*)
57        ($($data:tt)*)
58
59        ($out_macro:path)
60        $($macro_args:tt)*
61    } => {
62        $crate::__msg_send_parse! {
63            ($($selector_output)* $selector:)
64            // Don't pass an argument
65            ($($argument_output)*)
66            ()
67
68            // Instead, we change the data to the error data.
69            ($($error_data)*)
70            ($($error_data)*)
71
72            ($out_macro)
73            $($macro_args)*
74        }
75    };
76    {
77        ($($selector_output:tt)*)
78        ($($argument_output:tt)*)
79        ($selector:ident : $argument:expr $(, $($rest:tt)*)?)
80
81        ($($error_data:tt)*)
82        ($($data:tt)*)
83
84        ($out_macro:path)
85        $($macro_args:tt)*
86    } => {
87        $crate::__msg_send_parse! {
88            ($($selector_output)* $selector:)
89            ($($argument_output)* $argument,)
90            ($($($rest)*)?)
91
92            ($($error_data)*)
93            ($($data)*)
94
95            ($out_macro)
96            $($macro_args)*
97        }
98    };
99
100    // Handle calls without comma between `selector: argument` pair.
101    {
102        // Intentionally empty
103        ()
104        ()
105        ($($selector:ident : $argument:expr)*)
106
107        ($($error_data:tt)*)
108        ($($data:tt)*)
109
110        ($out_macro:path)
111        $($macro_args:tt)*
112    } => {{
113        $crate::__missing_comma_between_args!(
114            ($($data)*)
115
116            ($(
117                ", ",
118                $crate::__macro_helpers::stringify!($selector),
119                ": ",
120                $crate::__macro_helpers::stringify!($argument),
121            )+)
122
123            $($macro_args)*
124        );
125
126        $crate::__msg_send_parse! {
127            ()
128            ()
129            ($($selector : $argument),*)
130
131            ($($error_data)*)
132            ($($data)*)
133
134            ($out_macro)
135            $($macro_args)*
136        }
137    }};
138}
139
140#[doc(hidden)]
141#[macro_export]
142macro_rules! __missing_comma_between_args {
143    (
144        (MsgSendSuper::send_super_message_static)
145        ($($args:tt)*)
146        ($obj:expr)
147        ()
148    ) => {
149        $crate::__missing_comma_between_args_inner!(
150            "super", $crate::__macro_helpers::stringify!(($obj)), $($args)*
151        );
152    };
153    (
154        (MsgSendSuper::send_super_message)
155        ($($args:tt)*)
156        ($obj:expr, $superclass:expr)
157        ()
158    ) => {
159        $crate::__missing_comma_between_args_inner!(
160            "super", $crate::__macro_helpers::stringify!(($obj, $superclass)), $($args)*
161        );
162    };
163    (
164        (MsgSend::send_message)
165        ($($args:tt)*)
166        ($obj:expr)
167        ()
168    ) => {
169        $crate::__missing_comma_between_args_inner!(
170            $crate::__macro_helpers::stringify!($obj), $($args)*
171        );
172    };
173}
174
175#[doc(hidden)]
176#[macro_export]
177macro_rules! __missing_comma_between_args_inner {
178    ($($args:tt)*) => {{
179        #[deprecated = $crate::__macro_helpers::concat!(
180            "using msg_send! without a comma between arguments is ",
181            "technically not valid macro syntax, and may break in a future ",
182            "version of Rust. You should use the following instead:\n",
183            "msg_send![", $($args)* "]"
184        )]
185        #[inline]
186        fn __missing_comma() {}
187        __missing_comma();
188    }};
189}