pub enum Statement {
Show 15 variants
Declaration(Box<VariableDecl>),
Expression(Box<Expression>),
If(IfStatement),
Return(ReturnStatement),
Goto(GotoStatement),
Labeled(LabeledStatement),
Compound(CompoundStatement),
Switch(SwitchStatement),
For(Box<ForStatement>),
While(WhileStatement),
DoWhile(DoWhileStatement),
Break(BreakStatement),
Continue(ContinueStatement),
Preprocessor(PreprocessorDirective),
Comment(Comment),
}Variants§
Declaration(Box<VariableDecl>)
Expression(Box<Expression>)
If(IfStatement)
Return(ReturnStatement)
Goto(GotoStatement)
Labeled(LabeledStatement)
Compound(CompoundStatement)
Switch(SwitchStatement)
For(Box<ForStatement>)
While(WhileStatement)
DoWhile(DoWhileStatement)
Break(BreakStatement)
Continue(ContinueStatement)
Preprocessor(PreprocessorDirective)
Comment(Comment)
Implementations§
Source§impl Statement
impl Statement
Sourcepub fn walk<'s, F>(&'s self, f: &mut F)where
F: FnMut(&'s Self),
pub fn walk<'s, F>(&'s self, f: &mut F)where
F: FnMut(&'s Self),
Recursively visit all nested statements. The closure receives a
&'s Statement tied to self’s lifetime, so references extracted
inside the closure can be stored in an outer Vec<&'s T>.
Sourcepub fn for_each_child_block<F>(&self, f: F)where
F: FnMut(&[Self]),
pub fn for_each_child_block<F>(&self, f: F)where
F: FnMut(&[Self]),
Call f with each immediate child block (a &[Statement] slice) of
this statement. Covers all container variants exhaustively; leaf
variants produce no calls. Use this instead of a manual match when
you need to apply a slice-level operation (e.g. pair detection) to
every nested body.
Sourcepub fn visit_expressions<'s>(&'s self, f: &mut impl FnMut(&'s Expression))
pub fn visit_expressions<'s>(&'s self, f: &mut impl FnMut(&'s Expression))
Visit all direct expressions contained in this statement (non-recursive). Includes conditions, initialisers, and all other expressions that are immediate children of this statement node. Zero-allocation alternative to collecting into a Vec.
pub fn location(&self) -> &SourceLocation
Sourcepub fn walk_expressions<'s, F>(&'s self, f: &mut F)where
F: FnMut(&'s Expression),
pub fn walk_expressions<'s, F>(&'s self, f: &mut F)where
F: FnMut(&'s Expression),
Recursively walk all expressions in this statement tree.
Visits the direct expression of each statement (not sub-expressions —
call Expression::walk on the result if you need nested expressions).
Sourcepub fn iter_switches<'s>(
&'s self,
) -> impl Iterator<Item = &'s SwitchStatement> + 's
pub fn iter_switches<'s>( &'s self, ) -> impl Iterator<Item = &'s SwitchStatement> + 's
Iterator over all switch statements in this statement tree (recursive)
Sourcepub fn iter_if_statements<'s>(
&'s self,
) -> impl Iterator<Item = &'s IfStatement> + 's
pub fn iter_if_statements<'s>( &'s self, ) -> impl Iterator<Item = &'s IfStatement> + 's
Iterator over all if statements in this statement tree (recursive)
Sourcepub fn iter_declarations<'s>(
&'s self,
) -> impl Iterator<Item = &'s VariableDecl> + 's
pub fn iter_declarations<'s>( &'s self, ) -> impl Iterator<Item = &'s VariableDecl> + 's
Iterator over all variable declarations in this statement tree (recursive)
Sourcepub fn iter_returns<'s>(
&'s self,
) -> impl Iterator<Item = &'s ReturnStatement> + 's
pub fn iter_returns<'s>( &'s self, ) -> impl Iterator<Item = &'s ReturnStatement> + 's
Iterator over all return statements in this statement tree (recursive)
Sourcepub fn iter_assignments<'s>(
&'s self,
) -> impl Iterator<Item = &'s Assignment> + 's
pub fn iter_assignments<'s>( &'s self, ) -> impl Iterator<Item = &'s Assignment> + 's
Iterator over all top-level assignment statements in this statement tree (recursive). Only yields assignments that are the entire expression statement, not assignments nested inside other expressions.
Sourcepub fn iter_calls<'s>(&'s self) -> impl Iterator<Item = &'s CallExpression> + 's
pub fn iter_calls<'s>(&'s self) -> impl Iterator<Item = &'s CallExpression> + 's
Iterator over all call expressions in this statement tree (recursive). Includes calls at all nesting levels within expressions (e.g. nested arguments).
Sourcepub fn extract_call(&self) -> Option<&CallExpression>
pub fn extract_call(&self) -> Option<&CallExpression>
Extract the call expression if this is an expression statement with a call
Sourcepub fn is_assignment_to<F>(&self, target_var: &str, value_check: F) -> bool
pub fn is_assignment_to<F>(&self, target_var: &str, value_check: F) -> bool
Check if this statement assigns a value matching the predicate to the target variable
Sourcepub fn extract_assignment(&self) -> Option<&Assignment>
pub fn extract_assignment(&self) -> Option<&Assignment>
Extract the assignment expression if this is an assignment statement
Sourcepub fn is_null_assignment_to(&self, var_name: &str) -> bool
pub fn is_null_assignment_to(&self, var_name: &str) -> bool
Check if this statement assigns NULL to the target variable
Sourcepub fn for_each_pair<F>(statements: &[Self], f: F)where
F: FnMut(&Self, &Self),
pub fn for_each_pair<F>(statements: &[Self], f: F)where
F: FnMut(&Self, &Self),
Iterate over consecutive pairs of statements (skipping comments)
Sourcepub fn for_each_triple<F>(statements: &[Self], f: F)where
F: FnMut(&Self, &Self, &Self),
pub fn for_each_triple<F>(statements: &[Self], f: F)where
F: FnMut(&Self, &Self, &Self),
Iterate over consecutive triples of statements (skipping comments)
Sourcepub fn walk_pairs<F>(stmts: &[Self], f: &mut F)where
F: FnMut(&Self, &Self),
pub fn walk_pairs<F>(stmts: &[Self], f: &mut F)where
F: FnMut(&Self, &Self),
Recursively visit consecutive pairs of statements at every nesting level (if bodies, else bodies, compound blocks, loops, switch cases, labeled statements). Comments are skipped so they don’t break pair detection.
Sourcepub fn walk_triples<F>(stmts: &[Self], f: &mut F)where
F: FnMut(&Self, &Self, &Self),
pub fn walk_triples<F>(stmts: &[Self], f: &mut F)where
F: FnMut(&Self, &Self, &Self),
Recursively visit consecutive triples of statements at every nesting level. Comments are skipped so they don’t break triple detection.