summaryrefslogtreecommitdiff
path: root/src/codegen/helpers.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2018-04-07 09:29:00 -0400
committerGitHub <noreply@github.com>2018-04-07 09:29:00 -0400
commit8fe4d63bb7f610d26704dbdfaa4a36b71660b084 (patch)
treecc354c9a53840e1ca9c6d38be2bc9f284fd6fa89 /src/codegen/helpers.rs
parent0a601d6b3cd9fc32e119db2c33961d8f4db7e89e (diff)
parent3258c5a949d2ef9290189b4b8fb2af635f1ba86a (diff)
Auto merge of #1303 - Eijebong:bump, r=emilio
Bump quote to 0.5
Diffstat (limited to 'src/codegen/helpers.rs')
-rw-r--r--src/codegen/helpers.rs48
1 files changed, 20 insertions, 28 deletions
diff --git a/src/codegen/helpers.rs b/src/codegen/helpers.rs
index 99054305..f1007c51 100644
--- a/src/codegen/helpers.rs
+++ b/src/codegen/helpers.rs
@@ -4,26 +4,28 @@ use ir::context::BindgenContext;
use ir::layout::Layout;
use quote;
use std::mem;
+use proc_macro2::{Term, Span};
pub mod attributes {
use quote;
+ use proc_macro2::{Term, Span};
pub fn repr(which: &str) -> quote::Tokens {
- let which = quote::Ident::new(which);
+ let which = Term::new(which, Span::call_site());
quote! {
#[repr( #which )]
}
}
pub fn repr_list(which_ones: &[&str]) -> quote::Tokens {
- let which_ones = which_ones.iter().cloned().map(quote::Ident::new);
+ let which_ones = which_ones.iter().cloned().map(|one| Term::new(one, Span::call_site()));
quote! {
#[repr( #( #which_ones ),* )]
}
}
pub fn derives(which_ones: &[&str]) -> quote::Tokens {
- let which_ones = which_ones.iter().cloned().map(quote::Ident::new);
+ let which_ones = which_ones.iter().cloned().map(|one| Term::new(one, Span::call_site()));
quote! {
#[derive( #( #which_ones ),* )]
}
@@ -40,9 +42,9 @@ pub mod attributes {
// time they get here. Just make sure that we have newlines around it so
// that nothing else gets wrapped into the comment.
let mut tokens = quote! {};
- tokens.append("\n");
- tokens.append(comment);
- tokens.append("\n");
+ tokens.append(Term::new("\n", Span::call_site()));
+ tokens.append(Term::new(&comment, Span::call_site()));
+ tokens.append(Term::new("\n", Span::call_site()));
tokens
}
@@ -73,7 +75,7 @@ pub fn blob(layout: Layout) -> quote::Tokens {
}
};
- let ty_name = quote::Ident::new(ty_name);
+ let ty_name = Term::new(ty_name, Span::call_site());
let data_len = opaque.array_size().unwrap_or(layout.size);
@@ -103,7 +105,7 @@ pub fn bitfield_unit(ctx: &BindgenContext, layout: Layout) -> quote::Tokens {
let mut tokens = quote! {};
if ctx.options().enable_cxx_namespaces {
- tokens.append(quote! { root:: });
+ tokens.append_all(quote! { root:: });
}
let align = match layout.align {
@@ -114,7 +116,7 @@ pub fn bitfield_unit(ctx: &BindgenContext, layout: Layout) -> quote::Tokens {
};
let size = layout.size;
- tokens.append(quote! {
+ tokens.append_all(quote! {
__BindgenBitfieldUnit<[u8; #size], #align>
});
@@ -126,6 +128,7 @@ pub mod ast_ty {
use ir::function::FunctionSig;
use ir::ty::FloatKind;
use quote;
+ use proc_macro2;
pub fn raw_type(ctx: &BindgenContext, name: &str) -> quote::Tokens {
let ident = ctx.rust_ident_raw(name);
@@ -166,29 +169,25 @@ pub mod ast_ty {
pub fn int_expr(val: i64) -> quote::Tokens {
// Don't use quote! { #val } because that adds the type suffix.
- let mut tokens = quote! {};
- tokens.append(val.to_string());
- tokens
+ let val = proc_macro2::Literal::i64_unsuffixed(val);
+ quote!(#val)
}
pub fn uint_expr(val: u64) -> quote::Tokens {
// Don't use quote! { #val } because that adds the type suffix.
- let mut tokens = quote! {};
- tokens.append(val.to_string());
- tokens
+ let val = proc_macro2::Literal::u64_unsuffixed(val);
+ quote!(#val)
}
pub fn byte_array_expr(bytes: &[u8]) -> quote::Tokens {
let mut bytes: Vec<_> = bytes.iter().cloned().collect();
bytes.push(0);
- quote! {
- #bytes
- }
+ quote! { [ #(#bytes),* ] }
}
pub fn cstr_expr(mut string: String) -> quote::Tokens {
string.push('\0');
- let b = quote::ByteStr(&string);
+ let b = proc_macro2::Literal::byte_string(&string.as_bytes());
quote! {
#b
}
@@ -199,16 +198,9 @@ pub mod ast_ty {
f: f64,
) -> Result<quote::Tokens, ()> {
if f.is_finite() {
- let mut string = f.to_string();
-
- // So it gets properly recognised as a floating point constant.
- if !string.contains('.') {
- string.push('.');
- }
+ let val = proc_macro2::Literal::f64_unsuffixed(f);
- let mut tokens = quote! {};
- tokens.append(string);
- return Ok(tokens);
+ return Ok(quote!(#val));
}
let prefix = ctx.trait_prefix();