pub struct StaticSingleAssigner<'a> {
pub(crate) node_builder: &'a NodeBuilder,
pub(crate) symbol_table: &'a SymbolTable,
pub(crate) type_table: &'a TypeTable,
pub(crate) rename_table: RenameTable,
pub(crate) is_lhs: bool,
pub(crate) assigner: &'a Assigner,
pub(crate) program: Option<Symbol>,
}
Fields§
§node_builder: &'a NodeBuilder
A counter used to generate unique node IDs.
symbol_table: &'a SymbolTable
The SymbolTable
of the program.
type_table: &'a TypeTable
A mapping from node IDs to their types.
rename_table: RenameTable
The RenameTable
for the current basic block in the AST
is_lhs: bool
A flag to determine whether or not the traversal is on the left-hand side of a definition or an assignment.
assigner: &'a Assigner
A struct used to construct (unique) assignment statements.
program: Option<Symbol>
The main program name.
Implementations§
source§impl<'a> StaticSingleAssigner<'a>
impl<'a> StaticSingleAssigner<'a>
sourcepub(crate) fn new(
node_builder: &'a NodeBuilder,
symbol_table: &'a SymbolTable,
type_table: &'a TypeTable,
assigner: &'a Assigner,
) -> Self
pub(crate) fn new( node_builder: &'a NodeBuilder, symbol_table: &'a SymbolTable, type_table: &'a TypeTable, assigner: &'a Assigner, ) -> Self
Initializes a new StaticSingleAssigner
with an empty RenameTable
.
sourcepub(crate) fn push(&mut self)
pub(crate) fn push(&mut self)
Pushes a new scope, setting the current scope as the new scope’s parent.
sourcepub(crate) fn pop(&mut self) -> RenameTable
pub(crate) fn pop(&mut self) -> RenameTable
If the RenameTable has a parent, then self.rename_table
is set to the parent, otherwise it is set to a default RenameTable
.
pub(crate) fn simple_assign_statement( &mut self, identifier: Identifier, rhs: Expression, ) -> Statement
sourcepub(crate) fn unique_simple_assign_statement(
&mut self,
expr: Expression,
) -> (Identifier, Statement)
pub(crate) fn unique_simple_assign_statement( &mut self, expr: Expression, ) -> (Identifier, Statement)
Constructs a simple assign statement for expr
with a unique name.
For example, expr
is transformed into $var$0 = expr;
.
The lhs is guaranteed to be unique with respect to the Assigner
.
Trait Implementations§
source§impl ExpressionConsumer for StaticSingleAssigner<'_>
impl ExpressionConsumer for StaticSingleAssigner<'_>
source§fn consume_access(&mut self, input: AccessExpression) -> Self::Output
fn consume_access(&mut self, input: AccessExpression) -> Self::Output
Consumes an access expression, accumulating any statements that are generated.
source§fn consume_array(&mut self, input: ArrayExpression) -> Self::Output
fn consume_array(&mut self, input: ArrayExpression) -> Self::Output
Consumes an array expression, accumulating any statements that are generated.
source§fn consume_binary(&mut self, input: BinaryExpression) -> Self::Output
fn consume_binary(&mut self, input: BinaryExpression) -> Self::Output
Consumes a binary expression, accumulating any statements that are generated.
source§fn consume_call(&mut self, input: CallExpression) -> Self::Output
fn consume_call(&mut self, input: CallExpression) -> Self::Output
Consumes a call expression without visiting the function name, accumulating any statements that are generated.
source§fn consume_cast(&mut self, input: CastExpression) -> Self::Output
fn consume_cast(&mut self, input: CastExpression) -> Self::Output
Consumes a cast expression, accumulating any statements that are generated.
source§fn consume_struct_init(&mut self, input: StructExpression) -> Self::Output
fn consume_struct_init(&mut self, input: StructExpression) -> Self::Output
Consumes a struct initialization expression with renamed variables, accumulating any statements that are generated.
source§fn consume_identifier(&mut self, identifier: Identifier) -> Self::Output
fn consume_identifier(&mut self, identifier: Identifier) -> Self::Output
Produces a new Identifier
with a unique name.
source§fn consume_literal(&mut self, input: Literal) -> Self::Output
fn consume_literal(&mut self, input: Literal) -> Self::Output
Consumes and returns the literal without making any modifications.
source§fn consume_locator(&mut self, input: LocatorExpression) -> Self::Output
fn consume_locator(&mut self, input: LocatorExpression) -> Self::Output
Consumes and returns the locator expression without making any modifciations
source§fn consume_ternary(&mut self, input: TernaryExpression) -> Self::Output
fn consume_ternary(&mut self, input: TernaryExpression) -> Self::Output
Consumes a ternary expression, accumulating any statements that are generated.
source§fn consume_tuple(&mut self, input: TupleExpression) -> Self::Output
fn consume_tuple(&mut self, input: TupleExpression) -> Self::Output
Consumes a tuple expression, accumulating any statements that are generated
source§fn consume_unary(&mut self, input: UnaryExpression) -> Self::Output
fn consume_unary(&mut self, input: UnaryExpression) -> Self::Output
Consumes a unary expression, accumulating any statements that are generated.
type Output = (Expression, Vec<Statement>)
fn consume_unit(&mut self, input: UnitExpression) -> Self::Output
fn consume_expression(&mut self, input: Expression) -> Self::Output
fn consume_err(&mut self, _input: ErrExpression) -> Self::Output
source§impl FunctionConsumer for StaticSingleAssigner<'_>
impl FunctionConsumer for StaticSingleAssigner<'_>
source§impl<'a> Pass for StaticSingleAssigner<'a>
impl<'a> Pass for StaticSingleAssigner<'a>
source§impl ProgramConsumer for StaticSingleAssigner<'_>
impl ProgramConsumer for StaticSingleAssigner<'_>
source§impl ProgramScopeConsumer for StaticSingleAssigner<'_>
impl ProgramScopeConsumer for StaticSingleAssigner<'_>
type Output = ProgramScope
fn consume_program_scope(&mut self, input: ProgramScope) -> Self::Output
source§impl StatementConsumer for StaticSingleAssigner<'_>
impl StatementConsumer for StaticSingleAssigner<'_>
source§fn consume_assert(&mut self, input: AssertStatement) -> Self::Output
fn consume_assert(&mut self, input: AssertStatement) -> Self::Output
Consumes the expressions in an AssertStatement
, returning the list of simplified statements.
source§fn consume_assign(&mut self, assign: AssignStatement) -> Self::Output
fn consume_assign(&mut self, assign: AssignStatement) -> Self::Output
Consume all AssignStatement
s, renaming as necessary.
source§fn consume_block(&mut self, block: Block) -> Self::Output
fn consume_block(&mut self, block: Block) -> Self::Output
Consumes a Block
, flattening its constituent ConditionalStatement
s.
source§fn consume_conditional(
&mut self,
conditional: ConditionalStatement,
) -> Self::Output
fn consume_conditional( &mut self, conditional: ConditionalStatement, ) -> Self::Output
Consumes a ConditionalStatement
, producing phi functions (assign statements) for variables written in the then-block and otherwise-block.
For more information on phi functions, see https://en.wikipedia.org/wiki/Static_single_assignment_form.
Furthermore a new AssignStatement
is introduced for non-trivial expressions in the condition of ConditionalStatement
s.
For example,
if x > 0 { x = x + 1 }
becomeslet $cond$0 = x > 0; if $cond$0 { x = x + 1; }
if true { x = x + 1 }
remains the same.if b { x = x + 1 }
remains the same.
source§fn consume_console(&mut self, _: ConsoleStatement) -> Self::Output
fn consume_console(&mut self, _: ConsoleStatement) -> Self::Output
Parsing guarantees that console statements are not present in the program.
source§fn consume_definition(
&mut self,
definition: DefinitionStatement,
) -> Self::Output
fn consume_definition( &mut self, definition: DefinitionStatement, ) -> Self::Output
Consumes the DefinitionStatement
into an AssignStatement
, renaming the left-hand-side as appropriate.
source§fn consume_expression_statement(
&mut self,
input: ExpressionStatement,
) -> Self::Output
fn consume_expression_statement( &mut self, input: ExpressionStatement, ) -> Self::Output
Consumes the expressions associated with ExpressionStatement
, returning the simplified ExpressionStatement
.
source§fn consume_return(&mut self, input: ReturnStatement) -> Self::Output
fn consume_return(&mut self, input: ReturnStatement) -> Self::Output
Reconstructs the expression associated with the return statement, returning a simplified ReturnStatement
.
Note that type checking guarantees that there is at most one ReturnStatement
in a block.
type Output = Vec<Statement>
fn consume_const(&mut self, _: ConstDeclaration) -> Self::Output
fn consume_iteration(&mut self, _input: IterationStatement) -> Self::Output
fn consume_statement(&mut self, input: Statement) -> Self::Output
source§impl StructConsumer for StaticSingleAssigner<'_>
impl StructConsumer for StaticSingleAssigner<'_>
Auto Trait Implementations§
impl<'a> Freeze for StaticSingleAssigner<'a>
impl<'a> !RefUnwindSafe for StaticSingleAssigner<'a>
impl<'a> !Send for StaticSingleAssigner<'a>
impl<'a> !Sync for StaticSingleAssigner<'a>
impl<'a> Unpin for StaticSingleAssigner<'a>
impl<'a> !UnwindSafe for StaticSingleAssigner<'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