Switch from serialization to std::serialize. (snapshot)

This commit is contained in:
Erick Tryzelaar 2012-12-17 19:31:04 -08:00
parent ec9305802b
commit 8650c6f683
19 changed files with 422 additions and 431 deletions

View file

@ -23,7 +23,7 @@ front/ - front-end: attributes, conditional compilation
middle/ - middle-end: name resolution, typechecking, LLVM code
generation
back/ - back-end: linking and ABI
metadata/ - serializer and deserializer for data required by
metadata/ - encoder and decoder for data required by
separate compilation
driver/ - command-line processing, main() entrypoint
util/ - ubiquitous types and helper functions

View file

@ -25,7 +25,7 @@ use reader = std::ebml::reader;
use std::ebml;
use std::map::HashMap;
use std::map;
use std::serialization::deserialize;
use std::serialize::decode;
use syntax::ast_map;
use syntax::attr;
use syntax::diagnostic::span_handler;
@ -284,7 +284,7 @@ fn item_ty_param_bounds(item: ebml::Doc, tcx: ty::ctxt, cdata: cmd)
fn item_ty_region_param(item: ebml::Doc) -> Option<ty::region_variance> {
reader::maybe_get_doc(item, tag_region_param).map(|doc| {
deserialize(&reader::Deserializer(*doc))
decode(&reader::Decoder(*doc))
})
}

View file

