about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKevin Atkinson <kevina@cs.utah.edu>2012-02-01 21:21:01 -0700
committerKevin Atkinson <kevina@cs.utah.edu>2012-02-03 20:54:17 -0700
commit3604f36938f46104d8b538edbcbd322e4829a081 (patch)
tree0f867b3132103f16d5fe7bbf8c5ff24414b7c408
parent42e25b2bb91118ff40e110129808451a762e7f5c (diff)
downloadrust-3604f36938f46104d8b538edbcbd322e4829a081.tar.gz
rust-3604f36938f46104d8b538edbcbd322e4829a081.zip
Implement folding of ast::ty.
-rw-r--r--src/comp/syntax/fold.rs33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs
index e3a05961bea..dc172e430a5 100644
--- a/src/comp/syntax/fold.rs
+++ b/src/comp/syntax/fold.rs
@@ -415,9 +415,36 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
         }
 }
 
-fn noop_fold_ty(t: ty_, _fld: ast_fold) -> ty_ {
-    //drop in ty::fold_ty here if necessary
-    ret t;
+fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ {
+    let fold_mac = bind fold_mac_(_, fld);
+    fn fold_mt(mt: mt, fld: ast_fold) -> mt {
+        {ty: fld.fold_ty(mt.ty), mut: mt.mut}
+    }
+    fn fold_field(f: ty_field, fld: ast_fold) -> ty_field {
+        {node: {ident: fld.fold_ident(f.node.ident),
+                mt: fold_mt(f.node.mt, fld)},
+         span: fld.new_span(f.span)}
+    }
+    alt t {
+      ty_nil | ty_bot | ty_bool | ty_str {t}
+      ty_int(_) | ty_uint(_) | ty_float(_) {t}
+      ty_box(mt) {ty_box(fold_mt(mt, fld))}
+      ty_uniq(mt) {ty_uniq(fold_mt(mt, fld))}
+      ty_vec(mt) {ty_vec(fold_mt(mt, fld))}
+      ty_ptr(mt) {ty_ptr(fold_mt(mt, fld))}
+      ty_task {t}
+      ty_port(ty) {ty_port(fld.fold_ty(ty))}
+      ty_chan(ty) {ty_chan(fld.fold_ty(ty))}
+      ty_rec(fields) {ty_rec(vec::map(fields) {|f| fold_field(f, fld)})}
+      ty_fn(proto, decl) {ty_fn(proto, fold_fn_decl(decl, fld))}
+      ty_tup(tys) {ty_tup(vec::map(tys) {|ty| fld.fold_ty(ty)})}
+      ty_path(path, id) {ty_path(fld.fold_path(path), fld.new_id(id))}
+      ty_type {t}
+      // FIXME: constrs likely needs to be folded...
+      ty_constr(ty, constrs) {ty_constr(fld.fold_ty(ty), constrs)}
+      ty_mac(mac) {ty_mac(fold_mac(mac))}
+      ty_infer {t}
+    }
 }
 
 fn noop_fold_constr(c: constr_, fld: ast_fold) -> constr_ {