2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-03-13 21:25:28 -05:00
|
|
|
use abi::AbiSet;
|
2012-09-04 13:37:29 -05:00
|
|
|
use ast::*;
|
2012-12-23 16:41:37 -06:00
|
|
|
use ast;
|
2012-09-04 13:37:29 -05:00
|
|
|
use codemap::span;
|
2012-12-23 16:41:37 -06:00
|
|
|
use parse;
|
2013-02-14 23:50:03 -06:00
|
|
|
use opt_vec;
|
2013-02-25 13:11:21 -06:00
|
|
|
use opt_vec::OptVec;
|
2012-12-23 16:41:37 -06:00
|
|
|
|
2011-06-10 10:29:34 -05:00
|
|
|
// Context-passing AST walker. Each overridden visit method has full control
|
|
|
|
// over what happens with its node, it can do its own traversal of the node's
|
|
|
|
// children (potentially passing in different contexts to each), call
|
|
|
|
// visit::visit_* to apply the default traversal algorithm (again, it can
|
|
|
|
// override the context), or prevent deeper traversal by doing nothing.
|
2013-03-15 14:24:24 -05:00
|
|
|
//
|
|
|
|
// Note: it is an important invariant that the default visitor walks the body
|
|
|
|
// of a function in "execution order" (more concretely, reverse post-order
|
|
|
|
// with respect to the CFG implied by the AST), meaning that if AST node A may
|
|
|
|
// execute before AST node B, then A is visited first. The borrow checker in
|
|
|
|
// particular relies on this property.
|
2011-06-10 10:29:34 -05:00
|
|
|
|
2011-07-26 09:35:31 -05:00
|
|
|
// Our typesystem doesn't do circular types, so the visitor record can not
|
2012-01-19 16:24:03 -06:00
|
|
|
// hold functions that take visitors. A vt enum is used to break the cycle.
|
2013-01-29 16:41:40 -06:00
|
|
|
pub enum vt<E> { mk_vt(visitor<E>), }
|
2011-06-08 15:48:19 -05:00
|
|
|
|
2013-02-26 13:34:00 -06:00
|
|
|
pub enum fn_kind<'self> {
|
2013-03-13 21:25:28 -05:00
|
|
|
// fn foo() or extern "Abi" fn foo()
|
|
|
|
fk_item_fn(ident, &'self Generics, purity, AbiSet),
|
|
|
|
|
|
|
|
// fn foo(&self)
|
|
|
|
fk_method(ident, &'self Generics, &'self method),
|
|
|
|
|
2013-06-27 08:04:22 -05:00
|
|
|
// @fn(x, y) { ... }
|
2013-03-13 21:25:28 -05:00
|
|
|
fk_anon(ast::Sigil),
|
|
|
|
|
|
|
|
// |x, y| ...
|
|
|
|
fk_fn_block,
|
2011-12-29 22:07:55 -06:00
|
|
|
}
|
|
|
|
|
2013-02-18 23:25:44 -06:00
|
|
|
pub fn name_of_fn(fk: &fn_kind) -> ident {
|
|
|
|
match *fk {
|
2013-03-13 21:25:28 -05:00
|
|
|
fk_item_fn(name, _, _, _) | fk_method(name, _, _) => {
|
|
|
|
name
|
2012-10-08 13:49:01 -05:00
|
|
|
}
|
2012-07-18 18:18:02 -05:00
|
|
|
fk_anon(*) | fk_fn_block(*) => parse::token::special_idents::anon,
|
2011-12-29 22:07:55 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-28 09:25:31 -06:00
|
|
|
pub fn generics_of_fn(fk: &fn_kind) -> Generics {
|
2013-02-18 23:25:44 -06:00
|
|
|
match *fk {
|
2013-03-13 21:25:28 -05:00
|
|
|
fk_item_fn(_, generics, _, _) |
|
2013-04-30 23:00:45 -05:00
|
|
|
fk_method(_, generics, _) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(*generics).clone()
|
2013-02-14 23:50:03 -06:00
|
|
|
}
|
|
|
|
fk_anon(*) | fk_fn_block(*) => {
|
2013-02-28 09:25:31 -06:00
|
|
|
Generics {
|
|
|
|
lifetimes: opt_vec::Empty,
|
|
|
|
ty_params: opt_vec::Empty,
|
|
|
|
}
|
2012-10-08 13:49:01 -05:00
|
|
|
}
|
2011-12-29 22:07:55 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub struct Visitor<E> {
|
2013-07-27 03:25:59 -05:00
|
|
|
visit_mod: @fn(&_mod, span, NodeId, (E, vt<E>)),
|
2013-07-05 03:28:53 -05:00
|
|
|
visit_view_item: @fn(&view_item, (E, vt<E>)),
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_foreign_item: @fn(@foreign_item, (E, vt<E>)),
|
|
|
|
visit_item: @fn(@item, (E, vt<E>)),
|
2013-07-19 00:38:55 -05:00
|
|
|
visit_local: @fn(@Local, (E, vt<E>)),
|
|
|
|
visit_block: @fn(&Block, (E, vt<E>)),
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_stmt: @fn(@stmt, (E, vt<E>)),
|
|
|
|
visit_arm: @fn(&arm, (E, vt<E>)),
|
|
|
|
visit_pat: @fn(@pat, (E, vt<E>)),
|
|
|
|
visit_decl: @fn(@decl, (E, vt<E>)),
|
|
|
|
visit_expr: @fn(@expr, (E, vt<E>)),
|
|
|
|
visit_expr_post: @fn(@expr, (E, vt<E>)),
|
2013-07-05 23:57:11 -05:00
|
|
|
visit_ty: @fn(&Ty, (E, vt<E>)),
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_generics: @fn(&Generics, (E, vt<E>)),
|
2013-07-27 03:25:59 -05:00
|
|
|
visit_fn: @fn(&fn_kind, &fn_decl, &Block, span, NodeId, (E, vt<E>)),
|
|
|
|
visit_ty_method: @fn(&TypeMethod, (E, vt<E>)),
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_trait_method: @fn(&trait_method, (E, vt<E>)),
|
2013-07-27 03:25:59 -05:00
|
|
|
visit_struct_def: @fn(@struct_def, ident, &Generics, NodeId, (E, vt<E>)),
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_struct_field: @fn(@struct_field, (E, vt<E>)),
|
2013-01-08 16:00:45 -06:00
|
|
|
}
|
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub type visitor<E> = @Visitor<E>;
|
2011-06-08 15:48:19 -05:00
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
pub fn default_visitor<E:Clone>() -> visitor<E> {
|
2013-01-08 16:00:45 -06:00
|
|
|
return @Visitor {
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_mod: |a,b,c,d|visit_mod::<E>(a, b, c, d),
|
|
|
|
visit_view_item: |a,b|visit_view_item::<E>(a, b),
|
|
|
|
visit_foreign_item: |a,b|visit_foreign_item::<E>(a, b),
|
|
|
|
visit_item: |a,b|visit_item::<E>(a, b),
|
|
|
|
visit_local: |a,b|visit_local::<E>(a, b),
|
|
|
|
visit_block: |a,b|visit_block::<E>(a, b),
|
|
|
|
visit_stmt: |a,b|visit_stmt::<E>(a, b),
|
|
|
|
visit_arm: |a,b|visit_arm::<E>(a, b),
|
|
|
|
visit_pat: |a,b|visit_pat::<E>(a, b),
|
|
|
|
visit_decl: |a,b|visit_decl::<E>(a, b),
|
|
|
|
visit_expr: |a,b|visit_expr::<E>(a, b),
|
|
|
|
visit_expr_post: |_a,_b| (),
|
|
|
|
visit_ty: |a,b|skip_ty::<E>(a, b),
|
|
|
|
visit_generics: |a,b|visit_generics::<E>(a, b),
|
|
|
|
visit_fn: |a,b,c,d,e,f|visit_fn::<E>(a, b, c, d, e, f),
|
|
|
|
visit_ty_method: |a,b|visit_ty_method::<E>(a, b),
|
|
|
|
visit_trait_method: |a,b|visit_trait_method::<E>(a, b),
|
|
|
|
visit_struct_def: |a,b,c,d,e|visit_struct_def::<E>(a, b, c, d, e),
|
|
|
|
visit_struct_field: |a,b|visit_struct_field::<E>(a, b),
|
2013-01-08 16:00:45 -06:00
|
|
|
};
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2013-07-19 00:38:55 -05:00
|
|
|
pub fn visit_crate<E:Clone>(c: &Crate, (e, v): (E, vt<E>)) {
|
2013-07-27 03:25:59 -05:00
|
|
|
(v.visit_mod)(&c.module, c.span, CRATE_NODE_ID, (e, v));
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
pub fn visit_mod<E:Clone>(m: &_mod,
|
|
|
|
_sp: span,
|
2013-07-27 03:25:59 -05:00
|
|
|
_id: NodeId,
|
2013-07-02 14:47:32 -05:00
|
|
|
(e, v): (E, vt<E>)) {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach vi in m.view_items.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_view_item)(vi, (e.clone(), v));
|
|
|
|
}
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach i in m.items.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_item)(*i, (e.clone(), v));
|
|
|
|
}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2013-06-27 08:04:22 -05:00
|
|
|
pub fn visit_view_item<E>(_vi: &view_item, (_e, _v): (E, vt<E>)) { }
|
2011-06-09 08:50:20 -05:00
|
|
|
|
2013-07-19 00:38:55 -05:00
|
|
|
pub fn visit_local<E:Clone>(loc: &Local, (e, v): (E, vt<E>)) {
|
|
|
|
(v.visit_pat)(loc.pat, (e.clone(), v));
|
|
|
|
(v.visit_ty)(&loc.ty, (e.clone(), v));
|
|
|
|
match loc.init {
|
2012-08-20 14:23:37 -05:00
|
|
|
None => (),
|
2013-06-11 21:55:16 -05:00
|
|
|
Some(ex) => (v.visit_expr)(ex, (e, v))
|
2012-08-03 21:59:04 -05:00
|
|
|
}
|
2011-06-13 19:04:15 -05:00
|
|
|
}
|
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
fn visit_trait_ref<E:Clone>(tref: &ast::trait_ref, (e, v): (E, vt<E>)) {
|
2013-07-05 05:15:21 -05:00
|
|
|
visit_path(&tref.path, (e, v));
|
2013-03-27 05:16:28 -05:00
|
|
|
}
|
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
pub fn visit_item<E:Clone>(i: &item, (e, v): (E, vt<E>)) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match i.node {
|
2013-07-05 23:57:11 -05:00
|
|
|
item_static(ref t, _, ex) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_ty)(t, (e.clone(), v));
|
|
|
|
(v.visit_expr)(ex, (e.clone(), v));
|
2012-07-18 11:31:53 -05:00
|
|
|
}
|
2013-03-13 21:25:28 -05:00
|
|
|
item_fn(ref decl, purity, abi, ref generics, ref body) => {
|
2013-02-18 23:25:44 -06:00
|
|
|
(v.visit_fn)(
|
|
|
|
&fk_item_fn(
|
2013-03-13 21:25:28 -05:00
|
|
|
i.ident,
|
2013-02-28 09:25:31 -06:00
|
|
|
generics,
|
2013-03-13 21:25:28 -05:00
|
|
|
purity,
|
|
|
|
abi
|
2013-02-18 23:25:44 -06:00
|
|
|
),
|
2013-02-18 00:20:36 -06:00
|
|
|
decl,
|
|
|
|
body,
|
2013-02-18 23:25:44 -06:00
|
|
|
i.span,
|
|
|
|
i.id,
|
2013-06-11 21:55:16 -05:00
|
|
|
(e,
|
|
|
|
v)
|
2013-02-18 23:25:44 -06:00
|
|
|
);
|
2011-12-13 06:19:56 -06:00
|
|
|
}
|
2013-06-11 21:55:16 -05:00
|
|
|
item_mod(ref m) => (v.visit_mod)(m, i.span, i.id, (e, v)),
|
2013-02-18 23:25:44 -06:00
|
|
|
item_foreign_mod(ref nm) => {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach vi in nm.view_items.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_view_item)(vi, (e.clone(), v));
|
|
|
|
}
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach ni in nm.items.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_foreign_item)(*ni, (e.clone(), v));
|
|
|
|
}
|
2011-12-20 09:33:55 -06:00
|
|
|
}
|
2013-07-05 23:57:11 -05:00
|
|
|
item_ty(ref t, ref tps) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_ty)(t, (e.clone(), v));
|
2013-06-11 21:55:16 -05:00
|
|
|
(v.visit_generics)(tps, (e, v));
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
|
|
|
item_enum(ref enum_definition, ref tps) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_generics)(tps, (e.clone(), v));
|
2013-02-18 23:25:44 -06:00
|
|
|
visit_enum_def(
|
2013-05-11 23:25:31 -05:00
|
|
|
enum_definition,
|
2013-02-28 09:25:31 -06:00
|
|
|
tps,
|
2013-06-11 21:55:16 -05:00
|
|
|
(e, v)
|
2013-02-18 23:25:44 -06:00
|
|
|
);
|
|
|
|
}
|
2013-07-05 23:57:11 -05:00
|
|
|
item_impl(ref tps, ref traits, ref ty, ref methods) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_generics)(tps, (e.clone(), v));
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach p in traits.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
visit_trait_ref(p, (e.clone(), v));
|
2013-03-27 05:16:28 -05:00
|
|
|
}
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_ty)(ty, (e.clone(), v));
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach m in methods.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
visit_method_helper(*m, (e.clone(), v))
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
|
|
|
}
|
2013-02-28 09:25:31 -06:00
|
|
|
item_struct(struct_def, ref generics) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_generics)(generics, (e.clone(), v));
|
2013-06-11 21:55:16 -05:00
|
|
|
(v.visit_struct_def)(struct_def, i.ident, generics, i.id, (e, v));
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
2013-02-28 09:25:31 -06:00
|
|
|
item_trait(ref generics, ref traits, ref methods) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_generics)(generics, (e.clone(), v));
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach p in traits.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
visit_path(&p.path, (e.clone(), v));
|
|
|
|
}
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach m in methods.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_trait_method)(m, (e.clone(), v));
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
|
|
|
}
|
2013-06-11 21:55:16 -05:00
|
|
|
item_mac(ref m) => visit_mac(m, (e, v))
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
pub fn visit_enum_def<E:Clone>(enum_definition: &ast::enum_def,
|
2013-04-17 11:15:08 -05:00
|
|
|
tps: &Generics,
|
2013-06-11 21:55:16 -05:00
|
|
|
(e, v): (E, vt<E>)) {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach vr in enum_definition.variants.iter() {
|
2012-08-08 16:17:52 -05:00
|
|
|
match vr.node.kind {
|
2013-02-18 00:20:36 -06:00
|
|
|
tuple_variant_kind(ref variant_args) => {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach va in variant_args.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_ty)(&va.ty, (e.clone(), v));
|
2013-06-15 19:26:59 -05:00
|
|
|
}
|
2012-08-08 16:17:52 -05:00
|
|
|
}
|
|
|
|
struct_variant_kind(struct_def) => {
|
2012-11-29 19:51:16 -06:00
|
|
|
(v.visit_struct_def)(struct_def, vr.node.name, tps,
|
2013-07-02 14:47:32 -05:00
|
|
|
vr.node.id, (e.clone(), v));
|
2012-08-08 16:17:52 -05:00
|
|
|
}
|
|
|
|
}
|
2012-10-15 14:27:09 -05:00
|
|
|
// Visit the disr expr if it exists
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach ex in vr.node.disr_expr.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_expr)(*ex, (e.clone(), v))
|
2013-06-15 19:26:59 -05:00
|
|
|
}
|
2012-08-08 16:17:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-27 08:04:22 -05:00
|
|
|
pub fn skip_ty<E>(_t: &Ty, (_e,_v): (E, vt<E>)) {}
|
2011-11-22 03:57:47 -06:00
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
pub fn visit_ty<E:Clone>(t: &Ty, (e, v): (E, vt<E>)) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match t.node {
|
2013-07-05 23:57:11 -05:00
|
|
|
ty_box(ref mt) | ty_uniq(ref mt) |
|
|
|
|
ty_vec(ref mt) | ty_ptr(ref mt) | ty_rptr(_, ref mt) => {
|
2013-06-11 21:55:16 -05:00
|
|
|
(v.visit_ty)(mt.ty, (e, v));
|
2013-02-18 00:20:36 -06:00
|
|
|
},
|
|
|
|
ty_tup(ref ts) => {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach tt in ts.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_ty)(tt, (e.clone(), v));
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
ty_closure(ref f) => {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach a in f.decl.inputs.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_ty)(&a.ty, (e.clone(), v));
|
|
|
|
}
|
|
|
|
(v.visit_ty)(&f.decl.output, (e.clone(), v));
|
2013-06-20 17:23:25 -05:00
|
|
|
do f.bounds.map |bounds| {
|
2013-07-02 14:47:32 -05:00
|
|
|
visit_ty_param_bounds(bounds, (e.clone(), v));
|
2013-06-20 17:23:25 -05:00
|
|
|
};
|
2013-02-18 00:20:36 -06:00
|
|
|
},
|
|
|
|
ty_bare_fn(ref f) => {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach a in f.decl.inputs.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_ty)(&a.ty, (e.clone(), v));
|
|
|
|
}
|
2013-07-05 23:57:11 -05:00
|
|
|
(v.visit_ty)(&f.decl.output, (e, v));
|
2013-02-18 00:20:36 -06:00
|
|
|
},
|
2013-07-05 20:38:56 -05:00
|
|
|
ty_path(ref p, ref bounds, _) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
visit_path(p, (e.clone(), v));
|
2013-06-20 17:23:25 -05:00
|
|
|
do bounds.map |bounds| {
|
2013-07-02 14:47:32 -05:00
|
|
|
visit_ty_param_bounds(bounds, (e.clone(), v));
|
2013-06-20 17:23:25 -05:00
|
|
|
};
|
2013-06-17 14:16:30 -05:00
|
|
|
},
|
2013-03-05 19:43:37 -06:00
|
|
|
ty_fixed_length_vec(ref mt, ex) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_ty)(mt.ty, (e.clone(), v));
|
|
|
|
(v.visit_expr)(ex, (e.clone(), v));
|
2013-03-05 19:43:37 -06:00
|
|
|
},
|
2013-02-18 00:20:36 -06:00
|
|
|
ty_nil | ty_bot | ty_mac(_) | ty_infer => ()
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
pub fn visit_path<E:Clone>(p: &Path, (e, v): (E, vt<E>)) {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach tp in p.types.iter() { (v.visit_ty)(tp, (e.clone(), v)); }
|
2011-12-13 06:19:56 -06:00
|
|
|
}
|
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
pub fn visit_pat<E:Clone>(p: &pat, (e, v): (E, vt<E>)) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match p.node {
|
2013-07-05 05:15:21 -05:00
|
|
|
pat_enum(ref path, ref children) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
visit_path(path, (e.clone(), v));
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach children in children.iter() {
|
|
|
|
foreach child in children.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_pat)(*child, (e.clone(), v));
|
2013-06-15 19:26:59 -05:00
|
|
|
}
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2012-08-06 19:01:14 -05:00
|
|
|
}
|
2013-07-05 05:15:21 -05:00
|
|
|
pat_struct(ref path, ref fields, _) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
visit_path(path, (e.clone(), v));
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach f in fields.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_pat)(f.pat, (e.clone(), v));
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pat_tup(ref elts) => {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach elt in elts.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_pat)(*elt, (e.clone(), v))
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
pat_box(inner) | pat_uniq(inner) | pat_region(inner) => {
|
2013-06-11 21:55:16 -05:00
|
|
|
(v.visit_pat)(inner, (e, v))
|
2013-02-18 00:20:36 -06:00
|
|
|
},
|
2013-07-05 05:15:21 -05:00
|
|
|
pat_ident(_, ref path, ref inner) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
visit_path(path, (e.clone(), v));
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach subpat in inner.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_pat)(*subpat, (e.clone(), v))
|
2013-06-15 19:26:59 -05:00
|
|
|
}
|
2012-12-08 14:22:43 -06:00
|
|
|
}
|
2013-06-11 21:55:16 -05:00
|
|
|
pat_lit(ex) => (v.visit_expr)(ex, (e, v)),
|
2013-02-18 00:20:36 -06:00
|
|
|
pat_range(e1, e2) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_expr)(e1, (e.clone(), v));
|
2013-06-11 21:55:16 -05:00
|
|
|
(v.visit_expr)(e2, (e, v));
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
|
|
|
pat_wild => (),
|
2013-02-26 12:58:46 -06:00
|
|
|
pat_vec(ref before, ref slice, ref after) => {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach elt in before.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_pat)(*elt, (e.clone(), v));
|
2013-02-26 12:58:46 -06:00
|
|
|
}
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach elt in slice.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_pat)(*elt, (e.clone(), v));
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach tail in after.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_pat)(*tail, (e.clone(), v));
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2012-12-08 14:22:43 -06:00
|
|
|
}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
pub fn visit_foreign_item<E:Clone>(ni: &foreign_item, (e, v): (E, vt<E>)) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match ni.node {
|
2013-02-28 09:25:31 -06:00
|
|
|
foreign_item_fn(ref fd, _, ref generics) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
visit_fn_decl(fd, (e.clone(), v));
|
2013-06-11 21:55:16 -05:00
|
|
|
(v.visit_generics)(generics, (e, v));
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
2013-07-05 23:57:11 -05:00
|
|
|
foreign_item_static(ref t, _) => {
|
2013-06-11 21:55:16 -05:00
|
|
|
(v.visit_ty)(t, (e, v));
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
pub fn visit_ty_param_bounds<E:Clone>(bounds: &OptVec<TyParamBound>,
|
2013-06-11 21:55:16 -05:00
|
|
|
(e, v): (E, vt<E>)) {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach bound in bounds.iter() {
|
2013-02-14 23:50:03 -06:00
|
|
|
match *bound {
|
2013-07-02 14:47:32 -05:00
|
|
|
TraitTyParamBound(ref ty) => visit_trait_ref(ty, (e.clone(), v)),
|
2013-03-27 05:16:28 -05:00
|
|
|
RegionTyParamBound => {}
|
2013-01-10 13:16:54 -06:00
|
|
|
}
|
2012-08-06 20:54:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
pub fn visit_generics<E:Clone>(generics: &Generics, (e, v): (E, vt<E>)) {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach tp in generics.ty_params.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
visit_ty_param_bounds(&tp.bounds, (e.clone(), v));
|
2011-12-28 10:50:12 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
pub fn visit_fn_decl<E:Clone>(fd: &fn_decl, (e, v): (E, vt<E>)) {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach a in fd.inputs.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_pat)(a.pat, (e.clone(), v));
|
|
|
|
(v.visit_ty)(&a.ty, (e.clone(), v));
|
2012-11-06 20:41:06 -06:00
|
|
|
}
|
2013-07-05 23:57:11 -05:00
|
|
|
(v.visit_ty)(&fd.output, (e, v));
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2012-03-01 12:36:22 -06:00
|
|
|
// Note: there is no visit_method() method in the visitor, instead override
|
|
|
|
// visit_fn() and check for fk_method(). I named this visit_method_helper()
|
|
|
|
// because it is not a default impl of any method, though I doubt that really
|
|
|
|
// clarifies anything. - Niko
|
2013-07-02 14:47:32 -05:00
|
|
|
pub fn visit_method_helper<E:Clone>(m: &method, (e, v): (E, vt<E>)) {
|
2013-06-27 19:41:35 -05:00
|
|
|
(v.visit_fn)(&fk_method(m.ident, &m.generics, m),
|
|
|
|
&m.decl,
|
|
|
|
&m.body,
|
|
|
|
m.span,
|
|
|
|
m.id,
|
|
|
|
(e, v));
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
|
|
|
|
2013-07-19 00:38:55 -05:00
|
|
|
pub fn visit_fn<E:Clone>(fk: &fn_kind, decl: &fn_decl, body: &Block, _sp: span,
|
2013-07-27 03:25:59 -05:00
|
|
|
_id: NodeId, (e, v): (E, vt<E>)) {
|
2013-07-02 14:47:32 -05:00
|
|
|
visit_fn_decl(decl, (e.clone(), v));
|
2013-02-14 23:50:03 -06:00
|
|
|
let generics = generics_of_fn(fk);
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_generics)(&generics, (e.clone(), v));
|
2013-06-11 21:55:16 -05:00
|
|
|
(v.visit_block)(body, (e, v));
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2013-07-27 03:25:59 -05:00
|
|
|
pub fn visit_ty_method<E:Clone>(m: &TypeMethod, (e, v): (E, vt<E>)) {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach a in m.decl.inputs.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_ty)(&a.ty, (e.clone(), v));
|
|
|
|
}
|
|
|
|
(v.visit_generics)(&m.generics, (e.clone(), v));
|
2013-07-05 23:57:11 -05:00
|
|
|
(v.visit_ty)(&m.decl.output, (e, v));
|
2012-07-11 12:28:30 -05:00
|
|
|
}
|
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
pub fn visit_trait_method<E:Clone>(m: &trait_method, (e, v): (E, vt<E>)) {
|
2013-02-18 00:20:36 -06:00
|
|
|
match *m {
|
2013-06-11 21:55:16 -05:00
|
|
|
required(ref ty_m) => (v.visit_ty_method)(ty_m, (e, v)),
|
|
|
|
provided(m) => visit_method_helper(m, (e, v))
|
2012-07-10 15:44:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
pub fn visit_struct_def<E:Clone>(
|
2013-02-28 09:25:31 -06:00
|
|
|
sd: @struct_def,
|
|
|
|
_nm: ast::ident,
|
2013-04-30 23:00:45 -05:00
|
|
|
_generics: &Generics,
|
2013-07-27 03:25:59 -05:00
|
|
|
_id: NodeId,
|
2013-06-11 21:55:16 -05:00
|
|
|
(e, v): (E, vt<E>)
|
2013-02-28 09:25:31 -06:00
|
|
|
) {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach f in sd.fields.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_struct_field)(*f, (e.clone(), v));
|
2012-08-15 17:53:58 -05:00
|
|
|
}
|
2012-08-07 17:54:59 -05:00
|
|
|
}
|
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
pub fn visit_struct_field<E:Clone>(sf: &struct_field, (e, v): (E, vt<E>)) {
|
2013-07-05 23:57:11 -05:00
|
|
|
(v.visit_ty)(&sf.node.ty, (e, v));
|
2012-08-15 17:53:58 -05:00
|
|
|
}
|
|
|
|
|
2013-07-19 00:38:55 -05:00
|
|
|
pub fn visit_block<E:Clone>(b: &Block, (e, v): (E, vt<E>)) {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach vi in b.view_items.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_view_item)(vi, (e.clone(), v));
|
2012-09-19 18:55:01 -05:00
|
|
|
}
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach s in b.stmts.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_stmt)(*s, (e.clone(), v));
|
2012-09-19 18:55:01 -05:00
|
|
|
}
|
2013-07-16 13:08:35 -05:00
|
|
|
visit_expr_opt(b.expr, (e, v));
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2013-06-27 08:04:22 -05:00
|
|
|
pub fn visit_stmt<E>(s: &stmt, (e, v): (E, vt<E>)) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match s.node {
|
2013-06-11 21:55:16 -05:00
|
|
|
stmt_decl(d, _) => (v.visit_decl)(d, (e, v)),
|
|
|
|
stmt_expr(ex, _) => (v.visit_expr)(ex, (e, v)),
|
|
|
|
stmt_semi(ex, _) => (v.visit_expr)(ex, (e, v)),
|
|
|
|
stmt_mac(ref mac, _) => visit_mac(mac, (e, v))
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
pub fn visit_decl<E:Clone>(d: &decl, (e, v): (E, vt<E>)) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match d.node {
|
2013-06-11 21:55:16 -05:00
|
|
|
decl_local(ref loc) => (v.visit_local)(*loc, (e, v)),
|
|
|
|
decl_item(it) => (v.visit_item)(it, (e, v))
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-11 21:55:16 -05:00
|
|
|
pub fn visit_expr_opt<E>(eo: Option<@expr>, (e, v): (E, vt<E>)) {
|
|
|
|
match eo { None => (), Some(ex) => (v.visit_expr)(ex, (e, v)) }
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
pub fn visit_exprs<E:Clone>(exprs: &[@expr], (e, v): (E, vt<E>)) {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach ex in exprs.iter() { (v.visit_expr)(*ex, (e.clone(), v)); }
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2013-06-11 21:55:16 -05:00
|
|
|
pub fn visit_mac<E>(_m: &mac, (_e, _v): (E, vt<E>)) {
|
2012-12-12 14:25:40 -06:00
|
|
|
/* no user-serviceable parts inside */
|
2011-07-08 18:35:09 -05:00
|
|
|
}
|
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
pub fn visit_expr<E:Clone>(ex: @expr, (e, v): (E, vt<E>)) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match ex.node {
|
2013-07-02 14:47:32 -05:00
|
|
|
expr_vstore(x, _) => (v.visit_expr)(x, (e.clone(), v)),
|
|
|
|
expr_vec(ref es, _) => visit_exprs(*es, (e.clone(), v)),
|
2013-02-18 00:20:36 -06:00
|
|
|
expr_repeat(element, count, _) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_expr)(element, (e.clone(), v));
|
|
|
|
(v.visit_expr)(count, (e.clone(), v));
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-07-05 05:15:21 -05:00
|
|
|
expr_struct(ref p, ref flds, base) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
visit_path(p, (e.clone(), v));
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach f in flds.iter() {
|
2013-07-19 09:24:22 -05:00
|
|
|
(v.visit_expr)(f.expr, (e.clone(), v));
|
2013-06-15 19:26:59 -05:00
|
|
|
}
|
2013-07-02 14:47:32 -05:00
|
|
|
visit_expr_opt(base, (e.clone(), v));
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
|
|
|
expr_tup(ref elts) => {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach el in elts.iter() { (v.visit_expr)(*el, (e.clone(), v)) }
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
|
|
|
expr_call(callee, ref args, _) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
visit_exprs(*args, (e.clone(), v));
|
|
|
|
(v.visit_expr)(callee, (e.clone(), v));
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-06-01 17:31:56 -05:00
|
|
|
expr_method_call(_, callee, _, ref tys, ref args, _) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
visit_exprs(*args, (e.clone(), v));
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach tp in tys.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_ty)(tp, (e.clone(), v));
|
2013-06-15 19:26:59 -05:00
|
|
|
}
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_expr)(callee, (e.clone(), v));
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-06-01 17:31:56 -05:00
|
|
|
expr_binary(_, _, a, b) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_expr)(a, (e.clone(), v));
|
|
|
|
(v.visit_expr)(b, (e.clone(), v));
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-06-01 17:31:56 -05:00
|
|
|
expr_addr_of(_, x) | expr_unary(_, _, x) |
|
2013-07-02 14:47:32 -05:00
|
|
|
expr_loop_body(x) | expr_do_body(x) => (v.visit_expr)(x, (e.clone(), v)),
|
2013-02-18 00:20:36 -06:00
|
|
|
expr_lit(_) => (),
|
2013-07-05 23:57:11 -05:00
|
|
|
expr_cast(x, ref t) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_expr)(x, (e.clone(), v));
|
|
|
|
(v.visit_ty)(t, (e.clone(), v));
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
|
|
|
expr_if(x, ref b, eo) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_expr)(x, (e.clone(), v));
|
|
|
|
(v.visit_block)(b, (e.clone(), v));
|
|
|
|
visit_expr_opt(eo, (e.clone(), v));
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
|
|
|
expr_while(x, ref b) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_expr)(x, (e.clone(), v));
|
|
|
|
(v.visit_block)(b, (e.clone(), v));
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-07-29 19:25:00 -05:00
|
|
|
expr_for_loop(pat, iter, ref b) => {
|
|
|
|
(v.visit_pat)(pat, (e.clone(), v));
|
|
|
|
(v.visit_expr)(iter, (e.clone(), v));
|
|
|
|
(v.visit_block)(b, (e.clone(), v));
|
|
|
|
}
|
2013-07-02 14:47:32 -05:00
|
|
|
expr_loop(ref b, _) => (v.visit_block)(b, (e.clone(), v)),
|
2013-02-18 00:20:36 -06:00
|
|
|
expr_match(x, ref arms) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_expr)(x, (e.clone(), v));
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach a in arms.iter() { (v.visit_arm)(a, (e.clone(), v)); }
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
|
|
|
expr_fn_block(ref decl, ref body) => {
|
|
|
|
(v.visit_fn)(
|
|
|
|
&fk_fn_block,
|
|
|
|
decl,
|
|
|
|
body,
|
|
|
|
ex.span,
|
|
|
|
ex.id,
|
2013-07-02 14:47:32 -05:00
|
|
|
(e.clone(), v)
|
2013-02-18 00:20:36 -06:00
|
|
|
);
|
|
|
|
}
|
2013-07-02 14:47:32 -05:00
|
|
|
expr_block(ref b) => (v.visit_block)(b, (e.clone(), v)),
|
2013-02-18 00:20:36 -06:00
|
|
|
expr_assign(a, b) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_expr)(b, (e.clone(), v));
|
|
|
|
(v.visit_expr)(a, (e.clone(), v));
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-06-01 17:31:56 -05:00
|
|
|
expr_assign_op(_, _, a, b) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_expr)(b, (e.clone(), v));
|
|
|
|
(v.visit_expr)(a, (e.clone(), v));
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
|
|
|
expr_field(x, _, ref tys) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_expr)(x, (e.clone(), v));
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach tp in tys.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_ty)(tp, (e.clone(), v));
|
2013-06-15 19:26:59 -05:00
|
|
|
}
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-06-01 17:31:56 -05:00
|
|
|
expr_index(_, a, b) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_expr)(a, (e.clone(), v));
|
|
|
|
(v.visit_expr)(b, (e.clone(), v));
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-07-02 14:47:32 -05:00
|
|
|
expr_path(ref p) => visit_path(p, (e.clone(), v)),
|
2013-05-10 17:15:06 -05:00
|
|
|
expr_self => (),
|
2013-02-18 00:20:36 -06:00
|
|
|
expr_break(_) => (),
|
|
|
|
expr_again(_) => (),
|
2013-07-02 14:47:32 -05:00
|
|
|
expr_ret(eo) => visit_expr_opt(eo, (e.clone(), v)),
|
2013-03-26 23:42:01 -05:00
|
|
|
expr_log(lv, x) => {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_expr)(lv, (e.clone(), v));
|
|
|
|
(v.visit_expr)(x, (e.clone(), v));
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-07-02 14:47:32 -05:00
|
|
|
expr_mac(ref mac) => visit_mac(mac, (e.clone(), v)),
|
|
|
|
expr_paren(x) => (v.visit_expr)(x, (e.clone(), v)),
|
2013-03-27 15:42:21 -05:00
|
|
|
expr_inline_asm(ref a) => {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach &(_, input) in a.inputs.iter() {
|
2013-07-31 16:59:59 -05:00
|
|
|
(v.visit_expr)(input, (e.clone(), v));
|
2013-03-12 19:53:25 -05:00
|
|
|
}
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach &(_, out) in a.outputs.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
(v.visit_expr)(out, (e.clone(), v));
|
2013-03-12 19:53:25 -05:00
|
|
|
}
|
|
|
|
}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
2013-06-11 21:55:16 -05:00
|
|
|
(v.visit_expr_post)(ex, (e, v));
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
pub fn visit_arm<E:Clone>(a: &arm, (e, v): (E, vt<E>)) {
|
2013-08-01 02:16:42 -05:00
|
|
|
foreach p in a.pats.iter() { (v.visit_pat)(*p, (e.clone(), v)); }
|
2013-07-02 14:47:32 -05:00
|
|
|
visit_expr_opt(a.guard, (e.clone(), v));
|
|
|
|
(v.visit_block)(&a.body, (e.clone(), v));
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
2011-07-01 07:05:54 -05:00
|
|
|
|
2011-07-26 09:35:31 -05:00
|
|
|
// Simpler, non-context passing interface. Always walks the whole tree, simply
|
|
|
|
// calls the given functions on the nodes.
|
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub struct SimpleVisitor {
|
2013-07-27 03:25:59 -05:00
|
|
|
visit_mod: @fn(&_mod, span, NodeId),
|
2013-07-05 03:28:53 -05:00
|
|
|
visit_view_item: @fn(&view_item),
|
2013-03-01 15:30:06 -06:00
|
|
|
visit_foreign_item: @fn(@foreign_item),
|
|
|
|
visit_item: @fn(@item),
|
2013-07-19 00:38:55 -05:00
|
|
|
visit_local: @fn(@Local),
|
|
|
|
visit_block: @fn(&Block),
|
2013-03-01 15:30:06 -06:00
|
|
|
visit_stmt: @fn(@stmt),
|
|
|
|
visit_arm: @fn(&arm),
|
|
|
|
visit_pat: @fn(@pat),
|
|
|
|
visit_decl: @fn(@decl),
|
|
|
|
visit_expr: @fn(@expr),
|
|
|
|
visit_expr_post: @fn(@expr),
|
2013-07-05 23:57:11 -05:00
|
|
|
visit_ty: @fn(&Ty),
|
2013-03-01 15:30:06 -06:00
|
|
|
visit_generics: @fn(&Generics),
|
2013-07-27 03:25:59 -05:00
|
|
|
visit_fn: @fn(&fn_kind, &fn_decl, &Block, span, NodeId),
|
|
|
|
visit_ty_method: @fn(&TypeMethod),
|
2013-03-01 15:30:06 -06:00
|
|
|
visit_trait_method: @fn(&trait_method),
|
2013-07-27 03:25:59 -05:00
|
|
|
visit_struct_def: @fn(@struct_def, ident, &Generics, NodeId),
|
2013-03-01 15:30:06 -06:00
|
|
|
visit_struct_field: @fn(@struct_field),
|
|
|
|
visit_struct_method: @fn(@method)
|
2013-01-08 16:00:45 -06:00
|
|
|
}
|
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub type simple_visitor = @SimpleVisitor;
|
2011-07-26 09:35:31 -05:00
|
|
|
|
2013-07-05 23:57:11 -05:00
|
|
|
pub fn simple_ignore_ty(_t: &Ty) {}
|
2011-11-22 03:57:47 -06:00
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub fn default_simple_visitor() -> @SimpleVisitor {
|
2013-02-17 11:42:50 -06:00
|
|
|
@SimpleVisitor {
|
|
|
|
visit_mod: |_m, _sp, _id| { },
|
|
|
|
visit_view_item: |_vi| { },
|
|
|
|
visit_foreign_item: |_ni| { },
|
|
|
|
visit_item: |_i| { },
|
|
|
|
visit_local: |_l| { },
|
|
|
|
visit_block: |_b| { },
|
|
|
|
visit_stmt: |_s| { },
|
|
|
|
visit_arm: |_a| { },
|
|
|
|
visit_pat: |_p| { },
|
|
|
|
visit_decl: |_d| { },
|
|
|
|
visit_expr: |_e| { },
|
|
|
|
visit_expr_post: |_e| { },
|
|
|
|
visit_ty: simple_ignore_ty,
|
2013-03-01 15:30:06 -06:00
|
|
|
visit_generics: |_| {},
|
|
|
|
visit_fn: |_, _, _, _, _| {},
|
|
|
|
visit_ty_method: |_| {},
|
|
|
|
visit_trait_method: |_| {},
|
|
|
|
visit_struct_def: |_, _, _, _| {},
|
|
|
|
visit_struct_field: |_| {},
|
|
|
|
visit_struct_method: |_| {},
|
2013-02-17 11:42:50 -06:00
|
|
|
}
|
2011-07-26 09:35:31 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub fn mk_simple_visitor(v: simple_visitor) -> vt<()> {
|
2013-02-18 23:25:44 -06:00
|
|
|
fn v_mod(
|
2013-07-27 03:25:59 -05:00
|
|
|
f: @fn(&_mod, span, NodeId),
|
2013-02-18 23:25:44 -06:00
|
|
|
m: &_mod,
|
|
|
|
sp: span,
|
2013-07-27 03:25:59 -05:00
|
|
|
id: NodeId,
|
2013-06-11 21:55:16 -05:00
|
|
|
(e, v): ((), vt<()>)
|
2013-02-18 23:25:44 -06:00
|
|
|
) {
|
2012-01-26 10:33:12 -06:00
|
|
|
f(m, sp, id);
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_mod(m, sp, id, (e, v));
|
2011-07-26 09:35:31 -05:00
|
|
|
}
|
2013-07-05 03:28:53 -05:00
|
|
|
fn v_view_item(f: @fn(&view_item), vi: &view_item, (e, v): ((), vt<()>)) {
|
2011-07-27 07:19:39 -05:00
|
|
|
f(vi);
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_view_item(vi, (e, v));
|
2011-07-26 09:35:31 -05:00
|
|
|
}
|
2013-06-11 21:55:16 -05:00
|
|
|
fn v_foreign_item(f: @fn(@foreign_item), ni: @foreign_item, (e, v): ((), vt<()>)) {
|
2011-07-27 07:19:39 -05:00
|
|
|
f(ni);
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_foreign_item(ni, (e, v));
|
2011-07-26 09:35:31 -05:00
|
|
|
}
|
2013-06-11 21:55:16 -05:00
|
|
|
fn v_item(f: @fn(@item), i: @item, (e, v): ((), vt<()>)) {
|
2011-07-27 07:19:39 -05:00
|
|
|
f(i);
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_item(i, (e, v));
|
2011-07-26 09:35:31 -05:00
|
|
|
}
|
2013-07-19 00:38:55 -05:00
|
|
|
fn v_local(f: @fn(@Local), l: @Local, (e, v): ((), vt<()>)) {
|
2011-07-27 07:19:39 -05:00
|
|
|
f(l);
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_local(l, (e, v));
|
2011-07-26 09:35:31 -05:00
|
|
|
}
|
2013-07-19 00:38:55 -05:00
|
|
|
fn v_block(f: @fn(&ast::Block), bl: &ast::Block, (e, v): ((), vt<()>)) {
|
2011-07-27 07:19:39 -05:00
|
|
|
f(bl);
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_block(bl, (e, v));
|
2011-07-26 09:35:31 -05:00
|
|
|
}
|
2013-06-11 21:55:16 -05:00
|
|
|
fn v_stmt(f: @fn(@stmt), st: @stmt, (e, v): ((), vt<()>)) {
|
2011-07-27 07:19:39 -05:00
|
|
|
f(st);
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_stmt(st, (e, v));
|
2011-07-26 09:35:31 -05:00
|
|
|
}
|
2013-06-11 21:55:16 -05:00
|
|
|
fn v_arm(f: @fn(&arm), a: &arm, (e, v): ((), vt<()>)) {
|
2011-07-27 07:19:39 -05:00
|
|
|
f(a);
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_arm(a, (e, v));
|
2011-07-26 09:35:31 -05:00
|
|
|
}
|
2013-06-11 21:55:16 -05:00
|
|
|
fn v_pat(f: @fn(@pat), p: @pat, (e, v): ((), vt<()>)) {
|
2011-07-27 07:19:39 -05:00
|
|
|
f(p);
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_pat(p, (e, v));
|
2011-07-26 09:35:31 -05:00
|
|
|
}
|
2013-06-11 21:55:16 -05:00
|
|
|
fn v_decl(f: @fn(@decl), d: @decl, (e, v): ((), vt<()>)) {
|
2011-07-27 07:19:39 -05:00
|
|
|
f(d);
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_decl(d, (e, v));
|
2011-07-26 09:35:31 -05:00
|
|
|
}
|
2013-06-11 21:55:16 -05:00
|
|
|
fn v_expr(f: @fn(@expr), ex: @expr, (e, v): ((), vt<()>)) {
|
2011-07-27 07:19:39 -05:00
|
|
|
f(ex);
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_expr(ex, (e, v));
|
2011-07-26 09:35:31 -05:00
|
|
|
}
|
2013-06-11 21:55:16 -05:00
|
|
|
fn v_expr_post(f: @fn(@expr), ex: @expr, (_e, _v): ((), vt<()>)) {
|
2012-07-30 21:05:56 -05:00
|
|
|
f(ex);
|
|
|
|
}
|
2013-07-05 23:57:11 -05:00
|
|
|
fn v_ty(f: @fn(&Ty), ty: &Ty, (e, v): ((), vt<()>)) {
|
2011-07-27 07:19:39 -05:00
|
|
|
f(ty);
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_ty(ty, (e, v));
|
2011-07-26 09:35:31 -05:00
|
|
|
}
|
2013-07-27 03:25:59 -05:00
|
|
|
fn v_ty_method(f: @fn(&TypeMethod), ty: &TypeMethod, (e, v): ((), vt<()>)) {
|
2012-07-11 12:28:30 -05:00
|
|
|
f(ty);
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_ty_method(ty, (e, v));
|
2012-07-11 12:28:30 -05:00
|
|
|
}
|
2013-03-01 15:30:06 -06:00
|
|
|
fn v_trait_method(f: @fn(&trait_method),
|
|
|
|
m: &trait_method,
|
2013-06-11 21:55:16 -05:00
|
|
|
(e, v): ((), vt<()>)) {
|
2012-07-10 15:44:20 -05:00
|
|
|
f(m);
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_trait_method(m, (e, v));
|
2012-07-10 15:44:20 -05:00
|
|
|
}
|
2013-02-28 09:25:31 -06:00
|
|
|
fn v_struct_def(
|
2013-07-27 03:25:59 -05:00
|
|
|
f: @fn(@struct_def, ident, &Generics, NodeId),
|
2013-02-28 09:25:31 -06:00
|
|
|
sd: @struct_def,
|
|
|
|
nm: ident,
|
|
|
|
generics: &Generics,
|
2013-07-27 03:25:59 -05:00
|
|
|
id: NodeId,
|
2013-06-11 21:55:16 -05:00
|
|
|
(e, v): ((), vt<()>)
|
2013-02-28 09:25:31 -06:00
|
|
|
) {
|
2013-02-14 23:50:03 -06:00
|
|
|
f(sd, nm, generics, id);
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_struct_def(sd, nm, generics, id, (e, v));
|
2012-08-07 17:54:59 -05:00
|
|
|
}
|
2013-02-28 09:25:31 -06:00
|
|
|
fn v_generics(
|
2013-03-01 15:30:06 -06:00
|
|
|
f: @fn(&Generics),
|
2013-02-28 09:25:31 -06:00
|
|
|
ps: &Generics,
|
2013-06-11 21:55:16 -05:00
|
|
|
(e, v): ((), vt<()>)
|
2013-02-28 09:25:31 -06:00
|
|
|
) {
|
2012-01-04 09:37:39 -06:00
|
|
|
f(ps);
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_generics(ps, (e, v));
|
2012-01-04 09:37:39 -06:00
|
|
|
}
|
2013-02-18 00:20:36 -06:00
|
|
|
fn v_fn(
|
2013-07-27 03:25:59 -05:00
|
|
|
f: @fn(&fn_kind, &fn_decl, &Block, span, NodeId),
|
2013-02-18 00:20:36 -06:00
|
|
|
fk: &fn_kind,
|
|
|
|
decl: &fn_decl,
|
2013-07-19 00:38:55 -05:00
|
|
|
body: &Block,
|
2013-02-18 00:20:36 -06:00
|
|
|
sp: span,
|
2013-07-27 03:25:59 -05:00
|
|
|
id: NodeId,
|
2013-06-11 21:55:16 -05:00
|
|
|
(e, v): ((), vt<()>)
|
2013-02-18 00:20:36 -06:00
|
|
|
) {
|
2011-12-29 22:07:55 -06:00
|
|
|
f(fk, decl, body, sp, id);
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_fn(fk, decl, body, sp, id, (e, v));
|
2011-07-26 09:35:31 -05:00
|
|
|
}
|
2013-07-05 23:57:11 -05:00
|
|
|
let visit_ty: @fn(&Ty, ((), vt<()>)) =
|
2013-06-11 21:55:16 -05:00
|
|
|
|a,b| v_ty(v.visit_ty, a, b);
|
|
|
|
fn v_struct_field(f: @fn(@struct_field), sf: @struct_field, (e, v): ((), vt<()>)) {
|
2012-08-15 17:53:58 -05:00
|
|
|
f(sf);
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_struct_field(sf, (e, v));
|
2012-08-15 17:53:58 -05:00
|
|
|
}
|
2013-01-08 16:00:45 -06:00
|
|
|
return mk_vt(@Visitor {
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_mod: |a,b,c,d|v_mod(v.visit_mod, a, b, c, d),
|
|
|
|
visit_view_item: |a,b| v_view_item(v.visit_view_item, a, b),
|
2013-01-08 16:00:45 -06:00
|
|
|
visit_foreign_item:
|
2013-06-11 21:55:16 -05:00
|
|
|
|a,b|v_foreign_item(v.visit_foreign_item, a, b),
|
|
|
|
visit_item: |a,b|v_item(v.visit_item, a, b),
|
|
|
|
visit_local: |a,b|v_local(v.visit_local, a, b),
|
|
|
|
visit_block: |a,b|v_block(v.visit_block, a, b),
|
|
|
|
visit_stmt: |a,b|v_stmt(v.visit_stmt, a, b),
|
|
|
|
visit_arm: |a,b|v_arm(v.visit_arm, a, b),
|
|
|
|
visit_pat: |a,b|v_pat(v.visit_pat, a, b),
|
|
|
|
visit_decl: |a,b|v_decl(v.visit_decl, a, b),
|
|
|
|
visit_expr: |a,b|v_expr(v.visit_expr, a, b),
|
|
|
|
visit_expr_post: |a,b| v_expr_post(v.visit_expr_post, a, b),
|
2013-01-08 16:00:45 -06:00
|
|
|
visit_ty: visit_ty,
|
2013-06-11 21:55:16 -05:00
|
|
|
visit_generics: |a,b|
|
|
|
|
v_generics(v.visit_generics, a, b),
|
|
|
|
visit_fn: |a,b,c,d,e,f|
|
|
|
|
v_fn(v.visit_fn, a, b, c, d, e, f),
|
|
|
|
visit_ty_method: |a,b|
|
|
|
|
v_ty_method(v.visit_ty_method, a, b),
|
|
|
|
visit_trait_method: |a,b|
|
|
|
|
v_trait_method(v.visit_trait_method, a, b),
|
|
|
|
visit_struct_def: |a,b,c,d,e|
|
|
|
|
v_struct_def(v.visit_struct_def, a, b, c, d, e),
|
|
|
|
visit_struct_field: |a,b|
|
|
|
|
v_struct_field(v.visit_struct_field, a, b),
|
2013-01-08 16:00:45 -06:00
|
|
|
});
|
2011-07-26 09:35:31 -05:00
|
|
|
}
|