1 // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
16 use owned_slice::OwnedSlice;
20 // Context-passing AST walker. Each overridden visit method has full control
21 // over what happens with its node, it can do its own traversal of the node's
22 // children (potentially passing in different contexts to each), call
23 // visit::visit_* to apply the default traversal algorithm (again, it can
24 // override the context), or prevent deeper traversal by doing nothing.
26 // Note: it is an important invariant that the default visitor walks the body
27 // of a function in "execution order" (more concretely, reverse post-order
28 // with respect to the CFG implied by the AST), meaning that if AST node A may
29 // execute before AST node B, then A is visited first. The borrow checker in
30 // particular relies on this property.
33 // fn foo() or extern "Abi" fn foo()
34 FkItemFn(Ident, &'a Generics, FnStyle, Abi),
37 FkMethod(Ident, &'a Generics, &'a Method),
44 pub fn name_of_fn(fk: &FnKind) -> Ident {
46 FkItemFn(name, _, _, _) | FkMethod(name, _, _) => name,
47 FkFnBlock(..) => parse::token::special_idents::invalid
51 pub fn generics_of_fn(fk: &FnKind) -> Generics {
53 FkItemFn(_, generics, _, _) |
54 FkMethod(_, generics, _) => {
59 lifetimes: Vec::new(),
60 ty_params: OwnedSlice::empty(),
66 /// Each method of the Visitor trait is a hook to be potentially
67 /// overridden. Each method's default implementation recursively visits
68 /// the substructure of the input via the corresponding `walk` method;
69 /// e.g. the `visit_mod` method by default calls `visit::walk_mod`.
71 /// If you want to ensure that your code handles every variant
72 /// explicitly, you need to override each method. (And you also need
73 /// to monitor future changes to `Visitor` in case a new method with a
74 /// new default implementation gets introduced.)
75 pub trait Visitor<E: Clone> {
77 fn visit_ident(&mut self, _sp: Span, _ident: Ident, _e: E) {
78 /*! Visit the idents */
80 fn visit_mod(&mut self, m: &Mod, _s: Span, _n: NodeId, e: E) { walk_mod(self, m, e) }
81 fn visit_view_item(&mut self, i: &ViewItem, e: E) { walk_view_item(self, i, e) }
82 fn visit_foreign_item(&mut self, i: &ForeignItem, e: E) { walk_foreign_item(self, i, e) }
83 fn visit_item(&mut self, i: &Item, e: E) { walk_item(self, i, e) }
84 fn visit_local(&mut self, l: &Local, e: E) { walk_local(self, l, e) }
85 fn visit_block(&mut self, b: &Block, e: E) { walk_block(self, b, e) }
86 fn visit_stmt(&mut self, s: &Stmt, e: E) { walk_stmt(self, s, e) }
87 fn visit_arm(&mut self, a: &Arm, e: E) { walk_arm(self, a, e) }
88 fn visit_pat(&mut self, p: &Pat, e: E) { walk_pat(self, p, e) }
89 fn visit_decl(&mut self, d: &Decl, e: E) { walk_decl(self, d, e) }
90 fn visit_expr(&mut self, ex: &Expr, e: E) { walk_expr(self, ex, e) }
91 fn visit_expr_post(&mut self, _ex: &Expr, _e: E) { }
92 fn visit_ty(&mut self, t: &Ty, e: E) { walk_ty(self, t, e) }
93 fn visit_generics(&mut self, g: &Generics, e: E) { walk_generics(self, g, e) }
94 fn visit_fn(&mut self, fk: &FnKind, fd: &FnDecl, b: &Block, s: Span, _: NodeId, e: E) {
95 walk_fn(self, fk, fd, b, s, e)
97 fn visit_ty_method(&mut self, t: &TypeMethod, e: E) { walk_ty_method(self, t, e) }
98 fn visit_trait_method(&mut self, t: &TraitMethod, e: E) { walk_trait_method(self, t, e) }
99 fn visit_struct_def(&mut self, s: &StructDef, _: Ident, _: &Generics, _: NodeId, e: E) {
100 walk_struct_def(self, s, e)
102 fn visit_struct_field(&mut self, s: &StructField, e: E) { walk_struct_field(self, s, e) }
103 fn visit_variant(&mut self, v: &Variant, g: &Generics, e: E) { walk_variant(self, v, g, e) }
104 fn visit_opt_lifetime_ref(&mut self,
106 opt_lifetime: &Option<Lifetime>,
109 * Visits an optional reference to a lifetime. The `span` is
110 * the span of some surrounding reference should opt_lifetime
113 match *opt_lifetime {
114 Some(ref l) => self.visit_lifetime_ref(l, env),
118 fn visit_lifetime_ref(&mut self, _lifetime: &Lifetime, _e: E) {
119 /*! Visits a reference to a lifetime */
121 fn visit_lifetime_decl(&mut self, _lifetime: &Lifetime, _e: E) {
122 /*! Visits a declaration of a lifetime */
124 fn visit_explicit_self(&mut self, es: &ExplicitSelf, e: E) {
125 walk_explicit_self(self, es, e)
127 fn visit_mac(&mut self, macro: &Mac, e: E) {
128 walk_mac(self, macro, e)
130 fn visit_path(&mut self, path: &Path, _id: ast::NodeId, e: E) {
131 walk_path(self, path, e)
133 fn visit_attribute(&mut self, _attr: &Attribute, _e: E) {}
136 pub fn walk_inlined_item<E: Clone, V: Visitor<E>>(visitor: &mut V,
137 item: &ast::InlinedItem,
140 IIItem(i) => visitor.visit_item(&*i, env),
141 IIForeign(i) => visitor.visit_foreign_item(&*i, env),
142 IIMethod(_, _, m) => walk_method_helper(visitor, &*m, env),
147 pub fn walk_crate<E: Clone, V: Visitor<E>>(visitor: &mut V, krate: &Crate, env: E) {
148 visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID, env.clone());
149 for attr in krate.attrs.iter() {
150 visitor.visit_attribute(attr, env.clone());
154 pub fn walk_mod<E: Clone, V: Visitor<E>>(visitor: &mut V, module: &Mod, env: E) {
155 for view_item in module.view_items.iter() {
156 visitor.visit_view_item(view_item, env.clone())
159 for item in module.items.iter() {
160 visitor.visit_item(&**item, env.clone())
164 pub fn walk_view_item<E: Clone, V: Visitor<E>>(visitor: &mut V, vi: &ViewItem, env: E) {
166 ViewItemExternCrate(name, _, _) => {
167 visitor.visit_ident(vi.span, name, env.clone())
169 ViewItemUse(ref vp) => {
171 ViewPathSimple(ident, ref path, id) => {
172 visitor.visit_ident(vp.span, ident, env.clone());
173 visitor.visit_path(path, id, env.clone());
175 ViewPathGlob(ref path, id) => {
176 visitor.visit_path(path, id, env.clone());
178 ViewPathList(ref path, ref list, _) => {
179 for id in list.iter() {
180 visitor.visit_ident(id.span, id.node.name, env.clone())
182 walk_path(visitor, path, env.clone());
187 for attr in vi.attrs.iter() {
188 visitor.visit_attribute(attr, env.clone());
192 pub fn walk_local<E: Clone, V: Visitor<E>>(visitor: &mut V, local: &Local, env: E) {
193 visitor.visit_pat(&*local.pat, env.clone());
194 visitor.visit_ty(&*local.ty, env.clone());
197 Some(initializer) => visitor.visit_expr(&*initializer, env),
201 pub fn walk_explicit_self<E: Clone, V: Visitor<E>>(visitor: &mut V,
202 explicit_self: &ExplicitSelf,
204 match explicit_self.node {
205 SelfStatic | SelfValue | SelfUniq => {}
206 SelfRegion(ref lifetime, _) => {
207 visitor.visit_opt_lifetime_ref(explicit_self.span, lifetime, env)
212 /// Like with walk_method_helper this doesn't correspond to a method
213 /// in Visitor, and so it gets a _helper suffix.
214 pub fn walk_trait_ref_helper<E: Clone, V: Visitor<E>>(visitor: &mut V,
215 trait_ref: &TraitRef,
217 visitor.visit_path(&trait_ref.path, trait_ref.ref_id, env)
220 pub fn walk_item<E: Clone, V: Visitor<E>>(visitor: &mut V, item: &Item, env: E) {
221 visitor.visit_ident(item.span, item.ident, env.clone());
223 ItemStatic(ref typ, _, ref expr) => {
224 visitor.visit_ty(&**typ, env.clone());
225 visitor.visit_expr(&**expr, env.clone());
227 ItemFn(declaration, fn_style, abi, ref generics, body) => {
228 visitor.visit_fn(&FkItemFn(item.ident, generics, fn_style, abi),
235 ItemMod(ref module) => {
236 visitor.visit_mod(module, item.span, item.id, env.clone())
238 ItemForeignMod(ref foreign_module) => {
239 for view_item in foreign_module.view_items.iter() {
240 visitor.visit_view_item(view_item, env.clone())
242 for foreign_item in foreign_module.items.iter() {
243 visitor.visit_foreign_item(&**foreign_item, env.clone())
246 ItemTy(ref typ, ref type_parameters) => {
247 visitor.visit_ty(&**typ, env.clone());
248 visitor.visit_generics(type_parameters, env.clone())
250 ItemEnum(ref enum_definition, ref type_parameters) => {
251 visitor.visit_generics(type_parameters, env.clone());
252 walk_enum_def(visitor, enum_definition, type_parameters, env.clone())
254 ItemImpl(ref type_parameters,
258 visitor.visit_generics(type_parameters, env.clone());
259 match *trait_reference {
260 Some(ref trait_reference) => walk_trait_ref_helper(visitor,
261 trait_reference, env.clone()),
264 visitor.visit_ty(&*typ, env.clone());
265 for method in methods.iter() {
266 walk_method_helper(visitor, &**method, env.clone())
269 ItemStruct(ref struct_definition, ref generics) => {
270 visitor.visit_generics(generics, env.clone());
271 visitor.visit_struct_def(&**struct_definition,
277 ItemTrait(ref generics, _, ref trait_paths, ref methods) => {
278 visitor.visit_generics(generics, env.clone());
279 for trait_path in trait_paths.iter() {
280 visitor.visit_path(&trait_path.path,
284 for method in methods.iter() {
285 visitor.visit_trait_method(method, env.clone())
288 ItemMac(ref macro) => visitor.visit_mac(macro, env.clone()),
290 for attr in item.attrs.iter() {
291 visitor.visit_attribute(attr, env.clone());
295 pub fn walk_enum_def<E: Clone, V:Visitor<E>>(visitor: &mut V,
296 enum_definition: &EnumDef,
299 for &variant in enum_definition.variants.iter() {
300 visitor.visit_variant(&*variant, generics, env.clone());
304 pub fn walk_variant<E: Clone, V: Visitor<E>>(visitor: &mut V,
308 visitor.visit_ident(variant.span, variant.node.name, env.clone());
310 match variant.node.kind {
311 TupleVariantKind(ref variant_arguments) => {
312 for variant_argument in variant_arguments.iter() {
313 visitor.visit_ty(&*variant_argument.ty, env.clone())
316 StructVariantKind(ref struct_definition) => {
317 visitor.visit_struct_def(&**struct_definition,
324 match variant.node.disr_expr {
325 Some(ref expr) => visitor.visit_expr(&**expr, env.clone()),
328 for attr in variant.node.attrs.iter() {
329 visitor.visit_attribute(attr, env.clone());
333 pub fn skip_ty<E, V: Visitor<E>>(_: &mut V, _: &Ty, _: E) {
337 pub fn walk_ty<E: Clone, V: Visitor<E>>(visitor: &mut V, typ: &Ty, env: E) {
339 TyUniq(ty) | TyVec(ty) | TyBox(ty) => {
340 visitor.visit_ty(&*ty, env)
342 TyPtr(ref mutable_type) => {
343 visitor.visit_ty(&*mutable_type.ty, env)
345 TyRptr(ref lifetime, ref mutable_type) => {
346 visitor.visit_opt_lifetime_ref(typ.span, lifetime, env.clone());
347 visitor.visit_ty(&*mutable_type.ty, env)
349 TyTup(ref tuple_element_types) => {
350 for &tuple_element_type in tuple_element_types.iter() {
351 visitor.visit_ty(&*tuple_element_type, env.clone())
354 TyClosure(ref function_declaration, ref region) => {
355 for argument in function_declaration.decl.inputs.iter() {
356 visitor.visit_ty(&*argument.ty, env.clone())
358 visitor.visit_ty(&*function_declaration.decl.output, env.clone());
359 for bounds in function_declaration.bounds.iter() {
360 walk_ty_param_bounds(visitor, bounds, env.clone())
362 visitor.visit_opt_lifetime_ref(
366 walk_lifetime_decls(visitor, &function_declaration.lifetimes,
369 TyProc(ref function_declaration) => {
370 for argument in function_declaration.decl.inputs.iter() {
371 visitor.visit_ty(&*argument.ty, env.clone())
373 visitor.visit_ty(&*function_declaration.decl.output, env.clone());
374 for bounds in function_declaration.bounds.iter() {
375 walk_ty_param_bounds(visitor, bounds, env.clone())
377 walk_lifetime_decls(visitor, &function_declaration.lifetimes,
380 TyBareFn(ref function_declaration) => {
381 for argument in function_declaration.decl.inputs.iter() {
382 visitor.visit_ty(&*argument.ty, env.clone())
384 visitor.visit_ty(&*function_declaration.decl.output, env.clone());
385 walk_lifetime_decls(visitor, &function_declaration.lifetimes,
388 TyUnboxedFn(ref function_declaration) => {
389 for argument in function_declaration.decl.inputs.iter() {
390 visitor.visit_ty(&*argument.ty, env.clone())
392 visitor.visit_ty(&*function_declaration.decl.output, env.clone());
394 TyPath(ref path, ref bounds, id) => {
395 visitor.visit_path(path, id, env.clone());
396 for bounds in bounds.iter() {
397 walk_ty_param_bounds(visitor, bounds, env.clone())
400 TyFixedLengthVec(ref ty, ref expression) => {
401 visitor.visit_ty(&**ty, env.clone());
402 visitor.visit_expr(&**expression, env)
404 TyTypeof(ref expression) => {
405 visitor.visit_expr(&**expression, env)
407 TyNil | TyBot | TyInfer => {}
411 fn walk_lifetime_decls<E: Clone, V: Visitor<E>>(visitor: &mut V,
412 lifetimes: &Vec<Lifetime>,
414 for l in lifetimes.iter() {
415 visitor.visit_lifetime_decl(l, env.clone());
419 pub fn walk_path<E: Clone, V: Visitor<E>>(visitor: &mut V, path: &Path, env: E) {
420 for segment in path.segments.iter() {
421 visitor.visit_ident(path.span, segment.identifier, env.clone());
423 for typ in segment.types.iter() {
424 visitor.visit_ty(&**typ, env.clone());
426 for lifetime in segment.lifetimes.iter() {
427 visitor.visit_lifetime_ref(lifetime, env.clone());
432 pub fn walk_pat<E: Clone, V: Visitor<E>>(visitor: &mut V, pattern: &Pat, env: E) {
434 PatEnum(ref path, ref children) => {
435 visitor.visit_path(path, pattern.id, env.clone());
436 for children in children.iter() {
437 for child in children.iter() {
438 visitor.visit_pat(&**child, env.clone())
442 PatStruct(ref path, ref fields, _) => {
443 visitor.visit_path(path, pattern.id, env.clone());
444 for field in fields.iter() {
445 visitor.visit_pat(&*field.pat, env.clone())
448 PatTup(ref tuple_elements) => {
449 for tuple_element in tuple_elements.iter() {
450 visitor.visit_pat(&**tuple_element, env.clone())
453 PatBox(ref subpattern) |
454 PatRegion(ref subpattern) => {
455 visitor.visit_pat(&**subpattern, env)
457 PatIdent(_, ref path, ref optional_subpattern) => {
458 visitor.visit_path(path, pattern.id, env.clone());
459 match *optional_subpattern {
461 Some(ref subpattern) => visitor.visit_pat(&**subpattern, env),
464 PatLit(ref expression) => visitor.visit_expr(&**expression, env),
465 PatRange(ref lower_bound, ref upper_bound) => {
466 visitor.visit_expr(&**lower_bound, env.clone());
467 visitor.visit_expr(&**upper_bound, env)
469 PatWild | PatWildMulti => (),
470 PatVec(ref prepattern, ref slice_pattern, ref postpatterns) => {
471 for prepattern in prepattern.iter() {
472 visitor.visit_pat(&**prepattern, env.clone())
474 for slice_pattern in slice_pattern.iter() {
475 visitor.visit_pat(&**slice_pattern, env.clone())
477 for postpattern in postpatterns.iter() {
478 visitor.visit_pat(&**postpattern, env.clone())
481 PatMac(ref macro) => visitor.visit_mac(macro, env),
485 pub fn walk_foreign_item<E: Clone, V: Visitor<E>>(visitor: &mut V,
486 foreign_item: &ForeignItem,
488 visitor.visit_ident(foreign_item.span, foreign_item.ident, env.clone());
490 match foreign_item.node {
491 ForeignItemFn(ref function_declaration, ref generics) => {
492 walk_fn_decl(visitor, &**function_declaration, env.clone());
493 visitor.visit_generics(generics, env.clone())
495 ForeignItemStatic(ref typ, _) => visitor.visit_ty(&**typ, env.clone()),
498 for attr in foreign_item.attrs.iter() {
499 visitor.visit_attribute(attr, env.clone());
503 pub fn walk_ty_param_bounds<E: Clone, V: Visitor<E>>(visitor: &mut V,
504 bounds: &OwnedSlice<TyParamBound>,
506 for bound in bounds.iter() {
508 TraitTyParamBound(ref typ) => {
509 walk_trait_ref_helper(visitor, typ, env.clone())
511 StaticRegionTyParamBound => {}
512 UnboxedFnTyParamBound(ref function_declaration) => {
513 for argument in function_declaration.decl.inputs.iter() {
514 visitor.visit_ty(&*argument.ty, env.clone())
516 visitor.visit_ty(&*function_declaration.decl.output,
519 OtherRegionTyParamBound(..) => {}
524 pub fn walk_generics<E: Clone, V: Visitor<E>>(visitor: &mut V,
527 for type_parameter in generics.ty_params.iter() {
528 walk_ty_param_bounds(visitor, &type_parameter.bounds, env.clone());
529 match type_parameter.default {
530 Some(ref ty) => visitor.visit_ty(&**ty, env.clone()),
534 walk_lifetime_decls(visitor, &generics.lifetimes, env);
537 pub fn walk_fn_decl<E: Clone, V: Visitor<E>>(visitor: &mut V,
538 function_declaration: &FnDecl,
540 for argument in function_declaration.inputs.iter() {
541 visitor.visit_pat(&*argument.pat, env.clone());
542 visitor.visit_ty(&*argument.ty, env.clone())
544 visitor.visit_ty(&*function_declaration.output, env)
547 // Note: there is no visit_method() method in the visitor, instead override
548 // visit_fn() and check for FkMethod(). I named this visit_method_helper()
549 // because it is not a default impl of any method, though I doubt that really
550 // clarifies anything. - Niko
551 pub fn walk_method_helper<E: Clone, V: Visitor<E>>(visitor: &mut V,
554 visitor.visit_ident(method.span, method.ident, env.clone());
555 visitor.visit_fn(&FkMethod(method.ident, &method.generics, method),
561 for attr in method.attrs.iter() {
562 visitor.visit_attribute(attr, env.clone());
566 pub fn walk_fn<E: Clone, V: Visitor<E>>(visitor: &mut V,
567 function_kind: &FnKind,
568 function_declaration: &FnDecl,
569 function_body: &Block,
572 walk_fn_decl(visitor, function_declaration, env.clone());
574 match *function_kind {
575 FkItemFn(_, generics, _, _) => {
576 visitor.visit_generics(generics, env.clone());
578 FkMethod(_, generics, method) => {
579 visitor.visit_generics(generics, env.clone());
581 visitor.visit_explicit_self(&method.explicit_self, env.clone());
586 visitor.visit_block(function_body, env)
589 pub fn walk_ty_method<E: Clone, V: Visitor<E>>(visitor: &mut V,
590 method_type: &TypeMethod,
592 visitor.visit_ident(method_type.span, method_type.ident, env.clone());
593 visitor.visit_explicit_self(&method_type.explicit_self, env.clone());
594 for argument_type in method_type.decl.inputs.iter() {
595 visitor.visit_ty(&*argument_type.ty, env.clone())
597 visitor.visit_generics(&method_type.generics, env.clone());
598 visitor.visit_ty(&*method_type.decl.output, env.clone());
599 for attr in method_type.attrs.iter() {
600 visitor.visit_attribute(attr, env.clone());
604 pub fn walk_trait_method<E: Clone, V: Visitor<E>>(visitor: &mut V,
605 trait_method: &TraitMethod,
607 match *trait_method {
608 Required(ref method_type) => {
609 visitor.visit_ty_method(method_type, env)
611 Provided(ref method) => walk_method_helper(visitor, &**method, env),
615 pub fn walk_struct_def<E: Clone, V: Visitor<E>>(visitor: &mut V,
616 struct_definition: &StructDef,
618 match struct_definition.super_struct {
619 Some(ref t) => visitor.visit_ty(&**t, env.clone()),
622 for field in struct_definition.fields.iter() {
623 visitor.visit_struct_field(field, env.clone())
627 pub fn walk_struct_field<E: Clone, V: Visitor<E>>(visitor: &mut V,
628 struct_field: &StructField,
630 match struct_field.node.kind {
631 NamedField(name, _) => {
632 visitor.visit_ident(struct_field.span, name, env.clone())
637 visitor.visit_ty(&*struct_field.node.ty, env.clone());
639 for attr in struct_field.node.attrs.iter() {
640 visitor.visit_attribute(attr, env.clone());
644 pub fn walk_block<E: Clone, V: Visitor<E>>(visitor: &mut V, block: &Block, env: E) {
645 for view_item in block.view_items.iter() {
646 visitor.visit_view_item(view_item, env.clone())
648 for statement in block.stmts.iter() {
649 visitor.visit_stmt(&**statement, env.clone())
651 walk_expr_opt(visitor, block.expr, env)
654 pub fn walk_stmt<E: Clone, V: Visitor<E>>(visitor: &mut V, statement: &Stmt, env: E) {
655 match statement.node {
656 StmtDecl(ref declaration, _) => visitor.visit_decl(&**declaration, env),
657 StmtExpr(ref expression, _) | StmtSemi(ref expression, _) => {
658 visitor.visit_expr(&**expression, env)
660 StmtMac(ref macro, _) => visitor.visit_mac(macro, env),
664 pub fn walk_decl<E: Clone, V: Visitor<E>>(visitor: &mut V, declaration: &Decl, env: E) {
665 match declaration.node {
666 DeclLocal(ref local) => visitor.visit_local(&**local, env),
667 DeclItem(ref item) => visitor.visit_item(&**item, env),
671 pub fn walk_expr_opt<E: Clone, V: Visitor<E>>(visitor: &mut V,
672 optional_expression: Option<Gc<Expr>>,
674 match optional_expression {
676 Some(ref expression) => visitor.visit_expr(&**expression, env),
680 pub fn walk_exprs<E: Clone, V: Visitor<E>>(visitor: &mut V,
681 expressions: &[Gc<Expr>],
683 for expression in expressions.iter() {
684 visitor.visit_expr(&**expression, env.clone())
688 pub fn walk_mac<E, V: Visitor<E>>(_: &mut V, _: &Mac, _: E) {
692 pub fn walk_expr<E: Clone, V: Visitor<E>>(visitor: &mut V, expression: &Expr, env: E) {
693 match expression.node {
694 ExprVstore(ref subexpression, _) => {
695 visitor.visit_expr(&**subexpression, env.clone())
697 ExprBox(ref place, ref subexpression) => {
698 visitor.visit_expr(&**place, env.clone());
699 visitor.visit_expr(&**subexpression, env.clone())
701 ExprVec(ref subexpressions) => {
702 walk_exprs(visitor, subexpressions.as_slice(), env.clone())
704 ExprRepeat(ref element, ref count) => {
705 visitor.visit_expr(&**element, env.clone());
706 visitor.visit_expr(&**count, env.clone())
708 ExprStruct(ref path, ref fields, optional_base) => {
709 visitor.visit_path(path, expression.id, env.clone());
710 for field in fields.iter() {
711 visitor.visit_expr(&*field.expr, env.clone())
713 walk_expr_opt(visitor, optional_base, env.clone())
715 ExprTup(ref subexpressions) => {
716 for subexpression in subexpressions.iter() {
717 visitor.visit_expr(&**subexpression, env.clone())
720 ExprCall(ref callee_expression, ref arguments) => {
721 for argument in arguments.iter() {
722 visitor.visit_expr(&**argument, env.clone())
724 visitor.visit_expr(&**callee_expression, env.clone())
726 ExprMethodCall(_, ref types, ref arguments) => {
727 walk_exprs(visitor, arguments.as_slice(), env.clone());
728 for typ in types.iter() {
729 visitor.visit_ty(&**typ, env.clone())
732 ExprBinary(_, ref left_expression, ref right_expression) => {
733 visitor.visit_expr(&**left_expression, env.clone());
734 visitor.visit_expr(&**right_expression, env.clone())
736 ExprAddrOf(_, ref subexpression) | ExprUnary(_, ref subexpression) => {
737 visitor.visit_expr(&**subexpression, env.clone())
740 ExprCast(ref subexpression, ref typ) => {
741 visitor.visit_expr(&**subexpression, env.clone());
742 visitor.visit_ty(&**typ, env.clone())
744 ExprIf(ref head_expression, ref if_block, optional_else) => {
745 visitor.visit_expr(&**head_expression, env.clone());
746 visitor.visit_block(&**if_block, env.clone());
747 walk_expr_opt(visitor, optional_else, env.clone())
749 ExprWhile(ref subexpression, ref block) => {
750 visitor.visit_expr(&**subexpression, env.clone());
751 visitor.visit_block(&**block, env.clone())
753 ExprForLoop(ref pattern, ref subexpression, ref block, _) => {
754 visitor.visit_pat(&**pattern, env.clone());
755 visitor.visit_expr(&**subexpression, env.clone());
756 visitor.visit_block(&**block, env.clone())
758 ExprLoop(ref block, _) => visitor.visit_block(&**block, env.clone()),
759 ExprMatch(ref subexpression, ref arms) => {
760 visitor.visit_expr(&**subexpression, env.clone());
761 for arm in arms.iter() {
762 visitor.visit_arm(arm, env.clone())
765 ExprFnBlock(ref function_declaration, ref body) => {
766 visitor.visit_fn(&FkFnBlock,
767 &**function_declaration,
773 ExprProc(ref function_declaration, ref body) => {
774 visitor.visit_fn(&FkFnBlock,
775 &**function_declaration,
781 ExprBlock(ref block) => visitor.visit_block(&**block, env.clone()),
782 ExprAssign(ref left_hand_expression, ref right_hand_expression) => {
783 visitor.visit_expr(&**right_hand_expression, env.clone());
784 visitor.visit_expr(&**left_hand_expression, env.clone())
786 ExprAssignOp(_, ref left_expression, ref right_expression) => {
787 visitor.visit_expr(&**right_expression, env.clone());
788 visitor.visit_expr(&**left_expression, env.clone())
790 ExprField(ref subexpression, _, ref types) => {
791 visitor.visit_expr(&**subexpression, env.clone());
792 for typ in types.iter() {
793 visitor.visit_ty(&**typ, env.clone())
796 ExprIndex(ref main_expression, ref index_expression) => {
797 visitor.visit_expr(&**main_expression, env.clone());
798 visitor.visit_expr(&**index_expression, env.clone())
800 ExprPath(ref path) => {
801 visitor.visit_path(path, expression.id, env.clone())
803 ExprBreak(_) | ExprAgain(_) => {}
804 ExprRet(optional_expression) => {
805 walk_expr_opt(visitor, optional_expression, env.clone())
807 ExprMac(ref macro) => visitor.visit_mac(macro, env.clone()),
808 ExprParen(ref subexpression) => {
809 visitor.visit_expr(&**subexpression, env.clone())
811 ExprInlineAsm(ref assembler) => {
812 for &(_, ref input) in assembler.inputs.iter() {
813 visitor.visit_expr(&**input, env.clone())
815 for &(_, ref output) in assembler.outputs.iter() {
816 visitor.visit_expr(&**output, env.clone())
821 visitor.visit_expr_post(expression, env.clone())
824 pub fn walk_arm<E: Clone, V: Visitor<E>>(visitor: &mut V, arm: &Arm, env: E) {
825 for pattern in arm.pats.iter() {
826 visitor.visit_pat(&**pattern, env.clone())
828 walk_expr_opt(visitor, arm.guard, env.clone());
829 visitor.visit_expr(&*arm.body, env.clone());
830 for attr in arm.attrs.iter() {
831 visitor.visit_attribute(attr, env.clone());