Struct TypeChecker

pub struct TypeChecker {
    pub metadata: AstMetadata,
    pub symbols: SymbolTable,
    pub constants: ConstantTable,
    /* private fields */
}
Expand description

The Type Checker holds mutable state necessary for type checking.

Fields§

§metadata: AstMetadata§symbols: SymbolTable§constants: ConstantTable

Implementations§

§

impl TypeChecker

pub fn new(metadata: AstMetadata) -> Self

Creates a new Type Checker.

pub fn current_declaration_scope(&mut self) -> &mut DeclarationScope

The current declaration scope.

pub fn begin_declaration_scope(&mut self)

Starts a new declaration scope.

pub fn end_declaration_scope(&mut self)

Ends the current declaration scope.

pub fn get_data_type(&self, node_id: AstNodeId) -> AstType

Gets a node’s data type

pub fn set_data_type(&mut self, node_id: AstNodeId, data_type: &AstType)

Sets a node’s data type

pub fn set_current_function( &mut self, id: AstNodeId, name: &str, return_type: &AstType, )

Sets the current function.

This is needed when processing a return statement, since we need to know what type the function returns in order to type check the return statement.

pub fn get_current_function(&self) -> (AstNodeId, &str, &AstType)

Gets the current function.

Emits an ICE if set_current_function was not previously called.

pub fn clear_current_function(&mut self)

Clears the current function.

pub fn add_cast( &mut self, target_type: &AstType, inner: Box<AstExpression>, is_implicit: bool, driver: &mut Driver, ) -> AstExpression

Wraps the given AstExpression in a cast to the given target_type.

pub fn add_implicit_cast_if_needed( &mut self, target_type: &AstType, expr: Box<AstExpression>, driver: &mut Driver, ) -> Box<AstExpression>

If the given boxed AstExpression’s type already matches the target_type then the existing expression is returned as-is. Otherwise, wraps the expression in an implicit cast to the target type.

pub fn add_explicit_cast_if_needed( &mut self, target_type: &AstType, expr: Box<AstExpression>, driver: &mut Driver, ) -> Box<AstExpression>

If the given boxed AstExpression’s type already matches the target_type then the existing expression is returned as-is. Otherwise, wraps the expression in an explicit cast to the target type.

Trait Implementations§

§

impl Debug for TypeChecker

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl Default for TypeChecker

§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.