]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Use std::vector for break and continue ast blocks
authorDale Weiler <weilercdale@gmail.com>
Thu, 15 Jan 2015 19:22:22 +0000 (14:22 -0500)
committerDale Weiler <weilercdale@gmail.com>
Thu, 15 Jan 2015 19:22:22 +0000 (14:22 -0500)
ast.cpp
ast.h

diff --git a/ast.cpp b/ast.cpp
index efff1116d0d1f00afabeb97e1a925d4b9e6bafbc..55e444054ea445513b5901768edb056f1f55b5d4 100644 (file)
--- a/ast.cpp
+++ b/ast.cpp
@@ -1181,9 +1181,6 @@ ast_function* ast_function_new(lex_ctx_t ctx, const char *name, ast_value *vtype
     self->ir_func = NULL;
     self->curblock = NULL;
 
     self->ir_func = NULL;
     self->curblock = NULL;
 
-    self->breakblocks    = NULL;
-    self->continueblocks = NULL;
-
     vtype->hasvalue = true;
     vtype->constval.vfunc = self;
 
     vtype->hasvalue = true;
     vtype->constval.vfunc = self;
 
@@ -1221,8 +1218,6 @@ void ast_function_delete(ast_function *self)
     vec_free(self->static_names);
     for (auto &it : self->blocks)
         ast_delete(it);
     vec_free(self->static_names);
     for (auto &it : self->blocks)
         ast_delete(it);
-    vec_free(self->breakblocks);
-    vec_free(self->continueblocks);
     if (self->varargs)
         ast_delete(self->varargs);
     if (self->argc)
     if (self->varargs)
         ast_delete(self->varargs);
     if (self->argc)
@@ -2895,11 +2890,11 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
         /* enter */
         func->curblock = bbody;
 
         /* enter */
         func->curblock = bbody;
 
-        vec_push(func->breakblocks,    bbreak);
+        func->breakblocks.push_back(bbreak);
         if (bcontinue)
         if (bcontinue)
-            vec_push(func->continueblocks, bcontinue);
+            func->continueblocks.push_back(bcontinue);
         else
         else
-            vec_push(func->continueblocks, bbody);
+            func->continueblocks.push_back(bbody);
 
         /* generate */
         if (self->body) {
 
         /* generate */
         if (self->body) {
@@ -2909,8 +2904,8 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
         }
 
         end_bbody = func->curblock;
         }
 
         end_bbody = func->curblock;
-        vec_pop(func->breakblocks);
-        vec_pop(func->continueblocks);
+        func->breakblocks.pop_back();
+        func->continueblocks.pop_back();
     }
 
     /* post-loop-condition */
     }
 
     /* post-loop-condition */
@@ -3047,9 +3042,9 @@ bool ast_breakcont_codegen(ast_breakcont *self, ast_function *func, bool lvalue,
     self->expression.outr = (ir_value*)1;
 
     if (self->is_continue)
     self->expression.outr = (ir_value*)1;
 
     if (self->is_continue)
-        target = func->continueblocks[vec_size(func->continueblocks)-1-self->levels];
+        target = func->continueblocks[func->continueblocks.size()-1-self->levels];
     else
     else
-        target = func->breakblocks[vec_size(func->breakblocks)-1-self->levels];
+        target = func->breakblocks[func->breakblocks.size()-1-self->levels];
 
     if (!target) {
         compile_error(ast_ctx(self), "%s is lacking a target block", (self->is_continue ? "continue" : "break"));
 
     if (!target) {
         compile_error(ast_ctx(self), "%s is lacking a target block", (self->is_continue ? "continue" : "break"));
@@ -3113,7 +3108,7 @@ bool ast_switch_codegen(ast_switch *self, ast_function *func, bool lvalue, ir_va
         return false;
 
     /* setup the break block */
         return false;
 
     /* setup the break block */
-    vec_push(func->breakblocks, bout);
+    func->breakblocks.push_back(bout);
 
     /* Now create all cases */
     for (auto &it : self->cases) {
 
     /* Now create all cases */
     for (auto &it : self->cases) {
@@ -3218,7 +3213,7 @@ bool ast_switch_codegen(ast_switch *self, ast_function *func, bool lvalue, ir_va
     func->curblock = bout;
 
     /* restore the break block */
     func->curblock = bout;
 
     /* restore the break block */
-    vec_pop(func->breakblocks);
+    func->breakblocks.pop_back();
 
     /* Move 'bout' to the end, it's nicer */
     vec_remove(func->ir_func->blocks, bout_id, 1);
 
     /* Move 'bout' to the end, it's nicer */
     vec_remove(func->ir_func->blocks, bout_id, 1);
diff --git a/ast.h b/ast.h
index d101a21b05b0f5172e11218f330af4a935e531ac..ad50c6178b50264dfb879c81b4166b708ce3d13a 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -640,8 +640,8 @@ struct ast_function
 
     ir_function *ir_func;
     ir_block    *curblock;
 
     ir_function *ir_func;
     ir_block    *curblock;
-    ir_block    **breakblocks;
-    ir_block    **continueblocks;
+    std::vector<ir_block*> breakblocks;
+    std::vector<ir_block*> continueblocks;
 
     size_t       labelcount;
     /* in order for thread safety - for the optional
 
     size_t       labelcount;
     /* in order for thread safety - for the optional