Remove the cfg(stageN)-specific serialize code.

This commit is contained in:
Erick Tryzelaar 2012-12-20 12:52:53 -08:00
parent faef32995c
commit 76a2891feb
3 changed files with 0 additions and 615 deletions

View File

@ -25,10 +25,6 @@ use reader = std::ebml::reader;
use std::ebml;
use std::map::HashMap;
use std::map;
#[cfg(stage0)]
use std::serialize::traits::Decodable;
#[cfg(stage1)]
#[cfg(stage2)]
use std::serialize::Decodable;
use syntax::ast_map;
use syntax::attr;

View File

@ -29,10 +29,6 @@ use std::ebml;
use std::map::HashMap;
use std::serialize;
use std::serialize::{Encodable, EncoderHelpers, DecoderHelpers};
#[cfg(stage0)]
use std::serialize::traits::Decodable;
#[cfg(stage1)]
#[cfg(stage2)]
use std::serialize::Decodable;
use syntax::ast;
use syntax::ast_map;

View File

@ -102,8 +102,6 @@ pub trait Decoder {
fn read_tup_elt<T>(&self, idx: uint, f: fn() -> T) -> T;
}
#[cfg(stage0)]
pub mod traits {
pub trait Encodable<S: Encoder> {
fn encode(&self, s: &S);
}
@ -582,608 +580,3 @@ pub impl<D: Decoder> D: DecoderHelpers {
}
}
}
}
#[cfg(stage0)]
pub use serialize::traits::*;
#[cfg(stage1)]
#[cfg(stage2)]
pub trait Encodable<S: Encoder> {
fn encode(&self, s: &S);
}
#[cfg(stage1)]
#[cfg(stage2)]
pub trait Decodable<D: Decoder> {
static fn decode(&self, d: &D) -> self;
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder> uint: Encodable<S> {
fn encode(&self, s: &S) { s.emit_uint(*self) }
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder> uint: Decodable<D> {
static fn decode(&self, d: &D) -> uint {
d.read_uint()
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder> u8: Encodable<S> {
fn encode(&self, s: &S) { s.emit_u8(*self) }
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder> u8: Decodable<D> {
static fn decode(&self, d: &D) -> u8 {
d.read_u8()
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder> u16: Encodable<S> {
fn encode(&self, s: &S) { s.emit_u16(*self) }
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder> u16: Decodable<D> {
static fn decode(&self, d: &D) -> u16 {
d.read_u16()
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder> u32: Encodable<S> {
fn encode(&self, s: &S) { s.emit_u32(*self) }
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder> u32: Decodable<D> {
static fn decode(&self, d: &D) -> u32 {
d.read_u32()
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder> u64: Encodable<S> {
fn encode(&self, s: &S) { s.emit_u64(*self) }
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder> u64: Decodable<D> {
static fn decode(&self, d: &D) -> u64 {
d.read_u64()
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder> int: Encodable<S> {
fn encode(&self, s: &S) { s.emit_int(*self) }
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder> int: Decodable<D> {
static fn decode(&self, d: &D) -> int {
d.read_int()
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder> i8: Encodable<S> {
fn encode(&self, s: &S) { s.emit_i8(*self) }
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder> i8: Decodable<D> {
static fn decode(&self, d: &D) -> i8 {
d.read_i8()
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder> i16: Encodable<S> {
fn encode(&self, s: &S) { s.emit_i16(*self) }
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder> i16: Decodable<D> {
static fn decode(&self, d: &D) -> i16 {
d.read_i16()
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder> i32: Encodable<S> {
fn encode(&self, s: &S) { s.emit_i32(*self) }
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder> i32: Decodable<D> {
static fn decode(&self, d: &D) -> i32 {
d.read_i32()
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder> i64: Encodable<S> {
fn encode(&self, s: &S) { s.emit_i64(*self) }
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder> i64: Decodable<D> {
static fn decode(&self, d: &D) -> i64 {
d.read_i64()
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder> &str: Encodable<S> {
fn encode(&self, s: &S) { s.emit_borrowed_str(*self) }
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder> ~str: Encodable<S> {
fn encode(&self, s: &S) { s.emit_owned_str(*self) }
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder> ~str: Decodable<D> {
static fn decode(&self, d: &D) -> ~str {
d.read_owned_str()
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder> @str: Encodable<S> {
fn encode(&self, s: &S) { s.emit_managed_str(*self) }
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder> @str: Decodable<D> {
static fn decode(&self, d: &D) -> @str {
d.read_managed_str()
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder> float: Encodable<S> {
fn encode(&self, s: &S) { s.emit_float(*self) }
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder> float: Decodable<D> {
static fn decode(&self, d: &D) -> float {
d.read_float()
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder> f32: Encodable<S> {
fn encode(&self, s: &S) { s.emit_f32(*self) }
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder> f32: Decodable<D> {
static fn decode(&self, d: &D) -> f32 {
d.read_f32() }
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder> f64: Encodable<S> {
fn encode(&self, s: &S) { s.emit_f64(*self) }
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder> f64: Decodable<D> {
static fn decode(&self, d: &D) -> f64 {
d.read_f64()
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder> bool: Encodable<S> {
fn encode(&self, s: &S) { s.emit_bool(*self) }
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder> bool: Decodable<D> {
static fn decode(&self, d: &D) -> bool {
d.read_bool()
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder> (): Encodable<S> {
fn encode(&self, s: &S) { s.emit_nil() }
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder> (): Decodable<D> {
static fn decode(&self, d: &D) -> () {
d.read_nil()
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder, T: Encodable<S>> &T: Encodable<S> {
fn encode(&self, s: &S) {
s.emit_borrowed(|| (**self).encode(s))
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder, T: Encodable<S>> ~T: Encodable<S> {
fn encode(&self, s: &S) {
s.emit_owned(|| (**self).encode(s))
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder, T: Decodable<D>> ~T: Decodable<D> {
static fn decode(&self, d: &D) -> ~T {
d.read_owned(|| ~Decodable::decode(d))
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder, T: Encodable<S>> @T: Encodable<S> {
fn encode(&self, s: &S) {
s.emit_managed(|| (**self).encode(s))
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder, T: Decodable<D>> @T: Decodable<D> {
static fn decode(&self, d: &D) -> @T {
d.read_managed(|| @Decodable::decode(d))
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder, T: Encodable<S>> &[T]: Encodable<S> {
fn encode(&self, s: &S) {
do s.emit_borrowed_vec(self.len()) {
for self.eachi |i, e| {
s.emit_vec_elt(i, || e.encode(s))
}
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder, T: Encodable<S>> ~[T]: Encodable<S> {
fn encode(&self, s: &S) {
do s.emit_owned_vec(self.len()) {
for self.eachi |i, e| {
s.emit_vec_elt(i, || e.encode(s))
}
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder, T: Decodable<D>> ~[T]: Decodable<D> {
static fn decode(&self, d: &D) -> ~[T] {
do d.read_owned_vec |len| {
do vec::from_fn(len) |i| {
d.read_vec_elt(i, || Decodable::decode(d))
}
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder, T: Encodable<S>> @[T]: Encodable<S> {
fn encode(&self, s: &S) {
do s.emit_managed_vec(self.len()) {
for self.eachi |i, e| {
s.emit_vec_elt(i, || e.encode(s))
}
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder, T: Decodable<D>> @[T]: Decodable<D> {
static fn decode(&self, d: &D) -> @[T] {
do d.read_managed_vec |len| {
do at_vec::from_fn(len) |i| {
d.read_vec_elt(i, || Decodable::decode(d))
}
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder, T: Encodable<S>> Option<T>: Encodable<S> {
fn encode(&self, s: &S) {
do s.emit_enum(~"option") {
match *self {
None => do s.emit_enum_variant(~"none", 0u, 0u) {
},
Some(ref v) => do s.emit_enum_variant(~"some", 1u, 1u) {
s.emit_enum_variant_arg(0u, || v.encode(s))
}
}
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder, T: Decodable<D>> Option<T>: Decodable<D> {
static fn decode(&self, d: &D) -> Option<T> {
do d.read_enum(~"option") {
do d.read_enum_variant |i| {
match i {
0 => None,
1 => Some(d.read_enum_variant_arg(
0u, || Decodable::decode(d))),
_ => fail(fmt!("Bad variant for option: %u", i))
}
}
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<
S: Encoder,
T0: Encodable<S>,
T1: Encodable<S>
> (T0, T1): Encodable<S> {
fn encode(&self, s: &S) {
match *self {
(ref t0, ref t1) => {
do s.emit_tup(2) {
s.emit_tup_elt(0, || t0.encode(s));
s.emit_tup_elt(1, || t1.encode(s));
}
}
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<
D: Decoder,
T0: Decodable<D>,
T1: Decodable<D>
> (T0, T1): Decodable<D> {
static fn decode(&self, d: &D) -> (T0, T1) {
do d.read_tup(2) {
(
d.read_tup_elt(0, || Decodable::decode(d)),
d.read_tup_elt(1, || Decodable::decode(d))
)
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<
S: Encoder,
T0: Encodable<S>,
T1: Encodable<S>,
T2: Encodable<S>
> (T0, T1, T2): Encodable<S> {
fn encode(&self, s: &S) {
match *self {
(ref t0, ref t1, ref t2) => {
do s.emit_tup(3) {
s.emit_tup_elt(0, || t0.encode(s));
s.emit_tup_elt(1, || t1.encode(s));
s.emit_tup_elt(2, || t2.encode(s));
}
}
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<
D: Decoder,
T0: Decodable<D>,
T1: Decodable<D>,
T2: Decodable<D>
> (T0, T1, T2): Decodable<D> {
static fn decode(&self, d: &D) -> (T0, T1, T2) {
do d.read_tup(3) {
(
d.read_tup_elt(0, || Decodable::decode(d)),
d.read_tup_elt(1, || Decodable::decode(d)),
d.read_tup_elt(2, || Decodable::decode(d))
)
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<
S: Encoder,
T0: Encodable<S>,
T1: Encodable<S>,
T2: Encodable<S>,
T3: Encodable<S>
> (T0, T1, T2, T3): Encodable<S> {
fn encode(&self, s: &S) {
match *self {
(ref t0, ref t1, ref t2, ref t3) => {
do s.emit_tup(4) {
s.emit_tup_elt(0, || t0.encode(s));
s.emit_tup_elt(1, || t1.encode(s));
s.emit_tup_elt(2, || t2.encode(s));
s.emit_tup_elt(3, || t3.encode(s));
}
}
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<
D: Decoder,
T0: Decodable<D>,
T1: Decodable<D>,
T2: Decodable<D>,
T3: Decodable<D>
> (T0, T1, T2, T3): Decodable<D> {
static fn decode(&self, d: &D) -> (T0, T1, T2, T3) {
do d.read_tup(4) {
(
d.read_tup_elt(0, || Decodable::decode(d)),
d.read_tup_elt(1, || Decodable::decode(d)),
d.read_tup_elt(2, || Decodable::decode(d)),
d.read_tup_elt(3, || Decodable::decode(d))
)
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<
S: Encoder,
T0: Encodable<S>,
T1: Encodable<S>,
T2: Encodable<S>,
T3: Encodable<S>,
T4: Encodable<S>
> (T0, T1, T2, T3, T4): Encodable<S> {
fn encode(&self, s: &S) {
match *self {
(ref t0, ref t1, ref t2, ref t3, ref t4) => {
do s.emit_tup(5) {
s.emit_tup_elt(0, || t0.encode(s));
s.emit_tup_elt(1, || t1.encode(s));
s.emit_tup_elt(2, || t2.encode(s));
s.emit_tup_elt(3, || t3.encode(s));
s.emit_tup_elt(4, || t4.encode(s));
}
}
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<
D: Decoder,
T0: Decodable<D>,
T1: Decodable<D>,
T2: Decodable<D>,
T3: Decodable<D>,
T4: Decodable<D>
> (T0, T1, T2, T3, T4): Decodable<D> {
static fn decode(&self, d: &D)
-> (T0, T1, T2, T3, T4) {
do d.read_tup(5) {
(
d.read_tup_elt(0, || Decodable::decode(d)),
d.read_tup_elt(1, || Decodable::decode(d)),
d.read_tup_elt(2, || Decodable::decode(d)),
d.read_tup_elt(3, || Decodable::decode(d)),
d.read_tup_elt(4, || Decodable::decode(d))
)
}
}
}
// ___________________________________________________________________________
// Helper routines
//
// In some cases, these should eventually be coded as traits.
#[cfg(stage1)]
#[cfg(stage2)]
pub trait EncoderHelpers {
fn emit_from_vec<T>(&self, v: ~[T], f: fn(v: &T));
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<S: Encoder> S: EncoderHelpers {
fn emit_from_vec<T>(&self, v: ~[T], f: fn(v: &T)) {
do self.emit_owned_vec(v.len()) {
for v.eachi |i, e| {
do self.emit_vec_elt(i) {
f(e)
}
}
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub trait DecoderHelpers {
fn read_to_vec<T>(&self, f: fn() -> T) -> ~[T];
}
#[cfg(stage1)]
#[cfg(stage2)]
pub impl<D: Decoder> D: DecoderHelpers {
fn read_to_vec<T>(&self, f: fn() -> T) -> ~[T] {
do self.read_owned_vec |len| {
do vec::from_fn(len) |i| {
self.read_vec_elt(i, || f())
}
}
}
}