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 \
|
TARGET_CRATES := libc std green rustuv native flate arena glob term semver \
|
||||||
uuid serialize sync getopts collections num test time rand \
|
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
|
unicode
|
||||||
HOST_CRATES := syntax rustc rustdoc fourcc hexfloat regex_macros fmt_macros \
|
HOST_CRATES := syntax rustc rustdoc fourcc hexfloat regex_macros fmt_macros \
|
||||||
rustc_llvm rustc_back
|
rustc_llvm rustc_back
|
||||||
@ -71,7 +71,7 @@ DEPS_green := std native:context_switch
|
|||||||
DEPS_rustuv := std native:uv native:uv_support
|
DEPS_rustuv := std native:uv native:uv_support
|
||||||
DEPS_native := std
|
DEPS_native := std
|
||||||
DEPS_syntax := std term serialize log fmt_macros debug
|
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
|
time log graphviz debug rustc_llvm rustc_back
|
||||||
DEPS_rustc_llvm := native:rustllvm libc std
|
DEPS_rustc_llvm := native:rustllvm libc std
|
||||||
DEPS_rustc_back := std syntax rustc_llvm flate log libc
|
DEPS_rustc_back := std syntax rustc_llvm flate log libc
|
||||||
@ -82,6 +82,7 @@ DEPS_arena := std
|
|||||||
DEPS_graphviz := std
|
DEPS_graphviz := std
|
||||||
DEPS_glob := std
|
DEPS_glob := std
|
||||||
DEPS_serialize := std log
|
DEPS_serialize := std log
|
||||||
|
DEPS_rbml := std log serialize
|
||||||
DEPS_term := std log
|
DEPS_term := std log
|
||||||
DEPS_semver := std
|
DEPS_semver := std
|
||||||
DEPS_uuid := std serialize
|
DEPS_uuid := std serialize
|
||||||
@ -91,7 +92,7 @@ DEPS_collections := core alloc unicode
|
|||||||
DEPS_fourcc := rustc syntax std
|
DEPS_fourcc := rustc syntax std
|
||||||
DEPS_hexfloat := rustc syntax std
|
DEPS_hexfloat := rustc syntax std
|
||||||
DEPS_num := 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_time := std serialize
|
||||||
DEPS_rand := core
|
DEPS_rand := core
|
||||||
DEPS_url := std
|
DEPS_url := std
|
||||||
|
@ -8,16 +8,35 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// 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)]
|
#![allow(missing_doc)]
|
||||||
|
|
||||||
|
extern crate serialize;
|
||||||
|
|
||||||
|
#[phase(plugin, link)] extern crate log;
|
||||||
|
#[cfg(test)] extern crate test;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::str;
|
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)]
|
#[deriving(Clone)]
|
||||||
pub struct Doc<'a> {
|
pub struct Doc<'a> {
|
||||||
pub data: &'a [u8],
|
pub data: &'a [u8],
|
||||||
@ -107,7 +126,7 @@ pub mod reader {
|
|||||||
Expected };
|
Expected };
|
||||||
|
|
||||||
pub type DecodeResult<T> = Result<T, Error>;
|
pub type DecodeResult<T> = Result<T, Error>;
|
||||||
// ebml reading
|
// rbml reading
|
||||||
|
|
||||||
macro_rules! try_or(
|
macro_rules! try_or(
|
||||||
($e:expr, $r:expr) => (
|
($e:expr, $r:expr) => (
|
||||||
@ -637,7 +656,7 @@ pub mod writer {
|
|||||||
|
|
||||||
pub type EncodeResult = io::IoResult<()>;
|
pub type EncodeResult = io::IoResult<()>;
|
||||||
|
|
||||||
// ebml writing
|
// rbml writing
|
||||||
pub struct Encoder<'a, W> {
|
pub struct Encoder<'a, W> {
|
||||||
pub writer: &'a mut W,
|
pub writer: &'a mut W,
|
||||||
size_positions: Vec<uint>,
|
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> {
|
impl<'a, W: Writer + Seek> Encoder<'a, W> {
|
||||||
pub fn new(w: &'a mut W) -> Encoder<'a, W> {
|
pub fn new(w: &'a mut W) -> Encoder<'a, W> {
|
||||||
Encoder {
|
Encoder {
|
||||||
@ -1018,10 +1037,8 @@ pub mod writer {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::Doc;
|
use super::{Doc, reader, writer};
|
||||||
use ebml::reader;
|
use serialize::{Encodable, Decodable};
|
||||||
use ebml::writer;
|
|
||||||
use {Encodable, Decodable};
|
|
||||||
|
|
||||||
use std::io::{IoError, IoResult, SeekStyle};
|
use std::io::{IoError, IoResult, SeekStyle};
|
||||||
use std::io;
|
use std::io;
|
||||||
@ -1196,11 +1213,11 @@ mod tests {
|
|||||||
debug!("v == {}", v);
|
debug!("v == {}", v);
|
||||||
let mut wr = SeekableMemWriter::new();
|
let mut wr = SeekableMemWriter::new();
|
||||||
{
|
{
|
||||||
let mut ebml_w = writer::Encoder::new(&mut wr);
|
let mut rbml_w = writer::Encoder::new(&mut wr);
|
||||||
let _ = v.encode(&mut ebml_w);
|
let _ = v.encode(&mut rbml_w);
|
||||||
}
|
}
|
||||||
let ebml_doc = Doc::new(wr.get_ref());
|
let rbml_doc = Doc::new(wr.get_ref());
|
||||||
let mut deser = reader::Decoder::new(ebml_doc);
|
let mut deser = reader::Decoder::new(rbml_doc);
|
||||||
let v1 = Decodable::decode(&mut deser).unwrap();
|
let v1 = Decodable::decode(&mut deser).unwrap();
|
||||||
debug!("v1 == {}", v1);
|
debug!("v1 == {}", v1);
|
||||||
assert_eq!(v, v1);
|
assert_eq!(v, v1);
|
||||||
@ -1215,9 +1232,8 @@ mod tests {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod bench {
|
mod bench {
|
||||||
#![allow(non_snake_case_functions)]
|
#![allow(non_snake_case_functions)]
|
||||||
extern crate test;
|
use test::Bencher;
|
||||||
use self::test::Bencher;
|
use super::reader;
|
||||||
use ebml::reader;
|
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
pub fn vuint_at_A_aligned(b: &mut Bencher) {
|
pub fn vuint_at_A_aligned(b: &mut Bencher) {
|
@ -44,6 +44,7 @@ extern crate libc;
|
|||||||
extern crate llvm = "rustc_llvm";
|
extern crate llvm = "rustc_llvm";
|
||||||
extern crate rustc_back = "rustc_back";
|
extern crate rustc_back = "rustc_back";
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
|
extern crate rbml;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
#[phase(plugin, link)] extern crate log;
|
#[phase(plugin, link)] extern crate log;
|
||||||
#[phase(plugin, link)] extern crate syntax;
|
#[phase(plugin, link)] extern crate syntax;
|
||||||
|
@ -20,8 +20,8 @@ use middle::ty;
|
|||||||
use middle::typeck;
|
use middle::typeck;
|
||||||
use middle::subst::VecPerParamSpace;
|
use middle::subst::VecPerParamSpace;
|
||||||
|
|
||||||
use serialize::ebml;
|
use rbml;
|
||||||
use serialize::ebml::reader;
|
use rbml::reader;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::ast_map;
|
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 {
|
def: ast::DefId) -> ty::Polytype {
|
||||||
let cstore = &tcx.sess.cstore;
|
let cstore = &tcx.sess.cstore;
|
||||||
let cdata = cstore.get_crate_data(class_id.krate);
|
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(),
|
let class_doc = expect(tcx.sess.diagnostic(),
|
||||||
decoder::maybe_find_item(class_id.node, all_items),
|
decoder::maybe_find_item(class_id.node, all_items),
|
||||||
|| {
|
|| {
|
||||||
|
@ -37,8 +37,8 @@ use std::io;
|
|||||||
use std::collections::hashmap::HashMap;
|
use std::collections::hashmap::HashMap;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::u64;
|
use std::u64;
|
||||||
use serialize::ebml::reader;
|
use rbml::reader;
|
||||||
use serialize::ebml;
|
use rbml;
|
||||||
use serialize::Decodable;
|
use serialize::Decodable;
|
||||||
use syntax::ast_map;
|
use syntax::ast_map;
|
||||||
use syntax::attr;
|
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
|
// what crate that's in and give us a def_id that makes sense for the current
|
||||||
// build.
|
// build.
|
||||||
|
|
||||||
fn lookup_hash<'a>(d: ebml::Doc<'a>, eq_fn: |&[u8]| -> bool,
|
fn lookup_hash<'a>(d: rbml::Doc<'a>, eq_fn: |&[u8]| -> bool,
|
||||||
hash: u64) -> Option<ebml::Doc<'a>> {
|
hash: u64) -> Option<rbml::Doc<'a>> {
|
||||||
let index = reader::get_doc(d, tag_index);
|
let index = reader::get_doc(d, tag_index);
|
||||||
let table = reader::get_doc(index, tag_index_table);
|
let table = reader::get_doc(index, tag_index_table);
|
||||||
let hash_pos = table.start + (hash % 256 * 4) as uint;
|
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,
|
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 {
|
fn eq_item(bytes: &[u8], item_id: ast::NodeId) -> bool {
|
||||||
return u64_from_be_bytes(
|
return u64_from_be_bytes(
|
||||||
bytes.slice(0u, 4u), 0u, 4u) as ast::NodeId
|
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)))
|
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) {
|
match maybe_find_item(item_id, items) {
|
||||||
None => fail!("lookup_item: id not found: {}", item_id),
|
None => fail!("lookup_item: id not found: {}", item_id),
|
||||||
Some(d) => d
|
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.
|
// to the item data.
|
||||||
fn lookup_item<'a>(item_id: ast::NodeId, data: &'a [u8]) -> ebml::Doc<'a> {
|
fn lookup_item<'a>(item_id: ast::NodeId, data: &'a [u8]) -> rbml::Doc<'a> {
|
||||||
let items = reader::get_doc(ebml::Doc::new(data), tag_items);
|
let items = reader::get_doc(rbml::Doc::new(data), tag_items);
|
||||||
find_item(item_id, items)
|
find_item(item_id, items)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ enum Family {
|
|||||||
InheritedField // N
|
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);
|
let fam = reader::get_doc(item, tag_items_data_item_family);
|
||||||
match reader::doc_as_u8(fam) as char {
|
match reader::doc_as_u8(fam) as char {
|
||||||
'c' => ImmStatic,
|
'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) {
|
match reader::maybe_get_doc(item, tag_items_data_item_visibility) {
|
||||||
None => ast::Public,
|
None => ast::Public,
|
||||||
Some(visibility_doc) => {
|
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';
|
let mut ret = 'r';
|
||||||
reader::tagged_docs(item, tag_item_trait_method_sort, |doc| {
|
reader::tagged_docs(item, tag_item_trait_method_sort, |doc| {
|
||||||
ret = doc.as_str_slice().as_bytes()[0] as char;
|
ret = doc.as_str_slice().as_bytes()[0] as char;
|
||||||
@ -174,11 +174,11 @@ fn item_method_sort(item: ebml::Doc) -> char {
|
|||||||
ret
|
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()
|
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;
|
let mut ret = None;
|
||||||
reader::tagged_docs(d, tag_items_data_parent_item, |did| {
|
reader::tagged_docs(d, tag_items_data_parent_item, |did| {
|
||||||
ret = Some(reader::with_doc_data(did, parse_def_id));
|
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,
|
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");
|
let trait_did = item_parent_item(d).expect("item without parent");
|
||||||
ast::DefId { krate: cnum, node: trait_did.node }
|
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);
|
let tagdoc = reader::get_doc(d, tag_def_id);
|
||||||
return translate_def_id(cdata, reader::with_doc_data(tagdoc, parse_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| {
|
reader::maybe_get_doc(d, tag_item_method_provided_source).map(|doc| {
|
||||||
translate_def_id(cdata, reader::with_doc_data(doc, parse_def_id))
|
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)
|
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::maybe_get_doc(d, tag_disr_val).and_then(|val_doc| {
|
||||||
reader::with_doc_data(val_doc, |data| u64::parse_bytes(data, 10u))
|
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);
|
let tp = reader::get_doc(doc, tag_items_data_item_type);
|
||||||
parse_ty_data(tp.data, cdata.cnum, tp.start, tcx,
|
parse_ty_data(tp.data, cdata.cnum, tp.start, tcx,
|
||||||
|_, did| translate_def_id(cdata, did))
|
|_, 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);
|
let tp = reader::get_doc(doc, tag_item_method_fty);
|
||||||
parse_bare_fn_ty_data(tp.data, cdata.cnum, tp.start, tcx,
|
parse_bare_fn_ty_data(tp.data, cdata.cnum, tp.start, tcx,
|
||||||
|_, did| translate_def_id(cdata, did))
|
|_, 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 {
|
tcx: &ty::ctxt, cdata: Cmd) -> ty::t {
|
||||||
doc_type(item, tcx, cdata)
|
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,
|
parse_trait_ref_data(doc.data, cdata.cnum, doc.start, tcx,
|
||||||
|_, did| translate_def_id(cdata, did))
|
|_, 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);
|
let tp = reader::get_doc(doc, tag_item_trait_ref);
|
||||||
doc_trait_ref(tp, tcx, cdata)
|
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,
|
tcx: &ty::ctxt,
|
||||||
cdata: Cmd,
|
cdata: Cmd,
|
||||||
tag: uint)
|
tag: uint)
|
||||||
@ -257,7 +257,7 @@ fn item_ty_param_defs(item: ebml::Doc,
|
|||||||
bounds
|
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>
|
-> subst::VecPerParamSpace<ty::RegionParameterDef>
|
||||||
{
|
{
|
||||||
let mut v = subst::VecPerParamSpace::empty();
|
let mut v = subst::VecPerParamSpace::empty();
|
||||||
@ -285,7 +285,7 @@ fn item_region_param_defs(item_doc: ebml::Doc, cdata: Cmd)
|
|||||||
v
|
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 mut ids: Vec<ast::DefId> = Vec::new();
|
||||||
let v = tag_items_data_item_variant;
|
let v = tag_items_data_item_variant;
|
||||||
reader::tagged_docs(item, v, |p| {
|
reader::tagged_docs(item, v, |p| {
|
||||||
@ -296,7 +296,7 @@ fn enum_variant_ids(item: ebml::Doc, cdata: Cmd) -> Vec<ast::DefId> {
|
|||||||
return ids;
|
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 path_doc = reader::get_doc(item_doc, tag_path);
|
||||||
|
|
||||||
let len_doc = reader::get_doc(path_doc, tag_path_len);
|
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
|
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 name = reader::get_doc(item, tag_paths_data_name);
|
||||||
let string = name.as_str_slice();
|
let string = name.as_str_slice();
|
||||||
match intr.find_equiv(&string) {
|
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 {
|
-> DefLike {
|
||||||
let fam = item_family(item);
|
let fam = item_family(item);
|
||||||
match fam {
|
match fam {
|
||||||
@ -463,7 +463,7 @@ pub enum DefLike {
|
|||||||
|
|
||||||
/// Iterates over the language items in the given crate.
|
/// Iterates over the language items in the given crate.
|
||||||
pub fn each_lang_item(cdata: Cmd, f: |ast::NodeId, uint| -> bool) -> bool {
|
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);
|
let lang_items = reader::get_doc(root, tag_lang_items);
|
||||||
reader::tagged_docs(lang_items, tag_lang_items_item, |item_doc| {
|
reader::tagged_docs(lang_items, tag_lang_items_item, |item_doc| {
|
||||||
let id_doc = reader::get_doc(item_doc, tag_lang_items_item_id);
|
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>,
|
fn each_child_of_item_or_crate(intr: Rc<IdentInterner>,
|
||||||
cdata: Cmd,
|
cdata: Cmd,
|
||||||
item_doc: ebml::Doc,
|
item_doc: rbml::Doc,
|
||||||
get_crate_data: GetCrateDataCb,
|
get_crate_data: GetCrateDataCb,
|
||||||
callback: |DefLike,
|
callback: |DefLike,
|
||||||
ast::Ident,
|
ast::Ident,
|
||||||
@ -503,7 +503,7 @@ fn each_child_of_item_or_crate(intr: Rc<IdentInterner>,
|
|||||||
None => cdata
|
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.
|
// Get the item.
|
||||||
match maybe_find_item(child_def_id.node, other_crates_items) {
|
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| {
|
|inherent_impl_def_id_doc| {
|
||||||
let inherent_impl_def_id = item_def_id(inherent_impl_def_id_doc,
|
let inherent_impl_def_id = item_def_id(inherent_impl_def_id_doc,
|
||||||
cdata);
|
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) {
|
match maybe_find_item(inherent_impl_def_id.node, items) {
|
||||||
None => {}
|
None => {}
|
||||||
Some(inherent_impl_doc) => {
|
Some(inherent_impl_doc) => {
|
||||||
@ -596,7 +596,7 @@ fn each_child_of_item_or_crate(intr: Rc<IdentInterner>,
|
|||||||
None => cdata
|
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.
|
// Get the item.
|
||||||
match maybe_find_item(child_def_id.node, other_crates_items) {
|
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,
|
get_crate_data: GetCrateDataCb,
|
||||||
callback: |DefLike, ast::Ident, ast::Visibility|) {
|
callback: |DefLike, ast::Ident, ast::Visibility|) {
|
||||||
// Find the item.
|
// 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 items = reader::get_doc(root_doc, tag_items);
|
||||||
let item_doc = match maybe_find_item(id, items) {
|
let item_doc = match maybe_find_item(id, items) {
|
||||||
None => return,
|
None => return,
|
||||||
@ -644,7 +644,7 @@ pub fn each_top_level_item_of_crate(intr: Rc<IdentInterner>,
|
|||||||
callback: |DefLike,
|
callback: |DefLike,
|
||||||
ast::Ident,
|
ast::Ident,
|
||||||
ast::Visibility|) {
|
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 misc_info_doc = reader::get_doc(root_doc, tag_misc_info);
|
||||||
let crate_items_doc = reader::get_doc(misc_info_doc,
|
let crate_items_doc = reader::get_doc(misc_info_doc,
|
||||||
tag_misc_info_crate_items);
|
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,
|
pub type DecodeInlinedItem<'a> = |cdata: Cmd,
|
||||||
tcx: &ty::ctxt,
|
tcx: &ty::ctxt,
|
||||||
path: Vec<ast_map::PathElem>,
|
path: Vec<ast_map::PathElem>,
|
||||||
par_doc: ebml::Doc|: 'a
|
par_doc: rbml::Doc|: 'a
|
||||||
-> Result<ast::InlinedItem, Vec<ast_map::PathElem> >;
|
-> Result<ast::InlinedItem, Vec<ast_map::PathElem> >;
|
||||||
|
|
||||||
pub fn maybe_get_item_ast(cdata: Cmd, tcx: &ty::ctxt, id: ast::NodeId,
|
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,
|
pub fn get_enum_variants(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId,
|
||||||
tcx: &ty::ctxt) -> Vec<Rc<ty::VariantInfo>> {
|
tcx: &ty::ctxt) -> Vec<Rc<ty::VariantInfo>> {
|
||||||
let data = cdata.data();
|
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 item = find_item(id, items);
|
||||||
let mut disr_val = 0;
|
let mut disr_val = 0;
|
||||||
enum_variant_ids(item, cdata).iter().map(|did| {
|
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()
|
}).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 {
|
fn get_mutability(ch: u8) -> ast::Mutability {
|
||||||
match ch as char {
|
match ch as char {
|
||||||
'i' => ast::MutImmutable,
|
'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>> {
|
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 fields = reader::get_doc(data, tag_struct_fields);
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
reader::tagged_docs(fields, tag_struct_field, |field| {
|
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
|
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();
|
let mut items: Vec<Gc<ast::MetaItem>> = Vec::new();
|
||||||
reader::tagged_docs(md, tag_meta_item_word, |meta_item_doc| {
|
reader::tagged_docs(md, tag_meta_item_word, |meta_item_doc| {
|
||||||
let nd = reader::get_doc(meta_item_doc, tag_meta_item_name);
|
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;
|
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();
|
let mut attrs: Vec<ast::Attribute> = Vec::new();
|
||||||
match reader::maybe_get_doc(md, tag_attributes) {
|
match reader::maybe_get_doc(md, tag_attributes) {
|
||||||
Some(attrs_d) => {
|
Some(attrs_d) => {
|
||||||
@ -1082,7 +1082,7 @@ fn get_attributes(md: ebml::Doc) -> Vec<ast::Attribute> {
|
|||||||
return attrs;
|
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<()> {
|
out: &mut io::Writer) -> io::IoResult<()> {
|
||||||
try!(write!(out, "=Crate Attributes ({})=\n", *hash));
|
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> {
|
pub fn get_crate_attributes(data: &[u8]) -> Vec<ast::Attribute> {
|
||||||
get_attributes(ebml::Doc::new(data))
|
get_attributes(rbml::Doc::new(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone)]
|
||||||
@ -1107,10 +1107,10 @@ pub struct CrateDep {
|
|||||||
|
|
||||||
pub fn get_crate_deps(data: &[u8]) -> Vec<CrateDep> {
|
pub fn get_crate_deps(data: &[u8]) -> Vec<CrateDep> {
|
||||||
let mut deps: Vec<CrateDep> = Vec::new();
|
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 depsdoc = reader::get_doc(cratedoc, tag_crate_deps);
|
||||||
let mut crate_num = 1;
|
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_);
|
let d = reader::get_doc(doc, tag_);
|
||||||
d.as_str_slice().to_string()
|
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> {
|
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| {
|
reader::maybe_get_doc(cratedoc, tag_crate_hash).map(|doc| {
|
||||||
Svh::new(doc.as_str_slice())
|
Svh::new(doc.as_str_slice())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_crate_hash(data: &[u8]) -> Svh {
|
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);
|
let hashdoc = reader::get_doc(cratedoc, tag_crate_hash);
|
||||||
Svh::new(hashdoc.as_str_slice())
|
Svh::new(hashdoc.as_str_slice())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn maybe_get_crate_name(data: &[u8]) -> Option<String> {
|
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| {
|
reader::maybe_get_doc(cratedoc, tag_crate_crate_name).map(|doc| {
|
||||||
doc.as_str_slice().to_string()
|
doc.as_str_slice().to_string()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_crate_triple(data: &[u8]) -> Option<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);
|
let triple_doc = reader::maybe_get_doc(cratedoc, tag_crate_triple);
|
||||||
triple_doc.map(|s| s.as_str().to_string())
|
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<()> {
|
pub fn list_crate_metadata(bytes: &[u8], out: &mut io::Writer) -> io::IoResult<()> {
|
||||||
let hash = get_crate_hash(bytes);
|
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));
|
try!(list_crate_attributes(md, &hash, out));
|
||||||
list_crate_deps(bytes, 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|) {
|
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| {
|
let _ = reader::tagged_docs(impls_doc, tag_impls_impl, |impl_doc| {
|
||||||
callback(item_def_id(impl_doc, cdata));
|
callback(item_def_id(impl_doc, cdata));
|
||||||
true
|
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)
|
pub fn get_native_libraries(cdata: Cmd)
|
||||||
-> Vec<(cstore::NativeLibaryKind, String)> {
|
-> 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);
|
tag_native_libraries);
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
reader::tagged_docs(libraries, tag_native_libraries_lib, |lib_doc| {
|
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> {
|
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())
|
.map(|doc| FromPrimitive::from_u32(reader::doc_as_u32(doc)).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_exported_macros(data: &[u8]) -> Vec<String> {
|
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);
|
tag_exported_macros);
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
reader::tagged_docs(macros, tag_macro_def, |macro_doc| {
|
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)
|
pub fn get_dylib_dependency_formats(cdata: Cmd)
|
||||||
-> Vec<(ast::CrateNum, cstore::LinkagePreference)>
|
-> 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);
|
tag_dylib_dependency_formats);
|
||||||
let mut result = Vec::new();
|
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)
|
pub fn get_missing_lang_items(cdata: Cmd)
|
||||||
-> Vec<lang_items::LangItem>
|
-> 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();
|
let mut result = Vec::new();
|
||||||
reader::tagged_docs(items, tag_lang_items_missing, |missing_doc| {
|
reader::tagged_docs(items, tag_lang_items_missing, |missing_doc| {
|
||||||
let item: lang_items::LangItem =
|
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> {
|
pub fn get_reachable_extern_fns(cdata: Cmd) -> Vec<ast::DefId> {
|
||||||
let mut ret = Vec::new();
|
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);
|
tag_reachable_extern_fns);
|
||||||
reader::tagged_docs(items, tag_reachable_extern_fn_id, |doc| {
|
reader::tagged_docs(items, tag_reachable_extern_fn_id, |doc| {
|
||||||
ret.push(ast::DefId {
|
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::mem;
|
||||||
use std::gc::GC;
|
use std::gc::GC;
|
||||||
|
|
||||||
use serialize::ebml::reader;
|
use rbml::{reader, writer};
|
||||||
use serialize::ebml;
|
use rbml;
|
||||||
use serialize;
|
use serialize;
|
||||||
use serialize::{Encoder, Encodable, EncoderHelpers, DecoderHelpers};
|
use serialize::{Encoder, Encodable, EncoderHelpers, DecoderHelpers};
|
||||||
use serialize::{Decoder, Decodable};
|
use serialize::{Decoder, Decodable};
|
||||||
use writer = serialize::ebml::writer;
|
|
||||||
|
|
||||||
#[cfg(test)] use syntax::parse;
|
#[cfg(test)] use syntax::parse;
|
||||||
#[cfg(test)] use syntax::print::pprust;
|
#[cfg(test)] use syntax::print::pprust;
|
||||||
@ -79,7 +78,7 @@ pub type Encoder<'a> = writer::Encoder<'a, SeekableMemWriter>;
|
|||||||
// Top-level methods.
|
// Top-level methods.
|
||||||
|
|
||||||
pub fn encode_inlined_item(ecx: &e::EncodeContext,
|
pub fn encode_inlined_item(ecx: &e::EncodeContext,
|
||||||
ebml_w: &mut Encoder,
|
rbml_w: &mut Encoder,
|
||||||
ii: e::InlinedItemRef) {
|
ii: e::InlinedItemRef) {
|
||||||
let id = match ii {
|
let id = match ii {
|
||||||
e::IIItemRef(i) => i.id,
|
e::IIItemRef(i) => i.id,
|
||||||
@ -88,26 +87,26 @@ pub fn encode_inlined_item(ecx: &e::EncodeContext,
|
|||||||
};
|
};
|
||||||
debug!("> Encoding inlined item: {} ({})",
|
debug!("> Encoding inlined item: {} ({})",
|
||||||
ecx.tcx.map.path_to_string(id),
|
ecx.tcx.map.path_to_string(id),
|
||||||
ebml_w.writer.tell());
|
rbml_w.writer.tell());
|
||||||
|
|
||||||
let ii = simplify_ast(ii);
|
let ii = simplify_ast(ii);
|
||||||
let id_range = ast_util::compute_id_range_for_inlined_item(&ii);
|
let id_range = ast_util::compute_id_range_for_inlined_item(&ii);
|
||||||
|
|
||||||
ebml_w.start_tag(c::tag_ast as uint);
|
rbml_w.start_tag(c::tag_ast as uint);
|
||||||
id_range.encode(ebml_w);
|
id_range.encode(rbml_w);
|
||||||
encode_ast(ebml_w, ii);
|
encode_ast(rbml_w, ii);
|
||||||
encode_side_tables_for_ii(ecx, ebml_w, &ii);
|
encode_side_tables_for_ii(ecx, rbml_w, &ii);
|
||||||
ebml_w.end_tag();
|
rbml_w.end_tag();
|
||||||
|
|
||||||
debug!("< Encoded inlined fn: {} ({})",
|
debug!("< Encoded inlined fn: {} ({})",
|
||||||
ecx.tcx.map.path_to_string(id),
|
ecx.tcx.map.path_to_string(id),
|
||||||
ebml_w.writer.tell());
|
rbml_w.writer.tell());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decode_inlined_item(cdata: &cstore::crate_metadata,
|
pub fn decode_inlined_item(cdata: &cstore::crate_metadata,
|
||||||
tcx: &ty::ctxt,
|
tcx: &ty::ctxt,
|
||||||
path: Vec<ast_map::PathElem>,
|
path: Vec<ast_map::PathElem>,
|
||||||
par_doc: ebml::Doc)
|
par_doc: rbml::Doc)
|
||||||
-> Result<ast::InlinedItem, Vec<ast_map::PathElem>> {
|
-> Result<ast::InlinedItem, Vec<ast_map::PathElem>> {
|
||||||
let dcx = &DecodeContext {
|
let dcx = &DecodeContext {
|
||||||
cdata: cdata,
|
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,
|
// 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: &mut Encoder, item: ast::InlinedItem) {
|
fn encode_ast(rbml_w: &mut Encoder, item: ast::InlinedItem) {
|
||||||
ebml_w.start_tag(c::tag_tree as uint);
|
rbml_w.start_tag(c::tag_tree as uint);
|
||||||
item.encode(ebml_w);
|
item.encode(rbml_w);
|
||||||
ebml_w.end_tag();
|
rbml_w.end_tag();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NestedItemsDropper;
|
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 chi_doc = par_doc.get(c::tag_tree as uint);
|
||||||
let mut d = reader::Decoder::new(chi_doc);
|
let mut d = reader::Decoder::new(chi_doc);
|
||||||
Decodable::decode(&mut d).unwrap()
|
Decodable::decode(&mut d).unwrap()
|
||||||
@ -401,7 +400,7 @@ fn renumber_and_map_ast(xcx: &ExtendedDecodeContext,
|
|||||||
// ______________________________________________________________________
|
// ______________________________________________________________________
|
||||||
// Encoding and decoding of ast::def
|
// 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 mut dsr = reader::Decoder::new(doc);
|
||||||
let def: def::Def = Decodable::decode(&mut dsr).unwrap();
|
let def: def::Def = Decodable::decode(&mut dsr).unwrap();
|
||||||
def.tr(xcx)
|
def.tr(xcx)
|
||||||
@ -526,16 +525,16 @@ impl tr for ty::TraitStore {
|
|||||||
// ______________________________________________________________________
|
// ______________________________________________________________________
|
||||||
// Encoding and decoding of freevar information
|
// Encoding and decoding of freevar information
|
||||||
|
|
||||||
fn encode_freevar_entry(ebml_w: &mut Encoder, fv: &freevar_entry) {
|
fn encode_freevar_entry(rbml_w: &mut Encoder, fv: &freevar_entry) {
|
||||||
(*fv).encode(ebml_w).unwrap();
|
(*fv).encode(rbml_w).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
trait ebml_decoder_helper {
|
trait rbml_decoder_helper {
|
||||||
fn read_freevar_entry(&mut self, xcx: &ExtendedDecodeContext)
|
fn read_freevar_entry(&mut self, xcx: &ExtendedDecodeContext)
|
||||||
-> freevar_entry;
|
-> 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)
|
fn read_freevar_entry(&mut self, xcx: &ExtendedDecodeContext)
|
||||||
-> freevar_entry {
|
-> freevar_entry {
|
||||||
let fv: freevar_entry = Decodable::decode(self).unwrap();
|
let fv: freevar_entry = Decodable::decode(self).unwrap();
|
||||||
@ -561,21 +560,21 @@ trait read_method_callee_helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn encode_method_callee(ecx: &e::EncodeContext,
|
fn encode_method_callee(ecx: &e::EncodeContext,
|
||||||
ebml_w: &mut Encoder,
|
rbml_w: &mut Encoder,
|
||||||
adjustment: typeck::ExprAdjustment,
|
adjustment: typeck::ExprAdjustment,
|
||||||
method: &MethodCallee) {
|
method: &MethodCallee) {
|
||||||
ebml_w.emit_struct("MethodCallee", 4, |ebml_w| {
|
rbml_w.emit_struct("MethodCallee", 4, |rbml_w| {
|
||||||
ebml_w.emit_struct_field("adjustment", 0u, |ebml_w| {
|
rbml_w.emit_struct_field("adjustment", 0u, |rbml_w| {
|
||||||
adjustment.encode(ebml_w)
|
adjustment.encode(rbml_w)
|
||||||
});
|
});
|
||||||
ebml_w.emit_struct_field("origin", 1u, |ebml_w| {
|
rbml_w.emit_struct_field("origin", 1u, |rbml_w| {
|
||||||
method.origin.encode(ebml_w)
|
method.origin.encode(rbml_w)
|
||||||
});
|
});
|
||||||
ebml_w.emit_struct_field("ty", 2u, |ebml_w| {
|
rbml_w.emit_struct_field("ty", 2u, |rbml_w| {
|
||||||
Ok(ebml_w.emit_ty(ecx, method.ty))
|
Ok(rbml_w.emit_ty(ecx, method.ty))
|
||||||
});
|
});
|
||||||
ebml_w.emit_struct_field("substs", 3u, |ebml_w| {
|
rbml_w.emit_struct_field("substs", 3u, |rbml_w| {
|
||||||
Ok(ebml_w.emit_substs(ecx, &method.substs))
|
Ok(rbml_w.emit_substs(ecx, &method.substs))
|
||||||
})
|
})
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
}
|
}
|
||||||
@ -636,81 +635,81 @@ impl tr for MethodOrigin {
|
|||||||
// Encoding and decoding vtable_res
|
// Encoding and decoding vtable_res
|
||||||
|
|
||||||
fn encode_vtable_res_with_key(ecx: &e::EncodeContext,
|
fn encode_vtable_res_with_key(ecx: &e::EncodeContext,
|
||||||
ebml_w: &mut Encoder,
|
rbml_w: &mut Encoder,
|
||||||
adjustment: typeck::ExprAdjustment,
|
adjustment: typeck::ExprAdjustment,
|
||||||
dr: &typeck::vtable_res) {
|
dr: &typeck::vtable_res) {
|
||||||
ebml_w.emit_struct("VtableWithKey", 2, |ebml_w| {
|
rbml_w.emit_struct("VtableWithKey", 2, |rbml_w| {
|
||||||
ebml_w.emit_struct_field("adjustment", 0u, |ebml_w| {
|
rbml_w.emit_struct_field("adjustment", 0u, |rbml_w| {
|
||||||
adjustment.encode(ebml_w)
|
adjustment.encode(rbml_w)
|
||||||
});
|
});
|
||||||
ebml_w.emit_struct_field("vtable_res", 1u, |ebml_w| {
|
rbml_w.emit_struct_field("vtable_res", 1u, |rbml_w| {
|
||||||
Ok(encode_vtable_res(ecx, ebml_w, dr))
|
Ok(encode_vtable_res(ecx, rbml_w, dr))
|
||||||
})
|
})
|
||||||
}).unwrap()
|
}).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn encode_vtable_res(ecx: &e::EncodeContext,
|
pub fn encode_vtable_res(ecx: &e::EncodeContext,
|
||||||
ebml_w: &mut Encoder,
|
rbml_w: &mut Encoder,
|
||||||
dr: &typeck::vtable_res) {
|
dr: &typeck::vtable_res) {
|
||||||
// can't autogenerate this code because automatic code 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 encoding 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.
|
||||||
encode_vec_per_param_space(
|
encode_vec_per_param_space(
|
||||||
ebml_w, dr,
|
rbml_w, dr,
|
||||||
|ebml_w, param_tables| encode_vtable_param_res(ecx, ebml_w,
|
|rbml_w, param_tables| encode_vtable_param_res(ecx, rbml_w,
|
||||||
param_tables))
|
param_tables))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn encode_vtable_param_res(ecx: &e::EncodeContext,
|
pub fn encode_vtable_param_res(ecx: &e::EncodeContext,
|
||||||
ebml_w: &mut Encoder,
|
rbml_w: &mut Encoder,
|
||||||
param_tables: &typeck::vtable_param_res) {
|
param_tables: &typeck::vtable_param_res) {
|
||||||
ebml_w.emit_from_vec(param_tables.as_slice(), |ebml_w, vtable_origin| {
|
rbml_w.emit_from_vec(param_tables.as_slice(), |rbml_w, vtable_origin| {
|
||||||
Ok(encode_vtable_origin(ecx, ebml_w, vtable_origin))
|
Ok(encode_vtable_origin(ecx, rbml_w, vtable_origin))
|
||||||
}).unwrap()
|
}).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn encode_vtable_origin(ecx: &e::EncodeContext,
|
pub fn encode_vtable_origin(ecx: &e::EncodeContext,
|
||||||
ebml_w: &mut Encoder,
|
rbml_w: &mut Encoder,
|
||||||
vtable_origin: &typeck::vtable_origin) {
|
vtable_origin: &typeck::vtable_origin) {
|
||||||
ebml_w.emit_enum("vtable_origin", |ebml_w| {
|
rbml_w.emit_enum("vtable_origin", |rbml_w| {
|
||||||
match *vtable_origin {
|
match *vtable_origin {
|
||||||
typeck::vtable_static(def_id, ref substs, ref vtable_res) => {
|
typeck::vtable_static(def_id, ref substs, ref vtable_res) => {
|
||||||
ebml_w.emit_enum_variant("vtable_static", 0u, 3u, |ebml_w| {
|
rbml_w.emit_enum_variant("vtable_static", 0u, 3u, |rbml_w| {
|
||||||
ebml_w.emit_enum_variant_arg(0u, |ebml_w| {
|
rbml_w.emit_enum_variant_arg(0u, |rbml_w| {
|
||||||
Ok(ebml_w.emit_def_id(def_id))
|
Ok(rbml_w.emit_def_id(def_id))
|
||||||
});
|
});
|
||||||
ebml_w.emit_enum_variant_arg(1u, |ebml_w| {
|
rbml_w.emit_enum_variant_arg(1u, |rbml_w| {
|
||||||
Ok(ebml_w.emit_substs(ecx, substs))
|
Ok(rbml_w.emit_substs(ecx, substs))
|
||||||
});
|
});
|
||||||
ebml_w.emit_enum_variant_arg(2u, |ebml_w| {
|
rbml_w.emit_enum_variant_arg(2u, |rbml_w| {
|
||||||
Ok(encode_vtable_res(ecx, ebml_w, vtable_res))
|
Ok(encode_vtable_res(ecx, rbml_w, vtable_res))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
typeck::vtable_param(pn, bn) => {
|
typeck::vtable_param(pn, bn) => {
|
||||||
ebml_w.emit_enum_variant("vtable_param", 1u, 3u, |ebml_w| {
|
rbml_w.emit_enum_variant("vtable_param", 1u, 3u, |rbml_w| {
|
||||||
ebml_w.emit_enum_variant_arg(0u, |ebml_w| {
|
rbml_w.emit_enum_variant_arg(0u, |rbml_w| {
|
||||||
pn.encode(ebml_w)
|
pn.encode(rbml_w)
|
||||||
});
|
});
|
||||||
ebml_w.emit_enum_variant_arg(1u, |ebml_w| {
|
rbml_w.emit_enum_variant_arg(1u, |rbml_w| {
|
||||||
ebml_w.emit_uint(bn)
|
rbml_w.emit_uint(bn)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
typeck::vtable_unboxed_closure(def_id) => {
|
typeck::vtable_unboxed_closure(def_id) => {
|
||||||
ebml_w.emit_enum_variant("vtable_unboxed_closure",
|
rbml_w.emit_enum_variant("vtable_unboxed_closure",
|
||||||
2u,
|
2u,
|
||||||
1u,
|
1u,
|
||||||
|ebml_w| {
|
|rbml_w| {
|
||||||
ebml_w.emit_enum_variant_arg(0u, |ebml_w| {
|
rbml_w.emit_enum_variant_arg(0u, |rbml_w| {
|
||||||
Ok(ebml_w.emit_def_id(def_id))
|
Ok(rbml_w.emit_def_id(def_id))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
typeck::vtable_error => {
|
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(())
|
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>,
|
v: &subst::VecPerParamSpace<T>,
|
||||||
f: |&mut Encoder, &T|) {
|
f: |&mut Encoder, &T|) {
|
||||||
for &space in subst::ParamSpace::all().iter() {
|
for &space in subst::ParamSpace::all().iter() {
|
||||||
ebml_w.emit_from_vec(v.get_slice(space),
|
rbml_w.emit_from_vec(v.get_slice(space),
|
||||||
|ebml_w, n| Ok(f(ebml_w, n))).unwrap();
|
|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,
|
fn emit_closure_type(&mut self,
|
||||||
ecx: &e::EncodeContext,
|
ecx: &e::EncodeContext,
|
||||||
closure_type: &ty::ClosureTy);
|
closure_type: &ty::ClosureTy);
|
||||||
@ -874,7 +873,7 @@ trait ebml_writer_helpers {
|
|||||||
fn emit_auto_adjustment(&mut self, ecx: &e::EncodeContext, adj: &ty::AutoAdjustment);
|
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,
|
fn emit_closure_type(&mut self,
|
||||||
ecx: &e::EncodeContext,
|
ecx: &e::EncodeContext,
|
||||||
closure_type: &ty::ClosureTy) {
|
closure_type: &ty::ClosureTy) {
|
||||||
@ -980,34 +979,34 @@ impl<'a> write_tag_and_id for Encoder<'a> {
|
|||||||
|
|
||||||
struct SideTableEncodingIdVisitor<'a,'b> {
|
struct SideTableEncodingIdVisitor<'a,'b> {
|
||||||
ecx_ptr: *const libc::c_void,
|
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
|
impl<'a,'b> ast_util::IdVisitingOperation for
|
||||||
SideTableEncodingIdVisitor<'a,'b> {
|
SideTableEncodingIdVisitor<'a,'b> {
|
||||||
fn visit_id(&self, id: ast::NodeId) {
|
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
|
// it is mutable. But I believe it's harmless since we generate
|
||||||
// balanced EBML.
|
// balanced EBML.
|
||||||
//
|
//
|
||||||
// FIXME(pcwalton): Don't copy this way.
|
// FIXME(pcwalton): Don't copy this way.
|
||||||
let mut new_ebml_w = unsafe {
|
let mut new_rbml_w = unsafe {
|
||||||
self.new_ebml_w.unsafe_clone()
|
self.new_rbml_w.unsafe_clone()
|
||||||
};
|
};
|
||||||
// See above
|
// See above
|
||||||
let ecx: &e::EncodeContext = unsafe {
|
let ecx: &e::EncodeContext = unsafe {
|
||||||
mem::transmute(self.ecx_ptr)
|
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,
|
fn encode_side_tables_for_ii(ecx: &e::EncodeContext,
|
||||||
ebml_w: &mut Encoder,
|
rbml_w: &mut Encoder,
|
||||||
ii: &ast::InlinedItem) {
|
ii: &ast::InlinedItem) {
|
||||||
ebml_w.start_tag(c::tag_table as uint);
|
rbml_w.start_tag(c::tag_table as uint);
|
||||||
let mut new_ebml_w = unsafe {
|
let mut new_rbml_w = unsafe {
|
||||||
ebml_w.unsafe_clone()
|
rbml_w.unsafe_clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Because the ast visitor uses @IdVisitingOperation, I can't pass in
|
// 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 {
|
ecx_ptr: unsafe {
|
||||||
mem::transmute(ecx)
|
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,
|
fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
||||||
ebml_w: &mut Encoder,
|
rbml_w: &mut Encoder,
|
||||||
id: ast::NodeId) {
|
id: ast::NodeId) {
|
||||||
let tcx = ecx.tcx;
|
let tcx = ecx.tcx;
|
||||||
|
|
||||||
debug!("Encoding side tables for id {}", id);
|
debug!("Encoding side tables for id {}", id);
|
||||||
|
|
||||||
for def in tcx.def_map.borrow().find(&id).iter() {
|
for def in tcx.def_map.borrow().find(&id).iter() {
|
||||||
ebml_w.tag(c::tag_table_def, |ebml_w| {
|
rbml_w.tag(c::tag_table_def, |rbml_w| {
|
||||||
ebml_w.id(id);
|
rbml_w.id(id);
|
||||||
ebml_w.tag(c::tag_table_val, |ebml_w| (*def).encode(ebml_w).unwrap());
|
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() {
|
for &ty in tcx.node_types.borrow().find(&(id as uint)).iter() {
|
||||||
ebml_w.tag(c::tag_table_node_type, |ebml_w| {
|
rbml_w.tag(c::tag_table_node_type, |rbml_w| {
|
||||||
ebml_w.id(id);
|
rbml_w.id(id);
|
||||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||||
ebml_w.emit_ty(ecx, *ty);
|
rbml_w.emit_ty(ecx, *ty);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for &item_substs in tcx.item_substs.borrow().find(&id).iter() {
|
for &item_substs in tcx.item_substs.borrow().find(&id).iter() {
|
||||||
ebml_w.tag(c::tag_table_item_subst, |ebml_w| {
|
rbml_w.tag(c::tag_table_item_subst, |rbml_w| {
|
||||||
ebml_w.id(id);
|
rbml_w.id(id);
|
||||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||||
ebml_w.emit_substs(ecx, &item_substs.substs);
|
rbml_w.emit_substs(ecx, &item_substs.substs);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for &fv in tcx.freevars.borrow().find(&id).iter() {
|
for &fv in tcx.freevars.borrow().find(&id).iter() {
|
||||||
ebml_w.tag(c::tag_table_freevars, |ebml_w| {
|
rbml_w.tag(c::tag_table_freevars, |rbml_w| {
|
||||||
ebml_w.id(id);
|
rbml_w.id(id);
|
||||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||||
ebml_w.emit_from_vec(fv.as_slice(), |ebml_w, fv_entry| {
|
rbml_w.emit_from_vec(fv.as_slice(), |rbml_w, fv_entry| {
|
||||||
Ok(encode_freevar_entry(ebml_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 };
|
let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id };
|
||||||
for &pty in tcx.tcache.borrow().find(&lid).iter() {
|
for &pty in tcx.tcache.borrow().find(&lid).iter() {
|
||||||
ebml_w.tag(c::tag_table_tcache, |ebml_w| {
|
rbml_w.tag(c::tag_table_tcache, |rbml_w| {
|
||||||
ebml_w.id(id);
|
rbml_w.id(id);
|
||||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||||
ebml_w.emit_polytype(ecx, pty.clone());
|
rbml_w.emit_polytype(ecx, pty.clone());
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for &type_param_def in tcx.ty_param_defs.borrow().find(&id).iter() {
|
for &type_param_def in tcx.ty_param_defs.borrow().find(&id).iter() {
|
||||||
ebml_w.tag(c::tag_table_param_defs, |ebml_w| {
|
rbml_w.tag(c::tag_table_param_defs, |rbml_w| {
|
||||||
ebml_w.id(id);
|
rbml_w.id(id);
|
||||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||||
ebml_w.emit_type_param_def(ecx, type_param_def)
|
rbml_w.emit_type_param_def(ecx, type_param_def)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let method_call = MethodCall::expr(id);
|
let method_call = MethodCall::expr(id);
|
||||||
for &method in tcx.method_map.borrow().find(&method_call).iter() {
|
for &method in tcx.method_map.borrow().find(&method_call).iter() {
|
||||||
ebml_w.tag(c::tag_table_method_map, |ebml_w| {
|
rbml_w.tag(c::tag_table_method_map, |rbml_w| {
|
||||||
ebml_w.id(id);
|
rbml_w.id(id);
|
||||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||||
encode_method_callee(ecx, ebml_w, method_call.adjustment, method)
|
encode_method_callee(ecx, rbml_w, method_call.adjustment, method)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for &dr in tcx.vtable_map.borrow().find(&method_call).iter() {
|
for &dr in tcx.vtable_map.borrow().find(&method_call).iter() {
|
||||||
ebml_w.tag(c::tag_table_vtable_map, |ebml_w| {
|
rbml_w.tag(c::tag_table_vtable_map, |rbml_w| {
|
||||||
ebml_w.id(id);
|
rbml_w.id(id);
|
||||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||||
encode_vtable_res_with_key(ecx, ebml_w, method_call.adjustment, dr);
|
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) {
|
for autoderef in range(0, adj.autoderefs) {
|
||||||
let method_call = MethodCall::autoderef(id, autoderef);
|
let method_call = MethodCall::autoderef(id, autoderef);
|
||||||
for &method in tcx.method_map.borrow().find(&method_call).iter() {
|
for &method in tcx.method_map.borrow().find(&method_call).iter() {
|
||||||
ebml_w.tag(c::tag_table_method_map, |ebml_w| {
|
rbml_w.tag(c::tag_table_method_map, |rbml_w| {
|
||||||
ebml_w.id(id);
|
rbml_w.id(id);
|
||||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||||
encode_method_callee(ecx, ebml_w,
|
encode_method_callee(ecx, rbml_w,
|
||||||
method_call.adjustment, method)
|
method_call.adjustment, method)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for &dr in tcx.vtable_map.borrow().find(&method_call).iter() {
|
for &dr in tcx.vtable_map.borrow().find(&method_call).iter() {
|
||||||
ebml_w.tag(c::tag_table_vtable_map, |ebml_w| {
|
rbml_w.tag(c::tag_table_vtable_map, |rbml_w| {
|
||||||
ebml_w.id(id);
|
rbml_w.id(id);
|
||||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||||
encode_vtable_res_with_key(ecx, ebml_w,
|
encode_vtable_res_with_key(ecx, rbml_w,
|
||||||
method_call.adjustment, dr);
|
method_call.adjustment, dr);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -1132,19 +1131,19 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
|||||||
ty::AutoObject(..) => {
|
ty::AutoObject(..) => {
|
||||||
let method_call = MethodCall::autoobject(id);
|
let method_call = MethodCall::autoobject(id);
|
||||||
for &method in tcx.method_map.borrow().find(&method_call).iter() {
|
for &method in tcx.method_map.borrow().find(&method_call).iter() {
|
||||||
ebml_w.tag(c::tag_table_method_map, |ebml_w| {
|
rbml_w.tag(c::tag_table_method_map, |rbml_w| {
|
||||||
ebml_w.id(id);
|
rbml_w.id(id);
|
||||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||||
encode_method_callee(ecx, ebml_w, method_call.adjustment, method)
|
encode_method_callee(ecx, rbml_w, method_call.adjustment, method)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for &dr in tcx.vtable_map.borrow().find(&method_call).iter() {
|
for &dr in tcx.vtable_map.borrow().find(&method_call).iter() {
|
||||||
ebml_w.tag(c::tag_table_vtable_map, |ebml_w| {
|
rbml_w.tag(c::tag_table_vtable_map, |rbml_w| {
|
||||||
ebml_w.id(id);
|
rbml_w.id(id);
|
||||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||||
encode_vtable_res_with_key(ecx, ebml_w, method_call.adjustment, dr);
|
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| {
|
rbml_w.tag(c::tag_table_adjustments, |rbml_w| {
|
||||||
ebml_w.id(id);
|
rbml_w.id(id);
|
||||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||||
ebml_w.emit_auto_adjustment(ecx, adj);
|
rbml_w.emit_auto_adjustment(ecx, adj);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1164,10 +1163,10 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
|||||||
.borrow()
|
.borrow()
|
||||||
.find(&ast_util::local_def(id))
|
.find(&ast_util::local_def(id))
|
||||||
.iter() {
|
.iter() {
|
||||||
ebml_w.tag(c::tag_table_unboxed_closure_type, |ebml_w| {
|
rbml_w.tag(c::tag_table_unboxed_closure_type, |rbml_w| {
|
||||||
ebml_w.id(id);
|
rbml_w.id(id);
|
||||||
ebml_w.tag(c::tag_table_val, |ebml_w| {
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
||||||
ebml_w.emit_closure_type(ecx, *unboxed_closure_type)
|
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>;
|
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 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)
|
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_ty(&mut self, xcx: &ExtendedDecodeContext) -> ty::t;
|
||||||
fn read_tys(&mut self, xcx: &ExtendedDecodeContext) -> Vec<ty::t>;
|
fn read_tys(&mut self, xcx: &ExtendedDecodeContext) -> Vec<ty::t>;
|
||||||
fn read_type_param_def(&mut self, xcx: &ExtendedDecodeContext)
|
fn read_type_param_def(&mut self, xcx: &ExtendedDecodeContext)
|
||||||
@ -1214,7 +1213,7 @@ trait ebml_decoder_decoder_helpers {
|
|||||||
-> subst::Substs;
|
-> 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,
|
fn read_ty_noxcx(&mut self,
|
||||||
tcx: &ty::ctxt, cdata: &cstore::crate_metadata) -> ty::t {
|
tcx: &ty::ctxt, cdata: &cstore::crate_metadata) -> ty::t {
|
||||||
self.read_opaque(|_, doc| {
|
self.read_opaque(|_, doc| {
|
||||||
@ -1270,7 +1269,7 @@ impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> {
|
|||||||
Ok(ty)
|
Ok(ty)
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
|
||||||
fn type_string(doc: ebml::Doc) -> String {
|
fn type_string(doc: rbml::Doc) -> String {
|
||||||
let mut str = String::new();
|
let mut str = String::new();
|
||||||
for i in range(doc.start, doc.end) {
|
for i in range(doc.start, doc.end) {
|
||||||
str.push_char(doc.data[i] as char);
|
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,
|
fn decode_side_tables(xcx: &ExtendedDecodeContext,
|
||||||
ast_doc: ebml::Doc) {
|
ast_doc: rbml::Doc) {
|
||||||
let dcx = xcx.dcx;
|
let dcx = xcx.dcx;
|
||||||
let tbl_doc = ast_doc.get(c::tag_table as uint);
|
let tbl_doc = ast_doc.get(c::tag_table as uint);
|
||||||
reader::docs(tbl_doc, |tag, entry_doc| {
|
reader::docs(tbl_doc, |tag, entry_doc| {
|
||||||
@ -1527,14 +1526,14 @@ fn decode_side_tables(xcx: &ExtendedDecodeContext,
|
|||||||
// Testing of astencode_gen
|
// Testing of astencode_gen
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn encode_item_ast(ebml_w: &mut Encoder, item: Gc<ast::Item>) {
|
fn encode_item_ast(rbml_w: &mut Encoder, item: Gc<ast::Item>) {
|
||||||
ebml_w.start_tag(c::tag_tree as uint);
|
rbml_w.start_tag(c::tag_tree as uint);
|
||||||
(*item).encode(ebml_w);
|
(*item).encode(rbml_w);
|
||||||
ebml_w.end_tag();
|
rbml_w.end_tag();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[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 chi_doc = par_doc.get(c::tag_tree as uint);
|
||||||
let mut d = reader::Decoder::new(chi_doc);
|
let mut d = reader::Decoder::new(chi_doc);
|
||||||
box(GC) Decodable::decode(&mut d).unwrap()
|
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 in_item = in_item.unwrap();
|
||||||
let mut wr = SeekableMemWriter::new();
|
let mut wr = SeekableMemWriter::new();
|
||||||
{
|
{
|
||||||
let mut ebml_w = writer::Encoder::new(&mut wr);
|
let mut rbml_w = writer::Encoder::new(&mut wr);
|
||||||
encode_item_ast(&mut ebml_w, in_item);
|
encode_item_ast(&mut rbml_w, in_item);
|
||||||
}
|
}
|
||||||
let ebml_doc = ebml::Doc::new(wr.get_ref());
|
let rbml_doc = rbml::Doc::new(wr.get_ref());
|
||||||
let out_item = decode_item_ast(ebml_doc);
|
let out_item = decode_item_ast(rbml_doc);
|
||||||
|
|
||||||
assert!(in_item == out_item);
|
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 =
|
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 encode_parms = crate_ctxt_to_encode_parms(cx, encode_inlined_item);
|
||||||
let metadata = encoder::encode_metadata(encode_parms, krate);
|
let metadata = encoder::encode_metadata(encode_parms, krate);
|
||||||
|
@ -39,6 +39,5 @@ mod serialize;
|
|||||||
mod collection_impls;
|
mod collection_impls;
|
||||||
|
|
||||||
pub mod base64;
|
pub mod base64;
|
||||||
pub mod ebml;
|
|
||||||
pub mod hex;
|
pub mod hex;
|
||||||
pub mod json;
|
pub mod json;
|
||||||
|
@ -10,33 +10,33 @@
|
|||||||
|
|
||||||
// ignore-test FIXME(#5121)
|
// ignore-test FIXME(#5121)
|
||||||
|
|
||||||
|
extern crate rbml;
|
||||||
extern crate time;
|
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
|
extern crate time;
|
||||||
|
|
||||||
// These tests used to be separate files, but I wanted to refactor all
|
// These tests used to be separate files, but I wanted to refactor all
|
||||||
// the common code.
|
// the common code.
|
||||||
|
|
||||||
use std::hashmap::{HashMap, HashSet};
|
use std::hashmap::{HashMap, HashSet};
|
||||||
|
|
||||||
use EBReader = serialize::ebml::reader;
|
use EBReader = rbml::reader;
|
||||||
use EBWriter = serialize::ebml::writer;
|
use EBWriter = rbml::writer;
|
||||||
use std::cmp::Eq;
|
use std::cmp::Eq;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::io;
|
use std::io;
|
||||||
use serialize::{Decodable, Encodable};
|
use serialize::{Decodable, Encodable};
|
||||||
|
|
||||||
fn test_ebml<'a, 'b, A:
|
fn test_rbml<'a, 'b, A:
|
||||||
Eq +
|
Eq +
|
||||||
Encodable<EBWriter::Encoder<'a>> +
|
Encodable<EBWriter::Encoder<'a>> +
|
||||||
Decodable<EBReader::Decoder<'b>>
|
Decodable<EBReader::Decoder<'b>>
|
||||||
>(a1: &A) {
|
>(a1: &A) {
|
||||||
let mut wr = std::io::MemWriter::new();
|
let mut wr = std::io::MemWriter::new();
|
||||||
let mut ebml_w = EBwriter::Encoder::new(&mut wr);
|
let mut rbml_w = EBwriter::Encoder::new(&mut wr);
|
||||||
a1.encode(&mut ebml_w);
|
a1.encode(&mut rbml_w);
|
||||||
let bytes = wr.get_ref();
|
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 mut decoder: EBReader::Decoder<'a> = EBreader::Decoder::new(d);
|
||||||
let a2: A = Decodable::decode(&mut decoder);
|
let a2: A = Decodable::decode(&mut decoder);
|
||||||
assert!(*a1 == a2);
|
assert!(*a1 == a2);
|
||||||
@ -133,40 +133,40 @@ enum CLike { A, B, C }
|
|||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let a = &Plus(@Minus(@Val(3u), @Val(10u)), @Plus(@Val(22u), @Val(5u)));
|
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};
|
let a = &Spanned {lo: 0u, hi: 5u, node: 22u};
|
||||||
test_ebml(a);
|
test_rbml(a);
|
||||||
|
|
||||||
let a = &Point {x: 3u, y: 5u};
|
let a = &Point {x: 3u, y: 5u};
|
||||||
test_ebml(a);
|
test_rbml(a);
|
||||||
|
|
||||||
let a = &Top(22u);
|
let a = &Top(22u);
|
||||||
test_ebml(a);
|
test_rbml(a);
|
||||||
|
|
||||||
let a = &Bottom(222u);
|
let a = &Bottom(222u);
|
||||||
test_ebml(a);
|
test_rbml(a);
|
||||||
|
|
||||||
let a = &A;
|
let a = &A;
|
||||||
test_ebml(a);
|
test_rbml(a);
|
||||||
|
|
||||||
let a = &B;
|
let a = &B;
|
||||||
test_ebml(a);
|
test_rbml(a);
|
||||||
|
|
||||||
let a = &time::now();
|
let a = &time::now();
|
||||||
test_ebml(a);
|
test_rbml(a);
|
||||||
|
|
||||||
test_ebml(&1.0f32);
|
test_rbml(&1.0f32);
|
||||||
test_ebml(&1.0f64);
|
test_rbml(&1.0f64);
|
||||||
test_ebml(&'a');
|
test_rbml(&'a');
|
||||||
|
|
||||||
let mut a = HashMap::new();
|
let mut a = HashMap::new();
|
||||||
test_ebml(&a);
|
test_rbml(&a);
|
||||||
a.insert(1, 2);
|
a.insert(1, 2);
|
||||||
test_ebml(&a);
|
test_rbml(&a);
|
||||||
|
|
||||||
let mut a = HashSet::new();
|
let mut a = HashSet::new();
|
||||||
test_ebml(&a);
|
test_rbml(&a);
|
||||||
a.insert(1);
|
a.insert(1);
|
||||||
test_ebml(&a);
|
test_rbml(&a);
|
||||||
}
|
}
|
||||||
|
@ -16,15 +16,16 @@
|
|||||||
#![feature(struct_variant)]
|
#![feature(struct_variant)]
|
||||||
|
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
|
extern crate rbml;
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
|
|
||||||
use std::io::MemWriter;
|
use std::io::MemWriter;
|
||||||
use rand::{random, Rand};
|
use rand::{random, Rand};
|
||||||
|
use rbml;
|
||||||
|
use rbml::Doc;
|
||||||
|
use rbml::writer::Encoder;
|
||||||
|
use rbml::reader::Decoder;
|
||||||
use serialize::{Encodable, Decodable};
|
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)]
|
#[deriving(Encodable, Decodable, Eq, Rand)]
|
||||||
struct A;
|
struct A;
|
||||||
@ -61,7 +62,7 @@ fn roundtrip<'a, T: Rand + Eq + Encodable<Encoder<'a>> +
|
|||||||
let mut w = MemWriter::new();
|
let mut w = MemWriter::new();
|
||||||
let mut e = Encoder::new(&mut w);
|
let mut e = Encoder::new(&mut w);
|
||||||
obj.encode(&mut e);
|
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 mut dec = Decoder::new(doc);
|
||||||
let obj2 = Decodable::decode(&mut dec);
|
let obj2 = Decodable::decode(&mut dec);
|
||||||
assert!(obj == obj2);
|
assert!(obj == obj2);
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
extern crate rbml;
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
@ -16,7 +17,7 @@ use std::slice;
|
|||||||
|
|
||||||
use serialize::{Encodable, Encoder};
|
use serialize::{Encodable, Encoder};
|
||||||
use serialize::json;
|
use serialize::json;
|
||||||
use serialize::ebml::writer;
|
use rbml::writer;
|
||||||
|
|
||||||
static BUF_CAPACITY: uint = 128;
|
static BUF_CAPACITY: uint = 128;
|
||||||
|
|
||||||
@ -144,7 +145,7 @@ struct Bar {
|
|||||||
|
|
||||||
enum WireProtocol {
|
enum WireProtocol {
|
||||||
JSON,
|
JSON,
|
||||||
EBML,
|
RBML,
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +156,7 @@ fn encode_json<'a,
|
|||||||
let mut encoder = json::Encoder::new(wr);
|
let mut encoder = json::Encoder::new(wr);
|
||||||
val.encode(&mut encoder);
|
val.encode(&mut encoder);
|
||||||
}
|
}
|
||||||
fn encode_ebml<'a,
|
fn encode_rbml<'a,
|
||||||
T: Encodable<writer::Encoder<'a, SeekableMemWriter>,
|
T: Encodable<writer::Encoder<'a, SeekableMemWriter>,
|
||||||
std::io::IoError>>(val: &T,
|
std::io::IoError>>(val: &T,
|
||||||
wr: &'a mut SeekableMemWriter) {
|
wr: &'a mut SeekableMemWriter) {
|
||||||
@ -169,6 +170,6 @@ pub fn main() {
|
|||||||
let proto = JSON;
|
let proto = JSON;
|
||||||
match proto {
|
match proto {
|
||||||
JSON => encode_json(&target, &mut wr),
|
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