2013-06-22 20:58:41 -05:00
|
|
|
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
2012-12-03 18:48:01 -06:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-05-17 17:28:44 -05:00
|
|
|
|
2012-12-13 15:05:22 -06:00
|
|
|
use c = metadata::common;
|
|
|
|
use cstore = metadata::cstore;
|
|
|
|
use driver::session::Session;
|
|
|
|
use e = metadata::encoder;
|
|
|
|
use metadata::decoder;
|
|
|
|
use metadata::tydecode;
|
2013-01-17 08:13:26 -06:00
|
|
|
use metadata::tydecode::{DefIdSource, NominalType, TypeWithId, TypeParameter};
|
2012-12-13 15:05:22 -06:00
|
|
|
use metadata::tyencode;
|
|
|
|
use middle::freevars::freevar_entry;
|
2013-03-26 15:38:07 -05:00
|
|
|
use middle::typeck::{method_origin, method_map_entry};
|
2013-01-10 12:59:58 -06:00
|
|
|
use middle::{ty, typeck, moves};
|
2012-12-23 16:41:37 -06:00
|
|
|
use middle;
|
2012-09-04 13:54:36 -05:00
|
|
|
use util::ppaux::ty_to_str;
|
2012-04-10 12:52:06 -05:00
|
|
|
|
2013-06-28 17:32:26 -05:00
|
|
|
use std::at_vec;
|
2013-05-18 14:39:17 -05:00
|
|
|
use extra::ebml::reader;
|
|
|
|
use extra::ebml;
|
|
|
|
use extra::serialize;
|
|
|
|
use extra::serialize::{Encoder, Encodable, EncoderHelpers, DecoderHelpers};
|
|
|
|
use extra::serialize::{Decoder, Decodable};
|
2012-09-04 13:54:36 -05:00
|
|
|
use syntax::ast;
|
|
|
|
use syntax::ast_map;
|
2013-03-05 16:49:03 -06:00
|
|
|
use syntax::ast_util::inlined_item_utils;
|
2012-09-04 13:54:36 -05:00
|
|
|
use syntax::ast_util;
|
|
|
|
use syntax::codemap::span;
|
|
|
|
use syntax::codemap;
|
2012-12-13 15:05:22 -06:00
|
|
|
use syntax::fold::*;
|
|
|
|
use syntax::fold;
|
2013-05-14 19:27:27 -05:00
|
|
|
use syntax::parse::token;
|
2012-12-23 16:41:37 -06:00
|
|
|
use syntax;
|
2013-05-18 14:39:17 -05:00
|
|
|
use writer = extra::ebml::writer;
|
2012-02-14 17:21:53 -06:00
|
|
|
|
2013-06-28 17:32:26 -05:00
|
|
|
use std::cast;
|
2013-06-13 02:19:50 -05:00
|
|
|
|
2013-02-28 10:57:33 -06:00
|
|
|
#[cfg(test)] use syntax::parse;
|
|
|
|
#[cfg(test)] use syntax::print::pprust;
|
|
|
|
|
2012-05-14 19:46:45 -05:00
|
|
|
// Auxiliary maps of things to be encoded
|
2013-01-10 12:59:58 -06:00
|
|
|
pub struct Maps {
|
2012-05-14 22:32:29 -05:00
|
|
|
root_map: middle::borrowck::root_map,
|
2012-05-14 19:46:45 -05:00
|
|
|
method_map: middle::typeck::method_map,
|
|
|
|
vtable_map: middle::typeck::vtable_map,
|
2013-01-11 23:01:42 -06:00
|
|
|
write_guard_map: middle::borrowck::write_guard_map,
|
2013-01-10 12:59:58 -06:00
|
|
|
capture_map: middle::moves::CaptureMap,
|
|
|
|
}
|
2012-05-14 19:46:45 -05:00
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
struct DecodeContext {
|
|
|
|
cdata: @cstore::crate_metadata,
|
2012-02-14 17:21:53 -06:00
|
|
|
tcx: ty::ctxt,
|
2013-01-10 12:59:58 -06:00
|
|
|
maps: Maps
|
2013-02-19 01:40:42 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
struct ExtendedDecodeContext {
|
|
|
|
dcx: @DecodeContext,
|
2012-06-13 18:14:01 -05:00
|
|
|
from_id_range: ast_util::id_range,
|
|
|
|
to_id_range: ast_util::id_range
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
|
|
|
|
2012-07-31 12:27:51 -05:00
|
|
|
trait tr {
|
2013-02-22 00:41:37 -06:00
|
|
|
fn tr(&self, xcx: @ExtendedDecodeContext) -> Self;
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-11-29 20:37:33 -06:00
|
|
|
trait tr_intern {
|
2013-02-22 00:41:37 -06:00
|
|
|
fn tr_intern(&self, xcx: @ExtendedDecodeContext) -> ast::def_id;
|
2012-11-29 20:37:33 -06:00
|
|
|
}
|
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
// ______________________________________________________________________
|
2012-03-01 12:36:22 -06:00
|
|
|
// Top-level methods.
|
|
|
|
|
2013-06-13 02:19:50 -05:00
|
|
|
pub fn encode_inlined_item(ecx: &e::EncodeContext,
|
2013-05-01 19:54:54 -05:00
|
|
|
ebml_w: &mut writer::Encoder,
|
2013-01-30 15:44:24 -06:00
|
|
|
path: &[ast_map::path_elt],
|
|
|
|
ii: ast::inlined_item,
|
2013-01-10 12:59:58 -06:00
|
|
|
maps: Maps) {
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("> Encoding inlined item: %s::%s (%u)",
|
2013-05-14 19:27:27 -05:00
|
|
|
ast_map::path_to_str(path, token::get_ident_interner()),
|
2013-06-12 12:02:55 -05:00
|
|
|
ecx.tcx.sess.str_of(ii.ident()),
|
2012-08-22 19:24:52 -05:00
|
|
|
ebml_w.writer.tell());
|
2012-03-01 12:36:22 -06:00
|
|
|
|
2013-04-17 11:15:37 -05:00
|
|
|
let id_range = ast_util::compute_id_range_for_inlined_item(&ii);
|
2013-05-01 19:54:54 -05:00
|
|
|
|
|
|
|
ebml_w.start_tag(c::tag_ast as uint);
|
|
|
|
id_range.encode(ebml_w);
|
|
|
|
encode_ast(ebml_w, simplify_ast(&ii));
|
|
|
|
encode_side_tables_for_ii(ecx, maps, ebml_w, &ii);
|
|
|
|
ebml_w.end_tag();
|
2012-03-01 12:36:22 -06:00
|
|
|
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("< Encoded inlined fn: %s::%s (%u)",
|
2013-05-14 19:27:27 -05:00
|
|
|
ast_map::path_to_str(path, token::get_ident_interner()),
|
2013-06-12 12:02:55 -05:00
|
|
|
ecx.tcx.sess.str_of(ii.ident()),
|
2012-08-22 19:24:52 -05:00
|
|
|
ebml_w.writer.tell());
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
pub fn decode_inlined_item(cdata: @cstore::crate_metadata,
|
2013-01-30 15:44:24 -06:00
|
|
|
tcx: ty::ctxt,
|
2013-01-10 12:59:58 -06:00
|
|
|
maps: Maps,
|
2013-07-02 14:47:32 -05:00
|
|
|
path: &[ast_map::path_elt],
|
2013-01-30 15:44:24 -06:00
|
|
|
par_doc: ebml::Doc)
|
|
|
|
-> Option<ast::inlined_item> {
|
2013-02-19 01:40:42 -06:00
|
|
|
let dcx = @DecodeContext {
|
|
|
|
cdata: cdata,
|
|
|
|
tcx: tcx,
|
|
|
|
maps: maps
|
|
|
|
};
|
2012-08-06 14:34:08 -05:00
|
|
|
match par_doc.opt_child(c::tag_ast) {
|
2012-08-20 14:23:37 -05:00
|
|
|
None => None,
|
|
|
|
Some(ast_doc) => {
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("> Decoding inlined fn: %s::?",
|
2013-05-14 19:27:27 -05:00
|
|
|
ast_map::path_to_str(path, token::get_ident_interner()));
|
2013-05-01 19:54:54 -05:00
|
|
|
let mut ast_dsr = reader::Decoder(ast_doc);
|
|
|
|
let from_id_range = Decodable::decode(&mut ast_dsr);
|
2012-02-14 17:21:53 -06:00
|
|
|
let to_id_range = reserve_id_range(dcx.tcx.sess, from_id_range);
|
2013-02-19 01:40:42 -06:00
|
|
|
let xcx = @ExtendedDecodeContext {
|
|
|
|
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);
|
2013-06-12 12:02:55 -05:00
|
|
|
debug!("Fn named: %s", tcx.sess.str_of(ii.ident()));
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("< Decoded inlined fn: %s::%s",
|
2013-05-14 19:27:27 -05:00
|
|
|
ast_map::path_to_str(path, token::get_ident_interner()),
|
2013-06-12 12:02:55 -05:00
|
|
|
tcx.sess.str_of(ii.ident()));
|
2013-01-24 18:45:20 -06:00
|
|
|
ast_map::map_decoded_item(tcx.sess.diagnostic(),
|
2013-07-02 14:47:32 -05:00
|
|
|
dcx.tcx.items,
|
|
|
|
path.to_owned(),
|
|
|
|
&ii);
|
2013-01-24 18:45:20 -06:00
|
|
|
decode_side_tables(xcx, ast_doc);
|
2012-08-06 14:34:08 -05:00
|
|
|
match ii {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::ii_item(i) => {
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!(">>> DECODED ITEM >>>\n%s\n<<< DECODED ITEM <<<",
|
|
|
|
syntax::print::pprust::item_to_str(i, tcx.sess.intr()));
|
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-08-20 14:23:37 -05: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-10-15 16:56:42 -05: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:
|
2013-03-15 14:24:24 -05:00
|
|
|
if from_id_range.empty() { 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;
|
2013-01-17 10:55:28 -06:00
|
|
|
ast_util::id_range { min: to_id_min, max: to_id_min }
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-05-31 17:17:22 -05:00
|
|
|
impl ExtendedDecodeContext {
|
2013-07-27 03:25:59 -05:00
|
|
|
pub fn tr_id(&self, id: ast::NodeId) -> ast::NodeId {
|
2013-01-17 08:13:26 -06:00
|
|
|
/*!
|
|
|
|
* Translates an internal id, meaning a node id that is known
|
|
|
|
* to refer to some part of the item currently being inlined,
|
|
|
|
* such as a local variable or argument. All naked node-ids
|
|
|
|
* that appear in types have this property, since if something
|
|
|
|
* might refer to an external item we would use a def-id to
|
|
|
|
* allow for the possibility that the item resides in another
|
|
|
|
* crate.
|
|
|
|
*/
|
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
// from_id_range should be non-empty
|
2013-03-15 14:24:24 -05:00
|
|
|
assert!(!self.from_id_range.empty());
|
2012-02-14 17:21:53 -06:00
|
|
|
(id - self.from_id_range.min + self.to_id_range.min)
|
|
|
|
}
|
2013-05-31 17:17:22 -05:00
|
|
|
pub fn tr_def_id(&self, did: ast::def_id) -> ast::def_id {
|
2013-01-17 08:13:26 -06:00
|
|
|
/*!
|
|
|
|
* Translates an EXTERNAL def-id, converting the crate number
|
|
|
|
* from the one used in the encoded data to the current crate
|
|
|
|
* numbers.. By external, I mean that it be translated to a
|
|
|
|
* reference to the item in its original crate, as opposed to
|
|
|
|
* being translated to a reference to the inlined version of
|
|
|
|
* the item. This is typically, but not always, what you
|
|
|
|
* want, because most def-ids refer to external things like
|
|
|
|
* types or other fns that may or may not be inlined. Note
|
|
|
|
* that even when the inlined function is referencing itself
|
|
|
|
* recursively, we would want `tr_def_id` for that
|
|
|
|
* reference--- conceptually the function calls the original,
|
|
|
|
* non-inlined version, and trans deals with linking that
|
|
|
|
* recursive call to the inlined copy.
|
|
|
|
*
|
|
|
|
* However, there are a *few* cases where def-ids are used but
|
|
|
|
* we know that the thing being referenced is in fact *internal*
|
|
|
|
* to the item being inlined. In those cases, you should use
|
|
|
|
* `tr_intern_def_id()` below.
|
|
|
|
*/
|
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
decoder::translate_def_id(self.dcx.cdata, did)
|
|
|
|
}
|
2013-05-31 17:17:22 -05:00
|
|
|
pub fn tr_intern_def_id(&self, did: ast::def_id) -> ast::def_id {
|
2013-01-17 08:13:26 -06:00
|
|
|
/*!
|
|
|
|
* Translates an INTERNAL def-id, meaning a def-id that is
|
|
|
|
* known to refer to some part of the item currently being
|
|
|
|
* inlined. In that case, we want to convert the def-id to
|
|
|
|
* refer to the current crate and to the new, inlined node-id.
|
|
|
|
*/
|
|
|
|
|
2013-07-27 03:25:59 -05:00
|
|
|
assert_eq!(did.crate, ast::LOCAL_CRATE);
|
|
|
|
ast::def_id { crate: ast::LOCAL_CRATE, node: self.tr_id(did.node) }
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2013-05-31 17:17:22 -05:00
|
|
|
pub fn tr_span(&self, _span: span) -> span {
|
2013-01-30 11:56:33 -06:00
|
|
|
codemap::dummy_sp() // FIXME (#1972): handle span properly
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl tr_intern for ast::def_id {
|
2013-02-22 00:41:37 -06:00
|
|
|
fn tr_intern(&self, xcx: @ExtendedDecodeContext) -> ast::def_id {
|
|
|
|
xcx.tr_intern_def_id(*self)
|
2012-11-29 20:37:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl tr for ast::def_id {
|
2013-02-22 00:41:37 -06:00
|
|
|
fn tr(&self, xcx: @ExtendedDecodeContext) -> ast::def_id {
|
|
|
|
xcx.tr_def_id(*self)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl tr for span {
|
2013-02-22 00:41:37 -06:00
|
|
|
fn tr(&self, xcx: @ExtendedDecodeContext) -> span {
|
|
|
|
xcx.tr_span(*self)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-12-17 21:31:04 -06:00
|
|
|
trait def_id_encoder_helpers {
|
2013-05-01 19:54:54 -05:00
|
|
|
fn emit_def_id(&mut self, did: ast::def_id);
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
|
|
|
|
2013-02-20 19:07:17 -06:00
|
|
|
impl<S:serialize::Encoder> def_id_encoder_helpers for S {
|
2013-05-01 19:54:54 -05:00
|
|
|
fn emit_def_id(&mut self, did: ast::def_id) {
|
2013-02-22 00:41:37 -06:00
|
|
|
did.encode(self)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-12-17 21:31:04 -06:00
|
|
|
trait def_id_decoder_helpers {
|
2013-05-01 19:54:54 -05:00
|
|
|
fn read_def_id(&mut self, xcx: @ExtendedDecodeContext) -> ast::def_id;
|
2013-07-22 18:40:31 -05:00
|
|
|
fn read_def_id_noxcx(&mut self,
|
|
|
|
cdata: @cstore::crate_metadata) -> ast::def_id;
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
|
|
|
|
2013-02-20 19:07:17 -06:00
|
|
|
impl<D:serialize::Decoder> def_id_decoder_helpers for D {
|
2013-05-01 19:54:54 -05:00
|
|
|
fn read_def_id(&mut self, xcx: @ExtendedDecodeContext) -> ast::def_id {
|
2013-02-22 00:41:37 -06:00
|
|
|
let did: ast::def_id = Decodable::decode(self);
|
2012-02-14 17:21:53 -06:00
|
|
|
did.tr(xcx)
|
|
|
|
}
|
2013-07-22 18:40:31 -05:00
|
|
|
|
|
|
|
fn read_def_id_noxcx(&mut self,
|
|
|
|
cdata: @cstore::crate_metadata) -> ast::def_id {
|
|
|
|
let did: ast::def_id = Decodable::decode(self);
|
|
|
|
decoder::translate_def_id(cdata, did)
|
|
|
|
}
|
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 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.
|
|
|
|
|
2013-05-01 19:54:54 -05:00
|
|
|
fn encode_ast(ebml_w: &mut writer::Encoder, item: ast::inlined_item) {
|
|
|
|
ebml_w.start_tag(c::tag_tree as uint);
|
|
|
|
item.encode(ebml_w);
|
|
|
|
ebml_w.end_tag();
|
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.
|
2013-04-17 11:15:37 -05:00
|
|
|
fn simplify_ast(ii: &ast::inlined_item) -> ast::inlined_item {
|
2013-07-19 00:38:55 -05:00
|
|
|
fn drop_nested_items(blk: &ast::Block, fld: @fold::ast_fold) -> ast::Block {
|
2013-07-01 21:38:19 -05:00
|
|
|
let stmts_sans_items = do blk.stmts.iter().filter_map |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(_, _) |
|
2013-07-01 21:38:19 -05:00
|
|
|
ast::stmt_decl(@codemap::spanned { node: ast::decl_local(_), span: _}, _)
|
|
|
|
=> Some(*stmt),
|
|
|
|
ast::stmt_decl(@codemap::spanned { node: ast::decl_item(_), span: _}, _)
|
|
|
|
=> None,
|
2013-05-05 17:18:51 -05:00
|
|
|
ast::stmt_mac(*) => fail!("unexpanded macro in astencode")
|
2012-03-07 17:13:31 -06:00
|
|
|
}
|
2013-07-01 21:38:19 -05:00
|
|
|
}.collect();
|
2013-07-19 00:38:55 -05:00
|
|
|
let blk_sans_items = ast::Block {
|
2013-01-24 18:45:20 -06:00
|
|
|
view_items: ~[], // I don't know if we need the view_items here,
|
|
|
|
// but it doesn't break tests!
|
2013-01-14 22:52:28 -06:00
|
|
|
stmts: stmts_sans_items,
|
2013-01-24 18:45:20 -06:00
|
|
|
expr: blk.expr,
|
|
|
|
id: blk.id,
|
2013-07-16 13:08:35 -05:00
|
|
|
rules: blk.rules,
|
|
|
|
span: blk.span,
|
2013-01-14 22:52:28 -06:00
|
|
|
};
|
2013-02-18 00:20:36 -06:00
|
|
|
fold::noop_fold_block(&blk_sans_items, fld)
|
2012-03-07 17:13:31 -06:00
|
|
|
}
|
|
|
|
|
2013-01-08 16:00:45 -06:00
|
|
|
let fld = fold::make_fold(@fold::AstFoldFns {
|
2013-07-16 13:08:35 -05:00
|
|
|
fold_block: drop_nested_items,
|
2012-09-04 15:29:32 -05:00
|
|
|
.. *fold::default_ast_fold()
|
2012-03-07 17:13:31 -06:00
|
|
|
});
|
|
|
|
|
2013-04-17 11:15:37 -05:00
|
|
|
match *ii {
|
2013-06-22 20:58:41 -05:00
|
|
|
//hack: we're not dropping items
|
2013-08-03 18:59:24 -05:00
|
|
|
ast::ii_item(i) => ast::ii_item(fld.fold_item(i).unwrap()),
|
2013-07-11 17:08:43 -05:00
|
|
|
ast::ii_method(d, is_provided, m) =>
|
|
|
|
ast::ii_method(d, is_provided, fld.fold_method(m)),
|
2013-06-22 20:58:41 -05:00
|
|
|
ast::ii_foreign(i) => ast::ii_foreign(fld.fold_foreign_item(i))
|
2012-03-07 17:13:31 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-07 18:33:20 -05:00
|
|
|
fn decode_ast(par_doc: ebml::Doc) -> ast::inlined_item {
|
2013-03-26 14:04:30 -05:00
|
|
|
let chi_doc = par_doc.get(c::tag_tree as uint);
|
2013-05-01 19:54:54 -05:00
|
|
|
let mut d = reader::Decoder(chi_doc);
|
|
|
|
Decodable::decode(&mut d)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
fn renumber_ast(xcx: @ExtendedDecodeContext, ii: ast::inlined_item)
|
2012-03-01 21:37:52 -06:00
|
|
|
-> ast::inlined_item {
|
2013-01-08 16:00:45 -06:00
|
|
|
let fld = fold::make_fold(@fold::AstFoldFns{
|
2012-06-30 18:19:07 -05:00
|
|
|
new_id: |a| xcx.tr_id(a),
|
2012-09-04 15:29:32 -05:00
|
|
|
new_span: |a| xcx.tr_span(a),
|
|
|
|
.. *fold::default_ast_fold()
|
2012-02-14 17:21:53 -06:00
|
|
|
});
|
2012-03-01 21:37:52 -06:00
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match ii {
|
2013-08-03 18:59:24 -05:00
|
|
|
ast::ii_item(i) => ast::ii_item(fld.fold_item(i).unwrap()),
|
2013-07-11 17:08:43 -05:00
|
|
|
ast::ii_method(d, is_provided, m) =>
|
|
|
|
ast::ii_method(xcx.tr_def_id(d), is_provided, fld.fold_method(m)),
|
2013-06-22 20:58:41 -05:00
|
|
|
ast::ii_foreign(i) => ast::ii_foreign(fld.fold_foreign_item(i)),
|
|
|
|
}
|
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
|
|
|
|
2013-05-01 19:54:54 -05:00
|
|
|
fn encode_def(ebml_w: &mut writer::Encoder, def: ast::def) {
|
2013-04-17 11:15:37 -05:00
|
|
|
def.encode(ebml_w)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
fn decode_def(xcx: @ExtendedDecodeContext, doc: ebml::Doc) -> ast::def {
|
2013-05-01 19:54:54 -05:00
|
|
|
let mut dsr = reader::Decoder(doc);
|
|
|
|
let def: ast::def = Decodable::decode(&mut dsr);
|
2012-02-14 17:21:53 -06:00
|
|
|
def.tr(xcx)
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl tr for ast::def {
|
2013-02-22 00:41:37 -06:00
|
|
|
fn tr(&self, xcx: @ExtendedDecodeContext) -> ast::def {
|
|
|
|
match *self {
|
2013-06-22 20:58:41 -05:00
|
|
|
ast::def_fn(did, p) => ast::def_fn(did.tr(xcx), p),
|
2012-10-18 15:29:34 -05:00
|
|
|
ast::def_static_method(did, did2_opt, p) => {
|
|
|
|
ast::def_static_method(did.tr(xcx),
|
|
|
|
did2_opt.map(|did2| did2.tr(xcx)),
|
|
|
|
p)
|
2013-06-14 20:21:47 -05:00
|
|
|
}
|
|
|
|
ast::def_method(did0, did1) => {
|
|
|
|
ast::def_method(did0.tr(xcx), did1.map(|did1| did1.tr(xcx)))
|
|
|
|
}
|
|
|
|
ast::def_self_ty(nid) => { ast::def_self_ty(xcx.tr_id(nid)) }
|
2013-08-27 15:36:42 -05:00
|
|
|
ast::def_self(nid) => { ast::def_self(xcx.tr_id(nid)) }
|
2013-06-14 20:21:47 -05:00
|
|
|
ast::def_mod(did) => { ast::def_mod(did.tr(xcx)) }
|
|
|
|
ast::def_foreign_mod(did) => { ast::def_foreign_mod(did.tr(xcx)) }
|
|
|
|
ast::def_static(did, m) => { ast::def_static(did.tr(xcx), m) }
|
|
|
|
ast::def_arg(nid, b) => { ast::def_arg(xcx.tr_id(nid), b) }
|
|
|
|
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))
|
2013-06-22 20:58:41 -05:00
|
|
|
},
|
2013-03-27 09:26:57 -05:00
|
|
|
ast::def_trait(did) => ast::def_trait(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
|
|
|
}
|
2013-06-22 20:58:41 -05:00
|
|
|
ast::def_struct(did) => ast::def_struct(did.tr(xcx)),
|
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-09-11 23:25:01 -05:00
|
|
|
// ______________________________________________________________________
|
|
|
|
// Encoding and decoding of adjustment information
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl tr for ty::AutoAdjustment {
|
2013-02-22 00:41:37 -06:00
|
|
|
fn tr(&self, xcx: @ExtendedDecodeContext) -> ty::AutoAdjustment {
|
2013-06-22 20:58:41 -05:00
|
|
|
match *self {
|
|
|
|
ty::AutoAddEnv(r, s) => ty::AutoAddEnv(r.tr(xcx), s),
|
|
|
|
ty::AutoDerefRef(ref adr) => {
|
2013-02-27 18:28:37 -06:00
|
|
|
ty::AutoDerefRef(ty::AutoDerefRef {
|
|
|
|
autoderefs: adr.autoderefs,
|
|
|
|
autoref: adr.autoref.map(|ar| ar.tr(xcx)),
|
|
|
|
})
|
|
|
|
}
|
2013-01-16 21:24:10 -06:00
|
|
|
}
|
2012-09-11 23:25:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl tr for ty::AutoRef {
|
2013-02-22 00:41:37 -06:00
|
|
|
fn tr(&self, xcx: @ExtendedDecodeContext) -> ty::AutoRef {
|
2013-03-15 14:24:24 -05:00
|
|
|
self.map_region(|r| r.tr(xcx))
|
2012-09-11 23:25:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl tr for ty::Region {
|
2013-02-22 00:41:37 -06:00
|
|
|
fn tr(&self, xcx: @ExtendedDecodeContext) -> ty::Region {
|
|
|
|
match *self {
|
2012-09-11 23:25:01 -05:00
|
|
|
ty::re_bound(br) => ty::re_bound(br.tr(xcx)),
|
|
|
|
ty::re_scope(id) => ty::re_scope(xcx.tr_id(id)),
|
2013-03-15 14:24:24 -05:00
|
|
|
ty::re_empty | ty::re_static | ty::re_infer(*) => *self,
|
2013-04-02 00:32:37 -05:00
|
|
|
ty::re_free(ref fr) => {
|
|
|
|
ty::re_free(ty::FreeRegion {scope_id: xcx.tr_id(fr.scope_id),
|
|
|
|
bound_region: fr.bound_region.tr(xcx)})
|
|
|
|
}
|
2012-09-11 23:25:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl tr for ty::bound_region {
|
2013-02-22 00:41:37 -06:00
|
|
|
fn tr(&self, xcx: @ExtendedDecodeContext) -> ty::bound_region {
|
|
|
|
match *self {
|
2012-12-05 17:13:24 -06:00
|
|
|
ty::br_anon(_) | ty::br_named(_) | ty::br_self |
|
2013-02-22 00:41:37 -06:00
|
|
|
ty::br_fresh(_) => *self,
|
2012-09-11 23:25:01 -05:00
|
|
|
ty::br_cap_avoid(id, br) => ty::br_cap_avoid(xcx.tr_id(id),
|
|
|
|
@br.tr(xcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
// ______________________________________________________________________
|
|
|
|
// Encoding and decoding of freevar information
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-05-01 19:54:54 -05:00
|
|
|
fn encode_freevar_entry(ebml_w: &mut writer::Encoder, fv: @freevar_entry) {
|
2013-04-17 11:15:37 -05:00
|
|
|
(*fv).encode(ebml_w)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-12-17 21:31:04 -06:00
|
|
|
trait ebml_decoder_helper {
|
2013-05-01 19:54:54 -05:00
|
|
|
fn read_freevar_entry(&mut self, xcx: @ExtendedDecodeContext)
|
|
|
|
-> freevar_entry;
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl ebml_decoder_helper for reader::Decoder {
|
2013-05-01 19:54:54 -05:00
|
|
|
fn read_freevar_entry(&mut self, xcx: @ExtendedDecodeContext)
|
|
|
|
-> freevar_entry {
|
2013-02-22 00:41:37 -06:00
|
|
|
let fv: freevar_entry = Decodable::decode(self);
|
2012-02-14 17:21:53 -06:00
|
|
|
fv.tr(xcx)
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl tr for freevar_entry {
|
2013-02-22 00:41:37 -06:00
|
|
|
fn tr(&self, xcx: @ExtendedDecodeContext) -> freevar_entry {
|
2013-01-16 21:24:10 -06:00
|
|
|
freevar_entry {
|
|
|
|
def: self.def.tr(xcx),
|
|
|
|
span: self.span.tr(xcx),
|
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-01-10 12:59:58 -06:00
|
|
|
// ______________________________________________________________________
|
|
|
|
// Encoding and decoding of CaptureVar information
|
|
|
|
|
|
|
|
trait capture_var_helper {
|
2013-05-01 19:54:54 -05:00
|
|
|
fn read_capture_var(&mut self, xcx: @ExtendedDecodeContext)
|
|
|
|
-> moves::CaptureVar;
|
2013-01-10 12:59:58 -06:00
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl capture_var_helper for reader::Decoder {
|
2013-05-01 19:54:54 -05:00
|
|
|
fn read_capture_var(&mut self, xcx: @ExtendedDecodeContext)
|
|
|
|
-> moves::CaptureVar {
|
2013-02-22 00:41:37 -06:00
|
|
|
let cvar: moves::CaptureVar = Decodable::decode(self);
|
2013-01-10 12:59:58 -06:00
|
|
|
cvar.tr(xcx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl tr for moves::CaptureVar {
|
2013-02-22 00:41:37 -06:00
|
|
|
fn tr(&self, xcx: @ExtendedDecodeContext) -> moves::CaptureVar {
|
2013-01-10 12:59:58 -06:00
|
|
|
moves::CaptureVar {
|
|
|
|
def: self.def.tr(xcx),
|
|
|
|
span: self.span.tr(xcx),
|
|
|
|
mode: self.mode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
2013-05-01 19:54:54 -05:00
|
|
|
fn read_method_map_entry(&mut self, xcx: @ExtendedDecodeContext)
|
|
|
|
-> method_map_entry;
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:19:50 -05:00
|
|
|
fn encode_method_map_entry(ecx: &e::EncodeContext,
|
2013-05-01 19:54:54 -05:00
|
|
|
ebml_w: &mut writer::Encoder,
|
|
|
|
mme: method_map_entry) {
|
|
|
|
do ebml_w.emit_struct("method_map_entry", 3) |ebml_w| {
|
2013-04-26 21:13:38 -05:00
|
|
|
do ebml_w.emit_struct_field("self_ty", 0u) |ebml_w| {
|
|
|
|
ebml_w.emit_ty(ecx, mme.self_ty);
|
2013-04-09 21:41:20 -05:00
|
|
|
}
|
2013-05-01 19:54:54 -05:00
|
|
|
do ebml_w.emit_struct_field("explicit_self", 2u) |ebml_w| {
|
2013-04-17 11:15:37 -05:00
|
|
|
mme.explicit_self.encode(ebml_w);
|
2013-04-09 21:41:20 -05:00
|
|
|
}
|
2013-05-01 19:54:54 -05:00
|
|
|
do ebml_w.emit_struct_field("origin", 1u) |ebml_w| {
|
2013-04-17 11:15:37 -05:00
|
|
|
mme.origin.encode(ebml_w);
|
2013-04-09 21:41:20 -05:00
|
|
|
}
|
2013-05-01 19:54:54 -05:00
|
|
|
do ebml_w.emit_struct_field("self_mode", 3) |ebml_w| {
|
2013-04-24 03:29:46 -05:00
|
|
|
mme.self_mode.encode(ebml_w);
|
|
|
|
}
|
2013-04-09 21:41:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl read_method_map_entry_helper for reader::Decoder {
|
2013-05-01 19:54:54 -05:00
|
|
|
fn read_method_map_entry(&mut self, xcx: @ExtendedDecodeContext)
|
|
|
|
-> method_map_entry {
|
|
|
|
do self.read_struct("method_map_entry", 3) |this| {
|
2013-04-09 21:41:20 -05:00
|
|
|
method_map_entry {
|
2013-04-26 21:13:38 -05:00
|
|
|
self_ty: this.read_struct_field("self_ty", 0u, |this| {
|
|
|
|
this.read_ty(xcx)
|
2013-04-09 21:41:20 -05:00
|
|
|
}),
|
2013-05-01 19:54:54 -05:00
|
|
|
explicit_self: this.read_struct_field("explicit_self",
|
|
|
|
2,
|
|
|
|
|this| {
|
2013-04-30 10:49:48 -05:00
|
|
|
let explicit_self: ast::explicit_self_ = Decodable::decode(this);
|
|
|
|
explicit_self
|
2013-04-09 21:41:20 -05:00
|
|
|
}),
|
2013-05-01 19:54:54 -05:00
|
|
|
origin: this.read_struct_field("origin", 1, |this| {
|
2013-04-09 21:41:20 -05:00
|
|
|
let method_origin: method_origin =
|
2013-05-01 19:54:54 -05:00
|
|
|
Decodable::decode(this);
|
2013-04-09 21:41:20 -05:00
|
|
|
method_origin.tr(xcx)
|
|
|
|
}),
|
2013-05-01 19:54:54 -05:00
|
|
|
self_mode: this.read_struct_field("self_mode", 3, |this| {
|
|
|
|
let self_mode: ty::SelfMode = Decodable::decode(this);
|
2013-04-24 03:29:46 -05:00
|
|
|
self_mode
|
|
|
|
}),
|
2013-04-09 21:41:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl tr for method_origin {
|
2013-02-22 00:41:37 -06:00
|
|
|
fn tr(&self, xcx: @ExtendedDecodeContext) -> method_origin {
|
|
|
|
match *self {
|
2012-08-03 21:59:04 -05:00
|
|
|
typeck::method_static(did) => {
|
2013-01-16 20:45:05 -06:00
|
|
|
typeck::method_static(did.tr(xcx))
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
2012-12-04 12:50:00 -06:00
|
|
|
typeck::method_param(ref mp) => {
|
2013-01-16 21:24:10 -06:00
|
|
|
typeck::method_param(
|
|
|
|
typeck::method_param {
|
|
|
|
trait_id: mp.trait_id.tr(xcx),
|
|
|
|
.. *mp
|
|
|
|
}
|
|
|
|
)
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
2013-08-11 12:44:26 -05:00
|
|
|
typeck::method_trait(did, m) => {
|
|
|
|
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
|
|
|
|
2013-07-22 18:40:31 -05:00
|
|
|
pub fn encode_vtable_res(ecx: &e::EncodeContext,
|
2013-05-01 19:54:54 -05:00
|
|
|
ebml_w: &mut writer::Encoder,
|
2012-09-11 23:25:01 -05:00
|
|
|
dr: typeck::vtable_res) {
|
2012-12-17 21:31:04 -06:00
|
|
|
// can't autogenerate this code because automatic code of
|
2012-02-14 17:21:53 -06:00
|
|
|
// ty::t doesn't work, and there is no way (atm) to have
|
2012-12-17 21:31:04 -06:00
|
|
|
// hand-written encoding routines combine with auto-generated
|
2012-02-14 17:21:53 -06:00
|
|
|
// ones. perhaps we should fix this.
|
2013-06-26 19:20:53 -05:00
|
|
|
do ebml_w.emit_from_vec(*dr) |ebml_w, param_tables| {
|
2013-07-22 18:40:31 -05:00
|
|
|
encode_vtable_param_res(ecx, ebml_w, *param_tables);
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-07-22 18:40:31 -05:00
|
|
|
pub fn encode_vtable_param_res(ecx: &e::EncodeContext,
|
|
|
|
ebml_w: &mut writer::Encoder,
|
|
|
|
param_tables: typeck::vtable_param_res) {
|
|
|
|
do ebml_w.emit_from_vec(*param_tables) |ebml_w, vtable_origin| {
|
|
|
|
encode_vtable_origin(ecx, ebml_w, vtable_origin)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn encode_vtable_origin(ecx: &e::EncodeContext,
|
2013-05-01 19:54:54 -05:00
|
|
|
ebml_w: &mut writer::Encoder,
|
2013-04-17 11:15:37 -05:00
|
|
|
vtable_origin: &typeck::vtable_origin) {
|
2013-05-19 00:07:44 -05:00
|
|
|
do ebml_w.emit_enum("vtable_origin") |ebml_w| {
|
2013-04-17 11:15:37 -05:00
|
|
|
match *vtable_origin {
|
2013-03-20 00:17:42 -05:00
|
|
|
typeck::vtable_static(def_id, ref tys, vtable_res) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
do ebml_w.emit_enum_variant("vtable_static", 0u, 3u) |ebml_w| {
|
2013-05-01 19:54:54 -05:00
|
|
|
do ebml_w.emit_enum_variant_arg(0u) |ebml_w| {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.emit_def_id(def_id)
|
|
|
|
}
|
2013-05-01 19:54:54 -05:00
|
|
|
do ebml_w.emit_enum_variant_arg(1u) |ebml_w| {
|
2013-07-02 14:47:32 -05:00
|
|
|
ebml_w.emit_tys(ecx, *tys);
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2013-05-01 19:54:54 -05:00
|
|
|
do ebml_w.emit_enum_variant_arg(2u) |ebml_w| {
|
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) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
do ebml_w.emit_enum_variant("vtable_param", 1u, 2u) |ebml_w| {
|
2013-05-01 19:54:54 -05:00
|
|
|
do ebml_w.emit_enum_variant_arg(0u) |ebml_w| {
|
2013-07-22 19:42:45 -05:00
|
|
|
pn.encode(ebml_w);
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2013-05-01 19:54:54 -05:00
|
|
|
do ebml_w.emit_enum_variant_arg(1u) |ebml_w| {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.emit_uint(bn);
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-07-22 18:40:31 -05:00
|
|
|
pub trait vtable_decoder_helpers {
|
|
|
|
fn read_vtable_res(&mut self,
|
|
|
|
tcx: ty::ctxt, cdata: @cstore::crate_metadata)
|
2013-02-22 00:41:37 -06:00
|
|
|
-> typeck::vtable_res;
|
2013-07-22 18:40:31 -05:00
|
|
|
fn read_vtable_param_res(&mut self,
|
|
|
|
tcx: ty::ctxt, cdata: @cstore::crate_metadata)
|
|
|
|
-> typeck::vtable_param_res;
|
|
|
|
fn read_vtable_origin(&mut self,
|
|
|
|
tcx: ty::ctxt, cdata: @cstore::crate_metadata)
|
2013-05-01 19:54:54 -05:00
|
|
|
-> typeck::vtable_origin;
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl vtable_decoder_helpers for reader::Decoder {
|
2013-07-22 18:40:31 -05:00
|
|
|
fn read_vtable_res(&mut self,
|
|
|
|
tcx: ty::ctxt, cdata: @cstore::crate_metadata)
|
2013-02-22 00:41:37 -06:00
|
|
|
-> typeck::vtable_res {
|
2013-06-26 19:20:53 -05:00
|
|
|
@self.read_to_vec(|this|
|
2013-07-22 18:40:31 -05:00
|
|
|
this.read_vtable_param_res(tcx, cdata))
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-07-22 18:40:31 -05:00
|
|
|
fn read_vtable_param_res(&mut self,
|
|
|
|
tcx: ty::ctxt, cdata: @cstore::crate_metadata)
|
|
|
|
-> typeck::vtable_param_res {
|
|
|
|
@self.read_to_vec(|this|
|
|
|
|
this.read_vtable_origin(tcx, cdata))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn read_vtable_origin(&mut self,
|
|
|
|
tcx: ty::ctxt, cdata: @cstore::crate_metadata)
|
2013-03-26 20:46:48 -05:00
|
|
|
-> typeck::vtable_origin {
|
2013-05-01 19:54:54 -05:00
|
|
|
do self.read_enum("vtable_origin") |this| {
|
2013-06-20 11:29:24 -05:00
|
|
|
do this.read_enum_variant(["vtable_static",
|
|
|
|
"vtable_param",
|
|
|
|
"vtable_self"])
|
2013-05-01 19:54:54 -05:00
|
|
|
|this, i| {
|
2013-03-26 20:46:48 -05:00
|
|
|
match i {
|
|
|
|
0 => {
|
|
|
|
typeck::vtable_static(
|
2013-05-01 19:54:54 -05:00
|
|
|
do this.read_enum_variant_arg(0u) |this| {
|
2013-07-22 18:40:31 -05:00
|
|
|
this.read_def_id_noxcx(cdata)
|
2013-03-26 20:46:48 -05:00
|
|
|
},
|
2013-05-01 19:54:54 -05:00
|
|
|
do this.read_enum_variant_arg(1u) |this| {
|
2013-07-22 18:40:31 -05:00
|
|
|
this.read_tys_noxcx(tcx, cdata)
|
2013-03-26 20:46:48 -05:00
|
|
|
},
|
2013-05-01 19:54:54 -05:00
|
|
|
do this.read_enum_variant_arg(2u) |this| {
|
2013-07-22 18:40:31 -05:00
|
|
|
this.read_vtable_res(tcx, cdata)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2012-08-21 19:22:45 -05:00
|
|
|
1 => {
|
2012-03-08 09:17:59 -06:00
|
|
|
typeck::vtable_param(
|
2013-05-01 19:54:54 -05:00
|
|
|
do this.read_enum_variant_arg(0u) |this| {
|
2013-07-22 19:42:45 -05:00
|
|
|
Decodable::decode(this)
|
2012-02-14 17:21:53 -06:00
|
|
|
},
|
2013-05-01 19:54:54 -05:00
|
|
|
do this.read_enum_variant_arg(1u) |this| {
|
|
|
|
this.read_uint()
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2012-08-21 19:22:45 -05:00
|
|
|
// hard to avoid - user input
|
2013-05-05 17:18:51 -05:00
|
|
|
_ => fail!("bad enum variant")
|
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 {
|
2013-06-13 02:19:50 -05:00
|
|
|
fn ty_str_ctxt(&self) -> @tyencode::ctxt;
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:19:50 -05:00
|
|
|
impl<'self> get_ty_str_ctxt for e::EncodeContext<'self> {
|
|
|
|
fn ty_str_ctxt(&self) -> @tyencode::ctxt {
|
2013-06-14 20:21:47 -05:00
|
|
|
@tyencode::ctxt {
|
|
|
|
diag: self.tcx.sess.diagnostic(),
|
|
|
|
ds: e::def_to_str,
|
|
|
|
tcx: self.tcx,
|
|
|
|
abbrevs: tyencode::ac_use_abbrevs(self.type_abbrevs)
|
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-11 17:00:40 -05:00
|
|
|
trait ebml_writer_helpers {
|
2013-06-13 02:19:50 -05:00
|
|
|
fn emit_ty(&mut self, ecx: &e::EncodeContext, ty: ty::t);
|
|
|
|
fn emit_vstore(&mut self, ecx: &e::EncodeContext, vstore: ty::vstore);
|
|
|
|
fn emit_tys(&mut self, ecx: &e::EncodeContext, tys: &[ty::t]);
|
2013-05-01 19:54:54 -05:00
|
|
|
fn emit_type_param_def(&mut self,
|
2013-06-13 02:19:50 -05:00
|
|
|
ecx: &e::EncodeContext,
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
type_param_def: &ty::TypeParameterDef);
|
2013-05-01 19:54:54 -05:00
|
|
|
fn emit_tpbt(&mut self,
|
2013-06-13 02:19:50 -05:00
|
|
|
ecx: &e::EncodeContext,
|
2013-02-22 00:41:37 -06:00
|
|
|
tpbt: ty::ty_param_bounds_and_ty);
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl ebml_writer_helpers for writer::Encoder {
|
2013-06-13 02:19:50 -05:00
|
|
|
fn emit_ty(&mut self, ecx: &e::EncodeContext, ty: ty::t) {
|
2013-05-01 19:54:54 -05:00
|
|
|
do self.emit_opaque |this| {
|
|
|
|
e::write_type(ecx, this, ty)
|
2012-09-11 23:25:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:19:50 -05:00
|
|
|
fn emit_vstore(&mut self, ecx: &e::EncodeContext, vstore: ty::vstore) {
|
2013-05-01 19:54:54 -05:00
|
|
|
do self.emit_opaque |this| {
|
|
|
|
e::write_vstore(ecx, this, vstore)
|
2012-10-05 18:55:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:19:50 -05:00
|
|
|
fn emit_tys(&mut self, ecx: &e::EncodeContext, tys: &[ty::t]) {
|
2013-05-01 19:54:54 -05:00
|
|
|
do self.emit_from_vec(tys) |this, ty| {
|
|
|
|
this.emit_ty(ecx, *ty)
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-01 19:54:54 -05:00
|
|
|
fn emit_type_param_def(&mut self,
|
2013-06-13 02:19:50 -05:00
|
|
|
ecx: &e::EncodeContext,
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
type_param_def: &ty::TypeParameterDef) {
|
2013-05-01 19:54:54 -05:00
|
|
|
do self.emit_opaque |this| {
|
|
|
|
tyencode::enc_type_param_def(this.writer,
|
|
|
|
ecx.ty_str_ctxt(),
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
type_param_def)
|
2012-09-11 23:25:01 -05:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
|
2013-05-01 19:54:54 -05:00
|
|
|
fn emit_tpbt(&mut self,
|
2013-06-13 02:19:50 -05:00
|
|
|
ecx: &e::EncodeContext,
|
2013-04-09 21:41:20 -05:00
|
|
|
tpbt: ty::ty_param_bounds_and_ty) {
|
2013-05-01 19:54:54 -05:00
|
|
|
do self.emit_struct("ty_param_bounds_and_ty", 2) |this| {
|
2013-05-19 00:07:44 -05:00
|
|
|
do this.emit_struct_field("generics", 0) |this| {
|
2013-05-01 19:54:54 -05:00
|
|
|
do this.emit_struct("Generics", 2) |this| {
|
2013-05-19 00:07:44 -05:00
|
|
|
do this.emit_struct_field("type_param_defs", 0) |this| {
|
2013-05-01 19:54:54 -05:00
|
|
|
do this.emit_from_vec(*tpbt.generics.type_param_defs)
|
|
|
|
|this, type_param_def| {
|
|
|
|
this.emit_type_param_def(ecx, type_param_def);
|
2013-04-09 21:41:20 -05:00
|
|
|
}
|
|
|
|
}
|
2013-05-19 00:07:44 -05:00
|
|
|
do this.emit_struct_field("region_param", 1) |this| {
|
2013-05-01 19:54:54 -05:00
|
|
|
tpbt.generics.region_param.encode(this);
|
2013-04-09 21:41:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-19 00:07:44 -05:00
|
|
|
do this.emit_struct_field("ty", 1) |this| {
|
2013-05-01 19:54:54 -05:00
|
|
|
this.emit_ty(ecx, tpbt.ty);
|
2013-04-09 21:41: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 write_tag_and_id {
|
2013-05-01 19:54:54 -05:00
|
|
|
fn tag(&mut self, tag_id: c::astencode_tag, f: &fn(&mut Self));
|
2013-07-27 03:25:59 -05:00
|
|
|
fn id(&mut self, id: ast::NodeId);
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl write_tag_and_id for writer::Encoder {
|
2013-05-01 19:54:54 -05:00
|
|
|
fn tag(&mut self,
|
|
|
|
tag_id: c::astencode_tag,
|
|
|
|
f: &fn(&mut writer::Encoder)) {
|
|
|
|
self.start_tag(tag_id as uint);
|
|
|
|
f(self);
|
|
|
|
self.end_tag();
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
|
2013-07-27 03:25:59 -05:00
|
|
|
fn id(&mut self, id: ast::NodeId) {
|
2012-02-14 17:21:53 -06:00
|
|
|
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
|
|
|
|
2013-06-13 02:19:50 -05:00
|
|
|
fn encode_side_tables_for_ii(ecx: &e::EncodeContext,
|
2013-01-10 12:59:58 -06:00
|
|
|
maps: Maps,
|
2013-05-01 19:54:54 -05:00
|
|
|
ebml_w: &mut writer::Encoder,
|
2013-04-17 11:15:37 -05:00
|
|
|
ii: &ast::inlined_item) {
|
2013-05-01 19:54:54 -05:00
|
|
|
ebml_w.start_tag(c::tag_table as uint);
|
2013-07-02 14:47:32 -05:00
|
|
|
let new_ebml_w = (*ebml_w).clone();
|
2013-06-13 02:19:50 -05:00
|
|
|
|
|
|
|
// Because the ast visitor uses @fn, I can't pass in
|
|
|
|
// ecx directly, but /I/ know that it'll be fine since
|
|
|
|
// the lifetime is tied to the CrateContext that
|
|
|
|
// lives this entire section.
|
|
|
|
let ecx_ptr : *() = unsafe { cast::transmute(ecx) };
|
2013-05-01 19:54:54 -05:00
|
|
|
ast_util::visit_ids_for_inlined_item(
|
|
|
|
ii,
|
2013-07-27 03:25:59 -05:00
|
|
|
|id: ast::NodeId| {
|
2013-05-01 19:54:54 -05:00
|
|
|
// Note: this will cause a copy of ebml_w, which is bad as
|
|
|
|
// it is mutable. But I believe it's harmless since we generate
|
|
|
|
// balanced EBML.
|
2013-07-02 14:47:32 -05:00
|
|
|
let mut new_ebml_w = new_ebml_w.clone();
|
2013-06-13 02:19:50 -05:00
|
|
|
// See above
|
|
|
|
let ecx : &e::EncodeContext = unsafe { cast::transmute(ecx_ptr) };
|
2013-05-01 19:54:54 -05:00
|
|
|
encode_side_tables_for_id(ecx, maps, &mut new_ebml_w, id)
|
|
|
|
});
|
|
|
|
ebml_w.end_tag();
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-06-13 02:19:50 -05:00
|
|
|
fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
2013-01-10 12:59:58 -06:00
|
|
|
maps: Maps,
|
2013-05-01 19:54:54 -05:00
|
|
|
ebml_w: &mut writer::Encoder,
|
2013-07-27 03:25:59 -05:00
|
|
|
id: ast::NodeId) {
|
2012-05-13 19:01:52 -05:00
|
|
|
let tcx = ecx.tcx;
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("Encoding side tables for id %d", id);
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-06-10 16:50:12 -05:00
|
|
|
{
|
|
|
|
let r = tcx.def_map.find(&id);
|
2013-08-03 11:45:23 -05:00
|
|
|
for def in r.iter() {
|
2013-06-10 16:50:12 -05:00
|
|
|
do ebml_w.tag(c::tag_table_def) |ebml_w| {
|
|
|
|
ebml_w.id(id);
|
|
|
|
do ebml_w.tag(c::tag_table_val) |ebml_w| {
|
|
|
|
(*def).encode(ebml_w)
|
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-03 06:33:39 -06:00
|
|
|
|
2013-06-10 16:50:12 -05:00
|
|
|
{
|
|
|
|
let r = tcx.node_types.find(&(id as uint));
|
2013-08-03 11:45:23 -05:00
|
|
|
for &ty in r.iter() {
|
2013-06-10 16:50:12 -05:00
|
|
|
do ebml_w.tag(c::tag_table_node_type) |ebml_w| {
|
|
|
|
ebml_w.id(id);
|
|
|
|
do ebml_w.tag(c::tag_table_val) |ebml_w| {
|
|
|
|
ebml_w.emit_ty(ecx, *ty);
|
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-06-10 16:50:12 -05:00
|
|
|
{
|
|
|
|
let r = tcx.node_type_substs.find(&id);
|
2013-08-03 11:45:23 -05:00
|
|
|
for tys in r.iter() {
|
2013-06-10 16:50:12 -05:00
|
|
|
do ebml_w.tag(c::tag_table_node_type_subst) |ebml_w| {
|
|
|
|
ebml_w.id(id);
|
|
|
|
do ebml_w.tag(c::tag_table_val) |ebml_w| {
|
|
|
|
ebml_w.emit_tys(ecx, **tys)
|
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-06-10 16:50:12 -05:00
|
|
|
{
|
|
|
|
let r = tcx.freevars.find(&id);
|
2013-08-03 11:45:23 -05:00
|
|
|
for &fv in r.iter() {
|
2013-06-10 16:50:12 -05:00
|
|
|
do ebml_w.tag(c::tag_table_freevars) |ebml_w| {
|
|
|
|
ebml_w.id(id);
|
|
|
|
do ebml_w.tag(c::tag_table_val) |ebml_w| {
|
|
|
|
do ebml_w.emit_from_vec(**fv) |ebml_w, fv_entry| {
|
|
|
|
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
|
|
|
|
2013-07-27 03:25:59 -05:00
|
|
|
let lid = ast::def_id { crate: ast::LOCAL_CRATE, node: id };
|
2013-06-10 16:50:12 -05:00
|
|
|
{
|
|
|
|
let r = tcx.tcache.find(&lid);
|
2013-08-03 11:45:23 -05:00
|
|
|
for &tpbt in r.iter() {
|
2013-06-10 16:50:12 -05:00
|
|
|
do ebml_w.tag(c::tag_table_tcache) |ebml_w| {
|
|
|
|
ebml_w.id(id);
|
|
|
|
do ebml_w.tag(c::tag_table_val) |ebml_w| {
|
|
|
|
ebml_w.emit_tpbt(ecx, *tpbt);
|
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-06-10 16:50:12 -05:00
|
|
|
{
|
|
|
|
let r = tcx.ty_param_defs.find(&id);
|
2013-08-03 11:45:23 -05:00
|
|
|
for &type_param_def in r.iter() {
|
2013-06-10 16:50:12 -05:00
|
|
|
do ebml_w.tag(c::tag_table_param_defs) |ebml_w| {
|
|
|
|
ebml_w.id(id);
|
|
|
|
do ebml_w.tag(c::tag_table_val) |ebml_w| {
|
|
|
|
ebml_w.emit_type_param_def(ecx, type_param_def)
|
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-06-10 16:50:12 -05:00
|
|
|
{
|
|
|
|
let r = maps.method_map.find(&id);
|
2013-08-03 11:45:23 -05:00
|
|
|
for &mme in r.iter() {
|
2013-06-10 16:50:12 -05:00
|
|
|
do ebml_w.tag(c::tag_table_method_map) |ebml_w| {
|
|
|
|
ebml_w.id(id);
|
|
|
|
do ebml_w.tag(c::tag_table_val) |ebml_w| {
|
|
|
|
encode_method_map_entry(ecx, ebml_w, *mme)
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-10 16:50:12 -05:00
|
|
|
{
|
|
|
|
let r = maps.vtable_map.find(&id);
|
2013-08-03 11:45:23 -05:00
|
|
|
for &dr in r.iter() {
|
2013-06-10 16:50:12 -05:00
|
|
|
do ebml_w.tag(c::tag_table_vtable_map) |ebml_w| {
|
|
|
|
ebml_w.id(id);
|
|
|
|
do ebml_w.tag(c::tag_table_val) |ebml_w| {
|
|
|
|
encode_vtable_res(ecx, ebml_w, *dr);
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-23 17:23:20 -05:00
|
|
|
|
2013-06-10 16:50:12 -05:00
|
|
|
{
|
|
|
|
let r = tcx.adjustments.find(&id);
|
2013-08-03 11:45:23 -05:00
|
|
|
for adj in r.iter() {
|
2013-06-10 16:50:12 -05:00
|
|
|
do ebml_w.tag(c::tag_table_adjustments) |ebml_w| {
|
|
|
|
ebml_w.id(id);
|
|
|
|
do ebml_w.tag(c::tag_table_val) |ebml_w| {
|
|
|
|
(**adj).encode(ebml_w)
|
|
|
|
}
|
2012-05-31 16:02:39 -05:00
|
|
|
}
|
2012-04-23 17:23:20 -05:00
|
|
|
}
|
|
|
|
}
|
2012-10-02 18:19:03 -05:00
|
|
|
|
2013-06-10 16:50:12 -05:00
|
|
|
{
|
|
|
|
let r = maps.capture_map.find(&id);
|
2013-08-03 11:45:23 -05:00
|
|
|
for &cap_vars in r.iter() {
|
2013-06-10 16:50:12 -05:00
|
|
|
do ebml_w.tag(c::tag_table_capture_map) |ebml_w| {
|
|
|
|
ebml_w.id(id);
|
|
|
|
do ebml_w.tag(c::tag_table_val) |ebml_w| {
|
|
|
|
do ebml_w.emit_from_vec(*cap_vars) |ebml_w, cap_var| {
|
|
|
|
cap_var.encode(ebml_w);
|
|
|
|
}
|
2013-01-10 12:59:58 -06:00
|
|
|
}
|
2012-12-04 17:38:04 -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 doc_decoder_helpers {
|
2013-02-22 00:41:37 -06:00
|
|
|
fn as_int(&self) -> int;
|
|
|
|
fn opt_child(&self, tag: c::astencode_tag) -> Option<ebml::Doc>;
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl doc_decoder_helpers for ebml::Doc {
|
2013-02-22 00:41:37 -06:00
|
|
|
fn as_int(&self) -> int { reader::doc_as_u64(*self) as int }
|
|
|
|
fn opt_child(&self, tag: c::astencode_tag) -> Option<ebml::Doc> {
|
|
|
|
reader::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-12-17 21:31:04 -06:00
|
|
|
trait ebml_decoder_decoder_helpers {
|
2013-05-01 19:54:54 -05:00
|
|
|
fn read_ty(&mut self, xcx: @ExtendedDecodeContext) -> ty::t;
|
|
|
|
fn read_tys(&mut self, xcx: @ExtendedDecodeContext) -> ~[ty::t];
|
|
|
|
fn read_type_param_def(&mut self, xcx: @ExtendedDecodeContext)
|
|
|
|
-> ty::TypeParameterDef;
|
|
|
|
fn read_ty_param_bounds_and_ty(&mut self, xcx: @ExtendedDecodeContext)
|
2012-07-11 17:00:40 -05:00
|
|
|
-> ty::ty_param_bounds_and_ty;
|
2013-05-01 19:54:54 -05:00
|
|
|
fn convert_def_id(&mut self,
|
|
|
|
xcx: @ExtendedDecodeContext,
|
2013-01-17 08:13:26 -06:00
|
|
|
source: DefIdSource,
|
2013-05-01 19:54:54 -05:00
|
|
|
did: ast::def_id)
|
|
|
|
-> ast::def_id;
|
2013-07-22 18:40:31 -05:00
|
|
|
|
|
|
|
// Versions of the type reading functions that don't need the full
|
|
|
|
// ExtendedDecodeContext.
|
|
|
|
fn read_ty_noxcx(&mut self,
|
|
|
|
tcx: ty::ctxt, cdata: @cstore::crate_metadata) -> ty::t;
|
|
|
|
fn read_tys_noxcx(&mut self,
|
|
|
|
tcx: ty::ctxt,
|
|
|
|
cdata: @cstore::crate_metadata) -> ~[ty::t];
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl ebml_decoder_decoder_helpers for reader::Decoder {
|
2013-07-22 18:40:31 -05:00
|
|
|
fn read_ty_noxcx(&mut self,
|
|
|
|
tcx: ty::ctxt, cdata: @cstore::crate_metadata) -> ty::t {
|
|
|
|
do self.read_opaque |_, doc| {
|
|
|
|
tydecode::parse_ty_data(
|
|
|
|
*doc.data,
|
|
|
|
cdata.cnum,
|
|
|
|
doc.start,
|
|
|
|
tcx,
|
|
|
|
|_, id| decoder::translate_def_id(cdata, id))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn read_tys_noxcx(&mut self,
|
|
|
|
tcx: ty::ctxt,
|
|
|
|
cdata: @cstore::crate_metadata) -> ~[ty::t] {
|
|
|
|
self.read_to_vec(|this| this.read_ty_noxcx(tcx, cdata) )
|
|
|
|
}
|
|
|
|
|
2013-05-01 19:54:54 -05:00
|
|
|
fn read_ty(&mut self, xcx: @ExtendedDecodeContext) -> 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.
|
|
|
|
|
2013-05-01 19:54:54 -05:00
|
|
|
return do self.read_opaque |this, doc| {
|
2013-01-10 12:59:58 -06:00
|
|
|
let ty = tydecode::parse_ty_data(
|
2013-06-07 19:24:11 -05:00
|
|
|
*doc.data,
|
2013-05-01 19:54:54 -05:00
|
|
|
xcx.dcx.cdata.cnum,
|
|
|
|
doc.start,
|
|
|
|
xcx.dcx.tcx,
|
|
|
|
|s, a| this.convert_def_id(xcx, s, a));
|
2013-01-10 12:59:58 -06:00
|
|
|
|
|
|
|
debug!("read_ty(%s) = %s",
|
2013-05-01 19:54:54 -05:00
|
|
|
type_string(doc),
|
|
|
|
ty_to_str(xcx.dcx.tcx, ty));
|
2013-01-10 12:59:58 -06:00
|
|
|
|
|
|
|
ty
|
|
|
|
};
|
|
|
|
|
|
|
|
fn type_string(doc: ebml::Doc) -> ~str {
|
|
|
|
let mut str = ~"";
|
2013-08-03 11:45:23 -05:00
|
|
|
for i in range(doc.start, doc.end) {
|
2013-06-10 02:42:24 -05:00
|
|
|
str.push_char(doc.data[i] as char);
|
2013-01-10 12:59:58 -06:00
|
|
|
}
|
|
|
|
str
|
2012-09-11 23:25:01 -05:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
|
2013-05-01 19:54:54 -05:00
|
|
|
fn read_tys(&mut self, xcx: @ExtendedDecodeContext) -> ~[ty::t] {
|
|
|
|
self.read_to_vec(|this| this.read_ty(xcx) )
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
|
2013-05-01 19:54:54 -05:00
|
|
|
fn read_type_param_def(&mut self, xcx: @ExtendedDecodeContext)
|
|
|
|
-> ty::TypeParameterDef {
|
|
|
|
do self.read_opaque |this, doc| {
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
tydecode::parse_type_param_def_data(
|
2013-06-07 19:24:11 -05:00
|
|
|
*doc.data,
|
2013-05-01 19:54:54 -05:00
|
|
|
doc.start,
|
|
|
|
xcx.dcx.cdata.cnum,
|
|
|
|
xcx.dcx.tcx,
|
|
|
|
|s, a| this.convert_def_id(xcx, s, a))
|
2012-09-11 23:25:01 -05:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
|
2013-05-01 19:54:54 -05:00
|
|
|
fn read_ty_param_bounds_and_ty(&mut self, xcx: @ExtendedDecodeContext)
|
|
|
|
-> ty::ty_param_bounds_and_ty {
|
|
|
|
do self.read_struct("ty_param_bounds_and_ty", 2) |this| {
|
2013-04-09 21:41:20 -05:00
|
|
|
ty::ty_param_bounds_and_ty {
|
2013-05-01 19:54:54 -05:00
|
|
|
generics: do this.read_struct_field("generics", 0) |this| {
|
|
|
|
do this.read_struct("Generics", 2) |this| {
|
|
|
|
ty::Generics {
|
|
|
|
type_param_defs:
|
|
|
|
this.read_struct_field("type_param_defs",
|
|
|
|
0,
|
|
|
|
|this| {
|
|
|
|
@this.read_to_vec(|this|
|
|
|
|
this.read_type_param_def(xcx))
|
|
|
|
}),
|
|
|
|
region_param:
|
|
|
|
this.read_struct_field("region_param",
|
|
|
|
1,
|
|
|
|
|this| {
|
|
|
|
Decodable::decode(this)
|
|
|
|
})
|
|
|
|
}
|
2013-04-09 21:41:20 -05:00
|
|
|
}
|
|
|
|
},
|
2013-05-01 19:54:54 -05:00
|
|
|
ty: this.read_struct_field("ty", 1, |this| {
|
|
|
|
this.read_ty(xcx)
|
2013-04-09 21:41:20 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-01 19:54:54 -05:00
|
|
|
fn convert_def_id(&mut self,
|
|
|
|
xcx: @ExtendedDecodeContext,
|
2013-01-17 08:13:26 -06:00
|
|
|
source: tydecode::DefIdSource,
|
2013-05-01 19:54:54 -05:00
|
|
|
did: ast::def_id)
|
|
|
|
-> ast::def_id {
|
2013-01-17 08:13:26 -06:00
|
|
|
/*!
|
|
|
|
*
|
|
|
|
* Converts a def-id that appears in a type. The correct
|
|
|
|
* translation will depend on what kind of def-id this is.
|
|
|
|
* This is a subtle point: type definitions are not
|
|
|
|
* inlined into the current crate, so if the def-id names
|
|
|
|
* a nominal type or type alias, then it should be
|
|
|
|
* translated to refer to the source crate.
|
|
|
|
*
|
|
|
|
* However, *type parameters* are cloned along with the function
|
|
|
|
* they are attached to. So we should translate those def-ids
|
|
|
|
* to refer to the new, cloned copy of the type parameter.
|
|
|
|
*/
|
|
|
|
|
2013-01-10 12:59:58 -06:00
|
|
|
let r = match source {
|
2013-01-17 08:13:26 -06:00
|
|
|
NominalType | TypeWithId => xcx.tr_def_id(did),
|
|
|
|
TypeParameter => xcx.tr_intern_def_id(did)
|
2013-01-10 12:59:58 -06:00
|
|
|
};
|
|
|
|
debug!("convert_def_id(source=%?, did=%?)=%?", source, did, r);
|
|
|
|
return r;
|
2013-01-17 08:13:26 -06:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
fn decode_side_tables(xcx: @ExtendedDecodeContext,
|
2012-10-07 18:33:20 -05:00
|
|
|
ast_doc: ebml::Doc) {
|
2012-02-14 17:21:53 -06:00
|
|
|
let dcx = xcx.dcx;
|
2013-03-26 14:04:30 -05:00
|
|
|
let tbl_doc = ast_doc.get(c::tag_table as uint);
|
2013-08-02 01:17:20 -05:00
|
|
|
do reader::docs(tbl_doc) |tag, entry_doc| {
|
2013-03-26 14:04:30 -05:00
|
|
|
let id0 = entry_doc.get(c::tag_table_id as uint).as_int();
|
2012-02-14 17:21:53 -06:00
|
|
|
let id = xcx.tr_id(id0);
|
|
|
|
|
2012-08-22 19:24:52 -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-08-22 19:24:52 -05:00
|
|
|
tag, id, id0);
|
2012-02-14 17:21:53 -06:00
|
|
|
|
2013-06-22 20:58:41 -05:00
|
|
|
match c::astencode_tag::from_uint(tag) {
|
|
|
|
None => {
|
2012-02-14 17:21:53 -06:00
|
|
|
xcx.dcx.tcx.sess.bug(
|
2012-08-22 19:24:52 -05:00
|
|
|
fmt!("unknown tag found in side tables: %x", tag));
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2013-06-20 14:23:52 -05:00
|
|
|
Some(value) => {
|
2013-06-22 20:58:41 -05:00
|
|
|
let val_doc = entry_doc.get(c::tag_table_val as uint);
|
|
|
|
let mut val_dsr = reader::Decoder(val_doc);
|
|
|
|
let val_dsr = &mut val_dsr;
|
|
|
|
|
|
|
|
match value {
|
|
|
|
c::tag_table_def => {
|
|
|
|
let def = decode_def(xcx, val_doc);
|
|
|
|
dcx.tcx.def_map.insert(id, def);
|
|
|
|
}
|
|
|
|
c::tag_table_node_type => {
|
|
|
|
let ty = val_dsr.read_ty(xcx);
|
|
|
|
debug!("inserting ty for node %?: %s",
|
|
|
|
id, ty_to_str(dcx.tcx, ty));
|
|
|
|
dcx.tcx.node_types.insert(id as uint, ty);
|
|
|
|
}
|
|
|
|
c::tag_table_node_type_subst => {
|
|
|
|
let tys = val_dsr.read_tys(xcx);
|
|
|
|
dcx.tcx.node_type_substs.insert(id, tys);
|
|
|
|
}
|
|
|
|
c::tag_table_freevars => {
|
|
|
|
let fv_info = @val_dsr.read_to_vec(|val_dsr| {
|
|
|
|
@val_dsr.read_freevar_entry(xcx)
|
|
|
|
});
|
|
|
|
dcx.tcx.freevars.insert(id, fv_info);
|
|
|
|
}
|
|
|
|
c::tag_table_tcache => {
|
|
|
|
let tpbt = val_dsr.read_ty_param_bounds_and_ty(xcx);
|
2013-07-27 03:25:59 -05:00
|
|
|
let lid = ast::def_id { crate: ast::LOCAL_CRATE, node: id };
|
2013-06-22 20:58:41 -05:00
|
|
|
dcx.tcx.tcache.insert(lid, tpbt);
|
|
|
|
}
|
|
|
|
c::tag_table_param_defs => {
|
|
|
|
let bounds = val_dsr.read_type_param_def(xcx);
|
|
|
|
dcx.tcx.ty_param_defs.insert(id, bounds);
|
|
|
|
}
|
|
|
|
c::tag_table_method_map => {
|
|
|
|
dcx.maps.method_map.insert(
|
|
|
|
id,
|
|
|
|
val_dsr.read_method_map_entry(xcx));
|
|
|
|
}
|
|
|
|
c::tag_table_vtable_map => {
|
2013-07-22 18:40:31 -05:00
|
|
|
dcx.maps.vtable_map.insert(
|
|
|
|
id,
|
|
|
|
val_dsr.read_vtable_res(xcx.dcx.tcx, xcx.dcx.cdata));
|
2013-06-22 20:58:41 -05:00
|
|
|
}
|
|
|
|
c::tag_table_adjustments => {
|
|
|
|
let adj: @ty::AutoAdjustment = @Decodable::decode(val_dsr);
|
|
|
|
adj.tr(xcx);
|
|
|
|
dcx.tcx.adjustments.insert(id, adj);
|
|
|
|
}
|
|
|
|
c::tag_table_capture_map => {
|
|
|
|
let cvars =
|
2013-08-07 21:21:36 -05:00
|
|
|
at_vec::to_managed_move(
|
2013-06-22 20:58:41 -05:00
|
|
|
val_dsr.read_to_vec(
|
|
|
|
|val_dsr| val_dsr.read_capture_var(xcx)));
|
|
|
|
dcx.maps.capture_map.insert(id, cvars);
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
xcx.dcx.tcx.sess.bug(
|
|
|
|
fmt!("unknown tag found in side tables: %x", tag));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
2012-02-27 16:06:44 -06:00
|
|
|
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!(">< Side table doc loaded");
|
2013-08-02 01:17:20 -05:00
|
|
|
true
|
|
|
|
};
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
2012-03-15 09:15:49 -05:00
|
|
|
|
|
|
|
// ______________________________________________________________________
|
|
|
|
// Testing of astencode_gen
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2013-05-01 19:54:54 -05:00
|
|
|
fn encode_item_ast(ebml_w: &mut writer::Encoder, item: @ast::item) {
|
|
|
|
ebml_w.start_tag(c::tag_tree as uint);
|
|
|
|
(*item).encode(ebml_w);
|
|
|
|
ebml_w.end_tag();
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2012-10-07 18:33:20 -05:00
|
|
|
fn decode_item_ast(par_doc: ebml::Doc) -> @ast::item {
|
2013-03-26 14:04:30 -05:00
|
|
|
let chi_doc = par_doc.get(c::tag_tree as uint);
|
2013-05-01 19:54:54 -05:00
|
|
|
let mut d = reader::Decoder(chi_doc);
|
|
|
|
@Decodable::decode(&mut d)
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2012-07-31 12:27:51 -05:00
|
|
|
trait fake_ext_ctxt {
|
2013-07-19 00:38:55 -05:00
|
|
|
fn cfg(&self) -> ast::CrateConfig;
|
2013-02-22 00:41:37 -06:00
|
|
|
fn parse_sess(&self) -> @mut parse::ParseSess;
|
|
|
|
fn call_site(&self) -> span;
|
2013-05-02 03:16:07 -05:00
|
|
|
fn ident_of(&self, st: &str) -> ast::ident;
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2013-02-21 02:16:31 -06:00
|
|
|
type fake_session = @mut parse::ParseSess;
|
2012-03-15 09:15:49 -05:00
|
|
|
|
|
|
|
#[cfg(test)]
|
2013-02-14 13:47:00 -06:00
|
|
|
impl fake_ext_ctxt for fake_session {
|
2013-07-19 00:38:55 -05:00
|
|
|
fn cfg(&self) -> ast::CrateConfig { ~[] }
|
2013-02-22 00:41:37 -06:00
|
|
|
fn parse_sess(&self) -> @mut parse::ParseSess { *self }
|
|
|
|
fn call_site(&self) -> span {
|
2012-12-12 12:44:01 -06:00
|
|
|
codemap::span {
|
|
|
|
lo: codemap::BytePos(0),
|
|
|
|
hi: codemap::BytePos(0),
|
|
|
|
expn_info: None
|
|
|
|
}
|
|
|
|
}
|
2013-05-02 03:16:07 -05:00
|
|
|
fn ident_of(&self, st: &str) -> ast::ident {
|
2013-06-04 14:34:25 -05:00
|
|
|
token::str_to_ident(st)
|
2012-12-12 12:44:01 -06:00
|
|
|
}
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2013-03-14 10:03:05 -05:00
|
|
|
fn mk_ctxt() -> @fake_ext_ctxt {
|
|
|
|
@parse::new_parse_sess(None) as @fake_ext_ctxt
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2012-12-12 12:44:01 -06:00
|
|
|
fn roundtrip(in_item: Option<@ast::item>) {
|
2013-06-28 17:32:26 -05:00
|
|
|
use std::io;
|
2013-02-28 10:57:33 -06:00
|
|
|
|
2013-08-03 18:59:24 -05:00
|
|
|
let in_item = in_item.unwrap();
|
2012-09-14 11:40:28 -05:00
|
|
|
let bytes = do io::with_bytes_writer |wr| {
|
2013-05-01 19:54:54 -05:00
|
|
|
let mut ebml_w = writer::Encoder(wr);
|
|
|
|
encode_item_ast(&mut ebml_w, in_item);
|
2012-09-14 11:40:28 -05:00
|
|
|
};
|
2012-12-06 18:13:54 -06:00
|
|
|
let ebml_doc = reader::Doc(@bytes);
|
2012-03-15 09:15:49 -05:00
|
|
|
let out_item = decode_item_ast(ebml_doc);
|
|
|
|
|
2013-03-30 17:04:24 -05:00
|
|
|
assert_eq!(in_item, out_item);
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_basic() {
|
2013-08-15 01:06:33 -05:00
|
|
|
let cx = mk_ctxt();
|
|
|
|
roundtrip(quote_item!(cx,
|
2012-03-15 09:15:49 -05:00
|
|
|
fn foo() {}
|
2012-12-12 12:44:01 -06:00
|
|
|
));
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_smalltalk() {
|
2013-08-15 01:06:33 -05:00
|
|
|
let cx = mk_ctxt();
|
|
|
|
roundtrip(quote_item!(cx,
|
2012-03-15 09:15:49 -05:00
|
|
|
fn foo() -> int { 3 + 4 } // first smalltalk program ever executed.
|
2012-12-12 12:44:01 -06:00
|
|
|
));
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_more() {
|
2013-08-15 01:06:33 -05:00
|
|
|
let cx = mk_ctxt();
|
|
|
|
roundtrip(quote_item!(cx,
|
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
|
|
|
}
|
2012-12-12 12:44:01 -06:00
|
|
|
));
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_simplification() {
|
2013-08-15 01:06:33 -05:00
|
|
|
let cx = mk_ctxt();
|
|
|
|
let item_in = ast::ii_item(quote_item!(cx,
|
2013-07-10 16:43:25 -05:00
|
|
|
fn new_int_alist<B>() -> alist<int, B> {
|
2013-05-07 19:57:58 -05:00
|
|
|
fn eq_int(a: int, b: int) -> bool { a == b }
|
2013-02-21 18:40:52 -06:00
|
|
|
return alist {eq_fn: eq_int, data: ~[]};
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
2013-08-03 18:59:24 -05:00
|
|
|
).unwrap());
|
2013-04-17 11:15:37 -05:00
|
|
|
let item_out = simplify_ast(&item_in);
|
2013-08-15 01:06:33 -05:00
|
|
|
let item_exp = ast::ii_item(quote_item!(cx,
|
2013-07-10 16:43:25 -05:00
|
|
|
fn new_int_alist<B>() -> alist<int, B> {
|
2013-02-21 18:40:52 -06:00
|
|
|
return alist {eq_fn: eq_int, data: ~[]};
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
2013-08-03 18:59:24 -05:00
|
|
|
).unwrap());
|
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)) => {
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(pprust::item_to_str(item_out,
|
2013-05-14 19:27:27 -05:00
|
|
|
token::get_ident_interner())
|
2013-03-06 15:58:02 -06:00
|
|
|
== pprust::item_to_str(item_exp,
|
2013-05-14 19:27:27 -05:00
|
|
|
token::get_ident_interner()));
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
2013-02-11 21:26:38 -06:00
|
|
|
_ => fail!()
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
|
|
|
}
|