rustc: Move much of metadata reading over to interior vectors

This commit is contained in:
Patrick Walton 2011-07-12 10:59:18 -07:00
parent 4664b67ea2
commit be489ee9e2
16 changed files with 337 additions and 336 deletions

View file

@ -27,7 +27,7 @@ import std::option::none;
import std::str;
import std::vec;
import std::int;
import std::io;
import std::ioivec;
import std::run;
import std::getopts;
import std::getopts::optopt;
@ -209,19 +209,19 @@ fn pretty_print_input(session::session sess, ast::crate_cfg cfg,
ann = pprust::no_ann();
}
}
pprust::print_crate(sess.get_codemap(), crate, input,
std::io::stdout(), ann);
pprust::print_crate(sess.get_codemap(), crate, input, ioivec::stdout(),
ann);
}
fn version(str argv0) {
auto vers = "unknown version";
auto env_vers = #env("CFG_VERSION");
if (str::byte_len(env_vers) != 0u) { vers = env_vers; }
io::stdout().write_str(#fmt("%s %s\n", argv0, vers));
ioivec::stdout().write_str(#fmt("%s %s\n", argv0, vers));
}
fn usage(str argv0) {
io::stdout().write_str(#fmt("usage: %s [options] <input>\n", argv0) +
ioivec::stdout().write_str(#fmt("usage: %s [options] <input>\n", argv0) +
"
options:
@ -450,7 +450,7 @@ fn main(vec[str] args) {
case (none[pp_mode]) {/* continue */ }
}
if (ls) {
metadata::creader::list_file_metadata(ifile, std::io::stdout());
metadata::creader::list_file_metadata(ifile, ioivec::stdout());
ret;
}

View file

@ -5,7 +5,6 @@ import syntax::codemap;
import codemap::span;
import syntax::ast::ty_mach;
import std::uint;
import std::io;
import std::map;
import std::option;
import std::option::some;

View file

@ -15,9 +15,8 @@ import util::common;
import std::ivec;
import std::str;
import std::vec;
import std::ebml;
import std::fs;
import std::io;
import std::ioivec;
import std::option;
import std::option::none;
import std::option::some;
@ -88,7 +87,7 @@ fn visit_item(env e, &@ast::item i) {
}
// A diagnostic function for dumping crate metadata to an output stream
fn list_file_metadata(str path, io::writer out) {
fn list_file_metadata(str path, ioivec::writer out) {
alt (get_metadata_section(path)) {
case (option::some(?bytes)) {
decoder::list_crate_metadata(bytes, out);
@ -99,8 +98,7 @@ fn list_file_metadata(str path, io::writer out) {
}
}
fn metadata_matches(&vec[u8] crate_data,
&(@ast::meta_item)[] metas) -> bool {
fn metadata_matches(&@u8[] crate_data, &(@ast::meta_item)[] metas) -> bool {
auto attrs = decoder::get_crate_attributes(crate_data);
auto linkage_metas = attr::find_linkage_metas(attrs);
@ -130,8 +128,8 @@ fn default_native_lib_naming(session::session sess, bool static) ->
fn find_library_crate(&session::session sess, &ast::ident ident,
&(@ast::meta_item)[] metas,
&vec[str] library_search_paths) ->
option::t[tup(str, vec[u8])] {
&vec[str] library_search_paths)
-> option::t[tup(str, @u8[])] {
attr::require_unique_names(sess, metas);
@ -165,7 +163,7 @@ fn find_library_crate(&session::session sess, &ast::ident ident,
fn find_library_crate_aux(&rec(str prefix, str suffix) nn, str crate_name,
&(@ast::meta_item)[] metas,
&vec[str] library_search_paths) ->
option::t[tup(str, vec[u8])] {
option::t[tup(str, @u8[])] {
let str prefix = nn.prefix + crate_name;
// FIXME: we could probably use a 'glob' function in std::fs but it will
// be much easier to write once the unsafe module knows more about FFI
@ -200,10 +198,10 @@ fn find_library_crate_aux(&rec(str prefix, str suffix) nn, str crate_name,
ret none;
}
fn get_metadata_section(str filename) -> option::t[vec[u8]] {
fn get_metadata_section(str filename) -> option::t[@u8[]] {
auto b = str::buf(filename);
auto mb = llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(b);
if (mb as int == 0) { ret option::none[vec[u8]]; }
if (mb as int == 0) { ret option::none[@u8[]]; }
auto of = mk_object_file(mb);
auto si = mk_section_iter(of.llof);
while (llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False) {
@ -212,18 +210,17 @@ fn get_metadata_section(str filename) -> option::t[vec[u8]] {
if (str::eq(name, x86::get_meta_sect_name())) {
auto cbuf = llvm::LLVMGetSectionContents(si.llsi);
auto csz = llvm::LLVMGetSectionSize(si.llsi);
auto cvbuf = cbuf as vec::vbuf;
ret option::some[vec[u8]](vec::vec_from_vbuf[u8](cvbuf, csz));
let *u8 cvbuf = std::unsafe::reinterpret_cast(cbuf);
ret option::some[@u8[]](@ivec::unsafe::from_buf(cvbuf, csz));
}
llvm::LLVMMoveToNextSection(si.llsi);
}
ret option::none[vec[u8]];
ret option::none[@u8[]];
}
fn load_library_crate(&session::session sess, span span,
&ast::ident ident, &(@ast::meta_item)[] metas,
&vec[str] library_search_paths)
-> tup(str, vec[u8]) {
&vec[str] library_search_paths) -> tup(str, @u8[]) {
alt (find_library_crate(sess, ident, metas, library_search_paths)) {
case (some(?t)) {
@ -266,7 +263,7 @@ fn resolve_crate(env e, ast::ident ident, (@ast::meta_item)[] metas,
}
// Go through the crate metadata and load any crates that it references
fn resolve_crate_deps(env e, &vec[u8] cdata) -> cstore::cnum_map {
fn resolve_crate_deps(env e, &@u8[] cdata) -> cstore::cnum_map {
log "resolving deps of external crate";
// The map from crate numbers in the crate we're resolving to local crate
// numbers

View file

@ -2,7 +2,6 @@
import syntax::ast;
import middle::ty;
import std::io;
import std::option;
import driver::session;

View file

@ -29,9 +29,7 @@ export get_use_stmt_cnum;
// own crate numbers.
type cnum_map = map::hashmap[ast::crate_num, ast::crate_num];
type crate_metadata = rec(str name,
vec[u8] data,
cnum_map cnum_map);
type crate_metadata = rec(str name, @u8[] data, cnum_map cnum_map);
// This is a bit of an experiment at encapsulating the data in cstore. By
// keeping all the data in a non-exported tag variant, it's impossible for

View file

@ -1,11 +1,11 @@
// Decoding metadata from a single crate's metadata
import std::ebml;
import std::ebmlivec;
import std::ivec;
import std::option;
import std::vec;
import std::str;
import std::io;
import std::ioivec;
import std::map::hashmap;
import syntax::ast;
import front::attr;
@ -35,69 +35,69 @@ export external_resolver;
// build.
type external_resolver = fn(&ast::def_id def_id) -> ast::def_id;
fn lookup_hash(&ebml::doc d, fn(vec[u8]) -> bool eq_fn, uint hash) ->
vec[ebml::doc] {
auto index = ebml::get_doc(d, tag_index);
auto table = ebml::get_doc(index, tag_index_table);
fn lookup_hash(&ebmlivec::doc d, fn(&u8[]) -> bool eq_fn, uint hash) ->
(ebmlivec::doc)[] {
auto index = ebmlivec::get_doc(d, tag_index);
auto table = ebmlivec::get_doc(index, tag_index_table);
auto hash_pos = table.start + hash % 256u * 4u;
auto pos = ebml::be_uint_from_bytes(d.data, hash_pos, 4u);
auto bucket = ebml::doc_at(d.data, pos);
auto pos = ebmlivec::be_uint_from_bytes(d.data, hash_pos, 4u);
auto bucket = ebmlivec::doc_at(d.data, pos);
// Awkward logic because we can't ret from foreach yet
let vec[ebml::doc] result = [];
let (ebmlivec::doc)[] result = ~[];
auto belt = tag_index_buckets_bucket_elt;
for each (ebml::doc elt in ebml::tagged_docs(bucket, belt)) {
auto pos = ebml::be_uint_from_bytes(elt.data, elt.start, 4u);
if (eq_fn(vec::slice[u8](elt.data, elt.start + 4u, elt.end))) {
vec::push(result, ebml::doc_at(d.data, pos));
for each (ebmlivec::doc elt in ebmlivec::tagged_docs(bucket, belt)) {
auto pos = ebmlivec::be_uint_from_bytes(elt.data, elt.start, 4u);
if (eq_fn(ivec::slice[u8](*elt.data, elt.start + 4u, elt.end))) {
result += ~[ebmlivec::doc_at(d.data, pos)];
}
}
ret result;
}
fn maybe_find_item(int item_id, &ebml::doc items) -> option::t[ebml::doc] {
fn eq_item(vec[u8] bytes, int item_id) -> bool {
ret ebml::be_uint_from_bytes(bytes, 0u, 4u) as int == item_id;
fn maybe_find_item(int item_id, &ebmlivec::doc items) -> option::t[ebmlivec::doc] {
fn eq_item(&u8[] bytes, int item_id) -> bool {
ret ebmlivec::be_uint_from_bytes(@bytes, 0u, 4u) as int == item_id;
}
auto eqer = bind eq_item(_, item_id);
auto found = lookup_hash(items, eqer, hash_node_id(item_id));
if (vec::len(found) == 0u) {
ret option::none[ebml::doc];
} else { ret option::some[ebml::doc](found.(0)); }
if (ivec::len(found) == 0u) {
ret option::none[ebmlivec::doc];
} else { ret option::some[ebmlivec::doc](found.(0)); }
}
fn find_item(int item_id, &ebml::doc items) -> ebml::doc {
fn find_item(int item_id, &ebmlivec::doc items) -> ebmlivec::doc {
ret option::get(maybe_find_item(item_id, items));
}
// Looks up an item in the given metadata and returns an ebml doc pointing
// Looks up an item in the given metadata and returns an ebmlivec doc pointing
// to the item data.
fn lookup_item(int item_id, vec[u8] data) -> ebml::doc {
auto items = ebml::get_doc(ebml::new_doc(data), tag_items);
fn lookup_item(int item_id, &@u8[] data) -> ebmlivec::doc {
auto items = ebmlivec::get_doc(ebmlivec::new_doc(data), tag_items);
ret find_item(item_id, items);
}
fn item_kind(&ebml::doc item) -> u8 {
auto kind = ebml::get_doc(item, tag_items_data_item_kind);
ret ebml::doc_as_uint(kind) as u8;
fn item_kind(&ebmlivec::doc item) -> u8 {
auto kind = ebmlivec::get_doc(item, tag_items_data_item_kind);
ret ebmlivec::doc_as_uint(kind) as u8;
}
fn item_symbol(&ebml::doc item) -> str {
auto sym = ebml::get_doc(item, tag_items_data_item_symbol);
ret str::unsafe_from_bytes(ebml::doc_data(sym));
fn item_symbol(&ebmlivec::doc item) -> str {
auto sym = ebmlivec::get_doc(item, tag_items_data_item_symbol);
ret str::unsafe_from_bytes_ivec(ebmlivec::doc_data(sym));
}
fn variant_tag_id(&ebml::doc d) -> ast::def_id {
auto tagdoc = ebml::get_doc(d, tag_items_data_item_tag_id);
ret parse_def_id(ebml::doc_data(tagdoc));
fn variant_tag_id(&ebmlivec::doc d) -> ast::def_id {
auto tagdoc = ebmlivec::get_doc(d, tag_items_data_item_tag_id);
ret parse_def_id(ebmlivec::doc_data(tagdoc));
}
fn item_type(&ebml::doc item, ast::crate_num this_cnum,
fn item_type(&ebmlivec::doc item, ast::crate_num this_cnum,
ty::ctxt tcx, &external_resolver extres) -> ty::t {
fn parse_external_def_id(ast::crate_num this_cnum,
&external_resolver extres,
str s) -> ast::def_id {
auto buf = str::bytes(s);
auto buf = str::bytes_ivec(s);
auto external_def_id = parse_def_id(buf);
// This item was defined in the crate we're searching if it's has the
@ -108,27 +108,27 @@ fn item_type(&ebml::doc item, ast::crate_num this_cnum,
ret extres(external_def_id);
}
}
auto tp = ebml::get_doc(item, tag_items_data_item_type);
auto tp = ebmlivec::get_doc(item, tag_items_data_item_type);
auto def_parser = bind parse_external_def_id(this_cnum, extres, _);
ret parse_ty_data(item.data, this_cnum, tp.start, tp.end - tp.start,
def_parser, tcx);
}
fn item_ty_param_count(&ebml::doc item) -> uint {
fn item_ty_param_count(&ebmlivec::doc item) -> uint {
let uint ty_param_count = 0u;
auto tp = tag_items_data_item_ty_param_count;
for each (ebml::doc p in ebml::tagged_docs(item, tp)) {
ty_param_count = ebml::vint_at(ebml::doc_data(p), 0u)._0;
for each (ebmlivec::doc p in ebmlivec::tagged_docs(item, tp)) {
ty_param_count = ebmlivec::vint_at(ebmlivec::doc_data(p), 0u)._0;
}
ret ty_param_count;
}
fn tag_variant_ids(&ebml::doc item,
fn tag_variant_ids(&ebmlivec::doc item,
ast::crate_num this_cnum) -> vec[ast::def_id] {
let vec[ast::def_id] ids = [];
auto v = tag_items_data_item_variant;
for each (ebml::doc p in ebml::tagged_docs(item, v)) {
auto ext = parse_def_id(ebml::doc_data(p));
for each (ebmlivec::doc p in ebmlivec::tagged_docs(item, v)) {
auto ext = parse_def_id(ebmlivec::doc_data(p));
vec::push[ast::def_id](ids, tup(this_cnum, ext._1));
}
ret ids;
@ -136,32 +136,32 @@ fn tag_variant_ids(&ebml::doc item,
// Given a path and serialized crate metadata, returns the ID of the
// definition the path refers to.
fn resolve_path(vec[ast::ident] path, vec[u8] data) -> vec[ast::def_id] {
fn eq_item(vec[u8] data, str s) -> bool {
ret str::eq(str::unsafe_from_bytes(data), s);
fn resolve_path(vec[ast::ident] path, @u8[] data) -> vec[ast::def_id] {
fn eq_item(&u8[] data, str s) -> bool {
ret str::eq(str::unsafe_from_bytes_ivec(data), s);
}
auto s = str::connect(path, "::");
auto md = ebml::new_doc(data);
auto paths = ebml::get_doc(md, tag_paths);
auto md = ebmlivec::new_doc(data);
auto paths = ebmlivec::get_doc(md, tag_paths);
auto eqer = bind eq_item(_, s);
let vec[ast::def_id] result = [];
for (ebml::doc doc in lookup_hash(paths, eqer, hash_path(s))) {
auto did_doc = ebml::get_doc(doc, tag_def_id);
vec::push(result, parse_def_id(ebml::doc_data(did_doc)));
for (ebmlivec::doc doc in lookup_hash(paths, eqer, hash_path(s))) {
auto did_doc = ebmlivec::get_doc(doc, tag_def_id);
vec::push(result, parse_def_id(ebmlivec::doc_data(did_doc)));
}
ret result;
}
// Crate metadata queries
fn lookup_defs(&vec[u8] data, ast::crate_num cnum,
fn lookup_defs(&@u8[] data, ast::crate_num cnum,
vec[ast::ident] path) -> vec[ast::def] {
ret vec::map(bind lookup_def(cnum, data, _), resolve_path(path, data));
}
// FIXME doesn't yet handle re-exported externals
fn lookup_def(ast::crate_num cnum, vec[u8] data,
&ast::def_id did_) -> ast::def {
fn lookup_def(ast::crate_num cnum, @u8[] data, &ast::def_id did_)
-> ast::def {
auto item = lookup_item(did_._1, data);
auto kind_ch = item_kind(item);
auto did = tup(cnum, did_._1);
@ -186,7 +186,7 @@ fn lookup_def(ast::crate_num cnum, vec[u8] data,
ret def;
}
fn get_type(&vec[u8] data, ast::def_id def, &ty::ctxt tcx,
fn get_type(@u8[] data, ast::def_id def, &ty::ctxt tcx,
&external_resolver extres) -> ty::ty_param_count_and_ty {
auto this_cnum = def._0;
auto node_id = def._1;
@ -201,21 +201,21 @@ fn get_type(&vec[u8] data, ast::def_id def, &ty::ctxt tcx,
ret tup(tp_count, t);
}
fn get_type_param_count(&vec[u8] data, ast::node_id id) -> uint {
fn get_type_param_count(@u8[] data, ast::node_id id) -> uint {
ret item_ty_param_count(lookup_item(id, data));
}
fn get_symbol(&vec[u8] data, ast::node_id id) -> str {
fn get_symbol(@u8[] data, ast::node_id id) -> str {
ret item_symbol(lookup_item(id, data));
}
fn get_tag_variants(&vec[u8] data, ast::def_id def,
fn get_tag_variants(&@u8[] data, ast::def_id def,
&ty::ctxt tcx,
&external_resolver extres) -> ty::variant_info[] {
auto external_crate_id = def._0;
auto data = cstore::get_crate_data(tcx.sess.get_cstore(),
external_crate_id).data;
auto items = ebml::get_doc(ebml::new_doc(data), tag_items);
auto items = ebmlivec::get_doc(ebmlivec::new_doc(data), tag_items);
auto item = find_item(def._1, items);
let ty::variant_info[] infos = ~[];
auto variant_ids = tag_variant_ids(item, external_crate_id);
@ -252,15 +252,15 @@ fn kind_has_type_params(u8 kind_ch) -> bool {
};
}
fn read_path(&ebml::doc d) -> tup(str, uint) {
auto desc = ebml::doc_data(d);
auto pos = ebml::be_uint_from_bytes(desc, 0u, 4u);
auto pathbytes = vec::slice[u8](desc, 4u, vec::len[u8](desc));
auto path = str::unsafe_from_bytes(pathbytes);
fn read_path(&ebmlivec::doc d) -> tup(str, uint) {
auto desc = ebmlivec::doc_data(d);
auto pos = ebmlivec::be_uint_from_bytes(@desc, 0u, 4u);
auto pathbytes = ivec::slice[u8](desc, 4u, ivec::len[u8](desc));
auto path = str::unsafe_from_bytes_ivec(pathbytes);
ret tup(path, pos);
}
fn describe_def(&ebml::doc items, ast::def_id id) -> str {
fn describe_def(&ebmlivec::doc items, ast::def_id id) -> str {
if (id._0 != 0) { ret "external"; }
ret item_kind_to_str(item_kind(find_item(id._1, items)));
}
@ -280,40 +280,40 @@ fn item_kind_to_str(u8 kind) -> str {
}
}
fn get_meta_items(&ebml::doc md) -> (@ast::meta_item)[] {
fn get_meta_items(&ebmlivec::doc md) -> (@ast::meta_item)[] {
let (@ast::meta_item)[] items = ~[];
for each (ebml::doc meta_item_doc in
ebml::tagged_docs(md, tag_meta_item_word)) {
auto nd = ebml::get_doc(meta_item_doc, tag_meta_item_name);
auto n = str::unsafe_from_bytes(ebml::doc_data(nd));
for each (ebmlivec::doc meta_item_doc in
ebmlivec::tagged_docs(md, tag_meta_item_word)) {
auto nd = ebmlivec::get_doc(meta_item_doc, tag_meta_item_name);
auto n = str::unsafe_from_bytes_ivec(ebmlivec::doc_data(nd));
items += ~[attr::mk_word_item(n)];
}
for each (ebml::doc meta_item_doc in
ebml::tagged_docs(md, tag_meta_item_name_value)) {
auto nd = ebml::get_doc(meta_item_doc, tag_meta_item_name);
auto vd = ebml::get_doc(meta_item_doc, tag_meta_item_value);
auto n = str::unsafe_from_bytes(ebml::doc_data(nd));
auto v = str::unsafe_from_bytes(ebml::doc_data(vd));
for each (ebmlivec::doc meta_item_doc in
ebmlivec::tagged_docs(md, tag_meta_item_name_value)) {
auto nd = ebmlivec::get_doc(meta_item_doc, tag_meta_item_name);
auto vd = ebmlivec::get_doc(meta_item_doc, tag_meta_item_value);
auto n = str::unsafe_from_bytes_ivec(ebmlivec::doc_data(nd));
auto v = str::unsafe_from_bytes_ivec(ebmlivec::doc_data(vd));
// FIXME (#611): Should be able to decode meta_name_value variants,
// but currently they can't be encoded
items += ~[attr::mk_name_value_item_str(n, v)];
}
for each (ebml::doc meta_item_doc in
ebml::tagged_docs(md, tag_meta_item_list)) {
auto nd = ebml::get_doc(meta_item_doc, tag_meta_item_name);
auto n = str::unsafe_from_bytes(ebml::doc_data(nd));
for each (ebmlivec::doc meta_item_doc in
ebmlivec::tagged_docs(md, tag_meta_item_list)) {
auto nd = ebmlivec::get_doc(meta_item_doc, tag_meta_item_name);
auto n = str::unsafe_from_bytes_ivec(ebmlivec::doc_data(nd));
auto subitems = get_meta_items(meta_item_doc);
items += ~[attr::mk_list_item(n, subitems)];
}
ret items;
}
fn get_attributes(&ebml::doc md) -> ast::attribute[] {
fn get_attributes(&ebmlivec::doc md) -> ast::attribute[] {
let ast::attribute[] attrs = ~[];
alt (ebml::maybe_get_doc(md, tag_attributes)) {
alt (ebmlivec::maybe_get_doc(md, tag_attributes)) {
case (option::some(?attrs_d)) {
for each (ebml::doc attr_doc in
ebml::tagged_docs(attrs_d, tag_attribute)) {
for each (ebmlivec::doc attr_doc in
ebmlivec::tagged_docs(attrs_d, tag_attribute)) {
auto meta_items = get_meta_items(attr_doc);
// Currently it's only possible to have a single meta item on
// an attribute
@ -329,13 +329,13 @@ fn get_attributes(&ebml::doc md) -> ast::attribute[] {
ret attrs;
}
fn list_meta_items(&ebml::doc meta_items, io::writer out) {
fn list_meta_items(&ebmlivec::doc meta_items, ioivec::writer out) {
for (@ast::meta_item mi in get_meta_items(meta_items)) {
out.write_str(#fmt("%s\n", pprust::meta_item_to_str(*mi)));
}
}
fn list_crate_attributes(&ebml::doc md, io::writer out) {
fn list_crate_attributes(&ebmlivec::doc md, ioivec::writer out) {
out.write_str("=Crate Attributes=\n");
for (ast::attribute attr in get_attributes(md)) {
@ -345,27 +345,28 @@ fn list_crate_attributes(&ebml::doc md, io::writer out) {
out.write_str("\n\n");
}
fn get_crate_attributes(&vec[u8] data) -> ast::attribute[] {
ret get_attributes(ebml::new_doc(data));
fn get_crate_attributes(@u8[] data) -> ast::attribute[] {
ret get_attributes(ebmlivec::new_doc(data));
}
type crate_dep = tup(ast::crate_num, str);
fn get_crate_deps(&vec[u8] data) -> vec[crate_dep] {
fn get_crate_deps(@u8[] data) -> vec[crate_dep] {
let vec[crate_dep] deps = [];
auto cratedoc = ebml::new_doc(data);
auto depsdoc = ebml::get_doc(cratedoc, tag_crate_deps);
auto cratedoc = ebmlivec::new_doc(data);
auto depsdoc = ebmlivec::get_doc(cratedoc, tag_crate_deps);
auto crate_num = 1;
for each (ebml::doc depdoc in
ebml::tagged_docs(depsdoc, tag_crate_dep)) {
auto depname = str::unsafe_from_bytes(ebml::doc_data(depdoc));
for each (ebmlivec::doc depdoc in
ebmlivec::tagged_docs(depsdoc, tag_crate_dep)) {
auto depname =
str::unsafe_from_bytes_ivec(ebmlivec::doc_data(depdoc));
deps += [tup(crate_num, depname)];
crate_num += 1;
}
ret deps;
}
fn list_crate_deps(&vec[u8] data, io::writer out) {
fn list_crate_deps(@u8[] data, ioivec::writer out) {
out.write_str("=External Dependencies=\n");
for (crate_dep dep in get_crate_deps(data)) {
@ -375,20 +376,20 @@ fn list_crate_deps(&vec[u8] data, io::writer out) {
out.write_str("\n");
}
fn list_crate_items(vec[u8] bytes, &ebml::doc md, io::writer out) {
fn list_crate_items(&@u8[] bytes, &ebmlivec::doc md, ioivec::writer out) {
out.write_str("=Items=\n");
auto paths = ebml::get_doc(md, tag_paths);
auto items = ebml::get_doc(md, tag_items);
auto index = ebml::get_doc(paths, tag_index);
auto bs = ebml::get_doc(index, tag_index_buckets);
for each (ebml::doc bucket in
ebml::tagged_docs(bs, tag_index_buckets_bucket)) {
auto paths = ebmlivec::get_doc(md, tag_paths);
auto items = ebmlivec::get_doc(md, tag_items);
auto index = ebmlivec::get_doc(paths, tag_index);
auto bs = ebmlivec::get_doc(index, tag_index_buckets);
for each (ebmlivec::doc bucket in
ebmlivec::tagged_docs(bs, tag_index_buckets_bucket)) {
auto et = tag_index_buckets_bucket_elt;
for each (ebml::doc elt in ebml::tagged_docs(bucket, et)) {
for each (ebmlivec::doc elt in ebmlivec::tagged_docs(bucket, et)) {
auto data = read_path(elt);
auto def = ebml::doc_at(bytes, data._1);
auto did_doc = ebml::get_doc(def, tag_def_id);
auto did = parse_def_id(ebml::doc_data(did_doc));
auto def = ebmlivec::doc_at(bytes, data._1);
auto did_doc = ebmlivec::get_doc(def, tag_def_id);
auto did = parse_def_id(ebmlivec::doc_data(did_doc));
out.write_str(#fmt("%s (%s)\n", data._0,
describe_def(items, did)));
}
@ -396,8 +397,8 @@ fn list_crate_items(vec[u8] bytes, &ebml::doc md, io::writer out) {
out.write_str("\n");
}
fn list_crate_metadata(vec[u8] bytes, io::writer out) {
auto md = ebml::new_doc(bytes);
fn list_crate_metadata(&@u8[] bytes, ioivec::writer out) {
auto md = ebmlivec::new_doc(bytes);
list_crate_attributes(md, out);
list_crate_deps(bytes, out);
list_crate_items(bytes, md, out);

View file

@ -4,11 +4,11 @@ import std::ivec;
import std::str;
import std::vec;
import std::uint;
import std::io;
import std::ioivec;
import std::option;
import std::option::some;
import std::option::none;
import std::ebml;
import std::ebmlivec;
import std::map;
import syntax::ast::*;
import common::*;
@ -26,49 +26,49 @@ type encode_ctxt = rec(@crate_ctxt ccx,
abbrev_map type_abbrevs);
// Path table encoding
fn encode_name(&ebml::writer ebml_w, &str name) {
ebml::start_tag(ebml_w, tag_paths_data_name);
ebml_w.writer.write(str::bytes(name));
ebml::end_tag(ebml_w);
fn encode_name(&ebmlivec::writer ebml_w, &str name) {
ebmlivec::start_tag(ebml_w, tag_paths_data_name);
ebml_w.writer.write(str::bytes_ivec(name));
ebmlivec::end_tag(ebml_w);
}
fn encode_def_id(&ebml::writer ebml_w, &def_id id) {
ebml::start_tag(ebml_w, tag_def_id);
ebml_w.writer.write(str::bytes(def_to_str(id)));
ebml::end_tag(ebml_w);
fn encode_def_id(&ebmlivec::writer ebml_w, &def_id id) {
ebmlivec::start_tag(ebml_w, tag_def_id);
ebml_w.writer.write(str::bytes_ivec(def_to_str(id)));
ebmlivec::end_tag(ebml_w);
}
fn encode_tag_variant_paths(&ebml::writer ebml_w, &variant[] variants,
fn encode_tag_variant_paths(&ebmlivec::writer ebml_w, &variant[] variants,
&vec[str] path,
&mutable vec[tup(str, uint)] index) {
for (variant variant in variants) {
add_to_index(ebml_w, path, index, variant.node.name);
ebml::start_tag(ebml_w, tag_paths_data_item);
ebmlivec::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, variant.node.name);
encode_def_id(ebml_w, local_def(variant.node.id));
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
}
fn add_to_index(&ebml::writer ebml_w, &vec[str] path,
fn add_to_index(&ebmlivec::writer ebml_w, &vec[str] path,
&mutable vec[tup(str, uint)] index, &str name) {
auto full_path = path + [name];
index += [tup(str::connect(full_path, "::"), ebml_w.writer.tell())];
}
fn encode_native_module_item_paths(&ebml::writer ebml_w,
fn encode_native_module_item_paths(&ebmlivec::writer ebml_w,
&native_mod nmod, &vec[str] path,
&mutable vec[tup(str, uint)] index) {
for (@native_item nitem in nmod.items) {
add_to_index(ebml_w, path, index, nitem.ident);
ebml::start_tag(ebml_w, tag_paths_data_item);
ebmlivec::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, nitem.ident);
encode_def_id(ebml_w, local_def(nitem.id));
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
}
fn encode_module_item_paths(&ebml::writer ebml_w, &_mod module,
fn encode_module_item_paths(&ebmlivec::writer ebml_w, &_mod module,
&vec[str] path,
&mutable vec[tup(str, uint)] index) {
for (@item it in module.items) {
@ -76,148 +76,148 @@ fn encode_module_item_paths(&ebml::writer ebml_w, &_mod module,
alt (it.node) {
case (item_const(_, _)) {
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_item);
ebmlivec::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, it.ident);
encode_def_id(ebml_w, local_def(it.id));
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
case (item_fn(_, ?tps)) {
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_item);
ebmlivec::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, it.ident);
encode_def_id(ebml_w, local_def(it.id));
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
case (item_mod(?_mod)) {
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_mod);
ebmlivec::start_tag(ebml_w, tag_paths_data_mod);
encode_name(ebml_w, it.ident);
encode_def_id(ebml_w, local_def(it.id));
encode_module_item_paths(ebml_w, _mod, path + [it.ident],
index);
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
case (item_native_mod(?nmod)) {
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_mod);
ebmlivec::start_tag(ebml_w, tag_paths_data_mod);
encode_name(ebml_w, it.ident);
encode_def_id(ebml_w, local_def(it.id));
encode_native_module_item_paths(ebml_w, nmod,
path + [it.ident], index);
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
case (item_ty(_, ?tps)) {
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_item);
ebmlivec::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, it.ident);
encode_def_id(ebml_w, local_def(it.id));
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
case (item_res(_, _, ?tps, ?ctor_id)) {
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_item);
ebmlivec::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, it.ident);
encode_def_id(ebml_w, local_def(ctor_id));
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_item);
ebmlivec::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, it.ident);
encode_def_id(ebml_w, local_def(it.id));
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
case (item_tag(?variants, ?tps)) {
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_item);
ebmlivec::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, it.ident);
encode_def_id(ebml_w, local_def(it.id));
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
encode_tag_variant_paths(ebml_w, variants, path, index);
}
case (item_obj(_, ?tps, ?ctor_id)) {
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_item);
ebmlivec::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, it.ident);
encode_def_id(ebml_w, local_def(ctor_id));
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_item);
ebmlivec::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, it.ident);
encode_def_id(ebml_w, local_def(it.id));
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
}
}
}
fn encode_item_paths(&ebml::writer ebml_w, &@crate crate) ->
fn encode_item_paths(&ebmlivec::writer ebml_w, &@crate crate) ->
vec[tup(str, uint)] {
let vec[tup(str, uint)] index = [];
let vec[str] path = [];
ebml::start_tag(ebml_w, tag_paths);
ebmlivec::start_tag(ebml_w, tag_paths);
encode_module_item_paths(ebml_w, crate.node.module, path, index);
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
ret index;
}
// Item info table encoding
fn encode_kind(&ebml::writer ebml_w, u8 c) {
ebml::start_tag(ebml_w, tag_items_data_item_kind);
ebml_w.writer.write([c]);
ebml::end_tag(ebml_w);
fn encode_kind(&ebmlivec::writer ebml_w, u8 c) {
ebmlivec::start_tag(ebml_w, tag_items_data_item_kind);
ebml_w.writer.write(~[c]);
ebmlivec::end_tag(ebml_w);
}
fn def_to_str(&def_id did) -> str { ret #fmt("%d:%d", did._0, did._1); }
fn encode_type_param_count(&ebml::writer ebml_w, &ty_param[] tps) {
ebml::start_tag(ebml_w, tag_items_data_item_ty_param_count);
ebml::write_vint(ebml_w.writer, ivec::len[ty_param](tps));
ebml::end_tag(ebml_w);
fn encode_type_param_count(&ebmlivec::writer ebml_w, &ty_param[] tps) {
ebmlivec::start_tag(ebml_w, tag_items_data_item_ty_param_count);
ebmlivec::write_vint(ebml_w.writer, ivec::len[ty_param](tps));
ebmlivec::end_tag(ebml_w);
}
fn encode_variant_id(&ebml::writer ebml_w, &def_id vid) {
ebml::start_tag(ebml_w, tag_items_data_item_variant);
ebml_w.writer.write(str::bytes(def_to_str(vid)));
ebml::end_tag(ebml_w);
fn encode_variant_id(&ebmlivec::writer ebml_w, &def_id vid) {
ebmlivec::start_tag(ebml_w, tag_items_data_item_variant);
ebml_w.writer.write(str::bytes_ivec(def_to_str(vid)));
ebmlivec::end_tag(ebml_w);
}
fn encode_type(&@encode_ctxt ecx, &ebml::writer ebml_w, &ty::t typ) {
ebml::start_tag(ebml_w, tag_items_data_item_type);
fn encode_type(&@encode_ctxt ecx, &ebmlivec::writer ebml_w, &ty::t typ) {
ebmlivec::start_tag(ebml_w, tag_items_data_item_type);
auto f = def_to_str;
auto ty_str_ctxt =
@rec(ds=f, tcx=ecx.ccx.tcx,
abbrevs=tyencode::ac_use_abbrevs(ecx.type_abbrevs));
tyencode::enc_ty(io::new_writer_(ebml_w.writer), ty_str_ctxt, typ);
ebml::end_tag(ebml_w);
tyencode::enc_ty(ioivec::new_writer_(ebml_w.writer), ty_str_ctxt, typ);
ebmlivec::end_tag(ebml_w);
}
fn encode_symbol(&@encode_ctxt ecx, &ebml::writer ebml_w,
fn encode_symbol(&@encode_ctxt ecx, &ebmlivec::writer ebml_w,
node_id id) {
ebml::start_tag(ebml_w, tag_items_data_item_symbol);
ebml_w.writer.write(str::bytes(ecx.ccx.item_symbols.get(id)));
ebml::end_tag(ebml_w);
ebmlivec::start_tag(ebml_w, tag_items_data_item_symbol);
ebml_w.writer.write(str::bytes_ivec(ecx.ccx.item_symbols.get(id)));
ebmlivec::end_tag(ebml_w);
}
fn encode_discriminant(&@encode_ctxt ecx, &ebml::writer ebml_w,
fn encode_discriminant(&@encode_ctxt ecx, &ebmlivec::writer ebml_w,
node_id id) {
ebml::start_tag(ebml_w, tag_items_data_item_symbol);
ebml_w.writer.write(str::bytes(ecx.ccx.discrim_symbols.get(id)));
ebml::end_tag(ebml_w);
ebmlivec::start_tag(ebml_w, tag_items_data_item_symbol);
ebml_w.writer.write(str::bytes_ivec(ecx.ccx.discrim_symbols.get(id)));
ebmlivec::end_tag(ebml_w);
}
fn encode_tag_id(&ebml::writer ebml_w, &def_id id) {
ebml::start_tag(ebml_w, tag_items_data_item_tag_id);
ebml_w.writer.write(str::bytes(def_to_str(id)));
ebml::end_tag(ebml_w);
fn encode_tag_id(&ebmlivec::writer ebml_w, &def_id id) {
ebmlivec::start_tag(ebml_w, tag_items_data_item_tag_id);
ebml_w.writer.write(str::bytes_ivec(def_to_str(id)));
ebmlivec::end_tag(ebml_w);
}
fn encode_tag_variant_info(&@encode_ctxt ecx, &ebml::writer ebml_w,
fn encode_tag_variant_info(&@encode_ctxt ecx, &ebmlivec::writer ebml_w,
node_id id, &variant[] variants,
&mutable vec[tup(int, uint)] index,
&ty_param[] ty_params) {
for (variant variant in variants) {
index += [tup(variant.node.id, ebml_w.writer.tell())];
ebml::start_tag(ebml_w, tag_items_data_item);
ebmlivec::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, local_def(variant.node.id));
encode_kind(ebml_w, 'v' as u8);
encode_tag_id(ebml_w, local_def(id));
@ -228,24 +228,24 @@ fn encode_tag_variant_info(&@encode_ctxt ecx, &ebml::writer ebml_w,
}
encode_discriminant(ecx, ebml_w, variant.node.id);
encode_type_param_count(ebml_w, ty_params);
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
}
fn encode_info_for_item(@encode_ctxt ecx, &ebml::writer ebml_w,
fn encode_info_for_item(@encode_ctxt ecx, &ebmlivec::writer ebml_w,
@item item, &mutable vec[tup(int, uint)] index) {
alt (item.node) {
case (item_const(_, _)) {
ebml::start_tag(ebml_w, tag_items_data_item);
ebmlivec::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
encode_kind(ebml_w, 'c' as u8);
encode_type(ecx, ebml_w,
node_id_to_monotype(ecx.ccx.tcx, item.id));
encode_symbol(ecx, ebml_w, item.id);
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
case (item_fn(?fd, ?tps)) {
ebml::start_tag(ebml_w, tag_items_data_item);
ebmlivec::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
encode_kind(ebml_w, alt (fd.decl.purity) {
case (pure_fn) { 'p' }
@ -254,31 +254,31 @@ fn encode_info_for_item(@encode_ctxt ecx, &ebml::writer ebml_w,
encode_type(ecx, ebml_w,
node_id_to_monotype(ecx.ccx.tcx, item.id));
encode_symbol(ecx, ebml_w, item.id);
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
case (item_mod(_)) {
ebml::start_tag(ebml_w, tag_items_data_item);
ebmlivec::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
encode_kind(ebml_w, 'm' as u8);
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
case (item_native_mod(_)) {
ebml::start_tag(ebml_w, tag_items_data_item);
ebmlivec::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
encode_kind(ebml_w, 'n' as u8);
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
case (item_ty(_, ?tps)) {
ebml::start_tag(ebml_w, tag_items_data_item);
ebmlivec::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
encode_kind(ebml_w, 'y' as u8);
encode_type_param_count(ebml_w, tps);
encode_type(ecx, ebml_w,
node_id_to_monotype(ecx.ccx.tcx, item.id));
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
case (item_tag(?variants, ?tps)) {
ebml::start_tag(ebml_w, tag_items_data_item);
ebmlivec::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
encode_kind(ebml_w, 't' as u8);
encode_type_param_count(ebml_w, tps);
@ -287,55 +287,55 @@ fn encode_info_for_item(@encode_ctxt ecx, &ebml::writer ebml_w,
for (variant v in variants) {
encode_variant_id(ebml_w, local_def(v.node.id));
}
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
encode_tag_variant_info(ecx, ebml_w, item.id, variants, index,
tps);
}
case (item_res(_, _, ?tps, ?ctor_id)) {
auto fn_ty = node_id_to_monotype(ecx.ccx.tcx, ctor_id);
ebml::start_tag(ebml_w, tag_items_data_item);
ebmlivec::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, local_def(ctor_id));
encode_kind(ebml_w, 'y' as u8);
encode_type_param_count(ebml_w, tps);
encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
encode_symbol(ecx, ebml_w, item.id);
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
index += [tup(ctor_id, ebml_w.writer.tell())];
ebml::start_tag(ebml_w, tag_items_data_item);
ebmlivec::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, local_def(ctor_id));
encode_kind(ebml_w, 'f' as u8);
encode_type_param_count(ebml_w, tps);
encode_type(ecx, ebml_w, fn_ty);
encode_symbol(ecx, ebml_w, ctor_id);
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
case (item_obj(_, ?tps, ?ctor_id)) {
auto fn_ty = node_id_to_monotype(ecx.ccx.tcx, ctor_id);
ebml::start_tag(ebml_w, tag_items_data_item);
ebmlivec::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
encode_kind(ebml_w, 'y' as u8);
encode_type_param_count(ebml_w, tps);
encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
index += [tup(ctor_id, ebml_w.writer.tell())];
ebml::start_tag(ebml_w, tag_items_data_item);
ebmlivec::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, local_def(ctor_id));
encode_kind(ebml_w, 'f' as u8);
encode_type_param_count(ebml_w, tps);
encode_type(ecx, ebml_w, fn_ty);
encode_symbol(ecx, ebml_w, ctor_id);
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
}
}
fn encode_info_for_native_item(&@encode_ctxt ecx, &ebml::writer ebml_w,
fn encode_info_for_native_item(&@encode_ctxt ecx, &ebmlivec::writer ebml_w,
&@native_item nitem) {
ebml::start_tag(ebml_w, tag_items_data_item);
ebmlivec::start_tag(ebml_w, tag_items_data_item);
alt (nitem.node) {
case (native_item_ty) {
encode_def_id(ebml_w, local_def(nitem.id));
@ -352,13 +352,13 @@ fn encode_info_for_native_item(&@encode_ctxt ecx, &ebml::writer ebml_w,
encode_symbol(ecx, ebml_w, nitem.id);
}
}
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
fn encode_info_for_items(&@encode_ctxt ecx, &ebml::writer ebml_w) ->
fn encode_info_for_items(&@encode_ctxt ecx, &ebmlivec::writer ebml_w) ->
vec[tup(int, uint)] {
let vec[tup(int, uint)] index = [];
ebml::start_tag(ebml_w, tag_items_data);
ebmlivec::start_tag(ebml_w, tag_items_data);
for each (@tup(node_id, middle::ast_map::ast_node) kvp in
ecx.ccx.ast_map.items()) {
alt (kvp._1) {
@ -373,7 +373,7 @@ fn encode_info_for_items(&@encode_ctxt ecx, &ebml::writer ebml_w) ->
case (_) {}
}
}
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
ret index;
}
@ -391,81 +391,81 @@ fn create_index[T](&vec[tup(T, uint)] index, fn(&T) -> uint hash_fn) ->
ret vec::freeze(buckets);
}
fn encode_index[T](&ebml::writer ebml_w, &vec[vec[tup(T, uint)]] buckets,
fn(&io::writer, &T) write_fn) {
auto writer = io::new_writer_(ebml_w.writer);
ebml::start_tag(ebml_w, tag_index);
fn encode_index[T](&ebmlivec::writer ebml_w, &vec[vec[tup(T, uint)]] buckets,
fn(&ioivec::writer, &T) write_fn) {
auto writer = ioivec::new_writer_(ebml_w.writer);
ebmlivec::start_tag(ebml_w, tag_index);
let vec[uint] bucket_locs = [];
ebml::start_tag(ebml_w, tag_index_buckets);
ebmlivec::start_tag(ebml_w, tag_index_buckets);
for (vec[tup(T, uint)] bucket in buckets) {
bucket_locs += [ebml_w.writer.tell()];
ebml::start_tag(ebml_w, tag_index_buckets_bucket);
ebmlivec::start_tag(ebml_w, tag_index_buckets_bucket);
for (tup(T, uint) elt in bucket) {
ebml::start_tag(ebml_w, tag_index_buckets_bucket_elt);
ebmlivec::start_tag(ebml_w, tag_index_buckets_bucket_elt);
writer.write_be_uint(elt._1, 4u);
write_fn(writer, elt._0);
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
ebml::end_tag(ebml_w);
ebml::start_tag(ebml_w, tag_index_table);
ebmlivec::end_tag(ebml_w);
ebmlivec::start_tag(ebml_w, tag_index_table);
for (uint pos in bucket_locs) { writer.write_be_uint(pos, 4u); }
ebml::end_tag(ebml_w);
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
fn write_str(&io::writer writer, &str s) { writer.write_str(s); }
fn write_str(&ioivec::writer writer, &str s) { writer.write_str(s); }
fn write_int(&io::writer writer, &int n) {
fn write_int(&ioivec::writer writer, &int n) {
writer.write_be_uint(n as uint, 4u);
}
fn encode_meta_item(&ebml::writer ebml_w, &meta_item mi) {
fn encode_meta_item(&ebmlivec::writer ebml_w, &meta_item mi) {
alt (mi.node) {
case (meta_word(?name)) {
ebml::start_tag(ebml_w, tag_meta_item_word);
ebml::start_tag(ebml_w, tag_meta_item_name);
ebml_w.writer.write(str::bytes(name));
ebml::end_tag(ebml_w);
ebml::end_tag(ebml_w);
ebmlivec::start_tag(ebml_w, tag_meta_item_word);
ebmlivec::start_tag(ebml_w, tag_meta_item_name);
ebml_w.writer.write(str::bytes_ivec(name));
ebmlivec::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
case (meta_name_value(?name, ?value)) {
alt (value.node) {
case (lit_str(?value, _)) {
ebml::start_tag(ebml_w, tag_meta_item_name_value);
ebml::start_tag(ebml_w, tag_meta_item_name);
ebml_w.writer.write(str::bytes(name));
ebml::end_tag(ebml_w);
ebml::start_tag(ebml_w, tag_meta_item_value);
ebml_w.writer.write(str::bytes(value));
ebml::end_tag(ebml_w);
ebml::end_tag(ebml_w);
ebmlivec::start_tag(ebml_w, tag_meta_item_name_value);
ebmlivec::start_tag(ebml_w, tag_meta_item_name);
ebml_w.writer.write(str::bytes_ivec(name));
ebmlivec::end_tag(ebml_w);
ebmlivec::start_tag(ebml_w, tag_meta_item_value);
ebml_w.writer.write(str::bytes_ivec(value));
ebmlivec::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
case (_) { /* FIXME (#611) */ }
}
}
case (meta_list(?name, ?items)) {
ebml::start_tag(ebml_w, tag_meta_item_list);
ebml::start_tag(ebml_w, tag_meta_item_name);
ebml_w.writer.write(str::bytes(name));
ebml::end_tag(ebml_w);
ebmlivec::start_tag(ebml_w, tag_meta_item_list);
ebmlivec::start_tag(ebml_w, tag_meta_item_name);
ebml_w.writer.write(str::bytes_ivec(name));
ebmlivec::end_tag(ebml_w);
for (@meta_item inner_item in items) {
encode_meta_item(ebml_w, *inner_item);
}
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
}
}
fn encode_attributes(&ebml::writer ebml_w, &vec[attribute] attrs) {
ebml::start_tag(ebml_w, tag_attributes);
fn encode_attributes(&ebmlivec::writer ebml_w, &vec[attribute] attrs) {
ebmlivec::start_tag(ebml_w, tag_attributes);
for (attribute attr in attrs) {
ebml::start_tag(ebml_w, tag_attribute);
ebmlivec::start_tag(ebml_w, tag_attribute);
encode_meta_item(ebml_w, attr.node.value);
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
// So there's a special crate attribute called 'link' which defines the
@ -520,7 +520,7 @@ fn synthesize_crate_attrs(&@encode_ctxt ecx,
ret attrs;
}
fn encode_crate_deps(&ebml::writer ebml_w, &cstore::cstore cstore) {
fn encode_crate_deps(&ebmlivec::writer ebml_w, &cstore::cstore cstore) {
fn get_ordered_names(&cstore::cstore cstore) -> vec[str] {
type hashkv = @tup(crate_num, cstore::crate_metadata);
@ -554,13 +554,13 @@ fn encode_crate_deps(&ebml::writer ebml_w, &cstore::cstore cstore) {
// that they are numbered 1 to n.
// FIXME: This is not nearly enough to support correct versioning
// but is enough to get transitive crate dependencies working.
ebml::start_tag(ebml_w, tag_crate_deps);
ebmlivec::start_tag(ebml_w, tag_crate_deps);
for (str cname in get_ordered_names(cstore)) {
ebml::start_tag(ebml_w, tag_crate_dep);
ebml_w.writer.write(str::bytes(cname));
ebml::end_tag(ebml_w);
ebmlivec::start_tag(ebml_w, tag_crate_dep);
ebml_w.writer.write(str::bytes_ivec(cname));
ebmlivec::end_tag(ebml_w);
}
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
fn encode_metadata(&@crate_ctxt cx, &@crate crate) -> str {
@ -568,9 +568,9 @@ fn encode_metadata(&@crate_ctxt cx, &@crate crate) -> str {
auto abbrevs = map::mk_hashmap(ty::hash_ty, ty::eq_ty);
auto ecx = @rec(ccx = cx, type_abbrevs = abbrevs);
auto string_w = io::string_writer();
auto string_w = ioivec::string_writer();
auto buf_w = string_w.get_writer().get_buf_writer();
auto ebml_w = ebml::create_writer(buf_w);
auto ebml_w = ebmlivec::create_writer(buf_w);
auto crate_attrs = synthesize_crate_attrs(ecx, crate);
encode_attributes(ebml_w, crate_attrs);
@ -579,26 +579,26 @@ fn encode_metadata(&@crate_ctxt cx, &@crate crate) -> str {
// Encode and index the paths.
ebml::start_tag(ebml_w, tag_paths);
ebmlivec::start_tag(ebml_w, tag_paths);
auto paths_index = encode_item_paths(ebml_w, crate);
auto str_writer = write_str;
auto path_hasher = hash_path;
auto paths_buckets = create_index[str](paths_index, path_hasher);
encode_index[str](ebml_w, paths_buckets, str_writer);
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
// Encode and index the items.
ebml::start_tag(ebml_w, tag_items);
ebmlivec::start_tag(ebml_w, tag_items);
auto items_index = encode_info_for_items(ecx, ebml_w);
auto int_writer = write_int;
auto item_hasher = hash_node_id;
auto items_buckets = create_index[int](items_index, item_hasher);
encode_index[int](ebml_w, items_buckets, int_writer);
ebml::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
// Pad this, since something (LLVM, presumably) is cutting off the
// remaining % 4 bytes.
// remaining % 4 bytes_ivec.
buf_w.write([0u8, 0u8, 0u8, 0u8]);
buf_w.write(~[0u8, 0u8, 0u8, 0u8]);
ret string_w.get_str();
}
@ -607,7 +607,7 @@ fn encoded_ty(&ty::ctxt tcx, &ty::t t) -> str {
auto cx = @rec(ds = def_to_str,
tcx = tcx,
abbrevs = tyencode::ac_no_abbrevs);
auto sw = io::string_writer();
auto sw = ioivec::string_writer();
tyencode::enc_ty(sw.get_writer(), cx, t);
ret sw.get_str();
}

View file

@ -1,5 +1,6 @@
// Type decoding
import std::ivec;
import std::str;
import std::vec;
import std::uint;
@ -21,7 +22,7 @@ export parse_ty_data;
type str_def = fn(str) -> ast::def_id ;
type pstate =
rec(vec[u8] data, int crate, mutable uint pos, uint len, ty::ctxt tcx);
rec(@u8[] data, int crate, mutable uint pos, uint len, ty::ctxt tcx);
tag ty_or_bang { a_ty(ty::t); a_bang; }
@ -50,7 +51,7 @@ fn parse_ident_(@pstate st, str_def sd, fn(char) -> bool is_last)
}
fn parse_ty_data(vec[u8] data, int crate_num, uint pos, uint len, str_def sd,
fn parse_ty_data(@u8[] data, int crate_num, uint pos, uint len, str_def sd,
ty::ctxt tcx) -> ty::t {
auto st =
@rec(data=data, crate=crate_num, mutable pos=pos, len=len, tcx=tcx);
@ -361,9 +362,9 @@ fn parse_ty_fn(@pstate st, str_def sd) ->
// Rust metadata parsing
fn parse_def_id(vec[u8] buf) -> ast::def_id {
fn parse_def_id(&u8[] buf) -> ast::def_id {
auto colon_idx = 0u;
auto len = vec::len[u8](buf);
auto len = ivec::len[u8](buf);
while (colon_idx < len && buf.(colon_idx) != ':' as u8) {
colon_idx += 1u;
}
@ -371,9 +372,15 @@ fn parse_def_id(vec[u8] buf) -> ast::def_id {
log_err "didn't find ':' when parsing def id";
fail;
}
auto crate_part = vec::slice[u8](buf, 0u, colon_idx);
auto def_part = vec::slice[u8](buf, colon_idx + 1u, len);
auto crate_num = uint::parse_buf(crate_part, 10u) as int;
auto def_id = uint::parse_buf(def_part, 10u) as int;
auto crate_part = ivec::slice[u8](buf, 0u, colon_idx);
auto def_part = ivec::slice[u8](buf, colon_idx + 1u, len);
// FIXME: Remove these ivec->vec conversions.
auto crate_part_vec = []; auto def_part_vec = [];
for (u8 b in crate_part) { crate_part_vec += [b]; }
for (u8 b in def_part) { def_part_vec += [b]; }
auto crate_num = uint::parse_buf(crate_part_vec, 10u) as int;
auto def_id = uint::parse_buf(def_part_vec, 10u) as int;
ret tup(crate_num, def_id);
}

View file

@ -1,6 +1,6 @@
// Type encoding
import std::io;
import std::ioivec;
import std::map::hashmap;
import std::option::some;
import std::option::none;
@ -36,14 +36,14 @@ fn cx_uses_abbrevs(&@ctxt cx) -> bool {
}
}
fn enc_ty(&io::writer w, &@ctxt cx, &ty::t t) {
fn enc_ty(&ioivec::writer w, &@ctxt cx, &ty::t t) {
alt (cx.abbrevs) {
case (ac_no_abbrevs) {
auto result_str;
alt (cx.tcx.short_names_cache.find(t)) {
case (some(?s)) { result_str = s; }
case (none) {
auto sw = io::string_writer();
auto sw = ioivec::string_writer();
enc_sty(sw.get_writer(), cx, ty::struct(cx.tcx, t));
result_str = sw.get_str();
cx.tcx.short_names_cache.insert(t, result_str);
@ -82,7 +82,7 @@ fn enc_ty(&io::writer w, &@ctxt cx, &ty::t t) {
}
}
}
fn enc_mt(&io::writer w, &@ctxt cx, &ty::mt mt) {
fn enc_mt(&ioivec::writer w, &@ctxt cx, &ty::mt mt) {
alt (mt.mut) {
case (imm) { }
case (mut) { w.write_char('m'); }
@ -90,7 +90,7 @@ fn enc_mt(&io::writer w, &@ctxt cx, &ty::mt mt) {
}
enc_ty(w, cx, mt.ty);
}
fn enc_sty(&io::writer w, &@ctxt cx, &ty::sty st) {
fn enc_sty(&ioivec::writer w, &@ctxt cx, &ty::sty st) {
alt (st) {
case (ty::ty_nil) { w.write_char('n'); }
case (ty::ty_bot) { w.write_char('z'); }
@ -192,13 +192,13 @@ fn enc_sty(&io::writer w, &@ctxt cx, &ty::sty st) {
case (ty::ty_task) { w.write_char('a'); }
}
}
fn enc_proto(&io::writer w, proto proto) {
fn enc_proto(&ioivec::writer w, proto proto) {
alt (proto) {
case (proto_iter) { w.write_char('W'); }
case (proto_fn) { w.write_char('F'); }
}
}
fn enc_ty_fn(&io::writer w, &@ctxt cx, &ty::arg[] args, &ty::t out,
fn enc_ty_fn(&ioivec::writer w, &@ctxt cx, &ty::arg[] args, &ty::t out,
&controlflow cf, &(@ty::constr_def)[] constrs) {
w.write_char('[');
for (ty::arg arg in args) {
@ -226,7 +226,7 @@ fn enc_ty_fn(&io::writer w, &@ctxt cx, &ty::arg[] args, &ty::t out,
}
}
fn enc_constr(&io::writer w, &@ctxt cx, &@ty::constr_def c) {
fn enc_constr(&ioivec::writer w, &@ctxt cx, &@ty::constr_def c) {
w.write_str(path_to_str(c.node.path));
w.write_char('(');
w.write_str(cx.ds(c.node.id));

View file

@ -1,8 +1,8 @@
import std::uint;
import std::str;
import std::vec;
import std::term;
import std::io;
import std::termivec;
import std::ioivec;
import std::option;
import std::option::some;
import std::option::none;
@ -70,21 +70,21 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
}
case (none) { }
}
io::stdout().write_str(ss + ": ");
if (term::color_supported()) {
term::fg(io::stdout().get_buf_writer(), color);
ioivec::stdout().write_str(ss + ": ");
if (termivec::color_supported()) {
termivec::fg(ioivec::stdout().get_buf_writer(), color);
}
io::stdout().write_str(#fmt("%s:", kind));
if (term::color_supported()) {
term::reset(io::stdout().get_buf_writer());
ioivec::stdout().write_str(#fmt("%s:", kind));
if (termivec::color_supported()) {
termivec::reset(ioivec::stdout().get_buf_writer());
}
io::stdout().write_str(#fmt(" %s\n", msg));
ioivec::stdout().write_str(#fmt(" %s\n", msg));
alt (maybe_lines) {
case (some(?lines)) {
// FIXME: reading in the entire file is the worst possible way to
// get access to the necessary lines.
auto rdr = io::file_reader(lines.name);
auto file = str::unsafe_from_bytes(rdr.read_whole_stream());
auto rdr = ioivec::file_reader(lines.name);
auto file = str::unsafe_from_bytes_ivec(rdr.read_whole_stream());
auto fm = codemap::get_filemap(cm, lines.name);
// arbitrarily only print up to six lines of the error
@ -97,12 +97,13 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
}
// Print the offending lines
for (uint line in display_lines) {
io::stdout().write_str(#fmt("%s:%u ", fm.name, line + 1u));
ioivec::stdout().write_str(#fmt("%s:%u ", fm.name,
line + 1u));
auto s = codemap::get_line(fm, line as int, file);
if (!str::ends_with(s, "\n")) {
s += "\n";
}
io::stdout().write_str(s);
ioivec::stdout().write_str(s);
}
if (elided) {
auto last_line = display_lines.(vec::len(display_lines) - 1u);
@ -111,7 +112,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
auto out = "";
while (indent > 0u) { out += " "; indent -= 1u; }
out += "...\n";
io::stdout().write_str(out);
ioivec::stdout().write_str(out);
}
// If there's one line at fault we can easily point to the problem
@ -138,7 +139,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
width -= 1u;
}
}
io::stdout().write_str(s + "\n");
ioivec::stdout().write_str(s + "\n");
}
}
case (_) {}

View file

@ -1,5 +1,5 @@
import std::io;
import std::ioivec;
import std::str;
import std::vec;
import std::int;
@ -734,8 +734,8 @@ type lit = rec(str lit, uint pos);
fn gather_comments_and_literals(&codemap::codemap cm, str path)
-> rec(cmnt[] cmnts, lit[] lits) {
auto srdr = io::file_reader(path);
auto src = str::unsafe_from_bytes(srdr.read_whole_stream());
auto srdr = ioivec::file_reader(path);
auto src = str::unsafe_from_bytes_ivec(srdr.read_whole_stream());
auto itr = @interner::mk[str](str::hash, str::eq);
auto rdr = new_reader(cm, src, codemap::new_filemap(path, 0u), itr);
let cmnt[] comments = ~[];

View file

@ -1,5 +1,5 @@
import std::io;
import std::ioivec;
import std::ivec;
import std::vec;
import std::str;
@ -59,8 +59,8 @@ fn new_parser_from_file(parse_sess sess, ast::crate_cfg cfg,
str path, uint pos) -> parser {
auto ftype = SOURCE_FILE;
if (str::ends_with(path, ".rc")) { ftype = CRATE_FILE; }
auto srdr = io::file_reader(path);
auto src = str::unsafe_from_bytes(srdr.read_whole_stream());
auto srdr = ioivec::file_reader(path);
auto src = str::unsafe_from_bytes_ivec(srdr.read_whole_stream());
auto filemap = codemap::new_filemap(path, pos);
vec::push(sess.cm.files, filemap);
auto itr = @interner::mk(str::hash, str::eq);

View file

@ -1,5 +1,5 @@
import std::io;
import std::ioivec;
import std::vec;
import std::str;
@ -98,7 +98,7 @@ type print_stack_elt = rec(int offset, print_stack_break pbreak);
const int size_infinity = 0xffff;
fn mk_printer(io::writer out, uint linewidth) -> printer {
fn mk_printer(ioivec::writer out, uint linewidth) -> printer {
// Yes 3, it makes the ring buffers big enough to never
// fall behind.
@ -198,7 +198,7 @@ fn mk_printer(io::writer out, uint linewidth) -> printer {
* the method called 'pretty_print', and the 'PRINT' process is the method
* called 'print'.
*/
obj printer(io::writer out,
obj printer(ioivec::writer out,
uint buf_len,
mutable int margin, // width of lines we're constrained to

View file

@ -1,7 +1,7 @@
import std::ivec;
import std::int;
import std::io;
import std::ioivec;
import std::str;
import std::uint;
import std::vec;
@ -57,7 +57,7 @@ fn ibox(&ps s, uint u) {
fn end(&ps s) { ivec::pop(s.boxes); pp::end(s.s); }
fn rust_printer(io::writer writer) -> ps {
fn rust_printer(ioivec::writer writer) -> ps {
let pp::breaks[] boxes = ~[];
ret @rec(s=pp::mk_printer(writer, default_columns),
cm=none[codemap],
@ -74,7 +74,7 @@ const uint indent_unit = 4u;
const uint default_columns = 78u;
fn print_crate(&codemap cm, @ast::crate crate, str filename,
io::writer out, &pp_ann ann) {
ioivec::writer out, &pp_ann ann) {
let pp::breaks[] boxes = ~[];
auto r = lexer::gather_comments_and_literals(cm, filename);
auto s =
@ -104,7 +104,7 @@ fn item_to_str(&@ast::item i) -> str { be to_str(i, print_item); }
fn path_to_str(&ast::path p) -> str { be to_str(p, print_path); }
fn fun_to_str(&ast::_fn f, str name, &ast::ty_param[] params) -> str {
auto writer = io::string_writer();
auto writer = ioivec::string_writer();
auto s = rust_printer(writer.get_writer());
print_fn(s, f.decl, f.proto, name, params);
eof(s.s);
@ -112,7 +112,7 @@ fn fun_to_str(&ast::_fn f, str name, &ast::ty_param[] params) -> str {
}
fn block_to_str(&ast::block blk) -> str {
auto writer = io::string_writer();
auto writer = ioivec::string_writer();
auto s = rust_printer(writer.get_writer());
// containing cbox, will be closed by print-block at }
@ -1505,7 +1505,7 @@ fn escape_str(str st, char to_escape) -> str {
}
fn to_str[T](&T t, fn(&ps, &T) f) -> str {
auto writer = io::string_writer();
auto writer = ioivec::string_writer();
auto s = rust_printer(writer.get_writer());
f(s, t);
eof(s.s);

View file

@ -14,9 +14,9 @@ import syntax::codemap::span;
import ast::lit;
import ast::path;
import syntax::walk;
import std::io::stdout;
import std::io::str_writer;
import std::io::string_writer;
import std::ioivec::stdout;
import std::ioivec::str_writer;
import std::ioivec::string_writer;
import syntax::print;
import print::pprust::print_block;
import print::pprust::print_item;

View file

@ -1,4 +1,3 @@
import std::io;
import std::ivec;
import std::str;
import std::int;