From 3604f36938f46104d8b538edbcbd322e4829a081 Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Wed, 1 Feb 2012 21:21:01 -0700 Subject: [PATCH] Implement folding of ast::ty. --- src/comp/syntax/fold.rs | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs index e3a05961bea7..dc172e430a59 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_ {