librustc: minor cleanup

This commit is contained in:
Erick Tryzelaar 2013-02-16 09:48:28 -08:00
parent 53951afe48
commit a18e7d6656
5 changed files with 56 additions and 61 deletions

View File

@ -168,39 +168,40 @@ fn visit_item(e: @mut Env, i: @ast::item) {
let link_args = attr::find_attrs_by_name(i.attrs, "link_args");
match fm.sort {
ast::named => {
let foreign_name =
match attr::first_attr_value_str_by_name(i.attrs,
~"link_name") {
Some(ref nn) => {
if **nn == ~"" {
e.diag.span_fatal(
i.span,
~"empty #[link_name] not allowed; use #[nolink].");
}
(/*bad*/copy *nn)
}
None => @/*bad*/copy *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);
ast::named => {
let foreign_name =
match attr::first_attr_value_str_by_name(i.attrs,
~"link_name") {
Some(ref nn) => {
if **nn == ~"" {
e.diag.span_fatal(
i.span,
~"empty #[link_name] not allowed; use " +
~"#[nolink].");
}
/*bad*/copy *nn
}
None => @/*bad*/copy *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);
}
if !link_args.is_empty() && already_added {
e.diag.span_fatal(i.span, ~"library '" + *foreign_name +
~"' already added: can't specify link_args.");
}
}
if !link_args.is_empty() && already_added {
e.diag.span_fatal(i.span, ~"library '" + *foreign_name +
~"' already added: can't specify link_args.");
}
}
ast::anonymous => { /* do nothing */ }
ast::anonymous => { /* do nothing */ }
}
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);
}
None => {/* fallthrough */ }
Some(ref linkarg) => {
cstore::add_used_link_args(cstore, /*bad*/copy **linkarg);
}
None => { /* fallthrough */ }
}
}
}
@ -276,8 +277,8 @@ fn resolve_crate(e: @mut Env,
let cname =
match attr::last_meta_item_value_str_by_name(load_ctxt.metas,
~"name") {
option::Some(ref v) => (/*bad*/copy *v),
option::None => @/*bad*/copy *e.intr.get(ident)
Some(ref v) => /*bad*/copy *v,
None => @/*bad*/copy *e.intr.get(ident),
};
let cmeta = @{name: /*bad*/copy *cname, data: cdata,
cnum_map: cnum_map, cnum: cnum};

View File

@ -70,12 +70,12 @@ pub fn get_crate_data(cstore: @mut CStore, cnum: ast::crate_num)
pub fn get_crate_hash(cstore: @mut CStore, cnum: ast::crate_num) -> ~str {
let cdata = get_crate_data(cstore, cnum);
return decoder::get_crate_hash(cdata.data);
decoder::get_crate_hash(cdata.data)
}
pub fn get_crate_vers(cstore: @mut CStore, cnum: ast::crate_num) -> ~str {
let cdata = get_crate_data(cstore, cnum);
return decoder::get_crate_vers(cdata.data);
decoder::get_crate_vers(cdata.data)
}
pub fn set_crate_data(cstore: @mut CStore,
@ -110,21 +110,21 @@ pub fn get_used_crate_files(cstore: @mut CStore) -> ~[Path] {
pub fn add_used_library(cstore: @mut CStore, +lib: ~str) -> bool {
assert lib != ~"";
if vec::contains(cstore.used_libraries, &lib) { return false; }
if cstore.used_libraries.contains(&lib) { return false; }
cstore.used_libraries.push(lib);
return true;
true
}
pub fn get_used_libraries(cstore: @mut CStore) -> ~[~str] {
return /*bad*/copy cstore.used_libraries;
/*bad*/copy cstore.used_libraries
}
pub fn add_used_link_args(cstore: @mut CStore, args: &str) {
cstore.used_link_args.push_all(str::split_char(args, ' '));
cstore.used_link_args.push_all(args.split_char(' '));
}
pub fn get_used_link_args(cstore: @mut CStore) -> ~[~str] {
return /*bad*/copy cstore.used_link_args;
/*bad*/copy cstore.used_link_args
}
pub fn add_extern_mod_stmt_cnum(cstore: @mut CStore,
@ -155,21 +155,14 @@ pub fn get_dep_hashes(cstore: @mut CStore) -> ~[~str] {
result.push({name: /*bad*/copy cdata.name, hash: hash});
}
pure fn lteq(a: &crate_hash, b: &crate_hash) -> bool {
a.name <= b.name
}
let sorted = std::sort::merge_sort(result, |a, b| a.name <= b.name);
let sorted = std::sort::merge_sort(result, lteq);
debug!("sorted:");
for sorted.each |x| {
debug!(" hash[%s]: %s", x.name, x.hash);
}
fn mapper(ch: &crate_hash) -> ~str {
return /*bad*/copy ch.hash;
}
return vec::map(sorted, mapper);
sorted.map(|ch| /*bad*/copy ch.hash)
}
// Local Variables:

View File

@ -1066,16 +1066,17 @@ fn list_crate_deps(intr: @ident_interner, data: @~[u8], out: io::Writer) {
pub fn get_crate_hash(data: @~[u8]) -> ~str {
let cratedoc = reader::Doc(data);
let hashdoc = reader::get_doc(cratedoc, tag_crate_hash);
return str::from_bytes(reader::doc_data(hashdoc));
str::from_bytes(reader::doc_data(hashdoc))
}
pub fn get_crate_vers(data: @~[u8]) -> ~str {
let attrs = decoder::get_crate_attributes(data);
return match attr::last_meta_item_value_str_by_name(
attr::find_linkage_metas(attrs), ~"vers") {
Some(ref ver) => (/*bad*/copy **ver),
None => ~"0.0"
};
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"
}
}
fn iter_crate_items(intr: @ident_interner, cdata: cmd,

View File

@ -145,15 +145,15 @@ fn find_library_crate_aux(cx: ctxt,
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,
// FIXME (#2406): Probably want a warning here since the user
// is using the wrong type of meta item.
_ => fail!()
Some(i) => {
match attr::get_meta_item_value_str(i) {
Some(ref n) => /*bad*/copy **n,
// FIXME (#2406): Probably want a warning here since the user
// is using the wrong type of meta item.
_ => fail!()
}
}
}
None => fail!(~"expected to find the crate name")
None => fail!(~"expected to find the crate name")
}
}

View File

@ -50,7 +50,7 @@ fn abi_info(arch: session::arch) -> cabi::ABIInfo {
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),
option::Some(ref ln) => (/*bad*/copy **ln)
Some(ref ln) => /*bad*/copy **ln,
}
}