libsyntax and librustc: minor cleanup
This commit is contained in:
parent
1a5b8e4aba
commit
27e235b64a
4 changed files with 11 additions and 16 deletions
|
@ -62,7 +62,7 @@ pub fn anon_src() -> ~str { ~"<anon>" }
|
||||||
|
|
||||||
pub fn source_name(input: input) -> ~str {
|
pub fn source_name(input: input) -> ~str {
|
||||||
match input {
|
match input {
|
||||||
file_input(ref ifile) => (*ifile).to_str(),
|
file_input(ref ifile) => ifile.to_str(),
|
||||||
str_input(_) => anon_src()
|
str_input(_) => anon_src()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,9 +112,9 @@ pub fn default_configuration(sess: Session, +argv0: ~str, input: input) ->
|
||||||
pub fn append_configuration(+cfg: ast::crate_cfg, +name: ~str)
|
pub fn append_configuration(+cfg: ast::crate_cfg, +name: ~str)
|
||||||
-> ast::crate_cfg {
|
-> ast::crate_cfg {
|
||||||
if attr::contains_name(cfg, name) {
|
if attr::contains_name(cfg, name) {
|
||||||
return cfg;
|
cfg
|
||||||
} else {
|
} else {
|
||||||
return vec::append_one(cfg, attr::mk_word_item(name));
|
vec::append_one(cfg, attr::mk_word_item(name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1124,7 +1124,7 @@ fn encode_crate_deps(ecx: @encode_ctxt,
|
||||||
type numdep = decoder::crate_dep;
|
type numdep = decoder::crate_dep;
|
||||||
|
|
||||||
// Pull the cnums and name,vers,hash out of cstore
|
// Pull the cnums and name,vers,hash out of cstore
|
||||||
let mut deps: ~[numdep] = ~[];
|
let mut deps = ~[];
|
||||||
do cstore::iter_crate_data(cstore) |key, val| {
|
do cstore::iter_crate_data(cstore) |key, val| {
|
||||||
let dep = {cnum: key,
|
let dep = {cnum: key,
|
||||||
name: ecx.tcx.sess.ident_of(/*bad*/copy val.name),
|
name: ecx.tcx.sess.ident_of(/*bad*/copy val.name),
|
||||||
|
@ -1134,10 +1134,7 @@ fn encode_crate_deps(ecx: @encode_ctxt,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Sort by cnum
|
// Sort by cnum
|
||||||
pure fn lteq(kv1: &numdep, kv2: &numdep) -> bool {
|
std::sort::quick_sort(deps, |kv1, kv2| kv1.cnum <= kv2.cnum);
|
||||||
kv1.cnum <= kv2.cnum
|
|
||||||
}
|
|
||||||
std::sort::quick_sort(deps, lteq);
|
|
||||||
|
|
||||||
// Sanity-check the crate numbers
|
// Sanity-check the crate numbers
|
||||||
let mut expected_cnum = 1;
|
let mut expected_cnum = 1;
|
||||||
|
@ -1147,7 +1144,7 @@ fn encode_crate_deps(ecx: @encode_ctxt,
|
||||||
}
|
}
|
||||||
|
|
||||||
// mut -> immutable hack for vec::map
|
// mut -> immutable hack for vec::map
|
||||||
return vec::slice(deps, 0u, vec::len(deps)).to_vec();
|
deps.slice(0, deps.len())
|
||||||
}
|
}
|
||||||
|
|
||||||
// We're just going to write a list of crate 'name-hash-version's, with
|
// We're just going to write a list of crate 'name-hash-version's, with
|
||||||
|
|
|
@ -267,7 +267,7 @@ pub fn sort_meta_items(+items: ~[@ast::meta_item]) -> ~[@ast::meta_item] {
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is sort of stupid here, converting to a vec of mutables and back
|
// This is sort of stupid here, converting to a vec of mutables and back
|
||||||
let mut v: ~[@ast::meta_item] = items;
|
let mut v = items;
|
||||||
std::sort::quick_sort(v, lteq);
|
std::sort::quick_sort(v, lteq);
|
||||||
|
|
||||||
// There doesn't seem to be a more optimal way to do this
|
// There doesn't seem to be a more optimal way to do this
|
||||||
|
@ -371,7 +371,7 @@ pub fn require_unique_names(diagnostic: span_handler,
|
||||||
let name = get_meta_item_name(*meta);
|
let name = get_meta_item_name(*meta);
|
||||||
|
|
||||||
// FIXME: How do I silence the warnings? --pcw (#2619)
|
// FIXME: How do I silence the warnings? --pcw (#2619)
|
||||||
if !set.insert(name) {
|
if !set.insert(copy name) {
|
||||||
diagnostic.span_fatal(meta.span,
|
diagnostic.span_fatal(meta.span,
|
||||||
fmt!("duplicate meta item `%s`", name));
|
fmt!("duplicate meta item `%s`", name));
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ use core::prelude::*;
|
||||||
use ast::{crate, expr_, expr_mac, mac_invoc_tt};
|
use ast::{crate, expr_, expr_mac, mac_invoc_tt};
|
||||||
use ast::{tt_delim, tt_tok, item_mac, stmt_, stmt_mac, stmt_expr, stmt_semi};
|
use ast::{tt_delim, tt_tok, item_mac, stmt_, stmt_mac, stmt_expr, stmt_semi};
|
||||||
use ast;
|
use ast;
|
||||||
|
use attr;
|
||||||
use codemap::{span, ExpandedFrom};
|
use codemap::{span, ExpandedFrom};
|
||||||
use ext::base::*;
|
use ext::base::*;
|
||||||
use fold::*;
|
use fold::*;
|
||||||
|
@ -99,11 +100,8 @@ pub fn expand_mod_items(exts: HashMap<~str, SyntaxExtension>, cx: ext_ctxt,
|
||||||
// the item into a new set of items.
|
// the item into a new set of items.
|
||||||
let new_items = do vec::flat_map(module_.items) |item| {
|
let new_items = do vec::flat_map(module_.items) |item| {
|
||||||
do vec::foldr(item.attrs, ~[*item]) |attr, items| {
|
do vec::foldr(item.attrs, ~[*item]) |attr, items| {
|
||||||
let mname = match attr.node.value.node {
|
let mname = attr::get_attr_name(attr);
|
||||||
ast::meta_word(ref n) => (*n),
|
|
||||||
ast::meta_name_value(ref n, _) => (*n),
|
|
||||||
ast::meta_list(ref n, _) => (*n)
|
|
||||||
};
|
|
||||||
match exts.find(&mname) {
|
match exts.find(&mname) {
|
||||||
None | Some(NormalTT(_)) | Some(ItemTT(*)) => items,
|
None | Some(NormalTT(_)) | Some(ItemTT(*)) => items,
|
||||||
Some(ItemDecorator(dec_fn)) => {
|
Some(ItemDecorator(dec_fn)) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue