mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-11 15:23:05 +00:00
Add some useful functions to freevars.
This commit is contained in:
parent
4b59ae0aa9
commit
4170390cb6
@ -3,6 +3,10 @@
|
||||
|
||||
import std::map;
|
||||
import std::map::*;
|
||||
import std::ivec;
|
||||
import std::option;
|
||||
import std::int;
|
||||
import std::option::*;
|
||||
import syntax::ast;
|
||||
import syntax::walk;
|
||||
import driver::session;
|
||||
@ -12,6 +16,10 @@ import syntax::codemap::span;
|
||||
export annotate_freevars;
|
||||
export freevar_set;
|
||||
export freevar_map;
|
||||
export get_freevars;
|
||||
export has_freevars;
|
||||
export is_freevarof;
|
||||
|
||||
|
||||
type freevar_set = @ast::node_id[];
|
||||
type freevar_map = hashmap[ast::node_id, freevar_set];
|
||||
@ -128,6 +136,21 @@ fn annotate_freevars(&session::session sess, &resolve::def_map def_map,
|
||||
ret e.freevars;
|
||||
}
|
||||
|
||||
fn get_freevars(&ty::ctxt tcx, ast::node_id fid) -> freevar_set {
|
||||
alt (tcx.freevars.find(fid)) {
|
||||
case (none) {
|
||||
fail "get_freevars: " + int::str(fid) + " has no freevars";
|
||||
}
|
||||
case (some(?d)) { ret d; }
|
||||
}
|
||||
}
|
||||
fn has_freevars(&ty::ctxt tcx, ast::node_id fid) -> bool {
|
||||
ret ivec::len(*get_freevars(tcx, fid)) != 0u;
|
||||
}
|
||||
fn is_freevar_of(&ty::ctxt tcx, ast::node_id var, ast::node_id f) -> bool {
|
||||
ret ivec::member(var, *get_freevars(tcx, f));
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
// mode: rust
|
||||
// fill-column: 78;
|
||||
|
@ -27,7 +27,7 @@ import syntax::ast;
|
||||
import syntax::walk;
|
||||
import driver::session;
|
||||
import middle::ty;
|
||||
import middle::freevars;
|
||||
import middle::freevars::*;
|
||||
import back::link;
|
||||
import back::x86;
|
||||
import back::abi;
|
||||
@ -3941,7 +3941,7 @@ fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
|
||||
// FIXME: possibly support alias-mode here?
|
||||
auto decl_ty = node_id_type(lcx.ccx, local.node.id);
|
||||
auto decl_id = local.node.id;
|
||||
auto upvars = cx.fcx.lcx.ccx.tcx.freevars.get(body.node.id);
|
||||
auto upvars = get_freevars(lcx.ccx.tcx, body.node.id);
|
||||
|
||||
auto environment_data = build_environment(cx, *upvars);
|
||||
auto llenvptr = environment_data._0;
|
||||
|
Loading…
Reference in New Issue
Block a user