unsigned Size = sizeof (ExprNodeBlock) + (Count-1) * sizeof (ExprNode);
/* Allocate memory */
- ExprNodeBlock* B = xmalloc (Size);
+ ExprNodeBlock* B = (ExprNodeBlock*) xmalloc (Size);
/* Initialize the fields */
B->Next = 0;
/* Create and return a new expression tree */
{
/* Allocate memory */
- ExprHeap* H = xmalloc (sizeof (ExprHeap));
+ ExprHeap* H = (ExprHeap*) xmalloc (sizeof (ExprHeap));
/* Allocate the first node block */
H->BlockRoot = NewExprNodeBlock (64);
ExprNode* AllocExprNode (nodetype_t NT, type* Type, int LValue)
/* Get a new node from the current expression heap */
-{
+{
ExprNode* N;
/* Must have a heap */
+void FreeExprTree (ExprNode* N)
+/* Free a complete expression tree starting with the current node */
+{
+ if (IsBranchNode (N)) {
+ /* Free the leaf nodes if necessary */
+ if ((N->NT & NT_MASK_LIST) == NT_LIST_EXPR) {
+ unsigned I;
+ unsigned Count = CollCount (&N->List);
+ for (I = 0; I < Count; ++I) {
+ FreeExprNode ((ExprNode*) CollAt (&N->List, I));
+ }
+ }
+ }
+
+ /* Free the node itself */
+ FreeExprNode (N);
+}
+
+