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: ConstantTableImplementations§
§impl TypeChecker
impl TypeChecker
pub fn new(metadata: AstMetadata) -> Self
pub fn new(metadata: AstMetadata) -> Self
Creates a new Type Checker.
pub fn current_declaration_scope(&mut self) -> &mut DeclarationScope
pub fn current_declaration_scope(&mut self) -> &mut DeclarationScope
The current declaration scope.
pub fn begin_declaration_scope(&mut self)
pub fn begin_declaration_scope(&mut self)
Starts a new declaration scope.
pub fn end_declaration_scope(&mut self)
pub fn end_declaration_scope(&mut self)
Ends the current declaration scope.
pub fn get_data_type(&self, node_id: AstNodeId) -> AstType
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)
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,
)
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)
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)
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
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>
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>
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.