]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ast.c
ast_block_collect: add to ast_block->collect and set the node's .keep=true, those...
[xonotic/gmqcc.git] / ast.c
diff --git a/ast.c b/ast.c
index 22c835f06eed6e90f0e04128965bb220d7e9217b..cdefab67ab27d960f20d0066e513e58a89dd6f91 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -557,6 +557,7 @@ ast_block* ast_block_new(lex_ctx ctx)
 
     MEM_VECTOR_INIT(self, locals);
     MEM_VECTOR_INIT(self, exprs);
+    MEM_VECTOR_INIT(self, collect);
 
     return self;
 }
@@ -564,18 +565,26 @@ MEM_VEC_FUNCTIONS(ast_block, ast_value*, locals)
 MEM_VEC_FUNCTIONS(ast_block, ast_expression*, exprs)
 MEM_VEC_FUNCTIONS(ast_block, ast_expression*, collect)
 
+bool ast_block_collect(ast_block *self, ast_expression *expr)
+{
+    if (!ast_block_collect_add(self, expr))
+        return false;
+    expr->expression.node.keep = true;
+    return true;
+}
+
 void ast_block_delete(ast_block *self)
 {
     size_t i;
-    for (i = 0; i < self->collect_count; ++i)
-        ast_unref(self->collect[i]);
-    MEM_VECTOR_CLEAR(self, collect);
     for (i = 0; i < self->exprs_count; ++i)
         ast_unref(self->exprs[i]);
     MEM_VECTOR_CLEAR(self, exprs);
     for (i = 0; i < self->locals_count; ++i)
         ast_delete(self->locals[i]);
     MEM_VECTOR_CLEAR(self, locals);
+    for (i = 0; i < self->collect_count; ++i)
+        ast_delete(self->collect[i]);
+    MEM_VECTOR_CLEAR(self, collect);
     ast_expression_delete((ast_expression*)self);
     mem_d(self);
 }