diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/codegen/helpers.rs | 24 | ||||
-rw-r--r-- | src/codegen/mod.rs | 40 | ||||
-rw-r--r-- | src/codegen/struct_layout.rs | 4 | ||||
-rw-r--r-- | src/ir/comment.rs | 12 | ||||
-rw-r--r-- | src/ir/context.rs | 10 | ||||
-rw-r--r-- | src/ir/objc.rs | 6 |
6 files changed, 47 insertions, 49 deletions
diff --git a/src/codegen/helpers.rs b/src/codegen/helpers.rs index ca93b519..a73f02ae 100644 --- a/src/codegen/helpers.rs +++ b/src/codegen/helpers.rs @@ -3,29 +3,29 @@ use ir::context::BindgenContext; use ir::layout::Layout; use quote; -use proc_macro2; use std::mem; +use proc_macro2::{Term, Span}; pub mod attributes { use quote; - use proc_macro2; + use proc_macro2::{Term, Span}; pub fn repr(which: &str) -> quote::Tokens { - let which = proc_macro2::Term::intern(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(proc_macro2::Term::intern); + 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(proc_macro2::Term::intern); + let which_ones = which_ones.iter().cloned().map(|one| Term::new(one, Span::call_site())); quote! { #[derive( #( #which_ones ),* )] } @@ -38,11 +38,7 @@ pub mod attributes { } pub fn doc(comment: String) -> quote::Tokens { - // Doc comments are already preprocessed into nice `///` formats by the - // time they get here. Just make sure that we have newlines around it so - // that nothing else gets wrapped into the comment. - let comment = proc_macro2::Literal::doccomment(&comment); - quote! {#comment} + quote!(#[doc=#comment]) } pub fn link_name(name: &str) -> quote::Tokens { @@ -72,7 +68,7 @@ pub fn blob(layout: Layout) -> quote::Tokens { } }; - let ty_name = proc_macro2::Term::intern(ty_name); + let ty_name = Term::new(ty_name, Span::call_site()); let data_len = opaque.array_size().unwrap_or(layout.size); @@ -166,13 +162,13 @@ pub mod ast_ty { pub fn int_expr(val: i64) -> quote::Tokens { // Don't use quote! { #val } because that adds the type suffix. - let val = proc_macro2::Literal::integer(val); + 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 val = proc_macro2::Term::intern(&val.to_string()); + let val = proc_macro2::Literal::u64_unsuffixed(val); quote!(#val) } @@ -195,7 +191,7 @@ pub mod ast_ty { f: f64, ) -> Result<quote::Tokens, ()> { if f.is_finite() { - let val = proc_macro2::Literal::float(f); + let val = proc_macro2::Literal::f64_unsuffixed(f); return Ok(quote!(#val)); } diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 1df7a5d0..63e1e11e 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -38,7 +38,7 @@ use ir::ty::{Type, TypeKind}; use ir::var::Var; use quote; -use proc_macro2; +use proc_macro2::{self, Term, Span}; use std::borrow::Cow; use std::cell::Cell; @@ -75,7 +75,7 @@ fn root_import(ctx: &BindgenContext, module: &Item) -> quote::Tokens { let mut tokens = quote! {}; - tokens.append_separated(path, proc_macro2::Term::intern("::")); + tokens.append_separated(path, Term::new("::", Span::call_site())); quote! { #[allow(unused_imports)] @@ -706,7 +706,7 @@ impl CodeGenerator for Type { pub use }); let path = top_level_path(ctx, item); - tokens.append_separated(path, proc_macro2::Term::intern("::")); + tokens.append_separated(path, Term::new("::", Span::call_site())); tokens.append_all(quote! { :: #inner_rust_type as #rust_name ; }); @@ -1123,7 +1123,7 @@ impl<'a> FieldCodegen<'a> for FieldData { impl BitfieldUnit { /// Get the constructor name for this bitfield unit. fn ctor_name(&self) -> quote::Tokens { - let ctor_name = proc_macro2::Term::intern(&format!("new_bitfield_{}", self.nth())); + let ctor_name = Term::new(&format!("new_bitfield_{}", self.nth()), Span::call_site()); quote! { #ctor_name } @@ -1322,7 +1322,7 @@ impl<'a> FieldCodegen<'a> for Bitfield { let prefix = ctx.trait_prefix(); let getter_name = bitfield_getter_name(ctx, self); let setter_name = bitfield_setter_name(ctx, self); - let unit_field_ident = proc_macro2::Term::intern(unit_field_name); + let unit_field_ident = Term::new(unit_field_name, Span::call_site()); let bitfield_ty_item = ctx.resolve_item(self.ty()); let bitfield_ty = bitfield_ty_item.expect_type(); @@ -2147,7 +2147,7 @@ enum EnumBuilder<'a> { Rust { codegen_depth: usize, attrs: Vec<quote::Tokens>, - ident: proc_macro2::Term, + ident: Term, tokens: quote::Tokens, emitted_any_variants: bool, }, @@ -2187,7 +2187,7 @@ impl<'a> EnumBuilder<'a> { enum_variation: EnumVariation, enum_codegen_depth: usize, ) -> Self { - let ident = proc_macro2::Term::intern(name); + let ident = Term::new(name, Span::call_site()); match enum_variation { EnumVariation::Bitfield => { @@ -2225,7 +2225,7 @@ impl<'a> EnumBuilder<'a> { } EnumVariation::ModuleConsts => { - let ident = proc_macro2::Term::intern(CONSTIFIED_ENUM_MODULE_REPR_NAME); + let ident = Term::new(CONSTIFIED_ENUM_MODULE_REPR_NAME, Span::call_site()); let type_definition = quote! { #( #attrs )* pub type #ident = #repr; @@ -2514,12 +2514,12 @@ impl CodeGenerator for Enum { ctx: &BindgenContext, enum_: &Type, // Only to avoid recomputing every time. - enum_canonical_name: &proc_macro2::Term, + enum_canonical_name: &Term, // May be the same as "variant" if it's because the // enum is unnamed and we still haven't seen the // value. variant_name: &str, - referenced_name: &proc_macro2::Term, + referenced_name: &Term, enum_rust_ty: quote::Tokens, result: &mut CodegenResult<'a>, ) { @@ -2554,7 +2554,7 @@ impl CodeGenerator for Enum { ); // A map where we keep a value -> variant relation. - let mut seen_values = HashMap::<_, proc_macro2::Term>::new(); + let mut seen_values = HashMap::<_, Term>::new(); let enum_rust_ty = item.to_rust_ty_or_opaque(ctx, &()); let is_toplevel = item.is_toplevel(ctx); @@ -2652,12 +2652,13 @@ impl CodeGenerator for Enum { let parent_name = parent_canonical_name.as_ref().unwrap(); - proc_macro2::Term::intern( + Term::new( &format!( "{}_{}", parent_name, variant_name.as_str() - ) + ), + Span::call_site() ) }; @@ -3000,7 +3001,7 @@ impl TryToRustTy for Type { } TypeKind::Enum(..) => { let path = item.namespace_aware_canonical_path(ctx); - let path = proc_macro2::Term::intern(&path.join("::")); + let path = Term::new(&path.join("::"), Span::call_site()); Ok(quote!(#path)) } TypeKind::TemplateInstantiation(ref inst) => { @@ -3123,7 +3124,7 @@ impl TryToRustTy for TemplateInstantiation { let mut ty = quote! {}; let def_path = def.namespace_aware_canonical_path(ctx); - ty.append_separated(def_path.into_iter().map(|p| ctx.rust_ident(p)), proc_macro2::Term::intern("::")); + ty.append_separated(def_path.into_iter().map(|p| ctx.rust_ident(p)), Term::new("::", Span::call_site())); let def_params = match def.self_template_params(ctx) { Some(params) => params, @@ -3462,11 +3463,11 @@ mod utils { use ir::item::{Item, ItemCanonicalPath}; use ir::ty::TypeKind; use quote; - use proc_macro2; + use proc_macro2::{Term, Span}; use std::mem; pub fn prepend_bitfield_unit_type(result: &mut Vec<quote::Tokens>) { - let bitfield_unit_type = proc_macro2::Term::intern(include_str!("./bitfield_unit.rs")); + let bitfield_unit_type = Term::new(include_str!("./bitfield_unit.rs"), Span::call_site()); let bitfield_unit_type = quote!(#bitfield_unit_type); let items = vec![bitfield_unit_type]; @@ -3693,9 +3694,10 @@ mod utils { item: &Item, ctx: &BindgenContext, ) -> error::Result<quote::Tokens> { - use proc_macro2; + use proc_macro2::{Term, Span}; + let path = item.namespace_aware_canonical_path(ctx); - let path = proc_macro2::Term::intern(&path.join("::")); + let path = Term::new(&path.join("::"), Span::call_site()); let tokens = quote! {#path}; //tokens.append_separated(path, "::"); diff --git a/src/codegen/struct_layout.rs b/src/codegen/struct_layout.rs index f576211b..6de7e030 100644 --- a/src/codegen/struct_layout.rs +++ b/src/codegen/struct_layout.rs @@ -7,7 +7,7 @@ use ir::context::BindgenContext; use ir::layout::Layout; use ir::ty::{Type, TypeKind}; use quote; -use proc_macro2; +use proc_macro2::{Term, Span}; use std::cmp; /// Trace the layout of struct. @@ -311,7 +311,7 @@ impl<'a> StructLayoutTracker<'a> { self.padding_count += 1; - let padding_field_name = proc_macro2::Term::intern(&format!("__bindgen_padding_{}", padding_count)); + let padding_field_name = Term::new(&format!("__bindgen_padding_{}", padding_count), Span::call_site()); self.max_field_align = cmp::max(self.max_field_align, layout.align); diff --git a/src/ir/comment.rs b/src/ir/comment.rs index afa2a385..b3140ffb 100644 --- a/src/ir/comment.rs +++ b/src/ir/comment.rs @@ -54,7 +54,7 @@ fn preprocess_single_lines(comment: &str, indent: usize) -> String { let indent = if is_first { "" } else { &*indent }; is_first = false; let maybe_space = if l.is_empty() { "" } else { " " }; - format!("{}///{}{}", indent, maybe_space, l) + format!("{}{}{}", indent, maybe_space, l) }) .collect(); lines.join("\n") @@ -79,7 +79,7 @@ fn preprocess_multi_line(comment: &str, indent: usize) -> String { let indent = if is_first { "" } else { &*indent }; is_first = false; let maybe_space = if line.is_empty() { "" } else { " " }; - format!("{}///{}{}", indent, maybe_space, line) + format!("{}{}{}", indent, maybe_space, line) }) .collect(); @@ -105,20 +105,20 @@ mod test { #[test] fn processes_single_lines_correctly() { - assert_eq!(preprocess("/// hello", 0), "/// hello"); - assert_eq!(preprocess("// hello", 0), "/// hello"); + assert_eq!(preprocess("/// hello", 0), " hello"); + assert_eq!(preprocess("// hello", 0), " hello"); } #[test] fn processes_multi_lines_correctly() { assert_eq!( preprocess("/** hello \n * world \n * foo \n */", 0), - "/// hello\n/// world\n/// foo" + " hello\n world\n foo" ); assert_eq!( preprocess("/**\nhello\n*world\n*foo\n*/", 0), - "/// hello\n/// world\n/// foo" + " hello\n world\n foo" ); } } diff --git a/src/ir/context.rs b/src/ir/context.rs index 7d316c3a..6ced43e8 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -24,7 +24,7 @@ use cexpr; use clang::{self, Cursor}; use clang_sys; use parse::ClangItemParser; -use proc_macro2; +use proc_macro2::{Term, Span}; use std::borrow::Cow; use std::cell::Cell; use std::collections::{HashMap, HashSet, hash_map}; @@ -905,7 +905,7 @@ impl BindgenContext { } /// Returns a mangled name as a rust identifier. - pub fn rust_ident<S>(&self, name: S) -> proc_macro2::Term + pub fn rust_ident<S>(&self, name: S) -> Term where S: AsRef<str> { @@ -913,11 +913,11 @@ impl BindgenContext { } /// Returns a mangled name as a rust identifier. - pub fn rust_ident_raw<T>(&self, name: T) -> proc_macro2::Term + pub fn rust_ident_raw<T>(&self, name: T) -> Term where T: AsRef<str> { - proc_macro2::Term::intern(name.as_ref()) + Term::new(name.as_ref(), Span::call_site()) } /// Iterate over all items that have been defined. @@ -2341,7 +2341,7 @@ impl BindgenContext { /// Convenient method for getting the prefix to use for most traits in /// codegen depending on the `use_core` option. - pub fn trait_prefix(&self) -> proc_macro2::Term { + pub fn trait_prefix(&self) -> Term { if self.options().use_core { self.rust_ident_raw("core") } else { diff --git a/src/ir/objc.rs b/src/ir/objc.rs index 18b51978..46c0802e 100644 --- a/src/ir/objc.rs +++ b/src/ir/objc.rs @@ -13,7 +13,7 @@ use clang_sys::CXCursor_ObjCInstanceMethodDecl; use clang_sys::CXCursor_ObjCProtocolDecl; use clang_sys::CXCursor_ObjCProtocolRef; use quote; -use proc_macro2; +use proc_macro2::{Term, Span}; /// Objective C interface as used in TypeKind /// @@ -217,7 +217,7 @@ impl ObjCMethod { let split_name: Vec<_> = self.name .split(':') .filter(|p| !p.is_empty()) - .map(proc_macro2::Term::intern) + .map(|name| Term::new(name, Span::call_site())) .collect(); // No arguments @@ -243,7 +243,7 @@ impl ObjCMethod { let arg = arg.to_string(); let name_and_sig: Vec<&str> = arg.split(' ').collect(); let name = name_and_sig[0]; - args_without_types.push(proc_macro2::Term::intern(name)) + args_without_types.push(Term::new(name, Span::call_site())) }; let args = split_name |