projects
/
cython.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
d36f3b8
)
tiny helper class for replacing all occurrences of a node in a subtree
author
Stefan Behnel
<scoder@users.berlios.de>
Sun, 4 Oct 2009 07:29:28 +0000
(09:29 +0200)
committer
Stefan Behnel
<scoder@users.berlios.de>
Sun, 4 Oct 2009 07:29:28 +0000
(09:29 +0200)
Cython/Compiler/Visitor.py
patch
|
blob
|
history
diff --git
a/Cython/Compiler/Visitor.py
b/Cython/Compiler/Visitor.py
index 823301985a996bd574bd280f756bdaee96c9abd7..cfc79f96d94223173ae2118aad0f1bedae69de61 100644
(file)
--- a/
Cython/Compiler/Visitor.py
+++ b/
Cython/Compiler/Visitor.py
@@
-272,6
+272,22
@@
class CythonTransform(VisitorTransform):
self.visitchildren(node)
return node
+class RecursiveNodeReplacer(VisitorTransform):
+ """
+ Recursively replace all occurrences of a node in a subtree by
+ another node.
+ """
+ def __init__(self, orig_node, new_node):
+ super(RecursiveNodeReplacer, self).__init__()
+ self.orig_node, self.new_node = orig_node, new_node
+
+ def visit_Node(self, node):
+ self.visitchildren(node)
+ if node is self.orig_node:
+ return self.new_node
+ else:
+ return node
+