3
3
use ir:: context:: BindgenContext ;
4
4
use ir:: layout:: Layout ;
5
5
use quote;
6
- use proc_macro2;
7
6
use std:: mem;
8
7
9
8
pub mod attributes {
10
9
use quote;
11
- use proc_macro2;
12
10
13
11
pub fn repr ( which : & str ) -> quote:: Tokens {
14
- let which = proc_macro2 :: Term :: intern ( which) ;
12
+ let which = quote :: Ident :: new ( which) ;
15
13
quote ! {
16
14
#[ repr( #which ) ]
17
15
}
18
16
}
19
17
20
18
pub fn repr_list ( which_ones : & [ & str ] ) -> quote:: Tokens {
21
- let which_ones = which_ones. iter ( ) . cloned ( ) . map ( proc_macro2 :: Term :: intern ) ;
19
+ let which_ones = which_ones. iter ( ) . cloned ( ) . map ( quote :: Ident :: new ) ;
22
20
quote ! {
23
21
#[ repr( #( #which_ones ) , * ) ]
24
22
}
25
23
}
26
24
27
25
pub fn derives ( which_ones : & [ & str ] ) -> quote:: Tokens {
28
- let which_ones = which_ones. iter ( ) . cloned ( ) . map ( proc_macro2 :: Term :: intern ) ;
26
+ let which_ones = which_ones. iter ( ) . cloned ( ) . map ( quote :: Ident :: new ) ;
29
27
quote ! {
30
28
#[ derive( #( #which_ones ) , * ) ]
31
29
}
@@ -41,8 +39,11 @@ pub mod attributes {
41
39
// Doc comments are already preprocessed into nice `///` formats by the
42
40
// time they get here. Just make sure that we have newlines around it so
43
41
// that nothing else gets wrapped into the comment.
44
- let comment = proc_macro2:: Literal :: doccomment ( & comment) ;
45
- quote ! { #comment}
42
+ let mut tokens = quote ! { } ;
43
+ tokens. append ( "\n " ) ;
44
+ tokens. append ( comment) ;
45
+ tokens. append ( "\n " ) ;
46
+ tokens
46
47
}
47
48
48
49
pub fn link_name ( name : & str ) -> quote:: Tokens {
@@ -72,7 +73,7 @@ pub fn blob(layout: Layout) -> quote::Tokens {
72
73
}
73
74
} ;
74
75
75
- let ty_name = proc_macro2 :: Term :: intern ( ty_name) ;
76
+ let ty_name = quote :: Ident :: new ( ty_name) ;
76
77
77
78
let data_len = opaque. array_size ( ) . unwrap_or ( layout. size ) ;
78
79
@@ -102,7 +103,7 @@ pub fn bitfield_unit(ctx: &BindgenContext, layout: Layout) -> quote::Tokens {
102
103
let mut tokens = quote ! { } ;
103
104
104
105
if ctx. options ( ) . enable_cxx_namespaces {
105
- tokens. append_all ( quote ! { root:: } ) ;
106
+ tokens. append ( quote ! { root:: } ) ;
106
107
}
107
108
108
109
let align = match layout. align {
@@ -113,7 +114,7 @@ pub fn bitfield_unit(ctx: &BindgenContext, layout: Layout) -> quote::Tokens {
113
114
} ;
114
115
115
116
let size = layout. size ;
116
- tokens. append_all ( quote ! {
117
+ tokens. append ( quote ! {
117
118
__BindgenBitfieldUnit<[ u8 ; #size] , #align>
118
119
} ) ;
119
120
@@ -125,7 +126,6 @@ pub mod ast_ty {
125
126
use ir:: function:: FunctionSig ;
126
127
use ir:: ty:: FloatKind ;
127
128
use quote;
128
- use proc_macro2;
129
129
130
130
pub fn raw_type ( ctx : & BindgenContext , name : & str ) -> quote:: Tokens {
131
131
let ident = ctx. rust_ident_raw ( name) ;
@@ -166,25 +166,29 @@ pub mod ast_ty {
166
166
167
167
pub fn int_expr ( val : i64 ) -> quote:: Tokens {
168
168
// Don't use quote! { #val } because that adds the type suffix.
169
- let val = proc_macro2:: Literal :: integer ( val) ;
170
- quote ! ( #val)
169
+ let mut tokens = quote ! { } ;
170
+ tokens. append ( val. to_string ( ) ) ;
171
+ tokens
171
172
}
172
173
173
174
pub fn uint_expr ( val : u64 ) -> quote:: Tokens {
174
175
// Don't use quote! { #val } because that adds the type suffix.
175
- let val = proc_macro2:: Term :: intern ( & val. to_string ( ) ) ;
176
- quote ! ( #val)
176
+ let mut tokens = quote ! { } ;
177
+ tokens. append ( val. to_string ( ) ) ;
178
+ tokens
177
179
}
178
180
179
181
pub fn byte_array_expr ( bytes : & [ u8 ] ) -> quote:: Tokens {
180
182
let mut bytes: Vec < _ > = bytes. iter ( ) . cloned ( ) . collect ( ) ;
181
183
bytes. push ( 0 ) ;
182
- quote ! { [ #( #bytes) , * ] }
184
+ quote ! {
185
+ #bytes
186
+ }
183
187
}
184
188
185
189
pub fn cstr_expr ( mut string : String ) -> quote:: Tokens {
186
190
string. push ( '\0' ) ;
187
- let b = proc_macro2 :: Literal :: byte_string ( & string. as_bytes ( ) ) ;
191
+ let b = quote :: ByteStr ( & string) ;
188
192
quote ! {
189
193
#b
190
194
}
@@ -195,9 +199,16 @@ pub mod ast_ty {
195
199
f : f64 ,
196
200
) -> Result < quote:: Tokens , ( ) > {
197
201
if f. is_finite ( ) {
198
- let val = proc_macro2:: Literal :: float ( f) ;
202
+ let mut string = f. to_string ( ) ;
203
+
204
+ // So it gets properly recognised as a floating point constant.
205
+ if !string. contains ( '.' ) {
206
+ string. push ( '.' ) ;
207
+ }
199
208
200
- return Ok ( quote ! ( #val) ) ;
209
+ let mut tokens = quote ! { } ;
210
+ tokens. append ( string) ;
211
+ return Ok ( tokens) ;
201
212
}
202
213
203
214
let prefix = ctx. trait_prefix ( ) ;
0 commit comments