1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
macro_rules! import_type_or_make_dummy {
(
types {$path:path} :: (
$( // Instruction name, base path part and root repetition block
$src_name:ident // The struct name to import
$(as $dst_name:ident)? // The name to reexport as
$(< $($lt:lifetime),+ $(,)? >)? // Matches, optionally, a separator comma, and a
// comma-separated lifetime list within angle
// brackets, with an optional trailing comma
),+
, // Mandatory trailing comma for the repitition list, or else teh compiler complains
// for some reason
),
cfg($pred:meta) // A cfg(...) predicate
$(,)? // Optional trailing comma for the whole macro
) => {$(
import_type_or_make_dummy!(
type
{$path}::$src_name
$(as $dst_name)?
$(< $($lt),+ >)?,
cfg($pred),
);
)+};
(
type // Instruction name
{$path:path}::$src_name:ident // The path to import, and the struct name
as $dst_name:ident // The name to reexport as
$(< $($lt:lifetime),+ $(,)? >)?, // From this point onwards, the same stuff as above
cfg($pred:meta)
$(,)?
) => {
#[cfg($pred)]
pub use $path::{$src_name as $dst_name};
#[cfg(not($pred))]
#[derive(Copy, Clone, Debug, Default)]
pub struct $dst_name // Expands the struct name
$(<$($lt),+>)? // Expands the lifetimes as declaration of generic parameters
($($(::core::marker::PhantomData<& $lt ()>),+)?); // Creates a tuple of PhantomData,
// one per lifetime
};
(
// Matches the same stuff, but without the `as`
type
{$path:path}::$name:ident
$(< $($lt:lifetime),+ $(,)? >)?,
cfg($pred:meta)
$(,)?
) => {
import_type_or_make_dummy!(type {$path}::$name as $name $(< $($lt),+ >)?, cfg($pred));
};
}
macro_rules! import_type_alias_or_make_dummy {
(
types {$path:path} :: ( // Instruction name and base path part
$( // Root repetition block
$src_name:ident // The type alias name to import
$(as $dst_name:ident)? // The type alias name to reexport as
= $dummy:ty // The fallback re-definition
$(,)? // Per-type-alias optional trailing comma
),+
, // Mandatory trailing comma, because an optional one breaks everything for some reason
),
cfg($pred:meta) // A cfg(...) predicate
$(,)? // Optional trailing comma for whole macro
) => {$(
import_type_alias_or_make_dummy!(
type {$path}::$src_name $(as $dst_name)? = $dummy,
cfg($pred),
);
)+};
(
type // Instruction name
{$path:path}::$src_name:ident // Path and type alias name to export
as $dst_name:ident // The same stuff as in the repeating case, basically
= $dummy:ty,
cfg($pred:meta)
$(,)?
) => {
#[cfg($pred)]
pub(super) use $path::{$src_name as $dst_name};
#[cfg(not($pred))]
pub(super) type $dst_name = $dummy;
};
(
type // Same as above, but without the `as` part
{$path:path}::$name:ident
= $dummy:ty,
cfg($pred:meta)
$(,)?
) => {
import_type_alias_or_make_dummy!(type {$path}::$name as $name = $dummy, cfg($pred));
};
}
macro_rules! import_const_or_make_dummy {
(
$ty:ty: consts {$path:path} :: ( // Instruction name, constant type and base path part
$( // Root repetition block
$src_name:ident // The constant name to import
$(as $dst_name:ident)? // The constant name to reexport as
= $dummy:expr // The fallback re-definition
$(,)? // Per-constant optional trailing comma
),+
, // Mandatory trailing comma, because an optional one breaks everything for some reason
),
cfg($pred:meta) // A cfg(...) predicate
$(,)? // Optional trailing comma for whole macro
) => {$(
import_const_or_make_dummy!(
$ty: const {$path}::$src_name $(as $dst_name)? = $dummy,
cfg($pred),
);
)+};
(
$ty:ty: const // Instruction name and constant type
{$path:path}::$src_name:ident // Path and constant name to export
as $dst_name:ident // The same stuff as in the repeating case, basically
= $dummy:expr,
cfg($pred:meta)
$(,)?
) => {
#[cfg($pred)]
pub(super) use $path::{$src_name as $dst_name};
#[cfg(not($pred))]
pub(super) const $dst_name: $ty = $dummy;
};
(
$ty:ty: const // Same as above, but without the `as` part
{$path:path}::$name:ident
= $dummy:expr,
cfg($pred:meta)
$(,)?
) => {
import_const_or_make_dummy!($ty: const {$path}::$name as $name = $dummy, cfg($pred));
};
}
macro_rules! import_trait_or_make_dummy {
(
traits {$path:path} :: ( // Instruction name and base path part
$( // Root repetition block
$(($unsafety:tt))? $src_name:ident // The trait name to import
$(as $dst_name:ident)? // The trait name to reexport as
),+
, // Mandatory trailing comma for the repetition, the compiler complains otherwise
),
cfg($pred:meta) // A cfg(...) predicate
$(,)? // Optional trailing comma for the whole macro
) => {$(
import_trait_or_make_dummy!(
$(($unsafety))? trait {$path}::$src_name $(as $dst_name)?,
cfg($pred),
);
)+};
(
$(($unsafety:tt))? trait // Instruction name, and whether the trait is unsafe
{$path:path}::$src_name:ident // Path and type alias name to export
as $dst_name:ident, // The same stuff as in the repeating case, basically
cfg($pred:meta)
$(,)?
) => {
#[cfg($pred)]
pub use $path::{$src_name as $dst_name};
#[cfg(not($pred))]
pub $($unsafety)? trait $dst_name {}
};
(
$(($unsafety:tt))? trait // Same as above, but without the `as` part
{$path:path}::$name:ident,
cfg($pred:meta)
$(,)?
) => {
import_trait_or_make_dummy!($(($unsafety))? trait {$path}::$name as $name, cfg($pred));
};
}