def visit_If(self, ast_if: If): if_node = IfNode() # coord = coordinate(ast_if.col_offset, ast_if.lineno) # self.set_coordinate(if_node, coord) # condition if_node.condition = self.visit(ast_if.test) # convert pyc true statement to list if type(ast_if.body) is not list: ast_if.body = [ast_if.body] self.parent = if_node.true_stmt for child in ast_if.body or []: child_node = self.visit(child) if child_node: if type(child_node) is list: if_node.true_stmt.extend(child_node) else: if_node.true_stmt.append(child_node) # convert pyc false statement to list if ast_if.orelse: if type(ast_if.orelse) is not list: ast_if.orelse = [ast_if.orelse] self.parent = if_node.false_stmt for child in ast_if.orelse or []: child_node = self.visit(child) if child_node: if type(child_node) is list: if_node.false_stmt.extend(child_node) else: if_node.false_stmt.append(child_node) return if_node
def compile_ifnode(self, srcnode, parent): comparison = get_comparison('{}'.format(srcnode.test)) if_ = If(test=comparison, body=[], orelse=[]) parent.body.append(self.annotate_runtime_errors(if_, srcnode)) for item in srcnode.children: self._compile(item, if_) if srcnode.else_: m = Module(body=[]) for item in srcnode.else_.children: self._compile(item, m) if_.orelse = m.body if if_.body == []: if_.body = [Pass()]
def visit_If(self, node: ast.If): node.body = self._process_stmts(node.body) if node.orelse: node.orelse = self._process_stmts(node.orelse) return node