Bases: YulStatementAbc
Represents an if statement with the following structure:
if <condition> {
<body>
}
Example
assembly {
if lt(i, 10) {
// ...
}
}
Note
There is no else branch in Yul. It must be implemented using a second if statement when needed.
Source code in wake/ir/yul/if_statement.py
| class YulIf(YulStatementAbc):
"""
Represents an if statement with the following structure:
```solidity
if <condition> {
<body>
}
```
!!! example
```solidity
assembly {
if lt(i, 10) {
// ...
}
}
```
!!! note
There is no `else` branch in Yul. It must be implemented using a second `if` statement when needed.
"""
_parent: YulBlock
_body: YulBlock
_condition: Union[YulFunctionCall, YulIdentifier, YulLiteral]
def __init__(self, init: IrInitTuple, if_statement: SolcYulIf, parent: YulAbc):
super().__init__(init, if_statement, parent)
self._body = YulBlock(init, if_statement.body, self)
if isinstance(if_statement.condition, SolcYulFunctionCall):
self._condition = YulFunctionCall(init, if_statement.condition, self)
elif isinstance(if_statement.condition, SolcYulIdentifier):
self._condition = YulIdentifier(init, if_statement.condition, self)
elif isinstance(if_statement.condition, SolcYulLiteral):
self._condition = YulLiteral(init, if_statement.condition, self)
else:
assert False, f"Unexpected type: {type(if_statement.condition)}"
def __iter__(self) -> Iterator[YulAbc]:
yield self
yield from self._condition
yield from self._body
@property
def parent(self) -> YulBlock:
"""
Returns:
Parent IR node.
"""
return self._parent
@property
def body(self) -> YulBlock:
"""
Returns:
Body of the function executed if the condition is true.
"""
return self._body
@property
def condition(self) -> Union[YulFunctionCall, YulIdentifier, YulLiteral]:
"""
Returns:
Condition of the if statement.
"""
return self._condition
|
body: YulBlock
property
Returns:
| Type |
Description |
YulBlock
|
Body of the function executed if the condition is true.
|
condition: Union[YulFunctionCall, YulIdentifier, YulLiteral]
property
parent: YulBlock
property