diff options
| author | Rafael Ávila de Espíndola <[email protected]> | 2011-03-11 17:29:53 -0500 |
|---|---|---|
| committer | Rafael Ávila de Espíndola <[email protected]> | 2011-03-11 17:35:33 -0500 |
| commit | 74d891517be8f6299b0626c26400dd54dd1aac6c (patch) | |
| tree | ef74eac61cfca9c57973a41622ac35a5cd164d25 /src/comp | |
| parent | Re-XFAIL size-and-align.rs to put out burning tinderbox (diff) | |
| download | rust-74d891517be8f6299b0626c26400dd54dd1aac6c.tar.xz rust-74d891517be8f6299b0626c26400dd54dd1aac6c.zip | |
reindex the block index.
Diffstat (limited to 'src/comp')
| -rw-r--r-- | src/comp/front/ast.rs | 38 | ||||
| -rw-r--r-- | src/comp/front/parser.rs | 36 | ||||
| -rw-r--r-- | src/comp/middle/fold.rs | 8 |
3 files changed, 44 insertions, 38 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index c17eddee..b39f3d4c 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -435,6 +435,44 @@ fn index_native_view_item(native_mod_index index, @view_item it) { } } +fn index_stmt(block_index index, @stmt s) { + alt (s.node) { + case (ast.stmt_decl(?d)) { + alt (d.node) { + case (ast.decl_local(?loc)) { + index.insert(loc.ident, ast.bie_local(loc)); + } + case (ast.decl_item(?it)) { + alt (it.node) { + case (ast.item_fn(?i, _, _, _, _)) { + index.insert(i, ast.bie_item(it)); + } + case (ast.item_mod(?i, _, _)) { + index.insert(i, ast.bie_item(it)); + } + case (ast.item_ty(?i, _, _, _, _)) { + index.insert(i, ast.bie_item(it)); + } + case (ast.item_tag(?i, ?variants, _, _)) { + index.insert(i, ast.bie_item(it)); + let uint vid = 0u; + for (ast.variant v in variants) { + auto t = ast.bie_tag_variant(it, vid); + index.insert(v.name, t); + vid += 1u; + } + } + case (ast.item_obj(?i, _, _, _, _)) { + index.insert(i, ast.bie_item(it)); + } + } + } + } + } + case (_) { /* fall through */ } + } +} + fn is_call_expr(@expr e) -> bool { alt (e.node) { case (expr_call(_, _, _)) { diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 58cbac00..cdd65539 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -1480,41 +1480,7 @@ impure fn parse_source_stmt(parser p) -> @ast.stmt { fn index_block(vec[@ast.stmt] stmts, option.t[@ast.expr] expr) -> ast.block_ { auto index = new_str_hash[ast.block_index_entry](); for (@ast.stmt s in stmts) { - alt (s.node) { - case (ast.stmt_decl(?d)) { - alt (d.node) { - case (ast.decl_local(?loc)) { - index.insert(loc.ident, ast.bie_local(loc)); - } - case (ast.decl_item(?it)) { - alt (it.node) { - case (ast.item_fn(?i, _, _, _, _)) { - index.insert(i, ast.bie_item(it)); - } - case (ast.item_mod(?i, _, _)) { - index.insert(i, ast.bie_item(it)); - } - case (ast.item_ty(?i, _, _, _, _)) { - index.insert(i, ast.bie_item(it)); - } - case (ast.item_tag(?i, ?variants, _, _)) { - index.insert(i, ast.bie_item(it)); - let uint vid = 0u; - for (ast.variant v in variants) { - auto t = ast.bie_tag_variant(it, vid); - index.insert(v.name, t); - vid += 1u; - } - } - case (ast.item_obj(?i, _, _, _, _)) { - index.insert(i, ast.bie_item(it)); - } - } - } - } - } - case (_) { /* fall through */ } - } + ast.index_stmt(index, s); } ret rec(stmts=stmts, expr=expr, index=index); } diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index d08b979a..37ae2c23 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -734,6 +734,7 @@ 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 { + auto index = new_str_hash[ast.block_index_entry](); let ENV env_ = fld.update_env_for_block(env, blk); if (!fld.keep_going(env_)) { @@ -742,7 +743,9 @@ fn fold_block[ENV](&ENV env, ast_fold[ENV] fld, &block blk) -> block { let vec[@ast.stmt] stmts = vec(); for (@ast.stmt s in blk.node.stmts) { - append[@ast.stmt](stmts, fold_stmt[ENV](env_, fld, s)); + auto new_stmt = fold_stmt[ENV](env_, fld, s); + append[@ast.stmt](stmts, new_stmt); + ast.index_stmt(index, new_stmt); } auto expr = none[@ast.expr]; @@ -755,8 +758,7 @@ fn fold_block[ENV](&ENV env, ast_fold[ENV] fld, &block blk) -> block { } } - // FIXME: should we reindex? - ret respan(blk.span, rec(stmts=stmts, expr=expr, index=blk.node.index)); + ret respan(blk.span, rec(stmts=stmts, expr=expr, index=index)); } fn fold_arm[ENV](&ENV env, ast_fold[ENV] fld, &arm a) -> arm { |