aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-08-12 13:39:31 +0200
committerOmar Polo <op@omarpolo.com>2021-08-12 13:39:31 +0200
commit8a2def82135dc493741663856310c5c662106aff (patch)
tree519ae9ddc671452252ece9e16419245f1bbb5f3a
parent13f9a4bd63892b264e45949e05f7c47ca74c0bc0 (diff)
downloadkamid-8a2def82135dc493741663856310c5c662106aff.tar.gz
kamid-8a2def82135dc493741663856310c5c662106aff.tar.bz2
actually free the AST
-rw-r--r--script.c54
1 files changed, 53 insertions, 1 deletions
diff --git a/script.c b/script.c
index c48be0e..3e12922 100644
--- a/script.c
+++ b/script.c
@@ -388,9 +388,61 @@ newop(int type)
}
void
+free_op_rec(struct op *op)
+{
+ struct op *n;
+
+ while (op != NULL) {
+ n = op->next;
+ free_op(op);
+ op = n;
+ }
+}
+
+void
free_op(struct op *op)
{
- /* TODO: probably more... */
+ if (op == NULL)
+ return;
+
+ switch (op->type) {
+ case OP_REST:
+ case OP_LITERAL:
+ case OP_VARGS:
+ break;
+ case OP_ASSIGN:
+ free(op->v.assign.name);
+ free_op_rec(op->v.assign.expr);
+ break;
+ case OP_ASSERT:
+ free_op_rec(op->v.assert);
+ break;
+ case OP_FUNCALL:
+ free_op_rec(op->v.funcall.argv);
+ break;
+ case OP_VAR:
+ free(op->v.var);
+ break;
+ case OP_CAST:
+ free_op_rec(op->v.cast.expr);
+ break;
+ case OP_CMP_EQ:
+ free_op_rec(op->v.cmp_eq.a);
+ free_op_rec(op->v.cmp_eq.b);
+ break;
+ case OP_FACCESS:
+ free_op_rec(op->v.faccess.expr);
+ free(op->v.faccess.field);
+ break;
+ case OP_SFAIL:
+ free(op->v.sfail.msg);
+ free_op_rec(op->v.sfail.expr);
+ break;
+ default:
+ /* unreachable */
+ abort();
+ }
+
free(op);
}