summaryrefslogtreecommitdiff
path: root/Parser/node.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1990-11-18 17:37:06 +0000
committerGuido van Rossum <guido@python.org>1990-11-18 17:37:06 +0000
commit10d4fcf75a5209a1999ae1c70c532cf1c447adc1 (patch)
tree66817788e3eb93dc3c66a0f3c89e61428d69fec9 /Parser/node.c
parent1f5badcc754f45d90d7a800907bc8e8f32a86ee6 (diff)
downloadcpython-10d4fcf75a5209a1999ae1c70c532cf1c447adc1.tar.gz
Add function to free an entire parse tree.
Diffstat (limited to 'Parser/node.c')
-rw-r--r--Parser/node.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/Parser/node.c b/Parser/node.c
index 86d607ab19..264fd9e8a1 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);
+ }
+}