diff --git a/ipc/codegen/Cargo.toml b/ipc/codegen/Cargo.toml index 09d6a14bb..e07aa9bf2 100644 --- a/ipc/codegen/Cargo.toml +++ b/ipc/codegen/Cargo.toml @@ -14,14 +14,14 @@ nightly-testing = ["clippy"] with-syntex = ["quasi/with-syntex", "quasi_codegen", "quasi_codegen/with-syntex", "syntex", "syntex_syntax"] [build-dependencies] -quasi_codegen = { version = "^0.8.0", optional = true } -syntex = { version = "^0.30.0", optional = true } +quasi_codegen = { version = "*", optional = true } +syntex = { version = "*", optional = true } [dependencies] -aster = { version = "^0.14.0", default-features = false } +aster = { version = "^0.15.0", default-features = false } clippy = { version = "^0.*", optional = true } -quasi = { version = "^0.8.0", default-features = false } -quasi_macros = { version = "^0.8.0", optional = true } -syntex = { version = "^0.30.0", optional = true } -syntex_syntax = { version = "^0.30.0", optional = true } +quasi = { version = "*", default-features = false } +quasi_macros = { version = "*", optional = true } +syntex = { version = "*", optional = true } +syntex_syntax = { version = "*", optional = true } "ethcore-ipc" = { path = "../rpc"} diff --git a/ipc/codegen/src/codegen.rs b/ipc/codegen/src/codegen.rs index 671e067b3..1d2c4765c 100644 --- a/ipc/codegen/src/codegen.rs +++ b/ipc/codegen/src/codegen.rs @@ -282,15 +282,14 @@ fn implement_dispatch_arms( /// generates client type for specified server type /// for say `Service` it generates `ServiceClient` fn push_client_struct(cx: &ExtCtxt, builder: &aster::AstBuilder, item: &Item, push: &mut FnMut(Annotatable)) { - let proxy_ident = builder.id(format!("{}Client", item.ident.name.as_str())); - - let proxy_struct_item = quote_item!(cx, - pub struct $proxy_ident { + let (_, client_ident) = get_item_idents(builder, item); + let client_struct_item = quote_item!(cx, + pub struct $client_ident { socket: ::std::cell::RefCell, phantom: ::std::marker::PhantomData, }); - push(Annotatable::Item(proxy_struct_item.expect(&format!("could not generate proxy struct for {:?}", proxy_ident.name)))); + push(Annotatable::Item(client_struct_item.expect(&format!("could not generate client struct for {:?}", client_ident.name)))); } /// pushes generated code for the client class (type declaration and method invocation implementations) @@ -492,7 +491,8 @@ fn push_with_socket_client_implementation( item: &Item, push: &mut FnMut(Annotatable)) { - let client_ident = builder.id(format!("{}Client", item.ident.name.as_str())); + let (_, client_ident) = get_item_idents(builder, item); + let implement = quote_item!(cx, impl ::ipc::WithSocket for $client_ident where S: ::ipc::IpcSocket { fn init(socket: S) -> $client_ident { @@ -513,13 +513,13 @@ fn push_client_implementation( item: &Item, push: &mut FnMut(Annotatable)) { + let (item_ident, client_ident) = get_item_idents(builder, item); + let mut index = -1i32; let items = dispatches.iter() .map(|dispatch| { index = index + 1; P(implement_client_method(cx, builder, index as u16, dispatch)) }) .collect::>>(); - let client_ident = builder.id(format!("{}Client", item.ident.name.as_str())); - let item_ident = builder.id(format!("{}", item.ident.name.as_str())); let implement = quote_item!(cx, impl $client_ident where S: ::ipc::IpcSocket { pub fn handshake(&self) -> Result<(), ::ipc::Error> { @@ -589,6 +589,24 @@ fn implement_handshake_arm( ) } +fn get_item_idents(builder: &aster::AstBuilder, item: &Item) -> (::syntax::ast::Ident, ::syntax::ast::Ident) { + let ty = match item.node { + ast::ItemKind::Impl(_, _, _, _, ref ty, _) => ty.clone(), + _ => { builder.ty().id("") } + }; + + let (item_ident, client_ident) = match ty.node { + ::syntax::ast::TyKind::Path(_, ref path) => { + ( + builder.id(format!("{}", path.segments[0].identifier)), + builder.id(format!("{}Client", path.segments[0].identifier)) + ) + }, + _ => { panic!("incompatible implementation"); } + }; + (item_ident, client_ident) +} + /// implements `IpcInterface` for the given class `C` fn implement_interface( cx: &ExtCtxt, @@ -612,12 +630,10 @@ fn implement_interface( ) .build(); - let ty = builder.ty().path() - .segment(item.ident).with_generics(impl_generics.clone()).build() - .build(); - let where_clause = &impl_generics.where_clause; + let (ty, _) = get_item_idents(builder, item); + let mut dispatch_table = Vec::new(); for impl_item in impl_items { if let ImplItemKind::Method(ref signature, _) = impl_item.node { diff --git a/ipc/codegen/src/lib.rs b/ipc/codegen/src/lib.rs index 44ac093d9..c256ec7c2 100644 --- a/ipc/codegen/src/lib.rs +++ b/ipc/codegen/src/lib.rs @@ -63,5 +63,5 @@ pub fn register(reg: &mut rustc_plugin::Registry) { reg.register_syntax_extension( syntax::parse::token::intern("derive_Ipc"), syntax::ext::base::MultiDecorator( - Box::new(ser::expand_derive_serialize))); + Box::new(codegen::expand_ipc_implementation))); } diff --git a/ipc/serde/Cargo.toml b/ipc/serde/Cargo.toml new file mode 100644 index 000000000..1663526e7 --- /dev/null +++ b/ipc/serde/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "ethcore-bin-serde" +version = "0.1.0" +authors = ["Nikolay Volf"] +build = "build.rs" + +[lib] + +[dependencies] +bincode = "*" +serde = "0.7.0" +ethcore-devtools = { path = "../../devtools" } + +[build-dependencies] +syntex = "*" +serde_codegen = "0.7.0" diff --git a/ipc/serde/build.rs b/ipc/serde/build.rs new file mode 100644 index 000000000..9a147f446 --- /dev/null +++ b/ipc/serde/build.rs @@ -0,0 +1,30 @@ +// Copyright 2015, 2016 Ethcore (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +extern crate syntex; +extern crate serde_codegen; + +use std::env; +use std::path::Path; + +pub fn main() { + let out_dir = env::var_os("OUT_DIR").unwrap(); + let src = Path::new("src/lib.rs.in"); + let dst = Path::new(&out_dir).join("lib.rs"); + let mut registry = syntex::Registry::new(); + serde_codegen::register(&mut registry); + registry.expand("", &src, &dst).unwrap(); +} diff --git a/ipc/serde/src/lib.rs b/ipc/serde/src/lib.rs new file mode 100644 index 000000000..af29c8f87 --- /dev/null +++ b/ipc/serde/src/lib.rs @@ -0,0 +1,17 @@ +// Copyright 2015, 2016 Ethcore (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +include!(concat!(env!("OUT_DIR"), "/lib.rs")); diff --git a/ipc/serde/src/lib.rs.in b/ipc/serde/src/lib.rs.in new file mode 100644 index 000000000..4235e6e76 --- /dev/null +++ b/ipc/serde/src/lib.rs.in @@ -0,0 +1,18 @@ +// Copyright 2015, 2016 Ethcore (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +#[derive(Serialize, Deserialize)] +struct BinBox([u8; mem::size_of()]); diff --git a/ipc/tests/Cargo.toml b/ipc/tests/Cargo.toml index 035de644c..7b37a58a4 100644 --- a/ipc/tests/Cargo.toml +++ b/ipc/tests/Cargo.toml @@ -18,6 +18,6 @@ ethcore-ipc-nano = { path = "../nano" } [build-dependencies] -syntex = "0.30.0" +syntex = "*" serde_codegen = "0.7.0" "ethcore-ipc-codegen" = { path = "../codegen" }