Commit 1fa5ba65 authored by Stefan Behnel's avatar Stefan Behnel

fix warning about unused temp variable when both FlattenInListTransform and...

fix warning about unused temp variable when both FlattenInListTransform and SwitchTransform are applied
parent 521e2d0d
import cython
cython.declare(UtilityCode=object, EncodedString=object, BytesLiteral=object,
Nodes=object, ExprNodes=object, PyrexTypes=object, Builtin=object,
......@@ -977,7 +976,19 @@ class SwitchTransform(Visitor.VisitorTransform):
test = common_var,
cases = cases,
else_clause = false_body)
return UtilNodes.TempResultFromStatNode(result_ref, switch_node)
replacement = UtilNodes.TempResultFromStatNode(result_ref, switch_node)
return replacement
def visit_EvalWithTempExprNode(self, node):
# drop unused expression temp from FlattenInListTransform
orig_expr = node.subexpression
temp_ref = node.lazy_temp
self.visitchildren(node)
if node.subexpression is not orig_expr:
# node was restructured => check if temp is still used
if not Visitor.tree_contains(node.subexpression, temp_ref):
return node.subexpression
return node
visit_Node = Visitor.VisitorTransform.recurse_to_children
......
......@@ -35,3 +35,7 @@ cdef class MethodDispatcherTransform(EnvTransform):
cdef class RecursiveNodeReplacer(VisitorTransform):
cdef public orig_node
cdef public new_node
cdef class NodeFinder(TreeVisitor):
cdef node
cdef public bint found
......@@ -488,6 +488,27 @@ def recursively_replace_node(tree, old_node, new_node):
replace_in(tree)
class NodeFinder(TreeVisitor):
"""
Find out if a node appears in a subtree.
"""
def __init__(self, node):
super(NodeFinder, self).__init__()
self.node = node
self.found = False
def visit_Node(self, node):
if node is self.node:
self.found = True
else:
self.visitchildren(node)
def tree_contains(tree, node):
finder = NodeFinder(node)
finder.visit(tree)
return finder.found
# Utils
def replace_node(ptr, value):
"""Replaces a node. ptr is of the form used on the access path stack
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment