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 middle/ - middle-end: name resolution, typechecking, LLVM code
generation generation
back/ - back-end: linking and ABI back/ - back-end: linking and ABI
metadata/ - serializer and deserializer for data required by metadata/ - encoder and decoder for data required by
separate compilation separate compilation
driver/ - command-line processing, main() entrypoint driver/ - command-line processing, main() entrypoint
util/ - ubiquitous types and helper functions util/ - ubiquitous types and helper functions

View file

@ -25,7 +25,7 @@ use reader = std::ebml::reader;
use std::ebml; use std::ebml;
use std::map::HashMap; use std::map::HashMap;
use std::map; use std::map;
use std::serialization::deserialize; use std::serialize::decode;
use syntax::ast_map; use syntax::ast_map;
use syntax::attr; use syntax::attr;
use syntax::diagnostic::span_handler; 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> { fn item_ty_region_param(item: ebml::Doc) -> Option<ty::region_variance> {
reader::maybe_get_doc(item, tag_region_param).map(|doc| { 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 abbrev_map = map::HashMap<ty::t, tyencode::ty_abbrev>;
type encode_inlined_item = fn@(ecx: @encode_ctxt, type encode_inlined_item = fn@(ecx: @encode_ctxt,
ebml_w: writer::Serializer, ebml_w: writer::Encoder,
path: ast_map::path, path: ast_map::path,
ii: ast::inlined_item); ii: ast::inlined_item);
@ -96,31 +96,31 @@ fn reachable(ecx: @encode_ctxt, id: node_id) -> bool {
ecx.reachable.contains_key(id) 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)); 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) { name: ident) {
ebml_w.wr_tagged_str(tag_item_impl_type_basename, ebml_w.wr_tagged_str(tag_item_impl_type_basename,
ecx.tcx.sess.str_of(name)); 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)); 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) { it: @ast::item) {
let opt_rp = ecx.tcx.region_paramd_items.find(it.id); let opt_rp = ecx.tcx.region_paramd_items.find(it.id);
for opt_rp.each |rp| { for opt_rp.each |rp| {
do ebml_w.wr_tag(tag_region_param) { 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) { do ebml_w.wr_tag(tag_struct_mut) {
let val = match mt { let val = match mt {
struct_immutable => 'a', struct_immutable => 'a',
@ -132,7 +132,7 @@ fn encode_mutability(ebml_w: writer::Serializer, mt: struct_mutability) {
type entry<T> = {val: T, pos: uint}; 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) { index: &mut ~[entry<~str>], name: ident) {
let mut full_path = ~[]; let mut full_path = ~[];
full_path.push_all(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()}); 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) { t: @trait_ref) {
ebml_w.start_tag(tag_impl_trait); ebml_w.start_tag(tag_impl_trait);
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, t.ref_id)); 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 // 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.start_tag(tag_items_data_item_family);
ebml_w.writer.write(&[c as u8]); ebml_w.writer.write(&[c as u8]);
ebml_w.end_tag(); 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 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]) { params: @~[ty::param_bounds]) {
let ty_str_ctxt = @{diag: ecx.diag, let ty_str_ctxt = @{diag: ecx.diag,
ds: def_to_str, 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]) { params: ~[ty_param]) {
let ty_param_bounds = let ty_param_bounds =
@params.map(|param| ecx.tcx.ty_param_bounds.get(param.id)); @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.start_tag(tag_items_data_item_variant);
ebml_w.writer.write(str::to_bytes(def_to_str(vid))); ebml_w.writer.write(str::to_bytes(def_to_str(vid)));
ebml_w.end_tag(); 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 = let ty_str_ctxt =
@{diag: ecx.diag, @{diag: ecx.diag,
ds: def_to_str, 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); 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) { vstore: ty::vstore) {
let ty_str_ctxt = let ty_str_ctxt =
@{diag: ecx.diag, @{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); 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); ebml_w.start_tag(tag_items_data_item_type);
write_type(ecx, ebml_w, typ); write_type(ecx, ebml_w, typ);
ebml_w.end_tag(); 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); ebml_w.start_tag(tag_items_data_item_symbol);
let sym = match ecx.item_symbols.find(id) { let sym = match ecx.item_symbols.find(id) {
Some(ref x) => (*x), 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(); 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) { id: node_id) {
ebml_w.start_tag(tag_items_data_item_symbol); ebml_w.start_tag(tag_items_data_item_symbol);
ebml_w.writer.write(str::to_bytes(ecx.discrim_symbols.get(id))); ebml_w.writer.write(str::to_bytes(ecx.discrim_symbols.get(id)));
ebml_w.end_tag(); 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) { disr_val: int) {
ebml_w.start_tag(tag_disr_val); ebml_w.start_tag(tag_disr_val);
ebml_w.writer.write(str::to_bytes(int::to_str(disr_val,10u))); ebml_w.writer.write(str::to_bytes(int::to_str(disr_val,10u)));
ebml_w.end_tag(); 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.start_tag(tag_items_data_parent_item);
ebml_w.writer.write(str::to_bytes(def_to_str(id))); ebml_w.writer.write(str::to_bytes(def_to_str(id)));
ebml_w.end_tag(); 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], id: node_id, variants: ~[variant],
path: ast_map::path, index: @mut ~[entry<int>], path: ast_map::path, index: @mut ~[entry<int>],
ty_params: ~[ty_param]) { 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) { 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) { elt: ast_map::path_elt) {
let (tag, name) = match elt { let (tag, name) = match elt {
ast_map::path_mod(name) => (tag_path_elt_mod, name), 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, md: _mod, id: node_id, path: ast_map::path,
name: ident) { name: ident) {
ebml_w.start_tag(tag_items_data_item); 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(); 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 { encode_family(ebml_w, match visibility {
public => 'g', public => 'g',
private => 'j', 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); ebml_w.start_tag(tag_item_trait_method_self_ty);
// Encode the base self type. // 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(); 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.start_tag(tag_item_trait_method_sort);
ebml_w.writer.write(&[ sort as u8 ]); ebml_w.writer.write(&[ sort as u8 ]);
ebml_w.end_tag(); ebml_w.end_tag();
} }
/* Returns an index of items in this class */ /* 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, path: ast_map::path,
fields: ~[@struct_field], fields: ~[@struct_field],
global_index: @mut~[entry<int>]) -> ~[entry<int>] { 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 // 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, id: node_id, ident: ident, path: ast_map::path,
item: Option<inlined_item>, tps: ~[ty_param]) { item: Option<inlined_item>, tps: ~[ty_param]) {
ebml_w.start_tag(tag_items_data_item); 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(); 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, impl_path: ast_map::path, should_inline: bool,
parent_id: node_id, parent_id: node_id,
m: @method, all_tps: ~[ty_param]) { 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>], item: @item, index: @mut ~[entry<int>],
path: ast_map::path) { 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; } 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: @mut ~[entry<int>]) {
index.push({val: item.id, pos: ebml_w.writer.tell()}); 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, nitem: @foreign_item,
index: @mut ~[entry<int>], index: @mut ~[entry<int>],
path: ast_map::path, abi: foreign_abi) { 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(); 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>] { crate: @crate) -> ~[entry<int>] {
let index = @mut ~[]; let index = @mut ~[];
ebml_w.start_tag(tag_items_data); ebml_w.start_tag(tag_items_data);
@ -895,7 +895,7 @@ fn create_index<T: Copy Hash IterBytes>(index: ~[entry<T>]) ->
return buckets_frozen; 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)) { write_fn: fn(io::Writer, T)) {
let writer = ebml_w.writer; let writer = ebml_w.writer;
ebml_w.start_tag(tag_index); 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); 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 { match mi.node {
meta_word(ref name) => { meta_word(ref name) => {
ebml_w.start_tag(tag_meta_item_word); 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); ebml_w.start_tag(tag_attributes);
for attrs.each |attr| { for attrs.each |attr| {
ebml_w.start_tag(tag_attribute); ebml_w.start_tag(tag_attribute);
@ -1028,7 +1028,7 @@ fn synthesize_crate_attrs(ecx: @encode_ctxt, crate: @crate) -> ~[attribute] {
return attrs; 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) { cstore: cstore::CStore) {
fn get_ordered_deps(ecx: @encode_ctxt, 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(); 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) { dep: decoder::crate_dep) {
ebml_w.start_tag(tag_crate_dep); ebml_w.start_tag(tag_crate_dep);
ebml_w.start_tag(tag_crate_dep_name); 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(); 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.start_tag(tag_crate_hash);
ebml_w.writer.write(str::to_bytes(hash)); ebml_w.writer.write(str::to_bytes(hash));
ebml_w.end_tag(); ebml_w.end_tag();
@ -1127,7 +1127,7 @@ fn encode_metadata(parms: encode_parms, crate: @crate) -> ~[u8] {
type_abbrevs: ty::new_ty_hash() 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); 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 reader = std::ebml::reader;
use std::ebml::reader::get_doc; use std::ebml::reader::get_doc;
use std::ebml::writer::Serializer; use std::ebml::writer::Encoder;
use std::ebml; use std::ebml;
use std::map::HashMap; use std::map::HashMap;
use std::serialization::{DeserializerHelpers, deserialize}; use std::serialize;
use std::serialization::{Serializable, SerializerHelpers}; use std::serialize::{Encodable, EncoderHelpers, DecoderHelpers, decode};
use std::serialization;
use syntax::ast; use syntax::ast;
use syntax::ast_map; use syntax::ast_map;
use syntax::ast_util; use syntax::ast_util;
@ -84,7 +83,7 @@ trait tr_intern {
// Top-level methods. // Top-level methods.
fn encode_inlined_item(ecx: @e::encode_ctxt, fn encode_inlined_item(ecx: @e::encode_ctxt,
ebml_w: writer::Serializer, ebml_w: writer::Encoder,
path: ast_map::path, path: ast_map::path,
ii: ast::inlined_item, ii: ast::inlined_item,
maps: maps) { 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); let id_range = ast_util::compute_id_range_for_inlined_item(ii);
do ebml_w.wr_tag(c::tag_ast as uint) { 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_ast(ebml_w, simplify_ast(ii));
encode_side_tables_for_ii(ecx, maps, ebml_w, 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) => { Some(ast_doc) => {
debug!("> Decoding inlined fn: %s::?", debug!("> Decoding inlined fn: %s::?",
ast_map::path_to_str(path, tcx.sess.parse_sess.interner)); ast_map::path_to_str(path, tcx.sess.parse_sess.interner));
let ast_dsr = &reader::Deserializer(ast_doc); let ast_dsr = &reader::Decoder(ast_doc);
let from_id_range = deserialize(ast_dsr); let from_id_range = decode(ast_dsr);
let to_id_range = reserve_id_range(dcx.tcx.sess, from_id_range); let to_id_range = reserve_id_range(dcx.tcx.sess, from_id_range);
let xcx = extended_decode_ctxt_(@{dcx: dcx, let xcx = extended_decode_ctxt_(@{dcx: dcx,
from_id_range: from_id_range, 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); 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) { 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; 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 { 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) 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, // 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. // 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) { 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 { fn decode_ast(par_doc: ebml::Doc) -> ast::inlined_item {
let chi_doc = par_doc[c::tag_tree as uint]; let chi_doc = par_doc[c::tag_tree as uint];
let d = &reader::Deserializer(chi_doc); let d = &reader::Decoder(chi_doc);
deserialize(d) decode(d)
} }
fn renumber_ast(xcx: extended_decode_ctxt, ii: ast::inlined_item) 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 // Encoding and decoding of ast::def
fn encode_def(ebml_w: writer::Serializer, def: ast::def) { fn encode_def(ebml_w: writer::Encoder, def: ast::def) {
def.serialize(&ebml_w) def.encode(&ebml_w)
} }
fn decode_def(xcx: extended_decode_ctxt, doc: ebml::Doc) -> ast::def { fn decode_def(xcx: extended_decode_ctxt, doc: ebml::Doc) -> ast::def {
let dsr = &reader::Deserializer(doc); let dsr = &reader::Decoder(doc);
let def: ast::def = deserialize(dsr); let def: ast::def = decode(dsr);
def.tr(xcx) def.tr(xcx)
} }
@ -421,17 +420,17 @@ impl ty::bound_region: tr {
// ______________________________________________________________________ // ______________________________________________________________________
// Encoding and decoding of freevar information // Encoding and decoding of freevar information
fn encode_freevar_entry(ebml_w: writer::Serializer, fv: @freevar_entry) { fn encode_freevar_entry(ebml_w: writer::Encoder, fv: @freevar_entry) {
(*fv).serialize(&ebml_w) (*fv).encode(&ebml_w)
} }
trait ebml_deserializer_helper { trait ebml_decoder_helper {
fn read_freevar_entry(xcx: extended_decode_ctxt) -> freevar_entry; 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 { 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) 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 read_method_map_entry(xcx: extended_decode_ctxt) -> method_map_entry;
} }
fn serialize_method_map_entry(ecx: @e::encode_ctxt, fn encode_method_map_entry(ecx: @e::encode_ctxt,
ebml_w: writer::Serializer, ebml_w: writer::Encoder,
mme: method_map_entry) { mme: method_map_entry) {
do ebml_w.emit_rec { do ebml_w.emit_rec {
do ebml_w.emit_field(~"self_arg", 0u) { do ebml_w.emit_field(~"self_arg", 0u) {
ebml_w.emit_arg(ecx, mme.self_arg); ebml_w.emit_arg(ecx, mme.self_arg);
} }
do ebml_w.emit_field(~"explicit_self", 2u) { 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) { 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 { fn read_method_map_entry(xcx: extended_decode_ctxt) -> method_map_entry {
do self.read_rec { do self.read_rec {
{self_arg: {self_arg:
@ -474,12 +473,12 @@ impl reader::Deserializer: read_method_map_entry_helper {
}), }),
explicit_self: explicit_self:
self.read_field(~"explicit_self", 2u, || { self.read_field(~"explicit_self", 2u, || {
let self_type: ast::self_ty_ = deserialize(&self); let self_type: ast::self_ty_ = decode(&self);
self_type self_type
}), }),
origin: origin:
self.read_field(~"origin", 1u, || { self.read_field(~"origin", 1u, || {
let method_origin: method_origin = deserialize(&self); let method_origin: method_origin = decode(&self);
method_origin.tr(xcx) method_origin.tr(xcx)
})} })}
} }
@ -509,11 +508,11 @@ impl method_origin: tr {
// Encoding and decoding vtable_res // Encoding and decoding vtable_res
fn encode_vtable_res(ecx: @e::encode_ctxt, fn encode_vtable_res(ecx: @e::encode_ctxt,
ebml_w: writer::Serializer, ebml_w: writer::Encoder,
dr: typeck::vtable_res) { 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 // 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. // ones. perhaps we should fix this.
do ebml_w.emit_from_vec(*dr) |vtable_origin| { do ebml_w.emit_from_vec(*dr) |vtable_origin| {
encode_vtable_origin(ecx, ebml_w, *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, fn encode_vtable_origin(ecx: @e::encode_ctxt,
ebml_w: writer::Serializer, ebml_w: writer::Encoder,
vtable_origin: typeck::vtable_origin) { vtable_origin: typeck::vtable_origin) {
do ebml_w.emit_enum(~"vtable_origin") { do ebml_w.emit_enum(~"vtable_origin") {
match 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_res(xcx: extended_decode_ctxt) -> typeck::vtable_res;
fn read_vtable_origin(xcx: extended_decode_ctxt) -> typeck::vtable_origin; 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 { fn read_vtable_res(xcx: extended_decode_ctxt) -> typeck::vtable_res {
@self.read_to_vec(|| self.read_vtable_origin(xcx) ) @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); 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) { fn emit_ty(ecx: @e::encode_ctxt, ty: ty::t) {
do self.emit_opaque { do self.emit_opaque {
e::write_type(ecx, self, ty) e::write_type(ecx, self, ty)
@ -684,7 +683,7 @@ impl writer::Serializer: ebml_writer_helpers {
} }
} }
do self.emit_field(~"region_param", 1u) { do self.emit_field(~"region_param", 1u) {
tpbt.region_param.serialize(&self); tpbt.region_param.encode(&self);
} }
do self.emit_field(~"ty", 2u) { do self.emit_field(~"ty", 2u) {
self.emit_ty(ecx, tpbt.ty); self.emit_ty(ecx, tpbt.ty);
@ -698,7 +697,7 @@ trait write_tag_and_id {
fn id(id: ast::node_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()) { fn tag(tag_id: c::astencode_tag, f: fn()) {
do self.wr_tag(tag_id as uint) { f() } 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, fn encode_side_tables_for_ii(ecx: @e::encode_ctxt,
maps: maps, maps: maps,
ebml_w: writer::Serializer, ebml_w: writer::Encoder,
ii: ast::inlined_item) { ii: ast::inlined_item) {
do ebml_w.wr_tag(c::tag_table as uint) { do ebml_w.wr_tag(c::tag_table as uint) {
ast_util::visit_ids_for_inlined_item( 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, fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
maps: maps, maps: maps,
ebml_w: writer::Serializer, ebml_w: writer::Encoder,
id: ast::node_id) { id: ast::node_id) {
let tcx = ecx.tcx; 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) { do ebml_w.tag(c::tag_table_def) {
ebml_w.id(id); ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) { 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); ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) { do ebml_w.tag(c::tag_table_val) {
do ebml_w.emit_from_vec((*m).get()) |id| { 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) { do ebml_w.tag(c::tag_table_method_map) {
ebml_w.id(id); ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) { 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) { do ebml_w.tag(c::tag_table_adjustments) {
ebml_w.id(id); ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) { 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) { do ebml_w.tag(c::tag_table_value_mode) {
ebml_w.id(id); ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) { 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_arg(xcx: extended_decode_ctxt) -> ty::arg;
fn read_ty(xcx: extended_decode_ctxt) -> ty::t; fn read_ty(xcx: extended_decode_ctxt) -> ty::t;
fn read_tys(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; -> 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 { fn read_arg(xcx: extended_decode_ctxt) -> ty::arg {
do self.read_opaque |doc| { do self.read_opaque |doc| {
@ -927,7 +926,7 @@ impl reader::Deserializer: ebml_deserializer_decoder_helpers {
@self.read_to_vec(|| self.read_bounds(xcx) ) @self.read_to_vec(|| self.read_bounds(xcx) )
}), }),
region_param: self.read_field(~"region_param", 1u, || { region_param: self.read_field(~"region_param", 1u, || {
deserialize(&self) decode(&self)
}), }),
ty: self.read_field(~"ty", 2u, || { ty: self.read_field(~"ty", 2u, || {
self.read_ty(xcx) self.read_ty(xcx)
@ -955,7 +954,7 @@ fn decode_side_tables(xcx: extended_decode_ctxt,
dcx.tcx.legacy_boxed_traits.insert(id, ()); dcx.tcx.legacy_boxed_traits.insert(id, ());
} else { } else {
let val_doc = entry_doc[c::tag_table_val as uint]; 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) { if tag == (c::tag_table_def as uint) {
let def = decode_def(xcx, val_doc); let def = decode_def(xcx, val_doc);
dcx.tcx.def_map.insert(id, def); 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, dcx.maps.vtable_map.insert(id,
val_dsr.read_vtable_res(xcx)); val_dsr.read_vtable_res(xcx));
} else if tag == (c::tag_table_adjustments as uint) { } 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); adj.tr(xcx);
dcx.tcx.adjustments.insert(id, adj); dcx.tcx.adjustments.insert(id, adj);
} else if tag == (c::tag_table_value_mode as uint) { } 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); dcx.tcx.value_modes.insert(id, vm);
} else { } else {
xcx.dcx.tcx.sess.bug( xcx.dcx.tcx.sess.bug(
@ -1011,17 +1010,17 @@ fn decode_side_tables(xcx: extended_decode_ctxt,
// Testing of astencode_gen // Testing of astencode_gen
#[cfg(test)] #[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) { do ebml_w.wr_tag(c::tag_tree as uint) {
(*item).serialize(&ebml_w) (*item).encode(&ebml_w)
} }
} }
#[cfg(test)] #[cfg(test)]
fn decode_item_ast(par_doc: ebml::Doc) -> @ast::item { fn decode_item_ast(par_doc: ebml::Doc) -> @ast::item {
let chi_doc = par_doc[c::tag_tree as uint]; let chi_doc = par_doc[c::tag_tree as uint];
let d = &reader::Deserializer(chi_doc); let d = &reader::Decoder(chi_doc);
@deserialize(d) @decode(d)
} }
#[cfg(test)] #[cfg(test)]
@ -1060,17 +1059,17 @@ fn mk_ctxt() -> fake_ext_ctxt {
fn roundtrip(in_item: Option<@ast::item>) { fn roundtrip(in_item: Option<@ast::item>) {
let in_item = in_item.get(); let in_item = in_item.get();
let bytes = do io::with_bytes_writer |wr| { 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); encode_item_ast(ebml_w, in_item);
}; };
let ebml_doc = reader::Doc(@bytes); let ebml_doc = reader::Doc(@bytes);
let out_item = decode_item_ast(ebml_doc); let out_item = decode_item_ast(ebml_doc);
let exp_str = do io::with_str_writer |w| { 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| { 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); 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. // A vector of defs representing the free variables referred to in a function.
// (The def_upvar will already have been stripped). // (The def_upvar will already have been stripped).
#[auto_serialize] #[auto_encode]
#[auto_deserialize] #[auto_decode]
type freevar_entry = { type freevar_entry = {
def: ast::def, //< The variable being accessed free. def: ast::def, //< The variable being accessed free.
span: span //< First span where it is accessed (there can be multiple) 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_evec, mk_evec, type_is_vec;
export ty_unboxed_vec, mk_unboxed_vec, mk_mut_unboxed_vec; export ty_unboxed_vec, mk_unboxed_vec, mk_mut_unboxed_vec;
export vstore, vstore_fixed, vstore_uniq, vstore_box, vstore_slice; 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_nil, mk_nil, type_is_nil;
export ty_trait, mk_trait; export ty_trait, mk_trait;
export ty_param, mk_param, ty_params_to_tys; 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}; type mt = {ty: t, mutbl: ast::mutability};
#[auto_serialize] #[auto_encode]
#[auto_deserialize] #[auto_decode]
enum vstore { enum vstore {
vstore_fixed(uint), vstore_fixed(uint),
vstore_uniq, vstore_uniq,
@ -255,8 +255,8 @@ type field_ty = {
}; };
/// How an lvalue is to be used. /// How an lvalue is to be used.
#[auto_serialize] #[auto_encode]
#[auto_deserialize] #[auto_decode]
pub enum ValueMode { pub enum ValueMode {
ReadValue, // Non-destructively read the value; do not copy or move. ReadValue, // Non-destructively read the value; do not copy or move.
CopyValue, // Copy the value. CopyValue, // Copy the value.
@ -307,8 +307,8 @@ enum ast_ty_to_ty_cache_entry {
type opt_region_variance = Option<region_variance>; type opt_region_variance = Option<region_variance>;
#[auto_serialize] #[auto_encode]
#[auto_deserialize] #[auto_decode]
enum region_variance { rv_covariant, rv_invariant, rv_contravariant } enum region_variance { rv_covariant, rv_invariant, rv_contravariant }
impl region_variance : cmp::Eq { 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) } pure fn ne(&self, other: &region_variance) -> bool { !(*self).eq(other) }
} }
#[auto_serialize] #[auto_encode]
#[auto_deserialize] #[auto_decode]
pub type AutoAdjustment = { pub type AutoAdjustment = {
autoderefs: uint, autoderefs: uint,
autoref: Option<AutoRef> autoref: Option<AutoRef>
}; };
#[auto_serialize] #[auto_encode]
#[auto_deserialize] #[auto_decode]
pub type AutoRef = { pub type AutoRef = {
kind: AutoRefKind, kind: AutoRefKind,
region: Region, region: Region,
mutbl: ast::mutability mutbl: ast::mutability
}; };
#[auto_serialize] #[auto_encode]
#[auto_deserialize] #[auto_decode]
enum AutoRefKind { enum AutoRefKind {
/// Convert from T to &T /// Convert from T to &T
AutoPtr, AutoPtr,
@ -544,8 +544,8 @@ impl param_ty : to_bytes::IterBytes {
/// Representation of regions: /// Representation of regions:
#[auto_serialize] #[auto_encode]
#[auto_deserialize] #[auto_decode]
enum Region { enum Region {
/// Bound regions are found (primarily) in function types. They indicate /// Bound regions are found (primarily) in function types. They indicate
/// region parameters that have yet to be replaced with actual regions /// region parameters that have yet to be replaced with actual regions
@ -573,8 +573,8 @@ enum Region {
re_infer(InferRegion) re_infer(InferRegion)
} }
#[auto_serialize] #[auto_encode]
#[auto_deserialize] #[auto_decode]
enum bound_region { enum bound_region {
/// The self region for structs, impls (&T in a type defn or &self/T) /// The self region for structs, impls (&T in a type defn or &self/T)
br_self, br_self,
@ -712,8 +712,8 @@ enum TyVid = uint;
enum IntVid = uint; enum IntVid = uint;
enum FloatVid = uint; enum FloatVid = uint;
enum FnVid = uint; enum FnVid = uint;
#[auto_serialize] #[auto_encode]
#[auto_deserialize] #[auto_decode]
enum RegionVid = uint; enum RegionVid = uint;
enum InferTy { enum InferTy {
@ -732,8 +732,8 @@ impl InferTy : to_bytes::IterBytes {
} }
} }
#[auto_serialize] #[auto_encode]
#[auto_deserialize] #[auto_decode]
enum InferRegion { enum InferRegion {
ReVar(RegionVid), ReVar(RegionVid),
ReSkolemized(uint, bound_region) ReSkolemized(uint, bound_region)

View file

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

View file

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

View file

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

View file

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

View file

@ -107,14 +107,16 @@ mod unicode;
pub mod test; pub mod test;
pub mod serialize; pub mod serialize;
#[cfg(stage0)]
pub mod serialization; pub mod serialization;
// A curious inner-module that's not exported that contains the binding // 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. // can be resolved within libcore.
#[doc(hidden)] // FIXME #3538 #[doc(hidden)] // FIXME #3538
mod std { mod std {
pub use serialize; pub use serialize;
#[cfg(stage0)]
pub use serialization; pub use serialization;
} }

View file

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

View file

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

View file

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

View file

@ -22,10 +22,7 @@ source code snippets, etc.
*/ */
use dvec::DVec; use dvec::DVec;
use std::serialization::{Serializable, use std::serialize::{Encodable, Decodable, Encoder, Decoder};
Deserializable,
Serializer,
Deserializer};
trait Pos { trait Pos {
static pure fn from_uint(n: uint) -> self; 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) } pure fn ne(&self, other: &span) -> bool { !(*self).eq(other) }
} }
impl<S: Serializer> span: Serializable<S> { impl<S: Encoder> span: Encodable<S> {
/* Note #1972 -- spans are serialized but not deserialized */ /* Note #1972 -- spans are encoded but not decoded */
fn serialize(&self, _s: &S) { } fn encode(&self, _s: &S) { }
} }
impl<D: Deserializer> span: Deserializable<D> { impl<D: Decoder> span: Decodable<D> {
static fn deserialize(_d: &D) -> span { static fn decode(_d: &D) -> span {
ast_util::dummy_sp() 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: // 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 // attribute prefixing an item, and are interpreted by feeding the item
// through the named attribute _as a syntax extension_ and splicing in the // through the named attribute _as a syntax extension_ and splicing in the
// resulting item vec into place in favour of the decorator. Note that // 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 util::interner::Interner;
use std::map::HashMap; use std::map::HashMap;
#[auto_serialize] #[auto_encode]
#[auto_deserialize] #[auto_decode]
enum binop { enum binop {
PLUS, PLUS,
MINUS, MINUS,
@ -27,8 +27,8 @@ enum binop {
SHR, SHR,
} }
#[auto_serialize] #[auto_encode]
#[auto_deserialize] #[auto_decode]
enum Token { enum Token {
/* Expression-operator symbols. */ /* Expression-operator symbols. */
EQ, EQ,
@ -85,8 +85,8 @@ enum Token {
EOF, EOF,
} }
#[auto_serialize] #[auto_encode]
#[auto_deserialize] #[auto_decode]
/// For interpolation during macro expansion. /// For interpolation during macro expansion.
enum nonterminal { enum nonterminal {
nt_item(@ast::item), nt_item(@ast::item),
@ -351,7 +351,7 @@ impl ident_interner {
} }
/* Key for thread-local data for sneaking interner information to the /* 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, * 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 * so we have to use a unique number. See taskgroup_key! in task.rs
* for another case of this. */ * for another case of this. */

View file

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