Skip to main content

ScopeWalker

Struct ScopeWalker 

Source
pub struct ScopeWalker<'src, V> { /* private fields */ }
Expand description

Drives a ScopeVisitor over an AST, maintaining Scope automatically.

ScopeWalker wraps a ScopeVisitor and tracks the lexical scope as it descends the tree, updating scope before visiting children and restoring it on exit from scope-defining nodes (functions, classes, namespaces).

§Usage

let arena = bumpalo::Bump::new();
let src = "<?php class Foo { public function bar() {} }";
let program = parse(&arena, src);
let mut walker = ScopeWalker::new(MyVisitor);
walker.walk(&program);
let _my_visitor = walker.into_inner();

Implementations§

Source§

impl<'src, V> ScopeWalker<'src, V>

Source

pub fn new(inner: V) -> Self

Creates a new ScopeWalker wrapping inner.

Source

pub fn into_inner(self) -> V

Consumes the walker and returns the inner visitor.

Source

pub fn inner(&self) -> &V

Returns a reference to the inner visitor.

Source

pub fn inner_mut(&mut self) -> &mut V

Returns a mutable reference to the inner visitor.

Source§

impl<'arena, 'src, V: ScopeVisitor<'arena, 'src>> ScopeWalker<'src, V>

Source

pub fn walk(&mut self, program: &Program<'arena, 'src>) -> ControlFlow<()>

Walks program, calling ScopeVisitor methods with scope context.

Trait Implementations§

Source§

impl<'arena, 'src, V: ScopeVisitor<'arena, 'src>> Visitor<'arena, 'src> for ScopeWalker<'src, V>

Source§

fn visit_program(&mut self, program: &Program<'arena, 'src>) -> ControlFlow<()>

Source§

fn visit_stmt(&mut self, stmt: &Stmt<'arena, 'src>) -> ControlFlow<()>

Source§

fn visit_expr(&mut self, expr: &Expr<'arena, 'src>) -> ControlFlow<()>

Source§

fn visit_class_member( &mut self, member: &ClassMember<'arena, 'src>, ) -> ControlFlow<()>

Source§

fn visit_enum_member( &mut self, member: &EnumMember<'arena, 'src>, ) -> ControlFlow<()>

Source§

fn visit_param(&mut self, param: &Param<'arena, 'src>) -> ControlFlow<()>

Source§

fn visit_arg(&mut self, arg: &Arg<'arena, 'src>) -> ControlFlow<()>

Source§

fn visit_property_hook( &mut self, hook: &PropertyHook<'arena, 'src>, ) -> ControlFlow<()>

Source§

fn visit_type_hint( &mut self, type_hint: &TypeHint<'arena, 'src>, ) -> ControlFlow<()>

Source§

fn visit_attribute( &mut self, attribute: &Attribute<'arena, 'src>, ) -> ControlFlow<()>

Source§

fn visit_catch_clause( &mut self, catch: &CatchClause<'arena, 'src>, ) -> ControlFlow<()>

Source§

fn visit_match_arm(&mut self, arm: &MatchArm<'arena, 'src>) -> ControlFlow<()>

Source§

fn visit_closure_use_var( &mut self, var: &ClosureUseVar<'src>, ) -> ControlFlow<()>

Auto Trait Implementations§

§

impl<'src, V> Freeze for ScopeWalker<'src, V>
where V: Freeze,

§

impl<'src, V> RefUnwindSafe for ScopeWalker<'src, V>
where V: RefUnwindSafe,

§

impl<'src, V> Send for ScopeWalker<'src, V>
where V: Send,

§

impl<'src, V> Sync for ScopeWalker<'src, V>
where V: Sync,

§

impl<'src, V> Unpin for ScopeWalker<'src, V>
where V: Unpin,

§

impl<'src, V> UnsafeUnpin for ScopeWalker<'src, V>
where V: UnsafeUnpin,

§

impl<'src, V> UnwindSafe for ScopeWalker<'src, V>
where V: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.