libstd: make Serializer a trait-level typaram
This commit is contained in:
parent
07edf90367
commit
ab89b5c294
5 changed files with 692 additions and 77 deletions
|
|
@ -7,17 +7,34 @@ use std::serialization::{Serializable,
|
|||
use codemap::{span, filename};
|
||||
use parse::token;
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl span: Serializable {
|
||||
/* Note #1972 -- spans are serialized but not deserialized */
|
||||
fn serialize<S: Serializer>(&self, _s: &S) { }
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl span: Deserializable {
|
||||
static fn deserialize<D: Deserializer>(_d: &D) -> span {
|
||||
ast_util::dummy_sp()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
impl<S: Serializer> span: Serializable<S> {
|
||||
/* Note #1972 -- spans are serialized but not deserialized */
|
||||
fn serialize(&self, _s: &S) { }
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
impl<D: Deserializer> span: Deserializable<D> {
|
||||
static fn deserialize(_d: &D) -> span {
|
||||
ast_util::dummy_sp()
|
||||
}
|
||||
}
|
||||
|
||||
#[auto_serialize]
|
||||
#[auto_deserialize]
|
||||
type spanned<T> = {node: T, span: span};
|
||||
|
|
@ -34,6 +51,7 @@ macro_rules! interner_key (
|
|||
// implemented.
|
||||
struct ident { repr: uint }
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl ident: Serializable {
|
||||
fn serialize<S: Serializer>(&self, s: &S) {
|
||||
let intr = match unsafe {
|
||||
|
|
@ -47,6 +65,7 @@ impl ident: Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl ident: Deserializable {
|
||||
static fn deserialize<D: Deserializer>(d: &D) -> ident {
|
||||
let intr = match unsafe {
|
||||
|
|
@ -60,6 +79,36 @@ impl ident: Deserializable {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
impl<S: Serializer> ident: Serializable<S> {
|
||||
fn serialize(&self, s: &S) {
|
||||
let intr = match unsafe {
|
||||
task::local_data::local_data_get(interner_key!())
|
||||
} {
|
||||
None => fail ~"serialization: TLS interner not set up",
|
||||
Some(intr) => intr
|
||||
};
|
||||
|
||||
s.emit_owned_str(*(*intr).get(*self));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
impl<D: Deserializer> ident: Deserializable<D> {
|
||||
static fn deserialize(d: &D) -> ident {
|
||||
let intr = match unsafe {
|
||||
task::local_data::local_data_get(interner_key!())
|
||||
} {
|
||||
None => fail ~"deserialization: TLS interner not set up",
|
||||
Some(intr) => intr
|
||||
};
|
||||
|
||||
(*intr).intern(@d.read_owned_str())
|
||||
}
|
||||
}
|
||||
|
||||
impl ident: cmp::Eq {
|
||||
pure fn eq(other: &ident) -> bool { self.repr == other.repr }
|
||||
pure fn ne(other: &ident) -> bool { !self.eq(other) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue