Struct StatementVisitor

Source
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>

Source

pub fn new(context: &'a mut CompilationContext) -> Self

Create a new statement visitor

§Arguments
  • context - The compilation context for symbol management
Source

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 management
  • return_type - The current function’s return type for context inheritance
Source

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

Source

pub fn current_return_type(&self) -> Option<&TypeId>

Get the current return type

Source

pub fn visit_function_declaration( &mut self, fn_decl: &FunctionDeclarationStmt, ) -> SemanticResult

Visit a function declaration statement

Source

pub fn visit_return_statement( &mut self, return_stmt: &ReturnStatement, ) -> SemanticResult

Visit a return statement

Source

pub fn visit_let_statement(&mut self, let_stmt: &LetStatement) -> SemanticResult

Visit a let statement

Source

pub fn visit_assignment_statement( &mut self, assign_stmt: &AssignmentStatement, ) -> SemanticResult

Visit an assignment statement

Source

pub fn visit_type_definition_statement( &mut self, type_def: &TypeDefinitionStmt, ) -> SemanticResult

Visit a type definition statement

Source

pub fn visit_expression_statement( &mut self, expr: &Expression, ) -> SemanticResult

Visit an expression statement

Source

pub fn visit_if_statement(&mut self, if_stmt: &IfStatement) -> SemanticResult

Visit an if statement

Source

fn resolve_variable(&self, name: &str) -> Option<&Symbol>

Source

fn check_return_expr_type_internal( &mut self, expr: &Expression, expected_type: &TypeId, location: &Location, ) -> SemanticResult

Source

fn determine_let_statement_type( &mut self, let_stmt: &LetStatement, expr_type: TypeId, ) -> SemanticResult

Source

fn visit_expression(&mut self, expr: &Expression) -> SemanticResult

Source

fn visit_block_expression(&mut self, block: &BlockExpr) -> SemanticResult

Source

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> 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.