From 6f5104eb2f342a7fae4942465282200fb7eea9ae Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Fri, 16 May 2008 18:09:01 +0200 Subject: [PATCH] Added Node.clone_node utility. A method for cloning nodes. I expect this one to work on all descandants, but it can be overriden if a node has special needs. It seems natural to put such core functionality in the node classes rather than in a visitor. --- Cython/Compiler/Nodes.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 352ee77e..c44fc00f 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -2,7 +2,7 @@ # Pyrex - Parse tree nodes # -import string, sys, os, time +import string, sys, os, time, copy import Code from Errors import error, warning, InternalError @@ -150,6 +150,19 @@ class Node(object): If you override get_child_accessors then this method is not used.""" return self.child_attrs + def clone_node(self): + """Clone the node. This is defined as a shallow copy, except for member lists + amongst the child attributes (from get_child_accessors) which are also + copied. Lists containing child nodes are thus seen as a way for the node + to hold multiple children directly; the list is not treated as a seperate + level in the tree.""" + c = copy.copy(self) + for acc in c.get_child_accessors(): + value = acc.get() + if isinstance(value, list): + acc.set([x for x in value]) + return c + # # There are 4 phases of parse tree processing, applied in order to -- 2.26.2