]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
ast_block_collect: add to ast_block->collect and set the node's .keep=true, those...
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sat, 18 Aug 2012 14:27:40 +0000 (16:27 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sat, 18 Aug 2012 14:27:40 +0000 (16:27 +0200)
ast.c
ast.h
parser.c

diff --git a/ast.c b/ast.c
index 755d0d7ab36abe1d54020d2114b87a81396312ac..cdefab67ab27d960f20d0066e513e58a89dd6f91 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -565,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);
 }
diff --git a/ast.h b/ast.h
index b7c61fbf6f96c6bc240dda87cceb4f4de2e19b11..9951216438bb43fdabc6643f994869d1e263e52c 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -438,6 +438,7 @@ MEM_VECTOR_PROTO(ast_block, ast_expression*, exprs);
 MEM_VECTOR_PROTO(ast_block, ast_expression*, collect);
 
 bool ast_block_codegen(ast_block*, ast_function*, bool lvalue, ir_value**);
+bool ast_block_collect(ast_block*, ast_expression*);
 
 /* Function
  *
index 598202dcba7bf45699bfc34a53e13302d0bc445c..1d9ae74577f9b9063f6d22c6d81da788b406f5c3 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1889,9 +1889,9 @@ static bool parser_variable(parser_t *parser, ast_block *localblock)
                 (void)!parser_t_locals_add(parser, vy);
                 (void)!parser_t_locals_add(parser, vz);
                 if (!ast_block_locals_add(localblock, var) ||
-                    !ast_block_collect_add(localblock, vx.var) ||
-                    !ast_block_collect_add(localblock, vy.var) ||
-                    !ast_block_collect_add(localblock, vz.var))
+                    !ast_block_collect(localblock, vx.var) ||
+                    !ast_block_collect(localblock, vy.var) ||
+                    !ast_block_collect(localblock, vz.var))
                 {
                     parser_pop_local(parser);
                     parser_pop_local(parser);