2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// 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-01-08 21:37:25 -06:00
|
|
|
use core::prelude::*;
|
2013-01-07 16:16:52 -06: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::encoder;
|
|
|
|
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
|
|
|
|
2012-12-23 16:41:37 -06:00
|
|
|
use std::ebml::reader;
|
2012-12-13 15:05:22 -06:00
|
|
|
use std::ebml;
|
2012-12-17 21:31:04 -06:00
|
|
|
use std::serialize;
|
2013-03-05 16:49:03 -06:00
|
|
|
use std::serialize::{Encoder, Encodable, EncoderHelpers, DecoderHelpers};
|
|
|
|
use std::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;
|
2012-12-23 16:41:37 -06:00
|
|
|
use syntax;
|
2012-12-13 15:05:22 -06:00
|
|
|
use writer = std::ebml::writer;
|
2012-02-14 17:21:53 -06: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 19:46:45 -05:00
|
|
|
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,
|
2013-01-11 23:01:42 -06:00
|
|
|
write_guard_map: middle::borrowck::write_guard_map,
|
2013-01-10 12:59:58 -06:00
|
|
|
moves_map: middle::moves::MovesMap,
|
|
|
|
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-02-19 01:40:42 -06:00
|
|
|
pub fn encode_inlined_item(ecx: @e::EncodeContext,
|
2013-01-30 15:44:24 -06:00
|
|
|
ebml_w: writer::Encoder,
|
|
|
|
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)",
|
2012-07-18 18:18:02 -05:00
|
|
|
ast_map::path_to_str(path, ecx.tcx.sess.parse_sess.interner),
|
2013-02-10 18:33:16 -06: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
|
|
|
|
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-12-17 21:31:04 -06:00
|
|
|
id_range.encode(&ebml_w);
|
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-08-22 19:24:52 -05:00
|
|
|
debug!("< Encoded inlined fn: %s::%s (%u)",
|
2012-07-18 18:18:02 -05:00
|
|
|
ast_map::path_to_str(path, ecx.tcx.sess.parse_sess.interner),
|
2013-02-10 18:33:16 -06: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-03-10 10:02:16 -05:00
|
|
|
+path: ast_map::path,
|
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::?",
|
|
|
|
ast_map::path_to_str(path, tcx.sess.parse_sess.interner));
|
2012-12-17 21:31:04 -06:00
|
|
|
let ast_dsr = &reader::Decoder(ast_doc);
|
2012-12-18 20:05:16 -06:00
|
|
|
let from_id_range = Decodable::decode(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-02-10 18:33:16 -06: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",
|
2012-07-18 18:18:02 -05:00
|
|
|
ast_map::path_to_str(path, tcx.sess.parse_sess.interner),
|
2013-02-10 18:33:16 -06:00
|
|
|
*tcx.sess.str_of(ii.ident()));
|
2013-01-24 18:45:20 -06:00
|
|
|
ast_map::map_decoded_item(tcx.sess.diagnostic(),
|
|
|
|
dcx.tcx.items, path, ii);
|
|
|
|
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:
|
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;
|
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-02-26 19:47:41 -06:00
|
|
|
pub impl ExtendedDecodeContext {
|
2013-02-19 01:40:42 -06:00
|
|
|
fn tr_id(&self, id: ast::node_id) -> ast::node_id {
|
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-28 20:39:09 -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)
|
|
|
|
}
|
2013-02-19 01:40:42 -06:00
|
|
|
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-02-19 01:40:42 -06:00
|
|
|
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-03-28 20:39:09 -05:00
|
|
|
assert!(did.crate == ast::local_crate);
|
2013-01-13 13:05:40 -06:00
|
|
|
ast::def_id { crate: ast::local_crate, node: self.tr_id(did.node) }
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2013-02-19 01:40:42 -06:00
|
|
|
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-02-22 00:41:37 -06:00
|
|
|
fn emit_def_id(&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-02-22 00:41:37 -06:00
|
|
|
fn emit_def_id(&self, did: ast::def_id) {
|
|
|
|
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-02-22 00:41:37 -06:00
|
|
|
fn read_def_id(&self, xcx: @ExtendedDecodeContext) -> 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 {
|
2012-07-11 17:00:40 -05:00
|
|
|
|
2013-02-22 00:41:37 -06:00
|
|
|
fn read_def_id(&self, xcx: @ExtendedDecodeContext) -> ast::def_id {
|
|
|
|
let did: ast::def_id = Decodable::decode(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-12-17 21:31:04 -06:00
|
|
|
fn encode_ast(ebml_w: writer::Encoder, item: ast::inlined_item) {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(c::tag_tree as uint) {
|
2012-12-17 21:31:04 -06:00
|
|
|
item.encode(&ebml_w)
|
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 {
|
2013-03-12 15:00:50 -05:00
|
|
|
fn drop_nested_items(blk: &ast::blk_, fld: @fold::ast_fold) -> ast::blk_ {
|
2013-01-07 23:15:25 -06:00
|
|
|
let stmts_sans_items = do blk.stmts.filtered |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-01-30 11:56:33 -06:00
|
|
|
ast::stmt_decl(@codemap::spanned { node: ast::decl_local(_),
|
2012-12-27 13:36:00 -06:00
|
|
|
span: _}, _) => true,
|
2013-01-30 11:56:33 -06:00
|
|
|
ast::stmt_decl(@codemap::spanned { node: ast::decl_item(_),
|
2012-12-27 13:36:00 -06:00
|
|
|
span: _}, _) => false,
|
2013-02-11 21:26:38 -06:00
|
|
|
ast::stmt_mac(*) => fail!(~"unexpanded macro in astencode")
|
2012-03-07 17:13:31 -06:00
|
|
|
}
|
|
|
|
};
|
2013-01-14 22:52:28 -06:00
|
|
|
let blk_sans_items = ast::blk_ {
|
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,
|
|
|
|
rules: blk.rules
|
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 {
|
2012-09-04 15:29:32 -05:00
|
|
|
fold_block: fold::wrap(drop_nested_items),
|
|
|
|
.. *fold::default_ast_fold()
|
2012-03-07 17:13:31 -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()) //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
|
|
|
}
|
2013-01-07 16:16:52 -06:00
|
|
|
ast::ii_dtor(ref dtor, nm, ref tps, parent_id) => {
|
2013-02-18 00:20:36 -06:00
|
|
|
let dtor_body = fld.fold_block(&dtor.node.body);
|
2013-01-13 14:29:36 -06:00
|
|
|
ast::ii_dtor(
|
2013-01-30 11:56:33 -06:00
|
|
|
codemap::spanned {
|
2013-01-13 14:29:36 -06:00
|
|
|
node: ast::struct_dtor_ { body: dtor_body,
|
|
|
|
.. /*bad*/copy (*dtor).node },
|
|
|
|
.. (/*bad*/copy *dtor) },
|
|
|
|
nm, /*bad*/copy *tps, parent_id)
|
2012-06-12 18:25:09 -05:00
|
|
|
}
|
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);
|
2012-12-17 21:31:04 -06:00
|
|
|
let d = &reader::Decoder(chi_doc);
|
2012-12-18 20:05:16 -06:00
|
|
|
Decodable::decode(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 {
|
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
|
|
|
}
|
2013-02-14 23:50:03 -06:00
|
|
|
ast::ii_dtor(ref dtor, nm, ref generics, parent_id) => {
|
2013-02-18 00:20:36 -06:00
|
|
|
let dtor_body = fld.fold_block(&dtor.node.body);
|
2013-01-07 16:16:52 -06:00
|
|
|
let dtor_attrs = fld.fold_attributes(/*bad*/copy (*dtor).node.attrs);
|
2013-02-14 23:50:03 -06:00
|
|
|
let new_generics = fold::fold_generics(generics, fld);
|
2012-12-04 12:50:00 -06:00
|
|
|
let dtor_id = fld.new_id((*dtor).node.id);
|
2012-06-12 18:25:09 -05:00
|
|
|
let new_parent = xcx.tr_def_id(parent_id);
|
2012-12-04 12:50:00 -06:00
|
|
|
let new_self = fld.new_id((*dtor).node.self_id);
|
2013-01-13 14:29:36 -06:00
|
|
|
ast::ii_dtor(
|
2013-01-30 11:56:33 -06:00
|
|
|
codemap::spanned {
|
2013-01-13 14:29:36 -06:00
|
|
|
node: ast::struct_dtor_ { id: dtor_id,
|
|
|
|
attrs: dtor_attrs,
|
|
|
|
self_id: new_self,
|
|
|
|
body: dtor_body },
|
|
|
|
.. (/*bad*/copy *dtor)
|
|
|
|
},
|
2013-02-14 23:50:03 -06:00
|
|
|
nm, new_generics, new_parent)
|
2012-06-12 18:25:09 -05:00
|
|
|
}
|
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-12-17 21:31:04 -06:00
|
|
|
fn encode_def(ebml_w: writer::Encoder, def: ast::def) {
|
|
|
|
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 {
|
2012-12-17 21:31:04 -06:00
|
|
|
let dsr = &reader::Decoder(doc);
|
2012-12-18 20:05:16 -06:00
|
|
|
let def: ast::def = Decodable::decode(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 {
|
2012-08-02 18:01:38 -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)
|
2012-08-02 18:01:38 -05:00
|
|
|
}
|
2012-12-10 13:58:37 -06:00
|
|
|
ast::def_self_ty(nid) => { ast::def_self_ty(xcx.tr_id(nid)) }
|
|
|
|
ast::def_self(nid, i) => { ast::def_self(xcx.tr_id(nid), i) }
|
2012-08-02 18:01:38 -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_const(did) => { ast::def_const(did.tr(xcx)) }
|
2013-01-03 11:57:08 -06:00
|
|
|
ast::def_arg(nid, m, b) => { ast::def_arg(xcx.tr_id(nid), m, b) }
|
2012-08-02 18:01:38 -05:00
|
|
|
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-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
|
|
|
}
|
2012-12-10 15:47:54 -06:00
|
|
|
ast::def_struct(did) => {
|
|
|
|
ast::def_struct(did.tr(xcx))
|
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-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-02-27 18:28:37 -06:00
|
|
|
match self {
|
|
|
|
&ty::AutoAddEnv(r, s) => {
|
|
|
|
ty::AutoAddEnv(r.tr(xcx), s)
|
|
|
|
}
|
|
|
|
|
|
|
|
&ty::AutoDerefRef(ref adr) => {
|
|
|
|
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-01-16 21:24:10 -06:00
|
|
|
ty::AutoRef {
|
|
|
|
kind: self.kind,
|
|
|
|
region: self.region.tr(xcx),
|
|
|
|
mutbl: self.mutbl,
|
|
|
|
}
|
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_free(id, br) => ty::re_free(xcx.tr_id(id), br.tr(xcx)),
|
|
|
|
ty::re_scope(id) => ty::re_scope(xcx.tr_id(id)),
|
2013-02-22 00:41:37 -06:00
|
|
|
ty::re_static | ty::re_infer(*) => *self,
|
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
|
|
|
|
2012-12-17 21:31:04 -06:00
|
|
|
fn encode_freevar_entry(ebml_w: writer::Encoder, fv: @freevar_entry) {
|
|
|
|
(*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-02-22 00:41:37 -06:00
|
|
|
fn read_freevar_entry(&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-02-22 00:41:37 -06:00
|
|
|
fn read_freevar_entry(&self, xcx: @ExtendedDecodeContext)
|
|
|
|
-> freevar_entry {
|
|
|
|
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-02-22 00:41:37 -06:00
|
|
|
fn read_capture_var(&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-02-22 00:41:37 -06:00
|
|
|
fn read_capture_var(&self, xcx: @ExtendedDecodeContext)
|
|
|
|
-> moves::CaptureVar {
|
|
|
|
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-02-22 00:41:37 -06:00
|
|
|
fn read_method_map_entry(&self, xcx: @ExtendedDecodeContext)
|
|
|
|
-> method_map_entry;
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
fn encode_method_map_entry(ecx: @e::EncodeContext,
|
2012-12-17 21:31:04 -06:00
|
|
|
ebml_w: writer::Encoder,
|
2012-09-11 23:25:01 -05:00
|
|
|
mme: method_map_entry) {
|
2013-03-29 00:19:43 -05:00
|
|
|
do ebml_w.emit_struct("method_map_entry", 3) {
|
2012-10-07 12:31:34 -05:00
|
|
|
do ebml_w.emit_field(~"self_arg", 0u) {
|
2012-09-11 23:25:01 -05:00
|
|
|
ebml_w.emit_arg(ecx, mme.self_arg);
|
|
|
|
}
|
2012-11-28 19:33:30 -06:00
|
|
|
do ebml_w.emit_field(~"explicit_self", 2u) {
|
2012-12-17 21:31:04 -06:00
|
|
|
mme.explicit_self.encode(&ebml_w);
|
2012-11-28 19:33:30 -06:00
|
|
|
}
|
2012-10-07 12:31:34 -05:00
|
|
|
do ebml_w.emit_field(~"origin", 1u) {
|
2012-12-17 21:31:04 -06:00
|
|
|
mme.origin.encode(&ebml_w);
|
2012-09-11 23:25:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl read_method_map_entry_helper for reader::Decoder {
|
2013-02-22 00:41:37 -06:00
|
|
|
fn read_method_map_entry(&self, xcx: @ExtendedDecodeContext)
|
2013-02-19 02:14:56 -06:00
|
|
|
-> method_map_entry {
|
2013-03-29 00:19:43 -05:00
|
|
|
do self.read_struct("method_map_entry", 3) {
|
2013-01-16 21:24:10 -06:00
|
|
|
method_map_entry {
|
|
|
|
self_arg: self.read_field(~"self_arg", 0u, || {
|
|
|
|
self.read_arg(xcx)
|
|
|
|
}),
|
|
|
|
explicit_self: self.read_field(~"explicit_self", 2u, || {
|
2013-02-22 00:41:37 -06:00
|
|
|
let self_type: ast::self_ty_ = Decodable::decode(self);
|
2012-11-28 19:33:30 -06:00
|
|
|
self_type
|
2013-01-16 21:24:10 -06:00
|
|
|
}),
|
|
|
|
origin: self.read_field(~"origin", 1u, || {
|
|
|
|
let method_origin: method_origin =
|
2013-02-22 00:41:37 -06:00
|
|
|
Decodable::decode(self);
|
2013-01-16 21:24:10 -06:00
|
|
|
method_origin.tr(xcx)
|
|
|
|
}),
|
|
|
|
}
|
2012-09-11 23:25:01 -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
|
|
|
}
|
2012-10-05 18:55:42 -05:00
|
|
|
typeck::method_trait(did, m, vstore) => {
|
2013-01-16 20:45:05 -06:00
|
|
|
typeck::method_trait(did.tr(xcx), m, vstore)
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
2012-10-05 20:51:36 -05:00
|
|
|
typeck::method_self(did, m) => {
|
2013-01-16 20:45:05 -06:00
|
|
|
typeck::method_self(did.tr(xcx), m)
|
|
|
|
}
|
|
|
|
typeck::method_super(trait_did, m) => {
|
|
|
|
typeck::method_super(trait_did.tr(xcx), m)
|
2012-10-05 20:51:36 -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
|
|
|
// ______________________________________________________________________
|
2012-03-08 09:17:59 -06:00
|
|
|
// Encoding and decoding vtable_res
|
2012-02-14 17:21:53 -06:00
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
fn encode_vtable_res(ecx: @e::EncodeContext,
|
2012-12-17 21:31:04 -06:00
|
|
|
ebml_w: 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-01-24 18:45:20 -06:00
|
|
|
do ebml_w.emit_from_vec(*dr) |vtable_origin| {
|
2012-10-07 12:31:34 -05: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
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
fn encode_vtable_origin(ecx: @e::EncodeContext,
|
2012-12-17 21:31:04 -06:00
|
|
|
ebml_w: writer::Encoder,
|
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") {
|
2013-03-20 00:17:42 -05:00
|
|
|
match vtable_origin {
|
|
|
|
typeck::vtable_static(def_id, ref 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) {
|
2013-03-20 00:17:42 -05:00
|
|
|
ebml_w.emit_tys(ecx, /*bad*/copy *tys);
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
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-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-12-17 21:31:04 -06:00
|
|
|
trait vtable_decoder_helpers {
|
2013-02-22 00:41:37 -06:00
|
|
|
fn read_vtable_res(&self, xcx: @ExtendedDecodeContext)
|
|
|
|
-> typeck::vtable_res;
|
|
|
|
fn read_vtable_origin(&self, xcx: @ExtendedDecodeContext)
|
2013-02-19 02:14:56 -06: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-02-22 00:41:37 -06:00
|
|
|
fn read_vtable_res(&self, xcx: @ExtendedDecodeContext)
|
|
|
|
-> 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
|
|
|
|
2013-03-26 20:46:48 -05:00
|
|
|
fn read_vtable_origin(&self, xcx: @ExtendedDecodeContext)
|
|
|
|
-> typeck::vtable_origin {
|
|
|
|
do self.read_enum("vtable_origin") {
|
|
|
|
do self.read_enum_variant(["vtable_static", "vtable_param"]) |i| {
|
|
|
|
match i {
|
|
|
|
0 => {
|
|
|
|
typeck::vtable_static(
|
|
|
|
do self.read_enum_variant_arg(0u) {
|
|
|
|
self.read_def_id(xcx)
|
|
|
|
},
|
|
|
|
do self.read_enum_variant_arg(1u) {
|
|
|
|
self.read_tys(xcx)
|
|
|
|
},
|
|
|
|
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-21 19:22:45 -05:00
|
|
|
1 => {
|
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-21 19:22:45 -05:00
|
|
|
// hard to avoid - user input
|
2013-02-11 21:26:38 -06: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-03-08 18:34:39 -06:00
|
|
|
fn ty_str_ctxt(@self) -> @tyencode::ctxt;
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
|
|
|
|
2013-03-08 18:34:39 -06:00
|
|
|
impl get_ty_str_ctxt for e::EncodeContext {
|
2013-02-22 00:41:37 -06:00
|
|
|
// IMPLICIT SELF WARNING: fix this!
|
2013-03-08 18:34:39 -06:00
|
|
|
fn ty_str_ctxt(@self) -> @tyencode::ctxt {
|
2013-01-08 16:00:45 -06:00
|
|
|
@tyencode::ctxt {diag: self.tcx.sess.diagnostic(),
|
|
|
|
ds: e::def_to_str,
|
|
|
|
tcx: self.tcx,
|
|
|
|
reachable: |a| encoder::reachable(self, a),
|
|
|
|
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-02-22 00:41:37 -06:00
|
|
|
fn emit_arg(&self, ecx: @e::EncodeContext, arg: ty::arg);
|
|
|
|
fn emit_ty(&self, ecx: @e::EncodeContext, ty: ty::t);
|
|
|
|
fn emit_vstore(&self, ecx: @e::EncodeContext, vstore: ty::vstore);
|
|
|
|
fn emit_tys(&self, ecx: @e::EncodeContext, tys: ~[ty::t]);
|
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
|
|
|
fn emit_type_param_def(&self,
|
|
|
|
ecx: @e::EncodeContext,
|
|
|
|
type_param_def: &ty::TypeParameterDef);
|
2013-02-22 00:41:37 -06:00
|
|
|
fn emit_tpbt(&self, ecx: @e::EncodeContext,
|
|
|
|
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-02-22 00:41:37 -06:00
|
|
|
fn emit_ty(&self, ecx: @e::EncodeContext, ty: ty::t) {
|
2012-09-11 23:25:01 -05:00
|
|
|
do self.emit_opaque {
|
2013-02-22 00:41:37 -06:00
|
|
|
e::write_type(ecx, *self, ty)
|
2012-09-11 23:25:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-22 00:41:37 -06:00
|
|
|
fn emit_vstore(&self, ecx: @e::EncodeContext, vstore: ty::vstore) {
|
2012-10-05 18:55:42 -05:00
|
|
|
do self.emit_opaque {
|
2013-02-22 00:41:37 -06:00
|
|
|
e::write_vstore(ecx, *self, vstore)
|
2012-10-05 18:55:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-22 00:41:37 -06:00
|
|
|
fn emit_arg(&self, ecx: @e::EncodeContext, arg: ty::arg) {
|
2012-09-11 23:25:01 -05:00
|
|
|
do self.emit_opaque {
|
|
|
|
tyencode::enc_arg(self.writer, ecx.ty_str_ctxt(), arg);
|
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
|
2013-02-22 00:41:37 -06:00
|
|
|
fn emit_tys(&self, ecx: @e::EncodeContext, tys: ~[ty::t]) {
|
2013-01-24 18:45:20 -06:00
|
|
|
do self.emit_from_vec(tys) |ty| {
|
2012-10-07 12:31:34 -05:00
|
|
|
self.emit_ty(ecx, *ty)
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
fn emit_type_param_def(&self,
|
|
|
|
ecx: @e::EncodeContext,
|
|
|
|
type_param_def: &ty::TypeParameterDef) {
|
2012-09-11 23:25:01 -05:00
|
|
|
do self.emit_opaque {
|
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
|
|
|
tyencode::enc_type_param_def(self.writer, ecx.ty_str_ctxt(),
|
|
|
|
type_param_def)
|
2012-09-11 23:25:01 -05:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
|
2013-02-22 00:41:37 -06:00
|
|
|
fn emit_tpbt(&self, ecx: @e::EncodeContext,
|
|
|
|
tpbt: ty::ty_param_bounds_and_ty) {
|
2013-03-27 05:16:28 -05:00
|
|
|
do self.emit_struct("ty_param_bounds_and_ty", 2) {
|
|
|
|
do self.emit_field(~"generics", 0) {
|
|
|
|
do self.emit_struct("Generics", 2) {
|
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
|
|
|
do self.emit_field(~"type_param_defs", 0) {
|
|
|
|
do self.emit_from_vec(*tpbt.generics.type_param_defs)
|
|
|
|
|type_param_def|
|
|
|
|
{
|
|
|
|
self.emit_type_param_def(ecx, type_param_def);
|
2013-03-27 05:16:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
do self.emit_field(~"region_param", 1) {
|
|
|
|
tpbt.generics.region_param.encode(self);
|
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
2013-03-27 05:16:28 -05:00
|
|
|
do self.emit_field(~"ty", 1) {
|
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 {
|
2013-03-07 16:38:38 -06:00
|
|
|
fn tag(&self, tag_id: c::astencode_tag, f: &fn());
|
2013-02-22 00:41:37 -06:00
|
|
|
fn id(&self, id: ast::node_id);
|
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-03-07 16:38:38 -06:00
|
|
|
fn tag(&self, 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
|
|
|
}
|
|
|
|
|
2013-02-22 00:41:37 -06:00
|
|
|
fn id(&self, id: ast::node_id) {
|
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-02-19 01:40:42 -06:00
|
|
|
fn encode_side_tables_for_ii(ecx: @e::EncodeContext,
|
2013-01-10 12:59:58 -06:00
|
|
|
maps: Maps,
|
2012-12-17 21:31:04 -06:00
|
|
|
ebml_w: writer::Encoder,
|
2012-03-01 21:37:52 -06:00
|
|
|
ii: ast::inlined_item) {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(c::tag_table as uint) {
|
2013-01-10 12:59:58 -06:00
|
|
|
let ebml_w = copy ebml_w;
|
2012-06-13 18:14:01 -05:00
|
|
|
ast_util::visit_ids_for_inlined_item(
|
|
|
|
ii,
|
2013-03-01 14:11:07 -06:00
|
|
|
|id: ast::node_id| {
|
2012-06-13 18:14:01 -05:00
|
|
|
// 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
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
fn encode_side_tables_for_id(ecx: @e::EncodeContext,
|
2013-01-10 12:59:58 -06:00
|
|
|
maps: Maps,
|
2012-12-17 21:31:04 -06:00
|
|
|
ebml_w: writer::Encoder,
|
2012-02-14 17:21:53 -06:00
|
|
|
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-08-22 19:24:52 -05:00
|
|
|
debug!("Encoding side tables for id %d", id);
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-03-03 06:33:39 -06:00
|
|
|
for tcx.def_map.find(&id).each |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-12-17 21:31:04 -06:00
|
|
|
(*def).encode(&ebml_w)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-03 06:33:39 -06:00
|
|
|
|
|
|
|
for tcx.node_types.find(&(id as uint)).each |&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-09-27 19:01:28 -05:00
|
|
|
ebml_w.emit_ty(ecx, *ty);
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-03-03 06:33:39 -06:00
|
|
|
for tcx.node_type_substs.find(&id).each |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) {
|
2013-03-23 17:55:58 -05:00
|
|
|
// FIXME(#5562): removing this copy causes a segfault
|
|
|
|
// before stage2
|
|
|
|
ebml_w.emit_tys(ecx, /*bad*/copy **tys)
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-03-22 21:26:41 -05:00
|
|
|
for tcx.freevars.find(&id).each |&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) {
|
2013-01-24 18:45:20 -06: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
|
|
|
|
2013-01-13 13:05:40 -06:00
|
|
|
let lid = ast::def_id { crate: ast::local_crate, node: id };
|
2013-03-22 21:26:41 -05:00
|
|
|
for tcx.tcache.find(&lid).each |&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-09-27 19:01:28 -05:00
|
|
|
ebml_w.emit_tpbt(ecx, *tpbt);
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
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
|
|
|
for tcx.ty_param_defs.find(&id).each |&type_param_def| {
|
|
|
|
do ebml_w.tag(c::tag_table_param_defs) {
|
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) {
|
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
|
|
|
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
|
|
|
|
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.
|
|
|
|
//
|
2013-03-03 06:33:39 -06:00
|
|
|
//for tcx.inferred_modes.find(&id).each |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);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
2013-03-22 21:26:41 -05:00
|
|
|
if maps.mutbl_map.contains(&id) {
|
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
|
|
|
|
2013-03-07 17:37:14 -06:00
|
|
|
for maps.last_use_map.find(&id).each |&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) {
|
2013-03-22 21:26:41 -05:00
|
|
|
do ebml_w.emit_from_vec(/*bad*/ copy **m) |id| {
|
2012-12-17 21:31:04 -06:00
|
|
|
id.encode(&ebml_w);
|
2012-05-25 02:14:40 -05:00
|
|
|
}
|
2012-03-08 04:14:35 -06:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
|
2013-03-23 17:55:58 -05:00
|
|
|
for maps.method_map.find(&id).each |&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-12-17 21:31:04 -06:00
|
|
|
encode_method_map_entry(ecx, ebml_w, *mme)
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 21:26:41 -05:00
|
|
|
for maps.vtable_map.find(&id).each |&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-09-27 19:01:28 -05:00
|
|
|
encode_vtable_res(ecx, ebml_w, *dr);
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-23 17:23:20 -05:00
|
|
|
|
2013-03-03 06:33:39 -06:00
|
|
|
for tcx.adjustments.find(&id).each |adj| {
|
2012-09-11 23:25:01 -05:00
|
|
|
do ebml_w.tag(c::tag_table_adjustments) {
|
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-12-17 21:31:04 -06:00
|
|
|
(**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-03-22 21:26:41 -05:00
|
|
|
if maps.moves_map.contains(&id) {
|
2013-01-10 12:59:58 -06:00
|
|
|
do ebml_w.tag(c::tag_table_moves_map) {
|
|
|
|
ebml_w.id(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 21:26:41 -05:00
|
|
|
for maps.capture_map.find(&id).each |&cap_vars| {
|
2013-01-10 12:59:58 -06:00
|
|
|
do ebml_w.tag(c::tag_table_capture_map) {
|
2012-12-04 17:38:04 -06:00
|
|
|
ebml_w.id(id);
|
|
|
|
do ebml_w.tag(c::tag_table_val) {
|
2013-01-10 12:59:58 -06:00
|
|
|
do ebml_w.emit_from_vec(*cap_vars) |cap_var| {
|
|
|
|
cap_var.encode(&ebml_w);
|
|
|
|
}
|
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-02-22 00:41:37 -06:00
|
|
|
fn read_arg(&self, xcx: @ExtendedDecodeContext) -> ty::arg;
|
|
|
|
fn read_ty(&self, xcx: @ExtendedDecodeContext) -> ty::t;
|
|
|
|
fn read_tys(&self, xcx: @ExtendedDecodeContext) -> ~[ty::t];
|
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
|
|
|
fn read_type_param_def(&self, xcx: @ExtendedDecodeContext) -> ty::TypeParameterDef;
|
2013-02-22 00:41:37 -06:00
|
|
|
fn read_ty_param_bounds_and_ty(&self, xcx: @ExtendedDecodeContext)
|
2012-07-11 17:00:40 -05:00
|
|
|
-> ty::ty_param_bounds_and_ty;
|
2013-02-22 00:41:37 -06:00
|
|
|
fn convert_def_id(&self, xcx: @ExtendedDecodeContext,
|
2013-01-17 08:13:26 -06:00
|
|
|
source: DefIdSource,
|
|
|
|
did: ast::def_id) -> ast::def_id;
|
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-02-22 00:41:37 -06:00
|
|
|
fn read_arg(&self, xcx: @ExtendedDecodeContext) -> ty::arg {
|
2012-09-11 23:25:01 -05:00
|
|
|
do self.read_opaque |doc| {
|
|
|
|
tydecode::parse_arg_data(
|
|
|
|
doc.data, xcx.dcx.cdata.cnum, doc.start, xcx.dcx.tcx,
|
2013-01-17 08:13:26 -06:00
|
|
|
|s, a| self.convert_def_id(xcx, s, a))
|
2012-09-11 23:25:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-22 00:41:37 -06:00
|
|
|
fn read_ty(&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-01-10 12:59:58 -06:00
|
|
|
return do self.read_opaque |doc| {
|
|
|
|
|
|
|
|
let ty = tydecode::parse_ty_data(
|
2012-09-11 23:25:01 -05:00
|
|
|
doc.data, xcx.dcx.cdata.cnum, doc.start, xcx.dcx.tcx,
|
2013-01-10 12:59:58 -06:00
|
|
|
|s, a| self.convert_def_id(xcx, s, a));
|
|
|
|
|
|
|
|
debug!("read_ty(%s) = %s",
|
|
|
|
type_string(doc), ty_to_str(xcx.dcx.tcx, ty));
|
|
|
|
|
|
|
|
ty
|
|
|
|
};
|
|
|
|
|
|
|
|
fn type_string(doc: ebml::Doc) -> ~str {
|
|
|
|
let mut str = ~"";
|
|
|
|
for uint::range(doc.start, doc.end) |i| {
|
|
|
|
str::push_char(&mut str, doc.data[i] as char);
|
|
|
|
}
|
|
|
|
str
|
2012-09-11 23:25:01 -05:00
|
|
|
}
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
|
2013-02-22 00:41:37 -06:00
|
|
|
fn read_tys(&self, xcx: @ExtendedDecodeContext) -> ~[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
|
|
|
}
|
|
|
|
|
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
|
|
|
fn read_type_param_def(&self, xcx: @ExtendedDecodeContext) -> ty::TypeParameterDef {
|
2012-09-11 23:25:01 -05:00
|
|
|
do self.read_opaque |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(
|
2012-09-11 23:25:01 -05:00
|
|
|
doc.data, doc.start, xcx.dcx.cdata.cnum, xcx.dcx.tcx,
|
2013-01-17 08:13:26 -06:00
|
|
|
|s, a| self.convert_def_id(xcx, s, a))
|
2012-09-11 23:25:01 -05:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
|
2013-02-22 00:41:37 -06:00
|
|
|
fn read_ty_param_bounds_and_ty(&self, xcx: @ExtendedDecodeContext)
|
2012-09-11 23:25:01 -05:00
|
|
|
-> ty::ty_param_bounds_and_ty
|
|
|
|
{
|
2013-03-27 05:16:28 -05:00
|
|
|
do self.read_struct("ty_param_bounds_and_ty", 2) {
|
2013-02-19 01:40:42 -06:00
|
|
|
ty::ty_param_bounds_and_ty {
|
2013-03-27 05:16:28 -05:00
|
|
|
generics: do self.read_struct("Generics", 2) {
|
|
|
|
ty::Generics {
|
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_defs: self.read_field("type_param_defs", 0, || {
|
|
|
|
@self.read_to_vec(|| self.read_type_param_def(xcx))
|
2013-03-27 05:16:28 -05:00
|
|
|
}),
|
|
|
|
region_param: self.read_field(~"region_param", 1, || {
|
|
|
|
Decodable::decode(self)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
ty: self.read_field(~"ty", 1, || {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-17 08:13:26 -06:00
|
|
|
|
2013-02-22 00:41:37 -06:00
|
|
|
fn convert_def_id(&self, xcx: @ExtendedDecodeContext,
|
2013-01-17 08:13:26 -06:00
|
|
|
source: tydecode::DefIdSource,
|
|
|
|
did: ast::def_id) -> ast::def_id {
|
|
|
|
/*!
|
|
|
|
*
|
|
|
|
* 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);
|
2012-12-06 18:13:54 -06:00
|
|
|
for 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
|
|
|
|
|
|
|
if tag == (c::tag_table_mutbl as uint) {
|
2013-03-22 21:26:41 -05:00
|
|
|
dcx.maps.mutbl_map.insert(id);
|
2013-01-10 12:59:58 -06:00
|
|
|
} else if tag == (c::tag_table_moves_map as uint) {
|
2013-03-22 21:26:41 -05:00
|
|
|
dcx.maps.moves_map.insert(id);
|
2012-02-14 17:21:53 -06:00
|
|
|
} else {
|
2013-03-26 14:04:30 -05:00
|
|
|
let val_doc = entry_doc.get(c::tag_table_val as uint);
|
2012-12-17 21:31:04 -06:00
|
|
|
let val_dsr = &reader::Decoder(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);
|
2013-01-10 12:59:58 -06:00
|
|
|
debug!("inserting ty for node %?: %s",
|
|
|
|
id, ty_to_str(dcx.tcx, ty));
|
2013-02-22 23:37:37 -06:00
|
|
|
dcx.tcx.node_types.insert(id as uint, ty);
|
2012-02-14 17:21:53 -06:00
|
|
|
} 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);
|
2013-01-13 13:05:40 -06:00
|
|
|
let lid = ast::def_id { crate: ast::local_crate, node: id };
|
2012-02-14 17:21:53 -06:00
|
|
|
dcx.tcx.tcache.insert(lid, tpbt);
|
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
|
|
|
} else if tag == (c::tag_table_param_defs as uint) {
|
|
|
|
let bounds = val_dsr.read_type_param_def(xcx);
|
|
|
|
dcx.tcx.ty_param_defs.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
|
|
|
});
|
2013-03-07 17:37:14 -06:00
|
|
|
dcx.maps.last_use_map.insert(id, @mut ids);
|
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));
|
2012-09-11 23:25:01 -05:00
|
|
|
} else if tag == (c::tag_table_adjustments as uint) {
|
2012-12-18 20:05:16 -06:00
|
|
|
let adj: @ty::AutoAdjustment = @Decodable::decode(val_dsr);
|
2012-10-07 12:31:34 -05:00
|
|
|
adj.tr(xcx);
|
2012-09-11 23:25:01 -05:00
|
|
|
dcx.tcx.adjustments.insert(id, adj);
|
2013-01-10 12:59:58 -06:00
|
|
|
} else if tag == (c::tag_table_capture_map as uint) {
|
|
|
|
let cvars =
|
|
|
|
at_vec::from_owned(
|
|
|
|
val_dsr.read_to_vec(
|
|
|
|
|| val_dsr.read_capture_var(xcx)));
|
|
|
|
dcx.maps.capture_map.insert(id, cvars);
|
2012-02-14 17:21:53 -06:00
|
|
|
} else {
|
|
|
|
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
|
|
|
}
|
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");
|
2012-02-07 23:19:53 -06:00
|
|
|
}
|
|
|
|
}
|
2012-03-15 09:15:49 -05:00
|
|
|
|
|
|
|
// ______________________________________________________________________
|
|
|
|
// Testing of astencode_gen
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2012-12-17 21:31:04 -06:00
|
|
|
fn encode_item_ast(ebml_w: writer::Encoder, item: @ast::item) {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(c::tag_tree as uint) {
|
2012-12-17 21:31:04 -06:00
|
|
|
(*item).encode(&ebml_w)
|
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);
|
2012-12-17 21:31:04 -06:00
|
|
|
let d = &reader::Decoder(chi_doc);
|
2012-12-18 20:05:16 -06:00
|
|
|
@Decodable::decode(d)
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2012-07-31 12:27:51 -05:00
|
|
|
trait fake_ext_ctxt {
|
2013-02-22 00:41:37 -06:00
|
|
|
fn cfg(&self) -> ast::crate_cfg;
|
|
|
|
fn parse_sess(&self) -> @mut parse::ParseSess;
|
|
|
|
fn call_site(&self) -> span;
|
|
|
|
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-02-22 00:41:37 -06:00
|
|
|
fn cfg(&self) -> ast::crate_cfg { ~[] }
|
|
|
|
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-02-22 00:41:37 -06:00
|
|
|
fn ident_of(&self, +st: ~str) -> ast::ident {
|
2012-12-12 12:44:01 -06:00
|
|
|
self.interner.intern(@st)
|
|
|
|
}
|
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-03-07 20:49:43 -06:00
|
|
|
use core::io;
|
2013-02-28 10:57:33 -06:00
|
|
|
|
2012-12-12 12:44:01 -06:00
|
|
|
let in_item = in_item.get();
|
2012-09-14 11:40:28 -05:00
|
|
|
let bytes = do io::with_bytes_writer |wr| {
|
2012-12-17 21:31:04 -06:00
|
|
|
let ebml_w = writer::Encoder(wr);
|
2012-09-14 11:40:28 -05:00
|
|
|
encode_item_ast(ebml_w, in_item);
|
|
|
|
};
|
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() {
|
|
|
|
let ext_cx = mk_ctxt();
|
2012-12-12 12:44:01 -06:00
|
|
|
roundtrip(quote_item!(
|
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() {
|
|
|
|
let ext_cx = mk_ctxt();
|
2012-12-12 12:44:01 -06:00
|
|
|
roundtrip(quote_item!(
|
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() {
|
|
|
|
let ext_cx = mk_ctxt();
|
2012-12-12 12:44:01 -06:00
|
|
|
roundtrip(quote_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
|
|
|
}
|
2012-12-12 12:44:01 -06:00
|
|
|
));
|
2012-03-15 09:15:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_simplification() {
|
|
|
|
let ext_cx = mk_ctxt();
|
2012-12-12 12:44:01 -06:00
|
|
|
let item_in = ast::ii_item(quote_item!(
|
2013-02-20 19:07:17 -06:00
|
|
|
fn new_int_alist<B:Copy>() -> alist<int, B> {
|
2012-03-15 09:15:49 -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
|
|
|
}
|
2012-12-12 12:44:01 -06:00
|
|
|
).get());
|
2012-03-15 09:15:49 -05:00
|
|
|
let item_out = simplify_ast(item_in);
|
2012-12-12 12:44:01 -06:00
|
|
|
let item_exp = ast::ii_item(quote_item!(
|
2013-02-20 19:07:17 -06:00
|
|
|
fn new_int_alist<B:Copy>() -> 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
|
|
|
}
|
2012-12-12 12:44:01 -06:00
|
|
|
).get());
|
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-03-06 15:58:02 -06:00
|
|
|
ext_cx.parse_sess().interner)
|
|
|
|
== pprust::item_to_str(item_exp,
|
|
|
|
ext_cx.parse_sess().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
|
|
|
}
|
|
|
|
}
|