Skip to content

wake.ir.yul.variable_declaration module #

YulVariableDeclaration class #

Bases: YulStatementAbc

Represents a new variable declaration with the following structure:

let <variables> := <value>

Example

let a, b := foo() in the following example:

assembly {
    function foo() -> x, y {
        x := 1
        y := 2
    }

    let a, b := foo()
}
Source code in wake/ir/yul/variable_declaration.py
class YulVariableDeclaration(YulStatementAbc):
    """
    Represents a new variable declaration with the following structure:

    ```solidity
    let <variables> := <value>
    ```

    !!! example
        `:::solidity let a, b := foo()` in the following example:

        ```solidity
        assembly {
            function foo() -> x, y {
                x := 1
                y := 2
            }

            let a, b := foo()
        }
        ```
    """

    _parent: YulBlock
    _variables: List[YulTypedName]
    _value: Optional[Union[YulFunctionCall, YulIdentifier, YulLiteral]]

    def __init__(
        self,
        init: IrInitTuple,
        variable_declaration: SolcYulVariableDeclaration,
        parent: YulAbc,
    ):
        super().__init__(init, variable_declaration, parent)
        self._variables = [
            YulTypedName(init, variable, self)
            for variable in variable_declaration.variables
        ]
        if variable_declaration.value is None:
            self._value = None
        elif isinstance(variable_declaration.value, SolcYulFunctionCall):
            self._value = YulFunctionCall(init, variable_declaration.value, self)
        elif isinstance(variable_declaration.value, SolcYulIdentifier):
            self._value = YulIdentifier(init, variable_declaration.value, self)
        elif isinstance(variable_declaration.value, SolcYulLiteral):
            self._value = YulLiteral(init, variable_declaration.value, self)
        else:
            assert False, f"Unexpected type: {type(variable_declaration.value)}"

    def __iter__(self) -> Iterator[YulAbc]:
        yield self
        for variable in self._variables:
            yield from variable
        if self._value is not None:
            yield from self._value

    @property
    def parent(self) -> YulBlock:
        """
        Returns:
            Parent IR node.
        """
        return self._parent

    @property
    def variables(self) -> Tuple[YulTypedName, ...]:
        """
        Returns:
            Tuple of variables declared in this statement.
        """
        return tuple(self._variables)

    @property
    def value(self) -> Optional[Union[YulFunctionCall, YulIdentifier, YulLiteral]]:
        """
        Returns:
            Value assigned to the variables.
        """
        return self._value

    @property
    def modifies_state(
        self,
    ) -> Set[Tuple[Union[ExpressionAbc, StatementAbc, YulAbc], ModifiesStateFlag]]:
        if self._value is None:
            return set()
        return self._value.modifies_state

parent: YulBlock property #

Returns:

Type Description
YulBlock

Parent IR node.

value: Optional[Union[YulFunctionCall, YulIdentifier, YulLiteral]] property #

Returns:

Type Description
Optional[Union[YulFunctionCall, YulIdentifier, YulLiteral]]

Value assigned to the variables.

variables: Tuple[YulTypedName, ...] property #

Returns:

Type Description
Tuple[YulTypedName, ...]

Tuple of variables declared in this statement.