pub struct CodeGenerator<'a> {Show 15 fields
pub(crate) symbol_table: &'a SymbolTable,
pub(crate) type_table: &'a TypeTable,
pub(crate) struct_graph: &'a StructGraph,
pub(crate) _call_graph: &'a CallGraph,
pub(crate) next_register: u64,
pub(crate) current_function: Option<&'a Function>,
pub(crate) variable_mapping: IndexMap<&'a Symbol, String>,
pub(crate) composite_mapping: IndexMap<&'a Symbol, (bool, String)>,
pub(crate) global_mapping: IndexMap<&'a Symbol, String>,
pub(crate) variant: Option<Variant>,
pub(crate) program: &'a Program,
pub(crate) program_id: Option<ProgramId>,
pub(crate) finalize_caller: Option<Symbol>,
pub(crate) next_label: u64,
pub(crate) conditional_depth: u64,
}
Fields§
§symbol_table: &'a SymbolTable
The symbol table for the program.
type_table: &'a TypeTable
A mapping between expressions and their types.
struct_graph: &'a StructGraph
The struct dependency graph for the program.
_call_graph: &'a CallGraph
The call graph for the program.
next_register: u64
A counter to track the next available register.
current_function: Option<&'a Function>
Reference to the current function.
variable_mapping: IndexMap<&'a Symbol, String>
Mapping of variables to registers.
composite_mapping: IndexMap<&'a Symbol, (bool, String)>
Mapping of composite names to a tuple containing metadata associated with the name. The first element of the tuple indicate whether the composite is a record or not. The second element of the tuple is a string modifier used for code generation.
global_mapping: IndexMap<&'a Symbol, String>
Mapping of global identifiers to their associated names.
variant: Option<Variant>
The variant of the function we are currently traversing.
program: &'a Program
A reference to program. This is needed to look up external programs.
program_id: Option<ProgramId>
The program ID of the current program.
finalize_caller: Option<Symbol>
A reference to the finalize caller.
next_label: u64
A counter to track the next available label.
conditional_depth: u64
The depth of the current conditional block.
Implementations§
Source§impl<'a> CodeGenerator<'a>
impl<'a> CodeGenerator<'a>
Sourcepub fn new(
symbol_table: &'a SymbolTable,
type_table: &'a TypeTable,
struct_graph: &'a StructGraph,
_call_graph: &'a CallGraph,
program: &'a Program,
) -> Self
pub fn new( symbol_table: &'a SymbolTable, type_table: &'a TypeTable, struct_graph: &'a StructGraph, _call_graph: &'a CallGraph, program: &'a Program, ) -> Self
Initializes a new CodeGenerator
.
Source§impl<'a> CodeGenerator<'a>
impl<'a> CodeGenerator<'a>
Implement the necessary methods to visit nodes in the AST.
pub(crate) fn visit_expression( &mut self, input: &'a Expression, ) -> (String, String)
fn visit_identifier(&mut self, input: &'a Identifier) -> (String, String)
fn visit_err(&mut self, _input: &'a ErrExpression) -> (String, String)
fn visit_value(&mut self, input: &'a Literal) -> (String, String)
fn visit_locator(&mut self, input: &'a LocatorExpression) -> (String, String)
fn visit_binary(&mut self, input: &'a BinaryExpression) -> (String, String)
fn visit_cast(&mut self, input: &'a CastExpression) -> (String, String)
fn visit_array(&mut self, input: &'a ArrayExpression) -> (String, String)
fn visit_unary(&mut self, input: &'a UnaryExpression) -> (String, String)
fn visit_ternary(&mut self, input: &'a TernaryExpression) -> (String, String)
fn visit_struct_init(&mut self, input: &'a StructExpression) -> (String, String)
fn visit_array_access(&mut self, input: &'a ArrayAccess) -> (String, String)
fn visit_member_access(&mut self, input: &'a MemberAccess) -> (String, String)
fn visit_associated_constant( &mut self, input: &'a AssociatedConstant, ) -> (String, String)
fn visit_associated_function( &mut self, input: &'a AssociatedFunction, ) -> (String, String)
fn visit_access(&mut self, input: &'a AccessExpression) -> (String, String)
fn visit_call(&mut self, input: &'a CallExpression) -> (String, String)
fn visit_tuple(&mut self, input: &'a TupleExpression) -> (String, String)
fn visit_unit(&mut self, _input: &'a UnitExpression) -> (String, String)
Source§impl<'a> CodeGenerator<'a>
impl<'a> CodeGenerator<'a>
pub(crate) fn visit_program(&mut self, input: &'a Program) -> String
fn visit_struct_or_record(&mut self, struct_: &'a Composite) -> String
fn visit_struct(&mut self, struct_: &'a Composite) -> String
fn visit_record(&mut self, record: &'a Composite) -> String
fn visit_function_with( &mut self, function: &'a Function, futures: &[Location], ) -> String
fn visit_function(&mut self, function: &'a Function) -> String
fn visit_mapping(&mut self, mapping: &'a Mapping) -> String
Source§impl<'a> CodeGenerator<'a>
impl<'a> CodeGenerator<'a>
fn visit_statement(&mut self, input: &'a Statement) -> String
fn visit_assert(&mut self, input: &'a AssertStatement) -> String
fn visit_return(&mut self, input: &'a ReturnStatement) -> String
fn visit_definition(&mut self, _input: &'a DefinitionStatement) -> String
fn visit_expression_statement( &mut self, input: &'a ExpressionStatement, ) -> String
fn visit_assign(&mut self, input: &'a AssignStatement) -> String
fn visit_conditional(&mut self, _input: &'a ConditionalStatement) -> String
fn visit_iteration(&mut self, _input: &'a IterationStatement) -> String
fn visit_console(&mut self, _: &'a ConsoleStatement) -> String
pub(crate) fn visit_block(&mut self, input: &'a Block) -> String
Source§impl<'a> CodeGenerator<'a>
impl<'a> CodeGenerator<'a>
pub(crate) fn visit_type(input: &Type) -> String
pub(crate) fn visit_type_with_visibility( &self, type_: &'a Type, visibility: Mode, ) -> String
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for CodeGenerator<'a>
impl<'a> !RefUnwindSafe for CodeGenerator<'a>
impl<'a> !Send for CodeGenerator<'a>
impl<'a> !Sync for CodeGenerator<'a>
impl<'a> Unpin for CodeGenerator<'a>
impl<'a> !UnwindSafe for CodeGenerator<'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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more