pub trait AstVisitor: Sized {
Show 45 methods
// Provided methods
fn visit(&mut self, node: &AstNode) { ... }
fn visit_statement_list(&mut self, stmts: &[AstNode]) { ... }
fn visit_compilation_unit(&mut self, unit: &CompilationUnit) { ... }
fn visit_implementation(&mut self, implementation: &Implementation) { ... }
fn visit_variable_block(&mut self, block: &VariableBlock) { ... }
fn visit_variable(&mut self, variable: &Variable) { ... }
fn visit_config_variable(&mut self, config_variable: &ConfigVariable) { ... }
fn visit_interface(&mut self, interface: &Interface) { ... }
fn visit_property(&mut self, property: &PropertyBlock) { ... }
fn visit_enum_element(&mut self, element: &AstNode) { ... }
fn visit_data_type_declaration(
&mut self,
data_type_declaration: &DataTypeDeclaration,
) { ... }
fn visit_user_type_declaration(&mut self, user_type: &UserTypeDeclaration) { ... }
fn visit_data_type(&mut self, data_type: &DataType) { ... }
fn visit_pou(&mut self, pou: &Pou) { ... }
fn visit_empty_statement(&mut self, _stmt: &EmptyStatement, _node: &AstNode) { ... }
fn visit_default_value(&mut self, _stmt: &DefaultValue, _node: &AstNode) { ... }
fn visit_literal(&mut self, stmt: &AstLiteral, _node: &AstNode) { ... }
fn visit_multiplied_statement(
&mut self,
stmt: &MultipliedStatement,
_node: &AstNode,
) { ... }
fn visit_reference_expr(&mut self, stmt: &ReferenceExpr, _node: &AstNode) { ... }
fn visit_identifier(&mut self, _stmt: &str, _node: &AstNode) { ... }
fn visit_direct_access(&mut self, stmt: &DirectAccess, _node: &AstNode) { ... }
fn visit_hardware_access(&mut self, stmt: &HardwareAccess, _node: &AstNode) { ... }
fn visit_binary_expression(
&mut self,
stmt: &BinaryExpression,
_node: &AstNode,
) { ... }
fn visit_unary_expression(
&mut self,
stmt: &UnaryExpression,
_node: &AstNode,
) { ... }
fn visit_expression_list(&mut self, stmt: &Vec<AstNode>, _node: &AstNode) { ... }
fn visit_paren_expression(&mut self, inner: &AstNode, _node: &AstNode) { ... }
fn visit_range_statement(&mut self, stmt: &RangeStatement, _node: &AstNode) { ... }
fn visit_vla_range_statement(&mut self, _node: &AstNode) { ... }
fn visit_assignment(&mut self, stmt: &Assignment, _node: &AstNode) { ... }
fn visit_output_assignment(&mut self, stmt: &Assignment, _node: &AstNode) { ... }
fn visit_ref_assignment(&mut self, stmt: &Assignment, _node: &AstNode) { ... }
fn visit_call_statement(&mut self, stmt: &CallStatement, _node: &AstNode) { ... }
fn visit_control_statement(
&mut self,
stmt: &AstControlStatement,
node: &AstNode,
) { ... }
fn visit_for_loop_statement(
&mut self,
stmt: &ForLoopStatement,
_node: &AstNode,
) { ... }
fn visit_while_loop_statement(
&mut self,
stmt: &LoopStatement,
_node: &AstNode,
) { ... }
fn visit_repeat_loop_statement(
&mut self,
stmt: &LoopStatement,
_node: &AstNode,
) { ... }
fn visit_case_condition(&mut self, child: &AstNode, _node: &AstNode) { ... }
fn visit_exit_statement(&mut self, _node: &AstNode) { ... }
fn visit_continue_statement(&mut self, _node: &AstNode) { ... }
fn visit_return_statement(
&mut self,
stmt: &ReturnStatement,
_node: &AstNode,
) { ... }
fn visit_jump_statement(&mut self, stmt: &JumpStatement, _node: &AstNode) { ... }
fn visit_label_statement(&mut self, _stmt: &LabelStatement, _node: &AstNode) { ... }
fn visit_allocation(&mut self, _stmt: &Allocation, _node: &AstNode) { ... }
fn visit_super(&mut self, _stmt: &AstStatement, _node: &AstNode) { ... }
fn visit_this(&mut self, _stmt: &AstStatement, _node: &AstNode) { ... }
}Expand description
The AstVisitor trait provides a set of methods for visiting different types of AST nodes.
Implementors can individually override the methods they are interested in. When overriding a method,
make sure to call walk on the visited statement to visit its children. DO NOT call walk on
the node itself to avoid a recursion (last parameter). Implementors may also decide to not call
the statement’s walk method to avoid visiting the children of the statement.
The visitor offers strongly typed visit_X functions for every node type. The function’s signature
is fn visit_X(&mut self, stmt: &X, node: &AstNode). The stmt parameter is the unwrapped, typed
node and the node parameter is the AstNode wrapping the stmt. The AstNode node offers access to location
information and the AstId. Note that some nodes are not wrapped in an AstNode node (e.g. CompilationUnit)
and therefore only the strongly typed node is passed to the visit_X function.
§Example
use plc_ast::{
ast::{Assignment, AstNode},
visitor::{AstVisitor, Walker},
};
struct AssignmentCounter {
count: usize,
}
impl AstVisitor for AssignmentCounter {
fn visit_assignment(&mut self, stmt: &Assignment, _node: &AstNode) {
self.count += 1;
// visit child nodes
stmt.walk(self);
}
fn visit_output_assignment(&mut self, stmt: &Assignment, _node: &AstNode) {
self.count += 1;
// visit child nodes
stmt.walk(self);
}
}Provided Methods§
Sourcefn visit(&mut self, node: &AstNode)
fn visit(&mut self, node: &AstNode)
Visits this AstNode. The default implementation calls the walk method on the node
and will eventually call the strongly typed visit method for the node (e.g. visit_assignment
if the node is an AstStatement::Assignment).
§Arguments
node- TheAstNodenode to visit.
Sourcefn visit_statement_list(&mut self, stmts: &[AstNode])
fn visit_statement_list(&mut self, stmts: &[AstNode])
Called when visiting a list of statements (e.g. implementation bodies, control flow branches). Override this to intercept statement-list processing.
Sourcefn visit_compilation_unit(&mut self, unit: &CompilationUnit)
fn visit_compilation_unit(&mut self, unit: &CompilationUnit)
Visits a CompilationUnit node.
Make sure to call walk on the CompilationUnit node to visit its children.
§Arguments
unit- The unwraped, typedCompilationUnitnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_implementation(&mut self, implementation: &Implementation)
fn visit_implementation(&mut self, implementation: &Implementation)
Visits an Implementation node.
Make sure to call walk on the Implementation node to visit its children.
§Arguments
implementation- The unwraped, typedImplementationnode to visit.
Sourcefn visit_variable_block(&mut self, block: &VariableBlock)
fn visit_variable_block(&mut self, block: &VariableBlock)
Visits a DataTypeDeclaration node.
Make sure to call walk on the VariableBlock node to visit its children.
§Arguments
block- The unwraped, typedVariableBlocknode to visit.
Sourcefn visit_variable(&mut self, variable: &Variable)
fn visit_variable(&mut self, variable: &Variable)
Visits a Variable node.
Make sure to call walk on the Variable node to visit its children.
§Arguments
variable- The unwraped, typedVariablenode to visit.
Sourcefn visit_config_variable(&mut self, config_variable: &ConfigVariable)
fn visit_config_variable(&mut self, config_variable: &ConfigVariable)
Visits a ConfigVariable node.
Make sure to call walk on the ConfigVariable node to visit its children.
§Arguments
variable- The unwraped, typedVariablenode to visit.
Sourcefn visit_interface(&mut self, interface: &Interface)
fn visit_interface(&mut self, interface: &Interface)
Visits a Interface.
Make sure to call walk on the Interface to visit its children.
§Arguments
interface- The unwraped, typedInterfacenode to visit.
Sourcefn visit_property(&mut self, property: &PropertyBlock)
fn visit_property(&mut self, property: &PropertyBlock)
Visits a Property.
Make sure to call walk on the PropertyBlock to visit its children.
Sourcefn visit_enum_element(&mut self, element: &AstNode)
fn visit_enum_element(&mut self, element: &AstNode)
Visits an enum element AstNode node.
Make sure to call walk on the AstNode node to visit its children.
§Arguments
element- The unwraped, typedAstNodenode to visit.
Sourcefn visit_data_type_declaration(
&mut self,
data_type_declaration: &DataTypeDeclaration,
)
fn visit_data_type_declaration( &mut self, data_type_declaration: &DataTypeDeclaration, )
Visits a DataTypeDeclaration node.
Make sure to call walk on the DataTypeDeclaration node to visit its children.
§Arguments
data_type_declaration- The unwraped, typedDataTypeDeclarationnode to visit.
Sourcefn visit_user_type_declaration(&mut self, user_type: &UserTypeDeclaration)
fn visit_user_type_declaration(&mut self, user_type: &UserTypeDeclaration)
Visits a UserTypeDeclaration node.
Make sure to call walk on the UserTypeDeclaration node to visit its children.
§Arguments
user_type- The unwraped, typedUserTypeDeclarationnode to visit.
Sourcefn visit_data_type(&mut self, data_type: &DataType)
fn visit_data_type(&mut self, data_type: &DataType)
Visits a UserTypeDeclaration node.
Make sure to call walk on the DataType node to visit its children.
§Arguments
data_type- The unwraped, typedDataTypenode to visit.
Sourcefn visit_pou(&mut self, pou: &Pou)
fn visit_pou(&mut self, pou: &Pou)
Visits a Pou node.
Make sure to call walk on the Pou node to visit its children.
§Arguments
pou- The unwraped, typedPounode to visit.
Sourcefn visit_empty_statement(&mut self, _stmt: &EmptyStatement, _node: &AstNode)
fn visit_empty_statement(&mut self, _stmt: &EmptyStatement, _node: &AstNode)
Visits an EmptyStatement node.
§Arguments
stmt- The unwraped, typedEmptyStatementnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_default_value(&mut self, _stmt: &DefaultValue, _node: &AstNode)
fn visit_default_value(&mut self, _stmt: &DefaultValue, _node: &AstNode)
Visits a DefaultValue node.
§Arguments
stmt- The unwraped, typedDefaultValuenode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_literal(&mut self, stmt: &AstLiteral, _node: &AstNode)
fn visit_literal(&mut self, stmt: &AstLiteral, _node: &AstNode)
Visits an AstLiteral node.
Make sure to call walk on the AstLiteral node to visit its children.
§Arguments
stmt- The unwraped, typedAstLiteralnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_multiplied_statement(
&mut self,
stmt: &MultipliedStatement,
_node: &AstNode,
)
fn visit_multiplied_statement( &mut self, stmt: &MultipliedStatement, _node: &AstNode, )
Visits a MultipliedStatement node.
Make sure to call walk on the MultipliedStatement node to visit its children.
§Arguments
stmt- The unwraped, typedMultipliedStatementnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_reference_expr(&mut self, stmt: &ReferenceExpr, _node: &AstNode)
fn visit_reference_expr(&mut self, stmt: &ReferenceExpr, _node: &AstNode)
Visits a ReferenceExpr node.
Make sure to call walk on the ReferenceExpr node to visit its children.
§Arguments
stmt- The unwraped, typedReferenceExprnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_identifier(&mut self, _stmt: &str, _node: &AstNode)
fn visit_identifier(&mut self, _stmt: &str, _node: &AstNode)
Visits an Identifier node.
Make sure to call walk on the Identifier node to visit its children.
§Arguments
stmt- The unwraped, typedIdentifiernode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_direct_access(&mut self, stmt: &DirectAccess, _node: &AstNode)
fn visit_direct_access(&mut self, stmt: &DirectAccess, _node: &AstNode)
Visits a DirectAccess node.
Make sure to call walk on the DirectAccess node to visit its children.
§Arguments
stmt- The unwraped, typedDirectAccessnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_hardware_access(&mut self, stmt: &HardwareAccess, _node: &AstNode)
fn visit_hardware_access(&mut self, stmt: &HardwareAccess, _node: &AstNode)
Visits a HardwareAccess node.
Make sure to call walk on the HardwareAccess node to visit its children.
§Arguments
stmt- The unwraped, typedHardwareAccessnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_binary_expression(&mut self, stmt: &BinaryExpression, _node: &AstNode)
fn visit_binary_expression(&mut self, stmt: &BinaryExpression, _node: &AstNode)
Visits a BinaryExpression node.
Make sure to call walk on the BinaryExpression node to visit its children.
§Arguments
stmt- The unwraped, typedBinaryExpressionnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_unary_expression(&mut self, stmt: &UnaryExpression, _node: &AstNode)
fn visit_unary_expression(&mut self, stmt: &UnaryExpression, _node: &AstNode)
Visits a UnaryExpression node.
Make sure to call walk on the UnaryExpression node to visit its children.
§Arguments
stmt- The unwraped, typedUnaryExpressionnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_expression_list(&mut self, stmt: &Vec<AstNode>, _node: &AstNode)
fn visit_expression_list(&mut self, stmt: &Vec<AstNode>, _node: &AstNode)
Visits an ExpressionList node.
Make sure to call walk on the Vec<AstNode> node to visit its children.
§Arguments
stmt- The unwraped, typedExpressionListnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_paren_expression(&mut self, inner: &AstNode, _node: &AstNode)
fn visit_paren_expression(&mut self, inner: &AstNode, _node: &AstNode)
Visits a ParenExpression node.
Make sure to call walk on the inner AstNode node to visit its children.
§Arguments
inner- The unwraped, typed innerAstNodenode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_range_statement(&mut self, stmt: &RangeStatement, _node: &AstNode)
fn visit_range_statement(&mut self, stmt: &RangeStatement, _node: &AstNode)
Visits a RangeStatement node.
Make sure to call walk on the RangeStatement node to visit its children.
§Arguments
stmt- The unwraped, typedRangeStatementnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_vla_range_statement(&mut self, _node: &AstNode)
fn visit_vla_range_statement(&mut self, _node: &AstNode)
Visits a VlaRangeStatement node.
§Arguments
node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_assignment(&mut self, stmt: &Assignment, _node: &AstNode)
fn visit_assignment(&mut self, stmt: &Assignment, _node: &AstNode)
Visits an Assignment node.
Make sure to call walk on the Assignment node to visit its children.
§Arguments
stmt- The unwraped, typedAssignmentnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_output_assignment(&mut self, stmt: &Assignment, _node: &AstNode)
fn visit_output_assignment(&mut self, stmt: &Assignment, _node: &AstNode)
Visits an OutputAssignment node.
Make sure to call walk on the Assignment node to visit its children.
§Arguments
stmt- The unwraped, typedAssignmentnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_ref_assignment(&mut self, stmt: &Assignment, _node: &AstNode)
fn visit_ref_assignment(&mut self, stmt: &Assignment, _node: &AstNode)
Visits an RefAssignment node.
Make sure to call walk on the Assignment node to visit its children.
§Arguments
stmt- The unwraped, typedAssignmentnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_call_statement(&mut self, stmt: &CallStatement, _node: &AstNode)
fn visit_call_statement(&mut self, stmt: &CallStatement, _node: &AstNode)
Visits a CallStatement node.
Make sure to call walk on the CallStatement node to visit its children.
§Arguments
stmt- The unwraped, typedCallStatementnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_control_statement(
&mut self,
stmt: &AstControlStatement,
node: &AstNode,
)
fn visit_control_statement( &mut self, stmt: &AstControlStatement, node: &AstNode, )
Visits an AstControlStatement node.
Make sure to call walk on the AstControlStatement node to visit its children.
§Arguments
stmt- The unwraped, typedAstControlStatementnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_for_loop_statement(&mut self, stmt: &ForLoopStatement, _node: &AstNode)
fn visit_for_loop_statement(&mut self, stmt: &ForLoopStatement, _node: &AstNode)
Visits a ForLoop control statement.
§Arguments
stmt- The unwraped, typedForLoopStatementnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_while_loop_statement(&mut self, stmt: &LoopStatement, _node: &AstNode)
fn visit_while_loop_statement(&mut self, stmt: &LoopStatement, _node: &AstNode)
Visits a WhileLoop control statement.
Make sure to call walk on the LoopStatement node to visit its children.
§Arguments
stmt- The unwraped, typedLoopStatementnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_repeat_loop_statement(&mut self, stmt: &LoopStatement, _node: &AstNode)
fn visit_repeat_loop_statement(&mut self, stmt: &LoopStatement, _node: &AstNode)
Visits a RepeatLoop control statement.
Make sure to call walk on the LoopStatement node to visit its children.
§Arguments
stmt- The unwraped, typedLoopStatementnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_case_condition(&mut self, child: &AstNode, _node: &AstNode)
fn visit_case_condition(&mut self, child: &AstNode, _node: &AstNode)
Visits a CaseCondition node.
Make sure to call walk on the child-AstNode node to visit its children.
§Arguments
stmt- The unwraped, typedCaseConditionnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_exit_statement(&mut self, _node: &AstNode)
fn visit_exit_statement(&mut self, _node: &AstNode)
Visits an ExitStatement node.
§Arguments
node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_continue_statement(&mut self, _node: &AstNode)
fn visit_continue_statement(&mut self, _node: &AstNode)
Visits a ContinueStatement node.
§Arguments
node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_return_statement(&mut self, stmt: &ReturnStatement, _node: &AstNode)
fn visit_return_statement(&mut self, stmt: &ReturnStatement, _node: &AstNode)
Visits a ReturnStatement node.
Make sure to call walk on the ReturnStatement node to visit its children.
§Arguments
stmt- The unwraped, typedReturnStatementnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_jump_statement(&mut self, stmt: &JumpStatement, _node: &AstNode)
fn visit_jump_statement(&mut self, stmt: &JumpStatement, _node: &AstNode)
Visits a JumpStatement node.
Make sure to call walk on the JumpStatement node to visit its children.
§Arguments
stmt- The unwraped, typedJumpStatementnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_label_statement(&mut self, _stmt: &LabelStatement, _node: &AstNode)
fn visit_label_statement(&mut self, _stmt: &LabelStatement, _node: &AstNode)
Visits a LabelStatement node.
§Arguments
stmt- The unwraped, typedLabelStatementnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_allocation(&mut self, _stmt: &Allocation, _node: &AstNode)
fn visit_allocation(&mut self, _stmt: &Allocation, _node: &AstNode)
Visits an Allocation node
§Arguments
stmt- The unwraped, typedAllocationnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_super(&mut self, _stmt: &AstStatement, _node: &AstNode)
fn visit_super(&mut self, _stmt: &AstStatement, _node: &AstNode)
Visits a Super node.
§Arguments
stmt- The unwraped, typedSupernode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Sourcefn visit_this(&mut self, _stmt: &AstStatement, _node: &AstNode)
fn visit_this(&mut self, _stmt: &AstStatement, _node: &AstNode)
Visits a This node.
§Arguments
stmt- The unwraped, typedThisnode to visit.node- The wrappedAstNodenode to visit. Offers access to location information and AstId
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.