pub struct StatementVisitor<'a> {
context: &'a mut CompilationContext,
current_return_type: Option<TypeId>,
}
Expand description
Handles semantic analysis for all statement types
This visitor is responsible for analyzing statement-level constructs including function declarations, variable declarations, assignments, return statements, type definitions, and control flow statements.
Fields§
§context: &'a mut CompilationContext
§current_return_type: Option<TypeId>
Implementations§
Source§impl<'a> StatementVisitor<'a>
impl<'a> StatementVisitor<'a>
Sourcepub fn new(context: &'a mut CompilationContext) -> Self
pub fn new(context: &'a mut CompilationContext) -> Self
Sourcepub fn with_return_type(
context: &'a mut CompilationContext,
return_type: Option<TypeId>,
) -> Self
pub fn with_return_type( context: &'a mut CompilationContext, return_type: Option<TypeId>, ) -> Self
Create a new statement visitor with an inherited return type context
§Arguments
context
- The compilation context for symbol managementreturn_type
- The current function’s return type for context inheritance
Sourcepub fn set_return_type(&mut self, return_type: Option<TypeId>)
pub fn set_return_type(&mut self, return_type: Option<TypeId>)
Set the current return type for function analysis
This is used when analyzing function bodies to validate return statements
Sourcepub fn current_return_type(&self) -> Option<&TypeId>
pub fn current_return_type(&self) -> Option<&TypeId>
Get the current return type
Sourcepub fn visit_function_declaration(
&mut self,
fn_decl: &FunctionDeclarationStmt,
) -> SemanticResult
pub fn visit_function_declaration( &mut self, fn_decl: &FunctionDeclarationStmt, ) -> SemanticResult
Visit a function declaration statement
Sourcepub fn visit_return_statement(
&mut self,
return_stmt: &ReturnStatement,
) -> SemanticResult
pub fn visit_return_statement( &mut self, return_stmt: &ReturnStatement, ) -> SemanticResult
Visit a return statement
Sourcepub fn visit_let_statement(&mut self, let_stmt: &LetStatement) -> SemanticResult
pub fn visit_let_statement(&mut self, let_stmt: &LetStatement) -> SemanticResult
Visit a let statement
Sourcepub fn visit_assignment_statement(
&mut self,
assign_stmt: &AssignmentStatement,
) -> SemanticResult
pub fn visit_assignment_statement( &mut self, assign_stmt: &AssignmentStatement, ) -> SemanticResult
Visit an assignment statement
Sourcepub fn visit_type_definition_statement(
&mut self,
type_def: &TypeDefinitionStmt,
) -> SemanticResult
pub fn visit_type_definition_statement( &mut self, type_def: &TypeDefinitionStmt, ) -> SemanticResult
Visit a type definition statement
Sourcepub fn visit_expression_statement(
&mut self,
expr: &Expression,
) -> SemanticResult
pub fn visit_expression_statement( &mut self, expr: &Expression, ) -> SemanticResult
Visit an expression statement
Sourcepub fn visit_if_statement(&mut self, if_stmt: &IfStatement) -> SemanticResult
pub fn visit_if_statement(&mut self, if_stmt: &IfStatement) -> SemanticResult
Visit an if statement
fn resolve_variable(&self, name: &str) -> Option<&Symbol>
fn check_return_expr_type_internal( &mut self, expr: &Expression, expected_type: &TypeId, location: &Location, ) -> SemanticResult
fn determine_let_statement_type( &mut self, let_stmt: &LetStatement, expr_type: TypeId, ) -> SemanticResult
fn visit_expression(&mut self, expr: &Expression) -> SemanticResult
fn visit_block_expression(&mut self, block: &BlockExpr) -> SemanticResult
fn analyze_function_body(&mut self, body: &BlockExpr) -> SemanticResult
Auto Trait Implementations§
impl<'a> Freeze for StatementVisitor<'a>
impl<'a> RefUnwindSafe for StatementVisitor<'a>
impl<'a> Send for StatementVisitor<'a>
impl<'a> Sync for StatementVisitor<'a>
impl<'a> Unpin for StatementVisitor<'a>
impl<'a> !UnwindSafe for StatementVisitor<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more