Newer
Older
from .basic_nodes import SfgCallTreeNode, SfgCallTreeLeaf
from ..source_concepts.source_objects import TypedSymbolOrObject
if TYPE_CHECKING:
from ..context import SfgContext
class SfgCondition(SfgCallTreeLeaf):
pass
class SfgCustomCondition(SfgCondition):
def __init__(self, cond_text: str):
def required_parameters(self) -> set[TypedSymbolOrObject]:
return set()
def get_code(self, ctx: SfgContext) -> str:
return self._cond_text
# class IntEven(SfgCondition):
# def __init__(self, )
class SfgBranch(SfgCallTreeNode):
def __init__(self,
cond: SfgCondition,
branch_true: SfgCallTreeNode,
branch_false: Optional[SfgCallTreeNode] = None):
super().__init__(cond, branch_true, *((branch_false,) if branch_false else ()))
@property
def condition(self) -> SfgCondition:
@property
def branch_true(self) -> SfgCallTreeNode:
return self._children[1]
def branch_false(self) -> SfgCallTreeNode:
return self._children[2]
code = f"if({self.condition.get_code(ctx)}) {{\n"
code += ctx.codestyle.indent(self.branch_true.get_code(ctx))
code += ctx.codestyle.indent(self.branch_false.get_code(ctx))