Convert rustc::metadata to istrs. Issue #855

This commit is contained in:
Brian Anderson 2011-08-26 22:48:10 -07:00
parent 7d70685eef
commit 54691f9a6c
10 changed files with 133 additions and 119 deletions

View File

@ -491,9 +491,10 @@ fn main(args: [str]) {
} else if n_inputs > 1u {
sess.fatal("Multiple input filenames provided.");
}
let ifile = istr::to_estr(match.free[0]);
let ifile = match.free[0];
let saved_out_filename: str = "";
let cfg = build_configuration(sess, binary, ifile);
let cfg = build_configuration(sess, binary,
istr::to_estr(ifile));
let pretty =
option::map::<istr,
pp_mode>(bind parse_pretty(sess, _),
@ -501,7 +502,7 @@ fn main(args: [str]) {
~"normal"));
alt pretty {
some::<pp_mode>(ppm) {
pretty_print_input(sess, cfg, ifile, ppm);
pretty_print_input(sess, cfg, istr::to_estr(ifile), ppm);
ret;
}
none::<pp_mode>. {/* continue */ }
@ -519,8 +520,8 @@ fn main(args: [str]) {
// have to make up a name
// We want to toss everything after the final '.'
let parts =
if !input_is_stdin(ifile) {
str::split(ifile, '.' as u8)
if !input_is_stdin(istr::to_estr(ifile)) {
istr::to_estrs(istr::split(ifile, '.' as u8))
} else { ["default", "rs"] };
vec::pop(parts);
saved_out_filename = str::connect(parts, ".");
@ -536,7 +537,7 @@ fn main(args: [str]) {
}
};
let ofile = saved_out_filename + "." + suffix;
compile_input(sess, cfg, ifile, ofile);
compile_input(sess, cfg, istr::to_estr(ifile), ofile);
}
some(ofile) {
let ofile = istr::to_estr(ofile);
@ -544,7 +545,7 @@ fn main(args: [str]) {
saved_out_filename = ofile;
let temp_filename =
if !stop_after_codegen { ofile + ".o" } else { ofile };
compile_input(sess, cfg, ifile, temp_filename);
compile_input(sess, cfg, istr::to_estr(ifile), temp_filename);
}
}
@ -596,12 +597,12 @@ fn rmext(filename: &istr) -> istr {
}
let cstore = sess.get_cstore();
for cratepath: str in cstore::get_used_crate_files(cstore) {
if str::ends_with(cratepath, ".rlib") {
gcc_args += [istr::from_estr(cratepath)];
for cratepath: istr in cstore::get_used_crate_files(cstore) {
if istr::ends_with(cratepath, ~".rlib") {
gcc_args += [cratepath];
cont;
}
let cratepath = istr::from_estr(cratepath);
let cratepath = cratepath;
let dir = fs::dirname(cratepath);
if dir != ~"" { gcc_args += [~"-L" + dir]; }
let libarg = unlib(sess.get_targ_cfg(), fs::basename(cratepath));
@ -609,10 +610,10 @@ fn rmext(filename: &istr) -> istr {
}
let ula = cstore::get_used_link_args(cstore);
for arg: str in ula { gcc_args += [istr::from_estr(arg)]; }
for arg: istr in ula { gcc_args += [arg]; }
let used_libs = cstore::get_used_libraries(cstore);
for l: str in used_libs { gcc_args += [~"-l" + istr::from_estr(l)]; }
for l: istr in used_libs { gcc_args += [~"-l" + l]; }
if sopts.library {
gcc_args += [istr::from_estr(lib_cmd)];

View File

@ -35,7 +35,8 @@ fn read_crates(sess: session::session, crate: &ast::crate) {
let e =
@{sess: sess,
crate_cache: @std::map::new_str_hash::<int>(),
library_search_paths: sess.get_opts().library_search_paths,
library_search_paths:
istr::from_estrs(sess.get_opts().library_search_paths),
mutable next_crate_num: 1};
let v =
visit::mk_simple_visitor(@{visit_view_item:
@ -48,7 +49,7 @@ fn read_crates(sess: session::session, crate: &ast::crate) {
type env =
@{sess: session::session,
crate_cache: @hashmap<istr, int>,
library_search_paths: [str],
library_search_paths: [istr],
mutable next_crate_num: ast::crate_num};
fn visit_view_item(e: env, i: &@ast::view_item) {
@ -69,12 +70,12 @@ fn visit_item(e: env, i: &@ast::item) {
}
let cstore = e.sess.get_cstore();
if !cstore::add_used_library(cstore,
istr::to_estr(m.native_name)) { ret; }
m.native_name) { ret; }
for a: ast::attribute in
attr::find_attrs_by_name(i.attrs, ~"link_args") {
alt attr::get_meta_item_value_str(attr::attr_meta(a)) {
some(linkarg) {
cstore::add_used_link_args(cstore, istr::to_estr(linkarg));
cstore::add_used_link_args(cstore, linkarg);
}
none. {/* fallthrough */ }
}
@ -85,12 +86,12 @@ fn visit_item(e: env, i: &@ast::item) {
}
// A diagnostic function for dumping crate metadata to an output stream
fn list_file_metadata(path: str, out: io::writer) {
fn list_file_metadata(path: &istr, out: io::writer) {
alt get_metadata_section(path) {
option::some(bytes) { decoder::list_crate_metadata(bytes, out); }
option::none. {
out.write_str(
istr::from_estr("Could not find metadata in " + path + ".\n"));
~"Could not find metadata in " + path + ~".\n");
}
}
}
@ -112,18 +113,18 @@ fn metadata_matches(crate_data: &@[u8], metas: &[@ast::meta_item]) -> bool {
}
fn default_native_lib_naming(sess: session::session, static: bool) ->
{prefix: str, suffix: str} {
if static { ret {prefix: "lib", suffix: ".rlib"}; }
{prefix: istr, suffix: istr} {
if static { ret {prefix: ~"lib", suffix: ~".rlib"}; }
alt sess.get_targ_cfg().os {
session::os_win32. { ret {prefix: "", suffix: ".dll"}; }
session::os_macos. { ret {prefix: "lib", suffix: ".dylib"}; }
session::os_linux. { ret {prefix: "lib", suffix: ".so"}; }
session::os_win32. { ret {prefix: ~"", suffix: ~".dll"}; }
session::os_macos. { ret {prefix: ~"lib", suffix: ~".dylib"}; }
session::os_linux. { ret {prefix: ~"lib", suffix: ~".so"}; }
}
}
fn find_library_crate(sess: &session::session, ident: &ast::ident,
metas: &[@ast::meta_item], library_search_paths: &[str])
-> option::t<{ident: str, data: @[u8]}> {
metas: &[@ast::meta_item], library_search_paths: &[istr])
-> option::t<{ident: istr, data: @[u8]}> {
attr::require_unique_names(sess, metas);
@ -145,37 +146,36 @@ fn find_library_crate(sess: &session::session, ident: &ast::ident,
let nn = default_native_lib_naming(sess, sess.get_opts().static);
let x =
find_library_crate_aux(nn, istr::to_estr(crate_name),
find_library_crate_aux(nn, crate_name,
metas, library_search_paths);
if x != none || sess.get_opts().static { ret x; }
let nn2 = default_native_lib_naming(sess, true);
ret find_library_crate_aux(nn2, istr::to_estr(crate_name),
ret find_library_crate_aux(nn2, crate_name,
metas, library_search_paths);
}
fn find_library_crate_aux(nn: &{prefix: str, suffix: str}, crate_name: str,
fn find_library_crate_aux(nn: &{prefix: istr, suffix: istr},
crate_name: &istr,
metas: &[@ast::meta_item],
library_search_paths: &[str]) ->
option::t<{ident: str, data: @[u8]}> {
let prefix: istr = istr::from_estr(nn.prefix + crate_name);
let suffix: istr = istr::from_estr(nn.suffix);
library_search_paths: &[istr]) ->
option::t<{ident: istr, data: @[u8]}> {
let prefix: istr = nn.prefix + crate_name;
let suffix: istr = nn.suffix;
// 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
// tricks. Currently the glob(3) interface is a bit more than we can
// stomach from here, and writing a C++ wrapper is more work than just
// manually filtering fs::list_dir here.
for library_search_path: str in library_search_paths {
log #fmt["searching %s", library_search_path];
let library_search_path = istr::from_estr(library_search_path);
for library_search_path: istr in library_search_paths {
log #fmt["searching %s", istr::to_estr(library_search_path)];
for path: istr in fs::list_dir(library_search_path) {
log #fmt["searching %s", istr::to_estr(path)];
let f: istr = fs::basename(path);
let path = istr::to_estr(path);
if !(istr::starts_with(f, prefix) && istr::ends_with(f, suffix))
{
log #fmt["skipping %s, doesn't look like %s*%s",
path,
istr::to_estr(path),
istr::to_estr(prefix),
istr::to_estr(suffix)];
cont;
@ -183,10 +183,12 @@ fn find_library_crate_aux(nn: &{prefix: str, suffix: str}, crate_name: str,
alt get_metadata_section(path) {
option::some(cvec) {
if !metadata_matches(cvec, metas) {
log #fmt["skipping %s, metadata doesn't match", path];
log #fmt["skipping %s, metadata doesn't match",
istr::to_estr(path)];
cont;
}
log #fmt["found %s with matching metadata", path];
log #fmt["found %s with matching metadata",
istr::to_estr(path)];
ret some({ident: path, data: cvec});
}
_ { }
@ -196,8 +198,8 @@ fn find_library_crate_aux(nn: &{prefix: str, suffix: str}, crate_name: str,
ret none;
}
fn get_metadata_section(filename: str) -> option::t<@[u8]> {
let mb = istr::as_buf(istr::from_estr(filename), { |buf|
fn get_metadata_section(filename: &istr) -> option::t<@[u8]> {
let mb = istr::as_buf(filename, { |buf|
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
});
if mb as int == 0 { ret option::none::<@[u8]>; }
@ -218,8 +220,9 @@ fn get_metadata_section(filename: str) -> option::t<@[u8]> {
}
fn load_library_crate(sess: &session::session, span: span, ident: &ast::ident,
metas: &[@ast::meta_item], library_search_paths: &[str])
-> {ident: str, data: @[u8]} {
metas: &[@ast::meta_item],
library_search_paths: &[istr])
-> {ident: istr, data: @[u8]} {
alt find_library_crate(sess, ident, metas, library_search_paths) {
@ -249,12 +252,13 @@ fn resolve_crate(e: env, ident: &ast::ident, metas: [@ast::meta_item],
// Now resolve the crates referenced by this crate
let cnum_map = resolve_crate_deps(e, cdata);
let cmeta = {name: istr::to_estr(ident),
let cmeta = {name: ident,
data: cdata, cnum_map: cnum_map};
let cstore = e.sess.get_cstore();
cstore::set_crate_data(cstore, cnum, cmeta);
cstore::add_used_crate_file(cstore, cfilename);
cstore::add_used_crate_file(cstore,
cfilename);
ret cnum;
} else { ret e.crate_cache.get(ident); }
}
@ -268,11 +272,11 @@ fn resolve_crate_deps(e: env, cdata: &@[u8]) -> cstore::cnum_map {
for dep: decoder::crate_dep in decoder::get_crate_deps(cdata) {
let extrn_cnum = dep.cnum;
let cname = dep.ident;
log #fmt["resolving dep %s", cname];
if e.crate_cache.contains_key(istr::from_estr(cname)) {
log #fmt["resolving dep %s", istr::to_estr(cname)];
if e.crate_cache.contains_key(cname) {
log "already have it";
// We've already seen this crate
let local_cnum = e.crate_cache.get(istr::from_estr(cname));
let local_cnum = e.crate_cache.get(cname);
cnum_map.insert(extrn_cnum, local_cnum);
} else {
log "need to load it";
@ -280,7 +284,7 @@ fn resolve_crate_deps(e: env, cdata: &@[u8]) -> cstore::cnum_map {
// FIXME: Need better error reporting than just a bogus span
let fake_span = ast_util::dummy_sp();
let local_cnum = resolve_crate(e,
istr::from_estr(cname),
cname,
[], fake_span);
cnum_map.insert(extrn_cnum, local_cnum);
}

View File

@ -11,7 +11,7 @@
export get_tag_variants;
export get_type;
fn get_symbol(cstore: &cstore::cstore, def: ast::def_id) -> str {
fn get_symbol(cstore: &cstore::cstore, def: ast::def_id) -> istr {
let cdata = cstore::get_crate_data(cstore, def.crate).data;
ret decoder::get_symbol(cdata, def.node);
}

View File

@ -4,6 +4,7 @@
import std::vec;
import std::map;
import std::str;
import std::istr;
import syntax::ast;
export cstore;
@ -29,7 +30,7 @@
// own crate numbers.
type cnum_map = map::hashmap<ast::crate_num, ast::crate_num>;
type crate_metadata = {name: str, data: @[u8], cnum_map: cnum_map};
type crate_metadata = {name: istr, data: @[u8], 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
@ -41,9 +42,9 @@
type cstore_private =
@{metas: map::hashmap<ast::crate_num, crate_metadata>,
use_crate_map: use_crate_map,
mutable used_crate_files: [str],
mutable used_libraries: [str],
mutable used_link_args: [str]};
mutable used_crate_files: [istr],
mutable used_libraries: [istr],
mutable used_link_args: [istr]};
// Map from node_id's of local use statements to crate numbers
type use_crate_map = map::hashmap<ast::node_id, ast::crate_num>;
@ -82,18 +83,18 @@ fn have_crate_data(cstore: &cstore, cnum: ast::crate_num) -> bool {
}
}
fn add_used_crate_file(cstore: &cstore, lib: &str) {
fn add_used_crate_file(cstore: &cstore, lib: &istr) {
if !vec::member(lib, p(cstore).used_crate_files) {
p(cstore).used_crate_files += [lib];
}
}
fn get_used_crate_files(cstore: &cstore) -> [str] {
fn get_used_crate_files(cstore: &cstore) -> [istr] {
ret p(cstore).used_crate_files;
}
fn add_used_library(cstore: &cstore, lib: &str) -> bool {
if lib == "" { ret false; }
fn add_used_library(cstore: &cstore, lib: &istr) -> bool {
if lib == ~"" { ret false; }
if vec::member(lib, p(cstore).used_libraries) { ret false; }
@ -101,15 +102,15 @@ fn add_used_library(cstore: &cstore, lib: &str) -> bool {
ret true;
}
fn get_used_libraries(cstore: &cstore) -> [str] {
fn get_used_libraries(cstore: &cstore) -> [istr] {
ret p(cstore).used_libraries;
}
fn add_used_link_args(cstore: &cstore, args: &str) {
p(cstore).used_link_args += str::split(args, ' ' as u8);
fn add_used_link_args(cstore: &cstore, args: &istr) {
p(cstore).used_link_args += istr::split(args, ' ' as u8);
}
fn get_used_link_args(cstore: &cstore) -> [str] {
fn get_used_link_args(cstore: &cstore) -> [istr] {
ret p(cstore).used_link_args;
}

View File

@ -84,9 +84,9 @@ fn item_family(item: &ebml::doc) -> u8 {
ret ebml::doc_as_uint(fam) as u8;
}
fn item_symbol(item: &ebml::doc) -> str {
fn item_symbol(item: &ebml::doc) -> istr {
let sym = ebml::get_doc(item, tag_items_data_item_symbol);
ret str::unsafe_from_bytes(ebml::doc_data(sym));
ret istr::unsafe_from_bytes(ebml::doc_data(sym));
}
fn variant_tag_id(d: &ebml::doc) -> ast::def_id {
@ -97,9 +97,9 @@ fn variant_tag_id(d: &ebml::doc) -> ast::def_id {
fn item_type(item: &ebml::doc, this_cnum: ast::crate_num, tcx: ty::ctxt,
extres: &external_resolver) -> ty::t {
fn parse_external_def_id(this_cnum: ast::crate_num,
extres: &external_resolver, s: str) ->
extres: &external_resolver, s: &istr) ->
ast::def_id {
let buf = str::bytes(s);
let buf = istr::bytes(s);
let external_def_id = parse_def_id(buf);
@ -150,16 +150,16 @@ fn tag_variant_ids(item: &ebml::doc, this_cnum: ast::crate_num) ->
// Given a path and serialized crate metadata, returns the ID of the
// definition the path refers to.
fn resolve_path(path: &[ast::ident], data: @[u8]) -> [ast::def_id] {
fn eq_item(data: &[u8], s: str) -> bool {
ret str::eq(str::unsafe_from_bytes(data), s);
fn eq_item(data: &[u8], s: &istr) -> bool {
ret istr::eq(istr::unsafe_from_bytes(data), s);
}
let s = istr::to_estr(istr::connect(path, ~"::"));
let s = istr::connect(path, ~"::");
let md = ebml::new_doc(data);
let paths = ebml::get_doc(md, tag_paths);
let eqer = bind eq_item(_, s);
let result: [ast::def_id] = [];
for doc: ebml::doc in lookup_hash(paths, eqer,
hash_path(istr::from_estr(s))) {
hash_path(s)) {
let did_doc = ebml::get_doc(doc, tag_def_id);
result += [parse_def_id(ebml::doc_data(did_doc))];
}
@ -223,7 +223,7 @@ fn get_type_param_kinds(data: @[u8], id: ast::node_id) -> [ast::kind] {
ret item_ty_param_kinds(lookup_item(id, data));
}
fn get_symbol(data: @[u8], id: ast::node_id) -> str {
fn get_symbol(data: @[u8], id: ast::node_id) -> istr {
ret item_symbol(lookup_item(id, data));
}
@ -269,31 +269,31 @@ fn family_has_type_params(fam_ch: u8) -> bool {
};
}
fn read_path(d: &ebml::doc) -> {path: str, pos: uint} {
fn read_path(d: &ebml::doc) -> {path: istr, pos: uint} {
let desc = ebml::doc_data(d);
let pos = ebml::be_uint_from_bytes(@desc, 0u, 4u);
let pathbytes = vec::slice::<u8>(desc, 4u, vec::len::<u8>(desc));
let path = str::unsafe_from_bytes(pathbytes);
let path = istr::unsafe_from_bytes(pathbytes);
ret {path: path, pos: pos};
}
fn describe_def(items: &ebml::doc, id: ast::def_id) -> str {
if id.crate != ast::local_crate { ret "external"; }
fn describe_def(items: &ebml::doc, id: ast::def_id) -> istr {
if id.crate != ast::local_crate { ret ~"external"; }
ret item_family_to_str(item_family(find_item(id.node, items)));
}
fn item_family_to_str(fam: u8) -> str {
fn item_family_to_str(fam: u8) -> istr {
alt fam as char {
'c' { ret "const"; }
'f' { ret "fn"; }
'p' { ret "pure fn"; }
'F' { ret "native fn"; }
'y' { ret "type"; }
'T' { ret "native type"; }
't' { ret "type"; }
'm' { ret "mod"; }
'n' { ret "native mod"; }
'v' { ret "tag"; }
'c' { ret ~"const"; }
'f' { ret ~"fn"; }
'p' { ret ~"pure fn"; }
'F' { ret ~"native fn"; }
'y' { ret ~"type"; }
'T' { ret ~"native type"; }
't' { ret ~"type"; }
'm' { ret ~"mod"; }
'n' { ret ~"native mod"; }
'v' { ret ~"tag"; }
}
}
@ -368,7 +368,7 @@ fn get_crate_attributes(data: @[u8]) -> [ast::attribute] {
ret get_attributes(ebml::new_doc(data));
}
type crate_dep = {cnum: ast::crate_num, ident: str};
type crate_dep = {cnum: ast::crate_num, ident: istr};
fn get_crate_deps(data: @[u8]) -> [crate_dep] {
let deps: [crate_dep] = [];
@ -376,7 +376,7 @@ fn get_crate_deps(data: @[u8]) -> [crate_dep] {
let depsdoc = ebml::get_doc(cratedoc, tag_crate_deps);
let crate_num = 1;
for each depdoc: ebml::doc in ebml::tagged_docs(depsdoc, tag_crate_dep) {
let depname = str::unsafe_from_bytes(ebml::doc_data(depdoc));
let depname = istr::unsafe_from_bytes(ebml::doc_data(depdoc));
deps += [{cnum: crate_num, ident: depname}];
crate_num += 1;
}
@ -388,7 +388,8 @@ fn list_crate_deps(data: @[u8], out: io::writer) {
for dep: crate_dep in get_crate_deps(data) {
out.write_str(
istr::from_estr(#fmt["%d %s\n", dep.cnum, dep.ident]));
istr::from_estr(#fmt["%d %s\n", dep.cnum,
istr::to_estr(dep.ident)]));
}
out.write_str(~"\n");
@ -409,8 +410,10 @@ fn list_crate_items(bytes: &@[u8], md: &ebml::doc, out: io::writer) {
let did_doc = ebml::get_doc(def, tag_def_id);
let did = parse_def_id(ebml::doc_data(did_doc));
out.write_str(
istr::from_estr(#fmt["%s (%s)\n", data.path,
describe_def(items, did)]));
istr::from_estr(
#fmt["%s (%s)\n",
istr::to_estr(data.path),
istr::to_estr(describe_def(items, did))]));
}
}
out.write_str(~"\n");

View File

@ -35,7 +35,7 @@ fn encode_name(ebml_w: &ebml::writer, name: &istr) {
fn encode_def_id(ebml_w: &ebml::writer, id: &def_id) {
ebml::start_tag(ebml_w, tag_def_id);
ebml_w.writer.write(str::bytes(def_to_str(id)));
ebml_w.writer.write(istr::bytes(def_to_str(id)));
ebml::end_tag(ebml_w);
}
@ -177,7 +177,9 @@ fn encode_inlineness(ebml_w: &ebml::writer, c: u8) {
ebml::end_tag(ebml_w);
}
fn def_to_str(did: &def_id) -> str { ret #fmt["%d:%d", did.crate, did.node]; }
fn def_to_str(did: &def_id) -> istr {
ret istr::from_estr(#fmt["%d:%d", did.crate, did.node]);
}
fn encode_type_param_kinds(ebml_w: &ebml::writer, tps: &[ty_param]) {
ebml::start_tag(ebml_w, tag_items_data_item_ty_param_kinds);
@ -196,7 +198,7 @@ fn encode_type_param_kinds(ebml_w: &ebml::writer, tps: &[ty_param]) {
fn encode_variant_id(ebml_w: &ebml::writer, vid: &def_id) {
ebml::start_tag(ebml_w, tag_items_data_item_variant);
ebml_w.writer.write(str::bytes(def_to_str(vid)));
ebml_w.writer.write(istr::bytes(def_to_str(vid)));
ebml::end_tag(ebml_w);
}
@ -226,7 +228,7 @@ fn encode_discriminant(ecx: &@encode_ctxt, ebml_w: &ebml::writer,
fn encode_tag_id(ebml_w: &ebml::writer, id: &def_id) {
ebml::start_tag(ebml_w, tag_items_data_item_tag_id);
ebml_w.writer.write(str::bytes(def_to_str(id)));
ebml_w.writer.write(istr::bytes(def_to_str(id)));
ebml::end_tag(ebml_w);
}
@ -550,9 +552,9 @@ fn synthesize_link_attr(ecx: &@encode_ctxt, items: &[@meta_item]) ->
fn encode_crate_deps(ebml_w: &ebml::writer, cstore: &cstore::cstore) {
fn get_ordered_names(cstore: &cstore::cstore) -> [str] {
fn get_ordered_names(cstore: &cstore::cstore) -> [istr] {
type hashkv = @{key: crate_num, val: cstore::crate_metadata};
type numname = {crate: crate_num, ident: str};
type numname = {crate: crate_num, ident: istr};
// Pull the cnums and names out of cstore
let pairs: [mutable numname] = [mutable];
@ -574,7 +576,7 @@ fn lteq(kv1: &numname, kv2: &numname) -> bool {
}
// Return just the names
fn name(kv: &numname) -> str { kv.ident }
fn name(kv: &numname) -> istr { kv.ident }
// mutable -> immutable hack for vec::map
let immpairs = vec::slice(pairs, 0u, vec::len(pairs));
ret vec::map(name, immpairs);
@ -585,15 +587,15 @@ fn name(kv: &numname) -> str { kv.ident }
// 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);
for cname: str in get_ordered_names(cstore) {
for cname: istr in get_ordered_names(cstore) {
ebml::start_tag(ebml_w, tag_crate_dep);
ebml_w.writer.write(str::bytes(cname));
ebml_w.writer.write(istr::bytes(cname));
ebml::end_tag(ebml_w);
}
ebml::end_tag(ebml_w);
}
fn encode_metadata(cx: &@crate_ctxt, crate: &@crate) -> str {
fn encode_metadata(cx: &@crate_ctxt, crate: &@crate) -> istr {
let abbrevs = map::mk_hashmap(ty::hash_ty, ty::eq_ty);
let ecx = @{ccx: cx, type_abbrevs: abbrevs};
@ -625,7 +627,7 @@ fn encode_metadata(cx: &@crate_ctxt, crate: &@crate) -> str {
// remaining % 4 bytes.
buf_w.write([0u8, 0u8, 0u8, 0u8]);
ret istr::to_estr(string_w.get_str());
ret string_w.get_str();
}
// Get the encoded string for a type

View File

@ -21,7 +21,7 @@
// data buffer. Whatever format you choose should not contain pipe characters.
// Callback to translate defs to strs or back:
type str_def = fn(str) -> ast::def_id;
type str_def = fn(&istr) -> ast::def_id;
type pstate =
{data: @[u8], crate: int, mutable pos: uint, len: uint, tcx: ty::ctxt};
@ -344,8 +344,10 @@ fn parse_mt(st: @pstate, sd: str_def) -> ty::mt {
}
fn parse_def(st: @pstate, sd: str_def) -> ast::def_id {
let def = "";
while peek(st) as char != '|' { def += str::unsafe_from_byte(next(st)); }
let def = ~"";
while peek(st) as char != '|' {
def += istr::unsafe_from_byte(next(st));
}
st.pos = st.pos + 1u;
ret sd(def);
}

View File

@ -21,7 +21,7 @@
type ctxt =
// Def -> str Callback:
// The type context.
{ds: fn(&def_id) -> str, tcx: ty::ctxt, abbrevs: abbrev_ctxt};
{ds: fn(&def_id) -> istr, tcx: ty::ctxt, abbrevs: abbrev_ctxt};
// Compact string representation for ty.t values. API ty_str & parse_from_str.
// Extra parameters are for converting to/from def_ids in the string rep.
@ -117,7 +117,7 @@ fn enc_sty(w: &io::writer, cx: &@ctxt, st: &ty::sty) {
ty::ty_istr. { w.write_char('S'); }
ty::ty_tag(def, tys) {
w.write_str(~"t[");
w.write_str(istr::from_estr(cx.ds(def)));
w.write_str(cx.ds(def));
w.write_char('|');
for t: ty::t in tys { enc_ty(w, cx, t); }
w.write_char(']');
@ -166,7 +166,7 @@ fn enc_sty(w: &io::writer, cx: &@ctxt, st: &ty::sty) {
}
ty::ty_res(def, ty, tps) {
w.write_str(~"r[");
w.write_str(istr::from_estr(cx.ds(def)));
w.write_str(cx.ds(def));
w.write_char('|');
enc_ty(w, cx, ty);
for t: ty::t in tps { enc_ty(w, cx, t); }
@ -178,7 +178,7 @@ fn enc_sty(w: &io::writer, cx: &@ctxt, st: &ty::sty) {
}
ty::ty_native(def) {
w.write_char('E');
w.write_str(istr::from_estr(cx.ds(def)));
w.write_str(cx.ds(def));
w.write_char('|');
}
ty::ty_param(id, k) {
@ -237,7 +237,7 @@ fn enc_ty_fn(w: &io::writer, cx: &@ctxt, args: &[ty::arg], out: ty::t,
fn enc_constr(w: &io::writer, cx: &@ctxt, c: &@ty::constr) {
w.write_str(istr::from_estr(path_to_str(c.node.path)));
w.write_char('(');
w.write_str(istr::from_estr(cx.ds(c.node.id)));
w.write_str(cx.ds(c.node.id));
w.write_char('|');
let semi = false;
for a: @constr_arg in c.node.args {
@ -256,7 +256,7 @@ fn enc_constr(w: &io::writer, cx: &@ctxt, c: &@ty::constr) {
fn enc_ty_constr(w: &io::writer, cx: &@ctxt, c: &@ty::type_constr) {
w.write_str(istr::from_estr(path_to_str(c.node.path)));
w.write_char('(');
w.write_str(istr::from_estr(cx.ds(c.node.id)));
w.write_str(cx.ds(c.node.id));
w.write_char('|');
let semi = false;
for a: @ty::ty_constr_arg in c.node.args {

View File

@ -3290,7 +3290,7 @@ fn trans_external_path(cx: &@block_ctxt, did: &ast::def_id,
let lcx = cx.fcx.lcx;
let name = csearch::get_symbol(lcx.ccx.sess.get_cstore(), did);
ret get_extern_const(lcx.ccx.externs, lcx.ccx.llmod,
istr::from_estr(name),
name,
type_of_ty_param_kinds_and_ty(lcx, cx.sp, tpt));
}
@ -3331,7 +3331,7 @@ fn lookup_discriminant(lcx: &@local_ctxt, vid: &ast::def_id) -> ValueRef {
// It's an external discriminant that we haven't seen yet.
assert (vid.crate != ast::local_crate);
let sym = csearch::get_symbol(lcx.ccx.sess.get_cstore(), vid);
let gvar = istr::as_buf(istr::from_estr(sym), { |buf|
let gvar = istr::as_buf(sym, { |buf|
llvm::LLVMAddGlobal(lcx.ccx.llmod, T_int(), buf)
});
llvm::LLVMSetLinkage(gvar,
@ -6350,8 +6350,9 @@ fn create_crate_map(ccx: &@crate_ctxt) -> ValueRef {
let i = 1;
let cstore = ccx.sess.get_cstore();
while cstore::have_crate_data(cstore, i) {
let nm = "_rust_crate_map_" + cstore::get_crate_data(cstore, i).name;
let cr = istr::as_buf(istr::from_estr(nm), { |buf|
let nm = ~"_rust_crate_map_" +
cstore::get_crate_data(cstore, i).name;
let cr = istr::as_buf(nm, { |buf|
llvm::LLVMAddGlobal(ccx.llmod, T_int(), buf)
});
subcrates += [p2i(cr)];
@ -6379,7 +6380,7 @@ fn create_crate_map(ccx: &@crate_ctxt) -> ValueRef {
fn write_metadata(cx: &@crate_ctxt, crate: &@ast::crate) {
if !cx.sess.get_opts().library { ret; }
let llmeta = C_postr(
istr::from_estr(metadata::encoder::encode_metadata(cx, crate)));
metadata::encoder::encode_metadata(cx, crate));
let llconst = trans_common::C_struct([llmeta]);
let llglobal = istr::as_buf(~"rust_metadata", { |buf|
llvm::LLVMAddGlobal(cx.llmod, val_ty(llconst), buf)

View File

@ -354,9 +354,9 @@ fn get_res_dtor(ccx: &@crate_ctxt, sp: &span, did: &ast::def_id,
[{mode: ty::mo_alias(false), ty: inner_t}],
ty::mk_nil(ccx.tcx), params);
ret trans::get_extern_const(ccx.externs, ccx.llmod,
istr::from_estr(csearch::get_symbol(
csearch::get_symbol(
ccx.sess.get_cstore(),
did)),
did),
T_fn_pair(*ccx, f_t));
}