Skip to main content

Module visitor

Module visitor 

Source
Expand description

Visitor infrastructure for owned (lifetime-free) PHP AST traversal.

This module mirrors crate::visitor but operates on the owned AST types in crate::owned rather than the arena-allocated types. Use it after calling [php_rs_parser::parse()] — no arena or lifetime management needed.

§Example

use php_ast::owned::visitor::{OwnedVisitor, walk_owned_expr};
use php_ast::owned::{Expr, ExprKind};
use std::ops::ControlFlow;

struct VarCounter { count: usize }

impl OwnedVisitor for VarCounter {
    fn visit_expr(&mut self, expr: &Expr) -> ControlFlow<()> {
        if matches!(&expr.kind, ExprKind::Variable(_)) {
            self.count += 1;
        }
        walk_owned_expr(self, expr)
    }
}

Structs§

OwnedScope
Lexical scope context for owned AST traversal.
OwnedScopeWalker
Drives an OwnedScopeVisitor over an owned AST, maintaining OwnedScope automatically.

Traits§

OwnedScopeVisitor
A scope-aware variant of OwnedVisitor.
OwnedVisitor
Visitor trait for immutable traversal of owned (lifetime-free) AST nodes.

Functions§

walk_owned_arg
Visits the value expression of a call argument.
walk_owned_attribute
Visits an attribute’s name and argument expressions.
walk_owned_block
Dispatches stmt to the appropriate child visitors based on its StmtKind.
walk_owned_catch_clause
Visits a catch clause’s type names and body statements.
walk_owned_class_member
Dispatches a class member to its child visitors.
walk_owned_comments
Calls OwnedVisitor::visit_comment for each comment in comments.
walk_owned_enum_member
Dispatches an enum member to its child visitors.
walk_owned_expr
Dispatches expr to the appropriate child visitors based on its ExprKind.
walk_owned_match_arm
Visits a match arm’s condition expressions and body expression.
walk_owned_name
Calls OwnedVisitor::visit_name on name.
walk_owned_param
Visits a function/method parameter’s attributes, type hint, default, and hooks.
walk_owned_program
Visits every top-level statement in program.
walk_owned_property_hook
Visits a property hook’s attributes, parameters, and body.
walk_owned_stmt
walk_owned_trait_use
Visits a trait use declaration’s names and adaptations.
walk_owned_type_hint
Visits the inner types of a type hint.