xref: /original-bsd/usr.bin/pascal/pdx/tree/tfree.c (revision b4971bb3)
1 /*-
2  * Copyright (c) 1980, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)tfree.c	8.1 (Berkeley) 06/06/93";
10 #endif /* not lint */
11 
12 /*
13  * Free a tree; this is expensive but useful.
14  */
15 
16 #include "defs.h"
17 #include "tree.h"
18 #include "sym.h"
19 #include "tree.rep"
20 
21 tfree(p)
22 register NODE *p;
23 {
24 	if (p == NIL) {
25 		return;
26 	}
27 	switch(degree(p->op)) {
28 		case LEAF:
29 			switch(p->op) {
30 				case O_CALL:
31 					tfree(p->left);
32 					tfree(p->right);
33 					break;
34 
35 				case O_QLINE:
36 					dispose(p->left->sconval);
37 					dispose(p->left);
38 					tfree(p->right);
39 					break;
40 
41 				case O_ALIAS:
42 					dispose(p->left->sconval);
43 					dispose(p->left);
44 					dispose(p->right->sconval);
45 					dispose(p->right);
46 					break;
47 
48 				case O_SCON:
49 					unmkstring(p->nodetype);
50 					free(p->nodetype);
51 					free(p->sconval);
52 					p->sconval = NIL;
53 					break;
54 			}
55 			break;
56 
57 		case BINARY:
58 			tfree(p->right);
59 			/* fall through */
60 		case UNARY:
61 			tfree(p->left);
62 			break;
63 
64 		default:
65 			panic("bad op %d in tfree", p->op);
66 	}
67 	dispose(p);
68 }
69