Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename serialization to encodement #4125

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ front/ - front-end: attributes, conditional compilation
middle/ - middle-end: name resolution, typechecking, LLVM code
generation
back/ - back-end: linking and ABI
metadata/ - serializer and deserializer for data required by
metadata/ - encoder and decoder for data required by
separate compilation
driver/ - command-line processing, main() entrypoint
util/ - ubiquitous types and helper functions
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use std::ebml;
use std::map;
use std::map::HashMap;
use std::serialization::deserialize;
use std::serialize::decode;
use reader = ebml::reader;
use io::WriterUtil;
use dvec::DVec;
Expand Down Expand Up @@ -283,7 +283,7 @@ fn item_ty_param_bounds(item: ebml::Doc, tcx: ty::ctxt, cdata: cmd)

fn item_ty_region_param(item: ebml::Doc) -> Option<ty::region_variance> {
reader::maybe_get_doc(item, tag_region_param).map(|doc| {
deserialize(&reader::Deserializer(*doc))
decode(&reader::Decoder(*doc))
})
}

Expand Down
82 changes: 41 additions & 41 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export encode_def_id;
type abbrev_map = map::HashMap<ty::t, tyencode::ty_abbrev>;

type encode_inlined_item = fn@(ecx: @encode_ctxt,
ebml_w: writer::Serializer,
ebml_w: writer::Encoder,
path: ast_map::path,
ii: ast::inlined_item);

Expand Down Expand Up @@ -96,31 +96,31 @@ fn reachable(ecx: @encode_ctxt, id: node_id) -> bool {
ecx.reachable.contains_key(id)
}

