2012-03-22 19:21:34 -05:00
|
|
|
import codemap::span;
|
2011-06-20 19:25:49 -05:00
|
|
|
import ast::*;
|
|
|
|
|
|
|
|
export ast_fold_precursor;
|
|
|
|
export ast_fold;
|
|
|
|
export default_ast_fold;
|
|
|
|
export make_fold;
|
2011-07-06 16:29:50 -05:00
|
|
|
export noop_fold_crate;
|
2011-07-08 22:52:54 -05:00
|
|
|
export noop_fold_item;
|
2011-07-10 18:08:13 -05:00
|
|
|
export noop_fold_expr;
|
2012-01-14 18:05:07 -06:00
|
|
|
export noop_fold_pat;
|
2011-07-12 18:46:42 -05:00
|
|
|
export noop_fold_mod;
|
2011-09-10 20:55:09 -05:00
|
|
|
export noop_fold_ty;
|
2012-03-07 17:13:31 -06:00
|
|
|
export noop_fold_block;
|
2012-01-22 18:30:07 -06:00
|
|
|
export wrap;
|
2012-03-02 16:36:22 -06:00
|
|
|
export fold_ty_param;
|
2012-04-10 12:52:06 -05:00
|
|
|
export fold_ty_params;
|
|
|
|
export fold_fn_decl;
|
2011-06-20 19:25:49 -05:00
|
|
|
|
2012-03-26 20:35:18 -05:00
|
|
|
type ast_fold = @mut a_f;
|
2011-06-20 19:25:49 -05:00
|
|
|
|
|
|
|
// We may eventually want to be able to fold over type parameters, too
|
|
|
|
|
2011-07-13 17:44:09 -05:00
|
|
|
type ast_fold_precursor =
|
2011-07-27 07:19:39 -05:00
|
|
|
//unlike the others, item_ is non-trivial
|
2012-01-22 18:30:07 -06:00
|
|
|
{fold_crate: fn@(crate_, span, ast_fold) -> (crate_, span),
|
|
|
|
fold_crate_directive: fn@(crate_directive_, span,
|
|
|
|
ast_fold) -> (crate_directive_, span),
|
2011-10-18 17:07:40 -05:00
|
|
|
fold_view_item: fn@(view_item_, ast_fold) -> view_item_,
|
|
|
|
fold_native_item: fn@(&&@native_item, ast_fold) -> @native_item,
|
|
|
|
fold_item: fn@(&&@item, ast_fold) -> @item,
|
2012-03-28 20:50:33 -05:00
|
|
|
fold_class_item: fn@(&&@class_member, ast_fold) -> @class_member,
|
2011-10-18 17:07:40 -05:00
|
|
|
fold_item_underscore: fn@(item_, ast_fold) -> item_,
|
2011-12-22 10:49:54 -06:00
|
|
|
fold_method: fn@(&&@method, ast_fold) -> @method,
|
2012-01-22 18:30:07 -06:00
|
|
|
fold_block: fn@(blk_, span, ast_fold) -> (blk_, span),
|
|
|
|
fold_stmt: fn@(stmt_, span, ast_fold) -> (stmt_, span),
|
2011-10-18 17:07:40 -05:00
|
|
|
fold_arm: fn@(arm, ast_fold) -> arm,
|
2012-01-22 18:30:07 -06:00
|
|
|
fold_pat: fn@(pat_, span, ast_fold) -> (pat_, span),
|
|
|
|
fold_decl: fn@(decl_, span, ast_fold) -> (decl_, span),
|
|
|
|
fold_expr: fn@(expr_, span, ast_fold) -> (expr_, span),
|
|
|
|
fold_ty: fn@(ty_, span, ast_fold) -> (ty_, span),
|
|
|
|
fold_constr: fn@(ast::constr_, span, ast_fold) -> (constr_, span),
|
2012-04-19 16:43:12 -05:00
|
|
|
fold_ty_constr: fn@(ast::ty_constr_, span, ast_fold)
|
|
|
|
-> (ty_constr_, span),
|
2011-10-18 17:07:40 -05:00
|
|
|
fold_mod: fn@(_mod, ast_fold) -> _mod,
|
|
|
|
fold_native_mod: fn@(native_mod, ast_fold) -> native_mod,
|
2012-01-22 18:30:07 -06:00
|
|
|
fold_variant: fn@(variant_, span, ast_fold) -> (variant_, span),
|
2011-10-18 17:07:40 -05:00
|
|
|
fold_ident: fn@(&&ident, ast_fold) -> ident,
|
2012-01-22 18:30:07 -06:00
|
|
|
fold_path: fn@(path_, span, ast_fold) -> (path_, span),
|
|
|
|
fold_local: fn@(local_, span, ast_fold) -> (local_, span),
|
2011-10-18 17:07:40 -05:00
|
|
|
map_exprs: fn@(fn@(&&@expr) -> @expr, [@expr]) -> [@expr],
|
|
|
|
new_id: fn@(node_id) -> node_id,
|
|
|
|
new_span: fn@(span) -> span};
|
2011-06-20 19:25:49 -05:00
|
|
|
|
|
|
|
type a_f =
|
2011-10-18 17:07:40 -05:00
|
|
|
{fold_crate: fn@(crate) -> crate,
|
|
|
|
fold_crate_directive: fn@(&&@crate_directive) -> @crate_directive,
|
|
|
|
fold_view_item: fn@(&&@view_item) -> @view_item,
|
|
|
|
fold_native_item: fn@(&&@native_item) -> @native_item,
|
|
|
|
fold_item: fn@(&&@item) -> @item,
|
2012-03-28 20:50:33 -05:00
|
|
|
fold_class_item: fn@(&&@class_member) -> @class_member,
|
2011-10-18 17:07:40 -05:00
|
|
|
fold_item_underscore: fn@(item_) -> item_,
|
|
|
|
fold_method: fn@(&&@method) -> @method,
|
|
|
|
fold_block: fn@(blk) -> blk,
|
|
|
|
fold_stmt: fn@(&&@stmt) -> @stmt,
|
|
|
|
fold_arm: fn@(arm) -> arm,
|
|
|
|
fold_pat: fn@(&&@pat) -> @pat,
|
|
|
|
fold_decl: fn@(&&@decl) -> @decl,
|
|
|
|
fold_expr: fn@(&&@expr) -> @expr,
|
|
|
|
fold_ty: fn@(&&@ty) -> @ty,
|
|
|
|
fold_constr: fn@(&&@constr) -> @constr,
|
2012-04-19 16:43:12 -05:00
|
|
|
fold_ty_constr: fn@(&&@ty_constr) -> @ty_constr,
|
2011-10-18 17:07:40 -05:00
|
|
|
fold_mod: fn@(_mod) -> _mod,
|
|
|
|
fold_native_mod: fn@(native_mod) -> native_mod,
|
|
|
|
fold_variant: fn@(variant) -> variant,
|
|
|
|
fold_ident: fn@(&&ident) -> ident,
|
2011-12-20 09:33:55 -06:00
|
|
|
fold_path: fn@(&&@path) -> @path,
|
2011-10-18 17:07:40 -05:00
|
|
|
fold_local: fn@(&&@local) -> @local,
|
|
|
|
map_exprs: fn@(fn@(&&@expr) -> @expr, [@expr]) -> [@expr],
|
|
|
|
new_id: fn@(node_id) -> node_id,
|
|
|
|
new_span: fn@(span) -> span};
|
2011-08-09 12:56:32 -05:00
|
|
|
|
2011-06-20 19:25:49 -05:00
|
|
|
|
2011-08-12 08:36:51 -05:00
|
|
|
//fn nf_dummy<T>(&T node) -> T { fail; }
|
2011-09-12 04:27:30 -05:00
|
|
|
fn nf_crate_dummy(_c: crate) -> crate { fail; }
|
2011-10-07 02:36:53 -05:00
|
|
|
fn nf_crate_directive_dummy(&&_c: @crate_directive) -> @crate_directive {
|
2011-07-27 07:19:39 -05:00
|
|
|
fail;
|
|
|
|
}
|
2011-10-07 02:36:53 -05:00
|
|
|
fn nf_view_item_dummy(&&_v: @view_item) -> @view_item { fail; }
|
|
|
|
fn nf_native_item_dummy(&&_n: @native_item) -> @native_item { fail; }
|
|
|
|
fn nf_item_dummy(&&_i: @item) -> @item { fail; }
|
2012-03-28 20:50:33 -05:00
|
|
|
fn nf_class_item_dummy(&&_ci: @class_member) -> @class_member { fail; }
|
2011-09-12 04:27:30 -05:00
|
|
|
fn nf_item_underscore_dummy(_i: item_) -> item_ { fail; }
|
2011-10-07 02:36:53 -05:00
|
|
|
fn nf_method_dummy(&&_m: @method) -> @method { fail; }
|
2011-09-12 04:27:30 -05:00
|
|
|
fn nf_blk_dummy(_b: blk) -> blk { fail; }
|
2011-10-07 02:36:53 -05:00
|
|
|
fn nf_stmt_dummy(&&_s: @stmt) -> @stmt { fail; }
|
2011-09-12 04:27:30 -05:00
|
|
|
fn nf_arm_dummy(_a: arm) -> arm { fail; }
|
2011-10-07 02:36:53 -05:00
|
|
|
fn nf_pat_dummy(&&_p: @pat) -> @pat { fail; }
|
|
|
|
fn nf_decl_dummy(&&_d: @decl) -> @decl { fail; }
|
|
|
|
fn nf_expr_dummy(&&_e: @expr) -> @expr { fail; }
|
|
|
|
fn nf_ty_dummy(&&_t: @ty) -> @ty { fail; }
|
|
|
|
fn nf_constr_dummy(&&_c: @constr) -> @constr { fail; }
|
2012-04-19 16:43:12 -05:00
|
|
|
fn nf_ty_constr_dummy(&&_c: @ty_constr) -> @ty_constr { fail; }
|
2011-09-12 04:27:30 -05:00
|
|
|
fn nf_mod_dummy(_m: _mod) -> _mod { fail; }
|
|
|
|
fn nf_native_mod_dummy(_n: native_mod) -> native_mod { fail; }
|
|
|
|
fn nf_variant_dummy(_v: variant) -> variant { fail; }
|
2011-10-10 06:54:03 -05:00
|
|
|
fn nf_ident_dummy(&&_i: ident) -> ident { fail; }
|
2011-12-20 09:33:55 -06:00
|
|
|
fn nf_path_dummy(&&_p: @path) -> @path { fail; }
|
2011-10-07 02:36:53 -05:00
|
|
|
fn nf_local_dummy(&&_o: @local) -> @local { fail; }
|
2011-06-20 19:25:49 -05:00
|
|
|
|
|
|
|
/* some little folds that probably aren't useful to have in ast_fold itself*/
|
|
|
|
|
|
|
|
//used in noop_fold_item and noop_fold_crate and noop_fold_crate_directive
|
2011-10-07 02:36:53 -05:00
|
|
|
fn fold_meta_item_(&&mi: @meta_item, fld: ast_fold) -> @meta_item {
|
2011-07-27 07:19:39 -05:00
|
|
|
ret @{node:
|
|
|
|
alt mi.node {
|
|
|
|
meta_word(id) { meta_word(fld.fold_ident(id)) }
|
|
|
|
meta_list(id, mis) {
|
|
|
|
let fold_meta_item = bind fold_meta_item_(_, fld);
|
2011-12-16 08:27:50 -06:00
|
|
|
meta_list(id, vec::map(mis, fold_meta_item))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
meta_name_value(id, s) {
|
|
|
|
meta_name_value(fld.fold_ident(id), s)
|
|
|
|
}
|
|
|
|
},
|
2012-03-15 09:15:49 -05:00
|
|
|
span: fld.new_span(mi.span)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
//used in noop_fold_item and noop_fold_crate
|
2012-03-15 09:15:49 -05:00
|
|
|
fn fold_attribute_(at: attribute, fld: ast_fold) ->
|
2011-07-27 07:19:39 -05:00
|
|
|
attribute {
|
2012-03-15 09:15:49 -05:00
|
|
|
ret {node: {style: at.node.style,
|
|
|
|
value: *fold_meta_item_(@at.node.value, fld)},
|
|
|
|
span: fld.new_span(at.span)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2011-12-22 10:49:54 -06:00
|
|
|
//used in noop_fold_native_item and noop_fold_fn_decl
|
2011-09-12 04:27:30 -05:00
|
|
|
fn fold_arg_(a: arg, fld: ast_fold) -> arg {
|
2012-02-14 17:21:53 -06:00
|
|
|
ret {mode: a.mode,
|
|
|
|
ty: fld.fold_ty(a.ty),
|
|
|
|
ident: fld.fold_ident(a.ident),
|
|
|
|
id: fld.new_id(a.id)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2011-07-08 18:35:09 -05:00
|
|
|
//used in noop_fold_expr, and possibly elsewhere in the future
|
2011-09-12 04:27:30 -05:00
|
|
|
fn fold_mac_(m: mac, fld: ast_fold) -> mac {
|
2011-07-27 07:19:39 -05:00
|
|
|
ret {node:
|
2011-08-19 17:16:48 -05:00
|
|
|
alt m.node {
|
|
|
|
mac_invoc(pth, arg, body) {
|
2012-02-01 01:20:31 -06:00
|
|
|
mac_invoc(fld.fold_path(pth),
|
2012-04-19 16:43:12 -05:00
|
|
|
option::map(arg, fld.fold_expr), body)
|
2011-08-19 17:16:48 -05:00
|
|
|
}
|
|
|
|
mac_embed_type(ty) { mac_embed_type(fld.fold_ty(ty)) }
|
|
|
|
mac_embed_block(blk) { mac_embed_block(fld.fold_block(blk)) }
|
2012-01-19 00:37:22 -06:00
|
|
|
mac_ellipsis { mac_ellipsis }
|
2012-01-25 17:38:09 -06:00
|
|
|
mac_aq(_,_) { /* fixme */ m.node }
|
|
|
|
mac_var(_) { /* fixme */ m.node }
|
2011-08-19 17:16:48 -05:00
|
|
|
},
|
2012-03-15 09:15:49 -05:00
|
|
|
span: fld.new_span(m.span)};
|
2011-07-08 18:35:09 -05:00
|
|
|
}
|
|
|
|
|
2011-12-20 13:03:21 -06:00
|
|
|
fn fold_fn_decl(decl: ast::fn_decl, fld: ast_fold) -> ast::fn_decl {
|
2011-12-29 22:07:55 -06:00
|
|
|
ret {inputs: vec::map(decl.inputs, bind fold_arg_(_, fld)),
|
2011-12-20 13:03:21 -06:00
|
|
|
output: fld.fold_ty(decl.output),
|
|
|
|
purity: decl.purity,
|
|
|
|
cf: decl.cf,
|
|
|
|
constraints: vec::map(decl.constraints, fld.fold_constr)}
|
|
|
|
}
|
2011-06-20 19:25:49 -05:00
|
|
|
|
2012-02-14 17:21:53 -06:00
|
|
|
fn fold_ty_param_bound(tpb: ty_param_bound, fld: ast_fold) -> ty_param_bound {
|
|
|
|
alt tpb {
|
|
|
|
bound_copy | bound_send { tpb }
|
|
|
|
bound_iface(ty) { bound_iface(fld.fold_ty(ty)) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fold_ty_param(tp: ty_param, fld: ast_fold) -> ty_param {
|
|
|
|
{ident: tp.ident,
|
|
|
|
id: fld.new_id(tp.id),
|
|
|
|
bounds: @vec::map(*tp.bounds, fold_ty_param_bound(_, fld))}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fold_ty_params(tps: [ty_param], fld: ast_fold) -> [ty_param] {
|
|
|
|
vec::map(tps, fold_ty_param(_, fld))
|
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn noop_fold_crate(c: crate_, fld: ast_fold) -> crate_ {
|
2011-07-27 07:19:39 -05:00
|
|
|
let fold_meta_item = bind fold_meta_item_(_, fld);
|
2012-03-15 09:15:49 -05:00
|
|
|
let fold_attribute = bind fold_attribute_(_, fld);
|
2011-06-20 19:25:49 -05:00
|
|
|
|
2011-12-16 08:27:50 -06:00
|
|
|
ret {directives: vec::map(c.directives, fld.fold_crate_directive),
|
2011-07-27 07:19:39 -05:00
|
|
|
module: fld.fold_mod(c.module),
|
2011-12-16 08:27:50 -06:00
|
|
|
attrs: vec::map(c.attrs, fold_attribute),
|
|
|
|
config: vec::map(c.config, fold_meta_item)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn noop_fold_crate_directive(cd: crate_directive_, fld: ast_fold) ->
|
2011-07-27 07:19:39 -05:00
|
|
|
crate_directive_ {
|
|
|
|
ret alt cd {
|
2011-11-21 22:31:09 -06:00
|
|
|
cdir_src_mod(id, attrs) {
|
|
|
|
cdir_src_mod(fld.fold_ident(id), attrs)
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-11-21 22:31:09 -06:00
|
|
|
cdir_dir_mod(id, cds, attrs) {
|
|
|
|
cdir_dir_mod(fld.fold_ident(id),
|
2011-12-16 08:27:50 -06:00
|
|
|
vec::map(cds, fld.fold_crate_directive), attrs)
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
cdir_view_item(vi) { cdir_view_item(fld.fold_view_item(vi)) }
|
|
|
|
cdir_syntax(_) { cd }
|
|
|
|
}
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn noop_fold_view_item(vi: view_item_, _fld: ast_fold) -> view_item_ {
|
2011-06-20 19:25:49 -05:00
|
|
|
ret vi;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-07 02:36:53 -05:00
|
|
|
fn noop_fold_native_item(&&ni: @native_item, fld: ast_fold) -> @native_item {
|
2011-07-27 07:19:39 -05:00
|
|
|
let fold_arg = bind fold_arg_(_, fld);
|
2012-03-15 09:15:49 -05:00
|
|
|
let fold_attribute = bind fold_attribute_(_, fld);
|
2011-07-27 07:19:39 -05:00
|
|
|
|
|
|
|
ret @{ident: fld.fold_ident(ni.ident),
|
2011-12-16 08:27:50 -06:00
|
|
|
attrs: vec::map(ni.attrs, fold_attribute),
|
2011-07-27 07:19:39 -05:00
|
|
|
node:
|
|
|
|
alt ni.node {
|
2011-11-14 07:06:39 -06:00
|
|
|
native_item_fn(fdec, typms) {
|
2011-12-29 22:07:55 -06:00
|
|
|
native_item_fn({inputs: vec::map(fdec.inputs, fold_arg),
|
2011-07-27 07:19:39 -05:00
|
|
|
output: fld.fold_ty(fdec.output),
|
|
|
|
purity: fdec.purity,
|
|
|
|
cf: fdec.cf,
|
|
|
|
constraints:
|
2011-12-16 08:27:50 -06:00
|
|
|
vec::map(fdec.constraints,
|
2012-02-14 17:21:53 -06:00
|
|
|
fld.fold_constr)},
|
|
|
|
fold_ty_params(typms, fld))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
},
|
2012-02-14 17:21:53 -06:00
|
|
|
id: fld.new_id(ni.id),
|
|
|
|
span: fld.new_span(ni.span)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2011-10-07 02:36:53 -05:00
|
|
|
fn noop_fold_item(&&i: @item, fld: ast_fold) -> @item {
|
2012-03-15 09:15:49 -05:00
|
|
|
let fold_attribute = bind fold_attribute_(_, fld);
|
2011-06-20 19:25:49 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
ret @{ident: fld.fold_ident(i.ident),
|
2011-12-16 08:27:50 -06:00
|
|
|
attrs: vec::map(i.attrs, fold_attribute),
|
2012-02-14 17:21:53 -06:00
|
|
|
id: fld.new_id(i.id),
|
2011-07-27 07:19:39 -05:00
|
|
|
node: fld.fold_item_underscore(i.node),
|
2012-02-14 17:21:53 -06:00
|
|
|
span: fld.new_span(i.span)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2012-03-28 20:50:33 -05:00
|
|
|
fn noop_fold_class_item(&&ci: @class_member, fld: ast_fold)
|
|
|
|
-> @class_member {
|
|
|
|
@{node: alt ci.node {
|
|
|
|
instance_var(ident, t, cm, id, p) {
|
|
|
|
instance_var(ident, fld.fold_ty(t), cm, id, p)
|
2012-01-31 21:30:40 -06:00
|
|
|
}
|
2012-03-19 12:19:00 -05:00
|
|
|
class_method(m) { class_method(fld.fold_method(m)) }
|
2012-03-28 20:50:33 -05:00
|
|
|
},
|
|
|
|
span: ci.span}
|
2012-01-31 21:30:40 -06:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
|
2011-07-27 07:19:39 -05:00
|
|
|
ret alt i {
|
|
|
|
item_const(t, e) { item_const(fld.fold_ty(t), fld.fold_expr(e)) }
|
2011-12-22 10:49:54 -06:00
|
|
|
item_fn(decl, typms, body) {
|
2012-02-14 17:21:53 -06:00
|
|
|
item_fn(fold_fn_decl(decl, fld),
|
|
|
|
fold_ty_params(typms, fld),
|
|
|
|
fld.fold_block(body))
|
2011-12-22 10:49:54 -06:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
item_mod(m) { item_mod(fld.fold_mod(m)) }
|
|
|
|
item_native_mod(nm) { item_native_mod(fld.fold_native_mod(nm)) }
|
2012-04-18 23:26:25 -05:00
|
|
|
item_ty(t, typms, rp) { item_ty(fld.fold_ty(t),
|
|
|
|
fold_ty_params(typms, fld),
|
|
|
|
rp) }
|
|
|
|
item_enum(variants, typms, r) {
|
2012-02-14 17:21:53 -06:00
|
|
|
item_enum(vec::map(variants, fld.fold_variant),
|
2012-04-18 23:26:25 -05:00
|
|
|
fold_ty_params(typms, fld),
|
|
|
|
r)
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-04-18 23:26:25 -05:00
|
|
|
item_class(typms, ifaces, items, ctor, rp) {
|
2012-03-03 19:49:23 -06:00
|
|
|
let ctor_body = fld.fold_block(ctor.node.body);
|
|
|
|
let ctor_decl = fold_fn_decl(ctor.node.dec, fld);
|
2012-04-10 12:52:06 -05:00
|
|
|
let ctor_id = fld.new_id(ctor.node.id);
|
2012-04-18 23:26:25 -05:00
|
|
|
item_class(
|
|
|
|
typms,
|
|
|
|
vec::map(ifaces, {|p|
|
|
|
|
{path: fld.fold_path(p.path),
|
|
|
|
id: fld.new_id(p.id)}}),
|
|
|
|
vec::map(items, fld.fold_class_item),
|
|
|
|
{node: {body: ctor_body,
|
|
|
|
dec: ctor_decl,
|
|
|
|
id: ctor_id with ctor.node}
|
|
|
|
with ctor},
|
|
|
|
rp)
|
2012-01-31 21:30:40 -06:00
|
|
|
}
|
2011-12-20 09:33:55 -06:00
|
|
|
item_impl(tps, ifce, ty, methods) {
|
|
|
|
item_impl(tps, option::map(ifce, fld.fold_ty), fld.fold_ty(ty),
|
2011-12-16 08:27:50 -06:00
|
|
|
vec::map(methods, fld.fold_method))
|
2011-12-13 06:19:56 -06:00
|
|
|
}
|
2012-01-30 04:52:34 -06:00
|
|
|
item_iface(tps, methods) { item_iface(tps, methods) }
|
2012-04-18 23:26:25 -05:00
|
|
|
item_res(decl, typms, body, did, cid, rp) {
|
2012-02-14 17:21:53 -06:00
|
|
|
item_res(fold_fn_decl(decl, fld),
|
|
|
|
fold_ty_params(typms, fld),
|
|
|
|
fld.fold_block(body),
|
2012-03-08 14:16:04 -06:00
|
|
|
fld.new_id(did),
|
2012-04-18 23:26:25 -05:00
|
|
|
fld.new_id(cid),
|
|
|
|
rp)
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2011-12-22 10:49:54 -06:00
|
|
|
fn noop_fold_method(&&m: @method, fld: ast_fold) -> @method {
|
|
|
|
ret @{ident: fld.fold_ident(m.ident),
|
2012-02-14 17:21:53 -06:00
|
|
|
attrs: m.attrs,
|
|
|
|
tps: fold_ty_params(m.tps, fld),
|
2011-12-22 10:49:54 -06:00
|
|
|
decl: fold_fn_decl(m.decl, fld),
|
2012-02-14 17:21:53 -06:00
|
|
|
body: fld.fold_block(m.body),
|
|
|
|
id: fld.new_id(m.id),
|
2012-03-07 05:54:00 -06:00
|
|
|
span: fld.new_span(m.span),
|
2012-03-28 20:50:33 -05:00
|
|
|
self_id: fld.new_id(m.self_id),
|
|
|
|
privacy: m.privacy};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn noop_fold_block(b: blk_, fld: ast_fold) -> blk_ {
|
2011-12-16 08:27:50 -06:00
|
|
|
ret {view_items: vec::map(b.view_items, fld.fold_view_item),
|
|
|
|
stmts: vec::map(b.stmts, fld.fold_stmt),
|
|
|
|
expr: option::map(b.expr, fld.fold_expr),
|
2012-02-14 17:21:53 -06:00
|
|
|
id: fld.new_id(b.id),
|
2011-08-25 19:42:38 -05:00
|
|
|
rules: b.rules};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ {
|
2011-07-27 07:19:39 -05:00
|
|
|
ret alt s {
|
2012-02-14 17:21:53 -06:00
|
|
|
stmt_decl(d, nid) { stmt_decl(fld.fold_decl(d), fld.new_id(nid)) }
|
|
|
|
stmt_expr(e, nid) { stmt_expr(fld.fold_expr(e), fld.new_id(nid)) }
|
|
|
|
stmt_semi(e, nid) { stmt_semi(fld.fold_expr(e), fld.new_id(nid)) }
|
2011-12-07 15:12:05 -06:00
|
|
|
};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn noop_fold_arm(a: arm, fld: ast_fold) -> arm {
|
2011-12-16 08:27:50 -06:00
|
|
|
ret {pats: vec::map(a.pats, fld.fold_pat),
|
|
|
|
guard: option::map(a.guard, fld.fold_expr),
|
2011-08-22 07:38:48 -05:00
|
|
|
body: fld.fold_block(a.body)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
|
2011-07-27 07:19:39 -05:00
|
|
|
ret alt p {
|
2012-01-19 00:37:22 -06:00
|
|
|
pat_wild { p }
|
2012-01-14 18:05:07 -06:00
|
|
|
pat_ident(pth, sub) {
|
|
|
|
pat_ident(fld.fold_path(pth), option::map(sub, fld.fold_pat))
|
2011-12-08 04:56:16 -06:00
|
|
|
}
|
2012-03-20 20:35:59 -05:00
|
|
|
pat_lit(e) { pat_lit(fld.fold_expr(e)) }
|
2012-01-25 07:34:31 -06:00
|
|
|
pat_enum(pth, pats) {
|
2012-04-20 02:54:42 -05:00
|
|
|
pat_enum(fld.fold_path(pth), option::map(pats)
|
|
|
|
{|pats| vec::map(pats, fld.fold_pat)})
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
pat_rec(fields, etc) {
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut fs = [];
|
2012-04-06 13:01:43 -05:00
|
|
|
for fields.each {|f|
|
2011-08-19 17:16:48 -05:00
|
|
|
fs += [{ident: f.ident, pat: fld.fold_pat(f.pat)}];
|
2011-07-11 07:13:20 -05:00
|
|
|
}
|
|
|
|
pat_rec(fs, etc)
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-12-16 08:27:50 -06:00
|
|
|
pat_tup(elts) { pat_tup(vec::map(elts, fld.fold_pat)) }
|
2011-07-27 07:19:39 -05:00
|
|
|
pat_box(inner) { pat_box(fld.fold_pat(inner)) }
|
2011-09-23 13:15:17 -05:00
|
|
|
pat_uniq(inner) { pat_uniq(fld.fold_pat(inner)) }
|
2012-03-20 20:35:59 -05:00
|
|
|
pat_range(e1, e2) {
|
|
|
|
pat_range(fld.fold_expr(e1), fld.fold_expr(e2))
|
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn noop_fold_decl(d: decl_, fld: ast_fold) -> decl_ {
|
2012-02-10 07:33:36 -06:00
|
|
|
alt d {
|
|
|
|
decl_local(ls) { decl_local(vec::map(ls, fld.fold_local)) }
|
|
|
|
decl_item(it) { decl_item(fld.fold_item(it)) }
|
|
|
|
}
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2012-01-22 18:30:07 -06:00
|
|
|
fn wrap<T>(f: fn@(T, ast_fold) -> T)
|
|
|
|
-> fn@(T, span, ast_fold) -> (T, span)
|
|
|
|
{
|
|
|
|
ret fn@(x: T, s: span, fld: ast_fold) -> (T, span) {
|
|
|
|
(f(x, fld), s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
|
|
|
|
fn fold_field_(field: field, fld: ast_fold) -> field {
|
2011-07-27 07:19:39 -05:00
|
|
|
ret {node:
|
2012-02-15 13:25:39 -06:00
|
|
|
{mutbl: field.node.mutbl,
|
2011-07-27 07:19:39 -05:00
|
|
|
ident: fld.fold_ident(field.node.ident),
|
|
|
|
expr: fld.fold_expr(field.node.expr)},
|
2012-03-15 09:15:49 -05:00
|
|
|
span: fld.new_span(field.span)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
let fold_field = bind fold_field_(_, fld);
|
2011-07-13 17:44:09 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
let fold_mac = bind fold_mac_(_, fld);
|
2011-06-20 19:25:49 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
ret alt e {
|
2012-03-14 14:16:46 -05:00
|
|
|
expr_new(p, i, v) {
|
|
|
|
expr_new(fld.fold_expr(p),
|
|
|
|
fld.new_id(i),
|
|
|
|
fld.fold_expr(v))
|
|
|
|
}
|
2012-04-09 19:32:49 -05:00
|
|
|
expr_vstore(e, v) {
|
|
|
|
expr_vstore(fld.fold_expr(e), v)
|
|
|
|
}
|
2012-03-09 18:11:56 -06:00
|
|
|
expr_vec(exprs, mutt) {
|
2012-01-14 18:05:07 -06:00
|
|
|
expr_vec(fld.map_exprs(fld.fold_expr, exprs), mutt)
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
expr_rec(fields, maybe_expr) {
|
2011-12-16 08:27:50 -06:00
|
|
|
expr_rec(vec::map(fields, fold_field),
|
|
|
|
option::map(maybe_expr, fld.fold_expr))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-12-16 08:27:50 -06:00
|
|
|
expr_tup(elts) { expr_tup(vec::map(elts, fld.fold_expr)) }
|
2011-10-21 07:11:24 -05:00
|
|
|
expr_call(f, args, blk) {
|
|
|
|
expr_call(fld.fold_expr(f), fld.map_exprs(fld.fold_expr, args),
|
|
|
|
blk)
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
expr_bind(f, args) {
|
2011-12-16 08:27:50 -06:00
|
|
|
let opt_map_se = bind option::map(_, fld.fold_expr);
|
|
|
|
expr_bind(fld.fold_expr(f), vec::map(args, opt_map_se))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
expr_binary(binop, lhs, rhs) {
|
2011-06-20 19:25:49 -05:00
|
|
|
expr_binary(binop, fld.fold_expr(lhs), fld.fold_expr(rhs))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
expr_unary(binop, ohs) { expr_unary(binop, fld.fold_expr(ohs)) }
|
2012-03-26 09:09:27 -05:00
|
|
|
expr_loop_body(f) { expr_loop_body(fld.fold_expr(f)) }
|
2011-07-27 07:19:39 -05:00
|
|
|
expr_lit(_) { e }
|
|
|
|
expr_cast(expr, ty) { expr_cast(fld.fold_expr(expr), ty) }
|
2012-03-08 18:34:36 -06:00
|
|
|
expr_addr_of(m, ohs) { expr_addr_of(m, fld.fold_expr(ohs)) }
|
2011-07-27 07:19:39 -05:00
|
|
|
expr_if(cond, tr, fl) {
|
2011-07-13 17:44:09 -05:00
|
|
|
expr_if(fld.fold_expr(cond), fld.fold_block(tr),
|
2011-12-16 08:27:50 -06:00
|
|
|
option::map(fl, fld.fold_expr))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
expr_while(cond, body) {
|
2011-06-20 19:25:49 -05:00
|
|
|
expr_while(fld.fold_expr(cond), fld.fold_block(body))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
expr_do_while(blk, expr) {
|
2011-07-25 15:42:38 -05:00
|
|
|
expr_do_while(fld.fold_block(blk), fld.fold_expr(expr))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-03-09 18:11:56 -06:00
|
|
|
expr_loop(body) {
|
|
|
|
expr_loop(fld.fold_block(body))
|
|
|
|
}
|
2012-02-15 02:35:11 -06:00
|
|
|
expr_alt(expr, arms, mode) {
|
|
|
|
expr_alt(fld.fold_expr(expr), vec::map(arms, fld.fold_arm), mode)
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-12-29 22:07:55 -06:00
|
|
|
expr_fn(proto, decl, body, captures) {
|
|
|
|
expr_fn(proto, fold_fn_decl(decl, fld),
|
|
|
|
fld.fold_block(body), captures)
|
2011-12-22 10:49:54 -06:00
|
|
|
}
|
2011-12-20 13:03:21 -06:00
|
|
|
expr_fn_block(decl, body) {
|
|
|
|
expr_fn_block(fold_fn_decl(decl, fld), fld.fold_block(body))
|
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
expr_block(blk) { expr_block(fld.fold_block(blk)) }
|
|
|
|
expr_move(el, er) {
|
2011-06-20 19:25:49 -05:00
|
|
|
expr_move(fld.fold_expr(el), fld.fold_expr(er))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-08-19 17:16:48 -05:00
|
|
|
expr_copy(e) { expr_copy(fld.fold_expr(e)) }
|
2011-07-27 07:19:39 -05:00
|
|
|
expr_assign(el, er) {
|
2011-06-20 19:25:49 -05:00
|
|
|
expr_assign(fld.fold_expr(el), fld.fold_expr(er))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
expr_swap(el, er) {
|
2011-06-30 02:35:05 -05:00
|
|
|
expr_swap(fld.fold_expr(el), fld.fold_expr(er))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
expr_assign_op(op, el, er) {
|
2011-06-20 19:25:49 -05:00
|
|
|
expr_assign_op(op, fld.fold_expr(el), fld.fold_expr(er))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-12-19 03:21:31 -06:00
|
|
|
expr_field(el, id, tys) {
|
|
|
|
expr_field(fld.fold_expr(el), fld.fold_ident(id),
|
|
|
|
vec::map(tys, fld.fold_ty))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
expr_index(el, er) {
|
2011-06-20 19:25:49 -05:00
|
|
|
expr_index(fld.fold_expr(el), fld.fold_expr(er))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
expr_path(pth) { expr_path(fld.fold_path(pth)) }
|
2011-12-16 08:27:50 -06:00
|
|
|
expr_fail(e) { expr_fail(option::map(e, fld.fold_expr)) }
|
2012-01-19 00:37:22 -06:00
|
|
|
expr_break | expr_cont { e }
|
2011-12-16 08:27:50 -06:00
|
|
|
expr_ret(e) { expr_ret(option::map(e, fld.fold_expr)) }
|
2011-07-27 07:19:39 -05:00
|
|
|
expr_be(e) { expr_be(fld.fold_expr(e)) }
|
2011-12-21 16:31:31 -06:00
|
|
|
expr_log(i, lv, e) { expr_log(i, fld.fold_expr(lv),
|
|
|
|
fld.fold_expr(e)) }
|
2011-07-27 07:19:39 -05:00
|
|
|
expr_assert(e) { expr_assert(fld.fold_expr(e)) }
|
|
|
|
expr_check(m, e) { expr_check(m, fld.fold_expr(e)) }
|
|
|
|
expr_if_check(cond, tr, fl) {
|
2011-07-13 17:44:09 -05:00
|
|
|
expr_if_check(fld.fold_expr(cond), fld.fold_block(tr),
|
2011-12-16 08:27:50 -06:00
|
|
|
option::map(fl, fld.fold_expr))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
expr_mac(mac) { expr_mac(fold_mac(mac)) }
|
2011-06-29 20:07:04 -05:00
|
|
|
}
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2012-02-01 22:21:01 -06:00
|
|
|
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 {
|
2012-02-15 13:25:39 -06:00
|
|
|
{ty: fld.fold_ty(mt.ty), mutbl: mt.mutbl}
|
2012-02-01 22:21:01 -06:00
|
|
|
}
|
|
|
|
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 {
|
2012-02-06 08:29:56 -06:00
|
|
|
ty_nil | ty_bot {t}
|
2012-02-01 22:21:01 -06:00
|
|
|
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))}
|
2012-03-08 12:49:43 -06:00
|
|
|
ty_rptr(region, mt) {ty_rptr(region, fold_mt(mt, fld))}
|
2012-02-01 22:21:01 -06:00
|
|
|
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))}
|
2012-04-19 16:43:12 -05:00
|
|
|
ty_constr(ty, constrs) {ty_constr(fld.fold_ty(ty),
|
|
|
|
vec::map(constrs, fld.fold_ty_constr))}
|
2012-04-09 19:32:49 -05:00
|
|
|
ty_vstore(t, vs) {ty_vstore(fld.fold_ty(t), vs)}
|
2012-02-01 22:21:01 -06:00
|
|
|
ty_mac(mac) {ty_mac(fold_mac(mac))}
|
|
|
|
ty_infer {t}
|
|
|
|
}
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn noop_fold_constr(c: constr_, fld: ast_fold) -> constr_ {
|
2012-02-14 17:21:53 -06:00
|
|
|
{path: fld.fold_path(c.path), args: c.args, id: fld.new_id(c.id)}
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2012-04-19 16:43:12 -05:00
|
|
|
fn noop_fold_ty_constr(c: ty_constr_, fld: ast_fold) -> ty_constr_ {
|
|
|
|
let rslt: ty_constr_ =
|
|
|
|
{path: fld.fold_path(c.path), args: c.args, id: fld.new_id(c.id)};
|
|
|
|
rslt
|
|
|
|
}
|
2011-06-20 19:25:49 -05:00
|
|
|
// ...nor do modules
|
2011-09-12 04:27:30 -05:00
|
|
|
fn noop_fold_mod(m: _mod, fld: ast_fold) -> _mod {
|
2011-12-16 08:27:50 -06:00
|
|
|
ret {view_items: vec::map(m.view_items, fld.fold_view_item),
|
|
|
|
items: vec::map(m.items, fld.fold_item)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn noop_fold_native_mod(nm: native_mod, fld: ast_fold) -> native_mod {
|
2011-12-16 08:27:50 -06:00
|
|
|
ret {view_items: vec::map(nm.view_items, fld.fold_view_item),
|
|
|
|
items: vec::map(nm.items, fld.fold_native_item)}
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
|
|
|
|
fn fold_variant_arg_(va: variant_arg, fld: ast_fold) -> variant_arg {
|
2012-02-14 17:21:53 -06:00
|
|
|
ret {ty: fld.fold_ty(va.ty), id: fld.new_id(va.id)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
let fold_variant_arg = bind fold_variant_arg_(_, fld);
|
2012-01-10 17:59:22 -06:00
|
|
|
let args = vec::map(v.args, fold_variant_arg);
|
2012-01-25 18:23:43 -06:00
|
|
|
|
2012-03-15 09:15:49 -05:00
|
|
|
let fold_attribute = bind fold_attribute_(_, fld);
|
2012-01-25 18:23:43 -06:00
|
|
|
let attrs = vec::map(v.attrs, fold_attribute);
|
|
|
|
|
2012-01-16 03:36:47 -06:00
|
|
|
let de = alt v.disr_expr {
|
|
|
|
some(e) {some(fld.fold_expr(e))}
|
2012-01-19 00:37:22 -06:00
|
|
|
none {none}
|
2012-01-10 17:59:22 -06:00
|
|
|
};
|
2012-01-25 18:23:43 -06:00
|
|
|
ret {name: v.name,
|
|
|
|
attrs: attrs,
|
2012-02-14 17:21:53 -06:00
|
|
|
args: args, id: fld.new_id(v.id),
|
2012-01-16 03:36:47 -06:00
|
|
|
disr_expr: de};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2011-10-10 06:54:03 -05:00
|
|
|
fn noop_fold_ident(&&i: ident, _fld: ast_fold) -> ident { ret i; }
|
2011-06-20 19:25:49 -05:00
|
|
|
|
2011-12-20 09:33:55 -06:00
|
|
|
fn noop_fold_path(&&p: path_, fld: ast_fold) -> path_ {
|
2011-07-27 07:19:39 -05:00
|
|
|
ret {global: p.global,
|
2011-12-16 08:27:50 -06:00
|
|
|
idents: vec::map(p.idents, fld.fold_ident),
|
|
|
|
types: vec::map(p.types, fld.fold_ty)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn noop_fold_local(l: local_, fld: ast_fold) -> local_ {
|
2012-02-28 21:28:29 -06:00
|
|
|
ret {is_mutbl: l.is_mutbl,
|
|
|
|
ty: fld.fold_ty(l.ty),
|
2011-07-28 05:01:45 -05:00
|
|
|
pat: fld.fold_pat(l.pat),
|
2011-08-19 17:16:48 -05:00
|
|
|
init:
|
|
|
|
alt l.init {
|
2012-01-19 03:03:57 -06:00
|
|
|
option::none::<initializer> { l.init }
|
2011-08-19 17:16:48 -05:00
|
|
|
option::some::<initializer>(init) {
|
|
|
|
option::some::<initializer>({op: init.op,
|
|
|
|
expr: fld.fold_expr(init.expr)})
|
|
|
|
}
|
|
|
|
},
|
2012-02-14 17:21:53 -06:00
|
|
|
id: fld.new_id(l.id)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2011-08-12 09:15:18 -05:00
|
|
|
/* temporarily eta-expand because of a compiler bug with using `fn<T>` as a
|
2011-07-21 18:47:47 -05:00
|
|
|
value */
|
2011-10-18 17:07:40 -05:00
|
|
|
fn noop_map_exprs(f: fn@(&&@expr) -> @expr, es: [@expr]) -> [@expr] {
|
2011-12-16 08:27:50 -06:00
|
|
|
ret vec::map(es, f);
|
2011-07-21 18:47:47 -05:00
|
|
|
}
|
|
|
|
|
2011-08-09 12:56:32 -05:00
|
|
|
fn noop_id(i: node_id) -> node_id { ret i; }
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn noop_span(sp: span) -> span { ret sp; }
|
2011-08-15 15:33:12 -05:00
|
|
|
|
2011-06-20 19:25:49 -05:00
|
|
|
|
|
|
|
fn default_ast_fold() -> @ast_fold_precursor {
|
2012-01-22 18:30:07 -06:00
|
|
|
ret @{fold_crate: wrap(noop_fold_crate),
|
|
|
|
fold_crate_directive: wrap(noop_fold_crate_directive),
|
2011-07-27 07:19:39 -05:00
|
|
|
fold_view_item: noop_fold_view_item,
|
|
|
|
fold_native_item: noop_fold_native_item,
|
|
|
|
fold_item: noop_fold_item,
|
2012-01-31 21:30:40 -06:00
|
|
|
fold_class_item: noop_fold_class_item,
|
2011-07-27 07:19:39 -05:00
|
|
|
fold_item_underscore: noop_fold_item_underscore,
|
|
|
|
fold_method: noop_fold_method,
|
2012-01-22 18:30:07 -06:00
|
|
|
fold_block: wrap(noop_fold_block),
|
|
|
|
fold_stmt: wrap(noop_fold_stmt),
|
2011-07-27 07:19:39 -05:00
|
|
|
fold_arm: noop_fold_arm,
|
2012-01-22 18:30:07 -06:00
|
|
|
fold_pat: wrap(noop_fold_pat),
|
|
|
|
fold_decl: wrap(noop_fold_decl),
|
|
|
|
fold_expr: wrap(noop_fold_expr),
|
|
|
|
fold_ty: wrap(noop_fold_ty),
|
|
|
|
fold_constr: wrap(noop_fold_constr),
|
2012-04-19 16:43:12 -05:00
|
|
|
fold_ty_constr: wrap(noop_fold_ty_constr),
|
2011-07-27 07:19:39 -05:00
|
|
|
fold_mod: noop_fold_mod,
|
|
|
|
fold_native_mod: noop_fold_native_mod,
|
2012-01-22 18:30:07 -06:00
|
|
|
fold_variant: wrap(noop_fold_variant),
|
2011-07-27 07:19:39 -05:00
|
|
|
fold_ident: noop_fold_ident,
|
2012-01-22 18:30:07 -06:00
|
|
|
fold_path: wrap(noop_fold_path),
|
|
|
|
fold_local: wrap(noop_fold_local),
|
2011-08-09 12:56:32 -05:00
|
|
|
map_exprs: noop_map_exprs,
|
2011-08-15 15:33:12 -05:00
|
|
|
new_id: noop_id,
|
|
|
|
new_span: noop_span};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2011-10-21 19:43:31 -05:00
|
|
|
fn make_fold(afp: ast_fold_precursor) -> ast_fold {
|
2011-10-18 17:07:40 -05:00
|
|
|
// FIXME: Have to bind all the bare functions into shared functions
|
2012-03-26 20:35:18 -05:00
|
|
|
// because @mut is invariant with respect to its contents
|
2012-04-19 16:43:12 -05:00
|
|
|
// I assume this has something to do with Issue #1973 - tjc
|
2011-07-27 07:19:39 -05:00
|
|
|
let result: ast_fold =
|
2012-03-26 20:35:18 -05:00
|
|
|
@mut {fold_crate: bind nf_crate_dummy(_),
|
2011-10-18 17:07:40 -05:00
|
|
|
fold_crate_directive: bind nf_crate_directive_dummy(_),
|
|
|
|
fold_view_item: bind nf_view_item_dummy(_),
|
|
|
|
fold_native_item: bind nf_native_item_dummy(_),
|
|
|
|
fold_item: bind nf_item_dummy(_),
|
2012-01-31 21:30:40 -06:00
|
|
|
fold_class_item: bind nf_class_item_dummy(_),
|
2011-10-18 17:07:40 -05:00
|
|
|
fold_item_underscore: bind nf_item_underscore_dummy(_),
|
|
|
|
fold_method: bind nf_method_dummy(_),
|
|
|
|
fold_block: bind nf_blk_dummy(_),
|
|
|
|
fold_stmt: bind nf_stmt_dummy(_),
|
|
|
|
fold_arm: bind nf_arm_dummy(_),
|
|
|
|
fold_pat: bind nf_pat_dummy(_),
|
|
|
|
fold_decl: bind nf_decl_dummy(_),
|
|
|
|
fold_expr: bind nf_expr_dummy(_),
|
|
|
|
fold_ty: bind nf_ty_dummy(_),
|
|
|
|
fold_constr: bind nf_constr_dummy(_),
|
2012-04-19 16:43:12 -05:00
|
|
|
fold_ty_constr: bind nf_ty_constr_dummy(_),
|
2011-10-18 17:07:40 -05:00
|
|
|
fold_mod: bind nf_mod_dummy(_),
|
|
|
|
fold_native_mod: bind nf_native_mod_dummy(_),
|
|
|
|
fold_variant: bind nf_variant_dummy(_),
|
|
|
|
fold_ident: bind nf_ident_dummy(_),
|
|
|
|
fold_path: bind nf_path_dummy(_),
|
|
|
|
fold_local: bind nf_local_dummy(_),
|
|
|
|
map_exprs: bind noop_map_exprs(_, _),
|
|
|
|
new_id: bind noop_id(_),
|
|
|
|
new_span: bind noop_span(_)};
|
2011-06-20 19:25:49 -05:00
|
|
|
|
|
|
|
/* naturally, a macro to write these would be nice */
|
2011-09-12 04:27:30 -05:00
|
|
|
fn f_crate(afp: ast_fold_precursor, f: ast_fold, c: crate) -> crate {
|
2012-01-22 18:30:07 -06:00
|
|
|
let (n, s) = afp.fold_crate(c.node, c.span, f);
|
|
|
|
ret {node: n, span: afp.new_span(s)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2011-09-12 04:27:30 -05:00
|
|
|
fn f_crate_directive(afp: ast_fold_precursor, f: ast_fold,
|
2011-10-07 02:36:53 -05:00
|
|
|
&&c: @crate_directive) -> @crate_directive {
|
2012-01-22 18:30:07 -06:00
|
|
|
let (n, s) = afp.fold_crate_directive(c.node, c.span, f);
|
|
|
|
ret @{node: n,
|
|
|
|
span: afp.new_span(s)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2011-10-07 02:36:53 -05:00
|
|
|
fn f_view_item(afp: ast_fold_precursor, f: ast_fold, &&x: @view_item) ->
|
2011-07-27 07:19:39 -05:00
|
|
|
@view_item {
|
2011-08-15 15:33:12 -05:00
|
|
|
ret @{node: afp.fold_view_item(x.node, f),
|
|
|
|
span: afp.new_span(x.span)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2011-10-07 02:36:53 -05:00
|
|
|
fn f_native_item(afp: ast_fold_precursor, f: ast_fold, &&x: @native_item)
|
|
|
|
-> @native_item {
|
2011-06-20 19:25:49 -05:00
|
|
|
ret afp.fold_native_item(x, f);
|
|
|
|
}
|
2011-10-07 02:36:53 -05:00
|
|
|
fn f_item(afp: ast_fold_precursor, f: ast_fold, &&i: @item) -> @item {
|
2011-06-20 19:25:49 -05:00
|
|
|
ret afp.fold_item(i, f);
|
|
|
|
}
|
2012-01-31 21:30:40 -06:00
|
|
|
fn f_class_item(afp: ast_fold_precursor, f: ast_fold,
|
2012-03-28 20:50:33 -05:00
|
|
|
&&ci: @class_member) -> @class_member {
|
|
|
|
@{node: alt ci.node {
|
|
|
|
instance_var(nm, t, mt, id, p) {
|
2012-01-31 21:30:40 -06:00
|
|
|
instance_var(nm, f_ty(afp, f, t),
|
2012-03-28 20:50:33 -05:00
|
|
|
mt, id, p)
|
2012-01-31 21:30:40 -06:00
|
|
|
}
|
2012-03-19 12:19:00 -05:00
|
|
|
class_method(m) {
|
|
|
|
class_method(afp.fold_method(m, f))
|
2012-01-31 21:30:40 -06:00
|
|
|
}
|
2012-03-28 20:50:33 -05:00
|
|
|
}, span: afp.new_span(ci.span)}
|
2012-01-31 21:30:40 -06:00
|
|
|
}
|
2011-09-12 04:27:30 -05:00
|
|
|
fn f_item_underscore(afp: ast_fold_precursor, f: ast_fold, i: item_) ->
|
2011-07-27 07:19:39 -05:00
|
|
|
item_ {
|
2011-06-20 19:25:49 -05:00
|
|
|
ret afp.fold_item_underscore(i, f);
|
|
|
|
}
|
2011-10-07 02:36:53 -05:00
|
|
|
fn f_method(afp: ast_fold_precursor, f: ast_fold, &&x: @method)
|
|
|
|
-> @method {
|
2011-12-22 10:49:54 -06:00
|
|
|
ret afp.fold_method(x, f);
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2011-09-12 04:27:30 -05:00
|
|
|
fn f_block(afp: ast_fold_precursor, f: ast_fold, x: blk) -> blk {
|
2012-01-22 18:30:07 -06:00
|
|
|
let (n, s) = afp.fold_block(x.node, x.span, f);
|
|
|
|
ret {node: n, span: afp.new_span(s)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2011-10-07 02:36:53 -05:00
|
|
|
fn f_stmt(afp: ast_fold_precursor, f: ast_fold, &&x: @stmt) -> @stmt {
|
2012-01-22 18:30:07 -06:00
|
|
|
let (n, s) = afp.fold_stmt(x.node, x.span, f);
|
|
|
|
ret @{node: n, span: afp.new_span(s)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2011-09-12 04:27:30 -05:00
|
|
|
fn f_arm(afp: ast_fold_precursor, f: ast_fold, x: arm) -> arm {
|
2011-06-20 19:25:49 -05:00
|
|
|
ret afp.fold_arm(x, f);
|
|
|
|
}
|
2011-10-07 02:36:53 -05:00
|
|
|
fn f_pat(afp: ast_fold_precursor, f: ast_fold, &&x: @pat) -> @pat {
|
2012-01-22 18:30:07 -06:00
|
|
|
let (n, s) = afp.fold_pat(x.node, x.span, f);
|
2011-08-09 12:56:32 -05:00
|
|
|
ret @{id: afp.new_id(x.id),
|
2012-01-22 18:30:07 -06:00
|
|
|
node: n,
|
|
|
|
span: afp.new_span(s)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2011-10-07 02:36:53 -05:00
|
|
|
fn f_decl(afp: ast_fold_precursor, f: ast_fold, &&x: @decl) -> @decl {
|
2012-01-22 18:30:07 -06:00
|
|
|
let (n, s) = afp.fold_decl(x.node, x.span, f);
|
|
|
|
ret @{node: n, span: afp.new_span(s)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2011-10-07 02:36:53 -05:00
|
|
|
fn f_expr(afp: ast_fold_precursor, f: ast_fold, &&x: @expr) -> @expr {
|
2012-01-22 18:30:07 -06:00
|
|
|
let (n, s) = afp.fold_expr(x.node, x.span, f);
|
2011-08-09 12:56:32 -05:00
|
|
|
ret @{id: afp.new_id(x.id),
|
2012-01-22 18:30:07 -06:00
|
|
|
node: n,
|
|
|
|
span: afp.new_span(s)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2011-10-07 02:36:53 -05:00
|
|
|
fn f_ty(afp: ast_fold_precursor, f: ast_fold, &&x: @ty) -> @ty {
|
2012-01-22 18:30:07 -06:00
|
|
|
let (n, s) = afp.fold_ty(x.node, x.span, f);
|
2012-03-20 20:35:59 -05:00
|
|
|
ret @{id: afp.new_id(x.id), node: n, span: afp.new_span(s)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2011-10-07 02:36:53 -05:00
|
|
|
fn f_constr(afp: ast_fold_precursor, f: ast_fold, &&x: @ast::constr) ->
|
2011-07-27 07:19:39 -05:00
|
|
|
@ast::constr {
|
2012-01-22 18:30:07 -06:00
|
|
|
let (n, s) = afp.fold_constr(x.node, x.span, f);
|
|
|
|
ret @{node: n, span: afp.new_span(s)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2012-04-19 16:43:12 -05:00
|
|
|
fn f_ty_constr(afp: ast_fold_precursor, f: ast_fold,
|
|
|
|
&&x: @ast::ty_constr) ->
|
|
|
|
@ast::ty_constr {
|
|
|
|
let (n, s) : (ty_constr_, span) =
|
|
|
|
afp.fold_ty_constr(x.node, x.span, f);
|
|
|
|
ret @{node: n, span: afp.new_span(s)};
|
|
|
|
}
|
2011-09-12 04:27:30 -05:00
|
|
|
fn f_mod(afp: ast_fold_precursor, f: ast_fold, x: _mod) -> _mod {
|
2011-06-20 19:25:49 -05:00
|
|
|
ret afp.fold_mod(x, f);
|
|
|
|
}
|
2011-09-12 04:27:30 -05:00
|
|
|
fn f_native_mod(afp: ast_fold_precursor, f: ast_fold, x: native_mod) ->
|
2011-07-27 07:19:39 -05:00
|
|
|
native_mod {
|
2011-06-20 19:25:49 -05:00
|
|
|
ret afp.fold_native_mod(x, f);
|
2011-07-13 17:44:09 -05:00
|
|
|
}
|
2011-09-12 04:27:30 -05:00
|
|
|
fn f_variant(afp: ast_fold_precursor, f: ast_fold, x: variant) ->
|
2011-07-27 07:19:39 -05:00
|
|
|
variant {
|
2012-01-22 18:30:07 -06:00
|
|
|
let (n, s) = afp.fold_variant(x.node, x.span, f);
|
|
|
|
ret {node: n, span: afp.new_span(s)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2011-10-10 06:54:03 -05:00
|
|
|
fn f_ident(afp: ast_fold_precursor, f: ast_fold, &&x: ident) -> ident {
|
2011-06-20 19:25:49 -05:00
|
|
|
ret afp.fold_ident(x, f);
|
|
|
|
}
|
2011-12-20 09:33:55 -06:00
|
|
|
fn f_path(afp: ast_fold_precursor, f: ast_fold, &&x: @path) -> @path {
|
2012-01-22 18:30:07 -06:00
|
|
|
let (n, s) = afp.fold_path(x.node, x.span, f);
|
|
|
|
ret @{node: n, span: afp.new_span(s)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2011-10-07 02:36:53 -05:00
|
|
|
fn f_local(afp: ast_fold_precursor, f: ast_fold, &&x: @local) -> @local {
|
2012-01-22 18:30:07 -06:00
|
|
|
let (n, s) = afp.fold_local(x.node, x.span, f);
|
|
|
|
ret @{node: n, span: afp.new_span(s)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
*result =
|
|
|
|
{fold_crate: bind f_crate(afp, result, _),
|
|
|
|
fold_crate_directive: bind f_crate_directive(afp, result, _),
|
|
|
|
fold_view_item: bind f_view_item(afp, result, _),
|
|
|
|
fold_native_item: bind f_native_item(afp, result, _),
|
|
|
|
fold_item: bind f_item(afp, result, _),
|
2012-01-31 21:30:40 -06:00
|
|
|
fold_class_item: bind f_class_item(afp, result, _),
|
2011-07-27 07:19:39 -05:00
|
|
|
fold_item_underscore: bind f_item_underscore(afp, result, _),
|
|
|
|
fold_method: bind f_method(afp, result, _),
|
|
|
|
fold_block: bind f_block(afp, result, _),
|
|
|
|
fold_stmt: bind f_stmt(afp, result, _),
|
|
|
|
fold_arm: bind f_arm(afp, result, _),
|
|
|
|
fold_pat: bind f_pat(afp, result, _),
|
|
|
|
fold_decl: bind f_decl(afp, result, _),
|
|
|
|
fold_expr: bind f_expr(afp, result, _),
|
|
|
|
fold_ty: bind f_ty(afp, result, _),
|
|
|
|
fold_constr: bind f_constr(afp, result, _),
|
2012-04-19 16:43:12 -05:00
|
|
|
fold_ty_constr: bind f_ty_constr(afp, result, _),
|
2011-07-27 07:19:39 -05:00
|
|
|
fold_mod: bind f_mod(afp, result, _),
|
|
|
|
fold_native_mod: bind f_native_mod(afp, result, _),
|
|
|
|
fold_variant: bind f_variant(afp, result, _),
|
|
|
|
fold_ident: bind f_ident(afp, result, _),
|
|
|
|
fold_path: bind f_path(afp, result, _),
|
|
|
|
fold_local: bind f_local(afp, result, _),
|
2011-08-09 12:56:32 -05:00
|
|
|
map_exprs: afp.map_exprs,
|
2011-08-15 15:33:12 -05:00
|
|
|
new_id: afp.new_id,
|
|
|
|
new_span: afp.new_span};
|
2011-10-21 19:43:31 -05:00
|
|
|
ret result;
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|
|
|
|
//
|