2012-04-10 12:52:06 -05:00
|
|
|
import util::ppaux::ty_to_str;
|
|
|
|
|
2012-02-07 23:19:53 -06:00
|
|
|
import syntax::ast;
|
2012-02-14 17:21:53 -06:00
|
|
|
import syntax::fold;
|
2012-07-16 21:16:19 -05:00
|
|
|
import syntax::fold::*;
|
2012-02-14 17:21:53 -06:00
|
|
|
import syntax::visit;
|
2012-05-22 01:34:34 -05:00
|
|
|
import syntax::ast_map;
|
2012-02-14 17:21:53 -06:00
|
|
|
import syntax::ast_util;
|
|
|
|
import syntax::codemap::span;
|
|
|
|
import std::ebml;
|
2012-02-07 23:19:53 -06:00
|
|
|
import std::ebml::writer;
|
2012-07-27 21:32:42 -05:00
|
|
|
import std::ebml::get_doc;
|
2012-03-07 18:48:57 -06:00
|
|
|
import std::map::hashmap;
|
2012-03-14 10:49:28 -05:00
|
|
|
import std::serialization::serializer;
|
|
|
|
import std::serialization::deserializer;
|
|
|
|
import std::serialization::serializer_helpers;
|
|
|
|
import std::serialization::deserializer_helpers;
|
2012-03-15 09:15:49 -05:00
|
|
|
import std::prettyprint::serializer;
|
2012-05-25 02:14:40 -05:00
|
|
|
import middle::{ty, typeck};
|
2012-06-07 12:51:21 -05:00
|
|
|
import middle::typeck::{method_origin, method_map_entry,
|
|
|
|
serialize_method_map_entry,
|
|
|
|
deserialize_method_map_entry,
|
2012-03-15 09:15:49 -05:00
|
|
|
vtable_res,
|
|
|
|
vtable_origin};
|
2012-02-14 17:21:53 -06:00
|
|
|
import driver::session::session;
|
2012-03-15 09:15:49 -05:00
|
|
|
import middle::freevars::{freevar_entry,
|
|
|
|
serialize_freevar_entry,
|
|
|
|
deserialize_freevar_entry};
|
2012-05-14 18:15:11 -05:00
|
|
|
import c = metadata::common;
|
|
|
|
import e = metadata::encoder;
|
|
|
|
import cstore = metadata::cstore;
|
|
|
|
import metadata::encoder;
|
|
|
|
import metadata::decoder;
|
|
|
|
import metadata::tyencode;
|
|
|
|
import metadata::tydecode;
|
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
|
|
|
|
// used in testing:
|
2012-05-13 19:49:27 -05:00
|
|
|
import syntax::diagnostic;
|
2012-02-14 17:21:53 -06:00
|
|
|
import syntax::codemap;
|
2012-04-18 01:34:48 -05:00
|
|
|
import syntax::parse;
|
2012-02-14 17:21:53 -06:00
|
|
|
import syntax::print::pprust;
|
|
|
|
|
2012-05-14 19:46:45 -05:00
|
|
|
export maps;
|
2012-02-14 17:21:53 -06:00
|
|
|
export encode_inlined_item;
|
|
|
|
export decode_inlined_item;
|
|
|
|
|
2012-05-14 19:46:45 -05:00
|
|
|
// Auxiliary maps of things to be encoded
|
|
|
|
type maps = {
|
|
|
|
mutbl_map: middle::borrowck::mutbl_map,
|
2012-05-14 22:32:29 -05:00
|
|
|
root_map: middle::borrowck::root_map,
|
2012-05-25 02:14:40 -05:00
|
|
|
last_use_map: middle::liveness::last_use_map,
|
2012-05-14 19:46:45 -05:00
|
|
|
method_map: middle::typeck::method_map,
|
|
|
|
vtable_map: middle::typeck::vtable_map,
|
|
|
|
};
|
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
type decode_ctxt = @{
|
|
|
|
cdata: cstore::crate_metadata,
|
|
|
|
tcx: ty::ctxt,
|
|
|
|
maps: maps
|
2012-02-07 23:19:53 -06:00
|
|
|
};
|
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
type extended_decode_ctxt_ = {
|
2012-02-14 17:21:53 -06:00
|
|
|
dcx: decode_ctxt,
|
2012-06-13 18:14:01 -05:00
|
|
|
from_id_range: ast_util::id_range,
|
|
|
|
to_id_range: ast_util::id_range
|
2012-02-14 17:21:53 -06:00
|
|
|
};
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
enum extended_decode_ctxt {
|
|
|
|
extended_decode_ctxt_(@extended_decode_ctxt_)
|
|
|
|
}
|
|
|
|
|
2012-07-31 12:27:51 -05:00
|
|
|
trait tr {
|
2012-02-14 17:21:53 -06:00
|
|
|
fn tr(xcx: extended_decode_ctxt) -> self;
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
// ______________________________________________________________________
|
2012-03-01 12:36:22 -06:00
|
|
|
// Top-level methods.
|
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
fn encode_inlined_item(ecx: @e::encode_ctxt,
|
|
|
|
ebml_w: ebml::writer,
|
2012-02-27 16:06:44 -06:00
|
|
|
path: ast_map::path,
|
2012-05-14 19:46:45 -05:00
|
|
|
ii: ast::inlined_item,
|
|
|
|
maps: maps) {
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"> Encoding inlined item: %s::%s (%u)",
|
2012-06-10 02:49:59 -05:00
|
|
|
ast_map::path_to_str(path), *ii.ident(),
|
2012-07-30 18:01:07 -05:00
|
|
|
ebml_w.writer.tell()};
|
2012-03-01 12:36:22 -06:00
|
|
|
|
2012-06-13 18:14:01 -05:00
|
|
|
let id_range = ast_util::compute_id_range_for_inlined_item(ii);
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(c::tag_ast as uint) {
|
2012-06-13 18:14:01 -05:00
|
|
|
ast_util::serialize_id_range(ebml_w, id_range);
|
2012-03-07 17:13:31 -06:00
|
|
|
encode_ast(ebml_w, simplify_ast(ii));
|
2012-05-14 19:46:45 -05:00
|
|
|
encode_side_tables_for_ii(ecx, maps, ebml_w, ii);
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
2012-03-01 12:36:22 -06:00
|
|
|
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"< Encoded inlined fn: %s::%s (%u)",
|
2012-06-10 02:49:59 -05:00
|
|
|
ast_map::path_to_str(path), *ii.ident(),
|
2012-07-30 18:01:07 -05:00
|
|
|
ebml_w.writer.tell()};
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-03-01 21:37:52 -06:00
|
|
|
fn decode_inlined_item(cdata: cstore::crate_metadata,
|
|
|
|
tcx: ty::ctxt,
|
|
|
|
maps: maps,
|
|
|
|
path: ast_map::path,
|
|
|
|
par_doc: ebml::doc) -> option<ast::inlined_item> {
|
2012-02-14 17:21:53 -06:00
|
|
|
let dcx = @{cdata: cdata, tcx: tcx, maps: maps};
|
2012-08-06 14:34:08 -05:00
|
|
|
match par_doc.opt_child(c::tag_ast) {
|
2012-08-03 21:59:04 -05:00
|
|
|
none => none,
|
|
|
|
some(ast_doc) => {
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"> Decoding inlined fn: %s::?", ast_map::path_to_str(path)};
|
2012-06-13 18:14:01 -05:00
|
|
|
let ast_dsr = ebml::ebml_deserializer(ast_doc);
|
|
|
|
let from_id_range = ast_util::deserialize_id_range(ast_dsr);
|
2012-02-14 17:21:53 -06:00
|
|
|
let to_id_range = reserve_id_range(dcx.tcx.sess, from_id_range);
|
2012-07-11 17:00:40 -05:00
|
|
|
let xcx = extended_decode_ctxt_(@{dcx: dcx,
|
|
|
|
from_id_range: from_id_range,
|
|
|
|
to_id_range: to_id_range});
|
2012-03-01 21:37:52 -06:00
|
|
|
let raw_ii = decode_ast(ast_doc);
|
|
|
|
let ii = renumber_ast(xcx, raw_ii);
|
2012-05-22 00:57:43 -05:00
|
|
|
ast_map::map_decoded_item(tcx.sess.diagnostic(),
|
|
|
|
dcx.tcx.items, path, ii);
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"Fn named: %s", *ii.ident()};
|
2012-02-14 17:21:53 -06:00
|
|
|
decode_side_tables(xcx, ast_doc);
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"< Decoded inlined fn: %s::%s",
|
|
|
|
ast_map::path_to_str(path), *ii.ident()};
|
2012-08-06 14:34:08 -05:00
|
|
|
match ii {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::ii_item(i) => {
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{">>> DECODED ITEM >>>\n%s\n<<< DECODED ITEM <<<",
|
|
|
|
syntax::print::pprust::item_to_str(i)};
|
2012-04-20 18:56:51 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => { }
|
2012-04-20 18:56:51 -05:00
|
|
|
}
|
2012-03-01 21:37:52 -06:00
|
|
|
some(ii)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
// ______________________________________________________________________
|
|
|
|
// Enumerating the IDs which appear in an AST
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-02-28 15:40:35 -06:00
|
|
|
fn reserve_id_range(sess: session,
|
2012-06-13 18:14:01 -05:00
|
|
|
from_id_range: ast_util::id_range) -> ast_util::id_range {
|
2012-02-14 17:21:53 -06:00
|
|
|
// Handle the case of an empty range:
|
2012-08-01 19:30:05 -05:00
|
|
|
if ast_util::empty(from_id_range) { return from_id_range; }
|
2012-02-14 17:21:53 -06:00
|
|
|
let cnt = from_id_range.max - from_id_range.min;
|
|
|
|
let to_id_min = sess.parse_sess.next_id;
|
|
|
|
let to_id_max = sess.parse_sess.next_id + cnt;
|
|
|
|
sess.parse_sess.next_id = to_id_max;
|
2012-08-01 19:30:05 -05:00
|
|
|
return {min: to_id_min, max: to_id_min};
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl extended_decode_ctxt {
|
2012-02-14 17:21:53 -06:00
|
|
|
fn tr_id(id: ast::node_id) -> ast::node_id {
|
|
|
|
// from_id_range should be non-empty
|
2012-06-13 18:14:01 -05:00
|
|
|
assert !ast_util::empty(self.from_id_range);
|
2012-02-14 17:21:53 -06:00
|
|
|
(id - self.from_id_range.min + self.to_id_range.min)
|
|
|
|
}
|
|
|
|
fn tr_def_id(did: ast::def_id) -> ast::def_id {
|
|
|
|
decoder::translate_def_id(self.dcx.cdata, did)
|
|
|
|
}
|
|
|
|
fn tr_intern_def_id(did: ast::def_id) -> ast::def_id {
|
|
|
|
assert did.crate == ast::local_crate;
|
|
|
|
{crate: ast::local_crate, node: self.tr_id(did.node)}
|
|
|
|
}
|
|
|
|
fn tr_span(_span: span) -> span {
|
2012-07-05 17:58:25 -05:00
|
|
|
ast_util::dummy_sp() // FIXME (#1972): handle span properly
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl ast::def_id: tr {
|
2012-02-14 17:21:53 -06:00
|
|
|
fn tr(xcx: extended_decode_ctxt) -> ast::def_id {
|
|
|
|
xcx.tr_def_id(self)
|
|
|
|
}
|
|
|
|
fn tr_intern(xcx: extended_decode_ctxt) -> ast::def_id {
|
|
|
|
xcx.tr_intern_def_id(self)
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl span: tr {
|
2012-02-14 17:21:53 -06:00
|
|
|
fn tr(xcx: extended_decode_ctxt) -> span {
|
|
|
|
xcx.tr_span(self)
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
trait def_id_serializer_helpers {
|
|
|
|
fn emit_def_id(did: ast::def_id);
|
|
|
|
}
|
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl<S: serializer> S: def_id_serializer_helpers {
|
2012-02-14 17:21:53 -06:00
|
|
|
fn emit_def_id(did: ast::def_id) {
|
2012-03-15 09:15:49 -05:00
|
|
|
ast::serialize_def_id(self, did)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
trait def_id_deserializer_helpers {
|
|
|
|
fn read_def_id(xcx: extended_decode_ctxt) -> ast::def_id;
|
|
|
|
}
|
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl<D: deserializer> D: def_id_deserializer_helpers {
|
2012-07-11 17:00:40 -05:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
fn read_def_id(xcx: extended_decode_ctxt) -> ast::def_id {
|
2012-03-15 09:15:49 -05:00
|
|
|
let did = ast::deserialize_def_id(self);
|
2012-02-14 17:21:53 -06:00
|
|
|
did.tr(xcx)
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
// ______________________________________________________________________
|
|
|
|
// Encoding and decoding the AST itself
|
|
|
|
//
|
|
|
|
// The hard work is done by an autogenerated module astencode_gen. To
|
|
|
|
// regenerate astencode_gen, run src/etc/gen-astencode. It will
|
|
|
|
// replace astencode_gen with a dummy file and regenerate its
|
|
|
|
// contents. If you get compile errors, the dummy file
|
|
|
|
// remains---resolve the errors and then rerun astencode_gen.
|
|
|
|
// Annoying, I know, but hopefully only temporary.
|
|
|
|
//
|
|
|
|
// When decoding, we have to renumber the AST so that the node ids that
|
|
|
|
// appear within are disjoint from the node ids in our existing ASTs.
|
|
|
|
// 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.
|
|
|
|
|
2012-03-01 21:37:52 -06:00
|
|
|
fn encode_ast(ebml_w: ebml::writer, item: ast::inlined_item) {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(c::tag_tree as uint) {
|
2012-03-15 09:15:49 -05:00
|
|
|
ast::serialize_inlined_item(ebml_w, item)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-03-07 17:13:31 -06:00
|
|
|
// Produces a simplified copy of the AST which does not include things
|
|
|
|
// that we do not need to or do not want to export. For example, we
|
|
|
|
// do not include any nested items: if these nested items are to be
|
|
|
|
// inlined, their AST will be exported separately (this only makes
|
|
|
|
// sense because, in Rust, nested items are independent except for
|
|
|
|
// their visibility).
|
|
|
|
//
|
|
|
|
// As it happens, trans relies on the fact that we do not export
|
|
|
|
// nested items, as otherwise it would get confused when translating
|
|
|
|
// inlined items.
|
|
|
|
fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
|
|
|
|
fn drop_nested_items(blk: ast::blk_, fld: fold::ast_fold) -> ast::blk_ {
|
2012-06-30 18:19:07 -05:00
|
|
|
let stmts_sans_items = do vec::filter(blk.stmts) |stmt| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match stmt.node {
|
2012-07-03 19:30:25 -05:00
|
|
|
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) |
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::stmt_decl(@{node: ast::decl_local(_), span: _}, _) => true,
|
|
|
|
ast::stmt_decl(@{node: ast::decl_item(_), span: _}, _) => false
|
2012-03-07 17:13:31 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
let blk_sans_items = { stmts: stmts_sans_items with blk };
|
|
|
|
fold::noop_fold_block(blk_sans_items, fld)
|
|
|
|
}
|
|
|
|
|
2012-05-21 20:28:39 -05:00
|
|
|
let fld = fold::make_fold(@{
|
2012-03-07 17:13:31 -06:00
|
|
|
fold_block: fold::wrap(drop_nested_items)
|
|
|
|
with *fold::default_ast_fold()
|
|
|
|
});
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match ii {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::ii_item(i) => {
|
2012-07-06 14:17:34 -05:00
|
|
|
ast::ii_item(fld.fold_item(i).get()) //hack: we're not dropping items
|
2012-03-07 17:13:31 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::ii_method(d, m) => {
|
2012-03-07 17:13:31 -06:00
|
|
|
ast::ii_method(d, fld.fold_method(m))
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::ii_foreign(i) => {
|
2012-06-26 18:18:37 -05:00
|
|
|
ast::ii_foreign(fld.fold_foreign_item(i))
|
2012-03-21 09:42:20 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::ii_ctor(ctor, nm, tps, parent_id) => {
|
2012-04-10 12:52:06 -05:00
|
|
|
let ctor_body = fld.fold_block(ctor.node.body);
|
|
|
|
let ctor_decl = fold::fold_fn_decl(ctor.node.dec, fld);
|
|
|
|
ast::ii_ctor({node: {body: ctor_body, dec: ctor_decl
|
|
|
|
with ctor.node}
|
|
|
|
with ctor}, nm, tps, parent_id)
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::ii_dtor(dtor, nm, tps, parent_id) => {
|
2012-06-12 18:25:09 -05:00
|
|
|
let dtor_body = fld.fold_block(dtor.node.body);
|
|
|
|
ast::ii_dtor({node: {body: dtor_body
|
|
|
|
with dtor.node}
|
|
|
|
with dtor}, nm, tps, parent_id)
|
|
|
|
}
|
2012-03-07 17:13:31 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-01 21:37:52 -06:00
|
|
|
fn decode_ast(par_doc: ebml::doc) -> ast::inlined_item {
|
2012-07-27 21:32:42 -05:00
|
|
|
let chi_doc = par_doc[c::tag_tree as uint];
|
2012-03-12 12:19:35 -05:00
|
|
|
let d = ebml::ebml_deserializer(chi_doc);
|
2012-03-15 09:15:49 -05:00
|
|
|
ast::deserialize_inlined_item(d)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-03-01 21:37:52 -06:00
|
|
|
fn renumber_ast(xcx: extended_decode_ctxt, ii: ast::inlined_item)
|
|
|
|
-> ast::inlined_item {
|
2012-05-21 20:28:39 -05:00
|
|
|
let fld = fold::make_fold(@{
|
2012-06-30 18:19:07 -05:00
|
|
|
new_id: |a| xcx.tr_id(a),
|
|
|
|
new_span: |a| xcx.tr_span(a)
|
2012-02-14 17:21:53 -06:00
|
|
|
with *fold::default_ast_fold()
|
|
|
|
});
|
2012-03-01 21:37:52 -06:00
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match ii {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::ii_item(i) => {
|
2012-07-06 14:17:34 -05:00
|
|
|
ast::ii_item(fld.fold_item(i).get())
|
2012-03-01 21:37:52 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::ii_method(d, m) => {
|
2012-03-01 21:37:52 -06:00
|
|
|
ast::ii_method(xcx.tr_def_id(d), fld.fold_method(m))
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::ii_foreign(i) => {
|
2012-06-26 18:18:37 -05:00
|
|
|
ast::ii_foreign(fld.fold_foreign_item(i))
|
2012-03-21 09:42:20 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::ii_ctor(ctor, nm, tps, parent_id) => {
|
2012-04-10 12:52:06 -05:00
|
|
|
let ctor_body = fld.fold_block(ctor.node.body);
|
2012-07-16 21:16:19 -05:00
|
|
|
let ctor_attrs = fld.fold_attributes(ctor.node.attrs);
|
2012-04-10 12:52:06 -05:00
|
|
|
let ctor_decl = fold::fold_fn_decl(ctor.node.dec, fld);
|
|
|
|
let new_params = fold::fold_ty_params(tps, fld);
|
|
|
|
let ctor_id = fld.new_id(ctor.node.id);
|
|
|
|
let new_parent = xcx.tr_def_id(parent_id);
|
2012-07-16 21:16:19 -05:00
|
|
|
ast::ii_ctor({node: {body: ctor_body, attrs: ctor_attrs,
|
|
|
|
dec: ctor_decl, id: ctor_id
|
2012-04-10 12:52:06 -05:00
|
|
|
with ctor.node}
|
|
|
|
with ctor}, nm, new_params, new_parent)
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::ii_dtor(dtor, nm, tps, parent_id) => {
|
2012-06-12 18:25:09 -05:00
|
|
|
let dtor_body = fld.fold_block(dtor.node.body);
|
2012-07-16 21:16:19 -05:00
|
|
|
let dtor_attrs = fld.fold_attributes(dtor.node.attrs);
|
2012-06-12 18:25:09 -05:00
|
|
|
let new_params = fold::fold_ty_params(tps, fld);
|
|
|
|
let dtor_id = fld.new_id(dtor.node.id);
|
|
|
|
let new_parent = xcx.tr_def_id(parent_id);
|
|
|
|
let new_self = fld.new_id(dtor.node.self_id);
|
2012-07-16 21:16:19 -05:00
|
|
|
ast::ii_dtor({node: {id: dtor_id, attrs: dtor_attrs,
|
|
|
|
self_id: new_self, body: dtor_body}
|
2012-06-12 18:25:09 -05:00
|
|
|
with dtor},
|
|
|
|
nm, new_params, new_parent)
|
|
|
|
}
|
2012-04-10 12:52:06 -05:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
// ______________________________________________________________________
|
|
|
|
// Encoding and decoding of ast::def
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
fn encode_def(ebml_w: ebml::writer, def: ast::def) {
|
2012-03-15 09:15:49 -05:00
|
|
|
ast::serialize_def(ebml_w, def)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
fn decode_def(xcx: extended_decode_ctxt, doc: ebml::doc) -> ast::def {
|
2012-03-12 12:19:35 -05:00
|
|
|
let dsr = ebml::ebml_deserializer(doc);
|
2012-03-15 09:15:49 -05:00
|
|
|
let def = ast::deserialize_def(dsr);
|
2012-02-14 17:21:53 -06:00
|
|
|
def.tr(xcx)
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl ast::def: tr {
|
2012-02-14 17:21:53 -06:00
|
|
|
fn tr(xcx: extended_decode_ctxt) -> ast::def {
|
2012-08-06 14:34:08 -05:00
|
|
|
match self {
|
2012-08-02 18:01:38 -05:00
|
|
|
ast::def_fn(did, p) => { ast::def_fn(did.tr(xcx), p) }
|
|
|
|
ast::def_static_method(did, p) => {
|
|
|
|
ast::def_static_method(did.tr(xcx), p)
|
|
|
|
}
|
|
|
|
ast::def_self(nid) => { ast::def_self(xcx.tr_id(nid)) }
|
|
|
|
ast::def_mod(did) => { ast::def_mod(did.tr(xcx)) }
|
|
|
|
ast::def_foreign_mod(did) => { ast::def_foreign_mod(did.tr(xcx)) }
|
|
|
|
ast::def_const(did) => { ast::def_const(did.tr(xcx)) }
|
|
|
|
ast::def_arg(nid, m) => { ast::def_arg(xcx.tr_id(nid), m) }
|
|
|
|
ast::def_local(nid, b) => { ast::def_local(xcx.tr_id(nid), b) }
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::def_variant(e_did, v_did) => {
|
2012-02-14 17:21:53 -06:00
|
|
|
ast::def_variant(e_did.tr(xcx), v_did.tr(xcx))
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::def_ty(did) => ast::def_ty(did.tr(xcx)),
|
|
|
|
ast::def_prim_ty(p) => ast::def_prim_ty(p),
|
|
|
|
ast::def_ty_param(did, v) => ast::def_ty_param(did.tr(xcx), v),
|
|
|
|
ast::def_binding(nid, bm) => ast::def_binding(xcx.tr_id(nid), bm),
|
|
|
|
ast::def_use(did) => ast::def_use(did.tr(xcx)),
|
2012-08-20 18:53:33 -05:00
|
|
|
ast::def_upvar(nid1, def, nid2, nid3) => {
|
|
|
|
ast::def_upvar(xcx.tr_id(nid1),
|
|
|
|
@(*def).tr(xcx),
|
|
|
|
xcx.tr_id(nid2),
|
|
|
|
xcx.tr_id(nid3))
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::def_class(did, has_constructor) => {
|
2012-07-26 17:29:33 -05:00
|
|
|
ast::def_class(did.tr(xcx), has_constructor)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::def_region(nid) => ast::def_region(xcx.tr_id(nid)),
|
|
|
|
ast::def_typaram_binder(nid) => {
|
2012-07-26 16:04:03 -05:00
|
|
|
ast::def_typaram_binder(xcx.tr_id(nid))
|
|
|
|
}
|
2012-08-14 21:20:56 -05:00
|
|
|
ast::def_label(nid) => ast::def_label(xcx.tr_id(nid))
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
// ______________________________________________________________________
|
|
|
|
// Encoding and decoding of freevar information
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
fn encode_freevar_entry(ebml_w: ebml::writer, fv: freevar_entry) {
|
2012-03-15 09:15:49 -05:00
|
|
|
serialize_freevar_entry(ebml_w, fv)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
trait ebml_deserializer_helper {
|
|
|
|
fn read_freevar_entry(xcx: extended_decode_ctxt) -> freevar_entry;
|
|
|
|
}
|
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl ebml::ebml_deserializer: ebml_deserializer_helper {
|
2012-02-14 17:21:53 -06:00
|
|
|
fn read_freevar_entry(xcx: extended_decode_ctxt) -> freevar_entry {
|
2012-03-15 09:15:49 -05:00
|
|
|
let fv = deserialize_freevar_entry(self);
|
2012-02-14 17:21:53 -06:00
|
|
|
fv.tr(xcx)
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl freevar_entry: tr {
|
2012-02-14 17:21:53 -06:00
|
|
|
fn tr(xcx: extended_decode_ctxt) -> freevar_entry {
|
|
|
|
{def: self.def.tr(xcx), span: self.span.tr(xcx)}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
// ______________________________________________________________________
|
2012-06-07 12:51:21 -05:00
|
|
|
// Encoding and decoding of method_map_entry
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
trait read_method_map_entry_helper {
|
|
|
|
fn read_method_map_entry(xcx: extended_decode_ctxt) -> method_map_entry;
|
|
|
|
}
|
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl ebml::ebml_deserializer: read_method_map_entry_helper {
|
2012-06-07 12:51:21 -05:00
|
|
|
fn read_method_map_entry(xcx: extended_decode_ctxt) -> method_map_entry {
|
|
|
|
let mme = deserialize_method_map_entry(self);
|
2012-08-16 18:44:22 -05:00
|
|
|
{derefs: mme.derefs,
|
|
|
|
self_mode: mme.self_mode,
|
|
|
|
origin: mme.origin.tr(xcx)}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl method_origin: tr {
|
2012-02-14 17:21:53 -06:00
|
|
|
fn tr(xcx: extended_decode_ctxt) -> method_origin {
|
2012-08-06 14:34:08 -05:00
|
|
|
match self {
|
2012-08-03 21:59:04 -05:00
|
|
|
typeck::method_static(did) => {
|
2012-02-14 17:21:53 -06:00
|
|
|
typeck::method_static(did.tr(xcx))
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
typeck::method_param(mp) => {
|
2012-07-03 18:30:42 -05:00
|
|
|
typeck::method_param({trait_id:mp.trait_id.tr(xcx) with mp})
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
typeck::method_trait(did, m) => {
|
2012-07-03 18:30:42 -05:00
|
|
|
typeck::method_trait(did.tr(xcx), m)
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
// ______________________________________________________________________
|
2012-03-08 09:17:59 -06:00
|
|
|
// Encoding and decoding vtable_res
|
2012-02-14 17:21:53 -06:00
|
|
|
|
2012-03-08 09:17:59 -06:00
|
|
|
fn encode_vtable_res(ecx: @e::encode_ctxt,
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w: ebml::writer,
|
2012-03-08 09:17:59 -06:00
|
|
|
dr: typeck::vtable_res) {
|
2012-02-14 17:21:53 -06:00
|
|
|
// can't autogenerate this code because automatic serialization of
|
|
|
|
// ty::t doesn't work, and there is no way (atm) to have
|
|
|
|
// hand-written serialization routines combine with auto-generated
|
|
|
|
// ones. perhaps we should fix this.
|
2012-06-30 18:19:07 -05:00
|
|
|
do ebml_w.emit_from_vec(*dr) |vtable_origin| {
|
2012-03-08 09:17:59 -06:00
|
|
|
encode_vtable_origin(ecx, ebml_w, vtable_origin)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-03-08 09:17:59 -06:00
|
|
|
fn encode_vtable_origin(ecx: @e::encode_ctxt,
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w: ebml::writer,
|
2012-03-08 09:17:59 -06:00
|
|
|
vtable_origin: typeck::vtable_origin) {
|
2012-07-14 00:57:48 -05:00
|
|
|
do ebml_w.emit_enum(~"vtable_origin") {
|
2012-08-06 14:34:08 -05:00
|
|
|
match vtable_origin {
|
2012-08-03 21:59:04 -05:00
|
|
|
typeck::vtable_static(def_id, tys, vtable_res) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
do ebml_w.emit_enum_variant(~"vtable_static", 0u, 3u) {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.emit_enum_variant_arg(0u) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.emit_def_id(def_id)
|
|
|
|
}
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.emit_enum_variant_arg(1u) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.emit_tys(ecx, tys);
|
|
|
|
}
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.emit_enum_variant_arg(2u) {
|
2012-03-08 09:17:59 -06:00
|
|
|
encode_vtable_res(ecx, ebml_w, vtable_res);
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
typeck::vtable_param(pn, bn) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
do ebml_w.emit_enum_variant(~"vtable_param", 1u, 2u) {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.emit_enum_variant_arg(0u) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.emit_uint(pn);
|
|
|
|
}
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.emit_enum_variant_arg(1u) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.emit_uint(bn);
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
typeck::vtable_trait(def_id, tys) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
do ebml_w.emit_enum_variant(~"vtable_trait", 1u, 3u) {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.emit_enum_variant_arg(0u) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.emit_def_id(def_id)
|
|
|
|
}
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.emit_enum_variant_arg(1u) {
|
2012-03-08 09:10:25 -06:00
|
|
|
ebml_w.emit_tys(ecx, tys);
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
trait vtable_deserialization_helpers {
|
|
|
|
fn read_vtable_res(xcx: extended_decode_ctxt) -> typeck::vtable_res;
|
|
|
|
fn read_vtable_origin(xcx: extended_decode_ctxt) -> typeck::vtable_origin;
|
|
|
|
}
|
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl ebml::ebml_deserializer: vtable_deserialization_helpers {
|
2012-03-08 09:17:59 -06:00
|
|
|
fn read_vtable_res(xcx: extended_decode_ctxt) -> typeck::vtable_res {
|
2012-06-30 18:19:07 -05:00
|
|
|
@self.read_to_vec(|| self.read_vtable_origin(xcx) )
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-03-08 09:17:59 -06:00
|
|
|
fn read_vtable_origin(xcx: extended_decode_ctxt)
|
|
|
|
-> typeck::vtable_origin {
|
2012-07-14 00:57:48 -05:00
|
|
|
do self.read_enum(~"vtable_origin") {
|
2012-06-30 18:19:07 -05:00
|
|
|
do self.read_enum_variant |i| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match check i {
|
2012-08-03 21:59:04 -05:00
|
|
|
0u => {
|
2012-03-08 09:17:59 -06:00
|
|
|
typeck::vtable_static(
|
2012-07-04 14:04:28 -05:00
|
|
|
do self.read_enum_variant_arg(0u) {
|
2012-02-14 17:21:53 -06:00
|
|
|
self.read_def_id(xcx)
|
|
|
|
},
|
2012-07-04 14:04:28 -05:00
|
|
|
do self.read_enum_variant_arg(1u) {
|
2012-02-14 17:21:53 -06:00
|
|
|
self.read_tys(xcx)
|
|
|
|
},
|
2012-07-04 14:04:28 -05:00
|
|
|
do self.read_enum_variant_arg(2u) {
|
2012-03-08 09:17:59 -06:00
|
|
|
self.read_vtable_res(xcx)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
1u => {
|
2012-03-08 09:17:59 -06:00
|
|
|
typeck::vtable_param(
|
2012-07-04 14:04:28 -05:00
|
|
|
do self.read_enum_variant_arg(0u) {
|
2012-02-14 17:21:53 -06:00
|
|
|
self.read_uint()
|
|
|
|
},
|
2012-07-04 14:04:28 -05:00
|
|
|
do self.read_enum_variant_arg(1u) {
|
2012-02-14 17:21:53 -06:00
|
|
|
self.read_uint()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
2u => {
|
2012-07-03 18:30:42 -05:00
|
|
|
typeck::vtable_trait(
|
2012-07-04 14:04:28 -05:00
|
|
|
do self.read_enum_variant_arg(0u) {
|
2012-02-14 17:21:53 -06:00
|
|
|
self.read_def_id(xcx)
|
2012-03-08 09:10:25 -06:00
|
|
|
},
|
2012-07-04 14:04:28 -05:00
|
|
|
do self.read_enum_variant_arg(1u) {
|
2012-03-08 09:10:25 -06:00
|
|
|
self.read_tys(xcx)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
// ______________________________________________________________________
|
|
|
|
// Encoding and decoding the side tables
|
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
trait get_ty_str_ctxt {
|
|
|
|
fn ty_str_ctxt() -> @tyencode::ctxt;
|
|
|
|
}
|
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl @e::encode_ctxt: get_ty_str_ctxt {
|
2012-02-14 17:21:53 -06:00
|
|
|
fn ty_str_ctxt() -> @tyencode::ctxt {
|
2012-05-14 22:41:33 -05:00
|
|
|
@{diag: self.tcx.sess.diagnostic(),
|
|
|
|
ds: e::def_to_str,
|
2012-05-13 19:01:52 -05:00
|
|
|
tcx: self.tcx,
|
2012-06-30 18:19:07 -05:00
|
|
|
reachable: |a| encoder::reachable(self, a),
|
2012-02-14 17:21:53 -06:00
|
|
|
abbrevs: tyencode::ac_use_abbrevs(self.type_abbrevs)}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
trait ebml_writer_helpers {
|
|
|
|
fn emit_ty(ecx: @e::encode_ctxt, ty: ty::t);
|
|
|
|
fn emit_tys(ecx: @e::encode_ctxt, tys: ~[ty::t]);
|
|
|
|
fn emit_bounds(ecx: @e::encode_ctxt, bs: ty::param_bounds);
|
|
|
|
fn emit_tpbt(ecx: @e::encode_ctxt, tpbt: ty::ty_param_bounds_and_ty);
|
|
|
|
}
|
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl ebml::writer: ebml_writer_helpers {
|
2012-02-14 17:21:53 -06:00
|
|
|
fn emit_ty(ecx: @e::encode_ctxt, ty: ty::t) {
|
|
|
|
e::write_type(ecx, self, ty)
|
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn emit_tys(ecx: @e::encode_ctxt, tys: ~[ty::t]) {
|
2012-06-30 18:19:07 -05:00
|
|
|
do self.emit_from_vec(tys) |ty| {
|
2012-02-14 17:21:53 -06:00
|
|
|
e::write_type(ecx, self, ty)
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
fn emit_bounds(ecx: @e::encode_ctxt, bs: ty::param_bounds) {
|
|
|
|
tyencode::enc_bounds(self.writer, ecx.ty_str_ctxt(), bs)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn emit_tpbt(ecx: @e::encode_ctxt, tpbt: ty::ty_param_bounds_and_ty) {
|
2012-07-04 14:04:28 -05:00
|
|
|
do self.emit_rec {
|
2012-07-14 00:57:48 -05:00
|
|
|
do self.emit_rec_field(~"bounds", 0u) {
|
2012-06-30 18:19:07 -05:00
|
|
|
do self.emit_from_vec(*tpbt.bounds) |bs| {
|
2012-07-11 12:28:30 -05:00
|
|
|
self.emit_bounds(ecx, bs);
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
do self.emit_rec_field(~"rp", 1u) {
|
2012-07-11 12:28:30 -05:00
|
|
|
self.emit_bool(tpbt.rp);
|
2012-04-18 23:26:25 -05:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
do self.emit_rec_field(~"ty", 2u) {
|
2012-02-14 17:21:53 -06:00
|
|
|
self.emit_ty(ecx, tpbt.ty);
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
trait write_tag_and_id {
|
|
|
|
fn tag(tag_id: c::astencode_tag, f: fn());
|
|
|
|
fn id(id: ast::node_id);
|
|
|
|
}
|
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl ebml::writer: write_tag_and_id {
|
2012-02-14 17:21:53 -06:00
|
|
|
fn tag(tag_id: c::astencode_tag, f: fn()) {
|
2012-07-04 14:04:28 -05:00
|
|
|
do self.wr_tag(tag_id as uint) { f() }
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
fn id(id: ast::node_id) {
|
|
|
|
self.wr_tagged_u64(c::tag_table_id as uint, id as u64)
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-03-01 21:37:52 -06:00
|
|
|
fn encode_side_tables_for_ii(ecx: @e::encode_ctxt,
|
2012-05-14 19:46:45 -05:00
|
|
|
maps: maps,
|
2012-03-01 21:37:52 -06:00
|
|
|
ebml_w: ebml::writer,
|
|
|
|
ii: ast::inlined_item) {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(c::tag_table as uint) {
|
2012-06-13 18:14:01 -05:00
|
|
|
ast_util::visit_ids_for_inlined_item(
|
|
|
|
ii,
|
|
|
|
fn@(id: ast::node_id, copy ebml_w) {
|
|
|
|
// Note: this will cause a copy of ebml_w, which is bad as
|
|
|
|
// it has mut fields. But I believe it's harmless since
|
|
|
|
// we generate balanced EBML.
|
|
|
|
encode_side_tables_for_id(ecx, maps, ebml_w, id)
|
|
|
|
});
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
|
2012-05-14 19:46:45 -05:00
|
|
|
maps: maps,
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w: ebml::writer,
|
|
|
|
id: ast::node_id) {
|
2012-05-13 19:01:52 -05:00
|
|
|
let tcx = ecx.tcx;
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"Encoding side tables for id %d", id};
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do option::iter(tcx.def_map.find(id)) |def| {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_def) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.id(id);
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_val) {
|
2012-03-15 09:15:49 -05:00
|
|
|
ast::serialize_def(ebml_w, def)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-30 18:19:07 -05:00
|
|
|
do option::iter((*tcx.node_types).find(id as uint)) |ty| {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_node_type) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.id(id);
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_val) {
|
2012-02-14 17:21:53 -06:00
|
|
|
e::write_type(ecx, ebml_w, ty)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do option::iter(tcx.node_type_substs.find(id)) |tys| {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_node_type_subst) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.id(id);
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_val) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.emit_tys(ecx, tys)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do option::iter(tcx.freevars.find(id)) |fv| {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_freevars) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.id(id);
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_val) {
|
2012-06-30 18:19:07 -05:00
|
|
|
do ebml_w.emit_from_vec(*fv) |fv_entry| {
|
2012-02-27 16:06:44 -06:00
|
|
|
encode_freevar_entry(ebml_w, *fv_entry)
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
let lid = {crate: ast::local_crate, node: id};
|
2012-06-30 18:19:07 -05:00
|
|
|
do option::iter(tcx.tcache.find(lid)) |tpbt| {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_tcache) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.id(id);
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_val) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.emit_tpbt(ecx, tpbt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do option::iter(tcx.ty_param_bounds.find(id)) |pbs| {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_param_bounds) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.id(id);
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_val) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.emit_bounds(ecx, pbs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
// I believe it is not necessary to encode this information. The
|
|
|
|
// ids will appear in the AST but in the *type* information, which
|
|
|
|
// is what we actually use in trans, all modes will have been
|
|
|
|
// resolved.
|
|
|
|
//
|
2012-04-06 14:14:09 -05:00
|
|
|
//option::iter(tcx.inferred_modes.find(id)) {|m|
|
2012-02-14 17:21:53 -06:00
|
|
|
// ebml_w.tag(c::tag_table_inferred_modes) {||
|
|
|
|
// ebml_w.id(id);
|
|
|
|
// ebml_w.tag(c::tag_table_val) {||
|
|
|
|
// tyencode::enc_mode(ebml_w.writer, ty_str_ctxt(), m);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do option::iter(maps.mutbl_map.find(id)) |_m| {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_mutbl) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.id(id);
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do option::iter(maps.last_use_map.find(id)) |m| {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_last_use) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.id(id);
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_val) {
|
2012-06-30 18:19:07 -05:00
|
|
|
do ebml_w.emit_from_vec((*m).get()) |id| {
|
2012-05-25 02:14:40 -05:00
|
|
|
ebml_w.emit_int(id);
|
|
|
|
}
|
2012-03-08 04:14:35 -06:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do option::iter(maps.method_map.find(id)) |mme| {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_method_map) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.id(id);
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_val) {
|
2012-06-07 12:51:21 -05:00
|
|
|
serialize_method_map_entry(ebml_w, mme)
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do option::iter(maps.vtable_map.find(id)) |dr| {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_vtable_map) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.id(id);
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_val) {
|
2012-03-08 09:17:59 -06:00
|
|
|
encode_vtable_res(ecx, ebml_w, dr);
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-23 17:23:20 -05:00
|
|
|
|
2012-07-26 10:51:57 -05:00
|
|
|
do option::iter(tcx.borrowings.find(id)) |_borrow| {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_borrowings) {
|
2012-04-23 17:23:20 -05:00
|
|
|
ebml_w.id(id);
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.tag(c::tag_table_val) {
|
2012-07-26 10:51:57 -05:00
|
|
|
// N.B. We don't actually serialize borrows as, in
|
|
|
|
// trans, we only care whether a value is borrowed or
|
|
|
|
// not.
|
2012-05-31 16:02:39 -05:00
|
|
|
}
|
2012-04-23 17:23:20 -05:00
|
|
|
}
|
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
trait doc_decoder_helpers {
|
|
|
|
fn as_int() -> int;
|
|
|
|
fn opt_child(tag: c::astencode_tag) -> option<ebml::doc>;
|
|
|
|
}
|
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl ebml::doc: doc_decoder_helpers {
|
2012-02-14 17:21:53 -06:00
|
|
|
fn as_int() -> int { ebml::doc_as_u64(self) as int }
|
|
|
|
fn opt_child(tag: c::astencode_tag) -> option<ebml::doc> {
|
|
|
|
ebml::maybe_get_doc(self, tag as uint)
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
trait ebml_deserializer_decoder_helpers {
|
|
|
|
fn read_ty(xcx: extended_decode_ctxt) -> ty::t;
|
|
|
|
fn read_tys(xcx: extended_decode_ctxt) -> ~[ty::t];
|
|
|
|
fn read_bounds(xcx: extended_decode_ctxt) -> @~[ty::param_bound];
|
|
|
|
fn read_ty_param_bounds_and_ty(xcx: extended_decode_ctxt)
|
|
|
|
-> ty::ty_param_bounds_and_ty;
|
|
|
|
}
|
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl ebml::ebml_deserializer: ebml_deserializer_decoder_helpers {
|
2012-07-11 17:00:40 -05:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
fn read_ty(xcx: extended_decode_ctxt) -> ty::t {
|
2012-04-18 23:26:25 -05:00
|
|
|
// Note: regions types embed local node ids. In principle, we
|
|
|
|
// should translate these node ids into the new decode
|
|
|
|
// context. However, we do not bother, because region types
|
|
|
|
// are not used during trans.
|
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
tydecode::parse_ty_data(
|
|
|
|
self.parent.data, xcx.dcx.cdata.cnum, self.pos, xcx.dcx.tcx,
|
2012-06-30 18:19:07 -05:00
|
|
|
|a| xcx.tr_def_id(a) )
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn read_tys(xcx: extended_decode_ctxt) -> ~[ty::t] {
|
2012-06-30 18:19:07 -05:00
|
|
|
self.read_to_vec(|| self.read_ty(xcx) )
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn read_bounds(xcx: extended_decode_ctxt) -> @~[ty::param_bound] {
|
2012-02-14 17:21:53 -06:00
|
|
|
tydecode::parse_bounds_data(
|
|
|
|
self.parent.data, self.pos, xcx.dcx.cdata.cnum, xcx.dcx.tcx,
|
2012-06-30 18:19:07 -05:00
|
|
|
|a| xcx.tr_def_id(a) )
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn read_ty_param_bounds_and_ty(xcx: extended_decode_ctxt)
|
|
|
|
-> ty::ty_param_bounds_and_ty {
|
2012-07-04 14:04:28 -05:00
|
|
|
do self.read_rec {
|
2012-02-14 17:21:53 -06:00
|
|
|
{
|
2012-07-14 00:57:48 -05:00
|
|
|
bounds: self.read_rec_field(~"bounds", 0u, || {
|
2012-06-30 18:19:07 -05:00
|
|
|
@self.read_to_vec(|| self.read_bounds(xcx) )
|
2012-06-26 15:55:56 -05:00
|
|
|
}),
|
2012-07-14 00:57:48 -05:00
|
|
|
rp: self.read_rec_field(~"rp", 1u, || {
|
2012-07-11 12:28:30 -05:00
|
|
|
self.read_bool()
|
2012-06-26 15:55:56 -05:00
|
|
|
}),
|
2012-07-14 00:57:48 -05:00
|
|
|
ty: self.read_rec_field(~"ty", 2u, || {
|
2012-02-14 17:21:53 -06:00
|
|
|
self.read_ty(xcx)
|
2012-06-26 15:55:56 -05:00
|
|
|
})
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn decode_side_tables(xcx: extended_decode_ctxt,
|
|
|
|
ast_doc: ebml::doc) {
|
|
|
|
let dcx = xcx.dcx;
|
2012-07-27 21:32:42 -05:00
|
|
|
let tbl_doc = ast_doc[c::tag_table as uint];
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::docs(tbl_doc) |tag, entry_doc| {
|
2012-07-27 21:32:42 -05:00
|
|
|
let id0 = entry_doc[c::tag_table_id as uint].as_int();
|
2012-02-14 17:21:53 -06:00
|
|
|
let id = xcx.tr_id(id0);
|
|
|
|
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{">> Side table document with tag 0x%x \
|
2012-02-27 23:23:49 -06:00
|
|
|
found for id %d (orig %d)",
|
2012-07-30 18:01:07 -05:00
|
|
|
tag, id, id0};
|
2012-02-14 17:21:53 -06:00
|
|
|
|
|
|
|
if tag == (c::tag_table_mutbl as uint) {
|
|
|
|
dcx.maps.mutbl_map.insert(id, ());
|
|
|
|
} else {
|
2012-07-27 21:32:42 -05:00
|
|
|
let val_doc = entry_doc[c::tag_table_val as uint];
|
2012-03-12 12:19:35 -05:00
|
|
|
let val_dsr = ebml::ebml_deserializer(val_doc);
|
2012-02-14 17:21:53 -06:00
|
|
|
if tag == (c::tag_table_def as uint) {
|
|
|
|
let def = decode_def(xcx, val_doc);
|
|
|
|
dcx.tcx.def_map.insert(id, def);
|
|
|
|
} else if tag == (c::tag_table_node_type as uint) {
|
|
|
|
let ty = val_dsr.read_ty(xcx);
|
|
|
|
(*dcx.tcx.node_types).insert(id as uint, ty);
|
|
|
|
} else if tag == (c::tag_table_node_type_subst as uint) {
|
|
|
|
let tys = val_dsr.read_tys(xcx);
|
|
|
|
dcx.tcx.node_type_substs.insert(id, tys);
|
|
|
|
} else if tag == (c::tag_table_freevars as uint) {
|
2012-06-30 18:19:07 -05:00
|
|
|
let fv_info = @val_dsr.read_to_vec(|| {
|
2012-02-14 17:21:53 -06:00
|
|
|
@val_dsr.read_freevar_entry(xcx)
|
2012-06-26 15:55:56 -05:00
|
|
|
});
|
2012-02-14 17:21:53 -06:00
|
|
|
dcx.tcx.freevars.insert(id, fv_info);
|
|
|
|
} else if tag == (c::tag_table_tcache as uint) {
|
|
|
|
let tpbt = val_dsr.read_ty_param_bounds_and_ty(xcx);
|
|
|
|
let lid = {crate: ast::local_crate, node: id};
|
|
|
|
dcx.tcx.tcache.insert(lid, tpbt);
|
|
|
|
} else if tag == (c::tag_table_param_bounds as uint) {
|
|
|
|
let bounds = val_dsr.read_bounds(xcx);
|
|
|
|
dcx.tcx.ty_param_bounds.insert(id, bounds);
|
2012-03-08 04:14:35 -06:00
|
|
|
} else if tag == (c::tag_table_last_use as uint) {
|
2012-06-30 18:19:07 -05:00
|
|
|
let ids = val_dsr.read_to_vec(|| {
|
2012-05-25 02:14:40 -05:00
|
|
|
xcx.tr_id(val_dsr.read_int())
|
2012-06-26 15:55:56 -05:00
|
|
|
});
|
2012-05-25 02:14:40 -05:00
|
|
|
let dvec = @dvec::from_vec(vec::to_mut(ids));
|
|
|
|
dcx.maps.last_use_map.insert(id, dvec);
|
2012-02-14 17:21:53 -06:00
|
|
|
} else if tag == (c::tag_table_method_map as uint) {
|
2012-06-07 12:51:21 -05:00
|
|
|
dcx.maps.method_map.insert(
|
|
|
|
id,
|
|
|
|
val_dsr.read_method_map_entry(xcx));
|
2012-03-08 09:17:59 -06:00
|
|
|
} else if tag == (c::tag_table_vtable_map as uint) {
|
|
|
|
dcx.maps.vtable_map.insert(id,
|
2012-04-26 18:02:01 -05:00
|
|
|
val_dsr.read_vtable_res(xcx));
|
|
|
|
} else if tag == (c::tag_table_borrowings as uint) {
|
2012-07-26 10:51:57 -05:00
|
|
|
// N.B.: we don't actually *serialize* borrows because, in
|
|
|
|
// trans, the only thing we care about is whether a value was
|
|
|
|
// borrowed or not.
|
|
|
|
let borrow = {region: ty::re_static, mutbl: ast::m_imm};
|
2012-05-31 16:02:39 -05:00
|
|
|
dcx.tcx.borrowings.insert(id, borrow);
|
2012-02-14 17:21:53 -06:00
|
|
|
} else {
|
|
|
|
xcx.dcx.tcx.sess.bug(
|
2012-07-30 18:01:07 -05:00
|
|
|
fmt!{"unknown tag found in side tables: %x", tag});
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
2012-02-27 16:06:44 -06:00
|
|
|
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{">< Side table doc loaded"};
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-03-15 09:15:49 -05:00
|
|
|
|
|
|
|
// ______________________________________________________________________
|
|
|
|
// Testing of astencode_gen
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
fn encode_item_ast(ebml_w: ebml::writer, item: @ast::item) {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(c::tag_tree as uint) {
|
2012-03-15 09:15:49 -05:00
|
|
|
ast::serialize_item(ebml_w, *item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
fn decode_item_ast(par_doc: ebml::doc) -> @ast::item {
|
2012-07-27 21:32:42 -05:00
|
|
|
let chi_doc = par_doc[c::tag_tree as uint];
|
2012-03-15 09:15:49 -05:00
|
|
|
let d = ebml::ebml_deserializer(chi_doc);
|
|
|
|
@ast::deserialize_item(d)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2012-07-31 12:27:51 -05:00
|
|
|
trait fake_ext_ctxt {
|
2012-03-22 20:53:30 -05:00
|
|
|
fn cfg() -> ast::crate_cfg;
|
2012-04-18 01:34:48 -05:00
|
|
|
fn parse_sess() -> parse::parse_sess;
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2012-03-22 20:53:30 -05:00
|
|
|
type fake_session = ();
|
2012-03-15 09:15:49 -05:00
|
|
|
|
|
|
|
#[cfg(test)]
|
2012-08-07 20:10:06 -05:00
|
|
|
impl fake_session: fake_ext_ctxt {
|
2012-06-29 18:26:56 -05:00
|
|
|
fn cfg() -> ast::crate_cfg { ~[] }
|
2012-06-06 11:50:08 -05:00
|
|
|
fn parse_sess() -> parse::parse_sess { parse::new_parse_sess(none) }
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
fn mk_ctxt() -> fake_ext_ctxt {
|
2012-03-22 20:53:30 -05:00
|
|
|
() as fake_ext_ctxt
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
fn roundtrip(in_item: @ast::item) {
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"in_item = %s", pprust::item_to_str(in_item)};
|
2012-03-15 09:15:49 -05:00
|
|
|
let mbuf = io::mem_buffer();
|
|
|
|
let ebml_w = ebml::writer(io::mem_buffer_writer(mbuf));
|
|
|
|
encode_item_ast(ebml_w, in_item);
|
|
|
|
let ebml_doc = ebml::doc(@io::mem_buffer_buf(mbuf));
|
|
|
|
let out_item = decode_item_ast(ebml_doc);
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"out_item = %s", pprust::item_to_str(out_item)};
|
2012-03-15 09:15:49 -05:00
|
|
|
|
|
|
|
let exp_str =
|
2012-06-30 18:19:07 -05:00
|
|
|
io::with_str_writer(|w| ast::serialize_item(w, *in_item) );
|
2012-03-15 09:15:49 -05:00
|
|
|
let out_str =
|
2012-06-30 18:19:07 -05:00
|
|
|
io::with_str_writer(|w| ast::serialize_item(w, *out_item) );
|
2012-03-15 09:15:49 -05:00
|
|
|
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"expected string: %s", exp_str};
|
|
|
|
debug!{"actual string : %s", out_str};
|
2012-03-15 09:15:49 -05:00
|
|
|
|
|
|
|
assert exp_str == out_str;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_basic() {
|
|
|
|
let ext_cx = mk_ctxt();
|
2012-07-30 18:01:07 -05:00
|
|
|
roundtrip(#ast[item]{
|
2012-03-15 09:15:49 -05:00
|
|
|
fn foo() {}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_smalltalk() {
|
|
|
|
let ext_cx = mk_ctxt();
|
2012-07-30 18:01:07 -05:00
|
|
|
roundtrip(#ast[item]{
|
2012-03-15 09:15:49 -05:00
|
|
|
fn foo() -> int { 3 + 4 } // first smalltalk program ever executed.
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_more() {
|
|
|
|
let ext_cx = mk_ctxt();
|
2012-07-30 18:01:07 -05:00
|
|
|
roundtrip(#ast[item]{
|
2012-03-15 09:15:49 -05:00
|
|
|
fn foo(x: uint, y: uint) -> uint {
|
|
|
|
let z = x + y;
|
2012-08-01 19:30:05 -05:00
|
|
|
return z;
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_simplification() {
|
|
|
|
let ext_cx = mk_ctxt();
|
2012-07-30 18:01:07 -05:00
|
|
|
let item_in = ast::ii_item(#ast[item] {
|
2012-03-15 09:15:49 -05:00
|
|
|
fn new_int_alist<B: copy>() -> alist<int, B> {
|
|
|
|
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
|
2012-08-01 19:30:05 -05:00
|
|
|
return {eq_fn: eq_int, mut data: ~[]};
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
let item_out = simplify_ast(item_in);
|
2012-07-30 18:01:07 -05:00
|
|
|
let item_exp = ast::ii_item(#ast[item] {
|
2012-03-15 09:15:49 -05:00
|
|
|
fn new_int_alist<B: copy>() -> alist<int, B> {
|
2012-08-01 19:30:05 -05:00
|
|
|
return {eq_fn: eq_int, mut data: ~[]};
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
|
|
|
});
|
2012-08-06 14:34:08 -05:00
|
|
|
match (item_out, item_exp) {
|
2012-08-03 21:59:04 -05:00
|
|
|
(ast::ii_item(item_out), ast::ii_item(item_exp)) => {
|
2012-03-15 09:15:49 -05:00
|
|
|
assert pprust::item_to_str(item_out) == pprust::item_to_str(item_exp);
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => fail
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
|
|
|
}
|