diff --git a/src/libstd/serialization2.rs b/src/libstd/serialization2.rs index 92461fed258..81941627ef6 100644 --- a/src/libstd/serialization2.rs +++ b/src/libstd/serialization2.rs @@ -4,179 +4,214 @@ Core serialization interfaces. */ -trait Serializer { +#[forbid(deprecated_mode)]; +#[forbid(deprecated_pattern)]; +#[forbid(non_camel_case_types)]; + +pub trait Serializer { // Primitive types: - fn emit_nil(); - fn emit_uint(v: uint); - fn emit_u64(v: u64); - fn emit_u32(v: u32); - fn emit_u16(v: u16); - fn emit_u8(v: u8); - fn emit_int(v: int); - fn emit_i64(v: i64); - fn emit_i32(v: i32); - fn emit_i16(v: i16); - fn emit_i8(v: i8); - fn emit_bool(v: bool); - fn emit_float(v: float); - fn emit_f64(v: f64); - fn emit_f32(v: f32); - fn emit_str(v: &str); + fn emit_nil(&self); + fn emit_uint(&self, v: uint); + fn emit_u64(&self, v: u64); + fn emit_u32(&self, v: u32); + fn emit_u16(&self, v: u16); + fn emit_u8(&self, v: u8); + fn emit_int(&self, v: int); + fn emit_i64(&self, v: i64); + fn emit_i32(&self, v: i32); + fn emit_i16(&self, v: i16); + fn emit_i8(&self, v: i8); + fn emit_bool(&self, v: bool); + fn emit_float(&self, v: float); + fn emit_f64(&self, v: f64); + fn emit_f32(&self, v: f32); + fn emit_str(&self, v: &str); // Compound types: - fn emit_enum(name: &str, f: fn()); - fn emit_enum_variant(v_name: &str, v_id: uint, sz: uint, f: fn()); - fn emit_enum_variant_arg(idx: uint, f: fn()); - fn emit_vec(len: uint, f: fn()); - fn emit_vec_elt(idx: uint, f: fn()); - fn emit_box(f: fn()); - fn emit_uniq(f: fn()); - fn emit_rec(f: fn()); - fn emit_rec_field(f_name: &str, f_idx: uint, f: fn()); - fn emit_tup(sz: uint, f: fn()); - fn emit_tup_elt(idx: uint, f: fn()); + fn emit_enum(&self, name: &str, f: fn()); + fn emit_enum_variant(&self, v_name: &str, v_id: uint, sz: uint, f: fn()); + fn emit_enum_variant_arg(&self, idx: uint, f: fn()); + fn emit_vec(&self, len: uint, f: fn()); + fn emit_vec_elt(&self, idx: uint, f: fn()); + fn emit_box(&self, f: fn()); + fn emit_uniq(&self, f: fn()); + fn emit_rec(&self, f: fn()); + fn emit_rec_field(&self, f_name: &str, f_idx: uint, f: fn()); + fn emit_tup(&self, sz: uint, f: fn()); + fn emit_tup_elt(&self, idx: uint, f: fn()); } -trait Deserializer { +pub trait Deserializer { // Primitive types: - fn read_nil() -> (); - fn read_uint() -> uint; - fn read_u64() -> u64; - fn read_u32() -> u32; - fn read_u16() -> u16; - fn read_u8() -> u8; - fn read_int() -> int; - fn read_i64() -> i64; - fn read_i32() -> i32; - fn read_i16() -> i16; - fn read_i8() -> i8; - fn read_bool() -> bool; - fn read_f64() -> f64; - fn read_f32() -> f32; - fn read_float() -> float; - fn read_str() -> ~str; + fn read_nil(&self) -> (); + fn read_uint(&self) -> uint; + fn read_u64(&self) -> u64; + fn read_u32(&self) -> u32; + fn read_u16(&self) -> u16; + fn read_u8(&self) -> u8; + fn read_int(&self) -> int; + fn read_i64(&self) -> i64; + fn read_i32(&self) -> i32; + fn read_i16(&self) -> i16; + fn read_i8(&self) -> i8; + fn read_bool(&self) -> bool; + fn read_f64(&self) -> f64; + fn read_f32(&self) -> f32; + fn read_float(&self) -> float; + fn read_str(&self) -> ~str; // Compound types: - fn read_enum(name: ~str, f: fn() -> T) -> T; - fn read_enum_variant(f: fn(uint) -> T) -> T; - fn read_enum_variant_arg(idx: uint, f: fn() -> T) -> T; - fn read_vec(f: fn(uint) -> T) -> T; - fn read_vec_elt(idx: uint, f: fn() -> T) -> T; - fn read_box(f: fn() -> T) -> T; - fn read_uniq(f: fn() -> T) -> T; - fn read_rec(f: fn() -> T) -> T; - fn read_rec_field(f_name: ~str, f_idx: uint, f: fn() -> T) -> T; - fn read_tup(sz: uint, f: fn() -> T) -> T; - fn read_tup_elt(idx: uint, f: fn() -> T) -> T; + fn read_enum(&self, name: ~str, f: fn() -> T) -> T; + fn read_enum_variant(&self, f: fn(uint) -> T) -> T; + fn read_enum_variant_arg(&self, idx: uint, f: fn() -> T) -> T; + fn read_vec(&self, f: fn(uint) -> T) -> T; + fn read_vec_elt(&self, idx: uint, f: fn() -> T) -> T; + fn read_box(&self, f: fn() -> T) -> T; + fn read_uniq(&self, f: fn() -> T) -> T; + fn read_rec(&self, f: fn() -> T) -> T; + fn read_rec_field(&self, f_name: ~str, f_idx: uint, f: fn() -> T) -> T; + fn read_tup(&self, sz: uint, f: fn() -> T) -> T; + fn read_tup_elt(&self, idx: uint, f: fn() -> T) -> T; } -trait Serializable { - fn serialize(s: S); - static fn deserialize(d: D) -> self; +pub trait Serializable { + fn serialize(&self, s: &S); + static fn deserialize(&self, d: &D) -> self; } -impl uint: Serializable { - fn serialize(s: S) { s.emit_uint(self) } - static fn deserialize(d: D) -> uint { d.read_uint() } +pub impl uint: Serializable { + fn serialize(&self, s: &S) { s.emit_uint(*self) } + static fn deserialize(&self, d: &D) -> uint { + d.read_uint() + } } -impl u8: Serializable { - fn serialize(s: S) { s.emit_u8(self) } - static fn deserialize(d: D) -> u8 { d.read_u8() } +pub impl u8: Serializable { + fn serialize(&self, s: &S) { s.emit_u8(*self) } + static fn deserialize(&self, d: &D) -> u8 { + d.read_u8() + } } -impl u16: Serializable { - fn serialize(s: S) { s.emit_u16(self) } - static fn deserialize(d: D) -> u16 { d.read_u16() } +pub impl u16: Serializable { + fn serialize(&self, s: &S) { s.emit_u16(*self) } + static fn deserialize(&self, d: &D) -> u16 { + d.read_u16() + } } -impl u32: Serializable { - fn serialize(s: S) { s.emit_u32(self) } - static fn deserialize(d: D) -> u32 { d.read_u32() } +pub impl u32: Serializable { + fn serialize(&self, s: &S) { s.emit_u32(*self) } + static fn deserialize(&self, d: &D) -> u32 { + d.read_u32() + } } -impl u64: Serializable { - fn serialize(s: S) { s.emit_u64(self) } - static fn deserialize(d: D) -> u64 { d.read_u64() } +pub impl u64: Serializable { + fn serialize(&self, s: &S) { s.emit_u64(*self) } + static fn deserialize(&self, d: &D) -> u64 { + d.read_u64() + } } -impl int: Serializable { - fn serialize(s: S) { s.emit_int(self) } - static fn deserialize(d: D) -> int { d.read_int() } +pub impl int: Serializable { + fn serialize(&self, s: &S) { s.emit_int(*self) } + static fn deserialize(&self, d: &D) -> int { + d.read_int() + } } -impl i8: Serializable { - fn serialize(s: S) { s.emit_i8(self) } - static fn deserialize(d: D) -> i8 { d.read_i8() } +pub impl i8: Serializable { + fn serialize(&self, s: &S) { s.emit_i8(*self) } + static fn deserialize(&self, d: &D) -> i8 { + d.read_i8() + } } -impl i16: Serializable { - fn serialize(s: S) { s.emit_i16(self) } - static fn deserialize(d: D) -> i16 { d.read_i16() } +pub impl i16: Serializable { + fn serialize(&self, s: &S) { s.emit_i16(*self) } + static fn deserialize(&self, d: &D) -> i16 { + d.read_i16() + } } -impl i32: Serializable { - fn serialize(s: S) { s.emit_i32(self) } - static fn deserialize(d: D) -> i32 { d.read_i32() } +pub impl i32: Serializable { + fn serialize(&self, s: &S) { s.emit_i32(*self) } + static fn deserialize(&self, d: &D) -> i32 { + d.read_i32() + } } -impl i64: Serializable { - fn serialize(s: S) { s.emit_i64(self) } - static fn deserialize(d: D) -> i64 { d.read_i64() } +pub impl i64: Serializable { + fn serialize(&self, s: &S) { s.emit_i64(*self) } + static fn deserialize(&self, d: &D) -> i64 { + d.read_i64() + } } -impl ~str: Serializable { - fn serialize(s: S) { s.emit_str(self) } - static fn deserialize(d: D) -> ~str { d.read_str() } +pub impl ~str: Serializable { + fn serialize(&self, s: &S) { s.emit_str(*self) } + static fn deserialize(&self, d: &D) -> ~str { + d.read_str() + } } -impl float: Serializable { - fn serialize(s: S) { s.emit_float(self) } - static fn deserialize(d: D) -> float { d.read_float() } +pub impl float: Serializable { + fn serialize(&self, s: &S) { s.emit_float(*self) } + static fn deserialize(&self, d: &D) -> float { + d.read_float() + } } -impl f32: Serializable { - fn serialize(s: S) { s.emit_f32(self) } - static fn deserialize(d: D) -> f32 { d.read_f32() } +pub impl f32: Serializable { + fn serialize(&self, s: &S) { s.emit_f32(*self) } + static fn deserialize(&self, d: &D) -> f32 { + d.read_f32() } } -impl f64: Serializable { - fn serialize(s: S) { s.emit_f64(self) } - static fn deserialize(d: D) -> f64 { d.read_f64() } +pub impl f64: Serializable { + fn serialize(&self, s: &S) { s.emit_f64(*self) } + static fn deserialize(&self, d: &D) -> f64 { + d.read_f64() + } } -impl bool: Serializable { - fn serialize(s: S) { s.emit_bool(self) } - static fn deserialize(d: D) -> bool { d.read_bool() } +pub impl bool: Serializable { + fn serialize(&self, s: &S) { s.emit_bool(*self) } + static fn deserialize(&self, d: &D) -> bool { + d.read_bool() + } } -impl (): Serializable { - fn serialize(s: S) { s.emit_nil() } - static fn deserialize(d: D) -> () { d.read_nil() } +pub impl (): Serializable { + fn serialize(&self, s: &S) { s.emit_nil() } + static fn deserialize(&self, d: &D) -> () { + d.read_nil() + } } -impl @T: Serializable { - fn serialize(s: S) { +pub impl @T: Serializable { + fn serialize(&self, s: &S) { s.emit_box(|| (*self).serialize(s)) } - static fn deserialize(d: D) -> @T { + static fn deserialize(&self, d: &D) -> @T { d.read_box(|| @deserialize(d)) } } -impl ~T: Serializable { - fn serialize(s: S) { +pub impl ~T: Serializable { + fn serialize(&self, s: &S) { s.emit_uniq(|| (*self).serialize(s)) } - static fn deserialize(d: D) -> ~T { + static fn deserialize(&self, d: &D) -> ~T { d.read_uniq(|| ~deserialize(d)) } } -impl ~[T]: Serializable { - fn serialize(s: S) { +pub impl ~[T]: Serializable { + fn serialize(&self, s: &S) { do s.emit_vec(self.len()) { for self.eachi |i, e| { s.emit_vec_elt(i, || e.serialize(s)) @@ -184,7 +219,7 @@ impl ~[T]: Serializable { } } - static fn deserialize(d: D) -> ~[T] { + static fn deserialize(&self, d: &D) -> ~[T] { do d.read_vec |len| { do vec::from_fn(len) |i| { d.read_vec_elt(i, || deserialize(d)) @@ -193,10 +228,10 @@ impl ~[T]: Serializable { } } -impl Option: Serializable { - fn serialize(s: S) { +pub impl Option: Serializable { + fn serialize(&self, s: &S) { do s.emit_enum(~"option") { - match self { + match *self { None => do s.emit_enum_variant(~"none", 0u, 0u) { }, @@ -207,7 +242,7 @@ impl Option: Serializable { } } - static fn deserialize(d: D) -> Option { + static fn deserialize(&self, d: &D) -> Option { do d.read_enum(~"option") { do d.read_enum_variant |i| { match i { @@ -220,12 +255,12 @@ impl Option: Serializable { } } -impl< +pub impl< T0: Serializable, T1: Serializable > (T0, T1): Serializable { - fn serialize(s: S) { - match self { + fn serialize(&self, s: &S) { + match *self { (t0, t1) => { do s.emit_tup(2) { s.emit_tup_elt(0, || t0.serialize(s)); @@ -235,7 +270,7 @@ impl< } } - static fn deserialize(d: D) -> (T0, T1) { + static fn deserialize(&self, d: &D) -> (T0, T1) { do d.read_tup(2) { ( d.read_tup_elt(0, || deserialize(d)), @@ -245,13 +280,13 @@ impl< } } -impl< +pub impl< T0: Serializable, T1: Serializable, T2: Serializable > (T0, T1, T2): Serializable { - fn serialize(s: S) { - match self { + fn serialize(&self, s: &S) { + match *self { (t0, t1, t2) => { do s.emit_tup(3) { s.emit_tup_elt(0, || t0.serialize(s)); @@ -262,7 +297,7 @@ impl< } } - static fn deserialize(d: D) -> (T0, T1, T2) { + static fn deserialize(&self, d: &D) -> (T0, T1, T2) { do d.read_tup(3) { ( d.read_tup_elt(0, || deserialize(d)), @@ -273,14 +308,14 @@ impl< } } -impl< +pub impl< T0: Serializable, T1: Serializable, T2: Serializable, T3: Serializable > (T0, T1, T2, T3): Serializable { - fn serialize(s: S) { - match self { + fn serialize(&self, s: &S) { + match *self { (t0, t1, t2, t3) => { do s.emit_tup(4) { s.emit_tup_elt(0, || t0.serialize(s)); @@ -292,7 +327,7 @@ impl< } } - static fn deserialize(d: D) -> (T0, T1, T2, T3) { + static fn deserialize(&self, d: &D) -> (T0, T1, T2, T3) { do d.read_tup(4) { ( d.read_tup_elt(0, || deserialize(d)), @@ -304,15 +339,15 @@ impl< } } -impl< +pub impl< T0: Serializable, T1: Serializable, T2: Serializable, T3: Serializable, T4: Serializable > (T0, T1, T2, T3, T4): Serializable { - fn serialize(s: S) { - match self { + fn serialize(&self, s: &S) { + match *self { (t0, t1, t2, t3, t4) => { do s.emit_tup(5) { s.emit_tup_elt(0, || t0.serialize(s)); @@ -325,7 +360,8 @@ impl< } } - static fn deserialize(d: D) -> (T0, T1, T2, T3, T4) { + static fn deserialize(&self, d: &D) + -> (T0, T1, T2, T3, T4) { do d.read_tup(5) { ( d.read_tup_elt(0, || deserialize(d)), @@ -343,40 +379,32 @@ impl< // // In some cases, these should eventually be coded as traits. -fn emit_from_vec(s: S, v: ~[T], f: fn(T)) { - do s.emit_vec(v.len()) { - for v.eachi |i, e| { - do s.emit_vec_elt(i) { - f(*e) +pub trait SerializerHelpers { + fn emit_from_vec(&self, v: ~[T], f: fn(v: &T)); +} + +pub impl S: SerializerHelpers { + fn emit_from_vec(&self, v: ~[T], f: fn(v: &T)) { + do self.emit_vec(v.len()) { + for v.eachi |i, e| { + do self.emit_vec_elt(i) { + f(e) + } } } } } -fn read_to_vec(d: D, f: fn() -> T) -> ~[T] { - do d.read_vec |len| { - do vec::from_fn(len) |i| { - d.read_vec_elt(i, || f()) +pub trait DeserializerHelpers { + fn read_to_vec(&self, f: fn() -> T) -> ~[T]; +} + +pub impl D: DeserializerHelpers { + fn read_to_vec(&self, f: fn() -> T) -> ~[T] { + do self.read_vec |len| { + do vec::from_fn(len) |i| { + self.read_vec_elt(i, || f()) + } } } } - -trait SerializerHelpers { - fn emit_from_vec(v: ~[T], f: fn(T)); -} - -impl S: SerializerHelpers { - fn emit_from_vec(v: ~[T], f: fn(T)) { - emit_from_vec(self, v, f) - } -} - -trait DeserializerHelpers { - fn read_to_vec(f: fn() -> T) -> ~[T]; -} - -impl D: DeserializerHelpers { - fn read_to_vec(f: fn() -> T) -> ~[T] { - read_to_vec(self, f) - } -} diff --git a/src/libstd/std.rc b/src/libstd/std.rc index 5979b98478f..548ec1c31b4 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -144,7 +144,6 @@ mod unicode; mod test; #[legacy_exports] mod serialization; -#[legacy_exports] mod serialization2; // Local Variables: diff --git a/src/libsyntax/ext/auto_serialize2.rs b/src/libsyntax/ext/auto_serialize2.rs index e2e308f7e2c..264711584fc 100644 --- a/src/libsyntax/ext/auto_serialize2.rs +++ b/src/libsyntax/ext/auto_serialize2.rs @@ -232,9 +232,24 @@ fn mk_ser_method( bounds: @~[ast::bound_trait(ser_bound)], }]; + let ty_s = @{ + id: cx.next_id(), + node: ast::ty_rptr( + @{ + id: cx.next_id(), + node: ast::re_anon, + }, + { + ty: cx.ty_path(span, ~[cx.ident_of(~"__S")], ~[]), + mutbl: ast::m_imm + } + ), + span: span, + }; + let ser_inputs = ~[{ - mode: ast::expl(ast::by_ref), - ty: cx.ty_path(span, ~[cx.ident_of(~"__S")], ~[]), + mode: ast::infer(cx.next_id()), + ty: ty_s, ident: cx.ident_of(~"__s"), id: cx.next_id(), }]; @@ -255,7 +270,7 @@ fn mk_ser_method( ident: cx.ident_of(~"serialize"), attrs: ~[], tps: ser_tps, - self_ty: { node: ast::sty_by_ref, span: span }, + self_ty: { node: ast::sty_region(ast::m_imm), span: span }, purity: ast::impure_fn, decl: ser_decl, body: ser_body, @@ -288,9 +303,24 @@ fn mk_deser_method( bounds: @~[ast::bound_trait(deser_bound)], }]; + let ty_d = @{ + id: cx.next_id(), + node: ast::ty_rptr( + @{ + id: cx.next_id(), + node: ast::re_anon, + }, + { + ty: cx.ty_path(span, ~[cx.ident_of(~"__D")], ~[]), + mutbl: ast::m_imm + } + ), + span: span, + }; + let deser_inputs = ~[{ - mode: ast::expl(ast::by_ref), - ty: cx.ty_path(span, ~[cx.ident_of(~"__D")], ~[]), + mode: ast::infer(cx.next_id()), + ty: ty_d, ident: cx.ident_of(~"__d"), id: cx.next_id(), }]; @@ -608,11 +638,14 @@ fn mk_enum_ser_body( } }; - // ast for `match self { $(arms) }` + // ast for `match *self { $(arms) }` let match_expr = cx.expr( span, ast::expr_match( - cx.expr_var(span, ~"self"), + cx.expr( + span, + ast::expr_unary(ast::deref, cx.expr_var(span, ~"self")) + ), arms ) ); diff --git a/src/test/run-pass/auto_serialize2-box.rs b/src/test/run-pass/auto_serialize2-box.rs new file mode 100644 index 00000000000..e395b1bfe5d --- /dev/null +++ b/src/test/run-pass/auto_serialize2-box.rs @@ -0,0 +1,73 @@ +// xfail-test FIXME Blocked on (#3585) + +extern mod std; + +// These tests used to be separate files, but I wanted to refactor all +// the common code. + +use cmp::Eq; +use std::ebml2; +use io::Writer; +use std::serialization2::{Serializer, Serializable, deserialize}; +use std::prettyprint2; + +fn test_ser_and_deser( + a1: A, + expected: ~str +) { + // check the pretty printer: + let s = do io::with_str_writer |w| { + a1.serialize(&prettyprint2::Serializer(w)) + }; + debug!("s == %?", s); + assert s == expected; + + // check the EBML serializer: + let bytes = do io::with_bytes_writer |wr| { + let ebml_w = &ebml2::Serializer(wr); + a1.serialize(ebml_w) + }; + let d = ebml2::Doc(@bytes); + let a2: A = deserialize(&ebml2::Deserializer(d)); + assert a1 == a2; +} + +#[auto_serialize2] +enum Expr { + Val(uint), + Plus(@Expr, @Expr), + Minus(@Expr, @Expr) +} + +impl Expr : cmp::Eq { + pure fn eq(other: &Expr) -> bool { + match self { + Val(e0a) => { + match *other { + Val(e0b) => e0a == e0b, + _ => false + } + } + Plus(e0a, e1a) => { + match *other { + Plus(e0b, e1b) => e0a == e0b && e1a == e1b, + _ => false + } + } + Minus(e0a, e1a) => { + match *other { + Minus(e0b, e1b) => e0a == e0b && e1a == e1b, + _ => false + } + } + } + } + pure fn ne(other: &Expr) -> bool { !self.eq(other) } +} + +fn main() { + test_ser_and_deser(Plus(@Minus(@Val(3u), @Val(10u)), + @Plus(@Val(22u), @Val(5u))), + ~"Plus(@Minus(@Val(3u), @Val(10u)), \ + @Plus(@Val(22u), @Val(5u)))"); +} diff --git a/src/test/run-pass/auto_serialize2.rs b/src/test/run-pass/auto_serialize2.rs index da48de2ffab..ac526a8f0b6 100644 --- a/src/test/run-pass/auto_serialize2.rs +++ b/src/test/run-pass/auto_serialize2.rs @@ -15,98 +15,71 @@ fn test_ser_and_deser( ) { // check the pretty printer: - let s = io::with_str_writer(|w| a1.serialize(w)); + let s = do io::with_str_writer |w| { + a1.serialize(&prettyprint2::Serializer(w)) + }; debug!("s == %?", s); assert s == expected; // check the EBML serializer: let bytes = do io::with_bytes_writer |wr| { - let ebml_w = ebml2::Serializer(wr); + let ebml_w = &ebml2::Serializer(wr); a1.serialize(ebml_w) }; let d = ebml2::Doc(@bytes); - let a2: A = deserialize(ebml2::Deserializer(d)); + let a2: A = deserialize(&ebml2::Deserializer(d)); assert a1 == a2; } -#[auto_serialize2] -enum Expr { - Val(uint), - Plus(@Expr, @Expr), - Minus(@Expr, @Expr) -} - impl AnEnum : cmp::Eq { - pure fn eq(&&other: AnEnum) -> bool { + pure fn eq(other: &AnEnum) -> bool { self.v == other.v } - pure fn ne(&&other: AnEnum) -> bool { !self.eq(other) } + pure fn ne(other: &AnEnum) -> bool { !self.eq(other) } } impl Point : cmp::Eq { - pure fn eq(&&other: Point) -> bool { + pure fn eq(other: &Point) -> bool { self.x == other.x && self.y == other.y } - pure fn ne(&&other: Point) -> bool { !self.eq(other) } + pure fn ne(other: &Point) -> bool { !self.eq(other) } } impl Quark : cmp::Eq { - pure fn eq(&&other: Quark) -> bool { + pure fn eq(other: &Quark) -> bool { match self { - Top(ref q) => match other { - Top(ref r) => q == r, - Bottom(_) => false - }, - Bottom(ref q) => match other { - Top(_) => false, - Bottom(ref r) => q == r - } + Top(ref q) => { + match *other { + Top(ref r) => q == r, + Bottom(_) => false + } + }, + Bottom(ref q) => { + match *other { + Top(_) => false, + Bottom(ref r) => q == r + } + }, } } - pure fn ne(&&other: Quark) -> bool { !self.eq(other) } + pure fn ne(other: &Quark) -> bool { !self.eq(other) } } impl CLike : cmp::Eq { - pure fn eq(&&other: CLike) -> bool { - self as int == other as int + pure fn eq(other: &CLike) -> bool { + self as int == *other as int } - pure fn ne(&&other: CLike) -> bool { !self.eq(other) } -} - -impl Expr : cmp::Eq { - pure fn eq(&&other: Expr) -> bool { - match self { - Val(e0a) => { - match other { - Val(e0b) => e0a == e0b, - _ => false - } - } - Plus(e0a, e1a) => { - match other { - Plus(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - Minus(e0a, e1a) => { - match other { - Minus(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - } - } - pure fn ne(&&other: Expr) -> bool { !self.eq(other) } + pure fn ne(other: &CLike) -> bool { !self.eq(other) } } #[auto_serialize2] type Spanned = {lo: uint, hi: uint, node: T}; impl Spanned : cmp::Eq { - pure fn eq(&&other: Spanned) -> bool { - self.lo == other.lo && self.hi == other.hi && self.node.eq(other.node) + pure fn eq(other: &Spanned) -> bool { + self.lo == other.lo && self.hi == other.hi && self.node == other.node } - pure fn ne(&&other: Spanned) -> bool { !self.eq(other) } + pure fn ne(other: &Spanned) -> bool { !self.eq(other) } } #[auto_serialize2] @@ -128,12 +101,6 @@ enum Quark { enum CLike { A, B, C } fn main() { - - test_ser_and_deser(Plus(@Minus(@Val(3u), @Val(10u)), - @Plus(@Val(22u), @Val(5u))), - ~"Plus(@Minus(@Val(3u), @Val(10u)), \ - @Plus(@Val(22u), @Val(5u)))"); - test_ser_and_deser({lo: 0u, hi: 5u, node: 22u}, ~"{lo: 0u, hi: 5u, node: 22u}");