Skip to content

Commit

Permalink
Bump quote to 0.5 and proc_macro2 to 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Eijebong committed Apr 3, 2018
1 parent 6dae67e commit 435095c
Show file tree
Hide file tree
Showing 79 changed files with 650 additions and 1,004 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ clap = "2"
clang-sys = { version = "0.22.0", features = ["runtime", "clang_6_0"] }
lazy_static = "1"
peeking_take_while = "0.1.2"
quote = "0.4"
quote = { version = "0.5", default-features = false }
regex = "0.2"
which = "1.0.2"
proc-macro2 = "0.2"
proc-macro2 = { version = "0.3", default-features = false }

[dependencies.env_logger]
optional = true
Expand Down
24 changes: 10 additions & 14 deletions src/codegen/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),* )]
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)
}

Expand All @@ -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));
}
Expand Down
40 changes: 21 additions & 19 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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 ;
});
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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>,
) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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()
)
};

Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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, "::");

Expand Down
4 changes: 2 additions & 2 deletions src/codegen/struct_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand Down
12 changes: 6 additions & 6 deletions src/ir/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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();

Expand All @@ -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"
);
}
}
10 changes: 5 additions & 5 deletions src/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -905,19 +905,19 @@ 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>
{
self.rust_ident_raw(self.rust_mangle(name.as_ref()))
}

/// 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.
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 435095c

Please sign in to comment.