Skip to content

Commit 4cbe897

Browse files
catamorphismgraydon
authored andcommitted
---
yaml --- r: 2684 b: refs/heads/master c: c8d488b h: refs/heads/master v: v3
1 parent ecff9a3 commit 4cbe897

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 9128a1bab8e54529a3fa2464b085ba782477c2ff
2+
refs/heads/master: c8d488b337b3f61d6336cc798aa74a4642bc204d

trunk/src/comp/middle/tstate/annotate.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ import util::common::log_expr;
8686
import util::common::log_block;
8787
import util::common::log_stmt;
8888

89-
import middle::tstate::aux::fn_info;
90-
import middle::tstate::aux::fn_info_map;
91-
import middle::tstate::aux::num_locals;
92-
import middle::tstate::aux::get_fn_info;
93-
import middle::tstate::aux::crate_ctxt;
89+
import aux::fn_info;
90+
import aux::fn_info_map;
91+
import aux::num_locals;
92+
import aux::get_fn_info;
93+
import aux::crate_ctxt;
94+
import aux::add_node;
9495
import middle::tstate::ann::empty_ann;
9596

9697
fn collect_ids_expr(&@expr e, @vec[uint] res) -> () {
@@ -140,7 +141,7 @@ fn node_ids_in_fn(&_fn f, &ident i, &def_id d, &ann a, @vec[uint] res) -> () {
140141
fn init_vecs(&crate_ctxt ccx, @vec[uint] node_ids, uint len) -> () {
141142
for (uint i in *node_ids) {
142143
log(uistr(i) + " |-> " + uistr(len));
143-
ccx.node_anns.insert(i, empty_ann(len));
144+
add_node(ccx, i, empty_ann(len));
144145
}
145146
}
146147

trunk/src/comp/middle/tstate/auxiliary.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import std::bitv;
2+
import std::vec;
23
import std::vec::len;
4+
import std::vec::grow;
35
import std::vec::pop;
46
import std::option;
57
import std::option::none;
@@ -156,7 +158,7 @@ type fn_info = rec(@std::map::hashmap[def_id, var_info] vars,
156158
controlflow cf);
157159

158160
/* 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];
160162

161163
/* mapping from function name to fn_info map */
162164
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 {
175177
ret ccx.fm.get(did);
176178
}
177179

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) + 1u, empty_ann(0u));
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+
}
178196
/********* utils ********/
179197

180198
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)) {
182200
case (none[ts_ann]) {
183201
log_err ("ann_to_ts_ann: no ts_ann for node_id "
184202
+ uistr(a.id));
@@ -296,8 +314,8 @@ fn block_poststate(&crate_ctxt ccx, &block b) -> poststate {
296314

297315
/* sets the pre_and_post for an ann */
298316
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))));
301319
}
302320

303321
fn set_prestate_ann(&crate_ctxt ccx, &ann a, &prestate pre) -> bool {
@@ -370,8 +388,8 @@ fn num_locals(fn_info m) -> uint {
370388
}
371389

372390
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]());
375393
}
376394

377395
fn controlflow_def_id(&crate_ctxt ccx, &def_id d) -> controlflow {

0 commit comments

Comments
 (0)