def setup_error_return(self, node, ret_type): """ Set FunctionDef.error_return to the AST statement that returns a "bad value" that can be used as error indicator. """ value = nodes.badval(ret_type) if value is not None: value = nodes.CoercionNode(value, dst_type=ret_type).cloneable error_return = ast.Return(value=value) if self.nopython and is_obj(self.func_signature.return_type): error_return = nodes.WithPythonNode(body=[error_return]) node.error_return = error_return
def setup_error_return(self, node, ret_type): """ Set FunctionDef.error_return to the AST statement that returns a "bad value" that can be used as error indicator. """ value = nodes.badval(ret_type) if value is not None: value = nodes.CoercionNode(value, dst_type=ret_type).cloneable error_return = ast.Return(value=value) if self.nopython and is_obj(self.func_signature.return_type): error_return = nodes.WithPythonNode(body=[error_return]) error_return = self.visit(error_return) node.error_return = error_return
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