summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1990-11-18 17:37:06 (GMT)
committerGuido van Rossum <guido@python.org>1990-11-18 17:37:06 (GMT)
commit03a24cd47b0d067110db1026e99e13e974409768 (patch)
tree66817788e3eb93dc3c66a0f3c89e61428d69fec9 /Parser
parenteb38d2411c9ed3c1aeedc974e20e20a95c87427e (diff)
downloadcpython-03a24cd47b0d067110db1026e99e13e974409768.zip
cpython-03a24cd47b0d067110db1026e99e13e974409768.tar.gz
cpython-03a24cd47b0d067110db1026e99e13e974409768.tar.bz2
Add function to free an entire parse tree.
Diffstat (limited to 'Parser')
-rw-r--r--Parser/node.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/Parser/node.c b/Parser/node.c
index 86d607a..264fd9e 100644
--- a/Parser/node.c
+++ b/Parser/node.c
@@ -45,3 +45,26 @@ addchild(n1, type, str)
n->n_child = NULL;
return n;
}
+
+static void
+freechildren(n)
+ node *n;
+{
+ int i;
+ for (i = NCH(n); --i >= 0; )
+ freechildren(CHILD(n, i));
+ if (n->n_child != NULL)
+ DEL(n->n_child);
+ if (STR(n) != NULL)
+ DEL(STR(n));
+}
+
+void
+freenode(n)
+ node *n;
+{
+ if (n != NULL) {
+ freechildren(n);
+ DEL(n);
+ }
+}