@@ -8,6 +8,8 @@ import middle::ty;
8
8
import syntax :: { ast, visit} ;
9
9
import util:: common:: new_def_hash;
10
10
11
+ import std:: list;
12
+ import std:: list:: list;
11
13
import std:: map;
12
14
import std:: map:: hashmap;
13
15
@@ -19,6 +21,12 @@ enum parent {
19
21
pa_crate
20
22
}
21
23
24
+ /* Records the binding site of a region name. */
25
+ type binding = {
26
+ name : str ,
27
+ id : ast:: def_id
28
+ } ;
29
+
22
30
type region_map = {
23
31
/*
24
32
* Mapping from blocks and function expression to their parent block or
@@ -37,7 +45,7 @@ type ctxt = {
37
45
sess : session ,
38
46
def_map : resolve:: def_map ,
39
47
region_map : @region_map ,
40
- names_in_scope : hashmap < str , ast :: def_id > ,
48
+ mut bindings : @ list < binding > ,
41
49
42
50
/*
43
51
* A list of local IDs that will be parented to the next block we
@@ -106,12 +114,14 @@ fn resolve_ty(ty: @ast::ty, cx: ctxt, visitor: visit::vt<ctxt>) {
106
114
ast:: re_named ( ident) {
107
115
// If at item scope, introduce or reuse a binding. If at
108
116
// block scope, require that the binding be introduced.
109
- alt cx. names_in_scope . find ( ident) {
110
- some ( def_id) { region = ty:: re_named ( def_id) ; }
117
+ let bindings = cx. bindings ;
118
+ alt list:: find ( * bindings, { |b| ident == b. name } ) {
119
+ some ( binding) { region = ty:: re_named ( binding. id ) ; }
111
120
none {
112
121
let def_id = { crate : ast:: local_crate,
113
122
node : region_id} ;
114
- cx. names_in_scope . insert ( ident, def_id) ;
123
+ let binding = { name: ident, id: def_id} ;
124
+ cx. bindings = @list:: cons ( binding, cx. bindings ) ;
115
125
region = ty:: re_named ( def_id) ;
116
126
117
127
alt cx. parent {
@@ -248,7 +258,7 @@ fn resolve_expr(expr: @ast::expr, cx: ctxt, visitor: visit::vt<ctxt>) {
248
258
249
259
fn resolve_item ( item : @ast:: item , cx : ctxt , visitor : visit:: vt < ctxt > ) {
250
260
// Items create a new outer block scope as far as we're concerned.
251
- let new_cx: ctxt = { names_in_scope : map :: new_str_hash ( ) ,
261
+ let new_cx: ctxt = { bindings : @list :: nil ,
252
262
parent: pa_item ( item. id ) ,
253
263
in_alt: false
254
264
with cx} ;
@@ -263,7 +273,7 @@ fn resolve_crate(sess: session, def_map: resolve::def_map, crate: @ast::crate)
263
273
ast_type_to_region : map:: new_int_hash ( ) ,
264
274
local_blocks : map:: new_int_hash ( ) ,
265
275
region_name_to_fn : new_def_hash ( ) } ,
266
- names_in_scope : map :: new_str_hash ( ) ,
276
+ mut bindings : @list :: nil ,
267
277
mut queued_locals: [ ] ,
268
278
parent: pa_crate,
269
279
in_alt: false } ;
0 commit comments