aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-10-18 14:36:40 -0700
committerGraydon Hoare <[email protected]>2010-10-18 14:36:40 -0700
commit05e7374e29cdcd293a1e3e29bc46a6283dacee85 (patch)
treed8cdccb18f48c28d70e301a989461fcc62a93b97
parentMake type errors in rustboot report the friendly type of both expected and ac... (diff)
downloadrust-05e7374e29cdcd293a1e3e29bc46a6283dacee85.tar.xz
rust-05e7374e29cdcd293a1e3e29bc46a6283dacee85.zip
Expand rustc's fold to update env on block boundaries.
-rw-r--r--src/comp/middle/fold.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs
index f8c058ff..fa14e1e3 100644
--- a/src/comp/middle/fold.rs
+++ b/src/comp/middle/fold.rs
@@ -136,6 +136,7 @@ type ast_fold[ENV] =
// Env updates.
(fn(&ENV e, @ast.crate c) -> ENV) update_env_for_crate,
(fn(&ENV e, @item i) -> ENV) update_env_for_item,
+ (fn(&ENV e, block b) -> ENV) update_env_for_block,
(fn(&ENV e, @stmt s) -> ENV) update_env_for_stmt,
(fn(&ENV e, @decl i) -> ENV) update_env_for_decl,
(fn(&ENV e, @expr x) -> ENV) update_env_for_expr,
@@ -397,9 +398,16 @@ fn fold_stmt[ENV](&ENV env, ast_fold[ENV] fld, &@stmt s) -> @stmt {
}
fn fold_block[ENV](&ENV env, ast_fold[ENV] fld, &block blk) -> block {
+
+ let ENV env_ = fld.update_env_for_block(env, blk);
+
+ if (!fld.keep_going(env_)) {
+ ret blk;
+ }
+
let vec[@ast.stmt] stmts = vec();
for (@ast.stmt s in blk.node) {
- append[@ast.stmt](stmts, fold_stmt[ENV](env, fld, s));
+ append[@ast.stmt](stmts, fold_stmt[ENV](env_, fld, s));
}
ret respan(blk.span, stmts);
}
@@ -684,6 +692,10 @@ fn identity_update_env_for_item[ENV](&ENV e, @item i) -> ENV {
ret e;
}
+fn identity_update_env_for_block[ENV](&ENV e, block b) -> ENV {
+ ret e;
+}
+
fn identity_update_env_for_stmt[ENV](&ENV e, @stmt s) -> ENV {
ret e;
}
@@ -758,6 +770,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
update_env_for_crate = bind identity_update_env_for_crate[ENV](_,_),
update_env_for_item = bind identity_update_env_for_item[ENV](_,_),
+ update_env_for_block = bind identity_update_env_for_block[ENV](_,_),
update_env_for_stmt = bind identity_update_env_for_stmt[ENV](_,_),
update_env_for_decl = bind identity_update_env_for_decl[ENV](_,_),
update_env_for_expr = bind identity_update_env_for_expr[ENV](_,_),