2011-05-12 10:24:54 -05:00
|
|
|
import front::ast;
|
2011-04-18 20:31:47 -05:00
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
import std::option;
|
|
|
|
import std::option::some;
|
|
|
|
import std::option::none;
|
2011-04-18 20:31:47 -05:00
|
|
|
|
2011-05-31 20:24:06 -05:00
|
|
|
import util::common::span;
|
2011-06-13 19:04:15 -05:00
|
|
|
import util::common::respan;
|
2011-05-26 18:02:25 -05:00
|
|
|
|
2011-05-17 21:00:29 -05:00
|
|
|
// FIXME: Should visit patterns as well.
|
2011-04-18 20:31:47 -05:00
|
|
|
type ast_visitor =
|
2011-05-09 18:09:00 -05:00
|
|
|
rec(fn () -> bool keep_going,
|
|
|
|
fn () -> bool want_crate_directives,
|
2011-05-12 10:24:54 -05:00
|
|
|
fn (&ast::crate c) visit_crate_pre,
|
|
|
|
fn (&ast::crate c) visit_crate_post,
|
|
|
|
fn (&@ast::crate_directive cd) visit_crate_directive_pre,
|
|
|
|
fn (&@ast::crate_directive cd) visit_crate_directive_post,
|
|
|
|
fn (&@ast::view_item i) visit_view_item_pre,
|
|
|
|
fn (&@ast::view_item i) visit_view_item_post,
|
|
|
|
fn (&@ast::native_item i) visit_native_item_pre,
|
|
|
|
fn (&@ast::native_item i) visit_native_item_post,
|
|
|
|
fn (&@ast::item i) visit_item_pre,
|
|
|
|
fn (&@ast::item i) visit_item_post,
|
2011-05-13 02:39:41 -05:00
|
|
|
fn (&@ast::method m) visit_method_pre,
|
|
|
|
fn (&@ast::method m) visit_method_post,
|
2011-05-12 10:24:54 -05:00
|
|
|
fn (&ast::block b) visit_block_pre,
|
|
|
|
fn (&ast::block b) visit_block_post,
|
|
|
|
fn (&@ast::stmt s) visit_stmt_pre,
|
|
|
|
fn (&@ast::stmt s) visit_stmt_post,
|
2011-05-13 02:39:41 -05:00
|
|
|
fn (&ast::arm a) visit_arm_pre,
|
|
|
|
fn (&ast::arm a) visit_arm_post,
|
2011-06-01 18:46:55 -05:00
|
|
|
fn (&@ast::pat p) visit_pat_pre,
|
|
|
|
fn (&@ast::pat p) visit_pat_post,
|
2011-05-12 10:24:54 -05:00
|
|
|
fn (&@ast::decl d) visit_decl_pre,
|
|
|
|
fn (&@ast::decl d) visit_decl_post,
|
2011-06-13 19:04:15 -05:00
|
|
|
fn (&@ast::local l) visit_local_pre,
|
|
|
|
fn (&@ast::local l) visit_local_post,
|
2011-05-12 10:24:54 -05:00
|
|
|
fn (&@ast::expr e) visit_expr_pre,
|
|
|
|
fn (&@ast::expr e) visit_expr_post,
|
|
|
|
fn (&@ast::ty t) visit_ty_pre,
|
2011-05-18 17:38:54 -05:00
|
|
|
fn (&@ast::ty t) visit_ty_post,
|
2011-06-10 21:12:42 -05:00
|
|
|
fn (&@ast::constr c) visit_constr,
|
2011-05-26 18:02:25 -05:00
|
|
|
fn (&ast::_fn f, &span sp, &ast::ident name,
|
2011-05-18 20:01:53 -05:00
|
|
|
&ast::def_id d_id, &ast::ann a) visit_fn_pre,
|
2011-05-26 18:02:25 -05:00
|
|
|
fn (&ast::_fn f, &span sp, &ast::ident name,
|
2011-05-18 20:01:53 -05:00
|
|
|
&ast::def_id d_id, &ast::ann a) visit_fn_post);
|
2011-04-18 20:31:47 -05:00
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn walk_crate(&ast_visitor v, &ast::crate c) {
|
2011-04-18 20:31:47 -05:00
|
|
|
if (!v.keep_going()) { ret; }
|
|
|
|
v.visit_crate_pre(c);
|
|
|
|
walk_mod(v, c.node.module);
|
|
|
|
v.visit_crate_post(c);
|
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn walk_crate_directive(&ast_visitor v, @ast::crate_directive cd) {
|
2011-04-18 20:31:47 -05:00
|
|
|
if (!v.keep_going()) { ret; }
|
|
|
|
if (!v.want_crate_directives()) { ret; }
|
|
|
|
v.visit_crate_directive_pre(cd);
|
|
|
|
alt (cd.node) {
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::cdir_let(_, ?e, ?cdirs)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, e);
|
2011-05-12 10:24:54 -05:00
|
|
|
for (@ast::crate_directive cdir in cdirs) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_crate_directive(v, cdir);
|
|
|
|
}
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::cdir_src_mod(_, _)) {}
|
|
|
|
case (ast::cdir_dir_mod(_, _, ?cdirs)) {
|
|
|
|
for (@ast::crate_directive cdir in cdirs) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_crate_directive(v, cdir);
|
|
|
|
}
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::cdir_view_item(?vi)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_view_item(v, vi);
|
|
|
|
}
|
2011-06-07 19:54:22 -05:00
|
|
|
case (ast::cdir_meta(_,_)) {}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::cdir_syntax(_)) {}
|
|
|
|
case (ast::cdir_auth(_, _)) {}
|
2011-04-18 20:31:47 -05:00
|
|
|
}
|
|
|
|
v.visit_crate_directive_post(cd);
|
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn walk_mod(&ast_visitor v, &ast::_mod m) {
|
2011-04-18 20:31:47 -05:00
|
|
|
if (!v.keep_going()) { ret; }
|
2011-05-12 10:24:54 -05:00
|
|
|
for (@ast::view_item vi in m.view_items) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_view_item(v, vi);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
for (@ast::item i in m.items) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_item(v, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn walk_view_item(&ast_visitor v, @ast::view_item vi) {
|
2011-04-18 20:31:47 -05:00
|
|
|
if (!v.keep_going()) { ret; }
|
|
|
|
v.visit_view_item_pre(vi);
|
|
|
|
v.visit_view_item_post(vi);
|
|
|
|
}
|
|
|
|
|
2011-06-13 19:04:15 -05:00
|
|
|
fn walk_local(&ast_visitor v, @ast::local loc) {
|
|
|
|
v.visit_local_pre(loc);
|
|
|
|
alt (loc.node.ty) {
|
|
|
|
case (none) {}
|
|
|
|
case (some(?t)) { walk_ty(v, t); }
|
|
|
|
}
|
|
|
|
alt (loc.node.init) {
|
|
|
|
case (none) {}
|
|
|
|
case (some(?i)) {
|
|
|
|
walk_expr(v, i.expr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
v.visit_local_post(loc);
|
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn walk_item(&ast_visitor v, @ast::item i) {
|
2011-04-18 20:31:47 -05:00
|
|
|
if (!v.keep_going()) { ret; }
|
|
|
|
v.visit_item_pre(i);
|
|
|
|
alt (i.node) {
|
2011-06-14 19:06:06 -05:00
|
|
|
case (ast::item_const(_, ?t, ?e, _, _, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_ty(v, t);
|
|
|
|
walk_expr(v, e);
|
|
|
|
}
|
2011-06-14 19:06:06 -05:00
|
|
|
case (ast::item_fn(?nm, ?f, _, _, ?d, ?a)) {
|
2011-05-26 18:02:25 -05:00
|
|
|
walk_fn(v, f, i.span, nm, d, a);
|
2011-04-18 20:31:47 -05:00
|
|
|
}
|
2011-06-14 16:39:28 -05:00
|
|
|
case (ast::item_mod(_, ?m, _, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_mod(v, m);
|
|
|
|
}
|
2011-06-14 19:06:06 -05:00
|
|
|
case (ast::item_native_mod(_, ?nm, _, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_native_mod(v, nm);
|
|
|
|
}
|
2011-06-14 19:06:06 -05:00
|
|
|
case (ast::item_ty(_, ?t, _, _, _, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_ty(v, t);
|
|
|
|
}
|
2011-06-14 19:06:06 -05:00
|
|
|
case (ast::item_tag(_, ?variants, _, _, _, _)) {
|
2011-05-12 10:24:54 -05:00
|
|
|
for (ast::variant vr in variants) {
|
|
|
|
for (ast::variant_arg va in vr.node.args) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_ty(v, va.ty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-14 19:06:06 -05:00
|
|
|
case (ast::item_obj(_, ?ob, _, _, _, _)) {
|
2011-05-12 10:24:54 -05:00
|
|
|
for (ast::obj_field f in ob.fields) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_ty(v, f.ty);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
for (@ast::method m in ob.methods) {
|
2011-05-13 02:39:41 -05:00
|
|
|
v.visit_method_pre(m);
|
2011-05-26 18:02:25 -05:00
|
|
|
walk_fn(v, m.node.meth, m.span,
|
|
|
|
m.node.ident, m.node.id, m.node.ann);
|
2011-05-13 02:39:41 -05:00
|
|
|
v.visit_method_post(m);
|
2011-04-18 20:31:47 -05:00
|
|
|
}
|
|
|
|
alt (ob.dtor) {
|
2011-05-30 23:39:19 -05:00
|
|
|
case (none) {}
|
|
|
|
case (some(?m)) {
|
2011-05-26 18:02:25 -05:00
|
|
|
walk_fn(v, m.node.meth, m.span, m.node.ident, m.node.id,
|
2011-05-18 20:01:53 -05:00
|
|
|
m.node.ann);
|
2011-04-18 20:31:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
v.visit_item_post(i);
|
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn walk_ty(&ast_visitor v, @ast::ty t) {
|
2011-04-18 20:31:47 -05:00
|
|
|
if (!v.keep_going()) { ret; }
|
|
|
|
v.visit_ty_pre(t);
|
|
|
|
alt (t.node) {
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::ty_nil) {}
|
2011-05-14 21:02:30 -05:00
|
|
|
case (ast::ty_bot) {}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::ty_bool) {}
|
|
|
|
case (ast::ty_int) {}
|
|
|
|
case (ast::ty_uint) {}
|
|
|
|
case (ast::ty_float) {}
|
|
|
|
case (ast::ty_machine(_)) {}
|
|
|
|
case (ast::ty_char) {}
|
|
|
|
case (ast::ty_str) {}
|
2011-06-09 18:23:19 -05:00
|
|
|
case (ast::ty_istr) {}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::ty_box(?mt)) { walk_ty(v, mt.ty); }
|
|
|
|
case (ast::ty_vec(?mt)) { walk_ty(v, mt.ty); }
|
2011-06-09 18:23:19 -05:00
|
|
|
case (ast::ty_ivec(?mt)) { walk_ty(v, mt.ty); }
|
2011-06-03 14:02:58 -05:00
|
|
|
case (ast::ty_ptr(?mt)) { walk_ty(v, mt.ty); }
|
2011-05-31 18:27:39 -05:00
|
|
|
case (ast::ty_task) {}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::ty_port(?t)) { walk_ty(v, t); }
|
|
|
|
case (ast::ty_chan(?t)) { walk_ty(v, t); }
|
|
|
|
case (ast::ty_tup(?mts)) {
|
|
|
|
for (ast::mt mt in mts) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_ty(v, mt.ty);
|
|
|
|
}
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::ty_rec(?flds)) {
|
|
|
|
for (ast::ty_field f in flds) {
|
2011-06-03 17:26:03 -05:00
|
|
|
walk_ty(v, f.node.mt.ty);
|
2011-04-18 20:31:47 -05:00
|
|
|
}
|
|
|
|
}
|
2011-06-10 21:12:42 -05:00
|
|
|
case (ast::ty_fn(_, ?args, ?out, _, ?constrs)) {
|
2011-05-12 10:24:54 -05:00
|
|
|
for (ast::ty_arg a in args) {
|
2011-06-03 17:26:03 -05:00
|
|
|
walk_ty(v, a.node.ty);
|
2011-04-18 20:31:47 -05:00
|
|
|
}
|
2011-06-10 21:12:42 -05:00
|
|
|
for (@ast::constr c in constrs) {
|
|
|
|
v.visit_constr(c);
|
|
|
|
}
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_ty(v, out);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::ty_obj(?tmeths)) {
|
|
|
|
for (ast::ty_method m in tmeths) {
|
2011-06-03 17:26:03 -05:00
|
|
|
for (ast::ty_arg a in m.node.inputs) {
|
|
|
|
walk_ty(v, a.node.ty);
|
2011-04-18 20:31:47 -05:00
|
|
|
}
|
2011-06-03 17:26:03 -05:00
|
|
|
walk_ty(v, m.node.output);
|
2011-04-18 20:31:47 -05:00
|
|
|
}
|
|
|
|
}
|
2011-05-13 04:31:27 -05:00
|
|
|
case (ast::ty_path(?p, _)) {
|
|
|
|
for (@ast::ty tp in p.node.types) {
|
|
|
|
walk_ty(v, tp);
|
|
|
|
}
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::ty_type) {}
|
|
|
|
case (ast::ty_constr(?t, _)) { walk_ty(v, t); }
|
2011-04-18 20:31:47 -05:00
|
|
|
}
|
|
|
|
v.visit_ty_post(t);
|
|
|
|
}
|
|
|
|
|
2011-05-13 04:31:27 -05:00
|
|
|
fn walk_pat(&ast_visitor v, &@ast::pat p) {
|
2011-06-01 18:46:55 -05:00
|
|
|
v.visit_pat_pre(p);
|
2011-05-13 04:31:27 -05:00
|
|
|
alt (p.node) {
|
|
|
|
case (ast::pat_tag(?path, ?children, _)) {
|
|
|
|
for (@ast::ty tp in path.node.types) {
|
|
|
|
walk_ty(v, tp);
|
|
|
|
}
|
|
|
|
for (@ast::pat child in children) {
|
|
|
|
walk_pat(v, child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case (_) {}
|
|
|
|
}
|
2011-06-01 18:46:55 -05:00
|
|
|
v.visit_pat_post(p);
|
2011-05-13 04:31:27 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn walk_native_mod(&ast_visitor v, &ast::native_mod nm) {
|
2011-04-18 20:31:47 -05:00
|
|
|
if (!v.keep_going()) { ret; }
|
2011-05-12 10:24:54 -05:00
|
|
|
for (@ast::view_item vi in nm.view_items) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_view_item(v, vi);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
for (@ast::native_item ni in nm.items) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_native_item(v, ni);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn walk_native_item(&ast_visitor v, @ast::native_item ni) {
|
2011-04-18 20:31:47 -05:00
|
|
|
if (!v.keep_going()) { ret; }
|
|
|
|
v.visit_native_item_pre(ni);
|
|
|
|
alt (ni.node) {
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::native_item_fn(_, _, ?fd, _, _, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_fn_decl(v, fd);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::native_item_ty(_, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
v.visit_native_item_post(ni);
|
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn walk_fn_decl(&ast_visitor v, &ast::fn_decl fd) {
|
|
|
|
for (ast::arg a in fd.inputs) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_ty(v, a.ty);
|
|
|
|
}
|
2011-06-10 21:12:42 -05:00
|
|
|
for (@ast::constr c in fd.constraints) {
|
|
|
|
v.visit_constr(c);
|
|
|
|
}
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_ty(v, fd.output);
|
|
|
|
}
|
|
|
|
|
2011-05-26 18:02:25 -05:00
|
|
|
fn walk_fn(&ast_visitor v, &ast::_fn f, &span sp, &ast::ident i,
|
|
|
|
&ast::def_id d, &ast::ann a) {
|
2011-04-18 20:31:47 -05:00
|
|
|
if (!v.keep_going()) { ret; }
|
2011-05-26 18:02:25 -05:00
|
|
|
v.visit_fn_pre(f, sp, i, d, a);
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_fn_decl(v, f.decl);
|
|
|
|
walk_block(v, f.body);
|
2011-05-26 18:02:25 -05:00
|
|
|
v.visit_fn_post(f, sp, i, d, a);
|
2011-04-18 20:31:47 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn walk_block(&ast_visitor v, &ast::block b) {
|
2011-04-18 20:31:47 -05:00
|
|
|
if (!v.keep_going()) { ret; }
|
|
|
|
v.visit_block_pre(b);
|
2011-05-12 10:24:54 -05:00
|
|
|
for (@ast::stmt s in b.node.stmts) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_stmt(v, s);
|
|
|
|
}
|
|
|
|
walk_expr_opt(v, b.node.expr);
|
|
|
|
v.visit_block_post(b);
|
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn walk_stmt(&ast_visitor v, @ast::stmt s) {
|
2011-04-18 20:31:47 -05:00
|
|
|
if (!v.keep_going()) { ret; }
|
|
|
|
v.visit_stmt_pre(s);
|
|
|
|
alt (s.node) {
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::stmt_decl(?d, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_decl(v, d);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::stmt_expr(?e, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, e);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::stmt_crate_directive(?cdir)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_crate_directive(v, cdir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
v.visit_stmt_post(s);
|
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn walk_decl(&ast_visitor v, @ast::decl d) {
|
2011-04-18 20:31:47 -05:00
|
|
|
if (!v.keep_going()) { ret; }
|
|
|
|
v.visit_decl_pre(d);
|
|
|
|
alt (d.node) {
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::decl_local(?loc)) {
|
2011-06-13 19:04:15 -05:00
|
|
|
walk_local(v, @respan(d.span, loc));
|
2011-04-18 20:31:47 -05:00
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::decl_item(?it)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_item(v, it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
v.visit_decl_post(d);
|
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn walk_expr_opt(&ast_visitor v, option::t[@ast::expr] eo) {
|
2011-04-18 20:31:47 -05:00
|
|
|
alt (eo) {
|
2011-05-30 23:39:19 -05:00
|
|
|
case (none) {}
|
|
|
|
case (some(?e)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn walk_exprs(&ast_visitor v, vec[@ast::expr] exprs) {
|
|
|
|
for (@ast::expr e in exprs) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn walk_expr(&ast_visitor v, @ast::expr e) {
|
2011-04-18 20:31:47 -05:00
|
|
|
if (!v.keep_going()) { ret; }
|
|
|
|
v.visit_expr_pre(e);
|
|
|
|
alt (e.node) {
|
2011-06-09 19:11:21 -05:00
|
|
|
case (ast::expr_vec(?es, _, _, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_exprs(v, es);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_tup(?elts, _)) {
|
|
|
|
for (ast::elt e in elts) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, e.expr);
|
|
|
|
}
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_rec(?flds, ?base, _)) {
|
|
|
|
for (ast::field f in flds) {
|
2011-05-30 17:56:01 -05:00
|
|
|
walk_expr(v, f.node.expr);
|
2011-04-18 20:31:47 -05:00
|
|
|
}
|
|
|
|
walk_expr_opt(v, base);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_call(?callee, ?args, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, callee);
|
|
|
|
walk_exprs(v, args);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_self_method(_, _)) { }
|
|
|
|
case (ast::expr_bind(?callee, ?args, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, callee);
|
2011-05-12 10:24:54 -05:00
|
|
|
for (option::t[@ast::expr] eo in args) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr_opt(v, eo);
|
|
|
|
}
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_spawn(_, _, ?callee, ?args, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, callee);
|
|
|
|
walk_exprs(v, args);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_binary(_, ?a, ?b, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, a);
|
|
|
|
walk_expr(v, b);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_unary(_, ?a, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, a);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_lit(_, _)) { }
|
|
|
|
case (ast::expr_cast(?x, ?t, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, x);
|
|
|
|
walk_ty(v, t);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_if(?x, ?b, ?eo, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, x);
|
|
|
|
walk_block(v, b);
|
|
|
|
walk_expr_opt(v, eo);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_while(?x, ?b, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, x);
|
|
|
|
walk_block(v, b);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_for(?dcl, ?x, ?b, _)) {
|
2011-06-13 19:04:15 -05:00
|
|
|
walk_local(v, dcl);
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, x);
|
|
|
|
walk_block(v, b);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_for_each(?dcl, ?x, ?b, _)) {
|
2011-06-13 19:04:15 -05:00
|
|
|
walk_local(v, dcl);
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, x);
|
|
|
|
walk_block(v, b);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_do_while(?b, ?x, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_block(v, b);
|
|
|
|
walk_expr(v, x);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_alt(?x, ?arms, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, x);
|
2011-05-12 10:24:54 -05:00
|
|
|
for (ast::arm a in arms) {
|
2011-05-13 04:31:27 -05:00
|
|
|
walk_pat(v, a.pat);
|
2011-05-13 02:39:41 -05:00
|
|
|
v.visit_arm_pre(a);
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_block(v, a.block);
|
2011-05-13 02:39:41 -05:00
|
|
|
v.visit_arm_post(a);
|
2011-04-18 20:31:47 -05:00
|
|
|
}
|
|
|
|
}
|
2011-06-14 08:20:04 -05:00
|
|
|
case (ast::expr_fn(?f, ?a)) {
|
|
|
|
walk_fn_decl(v, f.decl);
|
|
|
|
walk_block(v, f.body);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_block(?b, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_block(v, b);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_assign(?a, ?b, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, a);
|
|
|
|
walk_expr(v, b);
|
|
|
|
}
|
2011-05-27 19:38:52 -05:00
|
|
|
case (ast::expr_move(?a, ?b, _)) {
|
|
|
|
walk_expr(v, a);
|
|
|
|
walk_expr(v, b);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_assign_op(_, ?a, ?b, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, a);
|
|
|
|
walk_expr(v, b);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_send(?a, ?b, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, a);
|
|
|
|
walk_expr(v, b);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_recv(?a, ?b, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, a);
|
|
|
|
walk_expr(v, b);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_field(?x, _, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, x);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_index(?a, ?b, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, a);
|
|
|
|
walk_expr(v, b);
|
|
|
|
}
|
2011-05-13 04:31:27 -05:00
|
|
|
case (ast::expr_path(?p, _)) {
|
|
|
|
for (@ast::ty tp in p.node.types) {
|
|
|
|
walk_ty(v, tp);
|
|
|
|
}
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_ext(_, ?args, ?body, ?expansion, _)) {
|
2011-04-20 17:52:33 -05:00
|
|
|
// Only walk expansion, not args/body.
|
|
|
|
walk_expr(v, expansion);
|
2011-04-18 20:31:47 -05:00
|
|
|
}
|
2011-06-08 02:58:52 -05:00
|
|
|
case (ast::expr_fail(_, _)) { }
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_break(_)) { }
|
|
|
|
case (ast::expr_cont(_)) { }
|
|
|
|
case (ast::expr_ret(?eo, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr_opt(v, eo);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_put(?eo, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr_opt(v, eo);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_be(?x, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, x);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_log(_,?x, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, x);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_check(?x, _)) {
|
2011-05-02 19:47:24 -05:00
|
|
|
walk_expr(v, x);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_assert(?x, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, x);
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::expr_port(_)) { }
|
|
|
|
case (ast::expr_chan(?x, _)) {
|
2011-04-18 20:31:47 -05:00
|
|
|
walk_expr(v, x);
|
|
|
|
}
|
2011-05-11 14:04:58 -05:00
|
|
|
|
2011-05-20 19:41:36 -05:00
|
|
|
case (ast::expr_anon_obj(?anon_obj,_,_,_)) {
|
|
|
|
|
|
|
|
// Fields
|
|
|
|
let option::t[vec[ast::obj_field]] fields
|
|
|
|
= none[vec[ast::obj_field]];
|
|
|
|
|
|
|
|
alt (anon_obj.fields) {
|
2011-05-30 23:39:19 -05:00
|
|
|
case (none) { }
|
|
|
|
case (some(?fields)) {
|
2011-05-20 19:41:36 -05:00
|
|
|
for (ast::obj_field f in fields) {
|
|
|
|
walk_ty(v, f.ty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// with_obj
|
|
|
|
let option::t[@ast::expr] with_obj = none[@ast::expr];
|
|
|
|
alt (anon_obj.with_obj) {
|
2011-05-30 23:39:19 -05:00
|
|
|
case (none) { }
|
|
|
|
case (some(?e)) {
|
2011-05-20 19:41:36 -05:00
|
|
|
walk_expr(v, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
for (@ast::method m in anon_obj.methods) {
|
|
|
|
v.visit_method_pre(m);
|
2011-05-26 18:02:25 -05:00
|
|
|
walk_fn(v, m.node.meth, m.span, m.node.ident,
|
2011-05-20 19:41:36 -05:00
|
|
|
m.node.id, m.node.ann);
|
|
|
|
v.visit_method_post(m);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2011-04-18 20:31:47 -05:00
|
|
|
}
|
|
|
|
v.visit_expr_post(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn def_keep_going() -> bool { ret true; }
|
|
|
|
fn def_want_crate_directives() -> bool { ret false; }
|
2011-05-12 10:24:54 -05:00
|
|
|
fn def_visit_crate(&ast::crate c) { }
|
|
|
|
fn def_visit_crate_directive(&@ast::crate_directive c) { }
|
|
|
|
fn def_visit_view_item(&@ast::view_item vi) { }
|
|
|
|
fn def_visit_native_item(&@ast::native_item ni) { }
|
|
|
|
fn def_visit_item(&@ast::item i) { }
|
2011-05-13 02:39:41 -05:00
|
|
|
fn def_visit_method(&@ast::method m) { }
|
2011-05-12 10:24:54 -05:00
|
|
|
fn def_visit_block(&ast::block b) { }
|
|
|
|
fn def_visit_stmt(&@ast::stmt s) { }
|
2011-05-13 02:39:41 -05:00
|
|
|
fn def_visit_arm(&ast::arm a) { }
|
2011-06-01 18:46:55 -05:00
|
|
|
fn def_visit_pat(&@ast::pat p) { }
|
2011-05-12 10:24:54 -05:00
|
|
|
fn def_visit_decl(&@ast::decl d) { }
|
2011-06-13 19:04:15 -05:00
|
|
|
fn def_visit_local(&@ast::local l) { }
|
2011-05-12 10:24:54 -05:00
|
|
|
fn def_visit_expr(&@ast::expr e) { }
|
|
|
|
fn def_visit_ty(&@ast::ty t) { }
|
2011-06-10 21:12:42 -05:00
|
|
|
fn def_visit_constr(&@ast::constr c) { }
|
2011-05-26 18:02:25 -05:00
|
|
|
fn def_visit_fn(&ast::_fn f, &span sp, &ast::ident i, &ast::def_id d,
|
|
|
|
&ast::ann a) { }
|
2011-04-18 20:31:47 -05:00
|
|
|
|
|
|
|
fn default_visitor() -> ast_visitor {
|
2011-06-01 18:52:22 -05:00
|
|
|
ret rec(keep_going=def_keep_going,
|
|
|
|
want_crate_directives=def_want_crate_directives,
|
|
|
|
visit_crate_pre=def_visit_crate,
|
|
|
|
visit_crate_post=def_visit_crate,
|
|
|
|
visit_crate_directive_pre=def_visit_crate_directive,
|
|
|
|
visit_crate_directive_post=def_visit_crate_directive,
|
|
|
|
visit_view_item_pre=def_visit_view_item,
|
|
|
|
visit_view_item_post=def_visit_view_item,
|
|
|
|
visit_native_item_pre=def_visit_native_item,
|
|
|
|
visit_native_item_post=def_visit_native_item,
|
|
|
|
visit_item_pre=def_visit_item,
|
|
|
|
visit_item_post=def_visit_item,
|
|
|
|
visit_method_pre=def_visit_method,
|
|
|
|
visit_method_post=def_visit_method,
|
|
|
|
visit_block_pre=def_visit_block,
|
|
|
|
visit_block_post=def_visit_block,
|
|
|
|
visit_stmt_pre=def_visit_stmt,
|
|
|
|
visit_stmt_post=def_visit_stmt,
|
|
|
|
visit_arm_pre=def_visit_arm,
|
|
|
|
visit_arm_post=def_visit_arm,
|
|
|
|
visit_pat_pre=def_visit_pat,
|
|
|
|
visit_pat_post=def_visit_pat,
|
|
|
|
visit_decl_pre=def_visit_decl,
|
|
|
|
visit_decl_post=def_visit_decl,
|
2011-06-13 19:04:15 -05:00
|
|
|
visit_local_pre=def_visit_local,
|
|
|
|
visit_local_post=def_visit_local,
|
2011-06-01 18:52:22 -05:00
|
|
|
visit_expr_pre=def_visit_expr,
|
|
|
|
visit_expr_post=def_visit_expr,
|
|
|
|
visit_ty_pre=def_visit_ty,
|
|
|
|
visit_ty_post=def_visit_ty,
|
2011-06-10 21:12:42 -05:00
|
|
|
visit_constr=def_visit_constr,
|
2011-06-01 18:52:22 -05:00
|
|
|
visit_fn_pre=def_visit_fn,
|
|
|
|
visit_fn_post=def_visit_fn);
|
2011-04-18 20:31:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
|
|
|
// End:
|
|
|
|
//
|