From c9d2eceb4588e5fe57be4cbd41dbab789f9ecb29 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Thu, 20 Jan 2011 15:17:26 -0800 Subject: Teach resolve about linear for loops. --- src/comp/middle/resolve.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/comp/middle/resolve.rs b/src/comp/middle/resolve.rs index a9e6802e..9e082ae4 100644 --- a/src/comp/middle/resolve.rs +++ b/src/comp/middle/resolve.rs @@ -18,6 +18,7 @@ import std._vec; tag scope { scope_crate(@ast.crate); scope_item(@ast.item); + scope_loop(@ast.decl); // there's only 1 decl per loop. scope_block(ast.block); scope_arm(ast.arm); } @@ -317,6 +318,17 @@ fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[tup(@env, def_wrap)] { } } + case (scope_loop(?d)) { + alt (d.node) { + case (ast.decl_local(?local)) { + if (_str.eq(local.ident, i)) { + auto lc = ast.def_local(local.id); + ret some(def_wrap_other(lc)); + } + } + } + } + case (scope_block(?b)) { alt (b.node.index.find(i)) { case (some[uint](?ix)) { @@ -494,6 +506,16 @@ fn update_env_for_block(&env e, &ast.block b) -> env { ret rec(scopes = cons[scope](scope_block(b), @e.scopes) with e); } +fn update_env_for_expr(&env e, @ast.expr x) -> env { + alt (x.node) { + case (ast.expr_for(?d, _, _, _)) { + ret rec(scopes = cons[scope](scope_loop(d), @e.scopes) with e); + } + case (_) { } + } + ret e; +} + fn update_env_for_arm(&env e, &ast.arm p) -> env { ret rec(scopes = cons[scope](scope_arm(p), @e.scopes) with e); } @@ -507,7 +529,8 @@ fn resolve_imports(session.session sess, @ast.crate crate) -> @ast.crate { update_env_for_crate = bind update_env_for_crate(_,_), update_env_for_item = bind update_env_for_item(_,_), update_env_for_block = bind update_env_for_block(_,_), - update_env_for_arm = bind update_env_for_arm(_,_) + update_env_for_arm = bind update_env_for_arm(_,_), + update_env_for_expr = bind update_env_for_expr(_,_) with *fld ); auto e = rec(scopes = nil[scope], @@ -528,7 +551,8 @@ fn resolve_crate(session.session sess, @ast.crate crate) -> @ast.crate { update_env_for_crate = bind update_env_for_crate(_,_), update_env_for_item = bind update_env_for_item(_,_), update_env_for_block = bind update_env_for_block(_,_), - update_env_for_arm = bind update_env_for_arm(_,_) + update_env_for_arm = bind update_env_for_arm(_,_), + update_env_for_expr = bind update_env_for_expr(_,_) with *fld ); auto e = rec(scopes = nil[scope], -- cgit v1.2.3