diff options
| author | Rafael Ávila de Espíndola <[email protected]> | 2011-03-14 16:56:03 -0400 |
|---|---|---|
| committer | Rafael Ávila de Espíndola <[email protected]> | 2011-03-14 16:56:03 -0400 |
| commit | 3436979b175496a3936f00e90748e2fad0343ae9 (patch) | |
| tree | 644b108a195f87675199311905ff5799889caec5 | |
| parent | Add llvmext/include to the list of include directories to hopefully put out t... (diff) | |
| download | rust-3436979b175496a3936f00e90748e2fad0343ae9.tar.xz rust-3436979b175496a3936f00e90748e2fad0343ae9.zip | |
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.
| -rw-r--r-- | src/comp/middle/trans.rs | 48 | ||||
| -rw-r--r-- | src/test/run-pass/tag-in-block.rs | 13 |
2 files changed, 45 insertions, 16 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 64850542..de19a01a 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -5485,6 +5485,25 @@ 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_const(?name, _, _, ?cid, _)) { + cx.items.insert(cid, i); + } + + case (ast.item_mod(?name, ?m, ?mid)) { + cx.items.insert(mid, i); + } + + case (ast.item_tag(_, ?variants, ?tps, ?tag_id)) { + cx.items.insert(tag_id, i); + } + + case (_) { /* fall through */ } + } + 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)) { @@ -5500,18 +5519,6 @@ fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt { } } - case (ast.item_const(?name, _, _, ?cid, _)) { - cx.items.insert(cid, i); - } - - case (ast.item_mod(?name, ?m, ?mid)) { - cx.items.insert(mid, i); - } - - case (ast.item_tag(_, ?variants, ?tps, ?tag_id)) { - cx.items.insert(tag_id, i); - } - case (_) { /* fall through */ } } ret cx; @@ -5523,11 +5530,20 @@ 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 00000000..3ee7b740 --- /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) { +} |