xref: /csrg-svn/usr.bin/pascal/pdx/tree/tfree.c (revision 22563)
1*22563Sdist /*
2*22563Sdist  * Copyright (c) 1980 Regents of the University of California.
3*22563Sdist  * All rights reserved.  The Berkeley software License Agreement
4*22563Sdist  * specifies the terms and conditions for redistribution.
5*22563Sdist  */
65539Slinton 
7*22563Sdist #ifndef lint
8*22563Sdist static char sccsid[] = "@(#)tfree.c	5.1 (Berkeley) 06/06/85";
9*22563Sdist #endif not lint
105539Slinton 
115539Slinton /*
125539Slinton  * Free a tree; this is expensive but useful.
135539Slinton  */
145539Slinton 
155539Slinton #include "defs.h"
165539Slinton #include "tree.h"
175539Slinton #include "sym.h"
185539Slinton #include "tree.rep"
195539Slinton 
205539Slinton tfree(p)
215539Slinton register NODE *p;
225539Slinton {
235539Slinton 	if (p == NIL) {
245539Slinton 		return;
255539Slinton 	}
265539Slinton 	switch(degree(p->op)) {
275539Slinton 		case LEAF:
285539Slinton 			switch(p->op) {
295539Slinton 				case O_CALL:
305539Slinton 					tfree(p->left);
315539Slinton 					tfree(p->right);
325539Slinton 					break;
335539Slinton 
345539Slinton 				case O_QLINE:
355539Slinton 					dispose(p->left->sconval);
365539Slinton 					dispose(p->left);
375539Slinton 					tfree(p->right);
385539Slinton 					break;
395539Slinton 
405539Slinton 				case O_ALIAS:
415539Slinton 					dispose(p->left->sconval);
425539Slinton 					dispose(p->left);
435539Slinton 					dispose(p->right->sconval);
445539Slinton 					dispose(p->right);
455539Slinton 					break;
465539Slinton 
475539Slinton 				case O_SCON:
485539Slinton 					unmkstring(p->nodetype);
495539Slinton 					free(p->nodetype);
505539Slinton 					free(p->sconval);
515539Slinton 					p->sconval = NIL;
525539Slinton 					break;
535539Slinton 			}
545539Slinton 			break;
555539Slinton 
565539Slinton 		case BINARY:
575539Slinton 			tfree(p->right);
585539Slinton 			/* fall through */
595539Slinton 		case UNARY:
605539Slinton 			tfree(p->left);
615539Slinton 			break;
625539Slinton 
635539Slinton 		default:
645539Slinton 			panic("bad op %d in tfree", p->op);
655539Slinton 	}
665539Slinton 	dispose(p);
675539Slinton }
68