mirror of
https://github.com/python/cpython
synced 2024-09-04 15:56:13 +00:00
Add function to free an entire parse tree.
This commit is contained in:
parent
eb38d2411c
commit
03a24cd47b
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue