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>

source

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.

source

pub(crate) fn push(&mut self)

Pushes a new scope, setting the current scope as the new scope’s parent.

source

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.

source

pub(crate) fn simple_assign_statement( &mut self, identifier: Identifier, rhs: Expression, ) -> Statement

source

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<'_>

source§

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

Consumes an array expression, accumulating any statements that are generated.

source§

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

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

Consumes a cast expression, accumulating any statements that are generated.

source§

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

Produces a new Identifier with a unique name.

source§

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

Consumes and returns the locator expression without making any modifciations

source§

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

Consumes a tuple expression, accumulating any statements that are generated

source§

fn consume_unary(&mut self, input: UnaryExpression) -> Self::Output

Consumes a unary expression, accumulating any statements that are generated.

§

type Output = (Expression, Vec<Statement>)

source§

fn consume_unit(&mut self, input: UnitExpression) -> Self::Output

source§

fn consume_expression(&mut self, input: Expression) -> Self::Output

source§

fn consume_err(&mut self, _input: ErrExpression) -> Self::Output

source§

impl FunctionConsumer for StaticSingleAssigner<'_>

source§

fn consume_function(&mut self, function: Function) -> Self::Output

Reconstructs the Functions in the Program, while allocating the appropriate RenameTables.

§

type Output = Function

source§

impl<'a> Pass for StaticSingleAssigner<'a>

§

type Input = (Ast, &'a NodeBuilder, &'a Assigner, &'a SymbolTable, &'a TypeTable)

§

type Output = Result<Ast, LeoError>

source§

fn do_pass( (ast, node_builder, assigner, symbol_table, type_table): Self::Input, ) -> Self::Output

Runs the compiler pass.
source§

impl ProgramConsumer for StaticSingleAssigner<'_>

§

type Output = Program

source§

fn consume_program(&mut self, input: Program) -> Self::Output

source§

impl ProgramScopeConsumer for StaticSingleAssigner<'_>

source§

impl StatementConsumer for StaticSingleAssigner<'_>

source§

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

Consume all AssignStatements, renaming as necessary.

source§

fn consume_block(&mut self, block: Block) -> Self::Output

Consumes a Block, flattening its constituent ConditionalStatements.

source§

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 ConditionalStatements. For example,

  • if x > 0 { x = x + 1 } becomes let $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

Parsing guarantees that console statements are not present in the program.

source§

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

Consumes the expressions associated with ExpressionStatement, returning the simplified ExpressionStatement.

source§

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>

source§

fn consume_const(&mut self, _: ConstDeclaration) -> Self::Output

source§

fn consume_iteration(&mut self, _input: IterationStatement) -> Self::Output

source§

fn consume_statement(&mut self, input: Statement) -> Self::Output

source§

impl StructConsumer for StaticSingleAssigner<'_>

source§

fn consume_struct(&mut self, struct_: Composite) -> Self::Output

Reconstructs records in the program, ordering its fields such that owner and is the first field.

§

type Output = Composite

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more