]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
collect vector-member locals in ast_block->collect, like a garbage collection...
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sat, 18 Aug 2012 14:24:26 +0000 (16:24 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sat, 18 Aug 2012 14:24:26 +0000 (16:24 +0200)
ast.c
ast.h
parser.c

diff --git a/ast.c b/ast.c
index e4d18592b8d0b6480194eefe1c1485b0d676c58a..22c835f06eed6e90f0e04128965bb220d7e9217b 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -562,10 +562,14 @@ ast_block* ast_block_new(lex_ctx ctx)
 }
 MEM_VEC_FUNCTIONS(ast_block, ast_value*, locals)
 MEM_VEC_FUNCTIONS(ast_block, ast_expression*, exprs)
+MEM_VEC_FUNCTIONS(ast_block, ast_expression*, collect)
 
 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);
diff --git a/ast.h b/ast.h
index 0059e823fa303c0bc895ea3e7d0a7db4c68e8ce1..b7c61fbf6f96c6bc240dda87cceb4f4de2e19b11 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -427,6 +427,7 @@ struct ast_block_s
 
     MEM_VECTOR_MAKE(ast_value*,      locals);
     MEM_VECTOR_MAKE(ast_expression*, exprs);
+    MEM_VECTOR_MAKE(ast_expression*, collect);
 };
 ast_block* ast_block_new(lex_ctx ctx);
 void ast_block_delete(ast_block*);
@@ -434,6 +435,7 @@ bool ast_block_set_type(ast_block*, ast_expression *from);
 
 MEM_VECTOR_PROTO(ast_block, ast_value*, locals);
 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**);
 
index 24be6ec1dfe1a5a1c6a4e308d171d2393484582b..598202dcba7bf45699bfc34a53e13302d0bc445c 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1888,6 +1888,18 @@ static bool parser_variable(parser_t *parser, ast_block *localblock)
                 (void)!parser_t_locals_add(parser, vx);
                 (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))
+                {
+                    parser_pop_local(parser);
+                    parser_pop_local(parser);
+                    parser_pop_local(parser);
+                    parser_pop_local(parser);
+                    ast_value_delete(var);
+                    return false;
+                }
             }
         }
         else
@@ -1898,12 +1910,12 @@ static bool parser_variable(parser_t *parser, ast_block *localblock)
                 ast_value_delete(var);
                 return false;
             }
-        }
-        if (localblock && !ast_block_locals_add(localblock, var))
-        {
-            parser_pop_local(parser);
-            ast_value_delete(var);
-            return false;
+            if (localblock && !ast_block_locals_add(localblock, var))
+            {
+                parser_pop_local(parser);
+                ast_value_delete(var);
+                return false;
+            }
         }
 
         if (!parser_next(parser)) {