@ -50,7 +50,7 @@ export encode_def_id;
type abbrev_map = map::HashMap<ty::t, tyencode::ty_abbrev>;
type encode_inlined_item = fn@(ecx: @encode_ctxt,
ebml_w: writer::Serializer,
ebml_w: writer::Encoder,
path: ast_map::path,
ii: ast::inlined_item);
@ -96,31 +96,31 @@ fn reachable(ecx: @encode_ctxt, id: node_id) -> bool {
ecx.reachable.contains_key(id)
}
fn encode_name(ecx: @encode_ctxt, ebml_w: writer::Serializer, name: ident) {
fn encode_name(ecx: @encode_ctxt, ebml_w: writer::Encoder, name: ident) {
ebml_w.wr_tagged_str(tag_paths_data_name, ecx.tcx.sess.str_of(name));
}
fn encode_impl_type_basename(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_impl_type_basename(ecx: @encode_ctxt, ebml_w: writer::Encoder,
name: ident) {
ebml_w.wr_tagged_str(tag_item_impl_type_basename,
ecx.tcx.sess.str_of(name));
}
fn encode_def_id(ebml_w: writer::Serializer, id: def_id) {
fn encode_def_id(ebml_w: writer::Encoder, id: def_id) {
ebml_w.wr_tagged_str(tag_def_id, def_to_str(id));
}
fn encode_region_param(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_region_param(ecx: @encode_ctxt, ebml_w: writer::Encoder,
it: @ast::item) {
let opt_rp = ecx.tcx.region_paramd_items.find(it.id);
for opt_rp.each |rp| {
do ebml_w.wr_tag(tag_region_param) {
(*rp).serialize(&ebml_w);
(*rp).encode(&ebml_w);
}
}
}
fn encode_mutability(ebml_w: writer::Serializer, mt: struct_mutability) {
fn encode_mutability(ebml_w: writer::Encoder, mt: struct_mutability) {
do ebml_w.wr_tag(tag_struct_mut) {
let val = match mt {
struct_immutable => 'a',
@ -132,7 +132,7 @@ fn encode_mutability(ebml_w: writer::Serializer, mt: struct_mutability) {
type entry<T> = {val: T, pos: uint};
fn add_to_index(ecx: @encode_ctxt, ebml_w: writer::Serializer, path: &[ident],
fn add_to_index(ecx: @encode_ctxt, ebml_w: writer::Encoder, path: &[ident],
index: &mut ~[entry<~str>], name: ident) {
let mut full_path = ~[];
full_path.push_all(path);
@ -143,7 +143,7 @@ fn add_to_index(ecx: @encode_ctxt, ebml_w: writer::Serializer, path: &[ident],
pos: ebml_w.writer.tell()});
}
fn encode_trait_ref(ebml_w: writer::Serializer, ecx: @encode_ctxt,
fn encode_trait_ref(ebml_w: writer::Encoder, ecx: @encode_ctxt,
t: @trait_ref) {
ebml_w.start_tag(tag_impl_trait);
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, t.ref_id));
@ -152,7 +152,7 @@ fn encode_trait_ref(ebml_w: writer::Serializer, ecx: @encode_ctxt,
// Item info table encoding
fn encode_family(ebml_w: writer::Serializer, c: char) {
fn encode_family(ebml_w: writer::Encoder, c: char) {
ebml_w.start_tag(tag_items_data_item_family);
ebml_w.writer.write(&[c as u8]);
ebml_w.end_tag();
@ -160,7 +160,7 @@ fn encode_family(ebml_w: writer::Serializer, c: char) {
fn def_to_str(did: def_id) -> ~str { fmt!("%d:%d", did.crate, did.node) }
fn encode_ty_type_param_bounds(ebml_w: writer::Serializer, ecx: @encode_ctxt,
fn encode_ty_type_param_bounds(ebml_w: writer::Encoder, ecx: @encode_ctxt,
params: @~[ty::param_bounds]) {
let ty_str_ctxt = @{diag: ecx.diag,
ds: def_to_str,
@ -174,7 +174,7 @@ fn encode_ty_type_param_bounds(ebml_w: writer::Serializer, ecx: @encode_ctxt,
}
}
fn encode_type_param_bounds(ebml_w: writer::Serializer, ecx: @encode_ctxt,
fn encode_type_param_bounds(ebml_w: writer::Encoder, ecx: @encode_ctxt,
params: ~[ty_param]) {
let ty_param_bounds =
@params.map(|param| ecx.tcx.ty_param_bounds.get(param.id));
@ -182,13 +182,13 @@ fn encode_type_param_bounds(ebml_w: writer::Serializer, ecx: @encode_ctxt,
}
fn encode_variant_id(ebml_w: writer::Serializer, vid: def_id) {
fn encode_variant_id(ebml_w: writer::Encoder, vid: def_id) {
ebml_w.start_tag(tag_items_data_item_variant);
ebml_w.writer.write(str::to_bytes(def_to_str(vid)));
ebml_w.end_tag();
}
fn write_type(ecx: @encode_ctxt, ebml_w: writer::Serializer, typ: ty::t) {
fn write_type(ecx: @encode_ctxt, ebml_w: writer::Encoder, typ: ty::t) {
let ty_str_ctxt =
@{diag: ecx.diag,
ds: def_to_str,
@ -198,7 +198,7 @@ fn write_type(ecx: @encode_ctxt, ebml_w: writer::Serializer, typ: ty::t) {
tyencode::enc_ty(ebml_w.writer, ty_str_ctxt, typ);
}
fn write_vstore(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn write_vstore(ecx: @encode_ctxt, ebml_w: writer::Encoder,
vstore: ty::vstore) {
let ty_str_ctxt =
@{diag: ecx.diag,
@ -209,13 +209,13 @@ fn write_vstore(ecx: @encode_ctxt, ebml_w: writer::Serializer,
tyencode::enc_vstore(ebml_w.writer, ty_str_ctxt, vstore);
}
fn encode_type(ecx: @encode_ctxt, ebml_w: writer::Serializer, typ: ty::t) {
fn encode_type(ecx: @encode_ctxt, ebml_w: writer::Encoder, typ: ty::t) {
ebml_w.start_tag(tag_items_data_item_type);
write_type(ecx, ebml_w, typ);
ebml_w.end_tag();
}
fn encode_symbol(ecx: @encode_ctxt, ebml_w: writer::Serializer, id: node_id) {
fn encode_symbol(ecx: @encode_ctxt, ebml_w: writer::Encoder, id: node_id) {
ebml_w.start_tag(tag_items_data_item_symbol);
let sym = match ecx.item_symbols.find(id) {
Some(ref x) => (*x),
@ -228,27 +228,27 @@ fn encode_symbol(ecx: @encode_ctxt, ebml_w: writer::Serializer, id: node_id) {
ebml_w.end_tag();
}
fn encode_discriminant(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_discriminant(ecx: @encode_ctxt, ebml_w: writer::Encoder,
id: node_id) {
ebml_w.start_tag(tag_items_data_item_symbol);
ebml_w.writer.write(str::to_bytes(ecx.discrim_symbols.get(id)));
ebml_w.end_tag();
}
fn encode_disr_val(_ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_disr_val(_ecx: @encode_ctxt, ebml_w: writer::Encoder,
disr_val: int) {
ebml_w.start_tag(tag_disr_val);
ebml_w.writer.write(str::to_bytes(int::to_str(disr_val,10u)));
ebml_w.end_tag();
}
fn encode_parent_item(ebml_w: writer::Serializer, id: def_id) {
fn encode_parent_item(ebml_w: writer::Encoder, id: def_id) {
ebml_w.start_tag(tag_items_data_parent_item);
ebml_w.writer.write(str::to_bytes(def_to_str(id)));
ebml_w.end_tag();
}
fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: writer::Encoder,
id: node_id, variants: ~[variant],
path: ast_map::path, index: @mut ~[entry<int>],
ty_params: ~[ty_param]) {
@ -285,9 +285,9 @@ fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: writer::Serializer,
}
}
fn encode_path(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_path(ecx: @encode_ctxt, ebml_w: writer::Encoder,
path: ast_map::path, name: ast_map::path_elt) {
fn encode_path_elt(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_path_elt(ecx: @encode_ctxt, ebml_w: writer::Encoder,
elt: ast_map::path_elt) {
let (tag, name) = match elt {
ast_map::path_mod(name) => (tag_path_elt_mod, name),
@ -306,7 +306,7 @@ fn encode_path(ecx: @encode_ctxt, ebml_w: writer::Serializer,
}
}
fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: writer::Encoder,
md: _mod, id: node_id, path: ast_map::path,
name: ident) {
ebml_w.start_tag(tag_items_data_item);
@ -365,7 +365,7 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: writer::Serializer,
ebml_w.end_tag();
}
fn encode_visibility(ebml_w: writer::Serializer, visibility: visibility) {
fn encode_visibility(ebml_w: writer::Encoder, visibility: visibility) {
encode_family(ebml_w, match visibility {
public => 'g',
private => 'j',
@ -373,7 +373,7 @@ fn encode_visibility(ebml_w: writer::Serializer, visibility: visibility) {
});
}
fn encode_self_type(ebml_w: writer::Serializer, self_type: ast::self_ty_) {
fn encode_self_type(ebml_w: writer::Encoder, self_type: ast::self_ty_) {
ebml_w.start_tag(tag_item_trait_method_self_ty);
// Encode the base self type.
@ -405,14 +405,14 @@ fn encode_self_type(ebml_w: writer::Serializer, self_type: ast::self_ty_) {
ebml_w.end_tag();
}
fn encode_method_sort(ebml_w: writer::Serializer, sort: char) {
fn encode_method_sort(ebml_w: writer::Encoder, sort: char) {
ebml_w.start_tag(tag_item_trait_method_sort);
ebml_w.writer.write(&[ sort as u8 ]);
ebml_w.end_tag();
}
/* Returns an index of items in this class */
fn encode_info_for_struct(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_info_for_struct(ecx: @encode_ctxt, ebml_w: writer::Encoder,
path: ast_map::path,
fields: ~[@struct_field],
global_index: @mut~[entry<int>]) -> ~[entry<int>] {
@ -447,7 +447,7 @@ fn encode_info_for_struct(ecx: @encode_ctxt, ebml_w: writer::Serializer,
}
// This is for encoding info for ctors and dtors
fn encode_info_for_ctor(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_info_for_ctor(ecx: @encode_ctxt, ebml_w: writer::Encoder,
id: node_id, ident: ident, path: ast_map::path,
item: Option<inlined_item>, tps: ~[ty_param]) {
ebml_w.start_tag(tag_items_data_item);
@ -472,7 +472,7 @@ fn encode_info_for_ctor(ecx: @encode_ctxt, ebml_w: writer::Serializer,
ebml_w.end_tag();
}
fn encode_info_for_method(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_info_for_method(ecx: @encode_ctxt, ebml_w: writer::Encoder,
impl_path: ast_map::path, should_inline: bool,
parent_id: node_id,
m: @method, all_tps: ~[ty_param]) {
@ -527,7 +527,7 @@ fn should_inline(attrs: ~[attribute]) -> bool {
}
fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
item: @item, index: @mut ~[entry<int>],
path: ast_map::path) {
@ -540,7 +540,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Serializer,
};
if !must_write && !reachable(ecx, item.id) { return; }
fn add_to_index_(item: @item, ebml_w: writer::Serializer,
fn add_to_index_(item: @item, ebml_w: writer::Encoder,
index: @mut ~[entry<int>]) {
index.push({val: item.id, pos: ebml_w.writer.tell()});
}
@ -807,7 +807,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Serializer,
}
}
fn encode_info_for_foreign_item(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_info_for_foreign_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
nitem: @foreign_item,
index: @mut ~[entry<int>],
path: ast_map::path, abi: foreign_abi) {
@ -840,7 +840,7 @@ fn encode_info_for_foreign_item(ecx: @encode_ctxt, ebml_w: writer::Serializer,
ebml_w.end_tag();
}
fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: writer::Encoder,
crate: @crate) -> ~[entry<int>] {
let index = @mut ~[];
ebml_w.start_tag(tag_items_data);
@ -895,7 +895,7 @@ fn create_index<T: Copy Hash IterBytes>(index: ~[entry<T>]) ->
return buckets_frozen;
}
fn encode_index<T>(ebml_w: writer::Serializer, buckets: ~[@~[entry<T>]],
fn encode_index<T>(ebml_w: writer::Encoder, buckets: ~[@~[entry<T>]],
write_fn: fn(io::Writer, T)) {
let writer = ebml_w.writer;
ebml_w.start_tag(tag_index);
@ -930,7 +930,7 @@ fn write_int(writer: io::Writer, &&n: int) {
writer.write_be_u32(n as u32);
}
fn encode_meta_item(ebml_w: writer::Serializer, mi: meta_item) {
fn encode_meta_item(ebml_w: writer::Encoder, mi: meta_item) {
match mi.node {
meta_word(ref name) => {
ebml_w.start_tag(tag_meta_item_word);
@ -967,7 +967,7 @@ fn encode_meta_item(ebml_w: writer::Serializer, mi: meta_item) {
}
}
fn encode_attributes(ebml_w: writer::Serializer, attrs: ~[attribute]) {
fn encode_attributes(ebml_w: writer::Encoder, attrs: ~[attribute]) {
ebml_w.start_tag(tag_attributes);
for attrs.each |attr| {
ebml_w.start_tag(tag_attribute);
@ -1028,7 +1028,7 @@ fn synthesize_crate_attrs(ecx: @encode_ctxt, crate: @crate) -> ~[attribute] {
return attrs;
}
fn encode_crate_deps(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_crate_deps(ecx: @encode_ctxt, ebml_w: writer::Encoder,
cstore: cstore::CStore) {
fn get_ordered_deps(ecx: @encode_ctxt, cstore: cstore::CStore)
@ -1074,7 +1074,7 @@ fn encode_crate_deps(ecx: @encode_ctxt, ebml_w: writer::Serializer,
ebml_w.end_tag();
}
fn encode_crate_dep(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_crate_dep(ecx: @encode_ctxt, ebml_w: writer::Encoder,
dep: decoder::crate_dep) {
ebml_w.start_tag(tag_crate_dep);
ebml_w.start_tag(tag_crate_dep_name);
@ -1089,7 +1089,7 @@ fn encode_crate_dep(ecx: @encode_ctxt, ebml_w: writer::Serializer,
ebml_w.end_tag();
}
fn encode_hash(ebml_w: writer::Serializer, hash: ~str) {
fn encode_hash(ebml_w: writer::Encoder, hash: ~str) {
ebml_w.start_tag(tag_crate_hash);
ebml_w.writer.write(str::to_bytes(hash));
ebml_w.end_tag();
@ -1127,7 +1127,7 @@ fn encode_metadata(parms: encode_parms, crate: @crate) -> ~[u8] {
type_abbrevs: ty::new_ty_hash()
});
let ebml_w = writer::Serializer(wr as io::Writer);
let ebml_w = writer::Encoder(wr as io::Writer);
encode_hash(ebml_w, ecx.link_meta.extras_hash);

View file

@ -24,12 +24,11 @@ use util::ppaux::ty_to_str;
use reader = std::ebml::reader;
use std::ebml::reader::get_doc;
use std::ebml::writer::Serializer;
use std::ebml::writer::Encoder;
use std::ebml;
use std::map::HashMap;
use std::serialization::{DeserializerHelpers, deserialize};
use std::serialization::{Serializable, SerializerHelpers};
use std::serialization;
use std::serialize;
use std::serialize::{Encodable, EncoderHelpers, DecoderHelpers, decode};
use syntax::ast;
use syntax::ast_map;
use syntax::ast_util;
@ -84,7 +83,7 @@ trait tr_intern {
// Top-level methods.
fn encode_inlined_item(ecx: @e::encode_ctxt,
ebml_w: writer::Serializer,
ebml_w: writer::Encoder,
path: ast_map::path,
ii: ast::inlined_item,
maps: maps) {
@ -95,7 +94,7 @@ fn encode_inlined_item(ecx: @e::encode_ctxt,
let id_range = ast_util::compute_id_range_for_inlined_item(ii);
do ebml_w.wr_tag(c::tag_ast as uint) {
id_range.serialize(&ebml_w);
id_range.encode(&ebml_w);
encode_ast(ebml_w, simplify_ast(ii));
encode_side_tables_for_ii(ecx, maps, ebml_w, ii);
}
@ -117,8 +116,8 @@ fn decode_inlined_item(cdata: cstore::crate_metadata,
Some(ast_doc) => {
debug!("> Decoding inlined fn: %s::?",
ast_map::path_to_str(path, tcx.sess.parse_sess.interner));
let ast_dsr = &reader::Deserializer(ast_doc);
let from_id_range = deserialize(ast_dsr);
let ast_dsr = &reader::Decoder(ast_doc);
let from_id_range = decode(ast_dsr);
let to_id_range = reserve_id_range(dcx.tcx.sess, from_id_range);
let xcx = extended_decode_ctxt_(@{dcx: dcx,
from_id_range: from_id_range,
@ -194,24 +193,24 @@ impl span: tr {
}
}
trait def_id_serializer_helpers {
trait def_id_encoder_helpers {
fn emit_def_id(did: ast::def_id);
}
impl<S: serialization::Serializer> S: def_id_serializer_helpers {
impl<S: serialize::Encoder> S: def_id_encoder_helpers {
fn emit_def_id(did: ast::def_id) {
did.serialize(&self)
did.encode(&self)
}
}
trait def_id_deserializer_helpers {
trait def_id_decoder_helpers {
fn read_def_id(xcx: extended_decode_ctxt) -> ast::def_id;
}
impl<D: serialization::Deserializer> D: def_id_deserializer_helpers {
impl<D: serialize::Decoder> D: def_id_decoder_helpers {
fn read_def_id(xcx: extended_decode_ctxt) -> ast::def_id {
let did: ast::def_id = deserialize(&self);
let did: ast::def_id = decode(&self);
did.tr(xcx)
}
}
@ -231,9 +230,9 @@ impl<D: serialization::Deserializer> D: def_id_deserializer_helpers {
// We also have to adjust the spans: for now we just insert a dummy span,
// but eventually we should add entries to the local codemap as required.
fn encode_ast(ebml_w: writer::Serializer, item: ast::inlined_item) {
fn encode_ast(ebml_w: writer::Encoder, item: ast::inlined_item) {
do ebml_w.wr_tag(c::tag_tree as uint) {
item.serialize(&ebml_w)
item.encode(&ebml_w)
}
}
@ -287,8 +286,8 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
fn decode_ast(par_doc: ebml::Doc) -> ast::inlined_item {
let chi_doc = par_doc[c::tag_tree as uint];
let d = &reader::Deserializer(chi_doc);
deserialize(d)
let d = &reader::Decoder(chi_doc);
decode(d)
}
fn renumber_ast(xcx: extended_decode_ctxt, ii: ast::inlined_item)
@ -327,13 +326,13 @@ fn renumber_ast(xcx: extended_decode_ctxt, ii: ast::inlined_item)
// ______________________________________________________________________
// Encoding and decoding of ast::def
fn encode_def(ebml_w: writer::Serializer, def: ast::def) {
def.serialize(&ebml_w)
fn encode_def(ebml_w: writer::Encoder, def: ast::def) {
def.encode(&ebml_w)
}
fn decode_def(xcx: extended_decode_ctxt, doc: ebml::Doc) -> ast::def {
let dsr = &reader::Deserializer(doc);
let def: ast::def = deserialize(dsr);
let dsr = &reader::Decoder(doc);
let def: ast::def = decode(dsr);
def.tr(xcx)
}
@ -421,17 +420,17 @@ impl ty::bound_region: tr {
// ______________________________________________________________________
// Encoding and decoding of freevar information
fn encode_freevar_entry(ebml_w: writer::Serializer, fv: @freevar_entry) {
(*fv).serialize(&ebml_w)
fn encode_freevar_entry(ebml_w: writer::Encoder, fv: @freevar_entry) {
(*fv).encode(&ebml_w)
}
trait ebml_deserializer_helper {
trait ebml_decoder_helper {
fn read_freevar_entry(xcx: extended_decode_ctxt) -> freevar_entry;
}
impl reader::Deserializer: ebml_deserializer_helper {
impl reader::Decoder: ebml_decoder_helper {
fn read_freevar_entry(xcx: extended_decode_ctxt) -> freevar_entry {
let fv: freevar_entry = deserialize(&self);
let fv: freevar_entry = decode(&self);
fv.tr(xcx)
}
}
@ -449,23 +448,23 @@ trait read_method_map_entry_helper {
fn read_method_map_entry(xcx: extended_decode_ctxt) -> method_map_entry;
}
fn serialize_method_map_entry(ecx: @e::encode_ctxt,
ebml_w: writer::Serializer,
fn encode_method_map_entry(ecx: @e::encode_ctxt,
ebml_w: writer::Encoder,
mme: method_map_entry) {
do ebml_w.emit_rec {
do ebml_w.emit_field(~"self_arg", 0u) {
ebml_w.emit_arg(ecx, mme.self_arg);
}
do ebml_w.emit_field(~"explicit_self", 2u) {
mme.explicit_self.serialize(&ebml_w);
mme.explicit_self.encode(&ebml_w);
}
do ebml_w.emit_field(~"origin", 1u) {
mme.origin.serialize(&ebml_w);
mme.origin.encode(&ebml_w);
}
}
}
impl reader::Deserializer: read_method_map_entry_helper {
impl reader::Decoder: read_method_map_entry_helper {
fn read_method_map_entry(xcx: extended_decode_ctxt) -> method_map_entry {
do self.read_rec {
{self_arg:
@ -474,12 +473,12 @@ impl reader::Deserializer: read_method_map_entry_helper {
}),
explicit_self:
self.read_field(~"explicit_self", 2u, || {
let self_type: ast::self_ty_ = deserialize(&self);
let self_type: ast::self_ty_ = decode(&self);
self_type
}),
origin:
self.read_field(~"origin", 1u, || {
let method_origin: method_origin = deserialize(&self);
let method_origin: method_origin = decode(&self);
method_origin.tr(xcx)
})}
}
@ -509,11 +508,11 @@ impl method_origin: tr {
// Encoding and decoding vtable_res
fn encode_vtable_res(ecx: @e::encode_ctxt,
ebml_w: writer::Serializer,
ebml_w: writer::Encoder,
dr: typeck::vtable_res) {
// can't autogenerate this code because automatic serialization of
// can't autogenerate this code because automatic code of
// ty::t doesn't work, and there is no way (atm) to have
// hand-written serialization routines combine with auto-generated
// hand-written encoding routines combine with auto-generated
// ones. perhaps we should fix this.
do ebml_w.emit_from_vec(*dr) |vtable_origin| {
encode_vtable_origin(ecx, ebml_w, *vtable_origin)
@ -521,7 +520,7 @@ fn encode_vtable_res(ecx: @e::encode_ctxt,
}
fn encode_vtable_origin(ecx: @e::encode_ctxt,
ebml_w: writer::Serializer,
ebml_w: writer::Encoder,
vtable_origin: typeck::vtable_origin) {
do ebml_w.emit_enum(~"vtable_origin") {
match vtable_origin {
@ -563,12 +562,12 @@ fn encode_vtable_origin(ecx: @e::encode_ctxt,
}
trait vtable_deserialization_helpers {
trait vtable_decoder_helpers {
fn read_vtable_res(xcx: extended_decode_ctxt) -> typeck::vtable_res;
fn read_vtable_origin(xcx: extended_decode_ctxt) -> typeck::vtable_origin;
}
impl reader::Deserializer: vtable_deserialization_helpers {
impl reader::Decoder: vtable_decoder_helpers {
fn read_vtable_res(xcx: extended_decode_ctxt) -> typeck::vtable_res {
@self.read_to_vec(|| self.read_vtable_origin(xcx) )
}
@ -645,7 +644,7 @@ trait ebml_writer_helpers {
fn emit_tpbt(ecx: @e::encode_ctxt, tpbt: ty::ty_param_bounds_and_ty);
}
impl writer::Serializer: ebml_writer_helpers {
impl writer::Encoder: ebml_writer_helpers {
fn emit_ty(ecx: @e::encode_ctxt, ty: ty::t) {
do self.emit_opaque {
e::write_type(ecx, self, ty)
@ -684,7 +683,7 @@ impl writer::Serializer: ebml_writer_helpers {
}
}
do self.emit_field(~"region_param", 1u) {
tpbt.region_param.serialize(&self);
tpbt.region_param.encode(&self);
}
do self.emit_field(~"ty", 2u) {
self.emit_ty(ecx, tpbt.ty);
@ -698,7 +697,7 @@ trait write_tag_and_id {
fn id(id: ast::node_id);
}
impl writer::Serializer: write_tag_and_id {
impl writer::Encoder: write_tag_and_id {
fn tag(tag_id: c::astencode_tag, f: fn()) {
do self.wr_tag(tag_id as uint) { f() }
}
@ -710,7 +709,7 @@ impl writer::Serializer: write_tag_and_id {
fn encode_side_tables_for_ii(ecx: @e::encode_ctxt,
maps: maps,
ebml_w: writer::Serializer,
ebml_w: writer::Encoder,
ii: ast::inlined_item) {
do ebml_w.wr_tag(c::tag_table as uint) {
ast_util::visit_ids_for_inlined_item(
@ -726,7 +725,7 @@ fn encode_side_tables_for_ii(ecx: @e::encode_ctxt,
fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
maps: maps,
ebml_w: writer::Serializer,
ebml_w: writer::Encoder,
id: ast::node_id) {
let tcx = ecx.tcx;
@ -736,7 +735,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
do ebml_w.tag(c::tag_table_def) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
(*def).serialize(&ebml_w)
(*def).encode(&ebml_w)
}
}
}
@ -813,7 +812,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
do ebml_w.emit_from_vec((*m).get()) |id| {
id.serialize(&ebml_w);
id.encode(&ebml_w);
}
}
}
@ -823,7 +822,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
do ebml_w.tag(c::tag_table_method_map) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
serialize_method_map_entry(ecx, ebml_w, *mme)
encode_method_map_entry(ecx, ebml_w, *mme)
}
}
}
@ -841,7 +840,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
do ebml_w.tag(c::tag_table_adjustments) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
(**adj).serialize(&ebml_w)
(**adj).encode(&ebml_w)
}
}
}
@ -856,7 +855,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
do ebml_w.tag(c::tag_table_value_mode) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
(*vm).serialize(&ebml_w)
(*vm).encode(&ebml_w)
}
}
}
@ -874,7 +873,7 @@ impl ebml::Doc: doc_decoder_helpers {
}
}
trait ebml_deserializer_decoder_helpers {
trait ebml_decoder_decoder_helpers {
fn read_arg(xcx: extended_decode_ctxt) -> ty::arg;
fn read_ty(xcx: extended_decode_ctxt) -> ty::t;
fn read_tys(xcx: extended_decode_ctxt) -> ~[ty::t];
@ -883,7 +882,7 @@ trait ebml_deserializer_decoder_helpers {
-> ty::ty_param_bounds_and_ty;
}
impl reader::Deserializer: ebml_deserializer_decoder_helpers {
impl reader::Decoder: ebml_decoder_decoder_helpers {
fn read_arg(xcx: extended_decode_ctxt) -> ty::arg {
do self.read_opaque |doc| {
@ -927,7 +926,7 @@ impl reader::Deserializer: ebml_deserializer_decoder_helpers {
@self.read_to_vec(|| self.read_bounds(xcx) )
}),
region_param: self.read_field(~"region_param", 1u, || {
deserialize(&self)
decode(&self)
}),
ty: self.read_field(~"ty", 2u, || {
self.read_ty(xcx)
@ -955,7 +954,7 @@ fn decode_side_tables(xcx: extended_decode_ctxt,
dcx.tcx.legacy_boxed_traits.insert(id, ());
} else {
let val_doc = entry_doc[c::tag_table_val as uint];
let val_dsr = &reader::Deserializer(val_doc);
let val_dsr = &reader::Decoder(val_doc);
if tag == (c::tag_table_def as uint) {
let def = decode_def(xcx, val_doc);
dcx.tcx.def_map.insert(id, def);
@ -991,11 +990,11 @@ fn decode_side_tables(xcx: extended_decode_ctxt,
dcx.maps.vtable_map.insert(id,
val_dsr.read_vtable_res(xcx));
} else if tag == (c::tag_table_adjustments as uint) {
let adj: @ty::AutoAdjustment = @deserialize(val_dsr);
let adj: @ty::AutoAdjustment = @decode(val_dsr);
adj.tr(xcx);
dcx.tcx.adjustments.insert(id, adj);
} else if tag == (c::tag_table_value_mode as uint) {
let vm: ty::ValueMode = deserialize(val_dsr);
let vm: ty::ValueMode = decode(val_dsr);
dcx.tcx.value_modes.insert(id, vm);
} else {
xcx.dcx.tcx.sess.bug(
@ -1011,17 +1010,17 @@ fn decode_side_tables(xcx: extended_decode_ctxt,
// Testing of astencode_gen
#[cfg(test)]
fn encode_item_ast(ebml_w: writer::Serializer, item: @ast::item) {
fn encode_item_ast(ebml_w: writer::Encoder, item: @ast::item) {
do ebml_w.wr_tag(c::tag_tree as uint) {
(*item).serialize(&ebml_w)
(*item).encode(&ebml_w)
}
}
#[cfg(test)]
fn decode_item_ast(par_doc: ebml::Doc) -> @ast::item {
let chi_doc = par_doc[c::tag_tree as uint];
let d = &reader::Deserializer(chi_doc);
@deserialize(d)
let d = &reader::Decoder(chi_doc);
@decode(d)
}
#[cfg(test)]
@ -1060,17 +1059,17 @@ fn mk_ctxt() -> fake_ext_ctxt {
fn roundtrip(in_item: Option<@ast::item>) {
let in_item = in_item.get();
let bytes = do io::with_bytes_writer |wr| {
let ebml_w = writer::Serializer(wr);
let ebml_w = writer::Encoder(wr);
encode_item_ast(ebml_w, in_item);
};
let ebml_doc = reader::Doc(@bytes);
let out_item = decode_item_ast(ebml_doc);
let exp_str = do io::with_str_writer |w| {
in_item.serialize(&std::prettyprint::Serializer(w))
in_item.encode(&std::prettyprint::Encoder(w))
};
let out_str = do io::with_str_writer |w| {
out_item.serialize(&std::prettyprint::Serializer(w))
out_item.encode(&std::prettyprint::Encoder(w))
};
debug!("expected string: %s", exp_str);

View file

@ -26,8 +26,8 @@ export has_freevars;
// A vector of defs representing the free variables referred to in a function.
// (The def_upvar will already have been stripped).
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type freevar_entry = {
def: ast::def, //< The variable being accessed free.
span: span //< First span where it is accessed (there can be multiple)

View file

@ -106,7 +106,7 @@ export ty_estr, mk_estr, type_is_str;
export ty_evec, mk_evec, type_is_vec;
export ty_unboxed_vec, mk_unboxed_vec, mk_mut_unboxed_vec;
export vstore, vstore_fixed, vstore_uniq, vstore_box, vstore_slice;
export serialize_vstore, deserialize_vstore;
export encode_vstore, decode_vstore;
export ty_nil, mk_nil, type_is_nil;
export ty_trait, mk_trait;
export ty_param, mk_param, ty_params_to_tys;
@ -238,8 +238,8 @@ type method = {ident: ast::ident,
type mt = {ty: t, mutbl: ast::mutability};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum vstore {
vstore_fixed(uint),
vstore_uniq,
@ -255,8 +255,8 @@ type field_ty = {
};
/// How an lvalue is to be used.
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
pub enum ValueMode {
ReadValue, // Non-destructively read the value; do not copy or move.
CopyValue, // Copy the value.
@ -307,8 +307,8 @@ enum ast_ty_to_ty_cache_entry {
type opt_region_variance = Option<region_variance>;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum region_variance { rv_covariant, rv_invariant, rv_contravariant }
impl region_variance : cmp::Eq {
@ -325,23 +325,23 @@ impl region_variance : cmp::Eq {
pure fn ne(&self, other: &region_variance) -> bool { !(*self).eq(other) }
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
pub type AutoAdjustment = {
autoderefs: uint,
autoref: Option<AutoRef>
};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
pub type AutoRef = {
kind: AutoRefKind,
region: Region,
mutbl: ast::mutability
};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum AutoRefKind {
/// Convert from T to &T
AutoPtr,
@ -544,8 +544,8 @@ impl param_ty : to_bytes::IterBytes {
/// Representation of regions:
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum Region {
/// Bound regions are found (primarily) in function types. They indicate
/// region parameters that have yet to be replaced with actual regions
@ -573,8 +573,8 @@ enum Region {
re_infer(InferRegion)
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum bound_region {
/// The self region for structs, impls (&T in a type defn or &self/T)
br_self,
@ -712,8 +712,8 @@ enum TyVid = uint;
enum IntVid = uint;
enum FloatVid = uint;
enum FnVid = uint;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum RegionVid = uint;
enum InferTy {
@ -732,8 +732,8 @@ impl InferTy : to_bytes::IterBytes {
}
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum InferRegion {
ReVar(RegionVid),
ReSkolemized(uint, bound_region)

View file

@ -111,8 +111,8 @@ pub mod collect;
#[legacy_exports]
pub mod coherence;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
pub enum method_origin {
// fully statically resolved method
method_static(ast::def_id),
@ -129,8 +129,8 @@ pub enum method_origin {
// details for a method invoked with a receiver whose type is a type parameter
// with a bounded trait.
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type method_param = {
// the trait containing the method to be invoked
trait_id: ast::def_id,

View file

@ -9,7 +9,7 @@
// except according to those terms.
#[forbid(deprecated_mode)];
use serialization;
use serialize;
// Simple Extensible Binary Markup Language (ebml) reader and writer on a
// cursor model. See the specification here:
@ -38,7 +38,7 @@ struct TaggedDoc {
doc: Doc,
}
enum EbmlSerializerTag {
enum EbmlEncoderTag {
EsUint, EsU64, EsU32, EsU16, EsU8,
EsInt, EsI64, EsI32, EsI16, EsI8,
EsBool,
@ -189,16 +189,16 @@ pub mod reader {
pub fn doc_as_i64(d: Doc) -> i64 { doc_as_u64(d) as i64 }
pub struct Deserializer {
pub struct Decoder {
priv mut parent: Doc,
priv mut pos: uint,
}
pub fn Deserializer(d: Doc) -> Deserializer {
Deserializer { mut parent: d, mut pos: d.start }
pub fn Decoder(d: Doc) -> Decoder {
Decoder { mut parent: d, mut pos: d.start }
}
priv impl Deserializer {
priv impl Decoder {
fn _check_label(lbl: &str) {
if self.pos < self.parent.end {
let TaggedDoc { tag: r_tag, doc: r_doc } =
@ -214,7 +214,7 @@ pub mod reader {
}
}
fn next_doc(exp_tag: EbmlSerializerTag) -> Doc {
fn next_doc(exp_tag: EbmlEncoderTag) -> Doc {
debug!(". next_doc(exp_tag=%?)", exp_tag);
if self.pos >= self.parent.end {
fail ~"no more documents in current node!";
@ -247,14 +247,14 @@ pub mod reader {
move r
}
fn _next_uint(exp_tag: EbmlSerializerTag) -> uint {
fn _next_uint(exp_tag: EbmlEncoderTag) -> uint {
let r = doc_as_u32(self.next_doc(exp_tag));
debug!("_next_uint exp_tag=%? result=%?", exp_tag, r);
r as uint
}
}
impl Deserializer {
impl Decoder {
fn read_opaque<R>(&self, op: fn(Doc) -> R) -> R {
do self.push_doc(self.next_doc(EsOpaque)) {
op(copy self.parent)
@ -262,7 +262,7 @@ pub mod reader {
}
}
impl Deserializer: serialization::Deserializer {
impl Decoder: serialize::Decoder {
fn read_nil(&self) -> () { () }
fn read_u64(&self) -> u64 { doc_as_u64(self.next_doc(EsU64)) }
@ -387,7 +387,7 @@ pub mod reader {
pub mod writer {
// ebml writing
pub struct Serializer {
pub struct Encoder {
writer: io::Writer,
priv mut size_positions: ~[uint],
}
@ -412,13 +412,13 @@ pub mod writer {
fail fmt!("vint to write too big: %?", n);
}
pub fn Serializer(w: io::Writer) -> Serializer {
pub fn Encoder(w: io::Writer) -> Encoder {
let size_positions: ~[uint] = ~[];
Serializer { writer: w, mut size_positions: size_positions }
Encoder { writer: w, mut size_positions: size_positions }
}
// FIXME (#2741): Provide a function to write the standard ebml header.
impl Serializer {
impl Encoder {
fn start_tag(tag_id: uint) {
debug!("Start tag %u", tag_id);
@ -516,13 +516,13 @@ pub mod writer {
// FIXME (#2743): optionally perform "relaxations" on end_tag to more
// efficiently encode sizes; this is a fixed point iteration
// Set to true to generate more debugging in EBML serialization.
// Set to true to generate more debugging in EBML code.
// Totally lame approach.
const debug: bool = false;
priv impl Serializer {
priv impl Encoder {
// used internally to emit things like the vector length and so on
fn _emit_tagged_uint(t: EbmlSerializerTag, v: uint) {
fn _emit_tagged_uint(t: EbmlEncoderTag, v: uint) {
assert v <= 0xFFFF_FFFF_u;
self.wr_tagged_u32(t as uint, v as u32);
}
@ -530,15 +530,15 @@ pub mod writer {
fn _emit_label(label: &str) {
// There are various strings that we have access to, such as
// the name of a record field, which do not actually appear in
// the serialized EBML (normally). This is just for
// the encoded EBML (normally). This is just for
// efficiency. When debugging, though, we can emit such
// labels and then they will be checked by deserializer to
// labels and then they will be checked by decoder to
// try and check failures more quickly.
if debug { self.wr_tagged_str(EsLabel as uint, label) }
}
}
impl Serializer {
impl Encoder {
fn emit_opaque(&self, f: fn()) {
do self.wr_tag(EsOpaque as uint) {
f()
@ -546,7 +546,7 @@ pub mod writer {
}
}
impl Serializer: serialization::Serializer {
impl Encoder: serialize::Encoder {
fn emit_nil(&self) {}
fn emit_uint(&self, v: uint) {
@ -652,12 +652,12 @@ mod tests {
fn test_v(v: Option<int>) {
debug!("v == %?", v);
let bytes = do io::with_bytes_writer |wr| {
let ebml_w = writer::Serializer(wr);
v.serialize(&ebml_w)
let ebml_w = writer::Encoder(wr);
v.encode(&ebml_w)
};
let ebml_doc = reader::Doc(@bytes);
let deser = reader::Deserializer(ebml_doc);
let v1 = serialization::deserialize(&deser);
let deser = reader::Decoder(ebml_doc);
let v1 = serialize::decode(&deser);
debug!("v1 == %?", v1);
assert v == v1;
}

View file

@ -65,15 +65,15 @@ fn spaces(n: uint) -> ~str {
return ss;
}
pub struct Serializer {
pub struct Encoder {
priv wr: io::Writer,
}
pub fn Serializer(wr: io::Writer) -> Serializer {
Serializer { wr: wr }
pub fn Encoder(wr: io::Writer) -> Encoder {
Encoder { wr: wr }
}
pub impl Serializer: serialization::Serializer {
pub impl Encoder: serialize::Encoder {
fn emit_nil(&self) { self.wr.write_str("null") }
fn emit_uint(&self, v: uint) { self.emit_float(v as float); }
@ -168,16 +168,16 @@ pub impl Serializer: serialization::Serializer {
}
}
pub struct PrettySerializer {
pub struct PrettyEncoder {
priv wr: io::Writer,
priv mut indent: uint,
}
pub fn PrettySerializer(wr: io::Writer) -> PrettySerializer {
PrettySerializer { wr: wr, indent: 0 }
pub fn PrettyEncoder(wr: io::Writer) -> PrettyEncoder {
PrettyEncoder { wr: wr, indent: 0 }
}
pub impl PrettySerializer: serialization::Serializer {
pub impl PrettyEncoder: serialize::Encoder {
fn emit_nil(&self) { self.wr.write_str("null") }
fn emit_uint(&self, v: uint) { self.emit_float(v as float); }
@ -283,21 +283,19 @@ pub impl PrettySerializer: serialization::Serializer {
}
}
pub impl<
S: serialization::Serializer
> Json: serialization::Serializable<S> {
fn serialize(&self, s: &S) {
pub impl<S: serialize::Encoder> Json: serialize::Encodable<S> {
fn encode(&self, s: &S) {
match *self {
Number(v) => v.serialize(s),
String(ref v) => v.serialize(s),
Boolean(v) => v.serialize(s),
List(ref v) => v.serialize(s),
Number(v) => v.encode(s),
String(ref v) => v.encode(s),
Boolean(v) => v.encode(s),
List(ref v) => v.encode(s),
Object(ref v) => {
do s.emit_rec || {
let mut idx = 0;
for v.each |key, value| {
do s.emit_field(*key, idx) {
value.serialize(s);
value.encode(s);
}
idx += 1;
}
@ -308,23 +306,23 @@ pub impl<
}
}
/// Serializes a json value into a io::writer
/// Encodes a json value into a io::writer
pub fn to_writer(wr: io::Writer, json: &Json) {
json.serialize(&Serializer(wr))
json.encode(&Encoder(wr))
}
/// Serializes a json value into a string
/// Encodes a json value into a string
pub pure fn to_str(json: &Json) -> ~str unsafe {
// ugh, should be safe
io::with_str_writer(|wr| to_writer(wr, json))
}
/// Serializes a json value into a io::writer
/// Encodes a json value into a io::writer
pub fn to_pretty_writer(wr: io::Writer, json: &Json) {
json.serialize(&PrettySerializer(wr))
json.encode(&PrettyEncoder(wr))
}
/// Serializes a json value into a string
/// Encodes a json value into a string
pub fn to_pretty_str(json: &Json) -> ~str {
io::with_str_writer(|wr| to_pretty_writer(wr, json))
}
@ -336,7 +334,7 @@ pub struct Parser {
priv mut col: uint,
}
/// Deserializes a json value from an io::reader
/// Decode a json value from an io::reader
pub fn Parser(rdr: io::Reader) -> Parser {
Parser {
rdr: rdr,
@ -695,28 +693,28 @@ priv impl Parser {
}
}
/// Deserializes a json value from an io::reader
/// Decodes a json value from an io::reader
pub fn from_reader(rdr: io::Reader) -> Result<Json, Error> {
Parser(rdr).parse()
}
/// Deserializes a json value from a string
/// Decodes a json value from a string
pub fn from_str(s: &str) -> Result<Json, Error> {
do io::with_str_reader(s) |rdr| {
from_reader(rdr)
}
}
pub struct Deserializer {
pub struct Decoder {
priv json: Json,
priv mut stack: ~[&Json],
}
pub fn Deserializer(json: Json) -> Deserializer {
Deserializer { json: move json, stack: ~[] }
pub fn Decoder(json: Json) -> Decoder {
Decoder { json: move json, stack: ~[] }
}
priv impl Deserializer {
priv impl Decoder {
fn peek(&self) -> &self/Json {
if self.stack.len() == 0 { self.stack.push(&self.json); }
vec::last(self.stack)
@ -728,7 +726,7 @@ priv impl Deserializer {
}
}
pub impl Deserializer: serialization::Deserializer {
pub impl Decoder: serialize::Decoder {
fn read_nil(&self) -> () {
debug!("read_nil");
match *self.pop() {

View file

@ -12,17 +12,17 @@
use io::Writer;
use io::WriterUtil;
use serialization;
use serialize;
pub struct Serializer {
pub struct Encoder {
wr: io::Writer,
}
pub fn Serializer(wr: io::Writer) -> Serializer {
Serializer { wr: wr }
pub fn Encoder(wr: io::Writer) -> Encoder {
Encoder { wr: wr }
}
pub impl Serializer: serialization::Serializer {
pub impl Encoder: serialize::Encoder {
fn emit_nil(&self) {
self.wr.write_str(~"()")
}

View file

@ -107,14 +107,16 @@ mod unicode;
pub mod test;
pub mod serialize;
#[cfg(stage0)]
pub mod serialization;
// A curious inner-module that's not exported that contains the binding
// 'std' so that macro-expanded references to std::code and such
// 'std' so that macro-expanded references to std::serialize and such
// can be resolved within libcore.
#[doc(hidden)] // FIXME #3538
mod std {
pub use serialize;
#[cfg(stage0)]
pub use serialization;
}

View file

@ -31,8 +31,8 @@ extern mod rustrt {
}
/// A record specifying a time value in seconds and nanoseconds.
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
pub struct Timespec { sec: i64, nsec: i32 }
impl Timespec {
@ -83,8 +83,8 @@ pub fn tzset() {
rustrt::rust_tzset();
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
pub struct Tm {
tm_sec: i32, // seconds after the minute ~[0-60]
tm_min: i32, // minutes after the hour ~[0-59]

View file

@ -15,8 +15,7 @@ use either::{Right,Left,Either};
use json;
use sha1;
use serialization::{Serializer,Serializable,
Deserializer,Deserializable};
use serialize::{Encoder, Encodable, Decoder, Decodable, decode};
/**
*
@ -162,13 +161,13 @@ struct Work<T:Owned> {
res: Option<Either<T,PortOne<(Exec,T)>>>
}
fn digest<T:Serializable<json::Serializer>
Deserializable<json::Deserializer>>(t: &T) -> ~str {
fn digest<T:Encodable<json::Encoder>
Decodable<json::Decoder>>(t: &T) -> ~str {
let sha = sha1::sha1();
let s = do io::with_str_writer |wr| {
// XXX: sha1 should be a writer itself, shouldn't
// go via strings.
t.serialize(&json::Serializer(wr));
t.encode(&json::Encoder(wr));
};
sha.input_str(s);
sha.result_str()
@ -189,8 +188,8 @@ impl Context {
}
fn prep<T:Owned
Serializable<json::Serializer>
Deserializable<json::Deserializer>>(
Encodable<json::Encoder>
Decodable<json::Decoder>>(
@self,
fn_name:&str,
blk: fn((@mut Prep))->Work<T>) -> Work<T> {
@ -237,8 +236,8 @@ impl Prep {
}
fn exec<T:Owned
Serializable<json::Serializer>
Deserializable<json::Deserializer>>(
Encodable<json::Encoder>
Decodable<json::Decoder>>(
@mut self, blk: ~fn(&Exec) -> T) -> Work<T> {
let cached = self.ctxt.db.prepare(self.fn_name,
@ -260,8 +259,7 @@ impl Prep {
let v : T = do io::with_str_reader(res) |rdr| {
let j = result::unwrap(json::from_reader(rdr));
Deserializable::deserialize(
&json::Deserializer(move j))
Decodable::decode(&json::Decoder(move j))
};
return Work::new(self, move Left(move v));
}
@ -284,8 +282,8 @@ impl Prep {
}
impl<T:Owned
Serializable<json::Serializer>
Deserializable<json::Deserializer>>
Encodable<json::Encoder>
Decodable<json::Decoder>>
Work<T> {
static fn new(p: @mut Prep, e: Either<T,PortOne<(Exec,T)>>) -> Work<T> {
move Work { prep: p, res: Some(move e) }
@ -294,8 +292,8 @@ impl<T:Owned
// FIXME (#3724): movable self. This should be in impl Work.
fn unwrap<T:Owned
Serializable<json::Serializer>
Deserializable<json::Deserializer>>(w: Work<T>) -> T {
Encodable<json::Encoder>
Decodable<json::Decoder>>(w: Work<T>) -> T {
let mut ww = move w;
let mut s = None;
@ -312,7 +310,7 @@ fn unwrap<T:Owned
};
let s = do io::with_str_writer |wr| {
v.serialize(&json::Serializer(wr));
v.encode(&json::Encoder(wr));
};
ww.prep.ctxt.db.cache(ww.prep.fn_name,

View file

@ -10,15 +10,12 @@
// The Rust abstract syntax tree.
use std::serialization::{Serializable,
Deserializable,
Serializer,
Deserializer};
use std::serialize::{Encodable, Decodable, Encoder, Decoder};
use codemap::{span, FileName};
use parse::token;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type spanned<T> = {node: T, span: span};
@ -33,12 +30,12 @@ macro_rules! interner_key (
// implemented.
struct ident { repr: uint }
impl<S: Serializer> ident: Serializable<S> {
fn serialize(&self, s: &S) {
impl<S: Encoder> ident: Encodable<S> {
fn encode(&self, s: &S) {
let intr = match unsafe {
task::local_data::local_data_get(interner_key!())
} {
None => fail ~"serialization: TLS interner not set up",
None => fail ~"encode: TLS interner not set up",
Some(intr) => intr
};
@ -46,12 +43,12 @@ impl<S: Serializer> ident: Serializable<S> {
}
}
impl<D: Deserializer> ident: Deserializable<D> {
static fn deserialize(d: &D) -> ident {
impl<D: Decoder> ident: Decodable<D> {
static fn decode(d: &D) -> ident {
let intr = match unsafe {
task::local_data::local_data_get(interner_key!())
} {
None => fail ~"deserialization: TLS interner not set up",
None => fail ~"decode: TLS interner not set up",
Some(intr) => intr
};
@ -73,8 +70,8 @@ impl ident: to_bytes::IterBytes {
// Functions may or may not have names.
type fn_ident = Option<ident>;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type path = {span: span,
global: bool,
idents: ~[ident],
@ -85,8 +82,8 @@ type crate_num = int;
type node_id = int;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type def_id = {crate: crate_num, node: node_id};
impl def_id : cmp::Eq {
@ -99,20 +96,20 @@ impl def_id : cmp::Eq {
const local_crate: crate_num = 0;
const crate_node_id: node_id = 0;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
// The AST represents all type param bounds as types.
// typeck::collect::compute_bounds matches these against
// the "special" built-in traits (see middle::lang_items) and
// detects Copy, Send, Owned, and Const.
enum ty_param_bound = @Ty;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type ty_param = {ident: ident, id: node_id, bounds: @~[ty_param_bound]};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum def {
def_fn(def_id, purity),
def_static_method(/* method */ def_id,
@ -284,8 +281,8 @@ type crate_ =
type meta_item = spanned<meta_item_>;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum meta_item_ {
meta_word(~str),
meta_list(~str, ~[@meta_item]),
@ -294,24 +291,24 @@ enum meta_item_ {
type blk = spanned<blk_>;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type blk_ = {view_items: ~[@view_item],
stmts: ~[@stmt],
expr: Option<@expr>,
id: node_id,
rules: blk_check_mode};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type pat = {id: node_id, node: pat_, span: span};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type field_pat = {ident: ident, pat: @pat};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum binding_mode {
bind_by_value,
bind_by_move,
@ -367,8 +364,8 @@ impl binding_mode : cmp::Eq {
pure fn ne(&self, other: &binding_mode) -> bool { !(*self).eq(other) }
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum pat_ {
pat_wild,
// A pat_ident may either be a new bound variable,
@ -392,8 +389,8 @@ enum pat_ {
pat_vec(~[@pat], Option<@pat>)
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum mutability { m_mutbl, m_imm, m_const, }
impl mutability : to_bytes::IterBytes {
@ -409,8 +406,8 @@ impl mutability : cmp::Eq {
pure fn ne(&self, other: &mutability) -> bool { !(*self).eq(other) }
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
pub enum Proto {
ProtoBare, // bare functions (deprecated)
ProtoUniq, // ~fn
@ -431,8 +428,8 @@ impl Proto : to_bytes::IterBytes {
}
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum vstore {
// FIXME (#3469): Change uint to @expr (actually only constant exprs)
vstore_fixed(Option<uint>), // [1,2,3,4]
@ -441,8 +438,8 @@ enum vstore {
vstore_slice(@region) // &[1,2,3,4](foo)?
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum expr_vstore {
// FIXME (#3469): Change uint to @expr (actually only constant exprs)
expr_vstore_fixed(Option<uint>), // [1,2,3,4]
@ -460,8 +457,8 @@ pure fn is_blockish(p: ast::Proto) -> bool {
}
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum binop {
add,
subtract,
@ -490,8 +487,8 @@ impl binop : cmp::Eq {
pure fn ne(&self, other: &binop) -> bool { !(*self).eq(other) }
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum unop {
box(mutability),
uniq(mutability),
@ -542,8 +539,8 @@ impl unop : cmp::Eq {
// Generally, after typeck you can get the inferred value
// using ty::resolved_T(...).
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum inferable<T> {
expl(T),
infer(node_id)
@ -582,8 +579,8 @@ impl<T:cmp::Eq> inferable<T> : cmp::Eq {
}
// "resolved" mode: the real modes.
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum rmode { by_ref, by_val, by_move, by_copy }
impl rmode : to_bytes::IterBytes {
@ -605,8 +602,8 @@ type mode = inferable<rmode>;
type stmt = spanned<stmt_>;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum stmt_ {
stmt_decl(@decl, node_id),
@ -622,8 +619,8 @@ enum stmt_ {
// FIXME (pending discussion of #1697, #2178...): local should really be
// a refinement on pat.
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type local_ = {is_mutbl: bool, ty: @Ty, pat: @pat,
init: Option<@expr>, id: node_id};
@ -631,22 +628,22 @@ type local = spanned<local_>;
type decl = spanned<decl_>;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum decl_ { decl_local(~[@local]), decl_item(@item), }
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type arm = {pats: ~[@pat], guard: Option<@expr>, body: blk};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type field_ = {mutbl: mutability, ident: ident, expr: @expr};
type field = spanned<field_>;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum blk_check_mode { default_blk, unsafe_blk, }
impl blk_check_mode : cmp::Eq {
@ -661,18 +658,18 @@ impl blk_check_mode : cmp::Eq {
pure fn ne(&self, other: &blk_check_mode) -> bool { !(*self).eq(other) }
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type expr = {id: node_id, callee_id: node_id, node: expr_, span: span};
// Extra node ID is only used for index, assign_op, unary, binary, method call
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum log_level { error, debug, log_other }
// 0 = error, 1 = debug, 2 = log_other
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum expr_ {
expr_vstore(@expr, expr_vstore),
expr_vec(~[@expr], mutability),
@ -731,8 +728,8 @@ enum expr_ {
expr_paren(@expr)
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type capture_item_ = {
id: int,
is_move: bool,
@ -760,8 +757,8 @@ type capture_clause = @~[capture_item];
// else knows what to do with them, so you'll probably get a syntax
// error.
//
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
#[doc="For macro invocations; parsing is delegated to the macro"]
enum token_tree {
tt_tok(span, token::Token),
@ -825,8 +822,8 @@ enum token_tree {
//
type matcher = spanned<matcher_>;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum matcher_ {
// match one token
match_tok(token::Token),
@ -839,16 +836,16 @@ enum matcher_ {
type mac = spanned<mac_>;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum mac_ {
mac_invoc_tt(@path,~[token_tree]), // new macro-invocation
}
type lit = spanned<lit_>;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum lit_ {
lit_str(@~str),
lit_int(i64, int_ty),
@ -892,24 +889,24 @@ impl ast::lit_: cmp::Eq {
// NB: If you change this, you'll probably want to change the corresponding
// type structure in middle/ty.rs as well.
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type mt = {ty: @Ty, mutbl: mutability};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type ty_field_ = {ident: ident, mt: mt};
type ty_field = spanned<ty_field_>;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type ty_method = {ident: ident, attrs: ~[attribute], purity: purity,
decl: fn_decl, tps: ~[ty_param], self_ty: self_ty,
id: node_id, span: span};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
// A trait method is either required (meaning it doesn't have an
// implementation, just a signature) or provided (meaning it has a default
// implementation).
@ -918,8 +915,8 @@ enum trait_method {
provided(@method),
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum int_ty { ty_i, ty_char, ty_i8, ty_i16, ty_i32, ty_i64, }
impl int_ty : to_bytes::IterBytes {
@ -948,8 +945,8 @@ impl int_ty : cmp::Eq {
pure fn ne(&self, other: &int_ty) -> bool { !(*self).eq(other) }
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum uint_ty { ty_u, ty_u8, ty_u16, ty_u32, ty_u64, }
impl uint_ty : to_bytes::IterBytes {
@ -976,8 +973,8 @@ impl uint_ty : cmp::Eq {
pure fn ne(&self, other: &uint_ty) -> bool { !(*self).eq(other) }
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum float_ty { ty_f, ty_f32, ty_f64, }
impl float_ty : to_bytes::IterBytes {
@ -996,13 +993,13 @@ impl float_ty : cmp::Eq {
pure fn ne(&self, other: &float_ty) -> bool { !(*self).eq(other) }
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type Ty = {id: node_id, node: ty_, span: span};
// Not represented directly in the AST, referred to by name through a ty_path.
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum prim_ty {
ty_int(int_ty),
ty_uint(uint_ty),
@ -1049,12 +1046,12 @@ impl prim_ty : cmp::Eq {
pure fn ne(&self, other: &prim_ty) -> bool { !(*self).eq(other) }
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type region = {id: node_id, node: region_};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum region_ {
re_anon,
re_static,
@ -1062,8 +1059,8 @@ enum region_ {
re_named(ident)
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum Onceness {
Once,
Many
@ -1081,8 +1078,8 @@ impl Onceness : cmp::Eq {
}
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
struct TyFn {
proto: Proto,
region: Option<@region>,
@ -1092,8 +1089,8 @@ struct TyFn {
decl: fn_decl
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum ty_ {
ty_nil,
ty_bot, /* bottom type */
@ -1132,19 +1129,19 @@ impl Ty : to_bytes::IterBytes {
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type arg = {mode: mode, ty: @Ty, pat: @pat, id: node_id};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type fn_decl =
{inputs: ~[arg],
output: @Ty,
cf: ret_style};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum purity {
pure_fn, // declared with "pure fn"
unsafe_fn, // declared with "unsafe fn"
@ -1165,8 +1162,8 @@ impl purity : cmp::Eq {
pure fn ne(&self, other: &purity) -> bool { !(*self).eq(other) }
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum ret_style {
noreturn, // functions with return type _|_ that always
// raise an error or exit (i.e. never return to the caller)
@ -1191,8 +1188,8 @@ impl ret_style : cmp::Eq {
pure fn ne(&self, other: &ret_style) -> bool { !(*self).eq(other) }
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum self_ty_ {
sty_static, // no self: static method
sty_by_ref, // old by-reference self: ``
@ -1248,20 +1245,20 @@ impl self_ty_ : cmp::Eq {
type self_ty = spanned<self_ty_>;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type method = {ident: ident, attrs: ~[attribute],
tps: ~[ty_param], self_ty: self_ty,
purity: purity, decl: fn_decl, body: blk,
id: node_id, span: span, self_id: node_id,
vis: visibility};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type _mod = {view_items: ~[@view_item], items: ~[@item]};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum foreign_abi {
foreign_abi_rust_intrinsic,
foreign_abi_cdecl,
@ -1269,8 +1266,8 @@ enum foreign_abi {
}
// Foreign mods can be named or anonymous
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum foreign_mod_sort { named, anonymous }
impl foreign_mod_sort : cmp::Eq {
@ -1294,49 +1291,49 @@ impl foreign_abi : cmp::Eq {
pure fn ne(&self, other: &foreign_abi) -> bool { !(*self).eq(other) }
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type foreign_mod =
{sort: foreign_mod_sort,
abi: ident,
view_items: ~[@view_item],
items: ~[@foreign_item]};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type variant_arg = {ty: @Ty, id: node_id};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum variant_kind {
tuple_variant_kind(~[variant_arg]),
struct_variant_kind(@struct_def),
enum_variant_kind(enum_def)
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type enum_def_ = { variants: ~[variant], common: Option<@struct_def> };
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum enum_def = enum_def_;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type variant_ = {name: ident, attrs: ~[attribute], kind: variant_kind,
id: node_id, disr_expr: Option<@expr>, vis: visibility};
type variant = spanned<variant_>;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type path_list_ident_ = {name: ident, id: node_id};
type path_list_ident = spanned<path_list_ident_>;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum namespace { module_ns, type_value_ns }
impl namespace : cmp::Eq {
@ -1348,8 +1345,8 @@ impl namespace : cmp::Eq {
type view_path = spanned<view_path_>;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum view_path_ {
// quux = foo::bar::baz
@ -1366,13 +1363,13 @@ enum view_path_ {
view_path_list(@path, ~[path_list_ident], node_id)
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type view_item = {node: view_item_, attrs: ~[attribute],
vis: visibility, span: span};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum view_item_ {
view_item_use(ident, ~[@meta_item], node_id),
view_item_import(~[@view_path]),
@ -1385,8 +1382,8 @@ type attribute = spanned<attribute_>;
// Distinguishes between attributes that decorate items and attributes that
// are contained as statements within items. These two cases need to be
// distinguished for pretty-printing.
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum attr_style { attr_outer, attr_inner, }
impl attr_style : cmp::Eq {
@ -1397,8 +1394,8 @@ impl attr_style : cmp::Eq {
}
// doc-comments are promoted to attributes that have is_sugared_doc = true
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type attribute_ = {style: attr_style, value: meta_item, is_sugared_doc: bool};
/*
@ -1408,12 +1405,12 @@ type attribute_ = {style: attr_style, value: meta_item, is_sugared_doc: bool};
If this impl is an item_impl, the impl_id is redundant (it could be the
same as the impl's node id).
*/
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type trait_ref = {path: @path, ref_id: node_id};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum visibility { public, private, inherited }
impl visibility : cmp::Eq {
@ -1430,8 +1427,8 @@ impl visibility : cmp::Eq {
pure fn ne(&self, other: &visibility) -> bool { !(*self).eq(other) }
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type struct_field_ = {
kind: struct_field_kind,
id: node_id,
@ -1440,8 +1437,8 @@ type struct_field_ = {
type struct_field = spanned<struct_field_>;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum struct_field_kind {
named_field(ident, struct_mutability, visibility),
unnamed_field // element of a tuple-like struct
@ -1474,8 +1471,8 @@ impl struct_field_kind : cmp::Eq {
}
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type struct_def = {
fields: ~[@struct_field], /* fields */
/* (not including ctor or dtor) */
@ -1490,14 +1487,14 @@ type struct_def = {
FIXME (#3300): Should allow items to be anonymous. Right now
we just use dummy names for anon items.
*/
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type item = {ident: ident, attrs: ~[attribute],
id: node_id, node: item_,
vis: visibility, span: span};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum item_ {
item_const(@Ty, @expr),
item_fn(fn_decl, purity, ~[ty_param], blk),
@ -1514,8 +1511,8 @@ enum item_ {
item_mac(mac),
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum struct_mutability { struct_mutable, struct_immutable }
impl struct_mutability : to_bytes::IterBytes {
@ -1540,15 +1537,15 @@ impl struct_mutability : cmp::Eq {
type struct_dtor = spanned<struct_dtor_>;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type struct_dtor_ = {id: node_id,
attrs: ~[attribute],
self_id: node_id,
body: blk};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type foreign_item =
{ident: ident,
attrs: ~[attribute],
@ -1557,8 +1554,8 @@ type foreign_item =
span: span,
vis: visibility};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum foreign_item_ {
foreign_item_fn(fn_decl, purity, ~[ty_param]),
foreign_item_const(@Ty)
@ -1567,8 +1564,8 @@ enum foreign_item_ {
// The data we save and restore about an inlined item or method. This is not
// part of the AST that we parse from a file, but it becomes part of the tree
// that we trans.
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum inlined_item {
ii_item(@item),
ii_method(def_id /* impl id */, @method),

View file

@ -417,8 +417,8 @@ fn dtor_dec() -> fn_decl {
// ______________________________________________________________________
// Enumerating the IDs which appear in an AST
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type id_range = {min: node_id, max: node_id};
fn empty(range: id_range) -> bool {

View file

@ -22,10 +22,7 @@ source code snippets, etc.
*/
use dvec::DVec;
use std::serialization::{Serializable,
Deserializable,
Serializer,
Deserializer};
use std::serialize::{Encodable, Decodable, Encoder, Decoder};
trait Pos {
static pure fn from_uint(n: uint) -> self;
@ -131,13 +128,13 @@ impl span : cmp::Eq {
pure fn ne(&self, other: &span) -> bool { !(*self).eq(other) }
}
impl<S: Serializer> span: Serializable<S> {
/* Note #1972 -- spans are serialized but not deserialized */
fn serialize(&self, _s: &S) { }
impl<S: Encoder> span: Encodable<S> {
/* Note #1972 -- spans are encoded but not decoded */
fn encode(&self, _s: &S) { }
}
impl<D: Deserializer> span: Deserializable<D> {
static fn deserialize(_d: &D) -> span {
impl<D: Decoder> span: Decodable<D> {
static fn decode(_d: &D) -> span {
ast_util::dummy_sp()
}
}

View file

@ -77,7 +77,7 @@ fn expand_expr(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
}
// This is a secondary mechanism for invoking syntax extensions on items:
// "decorator" attributes, such as #[auto_serialize]. These are invoked by an
// "decorator" attributes, such as #[auto_encode]. These are invoked by an
// attribute prefixing an item, and are interpreted by feeding the item
// through the named attribute _as a syntax extension_ and splicing in the
// resulting item vec into place in favour of the decorator. Note that

View file

@ -12,8 +12,8 @@ use util::interner;
use util::interner::Interner;
use std::map::HashMap;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum binop {
PLUS,
MINUS,
@ -27,8 +27,8 @@ enum binop {
SHR,
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum Token {
/* Expression-operator symbols. */
EQ,
@ -85,8 +85,8 @@ enum Token {
EOF,
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
/// For interpolation during macro expansion.
enum nonterminal {
nt_item(@ast::item),
@ -351,7 +351,7 @@ impl ident_interner {
}
/* Key for thread-local data for sneaking interner information to the
* serializer/deserializer. It sounds like a hack because it is one.
* encoder/decoder. It sounds like a hack because it is one.
* Bonus ultra-hack: functions as keys don't work across crates,
* so we have to use a unique number. See taskgroup_key! in task.rs
* for another case of this. */

View file

@ -22,16 +22,16 @@ use std::ebml;
use EBReader = std::ebml::reader;
use EBWriter = std::ebml::writer;
use io::Writer;
use std::serialization::{Serializable, Deserializable, deserialize};
use std::serialize::{Encodable, Decodable, decode};
use std::prettyprint;
use std::time;
fn test_prettyprint<A: Serializable<prettyprint::Serializer>>(
fn test_prettyprint<A: Encodable<prettyprint::Encoder>>(
a: &A,
expected: &~str
) {
let s = do io::with_str_writer |w| {
a.serialize(&prettyprint::Serializer(w))
a.encode(&prettyprint::Encoder(w))
};
debug!("s == %?", s);
assert s == *expected;
@ -39,20 +39,20 @@ fn test_prettyprint<A: Serializable<prettyprint::Serializer>>(
fn test_ebml<A:
Eq
Serializable<EBWriter::Serializer>
Deserializable<EBReader::Deserializer>
Encodable<EBWriter::Encoder>
Decodable<EBReader::Decoder>
>(a1: &A) {
let bytes = do io::with_bytes_writer |wr| {
let ebml_w = &EBWriter::Serializer(wr);
a1.serialize(ebml_w)
let ebml_w = &EBWriter::Encoder(wr);
a1.encode(ebml_w)
};
let d = EBReader::Doc(@move bytes);
let a2: A = deserialize(&EBReader::Deserializer(d));
let a2: A = decode(&EBReader::Decoder(d));
assert *a1 == a2;
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum Expr {
Val(uint),
Plus(@Expr, @Expr),
@ -126,8 +126,8 @@ impl CLike : cmp::Eq {
pure fn ne(&self, other: &CLike) -> bool { !(*self).eq(other) }
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type Spanned<T> = {lo: uint, hi: uint, node: T};
impl<T:cmp::Eq> Spanned<T> : cmp::Eq {
@ -139,27 +139,27 @@ impl<T:cmp::Eq> Spanned<T> : cmp::Eq {
pure fn ne(&self, other: &Spanned<T>) -> bool { !(*self).eq(other) }
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
type SomeRec = {v: ~[uint]};
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum AnEnum = SomeRec;
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
struct Point {x: uint, y: uint}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum Quark<T> {
Top(T),
Bottom(T)
}
#[auto_serialize]
#[auto_deserialize]
#[auto_encode]
#[auto_decode]
enum CLike { A, B, C }
fn main() {