flux_attrs/
lib.rs

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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#[cfg(not(flux_sysroot))]
use attr_dummy as attr_impl;
#[cfg(flux_sysroot)]
use attr_sysroot as attr_impl;
use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn alias(attr: TokenStream, tokens: TokenStream) -> TokenStream {
    attr_impl::alias(attr, tokens)
}

#[proc_macro_attribute]
pub fn sig(attr: TokenStream, tokens: TokenStream) -> TokenStream {
    attr_impl::sig(attr, tokens)
}

#[proc_macro_attribute]
pub fn spec(attr: TokenStream, tokens: TokenStream) -> TokenStream {
    attr_impl::spec(attr, tokens)
}

#[proc_macro_attribute]
pub fn qualifiers(attr: TokenStream, tokens: TokenStream) -> TokenStream {
    attr_impl::qualifiers(attr, tokens)
}

#[proc_macro_attribute]
pub fn refined_by(attr: TokenStream, tokens: TokenStream) -> TokenStream {
    attr_impl::refined_by(attr, tokens)
}

#[proc_macro_attribute]
pub fn invariant(attr: TokenStream, tokens: TokenStream) -> TokenStream {
    attr_impl::invariant(attr, tokens)
}

#[proc_macro_attribute]
pub fn constant(attr: TokenStream, tokens: TokenStream) -> TokenStream {
    attr_impl::constant(attr, tokens)
}

#[proc_macro_attribute]
pub fn opaque(attr: TokenStream, tokens: TokenStream) -> TokenStream {
    attr_impl::opaque(attr, tokens)
}

#[proc_macro_attribute]
pub fn reflected(attr: TokenStream, tokens: TokenStream) -> TokenStream {
    attr_impl::reflected(attr, tokens)
}

#[proc_macro_attribute]
pub fn opts(attr: TokenStream, tokens: TokenStream) -> TokenStream {
    attr_impl::opts(attr, tokens)
}

#[proc_macro_attribute]
pub fn trusted(attr: TokenStream, tokens: TokenStream) -> TokenStream {
    attr_impl::trusted(attr, tokens)
}

#[proc_macro_attribute]
pub fn trusted_impl(attr: TokenStream, tokens: TokenStream) -> TokenStream {
    attr_impl::trusted_impl(attr, tokens)
}

#[proc_macro_attribute]
pub fn generics(attr: TokenStream, tokens: TokenStream) -> TokenStream {
    attr_impl::generics(attr, tokens)
}

#[proc_macro_attribute]
pub fn assoc(attr: TokenStream, tokens: TokenStream) -> TokenStream {
    attr_impl::assoc(attr, tokens)
}

#[proc_macro]
pub fn flux(tokens: TokenStream) -> TokenStream {
    flux_attrs_impl::flux(tokens.into()).into()
}

#[proc_macro]
pub fn defs(tokens: TokenStream) -> TokenStream {
    attr_impl::defs(tokens)
}

#[proc_macro_attribute]
pub fn extern_spec(attrs: TokenStream, tokens: TokenStream) -> TokenStream {
    attr_impl::extern_spec(attrs, tokens)
}

#[proc_macro_attribute]
pub fn ignore(attrs: TokenStream, tokens: TokenStream) -> TokenStream {
    attr_impl::ignore(attrs, tokens)
}

#[proc_macro_attribute]
pub fn should_fail(attrs: TokenStream, tokens: TokenStream) -> TokenStream {
    attr_impl::should_fail(attrs, tokens)
}

#[proc_macro_attribute]
pub fn reft(attrs: TokenStream, tokens: TokenStream) -> TokenStream {
    attr_impl::reft(attrs, tokens)
}

#[cfg(flux_sysroot)]
mod attr_sysroot {
    use super::*;

    pub fn extern_spec(attr: TokenStream, tokens: TokenStream) -> TokenStream {
        flux_attrs_impl::extern_spec(attr.into(), tokens.into()).into()
    }

    pub fn refined_by(attr: TokenStream, item: TokenStream) -> TokenStream {
        flux_attrs_impl::refined_by(attr.into(), item.into()).into()
    }

    pub fn defs(tokens: TokenStream) -> TokenStream {
        flux_attrs_impl::defs(tokens.into()).into()
    }

    macro_rules! flux_tool_attrs {
        ($($name:ident),+ $(,)?) => {
            $(
            pub fn $name(attr: TokenStream, item: TokenStream) -> TokenStream {
                flux_attrs_impl::flux_tool_item_attr(stringify!($name), attr.into(), item.into()).into()
            }
            )*
        };
    }

    flux_tool_attrs!(
        alias,
        spec,
        sig,
        qualifiers,
        constant,
        invariant,
        opaque,
        reflected,
        opts,
        trusted,
        trusted_impl,
        generics,
        assoc,
        ignore,
        should_fail,
        reft,
    );
}

#[cfg(not(flux_sysroot))]
mod attr_dummy {
    use super::*;

    pub fn refined_by(attr: TokenStream, item: TokenStream) -> TokenStream {
        flux_attrs_impl::refined_by(attr.into(), item.into()).into()
    }

    pub fn defs(_tokens: TokenStream) -> TokenStream {
        TokenStream::new()
    }

    pub fn extern_spec(_attrs: TokenStream, _tokens: TokenStream) -> TokenStream {
        TokenStream::new()
    }

    macro_rules! no_op {
        ($($name:ident),+ $(,)?) => {
            $(
            pub fn $name(_attr: TokenStream, item: TokenStream) -> TokenStream {
                item
            }
            )+
        };
    }

    no_op!(
        alias,
        spec,
        sig,
        qualifiers,
        invariant,
        constant,
        opaque,
        reflected,
        opts,
        trusted,
        trusted_impl,
        generics,
        assoc,
        ignore,
        should_fail,
        reft,
    );
}