Use plain quote!, not our quote_cs! now that quote! outputs Span::call_site()

Since quote 0.6.2, the quote! macro generates tokens with
Span::call_site(), which is what we wanted.
parent 083b7591
......@@ -77,12 +77,12 @@ impl<'ast> ClassContext<'ast> {
let properties_registration = properties::properties_registration(&self.class.properties);
let parent_instance_tokens = if self.class.gobject_parent {
quote_cs!{}
quote!{}
} else {
quote_cs! { : #ParentInstance }
quote! { : #ParentInstance }
};
quote_cs! {
quote! {
pub mod #ModuleName {
#![allow(non_snake_case)] // "oddly" named module above
extern crate glib_sys as glib_ffi;
......
......@@ -60,7 +60,7 @@ impl<'ast> ClassContext<'ast> {
let name = method.sig.name;
let trampoline_name = self.names.slot_trampoline(&method.sig.name);
ret.push(quote_cs! {
ret.push(quote! {
(
*(vtable as *mut _ as *mut <
#parent_class as glib::wrapper::Wrapper
......@@ -80,7 +80,7 @@ impl<'ast> ClassContext<'ast> {
pub fn register_instance_private(&self) -> TokenStream {
let PrivateStructName = self.names.instance_private();
quote_cs! {
quote! {
// This is an Option<_> so that we can replace its value with None on finalize() to
// release all memory it holds
gobject_ffi::g_type_class_add_private(vtable, mem::size_of::<Option<#PrivateStructName>>());
......@@ -92,7 +92,7 @@ impl<'ast> ClassContext<'ast> {
let InstanceNameFfi = self.names.instance_ffi();
let get_type_fn_name = self.names.get_type_fn();
quote_cs! {
quote! {
#[allow(dead_code)]
fn get_priv(&self) -> &#PrivateStructName {
unsafe {
......@@ -111,7 +111,7 @@ impl<'ast> ClassContext<'ast> {
let PrivateStructName = self.names.instance_private();
let get_type_fn_name = self.names.get_type_fn();
quote_cs! {
quote! {
let _private = gobject_ffi::g_type_instance_get_private(
obj,
#get_type_fn_name()
......@@ -128,7 +128,7 @@ impl<'ast> ClassContext<'ast> {
let PrivateStructName = self.names.instance_private();
let get_type_fn_name = self.names.get_type_fn();
quote_cs! {
quote! {
let _private = gobject_ffi::g_type_instance_get_private(
obj as *mut gobject_ffi::GTypeInstance,
#get_type_fn_name(),
......
......@@ -15,6 +15,6 @@ impl<'a> ToTokens for CStringLiteral<'a> {
let mut v = Vec::from(self.0.as_bytes());
v.push(0u8);
tokens.append(TokenTree::Literal(Literal::byte_string(&v)));
(quote_cs! { as *const u8 as *const i8 }).to_tokens(tokens);
(quote! { as *const u8 as *const i8 }).to_tokens(tokens);
}
}
......@@ -20,7 +20,7 @@ pub fn slot_assignments<'ast>(names: &Names, slots: &[Slot<'ast>]) -> Vec<TokenS
let name = sig.name;
let trampoline_name = names.slot_trampoline(&name);
Some(quote_cs! {
Some(quote! {
vtable.#name = Some(#InstanceNameFfi::#trampoline_name);
})
}
......@@ -29,7 +29,7 @@ pub fn slot_assignments<'ast>(names: &Names, slots: &[Slot<'ast>]) -> Vec<TokenS
let signalname = signal.sig.name;
let trampoline_name = names.slot_trampoline(&signalname);
Some(quote_cs! {
Some(quote! {
vtable.#signalname = Some(#InstanceNameFfi::#trampoline_name);
})
}
......@@ -53,16 +53,16 @@ pub fn instance_slot_trampolines<'ast>(
let inputs = sig.input_args_with_glib_types();
let arg_names = sig.input_args_from_glib_types();
let ret = quote_cs! { instance.#method_impl_name(#arg_names) };
let ret = quote! { instance.#method_impl_name(#arg_names) };
let ret = sig.ret_to_glib(ret);
let output = sig.output_glib_type();
let receiver_instance = match parent_class {
Some(parent) => {
quote_cs! { <#parent as glib::wrapper::Wrapper>::GlibType }
quote! { <#parent as glib::wrapper::Wrapper>::GlibType }
}
None => quote_cs! { #InstanceNameFfi },
None => quote! { #InstanceNameFfi },
};
quote_cs! {
quote! {
unsafe extern "C" fn #trampoline_name(
this: *mut #receiver_instance,
#inputs
......@@ -112,7 +112,7 @@ pub fn slot_default_handlers<'ast>(
let name = name.unwrap_or_else(|| names.slot_impl(&sig.name));
let inputs = &sig.inputs;
let output = &sig.output;
quote_cs! {
quote! {
fn #name(#(#inputs),*) -> #output #body
}
};
......@@ -139,7 +139,7 @@ pub fn slot_default_handlers<'ast>(
let name = names.slot_impl(&sig.name);
let inputs = &sig.inputs;
let output = &sig.output;
quote_cs! {
quote! {
fn #name(#(#inputs),*) -> #output {
panic!("Called abstract method {} with no implementation", stringify!(#name));
}
......@@ -158,7 +158,7 @@ pub fn slot_default_handlers<'ast>(
let name = names.slot_impl(&sig.name);
let inputs = &sig.inputs;
let output = &sig.output;
quote_cs! {
quote! {
#[allow(unused_variables)] // since none of the inputs will be used
fn #name(#(#inputs),*) -> #output {
panic!("Called default signal handler {} with no implementation", stringify!(#name));
......@@ -202,10 +202,10 @@ pub fn extern_methods<'ast>(names: &Names, slots: &[Slot<'ast>]) -> Vec<TokenStr
let method_impl_name = names.slot_impl(&sig.name);
let inputs = sig.input_args_with_glib_types();
let args = sig.input_args_from_glib_types();
let ret = quote_cs! { instance.#method_impl_name(#args) };
let ret = quote! { instance.#method_impl_name(#args) };
let ret = sig.ret_to_glib(ret);
let output = sig.output_glib_type();
Some(quote_cs! {
Some(quote! {
#[no_mangle]
pub unsafe extern "C" fn #ffi_name(this: *mut #InstanceNameFfi,
#inputs)
......@@ -225,7 +225,7 @@ pub fn extern_methods<'ast>(names: &Names, slots: &[Slot<'ast>]) -> Vec<TokenStr
let inputs = sig.input_args_with_glib_types();
let args = sig.input_arg_names();
let output = sig.output_glib_type();
Some(quote_cs! {
Some(quote! {
#[no_mangle]
pub unsafe extern "C" fn #ffi_name(this: *mut #InstanceNameFfi,
#inputs)
......
......@@ -33,7 +33,7 @@ pub fn slot_trait_fns<'ast>(slots: &[Slot<'ast>]) -> Vec<TokenStream> {
let name = sig.name;
let inputs = &sig.inputs;
let output = &sig.output;
Some(quote_cs! {
Some(quote! {
fn #name(#(#inputs),*) -> #output;
})
}
......@@ -43,7 +43,7 @@ pub fn slot_trait_fns<'ast>(slots: &[Slot<'ast>]) -> Vec<TokenStream> {
let sig = &signal.sig;
let input_types = signal.sig.input_arg_types();
let output = &sig.output;
Some(quote_cs! {
Some(quote! {
fn #connect_signalname<F: Fn(&Self, #input_types) -> #output + 'static>(&self, f: F) ->
glib::SignalHandlerId;
})
......@@ -69,7 +69,7 @@ pub fn slot_trait_impls<'ast>(names: &Names, slots: &[Slot<'ast>]) -> Vec<TokenS
let name = sig.name;
let ffi_name = names.exported_fn(&name);
let arg_names = sig.input_args_to_glib_types();
let value = quote_cs! {
let value = quote! {
unsafe {
imp::#ffi_name(self.to_glib_none().0,
#arg_names)
......@@ -78,7 +78,7 @@ pub fn slot_trait_impls<'ast>(names: &Names, slots: &[Slot<'ast>]) -> Vec<TokenS
let output_from = sig.ret_from_glib_fn(&value);
let inputs = &sig.inputs;
let output = &sig.output;
Some(quote_cs! {
Some(quote! {
fn #name(#(#inputs),*) -> #output {
#output_from
}
......@@ -93,7 +93,7 @@ pub fn slot_trait_impls<'ast>(names: &Names, slots: &[Slot<'ast>]) -> Vec<TokenS
let input_types = signal.sig.input_arg_types();
let output = &sig.output;
Some(quote_cs! {
Some(quote! {
fn #connect_signalname<F: Fn(&Self, #input_types) -> #output + 'static>(&self, f: F) ->
glib::SignalHandlerId
{
......
......@@ -81,7 +81,7 @@ impl<'ast> InterfaceContext<'ast> {
let properties_enum = properties::properties_enum(&self.iface.properties);
let properties_registration = properties::properties_registration(&self.iface.properties);
quote_cs! {
quote! {
pub mod #ModuleName {
#![allow(non_snake_case)] // "oddly" named module above
......
// We give `ClassName` variables an identifier that uses upper-case.
#![allow(non_snake_case)]
use proc_macro2::{Ident, TokenStream};
use proc_macro::TokenStream;
use proc_macro2::{Ident};
use std::fmt::Display;
mod boilerplate;
......@@ -40,7 +41,7 @@ pub fn codegen(program: &Program) -> TokenStream {
})
.collect::<Vec<_>>();
quote_cs! {
quote! {
#(#class_tokens)*
#(#interface_tokens)*
......
......@@ -5,7 +5,7 @@ use ident_ext::IdentExt;
pub fn properties_enum<'ast>(properties: &[Property<'ast>]) -> TokenStream {
if properties.is_empty() {
return quote_cs!{};
return quote! {};
}
let properties: Vec<TokenStream> = properties
......@@ -14,11 +14,11 @@ pub fn properties_enum<'ast>(properties: &[Property<'ast>]) -> TokenStream {
.map(|(i, prop)| {
let name = prop.name;
let index = (i as u32) + 1;
quote_cs! { #name = #index }
quote! { #name = #index }
})
.collect();
quote_cs! {
quote! {
#[repr(u32)]
enum Properties {
#(#properties, )*
......@@ -36,7 +36,7 @@ pub fn property_setter<'ast>(properties: &[Property<'ast>]) -> TokenStream {
let type_ = prop.type_;
let body = prop.setter.body;
quote_cs! {
quote! {
#index => {
let v: glib::Value = unsafe {FromGlibPtrNone::from_glib_none(value)};
if let Some(#param) = v.get::<#type_>()
......@@ -46,7 +46,7 @@ pub fn property_setter<'ast>(properties: &[Property<'ast>]) -> TokenStream {
})
.collect();
quote_cs! {
quote! {
#[allow(dead_code, unused_variables)]
fn set_property_impl(&self, property_id: u32, value: *mut gobject_ffi::GValue) {
match property_id {
......@@ -76,35 +76,35 @@ pub fn property_getter<'ast>(properties: &[Property<'ast>]) -> TokenStream {
let g_value_set = match &tname[..] {
"i32" => {
quote_cs! {gobject_ffi::g_value_set_int(value, ret);}
quote! {gobject_ffi::g_value_set_int(value, ret);}
}
"i64" => {
quote_cs! {gobject_ffi::g_value_set_int64(value, ret);}
quote! {gobject_ffi::g_value_set_int64(value, ret);}
}
"u32" => {
quote_cs! {gobject_ffi::g_value_set_uint(value, ret);}
quote! {gobject_ffi::g_value_set_uint(value, ret);}
}
"u64" => {
quote_cs! {gobject_ffi::g_value_set_uint64(value, ret);}
quote! {gobject_ffi::g_value_set_uint64(value, ret);}
}
"f32" => {
quote_cs! {gobject_ffi::g_value_set_float(value, ret);}
quote! {gobject_ffi::g_value_set_float(value, ret);}
}
"f64" => {
quote_cs! {gobject_ffi::g_value_set_double(value, ret);}
quote! {gobject_ffi::g_value_set_double(value, ret);}
}
"bool" => {
quote_cs! {gobject_ffi::g_value_set_bool(value, ret);}
quote! {gobject_ffi::g_value_set_bool(value, ret);}
}
"String" => {
quote_cs! {gobject_ffi::g_value_set_string(value, ret.to_glib_none().0);}
quote! {gobject_ffi::g_value_set_string(value, ret.to_glib_none().0);}
}
_ => {
quote_cs! {gobject_ffi::g_value_set_object(value, ret.to_glib_none().0);}
quote! {gobject_ffi::g_value_set_object(value, ret.to_glib_none().0);}
}
};
quote_cs! {
quote! {
#index => {
let ret: #type_ = (|| #body)();
unsafe {
......@@ -115,7 +115,7 @@ pub fn property_getter<'ast>(properties: &[Property<'ast>]) -> TokenStream {
})
.collect();
quote_cs! {
quote! {
#[allow(dead_code, unused_variables)]
fn get_property_impl(&self, property_id: u32, value: *mut gobject_ffi::GValue) {
match property_id {
......@@ -139,7 +139,7 @@ pub fn set_properties<'ast>(properties: &[Property<'ast>]) -> Vec<TokenStream> {
let name_str = prop.name.to_owned_string();
let type_ = prop.type_;
quote_cs! {
quote! {
fn #name(&self, v: #type_) {
unsafe {
gobject_ffi::g_object_set_property(
......@@ -164,7 +164,7 @@ pub fn get_properties<'ast>(properties: &[Property<'ast>]) -> Vec<TokenStream> {
let name_str = prop.name.to_owned_string();
let type_ = prop.type_;
quote_cs! {
quote! {
fn #name(&self) -> #type_ {
let mut value = glib::Value::from(&#type_::default());
unsafe {
......@@ -190,7 +190,7 @@ pub fn set_properties_fn<'ast>(properties: &[Property<'ast>]) -> Vec<TokenStream
));
let type_ = prop.type_;
quote_cs! {
quote! {
fn #name(&self, v: #type_);
}
})
......@@ -207,7 +207,7 @@ pub fn get_properties_fn<'ast>(properties: &[Property<'ast>]) -> Vec<TokenStream
));
let type_ = prop.type_;
quote_cs! {
quote! {
fn #name(&self) -> #type_;
}
})
......@@ -231,44 +231,44 @@ fn prop_registration<'ast>(properties: &[Property<'ast>]) -> Vec<TokenStream> {
match &type_[..] {
"i32" => {
para_spec = quote_cs! { g_param_spec_int };
default = quote_cs! { i32::MIN, i32::MAX, 0, };
para_spec = quote! { g_param_spec_int };
default = quote! { i32::MIN, i32::MAX, 0, };
}
"i64" => {
para_spec = quote_cs! { g_param_spec_long };
default = quote_cs! { i64::MIN, i64::MAX, 0, };
para_spec = quote! { g_param_spec_long };
default = quote! { i64::MIN, i64::MAX, 0, };
}
"u32" => {
para_spec = quote_cs! { g_param_spec_uint };
default = quote_cs! { std::u32::MIN, std::u32::MAX, 0, };
para_spec = quote! { g_param_spec_uint };
default = quote! { std::u32::MIN, std::u32::MAX, 0, };
}
"u64" => {
para_spec = quote_cs! { g_param_spec_ulong };
default = quote_cs! { u64::MIN, u64::MAX, 0, };
para_spec = quote! { g_param_spec_ulong };
default = quote! { u64::MIN, u64::MAX, 0, };
}
"f32" => {
para_spec = quote_cs! { g_param_spec_float };
default = quote_cs! { f32::MIN, f32::MAX, 0, };
para_spec = quote! { g_param_spec_float };
default = quote! { f32::MIN, f32::MAX, 0, };
}
"f64" => {
para_spec = quote_cs! { g_param_spec_double };
default = quote_cs! { f64::MIN, f64::MAX, 0, };
para_spec = quote! { g_param_spec_double };
default = quote! { f64::MIN, f64::MAX, 0, };
}
"bool" => {
para_spec = quote_cs! { g_param_spec_boolean };
default = quote_cs! { false, };
para_spec = quote! { g_param_spec_boolean };
default = quote! { false, };
}
"String" => {
para_spec = quote_cs! { g_param_spec_pointer };
default = quote_cs! { ptr::null_mut(), };
para_spec = quote! { g_param_spec_pointer };
default = quote! { ptr::null_mut(), };
}
_ => {
para_spec = quote_cs! { g_param_spec_pointer };
default = quote_cs!{};
para_spec = quote! { g_param_spec_pointer };
default = quote!{};
}
};
quote_cs! {
quote! {
properties.push(gobject_ffi::#para_spec(
// We're using here the same value for name, nick and blurb because with
// the current property declaration syntax we only have the property name.
......@@ -295,7 +295,7 @@ fn prop_registration<'ast>(properties: &[Property<'ast>]) -> Vec<TokenStream> {
pub fn properties_registration<'ast>(properties: &[Property<'ast>]) -> TokenStream {
let prop = prop_registration(properties);
quote_cs! {
quote! {
let mut properties = Vec::new();
properties.push(ptr::null()); // dummy item
......
......@@ -23,13 +23,13 @@ pub fn signal_emit_methods<'ast>(
let return_gtype = signal.sig.output.to_gtype_path();
let (initialize_return_value, convert_return_value_to_rust) = match rust_return_ty {
Ty::Unit => (quote_cs!{}, quote_cs! { () }),
Ty::Unit => (quote!{}, quote! { () }),
_ => (
quote_cs! {
quote! {
gobject_sys::g_value_init(ret.to_glib_none_mut().0, #return_gtype);
},
quote_cs! {
quote! {
if ret.type_() == glib::Type::Invalid {
unreachable!();
} else {
......@@ -39,7 +39,7 @@ pub fn signal_emit_methods<'ast>(
),
};
quote_cs! {
quote! {
#[allow(unused)]
fn #emit_name(#(#rust_params),*) -> #rust_return_ty {
// foo/imp.rs: increment()
......@@ -106,7 +106,7 @@ pub fn signal_declarations<'ast>(
let return_gtype = signal.sig.output.to_gtype_path();
quote_cs! {
quote! {
let param_gtypes = [#(#param_gtypes),*];
// FIXME: we are using G_SIGNAL_RUN_LAST all the time so that signals
......@@ -146,12 +146,12 @@ pub fn signal_trampolines<'ast>(
let arg_names = sig.input_args_from_glib_types();
let output = &sig.output;
let ret = quote_cs! {
let ret = quote! {
f(&#InstanceName::from_glib_borrow(this).downcast_unchecked(), #arg_names)
};
let ret = sig.ret_to_glib(ret);
quote_cs! {
quote! {
unsafe extern "C" fn #signalname_trampoline<P>(
this: *mut imp::#InstanceNameFfi,
#c_inputs
......
......@@ -117,12 +117,12 @@ impl<'ast> ToTokens for ToGlibType<'ast> {
match *self.0 {
Ty::Unit => self.0.to_tokens(tokens),
Ty::Char(i) | Ty::Bool(i) => {
(quote_cs! {
(quote! {
<#i as ToGlib>::GlibType
}).to_tokens(tokens);
}
Ty::Borrowed(ref t) => {
(quote_cs! {
(quote! {
<#t as GlibPtrDefault>::GlibType
}).to_tokens(tokens);
}
......@@ -151,12 +151,12 @@ impl<'ast, T: ToTokens> ToTokens for ToGlib<'ast, T> {
Ty::Unit | Ty::Integer(_) => self.1.to_tokens(tokens),
Ty::Char(i) | Ty::Bool(i) => {
(quote_cs! {
(quote! {
<#i as ToGlib>::to_glib(&#expr)
}).to_tokens(tokens);
}
Ty::Borrowed(ref t) => {
(quote_cs! {
(quote! {
<#t as ToGlibPtr<_>>::to_glib_none(#expr).0
}).to_tokens(tokens);
}
......@@ -181,13 +181,13 @@ impl<'ast> ToTokens for FromGlib<'ast> {
let needs_conversion = match *self.0 {
Ty::Unit => false, // no conversion necessary
Ty::Char(i) | Ty::Bool(i) => {
(quote_cs! {
(quote! {
<#i as FromGlib<_>>::from_glib
}).to_tokens(tokens);
true
}
Ty::Borrowed(ref t) => {
(quote_cs! {
(quote! {
&<#t as FromGlibPtrBorrow<_>>::from_glib_borrow
}).to_tokens(tokens);
true
......@@ -291,7 +291,7 @@ impl<'ast> ToTokens for ArgNamesToGlibValues<'ast> {
for arg in self.0 {
match *arg {
FnArg::SelfRef(..) => {
let code = quote_cs! {
let code = quote! {
(self as &glib::ToValue).to_value(),
};
......@@ -299,7 +299,7 @@ impl<'ast> ToTokens for ArgNamesToGlibValues<'ast> {
}
FnArg::Arg { name, .. } => {
let code = quote_cs! {
let code = quote! {
(&#name as &glib::ToValue).to_value(),
};
......
......@@ -23,7 +23,7 @@ impl<'ast> ToTokens for SlotDeclaration<'ast> {
let output = sig.output_glib_type();
let inputs = sig.input_args_with_glib_types();
let name = sig.name;
(quote_cs! {
(quote! {
pub #name: Option<unsafe extern "C" fn(
this: *mut #InstanceNameFfi,
#inputs
......@@ -36,7 +36,7 @@ impl<'ast> ToTokens for SlotDeclaration<'ast> {
let inputs = signal.sig.input_args_with_glib_types();
let signalname = signal.sig.name;
(quote_cs! {
(quote! {
pub #signalname: Option<unsafe extern "C" fn(
this: *mut #InstanceNameFfi,
#inputs
......
......@@ -5,15 +5,15 @@ use proc_macro2::TokenStream;
use quote::ToTokens;
pub fn tokens_GObject() -> TokenStream {
quote_cs! { glib::Object }
quote! { glib::Object }
}
pub fn tokens_GObjectFfi() -> TokenStream {
quote_cs! { gobject_ffi::GObject }
quote! { gobject_ffi::GObject }
}
pub fn tokens_GObjectClassFfi() -> TokenStream {
quote_cs! { gobject_ffi::GObjectClass }
quote! { gobject_ffi::GObjectClass }
}
pub fn tokens_ParentInstance(class: &ast::Class) -> TokenStream {
......@@ -30,14 +30,14 @@ pub fn tokens_ParentInstance(class: &ast::Class) -> TokenStream {
pub fn tokens_ParentInstanceFfi(class: &ast::Class) -> TokenStream {
let ParentInstance = tokens_ParentInstance(class);
quote_cs! {
quote! {
<#ParentInstance as glib::wrapper::Wrapper>::GlibType
}
}
pub fn tokens_ParentClassFfi(class: &ast::Class) -> TokenStream {
let ParentInstance = tokens_ParentInstance(class);
quote_cs! {
quote! {
<#ParentInstance as glib::wrapper::Wrapper>::GlibClassType
}
}
......@@ -46,7 +46,7 @@ pub fn glib_callback_guard() -> TokenStream {
// FIXME: remove this function if we formally declare that
// gnome-class will require Rust 1.24 or later? That version made
// glib::CallbackGuard obsolete.
quote_cs! {
quote! {
#[allow(deprecated)]
let _guard = glib::CallbackGuard::new();
}
......
......@@ -622,7 +622,7 @@ impl<'ast> Interfaces<'ast> {
}
fn make_path_glib_object() -> Path {
let tokens = quote_cs! { glib::Object };
let tokens = quote! { glib::Object };
let token_stream = TokenStream::from(tokens);
let buffer = TokenBuffer::new(token_stream);
let cursor = buffer.begin();
......
......@@ -24,11 +24,6 @@ use errors::*;
use proc_macro::TokenStream;
use std::error::Error;
macro_rules! quote_cs {
($($tt:tt)*) => (quote_spanned!(::proc_macro2::Span::call_site()=>
$($tt)*))
}
mod ast;
mod checking;
mod errors;
......
use proc_macro::{Diagnostic, Level};
use proc_macro::{Diagnostic, Level, TokenStream};
use proc_macro2::{Ident, TokenStream};
use proc_macro2::{Ident};
use syn::buffer::Cursor;
use syn::punctuated::Punctuated;
use syn::synom::{PResult, Synom};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment