mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-21 20:23:21 +00:00
remove serialize::ebml, add librbml
Our implementation of ebml has diverged from the standard in order to better serve the needs of the compiler, so it doesn't make much sense to call what we have ebml anyore. Furthermore, our implementation is pretty crufty, and should eventually be rewritten into a format that better suits the needs of the compiler. This patch factors out serialize::ebml into librbml, otherwise known as the Really Bad Markup Language. This is a stopgap library that shouldn't be used by end users, and will eventually be replaced by something better. [breaking-change]
This commit is contained in:
parent
ea1b637654
commit
e1dcbefe52
@ -51,7 +51,7 @@
|
||||
|
||||
TARGET_CRATES := libc std green rustuv native flate arena glob term semver \
|
||||
uuid serialize sync getopts collections num test time rand \
|
||||
url log regex graphviz core rlibc alloc debug rustrt \
|
||||
url log regex graphviz core rbml rlibc alloc debug rustrt \
|
||||
unicode
|
||||
HOST_CRATES := syntax rustc rustdoc fourcc hexfloat regex_macros fmt_macros \
|
||||
rustc_llvm rustc_back
|
||||
@ -71,7 +71,7 @@ DEPS_green := std native:context_switch
|
||||
DEPS_rustuv := std native:uv native:uv_support
|
||||
DEPS_native := std
|
||||
DEPS_syntax := std term serialize log fmt_macros debug
|
||||
DEPS_rustc := syntax flate arena serialize getopts \
|
||||
DEPS_rustc := syntax flate arena serialize getopts rbml \
|
||||
time log graphviz debug rustc_llvm rustc_back
|
||||
DEPS_rustc_llvm := native:rustllvm libc std
|
||||
DEPS_rustc_back := std syntax rustc_llvm flate log libc
|
||||
@ -82,6 +82,7 @@ DEPS_arena := std
|
||||
DEPS_graphviz := std
|
||||
DEPS_glob := std
|
||||
DEPS_serialize := std log
|
||||
DEPS_rbml := std log serialize
|
||||
DEPS_term := std log
|
||||
DEPS_semver := std
|
||||
DEPS_uuid := std serialize
|
||||
@ -91,7 +92,7 @@ DEPS_collections := core alloc unicode
|
||||
DEPS_fourcc := rustc syntax std
|
||||
DEPS_hexfloat := rustc syntax std
|
||||
DEPS_num := std
|
||||
DEPS_test := std getopts serialize term time regex native:rust_test_helpers
|
||||
DEPS_test := std getopts serialize rbml term time regex native:rust_test_helpers
|
||||
DEPS_time := std serialize
|
||||
DEPS_rand := core
|
||||
DEPS_url := std
|
||||
|
@ -8,16 +8,35 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//! Really Bad Markup Language (rbml) is a temporary measure until we migrate
|
||||
//! the rust object metadata to a better serialization format. It is not
|
||||
//! intended to be used by users.
|
||||
//!
|
||||
//! It is loosely based on the Extensible Binary Markup Language (ebml):
|
||||
//! http://www.matroska.org/technical/specs/rfc/index.html
|
||||
|
||||
#![crate_name = "rbml"]
|
||||
#![experimental]
|
||||
#![crate_type = "rlib"]
|
||||
#![crate_type = "dylib"]
|
||||
#![license = "MIT/ASL2"]
|
||||
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
||||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/master/",
|
||||
html_playground_url = "http://play.rust-lang.org/")]
|
||||
#![feature(macro_rules, phase)]
|
||||
#![allow(missing_doc)]
|
||||
|
||||
extern crate serialize;
|
||||
|
||||
#[phase(plugin, link)] extern crate log;
|
||||
#[cfg(test)] extern crate test;
|
||||
|
||||
use std::io;
|
||||
use std::str;
|
||||
|
||||
// Simple Extensible Binary Markup Language (ebml) reader and writer on a
|
||||
// cursor model. See the specification here:
|
||||
// http://www.matroska.org/technical/specs/rfc/index.html
|
||||
|
||||
// Common data structures
|
||||
/// Common data structures
|
||||
#[deriving(Clone)]
|
||||
pub struct Doc<'a> {
|
||||
pub data: &'a [u8],
|
||||
@ -107,7 +126,7 @@ pub mod reader {
|
||||
Expected };
|
||||
|
||||
pub type DecodeResult<T> = Result<T, Error>;
|
||||
// ebml reading
|
||||
// rbml reading
|
||||
|
||||
macro_rules! try_or(
|
||||
($e:expr, $r:expr) => (
|
||||
@ -637,7 +656,7 @@ pub mod writer {
|
||||
|
||||
pub type EncodeResult = io::IoResult<()>;
|
||||
|
||||
// ebml writing
|
||||
// rbml writing
|
||||
pub struct Encoder<'a, W> {
|
||||
pub writer: &'a mut W,
|
||||
size_positions: Vec<uint>,
|
||||
@ -671,7 +690,7 @@ pub mod writer {
|
||||
})
|
||||
}
|
||||
|
||||
// FIXME (#2741): Provide a function to write the standard ebml header.
|
||||
// FIXME (#2741): Provide a function to write the standard rbml header.
|
||||
impl<'a, W: Writer + Seek> Encoder<'a, W> {
|
||||
pub fn new(w: &'a mut W) -> Encoder<'a, W> {
|
||||
Encoder {
|
||||
@ -1018,10 +1037,8 @@ pub mod writer {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Doc;
|
||||
use ebml::reader;
|
||||
use ebml::writer;
|
||||
use {Encodable, Decodable};
|
||||
use super::{Doc, reader, writer};
|
||||
use serialize::{Encodable, Decodable};
|
||||
|
||||
use std::io::{IoError, IoResult, SeekStyle};
|
||||
use std::io;
|
||||
@ -1196,11 +1213,11 @@ mod tests {
|
||||
debug!("v == {}", v);
|
||||
let mut wr = SeekableMemWriter::new();
|
||||
{
|
||||
let mut ebml_w = writer::Encoder::new(&mut wr);
|
||||
let _ = v.encode(&mut ebml_w);
|
||||
let mut rbml_w = writer::Encoder::new(&mut wr);
|
||||
let _ = v.encode(&mut rbml_w);
|
||||
}
|
||||
let ebml_doc = Doc::new(wr.get_ref());
|
||||
let mut deser = reader::Decoder::new(ebml_doc);
|
||||
let rbml_doc = Doc::new(wr.get_ref());
|
||||
let mut deser = reader::Decoder::new(rbml_doc);
|
||||
let v1 = Decodable::decode(&mut deser).unwrap();
|
||||
debug!("v1 == {}", v1);
|
||||
assert_eq!(v, v1);
|
||||
@ -1215,9 +1232,8 @@ mod tests {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
#![allow(non_snake_case_functions)]
|
||||
extern crate test;
|
||||
use self::test::Bencher;
|
||||
use ebml::reader;
|
||||
use test::Bencher;
|
||||
use super::reader;
|
||||
|
||||
#[bench]
|
||||
pub fn vuint_at_A_aligned(b: &mut Bencher) {
|
@ -44,6 +44,7 @@ extern crate libc;
|
||||
extern crate llvm = "rustc_llvm";
|
||||
extern crate rustc_back = "rustc_back";
|
||||
extern crate serialize;
|
||||
extern crate rbml;
|
||||
extern crate time;
|
||||
#[phase(plugin, link)] extern crate log;
|
||||
#[phase(plugin, link)] extern crate syntax;
|
||||
|
@ -20,8 +20,8 @@ use middle::ty;
|
||||
use middle::typeck;
|
||||
use middle::subst::VecPerParamSpace;
|
||||
|
||||
use serialize::ebml;
|
||||
use serialize::ebml::reader;
|
||||
use rbml;
|
||||
use rbml::reader;
|
||||
use std::rc::Rc;
|
||||
use syntax::ast;
|
||||
use syntax::ast_map;
|
||||
@ -218,7 +218,7 @@ pub fn get_field_type(tcx: &ty::ctxt, class_id: ast::DefId,
|
||||
def: ast::DefId) -> ty::Polytype {
|
||||
let cstore = &tcx.sess.cstore;
|
||||
let cdata = cstore.get_crate_data(class_id.krate);
|
||||
let all_items = reader::get_doc(ebml::Doc::new(cdata.data()), tag_items);
|
||||
let all_items = reader::get_doc(rbml::Doc::new(cdata.data()), tag_items);
|
||||
let class_doc = expect(tcx.sess.diagnostic(),
|
||||
decoder::maybe_find_item(class_id.node, all_items),
|
||||
|| {
|
||||
|
@ -37,8 +37,8 @@ use std::io;
|
||||
use std::collections::hashmap::HashMap;
|
||||
use std::rc::Rc;
|
||||
use std::u64;
|
||||
use serialize::ebml::reader;
|
||||
use serialize::ebml;
|
||||
use rbml::reader;
|
||||
use rbml;
|
||||
use serialize::Decodable;
|
||||
use syntax::ast_map;
|
||||
use syntax::attr;
|
||||
@ -56,8 +56,8 @@ pub type Cmd<'a> = &'a crate_metadata;
|
||||
// what crate that's in and give us a def_id that makes sense for the current
|
||||
// build.
|
||||
|
||||
fn lookup_hash<'a>(d: ebml::Doc<'a>, eq_fn: |&[u8]| -> bool,
|
||||
hash: u64) -> Option<ebml::Doc<'a>> {
|
||||
fn lookup_hash<'a>(d: rbml::Doc<'a>, eq_fn: |&[u8]| -> bool,
|
||||
hash: u64) -> Option<rbml::Doc<'a>> {
|
||||
let index = reader::get_doc(d, tag_index);
|
||||
let table = reader::get_doc(index, tag_index_table);
|
||||
let hash_pos = table.start + (hash % 256 * 4) as uint;
|
||||
@ -80,7 +80,7 @@ fn lookup_hash<'a>(d: ebml::Doc<'a>, eq_fn: |&[u8]| -> bool,
|
||||
}
|
||||
|
||||
pub fn maybe_find_item<'a>(item_id: ast::NodeId,
|
||||
items: ebml::Doc<'a>) -> Option<ebml::Doc<'a>> {
|
||||
items: rbml::Doc<'a>) -> Option<rbml::Doc<'a>> {
|
||||
fn eq_item(bytes: &[u8], item_id: ast::NodeId) -> bool {
|
||||
return u64_from_be_bytes(
|
||||
bytes.slice(0u, 4u), 0u, 4u) as ast::NodeId
|
||||
@ -91,17 +91,17 @@ pub fn maybe_find_item<'a>(item_id: ast::NodeId,
|
||||
hash::hash(&(item_id as i64)))
|
||||
}
|
||||
|
||||
fn find_item<'a>(item_id: ast::NodeId, items: ebml::Doc<'a>) -> ebml::Doc<'a> {
|
||||
fn find_item<'a>(item_id: ast::NodeId, items: rbml::Doc<'a>) -> rbml::Doc<'a> {
|
||||
match maybe_find_item(item_id, items) {
|
||||
None => fail!("lookup_item: id not found: {}", item_id),
|
||||
Some(d) => d
|
||||
}
|
||||
}
|
||||
|
||||
// Looks up an item in the given metadata and returns an ebml doc pointing
|
||||
// Looks up an item in the given metadata and returns an rbml doc pointing
|
||||
// to the item data.
|
||||
fn lookup_item<'a>(item_id: ast::NodeId, data: &'a [u8]) -> ebml::Doc<'a> {
|
||||
let items = reader::get_doc(ebml::Doc::new(data), tag_items);
|
||||
fn lookup_item<'a>(item_id: ast::NodeId, data: &'a [u8]) -> rbml::Doc<'a> {
|
||||
let items = reader::get_doc(rbml::Doc::new(data), tag_items);
|
||||
find_item(item_id, items)
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ enum Family {
|
||||
InheritedField // N
|
||||
}
|
||||
|
||||
fn item_family(item: ebml::Doc) -> Family {
|
||||
fn item_family(item: rbml::Doc) -> Family {
|
||||
let fam = reader::get_doc(item, tag_items_data_item_family);
|
||||
match reader::doc_as_u8(fam) as char {
|
||||
'c' => ImmStatic,
|
||||
@ -152,7 +152,7 @@ fn item_family(item: ebml::Doc) -> Family {
|
||||
}
|
||||
}
|
||||
|
||||
fn item_visibility(item: ebml::Doc) -> ast::Visibility {
|
||||
fn item_visibility(item: rbml::Doc) -> ast::Visibility {
|
||||
match reader::maybe_get_doc(item, tag_items_data_item_visibility) {
|
||||
None => ast::Public,
|
||||
Some(visibility_doc) => {
|
||||
@ -165,7 +165,7 @@ fn item_visibility(item: ebml::Doc) -> ast::Visibility {
|
||||
}
|
||||
}
|
||||
|
||||
fn item_method_sort(item: ebml::Doc) -> char {
|
||||
fn item_method_sort(item: rbml::Doc) -> char {
|
||||
let mut ret = 'r';
|
||||
reader::tagged_docs(item, tag_item_trait_method_sort, |doc| {
|
||||
ret = doc.as_str_slice().as_bytes()[0] as char;
|
||||
@ -174,11 +174,11 @@ fn item_method_sort(item: ebml::Doc) -> char {
|
||||
ret
|
||||
}
|
||||
|
||||
fn item_symbol(item: ebml::Doc) -> String {
|
||||
fn item_symbol(item: rbml::Doc) -> String {
|
||||
reader::get_doc(item, tag_items_data_item_symbol).as_str().to_string()
|
||||
}
|
||||
|
||||
fn item_parent_item(d: ebml::Doc) -> Option<ast::DefId> {
|
||||
fn item_parent_item(d: rbml::Doc) -> Option<ast::DefId> {
|
||||
let mut ret = None;
|
||||
reader::tagged_docs(d, tag_items_data_parent_item, |did| {
|
||||
ret = Some(reader::with_doc_data(did, parse_def_id));
|
||||
@ -188,60 +188,60 @@ fn item_parent_item(d: ebml::Doc) -> Option<ast::DefId> {
|
||||
}
|
||||
|
||||
fn item_reqd_and_translated_parent_item(cnum: ast::CrateNum,
|
||||
d: ebml::Doc) -> ast::DefId {
|
||||
d: rbml::Doc) -> ast::DefId {
|
||||
let trait_did = item_parent_item(d).expect("item without parent");
|
||||
ast::DefId { krate: cnum, node: trait_did.node }
|
||||
}
|
||||
|
||||
fn item_def_id(d: ebml::Doc, cdata: Cmd) -> ast::DefId {
|
||||
fn item_def_id(d: rbml::Doc, cdata: Cmd) -> ast::DefId {
|
||||
let tagdoc = reader::get_doc(d, tag_def_id);
|
||||
return translate_def_id(cdata, reader::with_doc_data(tagdoc, parse_def_id));
|
||||
}
|
||||
|
||||
fn get_provided_source(d: ebml::Doc, cdata: Cmd) -> Option<ast::DefId> {
|
||||
fn get_provided_source(d: rbml::Doc, cdata: Cmd) -> Option<ast::DefId> {
|
||||
reader::maybe_get_doc(d, tag_item_method_provided_source).map(|doc| {
|
||||
translate_def_id(cdata, reader::with_doc_data(doc, parse_def_id))
|
||||
})
|
||||
}
|
||||
|
||||
fn each_reexport(d: ebml::Doc, f: |ebml::Doc| -> bool) -> bool {
|
||||
fn each_reexport(d: rbml::Doc, f: |rbml::Doc| -> bool) -> bool {
|
||||
reader::tagged_docs(d, tag_items_data_item_reexport, f)
|
||||
}
|
||||
|
||||
fn variant_disr_val(d: ebml::Doc) -> Option<ty::Disr> {
|
||||
fn variant_disr_val(d: rbml::Doc) -> Option<ty::Disr> {
|
||||
reader::maybe_get_doc(d, tag_disr_val).and_then(|val_doc| {
|
||||
reader::with_doc_data(val_doc, |data| u64::parse_bytes(data, 10u))
|
||||
})
|
||||
}
|
||||
|
||||
fn doc_type(doc: ebml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::t {
|
||||
fn doc_type(doc: rbml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::t {
|
||||
let tp = reader::get_doc(doc, tag_items_data_item_type);
|
||||
parse_ty_data(tp.data, cdata.cnum, tp.start, tcx,
|
||||
|_, did| translate_def_id(cdata, did))
|
||||
}
|
||||
|
||||
fn doc_method_fty(doc: ebml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::BareFnTy {
|
||||
fn doc_method_fty(doc: rbml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::BareFnTy {
|
||||
let tp = reader::get_doc(doc, tag_item_method_fty);
|
||||
parse_bare_fn_ty_data(tp.data, cdata.cnum, tp.start, tcx,
|
||||
|_, did| translate_def_id(cdata, did))
|
||||
}
|
||||
|
||||
pub fn item_type(_item_id: ast::DefId, item: ebml::Doc,
|
||||
pub fn item_type(_item_id: ast::DefId, item: rbml::Doc,
|
||||
tcx: &ty::ctxt, cdata: Cmd) -> ty::t {
|
||||
doc_type(item, tcx, cdata)
|
||||
}
|
||||
|
||||
fn doc_trait_ref(doc: ebml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::TraitRef {
|
||||
fn doc_trait_ref(doc: rbml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::TraitRef {
|
||||
parse_trait_ref_data(doc.data, cdata.cnum, doc.start, tcx,
|
||||
|_, did| translate_def_id(cdata, did))
|
||||
}
|
||||
|
||||
fn item_trait_ref(doc: ebml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::TraitRef {
|
||||
fn item_trait_ref(doc: rbml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::TraitRef {
|
||||
let tp = reader::get_doc(doc, tag_item_trait_ref);
|
||||
doc_trait_ref(tp, tcx, cdata)
|
||||
}
|
||||
|
||||
fn item_ty_param_defs(item: ebml::Doc,
|
||||
fn item_ty_param_defs(item: rbml::Doc,
|
||||
tcx: &ty::ctxt,
|
||||
cdata: Cmd,
|
||||
tag: uint)
|
||||
@ -257,7 +257,7 @@ fn item_ty_param_defs(item: ebml::Doc,
|
||||
bounds
|
||||
}
|
||||
|
||||
fn item_region_param_defs(item_doc: ebml::Doc, cdata: Cmd)
|
||||
fn item_region_param_defs(item_doc: rbml::Doc, cdata: Cmd)
|
||||
-> subst::VecPerParamSpace<ty::RegionParameterDef>
|
||||
{
|
||||
let mut v = subst::VecPerParamSpace::empty();
|
||||
@ -285,7 +285,7 @@ fn item_region_param_defs(item_doc: ebml::Doc, cdata: Cmd)
|
||||
v
|
||||
}
|
||||
|
||||
fn enum_variant_ids(item: ebml::Doc, cdata: Cmd) -> Vec<ast::DefId> {
|
||||
fn enum_variant_ids(item: rbml::Doc, cdata: Cmd) -> Vec<ast::DefId> {
|
||||
let mut ids: Vec<ast::DefId> = Vec::new();
|
||||
let v = tag_items_data_item_variant;
|
||||
reader::tagged_docs(item, v, |p| {
|
||||
@ -296,7 +296,7 @@ fn enum_variant_ids(item: ebml::Doc, cdata: Cmd) -> Vec<ast::DefId> {
|
||||
return ids;
|
||||
}
|
||||
|
||||
fn item_path(item_doc: ebml::Doc) -> Vec<ast_map::PathElem> {
|
||||
fn item_path(item_doc: rbml::Doc) -> Vec<ast_map::PathElem> {
|
||||
let path_doc = reader::get_doc(item_doc, tag_path);
|
||||
|
||||
let len_doc = reader::get_doc(path_doc, tag_path_len);
|
||||
@ -319,7 +319,7 @@ fn item_path(item_doc: ebml::Doc) -> Vec<ast_map::PathElem> {
|
||||
result
|
||||
}
|
||||
|
||||
fn item_name(intr: &IdentInterner, item: ebml::Doc) -> ast::Ident {
|
||||
fn item_name(intr: &IdentInterner, item: rbml::Doc) -> ast::Ident {
|
||||
let name = reader::get_doc(item, tag_paths_data_name);
|
||||
let string = name.as_str_slice();
|
||||
match intr.find_equiv(&string) {
|
||||
@ -328,7 +328,7 @@ fn item_name(intr: &IdentInterner, item: ebml::Doc) -> ast::Ident {
|
||||
}
|
||||
}
|
||||
|
||||
fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
|
||||
fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum)
|
||||
-> DefLike {
|
||||
let fam = item_family(item);
|
||||
match fam {
|
||||
@ -463,7 +463,7 @@ pub enum DefLike {
|
||||
|
||||
/// Iterates over the language items in the given crate.
|
||||
pub fn each_lang_item(cdata: Cmd, f: |ast::NodeId, uint| -> bool) -> bool {
|
||||
let root = ebml::Doc::new(cdata.data());
|
||||
let root = rbml::Doc::new(cdata.data());
|
||||
let lang_items = reader::get_doc(root, tag_lang_items);
|
||||
reader::tagged_docs(lang_items, tag_lang_items_item, |item_doc| {
|
||||
let id_doc = reader::get_doc(item_doc, tag_lang_items_item_id);
|
||||
@ -480,7 +480,7 @@ pub type GetCrateDataCb<'a> = |ast::CrateNum|: 'a -> Rc<crate_metadata>;
|
||||
|
||||
fn each_child_of_item_or_crate(intr: Rc<IdentInterner>,
|
||||
cdata: Cmd,
|
||||
item_doc: ebml::Doc,
|
||||
item_doc: rbml::Doc,
|
||||
get_crate_data: GetCrateDataCb,
|
||||
callback: |DefLike,
|
||||
ast::Ident,
|
||||
@ -503,7 +503,7 @@ fn each_child_of_item_or_crate(intr: Rc<IdentInterner>,
|
||||
None => cdata
|
||||
};
|
||||
|
||||
let other_crates_items = reader::get_doc(ebml::Doc::new(crate_data.data()), tag_items);
|
||||
let other_crates_items = reader::get_doc(rbml::Doc::new(crate_data.data()), tag_items);
|
||||
|
||||
// Get the item.
|
||||
match maybe_find_item(child_def_id.node, other_crates_items) {
|
||||
@ -531,7 +531,7 @@ fn each_child_of_item_or_crate(intr: Rc<IdentInterner>,
|
||||
|inherent_impl_def_id_doc| {
|
||||
let inherent_impl_def_id = item_def_id(inherent_impl_def_id_doc,
|
||||
cdata);
|
||||
let items = reader::get_doc(ebml::Doc::new(cdata.data()), tag_items);
|
||||
let items = reader::get_doc(rbml::Doc::new(cdata.data()), tag_items);
|
||||
match maybe_find_item(inherent_impl_def_id.node, items) {
|
||||
None => {}
|
||||
Some(inherent_impl_doc) => {
|
||||
@ -596,7 +596,7 @@ fn each_child_of_item_or_crate(intr: Rc<IdentInterner>,
|
||||
None => cdata
|
||||
};
|
||||
|
||||
let other_crates_items = reader::get_doc(ebml::Doc::new(crate_data.data()), tag_items);
|
||||
let other_crates_items = reader::get_doc(rbml::Doc::new(crate_data.data()), tag_items);
|
||||
|
||||
// Get the item.
|
||||
match maybe_find_item(child_def_id.node, other_crates_items) {
|
||||
@ -623,7 +623,7 @@ pub fn each_child_of_item(intr: Rc<IdentInterner>,
|
||||
get_crate_data: GetCrateDataCb,
|
||||
callback: |DefLike, ast::Ident, ast::Visibility|) {
|
||||
// Find the item.
|
||||
let root_doc = ebml::Doc::new(cdata.data());
|
||||
let root_doc = rbml::Doc::new(cdata.data());
|
||||
let items = reader::get_doc(root_doc, tag_items);
|
||||
let item_doc = match maybe_find_item(id, items) {
|
||||
None => return,
|
||||
@ -644,7 +644,7 @@ pub fn each_top_level_item_of_crate(intr: Rc<IdentInterner>,
|
||||
callback: |DefLike,
|
||||
ast::Ident,
|
||||
ast::Visibility|) {
|
||||
let root_doc = ebml::Doc::new(cdata.data());
|
||||
let root_doc = rbml::Doc::new(cdata.data());
|
||||
let misc_info_doc = reader::get_doc(root_doc, tag_misc_info);
|
||||
let crate_items_doc = reader::get_doc(misc_info_doc,
|
||||
tag_misc_info_crate_items);
|
||||
@ -663,7 +663,7 @@ pub fn get_item_path(cdata: Cmd, id: ast::NodeId) -> Vec<ast_map::PathElem> {
|
||||
pub type DecodeInlinedItem<'a> = |cdata: Cmd,
|
||||
tcx: &ty::ctxt,
|
||||
path: Vec<ast_map::PathElem>,
|
||||
par_doc: ebml::Doc|: 'a
|
||||
par_doc: rbml::Doc|: 'a
|
||||
-> Result<ast::InlinedItem, Vec<ast_map::PathElem> >;
|
||||
|
||||
pub fn maybe_get_item_ast(cdata: Cmd, tcx: &ty::ctxt, id: ast::NodeId,
|
||||
@ -693,7 +693,7 @@ pub fn maybe_get_item_ast(cdata: Cmd, tcx: &ty::ctxt, id: ast::NodeId,
|
||||
pub fn get_enum_variants(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId,
|
||||
tcx: &ty::ctxt) -> Vec<Rc<ty::VariantInfo>> {
|
||||
let data = cdata.data();
|
||||
let items = reader::get_doc(ebml::Doc::new(data), tag_items);
|
||||
let items = reader::get_doc(rbml::Doc::new(data), tag_items);
|
||||
let item = find_item(id, items);
|
||||
let mut disr_val = 0;
|
||||
enum_variant_ids(item, cdata).iter().map(|did| {
|
||||
@ -725,7 +725,7 @@ pub fn get_enum_variants(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId,
|
||||
}).collect()
|
||||
}
|
||||
|
||||
fn get_explicit_self(item: ebml::Doc) -> ty::ExplicitSelfCategory {
|
||||
fn get_explicit_self(item: rbml::Doc) -> ty::ExplicitSelfCategory {
|
||||
fn get_mutability(ch: u8) -> ast::Mutability {
|
||||
match ch as char {
|
||||
'i' => ast::MutImmutable,
|
||||
@ -965,7 +965,7 @@ pub fn get_item_attrs(cdata: Cmd,
|
||||
}
|
||||
|
||||
pub fn get_struct_field_attrs(cdata: Cmd) -> HashMap<ast::NodeId, Vec<ast::Attribute>> {
|
||||
let data = ebml::Doc::new(cdata.data());
|
||||
let data = rbml::Doc::new(cdata.data());
|
||||
let fields = reader::get_doc(data, tag_struct_fields);
|
||||
let mut map = HashMap::new();
|
||||
reader::tagged_docs(fields, tag_struct_field, |field| {
|
||||
@ -1023,7 +1023,7 @@ pub fn get_struct_fields(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId)
|
||||
result
|
||||
}
|
||||
|
||||
fn get_meta_items(md: ebml::Doc) -> Vec<Gc<ast::MetaItem>> {
|
||||
fn get_meta_items(md: rbml::Doc) -> Vec<Gc<ast::MetaItem>> {
|
||||
let mut items: Vec<Gc<ast::MetaItem>> = Vec::new();
|
||||
reader::tagged_docs(md, tag_meta_item_word, |meta_item_doc| {
|
||||
let nd = reader::get_doc(meta_item_doc, tag_meta_item_name);
|
||||
@ -1051,7 +1051,7 @@ fn get_meta_items(md: ebml::Doc) -> Vec<Gc<ast::MetaItem>> {
|
||||
return items;
|
||||
}
|
||||
|
||||
fn get_attributes(md: ebml::Doc) -> Vec<ast::Attribute> {
|
||||
fn get_attributes(md: rbml::Doc) -> Vec<ast::Attribute> {
|
||||
let mut attrs: Vec<ast::Attribute> = Vec::new();
|
||||
match reader::maybe_get_doc(md, tag_attributes) {
|
||||
Some(attrs_d) => {
|
||||
@ -1082,7 +1082,7 @@ fn get_attributes(md: ebml::Doc) -> Vec<ast::Attribute> {
|
||||
return attrs;
|
||||
}
|
||||
|
||||
fn list_crate_attributes(md: ebml::Doc, hash: &Svh,
|
||||
fn list_crate_attributes(md: rbml::Doc, hash: &Svh,
|
||||
out: &mut io::Writer) -> io::IoResult<()> {
|
||||
try!(write!(out, "=Crate Attributes ({})=\n", *hash));
|
||||
|
||||
@ -1095,7 +1095,7 @@ fn list_crate_attributes(md: ebml::Doc, hash: &Svh,
|
||||
}
|
||||
|
||||
pub fn get_crate_attributes(data: &[u8]) -> Vec<ast::Attribute> {
|
||||
get_attributes(ebml::Doc::new(data))
|
||||
get_attributes(rbml::Doc::new(data))
|
||||
}
|
||||
|
||||
#[deriving(Clone)]
|
||||
@ -1107,10 +1107,10 @@ pub struct CrateDep {
|
||||
|
||||
pub fn get_crate_deps(data: &[u8]) -> Vec<CrateDep> {
|
||||
let mut deps: Vec<CrateDep> = Vec::new();
|
||||
let cratedoc = ebml::Doc::new(data);
|
||||
let cratedoc = rbml::Doc::new(data);
|
||||
let depsdoc = reader::get_doc(cratedoc, tag_crate_deps);
|
||||
let mut crate_num = 1;
|
||||
fn docstr(doc: ebml::Doc, tag_: uint) -> String {
|
||||
fn docstr(doc: rbml::Doc, tag_: uint) -> String {
|
||||
let d = reader::get_doc(doc, tag_);
|
||||
d.as_str_slice().to_string()
|
||||
}
|
||||
@ -1138,27 +1138,27 @@ fn list_crate_deps(data: &[u8], out: &mut io::Writer) -> io::IoResult<()> {
|
||||
}
|
||||
|
||||
pub fn maybe_get_crate_hash(data: &[u8]) -> Option<Svh> {
|
||||
let cratedoc = ebml::Doc::new(data);
|
||||
let cratedoc = rbml::Doc::new(data);
|
||||
reader::maybe_get_doc(cratedoc, tag_crate_hash).map(|doc| {
|
||||
Svh::new(doc.as_str_slice())
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_crate_hash(data: &[u8]) -> Svh {
|
||||
let cratedoc = ebml::Doc::new(data);
|
||||
let cratedoc = rbml::Doc::new(data);
|
||||
let hashdoc = reader::get_doc(cratedoc, tag_crate_hash);
|
||||
Svh::new(hashdoc.as_str_slice())
|
||||
}
|
||||
|
||||
pub fn maybe_get_crate_name(data: &[u8]) -> Option<String> {
|
||||
let cratedoc = ebml::Doc::new(data);
|
||||
let cratedoc = rbml::Doc::new(data);
|
||||
reader::maybe_get_doc(cratedoc, tag_crate_crate_name).map(|doc| {
|
||||
doc.as_str_slice().to_string()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_crate_triple(data: &[u8]) -> Option<String> {
|
||||
let cratedoc = ebml::Doc::new(data);
|
||||
let cratedoc = rbml::Doc::new(data);
|
||||
let triple_doc = reader::maybe_get_doc(cratedoc, tag_crate_triple);
|
||||
triple_doc.map(|s| s.as_str().to_string())
|
||||
}
|
||||
@ -1169,7 +1169,7 @@ pub fn get_crate_name(data: &[u8]) -> String {
|
||||
|
||||
pub fn list_crate_metadata(bytes: &[u8], out: &mut io::Writer) -> io::IoResult<()> {
|
||||
let hash = get_crate_hash(bytes);
|
||||
let md = ebml::Doc::new(bytes);
|
||||
let md = rbml::Doc::new(bytes);
|
||||
try!(list_crate_attributes(md, &hash, out));
|
||||
list_crate_deps(bytes, out)
|
||||
}
|
||||
@ -1196,7 +1196,7 @@ pub fn translate_def_id(cdata: Cmd, did: ast::DefId) -> ast::DefId {
|
||||
}
|
||||
|
||||
pub fn each_impl(cdata: Cmd, callback: |ast::DefId|) {
|
||||
let impls_doc = reader::get_doc(ebml::Doc::new(cdata.data()), tag_impls);
|
||||
let impls_doc = reader::get_doc(rbml::Doc::new(cdata.data()), tag_impls);
|
||||
let _ = reader::tagged_docs(impls_doc, tag_impls_impl, |impl_doc| {
|
||||
callback(item_def_id(impl_doc, cdata));
|
||||
true
|
||||
@ -1252,7 +1252,7 @@ pub fn get_trait_of_method(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt)
|
||||
|
||||
pub fn get_native_libraries(cdata: Cmd)
|
||||
-> Vec<(cstore::NativeLibaryKind, String)> {
|
||||
let libraries = reader::get_doc(ebml::Doc::new(cdata.data()),
|
||||
let libraries = reader::get_doc(rbml::Doc::new(cdata.data()),
|
||||
tag_native_libraries);
|
||||
let mut result = Vec::new();
|
||||
reader::tagged_docs(libraries, tag_native_libraries_lib, |lib_doc| {
|
||||
@ -1268,12 +1268,12 @@ pub fn get_native_libraries(cdata: Cmd)
|
||||
}
|
||||
|
||||
pub fn get_plugin_registrar_fn(data: &[u8]) -> Option<ast::NodeId> {
|
||||
reader::maybe_get_doc(ebml::Doc::new(data), tag_plugin_registrar_fn)
|
||||
reader::maybe_get_doc(rbml::Doc::new(data), tag_plugin_registrar_fn)
|
||||
.map(|doc| FromPrimitive::from_u32(reader::doc_as_u32(doc)).unwrap())
|
||||
}
|
||||
|
||||
pub fn get_exported_macros(data: &[u8]) -> Vec<String> {
|
||||
let macros = reader::get_doc(ebml::Doc::new(data),
|
||||
let macros = reader::get_doc(rbml::Doc::new(data),
|
||||
tag_exported_macros);
|
||||
let mut result = Vec::new();
|
||||
reader::tagged_docs(macros, tag_macro_def, |macro_doc| {
|
||||
@ -1286,7 +1286,7 @@ pub fn get_exported_macros(data: &[u8]) -> Vec<String> {
|
||||
pub fn get_dylib_dependency_formats(cdata: Cmd)
|
||||
-> Vec<(ast::CrateNum, cstore::LinkagePreference)>
|
||||
{
|
||||
let formats = reader::get_doc(ebml::Doc::new(cdata.data()),
|
||||
let formats = reader::get_doc(rbml::Doc::new(cdata.data()),
|
||||
tag_dylib_dependency_formats);
|
||||
let mut result = Vec::new();
|
||||
|
||||
@ -1312,7 +1312,7 @@ pub fn get_dylib_dependency_formats(cdata: Cmd)
|
||||
pub fn get_missing_lang_items(cdata: Cmd)
|
||||
-> Vec<lang_items::LangItem>
|
||||
{
|
||||
let items = reader::get_doc(ebml::Doc::new(cdata.data()), tag_lang_items);
|
||||
let items = reader::get_doc(rbml::Doc::new(cdata.data()), tag_lang_items);
|
||||
let mut result = Vec::new();
|
||||
reader::tagged_docs(items, tag_lang_items_missing, |missing_doc| {
|
||||
let item: lang_items::LangItem =
|
||||
@ -1340,7 +1340,7 @@ pub fn get_method_arg_names(cdata: Cmd, id: ast::NodeId) -> Vec<String> {
|
||||
|
||||
pub fn get_reachable_extern_fns(cdata: Cmd) -> Vec<ast::DefId> {
|
||||
let mut ret = Vec::new();
|
||||
let items = reader::get_doc(ebml::Doc::new(cdata.data()),
|
||||
let items = reader::get_doc(rbml::Doc::new(cdata.data()),
|
||||
tag_reachable_extern_fns);
|
||||
reader::tagged_docs(items, tag_reachable_extern_fn_id, |doc| {
|
||||
ret.push(ast::DefId {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -43,12 +43,11 @@ use std::io::Seek;
|
||||
use std::mem;
|
||||
use std::gc::GC;
|
||||
|
||||
use serialize::ebml::reader;
|
||||
use serialize::ebml;
|
||||
use rbml::{reader, writer};
|
||||
use rbml;
|
||||
use serialize;
|
||||
use serialize::{Encoder, Encodable, EncoderHelpers, DecoderHelpers};
|
||||
use serialize::{Decoder, Decodable};
|
||||
use writer = serialize::ebml::writer;
|
||||
|
||||
#[cfg(test)] use syntax::parse;
|
||||
#[cfg(test)] use syntax::print::pprust;
|
||||
@ -79,7 +78,7 @@ pub type Encoder<'a> = writer::Encoder<'a, SeekableMemWriter>;
|
||||
// Top-level methods.
|
||||
|
||||
pub fn encode_inlined_item(ecx: &e::EncodeContext,
|
||||
ebml_w: &mut Encoder,
|
||||
rbml_w: &mut Encoder,
|
||||
ii: e::InlinedItemRef) {
|
||||
let id = match ii {
|
||||
e::IIItemRef(i) => i.id,
|
||||
@ -88,26 +87,26 @@ pub fn encode_inlined_item(ecx: &e::EncodeContext,
|
||||
};
|
||||
debug!("> Encoding inlined item: {} ({})",
|
||||
ecx.tcx.map.path_to_string(id),
|
||||
ebml_w.writer.tell());
|
||||
rbml_w.writer.tell());
|
||||
|
||||
let ii = simplify_ast(ii);
|
||||
let id_range = ast_util::compute_id_range_for_inlined_item(&ii);
|
||||
|
||||
ebml_w.start_tag(c::tag_ast as uint);
|
||||
id_range.encode(ebml_w);
|
||||
encode_ast(ebml_w, ii);
|
||||
encode_side_tables_for_ii(ecx, ebml_w, &ii);
|
||||
ebml_w.end_tag();
|
||||
rbml_w.start_tag(c::tag_ast as uint);
|
||||
id_range.encode(rbml_w);
|
||||
encode_ast(rbml_w, ii);
|
||||
encode_side_tables_for_ii(ecx, rbml_w, &ii);
|
||||
rbml_w.end_tag();
|
||||
|
||||
debug!("< Encoded inlined fn: {} ({})",
|
||||
ecx.tcx.map.path_to_string(id),
|
||||
ebml_w.writer.tell());
|
||||
rbml_w.writer.tell());
|
||||
}
|
||||
|
||||
pub fn decode_inlined_item(cdata: &cstore::crate_metadata,
|
||||
tcx: &ty::ctxt,
|
||||
path: Vec<ast_map::PathElem>,
|
||||
par_doc: ebml::Doc)
|
||||
par_doc: rbml::Doc)
|
||||
-> Result<ast::InlinedItem, Vec<ast_map::PathElem>> {
|
||||
let dcx = &DecodeContext {
|
||||
cdata: cdata,
|
||||
@ -294,10 +293,10 @@ impl<D:serialize::Decoder<E>, E> def_id_decoder_helpers for D {
|
||||
// We also have to adjust the spans: for now we just insert a dummy span,
|
||||
// but eventually we should add entries to the local codemap as required.
|
||||
|
||||
fn encode_ast(ebml_w: &mut Encoder, item: ast::InlinedItem) {
|
||||
ebml_w.start_tag(c::tag_tree as uint);
|
||||
item.encode(ebml_w);
|
||||
ebml_w.end_tag();
|
||||
fn encode_ast(rbml_w: &mut Encoder, item: ast::InlinedItem) {
|
||||
rbml_w.start_tag(c::tag_tree as uint);
|
||||
item.encode(rbml_w);
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
|
||||
struct NestedItemsDropper;
|
||||
@ -353,7 +352,7 @@ fn simplify_ast(ii: e::InlinedItemRef) -> ast::InlinedItem {
|
||||
}
|
||||
}
|
||||
|
||||
fn decode_ast(par_doc: ebml::Doc) -> ast::InlinedItem {
|
||||
fn decode_ast(par_doc: rbml::Doc) -> ast::InlinedItem {
|
||||
let chi_doc = par_doc.get(c::tag_tree as uint);
|
||||
let mut d = reader::Decoder::new(chi_doc);
|
||||
Decodable::decode(&mut d).unwrap()
|
||||
@ -401,7 +400,7 @@ fn renumber_and_map_ast(xcx: &ExtendedDecodeContext,
|
||||
// ______________________________________________________________________
|
||||
// Encoding and decoding of ast::def
|
||||
|
||||
fn decode_def(xcx: &ExtendedDecodeContext, doc: ebml::Doc) -> def::Def {
|
||||
fn decode_def(xcx: &ExtendedDecodeContext, doc: rbml::Doc) -> def::Def {
|
||||
let mut dsr = reader::Decoder::new(doc);
|
||||
let def: def::Def = Decodable::decode(&mut dsr).unwrap();
|
||||
def.tr(xcx)
|
||||
@ -526,16 +525,16 @@ impl tr for ty::TraitStore {
|
||||
// ______________________________________________________________________
|
||||
// Encoding and decoding of freevar information
|
||||
|
||||
fn encode_freevar_entry(ebml_w: &mut Encoder, fv: &freevar_entry) {
|
||||
(*fv).encode(ebml_w).unwrap();
|
||||
fn encode_freevar_entry(rbml_w: &mut Encoder, fv: &freevar_entry) {
|
||||
(*fv).encode(rbml_w).unwrap();
|
||||
}
|
||||
|
||||
trait ebml_decoder_helper {
|
||||
trait rbml_decoder_helper {
|
||||
fn read_freevar_entry(&mut self, xcx: &ExtendedDecodeContext)
|
||||
-> freevar_entry;
|
||||
}
|
||||
|
||||
impl<'a> ebml_decoder_helper for reader::Decoder<'a> {
|
||||
impl<'a> rbml_decoder_helper for reader::Decoder<'a> {
|
||||
fn read_freevar_entry(&mut self, xcx: &ExtendedDecodeContext)
|
||||
-> freevar_entry {
|
||||
let fv: freevar_entry = Decodable::decode(self).unwrap();
|
||||
@ -561,21 +560,21 @@ trait read_method_callee_helper {
|
||||
}
|
||||
|
||||
fn encode_method_callee(ecx: &e::EncodeContext,
|
||||
ebml_w: &mut Encoder,
|
||||
rbml_w: &mut Encoder,
|
||||
adjustment: typeck::ExprAdjustment,
|
||||
method: &MethodCallee) {
|
||||
ebml_w.emit_struct("MethodCallee", 4, |ebml_w| {
|
||||
ebml_w.emit_struct_field("adjustment", 0u, |ebml_w| {
|
||||
adjustment.encode(ebml_w)
|
||||
rbml_w.emit_struct("MethodCallee", 4, |rbml_w| {
|
||||
rbml_w.emit_struct_field("adjustment", 0u, |rbml_w| {
|
||||
adjustment.encode(rbml_w)
|
||||
});
|
||||
ebml_w.emit_struct_field("origin", 1u, |ebml_w| {
|
||||
method.origin.encode(ebml_w)
|
||||
rbml_w.emit_struct_field("origin", 1u, |rbml_w| {
|
||||
method.origin.encode(rbml_w)
|
||||
});
|
||||
ebml_w.emit_struct_field("ty", 2u, |ebml_w| {
|
||||
Ok(ebml_w.emit_ty(ecx, method.ty))
|
||||
rbml_w.emit_struct_field("ty", 2u, |rbml_w| {
|
||||
Ok(rbml_w.emit_ty(ecx, method.ty))
|
||||
});
|
||||
ebml_w.emit_struct_field("substs", 3u, |ebml_w| {
|
||||
Ok(ebml_w.emit_substs(ecx, &method.substs))
|
||||
rbml_w.emit_struct_field("substs", 3u, |rbml_w| {
|
||||
Ok(rbml_w.emit_substs(ecx, &method.substs))
|
||||
})
|
||||
}).unwrap();
|
||||
}
|
||||
@ -636,81 +635,81 @@ impl tr for MethodOrigin {
|
||||
// Encoding and decoding vtable_res
|
||||
|
||||
fn encode_vtable_res_with_key(ecx: &e::EncodeContext,
|
||||
ebml_w: &mut Encoder,
|
||||
rbml_w: &mut Encoder,
|
||||
adjustment: typeck::ExprAdjustment,
|
||||
dr: &typeck::vtable_res) {
|
||||
ebml_w.emit_struct("VtableWithKey", 2, |ebml_w| {
|
||||
ebml_w.emit_struct_field("adjustment", 0u, |ebml_w| {
|
||||
adjustment.encode(ebml_w)
|
||||
rbml_w.emit_struct("VtableWithKey", 2, |rbml_w| {
|
||||
rbml_w.emit_struct_field("adjustment", 0u, |rbml_w| {
|
||||
adjustment.encode(rbml_w)
|
||||
});
|
||||
ebml_w.emit_struct_field("vtable_res", 1u, |ebml_w| {
|
||||
Ok(encode_vtable_res(ecx, ebml_w, dr))
|
||||
rbml_w.emit_struct_field("vtable_res", 1u, |rbml_w| {
|
||||
Ok(encode_vtable_res(ecx, rbml_w, dr))
|
||||
})
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
pub fn encode_vtable_res(ecx: &e::EncodeContext,
|
||||
ebml_w: &mut Encoder,
|
||||
rbml_w: &mut Encoder,
|
||||
dr: &typeck::vtable_res) {
|
||||
// can't autogenerate this code because automatic code of
|
||||
// ty::t doesn't work, and there is no way (atm) to have
|
||||
// hand-written encoding routines combine with auto-generated
|
||||
// ones. perhaps we should fix this.
|
||||
encode_vec_per_param_space(
|
||||
ebml_w, dr,
|
||||
|ebml_w, param_tables| encode_vtable_param_res(ecx, ebml_w,
|
||||
rbml_w, dr,
|
||||
|rbml_w, param_tables| encode_vtable_param_res(ecx, rbml_w,
|
||||
param_tables))
|
||||
}
|
||||
|
||||
pub fn encode_vtable_param_res(ecx: &e::EncodeContext,
|
||||
ebml_w: &mut Encoder,
|
||||
rbml_w: &mut Encoder,
|
||||
param_tables: &typeck::vtable_param_res) {
|
||||
ebml_w.emit_from_vec(param_tables.as_slice(), |ebml_w, vtable_origin| {
|
||||
Ok(encode_vtable_origin(ecx, ebml_w, vtable_origin))
|
||||
rbml_w.emit_from_vec(param_tables.as_slice(), |rbml_w, vtable_origin| {
|
||||
Ok(encode_vtable_origin(ecx, rbml_w, vtable_origin))
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
|
||||
pub fn encode_vtable_origin(ecx: &e::EncodeContext,
|
||||
ebml_w: &mut Encoder,
|
||||
rbml_w: &mut Encoder,
|
||||
vtable_origin: &typeck::vtable_origin) {
|
||||
ebml_w.emit_enum("vtable_origin", |ebml_w| {
|
||||
rbml_w.emit_enum("vtable_origin", |rbml_w| {
|
||||
match *vtable_origin {
|
||||
typeck::vtable_static(def_id, ref substs, ref vtable_res) => {
|
||||
ebml_w.emit_enum_variant("vtable_static", 0u, 3u, |ebml_w| {
|
||||
ebml_w.emit_enum_variant_arg(0u, |ebml_w| {
|
||||
Ok(ebml_w.emit_def_id(def_id))
|
||||
rbml_w.emit_enum_variant("vtable_static", 0u, 3u, |rbml_w| {
|
||||
rbml_w.emit_enum_variant_arg(0u, |rbml_w| {
|
||||
Ok(rbml_w.emit_def_id(def_id))
|
||||
});
|
||||
ebml_w.emit_enum_variant_arg(1u, |ebml_w| {
|
||||
Ok(ebml_w.emit_substs(ecx, substs))
|
||||
rbml_w.emit_enum_variant_arg(1u, |rbml_w| {
|
||||
Ok(rbml_w.emit_substs(ecx, substs))
|
||||
});
|
||||
ebml_w.emit_enum_variant_arg(2u, |ebml_w| {
|
||||
Ok(encode_vtable_res(ecx, ebml_w, vtable_res))
|
||||
rbml_w.emit_enum_variant_arg(2u, |rbml_w| {
|
||||
Ok(encode_vtable_res(ecx, rbml_w, vtable_res))
|
||||
})
|
||||
})
|
||||
}
|
||||
typeck::vtable_param(pn, bn) => {
|
||||
ebml_w.emit_enum_variant("vtable_param", 1u, 3u, |ebml_w| {
|
||||
ebml_w.emit_enum_variant_arg(0u, |ebml_w| {
|
||||
pn.encode(ebml_w)
|
||||
rbml_w.emit_enum_variant("vtable_param", 1u, 3u, |rbml_w| {
|
||||
rbml_w.emit_enum_variant_arg(0u, |rbml_w| {
|
||||
pn.encode(rbml_w)
|
||||
});
|
||||
ebml_w.emit_enum_variant_arg(1u, |ebml_w| {
|
||||
ebml_w.emit_uint(bn)
|
||||
rbml_w.emit_enum_variant_arg(1u, |rbml_w| {
|
||||
rbml_w.emit_uint(bn)
|
||||
})
|
||||
})
|
||||
}
|
||||
typeck::vtable_unboxed_closure(def_id) => {
|
||||
ebml_w.emit_enum_variant("vtable_unboxed_closure",
|
||||
rbml_w.emit_enum_variant("vtable_unboxed_closure",
|
||||
2u,
|
||||
1u,
|
||||
|ebml_w| {
|
||||
ebml_w.emit_enum_variant_arg(0u, |ebml_w| {
|
||||
Ok(ebml_w.emit_def_id(def_id))
|
||||
|rbml_w| {
|
||||
rbml_w.emit_enum_variant_arg(0u, |rbml_w| {
|
||||
Ok(rbml_w.emit_def_id(def_id))
|
||||
})
|
||||
})
|
||||
}
|
||||
typeck::vtable_error => {
|
||||
ebml_w.emit_enum_variant("vtable_error", 3u, 3u, |_ebml_w| {
|
||||
rbml_w.emit_enum_variant("vtable_error", 3u, 3u, |_rbml_w| {
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
@ -831,12 +830,12 @@ impl<'a> vtable_decoder_helpers for reader::Decoder<'a> {
|
||||
// ___________________________________________________________________________
|
||||
//
|
||||
|
||||
fn encode_vec_per_param_space<T>(ebml_w: &mut Encoder,
|
||||
fn encode_vec_per_param_space<T>(rbml_w: &mut Encoder,
|
||||
v: &subst::VecPerParamSpace<T>,
|
||||
f: |&mut Encoder, &T|) {
|
||||
for &space in subst::ParamSpace::all().iter() {
|
||||
ebml_w.emit_from_vec(v.get_slice(space),
|
||||
|ebml_w, n| Ok(f(ebml_w, n))).unwrap();
|
||||
rbml_w.emit_from_vec(v.get_slice(space),
|
||||
|rbml_w, n| Ok(f(rbml_w, n))).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@ -858,7 +857,7 @@ impl<'a> get_ty_str_ctxt for e::EncodeContext<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
trait ebml_writer_helpers {
|
||||
trait rbml_writer_helpers {
|
||||
fn emit_closure_type(&mut self,
|
||||
ecx: &e::EncodeContext,
|
||||
closure_type: &ty::ClosureTy);
|
||||
@ -874,7 +873,7 @@ trait ebml_writer_helpers {
|
||||
fn emit_auto_adjustment(&mut self, ecx: &e::EncodeContext, adj: &ty::AutoAdjustment);
|
||||
}
|
||||
|
||||
impl<'a> ebml_writer_helpers for Encoder<'a> {
|
||||
impl<'a> rbml_writer_helpers for Encoder<'a> {
|
||||
fn emit_closure_type(&mut self,
|
||||
ecx: &e::EncodeContext,
|
||||
closure_type: &ty::ClosureTy) {
|
||||
@ -980,34 +979,34 @@ impl<'a> write_tag_and_id for Encoder<'a> {
|
||||
|
||||
struct SideTableEncodingIdVisitor<'a,'b> {
|
||||
ecx_ptr: *const libc::c_void,
|
||||
new_ebml_w: &'a mut Encoder<'b>,
|
||||
new_rbml_w: &'a mut Encoder<'b>,
|
||||
}
|
||||
|
||||
impl<'a,'b> ast_util::IdVisitingOperation for
|
||||
SideTableEncodingIdVisitor<'a,'b> {
|
||||
fn visit_id(&self, id: ast::NodeId) {
|
||||
// Note: this will cause a copy of ebml_w, which is bad as
|
||||
// Note: this will cause a copy of rbml_w, which is bad as
|
||||
// it is mutable. But I believe it's harmless since we generate
|
||||
// balanced EBML.
|
||||
//
|
||||
// FIXME(pcwalton): Don't copy this way.
|
||||
let mut new_ebml_w = unsafe {
|
||||
self.new_ebml_w.unsafe_clone()
|
||||
let mut new_rbml_w = unsafe {
|
||||
self.new_rbml_w.unsafe_clone()
|
||||
};
|
||||
// See above
|
||||
let ecx: &e::EncodeContext = unsafe {
|
||||
mem::transmute(self.ecx_ptr)
|
||||
};
|
||||
encode_side_tables_for_id(ecx, &mut new_ebml_w, id)
|
||||
encode_side_tables_for_id(ecx, &mut new_rbml_w, id)
|
||||
}
|
||||
}
|
||||
|
||||
fn encode_side_tables_for_ii(ecx: &e::EncodeContext,
|
||||
ebml_w: &mut Encoder,
|
||||
rbml_w: &mut Encoder,
|
||||
ii: &ast::InlinedItem) {
|
||||
ebml_w.start_tag(c::tag_table as uint);
|
||||
let mut new_ebml_w = unsafe {
|
||||
ebml_w.unsafe_clone()
|
||||
rbml_w.start_tag(c::tag_table as uint);
|
||||
let mut new_rbml_w = unsafe {
|
||||
rbml_w.unsafe_clone()
|
||||
};
|
||||
|
||||
// Because the ast visitor uses @IdVisitingOperation, I can't pass in
|
||||
@ -1017,49 +1016,49 @@ fn encode_side_tables_for_ii(ecx: &e::EncodeContext,
|
||||
ecx_ptr: unsafe {
|
||||
mem::transmute(ecx)
|
||||
},
|
||||
new_ebml_w: &mut new_ebml_w,
|
||||
new_rbml_w: &mut new_rbml_w,
|
||||
});
|
||||
ebml_w.end_tag();
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
|
||||
fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
||||
ebml_w: &mut Encoder,
|
||||
rbml_w: &mut Encoder,
|
||||
id: ast::NodeId) {
|
||||
let tcx = ecx.tcx;
|
||||
|
||||
debug!("Encoding side tables for id {}", id);
|
||||
|
||||
for def in tcx.def_map.borrow().find(&id).iter() {
|
||||
ebml_w.tag(c::tag_table_def, |ebml_w| {
|
||||
ebml_w.id(id);
|
||||
ebml_w.tag(c::tag_table_val, |ebml_w| (*def).encode(ebml_w).unwrap());
|
||||
rbml_w.tag(c::tag_table_def, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| (*def).encode(rbml_w).unwrap());
|
||||
})
|
||||
}
|
||||
|
||||
for &ty in tcx.node_types.borrow().find(&(id as uint)).iter() {
|
||||
ebml_w.tag(c::tag_table_node_type, |ebml_w| {
|
||||
ebml_w.id(id);
|
||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
||||
ebml_w.emit_ty(ecx, *ty);
|
||||
rbml_w.tag(c::tag_table_node_type, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
rbml_w.emit_ty(ecx, *ty);
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
for &item_substs in tcx.item_substs.borrow().find(&id).iter() {
|
||||
ebml_w.tag(c::tag_table_item_subst, |ebml_w| {
|
||||
ebml_w.id(id);
|
||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
||||
ebml_w.emit_substs(ecx, &item_substs.substs);
|
||||
rbml_w.tag(c::tag_table_item_subst, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
rbml_w.emit_substs(ecx, &item_substs.substs);
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
for &fv in tcx.freevars.borrow().find(&id).iter() {
|
||||
ebml_w.tag(c::tag_table_freevars, |ebml_w| {
|
||||
ebml_w.id(id);
|
||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
||||
ebml_w.emit_from_vec(fv.as_slice(), |ebml_w, fv_entry| {
|
||||
Ok(encode_freevar_entry(ebml_w, fv_entry))
|
||||
rbml_w.tag(c::tag_table_freevars, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
rbml_w.emit_from_vec(fv.as_slice(), |rbml_w, fv_entry| {
|
||||
Ok(encode_freevar_entry(rbml_w, fv_entry))
|
||||
});
|
||||
})
|
||||
})
|
||||
@ -1067,38 +1066,38 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
||||
|
||||
let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id };
|
||||
for &pty in tcx.tcache.borrow().find(&lid).iter() {
|
||||
ebml_w.tag(c::tag_table_tcache, |ebml_w| {
|
||||
ebml_w.id(id);
|
||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
||||
ebml_w.emit_polytype(ecx, pty.clone());
|
||||
rbml_w.tag(c::tag_table_tcache, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
rbml_w.emit_polytype(ecx, pty.clone());
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
for &type_param_def in tcx.ty_param_defs.borrow().find(&id).iter() {
|
||||
ebml_w.tag(c::tag_table_param_defs, |ebml_w| {
|
||||
ebml_w.id(id);
|
||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
||||
ebml_w.emit_type_param_def(ecx, type_param_def)
|
||||
rbml_w.tag(c::tag_table_param_defs, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
rbml_w.emit_type_param_def(ecx, type_param_def)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
let method_call = MethodCall::expr(id);
|
||||
for &method in tcx.method_map.borrow().find(&method_call).iter() {
|
||||
ebml_w.tag(c::tag_table_method_map, |ebml_w| {
|
||||
ebml_w.id(id);
|
||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
||||
encode_method_callee(ecx, ebml_w, method_call.adjustment, method)
|
||||
rbml_w.tag(c::tag_table_method_map, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
encode_method_callee(ecx, rbml_w, method_call.adjustment, method)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
for &dr in tcx.vtable_map.borrow().find(&method_call).iter() {
|
||||
ebml_w.tag(c::tag_table_vtable_map, |ebml_w| {
|
||||
ebml_w.id(id);
|
||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
||||
encode_vtable_res_with_key(ecx, ebml_w, method_call.adjustment, dr);
|
||||
rbml_w.tag(c::tag_table_vtable_map, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
encode_vtable_res_with_key(ecx, rbml_w, method_call.adjustment, dr);
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -1109,20 +1108,20 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
||||
for autoderef in range(0, adj.autoderefs) {
|
||||
let method_call = MethodCall::autoderef(id, autoderef);
|
||||
for &method in tcx.method_map.borrow().find(&method_call).iter() {
|
||||
ebml_w.tag(c::tag_table_method_map, |ebml_w| {
|
||||
ebml_w.id(id);
|
||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
||||
encode_method_callee(ecx, ebml_w,
|
||||
rbml_w.tag(c::tag_table_method_map, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
encode_method_callee(ecx, rbml_w,
|
||||
method_call.adjustment, method)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
for &dr in tcx.vtable_map.borrow().find(&method_call).iter() {
|
||||
ebml_w.tag(c::tag_table_vtable_map, |ebml_w| {
|
||||
ebml_w.id(id);
|
||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
||||
encode_vtable_res_with_key(ecx, ebml_w,
|
||||
rbml_w.tag(c::tag_table_vtable_map, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
encode_vtable_res_with_key(ecx, rbml_w,
|
||||
method_call.adjustment, dr);
|
||||
})
|
||||
})
|
||||
@ -1132,19 +1131,19 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
||||
ty::AutoObject(..) => {
|
||||
let method_call = MethodCall::autoobject(id);
|
||||
for &method in tcx.method_map.borrow().find(&method_call).iter() {
|
||||
ebml_w.tag(c::tag_table_method_map, |ebml_w| {
|
||||
ebml_w.id(id);
|
||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
||||
encode_method_callee(ecx, ebml_w, method_call.adjustment, method)
|
||||
rbml_w.tag(c::tag_table_method_map, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
encode_method_callee(ecx, rbml_w, method_call.adjustment, method)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
for &dr in tcx.vtable_map.borrow().find(&method_call).iter() {
|
||||
ebml_w.tag(c::tag_table_vtable_map, |ebml_w| {
|
||||
ebml_w.id(id);
|
||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
||||
encode_vtable_res_with_key(ecx, ebml_w, method_call.adjustment, dr);
|
||||
rbml_w.tag(c::tag_table_vtable_map, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
encode_vtable_res_with_key(ecx, rbml_w, method_call.adjustment, dr);
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -1152,10 +1151,10 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
||||
_ => {}
|
||||
}
|
||||
|
||||
ebml_w.tag(c::tag_table_adjustments, |ebml_w| {
|
||||
ebml_w.id(id);
|
||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
||||
ebml_w.emit_auto_adjustment(ecx, adj);
|
||||
rbml_w.tag(c::tag_table_adjustments, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
rbml_w.emit_auto_adjustment(ecx, adj);
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -1164,10 +1163,10 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
||||
.borrow()
|
||||
.find(&ast_util::local_def(id))
|
||||
.iter() {
|
||||
ebml_w.tag(c::tag_table_unboxed_closure_type, |ebml_w| {
|
||||
ebml_w.id(id);
|
||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
||||
ebml_w.emit_closure_type(ecx, *unboxed_closure_type)
|
||||
rbml_w.tag(c::tag_table_unboxed_closure_type, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||
rbml_w.emit_closure_type(ecx, *unboxed_closure_type)
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -1178,14 +1177,14 @@ trait doc_decoder_helpers {
|
||||
fn opt_child(&self, tag: c::astencode_tag) -> Option<Self>;
|
||||
}
|
||||
|
||||
impl<'a> doc_decoder_helpers for ebml::Doc<'a> {
|
||||
impl<'a> doc_decoder_helpers for rbml::Doc<'a> {
|
||||
fn as_int(&self) -> int { reader::doc_as_u64(*self) as int }
|
||||
fn opt_child(&self, tag: c::astencode_tag) -> Option<ebml::Doc<'a>> {
|
||||
fn opt_child(&self, tag: c::astencode_tag) -> Option<rbml::Doc<'a>> {
|
||||
reader::maybe_get_doc(*self, tag as uint)
|
||||
}
|
||||
}
|
||||
|
||||
trait ebml_decoder_decoder_helpers {
|
||||
trait rbml_decoder_decoder_helpers {
|
||||
fn read_ty(&mut self, xcx: &ExtendedDecodeContext) -> ty::t;
|
||||
fn read_tys(&mut self, xcx: &ExtendedDecodeContext) -> Vec<ty::t>;
|
||||
fn read_type_param_def(&mut self, xcx: &ExtendedDecodeContext)
|
||||
@ -1214,7 +1213,7 @@ trait ebml_decoder_decoder_helpers {
|
||||
-> subst::Substs;
|
||||
}
|
||||
|
||||
impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> {
|
||||
impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> {
|
||||
fn read_ty_noxcx(&mut self,
|
||||
tcx: &ty::ctxt, cdata: &cstore::crate_metadata) -> ty::t {
|
||||
self.read_opaque(|_, doc| {
|
||||
@ -1270,7 +1269,7 @@ impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> {
|
||||
Ok(ty)
|
||||
}).unwrap();
|
||||
|
||||
fn type_string(doc: ebml::Doc) -> String {
|
||||
fn type_string(doc: rbml::Doc) -> String {
|
||||
let mut str = String::new();
|
||||
for i in range(doc.start, doc.end) {
|
||||
str.push_char(doc.data[i] as char);
|
||||
@ -1423,7 +1422,7 @@ impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> {
|
||||
}
|
||||
|
||||
fn decode_side_tables(xcx: &ExtendedDecodeContext,
|
||||
ast_doc: ebml::Doc) {
|
||||
ast_doc: rbml::Doc) {
|
||||
let dcx = xcx.dcx;
|
||||
let tbl_doc = ast_doc.get(c::tag_table as uint);
|
||||
reader::docs(tbl_doc, |tag, entry_doc| {
|
||||
@ -1527,14 +1526,14 @@ fn decode_side_tables(xcx: &ExtendedDecodeContext,
|
||||
// Testing of astencode_gen
|
||||
|
||||
#[cfg(test)]
|
||||
fn encode_item_ast(ebml_w: &mut Encoder, item: Gc<ast::Item>) {
|
||||
ebml_w.start_tag(c::tag_tree as uint);
|
||||
(*item).encode(ebml_w);
|
||||
ebml_w.end_tag();
|
||||
fn encode_item_ast(rbml_w: &mut Encoder, item: Gc<ast::Item>) {
|
||||
rbml_w.start_tag(c::tag_tree as uint);
|
||||
(*item).encode(rbml_w);
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn decode_item_ast(par_doc: ebml::Doc) -> Gc<ast::Item> {
|
||||
fn decode_item_ast(par_doc: rbml::Doc) -> Gc<ast::Item> {
|
||||
let chi_doc = par_doc.get(c::tag_tree as uint);
|
||||
let mut d = reader::Decoder::new(chi_doc);
|
||||
box(GC) Decodable::decode(&mut d).unwrap()
|
||||
@ -1576,11 +1575,11 @@ fn roundtrip(in_item: Option<Gc<ast::Item>>) {
|
||||
let in_item = in_item.unwrap();
|
||||
let mut wr = SeekableMemWriter::new();
|
||||
{
|
||||
let mut ebml_w = writer::Encoder::new(&mut wr);
|
||||
encode_item_ast(&mut ebml_w, in_item);
|
||||
let mut rbml_w = writer::Encoder::new(&mut wr);
|
||||
encode_item_ast(&mut rbml_w, in_item);
|
||||
}
|
||||
let ebml_doc = ebml::Doc::new(wr.get_ref());
|
||||
let out_item = decode_item_ast(ebml_doc);
|
||||
let rbml_doc = rbml::Doc::new(wr.get_ref());
|
||||
let out_item = decode_item_ast(rbml_doc);
|
||||
|
||||
assert!(in_item == out_item);
|
||||
}
|
||||
|
@ -2593,7 +2593,7 @@ pub fn write_metadata(cx: &CrateContext, krate: &ast::Crate) -> Vec<u8> {
|
||||
}
|
||||
|
||||
let encode_inlined_item: encoder::EncodeInlinedItem =
|
||||
|ecx, ebml_w, ii| astencode::encode_inlined_item(ecx, ebml_w, ii);
|
||||
|ecx, rbml_w, ii| astencode::encode_inlined_item(ecx, rbml_w, ii);
|
||||
|
||||
let encode_parms = crate_ctxt_to_encode_parms(cx, encode_inlined_item);
|
||||
let metadata = encoder::encode_metadata(encode_parms, krate);
|
||||
|
@ -39,6 +39,5 @@ mod serialize;
|
||||
mod collection_impls;
|
||||
|
||||
pub mod base64;
|
||||
pub mod ebml;
|
||||
pub mod hex;
|
||||
pub mod json;
|
||||
|
@ -10,33 +10,33 @@
|
||||
|
||||
// ignore-test FIXME(#5121)
|
||||
|
||||
|
||||
extern crate time;
|
||||
extern crate rbml;
|
||||
extern crate serialize;
|
||||
extern crate time;
|
||||
|
||||
// These tests used to be separate files, but I wanted to refactor all
|
||||
// the common code.
|
||||
|
||||
use std::hashmap::{HashMap, HashSet};
|
||||
|
||||
use EBReader = serialize::ebml::reader;
|
||||
use EBWriter = serialize::ebml::writer;
|
||||
use EBReader = rbml::reader;
|
||||
use EBWriter = rbml::writer;
|
||||
use std::cmp::Eq;
|
||||
use std::cmp;
|
||||
use std::io;
|
||||
use serialize::{Decodable, Encodable};
|
||||
|
||||
fn test_ebml<'a, 'b, A:
|
||||
fn test_rbml<'a, 'b, A:
|
||||
Eq +
|
||||
Encodable<EBWriter::Encoder<'a>> +
|
||||
Decodable<EBReader::Decoder<'b>>
|
||||
>(a1: &A) {
|
||||
let mut wr = std::io::MemWriter::new();
|
||||
let mut ebml_w = EBwriter::Encoder::new(&mut wr);
|
||||
a1.encode(&mut ebml_w);
|
||||
let mut rbml_w = EBwriter::Encoder::new(&mut wr);
|
||||
a1.encode(&mut rbml_w);
|
||||
let bytes = wr.get_ref();
|
||||
|
||||
let d: serialize::ebml::Doc<'a> = EBDoc::new(bytes);
|
||||
let d: serialize::rbml::Doc<'a> = EBDoc::new(bytes);
|
||||
let mut decoder: EBReader::Decoder<'a> = EBreader::Decoder::new(d);
|
||||
let a2: A = Decodable::decode(&mut decoder);
|
||||
assert!(*a1 == a2);
|
||||
@ -133,40 +133,40 @@ enum CLike { A, B, C }
|
||||
|
||||
pub fn main() {
|
||||
let a = &Plus(@Minus(@Val(3u), @Val(10u)), @Plus(@Val(22u), @Val(5u)));
|
||||
test_ebml(a);
|
||||
test_rbml(a);
|
||||
|
||||
let a = &Spanned {lo: 0u, hi: 5u, node: 22u};
|
||||
test_ebml(a);
|
||||
test_rbml(a);
|
||||
|
||||
let a = &Point {x: 3u, y: 5u};
|
||||
test_ebml(a);
|
||||
test_rbml(a);
|
||||
|
||||
let a = &Top(22u);
|
||||
test_ebml(a);
|
||||
test_rbml(a);
|
||||
|
||||
let a = &Bottom(222u);
|
||||
test_ebml(a);
|
||||
test_rbml(a);
|
||||
|
||||
let a = &A;
|
||||
test_ebml(a);
|
||||
test_rbml(a);
|
||||
|
||||
let a = &B;
|
||||
test_ebml(a);
|
||||
test_rbml(a);
|
||||
|
||||
let a = &time::now();
|
||||
test_ebml(a);
|
||||
test_rbml(a);
|
||||
|
||||
test_ebml(&1.0f32);
|
||||
test_ebml(&1.0f64);
|
||||
test_ebml(&'a');
|
||||
test_rbml(&1.0f32);
|
||||
test_rbml(&1.0f64);
|
||||
test_rbml(&'a');
|
||||
|
||||
let mut a = HashMap::new();
|
||||
test_ebml(&a);
|
||||
test_rbml(&a);
|
||||
a.insert(1, 2);
|
||||
test_ebml(&a);
|
||||
test_rbml(&a);
|
||||
|
||||
let mut a = HashSet::new();
|
||||
test_ebml(&a);
|
||||
test_rbml(&a);
|
||||
a.insert(1);
|
||||
test_ebml(&a);
|
||||
test_rbml(&a);
|
||||
}
|
||||
|
@ -16,15 +16,16 @@
|
||||
#![feature(struct_variant)]
|
||||
|
||||
extern crate rand;
|
||||
extern crate rbml;
|
||||
extern crate serialize;
|
||||
|
||||
use std::io::MemWriter;
|
||||
use rand::{random, Rand};
|
||||
use rbml;
|
||||
use rbml::Doc;
|
||||
use rbml::writer::Encoder;
|
||||
use rbml::reader::Decoder;
|
||||
use serialize::{Encodable, Decodable};
|
||||
use serialize::ebml;
|
||||
use serialize::ebml::Doc;
|
||||
use serialize::ebml::writer::Encoder;
|
||||
use serialize::ebml::reader::Decoder;
|
||||
|
||||
#[deriving(Encodable, Decodable, Eq, Rand)]
|
||||
struct A;
|
||||
@ -61,7 +62,7 @@ fn roundtrip<'a, T: Rand + Eq + Encodable<Encoder<'a>> +
|
||||
let mut w = MemWriter::new();
|
||||
let mut e = Encoder::new(&mut w);
|
||||
obj.encode(&mut e);
|
||||
let doc = ebml::Doc::new(@w.get_ref());
|
||||
let doc = rbml::Doc::new(@w.get_ref());
|
||||
let mut dec = Decoder::new(doc);
|
||||
let obj2 = Decodable::decode(&mut dec);
|
||||
assert!(obj == obj2);
|
||||
|
@ -8,6 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
extern crate rbml;
|
||||
extern crate serialize;
|
||||
|
||||
use std::io;
|
||||
@ -16,7 +17,7 @@ use std::slice;
|
||||
|
||||
use serialize::{Encodable, Encoder};
|
||||
use serialize::json;
|
||||
use serialize::ebml::writer;
|
||||
use rbml::writer;
|
||||
|
||||
static BUF_CAPACITY: uint = 128;
|
||||
|
||||
@ -144,7 +145,7 @@ struct Bar {
|
||||
|
||||
enum WireProtocol {
|
||||
JSON,
|
||||
EBML,
|
||||
RBML,
|
||||
// ...
|
||||
}
|
||||
|
||||
@ -155,7 +156,7 @@ fn encode_json<'a,
|
||||
let mut encoder = json::Encoder::new(wr);
|
||||
val.encode(&mut encoder);
|
||||
}
|
||||
fn encode_ebml<'a,
|
||||
fn encode_rbml<'a,
|
||||
T: Encodable<writer::Encoder<'a, SeekableMemWriter>,
|
||||
std::io::IoError>>(val: &T,
|
||||
wr: &'a mut SeekableMemWriter) {
|
||||
@ -169,6 +170,6 @@ pub fn main() {
|
||||
let proto = JSON;
|
||||
match proto {
|
||||
JSON => encode_json(&target, &mut wr),
|
||||
EBML => encode_ebml(&target, &mut wr)
|
||||
RBML => encode_rbml(&target, &mut wr)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user