def specialize_phi(node): for parent_block, incoming_var in node.find_incoming(): if incoming_var.type.is_uninitialized: incoming_type = incoming_var.type.base_type or node.type bad = nodes.badval(incoming_type) incoming_var.type.base_type = incoming_type incoming_var.uninitialized_value = bad # print incoming_var elif not incoming_var.type == node.type: # Create promotions for variables with phi nodes in successor # blocks. incoming_symtab = incoming_var.block.symtab if (incoming_var, node.type) not in node.block.promotions: # Make sure we only coerce once for each destination type and # each variable incoming_var.block.promotions.add((incoming_var, node.type)) # Create promotion node name_node = nodes.Name(id=incoming_var.renamed_name, ctx=ast.Load()) name_node.variable = incoming_var name_node.type = incoming_var.type coercion = name_node.coerce(node.type) promotion = nodes.PromotionNode(node=coercion) # Add promotion node to block body incoming_var.block.body.append(promotion) promotion.variable.block = incoming_var.block # Update symtab incoming_symtab.promotions[incoming_var.name, node.type] = promotion else: promotion = incoming_symtab.lookup_promotion( incoming_var.name, node.type) return node
def visit_Name(self, old_node): node = nodes.Name(old_node.id, old_node.ctx) ast.copy_location(node, old_node) return self._visit_Name(node)
def visit_arg(self, old_node, lineno, col_offset): node = nodes.Name(old_node.arg, ast.Param()) node.lineno = lineno node.col_offset = col_offset return self._visit_Name(node)