librustc: convert creader and cstore to use @~strs
This commit is contained in:
parent
a18e7d6656
commit
3c0eca7940
src/librustc
@ -64,7 +64,7 @@ pub fn read_crates(diag: span_handler,
|
||||
type cache_entry = {
|
||||
cnum: int,
|
||||
span: span,
|
||||
hash: ~str,
|
||||
hash: @~str,
|
||||
metas: @~[@ast::meta_item]
|
||||
};
|
||||
|
||||
@ -100,7 +100,7 @@ fn warn_if_multiple_versions(e: @mut Env,
|
||||
|
||||
if matches.len() != 1u {
|
||||
diag.handler().warn(
|
||||
fmt!("using multiple versions of crate `%s`", name));
|
||||
fmt!("using multiple versions of crate `%s`", *name));
|
||||
for matches.each |match_| {
|
||||
diag.span_note(match_.span, ~"used here");
|
||||
let attrs = ~[
|
||||
@ -145,7 +145,7 @@ fn visit_view_item(e: @mut Env, i: @ast::view_item) {
|
||||
ast::view_item_extern_mod(ident, meta_items, id) => {
|
||||
debug!("resolving extern mod stmt. ident: %?, meta: %?",
|
||||
ident, meta_items);
|
||||
let cnum = resolve_crate(e, ident, meta_items, ~"", i.span);
|
||||
let cnum = resolve_crate(e, ident, meta_items, @~"", i.span);
|
||||
cstore::add_extern_mod_stmt_cnum(e.cstore, id, cnum);
|
||||
}
|
||||
_ => ()
|
||||
@ -172,21 +172,20 @@ fn visit_item(e: @mut Env, i: @ast::item) {
|
||||
let foreign_name =
|
||||
match attr::first_attr_value_str_by_name(i.attrs,
|
||||
~"link_name") {
|
||||
Some(ref nn) => {
|
||||
if **nn == ~"" {
|
||||
Some(nn) => {
|
||||
if *nn == ~"" {
|
||||
e.diag.span_fatal(
|
||||
i.span,
|
||||
~"empty #[link_name] not allowed; use " +
|
||||
~"#[nolink].");
|
||||
}
|
||||
/*bad*/copy *nn
|
||||
nn
|
||||
}
|
||||
None => @/*bad*/copy *e.intr.get(i.ident)
|
||||
None => e.intr.get(i.ident)
|
||||
};
|
||||
if attr::find_attrs_by_name(i.attrs, ~"nolink").is_empty() {
|
||||
already_added =
|
||||
!cstore::add_used_library(cstore,
|
||||
/*bad*/ copy *foreign_name);
|
||||
!cstore::add_used_library(cstore, foreign_name);
|
||||
}
|
||||
if !link_args.is_empty() && already_added {
|
||||
e.diag.span_fatal(i.span, ~"library '" + *foreign_name +
|
||||
@ -198,8 +197,8 @@ fn visit_item(e: @mut Env, i: @ast::item) {
|
||||
|
||||
for link_args.each |a| {
|
||||
match attr::get_meta_item_value_str(attr::attr_meta(*a)) {
|
||||
Some(ref linkarg) => {
|
||||
cstore::add_used_link_args(cstore, /*bad*/copy **linkarg);
|
||||
Some(linkarg) => {
|
||||
cstore::add_used_link_args(cstore, *linkarg);
|
||||
}
|
||||
None => { /* fallthrough */ }
|
||||
}
|
||||
@ -209,22 +208,22 @@ fn visit_item(e: @mut Env, i: @ast::item) {
|
||||
}
|
||||
}
|
||||
|
||||
fn metas_with(+ident: ~str, +key: ~str, +metas: ~[@ast::meta_item])
|
||||
fn metas_with(ident: @~str, key: @~str, +metas: ~[@ast::meta_item])
|
||||
-> ~[@ast::meta_item] {
|
||||
let name_items = attr::find_meta_items_by_name(metas, key);
|
||||
let name_items = attr::find_meta_items_by_name(metas, *key);
|
||||
if name_items.is_empty() {
|
||||
vec::append_one(metas, attr::mk_name_value_item_str(@key, @ident))
|
||||
vec::append_one(metas, attr::mk_name_value_item_str(key, ident))
|
||||
} else {
|
||||
metas
|
||||
}
|
||||
}
|
||||
|
||||
fn metas_with_ident(+ident: ~str, +metas: ~[@ast::meta_item])
|
||||
fn metas_with_ident(ident: @~str, +metas: ~[@ast::meta_item])
|
||||
-> ~[@ast::meta_item] {
|
||||
metas_with(ident, ~"name", metas)
|
||||
metas_with(ident, @~"name", metas)
|
||||
}
|
||||
|
||||
fn existing_match(e: @mut Env, metas: ~[@ast::meta_item], hash: ~str)
|
||||
fn existing_match(e: @mut Env, metas: ~[@ast::meta_item], hash: @~str)
|
||||
-> Option<int> {
|
||||
for e.crate_cache.each |c| {
|
||||
if loader::metadata_matches(*c.metas, metas)
|
||||
@ -238,10 +237,10 @@ fn existing_match(e: @mut Env, metas: ~[@ast::meta_item], hash: ~str)
|
||||
fn resolve_crate(e: @mut Env,
|
||||
ident: ast::ident,
|
||||
+metas: ~[@ast::meta_item],
|
||||
+hash: ~str,
|
||||
hash: @~str,
|
||||
span: span)
|
||||
-> ast::crate_num {
|
||||
let metas = metas_with_ident(/*bad*/copy *e.intr.get(ident), metas);
|
||||
let metas = metas_with_ident(@/*bad*/copy *e.intr.get(ident), metas);
|
||||
|
||||
match existing_match(e, metas, hash) {
|
||||
None => {
|
||||
@ -277,10 +276,10 @@ fn resolve_crate(e: @mut Env,
|
||||
let cname =
|
||||
match attr::last_meta_item_value_str_by_name(load_ctxt.metas,
|
||||
~"name") {
|
||||
Some(ref v) => /*bad*/copy *v,
|
||||
None => @/*bad*/copy *e.intr.get(ident),
|
||||
Some(v) => v,
|
||||
None => e.intr.get(ident),
|
||||
};
|
||||
let cmeta = @{name: /*bad*/copy *cname, data: cdata,
|
||||
let cmeta = @{name: cname, data: cdata,
|
||||
cnum_map: cnum_map, cnum: cnum};
|
||||
|
||||
let cstore = e.cstore;
|
||||
@ -303,10 +302,10 @@ fn resolve_crate_deps(e: @mut Env, cdata: @~[u8]) -> cstore::cnum_map {
|
||||
for decoder::get_crate_deps(e.intr, cdata).each |dep| {
|
||||
let extrn_cnum = dep.cnum;
|
||||
let cname = dep.name;
|
||||
let cmetas = metas_with(/*bad*/copy dep.vers, ~"vers", ~[]);
|
||||
let cmetas = metas_with(dep.vers, @~"vers", ~[]);
|
||||
debug!("resolving dep crate %s ver: %s hash: %s",
|
||||
*e.intr.get(dep.name), dep.vers, dep.hash);
|
||||
match existing_match(e, metas_with_ident(copy *e.intr.get(cname),
|
||||
*e.intr.get(dep.name), *dep.vers, *dep.hash);
|
||||
match existing_match(e, metas_with_ident(e.intr.get(cname),
|
||||
copy cmetas),
|
||||
dep.hash) {
|
||||
Some(local_cnum) => {
|
||||
@ -320,8 +319,8 @@ fn resolve_crate_deps(e: @mut Env, cdata: @~[u8]) -> cstore::cnum_map {
|
||||
// FIXME (#2404): Need better error reporting than just a bogus
|
||||
// span.
|
||||
let fake_span = dummy_sp();
|
||||
let local_cnum = resolve_crate(e, cname, cmetas,
|
||||
/*bad*/copy dep.hash, fake_span);
|
||||
let local_cnum = resolve_crate(e, cname, cmetas, dep.hash,
|
||||
fake_span);
|
||||
cnum_map.insert(extrn_cnum, local_cnum);
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ pub fn get_item_path(tcx: ty::ctxt, def: ast::def_id) -> ast_map::path {
|
||||
// FIXME #1920: This path is not always correct if the crate is not linked
|
||||
// into the root namespace.
|
||||
vec::append(~[ast_map::path_mod(tcx.sess.ident_of(
|
||||
/*bad*/copy cdata.name))], path)
|
||||
/*bad*/copy *cdata.name))], path)
|
||||
}
|
||||
|
||||
pub enum found_ast {
|
||||
|
@ -33,7 +33,7 @@ use syntax::parse::token::ident_interner;
|
||||
// own crate numbers.
|
||||
pub type cnum_map = oldmap::HashMap<ast::crate_num, ast::crate_num>;
|
||||
|
||||
pub type crate_metadata = @{name: ~str,
|
||||
pub type crate_metadata = @{name: @~str,
|
||||
data: @~[u8],
|
||||
cnum_map: cnum_map,
|
||||
cnum: ast::crate_num};
|
||||
@ -68,12 +68,12 @@ pub fn get_crate_data(cstore: @mut CStore, cnum: ast::crate_num)
|
||||
return cstore.metas.get(&cnum);
|
||||
}
|
||||
|
||||
pub fn get_crate_hash(cstore: @mut CStore, cnum: ast::crate_num) -> ~str {
|
||||
pub fn get_crate_hash(cstore: @mut CStore, cnum: ast::crate_num) -> @~str {
|
||||
let cdata = get_crate_data(cstore, cnum);
|
||||
decoder::get_crate_hash(cdata.data)
|
||||
}
|
||||
|
||||
pub fn get_crate_vers(cstore: @mut CStore, cnum: ast::crate_num) -> ~str {
|
||||
pub fn get_crate_vers(cstore: @mut CStore, cnum: ast::crate_num) -> @~str {
|
||||
let cdata = get_crate_data(cstore, cnum);
|
||||
decoder::get_crate_vers(cdata.data)
|
||||
}
|
||||
@ -107,11 +107,11 @@ pub fn get_used_crate_files(cstore: @mut CStore) -> ~[Path] {
|
||||
return /*bad*/copy cstore.used_crate_files;
|
||||
}
|
||||
|
||||
pub fn add_used_library(cstore: @mut CStore, +lib: ~str) -> bool {
|
||||
assert lib != ~"";
|
||||
pub fn add_used_library(cstore: @mut CStore, lib: @~str) -> bool {
|
||||
assert *lib != ~"";
|
||||
|
||||
if cstore.used_libraries.contains(&lib) { return false; }
|
||||
cstore.used_libraries.push(lib);
|
||||
if cstore.used_libraries.contains(&*lib) { return false; }
|
||||
cstore.used_libraries.push(/*bad*/ copy *lib);
|
||||
true
|
||||
}
|
||||
|
||||
@ -151,7 +151,7 @@ pub fn get_dep_hashes(cstore: @mut CStore) -> ~[~str] {
|
||||
for extern_mod_crate_map.each_value |&cnum| {
|
||||
let cdata = cstore::get_crate_data(cstore, cnum);
|
||||
let hash = decoder::get_crate_hash(cdata.data);
|
||||
debug!("Add hash[%s]: %s", cdata.name, hash);
|
||||
debug!("Add hash[%s]: %s", *cdata.name, *hash);
|
||||
result.push({name: /*bad*/copy cdata.name, hash: hash});
|
||||
}
|
||||
|
||||
@ -159,10 +159,10 @@ pub fn get_dep_hashes(cstore: @mut CStore) -> ~[~str] {
|
||||
|
||||
debug!("sorted:");
|
||||
for sorted.each |x| {
|
||||
debug!(" hash[%s]: %s", x.name, x.hash);
|
||||
debug!(" hash[%s]: %s", *x.name, *x.hash);
|
||||
}
|
||||
|
||||
sorted.map(|ch| /*bad*/copy ch.hash)
|
||||
sorted.map(|ch| /*bad*/copy *ch.hash)
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
|
@ -1015,7 +1015,7 @@ fn list_meta_items(intr: @ident_interner,
|
||||
}
|
||||
}
|
||||
|
||||
fn list_crate_attributes(intr: @ident_interner, md: ebml::Doc, hash: ~str,
|
||||
fn list_crate_attributes(intr: @ident_interner, md: ebml::Doc, hash: &str,
|
||||
out: io::Writer) {
|
||||
out.write_str(fmt!("=Crate Attributes (%s)=\n", hash));
|
||||
|
||||
@ -1031,7 +1031,7 @@ pub fn get_crate_attributes(data: @~[u8]) -> ~[ast::attribute] {
|
||||
}
|
||||
|
||||
pub type crate_dep = {cnum: ast::crate_num, name: ast::ident,
|
||||
vers: ~str, hash: ~str};
|
||||
vers: @~str, hash: @~str};
|
||||
|
||||
pub fn get_crate_deps(intr: @ident_interner, data: @~[u8]) -> ~[crate_dep] {
|
||||
let mut deps: ~[crate_dep] = ~[];
|
||||
@ -1044,8 +1044,8 @@ pub fn get_crate_deps(intr: @ident_interner, data: @~[u8]) -> ~[crate_dep] {
|
||||
for reader::tagged_docs(depsdoc, tag_crate_dep) |depdoc| {
|
||||
deps.push({cnum: crate_num,
|
||||
name: intr.intern(@docstr(depdoc, tag_crate_dep_name)),
|
||||
vers: docstr(depdoc, tag_crate_dep_vers),
|
||||
hash: docstr(depdoc, tag_crate_dep_hash)});
|
||||
vers: @docstr(depdoc, tag_crate_dep_vers),
|
||||
hash: @docstr(depdoc, tag_crate_dep_hash)});
|
||||
crate_num += 1;
|
||||
};
|
||||
return deps;
|
||||
@ -1057,25 +1057,25 @@ fn list_crate_deps(intr: @ident_interner, data: @~[u8], out: io::Writer) {
|
||||
for get_crate_deps(intr, data).each |dep| {
|
||||
out.write_str(
|
||||
fmt!("%d %s-%s-%s\n",
|
||||
dep.cnum, *intr.get(dep.name), dep.hash, dep.vers));
|
||||
dep.cnum, *intr.get(dep.name), *dep.hash, *dep.vers));
|
||||
}
|
||||
|
||||
out.write_str(~"\n");
|
||||
}
|
||||
|
||||
pub fn get_crate_hash(data: @~[u8]) -> ~str {
|
||||
pub fn get_crate_hash(data: @~[u8]) -> @~str {
|
||||
let cratedoc = reader::Doc(data);
|
||||
let hashdoc = reader::get_doc(cratedoc, tag_crate_hash);
|
||||
str::from_bytes(reader::doc_data(hashdoc))
|
||||
@str::from_bytes(reader::doc_data(hashdoc))
|
||||
}
|
||||
|
||||
pub fn get_crate_vers(data: @~[u8]) -> ~str {
|
||||
pub fn get_crate_vers(data: @~[u8]) -> @~str {
|
||||
let attrs = decoder::get_crate_attributes(data);
|
||||
let linkage_attrs = attr::find_linkage_metas(attrs);
|
||||
|
||||
match attr::last_meta_item_value_str_by_name(linkage_attrs, ~"vers") {
|
||||
Some(ref ver) => /*bad*/copy **ver,
|
||||
None => ~"0.0"
|
||||
Some(ver) => ver,
|
||||
None => @~"0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1097,7 +1097,7 @@ pub fn list_crate_metadata(intr: @ident_interner, bytes: @~[u8],
|
||||
out: io::Writer) {
|
||||
let hash = get_crate_hash(bytes);
|
||||
let md = reader::Doc(bytes);
|
||||
list_crate_attributes(intr, md, hash, out);
|
||||
list_crate_attributes(intr, md, *hash, out);
|
||||
list_crate_deps(intr, bytes, out);
|
||||
}
|
||||
|
||||
|
@ -1127,7 +1127,7 @@ fn encode_crate_deps(ecx: @encode_ctxt,
|
||||
let mut deps = ~[];
|
||||
do cstore::iter_crate_data(cstore) |key, val| {
|
||||
let dep = {cnum: key,
|
||||
name: ecx.tcx.sess.ident_of(/*bad*/ copy val.name),
|
||||
name: ecx.tcx.sess.ident_of(/*bad*/ copy *val.name),
|
||||
vers: decoder::get_crate_vers(val.data),
|
||||
hash: decoder::get_crate_hash(val.data)};
|
||||
deps.push(dep);
|
||||
@ -1189,10 +1189,10 @@ fn encode_crate_dep(ecx: @encode_ctxt, ebml_w: writer::Encoder,
|
||||
ebml_w.writer.write(str::to_bytes(ecx.tcx.sess.str_of(dep.name)));
|
||||
ebml_w.end_tag();
|
||||
ebml_w.start_tag(tag_crate_dep_vers);
|
||||
ebml_w.writer.write(str::to_bytes(dep.vers));
|
||||
ebml_w.writer.write(str::to_bytes(*dep.vers));
|
||||
ebml_w.end_tag();
|
||||
ebml_w.start_tag(tag_crate_dep_hash);
|
||||
ebml_w.writer.write(str::to_bytes(dep.hash));
|
||||
ebml_w.writer.write(str::to_bytes(*dep.hash));
|
||||
ebml_w.end_tag();
|
||||
ebml_w.end_tag();
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ pub type ctxt = {
|
||||
span: span,
|
||||
ident: ast::ident,
|
||||
metas: ~[@ast::meta_item],
|
||||
hash: ~str,
|
||||
hash: @~str,
|
||||
os: os,
|
||||
static: bool,
|
||||
intr: @ident_interner
|
||||
@ -91,7 +91,7 @@ fn find_library_crate_aux(cx: ctxt,
|
||||
filesearch: filesearch::FileSearch) ->
|
||||
Option<{ident: ~str, data: @~[u8]}> {
|
||||
let crate_name = crate_name_from_metas(/*bad*/copy cx.metas);
|
||||
let prefix: ~str = nn.prefix + crate_name + ~"-";
|
||||
let prefix: ~str = nn.prefix + *crate_name + ~"-";
|
||||
let suffix: ~str = /*bad*/copy nn.suffix;
|
||||
|
||||
let mut matches = ~[];
|
||||
@ -130,7 +130,7 @@ fn find_library_crate_aux(cx: ctxt,
|
||||
Some(/*bad*/copy matches[0])
|
||||
} else {
|
||||
cx.diag.span_err(
|
||||
cx.span, fmt!("multiple matching crates for `%s`", crate_name));
|
||||
cx.span, fmt!("multiple matching crates for `%s`", *crate_name));
|
||||
cx.diag.handler().note(~"candidates:");
|
||||
for matches.each |match_| {
|
||||
cx.diag.handler().note(fmt!("path: %s", match_.ident));
|
||||
@ -142,12 +142,12 @@ fn find_library_crate_aux(cx: ctxt,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn crate_name_from_metas(+metas: ~[@ast::meta_item]) -> ~str {
|
||||
pub fn crate_name_from_metas(+metas: &[@ast::meta_item]) -> @~str {
|
||||
let name_items = attr::find_meta_items_by_name(metas, ~"name");
|
||||
match vec::last_opt(name_items) {
|
||||
Some(i) => {
|
||||
match attr::get_meta_item_value_str(i) {
|
||||
Some(ref n) => /*bad*/copy **n,
|
||||
Some(n) => n,
|
||||
// FIXME (#2406): Probably want a warning here since the user
|
||||
// is using the wrong type of meta item.
|
||||
_ => fail!()
|
||||
@ -167,7 +167,7 @@ pub fn note_linkage_attrs(intr: @ident_interner, diag: span_handler,
|
||||
|
||||
fn crate_matches(crate_data: @~[u8],
|
||||
metas: &[@ast::meta_item],
|
||||
hash: ~str) -> bool {
|
||||
hash: @~str) -> bool {
|
||||
let attrs = decoder::get_crate_attributes(crate_data);
|
||||
let linkage_metas = attr::find_linkage_metas(attrs);
|
||||
if !hash.is_empty() {
|
||||
|
@ -2859,9 +2859,9 @@ pub fn fill_crate_map(ccx: @crate_ctxt, map: ValueRef) {
|
||||
let cstore = ccx.sess.cstore;
|
||||
while cstore::have_crate_data(cstore, i) {
|
||||
let cdata = cstore::get_crate_data(cstore, i);
|
||||
let nm = ~"_rust_crate_map_" + cdata.name +
|
||||
~"_" + cstore::get_crate_vers(cstore, i) +
|
||||
~"_" + cstore::get_crate_hash(cstore, i);
|
||||
let nm = ~"_rust_crate_map_" + *cdata.name +
|
||||
~"_" + *cstore::get_crate_vers(cstore, i) +
|
||||
~"_" + *cstore::get_crate_hash(cstore, i);
|
||||
let cr = str::as_c_str(nm, |buf| {
|
||||
unsafe {
|
||||
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf)
|
||||
|
@ -47,10 +47,10 @@ fn abi_info(arch: session::arch) -> cabi::ABIInfo {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn link_name(ccx: @crate_ctxt, i: @ast::foreign_item) -> ~str {
|
||||
pub fn link_name(ccx: @crate_ctxt, i: @ast::foreign_item) -> @~str {
|
||||
match attr::first_attr_value_str_by_name(i.attrs, ~"link_name") {
|
||||
None => ccx.sess.str_of(i.ident),
|
||||
Some(ref ln) => /*bad*/copy **ln,
|
||||
None => @ccx.sess.str_of(i.ident),
|
||||
Some(ln) => ln,
|
||||
}
|
||||
}
|
||||
|
||||
@ -228,18 +228,18 @@ pub fn trans_foreign_mod(ccx: @crate_ctxt,
|
||||
}
|
||||
|
||||
let lname = link_name(ccx, foreign_item);
|
||||
let llbasefn = base_fn(ccx, copy lname, tys, cc);
|
||||
let llbasefn = base_fn(ccx, *lname, tys, cc);
|
||||
// Name the shim function
|
||||
let shim_name = lname + ~"__c_stack_shim";
|
||||
return build_shim_fn_(ccx, shim_name, llbasefn, tys, cc,
|
||||
build_args, build_ret);
|
||||
}
|
||||
|
||||
fn base_fn(ccx: @crate_ctxt, +lname: ~str, tys: @c_stack_tys,
|
||||
fn base_fn(ccx: @crate_ctxt, lname: &str, tys: @c_stack_tys,
|
||||
cc: lib::llvm::CallConv) -> ValueRef {
|
||||
// Declare the "prototype" for the base function F:
|
||||
do tys.fn_ty.decl_fn |fnty| {
|
||||
decl_fn(ccx.llmod, /*bad*/copy lname, cc, fnty)
|
||||
decl_fn(ccx.llmod, lname, cc, fnty)
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,7 +250,7 @@ pub fn trans_foreign_mod(ccx: @crate_ctxt,
|
||||
cc: lib::llvm::CallConv) {
|
||||
let fcx = new_fn_ctxt(ccx, ~[], decl, None);
|
||||
let bcx = top_scope_block(fcx, None), lltop = bcx.llbb;
|
||||
let llbasefn = base_fn(ccx, link_name(ccx, item), tys, cc);
|
||||
let llbasefn = base_fn(ccx, *link_name(ccx, item), tys, cc);
|
||||
let ty = ty::lookup_item_type(ccx.tcx,
|
||||
ast_util::local_def(item.id)).ty;
|
||||
let args = vec::from_fn(ty::ty_fn_args(ty).len(), |i| {
|
||||
|
Loading…
x
Reference in New Issue
Block a user