Map a Python `ast.If` node to an if statement operation in the CC dialect.
(self, node)
| 5212 | "CUDA-Q does not currently support Assert expressions", node) |
| 5213 | |
| 5214 | def visit_If(self, node): |
| 5215 | """Map a Python `ast.If` node to an if statement operation in the CC |
| 5216 | dialect.""" |
| 5217 | |
| 5218 | # Visit the conditional node, retain |
| 5219 | # measurement results by assigning a dummy variable name |
| 5220 | self.currentAssignVariableName = '' |
| 5221 | self.visit(node.test) |
| 5222 | self.currentAssignVariableName = None |
| 5223 | condition = self.__arithmetic_to_bool(self.popValue()) |
| 5224 | |
| 5225 | ifOp = cc.IfOp([], condition, []) |
| 5226 | thenBlock = Block.create_at_start(ifOp.thenRegion, []) |
| 5227 | with InsertionPoint(thenBlock): |
| 5228 | self.symbolTable.beginBlock() |
| 5229 | self.pushIfStmtBlockStack() |
| 5230 | [self.visit(b) for b in node.body] |
| 5231 | if not self.hasTerminator(thenBlock): |
| 5232 | cc.ContinueOp([]) |
| 5233 | self.popIfStmtBlockStack() |
| 5234 | self.symbolTable.endBlock() |
| 5235 | |
| 5236 | if len(node.orelse) > 0: |
| 5237 | elseBlock = Block.create_at_start(ifOp.elseRegion, []) |
| 5238 | with InsertionPoint(elseBlock): |
| 5239 | self.symbolTable.beginBlock() |
| 5240 | self.pushIfStmtBlockStack() |
| 5241 | [self.visit(b) for b in node.orelse] |
| 5242 | if not self.hasTerminator(elseBlock): |
| 5243 | cc.ContinueOp([]) |
| 5244 | self.popIfStmtBlockStack() |
| 5245 | self.symbolTable.endBlock() |
| 5246 | |
| 5247 | def visit_Return(self, node): |
| 5248 |
nothing calls this directly
no test coverage detected