Commit 6bff7773 authored by Stefan Behnel's avatar Stefan Behnel

explicitly handle CloneNode in replacement transforms to make sure we take...

explicitly handle CloneNode in replacement transforms to make sure we take care of its content argument
parent 40f1b2a2
...@@ -416,8 +416,7 @@ class NodeRefCleanupMixin(object): ...@@ -416,8 +416,7 @@ class NodeRefCleanupMixin(object):
def visit_CloneNode(self, node): def visit_CloneNode(self, node):
arg = node.arg arg = node.arg
if arg not in self._replacements: if arg not in self._replacements:
self.visitchildren(node) self.visitchildren(arg)
arg = node.arg
node.arg = self._replacements.get(arg, arg) node.arg = self._replacements.get(arg, arg)
return node return node
...@@ -679,6 +678,13 @@ class RecursiveNodeReplacer(VisitorTransform): ...@@ -679,6 +678,13 @@ class RecursiveNodeReplacer(VisitorTransform):
super(RecursiveNodeReplacer, self).__init__() super(RecursiveNodeReplacer, self).__init__()
self.orig_node, self.new_node = orig_node, new_node self.orig_node, self.new_node = orig_node, new_node
def visit_CloneNode(self, node):
if node is self.orig_node:
return self.new_node
if node.arg is self.orig_node:
node.arg = self.new_node
return node
def visit_Node(self, node): def visit_Node(self, node):
self.visitchildren(node) self.visitchildren(node)
if node is self.orig_node: if node is self.orig_node:
...@@ -725,6 +731,7 @@ def replace_node(ptr, value): ...@@ -725,6 +731,7 @@ def replace_node(ptr, value):
else: else:
getattr(parent, attrname)[listidx] = value getattr(parent, attrname)[listidx] = value
class PrintTree(TreeVisitor): class PrintTree(TreeVisitor):
"""Prints a representation of the tree to standard output. """Prints a representation of the tree to standard output.
Subclass and override repr_of to provide more information Subclass and override repr_of to provide more information
...@@ -753,6 +760,25 @@ class PrintTree(TreeVisitor): ...@@ -753,6 +760,25 @@ class PrintTree(TreeVisitor):
# under the parent-node, not displaying the list itself in # under the parent-node, not displaying the list itself in
# the hierarchy. # the hierarchy.
def visit_Node(self, node): def visit_Node(self, node):
self._print_node(node)
self.indent()
self.visitchildren(node)
self.unindent()
return node
def visit_CloneNode(self, node):
self._print_node(node)
self.indent()
line = node.pos[1]
if self._line_range is None or self._line_range[0] <= line <= self._line_range[1]:
print("%s- %s: %s" % (self._indent, 'arg', self.repr_of(node.arg)))
self.indent()
self.visitchildren(node.arg)
self.unindent()
self.unindent()
return node
def _print_node(self, node):
line = node.pos[1] line = node.pos[1]
if self._line_range is None or self._line_range[0] <= line <= self._line_range[1]: if self._line_range is None or self._line_range[0] <= line <= self._line_range[1]:
if len(self.access_path) == 0: if len(self.access_path) == 0:
...@@ -764,10 +790,6 @@ class PrintTree(TreeVisitor): ...@@ -764,10 +790,6 @@ class PrintTree(TreeVisitor):
else: else:
name = attr name = attr
print("%s- %s: %s" % (self._indent, name, self.repr_of(node))) print("%s- %s: %s" % (self._indent, name, self.repr_of(node)))
self.indent()
self.visitchildren(node)
self.unindent()
return node
def repr_of(self, node): def repr_of(self, node):
if node is None: if node is None:
......
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