From 1a8a0a77b14c44d98501cd9fb0f14ed88d4c38d9 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 10 Sep 2012 19:02:41 -0700 Subject: [PATCH] Camel case std::serialization --- src/libstd/ebml.rs | 4 +- src/libstd/prettyprint.rs | 4 +- src/libstd/serialization.rs | 88 +++++++++++++++-------------- src/libstd/std.rc | 1 - src/libsyntax/ast.rs | 8 +-- src/libsyntax/ext/auto_serialize.rs | 4 +- src/libsyntax/parse/token.rs | 4 +- src/rustc/metadata/encoder.rs | 2 - src/rustc/middle/astencode.rs | 14 ++--- 9 files changed, 66 insertions(+), 63 deletions(-) diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index 193a2a6370b..4b634677583 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -340,7 +340,7 @@ impl ebml::Writer: SerializerPriv { } } -impl ebml::Writer: serialization::serializer { +impl ebml::Writer: serialization::Serializer { fn emit_nil() {} 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_u64() -> u64 { ebml::doc_as_u64(self.next_doc(EsU64)) } diff --git a/src/libstd/prettyprint.rs b/src/libstd/prettyprint.rs index 2976927a78f..fa4c41dfa13 100644 --- a/src/libstd/prettyprint.rs +++ b/src/libstd/prettyprint.rs @@ -3,9 +3,9 @@ use io::Writer; use io::WriterUtil; -use serialization::serializer; +use serialization::Serializer; -impl Writer: serializer { +impl Writer: Serializer { fn emit_nil() { self.write_str(~"()") } diff --git a/src/libstd/serialization.rs b/src/libstd/serialization.rs index 743e2fc2bf1..64254d5b2e5 100644 --- a/src/libstd/serialization.rs +++ b/src/libstd/serialization.rs @@ -1,12 +1,18 @@ //! 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. */ -trait serializer { +trait Serializer { // Primitive types: fn emit_nil(); fn emit_uint(v: uint); @@ -39,7 +45,7 @@ trait serializer { fn emit_tup_elt(idx: uint, f: fn()); } -trait deserializer { +trait Deserializer { // Primitive types: fn read_nil() -> (); @@ -83,7 +89,7 @@ trait deserializer { // // In some cases, these should eventually be coded as traits. -fn emit_from_vec(s: S, v: ~[T], f: fn(T)) { +fn emit_from_vec(s: S, v: ~[T], f: fn(T)) { do s.emit_vec(vec::len(v)) { do vec::iteri(v) |i,e| { do s.emit_vec_elt(i) { @@ -93,7 +99,7 @@ fn emit_from_vec(s: S, v: ~[T], f: fn(T)) { } } -fn read_to_vec(d: D, f: fn() -> T) -> ~[T] { +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()) @@ -101,147 +107,147 @@ fn read_to_vec(d: D, f: fn() -> T) -> ~[T] { } } -trait serializer_helpers { +trait SerializerHelpers { fn emit_from_vec(v: ~[T], f: fn(T)); } -impl S: serializer_helpers { +impl S: SerializerHelpers { fn emit_from_vec(v: ~[T], f: fn(T)) { emit_from_vec(self, v, f) } } -trait deserializer_helpers { +trait DeserializerHelpers { fn read_to_vec(f: fn() -> T) -> ~[T]; } -impl D: deserializer_helpers { +impl D: DeserializerHelpers { fn read_to_vec(f: fn() -> T) -> ~[T] { read_to_vec(self, f) } } -fn serialize_uint(s: S, v: uint) { +fn serialize_uint(s: S, v: uint) { s.emit_uint(v); } -fn deserialize_uint(d: D) -> uint { +fn deserialize_uint(d: D) -> uint { d.read_uint() } -fn serialize_u8(s: S, v: u8) { +fn serialize_u8(s: S, v: u8) { s.emit_u8(v); } -fn deserialize_u8(d: D) -> u8 { +fn deserialize_u8(d: D) -> u8 { d.read_u8() } -fn serialize_u16(s: S, v: u16) { +fn serialize_u16(s: S, v: u16) { s.emit_u16(v); } -fn deserialize_u16(d: D) -> u16 { +fn deserialize_u16(d: D) -> u16 { d.read_u16() } -fn serialize_u32(s: S, v: u32) { +fn serialize_u32(s: S, v: u32) { s.emit_u32(v); } -fn deserialize_u32(d: D) -> u32 { +fn deserialize_u32(d: D) -> u32 { d.read_u32() } -fn serialize_u64(s: S, v: u64) { +fn serialize_u64(s: S, v: u64) { s.emit_u64(v); } -fn deserialize_u64(d: D) -> u64 { +fn deserialize_u64(d: D) -> u64 { d.read_u64() } -fn serialize_int(s: S, v: int) { +fn serialize_int(s: S, v: int) { s.emit_int(v); } -fn deserialize_int(d: D) -> int { +fn deserialize_int(d: D) -> int { d.read_int() } -fn serialize_i8(s: S, v: i8) { +fn serialize_i8(s: S, v: i8) { s.emit_i8(v); } -fn deserialize_i8(d: D) -> i8 { +fn deserialize_i8(d: D) -> i8 { d.read_i8() } -fn serialize_i16(s: S, v: i16) { +fn serialize_i16(s: S, v: i16) { s.emit_i16(v); } -fn deserialize_i16(d: D) -> i16 { +fn deserialize_i16(d: D) -> i16 { d.read_i16() } -fn serialize_i32(s: S, v: i32) { +fn serialize_i32(s: S, v: i32) { s.emit_i32(v); } -fn deserialize_i32(d: D) -> i32 { +fn deserialize_i32(d: D) -> i32 { d.read_i32() } -fn serialize_i64(s: S, v: i64) { +fn serialize_i64(s: S, v: i64) { s.emit_i64(v); } -fn deserialize_i64(d: D) -> i64 { +fn deserialize_i64(d: D) -> i64 { d.read_i64() } -fn serialize_str(s: S, v: &str) { +fn serialize_str(s: S, v: &str) { s.emit_str(v); } -fn deserialize_str(d: D) -> ~str { +fn deserialize_str(d: D) -> ~str { d.read_str() } -fn serialize_float(s: S, v: float) { +fn serialize_float(s: S, v: float) { s.emit_float(v); } -fn deserialize_float(d: D) -> float { +fn deserialize_float(d: D) -> float { d.read_float() } -fn serialize_f32(s: S, v: f32) { +fn serialize_f32(s: S, v: f32) { s.emit_f32(v); } -fn deserialize_f32(d: D) -> f32 { +fn deserialize_f32(d: D) -> f32 { d.read_f32() } -fn serialize_f64(s: S, v: f64) { +fn serialize_f64(s: S, v: f64) { s.emit_f64(v); } -fn deserialize_f64(d: D) -> f64 { +fn deserialize_f64(d: D) -> f64 { d.read_f64() } -fn serialize_bool(s: S, v: bool) { +fn serialize_bool(s: S, v: bool) { s.emit_bool(v); } -fn deserialize_bool(d: D) -> bool { +fn deserialize_bool(d: D) -> bool { d.read_bool() } -fn serialize_Option(s: S, v: Option, st: fn(T)) { +fn serialize_Option(s: S, v: Option, st: fn(T)) { do s.emit_enum(~"option") { match v { None => do s.emit_enum_variant(~"none", 0u, 0u) { @@ -256,7 +262,7 @@ fn serialize_Option(s: S, v: Option, st: fn(T)) { } } -fn deserialize_Option(d: D, st: fn() -> T) +fn deserialize_Option(d: D, st: fn() -> T) -> Option { do d.read_enum(~"option") { do d.read_enum_variant |i| { diff --git a/src/libstd/std.rc b/src/libstd/std.rc index 5381c1564a5..3442725cbdb 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -91,7 +91,6 @@ mod unicode; // Compiler support modules mod test; -#[allow(non_camel_case_types)] // XXX mod serialization; // Local Variables: diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 364576aae33..3d3fd5bfd11 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1,8 +1,8 @@ // The Rust abstract syntax tree. use codemap::{span, filename}; -use std::serialization::{serializer, - deserializer, +use std::serialization::{Serializer, + Deserializer, serialize_Option, deserialize_Option, serialize_uint, @@ -38,7 +38,7 @@ macro_rules! interner_key ( (-3 as uint, 0u))) ) -fn serialize_ident(s: S, i: ident) { +fn serialize_ident(s: S, i: ident) { let intr = match unsafe{task::local_data_get(interner_key!())}{ None => fail ~"serialization: TLS interner not set up", Some(intr) => intr @@ -46,7 +46,7 @@ fn serialize_ident(s: S, i: ident) { s.emit_str(*(*intr).get(i)); } -fn deserialize_ident(d: D) -> ident { +fn deserialize_ident(d: D) -> ident { let intr = match unsafe{task::local_data_get(interner_key!())}{ None => fail ~"deserialization: TLS interner not set up", Some(intr) => intr diff --git a/src/libsyntax/ext/auto_serialize.rs b/src/libsyntax/ext/auto_serialize.rs index 1dc8cee6ac9..1bb207adfc2 100644 --- a/src/libsyntax/ext/auto_serialize.rs +++ b/src/libsyntax/ext/auto_serialize.rs @@ -583,7 +583,7 @@ fn mk_ser_fn(cx: ext_ctxt, span: span, name: ast::ident, ast::bound_trait(cx.ty_path(span, ~[cx.ident_of(~"std"), cx.ident_of(~"serialization"), - cx.ident_of(~"serializer")], + cx.ident_of(~"Serializer")], ~[]))]; 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( span, ~[cx.ident_of(~"std"), cx.ident_of(~"serialization"), - cx.ident_of(~"deserializer")], + cx.ident_of(~"Deserializer")], ~[]))]; let deser_tps: ~[ast::ty_param] = diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 6f756c946a4..5f1bdf2ff3e 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -1,8 +1,8 @@ use util::interner; use util::interner::interner; use std::map::{HashMap, str_hash}; -use std::serialization::{serializer, - deserializer, +use std::serialization::{Serializer, + Deserializer, serialize_uint, deserialize_uint, serialize_i64, diff --git a/src/rustc/metadata/encoder.rs b/src/rustc/metadata/encoder.rs index 313723fc158..2bbfdfbe0e5 100644 --- a/src/rustc/metadata/encoder.rs +++ b/src/rustc/metadata/encoder.rs @@ -16,8 +16,6 @@ use middle::ty::node_id_to_type; use middle::resolve; use syntax::ast_map; use syntax::attr; -use std::serialization::serializer; -use std::ebml::serializer; use str::to_bytes; use syntax::ast; use syntax::diagnostic::span_handler; diff --git a/src/rustc/middle/astencode.rs b/src/rustc/middle/astencode.rs index d4891dc677e..85e4a5f2e18 100644 --- a/src/rustc/middle/astencode.rs +++ b/src/rustc/middle/astencode.rs @@ -11,11 +11,11 @@ use std::ebml; use std::ebml::Writer; use std::ebml::get_doc; use std::map::HashMap; -use std::serialization::serializer; -use std::serialization::deserializer; -use std::serialization::serializer_helpers; -use std::serialization::deserializer_helpers; -use std::prettyprint::serializer; +use std::serialization::Serializer; +use std::serialization::Deserializer; +use std::serialization::SerializerHelpers; +use std::serialization::DeserializerHelpers; +use std::prettyprint::Serializer; use middle::{ty, typeck}; use middle::typeck::{method_origin, method_map_entry, serialize_method_map_entry, @@ -189,7 +189,7 @@ trait def_id_serializer_helpers { fn emit_def_id(did: ast::def_id); } -impl S: def_id_serializer_helpers { +impl S: def_id_serializer_helpers { fn emit_def_id(did: ast::def_id) { 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; } -impl D: def_id_deserializer_helpers { +impl D: def_id_deserializer_helpers { fn read_def_id(xcx: extended_decode_ctxt) -> ast::def_id { let did = ast::deserialize_def_id(self);