Camel case std::serialization

This commit is contained in:
Brian Anderson 2012-09-10 19:02:41 -07:00
parent f8b3eaae82
commit 1a8a0a77b1
9 changed files with 66 additions and 63 deletions

View File

@ -340,7 +340,7 @@ impl ebml::Writer: SerializerPriv {
} }
} }
impl ebml::Writer: serialization::serializer { impl ebml::Writer: serialization::Serializer {
fn emit_nil() {} fn emit_nil() {}
fn emit_uint(v: uint) { self.wr_tagged_u64(EsUint as uint, v as u64); } fn emit_uint(v: uint) { self.wr_tagged_u64(EsUint as uint, v as u64); }
@ -462,7 +462,7 @@ priv impl EbmlDeserializer {
} }
} }
impl EbmlDeserializer: serialization::deserializer { impl EbmlDeserializer: serialization::Deserializer {
fn read_nil() -> () { () } fn read_nil() -> () { () }
fn read_u64() -> u64 { ebml::doc_as_u64(self.next_doc(EsU64)) } fn read_u64() -> u64 { ebml::doc_as_u64(self.next_doc(EsU64)) }

View File

@ -3,9 +3,9 @@
use io::Writer; use io::Writer;
use io::WriterUtil; use io::WriterUtil;
use serialization::serializer; use serialization::Serializer;
impl Writer: serializer { impl Writer: Serializer {
fn emit_nil() { fn emit_nil() {
self.write_str(~"()") self.write_str(~"()")
} }

View File

@ -1,12 +1,18 @@
//! Support code for serialization. //! Support code for serialization.
use core; // XXX remove
#[cfg(stage0)]
#[allow(non_camel_case_types)]
type serializer = Serializer;
#[cfg(stage0)]
#[allow(non_camel_case_types)]
type deserializer = Deserializer;
/* /*
Core serialization interfaces. Core serialization interfaces.
*/ */
trait serializer { trait Serializer {
// Primitive types: // Primitive types:
fn emit_nil(); fn emit_nil();
fn emit_uint(v: uint); fn emit_uint(v: uint);
@ -39,7 +45,7 @@ trait serializer {
fn emit_tup_elt(idx: uint, f: fn()); fn emit_tup_elt(idx: uint, f: fn());
} }
trait deserializer { trait Deserializer {
// Primitive types: // Primitive types:
fn read_nil() -> (); fn read_nil() -> ();
@ -83,7 +89,7 @@ trait deserializer {
// //
// In some cases, these should eventually be coded as traits. // In some cases, these should eventually be coded as traits.
fn emit_from_vec<S: serializer, T>(s: S, v: ~[T], f: fn(T)) { fn emit_from_vec<S: Serializer, T>(s: S, v: ~[T], f: fn(T)) {
do s.emit_vec(vec::len(v)) { do s.emit_vec(vec::len(v)) {
do vec::iteri(v) |i,e| { do vec::iteri(v) |i,e| {
do s.emit_vec_elt(i) { do s.emit_vec_elt(i) {
@ -93,7 +99,7 @@ fn emit_from_vec<S: serializer, T>(s: S, v: ~[T], f: fn(T)) {
} }
} }
fn read_to_vec<D: deserializer, T: Copy>(d: D, f: fn() -> T) -> ~[T] { fn read_to_vec<D: Deserializer, T: Copy>(d: D, f: fn() -> T) -> ~[T] {
do d.read_vec |len| { do d.read_vec |len| {
do vec::from_fn(len) |i| { do vec::from_fn(len) |i| {
d.read_vec_elt(i, || f()) d.read_vec_elt(i, || f())
@ -101,147 +107,147 @@ fn read_to_vec<D: deserializer, T: Copy>(d: D, f: fn() -> T) -> ~[T] {
} }
} }
trait serializer_helpers { trait SerializerHelpers {
fn emit_from_vec<T>(v: ~[T], f: fn(T)); fn emit_from_vec<T>(v: ~[T], f: fn(T));
} }
impl<S: serializer> S: serializer_helpers { impl<S: Serializer> S: SerializerHelpers {
fn emit_from_vec<T>(v: ~[T], f: fn(T)) { fn emit_from_vec<T>(v: ~[T], f: fn(T)) {
emit_from_vec(self, v, f) emit_from_vec(self, v, f)
} }
} }
trait deserializer_helpers { trait DeserializerHelpers {
fn read_to_vec<T: Copy>(f: fn() -> T) -> ~[T]; fn read_to_vec<T: Copy>(f: fn() -> T) -> ~[T];
} }
impl<D: deserializer> D: deserializer_helpers { impl<D: Deserializer> D: DeserializerHelpers {
fn read_to_vec<T: Copy>(f: fn() -> T) -> ~[T] { fn read_to_vec<T: Copy>(f: fn() -> T) -> ~[T] {
read_to_vec(self, f) read_to_vec(self, f)
} }
} }
fn serialize_uint<S: serializer>(s: S, v: uint) { fn serialize_uint<S: Serializer>(s: S, v: uint) {
s.emit_uint(v); s.emit_uint(v);
} }
fn deserialize_uint<D: deserializer>(d: D) -> uint { fn deserialize_uint<D: Deserializer>(d: D) -> uint {
d.read_uint() d.read_uint()
} }
fn serialize_u8<S: serializer>(s: S, v: u8) { fn serialize_u8<S: Serializer>(s: S, v: u8) {
s.emit_u8(v); s.emit_u8(v);
} }
fn deserialize_u8<D: deserializer>(d: D) -> u8 { fn deserialize_u8<D: Deserializer>(d: D) -> u8 {
d.read_u8() d.read_u8()
} }
fn serialize_u16<S: serializer>(s: S, v: u16) { fn serialize_u16<S: Serializer>(s: S, v: u16) {
s.emit_u16(v); s.emit_u16(v);
} }
fn deserialize_u16<D: deserializer>(d: D) -> u16 { fn deserialize_u16<D: Deserializer>(d: D) -> u16 {
d.read_u16() d.read_u16()
} }
fn serialize_u32<S: serializer>(s: S, v: u32) { fn serialize_u32<S: Serializer>(s: S, v: u32) {
s.emit_u32(v); s.emit_u32(v);
} }
fn deserialize_u32<D: deserializer>(d: D) -> u32 { fn deserialize_u32<D: Deserializer>(d: D) -> u32 {
d.read_u32() d.read_u32()
} }
fn serialize_u64<S: serializer>(s: S, v: u64) { fn serialize_u64<S: Serializer>(s: S, v: u64) {
s.emit_u64(v); s.emit_u64(v);
} }
fn deserialize_u64<D: deserializer>(d: D) -> u64 { fn deserialize_u64<D: Deserializer>(d: D) -> u64 {
d.read_u64() d.read_u64()
} }
fn serialize_int<S: serializer>(s: S, v: int) { fn serialize_int<S: Serializer>(s: S, v: int) {
s.emit_int(v); s.emit_int(v);
} }
fn deserialize_int<D: deserializer>(d: D) -> int { fn deserialize_int<D: Deserializer>(d: D) -> int {
d.read_int() d.read_int()
} }
fn serialize_i8<S: serializer>(s: S, v: i8) { fn serialize_i8<S: Serializer>(s: S, v: i8) {
s.emit_i8(v); s.emit_i8(v);
} }
fn deserialize_i8<D: deserializer>(d: D) -> i8 { fn deserialize_i8<D: Deserializer>(d: D) -> i8 {
d.read_i8() d.read_i8()
} }
fn serialize_i16<S: serializer>(s: S, v: i16) { fn serialize_i16<S: Serializer>(s: S, v: i16) {
s.emit_i16(v); s.emit_i16(v);
} }
fn deserialize_i16<D: deserializer>(d: D) -> i16 { fn deserialize_i16<D: Deserializer>(d: D) -> i16 {
d.read_i16() d.read_i16()
} }
fn serialize_i32<S: serializer>(s: S, v: i32) { fn serialize_i32<S: Serializer>(s: S, v: i32) {
s.emit_i32(v); s.emit_i32(v);
} }
fn deserialize_i32<D: deserializer>(d: D) -> i32 { fn deserialize_i32<D: Deserializer>(d: D) -> i32 {
d.read_i32() d.read_i32()
} }
fn serialize_i64<S: serializer>(s: S, v: i64) { fn serialize_i64<S: Serializer>(s: S, v: i64) {
s.emit_i64(v); s.emit_i64(v);
} }
fn deserialize_i64<D: deserializer>(d: D) -> i64 { fn deserialize_i64<D: Deserializer>(d: D) -> i64 {
d.read_i64() d.read_i64()
} }
fn serialize_str<S: serializer>(s: S, v: &str) { fn serialize_str<S: Serializer>(s: S, v: &str) {
s.emit_str(v); s.emit_str(v);
} }
fn deserialize_str<D: deserializer>(d: D) -> ~str { fn deserialize_str<D: Deserializer>(d: D) -> ~str {
d.read_str() d.read_str()
} }
fn serialize_float<S: serializer>(s: S, v: float) { fn serialize_float<S: Serializer>(s: S, v: float) {
s.emit_float(v); s.emit_float(v);
} }
fn deserialize_float<D: deserializer>(d: D) -> float { fn deserialize_float<D: Deserializer>(d: D) -> float {
d.read_float() d.read_float()
} }
fn serialize_f32<S: serializer>(s: S, v: f32) { fn serialize_f32<S: Serializer>(s: S, v: f32) {
s.emit_f32(v); s.emit_f32(v);
} }
fn deserialize_f32<D: deserializer>(d: D) -> f32 { fn deserialize_f32<D: Deserializer>(d: D) -> f32 {
d.read_f32() d.read_f32()
} }
fn serialize_f64<S: serializer>(s: S, v: f64) { fn serialize_f64<S: Serializer>(s: S, v: f64) {
s.emit_f64(v); s.emit_f64(v);
} }
fn deserialize_f64<D: deserializer>(d: D) -> f64 { fn deserialize_f64<D: Deserializer>(d: D) -> f64 {
d.read_f64() d.read_f64()
} }
fn serialize_bool<S: serializer>(s: S, v: bool) { fn serialize_bool<S: Serializer>(s: S, v: bool) {
s.emit_bool(v); s.emit_bool(v);
} }
fn deserialize_bool<D: deserializer>(d: D) -> bool { fn deserialize_bool<D: Deserializer>(d: D) -> bool {
d.read_bool() d.read_bool()
} }
fn serialize_Option<S: serializer,T>(s: S, v: Option<T>, st: fn(T)) { fn serialize_Option<S: Serializer,T>(s: S, v: Option<T>, st: fn(T)) {
do s.emit_enum(~"option") { do s.emit_enum(~"option") {
match v { match v {
None => do s.emit_enum_variant(~"none", 0u, 0u) { None => do s.emit_enum_variant(~"none", 0u, 0u) {
@ -256,7 +262,7 @@ fn serialize_Option<S: serializer,T>(s: S, v: Option<T>, st: fn(T)) {
} }
} }
fn deserialize_Option<D: deserializer,T: Copy>(d: D, st: fn() -> T) fn deserialize_Option<D: Deserializer,T: Copy>(d: D, st: fn() -> T)
-> Option<T> { -> Option<T> {
do d.read_enum(~"option") { do d.read_enum(~"option") {
do d.read_enum_variant |i| { do d.read_enum_variant |i| {

View File

@ -91,7 +91,6 @@ mod unicode;
// Compiler support modules // Compiler support modules
mod test; mod test;
#[allow(non_camel_case_types)] // XXX
mod serialization; mod serialization;
// Local Variables: // Local Variables:

View File

@ -1,8 +1,8 @@
// The Rust abstract syntax tree. // The Rust abstract syntax tree.
use codemap::{span, filename}; use codemap::{span, filename};
use std::serialization::{serializer, use std::serialization::{Serializer,
deserializer, Deserializer,
serialize_Option, serialize_Option,
deserialize_Option, deserialize_Option,
serialize_uint, serialize_uint,
@ -38,7 +38,7 @@ macro_rules! interner_key (
(-3 as uint, 0u))) (-3 as uint, 0u)))
) )
fn serialize_ident<S: serializer>(s: S, i: ident) { fn serialize_ident<S: Serializer>(s: S, i: ident) {
let intr = match unsafe{task::local_data_get(interner_key!())}{ let intr = match unsafe{task::local_data_get(interner_key!())}{
None => fail ~"serialization: TLS interner not set up", None => fail ~"serialization: TLS interner not set up",
Some(intr) => intr Some(intr) => intr
@ -46,7 +46,7 @@ fn serialize_ident<S: serializer>(s: S, i: ident) {
s.emit_str(*(*intr).get(i)); s.emit_str(*(*intr).get(i));
} }
fn deserialize_ident<D: deserializer>(d: D) -> ident { fn deserialize_ident<D: Deserializer>(d: D) -> ident {
let intr = match unsafe{task::local_data_get(interner_key!())}{ let intr = match unsafe{task::local_data_get(interner_key!())}{
None => fail ~"deserialization: TLS interner not set up", None => fail ~"deserialization: TLS interner not set up",
Some(intr) => intr Some(intr) => intr

View File

@ -583,7 +583,7 @@ fn mk_ser_fn(cx: ext_ctxt, span: span, name: ast::ident,
ast::bound_trait(cx.ty_path(span, ast::bound_trait(cx.ty_path(span,
~[cx.ident_of(~"std"), ~[cx.ident_of(~"std"),
cx.ident_of(~"serialization"), cx.ident_of(~"serialization"),
cx.ident_of(~"serializer")], cx.ident_of(~"Serializer")],
~[]))]; ~[]))];
let ser_tps: ~[ast::ty_param] = let ser_tps: ~[ast::ty_param] =
@ -789,7 +789,7 @@ fn mk_deser_fn(cx: ext_ctxt, span: span,
ast::bound_trait(cx.ty_path( ast::bound_trait(cx.ty_path(
span, span,
~[cx.ident_of(~"std"), cx.ident_of(~"serialization"), ~[cx.ident_of(~"std"), cx.ident_of(~"serialization"),
cx.ident_of(~"deserializer")], cx.ident_of(~"Deserializer")],
~[]))]; ~[]))];
let deser_tps: ~[ast::ty_param] = let deser_tps: ~[ast::ty_param] =

View File

@ -1,8 +1,8 @@
use util::interner; use util::interner;
use util::interner::interner; use util::interner::interner;
use std::map::{HashMap, str_hash}; use std::map::{HashMap, str_hash};
use std::serialization::{serializer, use std::serialization::{Serializer,
deserializer, Deserializer,
serialize_uint, serialize_uint,
deserialize_uint, deserialize_uint,
serialize_i64, serialize_i64,

View File

@ -16,8 +16,6 @@ use middle::ty::node_id_to_type;
use middle::resolve; use middle::resolve;
use syntax::ast_map; use syntax::ast_map;
use syntax::attr; use syntax::attr;
use std::serialization::serializer;
use std::ebml::serializer;
use str::to_bytes; use str::to_bytes;
use syntax::ast; use syntax::ast;
use syntax::diagnostic::span_handler; use syntax::diagnostic::span_handler;

View File

@ -11,11 +11,11 @@ use std::ebml;
use std::ebml::Writer; use std::ebml::Writer;
use std::ebml::get_doc; use std::ebml::get_doc;
use std::map::HashMap; use std::map::HashMap;
use std::serialization::serializer; use std::serialization::Serializer;
use std::serialization::deserializer; use std::serialization::Deserializer;
use std::serialization::serializer_helpers; use std::serialization::SerializerHelpers;
use std::serialization::deserializer_helpers; use std::serialization::DeserializerHelpers;
use std::prettyprint::serializer; use std::prettyprint::Serializer;
use middle::{ty, typeck}; use middle::{ty, typeck};
use middle::typeck::{method_origin, method_map_entry, use middle::typeck::{method_origin, method_map_entry,
serialize_method_map_entry, serialize_method_map_entry,
@ -189,7 +189,7 @@ trait def_id_serializer_helpers {
fn emit_def_id(did: ast::def_id); fn emit_def_id(did: ast::def_id);
} }
impl<S: serializer> S: def_id_serializer_helpers { impl<S: Serializer> S: def_id_serializer_helpers {
fn emit_def_id(did: ast::def_id) { fn emit_def_id(did: ast::def_id) {
ast::serialize_def_id(self, did) ast::serialize_def_id(self, did)
} }
@ -199,7 +199,7 @@ trait def_id_deserializer_helpers {
fn read_def_id(xcx: extended_decode_ctxt) -> ast::def_id; fn read_def_id(xcx: extended_decode_ctxt) -> ast::def_id;
} }
impl<D: deserializer> D: def_id_deserializer_helpers { impl<D: Deserializer> D: def_id_deserializer_helpers {
fn read_def_id(xcx: extended_decode_ctxt) -> ast::def_id { fn read_def_id(xcx: extended_decode_ctxt) -> ast::def_id {
let did = ast::deserialize_def_id(self); let did = ast::deserialize_def_id(self);