@@ -18,8 +18,8 @@ export freevar_set;
18
18
export freevar_map;
19
19
export get_freevars;
20
20
export has_freevars;
21
- export is_freevarof ;
22
-
21
+ export is_freevar_of ;
22
+ export def_lookup ;
23
23
24
24
type freevar_set = @ast:: node_id [ ] ;
25
25
type freevar_map = hashmap [ ast:: node_id, freevar_set] ;
@@ -138,10 +138,10 @@ fn annotate_freevars(&session::session sess, &resolve::def_map def_map,
138
138
139
139
fn get_freevars( & ty:: ctxt tcx, ast:: node_id fid) -> freevar_set {
140
140
alt ( tcx. freevars. find( fid) ) {
141
- case ( none) {
141
+ none {
142
142
fail "get_freevars : " + int::str(fid) + " has no freevars";
143
143
}
144
- case ( some( ?d) ) { ret d; }
144
+ some( ?d) { ret d; }
145
145
}
146
146
}
147
147
fn has_freevars( & ty:: ctxt tcx, ast:: node_id fid) -> bool {
@@ -150,6 +150,19 @@ fn has_freevars(&ty::ctxt tcx, ast::node_id fid) -> bool {
150
150
fn is_freevar_of( & ty:: ctxt tcx, ast:: node_id var, ast:: node_id f) -> bool {
151
151
ret ivec:: member( var, * get_freevars( tcx, f) ) ;
152
152
}
153
+ fn def_lookup( & ty:: ctxt tcx, ast:: node_id f, ast:: node_id id) ->
154
+ option:: t[ ast:: def] {
155
+ alt ( tcx. def_map. find( id) ) {
156
+ none { ret none; }
157
+ some( ?d) {
158
+ auto did = ast:: def_id_of_def( d) ;
159
+ if is_freevar_of( tcx, did. _1, f) {
160
+ ret some( ast:: def_upvar( did, @d) ) ;
161
+ } else { ret some( d) ; }
162
+ }
163
+ }
164
+ }
165
+
153
166
154
167
// Local Variables:
155
168
// mode: rust
0 commit comments