pub trait ScopeVisitor<'arena, 'src> {
Show 13 methods
// Provided methods
fn visit_program(
&mut self,
_program: &Program<'arena, 'src>,
_scope: &Scope<'src>,
) -> ControlFlow<()> { ... }
fn visit_stmt(
&mut self,
_stmt: &Stmt<'arena, 'src>,
_scope: &Scope<'src>,
) -> ControlFlow<()> { ... }
fn visit_expr(
&mut self,
_expr: &Expr<'arena, 'src>,
_scope: &Scope<'src>,
) -> ControlFlow<()> { ... }
fn visit_param(
&mut self,
_param: &Param<'arena, 'src>,
_scope: &Scope<'src>,
) -> ControlFlow<()> { ... }
fn visit_arg(
&mut self,
_arg: &Arg<'arena, 'src>,
_scope: &Scope<'src>,
) -> ControlFlow<()> { ... }
fn visit_class_member(
&mut self,
_member: &ClassMember<'arena, 'src>,
_scope: &Scope<'src>,
) -> ControlFlow<()> { ... }
fn visit_enum_member(
&mut self,
_member: &EnumMember<'arena, 'src>,
_scope: &Scope<'src>,
) -> ControlFlow<()> { ... }
fn visit_property_hook(
&mut self,
_hook: &PropertyHook<'arena, 'src>,
_scope: &Scope<'src>,
) -> ControlFlow<()> { ... }
fn visit_type_hint(
&mut self,
_type_hint: &TypeHint<'arena, 'src>,
_scope: &Scope<'src>,
) -> ControlFlow<()> { ... }
fn visit_attribute(
&mut self,
_attribute: &Attribute<'arena, 'src>,
_scope: &Scope<'src>,
) -> ControlFlow<()> { ... }
fn visit_catch_clause(
&mut self,
_catch: &CatchClause<'arena, 'src>,
_scope: &Scope<'src>,
) -> ControlFlow<()> { ... }
fn visit_match_arm(
&mut self,
_arm: &MatchArm<'arena, 'src>,
_scope: &Scope<'src>,
) -> ControlFlow<()> { ... }
fn visit_closure_use_var(
&mut self,
_var: &ClosureUseVar<'src>,
_scope: &Scope<'src>,
) -> ControlFlow<()> { ... }
}Expand description
A scope-aware variant of Visitor.
Every visit method receives a Scope describing the lexical context at
that node — the current namespace, enclosing class-like declaration, and
enclosing named function or method. All methods have no-op default
implementations, so implementors override only what they need.
Drive traversal with ScopeWalker, which maintains the scope
automatically and calls these methods with the current context.
§Example
use php_ast::visitor::{ScopeVisitor, ScopeWalker, Scope};
use php_ast::ast::*;
use std::ops::ControlFlow;
struct MethodCollector { methods: Vec<String> }
impl<'arena, 'src> ScopeVisitor<'arena, 'src> for MethodCollector {
fn visit_class_member(
&mut self,
member: &ClassMember<'arena, 'src>,
scope: &Scope<'src>,
) -> ControlFlow<()> {
if let ClassMemberKind::Method(m) = &member.kind {
self.methods.push(format!(
"{}::{}",
scope.class_name.unwrap_or("<anon>"),
m.name
));
}
ControlFlow::Continue(())
}
}