2011-06-27 18:03:01 -05:00
|
|
|
// Metadata encoding
|
|
|
|
|
2012-04-26 14:15:46 -05:00
|
|
|
import util::ppaux::ty_to_str;
|
|
|
|
|
2012-05-17 00:28:01 -05:00
|
|
|
import std::{ebml, map};
|
2012-03-07 18:48:57 -06:00
|
|
|
import std::map::hashmap;
|
2012-01-11 08:15:54 -06:00
|
|
|
import io::writer_util;
|
2012-02-14 17:21:53 -06:00
|
|
|
import ebml::writer;
|
2011-07-05 04:48:19 -05:00
|
|
|
import syntax::ast::*;
|
2012-02-14 17:21:53 -06:00
|
|
|
import syntax::print::pprust;
|
2012-03-08 16:37:45 -06:00
|
|
|
import syntax::{ast_util, visit};
|
2012-06-12 18:25:09 -05:00
|
|
|
import syntax::ast_util::*;
|
2011-07-07 14:22:39 -05:00
|
|
|
import common::*;
|
2011-06-27 17:20:17 -05:00
|
|
|
import middle::ty;
|
2012-01-30 10:28:30 -06:00
|
|
|
import middle::ty::node_id_to_type;
|
2012-05-22 01:34:34 -05:00
|
|
|
import syntax::ast_map;
|
2012-03-22 20:16:22 -05:00
|
|
|
import syntax::attr;
|
2012-02-14 17:21:53 -06:00
|
|
|
import std::serialization::serializer;
|
2012-04-18 23:26:25 -05:00
|
|
|
import std::ebml::serializer;
|
2012-05-13 19:01:52 -05:00
|
|
|
import syntax::ast;
|
2012-05-14 22:41:33 -05:00
|
|
|
import syntax::diagnostic::span_handler;
|
2011-06-27 17:20:17 -05:00
|
|
|
|
2012-05-13 19:01:52 -05:00
|
|
|
export encode_parms;
|
2011-06-27 17:20:17 -05:00
|
|
|
export encode_metadata;
|
2011-07-07 14:56:01 -05:00
|
|
|
export encoded_ty;
|
2012-04-24 01:40:53 -05:00
|
|
|
export reachable;
|
2012-05-14 19:38:17 -05:00
|
|
|
export encode_inlined_item;
|
2011-06-27 17:20:17 -05:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
// used by astencode:
|
|
|
|
export def_to_str;
|
|
|
|
export encode_ctxt;
|
|
|
|
export write_type;
|
|
|
|
export encode_def_id;
|
|
|
|
|
2011-08-12 09:15:18 -05:00
|
|
|
type abbrev_map = map::hashmap<ty::t, tyencode::ty_abbrev>;
|
2011-07-08 01:55:41 -05:00
|
|
|
|
2012-05-14 19:38:17 -05:00
|
|
|
type encode_inlined_item = fn@(ecx: @encode_ctxt,
|
|
|
|
ebml_w: ebml::writer,
|
|
|
|
path: ast_map::path,
|
|
|
|
ii: ast::inlined_item);
|
|
|
|
|
2012-05-13 19:01:52 -05:00
|
|
|
type encode_parms = {
|
2012-05-14 22:41:33 -05:00
|
|
|
diag: span_handler,
|
2012-05-13 19:01:52 -05:00
|
|
|
tcx: ty::ctxt,
|
|
|
|
reachable: hashmap<ast::node_id, ()>,
|
2012-07-14 00:57:48 -05:00
|
|
|
reexports: ~[(~str, def_id)],
|
2012-06-29 18:26:56 -05:00
|
|
|
impl_map: fn@(ast::node_id) -> ~[(ident, def_id)],
|
2012-07-14 00:57:48 -05:00
|
|
|
item_symbols: hashmap<ast::node_id, ~str>,
|
|
|
|
discrim_symbols: hashmap<ast::node_id, ~str>,
|
2012-05-14 20:29:01 -05:00
|
|
|
link_meta: link_meta,
|
2012-05-13 19:01:52 -05:00
|
|
|
cstore: cstore::cstore,
|
2012-05-14 19:38:17 -05:00
|
|
|
encode_inlined_item: encode_inlined_item
|
2012-05-13 19:01:52 -05:00
|
|
|
};
|
|
|
|
|
2012-05-14 19:38:17 -05:00
|
|
|
enum encode_ctxt = {
|
2012-05-14 22:41:33 -05:00
|
|
|
diag: span_handler,
|
2012-05-13 19:01:52 -05:00
|
|
|
tcx: ty::ctxt,
|
|
|
|
reachable: hashmap<ast::node_id, ()>,
|
2012-07-14 00:57:48 -05:00
|
|
|
reexports: ~[(~str, def_id)],
|
2012-06-29 18:26:56 -05:00
|
|
|
impl_map: fn@(ast::node_id) -> ~[(ident, def_id)],
|
2012-07-14 00:57:48 -05:00
|
|
|
item_symbols: hashmap<ast::node_id, ~str>,
|
|
|
|
discrim_symbols: hashmap<ast::node_id, ~str>,
|
2012-05-14 20:29:01 -05:00
|
|
|
link_meta: link_meta,
|
2012-05-13 19:01:52 -05:00
|
|
|
cstore: cstore::cstore,
|
2012-05-14 19:38:17 -05:00
|
|
|
encode_inlined_item: encode_inlined_item,
|
2012-05-13 19:01:52 -05:00
|
|
|
type_abbrevs: abbrev_map
|
|
|
|
};
|
2011-07-08 01:55:41 -05:00
|
|
|
|
2012-04-24 01:40:53 -05:00
|
|
|
fn reachable(ecx: @encode_ctxt, id: node_id) -> bool {
|
2012-05-13 19:01:52 -05:00
|
|
|
ecx.reachable.contains_key(id)
|
2012-04-24 01:40:53 -05:00
|
|
|
}
|
|
|
|
|
2011-06-27 17:20:17 -05:00
|
|
|
// Path table encoding
|
2012-06-10 02:49:59 -05:00
|
|
|
fn encode_name(ebml_w: ebml::writer, name: ident) {
|
|
|
|
ebml_w.wr_tagged_str(tag_paths_data_name, *name);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn encode_def_id(ebml_w: ebml::writer, id: def_id) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.wr_tagged_str(tag_def_id, def_to_str(id));
|
2012-02-06 09:13:14 -06:00
|
|
|
}
|
|
|
|
|
2012-05-17 22:37:17 -05:00
|
|
|
/* Encodes the given name, then def_id as tagged strings */
|
|
|
|
fn encode_name_and_def_id(ebml_w: ebml::writer, nm: ident,
|
|
|
|
id: node_id) {
|
|
|
|
encode_name(ebml_w, nm);
|
|
|
|
encode_def_id(ebml_w, local_def(id));
|
|
|
|
}
|
|
|
|
|
2012-07-11 12:28:30 -05:00
|
|
|
fn encode_region_param(ecx: @encode_ctxt, ebml_w: ebml::writer,
|
|
|
|
it: @ast::item) {
|
|
|
|
let rp = ecx.tcx.region_paramd_items.contains_key(it.id);
|
|
|
|
if rp { do ebml_w.wr_tag(tag_region_param) { } }
|
2012-04-18 23:26:25 -05:00
|
|
|
}
|
|
|
|
|
2012-06-10 02:49:59 -05:00
|
|
|
fn encode_named_def_id(ebml_w: ebml::writer, name: ident, id: def_id) {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(tag_paths_data_item) {
|
2012-02-06 09:13:14 -06:00
|
|
|
encode_name(ebml_w, name);
|
|
|
|
encode_def_id(ebml_w, id);
|
|
|
|
}
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2012-03-28 00:08:48 -05:00
|
|
|
fn encode_mutability(ebml_w: ebml::writer, mt: class_mutability) {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(tag_class_mut) {
|
2012-06-29 18:26:56 -05:00
|
|
|
ebml_w.writer.write(&[alt mt { class_immutable { 'i' }
|
|
|
|
class_mutable { 'm' } } as u8]);
|
2012-03-28 00:08:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-12 08:36:51 -05:00
|
|
|
type entry<T> = {val: T, pos: uint};
|
2011-07-26 07:06:02 -05:00
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn encode_enum_variant_paths(ebml_w: ebml::writer, variants: ~[variant],
|
2012-07-14 00:57:48 -05:00
|
|
|
path: ~[ident], &index: ~[entry<~str>]) {
|
2012-06-30 18:19:07 -05:00
|
|
|
for variants.each |variant| {
|
2011-08-25 19:00:12 -05:00
|
|
|
add_to_index(ebml_w, path, index, variant.node.name);
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(tag_paths_data_item) {
|
2012-02-06 09:13:14 -06:00
|
|
|
encode_name(ebml_w, variant.node.name);
|
|
|
|
encode_def_id(ebml_w, local_def(variant.node.id));
|
|
|
|
}
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn add_to_index(ebml_w: ebml::writer, path: &[ident], &index: ~[entry<~str>],
|
2012-06-10 02:49:59 -05:00
|
|
|
name: ident) {
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut full_path = ~[];
|
2012-06-28 17:00:03 -05:00
|
|
|
vec::push_all(full_path, path);
|
|
|
|
vec::push(full_path, name);
|
2012-06-25 22:00:46 -05:00
|
|
|
vec::push(index, {val: ast_util::path_name_i(full_path),
|
|
|
|
pos: ebml_w.writer.tell()});
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2012-06-26 18:18:37 -05:00
|
|
|
fn encode_foreign_module_item_paths(ebml_w: ebml::writer, nmod: foreign_mod,
|
2012-07-14 00:57:48 -05:00
|
|
|
path: ~[ident], &index: ~[entry<~str>]) {
|
2012-06-30 18:19:07 -05:00
|
|
|
for nmod.items.each |nitem| {
|
2012-07-09 17:19:34 -05:00
|
|
|
add_to_index(ebml_w, path, index, nitem.ident);
|
|
|
|
do ebml_w.wr_tag(tag_paths_foreign_path) {
|
|
|
|
encode_name(ebml_w, nitem.ident);
|
|
|
|
encode_def_id(ebml_w, local_def(nitem.id));
|
|
|
|
}
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-06 10:02:13 -06:00
|
|
|
fn encode_class_item_paths(ebml_w: ebml::writer,
|
2012-07-14 00:57:48 -05:00
|
|
|
items: ~[@class_member], path: ~[ident], &index: ~[entry<~str>]) {
|
2012-06-30 18:19:07 -05:00
|
|
|
for items.each |it| {
|
2012-05-08 09:06:24 -05:00
|
|
|
alt ast_util::class_member_visibility(it) {
|
2012-07-09 16:37:48 -05:00
|
|
|
private { again; }
|
2012-05-08 09:06:24 -05:00
|
|
|
public {
|
2012-03-28 20:50:33 -05:00
|
|
|
let (id, ident) = alt it.node {
|
|
|
|
instance_var(v, _, _, vid, _) { (vid, v) }
|
2012-03-19 12:19:00 -05:00
|
|
|
class_method(it) { (it.id, it.ident) }
|
2012-03-06 10:02:13 -06:00
|
|
|
};
|
|
|
|
add_to_index(ebml_w, path, index, ident);
|
|
|
|
encode_named_def_id(ebml_w, ident, local_def(id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-06 05:52:13 -06:00
|
|
|
fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt,
|
2012-07-31 18:38:41 -05:00
|
|
|
module_: _mod, path: ~[ident],
|
2012-07-14 00:57:48 -05:00
|
|
|
&index: ~[entry<~str>]) {
|
2012-07-31 18:38:41 -05:00
|
|
|
for module_.items.each |it| {
|
2012-04-24 01:40:53 -05:00
|
|
|
if !reachable(ecx, it.id) ||
|
2012-07-31 18:38:41 -05:00
|
|
|
!ast_util::is_exported(it.ident, module_) { again; }
|
2012-05-17 22:37:17 -05:00
|
|
|
if !ast_util::is_item_impl(it) {
|
|
|
|
add_to_index(ebml_w, path, index, it.ident);
|
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
alt it.node {
|
|
|
|
item_const(_, _) {
|
2012-02-06 09:13:14 -06:00
|
|
|
encode_named_def_id(ebml_w, it.ident, local_def(it.id));
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-12-22 10:49:54 -06:00
|
|
|
item_fn(_, tps, _) {
|
2012-02-06 09:13:14 -06:00
|
|
|
encode_named_def_id(ebml_w, it.ident, local_def(it.id));
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
item_mod(_mod) {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(tag_paths_data_mod) {
|
2012-05-17 22:37:17 -05:00
|
|
|
encode_name_and_def_id(ebml_w, it.ident, it.id);
|
2012-06-25 22:00:46 -05:00
|
|
|
encode_module_item_paths(ebml_w, ecx, _mod,
|
2012-06-28 17:00:03 -05:00
|
|
|
vec::append_one(path, it.ident),
|
2012-05-17 22:37:17 -05:00
|
|
|
index);
|
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-06-26 18:18:37 -05:00
|
|
|
item_foreign_mod(nmod) {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(tag_paths_data_mod) {
|
2012-05-17 22:37:17 -05:00
|
|
|
encode_name_and_def_id(ebml_w, it.ident, it.id);
|
2012-06-28 17:00:03 -05:00
|
|
|
encode_foreign_module_item_paths(
|
|
|
|
ebml_w, nmod,
|
|
|
|
vec::append_one(path, it.ident), index);
|
2012-05-17 22:37:17 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-07-11 12:28:30 -05:00
|
|
|
item_ty(_, tps) {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(tag_paths_data_item) {
|
2012-05-17 22:37:17 -05:00
|
|
|
encode_name_and_def_id(ebml_w, it.ident, it.id);
|
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-07-24 17:29:14 -05:00
|
|
|
item_class(_, _, items, m_ctor, m_dtor) {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(tag_paths_data_item) {
|
2012-05-17 22:37:17 -05:00
|
|
|
encode_name_and_def_id(ebml_w, it.ident, it.id);
|
|
|
|
}
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(tag_paths) {
|
2012-06-25 18:49:14 -05:00
|
|
|
// We add the same ident twice: for the
|
2012-05-17 22:37:17 -05:00
|
|
|
// class and for its ctor
|
|
|
|
add_to_index(ebml_w, path, index, it.ident);
|
2012-07-24 17:29:14 -05:00
|
|
|
|
|
|
|
alt m_ctor {
|
|
|
|
none => {
|
|
|
|
// Nothing to do.
|
|
|
|
}
|
|
|
|
some(ctor) {
|
|
|
|
encode_named_def_id(ebml_w, it.ident,
|
|
|
|
local_def(ctor.node.id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-28 17:00:03 -05:00
|
|
|
encode_class_item_paths(ebml_w, items,
|
|
|
|
vec::append_one(path, it.ident),
|
2012-05-17 22:37:17 -05:00
|
|
|
index);
|
|
|
|
}
|
2012-01-31 21:30:40 -06:00
|
|
|
}
|
2012-07-11 12:28:30 -05:00
|
|
|
item_enum(variants, _) {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(tag_paths_data_item) {
|
2012-05-17 22:37:17 -05:00
|
|
|
encode_name_and_def_id(ebml_w, it.ident, it.id);
|
|
|
|
}
|
|
|
|
encode_enum_variant_paths(ebml_w, variants, path, index);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-07-03 18:30:42 -05:00
|
|
|
item_trait(*) {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(tag_paths_data_item) {
|
2012-05-17 22:37:17 -05:00
|
|
|
encode_name_and_def_id(ebml_w, it.ident, it.id);
|
|
|
|
}
|
2011-12-20 09:33:55 -06:00
|
|
|
}
|
2012-04-24 17:52:52 -05:00
|
|
|
item_impl(*) {}
|
2012-07-14 00:57:48 -05:00
|
|
|
item_mac(*) { fail ~"item macros unimplemented" }
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-03 18:30:42 -05:00
|
|
|
fn encode_trait_ref(ebml_w: ebml::writer, ecx: @encode_ctxt, t: @trait_ref) {
|
|
|
|
ebml_w.start_tag(tag_impl_trait);
|
2012-06-26 18:25:52 -05:00
|
|
|
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, t.ref_id));
|
2012-04-26 14:15:46 -05:00
|
|
|
ebml_w.end_tag();
|
|
|
|
}
|
|
|
|
|
2011-12-15 04:42:27 -06:00
|
|
|
fn encode_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt, crate: @crate)
|
2012-07-14 00:57:48 -05:00
|
|
|
-> ~[entry<~str>] {
|
|
|
|
let mut index: ~[entry<~str>] = ~[];
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut path: ~[ident] = ~[];
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_paths);
|
2012-03-06 05:52:13 -06:00
|
|
|
encode_module_item_paths(ebml_w, ecx, crate.node.module, path, index);
|
2011-12-15 04:42:27 -06:00
|
|
|
encode_reexport_paths(ebml_w, ecx, index);
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2012-08-01 19:30:05 -05:00
|
|
|
return index;
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2011-12-15 04:42:27 -06:00
|
|
|
fn encode_reexport_paths(ebml_w: ebml::writer,
|
2012-07-14 00:57:48 -05:00
|
|
|
ecx: @encode_ctxt, &index: ~[entry<~str>]) {
|
2012-06-30 18:19:07 -05:00
|
|
|
for ecx.reexports.each |reexport| {
|
2012-05-16 23:50:17 -05:00
|
|
|
let (path, def_id) = reexport;
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(index, {val: path, pos: ebml_w.writer.tell()});
|
2012-07-09 17:19:34 -05:00
|
|
|
// List metadata ignores tag_paths_foreign_path things, but
|
|
|
|
// other things look at it.
|
|
|
|
ebml_w.start_tag(tag_paths_foreign_path);
|
2012-06-10 02:49:59 -05:00
|
|
|
encode_name(ebml_w, @path);
|
2012-05-16 23:50:17 -05:00
|
|
|
encode_def_id(ebml_w, def_id);
|
|
|
|
ebml_w.end_tag();
|
2011-12-15 04:42:27 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-27 17:20:17 -05:00
|
|
|
|
|
|
|
// Item info table encoding
|
2012-02-13 13:55:23 -06:00
|
|
|
fn encode_family(ebml_w: ebml::writer, c: char) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_items_data_item_family);
|
2012-06-29 18:26:56 -05:00
|
|
|
ebml_w.writer.write(&[c as u8]);
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
fn def_to_str(did: def_id) -> ~str { fmt!{"%d:%d", did.crate, did.node} }
|
2011-06-27 17:20:17 -05:00
|
|
|
|
2011-12-28 10:50:12 -06:00
|
|
|
fn encode_type_param_bounds(ebml_w: ebml::writer, ecx: @encode_ctxt,
|
2012-06-29 18:26:56 -05:00
|
|
|
params: ~[ty_param]) {
|
2012-05-14 22:41:33 -05:00
|
|
|
let ty_str_ctxt = @{diag: ecx.diag,
|
|
|
|
ds: def_to_str,
|
2012-05-13 19:01:52 -05:00
|
|
|
tcx: ecx.tcx,
|
2012-06-30 18:19:07 -05:00
|
|
|
reachable: |a| reachable(ecx, a),
|
2011-12-28 10:50:12 -06:00
|
|
|
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
|
2012-06-30 18:19:07 -05:00
|
|
|
for params.each |param| {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_items_data_item_ty_param_bounds);
|
2012-05-13 19:01:52 -05:00
|
|
|
let bs = ecx.tcx.ty_param_bounds.get(param.id);
|
2012-01-11 08:15:54 -06:00
|
|
|
tyencode::enc_bounds(ebml_w.writer, ty_str_ctxt, bs);
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-07-29 18:40:23 -05:00
|
|
|
}
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn encode_variant_id(ebml_w: ebml::writer, vid: def_id) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_items_data_item_variant);
|
2011-09-01 19:27:58 -05:00
|
|
|
ebml_w.writer.write(str::bytes(def_to_str(vid)));
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2012-01-05 03:57:19 -06:00
|
|
|
fn write_type(ecx: @encode_ctxt, ebml_w: ebml::writer, typ: ty::t) {
|
2011-07-27 07:19:39 -05:00
|
|
|
let ty_str_ctxt =
|
2012-05-14 22:41:33 -05:00
|
|
|
@{diag: ecx.diag,
|
|
|
|
ds: def_to_str,
|
2012-05-13 19:01:52 -05:00
|
|
|
tcx: ecx.tcx,
|
2012-06-30 18:19:07 -05:00
|
|
|
reachable: |a| reachable(ecx, a),
|
2011-07-27 07:19:39 -05:00
|
|
|
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
|
2012-01-11 08:15:54 -06:00
|
|
|
tyencode::enc_ty(ebml_w.writer, ty_str_ctxt, typ);
|
2012-01-05 03:57:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn encode_type(ecx: @encode_ctxt, ebml_w: ebml::writer, typ: ty::t) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_items_data_item_type);
|
2012-01-05 03:57:19 -06:00
|
|
|
write_type(ecx, ebml_w, typ);
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn encode_symbol(ecx: @encode_ctxt, ebml_w: ebml::writer, id: node_id) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_items_data_item_symbol);
|
2012-05-13 19:01:52 -05:00
|
|
|
let sym = alt ecx.item_symbols.find(id) {
|
2012-03-19 12:19:00 -05:00
|
|
|
some(x) { x }
|
2012-05-14 22:41:33 -05:00
|
|
|
none {
|
|
|
|
ecx.diag.handler().bug(
|
2012-07-30 18:01:07 -05:00
|
|
|
fmt!{"encode_symbol: id not found %d", id});
|
2012-05-14 22:41:33 -05:00
|
|
|
}
|
2012-03-19 12:19:00 -05:00
|
|
|
};
|
|
|
|
ebml_w.writer.write(str::bytes(sym));
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn encode_discriminant(ecx: @encode_ctxt, ebml_w: ebml::writer, id: node_id) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_items_data_item_symbol);
|
2012-05-13 19:01:52 -05:00
|
|
|
ebml_w.writer.write(str::bytes(ecx.discrim_symbols.get(id)));
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2012-01-10 15:50:40 -06:00
|
|
|
fn encode_disr_val(_ecx: @encode_ctxt, ebml_w: ebml::writer, disr_val: int) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_disr_val);
|
2012-01-10 15:50:40 -06:00
|
|
|
ebml_w.writer.write(str::bytes(int::to_str(disr_val,10u)));
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2012-01-10 15:50:40 -06:00
|
|
|
}
|
|
|
|
|
2012-03-08 16:13:57 -06:00
|
|
|
fn encode_parent_item(ebml_w: ebml::writer, id: def_id) {
|
|
|
|
ebml_w.start_tag(tag_items_data_parent_item);
|
2011-09-01 19:27:58 -05:00
|
|
|
ebml_w.writer.write(str::bytes(def_to_str(id)));
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2012-01-25 07:34:31 -06:00
|
|
|
fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: ebml::writer,
|
2012-06-29 18:26:56 -05:00
|
|
|
id: node_id, variants: ~[variant],
|
|
|
|
path: ast_map::path, index: @mut ~[entry<int>],
|
|
|
|
ty_params: ~[ty_param]) {
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut disr_val = 0;
|
|
|
|
let mut i = 0;
|
2012-05-13 19:01:52 -05:00
|
|
|
let vi = ty::enum_variants(ecx.tcx, {crate: local_crate, node: id});
|
2012-06-30 18:19:07 -05:00
|
|
|
for variants.each |variant| {
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(*index, {val: variant.node.id, pos: ebml_w.writer.tell()});
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_items_data_item);
|
2011-06-27 17:20:17 -05:00
|
|
|
encode_def_id(ebml_w, local_def(variant.node.id));
|
2012-02-13 13:55:23 -06:00
|
|
|
encode_family(ebml_w, 'v');
|
2012-01-15 23:42:10 -06:00
|
|
|
encode_name(ebml_w, variant.node.name);
|
2012-03-08 16:13:57 -06:00
|
|
|
encode_parent_item(ebml_w, local_def(id));
|
2011-07-08 01:55:41 -05:00
|
|
|
encode_type(ecx, ebml_w,
|
2012-05-13 19:01:52 -05:00
|
|
|
node_id_to_type(ecx.tcx, variant.node.id));
|
2012-03-08 06:30:22 -06:00
|
|
|
if vec::len(variant.node.args) > 0u && ty_params.len() == 0u {
|
2011-07-08 01:55:41 -05:00
|
|
|
encode_symbol(ecx, ebml_w, variant.node.id);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
2011-07-08 01:55:41 -05:00
|
|
|
encode_discriminant(ecx, ebml_w, variant.node.id);
|
2012-01-16 03:36:47 -06:00
|
|
|
if vi[i].disr_val != disr_val {
|
|
|
|
encode_disr_val(ecx, ebml_w, vi[i].disr_val);
|
|
|
|
disr_val = vi[i].disr_val;
|
2012-01-10 15:50:40 -06:00
|
|
|
}
|
2011-12-28 10:50:12 -06:00
|
|
|
encode_type_param_bounds(ebml_w, ecx, ty_params);
|
2012-02-10 08:01:32 -06:00
|
|
|
encode_path(ebml_w, path, ast_map::path_name(variant.node.name));
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2012-01-10 15:50:40 -06:00
|
|
|
disr_val += 1;
|
2012-01-16 03:36:47 -06:00
|
|
|
i += 1;
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-10 08:01:32 -06:00
|
|
|
fn encode_path(ebml_w: ebml::writer,
|
|
|
|
path: ast_map::path,
|
|
|
|
name: ast_map::path_elt) {
|
|
|
|
fn encode_path_elt(ebml_w: ebml::writer, elt: ast_map::path_elt) {
|
|
|
|
let (tag, name) = alt elt {
|
|
|
|
ast_map::path_mod(name) { (tag_path_elt_mod, name) }
|
|
|
|
ast_map::path_name(name) { (tag_path_elt_name, name) }
|
|
|
|
};
|
|
|
|
|
2012-06-10 02:49:59 -05:00
|
|
|
ebml_w.wr_tagged_str(tag, *name);
|
2012-02-10 08:01:32 -06:00
|
|
|
}
|
|
|
|
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(tag_path) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.wr_tagged_u32(tag_path_len, (vec::len(path) + 1u) as u32);
|
2012-06-30 18:19:07 -05:00
|
|
|
do vec::iter(path) |pe| { encode_path_elt(ebml_w, pe); }
|
2012-02-10 08:01:32 -06:00
|
|
|
encode_path_elt(ebml_w, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-26 10:33:12 -06:00
|
|
|
fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: ebml::writer, md: _mod,
|
2012-02-10 08:01:32 -06:00
|
|
|
id: node_id, path: ast_map::path, name: ident) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_items_data_item);
|
2011-12-16 07:41:12 -06:00
|
|
|
encode_def_id(ebml_w, local_def(id));
|
2012-02-13 13:55:23 -06:00
|
|
|
encode_family(ebml_w, 'm');
|
2011-12-19 13:30:23 -06:00
|
|
|
encode_name(ebml_w, name);
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"(encoding info for module) encoding info for module ID %d", id};
|
2012-06-26 18:25:52 -05:00
|
|
|
// the impl map contains ref_ids
|
2012-05-17 00:28:01 -05:00
|
|
|
let impls = ecx.impl_map(id);
|
2012-06-30 18:19:07 -05:00
|
|
|
for impls.each |i| {
|
2012-05-17 00:28:01 -05:00
|
|
|
let (ident, did) = i;
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"(encoding info for module) ... encoding impl %s (%?/%?), \
|
2012-05-22 12:54:12 -05:00
|
|
|
exported? %?",
|
2012-07-18 16:41:31 -05:00
|
|
|
*ident,
|
|
|
|
did,
|
|
|
|
ast_map::node_id_to_str(ecx.tcx.items, did.node),
|
2012-07-30 18:01:07 -05:00
|
|
|
ast_util::is_exported(ident, md)};
|
2012-07-18 16:41:31 -05:00
|
|
|
|
|
|
|
ebml_w.start_tag(tag_mod_impl);
|
|
|
|
alt ecx.tcx.items.find(did.node) {
|
|
|
|
some(ast_map::node_item(it@@{node: cl@item_class(*),_},_)) {
|
|
|
|
/* If did stands for a trait
|
|
|
|
ref, we need to map it to its parent class */
|
|
|
|
ebml_w.wr_str(def_to_str(local_def(it.id)));
|
|
|
|
}
|
2012-07-18 11:31:53 -05:00
|
|
|
_ {
|
2012-07-18 16:41:31 -05:00
|
|
|
// Must be a re-export, then!
|
2012-07-30 16:51:21 -05:00
|
|
|
// ...or a trait ref
|
2012-07-18 16:41:31 -05:00
|
|
|
ebml_w.wr_str(def_to_str(did));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
ebml_w.end_tag();
|
2012-05-17 00:28:01 -05:00
|
|
|
} // for
|
|
|
|
|
2012-02-10 08:01:32 -06:00
|
|
|
encode_path(ebml_w, path, ast_map::path_mod(name));
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-12-16 07:41:12 -06:00
|
|
|
}
|
|
|
|
|
2012-05-08 09:06:24 -05:00
|
|
|
fn encode_visibility(ebml_w: ebml::writer, visibility: visibility) {
|
|
|
|
encode_family(ebml_w, alt visibility {
|
|
|
|
public { 'g' } private { 'j' }
|
|
|
|
});
|
2012-03-26 11:59:59 -05:00
|
|
|
}
|
|
|
|
|
2012-07-31 18:32:37 -05:00
|
|
|
fn encode_region(ebml_w: ebml::writer, region: region) {
|
|
|
|
alt region.node {
|
|
|
|
re_anon => {
|
|
|
|
ebml_w.wr_tagged_str(tag_item_trait_method_self_ty, ~"");
|
|
|
|
}
|
|
|
|
re_named(ident) => {
|
|
|
|
ebml_w.wr_tagged_str(tag_item_trait_method_self_ty, *ident);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn encode_self_type(ebml_w: ebml::writer, self_type: ast::self_ty_) {
|
|
|
|
ebml_w.start_tag(tag_item_trait_method_self_ty);
|
|
|
|
|
|
|
|
// Encode the base self type.
|
|
|
|
let ch;
|
|
|
|
alt self_type {
|
|
|
|
sty_by_ref => { ch = 'r' as u8; }
|
|
|
|
sty_value => { ch = 'v' as u8; }
|
|
|
|
sty_region(_, _) => { ch = '&' as u8; }
|
|
|
|
sty_box(_) => { ch = '@' as u8; }
|
|
|
|
sty_uniq(_) => { ch = '~' as u8; }
|
|
|
|
}
|
|
|
|
ebml_w.writer.write(&[ ch ]);
|
|
|
|
|
|
|
|
// Encode mutability.
|
|
|
|
alt self_type {
|
|
|
|
sty_by_ref | sty_value => { /* No-op. */ }
|
|
|
|
sty_region(_, m_imm) | sty_box(m_imm) | sty_uniq(m_imm) => {
|
|
|
|
ebml_w.writer.write(&[ 'i' as u8 ]);
|
|
|
|
}
|
|
|
|
sty_region(_, m_mutbl) | sty_box(m_mutbl) | sty_uniq(m_mutbl) => {
|
|
|
|
ebml_w.writer.write(&[ 'm' as u8 ]);
|
|
|
|
}
|
|
|
|
sty_region(_, m_const) | sty_box(m_const) | sty_uniq(m_const) => {
|
|
|
|
ebml_w.writer.write(&[ 'c' as u8 ]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encode the region.
|
|
|
|
alt self_type {
|
|
|
|
sty_region(region, _) => {
|
|
|
|
encode_region(ebml_w, *region);
|
|
|
|
}
|
|
|
|
sty_by_ref | sty_value | sty_box(*) | sty_uniq(*) => {
|
|
|
|
// Nothing to do.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ebml_w.end_tag();
|
|
|
|
}
|
|
|
|
|
2012-03-19 12:19:00 -05:00
|
|
|
/* Returns an index of items in this class */
|
2012-03-06 10:02:13 -06:00
|
|
|
fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: ebml::writer,
|
2012-03-22 20:03:12 -05:00
|
|
|
id: node_id, path: ast_map::path,
|
2012-06-29 18:26:56 -05:00
|
|
|
class_tps: ~[ty_param],
|
|
|
|
items: ~[@class_member],
|
|
|
|
global_index: @mut~[entry<int>]) -> ~[entry<int>] {
|
2012-06-25 18:49:14 -05:00
|
|
|
/* Each class has its own index, since different classes
|
|
|
|
may have fields with the same name */
|
2012-06-29 18:26:56 -05:00
|
|
|
let index = @mut ~[];
|
2012-05-13 19:01:52 -05:00
|
|
|
let tcx = ecx.tcx;
|
2012-06-30 18:19:07 -05:00
|
|
|
for items.each |ci| {
|
2012-03-19 12:19:00 -05:00
|
|
|
/* We encode both private and public fields -- need to include
|
|
|
|
private fields to get the offsets right */
|
2012-03-28 20:50:33 -05:00
|
|
|
alt ci.node {
|
2012-05-08 09:06:24 -05:00
|
|
|
instance_var(nm, _, mt, id, vis) {
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(*index, {val: id, pos: ebml_w.writer.tell()});
|
|
|
|
vec::push(*global_index, {val: id, pos: ebml_w.writer.tell()});
|
2012-03-19 12:19:00 -05:00
|
|
|
ebml_w.start_tag(tag_items_data_item);
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"encode_info_for_class: doing %s %d", *nm, id};
|
2012-05-08 09:06:24 -05:00
|
|
|
encode_visibility(ebml_w, vis);
|
2012-03-19 12:19:00 -05:00
|
|
|
encode_name(ebml_w, nm);
|
|
|
|
encode_path(ebml_w, path, ast_map::path_name(nm));
|
|
|
|
encode_type(ecx, ebml_w, node_id_to_type(tcx, id));
|
2012-03-28 00:08:48 -05:00
|
|
|
encode_mutability(ebml_w, mt);
|
2012-03-19 12:19:00 -05:00
|
|
|
encode_def_id(ebml_w, local_def(id));
|
2012-03-22 20:03:12 -05:00
|
|
|
ebml_w.end_tag();
|
2012-03-19 12:19:00 -05:00
|
|
|
}
|
|
|
|
class_method(m) {
|
2012-05-08 09:06:24 -05:00
|
|
|
alt m.vis {
|
|
|
|
public {
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(*index, {val: m.id, pos: ebml_w.writer.tell()});
|
|
|
|
vec::push(*global_index,
|
|
|
|
{val: m.id, pos: ebml_w.writer.tell()});
|
2012-06-28 17:00:03 -05:00
|
|
|
let impl_path = vec::append_one(path,
|
|
|
|
ast_map::path_name(m.ident));
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"encode_info_for_class: doing %s %d", *m.ident, m.id};
|
2012-03-28 20:50:33 -05:00
|
|
|
encode_info_for_method(ecx, ebml_w, impl_path,
|
2012-04-10 12:52:06 -05:00
|
|
|
should_inline(m.attrs), id, m,
|
2012-06-28 17:00:03 -05:00
|
|
|
vec::append(class_tps, m.tps));
|
2012-03-28 20:50:33 -05:00
|
|
|
}
|
|
|
|
_ { /* don't encode private methods */ }
|
|
|
|
}
|
2012-03-19 12:19:00 -05:00
|
|
|
}
|
|
|
|
}
|
2012-04-06 13:01:43 -05:00
|
|
|
};
|
2012-03-19 12:19:00 -05:00
|
|
|
*index
|
2012-03-06 10:02:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn encode_info_for_fn(ecx: @encode_ctxt, ebml_w: ebml::writer,
|
|
|
|
id: node_id, ident: ident, path: ast_map::path,
|
2012-06-29 18:26:56 -05:00
|
|
|
item: option<inlined_item>, tps: ~[ty_param],
|
2012-04-10 12:52:06 -05:00
|
|
|
decl: fn_decl) {
|
2012-03-06 10:02:13 -06:00
|
|
|
ebml_w.start_tag(tag_items_data_item);
|
2012-03-22 20:03:12 -05:00
|
|
|
encode_name(ebml_w, ident);
|
2012-03-06 10:02:13 -06:00
|
|
|
encode_def_id(ebml_w, local_def(id));
|
|
|
|
encode_family(ebml_w, purity_fn_family(decl.purity));
|
|
|
|
encode_type_param_bounds(ebml_w, ecx, tps);
|
2012-05-13 19:01:52 -05:00
|
|
|
let its_ty = node_id_to_type(ecx.tcx, id);
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"fn name = %s ty = %s its node id = %d", *ident,
|
|
|
|
util::ppaux::ty_to_str(ecx.tcx, its_ty), id};
|
2012-03-06 10:02:13 -06:00
|
|
|
encode_type(ecx, ebml_w, its_ty);
|
|
|
|
encode_path(ebml_w, path, ast_map::path_name(ident));
|
|
|
|
alt item {
|
|
|
|
some(it) {
|
2012-05-14 19:38:17 -05:00
|
|
|
ecx.encode_inlined_item(ecx, ebml_w, path, it);
|
2012-03-06 10:02:13 -06:00
|
|
|
}
|
|
|
|
none {
|
|
|
|
encode_symbol(ecx, ebml_w, id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ebml_w.end_tag();
|
|
|
|
}
|
|
|
|
|
2012-03-19 12:19:00 -05:00
|
|
|
fn encode_info_for_method(ecx: @encode_ctxt, ebml_w: ebml::writer,
|
|
|
|
impl_path: ast_map::path, should_inline: bool,
|
|
|
|
parent_id: node_id,
|
2012-06-29 18:26:56 -05:00
|
|
|
m: @method, all_tps: ~[ty_param]) {
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"encode_info_for_method: %d %s %u", m.id, *m.ident, all_tps.len()};
|
2012-03-19 12:19:00 -05:00
|
|
|
ebml_w.start_tag(tag_items_data_item);
|
|
|
|
encode_def_id(ebml_w, local_def(m.id));
|
|
|
|
encode_family(ebml_w, purity_fn_family(m.decl.purity));
|
|
|
|
encode_type_param_bounds(ebml_w, ecx, all_tps);
|
2012-05-13 19:01:52 -05:00
|
|
|
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, m.id));
|
2012-03-19 12:19:00 -05:00
|
|
|
encode_name(ebml_w, m.ident);
|
|
|
|
encode_path(ebml_w, impl_path, ast_map::path_name(m.ident));
|
2012-07-31 18:32:37 -05:00
|
|
|
encode_self_type(ebml_w, m.self_ty.node);
|
2012-03-19 12:19:00 -05:00
|
|
|
if all_tps.len() > 0u || should_inline {
|
2012-05-14 19:38:17 -05:00
|
|
|
ecx.encode_inlined_item(
|
2012-03-19 12:19:00 -05:00
|
|
|
ecx, ebml_w, impl_path,
|
|
|
|
ii_method(local_def(parent_id), m));
|
|
|
|
} else {
|
|
|
|
encode_symbol(ecx, ebml_w, m.id);
|
|
|
|
}
|
|
|
|
ebml_w.end_tag();
|
|
|
|
}
|
|
|
|
|
2012-02-13 11:56:09 -06:00
|
|
|
fn purity_fn_family(p: purity) -> char {
|
2012-02-10 15:39:15 -06:00
|
|
|
alt p {
|
|
|
|
unsafe_fn { 'u' }
|
|
|
|
pure_fn { 'p' }
|
|
|
|
impure_fn { 'f' }
|
2012-07-06 23:52:31 -05:00
|
|
|
extern_fn { 'F' }
|
2012-02-10 15:39:15 -06:00
|
|
|
}
|
2012-02-13 11:56:09 -06:00
|
|
|
}
|
|
|
|
|
2012-03-02 15:14:10 -06:00
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn should_inline(attrs: ~[attribute]) -> bool {
|
2012-03-19 12:19:00 -05:00
|
|
|
alt attr::find_inline_attr(attrs) {
|
2012-07-25 19:29:34 -05:00
|
|
|
attr::ia_none | attr::ia_never { false }
|
|
|
|
attr::ia_hint | attr::ia_always { true }
|
2012-03-02 15:14:10 -06:00
|
|
|
}
|
2012-03-19 12:19:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
2012-06-29 18:26:56 -05:00
|
|
|
index: @mut ~[entry<int>], path: ast_map::path) {
|
2012-03-02 15:14:10 -06:00
|
|
|
|
2012-05-13 19:01:52 -05:00
|
|
|
let tcx = ecx.tcx;
|
2012-04-18 23:26:25 -05:00
|
|
|
let must_write =
|
2012-07-18 16:41:31 -05:00
|
|
|
alt item.node {
|
|
|
|
item_enum(_, _) | item_impl(*) | item_trait(*) | item_class(*) {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
_ {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
};
|
2012-08-01 19:30:05 -05:00
|
|
|
if !must_write && !reachable(ecx, item.id) { return; }
|
2012-03-22 20:03:12 -05:00
|
|
|
|
|
|
|
fn add_to_index_(item: @item, ebml_w: ebml::writer,
|
2012-06-29 18:26:56 -05:00
|
|
|
index: @mut ~[entry<int>]) {
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(*index, {val: item.id, pos: ebml_w.writer.tell()});
|
2012-03-22 20:03:12 -05:00
|
|
|
}
|
2012-06-30 18:19:07 -05:00
|
|
|
let add_to_index = |copy ebml_w| add_to_index_(item, ebml_w, index);
|
2012-03-06 05:52:13 -06:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
alt item.node {
|
|
|
|
item_const(_, _) {
|
2012-03-22 20:03:12 -05:00
|
|
|
add_to_index();
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_items_data_item);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(item.id));
|
2012-02-13 13:55:23 -06:00
|
|
|
encode_family(ebml_w, 'c');
|
2012-01-30 10:28:30 -06:00
|
|
|
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_symbol(ecx, ebml_w, item.id);
|
2012-02-10 08:01:32 -06:00
|
|
|
encode_path(ebml_w, path, ast_map::path_name(item.ident));
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-12-22 10:49:54 -06:00
|
|
|
item_fn(decl, tps, _) {
|
2012-03-22 20:03:12 -05:00
|
|
|
add_to_index();
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_items_data_item);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(item.id));
|
2012-02-13 13:55:23 -06:00
|
|
|
encode_family(ebml_w, purity_fn_family(decl.purity));
|
2011-12-28 10:50:12 -06:00
|
|
|
encode_type_param_bounds(ebml_w, ecx, tps);
|
2012-01-30 10:28:30 -06:00
|
|
|
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
|
2012-02-10 08:01:32 -06:00
|
|
|
encode_path(ebml_w, path, ast_map::path_name(item.ident));
|
2012-03-08 03:58:23 -06:00
|
|
|
if tps.len() > 0u || should_inline(item.attrs) {
|
2012-05-14 19:38:17 -05:00
|
|
|
ecx.encode_inlined_item(ecx, ebml_w, path, ii_item(item));
|
2012-03-08 06:30:22 -06:00
|
|
|
} else {
|
|
|
|
encode_symbol(ecx, ebml_w, item.id);
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
ebml_w.end_tag();
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-12-16 07:17:52 -06:00
|
|
|
item_mod(m) {
|
2012-03-22 20:03:12 -05:00
|
|
|
add_to_index();
|
2012-02-10 08:01:32 -06:00
|
|
|
encode_info_for_mod(ecx, ebml_w, m, item.id, path, item.ident);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-06-26 18:18:37 -05:00
|
|
|
item_foreign_mod(_) {
|
2012-03-22 20:03:12 -05:00
|
|
|
add_to_index();
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_items_data_item);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(item.id));
|
2012-02-13 13:55:23 -06:00
|
|
|
encode_family(ebml_w, 'n');
|
2011-12-19 13:30:23 -06:00
|
|
|
encode_name(ebml_w, item.ident);
|
2012-02-10 08:01:32 -06:00
|
|
|
encode_path(ebml_w, path, ast_map::path_name(item.ident));
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-07-11 12:28:30 -05:00
|
|
|
item_ty(_, tps) {
|
2012-03-22 20:03:12 -05:00
|
|
|
add_to_index();
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_items_data_item);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(item.id));
|
2012-02-13 13:55:23 -06:00
|
|
|
encode_family(ebml_w, 'y');
|
2011-12-28 10:50:12 -06:00
|
|
|
encode_type_param_bounds(ebml_w, ecx, tps);
|
2012-01-30 10:28:30 -06:00
|
|
|
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
|
2011-12-19 06:52:58 -06:00
|
|
|
encode_name(ebml_w, item.ident);
|
2012-02-10 08:01:32 -06:00
|
|
|
encode_path(ebml_w, path, ast_map::path_name(item.ident));
|
2012-07-11 12:28:30 -05:00
|
|
|
encode_region_param(ecx, ebml_w, item);
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-07-11 12:28:30 -05:00
|
|
|
item_enum(variants, tps) {
|
2012-03-22 20:03:12 -05:00
|
|
|
add_to_index();
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(tag_items_data_item) {
|
2012-04-18 23:26:25 -05:00
|
|
|
encode_def_id(ebml_w, local_def(item.id));
|
|
|
|
encode_family(ebml_w, 't');
|
|
|
|
encode_type_param_bounds(ebml_w, ecx, tps);
|
|
|
|
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
|
|
|
|
encode_name(ebml_w, item.ident);
|
2012-06-30 18:19:07 -05:00
|
|
|
for variants.each |v| {
|
2012-04-18 23:26:25 -05:00
|
|
|
encode_variant_id(ebml_w, local_def(v.node.id));
|
|
|
|
}
|
2012-05-14 19:38:17 -05:00
|
|
|
ecx.encode_inlined_item(ecx, ebml_w, path, ii_item(item));
|
2012-04-18 23:26:25 -05:00
|
|
|
encode_path(ebml_w, path, ast_map::path_name(item.ident));
|
2012-07-11 12:28:30 -05:00
|
|
|
encode_region_param(ecx, ebml_w, item);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
2012-02-10 08:01:32 -06:00
|
|
|
encode_enum_variant_info(ecx, ebml_w, item.id, variants,
|
|
|
|
path, index, tps);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-07-11 12:28:30 -05:00
|
|
|
item_class(tps, traits, items, ctor, m_dtor) {
|
2012-03-22 20:03:12 -05:00
|
|
|
/* First, encode the fields and methods
|
|
|
|
These come first because we need to write them to make
|
|
|
|
the index, and the index needs to be in the item for the
|
|
|
|
class itself */
|
2012-04-10 12:52:06 -05:00
|
|
|
let idx = encode_info_for_class(ecx, ebml_w, item.id, path, tps,
|
|
|
|
items, index);
|
2012-06-12 18:25:09 -05:00
|
|
|
/* Encode the dtor */
|
2012-06-30 18:19:07 -05:00
|
|
|
do option::iter(m_dtor) |dtor| {
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(*index, {val: dtor.node.id, pos: ebml_w.writer.tell()});
|
2012-06-10 02:49:59 -05:00
|
|
|
encode_info_for_fn(ecx, ebml_w, dtor.node.id, @(*item.ident
|
2012-07-14 00:57:48 -05:00
|
|
|
+ ~"_dtor"), path, if tps.len() > 0u {
|
2012-06-12 18:25:09 -05:00
|
|
|
some(ii_dtor(dtor, item.ident, tps,
|
|
|
|
local_def(item.id))) }
|
|
|
|
else { none }, tps, ast_util::dtor_dec());
|
|
|
|
}
|
|
|
|
|
2012-03-22 20:03:12 -05:00
|
|
|
/* Index the class*/
|
|
|
|
add_to_index();
|
|
|
|
/* Now, make an item for the class itself */
|
2012-03-16 21:19:37 -05:00
|
|
|
ebml_w.start_tag(tag_items_data_item);
|
2012-03-22 20:03:12 -05:00
|
|
|
encode_def_id(ebml_w, local_def(item.id));
|
2012-07-26 17:29:33 -05:00
|
|
|
|
|
|
|
alt ctor {
|
|
|
|
none {
|
|
|
|
encode_family(ebml_w, 'S');
|
|
|
|
}
|
|
|
|
some(_) {
|
|
|
|
encode_family(ebml_w, 'C');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-22 20:03:12 -05:00
|
|
|
encode_type_param_bounds(ebml_w, ecx, tps);
|
|
|
|
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
|
|
|
|
encode_name(ebml_w, item.ident);
|
|
|
|
encode_path(ebml_w, path, ast_map::path_name(item.ident));
|
2012-07-11 12:28:30 -05:00
|
|
|
encode_region_param(ecx, ebml_w, item);
|
2012-07-03 18:30:42 -05:00
|
|
|
for traits.each |t| {
|
|
|
|
encode_trait_ref(ebml_w, ecx, t);
|
2012-04-26 14:15:46 -05:00
|
|
|
}
|
2012-06-12 18:25:09 -05:00
|
|
|
/* Encode the dtor */
|
|
|
|
/* Encode id for dtor */
|
2012-06-30 18:19:07 -05:00
|
|
|
do option::iter(m_dtor) |dtor| {
|
2012-07-04 14:04:28 -05:00
|
|
|
do ebml_w.wr_tag(tag_item_dtor) {
|
2012-06-12 18:25:09 -05:00
|
|
|
encode_def_id(ebml_w, local_def(dtor.node.id));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-22 20:03:12 -05:00
|
|
|
/* Encode def_ids for each field and method
|
2012-07-03 18:30:42 -05:00
|
|
|
for methods, write all the stuff get_trait_method
|
2012-03-22 20:03:12 -05:00
|
|
|
needs to know*/
|
|
|
|
let (fs,ms) = ast_util::split_class_items(items);
|
2012-06-30 18:19:07 -05:00
|
|
|
for fs.each |f| {
|
2012-03-22 20:03:12 -05:00
|
|
|
ebml_w.start_tag(tag_item_field);
|
2012-05-08 09:06:24 -05:00
|
|
|
encode_visibility(ebml_w, f.vis);
|
2012-03-22 20:03:12 -05:00
|
|
|
encode_name(ebml_w, f.ident);
|
|
|
|
encode_def_id(ebml_w, local_def(f.id));
|
|
|
|
ebml_w.end_tag();
|
|
|
|
}
|
2012-06-30 18:19:07 -05:00
|
|
|
for ms.each |m| {
|
2012-05-08 09:06:24 -05:00
|
|
|
alt m.vis {
|
|
|
|
private { /* do nothing */ }
|
|
|
|
public {
|
2012-04-26 14:15:46 -05:00
|
|
|
/* Write the info that's needed when viewing this class
|
2012-07-03 18:30:42 -05:00
|
|
|
as a trait */
|
|
|
|
ebml_w.start_tag(tag_item_trait_method);
|
2012-03-26 11:59:59 -05:00
|
|
|
encode_family(ebml_w, purity_fn_family(m.decl.purity));
|
|
|
|
encode_name(ebml_w, m.ident);
|
2012-06-04 13:21:11 -05:00
|
|
|
encode_type_param_bounds(ebml_w, ecx, m.tps);
|
2012-03-26 11:59:59 -05:00
|
|
|
encode_type(ecx, ebml_w, node_id_to_type(tcx, m.id));
|
|
|
|
encode_def_id(ebml_w, local_def(m.id));
|
2012-07-31 18:32:37 -05:00
|
|
|
encode_self_type(ebml_w, m.self_ty.node);
|
2012-03-26 11:59:59 -05:00
|
|
|
ebml_w.end_tag();
|
2012-04-26 14:15:46 -05:00
|
|
|
/* Write the info that's needed when viewing this class
|
2012-07-31 18:32:37 -05:00
|
|
|
as an impl (just the method def_id and self type) */
|
2012-04-26 14:15:46 -05:00
|
|
|
ebml_w.start_tag(tag_item_impl_method);
|
|
|
|
ebml_w.writer.write(str::bytes(def_to_str(local_def(m.id))));
|
|
|
|
ebml_w.end_tag();
|
2012-03-26 11:59:59 -05:00
|
|
|
}
|
|
|
|
}
|
2012-03-22 20:03:12 -05:00
|
|
|
}
|
|
|
|
/* Each class has its own index -- encode it */
|
2012-03-19 12:19:00 -05:00
|
|
|
let bkts = create_index(idx, hash_node_id);
|
|
|
|
encode_index(ebml_w, bkts, write_int);
|
2012-03-16 21:19:37 -05:00
|
|
|
ebml_w.end_tag();
|
2012-01-31 21:30:40 -06:00
|
|
|
}
|
2012-07-18 11:31:53 -05:00
|
|
|
item_impl(tps, traits, _, methods) {
|
2012-03-22 20:03:12 -05:00
|
|
|
add_to_index();
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_items_data_item);
|
2011-12-16 07:17:52 -06:00
|
|
|
encode_def_id(ebml_w, local_def(item.id));
|
2012-02-13 13:55:23 -06:00
|
|
|
encode_family(ebml_w, 'i');
|
2012-07-11 12:28:30 -05:00
|
|
|
encode_region_param(ecx, ebml_w, item);
|
2011-12-28 10:50:12 -06:00
|
|
|
encode_type_param_bounds(ebml_w, ecx, tps);
|
2012-01-30 10:28:30 -06:00
|
|
|
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
|
2011-12-16 07:41:12 -06:00
|
|
|
encode_name(ebml_w, item.ident);
|
2012-07-24 19:06:32 -05:00
|
|
|
encode_attributes(ebml_w, item.attrs);
|
2012-06-30 18:19:07 -05:00
|
|
|
for methods.each |m| {
|
2012-04-26 14:15:46 -05:00
|
|
|
ebml_w.start_tag(tag_item_impl_method);
|
2011-12-22 10:49:54 -06:00
|
|
|
ebml_w.writer.write(str::bytes(def_to_str(local_def(m.id))));
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-12-16 07:17:52 -06:00
|
|
|
}
|
2012-07-18 11:31:53 -05:00
|
|
|
if traits.len() > 1 {
|
|
|
|
fail ~"multiple traits!!";
|
|
|
|
}
|
|
|
|
for traits.each |associated_trait| {
|
|
|
|
encode_trait_ref(ebml_w, ecx, associated_trait)
|
|
|
|
}
|
2012-02-10 08:01:32 -06:00
|
|
|
encode_path(ebml_w, path, ast_map::path_name(item.ident));
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-12-16 07:17:52 -06:00
|
|
|
|
2012-06-28 17:00:03 -05:00
|
|
|
let impl_path = vec::append_one(path,
|
|
|
|
ast_map::path_name(item.ident));
|
2012-06-30 18:19:07 -05:00
|
|
|
for methods.each |m| {
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(*index, {val: m.id, pos: ebml_w.writer.tell()});
|
2012-03-19 12:19:00 -05:00
|
|
|
encode_info_for_method(ecx, ebml_w, impl_path,
|
2012-06-28 17:00:03 -05:00
|
|
|
should_inline(m.attrs), item.id, m,
|
|
|
|
vec::append(tps, m.tps));
|
2011-12-16 07:17:52 -06:00
|
|
|
}
|
|
|
|
}
|
2012-07-11 12:28:30 -05:00
|
|
|
item_trait(tps, ms) {
|
2012-03-22 20:03:12 -05:00
|
|
|
add_to_index();
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_items_data_item);
|
2012-01-05 06:57:27 -06:00
|
|
|
encode_def_id(ebml_w, local_def(item.id));
|
2012-02-13 13:55:23 -06:00
|
|
|
encode_family(ebml_w, 'I');
|
2012-07-11 12:28:30 -05:00
|
|
|
encode_region_param(ecx, ebml_w, item);
|
2012-01-05 06:57:27 -06:00
|
|
|
encode_type_param_bounds(ebml_w, ecx, tps);
|
2012-01-30 10:28:30 -06:00
|
|
|
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
|
2012-01-05 06:57:27 -06:00
|
|
|
encode_name(ebml_w, item.ident);
|
2012-07-25 20:36:18 -05:00
|
|
|
encode_attributes(ebml_w, item.attrs);
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut i = 0u;
|
2012-07-03 18:30:42 -05:00
|
|
|
for vec::each(*ty::trait_methods(tcx, local_def(item.id))) |mty| {
|
2012-07-10 15:44:20 -05:00
|
|
|
alt ms[i] {
|
|
|
|
required(ty_m) {
|
|
|
|
ebml_w.start_tag(tag_item_trait_method);
|
|
|
|
encode_name(ebml_w, mty.ident);
|
|
|
|
encode_type_param_bounds(ebml_w, ecx, ty_m.tps);
|
|
|
|
encode_type(ecx, ebml_w, ty::mk_fn(tcx, mty.fty));
|
|
|
|
encode_family(ebml_w, purity_fn_family(mty.purity));
|
2012-07-31 18:32:37 -05:00
|
|
|
encode_self_type(ebml_w, mty.self_ty);
|
2012-07-10 15:44:20 -05:00
|
|
|
ebml_w.end_tag();
|
|
|
|
}
|
|
|
|
provided(m) {
|
|
|
|
encode_info_for_method(ecx, ebml_w, path,
|
|
|
|
should_inline(m.attrs), item.id,
|
|
|
|
m, m.tps);
|
|
|
|
}
|
|
|
|
}
|
2012-01-05 06:57:27 -06:00
|
|
|
i += 1u;
|
|
|
|
}
|
2012-02-10 08:01:32 -06:00
|
|
|
encode_path(ebml_w, path, ast_map::path_name(item.ident));
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2012-01-05 06:57:27 -06:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
item_mac(*) { fail ~"item macros unimplemented" }
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-26 18:18:37 -05:00
|
|
|
fn encode_info_for_foreign_item(ecx: @encode_ctxt, ebml_w: ebml::writer,
|
|
|
|
nitem: @foreign_item,
|
2012-06-29 18:26:56 -05:00
|
|
|
index: @mut ~[entry<int>],
|
2012-06-26 18:18:37 -05:00
|
|
|
path: ast_map::path, abi: foreign_abi) {
|
2012-08-01 19:30:05 -05:00
|
|
|
if !reachable(ecx, nitem.id) { return; }
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(*index, {val: nitem.id, pos: ebml_w.writer.tell()});
|
2012-03-08 16:37:45 -06:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_items_data_item);
|
2011-07-27 07:19:39 -05:00
|
|
|
alt nitem.node {
|
2012-06-26 18:18:37 -05:00
|
|
|
foreign_item_fn(fn_decl, tps) {
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(nitem.id));
|
2012-02-13 13:55:23 -06:00
|
|
|
encode_family(ebml_w, purity_fn_family(fn_decl.purity));
|
2011-12-28 10:50:12 -06:00
|
|
|
encode_type_param_bounds(ebml_w, ecx, tps);
|
2012-05-13 19:01:52 -05:00
|
|
|
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, nitem.id));
|
2012-06-26 18:18:37 -05:00
|
|
|
if abi == foreign_abi_rust_intrinsic {
|
2012-05-14 19:38:17 -05:00
|
|
|
ecx.encode_inlined_item(ecx, ebml_w, path,
|
2012-06-26 18:18:37 -05:00
|
|
|
ii_foreign(nitem));
|
2012-03-21 09:42:20 -05:00
|
|
|
} else {
|
|
|
|
encode_symbol(ecx, ebml_w, nitem.id);
|
|
|
|
}
|
2012-02-10 08:01:32 -06:00
|
|
|
encode_path(ebml_w, path, ast_map::path_name(nitem.ident));
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2011-12-16 07:41:12 -06:00
|
|
|
fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::writer,
|
2012-06-29 18:26:56 -05:00
|
|
|
crate: @crate) -> ~[entry<int>] {
|
|
|
|
let index = @mut ~[];
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_items_data);
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(*index, {val: crate_node_id, pos: ebml_w.writer.tell()});
|
2012-03-08 16:37:45 -06:00
|
|
|
encode_info_for_mod(ecx, ebml_w, crate.node.module,
|
2012-07-14 00:57:48 -05:00
|
|
|
crate_node_id, ~[], @~"");
|
2012-03-08 16:37:45 -06:00
|
|
|
visit::visit_crate(*crate, (), visit::mk_vt(@{
|
2012-06-30 18:19:07 -05:00
|
|
|
visit_expr: |_e, _cx, _v| { },
|
|
|
|
visit_item: |i, cx, v, copy ebml_w| {
|
2012-03-08 16:37:45 -06:00
|
|
|
visit::visit_item(i, cx, v);
|
2012-05-13 19:01:52 -05:00
|
|
|
alt check ecx.tcx.items.get(i.id) {
|
2012-03-09 06:35:20 -06:00
|
|
|
ast_map::node_item(_, pt) {
|
|
|
|
encode_info_for_item(ecx, ebml_w, i, index, *pt);
|
2012-03-16 21:19:37 -05:00
|
|
|
/* encode ctor, then encode items */
|
|
|
|
alt i.node {
|
2012-07-24 17:29:14 -05:00
|
|
|
item_class(tps, _, _, some(ctor), m_dtor) {
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"encoding info for ctor %s %d", *i.ident,
|
|
|
|
ctor.node.id};
|
2012-07-24 17:29:14 -05:00
|
|
|
vec::push(*index, {
|
|
|
|
val: ctor.node.id,
|
|
|
|
pos: ebml_w.writer.tell()
|
|
|
|
});
|
|
|
|
encode_info_for_fn(ecx, ebml_w, ctor.node.id, i.ident,
|
|
|
|
*pt, if tps.len() > 0u {
|
|
|
|
some(ii_ctor(ctor, i.ident, tps,
|
|
|
|
local_def(i.id))) }
|
|
|
|
else { none }, tps, ctor.node.dec);
|
|
|
|
}
|
|
|
|
_ {}
|
2012-03-20 21:06:04 -05:00
|
|
|
}
|
|
|
|
}
|
2012-03-06 10:02:13 -06:00
|
|
|
}
|
2012-03-08 16:37:45 -06:00
|
|
|
},
|
2012-06-30 18:19:07 -05:00
|
|
|
visit_foreign_item: |ni, cx, v, copy ebml_w| {
|
2012-06-26 18:18:37 -05:00
|
|
|
visit::visit_foreign_item(ni, cx, v);
|
2012-05-13 19:01:52 -05:00
|
|
|
alt check ecx.tcx.items.get(ni.id) {
|
2012-06-26 18:18:37 -05:00
|
|
|
ast_map::node_foreign_item(_, abi, pt) {
|
|
|
|
encode_info_for_foreign_item(ecx, ebml_w, ni,
|
|
|
|
index, *pt, abi);
|
2012-03-09 06:35:20 -06:00
|
|
|
}
|
|
|
|
}
|
2012-03-08 16:37:45 -06:00
|
|
|
}
|
|
|
|
with *visit::default_visitor()
|
|
|
|
}));
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2012-08-01 19:30:05 -05:00
|
|
|
return *index;
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Path and definition ID indexing
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn create_index<T: copy>(index: ~[entry<T>], hash_fn: fn@(T) -> uint) ->
|
|
|
|
~[@~[entry<T>]] {
|
|
|
|
let mut buckets: ~[@mut ~[entry<T>]] = ~[];
|
2012-06-30 18:19:07 -05:00
|
|
|
for uint::range(0u, 256u) |_i| { vec::push(buckets, @mut ~[]); };
|
|
|
|
for index.each |elt| {
|
2011-07-27 07:19:39 -05:00
|
|
|
let h = hash_fn(elt.val);
|
2012-06-25 22:00:46 -05:00
|
|
|
vec::push(*buckets[h % 256u], elt);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
2011-07-14 16:25:43 -05:00
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut buckets_frozen = ~[];
|
2012-06-30 18:19:07 -05:00
|
|
|
for buckets.each |bucket| {
|
2012-06-25 22:00:46 -05:00
|
|
|
vec::push(buckets_frozen, @*bucket);
|
2011-07-14 16:25:43 -05:00
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
return buckets_frozen;
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn encode_index<T>(ebml_w: ebml::writer, buckets: ~[@~[entry<T>]],
|
2012-01-23 16:59:00 -06:00
|
|
|
write_fn: fn(io::writer, T)) {
|
2012-01-11 14:52:25 -06:00
|
|
|
let writer = ebml_w.writer;
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_index);
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut bucket_locs: ~[uint] = ~[];
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_index_buckets);
|
2012-06-30 18:19:07 -05:00
|
|
|
for buckets.each |bucket| {
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(bucket_locs, ebml_w.writer.tell());
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_index_buckets_bucket);
|
2012-06-30 18:19:07 -05:00
|
|
|
for vec::each(*bucket) |elt| {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_index_buckets_bucket_elt);
|
2011-07-26 07:06:02 -05:00
|
|
|
writer.write_be_uint(elt.pos, 4u);
|
|
|
|
write_fn(writer, elt.val);
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
|
|
|
ebml_w.start_tag(tag_index_table);
|
2012-06-30 18:19:07 -05:00
|
|
|
for bucket_locs.each |pos| { writer.write_be_uint(pos, 4u); }
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
|
|
|
ebml_w.end_tag();
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn write_str(writer: io::writer, &&s: ~str) { writer.write_str(s); }
|
2011-06-27 17:20:17 -05:00
|
|
|
|
2011-10-06 05:26:12 -05:00
|
|
|
fn write_int(writer: io::writer, &&n: int) {
|
2011-06-27 17:20:17 -05:00
|
|
|
writer.write_be_uint(n as uint, 4u);
|
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn encode_meta_item(ebml_w: ebml::writer, mi: meta_item) {
|
2011-07-27 07:19:39 -05:00
|
|
|
alt mi.node {
|
|
|
|
meta_word(name) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_meta_item_word);
|
|
|
|
ebml_w.start_tag(tag_meta_item_name);
|
2012-06-10 02:49:59 -05:00
|
|
|
ebml_w.writer.write(str::bytes(*name));
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
|
|
|
ebml_w.end_tag();
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
meta_name_value(name, value) {
|
|
|
|
alt value.node {
|
2011-09-02 00:08:59 -05:00
|
|
|
lit_str(value) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_meta_item_name_value);
|
|
|
|
ebml_w.start_tag(tag_meta_item_name);
|
2012-06-10 02:49:59 -05:00
|
|
|
ebml_w.writer.write(str::bytes(*name));
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
|
|
|
ebml_w.start_tag(tag_meta_item_value);
|
2012-06-10 02:49:59 -05:00
|
|
|
ebml_w.writer.write(str::bytes(*value));
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
|
|
|
ebml_w.end_tag();
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-05-17 18:17:11 -05:00
|
|
|
_ {/* FIXME (#623): encode other variants */ }
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
meta_list(name, items) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_meta_item_list);
|
|
|
|
ebml_w.start_tag(tag_meta_item_name);
|
2012-06-10 02:49:59 -05:00
|
|
|
ebml_w.writer.write(str::bytes(*name));
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2012-06-30 18:19:07 -05:00
|
|
|
for items.each |inner_item| {
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_meta_item(ebml_w, *inner_item);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-06-27 21:41:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn encode_attributes(ebml_w: ebml::writer, attrs: ~[attribute]) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_attributes);
|
2012-06-30 18:19:07 -05:00
|
|
|
for attrs.each |attr| {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_attribute);
|
2011-06-27 21:41:48 -05:00
|
|
|
encode_meta_item(ebml_w, attr.node.value);
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-06-27 21:41:48 -05:00
|
|
|
}
|
|
|
|
|
2011-06-29 17:11:20 -05:00
|
|
|
// So there's a special crate attribute called 'link' which defines the
|
|
|
|
// metadata that Rust cares about for linking crates. This attribute requires
|
2011-06-30 19:03:08 -05:00
|
|
|
// 'name' and 'vers' items, so if the user didn't provide them we will throw
|
2011-06-29 17:11:20 -05:00
|
|
|
// them in anyway with default values.
|
2012-06-29 18:26:56 -05:00
|
|
|
fn synthesize_crate_attrs(ecx: @encode_ctxt, crate: @crate) -> ~[attribute] {
|
2011-06-29 16:17:23 -05:00
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn synthesize_link_attr(ecx: @encode_ctxt, items: ~[@meta_item]) ->
|
2011-07-27 07:19:39 -05:00
|
|
|
attribute {
|
2011-06-29 16:17:23 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
assert (*ecx.link_meta.name != ~"");
|
|
|
|
assert (*ecx.link_meta.vers != ~"");
|
2011-06-29 16:17:23 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
let name_item =
|
2012-07-14 00:57:48 -05:00
|
|
|
attr::mk_name_value_item_str(@~"name", *ecx.link_meta.name);
|
2011-07-27 07:19:39 -05:00
|
|
|
let vers_item =
|
2012-07-14 00:57:48 -05:00
|
|
|
attr::mk_name_value_item_str(@~"vers", *ecx.link_meta.vers);
|
2011-06-29 16:17:23 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
let other_items =
|
|
|
|
{
|
2012-07-14 00:57:48 -05:00
|
|
|
let tmp = attr::remove_meta_items_by_name(items, @~"name");
|
|
|
|
attr::remove_meta_items_by_name(tmp, @~"vers")
|
2011-07-27 07:19:39 -05:00
|
|
|
};
|
2011-06-29 16:17:23 -05:00
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
let meta_items = vec::append(~[name_item, vers_item], other_items);
|
2012-07-14 00:57:48 -05:00
|
|
|
let link_item = attr::mk_list_item(@~"link", meta_items);
|
2011-06-29 16:17:23 -05:00
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
return attr::mk_attr(link_item);
|
2011-06-29 16:17:23 -05:00
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut attrs: ~[attribute] = ~[];
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut found_link_attr = false;
|
2012-06-30 18:19:07 -05:00
|
|
|
for crate.node.attrs.each |attr| {
|
2012-06-28 17:00:03 -05:00
|
|
|
vec::push(
|
|
|
|
attrs,
|
2012-07-14 00:57:48 -05:00
|
|
|
if *attr::get_attr_name(attr) != ~"link" {
|
2012-06-28 17:00:03 -05:00
|
|
|
attr
|
2011-07-27 07:19:39 -05:00
|
|
|
} else {
|
|
|
|
alt attr.node.value.node {
|
|
|
|
meta_list(n, l) {
|
2011-09-12 04:27:30 -05:00
|
|
|
found_link_attr = true;;
|
2012-06-28 17:00:03 -05:00
|
|
|
synthesize_link_attr(ecx, l)
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-06-28 17:00:03 -05:00
|
|
|
_ { attr }
|
2011-06-29 16:17:23 -05:00
|
|
|
}
|
2012-06-28 17:00:03 -05:00
|
|
|
});
|
2011-06-29 16:17:23 -05:00
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
if !found_link_attr { vec::push(attrs, synthesize_link_attr(ecx, ~[])); }
|
2011-06-29 16:17:23 -05:00
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
return attrs;
|
2011-06-29 16:17:23 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn encode_crate_deps(ebml_w: ebml::writer, cstore: cstore::cstore) {
|
2011-07-08 13:29:56 -05:00
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn get_ordered_deps(cstore: cstore::cstore) -> ~[decoder::crate_dep] {
|
2011-07-27 07:19:39 -05:00
|
|
|
type hashkv = @{key: crate_num, val: cstore::crate_metadata};
|
2012-04-07 12:59:37 -05:00
|
|
|
type numdep = decoder::crate_dep;
|
2011-07-08 13:29:56 -05:00
|
|
|
|
2012-04-07 12:59:37 -05:00
|
|
|
// Pull the cnums and name,vers,hash out of cstore
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut deps: ~[mut numdep] = ~[mut];
|
2012-06-30 18:19:07 -05:00
|
|
|
do cstore::iter_crate_data(cstore) |key, val| {
|
2012-06-10 02:49:59 -05:00
|
|
|
let dep = {cnum: key, name: @val.name,
|
2012-04-07 12:59:37 -05:00
|
|
|
vers: decoder::get_crate_vers(val.data),
|
2012-06-10 02:49:59 -05:00
|
|
|
hash: decoder::get_crate_hash(val.data)};
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(deps, dep);
|
2011-10-21 05:21:27 -05:00
|
|
|
};
|
2011-07-08 13:29:56 -05:00
|
|
|
|
|
|
|
// Sort by cnum
|
2012-04-07 12:59:37 -05:00
|
|
|
fn lteq(kv1: numdep, kv2: numdep) -> bool { kv1.cnum <= kv2.cnum }
|
|
|
|
std::sort::quick_sort(lteq, deps);
|
2011-07-08 13:29:56 -05:00
|
|
|
|
|
|
|
// Sanity-check the crate numbers
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut expected_cnum = 1;
|
2012-06-30 18:19:07 -05:00
|
|
|
for deps.each |n| {
|
2012-04-07 12:59:37 -05:00
|
|
|
assert (n.cnum == expected_cnum);
|
2011-07-08 13:29:56 -05:00
|
|
|
expected_cnum += 1;
|
|
|
|
}
|
|
|
|
|
2012-03-26 20:35:18 -05:00
|
|
|
// mut -> immutable hack for vec::map
|
2012-08-01 19:30:05 -05:00
|
|
|
return vec::slice(deps, 0u, vec::len(deps));
|
2011-07-08 13:29:56 -05:00
|
|
|
}
|
|
|
|
|
2012-04-07 12:59:37 -05:00
|
|
|
// We're just going to write a list of crate 'name-hash-version's, with
|
|
|
|
// the assumption that they are numbered 1 to n.
|
2012-06-21 18:44:10 -05:00
|
|
|
// FIXME (#2166): This is not nearly enough to support correct versioning
|
2011-07-08 13:29:56 -05:00
|
|
|
// but is enough to get transitive crate dependencies working.
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_crate_deps);
|
2012-06-30 18:19:07 -05:00
|
|
|
for get_ordered_deps(cstore).each |dep| {
|
2012-04-07 12:59:37 -05:00
|
|
|
encode_crate_dep(ebml_w, dep);
|
2011-07-08 13:29:56 -05:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-07-08 13:29:56 -05:00
|
|
|
}
|
|
|
|
|
2012-04-07 12:59:37 -05:00
|
|
|
fn encode_crate_dep(ebml_w: ebml::writer, dep: decoder::crate_dep) {
|
|
|
|
ebml_w.start_tag(tag_crate_dep);
|
|
|
|
ebml_w.start_tag(tag_crate_dep_name);
|
2012-06-10 02:49:59 -05:00
|
|
|
ebml_w.writer.write(str::bytes(*dep.name));
|
2012-04-07 12:59:37 -05:00
|
|
|
ebml_w.end_tag();
|
|
|
|
ebml_w.start_tag(tag_crate_dep_vers);
|
2012-06-10 02:49:59 -05:00
|
|
|
ebml_w.writer.write(str::bytes(*dep.vers));
|
2012-04-07 12:59:37 -05:00
|
|
|
ebml_w.end_tag();
|
|
|
|
ebml_w.start_tag(tag_crate_dep_hash);
|
2012-06-10 02:49:59 -05:00
|
|
|
ebml_w.writer.write(str::bytes(*dep.hash));
|
2012-04-07 12:59:37 -05:00
|
|
|
ebml_w.end_tag();
|
|
|
|
ebml_w.end_tag();
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn encode_hash(ebml_w: ebml::writer, hash: ~str) {
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_crate_hash);
|
2011-12-11 09:23:38 -06:00
|
|
|
ebml_w.writer.write(str::bytes(hash));
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-12-11 09:23:38 -06:00
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn encode_metadata(parms: encode_parms, crate: @crate) -> ~[u8] {
|
2012-05-14 19:38:17 -05:00
|
|
|
let ecx: @encode_ctxt = @encode_ctxt({
|
2012-05-14 22:41:33 -05:00
|
|
|
diag: parms.diag,
|
2012-05-13 19:01:52 -05:00
|
|
|
tcx: parms.tcx,
|
|
|
|
reachable: parms.reachable,
|
2012-05-16 23:50:17 -05:00
|
|
|
reexports: parms.reexports,
|
2012-05-14 19:46:45 -05:00
|
|
|
impl_map: parms.impl_map,
|
2012-05-13 19:01:52 -05:00
|
|
|
item_symbols: parms.item_symbols,
|
|
|
|
discrim_symbols: parms.discrim_symbols,
|
|
|
|
link_meta: parms.link_meta,
|
|
|
|
cstore: parms.cstore,
|
2012-05-14 19:38:17 -05:00
|
|
|
encode_inlined_item: parms.encode_inlined_item,
|
2012-05-13 19:01:52 -05:00
|
|
|
type_abbrevs: ty::new_ty_hash()
|
2012-05-14 19:38:17 -05:00
|
|
|
});
|
2011-07-08 01:55:41 -05:00
|
|
|
|
2012-03-13 09:55:45 -05:00
|
|
|
let buf = io::mem_buffer();
|
2012-01-11 08:15:54 -06:00
|
|
|
let buf_w = io::mem_buffer_writer(buf);
|
2012-03-12 17:52:30 -05:00
|
|
|
let ebml_w = ebml::writer(buf_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
|
2012-05-13 19:01:52 -05:00
|
|
|
encode_hash(ebml_w, ecx.link_meta.extras_hash);
|
2011-12-11 09:23:38 -06:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
let crate_attrs = synthesize_crate_attrs(ecx, crate);
|
2011-06-29 16:17:23 -05:00
|
|
|
encode_attributes(ebml_w, crate_attrs);
|
2011-07-08 13:29:56 -05:00
|
|
|
|
2012-05-13 19:01:52 -05:00
|
|
|
encode_crate_deps(ebml_w, ecx.cstore);
|
2011-07-08 13:29:56 -05:00
|
|
|
|
2011-06-27 17:20:17 -05:00
|
|
|
// Encode and index the paths.
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_paths);
|
2011-12-15 04:42:27 -06:00
|
|
|
let paths_index = encode_item_paths(ebml_w, ecx, crate);
|
2011-07-27 07:19:39 -05:00
|
|
|
let paths_buckets = create_index(paths_index, hash_path);
|
2011-07-25 08:07:48 -05:00
|
|
|
encode_index(ebml_w, paths_buckets, write_str);
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2011-06-27 17:20:17 -05:00
|
|
|
|
2012-01-11 08:15:54 -06:00
|
|
|
// Encode and index the items.
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.start_tag(tag_items);
|
2012-03-08 16:37:45 -06:00
|
|
|
let items_index = encode_info_for_items(ecx, ebml_w, crate);
|
2011-07-27 07:19:39 -05:00
|
|
|
let items_buckets = create_index(items_index, hash_node_id);
|
2011-07-25 08:07:48 -05:00
|
|
|
encode_index(ebml_w, items_buckets, write_int);
|
2012-02-14 17:21:53 -06:00
|
|
|
ebml_w.end_tag();
|
2012-01-11 08:15:54 -06:00
|
|
|
|
2011-06-27 17:20:17 -05:00
|
|
|
// Pad this, since something (LLVM, presumably) is cutting off the
|
2011-08-11 18:36:20 -05:00
|
|
|
// remaining % 4 bytes.
|
2012-06-29 18:26:56 -05:00
|
|
|
buf_w.write(&[0u8, 0u8, 0u8, 0u8]);
|
2012-01-26 00:27:29 -06:00
|
|
|
io::mem_buffer_buf(buf)
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
2011-06-27 21:16:16 -05:00
|
|
|
|
2011-07-07 14:47:39 -05:00
|
|
|
// Get the encoded string for a type
|
2012-07-14 00:57:48 -05:00
|
|
|
fn encoded_ty(tcx: ty::ctxt, t: ty::t) -> ~str {
|
2012-05-14 22:41:33 -05:00
|
|
|
let cx = @{diag: tcx.diag,
|
|
|
|
ds: def_to_str,
|
2012-03-22 22:06:01 -05:00
|
|
|
tcx: tcx,
|
2012-06-30 18:19:07 -05:00
|
|
|
reachable: |_id| false,
|
2012-03-22 22:06:01 -05:00
|
|
|
abbrevs: tyencode::ac_no_abbrevs};
|
2012-03-13 09:55:45 -05:00
|
|
|
let buf = io::mem_buffer();
|
2012-01-11 08:15:54 -06:00
|
|
|
tyencode::enc_ty(io::mem_buffer_writer(buf), cx, t);
|
2012-08-01 19:30:05 -05:00
|
|
|
return io::mem_buffer_str(buf);
|
2011-07-07 14:47:39 -05:00
|
|
|
}
|
|
|
|
|
2011-06-27 21:16:16 -05:00
|
|
|
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|