fn encode_name(ecx: @encode_ctxt, ebml_w: writer::Serializer, name: ident) {
fn encode_name(ecx: @encode_ctxt, ebml_w: writer::Encoder, name: ident) {
ebml_w.wr_tagged_str(tag_paths_data_name, ecx.tcx.sess.str_of(name));
}

fn encode_impl_type_basename(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_impl_type_basename(ecx: @encode_ctxt, ebml_w: writer::Encoder,
name: ident) {
ebml_w.wr_tagged_str(tag_item_impl_type_basename,
ecx.tcx.sess.str_of(name));
}

fn encode_def_id(ebml_w: writer::Serializer, id: def_id) {
fn encode_def_id(ebml_w: writer::Encoder, id: def_id) {
ebml_w.wr_tagged_str(tag_def_id, def_to_str(id));
}

fn encode_region_param(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_region_param(ecx: @encode_ctxt, ebml_w: writer::Encoder,
it: @ast::item) {
let opt_rp = ecx.tcx.region_paramd_items.find(it.id);
for opt_rp.each |rp| {
do ebml_w.wr_tag(tag_region_param) {
(*rp).serialize(&ebml_w);
(*rp).encode(&ebml_w);
}
}
}

fn encode_mutability(ebml_w: writer::Serializer, mt: struct_mutability) {
fn encode_mutability(ebml_w: writer::Encoder, mt: struct_mutability) {
do ebml_w.wr_tag(tag_struct_mut) {
let val = match mt {
struct_immutable => 'a',
Expand All @@ -132,7 +132,7 @@ fn encode_mutability(ebml_w: writer::Serializer, mt: struct_mutability) {

type entry<T> = {val: T, pos: uint};

fn add_to_index(ecx: @encode_ctxt, ebml_w: writer::Serializer, path: &[ident],
fn add_to_index(ecx: @encode_ctxt, ebml_w: writer::Encoder, path: &[ident],
index: &mut ~[entry<~str>], name: ident) {
let mut full_path = ~[];
full_path.push_all(path);
Expand All @@ -143,7 +143,7 @@ fn add_to_index(ecx: @encode_ctxt, ebml_w: writer::Serializer, path: &[ident],
pos: ebml_w.writer.tell()});
}

fn encode_trait_ref(ebml_w: writer::Serializer, ecx: @encode_ctxt,
fn encode_trait_ref(ebml_w: writer::Encoder, ecx: @encode_ctxt,
t: @trait_ref) {
ebml_w.start_tag(tag_impl_trait);
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, t.ref_id));
Expand All @@ -152,15 +152,15 @@ fn encode_trait_ref(ebml_w: writer::Serializer, ecx: @encode_ctxt,


// Item info table encoding
fn encode_family(ebml_w: writer::Serializer, c: char) {
fn encode_family(ebml_w: writer::Encoder, c: char) {
ebml_w.start_tag(tag_items_data_item_family);
ebml_w.writer.write(&[c as u8]);
ebml_w.end_tag();
}

fn def_to_str(did: def_id) -> ~str { fmt!("%d:%d", did.crate, did.node) }

fn encode_ty_type_param_bounds(ebml_w: writer::Serializer, ecx: @encode_ctxt,
fn encode_ty_type_param_bounds(ebml_w: writer::Encoder, ecx: @encode_ctxt,
params: @~[ty::param_bounds]) {
let ty_str_ctxt = @{diag: ecx.diag,
ds: def_to_str,
Expand All @@ -174,21 +174,21 @@ fn encode_ty_type_param_bounds(ebml_w: writer::Serializer, ecx: @encode_ctxt,
}
}

fn encode_type_param_bounds(ebml_w: writer::Serializer, ecx: @encode_ctxt,
fn encode_type_param_bounds(ebml_w: writer::Encoder, ecx: @encode_ctxt,
params: ~[ty_param]) {
let ty_param_bounds =
@params.map(|param| ecx.tcx.ty_param_bounds.get(param.id));
encode_ty_type_param_bounds(ebml_w, ecx, ty_param_bounds);
}


fn encode_variant_id(ebml_w: writer::Serializer, vid: def_id) {
fn encode_variant_id(ebml_w: writer::Encoder, vid: def_id) {
ebml_w.start_tag(tag_items_data_item_variant);
ebml_w.writer.write(str::to_bytes(def_to_str(vid)));
ebml_w.end_tag();
}

fn write_type(ecx: @encode_ctxt, ebml_w: writer::Serializer, typ: ty::t) {
fn write_type(ecx: @encode_ctxt, ebml_w: writer::Encoder, typ: ty::t) {
let ty_str_ctxt =
@{diag: ecx.diag,
ds: def_to_str,
Expand All @@ -198,7 +198,7 @@ fn write_type(ecx: @encode_ctxt, ebml_w: writer::Serializer, typ: ty::t) {
tyencode::enc_ty(ebml_w.writer, ty_str_ctxt, typ);
}

fn write_vstore(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn write_vstore(ecx: @encode_ctxt, ebml_w: writer::Encoder,
vstore: ty::vstore) {
let ty_str_ctxt =
@{diag: ecx.diag,
Expand All @@ -209,13 +209,13 @@ fn write_vstore(ecx: @encode_ctxt, ebml_w: writer::Serializer,
tyencode::enc_vstore(ebml_w.writer, ty_str_ctxt, vstore);
}

fn encode_type(ecx: @encode_ctxt, ebml_w: writer::Serializer, typ: ty::t) {
fn encode_type(ecx: @encode_ctxt, ebml_w: writer::Encoder, typ: ty::t) {
ebml_w.start_tag(tag_items_data_item_type);
write_type(ecx, ebml_w, typ);
ebml_w.end_tag();
}

fn encode_symbol(ecx: @encode_ctxt, ebml_w: writer::Serializer, id: node_id) {
fn encode_symbol(ecx: @encode_ctxt, ebml_w: writer::Encoder, id: node_id) {
ebml_w.start_tag(tag_items_data_item_symbol);
let sym = match ecx.item_symbols.find(id) {
Some(ref x) => (*x),
Expand All @@ -228,27 +228,27 @@ fn encode_symbol(ecx: @encode_ctxt, ebml_w: writer::Serializer, id: node_id) {
ebml_w.end_tag();
}

fn encode_discriminant(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_discriminant(ecx: @encode_ctxt, ebml_w: writer::Encoder,
id: node_id) {
ebml_w.start_tag(tag_items_data_item_symbol);
ebml_w.writer.write(str::to_bytes(ecx.discrim_symbols.get(id)));
ebml_w.end_tag();
}

fn encode_disr_val(_ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_disr_val(_ecx: @encode_ctxt, ebml_w: writer::Encoder,
disr_val: int) {
ebml_w.start_tag(tag_disr_val);
ebml_w.writer.write(str::to_bytes(int::to_str(disr_val,10u)));
ebml_w.end_tag();
}

fn encode_parent_item(ebml_w: writer::Serializer, id: def_id) {
fn encode_parent_item(ebml_w: writer::Encoder, id: def_id) {
ebml_w.start_tag(tag_items_data_parent_item);
ebml_w.writer.write(str::to_bytes(def_to_str(id)));
ebml_w.end_tag();
}

fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: writer::Encoder,
id: node_id, variants: ~[variant],
path: ast_map::path, index: @mut ~[entry<int>],
ty_params: ~[ty_param]) {
Expand Down Expand Up @@ -285,9 +285,9 @@ fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: writer::Serializer,
}
}

fn encode_path(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_path(ecx: @encode_ctxt, ebml_w: writer::Encoder,
path: ast_map::path, name: ast_map::path_elt) {
fn encode_path_elt(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_path_elt(ecx: @encode_ctxt, ebml_w: writer::Encoder,
elt: ast_map::path_elt) {
let (tag, name) = match elt {
ast_map::path_mod(name) => (tag_path_elt_mod, name),
Expand All @@ -306,7 +306,7 @@ fn encode_path(ecx: @encode_ctxt, ebml_w: writer::Serializer,
}
}

fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: writer::Encoder,
md: _mod, id: node_id, path: ast_map::path,
name: ident) {
ebml_w.start_tag(tag_items_data_item);
Expand Down Expand Up @@ -365,15 +365,15 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: writer::Serializer,
ebml_w.end_tag();
}

fn encode_visibility(ebml_w: writer::Serializer, visibility: visibility) {
fn encode_visibility(ebml_w: writer::Encoder, visibility: visibility) {
encode_family(ebml_w, match visibility {
public => 'g',
private => 'j',
inherited => 'N'
});
}

fn encode_self_type(ebml_w: writer::Serializer, self_type: ast::self_ty_) {
fn encode_self_type(ebml_w: writer::Encoder, self_type: ast::self_ty_) {
ebml_w.start_tag(tag_item_trait_method_self_ty);

// Encode the base self type.
Expand Down Expand Up @@ -405,14 +405,14 @@ fn encode_self_type(ebml_w: writer::Serializer, self_type: ast::self_ty_) {
ebml_w.end_tag();
}

fn encode_method_sort(ebml_w: writer::Serializer, sort: char) {
fn encode_method_sort(ebml_w: writer::Encoder, sort: char) {
ebml_w.start_tag(tag_item_trait_method_sort);
ebml_w.writer.write(&[ sort as u8 ]);
ebml_w.end_tag();
}

/* Returns an index of items in this class */
fn encode_info_for_struct(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_info_for_struct(ecx: @encode_ctxt, ebml_w: writer::Encoder,
path: ast_map::path,
fields: ~[@struct_field],
global_index: @mut~[entry<int>]) -> ~[entry<int>] {
Expand Down Expand Up @@ -447,7 +447,7 @@ fn encode_info_for_struct(ecx: @encode_ctxt, ebml_w: writer::Serializer,
}

// This is for encoding info for ctors and dtors
fn encode_info_for_ctor(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_info_for_ctor(ecx: @encode_ctxt, ebml_w: writer::Encoder,
id: node_id, ident: ident, path: ast_map::path,
item: Option<inlined_item>, tps: ~[ty_param]) {
ebml_w.start_tag(tag_items_data_item);
Expand All @@ -472,7 +472,7 @@ fn encode_info_for_ctor(ecx: @encode_ctxt, ebml_w: writer::Serializer,
ebml_w.end_tag();
}

fn encode_info_for_method(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_info_for_method(ecx: @encode_ctxt, ebml_w: writer::Encoder,
impl_path: ast_map::path, should_inline: bool,
parent_id: node_id,
m: @method, all_tps: ~[ty_param]) {
Expand Down Expand Up @@ -527,7 +527,7 @@ fn should_inline(attrs: ~[attribute]) -> bool {
}


fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
item: @item, index: @mut ~[entry<int>],
path: ast_map::path) {

Expand All @@ -540,7 +540,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Serializer,
};
if !must_write && !reachable(ecx, item.id) { return; }

fn add_to_index_(item: @item, ebml_w: writer::Serializer,
fn add_to_index_(item: @item, ebml_w: writer::Encoder,
index: @mut ~[entry<int>]) {
index.push({val: item.id, pos: ebml_w.writer.tell()});
}
Expand Down Expand Up @@ -804,7 +804,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Serializer,
}
}

fn encode_info_for_foreign_item(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_info_for_foreign_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
nitem: @foreign_item,
index: @mut ~[entry<int>],
path: ast_map::path, abi: foreign_abi) {
Expand Down Expand Up @@ -837,7 +837,7 @@ fn encode_info_for_foreign_item(ecx: @encode_ctxt, ebml_w: writer::Serializer,
ebml_w.end_tag();
}

fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: writer::Encoder,
crate: @crate) -> ~[entry<int>] {
let index = @mut ~[];
ebml_w.start_tag(tag_items_data);
Expand Down Expand Up @@ -892,7 +892,7 @@ fn create_index<T: Copy Hash IterBytes>(index: ~[entry<T>]) ->
return buckets_frozen;
}

fn encode_index<T>(ebml_w: writer::Serializer, buckets: ~[@~[entry<T>]],
fn encode_index<T>(ebml_w: writer::Encoder, buckets: ~[@~[entry<T>]],
write_fn: fn(io::Writer, T)) {
let writer = ebml_w.writer;
ebml_w.start_tag(tag_index);
Expand Down Expand Up @@ -927,7 +927,7 @@ fn write_int(writer: io::Writer, &&n: int) {
writer.write_be_u32(n as u32);
}

fn encode_meta_item(ebml_w: writer::Serializer, mi: meta_item) {
fn encode_meta_item(ebml_w: writer::Encoder, mi: meta_item) {
match mi.node {
meta_word(ref name) => {
ebml_w.start_tag(tag_meta_item_word);
Expand Down Expand Up @@ -964,7 +964,7 @@ fn encode_meta_item(ebml_w: writer::Serializer, mi: meta_item) {
}
}

fn encode_attributes(ebml_w: writer::Serializer, attrs: ~[attribute]) {
fn encode_attributes(ebml_w: writer::Encoder, attrs: ~[attribute]) {
ebml_w.start_tag(tag_attributes);
for attrs.each |attr| {
ebml_w.start_tag(tag_attribute);
Expand Down Expand Up @@ -1025,7 +1025,7 @@ fn synthesize_crate_attrs(ecx: @encode_ctxt, crate: @crate) -> ~[attribute] {
return attrs;
}

fn encode_crate_deps(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_crate_deps(ecx: @encode_ctxt, ebml_w: writer::Encoder,
cstore: cstore::CStore) {

fn get_ordered_deps(ecx: @encode_ctxt, cstore: cstore::CStore)
Expand Down Expand Up @@ -1071,7 +1071,7 @@ fn encode_crate_deps(ecx: @encode_ctxt, ebml_w: writer::Serializer,
ebml_w.end_tag();
}

fn encode_crate_dep(ecx: @encode_ctxt, ebml_w: writer::Serializer,
fn encode_crate_dep(ecx: @encode_ctxt, ebml_w: writer::Encoder,
dep: decoder::crate_dep) {
ebml_w.start_tag(tag_crate_dep);
ebml_w.start_tag(tag_crate_dep_name);
Expand All @@ -1086,7 +1086,7 @@ fn encode_crate_dep(ecx: @encode_ctxt, ebml_w: writer::Serializer,
ebml_w.end_tag();
}

fn encode_hash(ebml_w: writer::Serializer, hash: ~str) {
fn encode_hash(ebml_w: writer::Encoder, hash: ~str) {
ebml_w.start_tag(tag_crate_hash);
ebml_w.writer.write(str::to_bytes(hash));
ebml_w.end_tag();
Expand Down Expand Up @@ -1124,7 +1124,7 @@ fn encode_metadata(parms: encode_parms, crate: @crate) -> ~[u8] {
type_abbrevs: ty::new_ty_hash()
});

let ebml_w = writer::Serializer(wr as io::Writer);
let ebml_w = writer::Encoder(wr as io::Writer);

encode_hash(ebml_w, ecx.link_meta.extras_hash);

Expand Down
Loading