Merge pull request #1250 from ethcore/codegen-unwraps

codegen - avoid unwraps leading to compilation crash
This commit is contained in:
Arkadiy Paronyan 2016-06-12 12:02:26 +02:00 committed by GitHub
commit 7f9e8d0b48
3 changed files with 26 additions and 17 deletions

View File

@ -15,7 +15,7 @@ with-syntex = ["quasi/with-syntex", "quasi_codegen", "quasi_codegen/with-syntex"
[build-dependencies]
quasi_codegen = { version = "0.11", optional = true }
syntex = { version = "*", optional = true }
syntex = { version = "0.33", optional = true }
[dependencies]
aster = { version = "0.17", default-features = false }

View File

@ -89,7 +89,7 @@ fn serialize_item(
let (size_expr, read_expr, write_expr) =
(binary_expressions.size, binary_expressions.read, binary_expressions.write);
Ok(quote_item!(cx,
match quote_item!(cx,
impl $generics ::ipc::BinaryConvertable for $ty $where_clause {
fn size(&self) -> usize {
$size_expr
@ -106,8 +106,16 @@ fn serialize_item(
fn len_params() -> usize {
1
}
}
).unwrap())
})
{
Some(item) => Ok(item),
None => {
cx.span_err(
item.span,
"syntax error expanding serialization implementation");
Err(Error)
}
}
}
#[allow(unreachable_code)]

View File

@ -19,20 +19,20 @@ extern crate ethcore_ipc_codegen as codegen;
use std::env;
use std::path::Path;
use std::process::exit;
pub fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
// ipc pass
{
// rpc pass
if {
let src = Path::new("nested.rs.in");
let dst = Path::new(&out_dir).join("nested_ipc.rs");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &src, &dst).unwrap();
registry.expand("", &src, &dst).is_ok()
}
// serde pass
// serialization pass
{
let src = Path::new(&out_dir).join("nested_ipc.rs");
let dst = Path::new(&out_dir).join("nested_cg.rs");
@ -41,16 +41,15 @@ pub fn main() {
registry.expand("", &src, &dst).unwrap();
}
// ipc pass
{
// rpc pass
if {
let src = Path::new("service.rs.in");
let dst = Path::new(&out_dir).join("service_ipc.rs");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &src, &dst).unwrap();
registry.expand("", &src, &dst).is_ok()
}
// serde pass
// serialization pass
{
let src = Path::new(&out_dir).join("service_ipc.rs");
let dst = Path::new(&out_dir).join("service_cg.rs");
@ -59,13 +58,15 @@ pub fn main() {
registry.expand("", &src, &dst).unwrap();
}
// ipc pass
// rpc pass
{
let src = Path::new("binary.rs.in");
let dst = Path::new(&out_dir).join("binary.rs");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &src, &dst).unwrap();
if let Err(err_msg) = registry.expand("", &src, &dst) {
println!("error: {}", err_msg);
exit(1);
}
}
}