Merge pull request #998 from ethcore/ipc-new-serialization
IPC with new serialization
This commit is contained in:
@@ -155,6 +155,16 @@ struct BinaryExpressions {
|
||||
pub read: P<ast::Expr>,
|
||||
}
|
||||
|
||||
fn replace_qualified(s: &str) -> String {
|
||||
if let Some(pos) = s.find("<") {
|
||||
let mut source = s.to_owned();
|
||||
source.insert(pos, ':');
|
||||
source.insert(pos, ':');
|
||||
source
|
||||
}
|
||||
else { s.to_owned() }
|
||||
}
|
||||
|
||||
fn binary_expr_struct(
|
||||
cx: &ExtCtxt,
|
||||
builder: &aster::AstBuilder,
|
||||
@@ -166,18 +176,21 @@ fn binary_expr_struct(
|
||||
|
||||
let size_exprs: Vec<P<ast::Expr>> = fields.iter().enumerate().map(|(index, field)| {
|
||||
let field_type_ident = builder.id(
|
||||
&::syntax::print::pprust::ty_to_string(
|
||||
&codegen::strip_ptr(&field.ty)));
|
||||
&::syntax::print::pprust::ty_to_string(&codegen::strip_ptr(&field.ty)));
|
||||
|
||||
let field_type_ident_qualified = builder.id(
|
||||
replace_qualified(&::syntax::print::pprust::ty_to_string(&codegen::strip_ptr(&field.ty))));
|
||||
|
||||
let index_ident = builder.id(format!("__field{}", index));
|
||||
value_ident.and_then(|x| {
|
||||
let field_id = builder.id(field.ident.unwrap());
|
||||
Some(quote_expr!(cx,
|
||||
match $field_type_ident::len_params() {
|
||||
match $field_type_ident_qualified::len_params() {
|
||||
0 => mem::size_of::<$field_type_ident>(),
|
||||
_ => $x. $field_id .size(),
|
||||
}))
|
||||
})
|
||||
.unwrap_or_else(|| quote_expr!(cx, match $field_type_ident::len_params() {
|
||||
.unwrap_or_else(|| quote_expr!(cx, match $field_type_ident_qualified::len_params() {
|
||||
0 => mem::size_of::<$field_type_ident>(),
|
||||
_ => $index_ident .size(),
|
||||
}))
|
||||
@@ -199,8 +212,10 @@ fn binary_expr_struct(
|
||||
map_stmts.push(quote_stmt!(cx, let mut total = 0usize;).unwrap());
|
||||
for (index, field) in fields.iter().enumerate() {
|
||||
let field_type_ident = builder.id(
|
||||
&::syntax::print::pprust::ty_to_string(
|
||||
&codegen::strip_ptr(&field.ty)));
|
||||
&::syntax::print::pprust::ty_to_string(&codegen::strip_ptr(&field.ty)));
|
||||
|
||||
let field_type_ident_qualified = builder.id(
|
||||
replace_qualified(&::syntax::print::pprust::ty_to_string(&codegen::strip_ptr(&field.ty))));
|
||||
|
||||
let member_expr = match value_ident {
|
||||
Some(x) => {
|
||||
@@ -213,7 +228,7 @@ fn binary_expr_struct(
|
||||
},
|
||||
};
|
||||
|
||||
write_stmts.push(quote_stmt!(cx, let next_line = offset + match $field_type_ident::len_params() {
|
||||
write_stmts.push(quote_stmt!(cx, let next_line = offset + match $field_type_ident_qualified::len_params() {
|
||||
0 => mem::size_of::<$field_type_ident>(),
|
||||
_ => { let size = $member_expr .size(); length_stack.push_back(size); size },
|
||||
}).unwrap());
|
||||
@@ -225,7 +240,7 @@ fn binary_expr_struct(
|
||||
|
||||
let field_index = builder.id(&format!("{}", index));
|
||||
map_stmts.push(quote_stmt!(cx, map[$field_index] = total;).unwrap());
|
||||
map_stmts.push(quote_stmt!(cx, let size = match $field_type_ident::len_params() {
|
||||
map_stmts.push(quote_stmt!(cx, let size = match $field_type_ident_qualified::len_params() {
|
||||
0 => mem::size_of::<$field_type_ident>(),
|
||||
_ => length_stack.pop_front().unwrap(),
|
||||
}).unwrap());
|
||||
@@ -371,7 +386,7 @@ fn fields_sequence(
|
||||
tt.push(Token(
|
||||
_sp,
|
||||
token::Ident(
|
||||
ext_cx.ident_of(&::syntax::print::pprust::ty_to_string(&field.ty)),
|
||||
ext_cx.ident_of(&replace_qualified(&::syntax::print::pprust::ty_to_string(&field.ty))),
|
||||
token::Plain)));
|
||||
tt.push(Token(_sp, token::ModSep));
|
||||
tt.push(Token(_sp, token::Ident(ext_cx.ident_of("from_bytes"), token::Plain)));
|
||||
@@ -445,7 +460,7 @@ fn named_fields_sequence(
|
||||
tt.push(Token(
|
||||
_sp,
|
||||
token::Ident(
|
||||
ext_cx.ident_of(&::syntax::print::pprust::ty_to_string(&field.ty)),
|
||||
ext_cx.ident_of(&replace_qualified(&::syntax::print::pprust::ty_to_string(&field.ty))),
|
||||
token::Plain)));
|
||||
tt.push(Token(_sp, token::ModSep));
|
||||
tt.push(Token(_sp, token::Ident(ext_cx.ident_of("from_bytes"), token::Plain)));
|
||||
|
||||
Reference in New Issue
Block a user