class Switch(YulStatementAbc):
"""
TBD
"""
_parent: Block
_cases: List[Case]
_expression: Union[FunctionCall, Identifier, Literal]
def __init__(self, init: IrInitTuple, switch: YulSwitch, parent: YulAbc):
super().__init__(init, switch, parent)
if isinstance(switch.expression, YulFunctionCall):
self._expression = FunctionCall(init, switch.expression, self)
elif isinstance(switch.expression, YulIdentifier):
self._expression = Identifier(init, switch.expression, self)
elif isinstance(switch.expression, YulLiteral):
self._expression = Literal(init, switch.expression, self)
else:
assert False, f"Unexpected type: {type(switch.expression)}"
self._cases = [Case(init, case, self) for case in switch.cases]
def __iter__(self) -> Iterator[YulAbc]:
yield self
yield from self._expression
for case_ in self._cases:
yield from case_
@property
def parent(self) -> Block:
return self._parent
@property
def cases(self) -> Tuple[Case, ...]:
return tuple(self._cases)
@property
def expression(self) -> Union[FunctionCall, Identifier, Literal]:
return self._expression