self.traverse(root=ccall)
return ccall
+ def ternary(self, node):
+ self[node].clear()
+ self[node].emit(stmt="(")
+ with self[node]:
+ for (level, stmt) in self[node.test]:
+ self[node].emit(stmt=stmt, level=level)
+ self[node].emit(stmt="?")
+ for (level, stmt) in self[node.body]:
+ self[node].emit(stmt=stmt, level=level)
+ self[node].emit(stmt=":")
+ for (level, stmt) in self[node.orelse]:
+ self[node].emit(stmt=stmt, level=level)
+ self[node].emit(stmt=")")
+
@contextlib.contextmanager
def pseudocode(self, node):
for (level, stmt) in self.__pseudocode[node]:
if isinstance(node.rvalue, (pc_ast.GPR, pc_ast.FPR)):
self.__regfetch[str(node.rvalue)].append(node.rvalue)
- rvalue = self[node.rvalue]
if isinstance(node.rvalue, pc_ast.IfExpr):
- rvalue = [(0, " ".join([
- str(self[node.rvalue.test]),
- "?",
- str(self[node.rvalue.body[0]]),
- ":",
- str(self[node.rvalue.orelse[0]]),
- ]))]
+ self.ternary(node=node.rvalue)
if isinstance(node.lvalue, pc_ast.SubscriptExpr):
ccall = self.ccall(name="oppc_subscript_assign", node=node, stmt=True, code=[
self[node.lvalue.subject],
self[node.lvalue.index],
- rvalue,
+ self[node.rvalue],
])
elif isinstance(node.lvalue, pc_ast.RangeSubscriptExpr):
ccall = self.ccall(name="oppc_range_subscript_assign", node=node, stmt=True, code=[
self[node.lvalue.subject],
self[node.lvalue.start],
self[node.lvalue.end],
- rvalue,
+ self[node.rvalue],
])
else:
ccall = self.ccall(name="oppc_assign", stmt=True, node=node, code=[
self[node.lvalue],
- rvalue,
+ self[node.rvalue],
])
with self.pseudocode(node=node):
for (level, stmt) in self[ccall]: