From 3436979b175496a3936f00e90748e2fad0343ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Mon, 14 Mar 2011 16:56:03 -0400 Subject: [PATCH] Split trans' collection in two passes. This allows us to handle tags that are defined after use in a block. This is really inefficient, but for now it lets us compile the included test. --- src/comp/middle/trans.rs | 54 ++++++++++++++++++++----------- src/test/run-pass/tag-in-block.rs | 13 ++++++++ 2 files changed, 48 insertions(+), 19 deletions(-) create mode 100644 src/test/run-pass/tag-in-block.rs diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 64850542317..de19a01acb8 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -5485,21 +5485,6 @@ fn collect_native_item(&@crate_ctxt cx, @ast.native_item i) -> @crate_ctxt { fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt { alt (i.node) { - case (ast.item_fn(?name, ?f, ?tps, ?fid, ?ann)) { - cx.items.insert(fid, i); - if (! cx.obj_methods.contains_key(fid)) { - decl_fn_and_pair(cx, "fn", name, tps, ann, fid); - } - } - - case (ast.item_obj(?name, ?ob, ?tps, ?oid, ?ann)) { - cx.items.insert(oid, i); - decl_fn_and_pair(cx, "obj_ctor", name, tps, ann, oid); - for (@ast.method m in ob.methods) { - cx.obj_methods.insert(m.node.id, ()); - } - } - case (ast.item_const(?name, _, _, ?cid, _)) { cx.items.insert(cid, i); } @@ -5517,17 +5502,48 @@ fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt { ret cx; } +fn collect_item_pass2(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt { + alt (i.node) { + case (ast.item_fn(?name, ?f, ?tps, ?fid, ?ann)) { + cx.items.insert(fid, i); + if (! cx.obj_methods.contains_key(fid)) { + decl_fn_and_pair(cx, "fn", name, tps, ann, fid); + } + } + + case (ast.item_obj(?name, ?ob, ?tps, ?oid, ?ann)) { + cx.items.insert(oid, i); + decl_fn_and_pair(cx, "obj_ctor", name, tps, ann, oid); + for (@ast.method m in ob.methods) { + cx.obj_methods.insert(m.node.id, ()); + } + } + + case (_) { /* fall through */ } + } + ret cx; +} + fn collect_items(@crate_ctxt cx, @ast.crate crate) { let fold.ast_fold[@crate_ctxt] fld = fold.new_identity_fold[@crate_ctxt](); - fld = @rec( update_env_for_item = bind collect_item(_,_), - update_env_for_native_item = bind collect_native_item(_,_) - with *fld ); + // FIXME: if ty_tag had a pointer directly to the definition instead + // of a def_id, we wouldn't need the second pass. - fold.fold_crate[@crate_ctxt](cx, fld, crate); + auto fld1 = + @rec( update_env_for_item = bind collect_item(_,_), + update_env_for_native_item = bind collect_native_item(_,_) + with *fld ); + + fold.fold_crate[@crate_ctxt](cx, fld1, crate); + + auto fld2 = @rec( update_env_for_item = bind collect_item_pass2(_,_) + with *fld ); + + fold.fold_crate[@crate_ctxt](cx, fld2, crate); } fn collect_tag_ctor(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt { diff --git a/src/test/run-pass/tag-in-block.rs b/src/test/run-pass/tag-in-block.rs new file mode 100644 index 00000000000..3ee7b740dca --- /dev/null +++ b/src/test/run-pass/tag-in-block.rs @@ -0,0 +1,13 @@ +fn foo() { + fn zed(bar z) { + } + tag bar { + nil; + } + fn baz() { + zed(nil); + } +} + +fn main(vec[str] args) { +}