pub struct CompilationContext {
type_registry: TypeRegistry,
symbol_table: SymbolTable,
}
Expand description
Compilation context that owns the type registry and symbol table
Fields§
§type_registry: TypeRegistry
The type registry that stores all types
symbol_table: SymbolTable
The symbol table that stores all symbols (variables, types, functions)
Implementations§
Source§impl CompilationContext
impl CompilationContext
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new compilation context with a type registry and symbol table
Initializes the context with all primitive types registered in both the type registry and symbol table. This includes boolean, integer, float, string, and unspecified types.
§Returns
A new CompilationContext instance ready for compilation
Sourcepub fn get_type_info(&self, id: &TypeId) -> Option<&TypeInfo>
pub fn get_type_info(&self, id: &TypeId) -> Option<&TypeInfo>
Sourcepub fn get_type_name(&self, type_id: &TypeId) -> String
pub fn get_type_name(&self, type_id: &TypeId) -> String
Sourcepub fn get_primitive_type_from_id(&self, id: &TypeId) -> Option<PrimitiveType>
pub fn get_primitive_type_from_id(&self, id: &TypeId) -> Option<PrimitiveType>
Sourcepub fn is_primitive_type(&self, id: &TypeId) -> bool
pub fn is_primitive_type(&self, id: &TypeId) -> bool
Sourcepub fn type_fulfills<F>(&self, type_id: &TypeId, predicate: F) -> bool
pub fn type_fulfills<F>(&self, type_id: &TypeId, predicate: F) -> bool
Sourcepub fn is_numeric_type(&self, type_id: &TypeId) -> bool
pub fn is_numeric_type(&self, type_id: &TypeId) -> bool
Sourcepub fn is_integer_type(&self, type_id: &TypeId) -> bool
pub fn is_integer_type(&self, type_id: &TypeId) -> bool
Sourcepub fn is_float_type(&self, type_id: &TypeId) -> bool
pub fn is_float_type(&self, type_id: &TypeId) -> bool
Sourcepub fn is_signed_integer_type(&self, type_id: &TypeId) -> bool
pub fn is_signed_integer_type(&self, type_id: &TypeId) -> bool
Sourcepub fn is_unsigned_integer_type(&self, type_id: &TypeId) -> bool
pub fn is_unsigned_integer_type(&self, type_id: &TypeId) -> bool
Sourcepub fn get_bit_width(&self, type_id: &TypeId) -> u8
pub fn get_bit_width(&self, type_id: &TypeId) -> u8
Sourcepub fn check_value_in_range(&self, value: &i64, type_id: &TypeId) -> bool
pub fn check_value_in_range(&self, value: &i64, type_id: &TypeId) -> bool
Sourcepub fn check_float_value_in_range(&self, value: &f64, type_id: &TypeId) -> bool
pub fn check_float_value_in_range(&self, value: &f64, type_id: &TypeId) -> bool
Sourcepub fn define_symbol(
&mut self,
name: String,
kind: SymbolKind,
type_id: TypeId,
is_mutable: bool,
) -> Result<(), String>
pub fn define_symbol( &mut self, name: String, kind: SymbolKind, type_id: TypeId, is_mutable: bool, ) -> Result<(), String>
Defines a symbol in the symbol table
§Arguments
name
- The name of the symbolkind
- The kind of symbol (variable, type, function)type_id
- The type ID associated with the symbolis_mutable
- Whether the symbol is mutable (only relevant for variables)
§Returns
A Result indicating success or an error message if the symbol cannot be defined
Sourcepub fn lookup_symbol(&self, name: &str) -> Option<&Symbol>
pub fn lookup_symbol(&self, name: &str) -> Option<&Symbol>
Sourcepub fn register_custom_type(
&mut self,
name: &str,
type_kind: TypeKind,
) -> Result<TypeId, String>
pub fn register_custom_type( &mut self, name: &str, type_kind: TypeKind, ) -> Result<TypeId, String>
Sourcepub fn register_struct_type(
&mut self,
name: String,
fields: Vec<(String, TypeId)>,
) -> Result<TypeId, String>
pub fn register_struct_type( &mut self, name: String, fields: Vec<(String, TypeId)>, ) -> Result<TypeId, String>
Sourcepub fn register_function_type(
&mut self,
param_types: Vec<TypeId>,
return_type: TypeId,
) -> TypeId
pub fn register_function_type( &mut self, param_types: Vec<TypeId>, return_type: TypeId, ) -> TypeId
Registers a function type and returns its TypeId
Sourcepub fn is_function_type(&self, type_id: &TypeId) -> bool
pub fn is_function_type(&self, type_id: &TypeId) -> bool
Checks if a type is a function type
Sourcepub fn get_function_type(&self, type_id: &TypeId) -> Option<&FunctionType>
pub fn get_function_type(&self, type_id: &TypeId) -> Option<&FunctionType>
Gets function type information
Sourcepub fn begin_scope(&mut self)
pub fn begin_scope(&mut self)
Begins a new scope by calling the symbol table Used when entering a block, function, or other lexical scope.