Move map iface over to more for-friendly iteration methods

This commit is contained in:
Marijn Haverbeke 2012-04-23 13:42:15 +02:00
parent a872a99bfe
commit 9053f54498
18 changed files with 74 additions and 83 deletions

View file

@ -106,7 +106,7 @@ fn have_crate_data(cstore: cstore, cnum: ast::crate_num) -> bool {
}
fn iter_crate_data(cstore: cstore, i: fn(ast::crate_num, crate_metadata)) {
p(cstore).metas.items {|k,v| i(k, v);};
for p(cstore).metas.each {|k,v| i(k, v);};
}
fn add_used_crate_file(cstore: cstore, lib: str) {
@ -155,7 +155,7 @@ fn get_dep_hashes(cstore: cstore) -> [str] {
type crate_hash = {name: str, hash: str};
let mut result = [];
p(cstore).use_crate_map.values {|cnum|
for p(cstore).use_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);

View file

@ -206,7 +206,7 @@ fn encode_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt, crate: @crate)
fn encode_reexport_paths(ebml_w: ebml::writer,
ecx: @encode_ctxt, &index: [entry<str>]) {
let tcx = ecx.ccx.tcx;
ecx.ccx.exp_map.items {|exp_id, defs|
for ecx.ccx.exp_map.each {|exp_id, defs|
for defs.each {|def|
if !def.reexp { cont; }
let path = alt check tcx.items.get(exp_id) {

View file

@ -129,6 +129,6 @@ fn compute_capture_vars(tcx: ty::ctxt,
}
let mut result = [];
cap_map.values { |cap_var| result += [cap_var]; }
for cap_map.each_value { |cap_var| result += [cap_var]; }
ret result;
}

View file

@ -70,7 +70,7 @@ fn find_last_uses(c: @crate, def_map: resolve::def_map,
mut blocks: nil};
visit::visit_crate(*c, cx, v);
let mini_table = std::map::int_hash();
cx.last_uses.items {|key, val|
for cx.last_uses.each {|key, val|
if val {
alt key {
path(id) {

View file

@ -172,7 +172,7 @@ fn time(do_it: bool, what: str, thunk: fn()) {
fn check_item(cx: ctxt, i: @ast::item) {
cx.with_warn_attrs(i.attrs) {|cx|
cx.curr.items {|lint, level|
for cx.curr.each {|lint, level|
alt lint {
ctypes { check_item_ctypes(cx, level, i); }
unused_imports { check_item_unused_imports(cx, level, i); }
@ -265,7 +265,7 @@ fn check_crate(tcx: ty::ctxt, crate: @ast::crate,
tcx: tcx};
// Install defaults.
cx.dict.items {|_k, spec| cx.set_level(spec.lint, spec.default); }
for cx.dict.each {|_k, spec| cx.set_level(spec.lint, spec.default); }
// Install command-line options, overriding defaults.
for lint_opts.each {|pair|

View file

@ -352,7 +352,7 @@ fn map_crate(e: @env, c: @ast::crate) {
fn resolve_imports(e: env) {
e.used_imports.track = true;
e.imports.items {|id, v|
for e.imports.each {|id, v|
alt check v {
todo(name, path, span, scopes) {
resolve_import(e, id, name, *path, span, scopes);
@ -368,7 +368,7 @@ fn resolve_imports(e: env) {
// using lint-specific control flags presently but resolve-specific data
// structures. Should use the general lint framework (with scopes, attrs).
fn check_unused_imports(e: @env, level: lint::level) {
e.imports.items {|k, v|
for e.imports.each {|k, v|
alt v {
resolved(_, _, _, _, name, sp) {
if !vec::contains(e.used_imports.data, k) {
@ -1673,8 +1673,8 @@ fn lookup_external(e: env, cnum: int, ids: [ident], ns: namespace) ->
fn check_for_collisions(e: @env, c: ast::crate) {
// Module indices make checking those relatively simple -- just check each
// name for multiple entities in the same namespace.
e.mod_map.values {|val|
val.index.items {|k, v| check_mod_name(*e, k, v); };
for e.mod_map.each_value {|val|
for val.index.each {|k, v| check_mod_name(*e, k, v); };
};
// Other scopes have to be checked the hard way.
let v =
@ -1912,7 +1912,7 @@ fn check_exports(e: @env) {
assert mid.crate == ast::local_crate;
let ixm = e.mod_map.get(mid.node);
ixm.index.items() {|ident, mies|
for ixm.index.each {|ident, mies|
list::iter(mies) {|mie|
alt mie {
mie_item(item) {
@ -2055,7 +2055,7 @@ fn check_exports(e: @env) {
}
}
e.mod_map.values {|_mod|
for e.mod_map.each_value {|_mod|
alt _mod.m {
some(m) {
let glob_is_re_exported = int_hash();

View file

@ -365,7 +365,7 @@ fn compile_submatch(bcx: block, m: match, vals: [ValueRef],
some(e) {
// Temporarily set bindings. They'll be rewritten to PHI nodes
// for the actual arm block.
data.id_map.items {|key, val|
for data.id_map.each {|key, val|
let loc = local_mem(option::get(assoc(key, m[0].bound)));
bcx.fcx.lllocals.insert(val, loc);
};
@ -565,7 +565,7 @@ fn make_phi_bindings(bcx: block, map: [exit_node],
let _icx = bcx.insn_ctxt("alt::make_phi_bindings");
let our_block = bcx.llbb as uint;
let mut success = true, bcx = bcx;
ids.items {|name, node_id|
for ids.each {|name, node_id|
let mut llbbs = [];
let mut vals = [];
for vec::each(map) {|ex|
@ -583,7 +583,7 @@ fn make_phi_bindings(bcx: block, map: [exit_node],
};
if success {
// Copy references that the alias analysis considered unsafe
ids.values {|node_id|
for ids.each_value {|node_id|
if bcx.ccx().maps.copy_map.contains_key(node_id) {
let local = alt bcx.fcx.lllocals.find(node_id) {
some(local_mem(x)) { x }

View file

@ -526,7 +526,7 @@ fn make_generic_glue(ccx: @crate_ctxt, t: ty::t, llfn: ValueRef,
fn emit_tydescs(ccx: @crate_ctxt) {
let _icx = ccx.insn_ctxt("emit_tydescs");
ccx.tydescs.items {|key, val|
for ccx.tydescs.each {|key, val|
let glue_fn_ty = T_ptr(T_glue_fn(ccx));
let ti = val;
let take_glue =
@ -4871,7 +4871,7 @@ fn create_module_map(ccx: @crate_ctxt) -> ValueRef {
});
lib::llvm::SetLinkage(map, lib::llvm::InternalLinkage);
let mut elts: [ValueRef] = [];
ccx.module_data.items {|key, val|
for ccx.module_data.each {|key, val|
let elt = C_struct([p2i(ccx, C_cstr(ccx, key)),
p2i(ccx, val)]);
elts += [elt];
@ -5091,7 +5091,7 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
}
if ccx.sess.opts.count_llvm_insns {
ccx.stats.llvm_insns.items() { |k, v|
for ccx.stats.llvm_insns.each { |k, v|
io::println(#fmt("%-7u %s", v, k));
}
}

View file

@ -555,7 +555,7 @@ fn norm_a_constraint(id: def_id, c: constraint) -> [norm_constraint] {
// non-exhaustive match in trans.
fn constraints(fcx: fn_ctxt) -> [norm_constraint] {
let mut rslt: [norm_constraint] = [];
fcx.enclosing.constrs.items {|key, val|
for fcx.enclosing.constrs.each {|key, val|
rslt += norm_a_constraint(key, val);
};
ret rslt;
@ -875,7 +875,7 @@ fn copy_in_poststate_two(fcx: fn_ctxt, src_post: poststate,
}
fcx.enclosing.constrs.values {|val|
for fcx.enclosing.constrs.each_value {|val|
// replace any occurrences of the src def_id with the
// dest def_id
let insts = find_instances(fcx, subst, val);