提交 da519c85 编写于 作者: T Tim Chevalier

Eliminate a use of map::get in freevars

map::get is evil -- just say no!
上级 4f3171ea
// A pass that annotates for each loops and functions with the free
// variables that they contain.
import syntax::print::pprust::path_to_str;
import int;
import std::map::*;
import option::*;
......@@ -47,21 +48,27 @@ fn ignore_item(_i: @ast::item, &&_depth: int, _v: visit::vt<int>) { }
visit::visit_expr(expr, depth + 1, v);
}
ast::expr_path(path) {
let def = def_map.get(expr.id), i = 0;
while i < depth {
alt copy def {
ast::def_upvar(_, inner, _) { def = *inner; }
_ { break; }
let i = 0;
alt def_map.find(expr.id) {
none. { fail ("Not found: " + path_to_str(path)) }
some(df) {
let def = df;
while i < depth {
alt copy def {
ast::def_upvar(_, inner, _) { def = *inner; }
_ { break; }
}
i += 1;
}
if i == depth { // Made it to end of loop
let dnum = ast_util::def_id_of_def(def).node;
if !seen.contains_key(dnum) {
*refs += [@{def:def, span:expr.span}];
seen.insert(dnum, ());
}
}
}
i += 1;
}
if i == depth { // Made it to end of loop
let dnum = ast_util::def_id_of_def(def).node;
if !seen.contains_key(dnum) {
*refs += [@{def:def, span:expr.span}];
seen.insert(dnum, ());
}
}
}
}
_ { visit::visit_expr(expr, depth, v); }
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册