oppc/code: support ternary expr inside binary and unary
authorDmitry Selyutin <ghostmansd@gmail.com>
Sun, 14 Jan 2024 13:22:34 +0000 (16:22 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Sun, 14 Jan 2024 13:22:34 +0000 (16:22 +0300)
src/openpower/oppc/pc_code.py

index f713e55b42f090898de61c5746d99c148cf62421..d18bd1406ba7717a2c536fc7da2556958c32e9b9 100644 (file)
@@ -149,6 +149,11 @@ class CodeVisitor(pc_util.Visitor):
             pc_ast.Eq, pc_ast.NotEq,
             pc_ast.Ge, pc_ast.Gt,
         )
+        if isinstance(node.left, pc_ast.IfExpr):
+            self.ternary(node=node.left)
+        if isinstance(node.right, pc_ast.IfExpr):
+            self.ternary(node=node.right)
+
         if isinstance(node.op, comparison):
             ccall = self.ccall(name=str(self[node.op]), node=node, code=[
                 self[node.left],
@@ -168,6 +173,8 @@ class CodeVisitor(pc_util.Visitor):
     @pc_util.Hook(pc_ast.UnaryExpr)
     def UnaryExpr(self, node):
         yield node
+        if isinstance(node.value, pc_ast.IfExpr):
+            self.ternary(node=node.value)
         ccall = self.ccall(name=str(self[node.op]), node=node, code=[
             self[node.value],
         ])