Skip to content

Commit 74d8915

Browse files
committed
reindex the block index.
1 parent 1feaf8f commit 74d8915

File tree

3 files changed

+44
-38
lines changed

3 files changed

+44
-38
lines changed

src/comp/front/ast.rs

+38
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,44 @@ fn index_native_view_item(native_mod_index index, @view_item it) {
435435
}
436436
}
437437

438+
fn index_stmt(block_index index, @stmt s) {
439+
alt (s.node) {
440+
case (ast.stmt_decl(?d)) {
441+
alt (d.node) {
442+
case (ast.decl_local(?loc)) {
443+
index.insert(loc.ident, ast.bie_local(loc));
444+
}
445+
case (ast.decl_item(?it)) {
446+
alt (it.node) {
447+
case (ast.item_fn(?i, _, _, _, _)) {
448+
index.insert(i, ast.bie_item(it));
449+
}
450+
case (ast.item_mod(?i, _, _)) {
451+
index.insert(i, ast.bie_item(it));
452+
}
453+
case (ast.item_ty(?i, _, _, _, _)) {
454+
index.insert(i, ast.bie_item(it));
455+
}
456+
case (ast.item_tag(?i, ?variants, _, _)) {
457+
index.insert(i, ast.bie_item(it));
458+
let uint vid = 0u;
459+
for (ast.variant v in variants) {
460+
auto t = ast.bie_tag_variant(it, vid);
461+
index.insert(v.name, t);
462+
vid += 1u;
463+
}
464+
}
465+
case (ast.item_obj(?i, _, _, _, _)) {
466+
index.insert(i, ast.bie_item(it));
467+
}
468+
}
469+
}
470+
}
471+
}
472+
case (_) { /* fall through */ }
473+
}
474+
}
475+
438476
fn is_call_expr(@expr e) -> bool {
439477
alt (e.node) {
440478
case (expr_call(_, _, _)) {

src/comp/front/parser.rs

+1-35
Original file line numberDiff line numberDiff line change
@@ -1480,41 +1480,7 @@ impure fn parse_source_stmt(parser p) -> @ast.stmt {
14801480
fn index_block(vec[@ast.stmt] stmts, option.t[@ast.expr] expr) -> ast.block_ {
14811481
auto index = new_str_hash[ast.block_index_entry]();
14821482
for (@ast.stmt s in stmts) {
1483-
alt (s.node) {
1484-
case (ast.stmt_decl(?d)) {
1485-
alt (d.node) {
1486-
case (ast.decl_local(?loc)) {
1487-
index.insert(loc.ident, ast.bie_local(loc));
1488-
}
1489-
case (ast.decl_item(?it)) {
1490-
alt (it.node) {
1491-
case (ast.item_fn(?i, _, _, _, _)) {
1492-
index.insert(i, ast.bie_item(it));
1493-
}
1494-
case (ast.item_mod(?i, _, _)) {
1495-
index.insert(i, ast.bie_item(it));
1496-
}
1497-
case (ast.item_ty(?i, _, _, _, _)) {
1498-
index.insert(i, ast.bie_item(it));
1499-
}
1500-
case (ast.item_tag(?i, ?variants, _, _)) {
1501-
index.insert(i, ast.bie_item(it));
1502-
let uint vid = 0u;
1503-
for (ast.variant v in variants) {
1504-
auto t = ast.bie_tag_variant(it, vid);
1505-
index.insert(v.name, t);
1506-
vid += 1u;
1507-
}
1508-
}
1509-
case (ast.item_obj(?i, _, _, _, _)) {
1510-
index.insert(i, ast.bie_item(it));
1511-
}
1512-
}
1513-
}
1514-
}
1515-
}
1516-
case (_) { /* fall through */ }
1517-
}
1483+
ast.index_stmt(index, s);
15181484
}
15191485
ret rec(stmts=stmts, expr=expr, index=index);
15201486
}

src/comp/middle/fold.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ fn fold_stmt[ENV](&ENV env, ast_fold[ENV] fld, &@stmt s) -> @stmt {
734734

735735
fn fold_block[ENV](&ENV env, ast_fold[ENV] fld, &block blk) -> block {
736736

737+
auto index = new_str_hash[ast.block_index_entry]();
737738
let ENV env_ = fld.update_env_for_block(env, blk);
738739

739740
if (!fld.keep_going(env_)) {
@@ -742,7 +743,9 @@ fn fold_block[ENV](&ENV env, ast_fold[ENV] fld, &block blk) -> block {
742743

743744
let vec[@ast.stmt] stmts = vec();
744745
for (@ast.stmt s in blk.node.stmts) {
745-
append[@ast.stmt](stmts, fold_stmt[ENV](env_, fld, s));
746+
auto new_stmt = fold_stmt[ENV](env_, fld, s);
747+
append[@ast.stmt](stmts, new_stmt);
748+
ast.index_stmt(index, new_stmt);
746749
}
747750

748751
auto expr = none[@ast.expr];
@@ -755,8 +758,7 @@ fn fold_block[ENV](&ENV env, ast_fold[ENV] fld, &block blk) -> block {
755758
}
756759
}
757760

758-
// FIXME: should we reindex?
759-
ret respan(blk.span, rec(stmts=stmts, expr=expr, index=blk.node.index));
761+
ret respan(blk.span, rec(stmts=stmts, expr=expr, index=index));
760762
}
761763

762764
fn fold_arm[ENV](&ENV env, ast_fold[ENV] fld, &arm a) -> arm {

0 commit comments

Comments
 (0)