2012-09-04 13:37:29 -05:00
|
|
|
use codemap::span;
|
|
|
|
use ast::*;
|
2011-06-20 19:25:49 -05:00
|
|
|
|
|
|
|
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-11-01 17:48:37 -05:00
|
|
|
export noop_fold_item_underscore;
|
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;
|
2012-07-16 21:16:19 -05:00
|
|
|
export extensions;
|
2011-06-20 19:25:49 -05:00
|
|
|
|
2012-07-31 12:27:51 -05:00
|
|
|
trait ast_fold {
|
2012-05-21 20:28:39 -05:00
|
|
|
fn fold_crate(crate) -> crate;
|
2012-09-23 06:39:27 -05:00
|
|
|
fn fold_view_item(&&v: @view_item) -> @view_item;
|
|
|
|
fn fold_foreign_item(&&v: @foreign_item) -> @foreign_item;
|
|
|
|
fn fold_item(&&v: @item) -> Option<@item>;
|
|
|
|
fn fold_struct_field(&&v: @struct_field) -> @struct_field;
|
2012-05-21 20:28:39 -05:00
|
|
|
fn fold_item_underscore(item_) -> item_;
|
2012-09-23 06:39:27 -05:00
|
|
|
fn fold_method(&&v: @method) -> @method;
|
2012-05-21 20:28:39 -05:00
|
|
|
fn fold_block(blk) -> blk;
|
2012-09-23 06:39:27 -05:00
|
|
|
fn fold_stmt(&&v: @stmt) -> @stmt;
|
2012-05-21 20:28:39 -05:00
|
|
|
fn fold_arm(arm) -> arm;
|
2012-09-23 06:39:27 -05:00
|
|
|
fn fold_pat(&&v: @pat) -> @pat;
|
|
|
|
fn fold_decl(&&v: @decl) -> @decl;
|
|
|
|
fn fold_expr(&&v: @expr) -> @expr;
|
2012-10-15 16:56:42 -05:00
|
|
|
fn fold_ty(&&v: @Ty) -> @Ty;
|
2012-05-21 20:28:39 -05:00
|
|
|
fn fold_mod(_mod) -> _mod;
|
2012-06-26 18:18:37 -05:00
|
|
|
fn fold_foreign_mod(foreign_mod) -> foreign_mod;
|
2012-05-21 20:28:39 -05:00
|
|
|
fn fold_variant(variant) -> variant;
|
2012-09-23 06:39:27 -05:00
|
|
|
fn fold_ident(&&v: ident) -> ident;
|
|
|
|
fn fold_path(&&v: @path) -> @path;
|
|
|
|
fn fold_local(&&v: @local) -> @local;
|
|
|
|
fn map_exprs(fn@(&&v: @expr) -> @expr, ~[@expr]) -> ~[@expr];
|
2012-05-21 20:28:39 -05:00
|
|
|
fn new_id(node_id) -> node_id;
|
|
|
|
fn new_span(span) -> span;
|
|
|
|
}
|
2011-06-20 19:25:49 -05:00
|
|
|
|
|
|
|
// We may eventually want to be able to fold over type parameters, too
|
|
|
|
|
2012-05-21 20:28:39 -05:00
|
|
|
type ast_fold_precursor = @{
|
2011-07-27 07:19:39 -05:00
|
|
|
//unlike the others, item_ is non-trivial
|
2012-05-21 20:28:39 -05:00
|
|
|
fold_crate: fn@(crate_, span, ast_fold) -> (crate_, span),
|
|
|
|
fold_view_item: fn@(view_item_, ast_fold) -> view_item_,
|
2012-09-23 06:39:27 -05:00
|
|
|
fold_foreign_item: fn@(&&v: @foreign_item, ast_fold) -> @foreign_item,
|
|
|
|
fold_item: fn@(&&v: @item, ast_fold) -> Option<@item>,
|
|
|
|
fold_struct_field: fn@(&&v: @struct_field, ast_fold) -> @struct_field,
|
2012-05-21 20:28:39 -05:00
|
|
|
fold_item_underscore: fn@(item_, ast_fold) -> item_,
|
2012-09-23 06:39:27 -05:00
|
|
|
fold_method: fn@(&&v: @method, ast_fold) -> @method,
|
2012-05-21 20:28:39 -05:00
|
|
|
fold_block: fn@(blk_, span, ast_fold) -> (blk_, span),
|
|
|
|
fold_stmt: fn@(stmt_, span, ast_fold) -> (stmt_, span),
|
|
|
|
fold_arm: fn@(arm, ast_fold) -> arm,
|
|
|
|
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_mod: fn@(_mod, ast_fold) -> _mod,
|
2012-06-26 18:18:37 -05:00
|
|
|
fold_foreign_mod: fn@(foreign_mod, ast_fold) -> foreign_mod,
|
2012-05-21 20:28:39 -05:00
|
|
|
fold_variant: fn@(variant_, span, ast_fold) -> (variant_, span),
|
2012-09-23 06:39:27 -05:00
|
|
|
fold_ident: fn@(&&v: ident, ast_fold) -> ident,
|
2012-05-21 20:28:39 -05:00
|
|
|
fold_path: fn@(path, ast_fold) -> path,
|
|
|
|
fold_local: fn@(local_, span, ast_fold) -> (local_, span),
|
2012-09-23 06:39:27 -05:00
|
|
|
map_exprs: fn@(fn@(&&v: @expr) -> @expr, ~[@expr]) -> ~[@expr],
|
2012-05-21 20:28:39 -05:00
|
|
|
new_id: fn@(node_id) -> node_id,
|
|
|
|
new_span: fn@(span) -> span};
|
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
|
2012-09-20 20:15:39 -05:00
|
|
|
fn fold_meta_item_(&&mi: @meta_item, fld: ast_fold) -> @meta_item {
|
|
|
|
return @{node:
|
2012-08-06 14:34:08 -05:00
|
|
|
match mi.node {
|
2012-07-18 18:18:02 -05:00
|
|
|
meta_word(id) => meta_word(id),
|
2012-08-03 21:59:04 -05:00
|
|
|
meta_list(id, mis) => {
|
2012-06-30 18:19:07 -05:00
|
|
|
let fold_meta_item = |x|fold_meta_item_(x, fld);
|
2012-06-21 18:44:10 -05:00
|
|
|
meta_list(/* FIXME: (#2543) */ copy id,
|
2012-09-21 20:43:30 -05:00
|
|
|
vec::map(mis, |e| fold_meta_item(*e)))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
meta_name_value(id, s) => {
|
2012-07-18 18:18:02 -05:00
|
|
|
meta_name_value(id, /* FIXME (#2543) */ copy s)
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
},
|
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-08-01 19:30:05 -05:00
|
|
|
return {node: {style: at.node.style,
|
2012-09-20 20:15:39 -05:00
|
|
|
value: *fold_meta_item_(@at.node.value, fld),
|
2012-06-30 05:54:54 -05:00
|
|
|
is_sugared_doc: at.node.is_sugared_doc },
|
2012-03-15 09:15:49 -05:00
|
|
|
span: fld.new_span(at.span)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2012-06-26 18:18:37 -05:00
|
|
|
//used in noop_fold_foreign_item and noop_fold_fn_decl
|
2011-09-12 04:27:30 -05:00
|
|
|
fn fold_arg_(a: arg, fld: ast_fold) -> arg {
|
2012-08-01 19:30:05 -05:00
|
|
|
return {mode: a.mode,
|
2012-11-06 20:41:06 -06:00
|
|
|
ty: fld.fold_ty(a.ty),
|
|
|
|
pat: fld.fold_pat(a.pat),
|
|
|
|
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 {
|
2012-08-01 19:30:05 -05:00
|
|
|
return {node:
|
2012-08-06 14:34:08 -05:00
|
|
|
match m.node {
|
2012-08-03 21:59:04 -05:00
|
|
|
mac_invoc(pth, arg, body) => {
|
2012-02-01 01:20:31 -06:00
|
|
|
mac_invoc(fld.fold_path(pth),
|
2012-09-26 18:27:12 -05:00
|
|
|
option::map(&arg, |x| fld.fold_expr(*x)), body)
|
2011-08-19 17:16:48 -05:00
|
|
|
}
|
2012-08-24 16:04:38 -05:00
|
|
|
mac_invoc_tt(*) => m.node,
|
2012-08-03 21:59:04 -05:00
|
|
|
mac_ellipsis => mac_ellipsis,
|
|
|
|
mac_aq(_,_) => /* FIXME (#2543) */ copy m.node,
|
|
|
|
mac_var(_) => /* FIXME (#2543) */ copy 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 {
|
2012-09-21 20:43:30 -05:00
|
|
|
return {inputs: vec::map(decl.inputs, |x| fold_arg_(*x, fld) ),
|
2011-12-20 13:03:21 -06:00
|
|
|
output: fld.fold_ty(decl.output),
|
2012-07-13 20:43:52 -05:00
|
|
|
cf: decl.cf}
|
2011-12-20 13:03:21 -06:00
|
|
|
}
|
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 {
|
2012-10-17 00:14:59 -05:00
|
|
|
ty_param_bound(fld.fold_ty(*tpb))
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn fold_ty_param(tp: ty_param, fld: ast_fold) -> ty_param {
|
2012-06-21 18:44:10 -05:00
|
|
|
{ident: /* FIXME (#2543) */ copy tp.ident,
|
2012-02-14 17:21:53 -06:00
|
|
|
id: fld.new_id(tp.id),
|
2012-09-21 20:43:30 -05:00
|
|
|
bounds: @vec::map(*tp.bounds, |x| fold_ty_param_bound(*x, fld) )}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn fold_ty_params(tps: ~[ty_param], fld: ast_fold) -> ~[ty_param] {
|
2012-09-21 20:43:30 -05:00
|
|
|
vec::map(tps, |x| fold_ty_param(*x, fld) )
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn noop_fold_crate(c: crate_, fld: ast_fold) -> crate_ {
|
2012-06-30 18:19:07 -05:00
|
|
|
let fold_meta_item = |x| fold_meta_item_(x, fld);
|
|
|
|
let fold_attribute = |x| fold_attribute_(x, fld);
|
2011-06-20 19:25:49 -05:00
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
return {
|
|
|
|
module: fld.fold_mod(c.module),
|
2012-09-21 20:43:30 -05:00
|
|
|
attrs: vec::map(c.attrs, |x| fold_attribute(*x)),
|
|
|
|
config: vec::map(c.config, |x| fold_meta_item(*x))
|
2012-08-01 19:30:05 -05:00
|
|
|
};
|
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_ {
|
2012-08-01 19:30:05 -05:00
|
|
|
return /* FIXME (#2543) */ copy vi;
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-26 18:18:37 -05:00
|
|
|
fn noop_fold_foreign_item(&&ni: @foreign_item, fld: ast_fold)
|
|
|
|
-> @foreign_item {
|
2012-06-30 18:19:07 -05:00
|
|
|
let fold_arg = |x| fold_arg_(x, fld);
|
|
|
|
let fold_attribute = |x| fold_attribute_(x, fld);
|
2011-07-27 07:19:39 -05:00
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
return @{ident: fld.fold_ident(ni.ident),
|
2012-09-21 20:43:30 -05:00
|
|
|
attrs: vec::map(ni.attrs, |x| fold_attribute(*x)),
|
2011-07-27 07:19:39 -05:00
|
|
|
node:
|
2012-08-06 14:34:08 -05:00
|
|
|
match ni.node {
|
2012-08-23 20:17:16 -05:00
|
|
|
foreign_item_fn(fdec, purity, typms) => {
|
2012-09-21 20:43:30 -05:00
|
|
|
foreign_item_fn(
|
|
|
|
{inputs: vec::map(fdec.inputs, |a| fold_arg(*a)),
|
|
|
|
output: fld.fold_ty(fdec.output),
|
|
|
|
cf: fdec.cf},
|
|
|
|
purity,
|
|
|
|
fold_ty_params(typms, fld))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-25 17:09:33 -05:00
|
|
|
foreign_item_const(t) => {
|
|
|
|
foreign_item_const(fld.fold_ty(t))
|
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
},
|
2012-02-14 17:21:53 -06:00
|
|
|
id: fld.new_id(ni.id),
|
2012-09-27 13:52:36 -05:00
|
|
|
span: fld.new_span(ni.span),
|
|
|
|
vis: ni.vis};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2012-08-20 14:23:37 -05:00
|
|
|
fn noop_fold_item(&&i: @item, fld: ast_fold) -> Option<@item> {
|
2012-06-30 18:19:07 -05:00
|
|
|
let fold_attribute = |x| fold_attribute_(x, fld);
|
2011-06-20 19:25:49 -05:00
|
|
|
|
2012-08-20 14:23:37 -05:00
|
|
|
return Some(@{ident: fld.fold_ident(i.ident),
|
2012-09-21 20:43:30 -05:00
|
|
|
attrs: vec::map(i.attrs, |e| fold_attribute(*e)),
|
2012-07-06 14:17:34 -05:00
|
|
|
id: fld.new_id(i.id),
|
|
|
|
node: fld.fold_item_underscore(i.node),
|
|
|
|
vis: i.vis,
|
|
|
|
span: fld.new_span(i.span)});
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2012-08-15 17:53:58 -05:00
|
|
|
fn noop_fold_struct_field(&&sf: @struct_field, fld: ast_fold)
|
|
|
|
-> @struct_field {
|
|
|
|
@{node: {kind: copy sf.node.kind,
|
|
|
|
id: sf.node.id,
|
|
|
|
ty: fld.fold_ty(sf.node.ty)},
|
|
|
|
span: sf.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_ {
|
2012-08-06 14:34:08 -05:00
|
|
|
return match i {
|
2012-08-03 21:59:04 -05:00
|
|
|
item_const(t, e) => item_const(fld.fold_ty(t), fld.fold_expr(e)),
|
2012-08-23 20:17:16 -05:00
|
|
|
item_fn(decl, purity, typms, body) => {
|
2012-02-14 17:21:53 -06:00
|
|
|
item_fn(fold_fn_decl(decl, fld),
|
2012-08-23 20:17:16 -05:00
|
|
|
purity,
|
2012-02-14 17:21:53 -06:00
|
|
|
fold_ty_params(typms, fld),
|
|
|
|
fld.fold_block(body))
|
2011-12-22 10:49:54 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
item_mod(m) => item_mod(fld.fold_mod(m)),
|
|
|
|
item_foreign_mod(nm) => item_foreign_mod(fld.fold_foreign_mod(nm)),
|
|
|
|
item_ty(t, typms) => item_ty(fld.fold_ty(t),
|
|
|
|
fold_ty_params(typms, fld)),
|
2012-08-08 19:14:25 -05:00
|
|
|
item_enum(enum_definition, typms) => {
|
|
|
|
item_enum(ast::enum_def({
|
|
|
|
variants: vec::map(enum_definition.variants,
|
2012-09-21 20:43:30 -05:00
|
|
|
|x| fld.fold_variant(*x)),
|
2012-09-21 21:37:57 -05:00
|
|
|
common: option::map(&enum_definition.common,
|
2012-09-26 18:27:12 -05:00
|
|
|
|x| fold_struct_def(*x, fld))
|
2012-08-08 19:14:25 -05:00
|
|
|
}), fold_ty_params(typms, fld))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-07 17:34:07 -05:00
|
|
|
item_class(struct_def, typms) => {
|
2012-08-08 21:51:19 -05:00
|
|
|
let struct_def = fold_struct_def(struct_def, fld);
|
|
|
|
item_class(struct_def, /* FIXME (#2543) */ copy typms)
|
2012-01-31 21:30:40 -06:00
|
|
|
}
|
2012-11-13 21:08:01 -06:00
|
|
|
item_impl(tps, ifce, ty, ref methods) => {
|
2012-04-24 17:52:52 -05:00
|
|
|
item_impl(fold_ty_params(tps, fld),
|
2012-09-26 18:27:12 -05:00
|
|
|
ifce.map(|p| fold_trait_ref(*p, fld)),
|
2012-04-13 14:22:35 -05:00
|
|
|
fld.fold_ty(ty),
|
2012-11-13 21:08:01 -06:00
|
|
|
vec::map(*methods, |x| fld.fold_method(*x)))
|
2012-04-24 17:52:52 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
item_trait(tps, traits, methods) => {
|
2012-11-03 01:11:36 -05:00
|
|
|
let methods = do methods.map |method| {
|
|
|
|
match *method {
|
|
|
|
required(*) => copy *method,
|
|
|
|
provided(method) => provided(fld.fold_method(method))
|
|
|
|
}
|
|
|
|
};
|
2012-07-03 18:30:42 -05:00
|
|
|
item_trait(fold_ty_params(tps, fld),
|
2012-09-21 20:43:30 -05:00
|
|
|
vec::map(traits, |p| fold_trait_ref(*p, fld)),
|
2012-11-03 01:11:36 -05:00
|
|
|
move methods)
|
2011-12-13 06:19:56 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
item_mac(m) => {
|
2012-07-12 20:08:55 -05:00
|
|
|
// FIXME #2888: we might actually want to do something here.
|
2012-07-05 14:10:33 -05:00
|
|
|
item_mac(m)
|
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2012-08-08 21:51:19 -05:00
|
|
|
fn fold_struct_def(struct_def: @ast::struct_def, fld: ast_fold)
|
|
|
|
-> @ast::struct_def {
|
2012-09-21 21:37:57 -05:00
|
|
|
let dtor = do option::map(&struct_def.dtor) |dtor| {
|
2012-08-08 21:51:19 -05:00
|
|
|
let dtor_body = fld.fold_block(dtor.node.body);
|
|
|
|
let dtor_id = fld.new_id(dtor.node.id);
|
|
|
|
{node: {body: dtor_body,
|
2012-09-04 15:29:32 -05:00
|
|
|
id: dtor_id,.. dtor.node},
|
2012-09-26 18:27:12 -05:00
|
|
|
.. *dtor}};
|
2012-08-08 21:51:19 -05:00
|
|
|
return @{
|
2012-09-21 20:43:30 -05:00
|
|
|
traits: vec::map(struct_def.traits, |p| fold_trait_ref(*p, fld)),
|
|
|
|
fields: vec::map(struct_def.fields, |f| fold_struct_field(*f, fld)),
|
|
|
|
methods: vec::map(struct_def.methods, |m| fld.fold_method(*m)),
|
2012-10-23 21:18:18 -05:00
|
|
|
dtor: dtor,
|
2012-10-24 16:36:00 -05:00
|
|
|
ctor_id: option::map(&struct_def.ctor_id, |cid| fld.new_id(*cid))
|
2012-08-08 21:51:19 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-07-03 18:30:42 -05:00
|
|
|
fn fold_trait_ref(&&p: @trait_ref, fld: ast_fold) -> @trait_ref {
|
2012-06-26 18:25:52 -05:00
|
|
|
@{path: fld.fold_path(p.path), ref_id: fld.new_id(p.ref_id),
|
|
|
|
impl_id: fld.new_id(p.impl_id)}
|
2012-04-13 14:22:35 -05:00
|
|
|
}
|
|
|
|
|
2012-08-15 17:53:58 -05:00
|
|
|
fn fold_struct_field(&&f: @struct_field, fld: ast_fold) -> @struct_field {
|
|
|
|
@{node: {kind: copy f.node.kind,
|
|
|
|
id: fld.new_id(f.node.id),
|
|
|
|
ty: fld.fold_ty(f.node.ty)},
|
|
|
|
span: fld.new_span(f.span)}
|
|
|
|
}
|
|
|
|
|
2011-12-22 10:49:54 -06:00
|
|
|
fn noop_fold_method(&&m: @method, fld: ast_fold) -> @method {
|
2012-08-01 19:30:05 -05:00
|
|
|
return @{ident: fld.fold_ident(m.ident),
|
2012-06-21 18:44:10 -05:00
|
|
|
attrs: /* FIXME (#2543) */ copy m.attrs,
|
2012-02-14 17:21:53 -06:00
|
|
|
tps: fold_ty_params(m.tps, fld),
|
2012-07-30 18:33:02 -05:00
|
|
|
self_ty: m.self_ty,
|
2012-08-23 20:17:16 -05:00
|
|
|
purity: m.purity,
|
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),
|
2012-05-08 09:06:24 -05:00
|
|
|
vis: m.vis};
|
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_ {
|
2012-09-21 20:43:30 -05:00
|
|
|
return {view_items: vec::map(b.view_items, |x| fld.fold_view_item(*x)),
|
|
|
|
stmts: vec::map(b.stmts, |x| fld.fold_stmt(*x)),
|
2012-09-26 18:27:12 -05:00
|
|
|
expr: option::map(&b.expr, |x| fld.fold_expr(*x)),
|
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_ {
|
2012-11-12 22:06:55 -06:00
|
|
|
let fold_mac = |x| fold_mac_(x, fld);
|
2012-08-06 14:34:08 -05:00
|
|
|
return match s {
|
2012-08-03 21:59:04 -05: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)),
|
2012-11-12 22:06:55 -06:00
|
|
|
stmt_semi(e, nid) => stmt_semi(fld.fold_expr(e), fld.new_id(nid)),
|
2012-11-21 12:37:43 -06:00
|
|
|
stmt_mac(mac, semi) => stmt_mac(fold_mac(mac), semi)
|
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 {
|
2012-09-21 20:43:30 -05:00
|
|
|
return {pats: vec::map(a.pats, |x| fld.fold_pat(*x)),
|
2012-09-26 18:27:12 -05:00
|
|
|
guard: option::map(&a.guard, |x| fld.fold_expr(*x)),
|
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_ {
|
2012-08-06 14:34:08 -05:00
|
|
|
return match p {
|
2012-08-03 21:59:04 -05:00
|
|
|
pat_wild => pat_wild,
|
|
|
|
pat_ident(binding_mode, pth, sub) => {
|
2012-07-31 21:25:24 -05:00
|
|
|
pat_ident(binding_mode,
|
|
|
|
fld.fold_path(pth),
|
2012-09-26 18:27:12 -05:00
|
|
|
option::map(&sub, |x| fld.fold_pat(*x)))
|
2011-12-08 04:56:16 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
pat_lit(e) => pat_lit(fld.fold_expr(e)),
|
|
|
|
pat_enum(pth, pats) => {
|
2012-09-21 21:37:57 -05:00
|
|
|
pat_enum(fld.fold_path(pth), option::map(&pats,
|
2012-09-26 18:27:12 -05:00
|
|
|
|pats| vec::map(*pats, |x| fld.fold_pat(*x))))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
pat_rec(fields, etc) => {
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut fs = ~[];
|
2012-06-30 18:19:07 -05:00
|
|
|
for fields.each |f| {
|
2012-09-26 19:33:34 -05:00
|
|
|
fs.push({ident: /* FIXME (#2543) */ copy 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
|
|
|
}
|
2012-08-06 19:01:14 -05:00
|
|
|
pat_struct(pth, fields, etc) => {
|
|
|
|
let pth_ = fld.fold_path(pth);
|
|
|
|
let mut fs = ~[];
|
|
|
|
for fields.each |f| {
|
2012-09-26 19:33:34 -05:00
|
|
|
fs.push({ident: /* FIXME (#2543) */ copy f.ident,
|
|
|
|
pat: fld.fold_pat(f.pat)});
|
2012-08-06 19:01:14 -05:00
|
|
|
}
|
|
|
|
pat_struct(pth_, fs, etc)
|
|
|
|
}
|
2012-09-21 20:43:30 -05:00
|
|
|
pat_tup(elts) => pat_tup(vec::map(elts, |x| fld.fold_pat(*x))),
|
2012-08-03 21:59:04 -05:00
|
|
|
pat_box(inner) => pat_box(fld.fold_pat(inner)),
|
|
|
|
pat_uniq(inner) => pat_uniq(fld.fold_pat(inner)),
|
2012-09-07 19:07:32 -05:00
|
|
|
pat_region(inner) => pat_region(fld.fold_pat(inner)),
|
2012-08-03 21:59:04 -05:00
|
|
|
pat_range(e1, e2) => {
|
2012-03-20 20:35:59 -05:00
|
|
|
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-08-06 14:34:08 -05:00
|
|
|
match d {
|
2012-09-21 20:43:30 -05:00
|
|
|
decl_local(ls) => decl_local(vec::map(ls, |x| fld.fold_local(*x))),
|
2012-08-06 14:34:08 -05:00
|
|
|
decl_item(it) => match fld.fold_item(it) {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(it_folded) => decl_item(it_folded),
|
|
|
|
None => decl_local(~[])
|
2012-07-06 14:17:34 -05:00
|
|
|
}
|
2012-02-10 07:33:36 -06:00
|
|
|
}
|
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)
|
|
|
|
{
|
2012-08-01 19:30:05 -05:00
|
|
|
return fn@(x: T, s: span, fld: ast_fold) -> (T, span) {
|
2012-01-22 18:30:07 -06:00
|
|
|
(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 {
|
2012-08-01 19:30:05 -05:00
|
|
|
return {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
|
|
|
}
|
2012-06-30 18:19:07 -05:00
|
|
|
let fold_field = |x| fold_field_(x, fld);
|
2011-07-13 17:44:09 -05:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
let fold_mac = |x| fold_mac_(x, fld);
|
2011-06-20 19:25:49 -05:00
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
return match e {
|
2012-08-03 21:59:04 -05:00
|
|
|
expr_vstore(e, v) => {
|
2012-04-09 19:32:49 -05:00
|
|
|
expr_vstore(fld.fold_expr(e), v)
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
expr_vec(exprs, mutt) => {
|
2012-07-09 21:12:50 -05:00
|
|
|
expr_vec(fld.map_exprs(|x| fld.fold_expr(x), exprs), mutt)
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 20:01:30 -05:00
|
|
|
expr_repeat(expr, count, mutt) =>
|
|
|
|
expr_repeat(fld.fold_expr(expr), fld.fold_expr(count), mutt),
|
2012-08-03 21:59:04 -05:00
|
|
|
expr_rec(fields, maybe_expr) => {
|
2012-09-21 20:43:30 -05:00
|
|
|
expr_rec(vec::map(fields, |x| fold_field(*x)),
|
2012-09-26 18:27:12 -05:00
|
|
|
option::map(&maybe_expr, |x| fld.fold_expr(*x)))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-09-21 20:43:30 -05:00
|
|
|
expr_tup(elts) => expr_tup(vec::map(elts, |x| fld.fold_expr(*x))),
|
2012-08-03 21:59:04 -05:00
|
|
|
expr_call(f, args, blk) => {
|
2012-07-09 21:12:50 -05:00
|
|
|
expr_call(fld.fold_expr(f),
|
|
|
|
fld.map_exprs(|x| fld.fold_expr(x), args),
|
2011-10-21 07:11:24 -05:00
|
|
|
blk)
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-11-30 13:18:25 -06:00
|
|
|
expr_method_call(f, i, tps, args, blk) => {
|
|
|
|
expr_method_call(fld.fold_expr(f),
|
|
|
|
fld.fold_ident(i),
|
|
|
|
vec::map(tps, |x| fld.fold_ty(*x)),
|
|
|
|
fld.map_exprs(|x| fld.fold_expr(x), args),
|
|
|
|
blk)
|
|
|
|
}
|
2012-08-03 21:59:04 -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
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
expr_unary(binop, ohs) => expr_unary(binop, fld.fold_expr(ohs)),
|
|
|
|
expr_loop_body(f) => expr_loop_body(fld.fold_expr(f)),
|
|
|
|
expr_do_body(f) => expr_do_body(fld.fold_expr(f)),
|
|
|
|
expr_lit(_) => copy e,
|
|
|
|
expr_cast(expr, ty) => expr_cast(fld.fold_expr(expr), ty),
|
|
|
|
expr_addr_of(m, ohs) => expr_addr_of(m, fld.fold_expr(ohs)),
|
|
|
|
expr_if(cond, tr, fl) => {
|
2011-07-13 17:44:09 -05:00
|
|
|
expr_if(fld.fold_expr(cond), fld.fold_block(tr),
|
2012-09-26 18:27:12 -05:00
|
|
|
option::map(&fl, |x| fld.fold_expr(*x)))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -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
|
|
|
}
|
2012-08-14 21:20:56 -05:00
|
|
|
expr_loop(body, opt_ident) => {
|
|
|
|
expr_loop(fld.fold_block(body),
|
2012-09-26 18:27:12 -05:00
|
|
|
option::map(&opt_ident, |x| fld.fold_ident(*x)))
|
2012-03-09 18:11:56 -06:00
|
|
|
}
|
2012-08-24 23:03:51 -05:00
|
|
|
expr_match(expr, arms) => {
|
2012-08-07 15:35:51 -05:00
|
|
|
expr_match(fld.fold_expr(expr),
|
2012-09-21 20:43:30 -05:00
|
|
|
vec::map(arms, |x| fld.fold_arm(*x)))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
expr_fn(proto, decl, body, captures) => {
|
2012-05-29 18:11:15 -05:00
|
|
|
expr_fn(proto, fold_fn_decl(decl, fld),
|
|
|
|
fld.fold_block(body),
|
2012-06-30 18:19:07 -05:00
|
|
|
@((*captures).map(|cap_item| {
|
2012-09-21 20:43:30 -05:00
|
|
|
@({id: fld.new_id(cap_item.id),
|
|
|
|
..**cap_item})})))
|
2011-12-22 10:49:54 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
expr_fn_block(decl, body, captures) => {
|
2012-05-04 14:33:04 -05:00
|
|
|
expr_fn_block(fold_fn_decl(decl, fld), fld.fold_block(body),
|
2012-06-30 18:19:07 -05:00
|
|
|
@((*captures).map(|cap_item| {
|
2012-09-21 20:43:30 -05:00
|
|
|
@({id: fld.new_id(cap_item.id),
|
|
|
|
..**cap_item})})))
|
2011-12-20 13:03:21 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
expr_block(blk) => expr_block(fld.fold_block(blk)),
|
|
|
|
expr_copy(e) => expr_copy(fld.fold_expr(e)),
|
|
|
|
expr_unary_move(e) => expr_unary_move(fld.fold_expr(e)),
|
|
|
|
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
|
|
|
}
|
2012-08-03 21:59:04 -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
|
|
|
}
|
2012-08-03 21:59:04 -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
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
expr_field(el, id, tys) => {
|
2011-12-19 03:21:31 -06:00
|
|
|
expr_field(fld.fold_expr(el), fld.fold_ident(id),
|
2012-09-21 20:43:30 -05:00
|
|
|
vec::map(tys, |x| fld.fold_ty(*x)))
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -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
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
expr_path(pth) => expr_path(fld.fold_path(pth)),
|
2012-09-26 18:27:12 -05:00
|
|
|
expr_fail(e) => expr_fail(option::map(&e, |x| fld.fold_expr(*x))),
|
2012-08-14 21:20:56 -05:00
|
|
|
expr_break(opt_ident) =>
|
2012-09-26 18:27:12 -05:00
|
|
|
expr_break(option::map(&opt_ident, |x| fld.fold_ident(*x))),
|
2012-08-14 21:20:56 -05:00
|
|
|
expr_again(opt_ident) =>
|
2012-09-26 18:27:12 -05:00
|
|
|
expr_again(option::map(&opt_ident, |x| fld.fold_ident(*x))),
|
|
|
|
expr_ret(e) => expr_ret(option::map(&e, |x| fld.fold_expr(*x))),
|
2012-08-03 21:59:04 -05:00
|
|
|
expr_log(i, lv, e) => expr_log(i, fld.fold_expr(lv),
|
|
|
|
fld.fold_expr(e)),
|
|
|
|
expr_assert(e) => expr_assert(fld.fold_expr(e)),
|
|
|
|
expr_mac(mac) => expr_mac(fold_mac(mac)),
|
2012-08-06 15:15:40 -05:00
|
|
|
expr_struct(path, fields, maybe_expr) => {
|
|
|
|
expr_struct(fld.fold_path(path),
|
2012-09-21 20:43:30 -05:00
|
|
|
vec::map(fields, |x| fold_field(*x)),
|
2012-09-26 18:27:12 -05:00
|
|
|
option::map(&maybe_expr, |x| fld.fold_expr(*x)))
|
2012-10-27 19:14:09 -05:00
|
|
|
},
|
|
|
|
expr_paren(ex) => expr_paren(fld.fold_expr(ex))
|
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_ {
|
2012-06-30 18:19:07 -05:00
|
|
|
let fold_mac = |x| fold_mac_(x, fld);
|
2012-02-01 22:21:01 -06:00
|
|
|
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)}
|
|
|
|
}
|
2012-08-06 14:34:08 -05:00
|
|
|
match t {
|
2012-08-03 21:59:04 -05:00
|
|
|
ty_nil | ty_bot | ty_infer => copy 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_rptr(region, mt) => ty_rptr(region, fold_mt(mt, fld)),
|
2012-09-21 20:43:30 -05:00
|
|
|
ty_rec(fields) => ty_rec(vec::map(fields, |f| fold_field(*f, fld))),
|
2012-11-04 22:41:00 -06:00
|
|
|
ty_fn(f) =>
|
|
|
|
ty_fn(@TyFn {
|
|
|
|
proto: f.proto,
|
|
|
|
purity: f.purity,
|
|
|
|
region: f.region,
|
|
|
|
onceness: f.onceness,
|
|
|
|
bounds: @vec::map(*f.bounds, |x| fold_ty_param_bound(*x, fld)),
|
|
|
|
decl: fold_fn_decl(f.decl, fld)
|
|
|
|
}),
|
2012-09-21 20:43:30 -05:00
|
|
|
ty_tup(tys) => ty_tup(vec::map(tys, |ty| fld.fold_ty(*ty))),
|
2012-08-03 21:59:04 -05:00
|
|
|
ty_path(path, id) => ty_path(fld.fold_path(path), fld.new_id(id)),
|
2012-11-04 22:41:00 -06:00
|
|
|
ty_fixed_length_vec(mt, vs) =>
|
|
|
|
ty_fixed_length_vec(fold_mt(mt, fld), vs),
|
2012-08-03 21:59:04 -05:00
|
|
|
ty_mac(mac) => ty_mac(fold_mac(mac))
|
2012-02-01 22:21:01 -06:00
|
|
|
}
|
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 {
|
2012-09-21 20:43:30 -05:00
|
|
|
return {view_items: vec::map(m.view_items, |x| fld.fold_view_item(*x)),
|
2012-09-28 00:20:47 -05:00
|
|
|
items: vec::filter_map(m.items, |x| fld.fold_item(*x))};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2012-06-26 18:18:37 -05:00
|
|
|
fn noop_fold_foreign_mod(nm: foreign_mod, fld: ast_fold) -> foreign_mod {
|
2012-08-29 14:22:05 -05:00
|
|
|
return {sort: nm.sort,
|
2012-11-27 19:25:55 -06:00
|
|
|
abi: nm.abi,
|
|
|
|
view_items: vec::map(nm.view_items, |x| fld.fold_view_item(*x)),
|
|
|
|
items: vec::map(nm.items, |x| fld.fold_foreign_item(*x))}
|
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-08-01 19:30:05 -05:00
|
|
|
return {ty: fld.fold_ty(va.ty), id: fld.new_id(va.id)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2012-06-30 18:19:07 -05:00
|
|
|
let fold_variant_arg = |x| fold_variant_arg_(x, fld);
|
2012-08-07 16:24:04 -05:00
|
|
|
|
|
|
|
let kind;
|
|
|
|
match v.kind {
|
|
|
|
tuple_variant_kind(variant_args) =>
|
|
|
|
kind = tuple_variant_kind(vec::map(variant_args,
|
2012-09-21 20:43:30 -05:00
|
|
|
|x| fold_variant_arg(*x))),
|
2012-08-07 20:54:44 -05:00
|
|
|
struct_variant_kind(struct_def) => {
|
2012-09-21 21:37:57 -05:00
|
|
|
let dtor = do option::map(&struct_def.dtor) |dtor| {
|
2012-08-07 20:54:44 -05:00
|
|
|
let dtor_body = fld.fold_block(dtor.node.body);
|
|
|
|
let dtor_id = fld.new_id(dtor.node.id);
|
|
|
|
{node: {body: dtor_body,
|
2012-09-04 15:29:32 -05:00
|
|
|
id: dtor_id,.. dtor.node},
|
2012-09-26 18:27:12 -05:00
|
|
|
.. *dtor}};
|
2012-08-07 20:54:44 -05:00
|
|
|
kind = struct_variant_kind(@{
|
|
|
|
traits: ~[],
|
2012-08-15 17:53:58 -05:00
|
|
|
fields: vec::map(struct_def.fields,
|
2012-09-21 20:43:30 -05:00
|
|
|
|f| fld.fold_struct_field(*f)),
|
|
|
|
methods: vec::map(struct_def.methods,
|
|
|
|
|m| fld.fold_method(*m)),
|
2012-10-23 21:18:18 -05:00
|
|
|
dtor: dtor,
|
2012-10-24 16:36:00 -05:00
|
|
|
ctor_id: option::map(&struct_def.ctor_id, |c| fld.new_id(*c))
|
2012-08-07 20:54:44 -05:00
|
|
|
})
|
|
|
|
}
|
2012-08-08 16:17:52 -05:00
|
|
|
|
2012-08-08 19:14:25 -05:00
|
|
|
enum_variant_kind(enum_definition) => {
|
|
|
|
let variants = vec::map(enum_definition.variants,
|
2012-09-21 20:43:30 -05:00
|
|
|
|x| fld.fold_variant(*x));
|
2012-09-21 21:37:57 -05:00
|
|
|
let common = option::map(&enum_definition.common,
|
2012-09-26 18:27:12 -05:00
|
|
|
|x| fold_struct_def(*x, fld));
|
2012-08-08 21:51:19 -05:00
|
|
|
kind = enum_variant_kind(ast::enum_def({ variants: variants,
|
|
|
|
common: common }));
|
2012-08-08 16:17:52 -05:00
|
|
|
}
|
2012-08-07 16:24:04 -05:00
|
|
|
}
|
2012-01-25 18:23:43 -06:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
let fold_attribute = |x| fold_attribute_(x, fld);
|
2012-09-21 20:43:30 -05:00
|
|
|
let attrs = vec::map(v.attrs, |x| fold_attribute(*x));
|
2012-01-25 18:23:43 -06:00
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
let de = match v.disr_expr {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(e) => Some(fld.fold_expr(e)),
|
|
|
|
None => None
|
2012-01-10 17:59:22 -06:00
|
|
|
};
|
2012-08-01 19:30:05 -05:00
|
|
|
return {name: /* FIXME (#2543) */ copy v.name,
|
2012-01-25 18:23:43 -06:00
|
|
|
attrs: attrs,
|
2012-08-07 16:24:04 -05:00
|
|
|
kind: kind,
|
|
|
|
id: fld.new_id(v.id),
|
2012-05-08 09:06:24 -05:00
|
|
|
disr_expr: de,
|
|
|
|
vis: v.vis};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
|
|
|
|
2012-06-07 23:53:47 -05:00
|
|
|
fn noop_fold_ident(&&i: ident, _fld: ast_fold) -> ident {
|
2012-08-01 19:30:05 -05:00
|
|
|
return /* FIXME (#2543) */ copy i;
|
2012-06-07 23:53:47 -05:00
|
|
|
}
|
2011-06-20 19:25:49 -05:00
|
|
|
|
2012-04-23 06:04:46 -05:00
|
|
|
fn noop_fold_path(&&p: path, fld: ast_fold) -> path {
|
2012-08-01 19:30:05 -05:00
|
|
|
return {span: fld.new_span(p.span), global: p.global,
|
2012-09-21 20:43:30 -05:00
|
|
|
idents: vec::map(p.idents, |x| fld.fold_ident(*x)),
|
2012-04-24 17:52:52 -05:00
|
|
|
rp: p.rp,
|
2012-09-21 20:43:30 -05:00
|
|
|
types: vec::map(p.types, |x| fld.fold_ty(*x))};
|
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-08-01 19:30:05 -05:00
|
|
|
return {is_mutbl: l.is_mutbl,
|
2012-02-28 21:28:29 -06:00
|
|
|
ty: fld.fold_ty(l.ty),
|
2011-07-28 05:01:45 -05:00
|
|
|
pat: fld.fold_pat(l.pat),
|
2012-10-23 13:28:20 -05:00
|
|
|
init: l.init.map(|e| fld.fold_expr(*e)),
|
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 */
|
2012-09-23 06:39:27 -05:00
|
|
|
fn noop_map_exprs(f: fn@(&&v: @expr) -> @expr, es: ~[@expr]) -> ~[@expr] {
|
2012-09-21 20:43:30 -05:00
|
|
|
return vec::map(es, |x| f(*x));
|
2011-07-21 18:47:47 -05:00
|
|
|
}
|
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
fn noop_id(i: node_id) -> node_id { return i; }
|
2011-08-09 12:56:32 -05:00
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
fn noop_span(sp: span) -> span { return sp; }
|
2011-08-15 15:33:12 -05:00
|
|
|
|
2012-05-21 20:28:39 -05:00
|
|
|
fn default_ast_fold() -> ast_fold_precursor {
|
2012-08-01 19:30:05 -05:00
|
|
|
return @{fold_crate: wrap(noop_fold_crate),
|
2011-07-27 07:19:39 -05:00
|
|
|
fold_view_item: noop_fold_view_item,
|
2012-06-26 18:18:37 -05:00
|
|
|
fold_foreign_item: noop_fold_foreign_item,
|
2011-07-27 07:19:39 -05:00
|
|
|
fold_item: noop_fold_item,
|
2012-08-15 17:53:58 -05:00
|
|
|
fold_struct_field: noop_fold_struct_field,
|
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),
|
2011-07-27 07:19:39 -05:00
|
|
|
fold_mod: noop_fold_mod,
|
2012-06-26 18:18:37 -05:00
|
|
|
fold_foreign_mod: noop_fold_foreign_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-04-23 06:04:46 -05:00
|
|
|
fold_path: noop_fold_path,
|
2012-01-22 18:30:07 -06:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl ast_fold_precursor: ast_fold {
|
2011-06-20 19:25:49 -05:00
|
|
|
/* naturally, a macro to write these would be nice */
|
2012-05-21 20:28:39 -05:00
|
|
|
fn fold_crate(c: crate) -> crate {
|
2012-11-29 19:51:16 -06:00
|
|
|
let (n, s) = (self.fold_crate)(c.node, c.span, self as ast_fold);
|
|
|
|
return {node: n, span: (self.new_span)(s)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2012-05-21 20:28:39 -05:00
|
|
|
fn fold_view_item(&&x: @view_item) ->
|
2011-07-27 07:19:39 -05:00
|
|
|
@view_item {
|
2012-11-29 19:51:16 -06:00
|
|
|
return @{node: (self.fold_view_item)(x.node, self as ast_fold),
|
2012-06-30 18:19:07 -05:00
|
|
|
attrs: vec::map(x.attrs, |a|
|
2012-09-21 20:43:30 -05:00
|
|
|
fold_attribute_(*a, self as ast_fold)),
|
2012-05-08 16:01:38 -05:00
|
|
|
vis: x.vis,
|
2012-11-29 19:51:16 -06:00
|
|
|
span: (self.new_span)(x.span)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2012-06-26 18:18:37 -05:00
|
|
|
fn fold_foreign_item(&&x: @foreign_item)
|
|
|
|
-> @foreign_item {
|
2012-11-29 19:51:16 -06:00
|
|
|
return (self.fold_foreign_item)(x, self as ast_fold);
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2012-08-20 14:23:37 -05:00
|
|
|
fn fold_item(&&i: @item) -> Option<@item> {
|
2012-11-29 19:51:16 -06:00
|
|
|
return (self.fold_item)(i, self as ast_fold);
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2012-08-15 17:53:58 -05:00
|
|
|
fn fold_struct_field(&&sf: @struct_field) -> @struct_field {
|
|
|
|
@{node: {kind: copy sf.node.kind,
|
|
|
|
id: sf.node.id,
|
|
|
|
ty: (self as ast_fold).fold_ty(sf.node.ty)},
|
2012-11-29 19:51:16 -06:00
|
|
|
span: (self.new_span)(sf.span)}
|
2012-01-31 21:30:40 -06:00
|
|
|
}
|
2012-05-21 20:28:39 -05:00
|
|
|
fn fold_item_underscore(i: item_) ->
|
2011-07-27 07:19:39 -05:00
|
|
|
item_ {
|
2012-11-29 19:51:16 -06:00
|
|
|
return (self.fold_item_underscore)(i, self as ast_fold);
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2012-05-21 20:28:39 -05:00
|
|
|
fn fold_method(&&x: @method)
|
2011-10-07 02:36:53 -05:00
|
|
|
-> @method {
|
2012-11-29 19:51:16 -06:00
|
|
|
return (self.fold_method)(x, self as ast_fold);
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2012-05-21 20:28:39 -05:00
|
|
|
fn fold_block(x: blk) -> blk {
|
2012-11-29 19:51:16 -06:00
|
|
|
let (n, s) = (self.fold_block)(x.node, x.span, self as ast_fold);
|
|
|
|
return {node: n, span: (self.new_span)(s)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2012-05-21 20:28:39 -05:00
|
|
|
fn fold_stmt(&&x: @stmt) -> @stmt {
|
2012-11-29 19:51:16 -06:00
|
|
|
let (n, s) = (self.fold_stmt)(x.node, x.span, self as ast_fold);
|
|
|
|
return @{node: n, span: (self.new_span)(s)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2012-05-21 20:28:39 -05:00
|
|
|
fn fold_arm(x: arm) -> arm {
|
2012-11-29 19:51:16 -06:00
|
|
|
return (self.fold_arm)(x, self as ast_fold);
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2012-05-21 20:28:39 -05:00
|
|
|
fn fold_pat(&&x: @pat) -> @pat {
|
2012-11-29 19:51:16 -06:00
|
|
|
let (n, s) = (self.fold_pat)(x.node, x.span, self as ast_fold);
|
|
|
|
return @{id: (self.new_id)(x.id),
|
2012-01-22 18:30:07 -06:00
|
|
|
node: n,
|
2012-11-29 19:51:16 -06:00
|
|
|
span: (self.new_span)(s)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2012-05-21 20:28:39 -05:00
|
|
|
fn fold_decl(&&x: @decl) -> @decl {
|
2012-11-29 19:51:16 -06:00
|
|
|
let (n, s) = (self.fold_decl)(x.node, x.span, self as ast_fold);
|
|
|
|
return @{node: n, span: (self.new_span)(s)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2012-05-21 20:28:39 -05:00
|
|
|
fn fold_expr(&&x: @expr) -> @expr {
|
2012-11-29 19:51:16 -06:00
|
|
|
let (n, s) = (self.fold_expr)(x.node, x.span, self as ast_fold);
|
|
|
|
return @{id: (self.new_id)(x.id),
|
|
|
|
callee_id: (self.new_id)(x.callee_id),
|
2012-01-22 18:30:07 -06:00
|
|
|
node: n,
|
2012-11-29 19:51:16 -06:00
|
|
|
span: (self.new_span)(s)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2012-10-15 16:56:42 -05:00
|
|
|
fn fold_ty(&&x: @Ty) -> @Ty {
|
2012-11-29 19:51:16 -06:00
|
|
|
let (n, s) = (self.fold_ty)(x.node, x.span, self as ast_fold);
|
|
|
|
return @{id: (self.new_id)(x.id), node: n, span: (self.new_span)(s)};
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2012-05-21 20:28:39 -05:00
|
|
|
fn fold_mod(x: _mod) -> _mod {
|
2012-11-29 19:51:16 -06:00
|
|
|
return (self.fold_mod)(x, self as ast_fold);
|
2011-06-20 19:25:49 -05:00
|
|
|
}
|
2012-06-26 18:18:37 -05:00
|
|
|
fn fold_foreign_mod(x: foreign_mod) ->
|
|
|
|
foreign_mod {
|
2012-11-29 19:51:16 -06:00
|
|
|
return (self.fold_foreign_mod)(x, self as ast_fold);
|
2011-07-13 17:44:09 -05:00
|
|
|
}
|
2012-05-21 20:28:39 -05:00
|
|
|
fn fold_variant(x: variant) ->
|
2011-07-27 07:19:39 -05:00
|
|
|
variant {
|
2012-11-29 19:51:16 -06:00
|
|
|
let (n, s) = (self.fold_variant)(x.node, x.span, self as ast_fold);
|
|
|
|
return {node: n, span: (self.new_span)(s)};
|
2012-05-21 20:28:39 -05:00
|
|
|
}
|
|
|
|
fn fold_ident(&&x: ident) -> ident {
|
2012-11-29 19:51:16 -06:00
|
|
|
return (self.fold_ident)(x, self as ast_fold);
|
2012-05-21 20:28:39 -05:00
|
|
|
}
|
|
|
|
fn fold_path(&&x: @path) -> @path {
|
2012-11-29 19:51:16 -06:00
|
|
|
@(self.fold_path)(*x, self as ast_fold)
|
2012-05-21 20:28:39 -05:00
|
|
|
}
|
|
|
|
fn fold_local(&&x: @local) -> @local {
|
2012-11-29 19:51:16 -06:00
|
|
|
let (n, s) = (self.fold_local)(x.node, x.span, self as ast_fold);
|
|
|
|
return @{node: n, span: (self.new_span)(s)};
|
2012-05-21 20:28:39 -05:00
|
|
|
}
|
2012-09-23 06:39:27 -05:00
|
|
|
fn map_exprs(f: fn@(&&v: @expr) -> @expr, e: ~[@expr]) -> ~[@expr] {
|
2012-11-29 19:51:16 -06:00
|
|
|
(self.map_exprs)(f, e)
|
2012-05-21 20:28:39 -05:00
|
|
|
}
|
|
|
|
fn new_id(node_id: ast::node_id) -> node_id {
|
2012-11-29 19:51:16 -06:00
|
|
|
(self.new_id)(node_id)
|
2012-05-21 20:28:39 -05:00
|
|
|
}
|
|
|
|
fn new_span(span: span) -> span {
|
2012-11-29 19:51:16 -06:00
|
|
|
(self.new_span)(span)
|
2012-05-21 20:28:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl ast_fold {
|
2012-07-16 21:16:19 -05:00
|
|
|
fn fold_attributes(attrs: ~[attribute]) -> ~[attribute] {
|
2012-09-21 20:43:30 -05:00
|
|
|
attrs.map(|x| fold_attribute_(*x, self))
|
2012-07-16 21:16:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-21 20:28:39 -05:00
|
|
|
fn make_fold(afp: ast_fold_precursor) -> ast_fold {
|
|
|
|
afp as ast_fold
|
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:
|
|
|
|
//
|