Commit 9b0547bf authored by mredlek's avatar mredlek Committed by Federico Mena Quintero

cargo fmt

parent f6a513a9
use crate::hir::FnSig;
use proc_macro2::TokenStream;
pub trait FnSigExt
{
pub trait FnSigExt {
fn signal_definition(&self) -> TokenStream;
}
impl<'ast> FnSigExt for FnSig<'ast>
{
fn signal_definition(&self) -> TokenStream
{
impl<'ast> FnSigExt for FnSig<'ast> {
fn signal_definition(&self) -> TokenStream {
let name = self.name.clone();
let inputs = &self.inputs;
let output = &self.output;
......
......@@ -8,21 +8,21 @@ mod boilerplate;
mod boilerplateext;
mod class;
mod cstringliteral;
pub mod gir;
mod fnsig_ext;
pub mod gir;
mod imp;
mod instance;
mod instance_ext;
mod interface;
mod private;
mod privatestatic;
mod properties;
mod property_ext;
mod public;
mod private;
mod signals;
mod signatures;
mod slots;
mod slot_ext;
mod slots;
mod writer;
pub use self::boilerplate::Boilerplate;
......@@ -35,9 +35,9 @@ pub use self::private::Private;
use self::writer::RustWriter;
use crate::hir::Program;
use self::slot_ext::SlotExt;
use self::property_ext::PropertyGenExt;
use self::fnsig_ext::FnSigExt;
use self::property_ext::PropertyGenExt;
use self::slot_ext::SlotExt;
pub fn codegen(program: &Program<'_>) -> TokenStream {
let mut writer = RustWriter::new();
......
......@@ -21,24 +21,37 @@ impl<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>> Private<'lt, '
}
}
impl<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>> ToTokens for Private<'lt, 'ast, Boilerplate>
impl<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>> ToTokens
for Private<'lt, 'ast, Boilerplate>
{
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.extend(self.gen_def_trait_ext_priv());
}
}
impl<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>> Private<'lt, 'ast, Boilerplate>
{
impl<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>> Private<'lt, 'ast, Boilerplate> {
fn gen_def_trait_ext_priv(&self) -> TokenStream {
let instance_ext_priv = self.boilerplate.names().instance_ext_priv();
let name = self.boilerplate.names().instance();
let ancestors = self.boilerplate.ancestors().iter().filter(|anc| !anc.is_fundamental()).map(|anc| anc.instance());
let ancestors = self
.boilerplate
.ancestors()
.iter()
.filter(|anc| !anc.is_fundamental())
.map(|anc| anc.instance());
let get_priv_def = self.gen_get_priv_def();
let get_priv_impl = self.gen_get_priv_impl();
let slot_def = self.boilerplate.slots().iter().filter(|slot| !slot.public())
let slot_def = self
.boilerplate
.slots()
.iter()
.filter(|slot| !slot.public())
.map(|slot| slot.trait_definition());
let slot_impl = self.boilerplate.slots().iter().filter(|slot| !slot.public())
let slot_impl = self
.boilerplate
.slots()
.iter()
.filter(|slot| !slot.public())
.map(|slot| slot.trait_implementation(self.boilerplate.names()));
let signal_emit_methods =
crate::gen::signals::signal_emit_methods(self.boilerplate.signals());
......@@ -95,4 +108,4 @@ impl<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>> Private<'lt, '
}
}
}
}
\ No newline at end of file
}
use super::boilerplate;
use super::instance_ext;
use super::properties;
use super::SlotExt;
use crate::gen::boilerplateext::BoilerplateExt;
use proc_macro2::TokenStream;
use quote::{quote, ToTokens};
use std::marker::PhantomData;
use super::SlotExt;
/// This class can generate the public part of the boilerplate code for objects
pub struct Public<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>> {
......@@ -25,8 +25,8 @@ impl<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>> ToTokens
{
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.extend(self.gen_public_new());
//tokens.extend(self.gen_def_trait_ext());
//tokens.extend(self.gen_impl_trait_ext());
// tokens.extend(self.gen_def_trait_ext());
// tokens.extend(self.gen_impl_trait_ext());
tokens.extend(self.gen_signal_trampolines());
}
}
......@@ -35,7 +35,6 @@ impl<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>> ToTokens
for PublicImp<'lt, 'ast, Boilerplate>
{
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.extend(self.gen_external_methods());
tokens.extend(self.gen_trait_ext());
}
......@@ -134,15 +133,29 @@ impl<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>>
}
}
impl<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>> PublicImp<'lt, 'ast, Boilerplate>
impl<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>>
PublicImp<'lt, 'ast, Boilerplate>
{
fn gen_trait_ext(&self) -> TokenStream {
let name = self.boilerplate.names().instance();
let ancestors = self.boilerplate.ancestors().iter().filter(|anc| !anc.is_fundamental()).map(|anc| anc.instance());
let ancestors = self
.boilerplate
.ancestors()
.iter()
.filter(|anc| !anc.is_fundamental())
.map(|anc| anc.instance());
let instance_ext = self.boilerplate.names().instance_ext();
let slot_def = self.boilerplate.slots().iter().filter(|slot| slot.public())
let slot_def = self
.boilerplate
.slots()
.iter()
.filter(|slot| slot.public())
.map(|slot| slot.trait_definition());
let slot_impl = self.boilerplate.slots().iter().filter(|slot| slot.public())
let slot_impl = self
.boilerplate
.slots()
.iter()
.filter(|slot| slot.public())
.map(|slot| slot.trait_implementation(self.boilerplate.names()));
let set_properties_fn = properties::set_properties_fn(self.boilerplate.properties().iter());
......
......@@ -12,73 +12,69 @@ use crate::hir::{FnArg, Signal, Ty};
pub fn signal_emit_methods_declaration<'ast>(
signals: impl Iterator<Item = &'ast Signal<'ast>>,
) -> TokenStream {
let signals = signals
.map(|signal| {
let emit_name = emit_signalname(signal);
let rust_params = &signal.sig.inputs;
let rust_return_ty = &signal.sig.output;
quote! {
fn #emit_name(#(#rust_params),*) -> #rust_return_ty;
}
});
let signals = signals.map(|signal| {
let emit_name = emit_signalname(signal);
let rust_params = &signal.sig.inputs;
let rust_return_ty = &signal.sig.output;
quote! {
fn #emit_name(#(#rust_params),*) -> #rust_return_ty;
}
});
quote!{ #(#signals)* }
}
pub fn signal_emit_methods<'ast>(
signals: impl Iterator<Item = &'ast Signal<'ast>>,
) -> TokenStream {
let signals = signals
.map(|signal| {
let emit_name = emit_signalname(signal);
let signal_id_name = signal_id_name(&signal);
let rust_params = &signal.sig.inputs;
let rust_return_ty = &signal.sig.output;
let signal_params = signal.sig.input_args_to_glib_values();
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!{}, quote! { () }),
_ => (
quote! {
gobject_sys::g_value_init(ret.to_glib_none_mut().0, #return_gtype);
},
quote! {
if ret.type_() == glib::Type::Invalid {
unreachable!();
} else {
ret.get().unwrap()
}
},
),
};
quote! {
#[allow(unused)]
fn #emit_name(#(#rust_params),*) -> #rust_return_ty {
// foo/imp.rs: increment()
let params: &[glib::Value] = &[
#signal_params
];
unsafe {
let mut ret = glib::Value::uninitialized();
#initialize_return_value
gobject_sys::g_signal_emitv(
mut_override(params.as_ptr()) as *mut gobject_sys::GValue,
PRIV.private.#signal_id_name,
0, // detail
ret.to_glib_none_mut().0,
);
#convert_return_value_to_rust
pub fn signal_emit_methods<'ast>(signals: impl Iterator<Item = &'ast Signal<'ast>>) -> TokenStream {
let signals = signals.map(|signal| {
let emit_name = emit_signalname(signal);
let signal_id_name = signal_id_name(&signal);
let rust_params = &signal.sig.inputs;
let rust_return_ty = &signal.sig.output;
let signal_params = signal.sig.input_args_to_glib_values();
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!{}, quote! { () }),
_ => (
quote! {
gobject_sys::g_value_init(ret.to_glib_none_mut().0, #return_gtype);
},
quote! {
if ret.type_() == glib::Type::Invalid {
unreachable!();
} else {
ret.get().unwrap()
}
},
),
};
quote! {
#[allow(unused)]
fn #emit_name(#(#rust_params),*) -> #rust_return_ty {
// foo/imp.rs: increment()
let params: &[glib::Value] = &[
#signal_params
];
unsafe {
let mut ret = glib::Value::uninitialized();
#initialize_return_value
gobject_sys::g_signal_emitv(
mut_override(params.as_ptr()) as *mut gobject_sys::GValue,
PRIV.private.#signal_id_name,
0, // detail
ret.to_glib_none_mut().0,
);
#convert_return_value_to_rust
}
}
});
}
});
quote!{ #(#signals)* }
}
......
use crate::hir::{Method,Signal,Slot,VirtualMethod,FnSig};
use super::FnSigExt;
use crate::gen::signals;
use crate::hir::names::Names;
use crate::hir::{FnSig, Method, Signal, Slot, VirtualMethod};
use proc_macro2::TokenStream;
use quote::ToTokens;
use super::FnSigExt;
use crate::gen::signals;
pub trait SlotExt
{
pub trait SlotExt {
fn trait_definition(&self) -> TokenStream;
fn trait_implementation(&self, names: &Names) -> TokenStream;
fn public(&self) -> bool;
}
trait SlotInnerExt
{
trait SlotInnerExt {
fn sig(&self) -> &FnSig;
fn body(&self, names: &Names) -> TokenStream;
}
trait SignalExt
{
trait SignalExt {
fn connect_def(&self) -> TokenStream;
fn connect_impl(&self) -> TokenStream;
}
impl<'ast> SlotExt for Slot<'ast>
{
impl<'ast> SlotExt for Slot<'ast> {
fn trait_definition(&self) -> TokenStream {
let sig = match self {
Slot::VirtualMethod(ref method) => method.sig(),
Slot::Method(ref method) => method.sig(),
Slot::Signal(ref method) => { return method.connect_def(); },
}.signal_definition();
Slot::Signal(ref method) => {
return method.connect_def();
}
}
.signal_definition();
quote!{
#sig;
}
}
fn trait_implementation(&self, names: &Names) -> TokenStream {
fn trait_implementation(&self, names: &Names) -> TokenStream {
let (sig, body) = match self {
Slot::VirtualMethod(ref method) => (method.sig(), method.body(names)),
Slot::Method(ref method) => (method.sig(), method.body(names)),
Slot::Signal(ref method) => { return method.connect_impl(); },
Slot::Signal(ref method) => {
return method.connect_impl();
}
};
let sig = sig.signal_definition();
......@@ -51,8 +52,7 @@ impl<'ast> SlotExt for Slot<'ast>
}
}
fn public(&self) -> bool
{
fn public(&self) -> bool {
match self {
Slot::Method(ref method) => method.public,
_ => true,
......@@ -60,27 +60,22 @@ impl<'ast> SlotExt for Slot<'ast>
}
}
impl<'ast> SlotInnerExt for Method<'ast>
{
impl<'ast> SlotInnerExt for Method<'ast> {
fn sig(&self) -> &FnSig {
&self.sig
}
fn body(&self, _names: &Names) -> TokenStream
{
fn body(&self, _names: &Names) -> TokenStream {
self.body.clone().into_token_stream()
}
}
impl<'ast> SlotInnerExt for VirtualMethod<'ast>
{
impl<'ast> SlotInnerExt for VirtualMethod<'ast> {
fn sig(&self) -> &FnSig {
&self.sig
}
fn body(&self, names: &Names) -> TokenStream
{
fn body(&self, names: &Names) -> TokenStream {
if self.body.is_some() {
let name = &self.sig.name;
let args = self.sig.input_args_to_glib_types();
......@@ -95,16 +90,17 @@ impl<'ast> SlotInnerExt for VirtualMethod<'ast>
#ret_from_glib_fn
} }
} else {
let panic_msg = format!("Called abstract method {} with no implementation", &self.sig.name);
let panic_msg = format!(
"Called abstract method {} with no implementation",
&self.sig.name
);
quote! { { panic!(#panic_msg) } }
}
}
}
impl<'ast> SignalExt for Signal<'ast>
{
fn connect_def(&self) -> TokenStream
{
impl<'ast> SignalExt for Signal<'ast> {
fn connect_def(&self) -> TokenStream {
let connect_signalname = signals::connect_signalname(self);
let sig = &self.sig;
let input_types = self.sig.input_arg_types();
......@@ -116,8 +112,7 @@ impl<'ast> SignalExt for Signal<'ast>
}
}
fn connect_impl(&self) -> TokenStream
{
fn connect_impl(&self) -> TokenStream {
let connect_signalname = signals::connect_signalname(self);
let signalname_trampoline = signals::signal_trampoline_name(self);
let sig = &self.sig;
......
#![cfg(any(not(feature = "single-test"), feature = "single-test-no-instance-private"))]
#![cfg(any(
not(feature = "single-test"),
feature = "single-test-no-instance-private"
))]
#![deny(warnings)]
extern crate gobject_gen;
......
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