Skip to content

wake.ir.statements.unchecked_block module #

UncheckedBlock class #

Bases: StatementAbc

Example

Lines 2-4 in the following code:

1
2
3
4
5
6
function inc(uint x) public pure returns(uint) {
    unchecked {
        x += 1;
    }
    return x;
}

Source code in wake/ir/statements/unchecked_block.py
class UncheckedBlock(StatementAbc):
    """
    !!! example
        Lines 2-4 in the following code:
        ```solidity linenums="1"
        function inc(uint x) public pure returns(uint) {
            unchecked {
                x += 1;
            }
            return x;
        }
        ```
    """

    _ast_node: SolcUncheckedBlock
    _parent: Union[Block, DoWhileStatement, ForStatement, IfStatement, WhileStatement]

    _statements: List[StatementAbc]

    def __init__(
        self,
        init: IrInitTuple,
        unchecked_block: SolcUncheckedBlock,
        parent: SolidityAbc,
    ):
        super().__init__(init, unchecked_block, parent)
        self._statements = [
            StatementAbc.from_ast(init, statement, self)
            for statement in unchecked_block.statements
        ]

    def __iter__(self) -> Iterator[IrAbc]:
        yield self
        for statement in self._statements:
            yield from statement

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

    @property
    def statements(self) -> Tuple[StatementAbc, ...]:
        """
        Can be empty.

        Returns:
            Statements in the block.
        """
        return tuple(self._statements)

    @property
    @lru_cache(maxsize=2048)
    def modifies_state(
        self,
    ) -> Set[Tuple[Union[ExpressionAbc, StatementAbc, YulAbc], ModifiesStateFlag]]:
        return reduce(
            or_,
            (statement.modifies_state for statement in self._statements),
            set(),
        )

    def statements_iter(self) -> Iterator[StatementAbc]:
        yield self
        for statement in self._statements:
            yield from statement.statements_iter()

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

Returns:

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

Parent IR node.

statements: Tuple[StatementAbc, ...] property #

Can be empty.

Returns:

Type Description
Tuple[StatementAbc, ...]

Statements in the block.