2013-09-14 00:10:48 -05:00
|
|
|
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
2012-12-03 18:48:01 -06:00
|
|
|
// 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;
|
2013-08-31 11:13:04 -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
|
|
|
|
2013-12-10 01:16:18 -06:00
|
|
|
pub enum fn_kind<'a> {
|
2013-03-13 21:25:28 -05:00
|
|
|
// fn foo() or extern "Abi" fn foo()
|
2013-12-10 01:16:18 -06:00
|
|
|
fk_item_fn(Ident, &'a Generics, purity, AbiSet),
|
2013-03-13 21:25:28 -05:00
|
|
|
|
|
|
|
// fn foo(&self)
|
2013-12-10 01:16:18 -06:00
|
|
|
fk_method(Ident, &'a Generics, &'a method),
|
2013-03-13 21:25:28 -05:00
|
|
|
|
|
|
|
// |x, y| ...
|
2013-12-12 08:01:47 -06:00
|
|
|
// proc(x, y) ...
|
2013-03-13 21:25:28 -05:00
|
|
|
fk_fn_block,
|
2011-12-29 22:07:55 -06:00
|
|
|
}
|
|
|
|
|
2013-09-01 19:50:59 -05:00
|
|
|
pub fn name_of_fn(fk: &fn_kind) -> Ident {
|
2013-02-18 23:25:44 -06:00
|
|
|
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
|
|
|
}
|
2013-12-12 08:01:47 -06:00
|
|
|
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
|
|
|
}
|
2013-12-12 08:01:47 -06:00
|
|
|
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-08-08 07:23:25 -05:00
|
|
|
pub trait Visitor<E:Clone> {
|
2013-11-22 06:24:49 -06:00
|
|
|
fn visit_ident(&mut self, _sp: Span, _ident: Ident, _e: E) {
|
|
|
|
/*! Visit the idents */
|
|
|
|
}
|
2013-08-31 11:13:04 -05:00
|
|
|
fn visit_mod(&mut self, m:&_mod, _s:Span, _n:NodeId, e:E) { walk_mod(self, m, e) }
|
2013-08-08 07:23:25 -05:00
|
|
|
fn visit_view_item(&mut self, i:&view_item, e:E) { walk_view_item(self, i, e) }
|
|
|
|
fn visit_foreign_item(&mut self, i:@foreign_item, e:E) { walk_foreign_item(self, i, e) }
|
|
|
|
fn visit_item(&mut self, i:@item, e:E) { walk_item(self, i, e) }
|
|
|
|
fn visit_local(&mut self, l:@Local, e:E) { walk_local(self, l, e) }
|
2013-11-30 16:00:39 -06:00
|
|
|
fn visit_block(&mut self, b:P<Block>, e:E) { walk_block(self, b, e) }
|
2013-09-01 20:45:37 -05:00
|
|
|
fn visit_stmt(&mut self, s:@Stmt, e:E) { walk_stmt(self, s, e) }
|
|
|
|
fn visit_arm(&mut self, a:&Arm, e:E) { walk_arm(self, a, e) }
|
2013-11-25 12:22:21 -06:00
|
|
|
fn visit_pat(&mut self, p:&Pat, e:E) { walk_pat(self, p, e) }
|
2013-09-01 20:45:37 -05:00
|
|
|
fn visit_decl(&mut self, d:@Decl, e:E) { walk_decl(self, d, e) }
|
|
|
|
fn visit_expr(&mut self, ex:@Expr, e:E) { walk_expr(self, ex, e) }
|
|
|
|
fn visit_expr_post(&mut self, _ex:@Expr, _e:E) { }
|
2013-12-08 13:25:35 -06:00
|
|
|
fn visit_ty(&mut self, t:&Ty, e:E) { walk_ty(self, t, e) }
|
2013-08-08 07:23:25 -05:00
|
|
|
fn visit_generics(&mut self, g:&Generics, e:E) { walk_generics(self, g, e) }
|
2013-11-30 16:00:39 -06:00
|
|
|
fn visit_fn(&mut self, fk:&fn_kind, fd:&fn_decl, b:P<Block>, s:Span, n:NodeId, e:E) {
|
2013-08-08 07:23:25 -05:00
|
|
|
walk_fn(self, fk, fd, b, s, n , e)
|
|
|
|
}
|
|
|
|
fn visit_ty_method(&mut self, t:&TypeMethod, e:E) { walk_ty_method(self, t, e) }
|
|
|
|
fn visit_trait_method(&mut self, t:&trait_method, e:E) { walk_trait_method(self, t, e) }
|
2013-09-01 19:50:59 -05:00
|
|
|
fn visit_struct_def(&mut self, s:@struct_def, i:Ident, g:&Generics, n:NodeId, e:E) {
|
2013-08-08 07:23:25 -05:00
|
|
|
walk_struct_def(self, s, i, g, n, e)
|
|
|
|
}
|
2013-11-30 10:27:25 -06:00
|
|
|
fn visit_struct_field(&mut self, s:&struct_field, e:E) { walk_struct_field(self, s, e) }
|
2013-11-11 22:17:47 -06:00
|
|
|
fn visit_variant(&mut self, v:&variant, g:&Generics, e:E) { walk_variant(self, v, g, e) }
|
2013-10-28 16:37:10 -05:00
|
|
|
fn visit_opt_lifetime_ref(&mut self,
|
|
|
|
_span: Span,
|
|
|
|
opt_lifetime: &Option<Lifetime>,
|
|
|
|
env: E) {
|
|
|
|
/*!
|
|
|
|
* Visits an optional reference to a lifetime. The `span` is
|
|
|
|
* the span of some surrounding reference should opt_lifetime
|
|
|
|
* be None.
|
|
|
|
*/
|
|
|
|
match *opt_lifetime {
|
|
|
|
Some(ref l) => self.visit_lifetime_ref(l, env),
|
|
|
|
None => ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn visit_lifetime_ref(&mut self, _lifetime: &Lifetime, _e: E) {
|
|
|
|
/*! Visits a reference to a lifetime */
|
|
|
|
}
|
|
|
|
fn visit_lifetime_decl(&mut self, _lifetime: &Lifetime, _e: E) {
|
|
|
|
/*! Visits a declaration of a lifetime */
|
|
|
|
}
|
|
|
|
fn visit_explicit_self(&mut self, es: &explicit_self, e: E) {
|
|
|
|
walk_explicit_self(self, es, e)
|
|
|
|
}
|
|
|
|
fn visit_mac(&mut self, macro:&mac, e:E) {
|
|
|
|
walk_mac(self, macro, e)
|
|
|
|
}
|
2013-12-08 13:25:35 -06:00
|
|
|
fn visit_path(&mut self, path: &Path, _id: ast::NodeId, e: E) {
|
|
|
|
walk_path(self, path, e)
|
|
|
|
}
|
2013-08-08 07:23:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn walk_crate<E:Clone, V:Visitor<E>>(visitor: &mut V, crate: &Crate, env: E) {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_mod(&crate.module, crate.span, CRATE_NODE_ID, env)
|
|
|
|
}
|
|
|
|
|
2013-08-08 07:23:25 -05:00
|
|
|
pub fn walk_mod<E:Clone, V:Visitor<E>>(visitor: &mut V, module: &_mod, env: E) {
|
2013-08-03 11:45:23 -05:00
|
|
|
for view_item in module.view_items.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_view_item(view_item, env.clone())
|
|
|
|
}
|
2013-11-26 00:12:14 -06:00
|
|
|
|
2013-08-03 11:45:23 -05:00
|
|
|
for item in module.items.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_item(*item, env.clone())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-22 06:24:49 -06:00
|
|
|
pub fn walk_view_item<E:Clone, V:Visitor<E>>(visitor: &mut V, vi: &view_item, env: E) {
|
|
|
|
match vi.node {
|
|
|
|
view_item_extern_mod(name, _, _, _) => {
|
|
|
|
visitor.visit_ident(vi.span, name, env)
|
|
|
|
}
|
|
|
|
view_item_use(ref paths) => {
|
|
|
|
for vp in paths.iter() {
|
2013-12-08 13:25:35 -06:00
|
|
|
match vp.node {
|
|
|
|
view_path_simple(ident, ref path, id) => {
|
2013-11-22 06:24:49 -06:00
|
|
|
visitor.visit_ident(vp.span, ident, env.clone());
|
2013-12-08 13:25:35 -06:00
|
|
|
visitor.visit_path(path, id, env.clone());
|
|
|
|
}
|
|
|
|
view_path_glob(ref path, id) => {
|
|
|
|
visitor.visit_path(path, id, env.clone());
|
2013-11-22 06:24:49 -06:00
|
|
|
}
|
|
|
|
view_path_list(ref path, ref list, _) => {
|
|
|
|
for id in list.iter() {
|
|
|
|
visitor.visit_ident(id.span, id.node.name, env.clone())
|
|
|
|
}
|
2013-12-08 13:25:35 -06:00
|
|
|
walk_path(visitor, path, env.clone());
|
2013-11-22 06:24:49 -06:00
|
|
|
}
|
2013-12-08 13:25:35 -06:00
|
|
|
}
|
2013-11-22 06:24:49 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
|
|
|
|
2013-08-08 07:23:25 -05:00
|
|
|
pub fn walk_local<E:Clone, V:Visitor<E>>(visitor: &mut V, local: &Local, env: E) {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_pat(local.pat, env.clone());
|
2013-11-30 16:00:39 -06:00
|
|
|
visitor.visit_ty(local.ty, env.clone());
|
2013-07-19 20:42:11 -05:00
|
|
|
match local.init {
|
|
|
|
None => {}
|
|
|
|
Some(initializer) => visitor.visit_expr(initializer, env),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-28 16:37:10 -05:00
|
|
|
fn walk_explicit_self<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
|
|
|
explicit_self: &explicit_self,
|
|
|
|
env: E) {
|
|
|
|
match explicit_self.node {
|
|
|
|
sty_static | sty_value(_) | sty_box(_) | sty_uniq(_) => {
|
|
|
|
}
|
|
|
|
sty_region(ref lifetime, _) => {
|
|
|
|
visitor.visit_opt_lifetime_ref(explicit_self.span, lifetime, env)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 07:23:25 -05:00
|
|
|
fn walk_trait_ref<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
2013-07-19 20:42:11 -05:00
|
|
|
trait_ref: &ast::trait_ref,
|
|
|
|
env: E) {
|
2013-12-08 13:25:35 -06:00
|
|
|
visitor.visit_path(&trait_ref.path, trait_ref.ref_id, env)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
|
|
|
|
2013-08-08 07:23:25 -05:00
|
|
|
pub fn walk_item<E:Clone, V:Visitor<E>>(visitor: &mut V, item: &item, env: E) {
|
2013-11-22 06:24:49 -06:00
|
|
|
visitor.visit_ident(item.span, item.ident, env.clone());
|
2013-07-19 20:42:11 -05:00
|
|
|
match item.node {
|
2013-11-30 16:00:39 -06:00
|
|
|
item_static(typ, _, expr) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_ty(typ, env.clone());
|
|
|
|
visitor.visit_expr(expr, env);
|
|
|
|
}
|
2013-11-30 16:00:39 -06:00
|
|
|
item_fn(declaration, purity, abi, ref generics, body) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_fn(&fk_item_fn(item.ident, generics, purity, abi),
|
|
|
|
declaration,
|
|
|
|
body,
|
|
|
|
item.span,
|
|
|
|
item.id,
|
|
|
|
env)
|
|
|
|
}
|
|
|
|
item_mod(ref module) => {
|
|
|
|
visitor.visit_mod(module, item.span, item.id, env)
|
|
|
|
}
|
|
|
|
item_foreign_mod(ref foreign_module) => {
|
2013-08-03 11:45:23 -05:00
|
|
|
for view_item in foreign_module.view_items.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_view_item(view_item, env.clone())
|
2013-07-02 14:47:32 -05:00
|
|
|
}
|
2013-08-03 11:45:23 -05:00
|
|
|
for foreign_item in foreign_module.items.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_foreign_item(*foreign_item, env.clone())
|
2013-07-02 14:47:32 -05:00
|
|
|
}
|
2011-12-20 09:33:55 -06:00
|
|
|
}
|
2013-11-30 16:00:39 -06:00
|
|
|
item_ty(typ, ref type_parameters) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_ty(typ, env.clone());
|
|
|
|
visitor.visit_generics(type_parameters, env)
|
|
|
|
}
|
|
|
|
item_enum(ref enum_definition, ref type_parameters) => {
|
|
|
|
visitor.visit_generics(type_parameters, env.clone());
|
2013-08-08 07:23:25 -05:00
|
|
|
walk_enum_def(visitor, enum_definition, type_parameters, env)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
|
|
|
item_impl(ref type_parameters,
|
|
|
|
ref trait_references,
|
2013-11-30 16:00:39 -06:00
|
|
|
typ,
|
2013-07-19 20:42:11 -05:00
|
|
|
ref methods) => {
|
|
|
|
visitor.visit_generics(type_parameters, env.clone());
|
2013-08-03 11:45:23 -05:00
|
|
|
for trait_reference in trait_references.iter() {
|
2013-08-08 07:23:25 -05:00
|
|
|
walk_trait_ref(visitor, trait_reference, env.clone())
|
2013-03-27 05:16:28 -05:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_ty(typ, env.clone());
|
2013-08-03 11:45:23 -05:00
|
|
|
for method in methods.iter() {
|
2013-08-08 07:23:25 -05:00
|
|
|
walk_method_helper(visitor, *method, env.clone())
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
item_struct(struct_definition, ref generics) => {
|
|
|
|
visitor.visit_generics(generics, env.clone());
|
|
|
|
visitor.visit_struct_def(struct_definition,
|
|
|
|
item.ident,
|
|
|
|
generics,
|
|
|
|
item.id,
|
|
|
|
env)
|
|
|
|
}
|
|
|
|
item_trait(ref generics, ref trait_paths, ref methods) => {
|
|
|
|
visitor.visit_generics(generics, env.clone());
|
2013-08-03 11:45:23 -05:00
|
|
|
for trait_path in trait_paths.iter() {
|
2013-12-08 13:25:35 -06:00
|
|
|
visitor.visit_path(&trait_path.path,
|
|
|
|
trait_path.ref_id,
|
|
|
|
env.clone())
|
2013-07-02 14:47:32 -05:00
|
|
|
}
|
2013-08-03 11:45:23 -05:00
|
|
|
for method in methods.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_trait_method(method, env.clone())
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
|
|
|
}
|
2013-10-21 04:16:58 -05:00
|
|
|
item_mac(ref macro) => visitor.visit_mac(macro, env),
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 07:23:25 -05:00
|
|
|
pub fn walk_enum_def<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
2013-07-19 20:42:11 -05:00
|
|
|
enum_definition: &ast::enum_def,
|
|
|
|
generics: &Generics,
|
|
|
|
env: E) {
|
2013-11-30 16:00:39 -06:00
|
|
|
for &variant in enum_definition.variants.iter() {
|
2013-11-11 22:17:47 -06:00
|
|
|
visitor.visit_variant(variant, generics, env.clone());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn walk_variant<E:Clone, V:Visitor<E>>(visitor:&mut V,
|
|
|
|
variant: &variant,
|
|
|
|
generics: &Generics,
|
|
|
|
env: E) {
|
2013-11-22 06:24:49 -06:00
|
|
|
visitor.visit_ident(variant.span, variant.node.name, env.clone());
|
|
|
|
|
2013-11-11 22:17:47 -06:00
|
|
|
match variant.node.kind {
|
|
|
|
tuple_variant_kind(ref variant_arguments) => {
|
|
|
|
for variant_argument in variant_arguments.iter() {
|
2013-11-30 16:00:39 -06:00
|
|
|
visitor.visit_ty(variant_argument.ty, env.clone())
|
2012-08-08 16:17:52 -05:00
|
|
|
}
|
|
|
|
}
|
2013-11-11 22:17:47 -06:00
|
|
|
struct_variant_kind(struct_definition) => {
|
|
|
|
visitor.visit_struct_def(struct_definition,
|
|
|
|
variant.node.name,
|
|
|
|
generics,
|
|
|
|
variant.node.id,
|
|
|
|
env.clone())
|
|
|
|
}
|
2012-08-08 16:17:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 07:23:25 -05:00
|
|
|
pub fn skip_ty<E, V:Visitor<E>>(_: &mut V, _: &Ty, _: E) {
|
2013-07-19 20:42:11 -05:00
|
|
|
// Empty!
|
|
|
|
}
|
2011-11-22 03:57:47 -06:00
|
|
|
|
2013-08-08 07:23:25 -05:00
|
|
|
pub fn walk_ty<E:Clone, V:Visitor<E>>(visitor: &mut V, typ: &Ty, env: E) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match typ.node {
|
|
|
|
ty_box(ref mutable_type) | ty_uniq(ref mutable_type) |
|
2013-10-28 16:37:10 -05:00
|
|
|
ty_vec(ref mutable_type) | ty_ptr(ref mutable_type) => {
|
|
|
|
visitor.visit_ty(mutable_type.ty, env)
|
|
|
|
}
|
|
|
|
ty_rptr(ref lifetime, ref mutable_type) => {
|
|
|
|
visitor.visit_opt_lifetime_ref(typ.span, lifetime, env.clone());
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_ty(mutable_type.ty, env)
|
|
|
|
}
|
|
|
|
ty_tup(ref tuple_element_types) => {
|
2013-11-30 16:00:39 -06:00
|
|
|
for &tuple_element_type in tuple_element_types.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_ty(tuple_element_type, env.clone())
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
|
|
|
ty_closure(ref function_declaration) => {
|
2013-10-28 16:37:10 -05:00
|
|
|
for argument in function_declaration.decl.inputs.iter() {
|
2013-11-30 16:00:39 -06:00
|
|
|
visitor.visit_ty(argument.ty, env.clone())
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2013-11-30 16:00:39 -06:00
|
|
|
visitor.visit_ty(function_declaration.decl.output, env.clone());
|
2013-10-28 16:37:10 -05:00
|
|
|
for bounds in function_declaration.bounds.iter() {
|
2013-08-08 07:23:25 -05:00
|
|
|
walk_ty_param_bounds(visitor, bounds, env.clone())
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
|
|
|
visitor.visit_opt_lifetime_ref(
|
|
|
|
typ.span,
|
|
|
|
&function_declaration.region,
|
|
|
|
env.clone());
|
|
|
|
walk_lifetime_decls(visitor, &function_declaration.lifetimes,
|
|
|
|
env.clone());
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
|
|
|
ty_bare_fn(ref function_declaration) => {
|
2013-08-03 11:45:23 -05:00
|
|
|
for argument in function_declaration.decl.inputs.iter() {
|
2013-11-30 16:00:39 -06:00
|
|
|
visitor.visit_ty(argument.ty, env.clone())
|
2013-07-02 14:47:32 -05:00
|
|
|
}
|
2013-11-30 16:00:39 -06:00
|
|
|
visitor.visit_ty(function_declaration.decl.output, env.clone());
|
2013-10-28 16:37:10 -05:00
|
|
|
walk_lifetime_decls(visitor, &function_declaration.lifetimes,
|
|
|
|
env.clone());
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2013-12-08 13:25:35 -06:00
|
|
|
ty_path(ref path, ref bounds, id) => {
|
|
|
|
visitor.visit_path(path, id, env.clone());
|
2013-08-03 11:45:23 -05:00
|
|
|
for bounds in bounds.iter() {
|
2013-08-08 07:23:25 -05:00
|
|
|
walk_ty_param_bounds(visitor, bounds, env.clone())
|
2013-07-02 14:47:32 -05:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
|
|
|
ty_fixed_length_vec(ref mutable_type, expression) => {
|
|
|
|
visitor.visit_ty(mutable_type.ty, env.clone());
|
|
|
|
visitor.visit_expr(expression, env)
|
|
|
|
}
|
2013-08-22 16:00:02 -05:00
|
|
|
ty_typeof(expression) => {
|
|
|
|
visitor.visit_expr(expression, env)
|
|
|
|
}
|
2013-11-21 07:59:56 -06:00
|
|
|
ty_nil | ty_bot | ty_infer => ()
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-28 16:37:10 -05:00
|
|
|
fn walk_lifetime_decls<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
|
|
|
lifetimes: &OptVec<Lifetime>,
|
|
|
|
env: E) {
|
|
|
|
for l in lifetimes.iter() {
|
|
|
|
visitor.visit_lifetime_decl(l, env.clone());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 07:23:25 -05:00
|
|
|
pub fn walk_path<E:Clone, V:Visitor<E>>(visitor: &mut V, path: &Path, env: E) {
|
2013-08-07 11:47:28 -05:00
|
|
|
for segment in path.segments.iter() {
|
2013-11-22 06:24:49 -06:00
|
|
|
visitor.visit_ident(path.span, segment.identifier, env.clone());
|
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
for &typ in segment.types.iter() {
|
2013-10-28 16:37:10 -05:00
|
|
|
visitor.visit_ty(typ, env.clone());
|
|
|
|
}
|
|
|
|
for lifetime in segment.lifetimes.iter() {
|
|
|
|
visitor.visit_lifetime_ref(lifetime, env.clone());
|
2013-08-07 11:47:28 -05:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2011-12-13 06:19:56 -06:00
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
pub fn walk_pat<E:Clone, V:Visitor<E>>(visitor: &mut V, pattern: &Pat, env: E) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match pattern.node {
|
2013-09-01 20:45:37 -05:00
|
|
|
PatEnum(ref path, ref children) => {
|
2013-12-08 13:25:35 -06:00
|
|
|
visitor.visit_path(path, pattern.id, env.clone());
|
2013-08-03 11:45:23 -05:00
|
|
|
for children in children.iter() {
|
|
|
|
for child in children.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_pat(*child, env.clone())
|
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-09-01 20:45:37 -05:00
|
|
|
PatStruct(ref path, ref fields, _) => {
|
2013-12-08 13:25:35 -06:00
|
|
|
visitor.visit_path(path, pattern.id, env.clone());
|
2013-08-03 11:45:23 -05:00
|
|
|
for field in fields.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_pat(field.pat, env.clone())
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
PatTup(ref tuple_elements) => {
|
2013-08-03 11:45:23 -05:00
|
|
|
for tuple_element in tuple_elements.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_pat(*tuple_element, env.clone())
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
PatBox(subpattern) |
|
|
|
|
PatUniq(subpattern) |
|
|
|
|
PatRegion(subpattern) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_pat(subpattern, env)
|
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
PatIdent(_, ref path, ref optional_subpattern) => {
|
2013-12-08 13:25:35 -06:00
|
|
|
visitor.visit_path(path, pattern.id, env.clone());
|
2013-07-19 20:42:11 -05:00
|
|
|
match *optional_subpattern {
|
|
|
|
None => {}
|
|
|
|
Some(subpattern) => visitor.visit_pat(subpattern, env),
|
2013-06-15 19:26:59 -05:00
|
|
|
}
|
2012-12-08 14:22:43 -06:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
PatLit(expression) => visitor.visit_expr(expression, env),
|
|
|
|
PatRange(lower_bound, upper_bound) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(lower_bound, env.clone());
|
|
|
|
visitor.visit_expr(upper_bound, env)
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-11-07 21:25:39 -06:00
|
|
|
PatWild | PatWildMulti => (),
|
2013-09-01 20:45:37 -05:00
|
|
|
PatVec(ref prepattern, ref slice_pattern, ref postpatterns) => {
|
2013-08-03 11:45:23 -05:00
|
|
|
for prepattern in prepattern.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_pat(*prepattern, env.clone())
|
2013-02-26 12:58:46 -06:00
|
|
|
}
|
2013-08-03 11:45:23 -05:00
|
|
|
for slice_pattern in slice_pattern.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_pat(*slice_pattern, env.clone())
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-08-03 11:45:23 -05:00
|
|
|
for postpattern in postpatterns.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_pat(*postpattern, env.clone())
|
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-08-08 07:23:25 -05:00
|
|
|
pub fn walk_foreign_item<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
2013-07-19 20:42:11 -05:00
|
|
|
foreign_item: &foreign_item,
|
|
|
|
env: E) {
|
2013-11-22 06:24:49 -06:00
|
|
|
visitor.visit_ident(foreign_item.span, foreign_item.ident, env.clone());
|
|
|
|
|
2013-07-19 20:42:11 -05:00
|
|
|
match foreign_item.node {
|
2013-11-30 16:00:39 -06:00
|
|
|
foreign_item_fn(function_declaration, ref generics) => {
|
2013-08-08 07:23:25 -05:00
|
|
|
walk_fn_decl(visitor, function_declaration, env.clone());
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_generics(generics, env)
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
2013-11-30 16:00:39 -06:00
|
|
|
foreign_item_static(typ, _) => visitor.visit_ty(typ, env),
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 07:23:25 -05:00
|
|
|
pub fn walk_ty_param_bounds<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
2013-07-19 20:42:11 -05:00
|
|
|
bounds: &OptVec<TyParamBound>,
|
|
|
|
env: E) {
|
2013-08-03 11:45:23 -05:00
|
|
|
for bound in bounds.iter() {
|
2013-02-14 23:50:03 -06:00
|
|
|
match *bound {
|
2013-07-19 20:42:11 -05:00
|
|
|
TraitTyParamBound(ref typ) => {
|
2013-08-08 07:23:25 -05:00
|
|
|
walk_trait_ref(visitor, typ, env.clone())
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
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-08-08 07:23:25 -05:00
|
|
|
pub fn walk_generics<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
2013-07-19 20:42:11 -05:00
|
|
|
generics: &Generics,
|
|
|
|
env: E) {
|
2013-08-03 11:45:23 -05:00
|
|
|
for type_parameter in generics.ty_params.iter() {
|
2013-08-08 07:23:25 -05:00
|
|
|
walk_ty_param_bounds(visitor, &type_parameter.bounds, env.clone())
|
2011-12-28 10:50:12 -06:00
|
|
|
}
|
2013-10-28 16:37:10 -05:00
|
|
|
walk_lifetime_decls(visitor, &generics.lifetimes, env);
|
2011-12-28 10:50:12 -06:00
|
|
|
}
|
|
|
|
|
2013-08-08 07:23:25 -05:00
|
|
|
pub fn walk_fn_decl<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
2013-07-19 20:42:11 -05:00
|
|
|
function_declaration: &fn_decl,
|
|
|
|
env: E) {
|
2013-08-03 11:45:23 -05:00
|
|
|
for argument in function_declaration.inputs.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_pat(argument.pat, env.clone());
|
2013-11-30 16:00:39 -06:00
|
|
|
visitor.visit_ty(argument.ty, env.clone())
|
2012-11-06 20:41:06 -06:00
|
|
|
}
|
2013-11-30 16:00:39 -06:00
|
|
|
visitor.visit_ty(function_declaration.output, env)
|
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-08-08 07:23:25 -05:00
|
|
|
pub fn walk_method_helper<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
2013-07-19 20:42:11 -05:00
|
|
|
method: &method,
|
|
|
|
env: E) {
|
2013-11-22 06:24:49 -06:00
|
|
|
visitor.visit_ident(method.span, method.ident, env.clone());
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_fn(&fk_method(method.ident, &method.generics, method),
|
2013-11-30 16:00:39 -06:00
|
|
|
method.decl,
|
|
|
|
method.body,
|
2013-07-19 20:42:11 -05:00
|
|
|
method.span,
|
|
|
|
method.id,
|
|
|
|
env)
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
|
|
|
|
2013-08-08 07:23:25 -05:00
|
|
|
pub fn walk_fn<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
2013-07-19 20:42:11 -05:00
|
|
|
function_kind: &fn_kind,
|
|
|
|
function_declaration: &fn_decl,
|
2013-11-30 16:00:39 -06:00
|
|
|
function_body: P<Block>,
|
2013-10-28 16:37:10 -05:00
|
|
|
_span: Span,
|
2013-07-19 20:42:11 -05:00
|
|
|
_: NodeId,
|
|
|
|
env: E) {
|
2013-08-08 07:23:25 -05:00
|
|
|
walk_fn_decl(visitor, function_declaration, env.clone());
|
2013-10-28 16:37:10 -05:00
|
|
|
|
|
|
|
match *function_kind {
|
|
|
|
fk_item_fn(_, generics, _, _) => {
|
|
|
|
visitor.visit_generics(generics, env.clone());
|
|
|
|
}
|
|
|
|
fk_method(_, generics, method) => {
|
|
|
|
visitor.visit_generics(generics, env.clone());
|
|
|
|
|
|
|
|
visitor.visit_explicit_self(&method.explicit_self, env.clone());
|
|
|
|
}
|
2013-12-12 08:01:47 -06:00
|
|
|
fk_fn_block(..) => {
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_block(function_body, env)
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2013-08-08 07:23:25 -05:00
|
|
|
pub fn walk_ty_method<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
2013-10-28 16:37:10 -05:00
|
|
|
method_type: &TypeMethod,
|
|
|
|
env: E) {
|
2013-11-22 06:24:49 -06:00
|
|
|
visitor.visit_ident(method_type.span, method_type.ident, env.clone());
|
2013-10-28 16:37:10 -05:00
|
|
|
visitor.visit_explicit_self(&method_type.explicit_self, env.clone());
|
2013-08-03 11:45:23 -05:00
|
|
|
for argument_type in method_type.decl.inputs.iter() {
|
2013-11-30 16:00:39 -06:00
|
|
|
visitor.visit_ty(argument_type.ty, env.clone())
|
2013-07-02 14:47:32 -05:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_generics(&method_type.generics, env.clone());
|
2013-11-30 16:00:39 -06:00
|
|
|
visitor.visit_ty(method_type.decl.output, env);
|
2012-07-11 12:28:30 -05:00
|
|
|
}
|
|
|
|
|
2013-08-08 07:23:25 -05:00
|
|
|
pub fn walk_trait_method<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
2013-07-19 20:42:11 -05:00
|
|
|
trait_method: &trait_method,
|
|
|
|
env: E) {
|
|
|
|
match *trait_method {
|
|
|
|
required(ref method_type) => {
|
|
|
|
visitor.visit_ty_method(method_type, env)
|
|
|
|
}
|
2013-08-08 07:23:25 -05:00
|
|
|
provided(method) => walk_method_helper(visitor, method, env),
|
2012-07-10 15:44:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 07:23:25 -05:00
|
|
|
pub fn walk_struct_def<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
2013-07-19 20:42:11 -05:00
|
|
|
struct_definition: @struct_def,
|
2013-09-01 19:50:59 -05:00
|
|
|
_: ast::Ident,
|
2013-07-19 20:42:11 -05:00
|
|
|
_: &Generics,
|
|
|
|
_: NodeId,
|
|
|
|
env: E) {
|
2013-08-03 11:45:23 -05:00
|
|
|
for field in struct_definition.fields.iter() {
|
2013-11-30 10:27:25 -06:00
|
|
|
visitor.visit_struct_field(field, env.clone())
|
2012-08-15 17:53:58 -05:00
|
|
|
}
|
2012-08-07 17:54:59 -05:00
|
|
|
}
|
|
|
|
|
2013-08-08 07:23:25 -05:00
|
|
|
pub fn walk_struct_field<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
2013-07-19 20:42:11 -05:00
|
|
|
struct_field: &struct_field,
|
|
|
|
env: E) {
|
2013-11-22 06:24:49 -06:00
|
|
|
match struct_field.node.kind {
|
|
|
|
named_field(name, _) => {
|
|
|
|
visitor.visit_ident(struct_field.span, name, env.clone())
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
visitor.visit_ty(struct_field.node.ty, env)
|
2012-08-15 17:53:58 -05:00
|
|
|
}
|
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
pub fn walk_block<E:Clone, V:Visitor<E>>(visitor: &mut V, block: P<Block>, env: E) {
|
2013-08-03 11:45:23 -05:00
|
|
|
for view_item in block.view_items.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_view_item(view_item, env.clone())
|
2012-09-19 18:55:01 -05:00
|
|
|
}
|
2013-08-03 11:45:23 -05:00
|
|
|
for statement in block.stmts.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_stmt(*statement, env.clone())
|
2012-09-19 18:55:01 -05:00
|
|
|
}
|
2013-08-08 07:23:25 -05:00
|
|
|
walk_expr_opt(visitor, block.expr, env)
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
pub fn walk_stmt<E:Clone, V:Visitor<E>>(visitor: &mut V, statement: &Stmt, env: E) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match statement.node {
|
2013-09-01 20:45:37 -05:00
|
|
|
StmtDecl(declaration, _) => visitor.visit_decl(declaration, env),
|
|
|
|
StmtExpr(expression, _) | StmtSemi(expression, _) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(expression, env)
|
|
|
|
}
|
2013-10-21 04:16:58 -05:00
|
|
|
StmtMac(ref macro, _) => visitor.visit_mac(macro, env),
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
pub fn walk_decl<E:Clone, V:Visitor<E>>(visitor: &mut V, declaration: &Decl, env: E) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match declaration.node {
|
2013-09-01 20:45:37 -05:00
|
|
|
DeclLocal(ref local) => visitor.visit_local(*local, env),
|
|
|
|
DeclItem(item) => visitor.visit_item(item, env),
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 07:23:25 -05:00
|
|
|
pub fn walk_expr_opt<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
2013-09-01 20:45:37 -05:00
|
|
|
optional_expression: Option<@Expr>,
|
2013-07-19 20:42:11 -05:00
|
|
|
env: E) {
|
|
|
|
match optional_expression {
|
|
|
|
None => {}
|
|
|
|
Some(expression) => visitor.visit_expr(expression, env),
|
|
|
|
}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2013-08-08 07:23:25 -05:00
|
|
|
pub fn walk_exprs<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
2013-09-01 20:45:37 -05:00
|
|
|
expressions: &[@Expr],
|
2013-07-19 20:42:11 -05:00
|
|
|
env: E) {
|
2013-08-03 11:45:23 -05:00
|
|
|
for expression in expressions.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(*expression, env.clone())
|
|
|
|
}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2013-08-08 07:23:25 -05:00
|
|
|
pub fn walk_mac<E, V:Visitor<E>>(_: &mut V, _: &mac, _: E) {
|
2013-07-19 20:42:11 -05:00
|
|
|
// Empty!
|
2011-07-08 18:35:09 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
pub fn walk_expr<E:Clone, V:Visitor<E>>(visitor: &mut V, expression: @Expr, env: E) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match expression.node {
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprVstore(subexpression, _) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(subexpression, env.clone())
|
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprVec(ref subexpressions, _) => {
|
2013-08-08 07:23:25 -05:00
|
|
|
walk_exprs(visitor, *subexpressions, env.clone())
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprRepeat(element, count, _) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(element, env.clone());
|
|
|
|
visitor.visit_expr(count, env.clone())
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprStruct(ref path, ref fields, optional_base) => {
|
2013-12-08 13:25:35 -06:00
|
|
|
visitor.visit_path(path, expression.id, env.clone());
|
2013-08-03 11:45:23 -05:00
|
|
|
for field in fields.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(field.expr, env.clone())
|
2013-06-15 19:26:59 -05:00
|
|
|
}
|
2013-08-08 07:23:25 -05:00
|
|
|
walk_expr_opt(visitor, optional_base, env.clone())
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprTup(ref subexpressions) => {
|
2013-08-03 11:45:23 -05:00
|
|
|
for subexpression in subexpressions.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(*subexpression, env.clone())
|
|
|
|
}
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprCall(callee_expression, ref arguments, _) => {
|
2013-08-03 11:45:23 -05:00
|
|
|
for argument in arguments.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(*argument, env.clone())
|
|
|
|
}
|
|
|
|
visitor.visit_expr(callee_expression, env.clone())
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprMethodCall(_, callee, _, ref types, ref arguments, _) => {
|
2013-08-08 07:23:25 -05:00
|
|
|
walk_exprs(visitor, *arguments, env.clone());
|
2013-11-30 16:00:39 -06:00
|
|
|
for &typ in types.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_ty(typ, env.clone())
|
|
|
|
}
|
|
|
|
visitor.visit_expr(callee, env.clone())
|
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprBinary(_, _, left_expression, right_expression) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(left_expression, env.clone());
|
|
|
|
visitor.visit_expr(right_expression, env.clone())
|
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprAddrOf(_, subexpression) |
|
|
|
|
ExprUnary(_, _, subexpression) |
|
|
|
|
ExprDoBody(subexpression) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(subexpression, env.clone())
|
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprLit(_) => {}
|
2013-11-30 16:00:39 -06:00
|
|
|
ExprCast(subexpression, typ) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(subexpression, env.clone());
|
|
|
|
visitor.visit_ty(typ, env.clone())
|
|
|
|
}
|
2013-11-30 16:00:39 -06:00
|
|
|
ExprIf(head_expression, if_block, optional_else) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(head_expression, env.clone());
|
|
|
|
visitor.visit_block(if_block, env.clone());
|
2013-08-08 07:23:25 -05:00
|
|
|
walk_expr_opt(visitor, optional_else, env.clone())
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2013-11-30 16:00:39 -06:00
|
|
|
ExprWhile(subexpression, block) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(subexpression, env.clone());
|
|
|
|
visitor.visit_block(block, env.clone())
|
|
|
|
}
|
2013-11-30 16:00:39 -06:00
|
|
|
ExprForLoop(pattern, subexpression, block, _) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_pat(pattern, env.clone());
|
|
|
|
visitor.visit_expr(subexpression, env.clone());
|
|
|
|
visitor.visit_block(block, env.clone())
|
|
|
|
}
|
2013-11-30 16:00:39 -06:00
|
|
|
ExprLoop(block, _) => visitor.visit_block(block, env.clone()),
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprMatch(subexpression, ref arms) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(subexpression, env.clone());
|
2013-08-03 11:45:23 -05:00
|
|
|
for arm in arms.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_arm(arm, env.clone())
|
2013-06-15 19:26:59 -05:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2013-11-30 16:00:39 -06:00
|
|
|
ExprFnBlock(function_declaration, body) => {
|
2013-10-28 17:22:49 -05:00
|
|
|
visitor.visit_fn(&fk_fn_block,
|
|
|
|
function_declaration,
|
|
|
|
body,
|
|
|
|
expression.span,
|
|
|
|
expression.id,
|
|
|
|
env.clone())
|
|
|
|
}
|
2013-11-30 16:00:39 -06:00
|
|
|
ExprProc(function_declaration, body) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_fn(&fk_fn_block,
|
|
|
|
function_declaration,
|
|
|
|
body,
|
|
|
|
expression.span,
|
|
|
|
expression.id,
|
|
|
|
env.clone())
|
|
|
|
}
|
2013-11-30 16:00:39 -06:00
|
|
|
ExprBlock(block) => visitor.visit_block(block, env.clone()),
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprAssign(left_hand_expression, right_hand_expression) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(right_hand_expression, env.clone());
|
|
|
|
visitor.visit_expr(left_hand_expression, env.clone())
|
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprAssignOp(_, _, left_expression, right_expression) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(right_expression, env.clone());
|
|
|
|
visitor.visit_expr(left_expression, env.clone())
|
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprField(subexpression, _, ref types) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(subexpression, env.clone());
|
2013-11-30 16:00:39 -06:00
|
|
|
for &typ in types.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_ty(typ, env.clone())
|
2013-06-15 19:26:59 -05:00
|
|
|
}
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprIndex(_, main_expression, index_expression) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(main_expression, env.clone());
|
|
|
|
visitor.visit_expr(index_expression, env.clone())
|
|
|
|
}
|
2013-12-08 13:25:35 -06:00
|
|
|
ExprPath(ref path) => {
|
|
|
|
visitor.visit_path(path, expression.id, env.clone())
|
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprSelf | ExprBreak(_) | ExprAgain(_) => {}
|
|
|
|
ExprRet(optional_expression) => {
|
2013-08-08 07:23:25 -05:00
|
|
|
walk_expr_opt(visitor, optional_expression, env.clone())
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2013-08-28 01:12:05 -05:00
|
|
|
ExprLogLevel => {}
|
2013-10-21 04:16:58 -05:00
|
|
|
ExprMac(ref macro) => visitor.visit_mac(macro, env.clone()),
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprParen(subexpression) => {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(subexpression, env.clone())
|
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprInlineAsm(ref assembler) => {
|
2013-08-03 11:45:23 -05:00
|
|
|
for &(_, input) in assembler.inputs.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(input, env.clone())
|
2013-03-12 19:53:25 -05:00
|
|
|
}
|
2013-08-03 11:45:23 -05:00
|
|
|
for &(_, output) in assembler.outputs.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_expr(output, env.clone())
|
2013-03-12 19:53:25 -05:00
|
|
|
}
|
|
|
|
}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
|
|
|
|
visitor.visit_expr_post(expression, env.clone())
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
pub fn walk_arm<E:Clone, V:Visitor<E>>(visitor: &mut V, arm: &Arm, env: E) {
|
2013-08-03 11:45:23 -05:00
|
|
|
for pattern in arm.pats.iter() {
|
2013-07-19 20:42:11 -05:00
|
|
|
visitor.visit_pat(*pattern, env.clone())
|
|
|
|
}
|
2013-08-08 07:23:25 -05:00
|
|
|
walk_expr_opt(visitor, arm.guard, env.clone());
|
2013-11-30 16:00:39 -06:00
|
|
|
visitor.visit_block(arm.body, env)
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|