Skip to content

wake.ir.statements.do_while_statement module #

DoWhileStatement class #

Bases: StatementAbc

Example

Lines 2-4 in the following code:

1
2
3
4
5
function foo(uint x) public {
    do {
        x += 1;
    } while (x < 10);
}

Source code in wake/ir/statements/do_while_statement.py
class DoWhileStatement(StatementAbc):
    """
    !!! example
        Lines 2-4 in the following code:
        ```solidity linenums="1"
        function foo(uint x) public {
            do {
                x += 1;
            } while (x < 10);
        }
        ```
    """

    _ast_node: SolcDoWhileStatement
    _parent: weakref.ReferenceType[
        Union[
            Block,
            DoWhileStatement,
            ForStatement,
            IfStatement,
            UncheckedBlock,
            WhileStatement,
        ]
    ]

    _body: StatementAbc
    _condition: ExpressionAbc

    def __init__(
        self, init: IrInitTuple, do_while: SolcDoWhileStatement, parent: SolidityAbc
    ):
        super().__init__(init, do_while, parent)
        self._body = StatementAbc.from_ast(init, do_while.body, self)
        self._condition = ExpressionAbc.from_ast(init, do_while.condition, self)

    def __iter__(self) -> Iterator[IrAbc]:
        yield self
        yield from self._body
        yield from self._condition

    @property
    def parent(
        self,
    ) -> Union[
        Block,
        DoWhileStatement,
        ForStatement,
        IfStatement,
        UncheckedBlock,
        WhileStatement,
    ]:
        """
        Returns:
            Parent IR node.
        """
        return super().parent

    @property
    def children(self) -> Iterator[Union[ExpressionAbc, StatementAbc]]:
        """
        Yields:
            Direct children of this node.
        """
        yield self._body
        yield self._condition

    @property
    def body(self) -> StatementAbc:
        """
        Returns:
            Body of the do-while statement.
        """
        return self._body

    @property
    def condition(self) -> ExpressionAbc:
        """
        Returns:
            Condition of the do-while statement.
        """
        return self._condition

    @property
    @weak_self_lru_cache(maxsize=2048)
    def modifies_state(
        self,
    ) -> Set[Tuple[Union[ExpressionAbc, StatementAbc, YulAbc], ModifiesStateFlag]]:
        return self.condition.modifies_state | self.body.modifies_state

    def statements_iter(self) -> Iterator[StatementAbc]:
        yield self
        yield from self._body.statements_iter()

body: StatementAbc property #

Returns:

Type Description
StatementAbc

Body of the do-while statement.

children: Iterator[Union[ExpressionAbc, StatementAbc]] property #

Yields:

Type Description
Union[ExpressionAbc, StatementAbc]

Direct children of this node.

condition: ExpressionAbc property #

Returns:

Type Description
ExpressionAbc

Condition of the do-while statement.

parent: Union[Block, DoWhileStatement, ForStatement, IfStatement, UncheckedBlock, WhileStatement] property #

Returns:

Type Description
Union[Block, DoWhileStatement, ForStatement, IfStatement, UncheckedBlock, WhileStatement]

Parent IR node.