aboutsummaryrefslogtreecommitdiff
path: root/src/comp/middle
diff options
context:
space:
mode:
authorPatrick Walton <[email protected]>2010-11-24 11:36:35 -0800
committerPatrick Walton <[email protected]>2010-11-24 11:36:35 -0800
commit5d72dae1d13fdbe6275d732aac7dd9a9ad604b6f (patch)
treec06fdafb3c451ab9771696e70b1bb780a3fcd077 /src/comp/middle
parentrustc: Typecheck whiles and do-whiles. Add a workaround to complex.rs pending... (diff)
downloadrust-5d72dae1d13fdbe6275d732aac7dd9a9ad604b6f.tar.xz
rust-5d72dae1d13fdbe6275d732aac7dd9a9ad604b6f.zip
rustc: Parse tag items. Currently segfaults in copy glue.
Diffstat (limited to 'src/comp/middle')
-rw-r--r--src/comp/middle/fold.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs
index 6ad65544..f32eddae 100644
--- a/src/comp/middle/fold.rs
+++ b/src/comp/middle/fold.rs
@@ -148,6 +148,10 @@ type ast_fold[ENV] =
(fn(&ENV e, &span sp, ident ident,
@ty t, def_id id, ann a) -> @item) fold_item_ty,
+ (fn(&ENV e, &span sp, ident ident,
+ vec[ast.variant] variants,
+ def_id id) -> @item) fold_item_tag,
+
// Additional nodes.
(fn(&ENV e, &span sp,
&ast.block_) -> block) fold_block,
@@ -495,6 +499,18 @@ fn fold_item[ENV](&ENV env, ast_fold[ENV] fld, @item i) -> @item {
let @ast.ty ty_ = fold_ty[ENV](env_, fld, ty);
ret fld.fold_item_ty(env_, i.span, ident, ty_, id, ann);
}
+
+ case (ast.item_tag(?ident, ?variants, ?id)) {
+ let vec[ast.variant] new_variants = vec();
+ for (ast.variant v in variants) {
+ let vec[@ast.ty] new_args = vec();
+ for (@ast.ty t in v.args) {
+ new_args += vec(fold_ty[ENV](env_, fld, t));
+ }
+ new_variants += rec(name=v.name, args=new_args);
+ }
+ ret fld.fold_item_tag(env_, i.span, ident, new_variants, id);
+ }
}
fail;
@@ -723,6 +739,12 @@ fn identity_fold_item_ty[ENV](&ENV e, &span sp, ident i,
ret @respan(sp, ast.item_ty(i, t, id, a));
}
+fn identity_fold_item_tag[ENV](&ENV e, &span sp, ident i,
+ vec[ast.variant] variants,
+ def_id id) -> @item {
+ ret @respan(sp, ast.item_tag(i, variants, id));
+}
+
// Additional identities.
@@ -832,6 +854,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
fold_item_fn = bind identity_fold_item_fn[ENV](_,_,_,_,_,_),
fold_item_mod = bind identity_fold_item_mod[ENV](_,_,_,_,_),
fold_item_ty = bind identity_fold_item_ty[ENV](_,_,_,_,_,_),
+ fold_item_tag = bind identity_fold_item_tag[ENV](_,_,_,_,_),
fold_block = bind identity_fold_block[ENV](_,_,_),
fold_fn = bind identity_fold_fn[ENV](_,_,_,_),