2014-07-27 06:50:46 -05:00
|
|
|
// Copyright 2012-2014 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.
|
|
|
|
|
2014-09-12 05:10:30 -05:00
|
|
|
//! 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,
|
|
|
|
//! call `visit::walk_*` to apply the default traversal algorithm, or prevent
|
|
|
|
//! deeper traversal by doing nothing.
|
2014-06-09 15:12:30 -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.
|
|
|
|
//!
|
2014-07-09 16:48:12 -05:00
|
|
|
//! Note: walking an AST before macro expansion is probably a bad idea. For
|
|
|
|
//! instance, a walker looking for item names in a module will miss all of
|
|
|
|
//! those that are created by the expansion of a macro.
|
|
|
|
|
2014-04-02 03:19:41 -05:00
|
|
|
use abi::Abi;
|
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;
|
2014-09-13 11:06:01 -05:00
|
|
|
use ptr::P;
|
2014-03-19 09:52:37 -05:00
|
|
|
use owned_slice::OwnedSlice;
|
2012-12-23 16:41:37 -06:00
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum FnKind<'a> {
|
2014-06-09 15:12:30 -05:00
|
|
|
/// fn foo() or extern "Abi" fn foo()
|
2014-04-06 20:04:40 -05:00
|
|
|
FkItemFn(Ident, &'a Generics, FnStyle, Abi),
|
2013-03-13 21:25:28 -05:00
|
|
|
|
2014-06-09 15:12:30 -05:00
|
|
|
/// fn foo(&self)
|
2014-01-09 07:05:33 -06:00
|
|
|
FkMethod(Ident, &'a Generics, &'a Method),
|
2013-03-13 21:25:28 -05:00
|
|
|
|
2014-06-09 15:12:30 -05:00
|
|
|
/// |x, y| ...
|
|
|
|
/// proc(x, y) ...
|
2014-01-09 07:05:33 -06:00
|
|
|
FkFnBlock,
|
2011-12-29 22:07:55 -06:00
|
|
|
}
|
|
|
|
|
2014-05-12 11:58:23 -05:00
|
|
|
/// Each method of the Visitor trait is a hook to be potentially
|
2014-06-08 23:00:52 -05:00
|
|
|
/// overridden. Each method's default implementation recursively visits
|
2014-05-12 11:58:23 -05:00
|
|
|
/// the substructure of the input via the corresponding `walk` method;
|
|
|
|
/// e.g. the `visit_mod` method by default calls `visit::walk_mod`.
|
|
|
|
///
|
|
|
|
/// If you want to ensure that your code handles every variant
|
|
|
|
/// explicitly, you need to override each method. (And you also need
|
|
|
|
/// to monitor future changes to `Visitor` in case a new method with a
|
|
|
|
/// new default implementation gets introduced.)
|
2014-09-09 17:54:36 -05:00
|
|
|
pub trait Visitor<'v> {
|
2014-05-12 11:58:23 -05:00
|
|
|
|
2014-09-12 05:10:30 -05:00
|
|
|
fn visit_ident(&mut self, _sp: Span, _ident: Ident) {
|
2013-11-22 06:24:49 -06:00
|
|
|
/*! Visit the idents */
|
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
fn visit_mod(&mut self, m: &'v Mod, _s: Span, _n: NodeId) { walk_mod(self, m) }
|
|
|
|
fn visit_view_item(&mut self, i: &'v ViewItem) { walk_view_item(self, i) }
|
|
|
|
fn visit_foreign_item(&mut self, i: &'v ForeignItem) { walk_foreign_item(self, i) }
|
|
|
|
fn visit_item(&mut self, i: &'v Item) { walk_item(self, i) }
|
|
|
|
fn visit_local(&mut self, l: &'v Local) { walk_local(self, l) }
|
|
|
|
fn visit_block(&mut self, b: &'v Block) { walk_block(self, b) }
|
|
|
|
fn visit_stmt(&mut self, s: &'v Stmt) { walk_stmt(self, s) }
|
|
|
|
fn visit_arm(&mut self, a: &'v Arm) { walk_arm(self, a) }
|
|
|
|
fn visit_pat(&mut self, p: &'v Pat) { walk_pat(self, p) }
|
|
|
|
fn visit_decl(&mut self, d: &'v Decl) { walk_decl(self, d) }
|
|
|
|
fn visit_expr(&mut self, ex: &'v Expr) { walk_expr(self, ex) }
|
|
|
|
fn visit_expr_post(&mut self, _ex: &'v Expr) { }
|
|
|
|
fn visit_ty(&mut self, t: &'v Ty) { walk_ty(self, t) }
|
|
|
|
fn visit_generics(&mut self, g: &'v Generics) { walk_generics(self, g) }
|
|
|
|
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, b: &'v Block, s: Span, _: NodeId) {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_fn(self, fk, fd, b, s)
|
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
fn visit_ty_method(&mut self, t: &'v TypeMethod) { walk_ty_method(self, t) }
|
|
|
|
fn visit_trait_item(&mut self, t: &'v TraitItem) { walk_trait_item(self, t) }
|
|
|
|
fn visit_struct_def(&mut self, s: &'v StructDef, _: Ident, _: &'v Generics, _: NodeId) {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_struct_def(self, s)
|
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
fn visit_struct_field(&mut self, s: &'v StructField) { walk_struct_field(self, s) }
|
|
|
|
fn visit_variant(&mut self, v: &'v Variant, g: &'v Generics) { walk_variant(self, v, g) }
|
2013-10-28 16:37:10 -05:00
|
|
|
fn visit_opt_lifetime_ref(&mut self,
|
|
|
|
_span: Span,
|
2014-09-09 17:54:36 -05:00
|
|
|
opt_lifetime: &'v Option<Lifetime>) {
|
2013-10-28 16:37:10 -05:00
|
|
|
/*!
|
|
|
|
* Visits an optional reference to a lifetime. The `span` is
|
|
|
|
* the span of some surrounding reference should opt_lifetime
|
|
|
|
* be None.
|
|
|
|
*/
|
|
|
|
match *opt_lifetime {
|
2014-09-12 05:10:30 -05:00
|
|
|
Some(ref l) => self.visit_lifetime_ref(l),
|
2013-10-28 16:37:10 -05:00
|
|
|
None => ()
|
|
|
|
}
|
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
fn visit_lifetime_ref(&mut self, _lifetime: &'v Lifetime) {
|
2013-10-28 16:37:10 -05:00
|
|
|
/*! Visits a reference to a lifetime */
|
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
fn visit_lifetime_decl(&mut self, _lifetime: &'v LifetimeDef) {
|
2013-10-28 16:37:10 -05:00
|
|
|
/*! Visits a declaration of a lifetime */
|
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
fn visit_explicit_self(&mut self, es: &'v ExplicitSelf) {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_explicit_self(self, es)
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
fn visit_mac(&mut self, _macro: &'v Mac) {
|
2014-07-09 16:48:12 -05:00
|
|
|
fail!("visit_mac disabled by default");
|
|
|
|
// NB: see note about macros above.
|
|
|
|
// if you really want a visitor that
|
|
|
|
// works on macros, use this
|
|
|
|
// definition in your trait impl:
|
2014-09-12 05:10:30 -05:00
|
|
|
// visit::walk_mac(self, _macro)
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
fn visit_path(&mut self, path: &'v Path, _id: ast::NodeId) {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_path(self, path)
|
2013-12-08 13:25:35 -06:00
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
fn visit_attribute(&mut self, _attr: &'v Attribute) {}
|
2013-08-08 07:23:25 -05:00
|
|
|
}
|
|
|
|
|
2014-08-05 21:44:21 -05:00
|
|
|
pub fn walk_inlined_item<'v,V>(visitor: &mut V, item: &'v InlinedItem)
|
|
|
|
where V: Visitor<'v> {
|
2014-01-15 13:39:08 -06:00
|
|
|
match *item {
|
2014-09-09 17:54:36 -05:00
|
|
|
IIItem(ref i) => visitor.visit_item(&**i),
|
|
|
|
IIForeign(ref i) => visitor.visit_foreign_item(&**i),
|
2014-09-13 11:06:01 -05:00
|
|
|
IITraitItem(_, ref ti) => visitor.visit_trait_item(ti),
|
2014-08-05 21:44:21 -05:00
|
|
|
IIImplItem(_, MethodImplItem(ref m)) => {
|
|
|
|
walk_method_helper(visitor, &**m)
|
|
|
|
}
|
|
|
|
IIImplItem(_, TypeImplItem(ref typedef)) => {
|
|
|
|
visitor.visit_ident(typedef.span, typedef.ident);
|
|
|
|
visitor.visit_ty(&*typedef.typ);
|
|
|
|
}
|
2014-01-15 13:39:08 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate) {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID);
|
2014-06-08 01:02:48 -05:00
|
|
|
for attr in krate.attrs.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_attribute(attr);
|
2014-06-08 01:02:48 -05:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod) {
|
2013-08-03 11:45:23 -05:00
|
|
|
for view_item in module.view_items.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_view_item(view_item)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2013-11-26 00:12:14 -06:00
|
|
|
|
2013-08-03 11:45:23 -05:00
|
|
|
for item in module.items.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_item(&**item)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_view_item<'v, V: Visitor<'v>>(visitor: &mut V, vi: &'v ViewItem) {
|
2013-11-22 06:24:49 -06:00
|
|
|
match vi.node {
|
2014-03-07 01:57:45 -06:00
|
|
|
ViewItemExternCrate(name, _, _) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ident(vi.span, name)
|
2013-11-22 06:24:49 -06:00
|
|
|
}
|
2014-04-26 08:33:45 -05:00
|
|
|
ViewItemUse(ref vp) => {
|
|
|
|
match vp.node {
|
|
|
|
ViewPathSimple(ident, ref path, id) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ident(vp.span, ident);
|
|
|
|
visitor.visit_path(path, id);
|
2014-04-26 08:33:45 -05:00
|
|
|
}
|
|
|
|
ViewPathGlob(ref path, id) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_path(path, id);
|
2014-04-26 08:33:45 -05:00
|
|
|
}
|
|
|
|
ViewPathList(ref path, ref list, _) => {
|
|
|
|
for id in list.iter() {
|
2014-07-17 17:56:56 -05:00
|
|
|
match id.node {
|
|
|
|
PathListIdent { name, .. } => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ident(id.span, name);
|
2014-07-17 17:56:56 -05:00
|
|
|
}
|
|
|
|
PathListMod { .. } => ()
|
|
|
|
}
|
2013-11-22 06:24:49 -06:00
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_path(visitor, path);
|
2013-12-08 13:25:35 -06:00
|
|
|
}
|
2013-11-22 06:24:49 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-08 01:02:48 -05:00
|
|
|
for attr in vi.attrs.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_attribute(attr);
|
2014-06-08 01:02:48 -05:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local) {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_pat(&*local.pat);
|
|
|
|
visitor.visit_ty(&*local.ty);
|
2014-09-09 17:54:36 -05:00
|
|
|
walk_expr_opt(visitor, &local.init);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_explicit_self<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
explicit_self: &'v ExplicitSelf) {
|
2013-10-28 16:37:10 -05:00
|
|
|
match explicit_self.node {
|
2014-07-23 12:21:50 -05:00
|
|
|
SelfStatic | SelfValue(_) => {},
|
2014-07-06 17:10:57 -05:00
|
|
|
SelfRegion(ref lifetime, _, _) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_opt_lifetime_ref(explicit_self.span, lifetime)
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
SelfExplicit(ref typ, _) => visitor.visit_ty(&**typ),
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 01:33:03 -06:00
|
|
|
/// Like with walk_method_helper this doesn't correspond to a method
|
|
|
|
/// in Visitor, and so it gets a _helper suffix.
|
2014-09-05 14:21:02 -05:00
|
|
|
pub fn walk_trait_ref_helper<'v,V>(visitor: &mut V, trait_ref: &'v TraitRef)
|
|
|
|
where V: Visitor<'v> {
|
|
|
|
walk_lifetime_decls(visitor, &trait_ref.lifetimes);
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_path(&trait_ref.path, trait_ref.ref_id)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ident(item.span, item.ident);
|
2013-07-19 20:42:11 -05:00
|
|
|
match item.node {
|
2014-05-16 12:15:33 -05:00
|
|
|
ItemStatic(ref typ, _, ref expr) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&**typ);
|
|
|
|
visitor.visit_expr(&**expr);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
ItemFn(ref declaration, fn_style, abi, ref generics, ref body) => {
|
|
|
|
visitor.visit_fn(FkItemFn(item.ident, generics, fn_style, abi),
|
|
|
|
&**declaration,
|
|
|
|
&**body,
|
2013-07-19 20:42:11 -05:00
|
|
|
item.span,
|
2014-09-12 05:10:30 -05:00
|
|
|
item.id)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-01-09 07:05:33 -06:00
|
|
|
ItemMod(ref module) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_mod(module, item.span, item.id)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-01-09 07:05:33 -06:00
|
|
|
ItemForeignMod(ref foreign_module) => {
|
2013-08-03 11:45:23 -05:00
|
|
|
for view_item in foreign_module.view_items.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_view_item(view_item)
|
2013-07-02 14:47:32 -05:00
|
|
|
}
|
2013-08-03 11:45:23 -05:00
|
|
|
for foreign_item in foreign_module.items.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_foreign_item(&**foreign_item)
|
2013-07-02 14:47:32 -05:00
|
|
|
}
|
2011-12-20 09:33:55 -06:00
|
|
|
}
|
2014-05-16 12:15:33 -05:00
|
|
|
ItemTy(ref typ, ref type_parameters) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&**typ);
|
|
|
|
visitor.visit_generics(type_parameters)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-01-09 07:05:33 -06:00
|
|
|
ItemEnum(ref enum_definition, ref type_parameters) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(type_parameters);
|
|
|
|
walk_enum_def(visitor, enum_definition, type_parameters)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-01-09 07:05:33 -06:00
|
|
|
ItemImpl(ref type_parameters,
|
2014-01-09 02:42:28 -06:00
|
|
|
ref trait_reference,
|
2014-09-09 17:54:36 -05:00
|
|
|
ref typ,
|
2014-08-04 15:56:56 -05:00
|
|
|
ref impl_items) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(type_parameters);
|
2014-01-09 02:42:28 -06:00
|
|
|
match *trait_reference {
|
2014-02-27 01:33:03 -06:00
|
|
|
Some(ref trait_reference) => walk_trait_ref_helper(visitor,
|
2014-09-12 05:10:30 -05:00
|
|
|
trait_reference),
|
2014-01-09 02:42:28 -06:00
|
|
|
None => ()
|
2013-03-27 05:16:28 -05:00
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
visitor.visit_ty(&**typ);
|
2014-08-04 15:56:56 -05:00
|
|
|
for impl_item in impl_items.iter() {
|
|
|
|
match *impl_item {
|
2014-09-09 17:54:36 -05:00
|
|
|
MethodImplItem(ref method) => {
|
|
|
|
walk_method_helper(visitor, &**method)
|
2014-08-04 15:56:56 -05:00
|
|
|
}
|
2014-08-05 21:44:21 -05:00
|
|
|
TypeImplItem(ref typedef) => {
|
|
|
|
visitor.visit_ident(typedef.span, typedef.ident);
|
|
|
|
visitor.visit_ty(&*typedef.typ);
|
|
|
|
}
|
2014-08-04 15:56:56 -05:00
|
|
|
}
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
|
|
|
}
|
2014-05-16 02:16:13 -05:00
|
|
|
ItemStruct(ref struct_definition, ref generics) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(generics);
|
2014-05-16 02:16:13 -05:00
|
|
|
visitor.visit_struct_def(&**struct_definition,
|
2013-07-19 20:42:11 -05:00
|
|
|
item.ident,
|
|
|
|
generics,
|
2014-09-12 05:10:30 -05:00
|
|
|
item.id)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-08-27 20:46:52 -05:00
|
|
|
ItemTrait(ref generics, _, ref bounds, ref methods) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(generics);
|
|
|
|
walk_ty_param_bounds(visitor, bounds);
|
2013-08-03 11:45:23 -05:00
|
|
|
for method in methods.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_trait_item(method)
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
ItemMac(ref macro) => visitor.visit_mac(macro),
|
2014-06-08 01:02:48 -05:00
|
|
|
}
|
|
|
|
for attr in item.attrs.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_attribute(attr);
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_enum_def<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
enum_definition: &'v EnumDef,
|
|
|
|
generics: &'v Generics) {
|
|
|
|
for variant in enum_definition.variants.iter() {
|
|
|
|
visitor.visit_variant(&**variant, generics);
|
2013-11-11 22:17:47 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
variant: &'v Variant,
|
|
|
|
generics: &'v Generics) {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ident(variant.span, variant.node.name);
|
2013-11-22 06:24:49 -06:00
|
|
|
|
2013-11-11 22:17:47 -06:00
|
|
|
match variant.node.kind {
|
2014-01-09 07:05:33 -06:00
|
|
|
TupleVariantKind(ref variant_arguments) => {
|
2013-11-11 22:17:47 -06:00
|
|
|
for variant_argument in variant_arguments.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&*variant_argument.ty)
|
2012-08-08 16:17:52 -05:00
|
|
|
}
|
|
|
|
}
|
2014-05-16 02:16:13 -05:00
|
|
|
StructVariantKind(ref struct_definition) => {
|
|
|
|
visitor.visit_struct_def(&**struct_definition,
|
2013-11-11 22:17:47 -06:00
|
|
|
variant.node.name,
|
|
|
|
generics,
|
2014-09-12 05:10:30 -05:00
|
|
|
variant.node.id)
|
2013-11-11 22:17:47 -06:00
|
|
|
}
|
2012-08-08 16:17:52 -05:00
|
|
|
}
|
2013-12-16 01:13:54 -06:00
|
|
|
match variant.node.disr_expr {
|
2014-09-12 05:10:30 -05:00
|
|
|
Some(ref expr) => visitor.visit_expr(&**expr),
|
2013-12-16 01:13:54 -06:00
|
|
|
None => ()
|
|
|
|
}
|
2014-06-08 01:02:48 -05:00
|
|
|
for attr in variant.node.attrs.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_attribute(attr);
|
2014-06-08 01:02:48 -05:00
|
|
|
}
|
2012-08-08 16:17:52 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn skip_ty<'v, V: Visitor<'v>>(_: &mut V, _: &'v Ty) {
|
2013-07-19 20:42:11 -05:00
|
|
|
// Empty!
|
|
|
|
}
|
2011-11-22 03:57:47 -06:00
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match typ.node {
|
2014-09-30 16:59:56 -05:00
|
|
|
TyUniq(ref ty) | TyVec(ref ty) | TyParen(ref ty) => {
|
2014-09-09 17:54:36 -05:00
|
|
|
visitor.visit_ty(&**ty)
|
2013-12-16 12:01:40 -06:00
|
|
|
}
|
2014-01-09 07:05:33 -06:00
|
|
|
TyPtr(ref mutable_type) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&*mutable_type.ty)
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2014-01-09 07:05:33 -06:00
|
|
|
TyRptr(ref lifetime, ref mutable_type) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_opt_lifetime_ref(typ.span, lifetime);
|
|
|
|
visitor.visit_ty(&*mutable_type.ty)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-01-09 07:05:33 -06:00
|
|
|
TyTup(ref tuple_element_types) => {
|
2014-09-09 17:54:36 -05:00
|
|
|
for tuple_element_type in tuple_element_types.iter() {
|
|
|
|
visitor.visit_ty(&**tuple_element_type)
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-08-27 20:46:52 -05:00
|
|
|
TyClosure(ref function_declaration) => {
|
2013-10-28 16:37:10 -05:00
|
|
|
for argument in function_declaration.decl.inputs.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&*argument.ty)
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&*function_declaration.decl.output);
|
|
|
|
walk_ty_param_bounds(visitor, &function_declaration.bounds);
|
|
|
|
walk_lifetime_decls(visitor, &function_declaration.lifetimes);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-04-09 07:33:42 -05:00
|
|
|
TyProc(ref function_declaration) => {
|
|
|
|
for argument in function_declaration.decl.inputs.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&*argument.ty)
|
2014-04-09 07:33:42 -05:00
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&*function_declaration.decl.output);
|
|
|
|
walk_ty_param_bounds(visitor, &function_declaration.bounds);
|
|
|
|
walk_lifetime_decls(visitor, &function_declaration.lifetimes);
|
2014-04-09 07:33:42 -05:00
|
|
|
}
|
2014-01-09 07:05:33 -06:00
|
|
|
TyBareFn(ref function_declaration) => {
|
2013-08-03 11:45:23 -05:00
|
|
|
for argument in function_declaration.decl.inputs.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&*argument.ty)
|
2013-07-02 14:47:32 -05:00
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&*function_declaration.decl.output);
|
|
|
|
walk_lifetime_decls(visitor, &function_declaration.lifetimes);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-06-01 20:41:46 -05:00
|
|
|
TyUnboxedFn(ref function_declaration) => {
|
|
|
|
for argument in function_declaration.decl.inputs.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&*argument.ty)
|
2014-06-01 20:41:46 -05:00
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&*function_declaration.decl.output);
|
2014-06-01 20:41:46 -05:00
|
|
|
}
|
2014-08-27 20:46:52 -05:00
|
|
|
TyPath(ref path, ref opt_bounds, id) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_path(path, id);
|
2014-08-27 20:46:52 -05:00
|
|
|
match *opt_bounds {
|
|
|
|
Some(ref bounds) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_ty_param_bounds(visitor, bounds);
|
2014-08-27 20:46:52 -05:00
|
|
|
}
|
|
|
|
None => { }
|
2013-07-02 14:47:32 -05:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-08-05 21:44:21 -05:00
|
|
|
TyQPath(ref qpath) => {
|
|
|
|
visitor.visit_ty(&*qpath.for_type);
|
|
|
|
visitor.visit_path(&qpath.trait_name, typ.id);
|
|
|
|
visitor.visit_ident(typ.span, qpath.item_name);
|
|
|
|
}
|
2014-05-16 02:16:13 -05:00
|
|
|
TyFixedLengthVec(ref ty, ref expression) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&**ty);
|
|
|
|
visitor.visit_expr(&**expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-05-16 02:16:13 -05:00
|
|
|
TyTypeof(ref expression) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**expression)
|
2013-08-22 16:00:02 -05:00
|
|
|
}
|
2014-01-09 07:05:33 -06:00
|
|
|
TyNil | TyBot | TyInfer => {}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
fn walk_lifetime_decls<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
lifetimes: &'v Vec<LifetimeDef>) {
|
2013-10-28 16:37:10 -05:00
|
|
|
for l in lifetimes.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_lifetime_decl(l);
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
|
2013-08-07 11:47:28 -05:00
|
|
|
for segment in path.segments.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ident(path.span, segment.identifier);
|
2013-11-22 06:24:49 -06:00
|
|
|
|
2014-05-16 02:16:13 -05:00
|
|
|
for typ in segment.types.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&**typ);
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
|
|
|
for lifetime in segment.lifetimes.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_lifetime_ref(lifetime);
|
2013-08-07 11:47:28 -05:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2011-12-13 06:19:56 -06:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match pattern.node {
|
2013-09-01 20:45:37 -05:00
|
|
|
PatEnum(ref path, ref children) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_path(path, pattern.id);
|
2013-08-03 11:45:23 -05:00
|
|
|
for children in children.iter() {
|
|
|
|
for child in children.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_pat(&**child)
|
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, _) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_path(path, pattern.id);
|
2013-08-03 11:45:23 -05:00
|
|
|
for field in fields.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_pat(&*field.pat)
|
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() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_pat(&**tuple_element)
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-05-16 02:16:13 -05:00
|
|
|
PatBox(ref subpattern) |
|
|
|
|
PatRegion(ref subpattern) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_pat(&**subpattern)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-06-30 20:02:14 -05:00
|
|
|
PatIdent(_, ref pth1, ref optional_subpattern) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ident(pth1.span, pth1.node);
|
2013-07-19 20:42:11 -05:00
|
|
|
match *optional_subpattern {
|
|
|
|
None => {}
|
2014-09-12 05:10:30 -05:00
|
|
|
Some(ref subpattern) => visitor.visit_pat(&**subpattern),
|
2013-06-15 19:26:59 -05:00
|
|
|
}
|
2012-12-08 14:22:43 -06:00
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
PatLit(ref expression) => visitor.visit_expr(&**expression),
|
2014-05-16 02:16:13 -05:00
|
|
|
PatRange(ref lower_bound, ref upper_bound) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**lower_bound);
|
|
|
|
visitor.visit_expr(&**upper_bound)
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2014-08-06 10:04:44 -05:00
|
|
|
PatWild(_) => (),
|
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() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_pat(&**prepattern)
|
2013-02-26 12:58:46 -06:00
|
|
|
}
|
2013-08-03 11:45:23 -05:00
|
|
|
for slice_pattern in slice_pattern.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_pat(&**slice_pattern)
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2013-08-03 11:45:23 -05:00
|
|
|
for postpattern in postpatterns.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_pat(&**postpattern)
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2012-12-08 14:22:43 -06:00
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
PatMac(ref macro) => visitor.visit_mac(macro),
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
foreign_item: &'v ForeignItem) {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ident(foreign_item.span, foreign_item.ident);
|
2013-11-22 06:24:49 -06:00
|
|
|
|
2013-07-19 20:42:11 -05:00
|
|
|
match foreign_item.node {
|
2014-05-16 02:16:13 -05:00
|
|
|
ForeignItemFn(ref function_declaration, ref generics) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_fn_decl(visitor, &**function_declaration);
|
|
|
|
visitor.visit_generics(generics)
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
ForeignItemStatic(ref typ, _) => visitor.visit_ty(&**typ),
|
2014-06-08 01:02:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for attr in foreign_item.attrs.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_attribute(attr);
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_ty_param_bounds<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
bounds: &'v OwnedSlice<TyParamBound>) {
|
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) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_trait_ref_helper(visitor, typ)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-06-01 20:41:46 -05:00
|
|
|
UnboxedFnTyParamBound(ref function_declaration) => {
|
|
|
|
for argument in function_declaration.decl.inputs.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&*argument.ty)
|
2014-06-01 20:41:46 -05:00
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&*function_declaration.decl.output);
|
2014-09-05 14:21:02 -05:00
|
|
|
walk_lifetime_decls(visitor, &function_declaration.lifetimes);
|
2014-06-01 20:41:46 -05:00
|
|
|
}
|
2014-08-27 20:46:52 -05:00
|
|
|
RegionTyParamBound(ref lifetime) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_lifetime_ref(lifetime);
|
2014-08-27 20:46:52 -05:00
|
|
|
}
|
2013-01-10 13:16:54 -06:00
|
|
|
}
|
2012-08-06 20:54:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) {
|
2013-08-03 11:45:23 -05:00
|
|
|
for type_parameter in generics.ty_params.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_ty_param_bounds(visitor, &type_parameter.bounds);
|
2014-01-30 11:28:02 -06:00
|
|
|
match type_parameter.default {
|
2014-09-12 05:10:30 -05:00
|
|
|
Some(ref ty) => visitor.visit_ty(&**ty),
|
2014-01-30 11:28:02 -06:00
|
|
|
None => {}
|
|
|
|
}
|
2011-12-28 10:50:12 -06:00
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_lifetime_decls(visitor, &generics.lifetimes);
|
2014-08-11 11:32:26 -05:00
|
|
|
for predicate in generics.where_clause.predicates.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ident(predicate.span, predicate.ident);
|
|
|
|
walk_ty_param_bounds(visitor, &predicate.bounds);
|
2014-08-11 11:32:26 -05:00
|
|
|
}
|
2011-12-28 10:50:12 -06:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl) {
|
2013-08-03 11:45:23 -05:00
|
|
|
for argument in function_declaration.inputs.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_pat(&*argument.pat);
|
|
|
|
visitor.visit_ty(&*argument.ty)
|
2012-11-06 20:41:06 -06:00
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&*function_declaration.output)
|
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
|
2014-01-09 07:05:33 -06:00
|
|
|
// visit_fn() and check for FkMethod(). I named this visit_method_helper()
|
2012-03-01 12:36:22 -06:00
|
|
|
// because it is not a default impl of any method, though I doubt that really
|
|
|
|
// clarifies anything. - Niko
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_method_helper<'v, V: Visitor<'v>>(visitor: &mut V, method: &'v Method) {
|
2014-07-11 23:22:11 -05:00
|
|
|
match method.node {
|
2014-09-09 17:54:36 -05:00
|
|
|
MethDecl(ident, ref generics, _, _, _, ref decl, ref body, _) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ident(method.span, ident);
|
2014-09-09 17:54:36 -05:00
|
|
|
visitor.visit_fn(FkMethod(ident, generics, method),
|
|
|
|
&**decl,
|
|
|
|
&**body,
|
2014-07-11 23:22:11 -05:00
|
|
|
method.span,
|
2014-09-12 05:10:30 -05:00
|
|
|
method.id);
|
2014-07-11 23:22:11 -05:00
|
|
|
for attr in method.attrs.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_attribute(attr);
|
2014-07-11 23:22:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
2014-09-12 05:10:30 -05:00
|
|
|
MethMac(ref mac) => visitor.visit_mac(mac)
|
2014-06-08 01:02:48 -05:00
|
|
|
}
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
function_kind: FnKind<'v>,
|
|
|
|
function_declaration: &'v FnDecl,
|
|
|
|
function_body: &'v Block,
|
|
|
|
_span: Span) {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_fn_decl(visitor, function_declaration);
|
2013-10-28 16:37:10 -05:00
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
match function_kind {
|
2014-01-09 07:05:33 -06:00
|
|
|
FkItemFn(_, generics, _, _) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(generics);
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2014-01-09 07:05:33 -06:00
|
|
|
FkMethod(_, generics, method) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(generics);
|
2014-07-11 23:22:11 -05:00
|
|
|
match method.node {
|
2014-05-29 00:26:56 -05:00
|
|
|
MethDecl(_, _, _, ref explicit_self, _, _, _, _) =>
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_explicit_self(explicit_self),
|
2014-07-11 23:22:11 -05:00
|
|
|
MethMac(ref mac) =>
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_mac(mac)
|
2014-07-11 23:22:11 -05:00
|
|
|
}
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2014-01-09 07:05:33 -06:00
|
|
|
FkFnBlock(..) => {}
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
|
|
|
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_block(function_body)
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_ty_method<'v, V: Visitor<'v>>(visitor: &mut V, method_type: &'v TypeMethod) {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ident(method_type.span, method_type.ident);
|
|
|
|
visitor.visit_explicit_self(&method_type.explicit_self);
|
2013-08-03 11:45:23 -05:00
|
|
|
for argument_type in method_type.decl.inputs.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&*argument_type.ty)
|
2013-07-02 14:47:32 -05:00
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(&method_type.generics);
|
|
|
|
visitor.visit_ty(&*method_type.decl.output);
|
2014-06-08 01:02:48 -05:00
|
|
|
for attr in method_type.attrs.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_attribute(attr);
|
2014-06-08 01:02:48 -05:00
|
|
|
}
|
2012-07-11 12:28:30 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_method: &'v TraitItem) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match *trait_method {
|
2014-08-05 21:44:21 -05:00
|
|
|
RequiredMethod(ref method_type) => visitor.visit_ty_method(method_type),
|
2014-09-12 05:10:30 -05:00
|
|
|
ProvidedMethod(ref method) => walk_method_helper(visitor, &**method),
|
2014-08-05 21:44:21 -05:00
|
|
|
TypeTraitItem(ref associated_type) => {
|
|
|
|
visitor.visit_ident(associated_type.span, associated_type.ident)
|
|
|
|
}
|
2012-07-10 15:44:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
struct_definition: &'v StructDef) {
|
2014-02-24 01:17:02 -06:00
|
|
|
match struct_definition.super_struct {
|
2014-09-12 05:10:30 -05:00
|
|
|
Some(ref t) => visitor.visit_ty(&**t),
|
2014-02-24 01:17:02 -06:00
|
|
|
None => {},
|
|
|
|
}
|
2013-08-03 11:45:23 -05:00
|
|
|
for field in struct_definition.fields.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_struct_field(field)
|
2012-08-15 17:53:58 -05:00
|
|
|
}
|
2012-08-07 17:54:59 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
struct_field: &'v StructField) {
|
2013-11-22 06:24:49 -06:00
|
|
|
match struct_field.node.kind {
|
2014-01-09 07:05:33 -06:00
|
|
|
NamedField(name, _) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ident(struct_field.span, name)
|
2013-11-22 06:24:49 -06:00
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&*struct_field.node.ty);
|
2014-06-08 01:02:48 -05:00
|
|
|
|
|
|
|
for attr in struct_field.node.attrs.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_attribute(attr);
|
2014-06-08 01:02:48 -05:00
|
|
|
}
|
2012-08-15 17:53:58 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block) {
|
2013-08-03 11:45:23 -05:00
|
|
|
for view_item in block.view_items.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_view_item(view_item)
|
2012-09-19 18:55:01 -05:00
|
|
|
}
|
2013-08-03 11:45:23 -05:00
|
|
|
for statement in block.stmts.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_stmt(&**statement)
|
2012-09-19 18:55:01 -05:00
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
walk_expr_opt(visitor, &block.expr)
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match statement.node {
|
2014-09-12 05:10:30 -05:00
|
|
|
StmtDecl(ref declaration, _) => visitor.visit_decl(&**declaration),
|
2014-05-16 02:16:13 -05:00
|
|
|
StmtExpr(ref expression, _) | StmtSemi(ref expression, _) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
StmtMac(ref macro, _) => visitor.visit_mac(macro),
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_decl<'v, V: Visitor<'v>>(visitor: &mut V, declaration: &'v Decl) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match declaration.node {
|
2014-09-12 05:10:30 -05:00
|
|
|
DeclLocal(ref local) => visitor.visit_local(&**local),
|
|
|
|
DeclItem(ref item) => visitor.visit_item(&**item),
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_expr_opt<'v, V: Visitor<'v>>(visitor: &mut V,
|
2014-09-13 11:06:01 -05:00
|
|
|
optional_expression: &'v Option<P<Expr>>) {
|
2014-09-09 17:54:36 -05:00
|
|
|
match *optional_expression {
|
2013-07-19 20:42:11 -05:00
|
|
|
None => {}
|
2014-09-12 05:10:30 -05:00
|
|
|
Some(ref expression) => visitor.visit_expr(&**expression),
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2014-09-13 11:06:01 -05:00
|
|
|
pub fn walk_exprs<'v, V: Visitor<'v>>(visitor: &mut V, expressions: &'v [P<Expr>]) {
|
2013-08-03 11:45:23 -05:00
|
|
|
for expression in expressions.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_mac<'v, V: Visitor<'v>>(_: &mut V, _: &'v Mac) {
|
2013-07-19 20:42:11 -05:00
|
|
|
// Empty!
|
2011-07-08 18:35:09 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match expression.node {
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprBox(ref place, ref subexpression) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**place);
|
|
|
|
visitor.visit_expr(&**subexpression)
|
2013-12-17 18:46:18 -06:00
|
|
|
}
|
2014-04-04 05:12:18 -05:00
|
|
|
ExprVec(ref subexpressions) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_exprs(visitor, subexpressions.as_slice())
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprRepeat(ref element, ref count) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**element);
|
|
|
|
visitor.visit_expr(&**count)
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
ExprStruct(ref path, ref fields, ref optional_base) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_path(path, expression.id);
|
2013-08-03 11:45:23 -05:00
|
|
|
for field in fields.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&*field.expr)
|
2013-06-15 19:26:59 -05:00
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_expr_opt(visitor, optional_base)
|
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() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**subexpression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprCall(ref callee_expression, ref arguments) => {
|
2013-08-03 11:45:23 -05:00
|
|
|
for argument in arguments.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**argument)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**callee_expression)
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2014-02-26 08:06:45 -06:00
|
|
|
ExprMethodCall(_, ref types, ref arguments) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_exprs(visitor, arguments.as_slice());
|
2014-05-16 02:16:13 -05:00
|
|
|
for typ in types.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&**typ)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
|
|
|
}
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprBinary(_, ref left_expression, ref right_expression) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**left_expression);
|
|
|
|
visitor.visit_expr(&**right_expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprAddrOf(_, ref subexpression) | ExprUnary(_, ref subexpression) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**subexpression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprLit(_) => {}
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprCast(ref subexpression, ref typ) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**subexpression);
|
|
|
|
visitor.visit_ty(&**typ)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
ExprIf(ref head_expression, ref if_block, ref optional_else) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**head_expression);
|
|
|
|
visitor.visit_block(&**if_block);
|
|
|
|
walk_expr_opt(visitor, optional_else)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-07-25 19:12:51 -05:00
|
|
|
ExprWhile(ref subexpression, ref block, _) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**subexpression);
|
|
|
|
visitor.visit_block(&**block)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-08-24 20:04:29 -05:00
|
|
|
ExprIfLet(ref pattern, ref subexpression, ref if_block, ref optional_else) => {
|
|
|
|
visitor.visit_pat(&**pattern);
|
|
|
|
visitor.visit_expr(&**subexpression);
|
|
|
|
visitor.visit_block(&**if_block);
|
|
|
|
walk_expr_opt(visitor, optional_else);
|
|
|
|
}
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprForLoop(ref pattern, ref subexpression, ref block, _) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_pat(&**pattern);
|
|
|
|
visitor.visit_expr(&**subexpression);
|
|
|
|
visitor.visit_block(&**block)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
ExprLoop(ref block, _) => visitor.visit_block(&**block),
|
2014-08-24 20:04:29 -05:00
|
|
|
ExprMatch(ref subexpression, ref arms, _) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**subexpression);
|
2013-08-03 11:45:23 -05:00
|
|
|
for arm in arms.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_arm(arm)
|
2013-06-15 19:26:59 -05:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-07-23 14:43:29 -05:00
|
|
|
ExprFnBlock(_, ref function_declaration, ref body) => {
|
2014-09-09 17:54:36 -05:00
|
|
|
visitor.visit_fn(FkFnBlock,
|
2014-05-16 02:16:13 -05:00
|
|
|
&**function_declaration,
|
|
|
|
&**body,
|
2013-10-28 17:22:49 -05:00
|
|
|
expression.span,
|
2014-09-12 05:10:30 -05:00
|
|
|
expression.id)
|
2013-10-28 17:22:49 -05:00
|
|
|
}
|
2014-07-30 00:08:39 -05:00
|
|
|
ExprUnboxedFn(_, _, ref function_declaration, ref body) => {
|
2014-09-09 17:54:36 -05:00
|
|
|
visitor.visit_fn(FkFnBlock,
|
2014-05-29 00:26:56 -05:00
|
|
|
&**function_declaration,
|
|
|
|
&**body,
|
|
|
|
expression.span,
|
2014-09-12 05:10:30 -05:00
|
|
|
expression.id)
|
2014-05-29 00:26:56 -05:00
|
|
|
}
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprProc(ref function_declaration, ref body) => {
|
2014-09-09 17:54:36 -05:00
|
|
|
visitor.visit_fn(FkFnBlock,
|
2014-05-16 02:16:13 -05:00
|
|
|
&**function_declaration,
|
|
|
|
&**body,
|
2013-07-19 20:42:11 -05:00
|
|
|
expression.span,
|
2014-09-12 05:10:30 -05:00
|
|
|
expression.id)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
ExprBlock(ref block) => visitor.visit_block(&**block),
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprAssign(ref left_hand_expression, ref right_hand_expression) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**right_hand_expression);
|
|
|
|
visitor.visit_expr(&**left_hand_expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprAssignOp(_, ref left_expression, ref right_expression) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**right_expression);
|
|
|
|
visitor.visit_expr(&**left_expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprField(ref subexpression, _, ref types) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**subexpression);
|
2014-05-16 02:16:13 -05:00
|
|
|
for typ in types.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&**typ)
|
2013-06-15 19:26:59 -05:00
|
|
|
}
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2014-08-09 22:54:33 -05:00
|
|
|
ExprTupField(ref subexpression, _, ref types) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**subexpression);
|
2014-08-09 22:54:33 -05:00
|
|
|
for typ in types.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ty(&**typ)
|
2014-08-09 22:54:33 -05:00
|
|
|
}
|
|
|
|
}
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprIndex(ref main_expression, ref index_expression) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**main_expression);
|
|
|
|
visitor.visit_expr(&**index_expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-09-15 03:48:58 -05:00
|
|
|
ExprSlice(ref main_expression, ref start, ref end, _) => {
|
|
|
|
visitor.visit_expr(&**main_expression);
|
|
|
|
walk_expr_opt(visitor, start);
|
|
|
|
walk_expr_opt(visitor, end)
|
|
|
|
}
|
2013-12-08 13:25:35 -06:00
|
|
|
ExprPath(ref path) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_path(path, expression.id)
|
2013-12-08 13:25:35 -06:00
|
|
|
}
|
2014-01-27 06:18:36 -06:00
|
|
|
ExprBreak(_) | ExprAgain(_) => {}
|
2014-09-09 17:54:36 -05:00
|
|
|
ExprRet(ref optional_expression) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_expr_opt(visitor, optional_expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
ExprMac(ref macro) => visitor.visit_mac(macro),
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprParen(ref subexpression) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**subexpression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-08-19 14:39:26 -05:00
|
|
|
ExprInlineAsm(ref ia) => {
|
2014-09-09 17:54:36 -05:00
|
|
|
for input in ia.inputs.iter() {
|
|
|
|
let (_, ref input) = *input;
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**input)
|
2013-03-12 19:53:25 -05:00
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
for output in ia.outputs.iter() {
|
|
|
|
let (_, ref output, _) = *output;
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&**output)
|
2013-03-12 19:53:25 -05:00
|
|
|
}
|
|
|
|
}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr_post(expression)
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) {
|
2013-08-03 11:45:23 -05:00
|
|
|
for pattern in arm.pats.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_pat(&**pattern)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
walk_expr_opt(visitor, &arm.guard);
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr(&*arm.body);
|
2014-06-08 01:02:48 -05:00
|
|
|
for attr in arm.attrs.iter() {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_attribute(attr);
|
2014-06-08 01:02:48 -05:00
|
|
|
}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|