Skip to content

wake.ir.statements.emit_statement module #

EmitStatement class #

Bases: StatementAbc

Example

emit Transfer(msg.sender, to, amount) in the following code:

function transfer(address to, uint amount) public {
    emit Transfer(msg.sender, to, amount);
}

Source code in wake/ir/statements/emit_statement.py
class EmitStatement(StatementAbc):
    """
    !!! example
        `:::solidity emit Transfer(msg.sender, to, amount)` in the following code:
        ```solidity
        function transfer(address to, uint amount) public {
            emit Transfer(msg.sender, to, amount);
        }
        ```
    """

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

    _event_call: FunctionCall

    def __init__(self, init: IrInitTuple, emit: SolcEmitStatement, parent: SolidityAbc):
        super().__init__(init, emit, parent)
        self._event_call = FunctionCall(init, emit.event_call, self)

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

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

    @property
    def children(self) -> Iterator[ExpressionAbc]:
        """
        Yields:
            Direct children of this node.
        """
        yield self._event_call

    @property
    def event_call(self) -> FunctionCall:
        """
        !!! example
            ```solidity
            Transfer(msg.sender, to, amount)
            ```
            in the following emit statement:
            ```solidity
            emit Transfer(msg.sender, to, amount)
            ```

        Returns:
            Expression representing the event call.
        """
        return self._event_call

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

children: Iterator[ExpressionAbc] property #

Yields:

Type Description
ExpressionAbc

Direct children of this node.

event_call: FunctionCall property #

Example

Transfer(msg.sender, to, amount)
in the following emit statement:
emit Transfer(msg.sender, to, amount)

Returns:

Type Description
FunctionCall

Expression representing the event call.

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

Returns:

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

Parent IR node.