Commit 6f5104eb authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

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.
parent f49378c5
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Pyrex - Parse tree nodes # Pyrex - Parse tree nodes
# #
import string, sys, os, time import string, sys, os, time, copy
import Code import Code
from Errors import error, warning, InternalError from Errors import error, warning, InternalError
...@@ -150,6 +150,19 @@ class Node(object): ...@@ -150,6 +150,19 @@ class Node(object):
If you override get_child_accessors then this method is not used.""" If you override get_child_accessors then this method is not used."""
return self.child_attrs 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 # There are 4 phases of parse tree processing, applied in order to
......
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