1
1
import std:: bitv;
2
+ import std:: vec;
2
3
import std:: vec:: len;
4
+ import std:: vec:: grow;
3
5
import std:: vec:: pop;
4
6
import std:: option;
5
7
import std:: option:: none;
@@ -156,7 +158,7 @@ type fn_info = rec(@std::map::hashmap[def_id, var_info] vars,
156
158
controlflow cf) ;
157
159
158
160
/* mapping from node ID to typestate annotation */
159
- type node_ann_table = @std :: map :: hashmap [ uint , ts_ann] ;
161
+ type node_ann_table = @vec [ ts_ann ] ;
160
162
161
163
/* mapping from function name to fn_info map */
162
164
type fn_info_map = @std:: map:: hashmap [ def_id, fn_info] ;
@@ -175,10 +177,26 @@ fn get_fn_info(&crate_ctxt ccx, def_id did) -> fn_info {
175
177
ret ccx. fm . get ( did) ;
176
178
}
177
179
180
+ fn add_node ( & crate_ctxt ccx, uint i, & ts_ann a) -> ( ) {
181
+ auto sz = len ( * ( ccx. node_anns ) ) ;
182
+ if ( sz <= i) {
183
+ grow ( * ( ccx. node_anns ) , ( i - sz) + 1 u, empty_ann ( 0 u) ) ;
184
+ }
185
+ ccx. node_anns . ( i) = a;
186
+ }
187
+
188
+ fn get_ts_ann ( & crate_ctxt ccx, uint i) -> option:: t [ ts_ann ] {
189
+ if ( i < len ( * ( ccx. node_anns ) ) ) {
190
+ ret some[ ts_ann] ( ccx. node_anns . ( i) ) ;
191
+ }
192
+ else {
193
+ ret none[ ts_ann] ;
194
+ }
195
+ }
178
196
/********* utils ********/
179
197
180
198
fn ann_to_ts_ann ( & crate_ctxt ccx, & ann a) -> ts_ann {
181
- alt ( ccx . node_anns . find ( a. id ) ) {
199
+ alt ( get_ts_ann ( ccx , a. id ) ) {
182
200
case ( none[ ts_ann] ) {
183
201
log_err ( "ann_to_ts_ann: no ts_ann for node_id "
184
202
+ uistr ( a. id ) ) ;
@@ -296,8 +314,8 @@ fn block_poststate(&crate_ctxt ccx, &block b) -> poststate {
296
314
297
315
/* sets the pre_and_post for an ann */
298
316
fn with_pp ( & crate_ctxt ccx, & ann a, pre_and_post p) {
299
- ccx . node_anns . insert ( a. id , @rec ( conditions=p,
300
- states=empty_states ( pps_len ( p) ) ) ) ;
317
+ add_node ( ccx , a. id , @rec ( conditions=p,
318
+ states=empty_states ( pps_len ( p) ) ) ) ;
301
319
}
302
320
303
321
fn set_prestate_ann ( & crate_ctxt ccx, & ann a, & prestate pre) -> bool {
@@ -370,8 +388,8 @@ fn num_locals(fn_info m) -> uint {
370
388
}
371
389
372
390
fn new_crate_ctxt ( ty:: ctxt cx) -> crate_ctxt {
373
- ret rec ( tcx=cx , node_anns=@new_uint_hash [ ts_ann ] ( ) ,
374
- fm=@new_def_hash[ fn_info] ( ) ) ;
391
+ let vec [ ts_ann ] na = [ ] ;
392
+ ret rec ( tcx=cx , node_anns=@na , fm=@new_def_hash[ fn_info] ( ) ) ;
375
393
}
376
394
377
395
fn controlflow_def_id ( & crate_ctxt ccx, & def_id d) -> controlflow {
0 commit comments