2015-09-28 06:26:26 -05:00
|
|
|
// Copyright 2012-2015 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::*;
|
2016-06-21 17:08:13 -05:00
|
|
|
use syntax_pos::Span;
|
|
|
|
use codemap::Spanned;
|
2012-12-23 16:41:37 -06:00
|
|
|
|
2015-08-16 07:44:37 -05:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
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()
|
2016-03-23 05:17:34 -05:00
|
|
|
ItemFn(Ident, &'a Generics, Unsafety, Constness, Abi, &'a Visibility),
|
2013-03-13 21:25:28 -05:00
|
|
|
|
2014-06-09 15:12:30 -05:00
|
|
|
/// fn foo(&self)
|
2016-03-23 05:17:34 -05:00
|
|
|
Method(Ident, &'a MethodSig, Option<&'a Visibility>),
|
2013-03-13 21:25:28 -05:00
|
|
|
|
2015-08-16 07:53:58 -05:00
|
|
|
/// |x, y| {}
|
2015-08-26 05:00:14 -05:00
|
|
|
Closure,
|
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.)
|
2016-06-12 02:51:31 -05:00
|
|
|
pub trait Visitor: Sized {
|
2014-11-18 10:39:16 -06:00
|
|
|
fn visit_name(&mut self, _span: Span, _name: Name) {
|
|
|
|
// Nothing to do.
|
|
|
|
}
|
|
|
|
fn visit_ident(&mut self, span: Span, ident: Ident) {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_ident(self, span, ident);
|
2013-11-22 06:24:49 -06:00
|
|
|
}
|
2016-06-12 02:51:31 -05:00
|
|
|
fn visit_mod(&mut self, m: &Mod, _s: Span, _n: NodeId) { walk_mod(self, m) }
|
|
|
|
fn visit_foreign_item(&mut self, i: &ForeignItem) { walk_foreign_item(self, i) }
|
|
|
|
fn visit_item(&mut self, i: &Item) { walk_item(self, i) }
|
|
|
|
fn visit_local(&mut self, l: &Local) { walk_local(self, l) }
|
|
|
|
fn visit_block(&mut self, b: &Block) { walk_block(self, b) }
|
|
|
|
fn visit_stmt(&mut self, s: &Stmt) { walk_stmt(self, s) }
|
|
|
|
fn visit_arm(&mut self, a: &Arm) { walk_arm(self, a) }
|
|
|
|
fn visit_pat(&mut self, p: &Pat) { walk_pat(self, p) }
|
|
|
|
fn visit_expr(&mut self, ex: &Expr) { walk_expr(self, ex) }
|
|
|
|
fn visit_expr_post(&mut self, _ex: &Expr) { }
|
|
|
|
fn visit_ty(&mut self, t: &Ty) { walk_ty(self, t) }
|
|
|
|
fn visit_generics(&mut self, g: &Generics) { walk_generics(self, g) }
|
|
|
|
fn visit_fn(&mut self, fk: FnKind, fd: &FnDecl, b: &Block, s: Span, _: NodeId) {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_fn(self, fk, fd, b, s)
|
|
|
|
}
|
2016-06-12 02:51:31 -05:00
|
|
|
fn visit_trait_item(&mut self, ti: &TraitItem) { walk_trait_item(self, ti) }
|
|
|
|
fn visit_impl_item(&mut self, ii: &ImplItem) { walk_impl_item(self, ii) }
|
|
|
|
fn visit_trait_ref(&mut self, t: &TraitRef) { walk_trait_ref(self, t) }
|
|
|
|
fn visit_ty_param_bound(&mut self, bounds: &TyParamBound) {
|
2014-11-15 15:55:27 -06:00
|
|
|
walk_ty_param_bound(self, bounds)
|
|
|
|
}
|
2016-06-12 02:51:31 -05:00
|
|
|
fn visit_poly_trait_ref(&mut self, t: &PolyTraitRef, m: &TraitBoundModifier) {
|
2014-12-24 00:38:10 -06:00
|
|
|
walk_poly_trait_ref(self, t, m)
|
2014-11-07 05:53:45 -06:00
|
|
|
}
|
2016-06-12 02:51:31 -05:00
|
|
|
fn visit_variant_data(&mut self, s: &VariantData, _: Ident,
|
|
|
|
_: &Generics, _: NodeId, _: Span) {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_struct_def(self, s)
|
|
|
|
}
|
2016-06-12 02:51:31 -05:00
|
|
|
fn visit_struct_field(&mut self, s: &StructField) { walk_struct_field(self, s) }
|
|
|
|
fn visit_enum_def(&mut self, enum_definition: &EnumDef,
|
|
|
|
generics: &Generics, item_id: NodeId, _: Span) {
|
2015-10-02 08:14:20 -05:00
|
|
|
walk_enum_def(self, enum_definition, generics, item_id)
|
|
|
|
}
|
2016-06-12 02:51:31 -05:00
|
|
|
fn visit_variant(&mut self, v: &Variant, g: &Generics, item_id: NodeId) {
|
2015-10-02 08:14:20 -05:00
|
|
|
walk_variant(self, v, g, item_id)
|
2015-06-22 21:55:57 -05:00
|
|
|
}
|
2016-06-12 02:51:31 -05:00
|
|
|
fn visit_lifetime(&mut self, lifetime: &Lifetime) {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_lifetime(self, lifetime)
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2016-06-12 02:51:31 -05:00
|
|
|
fn visit_lifetime_def(&mut self, lifetime: &LifetimeDef) {
|
2014-11-18 10:39:16 -06:00
|
|
|
walk_lifetime_def(self, lifetime)
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2016-06-12 02:51:31 -05:00
|
|
|
fn visit_mac(&mut self, _mac: &Mac) {
|
2014-10-09 14:17:22 -05:00
|
|
|
panic!("visit_mac disabled by default");
|
2014-07-09 16:48:12 -05:00
|
|
|
// NB: see note about macros above.
|
|
|
|
// if you really want a visitor that
|
|
|
|
// works on macros, use this
|
|
|
|
// definition in your trait impl:
|
2015-01-02 15:39:05 -06:00
|
|
|
// visit::walk_mac(self, _mac)
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2016-06-12 02:51:31 -05:00
|
|
|
fn visit_path(&mut self, path: &Path, _id: NodeId) {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_path(self, path)
|
2013-12-08 13:25:35 -06:00
|
|
|
}
|
2016-06-12 02:51:31 -05:00
|
|
|
fn visit_path_list_item(&mut self, prefix: &Path, item: &PathListItem) {
|
2015-09-12 08:10:12 -05:00
|
|
|
walk_path_list_item(self, prefix, item)
|
|
|
|
}
|
2016-06-12 02:51:31 -05:00
|
|
|
fn visit_path_segment(&mut self, path_span: Span, path_segment: &PathSegment) {
|
2014-11-15 15:55:27 -06:00
|
|
|
walk_path_segment(self, path_span, path_segment)
|
|
|
|
}
|
2016-06-12 02:51:31 -05:00
|
|
|
fn visit_path_parameters(&mut self, path_span: Span, path_parameters: &PathParameters) {
|
2014-11-15 15:55:27 -06:00
|
|
|
walk_path_parameters(self, path_span, path_parameters)
|
|
|
|
}
|
2016-06-12 02:51:31 -05:00
|
|
|
fn visit_assoc_type_binding(&mut self, type_binding: &TypeBinding) {
|
2014-12-28 09:07:21 -06:00
|
|
|
walk_assoc_type_binding(self, type_binding)
|
|
|
|
}
|
2016-06-12 02:51:31 -05:00
|
|
|
fn visit_attribute(&mut self, _attr: &Attribute) {}
|
|
|
|
fn visit_macro_def(&mut self, macro_def: &MacroDef) {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_macro_def(self, macro_def)
|
|
|
|
}
|
2016-06-12 02:51:31 -05:00
|
|
|
fn visit_vis(&mut self, vis: &Visibility) {
|
2016-03-31 14:10:38 -05:00
|
|
|
walk_vis(self, vis)
|
|
|
|
}
|
2013-08-08 07:23:25 -05:00
|
|
|
}
|
|
|
|
|
2015-09-28 06:26:26 -05:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! walk_list {
|
2015-09-28 16:23:54 -05:00
|
|
|
($visitor: expr, $method: ident, $list: expr) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
for elem in $list {
|
|
|
|
$visitor.$method(elem)
|
|
|
|
}
|
2015-10-16 09:17:14 -05:00
|
|
|
};
|
|
|
|
($visitor: expr, $method: ident, $list: expr, $($extra_args: expr),*) => {
|
|
|
|
for elem in $list {
|
|
|
|
$visitor.$method(elem, $($extra_args,)*)
|
|
|
|
}
|
2014-06-08 01:02:48 -05:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_opt_name<V: Visitor>(visitor: &mut V, span: Span, opt_name: Option<Name>) {
|
2016-05-02 11:22:03 -05:00
|
|
|
if let Some(name) = opt_name {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_name(span, name);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_opt_ident<V: Visitor>(visitor: &mut V, span: Span, opt_ident: Option<Ident>) {
|
2016-05-02 11:22:03 -05:00
|
|
|
if let Some(ident) = opt_ident {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ident(span, ident);
|
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_opt_sp_ident<V: Visitor>(visitor: &mut V, opt_sp_ident: &Option<Spanned<Ident>>) {
|
2016-05-02 11:22:03 -05:00
|
|
|
if let Some(ref sp_ident) = *opt_sp_ident {
|
|
|
|
visitor.visit_ident(sp_ident.span, sp_ident.node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_ident<V: Visitor>(visitor: &mut V, span: Span, ident: Ident) {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_name(span, ident.name);
|
2014-11-18 10:39:16 -06:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_crate<V: Visitor>(visitor: &mut V, krate: &Crate) {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID);
|
|
|
|
walk_list!(visitor, visit_attribute, &krate.attrs);
|
|
|
|
walk_list!(visitor, visit_macro_def, &krate.exported_macros);
|
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_macro_def<V: Visitor>(visitor: &mut V, macro_def: &MacroDef) {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ident(macro_def.span, macro_def.ident);
|
|
|
|
walk_opt_ident(visitor, macro_def.span, macro_def.imported_from);
|
|
|
|
walk_list!(visitor, visit_attribute, ¯o_def.attrs);
|
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_mod<V: Visitor>(visitor: &mut V, module: &Mod) {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_item, &module.items);
|
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_local<V: Visitor>(visitor: &mut V, local: &Local) {
|
2016-06-17 23:01:57 -05:00
|
|
|
for attr in local.attrs.iter() {
|
2016-06-10 05:31:45 -05:00
|
|
|
visitor.visit_attribute(attr);
|
|
|
|
}
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_pat(&local.pat);
|
|
|
|
walk_list!(visitor, visit_ty, &local.ty);
|
|
|
|
walk_list!(visitor, visit_expr, &local.init);
|
2014-12-13 04:34:34 -06:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_lifetime<V: Visitor>(visitor: &mut V, lifetime: &Lifetime) {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_name(lifetime.span, lifetime.name);
|
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_lifetime_def<V: Visitor>(visitor: &mut V, lifetime_def: &LifetimeDef) {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_lifetime(&lifetime_def.lifetime);
|
|
|
|
walk_list!(visitor, visit_lifetime, &lifetime_def.bounds);
|
2014-12-13 04:34:34 -06:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_poly_trait_ref<V>(visitor: &mut V, trait_ref: &PolyTraitRef, _: &TraitBoundModifier)
|
|
|
|
where V: Visitor,
|
2014-11-07 05:53:45 -06:00
|
|
|
{
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_lifetime_def, &trait_ref.bound_lifetimes);
|
2014-11-07 05:53:45 -06:00
|
|
|
visitor.visit_trait_ref(&trait_ref.trait_ref);
|
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_trait_ref<V: Visitor>(visitor: &mut V, trait_ref: &TraitRef) {
|
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
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_item<V: Visitor>(visitor: &mut V, item: &Item) {
|
2016-04-10 18:10:46 -05:00
|
|
|
visitor.visit_vis(&item.vis);
|
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 {
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::ExternCrate(opt_name) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_opt_name(visitor, item.span, opt_name)
|
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Use(ref vp) => {
|
2015-01-13 09:30:17 -06:00
|
|
|
match vp.node {
|
2015-09-28 06:26:26 -05:00
|
|
|
ViewPathSimple(ident, ref path) => {
|
|
|
|
visitor.visit_ident(vp.span, ident);
|
2015-01-13 09:30:17 -06:00
|
|
|
visitor.visit_path(path, item.id);
|
|
|
|
}
|
|
|
|
ViewPathGlob(ref path) => {
|
|
|
|
visitor.visit_path(path, item.id);
|
|
|
|
}
|
|
|
|
ViewPathList(ref prefix, ref list) => {
|
2016-03-06 06:54:44 -06:00
|
|
|
visitor.visit_path(prefix, item.id);
|
|
|
|
for item in list {
|
|
|
|
visitor.visit_path_list_item(prefix, item)
|
2015-01-13 09:30:17 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Static(ref typ, _, ref expr) |
|
|
|
|
ItemKind::Const(ref typ, ref expr) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(typ);
|
|
|
|
visitor.visit_expr(expr);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Fn(ref declaration, unsafety, constness, abi, ref generics, ref body) => {
|
2015-08-26 05:00:14 -05:00
|
|
|
visitor.visit_fn(FnKind::ItemFn(item.ident, generics, unsafety,
|
2016-03-23 05:17:34 -05:00
|
|
|
constness, abi, &item.vis),
|
2015-09-28 06:26:26 -05:00
|
|
|
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
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Mod(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
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::ForeignMod(ref foreign_module) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_foreign_item, &foreign_module.items);
|
2011-12-20 09:33:55 -06:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Ty(ref typ, ref type_parameters) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(typ);
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(type_parameters)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Enum(ref enum_definition, ref type_parameters) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(type_parameters);
|
2015-10-16 09:17:14 -05:00
|
|
|
visitor.visit_enum_def(enum_definition, type_parameters, item.id, item.span)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::DefaultImpl(_, ref trait_ref) => {
|
2015-01-22 15:14:52 -06:00
|
|
|
visitor.visit_trait_ref(trait_ref)
|
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Impl(_, _,
|
2014-12-10 05:15:06 -06:00
|
|
|
ref type_parameters,
|
2015-09-28 06:26:26 -05:00
|
|
|
ref opt_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);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_trait_ref, opt_trait_reference);
|
|
|
|
visitor.visit_ty(typ);
|
|
|
|
walk_list!(visitor, visit_impl_item, impl_items);
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Struct(ref struct_definition, ref generics) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(generics);
|
2015-10-07 19:20:57 -05:00
|
|
|
visitor.visit_variant_data(struct_definition, item.ident,
|
2015-10-02 12:06:59 -05:00
|
|
|
generics, item.id, item.span);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Trait(_, ref generics, ref bounds, ref methods) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(generics);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_ty_param_bound, bounds);
|
|
|
|
walk_list!(visitor, visit_trait_item, methods);
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Mac(ref mac) => visitor.visit_mac(mac),
|
2014-06-08 01:02:48 -05:00
|
|
|
}
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_attribute, &item.attrs);
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_enum_def<V: Visitor>(visitor: &mut V,
|
|
|
|
enum_definition: &EnumDef,
|
|
|
|
generics: &Generics,
|
|
|
|
item_id: NodeId) {
|
2015-10-16 09:17:14 -05:00
|
|
|
walk_list!(visitor, visit_variant, &enum_definition.variants, generics, item_id);
|
2013-11-11 22:17:47 -06:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_variant<V>(visitor: &mut V, variant: &Variant, generics: &Generics, item_id: NodeId)
|
|
|
|
where V: Visitor,
|
|
|
|
{
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ident(variant.span, variant.node.name);
|
2015-10-07 19:20:57 -05:00
|
|
|
visitor.visit_variant_data(&variant.node.data, variant.node.name,
|
2015-10-02 12:06:59 -05:00
|
|
|
generics, item_id, variant.span);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_expr, &variant.node.disr_expr);
|
|
|
|
walk_list!(visitor, visit_attribute, &variant.node.attrs);
|
2015-01-02 05:55:31 -06:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_ty<V: Visitor>(visitor: &mut V, typ: &Ty) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match typ.node {
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::Vec(ref ty) | TyKind::Paren(ref ty) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(ty)
|
2013-12-16 12:01:40 -06:00
|
|
|
}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::Ptr(ref mutable_type) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(&mutable_type.ty)
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::Rptr(ref opt_lifetime, ref mutable_type) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_lifetime, opt_lifetime);
|
|
|
|
visitor.visit_ty(&mutable_type.ty)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-05-09 11:03:59 -05:00
|
|
|
TyKind::Empty => {},
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::Tup(ref tuple_element_types) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_ty, tuple_element_types);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::BareFn(ref function_declaration) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_fn_decl(visitor, &function_declaration.decl);
|
|
|
|
walk_list!(visitor, visit_lifetime_def, &function_declaration.lifetimes);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::Path(ref maybe_qself, ref path) => {
|
2015-09-29 03:33:25 -05:00
|
|
|
if let Some(ref qself) = *maybe_qself {
|
2015-02-17 11:29:13 -06:00
|
|
|
visitor.visit_ty(&qself.ty);
|
|
|
|
}
|
2015-01-29 13:18:17 -06:00
|
|
|
visitor.visit_path(path, typ.id);
|
2014-11-20 14:08:48 -06:00
|
|
|
}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::ObjectSum(ref ty, ref bounds) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(ty);
|
|
|
|
walk_list!(visitor, visit_ty_param_bound, bounds);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::FixedLengthVec(ref ty, ref expression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(ty);
|
|
|
|
visitor.visit_expr(expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::PolyTraitRef(ref bounds) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_ty_param_bound, bounds);
|
2014-11-07 05:53:45 -06:00
|
|
|
}
|
2016-07-31 20:25:32 -05:00
|
|
|
TyKind::ImplTrait(ref bounds) => {
|
|
|
|
walk_list!(visitor, visit_ty_param_bound, bounds);
|
|
|
|
}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::Typeof(ref expression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(expression)
|
2013-08-22 16:00:02 -05:00
|
|
|
}
|
2016-03-06 06:54:44 -06:00
|
|
|
TyKind::Infer | TyKind::ImplicitSelf => {}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::Mac(ref mac) => {
|
2015-07-25 23:30:35 -05:00
|
|
|
visitor.visit_mac(mac)
|
|
|
|
}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_path<V: Visitor>(visitor: &mut V, path: &Path) {
|
2015-01-31 11:20:46 -06:00
|
|
|
for segment in &path.segments {
|
2014-11-15 15:55:27 -06:00
|
|
|
visitor.visit_path_segment(path.span, segment);
|
|
|
|
}
|
|
|
|
}
|
2013-11-22 06:24:49 -06:00
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_path_list_item<V: Visitor>(visitor: &mut V, _prefix: &Path, item: &PathListItem) {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_opt_ident(visitor, item.span, item.node.name());
|
|
|
|
walk_opt_ident(visitor, item.span, item.node.rename());
|
2015-09-12 08:10:12 -05:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_path_segment<V: Visitor>(visitor: &mut V, path_span: Span, segment: &PathSegment) {
|
2014-11-15 15:55:27 -06:00
|
|
|
visitor.visit_ident(path_span, segment.identifier);
|
|
|
|
visitor.visit_path_parameters(path_span, &segment.parameters);
|
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_path_parameters<V>(visitor: &mut V, _path_span: Span, path_parameters: &PathParameters)
|
|
|
|
where V: Visitor,
|
|
|
|
{
|
2014-11-15 15:55:27 -06:00
|
|
|
match *path_parameters {
|
2015-12-22 09:56:13 -06:00
|
|
|
PathParameters::AngleBracketed(ref data) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_ty, &data.types);
|
|
|
|
walk_list!(visitor, visit_lifetime, &data.lifetimes);
|
|
|
|
walk_list!(visitor, visit_assoc_type_binding, &data.bindings);
|
2014-11-15 15:55:27 -06:00
|
|
|
}
|
2015-12-22 09:56:13 -06:00
|
|
|
PathParameters::Parenthesized(ref data) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_ty, &data.inputs);
|
|
|
|
walk_list!(visitor, visit_ty, &data.output);
|
2013-08-07 11:47:28 -05:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2011-12-13 06:19:56 -06:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_assoc_type_binding<V: Visitor>(visitor: &mut V, type_binding: &TypeBinding) {
|
2014-12-28 09:07:21 -06:00
|
|
|
visitor.visit_ident(type_binding.span, type_binding.ident);
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(&type_binding.ty);
|
2014-12-28 09:07:21 -06:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_pat<V: Visitor>(visitor: &mut V, pattern: &Pat) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match pattern.node {
|
2016-03-06 06:54:44 -06:00
|
|
|
PatKind::TupleStruct(ref path, ref children, _) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_path(path, pattern.id);
|
2016-03-06 06:54:44 -06:00
|
|
|
walk_list!(visitor, visit_pat, children);
|
2012-08-06 19:01:14 -05:00
|
|
|
}
|
2016-06-11 10:47:47 -05:00
|
|
|
PatKind::Path(ref opt_qself, ref path) => {
|
|
|
|
if let Some(ref qself) = *opt_qself {
|
|
|
|
visitor.visit_ty(&qself.ty);
|
|
|
|
}
|
2015-03-25 11:53:28 -05:00
|
|
|
visitor.visit_path(path, pattern.id)
|
|
|
|
}
|
2016-02-11 12:16:33 -06:00
|
|
|
PatKind::Struct(ref path, ref fields, _) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_path(path, pattern.id);
|
2015-01-31 11:20:46 -06:00
|
|
|
for field in fields {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ident(field.span, field.node.ident);
|
|
|
|
visitor.visit_pat(&field.node.pat)
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
2016-03-06 06:54:44 -06:00
|
|
|
PatKind::Tuple(ref tuple_elements, _) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_pat, tuple_elements);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-11 12:16:33 -06:00
|
|
|
PatKind::Box(ref subpattern) |
|
|
|
|
PatKind::Ref(ref subpattern, _) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_pat(subpattern)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-11 12:16:33 -06:00
|
|
|
PatKind::Ident(_, ref pth1, ref optional_subpattern) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ident(pth1.span, pth1.node);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_pat, optional_subpattern);
|
2012-12-08 14:22:43 -06:00
|
|
|
}
|
2016-02-11 12:16:33 -06:00
|
|
|
PatKind::Lit(ref expression) => visitor.visit_expr(expression),
|
|
|
|
PatKind::Range(ref lower_bound, ref upper_bound) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(lower_bound);
|
|
|
|
visitor.visit_expr(upper_bound)
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2016-02-11 12:16:33 -06:00
|
|
|
PatKind::Wild => (),
|
|
|
|
PatKind::Vec(ref prepatterns, ref slice_pattern, ref postpatterns) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_pat, prepatterns);
|
|
|
|
walk_list!(visitor, visit_pat, slice_pattern);
|
|
|
|
walk_list!(visitor, visit_pat, postpatterns);
|
2012-12-08 14:22:43 -06:00
|
|
|
}
|
2016-02-11 12:16:33 -06:00
|
|
|
PatKind::Mac(ref mac) => visitor.visit_mac(mac),
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_foreign_item<V: Visitor>(visitor: &mut V, foreign_item: &ForeignItem) {
|
2016-04-10 18:10:46 -05:00
|
|
|
visitor.visit_vis(&foreign_item.vis);
|
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 {
|
2016-02-09 04:31:19 -06:00
|
|
|
ForeignItemKind::Fn(ref function_declaration, ref generics) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_fn_decl(visitor, function_declaration);
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(generics)
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
2016-02-09 04:31:19 -06:00
|
|
|
ForeignItemKind::Static(ref typ, _) => visitor.visit_ty(typ),
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_attribute, &foreign_item.attrs);
|
2014-11-15 15:55:27 -06:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_ty_param_bound<V: Visitor>(visitor: &mut V, bound: &TyParamBound) {
|
2014-11-15 15:55:27 -06:00
|
|
|
match *bound {
|
2014-12-24 00:38:10 -06:00
|
|
|
TraitTyParamBound(ref typ, ref modifier) => {
|
|
|
|
visitor.visit_poly_trait_ref(typ, modifier);
|
2014-11-15 15:55:27 -06:00
|
|
|
}
|
|
|
|
RegionTyParamBound(ref lifetime) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_lifetime(lifetime);
|
2013-01-10 13:16:54 -06:00
|
|
|
}
|
2012-08-06 20:54:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_generics<V: Visitor>(visitor: &mut V, generics: &Generics) {
|
2015-09-28 06:26:26 -05:00
|
|
|
for param in &generics.ty_params {
|
2015-03-10 05:28:44 -05:00
|
|
|
visitor.visit_ident(param.span, param.ident);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_ty_param_bound, ¶m.bounds);
|
|
|
|
walk_list!(visitor, visit_ty, ¶m.default);
|
2011-12-28 10:50:12 -06:00
|
|
|
}
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_lifetime_def, &generics.lifetimes);
|
2015-01-31 11:20:46 -06:00
|
|
|
for predicate in &generics.where_clause.predicates {
|
2015-11-17 08:24:49 -06:00
|
|
|
match *predicate {
|
|
|
|
WherePredicate::BoundPredicate(WhereBoundPredicate{ref bounded_ty,
|
|
|
|
ref bounds,
|
|
|
|
ref bound_lifetimes,
|
|
|
|
..}) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(bounded_ty);
|
|
|
|
walk_list!(visitor, visit_ty_param_bound, bounds);
|
|
|
|
walk_list!(visitor, visit_lifetime_def, bound_lifetimes);
|
2014-11-28 22:08:30 -06:00
|
|
|
}
|
2015-11-17 08:24:49 -06:00
|
|
|
WherePredicate::RegionPredicate(WhereRegionPredicate{ref lifetime,
|
|
|
|
ref bounds,
|
|
|
|
..}) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_lifetime(lifetime);
|
|
|
|
walk_list!(visitor, visit_lifetime, bounds);
|
2014-12-20 04:29:19 -06:00
|
|
|
}
|
2015-11-17 08:24:49 -06:00
|
|
|
WherePredicate::EqPredicate(WhereEqPredicate{id,
|
|
|
|
ref path,
|
|
|
|
ref ty,
|
|
|
|
..}) => {
|
2014-11-28 22:08:30 -06:00
|
|
|
visitor.visit_path(path, id);
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(ty);
|
2014-11-28 22:08:30 -06:00
|
|
|
}
|
|
|
|
}
|
2014-08-11 11:32:26 -05:00
|
|
|
}
|
2011-12-28 10:50:12 -06:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_fn_ret_ty<V: Visitor>(visitor: &mut V, ret_ty: &FunctionRetTy) {
|
2016-02-08 08:04:11 -06:00
|
|
|
if let FunctionRetTy::Ty(ref output_ty) = *ret_ty {
|
2015-09-28 16:23:54 -05:00
|
|
|
visitor.visit_ty(output_ty)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_fn_decl<V: Visitor>(visitor: &mut V, function_declaration: &FnDecl) {
|
2015-01-31 11:20:46 -06:00
|
|
|
for argument in &function_declaration.inputs {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_pat(&argument.pat);
|
|
|
|
visitor.visit_ty(&argument.ty)
|
|
|
|
}
|
2015-09-28 16:23:54 -05:00
|
|
|
walk_fn_ret_ty(visitor, &function_declaration.output)
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_fn_kind<V: Visitor>(visitor: &mut V, function_kind: FnKind) {
|
2014-09-09 17:54:36 -05:00
|
|
|
match function_kind {
|
2015-08-26 05:00:14 -05:00
|
|
|
FnKind::ItemFn(_, generics, _, _, _, _) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(generics);
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2016-03-23 05:17:34 -05:00
|
|
|
FnKind::Method(_, ref sig, _) => {
|
2015-03-11 16:38:58 -05:00
|
|
|
visitor.visit_generics(&sig.generics);
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2015-09-28 06:26:26 -05:00
|
|
|
FnKind::Closure => {}
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2015-09-28 16:23:54 -05:00
|
|
|
}
|
2013-10-28 16:37:10 -05:00
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_fn<V>(visitor: &mut V, kind: FnKind, declaration: &FnDecl, body: &Block, _span: Span)
|
|
|
|
where V: Visitor,
|
|
|
|
{
|
|
|
|
walk_fn_decl(visitor, declaration);
|
|
|
|
walk_fn_kind(visitor, kind);
|
|
|
|
visitor.visit_block(body)
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_trait_item<V: Visitor>(visitor: &mut V, trait_item: &TraitItem) {
|
2015-03-10 05:28:44 -05:00
|
|
|
visitor.visit_ident(trait_item.span, trait_item.ident);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_attribute, &trait_item.attrs);
|
2015-03-10 05:28:44 -05:00
|
|
|
match trait_item.node {
|
2016-02-09 10:54:11 -06:00
|
|
|
TraitItemKind::Const(ref ty, ref default) => {
|
2015-03-14 13:05:00 -05:00
|
|
|
visitor.visit_ty(ty);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_expr, default);
|
2015-03-14 13:05:00 -05:00
|
|
|
}
|
2016-02-09 10:54:11 -06:00
|
|
|
TraitItemKind::Method(ref sig, None) => {
|
2015-03-11 01:38:27 -05:00
|
|
|
visitor.visit_generics(&sig.generics);
|
|
|
|
walk_fn_decl(visitor, &sig.decl);
|
2015-03-10 05:28:44 -05:00
|
|
|
}
|
2016-02-09 10:54:11 -06:00
|
|
|
TraitItemKind::Method(ref sig, Some(ref body)) => {
|
2015-08-26 05:00:14 -05:00
|
|
|
visitor.visit_fn(FnKind::Method(trait_item.ident, sig, None), &sig.decl,
|
2015-03-11 16:38:58 -05:00
|
|
|
body, trait_item.span, trait_item.id);
|
2015-03-10 05:28:44 -05:00
|
|
|
}
|
2016-02-09 10:54:11 -06:00
|
|
|
TraitItemKind::Type(ref bounds, ref default) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_ty_param_bound, bounds);
|
|
|
|
walk_list!(visitor, visit_ty, default);
|
2015-03-10 05:28:44 -05:00
|
|
|
}
|
2016-06-10 20:00:07 -05:00
|
|
|
TraitItemKind::Macro(ref mac) => {
|
|
|
|
visitor.visit_mac(mac);
|
|
|
|
}
|
2015-03-10 05:28:44 -05:00
|
|
|
}
|
2012-07-11 12:28:30 -05:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_impl_item<V: Visitor>(visitor: &mut V, impl_item: &ImplItem) {
|
2016-04-10 18:10:46 -05:00
|
|
|
visitor.visit_vis(&impl_item.vis);
|
2015-03-10 05:28:44 -05:00
|
|
|
visitor.visit_ident(impl_item.span, impl_item.ident);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_attribute, &impl_item.attrs);
|
2015-03-10 05:28:44 -05:00
|
|
|
match impl_item.node {
|
2015-11-13 07:15:04 -06:00
|
|
|
ImplItemKind::Const(ref ty, ref expr) => {
|
2015-03-14 13:05:00 -05:00
|
|
|
visitor.visit_ty(ty);
|
|
|
|
visitor.visit_expr(expr);
|
|
|
|
}
|
2015-11-13 07:15:04 -06:00
|
|
|
ImplItemKind::Method(ref sig, ref body) => {
|
2016-03-23 05:17:34 -05:00
|
|
|
visitor.visit_fn(FnKind::Method(impl_item.ident, sig, Some(&impl_item.vis)), &sig.decl,
|
2015-03-11 16:38:58 -05:00
|
|
|
body, impl_item.span, impl_item.id);
|
2015-03-10 05:28:44 -05:00
|
|
|
}
|
2015-11-13 07:15:04 -06:00
|
|
|
ImplItemKind::Type(ref ty) => {
|
2015-03-10 05:28:44 -05:00
|
|
|
visitor.visit_ty(ty);
|
2014-08-05 21:44:21 -05:00
|
|
|
}
|
2015-11-13 07:15:04 -06:00
|
|
|
ImplItemKind::Macro(ref mac) => {
|
2015-03-11 16:38:58 -05:00
|
|
|
visitor.visit_mac(mac);
|
|
|
|
}
|
2012-07-10 15:44:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_struct_def<V: Visitor>(visitor: &mut V, struct_definition: &VariantData) {
|
2015-10-08 15:45:46 -05:00
|
|
|
walk_list!(visitor, visit_struct_field, struct_definition.fields());
|
2012-08-07 17:54:59 -05:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_struct_field<V: Visitor>(visitor: &mut V, struct_field: &StructField) {
|
2016-04-10 18:10:46 -05:00
|
|
|
visitor.visit_vis(&struct_field.vis);
|
2016-04-06 03:19:10 -05:00
|
|
|
walk_opt_ident(visitor, struct_field.span, struct_field.ident);
|
|
|
|
visitor.visit_ty(&struct_field.ty);
|
|
|
|
walk_list!(visitor, visit_attribute, &struct_field.attrs);
|
2012-08-15 17:53:58 -05:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_block<V: Visitor>(visitor: &mut V, block: &Block) {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_stmt, &block.stmts);
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_stmt<V: Visitor>(visitor: &mut V, statement: &Stmt) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match statement.node {
|
2016-06-16 21:30:01 -05:00
|
|
|
StmtKind::Local(ref local) => visitor.visit_local(local),
|
|
|
|
StmtKind::Item(ref item) => visitor.visit_item(item),
|
|
|
|
StmtKind::Expr(ref expression) | StmtKind::Semi(ref expression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-06-16 21:30:01 -05:00
|
|
|
StmtKind::Mac(ref mac) => {
|
|
|
|
let (ref mac, _, ref attrs) = **mac;
|
2015-11-03 10:39:51 -06:00
|
|
|
visitor.visit_mac(mac);
|
2016-06-17 23:01:57 -05:00
|
|
|
for attr in attrs.iter() {
|
2015-11-03 10:39:51 -06:00
|
|
|
visitor.visit_attribute(attr);
|
|
|
|
}
|
|
|
|
}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_mac<V: Visitor>(_: &mut V, _: &Mac) {
|
2013-07-19 20:42:11 -05:00
|
|
|
// Empty!
|
2011-07-08 18:35:09 -05:00
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_expr<V: Visitor>(visitor: &mut V, expression: &Expr) {
|
2016-06-17 23:01:57 -05:00
|
|
|
for attr in expression.attrs.iter() {
|
2016-06-10 05:31:45 -05:00
|
|
|
visitor.visit_attribute(attr);
|
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
match expression.node {
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Box(ref subexpression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression)
|
2015-09-24 10:00:08 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::InPlace(ref place, ref subexpression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(place);
|
|
|
|
visitor.visit_expr(subexpression)
|
2013-12-17 18:46:18 -06:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Vec(ref subexpressions) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_expr, subexpressions);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Repeat(ref element, ref count) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(element);
|
|
|
|
visitor.visit_expr(count)
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Struct(ref path, ref fields, ref optional_base) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_path(path, expression.id);
|
2015-01-31 11:20:46 -06:00
|
|
|
for field in fields {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ident(field.ident.span, field.ident.node);
|
|
|
|
visitor.visit_expr(&field.expr)
|
2013-06-15 19:26:59 -05:00
|
|
|
}
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_expr, optional_base);
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Tup(ref subexpressions) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_expr, subexpressions);
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Call(ref callee_expression, ref arguments) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_expr, arguments);
|
|
|
|
visitor.visit_expr(callee_expression)
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::MethodCall(ref ident, ref types, ref arguments) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ident(ident.span, ident.node);
|
|
|
|
walk_list!(visitor, visit_expr, arguments);
|
|
|
|
walk_list!(visitor, visit_ty, types);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Binary(_, ref left_expression, ref right_expression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(left_expression);
|
|
|
|
visitor.visit_expr(right_expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::AddrOf(_, ref subexpression) | ExprKind::Unary(_, ref subexpression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Lit(_) => {}
|
|
|
|
ExprKind::Cast(ref subexpression, ref typ) | ExprKind::Type(ref subexpression, ref typ) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression);
|
|
|
|
visitor.visit_ty(typ)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::If(ref head_expression, ref if_block, ref optional_else) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(head_expression);
|
|
|
|
visitor.visit_block(if_block);
|
|
|
|
walk_list!(visitor, visit_expr, optional_else);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-05-02 11:22:03 -05:00
|
|
|
ExprKind::While(ref subexpression, ref block, ref opt_sp_ident) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression);
|
|
|
|
visitor.visit_block(block);
|
2016-05-02 11:22:03 -05:00
|
|
|
walk_opt_sp_ident(visitor, opt_sp_ident);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::IfLet(ref pattern, ref subexpression, ref if_block, ref optional_else) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_pat(pattern);
|
|
|
|
visitor.visit_expr(subexpression);
|
|
|
|
visitor.visit_block(if_block);
|
|
|
|
walk_list!(visitor, visit_expr, optional_else);
|
|
|
|
}
|
2016-05-02 11:22:03 -05:00
|
|
|
ExprKind::WhileLet(ref pattern, ref subexpression, ref block, ref opt_sp_ident) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_pat(pattern);
|
|
|
|
visitor.visit_expr(subexpression);
|
|
|
|
visitor.visit_block(block);
|
2016-05-02 11:22:03 -05:00
|
|
|
walk_opt_sp_ident(visitor, opt_sp_ident);
|
2015-09-28 06:26:26 -05:00
|
|
|
}
|
2016-05-02 11:22:03 -05:00
|
|
|
ExprKind::ForLoop(ref pattern, ref subexpression, ref block, ref opt_sp_ident) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_pat(pattern);
|
|
|
|
visitor.visit_expr(subexpression);
|
|
|
|
visitor.visit_block(block);
|
2016-05-02 11:22:03 -05:00
|
|
|
walk_opt_sp_ident(visitor, opt_sp_ident);
|
2015-09-28 06:26:26 -05:00
|
|
|
}
|
2016-05-02 11:22:03 -05:00
|
|
|
ExprKind::Loop(ref block, ref opt_sp_ident) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_block(block);
|
2016-05-02 11:22:03 -05:00
|
|
|
walk_opt_sp_ident(visitor, opt_sp_ident);
|
2015-09-28 06:26:26 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Match(ref subexpression, ref arms) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression);
|
|
|
|
walk_list!(visitor, visit_arm, arms);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-04-20 13:44:07 -05:00
|
|
|
ExprKind::Closure(_, ref function_declaration, ref body, _decl_span) => {
|
2015-08-26 05:00:14 -05:00
|
|
|
visitor.visit_fn(FnKind::Closure,
|
2015-09-28 06:26:26 -05:00
|
|
|
function_declaration,
|
|
|
|
body,
|
2014-05-29 00:26:56 -05:00
|
|
|
expression.span,
|
2014-09-12 05:10:30 -05:00
|
|
|
expression.id)
|
2014-05-29 00:26:56 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Block(ref block) => visitor.visit_block(block),
|
|
|
|
ExprKind::Assign(ref left_hand_expression, ref right_hand_expression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(right_hand_expression);
|
|
|
|
visitor.visit_expr(left_hand_expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::AssignOp(_, ref left_expression, ref right_expression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(right_expression);
|
|
|
|
visitor.visit_expr(left_expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Field(ref subexpression, ref ident) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression);
|
|
|
|
visitor.visit_ident(ident.span, ident.node);
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::TupField(ref subexpression, _) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression);
|
2014-08-09 22:54:33 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Index(ref main_expression, ref index_expression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(main_expression);
|
|
|
|
visitor.visit_expr(index_expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-01-13 00:23:31 -06:00
|
|
|
ExprKind::Range(ref start, ref end, _) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_expr, start);
|
|
|
|
walk_list!(visitor, visit_expr, end);
|
2014-12-12 23:41:02 -06:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Path(ref maybe_qself, ref path) => {
|
2015-09-29 03:33:25 -05:00
|
|
|
if let Some(ref qself) = *maybe_qself {
|
2015-02-17 11:29:13 -06:00
|
|
|
visitor.visit_ty(&qself.ty);
|
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_path(path, expression.id)
|
2013-12-08 13:25:35 -06:00
|
|
|
}
|
2016-06-16 21:34:18 -05:00
|
|
|
ExprKind::Break(ref opt_sp_ident) | ExprKind::Continue(ref opt_sp_ident) => {
|
2016-05-02 11:22:03 -05:00
|
|
|
walk_opt_sp_ident(visitor, opt_sp_ident);
|
2015-09-28 06:26:26 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Ret(ref optional_expression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_expr, optional_expression);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Mac(ref mac) => visitor.visit_mac(mac),
|
|
|
|
ExprKind::Paren(ref subexpression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::InlineAsm(ref ia) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
for &(_, ref input) in &ia.inputs {
|
|
|
|
visitor.visit_expr(&input)
|
2013-03-12 19:53:25 -05:00
|
|
|
}
|
2015-12-05 02:18:24 -06:00
|
|
|
for output in &ia.outputs {
|
|
|
|
visitor.visit_expr(&output.expr)
|
2013-03-12 19:53:25 -05:00
|
|
|
}
|
|
|
|
}
|
2016-02-28 16:38:48 -06:00
|
|
|
ExprKind::Try(ref subexpression) => {
|
|
|
|
visitor.visit_expr(subexpression)
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_arm<V: Visitor>(visitor: &mut V, arm: &Arm) {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_pat, &arm.pats);
|
|
|
|
walk_list!(visitor, visit_expr, &arm.guard);
|
|
|
|
visitor.visit_expr(&arm.body);
|
|
|
|
walk_list!(visitor, visit_attribute, &arm.attrs);
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
2016-03-31 14:10:38 -05:00
|
|
|
|
2016-06-12 02:51:31 -05:00
|
|
|
pub fn walk_vis<V: Visitor>(visitor: &mut V, vis: &Visibility) {
|
2016-04-10 18:10:46 -05:00
|
|
|
if let Visibility::Restricted { ref path, id } = *vis {
|
|
|
|
visitor.visit_path(path, id);
|
2016-03-31 14:10:38 -05:00
|
|
|
}
|
|
|
|
}
|