]> 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 e4d18592b8d0b6480194eefe1c1485b0d676c58a..cdefab67ab27d960f20d0066e513e58a89dd6f91 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -557,11 +557,21 @@ 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;
 }
 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)
 {
@@ -572,6 +582,9 @@ void ast_block_delete(ast_block *self)
     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);
 }